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