wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
wdenk | d4ca31c | 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 | d9785c1 | 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 | 643d1ab | 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 | 3a473b2 | 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 | 682011f | 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 | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 39 | extern int eth_3com_initialize(bd_t*); |
| 40 | extern int fec_initialize(bd_t*); |
| 41 | extern int inca_switch_initialize(bd_t*); |
| 42 | extern int mpc5xxx_fec_initialize(bd_t*); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 43 | extern int mpc512x_fec_initialize(bd_t*); |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 44 | extern int mpc8220_fec_initialize(bd_t*); |
wdenk | 3a473b2 | 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 *); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | extern int natsemi_initialize(bd_t*); |
| 48 | extern int ns8382x_initialize(bd_t*); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | extern int pcnet_initialize(bd_t*); |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 50 | extern int plb2800_eth_initialize(bd_t*); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 51 | extern int ppc_4xx_eth_initialize(bd_t *); |
| 52 | extern int rtl8139_initialize(bd_t*); |
wdenk | a8bd82d | 2004-04-18 22:03:42 +0000 | [diff] [blame] | 53 | extern int rtl8169_initialize(bd_t*); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 54 | extern int scc_initialize(bd_t*); |
wdenk | 7152b1d | 2003-09-05 23:19:14 +0000 | [diff] [blame] | 55 | extern int skge_initialize(bd_t*); |
roy zang | d1927ce | 2006-11-02 19:08:55 +0800 | [diff] [blame] | 56 | extern int tsi108_eth_initialize(bd_t*); |
Roy Zang | 1f10310 | 2007-11-05 17:39:24 +0800 | [diff] [blame] | 57 | extern int uli526x_initialize(bd_t *); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 58 | extern int tsec_initialize(bd_t*, int, char *); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 59 | extern int npe_initialize(bd_t *); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 60 | extern int uec_initialize(int); |
Aubrey Li | 9fd437b | 2007-04-05 18:30:25 +0800 | [diff] [blame] | 61 | extern int bfin_EMAC_initialize(bd_t *); |
Haavard Skinnemoen | 9a24f47 | 2006-12-17 17:14:30 +0100 | [diff] [blame] | 62 | extern int atstk1000_eth_initialize(bd_t *); |
Haavard Skinnemoen | 6b44394 | 2007-04-14 17:11:49 +0200 | [diff] [blame] | 63 | extern int atngw100_eth_initialize(bd_t *); |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 64 | extern int mcffec_initialize(bd_t*); |
TsiChungLiew | 777d1ab | 2008-01-15 14:00:25 -0600 | [diff] [blame] | 65 | extern int mcdmafec_initialize(bd_t*); |
Stelian Pop | 20b197c | 2008-01-20 19:49:21 +0000 | [diff] [blame] | 66 | extern int at91cap9_eth_initialize(bd_t *); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | |
Rafal Jaworowski | f85b607 | 2007-12-27 18:19:02 +0100 | [diff] [blame] | 68 | #ifdef CONFIG_API |
| 69 | extern void (*push_packet)(volatile void *, int); |
| 70 | |
| 71 | static struct { |
| 72 | uchar data[PKTSIZE]; |
| 73 | int length; |
| 74 | } eth_rcv_bufs[PKTBUFSRX]; |
| 75 | |
| 76 | static unsigned int eth_rcv_current = 0, eth_rcv_last = 0; |
| 77 | #endif |
| 78 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | static struct eth_device *eth_devices, *eth_current; |
| 80 | |
| 81 | struct eth_device *eth_get_dev(void) |
| 82 | { |
| 83 | return eth_current; |
| 84 | } |
| 85 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 86 | struct eth_device *eth_get_dev_by_name(char *devname) |
| 87 | { |
| 88 | struct eth_device *dev, *target_dev; |
| 89 | |
| 90 | if (!eth_devices) |
| 91 | return NULL; |
| 92 | |
| 93 | dev = eth_devices; |
| 94 | target_dev = NULL; |
| 95 | do { |
| 96 | if (strcmp(devname, dev->name) == 0) { |
| 97 | target_dev = dev; |
| 98 | break; |
| 99 | } |
| 100 | dev = dev->next; |
| 101 | } while (dev != eth_devices); |
| 102 | |
| 103 | return target_dev; |
| 104 | } |
| 105 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | int eth_get_dev_index (void) |
| 107 | { |
| 108 | struct eth_device *dev; |
| 109 | int num = 0; |
| 110 | |
| 111 | if (!eth_devices) { |
| 112 | return (-1); |
| 113 | } |
| 114 | |
| 115 | for (dev = eth_devices; dev; dev = dev->next) { |
| 116 | if (dev == eth_current) |
| 117 | break; |
| 118 | ++num; |
| 119 | } |
| 120 | |
| 121 | if (dev) { |
| 122 | return (num); |
| 123 | } |
| 124 | |
| 125 | return (0); |
| 126 | } |
| 127 | |
| 128 | int eth_register(struct eth_device* dev) |
| 129 | { |
| 130 | struct eth_device *d; |
| 131 | |
| 132 | if (!eth_devices) { |
| 133 | eth_current = eth_devices = dev; |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 134 | #ifdef CONFIG_NET_MULTI |
| 135 | /* update current ethernet name */ |
| 136 | { |
| 137 | char *act = getenv("ethact"); |
| 138 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 139 | setenv("ethact", eth_current->name); |
| 140 | } |
| 141 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 142 | } else { |
| 143 | for (d=eth_devices; d->next!=eth_devices; d=d->next); |
| 144 | d->next = dev; |
| 145 | } |
| 146 | |
| 147 | dev->state = ETH_STATE_INIT; |
| 148 | dev->next = eth_devices; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | int eth_initialize(bd_t *bis) |
| 154 | { |
Shinya Kuribayashi | 5ca2d09 | 2007-11-19 20:27:04 +0900 | [diff] [blame] | 155 | char enetvar[32]; |
| 156 | unsigned char env_enetaddr[6]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 157 | int i, eth_number = 0; |
| 158 | char *tmp, *end; |
| 159 | |
| 160 | eth_devices = NULL; |
| 161 | eth_current = NULL; |
| 162 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 163 | show_boot_progress (64); |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 164 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 165 | miiphy_init(); |
| 166 | #endif |
| 167 | |
Stefan Roese | 1eac2a7 | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 168 | #if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 169 | mv6436x_eth_initialize(bis); |
| 170 | #endif |
Stefan Roese | 1eac2a7 | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 171 | #if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 172 | mv6446x_eth_initialize(bis); |
| 173 | #endif |
Wolfgang Denk | 7521af1 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 174 | #if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) && !defined(CONFIG_AP1000) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 175 | ppc_4xx_eth_initialize(bis); |
wdenk | a3ed399 | 2003-06-05 19:37:36 +0000 | [diff] [blame] | 176 | #endif |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 177 | #ifdef CONFIG_INCA_IP_SWITCH |
| 178 | inca_switch_initialize(bis); |
| 179 | #endif |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 180 | #ifdef CONFIG_PLB2800_ETHER |
| 181 | plb2800_eth_initialize(bis); |
| 182 | #endif |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 183 | #ifdef SCC_ENET |
| 184 | scc_initialize(bis); |
| 185 | #endif |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 186 | #if defined(CONFIG_MPC5xxx_FEC) |
| 187 | mpc5xxx_fec_initialize(bis); |
| 188 | #endif |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 189 | #if defined(CONFIG_MPC512x_FEC) |
| 190 | mpc512x_fec_initialize (bis); |
| 191 | #endif |
wdenk | 7680c14 | 2005-05-16 15:23:22 +0000 | [diff] [blame] | 192 | #if defined(CONFIG_MPC8220_FEC) |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 193 | mpc8220_fec_initialize(bis); |
| 194 | #endif |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 195 | #if defined(CONFIG_SK98) |
| 196 | skge_initialize(bis); |
| 197 | #endif |
Kim Phillips | 255a3577 | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 198 | #if defined(CONFIG_TSEC1) |
| 199 | tsec_initialize(bis, 0, CONFIG_TSEC1_NAME); |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 200 | #endif |
Kim Phillips | 255a3577 | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 201 | #if defined(CONFIG_TSEC2) |
| 202 | tsec_initialize(bis, 1, CONFIG_TSEC2_NAME); |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 203 | #endif |
| 204 | #if defined(CONFIG_MPC85XX_FEC) |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 205 | tsec_initialize(bis, 2, CONFIG_MPC85XX_FEC_NAME); |
| 206 | #else |
Kim Phillips | 255a3577 | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 207 | # if defined(CONFIG_TSEC3) |
| 208 | tsec_initialize(bis, 2, CONFIG_TSEC3_NAME); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 209 | # endif |
Kim Phillips | 255a3577 | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 210 | # if defined(CONFIG_TSEC4) |
| 211 | tsec_initialize(bis, 3, CONFIG_TSEC4_NAME); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 212 | # endif |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 213 | #endif |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 214 | #if defined(CONFIG_UEC_ETH1) |
| 215 | uec_initialize(0); |
| 216 | #endif |
| 217 | #if defined(CONFIG_UEC_ETH2) |
| 218 | uec_initialize(1); |
| 219 | #endif |
Joakim Tjernlund | ccf21c3 | 2007-12-06 16:43:40 +0100 | [diff] [blame] | 220 | #if defined(CONFIG_UEC_ETH3) |
| 221 | uec_initialize(2); |
| 222 | #endif |
David Saada | 2465665 | 2008-01-15 10:40:24 +0200 | [diff] [blame] | 223 | #if defined(CONFIG_UEC_ETH4) |
| 224 | uec_initialize(3); |
| 225 | #endif |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 226 | |
Stefan Roese | d96f41e | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 227 | #if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC) |
| 228 | fec_initialize(bis); |
| 229 | #endif |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 230 | #if defined(CONFIG_AU1X00) |
| 231 | au1x00_enet_initialize(bis); |
| 232 | #endif |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 233 | #if defined(CONFIG_IXP4XX_NPE) |
| 234 | npe_initialize(bis); |
| 235 | #endif |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 236 | #ifdef CONFIG_E1000 |
| 237 | e1000_initialize(bis); |
| 238 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 239 | #ifdef CONFIG_EEPRO100 |
| 240 | eepro100_initialize(bis); |
| 241 | #endif |
| 242 | #ifdef CONFIG_TULIP |
| 243 | dc21x4x_initialize(bis); |
| 244 | #endif |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 245 | #ifdef CONFIG_3COM |
| 246 | eth_3com_initialize(bis); |
| 247 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 248 | #ifdef CONFIG_PCNET |
| 249 | pcnet_initialize(bis); |
| 250 | #endif |
| 251 | #ifdef CFG_GT_6426x |
| 252 | gt6426x_eth_initialize(bis); |
| 253 | #endif |
| 254 | #ifdef CONFIG_NATSEMI |
| 255 | natsemi_initialize(bis); |
| 256 | #endif |
| 257 | #ifdef CONFIG_NS8382X |
| 258 | ns8382x_initialize(bis); |
| 259 | #endif |
roy zang | d1927ce | 2006-11-02 19:08:55 +0800 | [diff] [blame] | 260 | #if defined(CONFIG_TSI108_ETH) |
| 261 | tsi108_eth_initialize(bis); |
| 262 | #endif |
Roy Zang | 1f10310 | 2007-11-05 17:39:24 +0800 | [diff] [blame] | 263 | #if defined(CONFIG_ULI526X) |
| 264 | uli526x_initialize(bis); |
| 265 | #endif |
wdenk | 63f3491 | 2004-01-02 15:01:32 +0000 | [diff] [blame] | 266 | #if defined(CONFIG_RTL8139) |
| 267 | rtl8139_initialize(bis); |
| 268 | #endif |
wdenk | a8bd82d | 2004-04-18 22:03:42 +0000 | [diff] [blame] | 269 | #if defined(CONFIG_RTL8169) |
| 270 | rtl8169_initialize(bis); |
| 271 | #endif |
Aubrey Li | 9fd437b | 2007-04-05 18:30:25 +0800 | [diff] [blame] | 272 | #if defined(CONFIG_BF537) |
| 273 | bfin_EMAC_initialize(bis); |
| 274 | #endif |
Haavard Skinnemoen | 9a24f47 | 2006-12-17 17:14:30 +0100 | [diff] [blame] | 275 | #if defined(CONFIG_ATSTK1000) |
| 276 | atstk1000_eth_initialize(bis); |
| 277 | #endif |
Haavard Skinnemoen | 6b44394 | 2007-04-14 17:11:49 +0200 | [diff] [blame] | 278 | #if defined(CONFIG_ATNGW100) |
| 279 | atngw100_eth_initialize(bis); |
| 280 | #endif |
TsiChungLiew | 2870e98 | 2007-07-05 23:29:21 -0500 | [diff] [blame] | 281 | #if defined(CONFIG_MCFFEC) |
| 282 | mcffec_initialize(bis); |
| 283 | #endif |
TsiChungLiew | 777d1ab | 2008-01-15 14:00:25 -0600 | [diff] [blame] | 284 | #if defined(CONFIG_FSLDMAFEC) |
| 285 | mcdmafec_initialize(bis); |
| 286 | #endif |
Stelian Pop | 20b197c | 2008-01-20 19:49:21 +0000 | [diff] [blame] | 287 | #if defined(CONFIG_AT91CAP9) |
| 288 | at91cap9_eth_initialize(bis); |
| 289 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | |
| 291 | if (!eth_devices) { |
| 292 | puts ("No ethernet found.\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 293 | show_boot_progress (-64); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 294 | } else { |
| 295 | struct eth_device *dev = eth_devices; |
| 296 | char *ethprime = getenv ("ethprime"); |
| 297 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 298 | show_boot_progress (65); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 299 | do { |
| 300 | if (eth_number) |
| 301 | puts (", "); |
| 302 | |
| 303 | printf("%s", dev->name); |
| 304 | |
| 305 | if (ethprime && strcmp (dev->name, ethprime) == 0) { |
| 306 | eth_current = dev; |
| 307 | puts (" [PRIME]"); |
| 308 | } |
| 309 | |
| 310 | sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number); |
| 311 | tmp = getenv (enetvar); |
| 312 | |
| 313 | for (i=0; i<6; i++) { |
| 314 | env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; |
| 315 | if (tmp) |
| 316 | tmp = (*end) ? end+1 : end; |
| 317 | } |
| 318 | |
| 319 | if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) { |
| 320 | if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) && |
| 321 | memcmp(dev->enetaddr, env_enetaddr, 6)) |
| 322 | { |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 323 | printf ("\nWarning: %s MAC addresses don't match:\n", |
| 324 | dev->name); |
| 325 | printf ("Address in SROM is " |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 326 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 327 | dev->enetaddr[0], dev->enetaddr[1], |
| 328 | dev->enetaddr[2], dev->enetaddr[3], |
| 329 | dev->enetaddr[4], dev->enetaddr[5]); |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 330 | printf ("Address in environment is " |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 331 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 332 | env_enetaddr[0], env_enetaddr[1], |
| 333 | env_enetaddr[2], env_enetaddr[3], |
| 334 | env_enetaddr[4], env_enetaddr[5]); |
| 335 | } |
| 336 | |
| 337 | memcpy(dev->enetaddr, env_enetaddr, 6); |
| 338 | } |
| 339 | |
| 340 | eth_number++; |
| 341 | dev = dev->next; |
| 342 | } while(dev != eth_devices); |
| 343 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 344 | #ifdef CONFIG_NET_MULTI |
| 345 | /* update current ethernet name */ |
| 346 | if (eth_current) { |
| 347 | char *act = getenv("ethact"); |
| 348 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 349 | setenv("ethact", eth_current->name); |
| 350 | } else |
| 351 | setenv("ethact", NULL); |
| 352 | #endif |
| 353 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 354 | putc ('\n'); |
| 355 | } |
| 356 | |
| 357 | return eth_number; |
| 358 | } |
| 359 | |
| 360 | void eth_set_enetaddr(int num, char *addr) { |
| 361 | struct eth_device *dev; |
| 362 | unsigned char enetaddr[6]; |
| 363 | char *end; |
| 364 | int i; |
| 365 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 366 | debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr); |
| 367 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 368 | if (!eth_devices) |
| 369 | return; |
| 370 | |
| 371 | for (i=0; i<6; i++) { |
| 372 | enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; |
| 373 | if (addr) |
| 374 | addr = (*end) ? end+1 : end; |
| 375 | } |
| 376 | |
| 377 | dev = eth_devices; |
| 378 | while(num-- > 0) { |
| 379 | dev = dev->next; |
| 380 | |
| 381 | if (dev == eth_devices) |
| 382 | return; |
| 383 | } |
| 384 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 385 | debug ( "Setting new HW address on %s\n" |
| 386 | "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 387 | dev->name, |
Wolfgang Denk | a188b58 | 2005-09-25 17:05:57 +0200 | [diff] [blame] | 388 | enetaddr[0], enetaddr[1], |
| 389 | enetaddr[2], enetaddr[3], |
| 390 | enetaddr[4], enetaddr[5]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 391 | |
| 392 | memcpy(dev->enetaddr, enetaddr, 6); |
| 393 | } |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 394 | #ifdef CONFIG_MCAST_TFTP |
| 395 | /* Multicast. |
| 396 | * mcast_addr: multicast ipaddr from which multicast Mac is made |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 397 | * join: 1=join, 0=leave. |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 398 | */ |
| 399 | int eth_mcast_join( IPaddr_t mcast_ip, u8 join) |
| 400 | { |
| 401 | u8 mcast_mac[6]; |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 402 | if (!eth_current || !eth_current->mcast) |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 403 | return -1; |
| 404 | mcast_mac[5] = htonl(mcast_ip) & 0xff; |
| 405 | mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff; |
| 406 | mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f; |
| 407 | mcast_mac[2] = 0x5e; |
| 408 | mcast_mac[1] = 0x0; |
| 409 | mcast_mac[0] = 0x1; |
| 410 | return eth_current->mcast(eth_current, mcast_mac, join); |
| 411 | } |
| 412 | |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 413 | /* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c |
| 414 | * and this is the ethernet-crc method needed for TSEC -- and perhaps |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 415 | * some other adapter -- hash tables |
| 416 | */ |
| 417 | #define CRCPOLY_LE 0xedb88320 |
| 418 | u32 ether_crc (size_t len, unsigned char const *p) |
| 419 | { |
| 420 | int i; |
| 421 | u32 crc; |
| 422 | crc = ~0; |
| 423 | while (len--) { |
| 424 | crc ^= *p++; |
| 425 | for (i = 0; i < 8; i++) |
| 426 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
| 427 | } |
| 428 | /* an reverse the bits, cuz of way they arrive -- last-first */ |
| 429 | crc = (crc >> 16) | (crc << 16); |
| 430 | crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00); |
| 431 | crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0); |
| 432 | crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc); |
| 433 | crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa); |
| 434 | return crc; |
| 435 | } |
| 436 | |
| 437 | #endif |
| 438 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 439 | |
| 440 | int eth_init(bd_t *bis) |
| 441 | { |
| 442 | struct eth_device* old_current; |
| 443 | |
| 444 | if (!eth_current) |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 445 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 446 | |
| 447 | old_current = eth_current; |
| 448 | do { |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 449 | debug ("Trying %s\n", eth_current->name); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 450 | |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 451 | if (eth_current->init(eth_current,bis) >= 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | eth_current->state = ETH_STATE_ACTIVE; |
| 453 | |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 454 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 455 | } |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 456 | debug ("FAIL\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 457 | |
| 458 | eth_try_another(0); |
| 459 | } while (old_current != eth_current); |
| 460 | |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 461 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void eth_halt(void) |
| 465 | { |
| 466 | if (!eth_current) |
| 467 | return; |
| 468 | |
| 469 | eth_current->halt(eth_current); |
| 470 | |
| 471 | eth_current->state = ETH_STATE_PASSIVE; |
| 472 | } |
| 473 | |
| 474 | int eth_send(volatile void *packet, int length) |
| 475 | { |
| 476 | if (!eth_current) |
| 477 | return -1; |
| 478 | |
| 479 | return eth_current->send(eth_current, packet, length); |
| 480 | } |
| 481 | |
| 482 | int eth_rx(void) |
| 483 | { |
| 484 | if (!eth_current) |
| 485 | return -1; |
| 486 | |
| 487 | return eth_current->recv(eth_current); |
| 488 | } |
| 489 | |
Rafal Jaworowski | f85b607 | 2007-12-27 18:19:02 +0100 | [diff] [blame] | 490 | #ifdef CONFIG_API |
| 491 | static void eth_save_packet(volatile void *packet, int length) |
| 492 | { |
| 493 | volatile char *p = packet; |
| 494 | int i; |
| 495 | |
| 496 | if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current) |
| 497 | return; |
| 498 | |
| 499 | if (PKTSIZE < length) |
| 500 | return; |
| 501 | |
| 502 | for (i = 0; i < length; i++) |
| 503 | eth_rcv_bufs[eth_rcv_last].data[i] = p[i]; |
| 504 | |
| 505 | eth_rcv_bufs[eth_rcv_last].length = length; |
| 506 | eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX; |
| 507 | } |
| 508 | |
| 509 | int eth_receive(volatile void *packet, int length) |
| 510 | { |
| 511 | volatile char *p = packet; |
| 512 | void *pp = push_packet; |
| 513 | int i; |
| 514 | |
| 515 | if (eth_rcv_current == eth_rcv_last) { |
| 516 | push_packet = eth_save_packet; |
| 517 | eth_rx(); |
| 518 | push_packet = pp; |
| 519 | |
| 520 | if (eth_rcv_current == eth_rcv_last) |
| 521 | return -1; |
| 522 | } |
| 523 | |
| 524 | if (length < eth_rcv_bufs[eth_rcv_current].length) |
| 525 | return -1; |
| 526 | |
| 527 | length = eth_rcv_bufs[eth_rcv_current].length; |
| 528 | |
| 529 | for (i = 0; i < length; i++) |
| 530 | p[i] = eth_rcv_bufs[eth_rcv_current].data[i]; |
| 531 | |
| 532 | eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX; |
| 533 | return length; |
| 534 | } |
| 535 | #endif /* CONFIG_API */ |
| 536 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 537 | void eth_try_another(int first_restart) |
| 538 | { |
| 539 | static struct eth_device *first_failed = NULL; |
Matthias Fuchs | e169257 | 2008-01-17 07:45:05 +0100 | [diff] [blame] | 540 | char *ethrotate; |
| 541 | |
| 542 | /* |
| 543 | * Do not rotate between network interfaces when |
| 544 | * 'ethrotate' variable is set to 'no'. |
| 545 | */ |
| 546 | if (((ethrotate = getenv ("ethrotate")) != NULL) && |
| 547 | (strcmp(ethrotate, "no") == 0)) |
| 548 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 549 | |
| 550 | if (!eth_current) |
| 551 | return; |
| 552 | |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 553 | if (first_restart) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 554 | first_failed = eth_current; |
| 555 | } |
| 556 | |
| 557 | eth_current = eth_current->next; |
| 558 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 559 | #ifdef CONFIG_NET_MULTI |
| 560 | /* update current ethernet name */ |
| 561 | { |
| 562 | char *act = getenv("ethact"); |
| 563 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 564 | setenv("ethact", eth_current->name); |
| 565 | } |
| 566 | #endif |
| 567 | |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 568 | if (first_failed == eth_current) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 569 | NetRestartWrap = 1; |
| 570 | } |
| 571 | } |
| 572 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 573 | #ifdef CONFIG_NET_MULTI |
| 574 | void eth_set_current(void) |
| 575 | { |
| 576 | char *act; |
| 577 | struct eth_device* old_current; |
| 578 | |
| 579 | if (!eth_current) /* XXX no current */ |
| 580 | return; |
| 581 | |
| 582 | act = getenv("ethact"); |
| 583 | if (act != NULL) { |
| 584 | old_current = eth_current; |
| 585 | do { |
| 586 | if (strcmp(eth_current->name, act) == 0) |
| 587 | return; |
| 588 | eth_current = eth_current->next; |
| 589 | } while (old_current != eth_current); |
| 590 | } |
| 591 | |
| 592 | setenv("ethact", eth_current->name); |
| 593 | } |
| 594 | #endif |
| 595 | |
wdenk | 5bb226e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 596 | char *eth_get_name (void) |
| 597 | { |
| 598 | return (eth_current ? eth_current->name : "unknown"); |
| 599 | } |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 600 | #elif defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 601 | |
| 602 | extern int at91rm9200_miiphy_initialize(bd_t *bis); |
| 603 | extern int emac4xx_miiphy_initialize(bd_t *bis); |
| 604 | extern int mcf52x2_miiphy_initialize(bd_t *bis); |
| 605 | extern int ns7520_miiphy_initialize(bd_t *bis); |
Sergey Kubushyn | c74b210 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 606 | extern int dm644x_eth_miiphy_initialize(bd_t *bis); |
| 607 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 608 | |
| 609 | int eth_initialize(bd_t *bis) |
| 610 | { |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 611 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 612 | miiphy_init(); |
| 613 | #endif |
| 614 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 615 | #if defined(CONFIG_AT91RM9200) |
| 616 | at91rm9200_miiphy_initialize(bis); |
| 617 | #endif |
| 618 | #if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) \ |
| 619 | && !defined(CONFIG_AP1000) && !defined(CONFIG_405) |
| 620 | emac4xx_miiphy_initialize(bis); |
| 621 | #endif |
| 622 | #if defined(CONFIG_MCF52x2) |
| 623 | mcf52x2_miiphy_initialize(bis); |
| 624 | #endif |
| 625 | #if defined(CONFIG_NETARM) |
| 626 | ns7520_miiphy_initialize(bis); |
| 627 | #endif |
Sergey Kubushyn | c74b210 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 628 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 629 | dm644x_eth_miiphy_initialize(bis); |
| 630 | #endif |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 631 | return 0; |
| 632 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 633 | #endif |