wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------+ |
| 2 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 3 | * This source code has been made available to you by IBM on an AS-IS |
| 4 | * basis. Anyone receiving this source is licensed under IBM |
| 5 | * copyrights to use it in any way he or she deems fit, including |
| 6 | * copying it, modifying it, compiling it, and redistributing it either |
| 7 | * with or without modifications. No license under IBM patents or |
| 8 | * patent applications is to be implied by the copyright license. |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 9 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 10 | * Any user of this software should understand that IBM cannot provide |
| 11 | * technical support for this software and will not be responsible for |
| 12 | * any consequences resulting from the use of this software. |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 13 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 14 | * Any person who transfers this source code or any derivative work |
| 15 | * must include the IBM copyright notice, this paragraph, and the |
| 16 | * preceding two paragraphs in the transferred software. |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 17 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 18 | * COPYRIGHT I B M CORPORATION 1995 |
| 19 | * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 20 | *-----------------------------------------------------------------------------*/ |
| 21 | /*-----------------------------------------------------------------------------+ |
| 22 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 23 | * File Name: enetemac.c |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 24 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 25 | * Function: Device driver for the ethernet EMAC3 macro on the 405GP. |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 26 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 27 | * Author: Mark Wisner |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 28 | * |
| 29 | * Change Activity- |
| 30 | * |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 31 | * Date Description of Change BY |
| 32 | * --------- --------------------- --- |
| 33 | * 05-May-99 Created MKW |
| 34 | * 27-Jun-99 Clean up JWB |
| 35 | * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW |
| 36 | * 29-Jul-99 Added Full duplex support MKW |
| 37 | * 06-Aug-99 Changed names for Mal CR reg MKW |
| 38 | * 23-Aug-99 Turned off SYE when running at 10Mbs MKW |
| 39 | * 24-Aug-99 Marked descriptor empty after call_xlc MKW |
| 40 | * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG |
| 41 | * to avoid chaining maximum sized packets. Push starting |
| 42 | * RX descriptor address up to the next cache line boundary. |
| 43 | * 16-Jan-00 Added support for booting with IP of 0x0 MKW |
| 44 | * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the |
| 45 | * EMAC_RXM register. JWB |
| 46 | * 12-Mar-01 anne-sophie.harnois@nextream.fr |
| 47 | * - Variables are compatible with those already defined in |
| 48 | * include/net.h |
| 49 | * - Receive buffer descriptor ring is used to send buffers |
| 50 | * to the user |
| 51 | * - Info print about send/received/handled packet number if |
| 52 | * INFO_405_ENET is set |
| 53 | * 17-Apr-01 stefan.roese@esd-electronics.com |
| 54 | * - MAL reset in "eth_halt" included |
| 55 | * - Enet speed and duplex output now in one line |
| 56 | * 08-May-01 stefan.roese@esd-electronics.com |
| 57 | * - MAL error handling added (eth_init called again) |
| 58 | * 13-Nov-01 stefan.roese@esd-electronics.com |
| 59 | * - Set IST bit in EMAC_M1 reg upon 100MBit or full duplex |
| 60 | * 04-Jan-02 stefan.roese@esd-electronics.com |
| 61 | * - Wait for PHY auto negotiation to complete added |
| 62 | * 06-Feb-02 stefan.roese@esd-electronics.com |
| 63 | * - Bug fixed in waiting for auto negotiation to complete |
| 64 | * 26-Feb-02 stefan.roese@esd-electronics.com |
| 65 | * - rx and tx buffer descriptors now allocated (no fixed address |
| 66 | * used anymore) |
| 67 | * 17-Jun-02 stefan.roese@esd-electronics.com |
| 68 | * - MAL error debug printf 'M' removed (rx de interrupt may |
| 69 | * occur upon many incoming packets with only 4 rx buffers). |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 70 | *-----------------------------------------------------------------------------* |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 71 | * 17-Nov-03 travis.sawyer@sandburst.com |
| 72 | * - ported from 405gp_enet.c to utilized upto 4 EMAC ports |
| 73 | * in the 440GX. This port should work with the 440GP |
| 74 | * (2 EMACs) also |
| 75 | * 15-Aug-05 sr@denx.de |
| 76 | * - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c |
| 77 | now handling all 4xx cpu's. |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 78 | *-----------------------------------------------------------------------------*/ |
| 79 | |
| 80 | #include <config.h> |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 81 | #include <common.h> |
| 82 | #include <net.h> |
| 83 | #include <asm/processor.h> |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 84 | #include <asm/io.h> |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 85 | #include <asm/cache.h> |
| 86 | #include <asm/mmu.h> |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 87 | #include <commproc.h> |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 88 | #include <ppc4xx.h> |
| 89 | #include <ppc4xx_enet.h> |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 90 | #include <405_mal.h> |
| 91 | #include <miiphy.h> |
| 92 | #include <malloc.h> |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 93 | |
Jon Loeliger | 3a1ed1e | 2007-07-09 18:57:22 -0500 | [diff] [blame] | 94 | #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 95 | #error "CONFIG_MII has to be defined!" |
| 96 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 97 | |
Stefan Roese | 1e25f95 | 2005-10-20 16:34:28 +0200 | [diff] [blame] | 98 | #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI) |
| 99 | #error "CONFIG_NET_MULTI has to be defined for NetConsole" |
| 100 | #endif |
| 101 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 102 | #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */ |
Stefan Roese | 1338e6a | 2007-10-23 14:05:08 +0200 | [diff] [blame] | 103 | #define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 104 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 105 | /* Ethernet Transmit and Receive Buffers */ |
| 106 | /* AS.HARNOIS |
| 107 | * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from |
| 108 | * PKTSIZE and PKTSIZE_ALIGN (include/net.h) |
| 109 | */ |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 110 | #define ENET_MAX_MTU PKTSIZE |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 111 | #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN |
| 112 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 113 | /*-----------------------------------------------------------------------------+ |
| 114 | * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal |
| 115 | * Interrupt Controller). |
| 116 | *-----------------------------------------------------------------------------*/ |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 117 | #define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS)) |
| 118 | |
| 119 | #if defined(CONFIG_HAS_ETH3) |
| 120 | #if !defined(CONFIG_440GX) |
| 121 | #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \ |
| 122 | UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3))) |
| 123 | #else |
| 124 | /* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */ |
| 125 | #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1))) |
| 126 | #define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3))) |
| 127 | #endif /* !defined(CONFIG_440GX) */ |
| 128 | #elif defined(CONFIG_HAS_ETH2) |
| 129 | #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \ |
| 130 | UIC_MASK(ETH_IRQ_NUM(2))) |
| 131 | #elif defined(CONFIG_HAS_ETH1) |
| 132 | #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1))) |
| 133 | #else |
| 134 | #define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0)) |
| 135 | #endif |
| 136 | |
| 137 | /* |
| 138 | * Define a default version for UIC_ETHxB for non 440GX so that we can |
| 139 | * use common code for all 4xx variants |
| 140 | */ |
| 141 | #if !defined(UIC_ETHxB) |
| 142 | #define UIC_ETHxB 0 |
| 143 | #endif |
| 144 | |
| 145 | #define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR) |
| 146 | #define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE) |
| 147 | #define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE) |
| 148 | #define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB) |
| 149 | #define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB) |
| 150 | |
| 151 | #define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE) |
| 152 | #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR) |
| 153 | |
| 154 | /* |
| 155 | * We have 3 different interrupt types: |
| 156 | * - MAL interrupts indicating successful transfer |
| 157 | * - MAL error interrupts indicating MAL related errors |
| 158 | * - EMAC interrupts indicating EMAC related errors |
| 159 | * |
| 160 | * All those interrupts can be on different UIC's, but since |
| 161 | * now at least all interrupts from one type are on the same |
| 162 | * UIC. Only exception is 440GX where the EMAC interrupts are |
| 163 | * spread over two UIC's! |
| 164 | */ |
Stefan Roese | 5de8514 | 2008-06-26 17:36:39 +0200 | [diff] [blame] | 165 | #if defined(CONFIG_440GX) |
| 166 | #define UIC_BASE_MAL UIC1_DCR_BASE |
| 167 | #define UIC_BASE_MAL_ERR UIC2_DCR_BASE |
| 168 | #define UIC_BASE_EMAC UIC2_DCR_BASE |
| 169 | #define UIC_BASE_EMAC_B UIC3_DCR_BASE |
| 170 | #else |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 171 | #define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10)) |
| 172 | #define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10)) |
| 173 | #define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10)) |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 174 | #define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10)) |
| 175 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 176 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 177 | #undef INFO_4XX_ENET |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 178 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 179 | #define BI_PHYMODE_NONE 0 |
| 180 | #define BI_PHYMODE_ZMII 1 |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 181 | #define BI_PHYMODE_RGMII 2 |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 182 | #define BI_PHYMODE_GMII 3 |
| 183 | #define BI_PHYMODE_RTBI 4 |
| 184 | #define BI_PHYMODE_TBI 5 |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 185 | #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 186 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 187 | defined(CONFIG_405EX) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 188 | #define BI_PHYMODE_SMII 6 |
| 189 | #define BI_PHYMODE_MII 7 |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 190 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 191 | #define BI_PHYMODE_RMII 8 |
| 192 | #endif |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 193 | #endif |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 194 | #define BI_PHYMODE_SGMII 9 |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 195 | |
Stefan Roese | 1941cce | 2007-10-05 17:35:10 +0200 | [diff] [blame] | 196 | #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 197 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 198 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 199 | defined(CONFIG_405EX) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 200 | #define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1)) |
| 201 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 202 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 203 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 204 | #define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n)) |
| 205 | #endif |
| 206 | |
| 207 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 208 | #define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */ |
| 209 | #else |
| 210 | #define MAL_RX_CHAN_MUL 1 |
| 211 | #endif |
| 212 | |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 213 | /*--------------------------------------------------------------------+ |
| 214 | * Fixed PHY (PHY-less) support for Ethernet Ports. |
| 215 | *--------------------------------------------------------------------*/ |
| 216 | |
| 217 | /* |
| 218 | * Some boards do not have a PHY for each ethernet port. These ports |
| 219 | * are known as Fixed PHY (or PHY-less) ports. For such ports, set |
| 220 | * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 221 | * then define CONFIG_SYS_FIXED_PHY_PORTS to define what the speed and |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 222 | * duplex should be for these ports in the board configuration |
| 223 | * file. |
| 224 | * |
| 225 | * For Example: |
| 226 | * #define CONFIG_FIXED_PHY 0xFFFFFFFF |
| 227 | * |
| 228 | * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY |
| 229 | * #define CONFIG_PHY1_ADDR 1 |
| 230 | * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY |
| 231 | * #define CONFIG_PHY3_ADDR 3 |
| 232 | * |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 233 | * #define CONFIG_SYS_FIXED_PHY_PORT(devnum,speed,duplex) \ |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 234 | * {devnum, speed, duplex}, |
| 235 | * |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | * #define CONFIG_SYS_FIXED_PHY_PORTS \ |
| 237 | * CONFIG_SYS_FIXED_PHY_PORT(0,1000,FULL) \ |
| 238 | * CONFIG_SYS_FIXED_PHY_PORT(2,100,HALF) |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 239 | */ |
| 240 | |
| 241 | #ifndef CONFIG_FIXED_PHY |
| 242 | #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */ |
| 243 | #endif |
| 244 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 245 | #ifndef CONFIG_SYS_FIXED_PHY_PORTS |
| 246 | #define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */ |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 247 | #endif |
| 248 | |
| 249 | struct fixed_phy_port { |
| 250 | unsigned int devnum; /* ethernet port */ |
| 251 | unsigned int speed; /* specified speed 10,100 or 1000 */ |
| 252 | unsigned int duplex; /* specified duplex FULL or HALF */ |
| 253 | }; |
| 254 | |
| 255 | static const struct fixed_phy_port fixed_phy_port[] = { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 256 | CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */ |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 259 | /*-----------------------------------------------------------------------------+ |
| 260 | * Global variables. TX and RX descriptors and buffers. |
| 261 | *-----------------------------------------------------------------------------*/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 262 | |
Stefan Roese | 1e25f95 | 2005-10-20 16:34:28 +0200 | [diff] [blame] | 263 | /* |
| 264 | * Get count of EMAC devices (doesn't have to be the max. possible number |
| 265 | * supported by the cpu) |
Stefan Roese | 353f268 | 2007-10-23 10:10:08 +0200 | [diff] [blame] | 266 | * |
| 267 | * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the |
| 268 | * EMAC count is possible. As it is needed for the Kilauea/Haleakala |
| 269 | * 405EX/405EXr eval board, using the same binary. |
Stefan Roese | 1e25f95 | 2005-10-20 16:34:28 +0200 | [diff] [blame] | 270 | */ |
Stefan Roese | 353f268 | 2007-10-23 10:10:08 +0200 | [diff] [blame] | 271 | #if defined(CONFIG_BOARD_EMAC_COUNT) |
| 272 | #define LAST_EMAC_NUM board_emac_count() |
| 273 | #else /* CONFIG_BOARD_EMAC_COUNT */ |
Stefan Roese | 1e25f95 | 2005-10-20 16:34:28 +0200 | [diff] [blame] | 274 | #if defined(CONFIG_HAS_ETH3) |
| 275 | #define LAST_EMAC_NUM 4 |
| 276 | #elif defined(CONFIG_HAS_ETH2) |
| 277 | #define LAST_EMAC_NUM 3 |
| 278 | #elif defined(CONFIG_HAS_ETH1) |
| 279 | #define LAST_EMAC_NUM 2 |
| 280 | #else |
| 281 | #define LAST_EMAC_NUM 1 |
| 282 | #endif |
Stefan Roese | 353f268 | 2007-10-23 10:10:08 +0200 | [diff] [blame] | 283 | #endif /* CONFIG_BOARD_EMAC_COUNT */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 284 | |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 285 | /* normal boards start with EMAC0 */ |
| 286 | #if !defined(CONFIG_EMAC_NR_START) |
| 287 | #define CONFIG_EMAC_NR_START 0 |
| 288 | #endif |
| 289 | |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 290 | #define MAL_RX_DESC_SIZE 2048 |
| 291 | #define MAL_TX_DESC_SIZE 2048 |
| 292 | #define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE) |
| 293 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 294 | /*-----------------------------------------------------------------------------+ |
| 295 | * Prototypes and externals. |
| 296 | *-----------------------------------------------------------------------------*/ |
| 297 | static void enet_rcv (struct eth_device *dev, unsigned long malisr); |
| 298 | |
| 299 | int enetInt (struct eth_device *dev); |
| 300 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 301 | unsigned long uic, unsigned long maldef, |
| 302 | unsigned long mal_errr); |
| 303 | static void emac_err (struct eth_device *dev, unsigned long isr); |
| 304 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 305 | extern int phy_setup_aneg (char *devname, unsigned char addr); |
| 306 | extern int emac4xx_miiphy_read (char *devname, unsigned char addr, |
| 307 | unsigned char reg, unsigned short *value); |
| 308 | extern int emac4xx_miiphy_write (char *devname, unsigned char addr, |
| 309 | unsigned char reg, unsigned short value); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 310 | |
Stefan Roese | 353f268 | 2007-10-23 10:10:08 +0200 | [diff] [blame] | 311 | int board_emac_count(void); |
| 312 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 313 | static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p) |
| 314 | { |
| 315 | #if defined(CONFIG_440SPE) || \ |
| 316 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 317 | defined(CONFIG_405EX) |
| 318 | u32 val; |
| 319 | |
| 320 | mfsdr(sdr_mfr, val); |
| 321 | val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum); |
| 322 | mtsdr(sdr_mfr, val); |
| 323 | #elif defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 324 | u32 val; |
| 325 | |
| 326 | mfsdr(SDR0_ETH_CFG, val); |
| 327 | val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum); |
| 328 | mtsdr(SDR0_ETH_CFG, val); |
| 329 | #endif |
| 330 | } |
| 331 | |
| 332 | static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p) |
| 333 | { |
| 334 | #if defined(CONFIG_440SPE) || \ |
| 335 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 336 | defined(CONFIG_405EX) |
| 337 | u32 val; |
| 338 | |
| 339 | mfsdr(sdr_mfr, val); |
| 340 | val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum); |
| 341 | mtsdr(sdr_mfr, val); |
| 342 | #elif defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 343 | u32 val; |
| 344 | |
| 345 | mfsdr(SDR0_ETH_CFG, val); |
| 346 | val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum); |
| 347 | mtsdr(SDR0_ETH_CFG, val); |
| 348 | #endif |
| 349 | } |
| 350 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 351 | /*-----------------------------------------------------------------------------+ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 352 | | ppc_4xx_eth_halt |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 353 | | Disable MAL channel, and EMACn |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 354 | +-----------------------------------------------------------------------------*/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 355 | static void ppc_4xx_eth_halt (struct eth_device *dev) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 356 | { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 357 | EMAC_4XX_HW_PST hw_p = dev->priv; |
Stefan Roese | 9ad3198 | 2008-03-19 16:35:12 +0100 | [diff] [blame] | 358 | u32 val = 10000; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 359 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 360 | out_be32((void *)EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 361 | |
| 362 | /* 1st reset MAL channel */ |
| 363 | /* Note: writing a 0 to a channel has no effect */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 364 | #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR) |
| 365 | mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2))); |
| 366 | #else |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 367 | mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum)); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 368 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 369 | mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum)); |
| 370 | |
| 371 | /* wait for reset */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 372 | while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) { |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 373 | udelay (1000); /* Delay 1 MS so as not to hammer the register */ |
Stefan Roese | 9ad3198 | 2008-03-19 16:35:12 +0100 | [diff] [blame] | 374 | val--; |
| 375 | if (val == 0) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 376 | break; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 379 | /* provide clocks for EMAC internal loopback */ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 380 | emac_loopback_enable(hw_p); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 381 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 382 | /* EMAC RESET */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 383 | out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 384 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 385 | /* remove clocks for EMAC internal loopback */ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 386 | emac_loopback_disable(hw_p); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 387 | |
Stefan Roese | a93316c | 2005-10-18 19:17:12 +0200 | [diff] [blame] | 388 | #ifndef CONFIG_NETCONSOLE |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 389 | hw_p->print_speed = 1; /* print speed message again next time */ |
Stefan Roese | a93316c | 2005-10-18 19:17:12 +0200 | [diff] [blame] | 390 | #endif |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 391 | |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 392 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 393 | /* don't bypass the TAHOE0/TAHOE1 cores for Linux */ |
Stefan Roese | 9ad3198 | 2008-03-19 16:35:12 +0100 | [diff] [blame] | 394 | mfsdr(SDR0_ETH_CFG, val); |
| 395 | val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS); |
| 396 | mtsdr(SDR0_ETH_CFG, val); |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 397 | #endif |
| 398 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 399 | return; |
| 400 | } |
| 401 | |
Stefan Roese | 846b0dd | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 402 | #if defined (CONFIG_440GX) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 403 | int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis) |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 404 | { |
| 405 | unsigned long pfc1; |
| 406 | unsigned long zmiifer; |
| 407 | unsigned long rmiifer; |
| 408 | |
| 409 | mfsdr(sdr_pfc1, pfc1); |
| 410 | pfc1 = SDR0_PFC1_EPS_DECODE(pfc1); |
| 411 | |
| 412 | zmiifer = 0; |
| 413 | rmiifer = 0; |
| 414 | |
| 415 | switch (pfc1) { |
| 416 | case 1: |
| 417 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 418 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1); |
| 419 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2); |
| 420 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3); |
| 421 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 422 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 423 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 424 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 425 | break; |
| 426 | case 2: |
Stefan Roese | f6e495f | 2006-11-27 17:43:25 +0100 | [diff] [blame] | 427 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0); |
| 428 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1); |
| 429 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2); |
| 430 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 431 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 432 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 433 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 434 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 435 | break; |
| 436 | case 3: |
| 437 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 438 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 439 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 440 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 441 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 442 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 443 | break; |
| 444 | case 4: |
| 445 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0); |
| 446 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1); |
| 447 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2); |
| 448 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3); |
| 449 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 450 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 451 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 452 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 453 | break; |
| 454 | case 5: |
| 455 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0); |
| 456 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1); |
| 457 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2); |
| 458 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 459 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 460 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 461 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 462 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 463 | break; |
| 464 | case 6: |
| 465 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0); |
| 466 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1); |
| 467 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 468 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 469 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 470 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 471 | break; |
| 472 | case 0: |
| 473 | default: |
| 474 | zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum); |
| 475 | rmiifer = 0x0; |
| 476 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 477 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 478 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 479 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 480 | break; |
| 481 | } |
| 482 | |
| 483 | /* Ensure we setup mdio for this devnum and ONLY this devnum */ |
| 484 | zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum); |
| 485 | |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 486 | out_be32((void *)ZMII_FER, zmiifer); |
| 487 | out_be32((void *)RGMII_FER, rmiifer); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 488 | |
| 489 | return ((int)pfc1); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 490 | } |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 491 | #endif /* CONFIG_440_GX */ |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 492 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 493 | #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) |
| 494 | int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis) |
| 495 | { |
| 496 | unsigned long zmiifer=0x0; |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 497 | unsigned long pfc1; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 498 | |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 499 | mfsdr(sdr_pfc1, pfc1); |
| 500 | pfc1 &= SDR0_PFC1_SELECT_MASK; |
| 501 | |
Wolfgang Denk | 2f15278 | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 502 | switch (pfc1) { |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 503 | case SDR0_PFC1_SELECT_CONFIG_2: |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 504 | /* 1 x GMII port */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 505 | out_be32((void *)ZMII_FER, 0x00); |
| 506 | out_be32((void *)RGMII_FER, 0x00000037); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 507 | bis->bi_phymode[0] = BI_PHYMODE_GMII; |
| 508 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 509 | break; |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 510 | case SDR0_PFC1_SELECT_CONFIG_4: |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 511 | /* 2 x RGMII ports */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 512 | out_be32((void *)ZMII_FER, 0x00); |
| 513 | out_be32((void *)RGMII_FER, 0x00000055); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 514 | bis->bi_phymode[0] = BI_PHYMODE_RGMII; |
| 515 | bis->bi_phymode[1] = BI_PHYMODE_RGMII; |
| 516 | break; |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 517 | case SDR0_PFC1_SELECT_CONFIG_6: |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 518 | /* 2 x SMII ports */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 519 | out_be32((void *)ZMII_FER, |
| 520 | ((ZMII_FER_SMII) << ZMII_FER_V(0)) | |
| 521 | ((ZMII_FER_SMII) << ZMII_FER_V(1))); |
| 522 | out_be32((void *)RGMII_FER, 0x00000000); |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 523 | bis->bi_phymode[0] = BI_PHYMODE_SMII; |
| 524 | bis->bi_phymode[1] = BI_PHYMODE_SMII; |
| 525 | break; |
| 526 | case SDR0_PFC1_SELECT_CONFIG_1_2: |
| 527 | /* only 1 x MII supported */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 528 | out_be32((void *)ZMII_FER, (ZMII_FER_MII) << ZMII_FER_V(0)); |
| 529 | out_be32((void *)RGMII_FER, 0x00000000); |
Matthias Fuchs | 37ed6cd | 2007-04-24 14:03:45 +0200 | [diff] [blame] | 530 | bis->bi_phymode[0] = BI_PHYMODE_MII; |
| 531 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 532 | break; |
| 533 | default: |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | /* Ensure we setup mdio for this devnum and ONLY this devnum */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 538 | zmiifer = in_be32((void *)ZMII_FER); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 539 | zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum); |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 540 | out_be32((void *)ZMII_FER, zmiifer); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 541 | |
| 542 | return ((int)0x0); |
| 543 | } |
| 544 | #endif /* CONFIG_440EPX */ |
| 545 | |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 546 | #if defined(CONFIG_405EX) |
| 547 | int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis) |
| 548 | { |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 549 | u32 rgmiifer = 0; |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 550 | |
| 551 | /* |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 552 | * The 405EX(r)'s RGMII bridge can operate in one of several |
| 553 | * modes, only one of which (2 x RGMII) allows the |
| 554 | * simultaneous use of both EMACs on the 405EX. |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 555 | */ |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 556 | |
| 557 | switch (CONFIG_EMAC_PHY_MODE) { |
| 558 | |
| 559 | case EMAC_PHY_MODE_NONE: |
| 560 | /* No ports */ |
| 561 | rgmiifer |= RGMII_FER_DIS << 0; |
| 562 | rgmiifer |= RGMII_FER_DIS << 4; |
| 563 | out_be32((void *)RGMII_FER, rgmiifer); |
| 564 | bis->bi_phymode[0] = BI_PHYMODE_NONE; |
| 565 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 566 | break; |
| 567 | case EMAC_PHY_MODE_NONE_RGMII: |
| 568 | /* 1 x RGMII port on channel 0 */ |
| 569 | rgmiifer |= RGMII_FER_RGMII << 0; |
| 570 | rgmiifer |= RGMII_FER_DIS << 4; |
| 571 | out_be32((void *)RGMII_FER, rgmiifer); |
| 572 | bis->bi_phymode[0] = BI_PHYMODE_RGMII; |
| 573 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 574 | break; |
| 575 | case EMAC_PHY_MODE_RGMII_NONE: |
| 576 | /* 1 x RGMII port on channel 1 */ |
| 577 | rgmiifer |= RGMII_FER_DIS << 0; |
| 578 | rgmiifer |= RGMII_FER_RGMII << 4; |
| 579 | out_be32((void *)RGMII_FER, rgmiifer); |
| 580 | bis->bi_phymode[0] = BI_PHYMODE_NONE; |
| 581 | bis->bi_phymode[1] = BI_PHYMODE_RGMII; |
| 582 | break; |
| 583 | case EMAC_PHY_MODE_RGMII_RGMII: |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 584 | /* 2 x RGMII ports */ |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 585 | rgmiifer |= RGMII_FER_RGMII << 0; |
| 586 | rgmiifer |= RGMII_FER_RGMII << 4; |
| 587 | out_be32((void *)RGMII_FER, rgmiifer); |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 588 | bis->bi_phymode[0] = BI_PHYMODE_RGMII; |
| 589 | bis->bi_phymode[1] = BI_PHYMODE_RGMII; |
| 590 | break; |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 591 | case EMAC_PHY_MODE_NONE_GMII: |
| 592 | /* 1 x GMII port on channel 0 */ |
| 593 | rgmiifer |= RGMII_FER_GMII << 0; |
| 594 | rgmiifer |= RGMII_FER_DIS << 4; |
| 595 | out_be32((void *)RGMII_FER, rgmiifer); |
| 596 | bis->bi_phymode[0] = BI_PHYMODE_GMII; |
| 597 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 598 | break; |
| 599 | case EMAC_PHY_MODE_NONE_MII: |
| 600 | /* 1 x MII port on channel 0 */ |
| 601 | rgmiifer |= RGMII_FER_MII << 0; |
| 602 | rgmiifer |= RGMII_FER_DIS << 4; |
| 603 | out_be32((void *)RGMII_FER, rgmiifer); |
| 604 | bis->bi_phymode[0] = BI_PHYMODE_MII; |
| 605 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 606 | break; |
| 607 | case EMAC_PHY_MODE_GMII_NONE: |
| 608 | /* 1 x GMII port on channel 1 */ |
| 609 | rgmiifer |= RGMII_FER_DIS << 0; |
| 610 | rgmiifer |= RGMII_FER_GMII << 4; |
| 611 | out_be32((void *)RGMII_FER, rgmiifer); |
| 612 | bis->bi_phymode[0] = BI_PHYMODE_NONE; |
| 613 | bis->bi_phymode[1] = BI_PHYMODE_GMII; |
| 614 | break; |
| 615 | case EMAC_PHY_MODE_MII_NONE: |
| 616 | /* 1 x MII port on channel 1 */ |
| 617 | rgmiifer |= RGMII_FER_DIS << 0; |
| 618 | rgmiifer |= RGMII_FER_MII << 4; |
| 619 | out_be32((void *)RGMII_FER, rgmiifer); |
| 620 | bis->bi_phymode[0] = BI_PHYMODE_NONE; |
| 621 | bis->bi_phymode[1] = BI_PHYMODE_MII; |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 622 | break; |
| 623 | default: |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | /* Ensure we setup mdio for this devnum and ONLY this devnum */ |
Grant Erickson | 1740c1b | 2008-07-08 08:35:00 -0700 | [diff] [blame] | 628 | rgmiifer = in_be32((void *)RGMII_FER); |
| 629 | rgmiifer |= (1 << (19-devnum)); |
| 630 | out_be32((void *)RGMII_FER, rgmiifer); |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 631 | |
| 632 | return ((int)0x0); |
| 633 | } |
| 634 | #endif /* CONFIG_405EX */ |
| 635 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 636 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 637 | int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis) |
| 638 | { |
| 639 | u32 eth_cfg; |
| 640 | u32 zmiifer; /* ZMII0_FER reg. */ |
| 641 | u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */ |
| 642 | u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */ |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 643 | int mode; |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 644 | |
| 645 | zmiifer = 0; |
| 646 | rmiifer = 0; |
| 647 | rmiifer1 = 0; |
| 648 | |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 649 | #if defined(CONFIG_460EX) |
| 650 | mode = 9; |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 651 | mfsdr(SDR0_ETH_CFG, eth_cfg); |
| 652 | if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) && |
| 653 | ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0)) |
| 654 | mode = 11; /* config SGMII */ |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 655 | #else |
| 656 | mode = 10; |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 657 | mfsdr(SDR0_ETH_CFG, eth_cfg); |
| 658 | if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) && |
| 659 | ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) && |
| 660 | ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0)) |
| 661 | mode = 12; /* config SGMII */ |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 662 | #endif |
| 663 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 664 | /* TODO: |
| 665 | * NOTE: 460GT has 2 RGMII bridge cores: |
| 666 | * emac0 ------ RGMII0_BASE |
| 667 | * | |
| 668 | * emac1 -----+ |
| 669 | * |
| 670 | * emac2 ------ RGMII1_BASE |
| 671 | * | |
| 672 | * emac3 -----+ |
| 673 | * |
| 674 | * 460EX has 1 RGMII bridge core: |
| 675 | * and RGMII1_BASE is disabled |
| 676 | * emac0 ------ RGMII0_BASE |
| 677 | * | |
| 678 | * emac1 -----+ |
| 679 | */ |
| 680 | |
| 681 | /* |
| 682 | * Right now only 2*RGMII is supported. Please extend when needed. |
| 683 | * sr - 2008-02-19 |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 684 | * Add SGMII support. |
| 685 | * vg - 2008-07-28 |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 686 | */ |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 687 | switch (mode) { |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 688 | case 1: |
| 689 | /* 1 MII - 460EX */ |
| 690 | /* GMC0 EMAC4_0, ZMII Bridge */ |
| 691 | zmiifer |= ZMII_FER_MII << ZMII_FER_V(0); |
| 692 | bis->bi_phymode[0] = BI_PHYMODE_MII; |
| 693 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 694 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 695 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 696 | break; |
| 697 | case 2: |
| 698 | /* 2 MII - 460GT */ |
| 699 | /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */ |
| 700 | zmiifer |= ZMII_FER_MII << ZMII_FER_V(0); |
| 701 | zmiifer |= ZMII_FER_MII << ZMII_FER_V(2); |
| 702 | bis->bi_phymode[0] = BI_PHYMODE_MII; |
| 703 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 704 | bis->bi_phymode[2] = BI_PHYMODE_MII; |
| 705 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 706 | break; |
| 707 | case 3: |
| 708 | /* 2 RMII - 460EX */ |
| 709 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */ |
| 710 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 711 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1); |
| 712 | bis->bi_phymode[0] = BI_PHYMODE_RMII; |
| 713 | bis->bi_phymode[1] = BI_PHYMODE_RMII; |
| 714 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 715 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 716 | break; |
| 717 | case 4: |
| 718 | /* 4 RMII - 460GT */ |
| 719 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */ |
| 720 | /* ZMII Bridge */ |
| 721 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 722 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1); |
| 723 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2); |
| 724 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3); |
| 725 | bis->bi_phymode[0] = BI_PHYMODE_RMII; |
| 726 | bis->bi_phymode[1] = BI_PHYMODE_RMII; |
| 727 | bis->bi_phymode[2] = BI_PHYMODE_RMII; |
| 728 | bis->bi_phymode[3] = BI_PHYMODE_RMII; |
| 729 | break; |
| 730 | case 5: |
| 731 | /* 2 SMII - 460EX */ |
| 732 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */ |
| 733 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0); |
| 734 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1); |
| 735 | bis->bi_phymode[0] = BI_PHYMODE_SMII; |
| 736 | bis->bi_phymode[1] = BI_PHYMODE_SMII; |
| 737 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 738 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 739 | break; |
| 740 | case 6: |
| 741 | /* 4 SMII - 460GT */ |
| 742 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */ |
| 743 | /* ZMII Bridge */ |
| 744 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0); |
| 745 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1); |
| 746 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2); |
| 747 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3); |
| 748 | bis->bi_phymode[0] = BI_PHYMODE_SMII; |
| 749 | bis->bi_phymode[1] = BI_PHYMODE_SMII; |
| 750 | bis->bi_phymode[2] = BI_PHYMODE_SMII; |
| 751 | bis->bi_phymode[3] = BI_PHYMODE_SMII; |
| 752 | break; |
| 753 | case 7: |
| 754 | /* This is the default mode that we want for board bringup - Maple */ |
| 755 | /* 1 GMII - 460EX */ |
| 756 | /* GMC0 EMAC4_0, RGMII Bridge 0 */ |
| 757 | rmiifer |= RGMII_FER_MDIO(0); |
| 758 | |
| 759 | if (devnum == 0) { |
| 760 | rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */ |
| 761 | bis->bi_phymode[0] = BI_PHYMODE_GMII; |
| 762 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 763 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 764 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 765 | } else { |
| 766 | rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */ |
| 767 | bis->bi_phymode[0] = BI_PHYMODE_NONE; |
| 768 | bis->bi_phymode[1] = BI_PHYMODE_GMII; |
| 769 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 770 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 771 | } |
| 772 | break; |
| 773 | case 8: |
| 774 | /* 2 GMII - 460GT */ |
| 775 | /* GMC0 EMAC4_0, RGMII Bridge 0 */ |
| 776 | /* GMC1 EMAC4_2, RGMII Bridge 1 */ |
| 777 | rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */ |
| 778 | rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */ |
| 779 | rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */ |
| 780 | rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */ |
| 781 | |
| 782 | bis->bi_phymode[0] = BI_PHYMODE_GMII; |
| 783 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 784 | bis->bi_phymode[2] = BI_PHYMODE_GMII; |
| 785 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 786 | break; |
| 787 | case 9: |
| 788 | /* 2 RGMII - 460EX */ |
| 789 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */ |
| 790 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 791 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 792 | rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */ |
| 793 | |
| 794 | bis->bi_phymode[0] = BI_PHYMODE_RGMII; |
| 795 | bis->bi_phymode[1] = BI_PHYMODE_RGMII; |
| 796 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 797 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 798 | break; |
| 799 | case 10: |
| 800 | /* 4 RGMII - 460GT */ |
| 801 | /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */ |
| 802 | /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */ |
| 803 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 804 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 805 | rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 806 | rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 807 | bis->bi_phymode[0] = BI_PHYMODE_RGMII; |
| 808 | bis->bi_phymode[1] = BI_PHYMODE_RGMII; |
| 809 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 810 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 811 | break; |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 812 | case 11: |
| 813 | /* 2 SGMII - 460EX */ |
| 814 | bis->bi_phymode[0] = BI_PHYMODE_SGMII; |
| 815 | bis->bi_phymode[1] = BI_PHYMODE_SGMII; |
| 816 | bis->bi_phymode[2] = BI_PHYMODE_NONE; |
| 817 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 818 | break; |
| 819 | case 12: |
| 820 | /* 3 SGMII - 460GT */ |
| 821 | bis->bi_phymode[0] = BI_PHYMODE_SGMII; |
| 822 | bis->bi_phymode[1] = BI_PHYMODE_SGMII; |
| 823 | bis->bi_phymode[2] = BI_PHYMODE_SGMII; |
| 824 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 825 | break; |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 826 | default: |
| 827 | break; |
| 828 | } |
| 829 | |
| 830 | /* Set EMAC for MDIO */ |
| 831 | mfsdr(SDR0_ETH_CFG, eth_cfg); |
| 832 | eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0; |
| 833 | mtsdr(SDR0_ETH_CFG, eth_cfg); |
| 834 | |
| 835 | out_be32((void *)RGMII_FER, rmiifer); |
| 836 | #if defined(CONFIG_460GT) |
| 837 | out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1); |
| 838 | #endif |
| 839 | |
| 840 | /* bypass the TAHOE0/TAHOE1 cores for U-Boot */ |
| 841 | mfsdr(SDR0_ETH_CFG, eth_cfg); |
| 842 | eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS); |
| 843 | mtsdr(SDR0_ETH_CFG, eth_cfg); |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | #endif /* CONFIG_460EX || CONFIG_460GT */ |
| 848 | |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 849 | static inline void *malloc_aligned(u32 size, u32 align) |
| 850 | { |
| 851 | return (void *)(((u32)malloc(size + align) + align - 1) & |
| 852 | ~(align - 1)); |
| 853 | } |
| 854 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 855 | static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 856 | { |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 857 | int i; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 858 | unsigned long reg = 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 859 | unsigned long msr; |
| 860 | unsigned long speed; |
| 861 | unsigned long duplex; |
| 862 | unsigned long failsafe; |
| 863 | unsigned mode_reg; |
| 864 | unsigned short devnum; |
| 865 | unsigned short reg_short; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 866 | #if defined(CONFIG_440GX) || \ |
| 867 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 868 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 869 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 870 | defined(CONFIG_405EX) |
Felix Radensky | 0c24dec | 2009-05-31 20:44:15 +0300 | [diff] [blame] | 871 | u32 opbfreq; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 872 | sys_info_t sysinfo; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 873 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 874 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 875 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 876 | defined(CONFIG_405EX) |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 877 | int ethgroup = -1; |
| 878 | #endif |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 879 | #endif |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 880 | u32 bd_cached; |
| 881 | u32 bd_uncached = 0; |
Anatolij Gustschin | 4fae35a | 2008-02-25 20:54:04 +0100 | [diff] [blame] | 882 | #ifdef CONFIG_4xx_DCACHE |
| 883 | static u32 last_used_ea = 0; |
| 884 | #endif |
Stefan Roese | e54ec0f | 2008-04-03 14:50:34 +0200 | [diff] [blame] | 885 | #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 886 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
| 887 | defined(CONFIG_405EX) |
| 888 | int rgmii_channel; |
| 889 | #endif |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 890 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 891 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 892 | |
| 893 | /* before doing anything, figure out if we have a MAC address */ |
| 894 | /* if not, bail */ |
Stefan Roese | 4f92ac3 | 2005-10-10 17:43:58 +0200 | [diff] [blame] | 895 | if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) { |
| 896 | printf("ERROR: ethaddr not set!\n"); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 897 | return -1; |
Stefan Roese | 4f92ac3 | 2005-10-10 17:43:58 +0200 | [diff] [blame] | 898 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 899 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 900 | #if defined(CONFIG_440GX) || \ |
| 901 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 902 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 903 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 904 | defined(CONFIG_405EX) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 905 | /* Need to get the OPB frequency so we can access the PHY */ |
| 906 | get_sys_info (&sysinfo); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 907 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 908 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 909 | msr = mfmsr (); |
| 910 | mtmsr (msr & ~(MSR_EE)); /* disable interrupts */ |
| 911 | |
| 912 | devnum = hw_p->devnum; |
| 913 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 914 | #ifdef INFO_4XX_ENET |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 915 | /* AS.HARNOIS |
| 916 | * We should have : |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 917 | * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 918 | * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it |
| 919 | * is possible that new packets (without relationship with |
| 920 | * current transfer) have got the time to arrived before |
| 921 | * netloop calls eth_halt |
| 922 | */ |
| 923 | printf ("About preceeding transfer (eth%d):\n" |
| 924 | "- Sent packet number %d\n" |
| 925 | "- Received packet number %d\n" |
| 926 | "- Handled packet number %d\n", |
| 927 | hw_p->devnum, |
| 928 | hw_p->stats.pkts_tx, |
| 929 | hw_p->stats.pkts_rx, hw_p->stats.pkts_handled); |
| 930 | |
| 931 | hw_p->stats.pkts_tx = 0; |
| 932 | hw_p->stats.pkts_rx = 0; |
| 933 | hw_p->stats.pkts_handled = 0; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 934 | hw_p->print_speed = 1; /* print speed message again next time */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 935 | #endif |
| 936 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 937 | hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */ |
| 938 | hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 939 | |
| 940 | hw_p->rx_slot = 0; /* MAL Receive Slot */ |
| 941 | hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */ |
| 942 | hw_p->rx_u_index = 0; /* Receive User Queue Index */ |
| 943 | |
| 944 | hw_p->tx_slot = 0; /* MAL Transmit Slot */ |
| 945 | hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */ |
| 946 | hw_p->tx_u_index = 0; /* Transmit User Queue Index */ |
| 947 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 948 | #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 949 | /* set RMII mode */ |
| 950 | /* NOTE: 440GX spec states that mode is mutually exclusive */ |
| 951 | /* NOTE: Therefore, disable all other EMACS, since we handle */ |
| 952 | /* NOTE: only one emac at a time */ |
| 953 | reg = 0; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 954 | out_be32((void *)ZMII_FER, 0); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 955 | udelay (100); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 956 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 957 | #if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 958 | out_be32((void *)ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum)); |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 959 | #elif defined(CONFIG_440GX) || \ |
| 960 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 961 | defined(CONFIG_460EX) || defined(CONFIG_460GT) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 962 | ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis); |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 963 | #endif |
Stefan Roese | c57c798 | 2005-08-11 17:56:56 +0200 | [diff] [blame] | 964 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 965 | out_be32((void *)ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum)); |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 966 | #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 967 | #if defined(CONFIG_405EX) |
| 968 | ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis); |
| 969 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 970 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 971 | sync(); |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 972 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 973 | /* provide clocks for EMAC internal loopback */ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 974 | emac_loopback_enable(hw_p); |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 975 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 976 | /* EMAC RESET */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 977 | out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 978 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 979 | /* remove clocks for EMAC internal loopback */ |
| 980 | emac_loopback_disable(hw_p); |
| 981 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 982 | failsafe = 1000; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 983 | while ((in_be32((void *)EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) { |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 984 | udelay (1000); |
| 985 | failsafe--; |
| 986 | } |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 987 | if (failsafe <= 0) |
| 988 | printf("\nProblem resetting EMAC!\n"); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 989 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 990 | #if defined(CONFIG_440GX) || \ |
| 991 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 992 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 993 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 994 | defined(CONFIG_405EX) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 995 | /* Whack the M1 register */ |
| 996 | mode_reg = 0x0; |
| 997 | mode_reg &= ~0x00000038; |
Felix Radensky | 0c24dec | 2009-05-31 20:44:15 +0300 | [diff] [blame] | 998 | opbfreq = sysinfo.freqOPB / 1000000; |
| 999 | if (opbfreq <= 50); |
| 1000 | else if (opbfreq <= 66) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1001 | mode_reg |= EMAC_M1_OBCI_66; |
Felix Radensky | 0c24dec | 2009-05-31 20:44:15 +0300 | [diff] [blame] | 1002 | else if (opbfreq <= 83) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1003 | mode_reg |= EMAC_M1_OBCI_83; |
Felix Radensky | 0c24dec | 2009-05-31 20:44:15 +0300 | [diff] [blame] | 1004 | else if (opbfreq <= 100) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1005 | mode_reg |= EMAC_M1_OBCI_100; |
| 1006 | else |
| 1007 | mode_reg |= EMAC_M1_OBCI_GT100; |
| 1008 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1009 | out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg); |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1010 | #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1011 | |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 1012 | #if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \ |
| 1013 | defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR) |
| 1014 | if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) { |
| 1015 | /* |
| 1016 | * In SGMII mode, GPCS access is needed for |
| 1017 | * communication with the internal SGMII SerDes. |
| 1018 | */ |
| 1019 | switch (devnum) { |
| 1020 | #if defined(CONFIG_GPCS_PHY_ADDR) |
| 1021 | case 0: |
| 1022 | reg = CONFIG_GPCS_PHY_ADDR; |
| 1023 | break; |
| 1024 | #endif |
| 1025 | #if defined(CONFIG_GPCS_PHY1_ADDR) |
| 1026 | case 1: |
| 1027 | reg = CONFIG_GPCS_PHY1_ADDR; |
| 1028 | break; |
| 1029 | #endif |
| 1030 | #if defined(CONFIG_GPCS_PHY2_ADDR) |
| 1031 | case 2: |
| 1032 | reg = CONFIG_GPCS_PHY2_ADDR; |
| 1033 | break; |
| 1034 | #endif |
| 1035 | #if defined(CONFIG_GPCS_PHY3_ADDR) |
| 1036 | case 3: |
| 1037 | reg = CONFIG_GPCS_PHY3_ADDR; |
| 1038 | break; |
| 1039 | #endif |
| 1040 | } |
| 1041 | |
| 1042 | mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr); |
| 1043 | mode_reg |= EMAC_M1_MF_1000GPCS | EMAC_M1_IPPA_SET(reg); |
| 1044 | out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg); |
| 1045 | |
| 1046 | /* Configure GPCS interface to recommended setting for SGMII */ |
| 1047 | miiphy_reset(dev->name, reg); |
| 1048 | miiphy_write(dev->name, reg, 0x04, 0x8120); /* AsymPause, FDX */ |
| 1049 | miiphy_write(dev->name, reg, 0x07, 0x2801); /* msg_pg, toggle */ |
| 1050 | miiphy_write(dev->name, reg, 0x00, 0x0140); /* 1Gbps, FDX */ |
| 1051 | } |
| 1052 | #endif /* defined(CONFIG_GPCS_PHY_ADDR) */ |
| 1053 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1054 | /* wait for PHY to complete auto negotiation */ |
| 1055 | reg_short = 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1056 | switch (devnum) { |
| 1057 | case 0: |
| 1058 | reg = CONFIG_PHY_ADDR; |
| 1059 | break; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1060 | #if defined (CONFIG_PHY1_ADDR) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1061 | case 1: |
| 1062 | reg = CONFIG_PHY1_ADDR; |
| 1063 | break; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1064 | #endif |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1065 | #if defined (CONFIG_PHY2_ADDR) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1066 | case 2: |
| 1067 | reg = CONFIG_PHY2_ADDR; |
| 1068 | break; |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1069 | #endif |
| 1070 | #if defined (CONFIG_PHY3_ADDR) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1071 | case 3: |
| 1072 | reg = CONFIG_PHY3_ADDR; |
| 1073 | break; |
| 1074 | #endif |
| 1075 | default: |
| 1076 | reg = CONFIG_PHY_ADDR; |
| 1077 | break; |
| 1078 | } |
| 1079 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1080 | bis->bi_phynum[devnum] = reg; |
| 1081 | |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 1082 | if (reg == CONFIG_FIXED_PHY) |
| 1083 | goto get_speed; |
| 1084 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1085 | #if defined(CONFIG_PHY_RESET) |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 1086 | /* |
| 1087 | * Reset the phy, only if its the first time through |
| 1088 | * otherwise, just check the speeds & feeds |
| 1089 | */ |
| 1090 | if (hw_p->first_init == 0) { |
Stefan Roese | ec0c2ec | 2006-11-27 14:46:06 +0100 | [diff] [blame] | 1091 | #if defined(CONFIG_M88E1111_PHY) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1092 | miiphy_write (dev->name, reg, 0x14, 0x0ce3); |
| 1093 | miiphy_write (dev->name, reg, 0x18, 0x4101); |
| 1094 | miiphy_write (dev->name, reg, 0x09, 0x0e00); |
| 1095 | miiphy_write (dev->name, reg, 0x04, 0x01e1); |
| 1096 | #endif |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 1097 | #if defined(CONFIG_M88E1112_PHY) |
| 1098 | if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) { |
| 1099 | /* |
| 1100 | * Marvell 88E1112 PHY needs to have the SGMII MAC |
| 1101 | * interace (page 2) properly configured to |
| 1102 | * communicate with the 460EX/GT GPCS interface. |
| 1103 | */ |
| 1104 | |
| 1105 | /* Set access to Page 2 */ |
| 1106 | miiphy_write(dev->name, reg, 0x16, 0x0002); |
| 1107 | |
| 1108 | miiphy_write(dev->name, reg, 0x00, 0x0040); /* 1Gbps */ |
| 1109 | miiphy_read(dev->name, reg, 0x1a, ®_short); |
| 1110 | reg_short |= 0x8000; /* bypass Auto-Negotiation */ |
| 1111 | miiphy_write(dev->name, reg, 0x1a, reg_short); |
| 1112 | miiphy_reset(dev->name, reg); /* reset MAC interface */ |
| 1113 | |
| 1114 | /* Reset access to Page 0 */ |
| 1115 | miiphy_write(dev->name, reg, 0x16, 0x0000); |
| 1116 | } |
| 1117 | #endif /* defined(CONFIG_M88E1112_PHY) */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1118 | miiphy_reset (dev->name, reg); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1119 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1120 | #if defined(CONFIG_440GX) || \ |
| 1121 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1122 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1123 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1124 | defined(CONFIG_405EX) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1125 | |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 1126 | #if defined(CONFIG_CIS8201_PHY) |
wdenk | fc1cfcd | 2004-04-25 15:41:35 +0000 | [diff] [blame] | 1127 | /* |
Stefan Roese | 17f50f22 | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 1128 | * Cicada 8201 PHY needs to have an extended register whacked |
| 1129 | * for RGMII mode. |
wdenk | fc1cfcd | 2004-04-25 15:41:35 +0000 | [diff] [blame] | 1130 | */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1131 | if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) { |
Stefan Roese | b79316f | 2005-08-15 12:31:23 +0200 | [diff] [blame] | 1132 | #if defined(CONFIG_CIS8201_SHORT_ETCH) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1133 | miiphy_write (dev->name, reg, 23, 0x1300); |
Stefan Roese | b79316f | 2005-08-15 12:31:23 +0200 | [diff] [blame] | 1134 | #else |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1135 | miiphy_write (dev->name, reg, 23, 0x1000); |
Stefan Roese | b79316f | 2005-08-15 12:31:23 +0200 | [diff] [blame] | 1136 | #endif |
Stefan Roese | 17f50f22 | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 1137 | /* |
| 1138 | * Vitesse VSC8201/Cicada CIS8201 errata: |
| 1139 | * Interoperability problem with Intel 82547EI phys |
| 1140 | * This work around (provided by Vitesse) changes |
| 1141 | * the default timer convergence from 8ms to 12ms |
| 1142 | */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1143 | miiphy_write (dev->name, reg, 0x1f, 0x2a30); |
| 1144 | miiphy_write (dev->name, reg, 0x08, 0x0200); |
| 1145 | miiphy_write (dev->name, reg, 0x1f, 0x52b5); |
| 1146 | miiphy_write (dev->name, reg, 0x02, 0x0004); |
| 1147 | miiphy_write (dev->name, reg, 0x01, 0x0671); |
| 1148 | miiphy_write (dev->name, reg, 0x00, 0x8fae); |
| 1149 | miiphy_write (dev->name, reg, 0x1f, 0x2a30); |
| 1150 | miiphy_write (dev->name, reg, 0x08, 0x0000); |
| 1151 | miiphy_write (dev->name, reg, 0x1f, 0x0000); |
Stefan Roese | 17f50f22 | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 1152 | /* end Vitesse/Cicada errata */ |
| 1153 | } |
Stefan Roese | 6ca8646 | 2008-09-05 14:11:40 +0200 | [diff] [blame] | 1154 | #endif /* defined(CONFIG_CIS8201_PHY) */ |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1155 | |
| 1156 | #if defined(CONFIG_ET1011C_PHY) |
| 1157 | /* |
| 1158 | * Agere ET1011c PHY needs to have an extended register whacked |
| 1159 | * for RGMII mode. |
| 1160 | */ |
| 1161 | if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) { |
| 1162 | miiphy_read (dev->name, reg, 0x16, ®_short); |
| 1163 | reg_short &= ~(0x7); |
| 1164 | reg_short |= 0x6; /* RGMII DLL Delay*/ |
| 1165 | miiphy_write (dev->name, reg, 0x16, reg_short); |
| 1166 | |
| 1167 | miiphy_read (dev->name, reg, 0x17, ®_short); |
| 1168 | reg_short &= ~(0x40); |
| 1169 | miiphy_write (dev->name, reg, 0x17, reg_short); |
| 1170 | |
| 1171 | miiphy_write(dev->name, reg, 0x1c, 0x74f0); |
| 1172 | } |
Stefan Roese | 6ca8646 | 2008-09-05 14:11:40 +0200 | [diff] [blame] | 1173 | #endif /* defined(CONFIG_ET1011C_PHY) */ |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1174 | |
Stefan Roese | 6ca8646 | 2008-09-05 14:11:40 +0200 | [diff] [blame] | 1175 | #endif /* defined(CONFIG_440GX) ... */ |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 1176 | /* Start/Restart autonegotiation */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1177 | phy_setup_aneg (dev->name, reg); |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 1178 | udelay (1000); |
| 1179 | } |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1180 | #endif /* defined(CONFIG_PHY_RESET) */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1181 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1182 | miiphy_read (dev->name, reg, PHY_BMSR, ®_short); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1183 | |
| 1184 | /* |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 1185 | * Wait if PHY is capable of autonegotiation and autonegotiation is not complete |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1186 | */ |
| 1187 | if ((reg_short & PHY_BMSR_AUTN_ABLE) |
| 1188 | && !(reg_short & PHY_BMSR_AUTN_COMP)) { |
| 1189 | puts ("Waiting for PHY auto negotiation to complete"); |
| 1190 | i = 0; |
| 1191 | while (!(reg_short & PHY_BMSR_AUTN_COMP)) { |
| 1192 | /* |
| 1193 | * Timeout reached ? |
| 1194 | */ |
| 1195 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 1196 | puts (" TIMEOUT !\n"); |
| 1197 | break; |
| 1198 | } |
| 1199 | |
| 1200 | if ((i++ % 1000) == 0) { |
| 1201 | putc ('.'); |
| 1202 | } |
| 1203 | udelay (1000); /* 1 ms */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1204 | miiphy_read (dev->name, reg, PHY_BMSR, ®_short); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1205 | } |
| 1206 | puts (" done\n"); |
| 1207 | udelay (500000); /* another 500 ms (results in faster booting) */ |
| 1208 | } |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1209 | |
Victor Gallardo | 78d7823 | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 1210 | get_speed: |
| 1211 | if (reg == CONFIG_FIXED_PHY) { |
| 1212 | for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) { |
| 1213 | if (devnum == fixed_phy_port[i].devnum) { |
| 1214 | speed = fixed_phy_port[i].speed; |
| 1215 | duplex = fixed_phy_port[i].duplex; |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | if (i == ARRAY_SIZE(fixed_phy_port)) { |
| 1221 | printf("ERROR: PHY (%s) not configured correctly!\n", |
| 1222 | dev->name); |
| 1223 | return -1; |
| 1224 | } |
| 1225 | } else { |
| 1226 | speed = miiphy_speed(dev->name, reg); |
| 1227 | duplex = miiphy_duplex(dev->name, reg); |
| 1228 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1229 | |
| 1230 | if (hw_p->print_speed) { |
| 1231 | hw_p->print_speed = 0; |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1232 | printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n", |
| 1233 | (int) speed, (duplex == HALF) ? "HALF" : "FULL", |
| 1234 | hw_p->devnum); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1237 | #if defined(CONFIG_440) && \ |
| 1238 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
| 1239 | !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \ |
| 1240 | !defined(CONFIG_460EX) && !defined(CONFIG_460GT) |
Stefan Roese | 846b0dd | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 1241 | #if defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1242 | mfsdr(sdr_mfr, reg); |
| 1243 | if (speed == 100) { |
| 1244 | reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M; |
| 1245 | } else { |
| 1246 | reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M; |
| 1247 | } |
| 1248 | mtsdr(sdr_mfr, reg); |
| 1249 | #endif |
Stefan Roese | c57c798 | 2005-08-11 17:56:56 +0200 | [diff] [blame] | 1250 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1251 | /* Set ZMII/RGMII speed according to the phy link speed */ |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1252 | reg = in_be32((void *)ZMII_SSR); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 1253 | if ( (speed == 100) || (speed == 1000) ) |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1254 | out_be32((void *)ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum))); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1255 | else |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1256 | out_be32((void *)ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum)))); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1257 | |
| 1258 | if ((devnum == 2) || (devnum == 3)) { |
| 1259 | if (speed == 1000) |
| 1260 | reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum)); |
| 1261 | else if (speed == 100) |
| 1262 | reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum)); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1263 | else if (speed == 10) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1264 | reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum)); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1265 | else { |
| 1266 | printf("Error in RGMII Speed\n"); |
| 1267 | return -1; |
| 1268 | } |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1269 | out_be32((void *)RGMII_SSR, reg); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1270 | } |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1271 | #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1272 | |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1273 | #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1274 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1275 | defined(CONFIG_405EX) |
Stefan Roese | e54ec0f | 2008-04-03 14:50:34 +0200 | [diff] [blame] | 1276 | if (devnum >= 2) |
| 1277 | rgmii_channel = devnum - 2; |
| 1278 | else |
| 1279 | rgmii_channel = devnum; |
| 1280 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1281 | if (speed == 1000) |
Stefan Roese | e54ec0f | 2008-04-03 14:50:34 +0200 | [diff] [blame] | 1282 | reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel)); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1283 | else if (speed == 100) |
Stefan Roese | e54ec0f | 2008-04-03 14:50:34 +0200 | [diff] [blame] | 1284 | reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel)); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1285 | else if (speed == 10) |
Stefan Roese | e54ec0f | 2008-04-03 14:50:34 +0200 | [diff] [blame] | 1286 | reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel)); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1287 | else { |
| 1288 | printf("Error in RGMII Speed\n"); |
| 1289 | return -1; |
| 1290 | } |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1291 | out_be32((void *)RGMII_SSR, reg); |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1292 | #if defined(CONFIG_460GT) |
| 1293 | if ((devnum == 2) || (devnum == 3)) |
| 1294 | out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg); |
| 1295 | #endif |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1296 | #endif |
| 1297 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1298 | /* set the Mal configuration reg */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1299 | #if defined(CONFIG_440GX) || \ |
| 1300 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1301 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1302 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1303 | defined(CONFIG_405EX) |
Stefan Roese | 17f50f22 | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 1304 | mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | |
| 1305 | MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000); |
| 1306 | #else |
| 1307 | mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1308 | /* Errata 1.12: MAL_1 -- Disable MAL bursting */ |
Stefan Roese | 17f50f22 | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 1309 | if (get_pvr() == PVR_440GP_RB) { |
| 1310 | mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB); |
| 1311 | } |
| 1312 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1313 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1314 | /* |
| 1315 | * Malloc MAL buffer desciptors, make sure they are |
| 1316 | * aligned on cache line boundary size |
| 1317 | * (401/403/IOP480 = 16, 405 = 32) |
| 1318 | * and doesn't cross cache block boundaries. |
| 1319 | */ |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1320 | if (hw_p->first_init == 0) { |
| 1321 | debug("*** Allocating descriptor memory ***\n"); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1322 | |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1323 | bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096); |
| 1324 | if (!bd_cached) { |
Stefan Roese | b002144 | 2008-07-10 09:58:06 +0200 | [diff] [blame] | 1325 | printf("%s: Error allocating MAL descriptor buffers!\n", __func__); |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1326 | return -1; |
| 1327 | } |
Stefan Roese | b79316f | 2005-08-15 12:31:23 +0200 | [diff] [blame] | 1328 | |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1329 | #ifdef CONFIG_4xx_DCACHE |
Matthias Fuchs | ba79fde | 2007-12-14 11:19:56 +0100 | [diff] [blame] | 1330 | flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE); |
Anatolij Gustschin | 4fae35a | 2008-02-25 20:54:04 +0100 | [diff] [blame] | 1331 | if (!last_used_ea) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1332 | #if defined(CONFIG_SYS_MEM_TOP_HIDE) |
| 1333 | bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE; |
Anatolij Gustschin | 5e3dca5 | 2008-04-17 18:18:00 +0200 | [diff] [blame] | 1334 | #else |
Anatolij Gustschin | 4fae35a | 2008-02-25 20:54:04 +0100 | [diff] [blame] | 1335 | bd_uncached = bis->bi_memsize; |
Anatolij Gustschin | 5e3dca5 | 2008-04-17 18:18:00 +0200 | [diff] [blame] | 1336 | #endif |
Anatolij Gustschin | 4fae35a | 2008-02-25 20:54:04 +0100 | [diff] [blame] | 1337 | else |
| 1338 | bd_uncached = last_used_ea + MAL_ALLOC_SIZE; |
| 1339 | |
| 1340 | last_used_ea = bd_uncached; |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1341 | program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE, |
| 1342 | TLB_WORD2_I_ENABLE); |
| 1343 | #else |
| 1344 | bd_uncached = bd_cached; |
| 1345 | #endif |
| 1346 | hw_p->tx_phys = bd_cached; |
| 1347 | hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE; |
| 1348 | hw_p->tx = (mal_desc_t *)(bd_uncached); |
| 1349 | hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE); |
| 1350 | debug("hw_p->tx=%08x, hw_p->rx=%08x\n", hw_p->tx, hw_p->rx); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | for (i = 0; i < NUM_TX_BUFF; i++) { |
| 1354 | hw_p->tx[i].ctrl = 0; |
| 1355 | hw_p->tx[i].data_len = 0; |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1356 | if (hw_p->first_init == 0) |
| 1357 | hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE, |
| 1358 | L1_CACHE_BYTES); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1359 | hw_p->tx[i].data_ptr = hw_p->txbuf_ptr; |
| 1360 | if ((NUM_TX_BUFF - 1) == i) |
| 1361 | hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP; |
| 1362 | hw_p->tx_run[i] = -1; |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1363 | debug("TX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->tx[i].data_ptr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | for (i = 0; i < NUM_RX_BUFF; i++) { |
| 1367 | hw_p->rx[i].ctrl = 0; |
| 1368 | hw_p->rx[i].data_len = 0; |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1369 | hw_p->rx[i].data_ptr = (char *)NetRxPackets[i]; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1370 | if ((NUM_RX_BUFF - 1) == i) |
| 1371 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP; |
| 1372 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR; |
| 1373 | hw_p->rx_ready[i] = -1; |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1374 | debug("RX_BUFF %d @ 0x%08lx\n", i, (u32)hw_p->rx[i].data_ptr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | reg = 0x00000000; |
| 1378 | |
| 1379 | reg |= dev->enetaddr[0]; /* set high address */ |
| 1380 | reg = reg << 8; |
| 1381 | reg |= dev->enetaddr[1]; |
| 1382 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1383 | out_be32((void *)EMAC_IAH + hw_p->hw_addr, reg); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1384 | |
| 1385 | reg = 0x00000000; |
| 1386 | reg |= dev->enetaddr[2]; /* set low address */ |
| 1387 | reg = reg << 8; |
| 1388 | reg |= dev->enetaddr[3]; |
| 1389 | reg = reg << 8; |
| 1390 | reg |= dev->enetaddr[4]; |
| 1391 | reg = reg << 8; |
| 1392 | reg |= dev->enetaddr[5]; |
| 1393 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1394 | out_be32((void *)EMAC_IAL + hw_p->hw_addr, reg); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1395 | |
| 1396 | switch (devnum) { |
| 1397 | case 1: |
| 1398 | /* setup MAL tx & rx channel pointers */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1399 | #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR) |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1400 | mtdcr (maltxctp2r, hw_p->tx_phys); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1401 | #else |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1402 | mtdcr (maltxctp1r, hw_p->tx_phys); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1403 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1404 | #if defined(CONFIG_440) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1405 | mtdcr (maltxbattr, 0x0); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1406 | mtdcr (malrxbattr, 0x0); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1407 | #endif |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1408 | |
| 1409 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1410 | mtdcr (malrxctp8r, hw_p->rx_phys); |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1411 | /* set RX buffer size */ |
| 1412 | mtdcr (malrcbs8, ENET_MAX_MTU_ALIGNED / 16); |
| 1413 | #else |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1414 | mtdcr (malrxctp1r, hw_p->rx_phys); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1415 | /* set RX buffer size */ |
| 1416 | mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16); |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1417 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1418 | break; |
Stefan Roese | 846b0dd | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 1419 | #if defined (CONFIG_440GX) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1420 | case 2: |
| 1421 | /* setup MAL tx & rx channel pointers */ |
| 1422 | mtdcr (maltxbattr, 0x0); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1423 | mtdcr (malrxbattr, 0x0); |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1424 | mtdcr (maltxctp2r, hw_p->tx_phys); |
| 1425 | mtdcr (malrxctp2r, hw_p->rx_phys); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1426 | /* set RX buffer size */ |
| 1427 | mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16); |
| 1428 | break; |
| 1429 | case 3: |
| 1430 | /* setup MAL tx & rx channel pointers */ |
| 1431 | mtdcr (maltxbattr, 0x0); |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1432 | mtdcr (maltxctp3r, hw_p->tx_phys); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1433 | mtdcr (malrxbattr, 0x0); |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1434 | mtdcr (malrxctp3r, hw_p->rx_phys); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1435 | /* set RX buffer size */ |
| 1436 | mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16); |
| 1437 | break; |
Stefan Roese | c57c798 | 2005-08-11 17:56:56 +0200 | [diff] [blame] | 1438 | #endif /* CONFIG_440GX */ |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1439 | #if defined (CONFIG_460GT) |
| 1440 | case 2: |
| 1441 | /* setup MAL tx & rx channel pointers */ |
| 1442 | mtdcr (maltxbattr, 0x0); |
| 1443 | mtdcr (malrxbattr, 0x0); |
| 1444 | mtdcr (maltxctp2r, hw_p->tx_phys); |
| 1445 | mtdcr (malrxctp16r, hw_p->rx_phys); |
| 1446 | /* set RX buffer size */ |
| 1447 | mtdcr (malrcbs16, ENET_MAX_MTU_ALIGNED / 16); |
| 1448 | break; |
| 1449 | case 3: |
| 1450 | /* setup MAL tx & rx channel pointers */ |
| 1451 | mtdcr (maltxbattr, 0x0); |
| 1452 | mtdcr (malrxbattr, 0x0); |
| 1453 | mtdcr (maltxctp3r, hw_p->tx_phys); |
| 1454 | mtdcr (malrxctp24r, hw_p->rx_phys); |
| 1455 | /* set RX buffer size */ |
| 1456 | mtdcr (malrcbs24, ENET_MAX_MTU_ALIGNED / 16); |
| 1457 | break; |
| 1458 | #endif /* CONFIG_460GT */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1459 | case 0: |
| 1460 | default: |
| 1461 | /* setup MAL tx & rx channel pointers */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1462 | #if defined(CONFIG_440) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1463 | mtdcr (maltxbattr, 0x0); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1464 | mtdcr (malrxbattr, 0x0); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1465 | #endif |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1466 | mtdcr (maltxctp0r, hw_p->tx_phys); |
| 1467 | mtdcr (malrxctp0r, hw_p->rx_phys); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1468 | /* set RX buffer size */ |
| 1469 | mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16); |
| 1470 | break; |
| 1471 | } |
| 1472 | |
| 1473 | /* Enable MAL transmit and receive channels */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1474 | #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1475 | mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2))); |
| 1476 | #else |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1477 | mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1478 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1479 | mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 1480 | |
| 1481 | /* set transmit enable & receive enable */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1482 | out_be32((void *)EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1483 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1484 | mode_reg = in_be32((void *)EMAC_M1 + hw_p->hw_addr); |
Stefan Roese | 76957cb | 2008-03-01 12:11:40 +0100 | [diff] [blame] | 1485 | |
| 1486 | /* set rx-/tx-fifo size */ |
| 1487 | mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1488 | |
| 1489 | /* set speed */ |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1490 | if (speed == _1000BASET) { |
Stefan Roese | 738815c | 2007-10-02 11:44:46 +0200 | [diff] [blame] | 1491 | #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 1492 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1493 | unsigned long pfc1; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1494 | |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1495 | mfsdr (sdr_pfc1, pfc1); |
| 1496 | pfc1 |= SDR0_PFC1_EM_1000; |
| 1497 | mtsdr (sdr_pfc1, pfc1); |
| 1498 | #endif |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 1499 | mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST; |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1500 | } else if (speed == _100BASET) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1501 | mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST; |
| 1502 | else |
| 1503 | mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */ |
| 1504 | if (duplex == FULL) |
| 1505 | mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST; |
| 1506 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1507 | out_be32((void *)EMAC_M1 + hw_p->hw_addr, mode_reg); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1508 | |
| 1509 | /* Enable broadcast and indvidual address */ |
| 1510 | /* TBS: enabling runts as some misbehaved nics will send runts */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1511 | out_be32((void *)EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1512 | |
| 1513 | /* we probably need to set the tx mode1 reg? maybe at tx time */ |
| 1514 | |
| 1515 | /* set transmit request threshold register */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1516 | out_be32((void *)EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1517 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 1518 | /* set receive low/high water mark register */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1519 | #if defined(CONFIG_440) |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 1520 | /* 440s has a 64 byte burst length */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1521 | out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1522 | #else |
| 1523 | /* 405s have a 16 byte burst length */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1524 | out_be32((void *)EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1525 | #endif /* defined(CONFIG_440) */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1526 | out_be32((void *)EMAC_TXM1 + hw_p->hw_addr, 0xf8640000); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1527 | |
| 1528 | /* Set fifo limit entry in tx mode 0 */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1529 | out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, 0x00000003); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1530 | /* Frame gap set */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1531 | out_be32((void *)EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1532 | |
| 1533 | /* Set EMAC IER */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1534 | hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1535 | if (speed == _100BASET) |
| 1536 | hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE; |
| 1537 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1538 | out_be32((void *)EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */ |
| 1539 | out_be32((void *)EMAC_IER + hw_p->hw_addr, hw_p->emac_ier); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1540 | |
| 1541 | if (hw_p->first_init == 0) { |
| 1542 | /* |
| 1543 | * Connect interrupt service routines |
| 1544 | */ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1545 | irq_install_handler(ETH_IRQ_NUM(hw_p->devnum), |
| 1546 | (interrupt_handler_t *) enetInt, dev); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1547 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1548 | |
| 1549 | mtmsr (msr); /* enable interrupts again */ |
| 1550 | |
| 1551 | hw_p->bis = bis; |
| 1552 | hw_p->first_init = 1; |
| 1553 | |
Stefan Roese | 802b769 | 2008-01-08 18:39:30 +0100 | [diff] [blame] | 1554 | return 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1558 | static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1559 | int len) |
| 1560 | { |
| 1561 | struct enet_frame *ef_ptr; |
| 1562 | ulong time_start, time_now; |
| 1563 | unsigned long temp_txm0; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1564 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1565 | |
| 1566 | ef_ptr = (struct enet_frame *) ptr; |
| 1567 | |
| 1568 | /*-----------------------------------------------------------------------+ |
| 1569 | * Copy in our address into the frame. |
| 1570 | *-----------------------------------------------------------------------*/ |
| 1571 | (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH); |
| 1572 | |
| 1573 | /*-----------------------------------------------------------------------+ |
| 1574 | * If frame is too long or too short, modify length. |
| 1575 | *-----------------------------------------------------------------------*/ |
| 1576 | /* TBS: where does the fragment go???? */ |
| 1577 | if (len > ENET_MAX_MTU) |
| 1578 | len = ENET_MAX_MTU; |
| 1579 | |
| 1580 | /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */ |
| 1581 | memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len); |
Matthias Fuchs | ba79fde | 2007-12-14 11:19:56 +0100 | [diff] [blame] | 1582 | flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1583 | |
| 1584 | /*-----------------------------------------------------------------------+ |
| 1585 | * set TX Buffer busy, and send it |
| 1586 | *-----------------------------------------------------------------------*/ |
| 1587 | hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST | |
| 1588 | EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) & |
| 1589 | ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA); |
| 1590 | if ((NUM_TX_BUFF - 1) == hw_p->tx_slot) |
| 1591 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP; |
| 1592 | |
| 1593 | hw_p->tx[hw_p->tx_slot].data_len = (short) len; |
| 1594 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY; |
| 1595 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1596 | sync(); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1597 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1598 | out_be32((void *)EMAC_TXM0 + hw_p->hw_addr, |
| 1599 | in_be32((void *)EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1600 | #ifdef INFO_4XX_ENET |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1601 | hw_p->stats.pkts_tx++; |
| 1602 | #endif |
| 1603 | |
| 1604 | /*-----------------------------------------------------------------------+ |
| 1605 | * poll unitl the packet is sent and then make sure it is OK |
| 1606 | *-----------------------------------------------------------------------*/ |
| 1607 | time_start = get_timer (0); |
| 1608 | while (1) { |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1609 | temp_txm0 = in_be32((void *)EMAC_TXM0 + hw_p->hw_addr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1610 | /* loop until either TINT turns on or 3 seconds elapse */ |
| 1611 | if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) { |
| 1612 | /* transmit is done, so now check for errors |
| 1613 | * If there is an error, an interrupt should |
| 1614 | * happen when we return |
| 1615 | */ |
| 1616 | time_now = get_timer (0); |
| 1617 | if ((time_now - time_start) > 3000) { |
| 1618 | return (-1); |
| 1619 | } |
| 1620 | } else { |
| 1621 | return (len); |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1626 | int enetInt (struct eth_device *dev) |
| 1627 | { |
| 1628 | int serviced; |
| 1629 | int rc = -1; /* default to not us */ |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1630 | u32 mal_isr; |
| 1631 | u32 emac_isr = 0; |
| 1632 | u32 mal_eob; |
| 1633 | u32 uic_mal; |
| 1634 | u32 uic_mal_err; |
| 1635 | u32 uic_emac; |
| 1636 | u32 uic_emac_b; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1637 | EMAC_4XX_HW_PST hw_p; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1638 | |
| 1639 | /* |
| 1640 | * Because the mal is generic, we need to get the current |
| 1641 | * eth device |
| 1642 | */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1643 | dev = eth_get_dev(); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1644 | |
| 1645 | hw_p = dev->priv; |
| 1646 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1647 | /* enter loop that stays in interrupt code until nothing to service */ |
| 1648 | do { |
| 1649 | serviced = 0; |
| 1650 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1651 | uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR); |
| 1652 | uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR); |
| 1653 | uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR); |
| 1654 | uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1655 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1656 | if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB)) |
| 1657 | && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) |
| 1658 | && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) { |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1659 | /* not for us */ |
| 1660 | return (rc); |
| 1661 | } |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1662 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1663 | /* get and clear controller status interrupts */ |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1664 | /* look at MAL and EMAC error interrupts */ |
| 1665 | if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) { |
| 1666 | /* we have a MAL error interrupt */ |
| 1667 | mal_isr = mfdcr(malesr); |
| 1668 | mal_err(dev, mal_isr, uic_mal_err, |
| 1669 | MAL_UIC_DEF, MAL_UIC_ERR); |
| 1670 | |
| 1671 | /* clear MAL error interrupt status bits */ |
| 1672 | mtdcr(UIC_BASE_MAL_ERR + UIC_SR, |
| 1673 | UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE); |
| 1674 | |
| 1675 | return -1; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1678 | /* look for EMAC errors */ |
| 1679 | if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) { |
| 1680 | emac_isr = in_be32((void *)EMAC_ISR + hw_p->hw_addr); |
| 1681 | emac_err(dev, emac_isr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1682 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1683 | /* clear EMAC error interrupt status bits */ |
| 1684 | mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx); |
| 1685 | mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1686 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1687 | return -1; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1688 | } |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1689 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1690 | /* handle MAX TX EOB interrupt from a tx */ |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1691 | if (uic_mal & UIC_MAL_TXEOB) { |
| 1692 | /* clear MAL interrupt status bits */ |
| 1693 | mal_eob = mfdcr(maltxeobisr); |
| 1694 | mtdcr(maltxeobisr, mal_eob); |
| 1695 | mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB); |
| 1696 | |
| 1697 | /* indicate that we serviced an interrupt */ |
| 1698 | serviced = 1; |
| 1699 | rc = 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1700 | } |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1701 | |
| 1702 | /* handle MAL RX EOB interupt from a receive */ |
| 1703 | /* check for EOB on valid channels */ |
| 1704 | if (uic_mal & UIC_MAL_RXEOB) { |
| 1705 | mal_eob = mfdcr(malrxeobisr); |
| 1706 | if (mal_eob & |
| 1707 | (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) { |
| 1708 | /* push packet to upper layer */ |
| 1709 | enet_rcv(dev, emac_isr); |
| 1710 | |
| 1711 | /* clear MAL interrupt status bits */ |
| 1712 | mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB); |
| 1713 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1714 | /* indicate that we serviced an interrupt */ |
| 1715 | serviced = 1; |
| 1716 | rc = 0; |
| 1717 | } |
| 1718 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1719 | } while (serviced); |
| 1720 | |
| 1721 | return (rc); |
| 1722 | } |
| 1723 | |
| 1724 | /*-----------------------------------------------------------------------------+ |
| 1725 | * MAL Error Routine |
| 1726 | *-----------------------------------------------------------------------------*/ |
| 1727 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 1728 | unsigned long uic, unsigned long maldef, |
| 1729 | unsigned long mal_errr) |
| 1730 | { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1731 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1732 | |
| 1733 | mtdcr (malesr, isr); /* clear interrupt */ |
| 1734 | |
| 1735 | /* clear DE interrupt */ |
| 1736 | mtdcr (maltxdeir, 0xC0000000); |
| 1737 | mtdcr (malrxdeir, 0x80000000); |
| 1738 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1739 | #ifdef INFO_4XX_ENET |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 1740 | printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1741 | #endif |
| 1742 | |
| 1743 | eth_init (hw_p->bis); /* start again... */ |
| 1744 | } |
| 1745 | |
| 1746 | /*-----------------------------------------------------------------------------+ |
| 1747 | * EMAC Error Routine |
| 1748 | *-----------------------------------------------------------------------------*/ |
| 1749 | static void emac_err (struct eth_device *dev, unsigned long isr) |
| 1750 | { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1751 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1752 | |
| 1753 | printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr); |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 1754 | out_be32((void *)EMAC_ISR + hw_p->hw_addr, isr); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | /*-----------------------------------------------------------------------------+ |
| 1758 | * enet_rcv() handles the ethernet receive data |
| 1759 | *-----------------------------------------------------------------------------*/ |
| 1760 | static void enet_rcv (struct eth_device *dev, unsigned long malisr) |
| 1761 | { |
| 1762 | struct enet_frame *ef_ptr; |
| 1763 | unsigned long data_len; |
| 1764 | unsigned long rx_eob_isr; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1765 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1766 | |
| 1767 | int handled = 0; |
| 1768 | int i; |
| 1769 | int loop_count = 0; |
| 1770 | |
| 1771 | rx_eob_isr = mfdcr (malrxeobisr); |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1772 | if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) { |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1773 | /* clear EOB */ |
| 1774 | mtdcr (malrxeobisr, rx_eob_isr); |
| 1775 | |
| 1776 | /* EMAC RX done */ |
| 1777 | while (1) { /* do all */ |
| 1778 | i = hw_p->rx_slot; |
| 1779 | |
| 1780 | if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl) |
| 1781 | || (loop_count >= NUM_RX_BUFF)) |
| 1782 | break; |
Stefan Roese | a2e1c70 | 2007-07-12 16:32:08 +0200 | [diff] [blame] | 1783 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1784 | loop_count++; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1785 | handled++; |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1786 | data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1787 | if (data_len) { |
| 1788 | if (data_len > ENET_MAX_MTU) /* Check len */ |
| 1789 | data_len = 0; |
| 1790 | else { |
| 1791 | if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */ |
| 1792 | data_len = 0; |
| 1793 | hw_p->stats.rx_err_log[hw_p-> |
| 1794 | rx_err_index] |
| 1795 | = hw_p->rx[i].ctrl; |
| 1796 | hw_p->rx_err_index++; |
| 1797 | if (hw_p->rx_err_index == |
| 1798 | MAX_ERR_LOG) |
| 1799 | hw_p->rx_err_index = |
| 1800 | 0; |
wdenk | fc1cfcd | 2004-04-25 15:41:35 +0000 | [diff] [blame] | 1801 | } /* emac_erros */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1802 | } /* data_len < max mtu */ |
wdenk | fc1cfcd | 2004-04-25 15:41:35 +0000 | [diff] [blame] | 1803 | } /* if data_len */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1804 | if (!data_len) { /* no data */ |
| 1805 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */ |
| 1806 | |
| 1807 | hw_p->stats.data_len_err++; /* Error at Rx */ |
| 1808 | } |
| 1809 | |
| 1810 | /* !data_len */ |
| 1811 | /* AS.HARNOIS */ |
| 1812 | /* Check if user has already eaten buffer */ |
| 1813 | /* if not => ERROR */ |
| 1814 | else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) { |
| 1815 | if (hw_p->is_receiving) |
| 1816 | printf ("ERROR : Receive buffers are full!\n"); |
| 1817 | break; |
| 1818 | } else { |
| 1819 | hw_p->stats.rx_frames++; |
| 1820 | hw_p->stats.rx += data_len; |
| 1821 | ef_ptr = (struct enet_frame *) hw_p->rx[i]. |
| 1822 | data_ptr; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1823 | #ifdef INFO_4XX_ENET |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1824 | hw_p->stats.pkts_rx++; |
| 1825 | #endif |
| 1826 | /* AS.HARNOIS |
| 1827 | * use ring buffer |
| 1828 | */ |
| 1829 | hw_p->rx_ready[hw_p->rx_i_index] = i; |
| 1830 | hw_p->rx_i_index++; |
| 1831 | if (NUM_RX_BUFF == hw_p->rx_i_index) |
| 1832 | hw_p->rx_i_index = 0; |
| 1833 | |
Stefan Roese | a2e1c70 | 2007-07-12 16:32:08 +0200 | [diff] [blame] | 1834 | hw_p->rx_slot++; |
| 1835 | if (NUM_RX_BUFF == hw_p->rx_slot) |
| 1836 | hw_p->rx_slot = 0; |
| 1837 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1838 | /* AS.HARNOIS |
| 1839 | * free receive buffer only when |
| 1840 | * buffer has been handled (eth_rx) |
| 1841 | rx[i].ctrl |= MAL_RX_CTRL_EMPTY; |
| 1842 | */ |
| 1843 | } /* if data_len */ |
| 1844 | } /* while */ |
| 1845 | } /* if EMACK_RXCHL */ |
| 1846 | } |
| 1847 | |
| 1848 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1849 | static int ppc_4xx_eth_rx (struct eth_device *dev) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1850 | { |
| 1851 | int length; |
| 1852 | int user_index; |
| 1853 | unsigned long msr; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1854 | EMAC_4XX_HW_PST hw_p = dev->priv; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1855 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 1856 | hw_p->is_receiving = 1; /* tell driver */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1857 | |
| 1858 | for (;;) { |
| 1859 | /* AS.HARNOIS |
| 1860 | * use ring buffer and |
| 1861 | * get index from rx buffer desciptor queue |
| 1862 | */ |
| 1863 | user_index = hw_p->rx_ready[hw_p->rx_u_index]; |
| 1864 | if (user_index == -1) { |
| 1865 | length = -1; |
| 1866 | break; /* nothing received - leave for() loop */ |
| 1867 | } |
| 1868 | |
| 1869 | msr = mfmsr (); |
| 1870 | mtmsr (msr & ~(MSR_EE)); |
| 1871 | |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 1872 | length = hw_p->rx[user_index].data_len & 0x0fff; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1873 | |
| 1874 | /* Pass the packet up to the protocol layers. */ |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 1875 | /* NetReceive(NetRxPackets[rxIdx], length - 4); */ |
| 1876 | /* NetReceive(NetRxPackets[i], length); */ |
Stefan Roese | ff768cb | 2007-10-31 18:01:24 +0100 | [diff] [blame] | 1877 | invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr, |
| 1878 | (u32)hw_p->rx[user_index].data_ptr + |
Matthias Fuchs | ba79fde | 2007-12-14 11:19:56 +0100 | [diff] [blame] | 1879 | length - 4); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1880 | NetReceive (NetRxPackets[user_index], length - 4); |
| 1881 | /* Free Recv Buffer */ |
| 1882 | hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY; |
| 1883 | /* Free rx buffer descriptor queue */ |
| 1884 | hw_p->rx_ready[hw_p->rx_u_index] = -1; |
| 1885 | hw_p->rx_u_index++; |
| 1886 | if (NUM_RX_BUFF == hw_p->rx_u_index) |
| 1887 | hw_p->rx_u_index = 0; |
| 1888 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1889 | #ifdef INFO_4XX_ENET |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1890 | hw_p->stats.pkts_handled++; |
| 1891 | #endif |
| 1892 | |
| 1893 | mtmsr (msr); /* Enable IRQ's */ |
| 1894 | } |
| 1895 | |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 1896 | hw_p->is_receiving = 0; /* tell driver */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1897 | |
| 1898 | return length; |
| 1899 | } |
| 1900 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1901 | int ppc_4xx_eth_initialize (bd_t * bis) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1902 | { |
| 1903 | static int virgin = 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1904 | struct eth_device *dev; |
| 1905 | int eth_num = 0; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1906 | EMAC_4XX_HW_PST hw = NULL; |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1907 | u8 ethaddr[4 + CONFIG_EMAC_NR_START][6]; |
| 1908 | u32 hw_addr[4]; |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 1909 | u32 mal_ier; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1910 | |
Stefan Roese | 846b0dd | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 1911 | #if defined(CONFIG_440GX) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1912 | unsigned long pfc1; |
| 1913 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1914 | mfsdr (sdr_pfc1, pfc1); |
| 1915 | pfc1 &= ~(0x01e00000); |
| 1916 | pfc1 |= 0x01200000; |
| 1917 | mtsdr (sdr_pfc1, pfc1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1918 | #endif |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1919 | |
| 1920 | /* first clear all mac-addresses */ |
| 1921 | for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) |
| 1922 | memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6); |
| 1923 | |
| 1924 | for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) { |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 1925 | int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START; |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1926 | switch (eth_num) { |
| 1927 | default: /* fall through */ |
| 1928 | case 0: |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 1929 | eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]); |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1930 | hw_addr[eth_num] = 0x0; |
| 1931 | break; |
| 1932 | #ifdef CONFIG_HAS_ETH1 |
| 1933 | case 1: |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 1934 | eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]); |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1935 | hw_addr[eth_num] = 0x100; |
| 1936 | break; |
| 1937 | #endif |
| 1938 | #ifdef CONFIG_HAS_ETH2 |
| 1939 | case 2: |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 1940 | eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]); |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1941 | #if defined(CONFIG_460GT) |
| 1942 | hw_addr[eth_num] = 0x300; |
| 1943 | #else |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1944 | hw_addr[eth_num] = 0x400; |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1945 | #endif |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1946 | break; |
| 1947 | #endif |
| 1948 | #ifdef CONFIG_HAS_ETH3 |
| 1949 | case 3: |
Mike Frysinger | d3f8714 | 2009-02-11 19:01:26 -0500 | [diff] [blame] | 1950 | eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]); |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1951 | #if defined(CONFIG_460GT) |
| 1952 | hw_addr[eth_num] = 0x400; |
| 1953 | #else |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1954 | hw_addr[eth_num] = 0x600; |
Stefan Roese | 4c9e855 | 2008-03-19 16:20:49 +0100 | [diff] [blame] | 1955 | #endif |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1956 | break; |
| 1957 | #endif |
| 1958 | } |
| 1959 | } |
| 1960 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1961 | /* set phy num and mode */ |
| 1962 | bis->bi_phynum[0] = CONFIG_PHY_ADDR; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 1963 | bis->bi_phymode[0] = 0; |
| 1964 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1965 | #if defined(CONFIG_PHY1_ADDR) |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1966 | bis->bi_phynum[1] = CONFIG_PHY1_ADDR; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 1967 | bis->bi_phymode[1] = 0; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1968 | #endif |
Stefan Roese | 846b0dd | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 1969 | #if defined(CONFIG_440GX) |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1970 | bis->bi_phynum[2] = CONFIG_PHY2_ADDR; |
| 1971 | bis->bi_phynum[3] = CONFIG_PHY3_ADDR; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1972 | bis->bi_phymode[2] = 2; |
| 1973 | bis->bi_phymode[3] = 2; |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1974 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1975 | |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 1976 | #if defined(CONFIG_440GX) || \ |
| 1977 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 1978 | defined(CONFIG_405EX) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1979 | ppc_4xx_eth_setup_bridge(0, bis); |
wdenk | a06752e | 2004-09-29 22:43:59 +0000 | [diff] [blame] | 1980 | #endif |
| 1981 | |
Stefan Roese | 1e25f95 | 2005-10-20 16:34:28 +0200 | [diff] [blame] | 1982 | for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) { |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 1983 | /* |
| 1984 | * See if we can actually bring up the interface, |
| 1985 | * otherwise, skip it |
| 1986 | */ |
| 1987 | if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) { |
| 1988 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
| 1989 | continue; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | /* Allocate device structure */ |
| 1993 | dev = (struct eth_device *) malloc (sizeof (*dev)); |
| 1994 | if (dev == NULL) { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 1995 | printf ("ppc_4xx_eth_initialize: " |
wdenk | 3f85ce2 | 2004-02-23 16:11:30 +0000 | [diff] [blame] | 1996 | "Cannot allocate eth_device %d\n", eth_num); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1997 | return (-1); |
| 1998 | } |
wdenk | b2532ef | 2005-06-20 10:17:34 +0000 | [diff] [blame] | 1999 | memset(dev, 0, sizeof(*dev)); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2000 | |
| 2001 | /* Allocate our private use data */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 2002 | hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw)); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2003 | if (hw == NULL) { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 2004 | printf ("ppc_4xx_eth_initialize: " |
wdenk | 3f85ce2 | 2004-02-23 16:11:30 +0000 | [diff] [blame] | 2005 | "Cannot allocate private hw data for eth_device %d", |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2006 | eth_num); |
| 2007 | free (dev); |
| 2008 | return (-1); |
| 2009 | } |
wdenk | b2532ef | 2005-06-20 10:17:34 +0000 | [diff] [blame] | 2010 | memset(hw, 0, sizeof(*hw)); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2011 | |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 2012 | hw->hw_addr = hw_addr[eth_num]; |
| 2013 | memcpy (dev->enetaddr, ethaddr[eth_num], 6); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2014 | hw->devnum = eth_num; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 2015 | hw->print_speed = 1; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2016 | |
Stefan Roese | 5fb692c | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 2017 | sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2018 | dev->priv = (void *) hw; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 2019 | dev->init = ppc_4xx_eth_init; |
| 2020 | dev->halt = ppc_4xx_eth_halt; |
| 2021 | dev->send = ppc_4xx_eth_send; |
| 2022 | dev->recv = ppc_4xx_eth_rx; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2023 | |
| 2024 | if (0 == virgin) { |
| 2025 | /* set the MAL IER ??? names may change with new spec ??? */ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 2026 | #if defined(CONFIG_440SPE) || \ |
| 2027 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8ac41e3 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 2028 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 2029 | defined(CONFIG_405EX) |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 2030 | mal_ier = |
| 2031 | MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE | |
| 2032 | MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ; |
| 2033 | #else |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2034 | mal_ier = |
| 2035 | MAL_IER_DE | MAL_IER_NE | MAL_IER_TE | |
| 2036 | MAL_IER_OPBE | MAL_IER_PLBE; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 2037 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2038 | mtdcr (malesr, 0xffffffff); /* clear pending interrupts */ |
| 2039 | mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */ |
| 2040 | mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */ |
| 2041 | mtdcr (malier, mal_ier); |
| 2042 | |
| 2043 | /* install MAL interrupt handler */ |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 2044 | irq_install_handler (VECNUM_MAL_SERR, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2045 | (interrupt_handler_t *) enetInt, |
| 2046 | dev); |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 2047 | irq_install_handler (VECNUM_MAL_TXEOB, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2048 | (interrupt_handler_t *) enetInt, |
| 2049 | dev); |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 2050 | irq_install_handler (VECNUM_MAL_RXEOB, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2051 | (interrupt_handler_t *) enetInt, |
| 2052 | dev); |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 2053 | irq_install_handler (VECNUM_MAL_TXDE, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2054 | (interrupt_handler_t *) enetInt, |
| 2055 | dev); |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 2056 | irq_install_handler (VECNUM_MAL_RXDE, |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2057 | (interrupt_handler_t *) enetInt, |
| 2058 | dev); |
| 2059 | virgin = 1; |
| 2060 | } |
| 2061 | |
| 2062 | eth_register (dev); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 2063 | |
Jon Loeliger | 3a1ed1e | 2007-07-09 18:57:22 -0500 | [diff] [blame] | 2064 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 2065 | miiphy_register (dev->name, |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 2066 | emac4xx_miiphy_read, emac4xx_miiphy_write); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 2067 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2068 | } /* end for each supported device */ |
Stefan Roese | 802b769 | 2008-01-08 18:39:30 +0100 | [diff] [blame] | 2069 | |
| 2070 | return 0; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 2071 | } |