wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------+ |
| 2 | * |
| 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. |
| 9 | * |
| 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. |
| 13 | * |
| 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. |
| 17 | * |
| 18 | * COPYRIGHT I B M CORPORATION 1995 |
| 19 | * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M |
| 20 | *-----------------------------------------------------------------------------*/ |
| 21 | /*-----------------------------------------------------------------------------+ |
| 22 | * |
| 23 | * File Name: enetemac.c |
| 24 | * |
| 25 | * Function: Device driver for the ethernet EMAC3 macro on the 405GP. |
| 26 | * |
| 27 | * Author: Mark Wisner |
| 28 | * |
| 29 | * Change Activity- |
| 30 | * |
| 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). |
| 70 | *-----------------------------------------------------------------------------* |
| 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 | *-----------------------------------------------------------------------------*/ |
| 76 | |
| 77 | #include <config.h> |
| 78 | #if defined(CONFIG_440) && defined(CONFIG_NET_MULTI) |
| 79 | |
| 80 | #include <common.h> |
| 81 | #include <net.h> |
| 82 | #include <asm/processor.h> |
| 83 | #include <ppc440.h> |
| 84 | #include <commproc.h> |
| 85 | #include <440gx_enet.h> |
| 86 | #include <405_mal.h> |
| 87 | #include <miiphy.h> |
| 88 | #include <malloc.h> |
| 89 | #include "vecnum.h" |
| 90 | |
| 91 | |
| 92 | #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */ |
| 93 | #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */ |
| 94 | |
| 95 | |
| 96 | /* Ethernet Transmit and Receive Buffers */ |
| 97 | /* AS.HARNOIS |
| 98 | * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from |
| 99 | * PKTSIZE and PKTSIZE_ALIGN (include/net.h) |
| 100 | */ |
| 101 | #define ENET_MAX_MTU PKTSIZE |
| 102 | #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN |
| 103 | |
| 104 | |
| 105 | /* define the number of channels implemented */ |
| 106 | #define EMAC_RXCHL EMAC_NUM_DEV |
| 107 | #define EMAC_TXCHL EMAC_NUM_DEV |
| 108 | |
| 109 | /*-----------------------------------------------------------------------------+ |
| 110 | * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal |
| 111 | * Interrupt Controller). |
| 112 | *-----------------------------------------------------------------------------*/ |
| 113 | #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE) |
| 114 | #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR) |
| 115 | #define EMAC_UIC_DEF UIC_ENET |
| 116 | |
| 117 | #undef INFO_440_ENET |
| 118 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 119 | #define BI_PHYMODE_NONE 0 |
| 120 | #define BI_PHYMODE_ZMII 1 |
| 121 | #define BI_PHYMODE_RGMII 2 |
| 122 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 123 | /*-----------------------------------------------------------------------------+ |
| 124 | * Global variables. TX and RX descriptors and buffers. |
| 125 | *-----------------------------------------------------------------------------*/ |
| 126 | /* IER globals */ |
| 127 | static uint32_t mal_ier; |
| 128 | |
| 129 | /*-----------------------------------------------------------------------------+ |
| 130 | * Prototypes and externals. |
| 131 | *-----------------------------------------------------------------------------*/ |
| 132 | static void enet_rcv (struct eth_device *dev, unsigned long malisr); |
| 133 | |
| 134 | int enetInt (struct eth_device *dev); |
| 135 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 136 | unsigned long uic, unsigned long maldef, |
| 137 | unsigned long mal_errr); |
| 138 | static void emac_err (struct eth_device *dev, unsigned long isr); |
| 139 | |
| 140 | /*-----------------------------------------------------------------------------+ |
| 141 | | ppc_440x_eth_halt |
| 142 | | Disable MAL channel, and EMACn |
| 143 | | |
| 144 | | |
| 145 | +-----------------------------------------------------------------------------*/ |
| 146 | static void ppc_440x_eth_halt (struct eth_device *dev) |
| 147 | { |
| 148 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 149 | uint32_t failsafe = 10000; |
| 150 | |
| 151 | out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */ |
| 152 | |
| 153 | /* 1st reset MAL channel */ |
| 154 | /* Note: writing a 0 to a channel has no effect */ |
| 155 | mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum)); |
| 156 | mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum)); |
| 157 | |
| 158 | /* wait for reset */ |
| 159 | while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) { |
| 160 | udelay (1000); /* Delay 1 MS so as not to hammer the register */ |
| 161 | failsafe--; |
| 162 | if (failsafe == 0) |
| 163 | break; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /* EMAC RESET */ |
| 168 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
| 169 | |
| 170 | hw_p->print_speed = 1; /* print speed message again next time */ |
| 171 | |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | extern int phy_setup_aneg (unsigned char addr); |
| 176 | extern int miiphy_reset (unsigned char addr); |
| 177 | |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 178 | #if defined (CONFIG_440_GX) |
| 179 | int ppc_440x_eth_setup_bridge(int devnum, bd_t * bis) |
| 180 | { |
| 181 | unsigned long pfc1; |
| 182 | unsigned long zmiifer; |
| 183 | unsigned long rmiifer; |
| 184 | |
| 185 | mfsdr(sdr_pfc1, pfc1); |
| 186 | pfc1 = SDR0_PFC1_EPS_DECODE(pfc1); |
| 187 | |
| 188 | zmiifer = 0; |
| 189 | rmiifer = 0; |
| 190 | |
| 191 | switch (pfc1) { |
| 192 | case 1: |
| 193 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 194 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1); |
| 195 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2); |
| 196 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3); |
| 197 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 198 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 199 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 200 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 201 | break; |
| 202 | case 2: |
| 203 | zmiifer = ZMII_FER_SMII << ZMII_FER_V(0); |
| 204 | zmiifer = ZMII_FER_SMII << ZMII_FER_V(1); |
| 205 | zmiifer = ZMII_FER_SMII << ZMII_FER_V(2); |
| 206 | zmiifer = ZMII_FER_SMII << ZMII_FER_V(3); |
| 207 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 208 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 209 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 210 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 211 | break; |
| 212 | case 3: |
| 213 | zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0); |
| 214 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 215 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 216 | bis->bi_phymode[1] = BI_PHYMODE_NONE; |
| 217 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 218 | bis->bi_phymode[3] = BI_PHYMODE_NONE; |
| 219 | break; |
| 220 | case 4: |
| 221 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0); |
| 222 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1); |
| 223 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2); |
| 224 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3); |
| 225 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 226 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 227 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 228 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 229 | break; |
| 230 | case 5: |
| 231 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0); |
| 232 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1); |
| 233 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2); |
| 234 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 235 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 236 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 237 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 238 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 239 | break; |
| 240 | case 6: |
| 241 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0); |
| 242 | zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1); |
| 243 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2); |
| 244 | rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3); |
| 245 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 246 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 247 | bis->bi_phymode[2] = BI_PHYMODE_RGMII; |
| 248 | bis->bi_phymode[3] = BI_PHYMODE_RGMII; |
| 249 | break; |
| 250 | case 0: |
| 251 | default: |
| 252 | zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum); |
| 253 | rmiifer = 0x0; |
| 254 | bis->bi_phymode[0] = BI_PHYMODE_ZMII; |
| 255 | bis->bi_phymode[1] = BI_PHYMODE_ZMII; |
| 256 | bis->bi_phymode[2] = BI_PHYMODE_ZMII; |
| 257 | bis->bi_phymode[3] = BI_PHYMODE_ZMII; |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | /* Ensure we setup mdio for this devnum and ONLY this devnum */ |
| 262 | zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum); |
| 263 | |
| 264 | out32 (ZMII_FER, zmiifer); |
| 265 | out32 (RGMII_FER, rmiifer); |
| 266 | |
| 267 | return ((int)pfc1); |
| 268 | |
| 269 | } |
| 270 | #endif |
| 271 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 272 | static int ppc_440x_eth_init (struct eth_device *dev, bd_t * bis) |
| 273 | { |
| 274 | int i; |
| 275 | unsigned long reg; |
| 276 | unsigned long msr; |
| 277 | unsigned long speed; |
| 278 | unsigned long duplex; |
| 279 | unsigned long failsafe; |
| 280 | unsigned mode_reg; |
| 281 | unsigned short devnum; |
| 282 | unsigned short reg_short; |
| 283 | sys_info_t sysinfo; |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 284 | int ethgroup; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 285 | |
| 286 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 287 | |
| 288 | /* before doing anything, figure out if we have a MAC address */ |
| 289 | /* if not, bail */ |
| 290 | if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) |
| 291 | return -1; |
| 292 | |
| 293 | /* Need to get the OPB frequency so we can access the PHY */ |
| 294 | get_sys_info (&sysinfo); |
| 295 | |
| 296 | |
| 297 | msr = mfmsr (); |
| 298 | mtmsr (msr & ~(MSR_EE)); /* disable interrupts */ |
| 299 | |
| 300 | devnum = hw_p->devnum; |
| 301 | |
| 302 | #ifdef INFO_440_ENET |
| 303 | /* AS.HARNOIS |
| 304 | * We should have : |
| 305 | * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX |
| 306 | * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it |
| 307 | * is possible that new packets (without relationship with |
| 308 | * current transfer) have got the time to arrived before |
| 309 | * netloop calls eth_halt |
| 310 | */ |
| 311 | printf ("About preceeding transfer (eth%d):\n" |
| 312 | "- Sent packet number %d\n" |
| 313 | "- Received packet number %d\n" |
| 314 | "- Handled packet number %d\n", |
| 315 | hw_p->devnum, |
| 316 | hw_p->stats.pkts_tx, |
| 317 | hw_p->stats.pkts_rx, hw_p->stats.pkts_handled); |
| 318 | |
| 319 | hw_p->stats.pkts_tx = 0; |
| 320 | hw_p->stats.pkts_rx = 0; |
| 321 | hw_p->stats.pkts_handled = 0; |
| 322 | #endif |
| 323 | |
| 324 | /* MAL Channel RESET */ |
| 325 | /* 1st reset MAL channel */ |
| 326 | /* Note: writing a 0 to a channel has no effect */ |
| 327 | mtdcr (maltxcarr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 328 | mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 329 | |
| 330 | /* wait for reset */ |
| 331 | /* TBS: should have udelay and failsafe here */ |
| 332 | failsafe = 10000; |
| 333 | /* wait for reset */ |
| 334 | while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) { |
| 335 | udelay (1000); /* Delay 1 MS so as not to hammer the register */ |
| 336 | failsafe--; |
| 337 | if (failsafe == 0) |
| 338 | break; |
| 339 | |
| 340 | } |
| 341 | |
| 342 | hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */ |
| 343 | hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */ |
| 344 | |
| 345 | hw_p->rx_slot = 0; /* MAL Receive Slot */ |
| 346 | hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */ |
| 347 | hw_p->rx_u_index = 0; /* Receive User Queue Index */ |
| 348 | |
| 349 | hw_p->tx_slot = 0; /* MAL Transmit Slot */ |
| 350 | hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */ |
| 351 | hw_p->tx_u_index = 0; /* Transmit User Queue Index */ |
| 352 | |
| 353 | /* set RMII mode */ |
| 354 | /* NOTE: 440GX spec states that mode is mutually exclusive */ |
| 355 | /* NOTE: Therefore, disable all other EMACS, since we handle */ |
| 356 | /* NOTE: only one emac at a time */ |
| 357 | reg = 0; |
| 358 | out32 (ZMII_FER, 0); |
| 359 | udelay (100); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 360 | |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 361 | #if defined(CONFIG_440_GX) |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 362 | ethgroup = ppc_440x_eth_setup_bridge(devnum, bis); |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 363 | #else |
| 364 | if ((devnum == 0) || (devnum == 1)) { |
| 365 | out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum)); |
| 366 | } |
| 367 | else { /* ((devnum == 2) || (devnum == 3)) */ |
| 368 | out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum)); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 369 | out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) | |
| 370 | (RGMII_FER_RGMII << RGMII_FER_V (3)))); |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 371 | } |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 372 | |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 373 | #endif |
| 374 | out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum)); |
| 375 | __asm__ volatile ("eieio"); |
| 376 | |
| 377 | /* reset emac so we have access to the phy */ |
| 378 | |
| 379 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 380 | __asm__ volatile ("eieio"); |
| 381 | |
| 382 | failsafe = 1000; |
| 383 | while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) { |
| 384 | udelay (1000); |
| 385 | failsafe--; |
| 386 | } |
| 387 | |
| 388 | /* Whack the M1 register */ |
| 389 | mode_reg = 0x0; |
| 390 | mode_reg &= ~0x00000038; |
| 391 | if (sysinfo.freqOPB <= 50000000); |
| 392 | else if (sysinfo.freqOPB <= 66666667) |
| 393 | mode_reg |= EMAC_M1_OBCI_66; |
| 394 | else if (sysinfo.freqOPB <= 83333333) |
| 395 | mode_reg |= EMAC_M1_OBCI_83; |
| 396 | else if (sysinfo.freqOPB <= 100000000) |
| 397 | mode_reg |= EMAC_M1_OBCI_100; |
| 398 | else |
| 399 | mode_reg |= EMAC_M1_OBCI_GT100; |
| 400 | |
| 401 | out32 (EMAC_M1 + hw_p->hw_addr, mode_reg); |
| 402 | |
| 403 | |
| 404 | /* wait for PHY to complete auto negotiation */ |
| 405 | reg_short = 0; |
| 406 | #ifndef CONFIG_CS8952_PHY |
| 407 | switch (devnum) { |
| 408 | case 0: |
| 409 | reg = CONFIG_PHY_ADDR; |
| 410 | break; |
| 411 | case 1: |
| 412 | reg = CONFIG_PHY1_ADDR; |
| 413 | break; |
| 414 | #if defined (CONFIG_440_GX) |
| 415 | case 2: |
| 416 | reg = CONFIG_PHY2_ADDR; |
| 417 | break; |
| 418 | case 3: |
| 419 | reg = CONFIG_PHY3_ADDR; |
| 420 | break; |
| 421 | #endif |
| 422 | default: |
| 423 | reg = CONFIG_PHY_ADDR; |
| 424 | break; |
| 425 | } |
| 426 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 427 | bis->bi_phynum[devnum] = reg; |
| 428 | |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 429 | /* Reset the phy */ |
| 430 | miiphy_reset (reg); |
| 431 | |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 432 | #if defined(CONFIG_440_GX) |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 433 | #if defined(CONFIG_CIS8201_PHY) |
| 434 | /* |
| 435 | * Cicada 8201 PHY needs to have an extended register whacked |
| 436 | * for RGMII mode. |
| 437 | */ |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 438 | if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) { |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 439 | miiphy_write (reg, 23, 0x1200); |
| 440 | } |
| 441 | #endif |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 442 | #endif |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 443 | /* Start/Restart autonegotiation */ |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 444 | phy_setup_aneg (reg); |
| 445 | udelay (1000); |
| 446 | |
| 447 | miiphy_read (reg, PHY_BMSR, ®_short); |
| 448 | |
| 449 | /* |
wdenk | 0e6d798 | 2004-03-14 00:07:33 +0000 | [diff] [blame] | 450 | * Wait if PHY is capable of autonegotiation and autonegotiation is not complete |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 451 | */ |
| 452 | if ((reg_short & PHY_BMSR_AUTN_ABLE) |
| 453 | && !(reg_short & PHY_BMSR_AUTN_COMP)) { |
| 454 | puts ("Waiting for PHY auto negotiation to complete"); |
| 455 | i = 0; |
| 456 | while (!(reg_short & PHY_BMSR_AUTN_COMP)) { |
| 457 | /* |
| 458 | * Timeout reached ? |
| 459 | */ |
| 460 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 461 | puts (" TIMEOUT !\n"); |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | if ((i++ % 1000) == 0) { |
| 466 | putc ('.'); |
| 467 | } |
| 468 | udelay (1000); /* 1 ms */ |
| 469 | miiphy_read (reg, PHY_BMSR, ®_short); |
| 470 | |
| 471 | } |
| 472 | puts (" done\n"); |
| 473 | udelay (500000); /* another 500 ms (results in faster booting) */ |
| 474 | } |
| 475 | #endif |
| 476 | speed = miiphy_speed (reg); |
| 477 | duplex = miiphy_duplex (reg); |
| 478 | |
| 479 | if (hw_p->print_speed) { |
| 480 | hw_p->print_speed = 0; |
| 481 | printf ("ENET Speed is %d Mbps - %s duplex connection\n", |
| 482 | (int) speed, (duplex == HALF) ? "HALF" : "FULL"); |
| 483 | } |
| 484 | |
| 485 | /* Set ZMII/RGMII speed according to the phy link speed */ |
| 486 | reg = in32 (ZMII_SSR); |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 487 | if ( (speed == 100) || (speed == 1000) ) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 488 | out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum))); |
| 489 | else |
| 490 | out32 (ZMII_SSR, |
| 491 | reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum)))); |
| 492 | |
| 493 | if ((devnum == 2) || (devnum == 3)) { |
| 494 | if (speed == 1000) |
| 495 | reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum)); |
| 496 | else if (speed == 100) |
| 497 | reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum)); |
| 498 | else |
| 499 | reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum)); |
| 500 | |
| 501 | out32 (RGMII_SSR, reg); |
| 502 | } |
| 503 | |
| 504 | /* set the Mal configuration reg */ |
| 505 | /* Errata 1.12: MAL_1 -- Disable MAL bursting */ |
| 506 | if (get_pvr () == PVR_440GP_RB) |
| 507 | mtdcr (malmcr, |
| 508 | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT); |
| 509 | else |
| 510 | mtdcr (malmcr, |
| 511 | MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | |
| 512 | MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000); |
| 513 | |
| 514 | /* Free "old" buffers */ |
| 515 | if (hw_p->alloc_tx_buf) |
| 516 | free (hw_p->alloc_tx_buf); |
| 517 | if (hw_p->alloc_rx_buf) |
| 518 | free (hw_p->alloc_rx_buf); |
| 519 | |
| 520 | /* |
| 521 | * Malloc MAL buffer desciptors, make sure they are |
| 522 | * aligned on cache line boundary size |
| 523 | * (401/403/IOP480 = 16, 405 = 32) |
| 524 | * and doesn't cross cache block boundaries. |
| 525 | */ |
| 526 | hw_p->alloc_tx_buf = |
| 527 | (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) + |
| 528 | ((2 * CFG_CACHELINE_SIZE) - 2)); |
| 529 | if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) { |
| 530 | hw_p->tx = |
| 531 | (mal_desc_t *) ((int) hw_p->alloc_tx_buf + |
| 532 | CFG_CACHELINE_SIZE - |
| 533 | ((int) hw_p-> |
| 534 | alloc_tx_buf & CACHELINE_MASK)); |
| 535 | } else { |
| 536 | hw_p->tx = hw_p->alloc_tx_buf; |
| 537 | } |
| 538 | |
| 539 | hw_p->alloc_rx_buf = |
| 540 | (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) + |
| 541 | ((2 * CFG_CACHELINE_SIZE) - 2)); |
| 542 | if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) { |
| 543 | hw_p->rx = |
| 544 | (mal_desc_t *) ((int) hw_p->alloc_rx_buf + |
| 545 | CFG_CACHELINE_SIZE - |
| 546 | ((int) hw_p-> |
| 547 | alloc_rx_buf & CACHELINE_MASK)); |
| 548 | } else { |
| 549 | hw_p->rx = hw_p->alloc_rx_buf; |
| 550 | } |
| 551 | |
| 552 | for (i = 0; i < NUM_TX_BUFF; i++) { |
| 553 | hw_p->tx[i].ctrl = 0; |
| 554 | hw_p->tx[i].data_len = 0; |
| 555 | if (hw_p->first_init == 0) |
| 556 | hw_p->txbuf_ptr = |
| 557 | (char *) malloc (ENET_MAX_MTU_ALIGNED); |
| 558 | hw_p->tx[i].data_ptr = hw_p->txbuf_ptr; |
| 559 | if ((NUM_TX_BUFF - 1) == i) |
| 560 | hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP; |
| 561 | hw_p->tx_run[i] = -1; |
| 562 | #if 0 |
| 563 | printf ("TX_BUFF %d @ 0x%08lx\n", i, |
| 564 | (ulong) hw_p->tx[i].data_ptr); |
| 565 | #endif |
| 566 | } |
| 567 | |
| 568 | for (i = 0; i < NUM_RX_BUFF; i++) { |
| 569 | hw_p->rx[i].ctrl = 0; |
| 570 | hw_p->rx[i].data_len = 0; |
| 571 | /* rx[i].data_ptr = (char *) &rx_buff[i]; */ |
| 572 | hw_p->rx[i].data_ptr = (char *) NetRxPackets[i]; |
| 573 | if ((NUM_RX_BUFF - 1) == i) |
| 574 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP; |
| 575 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR; |
| 576 | hw_p->rx_ready[i] = -1; |
| 577 | #if 0 |
| 578 | printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr); |
| 579 | #endif |
| 580 | } |
| 581 | |
| 582 | reg = 0x00000000; |
| 583 | |
| 584 | reg |= dev->enetaddr[0]; /* set high address */ |
| 585 | reg = reg << 8; |
| 586 | reg |= dev->enetaddr[1]; |
| 587 | |
| 588 | out32 (EMAC_IAH + hw_p->hw_addr, reg); |
| 589 | |
| 590 | reg = 0x00000000; |
| 591 | reg |= dev->enetaddr[2]; /* set low address */ |
| 592 | reg = reg << 8; |
| 593 | reg |= dev->enetaddr[3]; |
| 594 | reg = reg << 8; |
| 595 | reg |= dev->enetaddr[4]; |
| 596 | reg = reg << 8; |
| 597 | reg |= dev->enetaddr[5]; |
| 598 | |
| 599 | out32 (EMAC_IAL + hw_p->hw_addr, reg); |
| 600 | |
| 601 | switch (devnum) { |
| 602 | case 1: |
| 603 | /* setup MAL tx & rx channel pointers */ |
| 604 | mtdcr (maltxbattr, 0x0); |
| 605 | mtdcr (maltxctp1r, hw_p->tx); |
| 606 | mtdcr (malrxbattr, 0x0); |
| 607 | mtdcr (malrxctp1r, hw_p->rx); |
| 608 | /* set RX buffer size */ |
| 609 | mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16); |
| 610 | break; |
| 611 | #if defined (CONFIG_440_GX) |
| 612 | case 2: |
| 613 | /* setup MAL tx & rx channel pointers */ |
| 614 | mtdcr (maltxbattr, 0x0); |
| 615 | mtdcr (maltxctp2r, hw_p->tx); |
| 616 | mtdcr (malrxbattr, 0x0); |
| 617 | mtdcr (malrxctp2r, hw_p->rx); |
| 618 | /* set RX buffer size */ |
| 619 | mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16); |
| 620 | break; |
| 621 | case 3: |
| 622 | /* setup MAL tx & rx channel pointers */ |
| 623 | mtdcr (maltxbattr, 0x0); |
| 624 | mtdcr (maltxctp3r, hw_p->tx); |
| 625 | mtdcr (malrxbattr, 0x0); |
| 626 | mtdcr (malrxctp3r, hw_p->rx); |
| 627 | /* set RX buffer size */ |
| 628 | mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16); |
| 629 | break; |
| 630 | #endif /*CONFIG_440_GX */ |
| 631 | case 0: |
| 632 | default: |
| 633 | /* setup MAL tx & rx channel pointers */ |
| 634 | mtdcr (maltxbattr, 0x0); |
| 635 | mtdcr (maltxctp0r, hw_p->tx); |
| 636 | mtdcr (malrxbattr, 0x0); |
| 637 | mtdcr (malrxctp0r, hw_p->rx); |
| 638 | /* set RX buffer size */ |
| 639 | mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16); |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | /* Enable MAL transmit and receive channels */ |
| 644 | mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 645 | mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 646 | |
| 647 | /* set transmit enable & receive enable */ |
| 648 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE); |
| 649 | |
| 650 | /* set receive fifo to 4k and tx fifo to 2k */ |
| 651 | mode_reg = in32 (EMAC_M1 + hw_p->hw_addr); |
| 652 | mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K; |
| 653 | |
| 654 | /* set speed */ |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 655 | if (speed == _1000BASET) |
| 656 | mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST; |
| 657 | else if (speed == _100BASET) |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 658 | mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST; |
| 659 | else |
| 660 | mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */ |
| 661 | if (duplex == FULL) |
| 662 | mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST; |
| 663 | |
| 664 | out32 (EMAC_M1 + hw_p->hw_addr, mode_reg); |
| 665 | |
| 666 | /* Enable broadcast and indvidual address */ |
| 667 | /* TBS: enabling runts as some misbehaved nics will send runts */ |
| 668 | out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE); |
| 669 | |
| 670 | /* we probably need to set the tx mode1 reg? maybe at tx time */ |
| 671 | |
| 672 | /* set transmit request threshold register */ |
| 673 | out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */ |
| 674 | |
| 675 | /* set receive low/high water mark register */ |
| 676 | /* 440GP has a 64 byte burst length */ |
| 677 | out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000); |
| 678 | out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000); |
| 679 | |
| 680 | /* Set fifo limit entry in tx mode 0 */ |
| 681 | out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003); |
| 682 | /* Frame gap set */ |
| 683 | out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008); |
| 684 | |
| 685 | /* Set EMAC IER */ |
| 686 | hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | |
| 687 | EMAC_ISR_PTLE | EMAC_ISR_ORE | EMAC_ISR_IRE; |
| 688 | if (speed == _100BASET) |
| 689 | hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE; |
| 690 | |
| 691 | out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */ |
| 692 | out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier); |
| 693 | |
| 694 | if (hw_p->first_init == 0) { |
| 695 | /* |
| 696 | * Connect interrupt service routines |
| 697 | */ |
| 698 | irq_install_handler (VECNUM_EWU0 + (hw_p->devnum * 2), |
| 699 | (interrupt_handler_t *) enetInt, dev); |
| 700 | irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2), |
| 701 | (interrupt_handler_t *) enetInt, dev); |
| 702 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 703 | |
| 704 | mtmsr (msr); /* enable interrupts again */ |
| 705 | |
| 706 | hw_p->bis = bis; |
| 707 | hw_p->first_init = 1; |
| 708 | |
| 709 | return (1); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | static int ppc_440x_eth_send (struct eth_device *dev, volatile void *ptr, |
| 714 | int len) |
| 715 | { |
| 716 | struct enet_frame *ef_ptr; |
| 717 | ulong time_start, time_now; |
| 718 | unsigned long temp_txm0; |
| 719 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 720 | |
| 721 | ef_ptr = (struct enet_frame *) ptr; |
| 722 | |
| 723 | /*-----------------------------------------------------------------------+ |
| 724 | * Copy in our address into the frame. |
| 725 | *-----------------------------------------------------------------------*/ |
| 726 | (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH); |
| 727 | |
| 728 | /*-----------------------------------------------------------------------+ |
| 729 | * If frame is too long or too short, modify length. |
| 730 | *-----------------------------------------------------------------------*/ |
| 731 | /* TBS: where does the fragment go???? */ |
| 732 | if (len > ENET_MAX_MTU) |
| 733 | len = ENET_MAX_MTU; |
| 734 | |
| 735 | /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */ |
| 736 | memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len); |
| 737 | |
| 738 | /*-----------------------------------------------------------------------+ |
| 739 | * set TX Buffer busy, and send it |
| 740 | *-----------------------------------------------------------------------*/ |
| 741 | hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST | |
| 742 | EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) & |
| 743 | ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA); |
| 744 | if ((NUM_TX_BUFF - 1) == hw_p->tx_slot) |
| 745 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP; |
| 746 | |
| 747 | hw_p->tx[hw_p->tx_slot].data_len = (short) len; |
| 748 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY; |
| 749 | |
| 750 | __asm__ volatile ("eieio"); |
| 751 | |
| 752 | out32 (EMAC_TXM0 + hw_p->hw_addr, |
| 753 | in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0); |
| 754 | #ifdef INFO_440_ENET |
| 755 | hw_p->stats.pkts_tx++; |
| 756 | #endif |
| 757 | |
| 758 | /*-----------------------------------------------------------------------+ |
| 759 | * poll unitl the packet is sent and then make sure it is OK |
| 760 | *-----------------------------------------------------------------------*/ |
| 761 | time_start = get_timer (0); |
| 762 | while (1) { |
| 763 | temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr); |
| 764 | /* loop until either TINT turns on or 3 seconds elapse */ |
| 765 | if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) { |
| 766 | /* transmit is done, so now check for errors |
| 767 | * If there is an error, an interrupt should |
| 768 | * happen when we return |
| 769 | */ |
| 770 | time_now = get_timer (0); |
| 771 | if ((time_now - time_start) > 3000) { |
| 772 | return (-1); |
| 773 | } |
| 774 | } else { |
| 775 | return (len); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | |
| 781 | int enetInt (struct eth_device *dev) |
| 782 | { |
| 783 | int serviced; |
| 784 | int rc = -1; /* default to not us */ |
| 785 | unsigned long mal_isr; |
| 786 | unsigned long emac_isr = 0; |
| 787 | unsigned long mal_rx_eob; |
| 788 | unsigned long my_uic0msr, my_uic1msr; |
| 789 | |
| 790 | #if defined(CONFIG_440_GX) |
| 791 | unsigned long my_uic2msr; |
| 792 | #endif |
| 793 | EMAC_440GX_HW_PST hw_p; |
| 794 | |
| 795 | /* |
| 796 | * Because the mal is generic, we need to get the current |
| 797 | * eth device |
| 798 | */ |
| 799 | dev = eth_get_dev (); |
| 800 | |
| 801 | hw_p = dev->priv; |
| 802 | |
| 803 | |
| 804 | /* enter loop that stays in interrupt code until nothing to service */ |
| 805 | do { |
| 806 | serviced = 0; |
| 807 | |
| 808 | my_uic0msr = mfdcr (uic0msr); |
| 809 | my_uic1msr = mfdcr (uic1msr); |
| 810 | #if defined(CONFIG_440_GX) |
| 811 | my_uic2msr = mfdcr (uic2msr); |
| 812 | #endif |
| 813 | if (!(my_uic0msr & (UIC_MRE | UIC_MTE)) |
| 814 | && !(my_uic1msr & |
| 815 | (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE | |
| 816 | UIC_MRDE))) { |
| 817 | /* not for us */ |
| 818 | return (rc); |
| 819 | } |
| 820 | #if defined (CONFIG_440_GX) |
| 821 | if (!(my_uic0msr & (UIC_MRE | UIC_MTE)) |
| 822 | && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) { |
| 823 | /* not for us */ |
| 824 | return (rc); |
| 825 | } |
| 826 | #endif |
| 827 | /* get and clear controller status interrupts */ |
| 828 | /* look at Mal and EMAC interrupts */ |
| 829 | if ((my_uic0msr & (UIC_MRE | UIC_MTE)) |
| 830 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 831 | /* we have a MAL interrupt */ |
| 832 | mal_isr = mfdcr (malesr); |
| 833 | /* look for mal error */ |
| 834 | if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) { |
| 835 | mal_err (dev, mal_isr, my_uic0msr, |
| 836 | MAL_UIC_DEF, MAL_UIC_ERR); |
| 837 | serviced = 1; |
| 838 | rc = 0; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /* port by port dispatch of emac interrupts */ |
| 843 | if (hw_p->devnum == 0) { |
| 844 | if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */ |
| 845 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 846 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 847 | emac_err (dev, emac_isr); |
| 848 | serviced = 1; |
| 849 | rc = 0; |
| 850 | } |
| 851 | } |
| 852 | if ((hw_p->emac_ier & emac_isr) |
| 853 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 854 | mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */ |
| 855 | mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 856 | return (rc); /* we had errors so get out */ |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | if (hw_p->devnum == 1) { |
| 861 | if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */ |
| 862 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 863 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 864 | emac_err (dev, emac_isr); |
| 865 | serviced = 1; |
| 866 | rc = 0; |
| 867 | } |
| 868 | } |
| 869 | if ((hw_p->emac_ier & emac_isr) |
| 870 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 871 | mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */ |
| 872 | mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 873 | return (rc); /* we had errors so get out */ |
| 874 | } |
| 875 | } |
| 876 | #if defined (CONFIG_440_GX) |
| 877 | if (hw_p->devnum == 2) { |
| 878 | if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */ |
| 879 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 880 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 881 | emac_err (dev, emac_isr); |
| 882 | serviced = 1; |
| 883 | rc = 0; |
| 884 | } |
| 885 | } |
| 886 | if ((hw_p->emac_ier & emac_isr) |
| 887 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 888 | mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */ |
| 889 | mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 890 | mtdcr (uic2sr, UIC_ETH2); |
| 891 | return (rc); /* we had errors so get out */ |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | if (hw_p->devnum == 3) { |
| 896 | if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */ |
| 897 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 898 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 899 | emac_err (dev, emac_isr); |
| 900 | serviced = 1; |
| 901 | rc = 0; |
| 902 | } |
| 903 | } |
| 904 | if ((hw_p->emac_ier & emac_isr) |
| 905 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 906 | mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */ |
| 907 | mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 908 | mtdcr (uic2sr, UIC_ETH3); |
| 909 | return (rc); /* we had errors so get out */ |
| 910 | } |
| 911 | } |
| 912 | #endif /* CONFIG_440_GX */ |
| 913 | /* handle MAX TX EOB interrupt from a tx */ |
| 914 | if (my_uic0msr & UIC_MTE) { |
| 915 | mal_rx_eob = mfdcr (maltxeobisr); |
| 916 | mtdcr (maltxeobisr, mal_rx_eob); |
| 917 | mtdcr (uic0sr, UIC_MTE); |
| 918 | } |
| 919 | /* handle MAL RX EOB interupt from a receive */ |
| 920 | /* check for EOB on valid channels */ |
| 921 | if (my_uic0msr & UIC_MRE) { |
| 922 | mal_rx_eob = mfdcr (malrxeobisr); |
| 923 | if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */ |
| 924 | /* clear EOB |
| 925 | mtdcr(malrxeobisr, mal_rx_eob); */ |
| 926 | enet_rcv (dev, emac_isr); |
| 927 | /* indicate that we serviced an interrupt */ |
| 928 | serviced = 1; |
| 929 | rc = 0; |
| 930 | } |
| 931 | } |
| 932 | mtdcr (uic0sr, UIC_MRE); /* Clear */ |
| 933 | mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 934 | switch (hw_p->devnum) { |
| 935 | case 0: |
| 936 | mtdcr (uic1sr, UIC_ETH0); |
| 937 | break; |
| 938 | case 1: |
| 939 | mtdcr (uic1sr, UIC_ETH1); |
| 940 | break; |
| 941 | #if defined (CONFIG_440_GX) |
| 942 | case 2: |
| 943 | mtdcr (uic2sr, UIC_ETH2); |
| 944 | break; |
| 945 | case 3: |
| 946 | mtdcr (uic2sr, UIC_ETH3); |
| 947 | break; |
| 948 | #endif /* CONFIG_440_GX */ |
| 949 | default: |
| 950 | break; |
| 951 | } |
| 952 | } while (serviced); |
| 953 | |
| 954 | return (rc); |
| 955 | } |
| 956 | |
| 957 | /*-----------------------------------------------------------------------------+ |
| 958 | * MAL Error Routine |
| 959 | *-----------------------------------------------------------------------------*/ |
| 960 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 961 | unsigned long uic, unsigned long maldef, |
| 962 | unsigned long mal_errr) |
| 963 | { |
| 964 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 965 | |
| 966 | mtdcr (malesr, isr); /* clear interrupt */ |
| 967 | |
| 968 | /* clear DE interrupt */ |
| 969 | mtdcr (maltxdeir, 0xC0000000); |
| 970 | mtdcr (malrxdeir, 0x80000000); |
| 971 | |
| 972 | #ifdef INFO_440_ENET |
| 973 | printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr); |
| 974 | #endif |
| 975 | |
| 976 | eth_init (hw_p->bis); /* start again... */ |
| 977 | } |
| 978 | |
| 979 | /*-----------------------------------------------------------------------------+ |
| 980 | * EMAC Error Routine |
| 981 | *-----------------------------------------------------------------------------*/ |
| 982 | static void emac_err (struct eth_device *dev, unsigned long isr) |
| 983 | { |
| 984 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 985 | |
| 986 | printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr); |
| 987 | out32 (EMAC_ISR + hw_p->hw_addr, isr); |
| 988 | } |
| 989 | |
| 990 | /*-----------------------------------------------------------------------------+ |
| 991 | * enet_rcv() handles the ethernet receive data |
| 992 | *-----------------------------------------------------------------------------*/ |
| 993 | static void enet_rcv (struct eth_device *dev, unsigned long malisr) |
| 994 | { |
| 995 | struct enet_frame *ef_ptr; |
| 996 | unsigned long data_len; |
| 997 | unsigned long rx_eob_isr; |
| 998 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 999 | |
| 1000 | int handled = 0; |
| 1001 | int i; |
| 1002 | int loop_count = 0; |
| 1003 | |
| 1004 | rx_eob_isr = mfdcr (malrxeobisr); |
| 1005 | if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) { |
| 1006 | /* clear EOB */ |
| 1007 | mtdcr (malrxeobisr, rx_eob_isr); |
| 1008 | |
| 1009 | /* EMAC RX done */ |
| 1010 | while (1) { /* do all */ |
| 1011 | i = hw_p->rx_slot; |
| 1012 | |
| 1013 | if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl) |
| 1014 | || (loop_count >= NUM_RX_BUFF)) |
| 1015 | break; |
| 1016 | loop_count++; |
| 1017 | hw_p->rx_slot++; |
| 1018 | if (NUM_RX_BUFF == hw_p->rx_slot) |
| 1019 | hw_p->rx_slot = 0; |
| 1020 | handled++; |
| 1021 | data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */ |
| 1022 | if (data_len) { |
| 1023 | if (data_len > ENET_MAX_MTU) /* Check len */ |
| 1024 | data_len = 0; |
| 1025 | else { |
| 1026 | if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */ |
| 1027 | data_len = 0; |
| 1028 | hw_p->stats.rx_err_log[hw_p-> |
| 1029 | rx_err_index] |
| 1030 | = hw_p->rx[i].ctrl; |
| 1031 | hw_p->rx_err_index++; |
| 1032 | if (hw_p->rx_err_index == |
| 1033 | MAX_ERR_LOG) |
| 1034 | hw_p->rx_err_index = |
| 1035 | 0; |
| 1036 | } /* emac_erros */ |
| 1037 | } /* data_len < max mtu */ |
| 1038 | } /* if data_len */ |
| 1039 | if (!data_len) { /* no data */ |
| 1040 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */ |
| 1041 | |
| 1042 | hw_p->stats.data_len_err++; /* Error at Rx */ |
| 1043 | } |
| 1044 | |
| 1045 | /* !data_len */ |
| 1046 | /* AS.HARNOIS */ |
| 1047 | /* Check if user has already eaten buffer */ |
| 1048 | /* if not => ERROR */ |
| 1049 | else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) { |
| 1050 | if (hw_p->is_receiving) |
| 1051 | printf ("ERROR : Receive buffers are full!\n"); |
| 1052 | break; |
| 1053 | } else { |
| 1054 | hw_p->stats.rx_frames++; |
| 1055 | hw_p->stats.rx += data_len; |
| 1056 | ef_ptr = (struct enet_frame *) hw_p->rx[i]. |
| 1057 | data_ptr; |
| 1058 | #ifdef INFO_440_ENET |
| 1059 | hw_p->stats.pkts_rx++; |
| 1060 | #endif |
| 1061 | /* AS.HARNOIS |
| 1062 | * use ring buffer |
| 1063 | */ |
| 1064 | hw_p->rx_ready[hw_p->rx_i_index] = i; |
| 1065 | hw_p->rx_i_index++; |
| 1066 | if (NUM_RX_BUFF == hw_p->rx_i_index) |
| 1067 | hw_p->rx_i_index = 0; |
| 1068 | |
| 1069 | /* printf("X"); /|* test-only *|/ */ |
| 1070 | |
| 1071 | /* AS.HARNOIS |
| 1072 | * free receive buffer only when |
| 1073 | * buffer has been handled (eth_rx) |
| 1074 | rx[i].ctrl |= MAL_RX_CTRL_EMPTY; |
| 1075 | */ |
| 1076 | } /* if data_len */ |
| 1077 | } /* while */ |
| 1078 | } /* if EMACK_RXCHL */ |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | static int ppc_440x_eth_rx (struct eth_device *dev) |
| 1083 | { |
| 1084 | int length; |
| 1085 | int user_index; |
| 1086 | unsigned long msr; |
| 1087 | EMAC_440GX_HW_PST hw_p = dev->priv; |
| 1088 | |
| 1089 | hw_p->is_receiving = 1; /* tell driver */ |
| 1090 | |
| 1091 | for (;;) { |
| 1092 | /* AS.HARNOIS |
| 1093 | * use ring buffer and |
| 1094 | * get index from rx buffer desciptor queue |
| 1095 | */ |
| 1096 | user_index = hw_p->rx_ready[hw_p->rx_u_index]; |
| 1097 | if (user_index == -1) { |
| 1098 | length = -1; |
| 1099 | break; /* nothing received - leave for() loop */ |
| 1100 | } |
| 1101 | |
| 1102 | msr = mfmsr (); |
| 1103 | mtmsr (msr & ~(MSR_EE)); |
| 1104 | |
| 1105 | length = hw_p->rx[user_index].data_len; |
| 1106 | |
| 1107 | /* Pass the packet up to the protocol layers. */ |
| 1108 | /* NetReceive(NetRxPackets[rxIdx], length - 4); */ |
| 1109 | /* NetReceive(NetRxPackets[i], length); */ |
| 1110 | NetReceive (NetRxPackets[user_index], length - 4); |
| 1111 | /* Free Recv Buffer */ |
| 1112 | hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY; |
| 1113 | /* Free rx buffer descriptor queue */ |
| 1114 | hw_p->rx_ready[hw_p->rx_u_index] = -1; |
| 1115 | hw_p->rx_u_index++; |
| 1116 | if (NUM_RX_BUFF == hw_p->rx_u_index) |
| 1117 | hw_p->rx_u_index = 0; |
| 1118 | |
| 1119 | #ifdef INFO_440_ENET |
| 1120 | hw_p->stats.pkts_handled++; |
| 1121 | #endif |
| 1122 | |
| 1123 | mtmsr (msr); /* Enable IRQ's */ |
| 1124 | } |
| 1125 | |
| 1126 | hw_p->is_receiving = 0; /* tell driver */ |
| 1127 | |
| 1128 | return length; |
| 1129 | } |
| 1130 | |
| 1131 | int ppc_440x_eth_initialize (bd_t * bis) |
| 1132 | { |
| 1133 | static int virgin = 0; |
| 1134 | unsigned long pfc1; |
| 1135 | struct eth_device *dev; |
| 1136 | int eth_num = 0; |
| 1137 | |
| 1138 | EMAC_440GX_HW_PST hw = NULL; |
| 1139 | |
| 1140 | mfsdr (sdr_pfc1, pfc1); |
| 1141 | pfc1 &= ~(0x01e00000); |
| 1142 | pfc1 |= 0x01200000; |
| 1143 | mtsdr (sdr_pfc1, pfc1); |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1144 | /* set phy num and mode */ |
| 1145 | bis->bi_phynum[0] = CONFIG_PHY_ADDR; |
| 1146 | bis->bi_phynum[1] = CONFIG_PHY1_ADDR; |
| 1147 | bis->bi_phynum[2] = CONFIG_PHY2_ADDR; |
| 1148 | bis->bi_phynum[3] = CONFIG_PHY3_ADDR; |
| 1149 | bis->bi_phymode[0] = 0; |
| 1150 | bis->bi_phymode[1] = 0; |
| 1151 | bis->bi_phymode[2] = 2; |
| 1152 | bis->bi_phymode[3] = 2; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1153 | |
| 1154 | for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) { |
| 1155 | |
| 1156 | /* See if we can actually bring up the interface, otherwise, skip it */ |
| 1157 | switch (eth_num) { |
| 1158 | case 0: |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1159 | if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) { |
| 1160 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1161 | continue; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1162 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | case 1: |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1165 | if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) { |
| 1166 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1167 | continue; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1168 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | case 2: |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1171 | if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) { |
| 1172 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1173 | continue; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1174 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1175 | break; |
| 1176 | case 3: |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1177 | if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) { |
| 1178 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1179 | continue; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1180 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1181 | break; |
| 1182 | default: |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1183 | if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) { |
| 1184 | bis->bi_phymode[eth_num] = BI_PHYMODE_NONE; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1185 | continue; |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 1186 | } |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1187 | break; |
| 1188 | } |
| 1189 | |
| 1190 | /* Allocate device structure */ |
| 1191 | dev = (struct eth_device *) malloc (sizeof (*dev)); |
| 1192 | if (dev == NULL) { |
wdenk | 3f85ce2 | 2004-02-23 16:11:30 +0000 | [diff] [blame] | 1193 | printf ("ppc_440x_eth_initialize: " |
| 1194 | "Cannot allocate eth_device %d\n", eth_num); |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1195 | return (-1); |
| 1196 | } |
| 1197 | |
| 1198 | /* Allocate our private use data */ |
| 1199 | hw = (EMAC_440GX_HW_PST) malloc (sizeof (*hw)); |
| 1200 | if (hw == NULL) { |
wdenk | 3f85ce2 | 2004-02-23 16:11:30 +0000 | [diff] [blame] | 1201 | printf ("ppc_440x_eth_initialize: " |
| 1202 | "Cannot allocate private hw data for eth_device %d", |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 1203 | eth_num); |
| 1204 | free (dev); |
| 1205 | return (-1); |
| 1206 | } |
| 1207 | |
| 1208 | switch (eth_num) { |
| 1209 | case 0: |
| 1210 | hw->hw_addr = 0; |
| 1211 | memcpy (dev->enetaddr, bis->bi_enetaddr, 6); |
| 1212 | break; |
| 1213 | case 1: |
| 1214 | hw->hw_addr = 0x100; |
| 1215 | memcpy (dev->enetaddr, bis->bi_enet1addr, 6); |
| 1216 | break; |
| 1217 | case 2: |
| 1218 | hw->hw_addr = 0x400; |
| 1219 | memcpy (dev->enetaddr, bis->bi_enet2addr, 6); |
| 1220 | break; |
| 1221 | case 3: |
| 1222 | hw->hw_addr = 0x600; |
| 1223 | memcpy (dev->enetaddr, bis->bi_enet3addr, 6); |
| 1224 | break; |
| 1225 | default: |
| 1226 | hw->hw_addr = 0; |
| 1227 | memcpy (dev->enetaddr, bis->bi_enetaddr, 6); |
| 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | hw->devnum = eth_num; |
| 1232 | |
| 1233 | sprintf (dev->name, "ppc_440x_eth%d", eth_num); |
| 1234 | dev->priv = (void *) hw; |
| 1235 | dev->init = ppc_440x_eth_init; |
| 1236 | dev->halt = ppc_440x_eth_halt; |
| 1237 | dev->send = ppc_440x_eth_send; |
| 1238 | dev->recv = ppc_440x_eth_rx; |
| 1239 | |
| 1240 | if (0 == virgin) { |
| 1241 | /* set the MAL IER ??? names may change with new spec ??? */ |
| 1242 | mal_ier = |
| 1243 | MAL_IER_DE | MAL_IER_NE | MAL_IER_TE | |
| 1244 | MAL_IER_OPBE | MAL_IER_PLBE; |
| 1245 | mtdcr (malesr, 0xffffffff); /* clear pending interrupts */ |
| 1246 | mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */ |
| 1247 | mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */ |
| 1248 | mtdcr (malier, mal_ier); |
| 1249 | |
| 1250 | /* install MAL interrupt handler */ |
| 1251 | irq_install_handler (VECNUM_MS, |
| 1252 | (interrupt_handler_t *) enetInt, |
| 1253 | dev); |
| 1254 | irq_install_handler (VECNUM_MTE, |
| 1255 | (interrupt_handler_t *) enetInt, |
| 1256 | dev); |
| 1257 | irq_install_handler (VECNUM_MRE, |
| 1258 | (interrupt_handler_t *) enetInt, |
| 1259 | dev); |
| 1260 | irq_install_handler (VECNUM_TXDE, |
| 1261 | (interrupt_handler_t *) enetInt, |
| 1262 | dev); |
| 1263 | irq_install_handler (VECNUM_RXDE, |
| 1264 | (interrupt_handler_t *) enetInt, |
| 1265 | dev); |
| 1266 | virgin = 1; |
| 1267 | } |
| 1268 | |
| 1269 | eth_register (dev); |
| 1270 | |
| 1271 | } /* end for each supported device */ |
| 1272 | return (1); |
| 1273 | } |
| 1274 | #endif /* CONFIG_440 && CONFIG_NET_MULTI */ |