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