wdenk | c609719 | 2002-11-03 00:24:07 +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). |
wdenk | 4e7a58a | 2003-12-07 19:24:00 +0000 | [diff] [blame] | 70 | * 21-Nov-03 pavel.bartusek@sysgo.com |
| 71 | * - set ZMII bridge speed on 440 |
| 72 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | *-----------------------------------------------------------------------------*/ |
| 74 | |
| 75 | #include <common.h> |
| 76 | #include <asm/processor.h> |
| 77 | #include <ppc4xx.h> |
| 78 | #include <commproc.h> |
| 79 | #include <405gp_enet.h> |
| 80 | #include <405_mal.h> |
| 81 | #include <miiphy.h> |
| 82 | #include <net.h> |
| 83 | #include <malloc.h> |
| 84 | #include "vecnum.h" |
| 85 | |
wdenk | 544e973 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 86 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ |
| 87 | ( defined(CONFIG_440) && !defined(CONFIG_NET_MULTI)) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 88 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 89 | #if !defined(CONFIG_NET_MULTI) || !defined(CONFIG_405EP) |
| 90 | /* 405GP, 440 with !CONFIG_NET_MULTI. For 440 only EMAC0 is supported */ |
| 91 | #define EMAC_NUM_DEV 1 |
| 92 | #else |
| 93 | /* 440EP && CONFIG_NET_MULTI */ |
| 94 | #define EMAC_NUM_DEV 2 |
| 95 | #endif |
| 96 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */ |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 98 | #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 100 | /* Ethernet Transmit and Receive Buffers */ |
| 101 | /* AS.HARNOIS |
| 102 | * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from |
| 103 | * PKTSIZE and PKTSIZE_ALIGN (include/net.h) |
| 104 | */ |
| 105 | #define ENET_MAX_MTU PKTSIZE |
| 106 | #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN |
| 107 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 108 | /* define the number of channels implemented */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 109 | #define EMAC_RXCHL EMAC_NUM_DEV |
| 110 | #define EMAC_TXCHL EMAC_NUM_DEV |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | |
| 112 | /*-----------------------------------------------------------------------------+ |
| 113 | * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal |
| 114 | * Interrupt Controller). |
| 115 | *-----------------------------------------------------------------------------*/ |
| 116 | #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE) |
| 117 | #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR) |
| 118 | #define EMAC_UIC_DEF UIC_ENET |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 119 | #define EMAC_UIC_DEF1 UIC_ENET1 |
| 120 | #define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET ) |
| 121 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 122 | |
| 123 | /*-----------------------------------------------------------------------------+ |
| 124 | * Global variables. TX and RX descriptors and buffers. |
| 125 | *-----------------------------------------------------------------------------*/ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | /* IER globals */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 127 | static uint32_t mal_ier; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 129 | #if !defined(CONFIG_NET_MULTI) |
| 130 | struct eth_device *emac0_dev; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 131 | #endif |
| 132 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 133 | /*-----------------------------------------------------------------------------+ |
| 134 | * Prototypes and externals. |
| 135 | *-----------------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 136 | static void enet_rcv (struct eth_device *dev, unsigned long malisr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 138 | int enetInt (struct eth_device *dev); |
| 139 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 140 | unsigned long uic, unsigned long maldef, |
| 141 | unsigned long mal_errr); |
| 142 | static void emac_err (struct eth_device *dev, unsigned long isr); |
| 143 | |
| 144 | /*-----------------------------------------------------------------------------+ |
| 145 | | ppc_405x_eth_halt |
| 146 | | Disable MAL channel, and EMACn |
| 147 | | |
| 148 | | |
| 149 | +-----------------------------------------------------------------------------*/ |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 150 | static void ppc_4xx_eth_halt (struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 151 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 152 | EMAC_405_HW_PST hw_p = dev->priv; |
| 153 | uint32_t failsafe = 10000; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 154 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 155 | mtdcr (malier, 0x00000000); /* disable mal interrupts */ |
| 156 | out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */ |
| 157 | |
| 158 | /* 1st reset MAL channel */ |
| 159 | /* Note: writing a 0 to a channel has no effect */ |
| 160 | mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2))); |
| 161 | mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | |
| 163 | /* wait for reset */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 164 | while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) { |
| 165 | udelay (1000); /* Delay 1 MS so as not to hammer the register */ |
| 166 | failsafe--; |
| 167 | if (failsafe == 0) |
| 168 | break; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 169 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | |
| 171 | /* EMAC RESET */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 172 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 173 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 174 | hw_p->print_speed = 1; /* print speed message again next time */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 175 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 176 | return; |
| 177 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 178 | |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 179 | static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 180 | { |
| 181 | int i; |
| 182 | unsigned long reg; |
| 183 | unsigned long msr; |
| 184 | unsigned long speed; |
| 185 | unsigned long duplex; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 186 | unsigned long failsafe; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 187 | unsigned mode_reg; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 188 | unsigned short devnum; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 189 | unsigned short reg_short; |
| 190 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 191 | EMAC_405_HW_PST hw_p = dev->priv; |
| 192 | /* before doing anything, figure out if we have a MAC address */ |
| 193 | /* if not, bail */ |
| 194 | if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) |
| 195 | return -1; |
| 196 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 197 | msr = mfmsr (); |
| 198 | mtmsr (msr & ~(MSR_EE)); /* disable interrupts */ |
| 199 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 200 | devnum = hw_p->devnum; |
| 201 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | #ifdef INFO_405_ENET |
| 203 | /* AS.HARNOIS |
| 204 | * We should have : |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 205 | * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX |
| 206 | * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 207 | * is possible that new packets (without relationship with |
| 208 | * current transfer) have got the time to arrived before |
| 209 | * netloop calls eth_halt |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 211 | printf ("About preceeding transfer (eth%d):\n" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 212 | "- Sent packet number %d\n" |
| 213 | "- Received packet number %d\n" |
| 214 | "- Handled packet number %d\n", |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 215 | hw_p->devnum, |
| 216 | hw_p->stats.pkts_tx, |
| 217 | hw_p->stats.pkts_rx, hw_p->stats.pkts_handled); |
| 218 | |
| 219 | hw_p->stats.pkts_tx = 0; |
| 220 | hw_p->stats.pkts_rx = 0; |
| 221 | hw_p->stats.pkts_handled = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 222 | #endif |
| 223 | |
| 224 | /* MAL RESET */ |
Stefan Roese | 363330b | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 225 | mtdcr (malmcr, MAL_CR_MMSR); |
| 226 | /* wait for reset */ |
| 227 | while (mfdcr (malmcr) & MAL_CR_MMSR) { |
| 228 | }; |
| 229 | |
Stefan Roese | b30f2a1 | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 230 | #if defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | 326c971 | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 231 | out32 (ZMII_FER, 0); |
| 232 | udelay(100); |
| 233 | /* set RII mode */ |
| 234 | out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0); |
| 235 | #elif defined(CONFIG_440) |
Stefan Roese | 363330b | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 236 | /* set RMII mode */ |
| 237 | out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 238 | #endif /* CONFIG_440 */ |
| 239 | |
| 240 | /* MAL Channel RESET */ |
| 241 | /* 1st reset MAL channel */ |
| 242 | /* Note: writing a 0 to a channel has no effect */ |
| 243 | mtdcr (maltxcarr, (MAL_TXRX_CASR >> (hw_p->devnum * 2))); |
| 244 | mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum)); |
| 245 | |
| 246 | /* wait for reset */ |
| 247 | /* TBS: should have udelay and failsafe here */ |
| 248 | failsafe = 10000; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 249 | /* wait for reset */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 250 | while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) { |
| 251 | udelay (1000); /* Delay 1 MS so as not to hammer the register */ |
| 252 | failsafe--; |
| 253 | if (failsafe == 0) |
| 254 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 255 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 256 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 257 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 258 | hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */ |
| 259 | hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 261 | hw_p->rx_slot = 0; /* MAL Receive Slot */ |
| 262 | hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */ |
| 263 | hw_p->rx_u_index = 0; /* Receive User Queue Index */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 265 | hw_p->tx_slot = 0; /* MAL Transmit Slot */ |
| 266 | hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */ |
| 267 | hw_p->tx_u_index = 0; /* Transmit User Queue Index */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 268 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 269 | __asm__ volatile ("eieio"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 270 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 271 | /* reset emac so we have access to the phy */ |
| 272 | |
| 273 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST); |
| 274 | __asm__ volatile ("eieio"); |
| 275 | |
| 276 | failsafe = 1000; |
| 277 | while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) { |
| 278 | udelay (1000); |
| 279 | failsafe--; |
| 280 | } |
| 281 | |
| 282 | #if defined(CONFIG_NET_MULTI) |
| 283 | reg = hw_p->devnum ? CONFIG_PHY1_ADDR : CONFIG_PHY_ADDR; |
| 284 | #else |
| 285 | reg = CONFIG_PHY_ADDR; |
| 286 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 287 | /* wait for PHY to complete auto negotiation */ |
| 288 | reg_short = 0; |
| 289 | #ifndef CONFIG_CS8952_PHY |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 290 | miiphy_read (reg, PHY_BMSR, ®_short); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | |
| 292 | /* |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 293 | * Wait if PHY is capable of autonegotiation and autonegotiation is not complete |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 294 | */ |
| 295 | if ((reg_short & PHY_BMSR_AUTN_ABLE) |
| 296 | && !(reg_short & PHY_BMSR_AUTN_COMP)) { |
| 297 | puts ("Waiting for PHY auto negotiation to complete"); |
| 298 | i = 0; |
| 299 | while (!(reg_short & PHY_BMSR_AUTN_COMP)) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 300 | /* |
| 301 | * Timeout reached ? |
| 302 | */ |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 303 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 304 | puts (" TIMEOUT !\n"); |
| 305 | break; |
| 306 | } |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 307 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 308 | if ((i++ % 1000) == 0) { |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 309 | putc ('.'); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 310 | } |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 311 | udelay (1000); /* 1 ms */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 312 | miiphy_read (reg, PHY_BMSR, ®_short); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 313 | } |
| 314 | puts (" done\n"); |
| 315 | udelay (500000); /* another 500 ms (results in faster booting) */ |
| 316 | } |
| 317 | #endif |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 318 | speed = miiphy_speed (reg); |
| 319 | duplex = miiphy_duplex (reg); |
| 320 | |
| 321 | if (hw_p->print_speed) { |
| 322 | hw_p->print_speed = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 323 | printf ("ENET Speed is %d Mbps - %s duplex connection\n", |
| 324 | (int) speed, (duplex == HALF) ? "HALF" : "FULL"); |
| 325 | } |
| 326 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 327 | mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT); |
Stefan Roese | 363330b | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 328 | /* Errata 1.12: MAL_1 -- Disable MAL bursting */ |
| 329 | if (get_pvr() == PVR_440GP_RB) { |
| 330 | mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB); |
| 331 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 332 | |
| 333 | /* Free "old" buffers */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 334 | if (hw_p->alloc_tx_buf) |
| 335 | free (hw_p->alloc_tx_buf); |
| 336 | if (hw_p->alloc_rx_buf) |
| 337 | free (hw_p->alloc_rx_buf); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * Malloc MAL buffer desciptors, make sure they are |
| 341 | * aligned on cache line boundary size |
| 342 | * (401/403/IOP480 = 16, 405 = 32) |
| 343 | * and doesn't cross cache block boundaries. |
| 344 | */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 345 | hw_p->alloc_tx_buf = |
| 346 | (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) + |
| 347 | ((2 * CFG_CACHELINE_SIZE) - 2)); |
| 348 | if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) { |
| 349 | hw_p->tx = |
| 350 | (mal_desc_t *) ((int) hw_p->alloc_tx_buf + |
| 351 | CFG_CACHELINE_SIZE - |
| 352 | ((int) hw_p-> |
| 353 | alloc_tx_buf & CACHELINE_MASK)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 354 | } else { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 355 | hw_p->tx = hw_p->alloc_tx_buf; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 356 | } |
| 357 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 358 | hw_p->alloc_rx_buf = |
| 359 | (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) + |
| 360 | ((2 * CFG_CACHELINE_SIZE) - 2)); |
| 361 | if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) { |
| 362 | hw_p->rx = |
| 363 | (mal_desc_t *) ((int) hw_p->alloc_rx_buf + |
| 364 | CFG_CACHELINE_SIZE - |
| 365 | ((int) hw_p-> |
| 366 | alloc_rx_buf & CACHELINE_MASK)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 367 | } else { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 368 | hw_p->rx = hw_p->alloc_rx_buf; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | for (i = 0; i < NUM_TX_BUFF; i++) { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 372 | hw_p->tx[i].ctrl = 0; |
| 373 | hw_p->tx[i].data_len = 0; |
| 374 | if (hw_p->first_init == 0) |
| 375 | hw_p->txbuf_ptr = |
| 376 | (char *) malloc (ENET_MAX_MTU_ALIGNED); |
| 377 | hw_p->tx[i].data_ptr = hw_p->txbuf_ptr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | if ((NUM_TX_BUFF - 1) == i) |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 379 | hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP; |
| 380 | hw_p->tx_run[i] = -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 381 | #if 0 |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 382 | printf ("TX_BUFF %d @ 0x%08lx\n", i, |
| 383 | (ulong) hw_p->tx[i].data_ptr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 384 | #endif |
| 385 | } |
| 386 | |
| 387 | for (i = 0; i < NUM_RX_BUFF; i++) { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 388 | hw_p->rx[i].ctrl = 0; |
| 389 | hw_p->rx[i].data_len = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 390 | /* rx[i].data_ptr = (char *) &rx_buff[i]; */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 391 | hw_p->rx[i].data_ptr = (char *) NetRxPackets[i]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | if ((NUM_RX_BUFF - 1) == i) |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 393 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP; |
| 394 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR; |
| 395 | hw_p->rx_ready[i] = -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 396 | #if 0 |
| 397 | printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr); |
| 398 | #endif |
| 399 | } |
| 400 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 401 | reg = 0x00000000; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 402 | reg |= dev->enetaddr[0]; /* set high address */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 403 | reg = reg << 8; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 404 | reg |= dev->enetaddr[1]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 405 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 406 | out32 (EMAC_IAH + hw_p->hw_addr, reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 407 | |
| 408 | reg = 0x00000000; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 409 | reg |= dev->enetaddr[2]; /* set low address */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 410 | reg = reg << 8; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 411 | reg |= dev->enetaddr[3]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 412 | reg = reg << 8; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 413 | reg |= dev->enetaddr[4]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 414 | reg = reg << 8; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 415 | reg |= dev->enetaddr[5]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 416 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 417 | out32 (EMAC_IAL + hw_p->hw_addr, reg); |
Stefan Roese | 363330b | 2005-08-04 17:09:16 +0200 | [diff] [blame] | 418 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 419 | switch (devnum) { |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 420 | #if defined(CONFIG_NET_MULTI) |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 421 | case 1: |
| 422 | /* setup MAL tx & rx channel pointers */ |
| 423 | /* For 405EP, the EMAC1 tx channel 0 is MAL tx channel 2 */ |
| 424 | mtdcr (maltxctp2r, hw_p->tx); |
| 425 | mtdcr (malrxctp1r, hw_p->rx); |
| 426 | /* set RX buffer size */ |
| 427 | mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16); |
| 428 | break; |
wdenk | 9e07690 | 2004-06-17 18:50:45 +0000 | [diff] [blame] | 429 | #endif |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 430 | case 0: |
| 431 | default: |
| 432 | /* setup MAL tx & rx channel pointers */ |
| 433 | mtdcr (maltxctp0r, hw_p->tx); |
| 434 | mtdcr (malrxctp0r, hw_p->rx); |
| 435 | /* set RX buffer size */ |
| 436 | mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16); |
| 437 | break; |
| 438 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 439 | |
| 440 | /* Enable MAL transmit and receive channels */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 441 | mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum * 2))); |
| 442 | mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 443 | |
| 444 | /* set transmit enable & receive enable */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 445 | out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 446 | |
| 447 | /* set receive fifo to 4k and tx fifo to 2k */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 448 | mode_reg = in32 (EMAC_M1 + hw_p->hw_addr); |
| 449 | mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 450 | |
| 451 | /* set speed */ |
| 452 | if (speed == _100BASET) |
| 453 | mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST; |
| 454 | else |
| 455 | mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */ |
| 456 | if (duplex == FULL) |
| 457 | mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST; |
| 458 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 459 | out32 (EMAC_M1 + hw_p->hw_addr, mode_reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 460 | |
wdenk | 4e7a58a | 2003-12-07 19:24:00 +0000 | [diff] [blame] | 461 | #if defined(CONFIG_440) |
| 462 | /* set speed in the ZMII bridge */ |
| 463 | if (speed == _100BASET) |
| 464 | out32(ZMII_SSR, in32(ZMII_SSR) | 0x10000000); |
| 465 | else |
| 466 | out32(ZMII_SSR, in32(ZMII_SSR) & ~0x10000000); |
Stefan Roese | b30f2a1 | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 467 | #if defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | 326c971 | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 468 | mfsdr(sdr_mfr, reg); |
| 469 | /* set speed */ |
| 470 | if (speed == _100BASET) { |
| 471 | out32(ZMII_SSR, in32(ZMII_SSR) | 0x10000000); |
| 472 | reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M; |
| 473 | } else { |
| 474 | reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M; |
| 475 | out32(ZMII_SSR, in32(ZMII_SSR) & ~0x10000000); |
| 476 | } |
| 477 | mtsdr(sdr_mfr, reg); |
| 478 | #endif |
wdenk | 4e7a58a | 2003-12-07 19:24:00 +0000 | [diff] [blame] | 479 | #endif |
| 480 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 481 | /* Enable broadcast and indvidual address */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 482 | /* TBS: enabling runts as some misbehaved nics will send runts */ |
| 483 | out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 484 | |
| 485 | /* we probably need to set the tx mode1 reg? maybe at tx time */ |
| 486 | |
| 487 | /* set transmit request threshold register */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 488 | out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 489 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 490 | #if defined(CONFIG_440) |
| 491 | /* 440GP has a 64 byte burst length */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 492 | out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000); |
| 493 | out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000); |
| 494 | #else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 495 | /* 405s have a 16 byte burst length */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 496 | out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000); |
| 497 | #endif |
| 498 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 499 | /* Frame gap set */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 500 | out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008); |
| 501 | |
| 502 | /* Set EMAC IER */ |
| 503 | hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | |
| 504 | EMAC_ISR_ORE | EMAC_ISR_IRE; |
| 505 | if (speed == _100BASET) |
| 506 | hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 507 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 508 | out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */ |
| 509 | out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier); |
| 510 | |
| 511 | if (hw_p->first_init == 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 512 | /* |
| 513 | * Connect interrupt service routines |
| 514 | */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 515 | irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2), |
| 516 | (interrupt_handler_t *) enetInt, dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 517 | } |
| 518 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 519 | mtmsr (msr); /* enable interrupts again */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 520 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 521 | hw_p->bis = bis; |
| 522 | hw_p->first_init = 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 523 | |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 524 | return (1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 528 | static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr, int len) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 529 | { |
| 530 | struct enet_frame *ef_ptr; |
| 531 | ulong time_start, time_now; |
| 532 | unsigned long temp_txm0; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 533 | EMAC_405_HW_PST hw_p = dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 534 | |
| 535 | ef_ptr = (struct enet_frame *) ptr; |
| 536 | |
| 537 | /*-----------------------------------------------------------------------+ |
| 538 | * Copy in our address into the frame. |
| 539 | *-----------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 540 | (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 541 | |
| 542 | /*-----------------------------------------------------------------------+ |
| 543 | * If frame is too long or too short, modify length. |
| 544 | *-----------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 545 | /* TBS: where does the fragment go???? */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 546 | if (len > ENET_MAX_MTU) |
| 547 | len = ENET_MAX_MTU; |
| 548 | |
| 549 | /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 550 | memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 551 | |
| 552 | /*-----------------------------------------------------------------------+ |
| 553 | * set TX Buffer busy, and send it |
| 554 | *-----------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 555 | hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST | |
| 556 | EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) & |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 557 | ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 558 | if ((NUM_TX_BUFF - 1) == hw_p->tx_slot) |
| 559 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 560 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 561 | hw_p->tx[hw_p->tx_slot].data_len = (short) len; |
| 562 | hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 563 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 564 | __asm__ volatile ("eieio"); |
| 565 | |
| 566 | out32 (EMAC_TXM0 + hw_p->hw_addr, |
| 567 | in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 568 | #ifdef INFO_405_ENET |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 569 | hw_p->stats.pkts_tx++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 570 | #endif |
| 571 | |
| 572 | /*-----------------------------------------------------------------------+ |
| 573 | * poll unitl the packet is sent and then make sure it is OK |
| 574 | *-----------------------------------------------------------------------*/ |
| 575 | time_start = get_timer (0); |
| 576 | while (1) { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 577 | temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 578 | /* loop until either TINT turns on or 3 seconds elapse */ |
| 579 | if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) { |
| 580 | /* transmit is done, so now check for errors |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 581 | * If there is an error, an interrupt should |
| 582 | * happen when we return |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 583 | */ |
| 584 | time_now = get_timer (0); |
| 585 | if ((time_now - time_start) > 3000) { |
| 586 | return (-1); |
| 587 | } |
| 588 | } else { |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 589 | return (len); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 594 | #if defined(CONFIG_440) |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 595 | int enetInt (struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 596 | { |
| 597 | int serviced; |
| 598 | int rc = -1; /* default to not us */ |
| 599 | unsigned long mal_isr; |
| 600 | unsigned long emac_isr = 0; |
| 601 | unsigned long mal_rx_eob; |
| 602 | unsigned long my_uic0msr, my_uic1msr; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 603 | EMAC_405_HW_PST hw_p; |
| 604 | |
| 605 | /* |
| 606 | * Because the mal is generic, we need to get the current |
| 607 | * eth device |
| 608 | */ |
| 609 | #if defined(CONFIG_NET_MULTI) |
| 610 | dev = eth_get_dev(); |
| 611 | #else |
| 612 | dev = emac0_dev; |
| 613 | #endif |
| 614 | hw_p = dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 615 | |
| 616 | /* enter loop that stays in interrupt code until nothing to service */ |
| 617 | do { |
| 618 | serviced = 0; |
| 619 | |
| 620 | my_uic0msr = mfdcr (uic0msr); |
| 621 | my_uic1msr = mfdcr (uic1msr); |
| 622 | |
| 623 | if (!(my_uic0msr & UIC_MRE) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 624 | && !(my_uic1msr & (UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 625 | /* not for us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 626 | return (rc); |
| 627 | } |
| 628 | |
| 629 | /* get and clear controller status interrupts */ |
| 630 | /* look at Mal and EMAC interrupts */ |
| 631 | if ((my_uic0msr & UIC_MRE) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 632 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
| 633 | /* we have a MAL interrupt */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 634 | mal_isr = mfdcr (malesr); |
| 635 | /* look for mal error */ |
| 636 | if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 637 | mal_err (dev, mal_isr, my_uic0msr, MAL_UIC_DEF, MAL_UIC_ERR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 638 | serviced = 1; |
| 639 | rc = 0; |
| 640 | } |
| 641 | } |
| 642 | if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 643 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 644 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 645 | emac_err (dev, emac_isr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 646 | serviced = 1; |
| 647 | rc = 0; |
| 648 | } |
| 649 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 650 | if ((hw_p->emac_ier & emac_isr) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 651 | || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 652 | mtdcr (uic0sr, UIC_MRE); /* Clear */ |
| 653 | mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
| 654 | return (rc); /* we had errors so get out */ |
| 655 | } |
| 656 | |
| 657 | /* handle MAL RX EOB interupt from a receive */ |
| 658 | /* check for EOB on valid channels */ |
| 659 | if (my_uic0msr & UIC_MRE) { |
| 660 | mal_rx_eob = mfdcr (malrxeobisr); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 661 | if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel 0 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 662 | /* clear EOB |
| 663 | mtdcr(malrxeobisr, mal_rx_eob); */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 664 | enet_rcv (dev, emac_isr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 665 | /* indicate that we serviced an interrupt */ |
| 666 | serviced = 1; |
| 667 | rc = 0; |
| 668 | } |
| 669 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 670 | mtdcr (uic0sr, UIC_MRE); /* Clear */ |
| 671 | mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 672 | } while (serviced); |
| 673 | |
| 674 | return (rc); |
| 675 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 676 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 677 | #else /* CONFIG_440 */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 678 | |
| 679 | int enetInt (struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 680 | { |
| 681 | int serviced; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 682 | int rc = -1; /* default to not us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 683 | unsigned long mal_isr; |
| 684 | unsigned long emac_isr = 0; |
| 685 | unsigned long mal_rx_eob; |
| 686 | unsigned long my_uicmsr; |
| 687 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 688 | EMAC_405_HW_PST hw_p; |
| 689 | |
| 690 | /* |
| 691 | * Because the mal is generic, we need to get the current |
| 692 | * eth device |
| 693 | */ |
| 694 | #if defined(CONFIG_NET_MULTI) |
| 695 | dev = eth_get_dev(); |
| 696 | #else |
| 697 | dev = emac0_dev; |
| 698 | #endif |
| 699 | |
| 700 | hw_p = dev->priv; |
| 701 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 702 | /* enter loop that stays in interrupt code until nothing to service */ |
| 703 | do { |
| 704 | serviced = 0; |
| 705 | |
| 706 | my_uicmsr = mfdcr (uicmsr); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 707 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 708 | if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */ |
| 709 | return (rc); |
| 710 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 711 | /* get and clear controller status interrupts */ |
| 712 | /* look at Mal and EMAC interrupts */ |
| 713 | if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */ |
| 714 | mal_isr = mfdcr (malesr); |
| 715 | /* look for mal error */ |
| 716 | if ((my_uicmsr & MAL_UIC_ERR) != 0) { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 717 | mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 718 | serviced = 1; |
| 719 | rc = 0; |
| 720 | } |
| 721 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 722 | |
| 723 | /* port by port dispatch of emac interrupts */ |
| 724 | |
| 725 | if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */ |
| 726 | emac_isr = in32 (EMAC_ISR + hw_p->hw_addr); |
| 727 | if ((hw_p->emac_ier & emac_isr) != 0) { |
| 728 | emac_err (dev, emac_isr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 729 | serviced = 1; |
| 730 | rc = 0; |
| 731 | } |
| 732 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 733 | if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) { |
| 734 | mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 735 | return (rc); /* we had errors so get out */ |
| 736 | } |
| 737 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 738 | /* handle MAX TX EOB interrupt from a tx */ |
| 739 | if (my_uicmsr & UIC_MAL_TXEOB) { |
| 740 | mal_rx_eob = mfdcr (maltxeobisr); |
| 741 | mtdcr (maltxeobisr, mal_rx_eob); |
| 742 | mtdcr (uicsr, UIC_MAL_TXEOB); |
| 743 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 744 | /* handle MAL RX EOB interupt from a receive */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 745 | /* check for EOB on valid channels */ |
| 746 | if (my_uicmsr & UIC_MAL_RXEOB) |
| 747 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 748 | mal_rx_eob = mfdcr (malrxeobisr); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 749 | if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 750 | /* clear EOB |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 751 | mtdcr(malrxeobisr, mal_rx_eob); */ |
| 752 | enet_rcv (dev, emac_isr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 753 | /* indicate that we serviced an interrupt */ |
| 754 | serviced = 1; |
| 755 | rc = 0; |
| 756 | } |
| 757 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 758 | mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 759 | } |
| 760 | while (serviced); |
| 761 | |
| 762 | return (rc); |
| 763 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 764 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 765 | /*-----------------------------------------------------------------------------+ |
| 766 | * MAL Error Routine |
| 767 | *-----------------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 768 | static void mal_err (struct eth_device *dev, unsigned long isr, |
| 769 | unsigned long uic, unsigned long maldef, |
| 770 | unsigned long mal_errr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 771 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 772 | EMAC_405_HW_PST hw_p = dev->priv; |
| 773 | |
| 774 | mtdcr (malesr, isr); /* clear interrupt */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 775 | |
| 776 | /* clear DE interrupt */ |
| 777 | mtdcr (maltxdeir, 0xC0000000); |
| 778 | mtdcr (malrxdeir, 0x80000000); |
| 779 | |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 780 | #ifdef INFO_405_ENET |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 781 | printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr); |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 782 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 783 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 784 | eth_init (hw_p->bis); /* start again... */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /*-----------------------------------------------------------------------------+ |
| 788 | * EMAC Error Routine |
| 789 | *-----------------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 790 | static void emac_err (struct eth_device *dev, unsigned long isr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 791 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 792 | EMAC_405_HW_PST hw_p = dev->priv; |
| 793 | |
| 794 | printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr); |
| 795 | out32 (EMAC_ISR + hw_p->hw_addr, isr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /*-----------------------------------------------------------------------------+ |
| 799 | * enet_rcv() handles the ethernet receive data |
| 800 | *-----------------------------------------------------------------------------*/ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 801 | static void enet_rcv (struct eth_device *dev, unsigned long malisr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 802 | { |
| 803 | struct enet_frame *ef_ptr; |
| 804 | unsigned long data_len; |
| 805 | unsigned long rx_eob_isr; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 806 | EMAC_405_HW_PST hw_p = dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 807 | |
| 808 | int handled = 0; |
| 809 | int i; |
| 810 | int loop_count = 0; |
| 811 | |
| 812 | rx_eob_isr = mfdcr (malrxeobisr); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 813 | if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 814 | /* clear EOB */ |
| 815 | mtdcr (malrxeobisr, rx_eob_isr); |
| 816 | |
| 817 | /* EMAC RX done */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 818 | while (1) { /* do all */ |
| 819 | i = hw_p->rx_slot; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 820 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 821 | if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 822 | || (loop_count >= NUM_RX_BUFF)) |
| 823 | break; |
| 824 | loop_count++; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 825 | hw_p->rx_slot++; |
| 826 | if (NUM_RX_BUFF == hw_p->rx_slot) |
| 827 | hw_p->rx_slot = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 828 | handled++; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 829 | data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 830 | if (data_len) { |
| 831 | if (data_len > ENET_MAX_MTU) /* Check len */ |
| 832 | data_len = 0; |
| 833 | else { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 834 | if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 835 | data_len = 0; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 836 | hw_p->stats.rx_err_log[hw_p-> |
| 837 | rx_err_index] |
| 838 | = hw_p->rx[i].ctrl; |
| 839 | hw_p->rx_err_index++; |
| 840 | if (hw_p->rx_err_index == |
| 841 | MAX_ERR_LOG) |
| 842 | hw_p->rx_err_index = |
| 843 | 0; |
| 844 | } /* emac_erros */ |
| 845 | } /* data_len < max mtu */ |
| 846 | } /* if data_len */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 847 | if (!data_len) { /* no data */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 848 | hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 849 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 850 | hw_p->stats.data_len_err++; /* Error at Rx */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /* !data_len */ |
| 854 | /* AS.HARNOIS */ |
| 855 | /* Check if user has already eaten buffer */ |
| 856 | /* if not => ERROR */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 857 | else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) { |
| 858 | if (hw_p->is_receiving) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 859 | printf ("ERROR : Receive buffers are full!\n"); |
| 860 | break; |
| 861 | } else { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 862 | hw_p->stats.rx_frames++; |
| 863 | hw_p->stats.rx += data_len; |
| 864 | ef_ptr = (struct enet_frame *) hw_p->rx[i]. |
| 865 | data_ptr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 866 | #ifdef INFO_405_ENET |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 867 | hw_p->stats.pkts_rx++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 868 | #endif |
| 869 | /* AS.HARNOIS |
| 870 | * use ring buffer |
| 871 | */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 872 | hw_p->rx_ready[hw_p->rx_i_index] = i; |
| 873 | hw_p->rx_i_index++; |
| 874 | if (NUM_RX_BUFF == hw_p->rx_i_index) |
| 875 | hw_p->rx_i_index = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 876 | |
| 877 | /* printf("X"); /|* test-only *|/ */ |
| 878 | |
| 879 | /* AS.HARNOIS |
| 880 | * free receive buffer only when |
| 881 | * buffer has been handled (eth_rx) |
| 882 | rx[i].ctrl |= MAL_RX_CTRL_EMPTY; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 883 | */ |
| 884 | } /* if data_len */ |
| 885 | } /* while */ |
| 886 | } /* if EMACK_RXCHL */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 890 | static int ppc_4xx_eth_rx (struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 891 | { |
| 892 | int length; |
| 893 | int user_index; |
| 894 | unsigned long msr; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 895 | EMAC_405_HW_PST hw_p = dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 896 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 897 | hw_p->is_receiving = 1; /* tell driver */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 898 | |
| 899 | for (;;) { |
| 900 | /* AS.HARNOIS |
| 901 | * use ring buffer and |
| 902 | * get index from rx buffer desciptor queue |
| 903 | */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 904 | user_index = hw_p->rx_ready[hw_p->rx_u_index]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 905 | if (user_index == -1) { |
| 906 | length = -1; |
| 907 | break; /* nothing received - leave for() loop */ |
| 908 | } |
| 909 | |
| 910 | msr = mfmsr (); |
| 911 | mtmsr (msr & ~(MSR_EE)); |
| 912 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 913 | length = hw_p->rx[user_index].data_len; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 914 | |
| 915 | /* Pass the packet up to the protocol layers. */ |
| 916 | /* NetReceive(NetRxPackets[rxIdx], length - 4); */ |
| 917 | /* NetReceive(NetRxPackets[i], length); */ |
| 918 | NetReceive (NetRxPackets[user_index], length - 4); |
| 919 | /* Free Recv Buffer */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 920 | hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 921 | /* Free rx buffer descriptor queue */ |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 922 | hw_p->rx_ready[hw_p->rx_u_index] = -1; |
| 923 | hw_p->rx_u_index++; |
| 924 | if (NUM_RX_BUFF == hw_p->rx_u_index) |
| 925 | hw_p->rx_u_index = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 926 | |
| 927 | #ifdef INFO_405_ENET |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 928 | hw_p->stats.pkts_handled++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 929 | #endif |
| 930 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 931 | mtmsr (msr); /* Enable IRQ's */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 932 | } |
| 933 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 934 | hw_p->is_receiving = 0; /* tell driver */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 935 | |
| 936 | return length; |
| 937 | } |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 938 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 939 | static int virgin = 0; |
| 940 | int ppc_4xx_eth_initialize (bd_t * bis) |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 941 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 942 | struct eth_device *dev; |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 943 | int eth_num = 0; |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 944 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 945 | EMAC_405_HW_PST hw = NULL; |
| 946 | |
| 947 | for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) { |
| 948 | |
| 949 | /* Allocate device structure */ |
| 950 | dev = (struct eth_device *) malloc (sizeof (*dev)); |
| 951 | if (dev == NULL) { |
| 952 | printf ("ppc_405x_eth_initialize: " |
| 953 | "Cannot allocate eth_device %d\n", eth_num); |
| 954 | return (-1); |
| 955 | } |
stroese | 7f77d16 | 2004-07-02 14:36:35 +0000 | [diff] [blame] | 956 | memset(dev, 0, sizeof(*dev)); |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 957 | /* Allocate our private use data */ |
| 958 | hw = (EMAC_405_HW_PST) malloc (sizeof (*hw)); |
| 959 | if (hw == NULL) { |
| 960 | printf ("ppc_405x_eth_initialize: " |
| 961 | "Cannot allocate private hw data for eth_device %d", |
| 962 | eth_num); |
| 963 | free (dev); |
| 964 | return (-1); |
| 965 | } |
stroese | 7f77d16 | 2004-07-02 14:36:35 +0000 | [diff] [blame] | 966 | memset(hw, 0, sizeof(*hw)); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 967 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 968 | switch (eth_num) { |
| 969 | case 0: |
| 970 | hw->hw_addr = 0; |
| 971 | memcpy (dev->enetaddr, bis->bi_enetaddr, 6); |
| 972 | break; |
| 973 | #if defined(CONFIG_NET_MULTI) |
| 974 | case 1: |
| 975 | hw->hw_addr = 0x100; |
| 976 | memcpy (dev->enetaddr, bis->bi_enet1addr, 6); |
| 977 | break; |
| 978 | #endif |
| 979 | default: |
| 980 | hw->hw_addr = 0; |
| 981 | memcpy (dev->enetaddr, bis->bi_enetaddr, 6); |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | hw->devnum = eth_num; |
| 986 | hw->print_speed = 1; |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 987 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 988 | sprintf (dev->name, "ppc_405x_eth%d", eth_num); |
| 989 | dev->priv = (void *) hw; |
| 990 | dev->init = ppc_4xx_eth_init; |
| 991 | dev->halt = ppc_4xx_eth_halt; |
| 992 | dev->send = ppc_4xx_eth_send; |
| 993 | dev->recv = ppc_4xx_eth_rx; |
| 994 | |
| 995 | if (0 == virgin) { |
| 996 | /* set the MAL IER ??? names may change with new spec ??? */ |
| 997 | mal_ier = |
| 998 | MAL_IER_DE | MAL_IER_NE | MAL_IER_TE | |
| 999 | MAL_IER_OPBE | MAL_IER_PLBE; |
| 1000 | mtdcr (malesr, 0xffffffff); /* clear pending interrupts */ |
| 1001 | mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */ |
| 1002 | mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */ |
| 1003 | mtdcr (malier, mal_ier); |
| 1004 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1005 | /* install MAL interrupt handler */ |
| 1006 | irq_install_handler (VECNUM_MS, |
| 1007 | (interrupt_handler_t *) enetInt, |
| 1008 | dev); |
| 1009 | irq_install_handler (VECNUM_MTE, |
| 1010 | (interrupt_handler_t *) enetInt, |
| 1011 | dev); |
| 1012 | irq_install_handler (VECNUM_MRE, |
| 1013 | (interrupt_handler_t *) enetInt, |
| 1014 | dev); |
| 1015 | irq_install_handler (VECNUM_TXDE, |
| 1016 | (interrupt_handler_t *) enetInt, |
| 1017 | dev); |
| 1018 | irq_install_handler (VECNUM_RXDE, |
| 1019 | (interrupt_handler_t *) enetInt, |
| 1020 | dev); |
| 1021 | virgin = 1; |
| 1022 | } |
| 1023 | |
| 1024 | #if defined(CONFIG_NET_MULTI) |
| 1025 | eth_register (dev); |
| 1026 | #else |
| 1027 | emac0_dev = dev; |
| 1028 | #endif |
| 1029 | |
| 1030 | } /* end for each supported device */ |
| 1031 | |
| 1032 | return (1); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1033 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1034 | |
| 1035 | #if !defined(CONFIG_NET_MULTI) |
| 1036 | void eth_halt (void) { |
| 1037 | if (emac0_dev) { |
| 1038 | ppc_4xx_eth_halt(emac0_dev); |
| 1039 | free(emac0_dev); |
| 1040 | emac0_dev = NULL; |
| 1041 | } |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | int eth_init (bd_t *bis) |
| 1045 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1046 | ppc_4xx_eth_initialize(bis); |
| 1047 | return(ppc_4xx_eth_init(emac0_dev, bis)); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1048 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1049 | |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1050 | int eth_send(volatile void *packet, int length) |
| 1051 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1052 | |
| 1053 | return (ppc_4xx_eth_send(emac0_dev, packet, length)); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | int eth_rx(void) |
| 1057 | { |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1058 | return (ppc_4xx_eth_rx(emac0_dev)); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 1059 | } |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1060 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1061 | |
wdenk | 2a6109c | 2004-06-06 23:53:59 +0000 | [diff] [blame] | 1062 | #endif /* CONFIG_405 */ |