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