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