wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 2 | * (C) Copyright 2001-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <net.h> |
Marian Balakowicz | cbdd1c8 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 27 | #include <miiphy.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 29 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | |
| 31 | #ifdef CFG_GT_6426x |
| 32 | extern int gt6426x_eth_initialize(bd_t *bis); |
| 33 | #endif |
| 34 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 35 | extern int au1x00_enet_initialize(bd_t*); |
| 36 | extern int dc21x4x_initialize(bd_t*); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 37 | extern int e1000_initialize(bd_t*); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 38 | extern int eepro100_initialize(bd_t*); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 39 | extern int eth_3com_initialize(bd_t*); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 40 | extern int fec_initialize(bd_t*); |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 41 | extern int inca_switch_initialize(bd_t*); |
wdenk | 21136db | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 42 | extern int mpc5xxx_fec_initialize(bd_t*); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 43 | extern int mpc512x_fec_initialize(bd_t*); |
wdenk | 337f565 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 44 | extern int mpc8220_fec_initialize(bd_t*); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 45 | extern int mv6436x_eth_initialize(bd_t *); |
| 46 | extern int mv6446x_eth_initialize(bd_t *); |
| 47 | extern int natsemi_initialize(bd_t*); |
| 48 | extern int ns8382x_initialize(bd_t*); |
| 49 | extern int pcnet_initialize(bd_t*); |
| 50 | extern int plb2800_eth_initialize(bd_t*); |
| 51 | extern int ppc_4xx_eth_initialize(bd_t *); |
| 52 | extern int rtl8139_initialize(bd_t*); |
wdenk | a627048 | 2004-04-18 22:03:42 +0000 | [diff] [blame] | 53 | extern int rtl8169_initialize(bd_t*); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 54 | extern int scc_initialize(bd_t*); |
wdenk | eb20ad3 | 2003-09-05 23:19:14 +0000 | [diff] [blame] | 55 | extern int skge_initialize(bd_t*); |
roy zang | 72526f7 | 2006-11-02 19:08:55 +0800 | [diff] [blame] | 56 | extern int tsi108_eth_initialize(bd_t*); |
Roy Zang | 9976223 | 2007-11-05 17:39:24 +0800 | [diff] [blame] | 57 | extern int uli526x_initialize(bd_t *); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 58 | extern int tsec_initialize(bd_t*, int, char *); |
Wolfgang Denk | 4646d2a | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 59 | extern int npe_initialize(bd_t *); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 60 | extern int uec_initialize(int); |
Aubrey Li | 570dc1e | 2007-04-05 18:30:25 +0800 | [diff] [blame] | 61 | extern int bfin_EMAC_initialize(bd_t *); |
Haavard Skinnemoen | 58f4c26 | 2006-12-17 17:14:30 +0100 | [diff] [blame] | 62 | extern int atstk1000_eth_initialize(bd_t *); |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 63 | extern int mcffec_initialize(bd_t*); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 64 | |
| 65 | static struct eth_device *eth_devices, *eth_current; |
| 66 | |
| 67 | struct eth_device *eth_get_dev(void) |
| 68 | { |
| 69 | return eth_current; |
| 70 | } |
| 71 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 72 | struct eth_device *eth_get_dev_by_name(char *devname) |
| 73 | { |
| 74 | struct eth_device *dev, *target_dev; |
| 75 | |
| 76 | if (!eth_devices) |
| 77 | return NULL; |
| 78 | |
| 79 | dev = eth_devices; |
| 80 | target_dev = NULL; |
| 81 | do { |
| 82 | if (strcmp(devname, dev->name) == 0) { |
| 83 | target_dev = dev; |
| 84 | break; |
| 85 | } |
| 86 | dev = dev->next; |
| 87 | } while (dev != eth_devices); |
| 88 | |
| 89 | return target_dev; |
| 90 | } |
| 91 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | int eth_get_dev_index (void) |
| 93 | { |
| 94 | struct eth_device *dev; |
| 95 | int num = 0; |
| 96 | |
| 97 | if (!eth_devices) { |
| 98 | return (-1); |
| 99 | } |
| 100 | |
| 101 | for (dev = eth_devices; dev; dev = dev->next) { |
| 102 | if (dev == eth_current) |
| 103 | break; |
| 104 | ++num; |
| 105 | } |
| 106 | |
| 107 | if (dev) { |
| 108 | return (num); |
| 109 | } |
| 110 | |
| 111 | return (0); |
| 112 | } |
| 113 | |
| 114 | int eth_register(struct eth_device* dev) |
| 115 | { |
| 116 | struct eth_device *d; |
| 117 | |
| 118 | if (!eth_devices) { |
| 119 | eth_current = eth_devices = dev; |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 120 | #ifdef CONFIG_NET_MULTI |
| 121 | /* update current ethernet name */ |
| 122 | { |
| 123 | char *act = getenv("ethact"); |
| 124 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 125 | setenv("ethact", eth_current->name); |
| 126 | } |
| 127 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | } else { |
| 129 | for (d=eth_devices; d->next!=eth_devices; d=d->next); |
| 130 | d->next = dev; |
| 131 | } |
| 132 | |
| 133 | dev->state = ETH_STATE_INIT; |
| 134 | dev->next = eth_devices; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | int eth_initialize(bd_t *bis) |
| 140 | { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 141 | char enetvar[32], env_enetaddr[6]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 142 | int i, eth_number = 0; |
| 143 | char *tmp, *end; |
| 144 | |
| 145 | eth_devices = NULL; |
| 146 | eth_current = NULL; |
| 147 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 148 | show_boot_progress (64); |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 149 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | cbdd1c8 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 150 | miiphy_init(); |
| 151 | #endif |
| 152 | |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 153 | #if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 154 | mv6436x_eth_initialize(bis); |
| 155 | #endif |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 156 | #if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 157 | mv6446x_eth_initialize(bis); |
| 158 | #endif |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 159 | #if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) && !defined(CONFIG_AP1000) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | ppc_4xx_eth_initialize(bis); |
wdenk | 7793444 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 161 | #endif |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 162 | #ifdef CONFIG_INCA_IP_SWITCH |
| 163 | inca_switch_initialize(bis); |
| 164 | #endif |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 165 | #ifdef CONFIG_PLB2800_ETHER |
| 166 | plb2800_eth_initialize(bis); |
| 167 | #endif |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 168 | #ifdef SCC_ENET |
| 169 | scc_initialize(bis); |
| 170 | #endif |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 171 | #if defined(CONFIG_MPC5xxx_FEC) |
| 172 | mpc5xxx_fec_initialize(bis); |
| 173 | #endif |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 174 | #if defined(CONFIG_MPC512x_FEC) |
| 175 | mpc512x_fec_initialize (bis); |
| 176 | #endif |
wdenk | 5c71a7a | 2005-05-16 15:23:22 +0000 | [diff] [blame] | 177 | #if defined(CONFIG_MPC8220_FEC) |
wdenk | 337f565 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 178 | mpc8220_fec_initialize(bis); |
| 179 | #endif |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 180 | #if defined(CONFIG_SK98) |
| 181 | skge_initialize(bis); |
| 182 | #endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 183 | #if defined(CONFIG_TSEC1) |
| 184 | tsec_initialize(bis, 0, CONFIG_TSEC1_NAME); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 185 | #endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 186 | #if defined(CONFIG_TSEC2) |
| 187 | tsec_initialize(bis, 1, CONFIG_TSEC2_NAME); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 188 | #endif |
| 189 | #if defined(CONFIG_MPC85XX_FEC) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 190 | tsec_initialize(bis, 2, CONFIG_MPC85XX_FEC_NAME); |
| 191 | #else |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 192 | # if defined(CONFIG_TSEC3) |
| 193 | tsec_initialize(bis, 2, CONFIG_TSEC3_NAME); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 194 | # endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 195 | # if defined(CONFIG_TSEC4) |
| 196 | tsec_initialize(bis, 3, CONFIG_TSEC4_NAME); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 197 | # endif |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 198 | #endif |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 199 | #if defined(CONFIG_UEC_ETH1) |
| 200 | uec_initialize(0); |
| 201 | #endif |
| 202 | #if defined(CONFIG_UEC_ETH2) |
| 203 | uec_initialize(1); |
| 204 | #endif |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 205 | |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 206 | #if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC) |
| 207 | fec_initialize(bis); |
| 208 | #endif |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 209 | #if defined(CONFIG_AU1X00) |
| 210 | au1x00_enet_initialize(bis); |
| 211 | #endif |
Wolfgang Denk | 4646d2a | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 212 | #if defined(CONFIG_IXP4XX_NPE) |
| 213 | npe_initialize(bis); |
| 214 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 215 | #ifdef CONFIG_E1000 |
| 216 | e1000_initialize(bis); |
| 217 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 218 | #ifdef CONFIG_EEPRO100 |
| 219 | eepro100_initialize(bis); |
| 220 | #endif |
| 221 | #ifdef CONFIG_TULIP |
| 222 | dc21x4x_initialize(bis); |
| 223 | #endif |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 224 | #ifdef CONFIG_3COM |
| 225 | eth_3com_initialize(bis); |
| 226 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 227 | #ifdef CONFIG_PCNET |
| 228 | pcnet_initialize(bis); |
| 229 | #endif |
| 230 | #ifdef CFG_GT_6426x |
| 231 | gt6426x_eth_initialize(bis); |
| 232 | #endif |
| 233 | #ifdef CONFIG_NATSEMI |
| 234 | natsemi_initialize(bis); |
| 235 | #endif |
| 236 | #ifdef CONFIG_NS8382X |
| 237 | ns8382x_initialize(bis); |
| 238 | #endif |
roy zang | 72526f7 | 2006-11-02 19:08:55 +0800 | [diff] [blame] | 239 | #if defined(CONFIG_TSI108_ETH) |
| 240 | tsi108_eth_initialize(bis); |
| 241 | #endif |
Roy Zang | 9976223 | 2007-11-05 17:39:24 +0800 | [diff] [blame] | 242 | #if defined(CONFIG_ULI526X) |
| 243 | uli526x_initialize(bis); |
| 244 | #endif |
wdenk | 0260cd6 | 2004-01-02 15:01:32 +0000 | [diff] [blame] | 245 | #if defined(CONFIG_RTL8139) |
| 246 | rtl8139_initialize(bis); |
| 247 | #endif |
wdenk | a627048 | 2004-04-18 22:03:42 +0000 | [diff] [blame] | 248 | #if defined(CONFIG_RTL8169) |
| 249 | rtl8169_initialize(bis); |
| 250 | #endif |
Aubrey Li | 570dc1e | 2007-04-05 18:30:25 +0800 | [diff] [blame] | 251 | #if defined(CONFIG_BF537) |
| 252 | bfin_EMAC_initialize(bis); |
| 253 | #endif |
Haavard Skinnemoen | 58f4c26 | 2006-12-17 17:14:30 +0100 | [diff] [blame] | 254 | #if defined(CONFIG_ATSTK1000) |
| 255 | atstk1000_eth_initialize(bis); |
| 256 | #endif |
TsiChungLiew | 507bd71 | 2007-07-05 23:29:21 -0500 | [diff] [blame] | 257 | #if defined(CONFIG_MCFFEC) |
| 258 | mcffec_initialize(bis); |
| 259 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | |
| 261 | if (!eth_devices) { |
| 262 | puts ("No ethernet found.\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 263 | show_boot_progress (-64); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | } else { |
| 265 | struct eth_device *dev = eth_devices; |
| 266 | char *ethprime = getenv ("ethprime"); |
| 267 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 268 | show_boot_progress (65); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | do { |
| 270 | if (eth_number) |
| 271 | puts (", "); |
| 272 | |
| 273 | printf("%s", dev->name); |
| 274 | |
| 275 | if (ethprime && strcmp (dev->name, ethprime) == 0) { |
| 276 | eth_current = dev; |
| 277 | puts (" [PRIME]"); |
| 278 | } |
| 279 | |
| 280 | sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number); |
| 281 | tmp = getenv (enetvar); |
| 282 | |
| 283 | for (i=0; i<6; i++) { |
| 284 | env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; |
| 285 | if (tmp) |
| 286 | tmp = (*end) ? end+1 : end; |
| 287 | } |
| 288 | |
| 289 | if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) { |
| 290 | if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) && |
| 291 | memcmp(dev->enetaddr, env_enetaddr, 6)) |
| 292 | { |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 293 | printf ("\nWarning: %s MAC addresses don't match:\n", |
| 294 | dev->name); |
| 295 | printf ("Address in SROM is " |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 296 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 297 | dev->enetaddr[0], dev->enetaddr[1], |
| 298 | dev->enetaddr[2], dev->enetaddr[3], |
| 299 | dev->enetaddr[4], dev->enetaddr[5]); |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 300 | printf ("Address in environment is " |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 301 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 302 | env_enetaddr[0], env_enetaddr[1], |
| 303 | env_enetaddr[2], env_enetaddr[3], |
| 304 | env_enetaddr[4], env_enetaddr[5]); |
| 305 | } |
| 306 | |
| 307 | memcpy(dev->enetaddr, env_enetaddr, 6); |
| 308 | } |
| 309 | |
| 310 | eth_number++; |
| 311 | dev = dev->next; |
| 312 | } while(dev != eth_devices); |
| 313 | |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 314 | #ifdef CONFIG_NET_MULTI |
| 315 | /* update current ethernet name */ |
| 316 | if (eth_current) { |
| 317 | char *act = getenv("ethact"); |
| 318 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 319 | setenv("ethact", eth_current->name); |
| 320 | } else |
| 321 | setenv("ethact", NULL); |
| 322 | #endif |
| 323 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 324 | putc ('\n'); |
| 325 | } |
| 326 | |
| 327 | return eth_number; |
| 328 | } |
| 329 | |
| 330 | void eth_set_enetaddr(int num, char *addr) { |
| 331 | struct eth_device *dev; |
| 332 | unsigned char enetaddr[6]; |
| 333 | char *end; |
| 334 | int i; |
| 335 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 336 | debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr); |
| 337 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 338 | if (!eth_devices) |
| 339 | return; |
| 340 | |
| 341 | for (i=0; i<6; i++) { |
| 342 | enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; |
| 343 | if (addr) |
| 344 | addr = (*end) ? end+1 : end; |
| 345 | } |
| 346 | |
| 347 | dev = eth_devices; |
| 348 | while(num-- > 0) { |
| 349 | dev = dev->next; |
| 350 | |
| 351 | if (dev == eth_devices) |
| 352 | return; |
| 353 | } |
| 354 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 355 | debug ( "Setting new HW address on %s\n" |
| 356 | "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 357 | dev->name, |
Wolfgang Denk | b6ea630 | 2005-09-25 17:05:57 +0200 | [diff] [blame] | 358 | enetaddr[0], enetaddr[1], |
| 359 | enetaddr[2], enetaddr[3], |
| 360 | enetaddr[4], enetaddr[5]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 361 | |
| 362 | memcpy(dev->enetaddr, enetaddr, 6); |
| 363 | } |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 364 | #ifdef CONFIG_MCAST_TFTP |
| 365 | /* Multicast. |
| 366 | * mcast_addr: multicast ipaddr from which multicast Mac is made |
Wolfgang Denk | 627f5c3 | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 367 | * join: 1=join, 0=leave. |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 368 | */ |
| 369 | int eth_mcast_join( IPaddr_t mcast_ip, u8 join) |
| 370 | { |
| 371 | u8 mcast_mac[6]; |
Wolfgang Denk | 627f5c3 | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 372 | if (!eth_current || !eth_current->mcast) |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 373 | return -1; |
| 374 | mcast_mac[5] = htonl(mcast_ip) & 0xff; |
| 375 | mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff; |
| 376 | mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f; |
| 377 | mcast_mac[2] = 0x5e; |
| 378 | mcast_mac[1] = 0x0; |
| 379 | mcast_mac[0] = 0x1; |
| 380 | return eth_current->mcast(eth_current, mcast_mac, join); |
| 381 | } |
| 382 | |
Wolfgang Denk | 627f5c3 | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 383 | /* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c |
| 384 | * and this is the ethernet-crc method needed for TSEC -- and perhaps |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 385 | * some other adapter -- hash tables |
| 386 | */ |
| 387 | #define CRCPOLY_LE 0xedb88320 |
| 388 | u32 ether_crc (size_t len, unsigned char const *p) |
| 389 | { |
| 390 | int i; |
| 391 | u32 crc; |
| 392 | crc = ~0; |
| 393 | while (len--) { |
| 394 | crc ^= *p++; |
| 395 | for (i = 0; i < 8; i++) |
| 396 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
| 397 | } |
| 398 | /* an reverse the bits, cuz of way they arrive -- last-first */ |
| 399 | crc = (crc >> 16) | (crc << 16); |
| 400 | crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00); |
| 401 | crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0); |
| 402 | crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc); |
| 403 | crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa); |
| 404 | return crc; |
| 405 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 406 | |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 407 | #endif |
| 408 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 409 | |
| 410 | int eth_init(bd_t *bis) |
| 411 | { |
| 412 | struct eth_device* old_current; |
| 413 | |
| 414 | if (!eth_current) |
| 415 | return 0; |
| 416 | |
| 417 | old_current = eth_current; |
| 418 | do { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 419 | debug ("Trying %s\n", eth_current->name); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | |
| 421 | if (eth_current->init(eth_current, bis)) { |
| 422 | eth_current->state = ETH_STATE_ACTIVE; |
| 423 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 424 | return 1; |
| 425 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 426 | debug ("FAIL\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 427 | |
| 428 | eth_try_another(0); |
| 429 | } while (old_current != eth_current); |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | void eth_halt(void) |
| 435 | { |
| 436 | if (!eth_current) |
| 437 | return; |
| 438 | |
| 439 | eth_current->halt(eth_current); |
| 440 | |
| 441 | eth_current->state = ETH_STATE_PASSIVE; |
| 442 | } |
| 443 | |
| 444 | int eth_send(volatile void *packet, int length) |
| 445 | { |
| 446 | if (!eth_current) |
| 447 | return -1; |
| 448 | |
| 449 | return eth_current->send(eth_current, packet, length); |
| 450 | } |
| 451 | |
| 452 | int eth_rx(void) |
| 453 | { |
| 454 | if (!eth_current) |
| 455 | return -1; |
| 456 | |
| 457 | return eth_current->recv(eth_current); |
| 458 | } |
| 459 | |
| 460 | void eth_try_another(int first_restart) |
| 461 | { |
| 462 | static struct eth_device *first_failed = NULL; |
| 463 | |
| 464 | if (!eth_current) |
| 465 | return; |
| 466 | |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 467 | if (first_restart) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 468 | first_failed = eth_current; |
| 469 | } |
| 470 | |
| 471 | eth_current = eth_current->next; |
| 472 | |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 473 | #ifdef CONFIG_NET_MULTI |
| 474 | /* update current ethernet name */ |
| 475 | { |
| 476 | char *act = getenv("ethact"); |
| 477 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 478 | setenv("ethact", eth_current->name); |
| 479 | } |
| 480 | #endif |
| 481 | |
wdenk | 63a10be | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 482 | if (first_failed == eth_current) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 483 | NetRestartWrap = 1; |
| 484 | } |
| 485 | } |
| 486 | |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 487 | #ifdef CONFIG_NET_MULTI |
| 488 | void eth_set_current(void) |
| 489 | { |
| 490 | char *act; |
| 491 | struct eth_device* old_current; |
| 492 | |
| 493 | if (!eth_current) /* XXX no current */ |
| 494 | return; |
| 495 | |
| 496 | act = getenv("ethact"); |
| 497 | if (act != NULL) { |
| 498 | old_current = eth_current; |
| 499 | do { |
| 500 | if (strcmp(eth_current->name, act) == 0) |
| 501 | return; |
| 502 | eth_current = eth_current->next; |
| 503 | } while (old_current != eth_current); |
| 504 | } |
| 505 | |
| 506 | setenv("ethact", eth_current->name); |
| 507 | } |
| 508 | #endif |
| 509 | |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 510 | char *eth_get_name (void) |
| 511 | { |
| 512 | return (eth_current ? eth_current->name : "unknown"); |
| 513 | } |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 514 | #elif defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 515 | |
| 516 | extern int at91rm9200_miiphy_initialize(bd_t *bis); |
| 517 | extern int emac4xx_miiphy_initialize(bd_t *bis); |
| 518 | extern int mcf52x2_miiphy_initialize(bd_t *bis); |
| 519 | extern int ns7520_miiphy_initialize(bd_t *bis); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 520 | extern int dm644x_eth_miiphy_initialize(bd_t *bis); |
| 521 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 522 | |
| 523 | int eth_initialize(bd_t *bis) |
| 524 | { |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 525 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | cbdd1c8 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 526 | miiphy_init(); |
| 527 | #endif |
| 528 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 529 | #if defined(CONFIG_AT91RM9200) |
| 530 | at91rm9200_miiphy_initialize(bis); |
| 531 | #endif |
| 532 | #if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) \ |
| 533 | && !defined(CONFIG_AP1000) && !defined(CONFIG_405) |
| 534 | emac4xx_miiphy_initialize(bis); |
| 535 | #endif |
| 536 | #if defined(CONFIG_MCF52x2) |
| 537 | mcf52x2_miiphy_initialize(bis); |
| 538 | #endif |
| 539 | #if defined(CONFIG_NETARM) |
| 540 | ns7520_miiphy_initialize(bis); |
| 541 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 542 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 543 | dm644x_eth_miiphy_initialize(bis); |
| 544 | #endif |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 545 | return 0; |
| 546 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 547 | #endif |