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