wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /*------------------------------------------------------------------------ |
| 2 | . smc91111.c |
| 3 | . This is a driver for SMSC's 91C111 single-chip Ethernet device. |
| 4 | . |
| 5 | . (C) Copyright 2002 |
| 6 | . Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | . Rolf Offermanns <rof@sysgo.de> |
| 8 | . |
| 9 | . Copyright (C) 2001 Standard Microsystems Corporation (SMSC) |
| 10 | . Developed by Simple Network Magic Corporation (SNMC) |
| 11 | . Copyright (C) 1996 by Erik Stahlman (ES) |
| 12 | . |
| 13 | . This program is free software; you can redistribute it and/or modify |
| 14 | . it under the terms of the GNU General Public License as published by |
| 15 | . the Free Software Foundation; either version 2 of the License, or |
| 16 | . (at your option) any later version. |
| 17 | . |
| 18 | . This program is distributed in the hope that it will be useful, |
| 19 | . but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | . GNU General Public License for more details. |
| 22 | . |
| 23 | . You should have received a copy of the GNU General Public License |
| 24 | . along with this program; if not, write to the Free Software |
| 25 | . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | . |
| 27 | . Information contained in this file was obtained from the LAN91C111 |
| 28 | . manual from SMC. To get a copy, if you really want one, you can find |
| 29 | . information under www.smsc.com. |
| 30 | . |
| 31 | . |
| 32 | . "Features" of the SMC chip: |
| 33 | . Integrated PHY/MAC for 10/100BaseT Operation |
| 34 | . Supports internal and external MII |
| 35 | . Integrated 8K packet memory |
| 36 | . EEPROM interface for configuration |
| 37 | . |
| 38 | . Arguments: |
| 39 | . io = for the base address |
| 40 | . irq = for the IRQ |
| 41 | . |
| 42 | . author: |
| 43 | . Erik Stahlman ( erik@vt.edu ) |
| 44 | . Daris A Nevil ( dnevil@snmc.com ) |
| 45 | . |
| 46 | . |
| 47 | . Hardware multicast code from Peter Cammaert ( pc@denkart.be ) |
| 48 | . |
| 49 | . Sources: |
| 50 | . o SMSC LAN91C111 databook (www.smsc.com) |
| 51 | . o smc9194.c by Erik Stahlman |
| 52 | . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov ) |
| 53 | . |
| 54 | . History: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | . 06/19/03 Richard Woodruff Made u-boot environment aware and added mac addr checks. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 56 | . 10/17/01 Marco Hasewinkel Modify for DNP/1110 |
| 57 | . 07/25/01 Woojung Huh Modify for ADS Bitsy |
| 58 | . 04/25/01 Daris A Nevil Initial public release through SMSC |
| 59 | . 03/16/01 Daris A Nevil Modified smc9194.c for use with LAN91C111 |
| 60 | ----------------------------------------------------------------------------*/ |
| 61 | |
| 62 | #include <common.h> |
| 63 | #include <command.h> |
| 64 | #include "smc91111.h" |
| 65 | #include <net.h> |
| 66 | |
| 67 | #ifdef CONFIG_DRIVER_SMC91111 |
| 68 | |
| 69 | /* Use power-down feature of the chip */ |
| 70 | #define POWER_DOWN 0 |
| 71 | |
| 72 | #define NO_AUTOPROBE |
| 73 | |
| 74 | static const char version[] = |
| 75 | "smc91111.c:v1.0 04/25/01 by Daris A Nevil (dnevil@snmc.com)\n"; |
| 76 | |
| 77 | #define SMC_DEBUG 0 |
| 78 | |
| 79 | /*------------------------------------------------------------------------ |
| 80 | . |
| 81 | . Configuration options, for the experienced user to change. |
| 82 | . |
| 83 | -------------------------------------------------------------------------*/ |
| 84 | |
| 85 | /* |
| 86 | . Wait time for memory to be free. This probably shouldn't be |
| 87 | . tuned that much, as waiting for this means nothing else happens |
| 88 | . in the system |
| 89 | */ |
| 90 | #define MEMORY_WAIT_TIME 16 |
| 91 | |
| 92 | |
| 93 | #if (SMC_DEBUG > 2 ) |
| 94 | #define PRINTK3(args...) printf(args) |
| 95 | #else |
| 96 | #define PRINTK3(args...) |
| 97 | #endif |
| 98 | |
| 99 | #if SMC_DEBUG > 1 |
| 100 | #define PRINTK2(args...) printf(args) |
| 101 | #else |
| 102 | #define PRINTK2(args...) |
| 103 | #endif |
| 104 | |
| 105 | #ifdef SMC_DEBUG |
| 106 | #define PRINTK(args...) printf(args) |
| 107 | #else |
| 108 | #define PRINTK(args...) |
| 109 | #endif |
| 110 | |
| 111 | |
| 112 | /*------------------------------------------------------------------------ |
| 113 | . |
| 114 | . The internal workings of the driver. If you are changing anything |
| 115 | . here with the SMC stuff, you should have the datasheet and know |
| 116 | . what you are doing. |
| 117 | . |
| 118 | -------------------------------------------------------------------------*/ |
| 119 | #define CARDNAME "LAN91C111" |
| 120 | |
| 121 | /* Memory sizing constant */ |
| 122 | #define LAN91C111_MEMORY_MULTIPLIER (1024*2) |
| 123 | |
| 124 | #ifndef CONFIG_SMC91111_BASE |
| 125 | #define CONFIG_SMC91111_BASE 0x20000300 |
| 126 | #endif |
| 127 | |
| 128 | #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE |
| 129 | |
| 130 | #define SMC_DEV_NAME "SMC91111" |
| 131 | #define SMC_PHY_ADDR 0x0000 |
| 132 | #define SMC_ALLOC_MAX_TRY 5 |
| 133 | #define SMC_TX_TIMEOUT 30 |
| 134 | |
| 135 | #define SMC_PHY_CLOCK_DELAY 1000 |
| 136 | |
| 137 | #define ETH_ZLEN 60 |
| 138 | |
| 139 | #ifdef CONFIG_SMC_USE_32_BIT |
| 140 | #define USE_32_BIT 1 |
| 141 | #else |
| 142 | #undef USE_32_BIT |
| 143 | #endif |
| 144 | /*----------------------------------------------------------------- |
| 145 | . |
| 146 | . The driver can be entered at any of the following entry points. |
| 147 | . |
| 148 | .------------------------------------------------------------------ */ |
| 149 | |
| 150 | extern int eth_init(bd_t *bd); |
| 151 | extern void eth_halt(void); |
| 152 | extern int eth_rx(void); |
| 153 | extern int eth_send(volatile void *packet, int length); |
| 154 | |
| 155 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 156 | /* |
| 157 | . This is called by register_netdev(). It is responsible for |
| 158 | . checking the portlist for the SMC9000 series chipset. If it finds |
| 159 | . one, then it will initialize the device, find the hardware information, |
| 160 | . and sets up the appropriate device parameters. |
| 161 | . NOTE: Interrupts are *OFF* when this procedure is called. |
| 162 | . |
| 163 | . NB:This shouldn't be static since it is referred to externally. |
| 164 | */ |
| 165 | int smc_init(void); |
| 166 | |
| 167 | /* |
| 168 | . This is called by unregister_netdev(). It is responsible for |
| 169 | . cleaning up before the driver is finally unregistered and discarded. |
| 170 | */ |
| 171 | void smc_destructor(void); |
| 172 | |
| 173 | /* |
| 174 | . The kernel calls this function when someone wants to use the device, |
| 175 | . typically 'ifconfig ethX up'. |
| 176 | */ |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 177 | static int smc_open(bd_t *bd); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 178 | |
| 179 | |
| 180 | /* |
| 181 | . This is called by the kernel in response to 'ifconfig ethX down'. It |
| 182 | . is responsible for cleaning up everything that the open routine |
| 183 | . does, and maybe putting the card into a powerdown state. |
| 184 | */ |
| 185 | static int smc_close(void); |
| 186 | |
| 187 | /* |
| 188 | . Configures the PHY through the MII Management interface |
| 189 | */ |
| 190 | #ifndef CONFIG_SMC91111_EXT_PHY |
| 191 | static void smc_phy_configure(void); |
| 192 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 193 | |
| 194 | /* |
| 195 | . This is a separate procedure to handle the receipt of a packet, to |
| 196 | . leave the interrupt code looking slightly cleaner |
| 197 | */ |
| 198 | static int smc_rcv(void); |
| 199 | |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 200 | /* See if a MAC address is defined in the current environment. If so use it. If not |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | . print a warning and set the environment and other globals with the default. |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 202 | . If an EEPROM is present it really should be consulted. |
| 203 | */ |
| 204 | int smc_get_ethaddr(bd_t *bd); |
| 205 | int get_rom_mac(char *v_rom_mac); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 206 | |
| 207 | /* |
| 208 | ------------------------------------------------------------ |
| 209 | . |
| 210 | . Internal routines |
| 211 | . |
| 212 | ------------------------------------------------------------ |
| 213 | */ |
| 214 | |
| 215 | static char smc_mac_addr[] = {0x02, 0x80, 0xad, 0x20, 0x31, 0xb8}; |
| 216 | |
| 217 | /* |
| 218 | * This function must be called before smc_open() if you want to override |
| 219 | * the default mac address. |
| 220 | */ |
| 221 | |
| 222 | void smc_set_mac_addr(const char *addr) { |
| 223 | int i; |
| 224 | |
| 225 | for (i=0; i < sizeof(smc_mac_addr); i++){ |
| 226 | smc_mac_addr[i] = addr[i]; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * smc_get_macaddr is no longer used. If you want to override the default |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 232 | * mac address, call smc_get_mac_addr as a part of the board initialization. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 233 | */ |
| 234 | |
| 235 | #if 0 |
| 236 | void smc_get_macaddr( byte *addr ) { |
| 237 | /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 238 | unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 239 | int i; |
| 240 | |
| 241 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 242 | for (i=0; i<6; i++) { |
| 243 | addr[0] = *(dnp1110_mac+0); |
| 244 | addr[1] = *(dnp1110_mac+1); |
| 245 | addr[2] = *(dnp1110_mac+2); |
| 246 | addr[3] = *(dnp1110_mac+3); |
| 247 | addr[4] = *(dnp1110_mac+4); |
| 248 | addr[5] = *(dnp1110_mac+5); |
| 249 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 250 | } |
| 251 | #endif /* 0 */ |
| 252 | |
| 253 | /*********************************************** |
| 254 | * Show available memory * |
| 255 | ***********************************************/ |
| 256 | void dump_memory_info(void) |
| 257 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 258 | word mem_info; |
| 259 | word old_bank; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 260 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 261 | old_bank = SMC_inw(BANK_SELECT)&0xF; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 262 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 263 | SMC_SELECT_BANK(0); |
| 264 | mem_info = SMC_inw( MIR_REG ); |
| 265 | PRINTK2("Memory: %4d available\n", (mem_info >> 8)*2048); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 266 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 267 | SMC_SELECT_BANK(old_bank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 268 | } |
| 269 | /* |
| 270 | . A rather simple routine to print out a packet for debugging purposes. |
| 271 | */ |
| 272 | #if SMC_DEBUG > 2 |
| 273 | static void print_packet( byte *, int ); |
| 274 | #endif |
| 275 | |
| 276 | #define tx_done(dev) 1 |
| 277 | |
| 278 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 279 | /* this does a soft reset on the device */ |
| 280 | static void smc_reset( void ); |
| 281 | |
| 282 | /* Enable Interrupts, Receive, and Transmit */ |
| 283 | static void smc_enable( void ); |
| 284 | |
| 285 | /* this puts the device in an inactive state */ |
| 286 | static void smc_shutdown( void ); |
| 287 | |
| 288 | /* Routines to Read and Write the PHY Registers across the |
| 289 | MII Management Interface |
| 290 | */ |
| 291 | |
| 292 | #ifndef CONFIG_SMC91111_EXT_PHY |
| 293 | static word smc_read_phy_register(byte phyreg); |
| 294 | static void smc_write_phy_register(byte phyreg, word phydata); |
| 295 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 296 | |
| 297 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 298 | static int poll4int (byte mask, int timeout) |
| 299 | { |
| 300 | int tmo = get_timer (0) + timeout * CFG_HZ; |
| 301 | int is_timeout = 0; |
| 302 | word old_bank = SMC_inw (BSR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 303 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 304 | PRINTK2 ("Polling...\n"); |
| 305 | SMC_SELECT_BANK (2); |
| 306 | while ((SMC_inw (SMC91111_INT_REG) & mask) == 0) { |
| 307 | if (get_timer (0) >= tmo) { |
| 308 | is_timeout = 1; |
| 309 | break; |
| 310 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 311 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 312 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 313 | /* restore old bank selection */ |
| 314 | SMC_SELECT_BANK (old_bank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 315 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 316 | if (is_timeout) |
| 317 | return 1; |
| 318 | else |
| 319 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 320 | } |
| 321 | |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 322 | /* Only one release command at a time, please */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 323 | static inline void smc_wait_mmu_release_complete (void) |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 324 | { |
| 325 | int count = 0; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 326 | |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 327 | /* assume bank 2 selected */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 328 | while (SMC_inw (MMU_CMD_REG) & MC_BUSY) { |
| 329 | udelay (1); /* Wait until not busy */ |
| 330 | if (++count > 200) |
| 331 | break; |
wdenk | b2abefb | 2003-06-06 11:20:01 +0000 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 335 | /* |
| 336 | . Function: smc_reset( void ) |
| 337 | . Purpose: |
| 338 | . This sets the SMC91111 chip to its normal state, hopefully from whatever |
| 339 | . mess that any other DOS driver has put it in. |
| 340 | . |
| 341 | . Maybe I should reset more registers to defaults in here? SOFTRST should |
| 342 | . do that for me. |
| 343 | . |
| 344 | . Method: |
| 345 | . 1. send a SOFT RESET |
| 346 | . 2. wait for it to finish |
| 347 | . 3. enable autorelease mode |
| 348 | . 4. reset the memory management unit |
| 349 | . 5. clear all interrupts |
| 350 | . |
| 351 | */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 352 | static void smc_reset (void) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 353 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 354 | PRINTK2 ("%s:smc_reset\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 355 | |
| 356 | /* This resets the registers mostly to defaults, but doesn't |
| 357 | affect EEPROM. That seems unnecessary */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 358 | SMC_SELECT_BANK (0); |
| 359 | SMC_outw (RCR_SOFTRST, RCR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 360 | |
| 361 | /* Setup the Configuration Register */ |
| 362 | /* This is necessary because the CONFIG_REG is not affected */ |
| 363 | /* by a soft reset */ |
| 364 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 365 | SMC_SELECT_BANK (1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 366 | #if defined(CONFIG_SMC91111_EXT_PHY) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 367 | SMC_outw (CONFIG_DEFAULT | CONFIG_EXT_PHY, CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 368 | #else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 369 | SMC_outw (CONFIG_DEFAULT, CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 370 | #endif |
| 371 | |
| 372 | |
| 373 | /* Release from possible power-down state */ |
| 374 | /* Configuration register is not affected by Soft Reset */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 375 | SMC_outw (SMC_inw (CONFIG_REG) | CONFIG_EPH_POWER_EN, CONFIG_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 376 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 377 | SMC_SELECT_BANK (0); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 378 | |
| 379 | /* this should pause enough for the chip to be happy */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 380 | udelay (10); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 381 | |
| 382 | /* Disable transmit and receive functionality */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 383 | SMC_outw (RCR_CLEAR, RCR_REG); |
| 384 | SMC_outw (TCR_CLEAR, TCR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 385 | |
| 386 | /* set the control register */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 387 | SMC_SELECT_BANK (1); |
| 388 | SMC_outw (CTL_DEFAULT, CTL_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 389 | |
| 390 | /* Reset the MMU */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 391 | SMC_SELECT_BANK (2); |
| 392 | smc_wait_mmu_release_complete (); |
| 393 | SMC_outw (MC_RESET, MMU_CMD_REG); |
| 394 | while (SMC_inw (MMU_CMD_REG) & MC_BUSY) |
| 395 | udelay (1); /* Wait until not busy */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 396 | |
| 397 | /* Note: It doesn't seem that waiting for the MMU busy is needed here, |
| 398 | but this is a place where future chipsets _COULD_ break. Be wary |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 399 | of issuing another MMU command right after this */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 400 | |
| 401 | /* Disable all interrupts */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 402 | SMC_outb (0, IM_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /* |
| 406 | . Function: smc_enable |
| 407 | . Purpose: let the chip talk to the outside work |
| 408 | . Method: |
| 409 | . 1. Enable the transmitter |
| 410 | . 2. Enable the receiver |
| 411 | . 3. Enable interrupts |
| 412 | */ |
| 413 | static void smc_enable() |
| 414 | { |
| 415 | PRINTK2("%s:smc_enable\n", SMC_DEV_NAME); |
| 416 | SMC_SELECT_BANK( 0 ); |
| 417 | /* see the header file for options in TCR/RCR DEFAULT*/ |
| 418 | SMC_outw( TCR_DEFAULT, TCR_REG ); |
| 419 | SMC_outw( RCR_DEFAULT, RCR_REG ); |
| 420 | |
| 421 | /* clear MII_DIS */ |
| 422 | /* smc_write_phy_register(PHY_CNTL_REG, 0x0000); */ |
| 423 | } |
| 424 | |
| 425 | /* |
| 426 | . Function: smc_shutdown |
| 427 | . Purpose: closes down the SMC91xxx chip. |
| 428 | . Method: |
| 429 | . 1. zero the interrupt mask |
| 430 | . 2. clear the enable receive flag |
| 431 | . 3. clear the enable xmit flags |
| 432 | . |
| 433 | . TODO: |
| 434 | . (1) maybe utilize power down mode. |
| 435 | . Why not yet? Because while the chip will go into power down mode, |
| 436 | . the manual says that it will wake up in response to any I/O requests |
| 437 | . in the register space. Empirical results do not show this working. |
| 438 | */ |
| 439 | static void smc_shutdown() |
| 440 | { |
| 441 | PRINTK2(CARDNAME ":smc_shutdown\n"); |
| 442 | |
| 443 | /* no more interrupts for me */ |
| 444 | SMC_SELECT_BANK( 2 ); |
| 445 | SMC_outb( 0, IM_REG ); |
| 446 | |
| 447 | /* and tell the card to stay away from that nasty outside world */ |
| 448 | SMC_SELECT_BANK( 0 ); |
| 449 | SMC_outb( RCR_CLEAR, RCR_REG ); |
| 450 | SMC_outb( TCR_CLEAR, TCR_REG ); |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* |
| 455 | . Function: smc_hardware_send_packet(struct net_device * ) |
| 456 | . Purpose: |
| 457 | . This sends the actual packet to the SMC9xxx chip. |
| 458 | . |
| 459 | . Algorithm: |
| 460 | . First, see if a saved_skb is available. |
| 461 | . ( this should NOT be called if there is no 'saved_skb' |
| 462 | . Now, find the packet number that the chip allocated |
| 463 | . Point the data pointers at it in memory |
| 464 | . Set the length word in the chip's memory |
| 465 | . Dump the packet to chip memory |
| 466 | . Check if a last byte is needed ( odd length packet ) |
| 467 | . if so, set the control flag right |
| 468 | . Tell the card to send it |
| 469 | . Enable the transmit interrupt, so I know if it failed |
| 470 | . Free the kernel data if I actually sent it. |
| 471 | */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 472 | static int smc_send_packet (volatile void *packet, int packet_length) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 473 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 474 | byte packet_no; |
| 475 | unsigned long ioaddr; |
| 476 | byte *buf; |
| 477 | int length; |
| 478 | int numPages; |
| 479 | int try = 0; |
| 480 | int time_out; |
| 481 | byte status; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 482 | |
| 483 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 484 | PRINTK3 ("%s:smc_hardware_send_packet\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 485 | |
| 486 | length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN; |
| 487 | |
| 488 | /* allocate memory |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 489 | ** The MMU wants the number of pages to be the number of 256 bytes |
| 490 | ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) ) |
| 491 | ** |
| 492 | ** The 91C111 ignores the size bits, but the code is left intact |
| 493 | ** for backwards and future compatibility. |
| 494 | ** |
| 495 | ** Pkt size for allocating is data length +6 (for additional status |
| 496 | ** words, length and ctl!) |
| 497 | ** |
| 498 | ** If odd size then last byte is included in this header. |
| 499 | */ |
| 500 | numPages = ((length & 0xfffe) + 6); |
| 501 | numPages >>= 8; /* Divide by 256 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 502 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 503 | if (numPages > 7) { |
| 504 | printf ("%s: Far too big packet error. \n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | /* now, try to allocate the memory */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 509 | SMC_SELECT_BANK (2); |
| 510 | SMC_outw (MC_ALLOC | numPages, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 511 | |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 512 | /* FIXME: the ALLOC_INT bit never gets set * |
| 513 | * so the following will always give a * |
| 514 | * memory allocation error. * |
| 515 | * same code works in armboot though * |
| 516 | * -ro |
| 517 | */ |
| 518 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 519 | again: |
| 520 | try++; |
| 521 | time_out = MEMORY_WAIT_TIME; |
| 522 | do { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 523 | status = SMC_inb (SMC91111_INT_REG); |
| 524 | if (status & IM_ALLOC_INT) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 525 | /* acknowledge the interrupt */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 526 | SMC_outb (IM_ALLOC_INT, SMC91111_INT_REG); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 527 | break; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 528 | } |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 529 | } while (--time_out); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 530 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 531 | if (!time_out) { |
| 532 | PRINTK2 ("%s: memory allocation, try %d failed ...\n", |
| 533 | SMC_DEV_NAME, try); |
| 534 | if (try < SMC_ALLOC_MAX_TRY) |
| 535 | goto again; |
| 536 | else |
| 537 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 538 | } |
| 539 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 540 | PRINTK2 ("%s: memory allocation, try %d succeeded ...\n", |
| 541 | SMC_DEV_NAME, try); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 542 | |
| 543 | /* I can send the packet now.. */ |
| 544 | |
| 545 | ioaddr = SMC_BASE_ADDRESS; |
| 546 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 547 | buf = (byte *) packet; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 548 | |
| 549 | /* If I get here, I _know_ there is a packet slot waiting for me */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 550 | packet_no = SMC_inb (AR_REG); |
| 551 | if (packet_no & AR_FAILED) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 552 | /* or isn't there? BAD CHIP! */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 553 | printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | /* we have a packet address, so tell the card to use it */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 558 | SMC_outb (packet_no, PN_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 559 | |
| 560 | /* point to the beginning of the packet */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 561 | SMC_outw (PTR_AUTOINC, PTR_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 562 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 563 | PRINTK3 ("%s: Trying to xmit packet of length %x\n", |
| 564 | SMC_DEV_NAME, length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 565 | |
| 566 | #if SMC_DEBUG > 2 |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 567 | printf ("Transmitting Packet\n"); |
| 568 | print_packet (buf, length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 569 | #endif |
| 570 | |
| 571 | /* send the packet length ( +6 for status, length and ctl byte ) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 572 | and the status word ( set to zeros ) */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 573 | #ifdef USE_32_BIT |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 574 | SMC_outl ((length + 6) << 16, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 575 | #else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 576 | SMC_outw (0, SMC91111_DATA_REG); |
| 577 | /* send the packet length ( +6 for status words, length, and ctl */ |
| 578 | SMC_outw ((length + 6), SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 579 | #endif |
| 580 | |
| 581 | /* send the actual data |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 582 | . I _think_ it's faster to send the longs first, and then |
| 583 | . mop up by sending the last word. It depends heavily |
| 584 | . on alignment, at least on the 486. Maybe it would be |
| 585 | . a good idea to check which is optimal? But that could take |
| 586 | . almost as much time as is saved? |
| 587 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 588 | #ifdef USE_32_BIT |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 589 | SMC_outsl (SMC91111_DATA_REG, buf, length >> 2); |
| 590 | if (length & 0x2) |
| 591 | SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))), |
| 592 | SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 593 | #else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 594 | SMC_outsw (SMC91111_DATA_REG, buf, (length) >> 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 595 | #endif /* USE_32_BIT */ |
| 596 | |
| 597 | /* Send the last byte, if there is one. */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 598 | if ((length & 1) == 0) { |
| 599 | SMC_outw (0, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 600 | } else { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 601 | SMC_outw (buf[length - 1] | 0x2000, SMC91111_DATA_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* and let the chipset deal with it */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 605 | SMC_outw (MC_ENQUEUE, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 606 | |
| 607 | /* poll for TX INT */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 608 | if (poll4int (IM_TX_INT, SMC_TX_TIMEOUT)) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 609 | /* sending failed */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 610 | PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 611 | |
| 612 | /* release packet */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 613 | SMC_outw (MC_FREEPKT, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 614 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 615 | /* wait for MMU getting ready (low) */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 616 | while (SMC_inw (MMU_CMD_REG) & MC_BUSY) { |
| 617 | udelay (10); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 618 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 619 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 620 | PRINTK2 ("MMU ready\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 621 | |
| 622 | |
| 623 | return 0; |
| 624 | } else { |
| 625 | /* ack. int */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 626 | SMC_outw (IM_TX_INT, SMC91111_INT_REG); |
| 627 | PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, |
| 628 | length); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 629 | |
| 630 | /* release packet */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 631 | SMC_outw (MC_FREEPKT, MMU_CMD_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 632 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 633 | /* wait for MMU getting ready (low) */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 634 | while (SMC_inw (MMU_CMD_REG) & MC_BUSY) { |
| 635 | udelay (10); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 636 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 637 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 638 | PRINTK2 ("MMU ready\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 639 | |
| 640 | |
| 641 | } |
| 642 | |
| 643 | return length; |
| 644 | } |
| 645 | |
| 646 | /*------------------------------------------------------------------------- |
| 647 | | |
| 648 | | smc_destructor( struct net_device * dev ) |
| 649 | | Input parameters: |
| 650 | | dev, pointer to the device structure |
| 651 | | |
| 652 | | Output: |
| 653 | | None. |
| 654 | | |
| 655 | --------------------------------------------------------------------------- |
| 656 | */ |
| 657 | void smc_destructor() |
| 658 | { |
| 659 | PRINTK2(CARDNAME ":smc_destructor\n"); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | /* |
| 664 | * Open and Initialize the board |
| 665 | * |
| 666 | * Set up everything, reset the card, etc .. |
| 667 | * |
| 668 | */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 669 | static int smc_open (bd_t * bd) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 670 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 671 | int i, err; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 672 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 673 | PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 674 | |
| 675 | /* reset the hardware */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 676 | smc_reset (); |
| 677 | smc_enable (); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 678 | |
| 679 | /* Configure the PHY */ |
| 680 | #ifndef CONFIG_SMC91111_EXT_PHY |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 681 | smc_phy_configure (); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 682 | #endif |
| 683 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 684 | /* conservative setting (10Mbps, HalfDuplex, no AutoNeg.) */ |
| 685 | /* SMC_SELECT_BANK(0); */ |
| 686 | /* SMC_outw(0, RPC_REG); */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 687 | SMC_SELECT_BANK (1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 688 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 689 | err = smc_get_ethaddr (bd); /* set smc_mac_addr, and sync it with u-boot globals */ |
| 690 | if (err < 0) { |
| 691 | memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */ |
| 692 | return (-1); /* upper code ignores this, but NOT bi_enetaddr */ |
| 693 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 694 | #ifdef USE_32_BIT |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 695 | for (i = 0; i < 6; i += 2) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 696 | word address; |
| 697 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 698 | address = smc_mac_addr[i + 1] << 8; |
| 699 | address |= smc_mac_addr[i]; |
| 700 | SMC_outw (address, ADDR0_REG + i); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 701 | } |
| 702 | #else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 703 | for (i = 0; i < 6; i++) |
| 704 | SMC_outb (smc_mac_addr[i], ADDR0_REG + i); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 705 | #endif |
| 706 | |
| 707 | return 0; |
| 708 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 709 | |
| 710 | /*------------------------------------------------------------- |
| 711 | . |
| 712 | . smc_rcv - receive a packet from the card |
| 713 | . |
| 714 | . There is ( at least ) a packet waiting to be read from |
| 715 | . chip-memory. |
| 716 | . |
| 717 | . o Read the status |
| 718 | . o If an error, record it |
| 719 | . o otherwise, read in the packet |
| 720 | -------------------------------------------------------------- |
| 721 | */ |
| 722 | static int smc_rcv() |
| 723 | { |
| 724 | int packet_number; |
| 725 | word status; |
| 726 | word packet_length; |
| 727 | int is_error = 0; |
| 728 | #ifdef USE_32_BIT |
| 729 | dword stat_len; |
| 730 | #endif |
| 731 | |
| 732 | |
| 733 | SMC_SELECT_BANK(2); |
| 734 | packet_number = SMC_inw( RXFIFO_REG ); |
| 735 | |
| 736 | if ( packet_number & RXFIFO_REMPTY ) { |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | PRINTK3("%s:smc_rcv\n", SMC_DEV_NAME); |
| 742 | /* start reading from the start of the packet */ |
| 743 | SMC_outw( PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG ); |
| 744 | |
| 745 | /* First two words are status and packet_length */ |
| 746 | #ifdef USE_32_BIT |
| 747 | stat_len = SMC_inl(SMC91111_DATA_REG); |
| 748 | status = stat_len & 0xffff; |
| 749 | packet_length = stat_len >> 16; |
| 750 | #else |
| 751 | status = SMC_inw( SMC91111_DATA_REG ); |
| 752 | packet_length = SMC_inw( SMC91111_DATA_REG ); |
| 753 | #endif |
| 754 | |
| 755 | packet_length &= 0x07ff; /* mask off top bits */ |
| 756 | |
| 757 | PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ); |
| 758 | |
| 759 | if ( !(status & RS_ERRORS ) ){ |
| 760 | /* Adjust for having already read the first two words */ |
| 761 | packet_length -= 4; /*4; */ |
| 762 | |
| 763 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 764 | /* set odd length for bug in LAN91C111, */ |
| 765 | /* which never sets RS_ODDFRAME */ |
| 766 | /* TODO ? */ |
| 767 | |
| 768 | |
| 769 | #ifdef USE_32_BIT |
| 770 | PRINTK3(" Reading %d dwords (and %d bytes) \n", |
| 771 | packet_length >> 2, packet_length & 3 ); |
| 772 | /* QUESTION: Like in the TX routine, do I want |
| 773 | to send the DWORDs or the bytes first, or some |
| 774 | mixture. A mixture might improve already slow PIO |
| 775 | performance */ |
| 776 | SMC_insl( SMC91111_DATA_REG , NetRxPackets[0], packet_length >> 2 ); |
| 777 | /* read the left over bytes */ |
| 778 | if (packet_length & 3) { |
| 779 | int i; |
| 780 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 781 | byte *tail = (byte *)(NetRxPackets[0] + (packet_length & ~3)); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 782 | dword leftover = SMC_inl(SMC91111_DATA_REG); |
| 783 | for (i=0; i<(packet_length & 3); i++) |
| 784 | *tail++ = (byte) (leftover >> (8*i)) & 0xff; |
| 785 | } |
| 786 | #else |
| 787 | PRINTK3(" Reading %d words and %d byte(s) \n", |
| 788 | (packet_length >> 1 ), packet_length & 1 ); |
| 789 | SMC_insw(SMC91111_DATA_REG , NetRxPackets[0], packet_length >> 1); |
| 790 | |
| 791 | #endif /* USE_32_BIT */ |
| 792 | |
| 793 | #if SMC_DEBUG > 2 |
| 794 | printf("Receiving Packet\n"); |
| 795 | print_packet( NetRxPackets[0], packet_length ); |
| 796 | #endif |
| 797 | } else { |
| 798 | /* error ... */ |
| 799 | /* TODO ? */ |
| 800 | is_error = 1; |
| 801 | } |
| 802 | |
| 803 | while ( SMC_inw( MMU_CMD_REG ) & MC_BUSY ) |
| 804 | udelay(1); /* Wait until not busy */ |
| 805 | |
| 806 | /* error or good, tell the card to get rid of this packet */ |
| 807 | SMC_outw( MC_RELEASE, MMU_CMD_REG ); |
| 808 | |
| 809 | while ( SMC_inw( MMU_CMD_REG ) & MC_BUSY ) |
| 810 | udelay(1); /* Wait until not busy */ |
| 811 | |
| 812 | if (!is_error) { |
| 813 | /* Pass the packet up to the protocol layers. */ |
| 814 | NetReceive(NetRxPackets[0], packet_length); |
| 815 | return packet_length; |
| 816 | } else { |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | } |
| 821 | |
| 822 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 823 | /*---------------------------------------------------- |
| 824 | . smc_close |
| 825 | . |
| 826 | . this makes the board clean up everything that it can |
| 827 | . and not talk to the outside world. Caused by |
| 828 | . an 'ifconfig ethX down' |
| 829 | . |
| 830 | -----------------------------------------------------*/ |
| 831 | static int smc_close() |
| 832 | { |
| 833 | PRINTK2("%s:smc_close\n", SMC_DEV_NAME); |
| 834 | |
| 835 | /* clear everything */ |
| 836 | smc_shutdown(); |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | |
| 842 | #if 0 |
| 843 | /*------------------------------------------------------------ |
| 844 | . Modify a bit in the LAN91C111 register set |
| 845 | .-------------------------------------------------------------*/ |
| 846 | static word smc_modify_regbit(int bank, int ioaddr, int reg, |
| 847 | unsigned int bit, int val) |
| 848 | { |
| 849 | word regval; |
| 850 | |
| 851 | SMC_SELECT_BANK( bank ); |
| 852 | |
| 853 | regval = SMC_inw( reg ); |
| 854 | if (val) |
| 855 | regval |= bit; |
| 856 | else |
| 857 | regval &= ~bit; |
| 858 | |
| 859 | SMC_outw( regval, 0 ); |
| 860 | return(regval); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | /*------------------------------------------------------------ |
| 865 | . Retrieve a bit in the LAN91C111 register set |
| 866 | .-------------------------------------------------------------*/ |
| 867 | static int smc_get_regbit(int bank, int ioaddr, int reg, unsigned int bit) |
| 868 | { |
| 869 | SMC_SELECT_BANK( bank ); |
| 870 | if ( SMC_inw( reg ) & bit) |
| 871 | return(1); |
| 872 | else |
| 873 | return(0); |
| 874 | } |
| 875 | |
| 876 | |
| 877 | /*------------------------------------------------------------ |
| 878 | . Modify a LAN91C111 register (word access only) |
| 879 | .-------------------------------------------------------------*/ |
| 880 | static void smc_modify_reg(int bank, int ioaddr, int reg, word val) |
| 881 | { |
| 882 | SMC_SELECT_BANK( bank ); |
| 883 | SMC_outw( val, reg ); |
| 884 | } |
| 885 | |
| 886 | |
| 887 | /*------------------------------------------------------------ |
| 888 | . Retrieve a LAN91C111 register (word access only) |
| 889 | .-------------------------------------------------------------*/ |
| 890 | static int smc_get_reg(int bank, int ioaddr, int reg) |
| 891 | { |
| 892 | SMC_SELECT_BANK( bank ); |
| 893 | return(SMC_inw( reg )); |
| 894 | } |
| 895 | |
| 896 | #endif /* 0 */ |
| 897 | |
| 898 | /*---PHY CONTROL AND CONFIGURATION----------------------------------------- */ |
| 899 | |
| 900 | #if (SMC_DEBUG > 2 ) |
| 901 | |
| 902 | /*------------------------------------------------------------ |
| 903 | . Debugging function for viewing MII Management serial bitstream |
| 904 | .-------------------------------------------------------------*/ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 905 | static void smc_dump_mii_stream (byte * bits, int size) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 906 | { |
| 907 | int i; |
| 908 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 909 | printf ("BIT#:"); |
| 910 | for (i = 0; i < size; ++i) { |
| 911 | printf ("%d", i % 10); |
| 912 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 913 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 914 | printf ("\nMDOE:"); |
| 915 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 916 | if (bits[i] & MII_MDOE) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 917 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 918 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 919 | printf ("0"); |
| 920 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 921 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 922 | printf ("\nMDO :"); |
| 923 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 924 | if (bits[i] & MII_MDO) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 925 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 926 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 927 | printf ("0"); |
| 928 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 929 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 930 | printf ("\nMDI :"); |
| 931 | for (i = 0; i < size; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 932 | if (bits[i] & MII_MDI) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 933 | printf ("1"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 934 | else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 935 | printf ("0"); |
| 936 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 937 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 938 | printf ("\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 939 | } |
| 940 | #endif |
| 941 | |
| 942 | /*------------------------------------------------------------ |
| 943 | . Reads a register from the MII Management serial interface |
| 944 | .-------------------------------------------------------------*/ |
| 945 | #ifndef CONFIG_SMC91111_EXT_PHY |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 946 | static word smc_read_phy_register (byte phyreg) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 947 | { |
| 948 | int oldBank; |
| 949 | int i; |
| 950 | byte mask; |
| 951 | word mii_reg; |
| 952 | byte bits[64]; |
| 953 | int clk_idx = 0; |
| 954 | int input_idx; |
| 955 | word phydata; |
| 956 | byte phyaddr = SMC_PHY_ADDR; |
| 957 | |
| 958 | /* 32 consecutive ones on MDO to establish sync */ |
| 959 | for (i = 0; i < 32; ++i) |
| 960 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 961 | |
| 962 | /* Start code <01> */ |
| 963 | bits[clk_idx++] = MII_MDOE; |
| 964 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 965 | |
| 966 | /* Read command <10> */ |
| 967 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 968 | bits[clk_idx++] = MII_MDOE; |
| 969 | |
| 970 | /* Output the PHY address, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 971 | mask = (byte) 0x10; |
| 972 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 973 | if (phyaddr & mask) |
| 974 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 975 | else |
| 976 | bits[clk_idx++] = MII_MDOE; |
| 977 | |
| 978 | /* Shift to next lowest bit */ |
| 979 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 980 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 981 | |
| 982 | /* Output the phy register number, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 983 | mask = (byte) 0x10; |
| 984 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 985 | if (phyreg & mask) |
| 986 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 987 | else |
| 988 | bits[clk_idx++] = MII_MDOE; |
| 989 | |
| 990 | /* Shift to next lowest bit */ |
| 991 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 992 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 993 | |
| 994 | /* Tristate and turnaround (2 bit times) */ |
| 995 | bits[clk_idx++] = 0; |
| 996 | /*bits[clk_idx++] = 0; */ |
| 997 | |
| 998 | /* Input starts at this bit time */ |
| 999 | input_idx = clk_idx; |
| 1000 | |
| 1001 | /* Will input 16 bits */ |
| 1002 | for (i = 0; i < 16; ++i) |
| 1003 | bits[clk_idx++] = 0; |
| 1004 | |
| 1005 | /* Final clock bit */ |
| 1006 | bits[clk_idx++] = 0; |
| 1007 | |
| 1008 | /* Save the current bank */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1009 | oldBank = SMC_inw (BANK_SELECT); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1010 | |
| 1011 | /* Select bank 3 */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1012 | SMC_SELECT_BANK (3); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1013 | |
| 1014 | /* Get the current MII register value */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1015 | mii_reg = SMC_inw (MII_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1016 | |
| 1017 | /* Turn off all MII Interface bits */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1018 | mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1019 | |
| 1020 | /* Clock all 64 cycles */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1021 | for (i = 0; i < sizeof bits; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1022 | /* Clock Low - output data */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1023 | SMC_outw (mii_reg | bits[i], MII_REG); |
| 1024 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1025 | |
| 1026 | |
| 1027 | /* Clock Hi - input data */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1028 | SMC_outw (mii_reg | bits[i] | MII_MCLK, MII_REG); |
| 1029 | udelay (SMC_PHY_CLOCK_DELAY); |
| 1030 | bits[i] |= SMC_inw (MII_REG) & MII_MDI; |
| 1031 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1032 | |
| 1033 | /* Return to idle state */ |
| 1034 | /* Set clock to low, data to low, and output tristated */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1035 | SMC_outw (mii_reg, MII_REG); |
| 1036 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1037 | |
| 1038 | /* Restore original bank select */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1039 | SMC_SELECT_BANK (oldBank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* Recover input data */ |
| 1042 | phydata = 0; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1043 | for (i = 0; i < 16; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1044 | phydata <<= 1; |
| 1045 | |
| 1046 | if (bits[input_idx++] & MII_MDI) |
| 1047 | phydata |= 0x0001; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1048 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1049 | |
| 1050 | #if (SMC_DEBUG > 2 ) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1051 | printf ("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1052 | phyaddr, phyreg, phydata); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1053 | smc_dump_mii_stream (bits, sizeof bits); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1054 | #endif |
| 1055 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1056 | return (phydata); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | /*------------------------------------------------------------ |
| 1061 | . Writes a register to the MII Management serial interface |
| 1062 | .-------------------------------------------------------------*/ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1063 | static void smc_write_phy_register (byte phyreg, word phydata) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1064 | { |
| 1065 | int oldBank; |
| 1066 | int i; |
| 1067 | word mask; |
| 1068 | word mii_reg; |
| 1069 | byte bits[65]; |
| 1070 | int clk_idx = 0; |
| 1071 | byte phyaddr = SMC_PHY_ADDR; |
| 1072 | |
| 1073 | /* 32 consecutive ones on MDO to establish sync */ |
| 1074 | for (i = 0; i < 32; ++i) |
| 1075 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1076 | |
| 1077 | /* Start code <01> */ |
| 1078 | bits[clk_idx++] = MII_MDOE; |
| 1079 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1080 | |
| 1081 | /* Write command <01> */ |
| 1082 | bits[clk_idx++] = MII_MDOE; |
| 1083 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1084 | |
| 1085 | /* Output the PHY address, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1086 | mask = (byte) 0x10; |
| 1087 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1088 | if (phyaddr & mask) |
| 1089 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1090 | else |
| 1091 | bits[clk_idx++] = MII_MDOE; |
| 1092 | |
| 1093 | /* Shift to next lowest bit */ |
| 1094 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1095 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1096 | |
| 1097 | /* Output the phy register number, msb first */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1098 | mask = (byte) 0x10; |
| 1099 | for (i = 0; i < 5; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1100 | if (phyreg & mask) |
| 1101 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1102 | else |
| 1103 | bits[clk_idx++] = MII_MDOE; |
| 1104 | |
| 1105 | /* Shift to next lowest bit */ |
| 1106 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1107 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* Tristate and turnaround (2 bit times) */ |
| 1110 | bits[clk_idx++] = 0; |
| 1111 | bits[clk_idx++] = 0; |
| 1112 | |
| 1113 | /* Write out 16 bits of data, msb first */ |
| 1114 | mask = 0x8000; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1115 | for (i = 0; i < 16; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1116 | if (phydata & mask) |
| 1117 | bits[clk_idx++] = MII_MDOE | MII_MDO; |
| 1118 | else |
| 1119 | bits[clk_idx++] = MII_MDOE; |
| 1120 | |
| 1121 | /* Shift to next lowest bit */ |
| 1122 | mask >>= 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1123 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1124 | |
| 1125 | /* Final clock bit (tristate) */ |
| 1126 | bits[clk_idx++] = 0; |
| 1127 | |
| 1128 | /* Save the current bank */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1129 | oldBank = SMC_inw (BANK_SELECT); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1130 | |
| 1131 | /* Select bank 3 */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1132 | SMC_SELECT_BANK (3); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1133 | |
| 1134 | /* Get the current MII register value */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1135 | mii_reg = SMC_inw (MII_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1136 | |
| 1137 | /* Turn off all MII Interface bits */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1138 | mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1139 | |
| 1140 | /* Clock all cycles */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1141 | for (i = 0; i < sizeof bits; ++i) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1142 | /* Clock Low - output data */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1143 | SMC_outw (mii_reg | bits[i], MII_REG); |
| 1144 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1145 | |
| 1146 | |
| 1147 | /* Clock Hi - input data */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1148 | SMC_outw (mii_reg | bits[i] | MII_MCLK, MII_REG); |
| 1149 | udelay (SMC_PHY_CLOCK_DELAY); |
| 1150 | bits[i] |= SMC_inw (MII_REG) & MII_MDI; |
| 1151 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1152 | |
| 1153 | /* Return to idle state */ |
| 1154 | /* Set clock to low, data to low, and output tristated */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1155 | SMC_outw (mii_reg, MII_REG); |
| 1156 | udelay (SMC_PHY_CLOCK_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1157 | |
| 1158 | /* Restore original bank select */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1159 | SMC_SELECT_BANK (oldBank); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1160 | |
| 1161 | #if (SMC_DEBUG > 2 ) |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1162 | printf ("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1163 | phyaddr, phyreg, phydata); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1164 | smc_dump_mii_stream (bits, sizeof bits); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1165 | #endif |
| 1166 | } |
| 1167 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 1168 | |
| 1169 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1170 | /*------------------------------------------------------------ |
| 1171 | . Waits the specified number of milliseconds - kernel friendly |
| 1172 | .-------------------------------------------------------------*/ |
| 1173 | #ifndef CONFIG_SMC91111_EXT_PHY |
| 1174 | static void smc_wait_ms(unsigned int ms) |
| 1175 | { |
| 1176 | udelay(ms*1000); |
| 1177 | } |
| 1178 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 1179 | |
| 1180 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1181 | /*------------------------------------------------------------ |
| 1182 | . Configures the specified PHY using Autonegotiation. Calls |
| 1183 | . smc_phy_fixed() if the user has requested a certain config. |
| 1184 | .-------------------------------------------------------------*/ |
| 1185 | #ifndef CONFIG_SMC91111_EXT_PHY |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1186 | static void smc_phy_configure () |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1187 | { |
| 1188 | int timeout; |
| 1189 | byte phyaddr; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1190 | word my_phy_caps; /* My PHY capabilities */ |
| 1191 | word my_ad_caps; /* My Advertised capabilities */ |
| 1192 | word status = 0; /*;my status = 0 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1193 | int failed = 0; |
| 1194 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1195 | PRINTK3 ("%s:smc_program_phy()\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1196 | |
| 1197 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1198 | /* Get the detected phy address */ |
| 1199 | phyaddr = SMC_PHY_ADDR; |
| 1200 | |
| 1201 | /* Reset the PHY, setting all other bits to zero */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1202 | smc_write_phy_register (PHY_CNTL_REG, PHY_CNTL_RST); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* Wait for the reset to complete, or time out */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1205 | timeout = 6; /* Wait up to 3 seconds */ |
| 1206 | while (timeout--) { |
| 1207 | if (!(smc_read_phy_register (PHY_CNTL_REG) |
| 1208 | & PHY_CNTL_RST)) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1209 | /* reset complete */ |
| 1210 | break; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1213 | smc_wait_ms (500); /* wait 500 millisecs */ |
| 1214 | } |
| 1215 | |
| 1216 | if (timeout < 1) { |
| 1217 | printf ("%s:PHY reset timed out\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1218 | goto smc_phy_configure_exit; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1219 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1220 | |
| 1221 | /* Read PHY Register 18, Status Output */ |
| 1222 | /* lp->lastPhy18 = smc_read_phy_register(PHY_INT_REG); */ |
| 1223 | |
| 1224 | /* Enable PHY Interrupts (for register 18) */ |
| 1225 | /* Interrupts listed here are disabled */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1226 | smc_write_phy_register (PHY_INT_REG, 0xffff); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1227 | |
| 1228 | /* Configure the Receive/Phy Control register */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1229 | SMC_SELECT_BANK (0); |
| 1230 | SMC_outw (RPC_DEFAULT, RPC_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1231 | |
| 1232 | /* Copy our capabilities from PHY_STAT_REG to PHY_AD_REG */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1233 | my_phy_caps = smc_read_phy_register (PHY_STAT_REG); |
| 1234 | my_ad_caps = PHY_AD_CSMA; /* I am CSMA capable */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1235 | |
| 1236 | if (my_phy_caps & PHY_STAT_CAP_T4) |
| 1237 | my_ad_caps |= PHY_AD_T4; |
| 1238 | |
| 1239 | if (my_phy_caps & PHY_STAT_CAP_TXF) |
| 1240 | my_ad_caps |= PHY_AD_TX_FDX; |
| 1241 | |
| 1242 | if (my_phy_caps & PHY_STAT_CAP_TXH) |
| 1243 | my_ad_caps |= PHY_AD_TX_HDX; |
| 1244 | |
| 1245 | if (my_phy_caps & PHY_STAT_CAP_TF) |
| 1246 | my_ad_caps |= PHY_AD_10_FDX; |
| 1247 | |
| 1248 | if (my_phy_caps & PHY_STAT_CAP_TH) |
| 1249 | my_ad_caps |= PHY_AD_10_HDX; |
| 1250 | |
| 1251 | /* Update our Auto-Neg Advertisement Register */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1252 | smc_write_phy_register (PHY_AD_REG, my_ad_caps); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1253 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1254 | PRINTK2 ("%s:phy caps=%x\n", SMC_DEV_NAME, my_phy_caps); |
| 1255 | PRINTK2 ("%s:phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1256 | |
| 1257 | /* Restart auto-negotiation process in order to advertise my caps */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1258 | smc_write_phy_register (PHY_CNTL_REG, |
| 1259 | PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1260 | |
| 1261 | /* Wait for the auto-negotiation to complete. This may take from */ |
| 1262 | /* 2 to 3 seconds. */ |
| 1263 | /* Wait for the reset to complete, or time out */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1264 | timeout = 20; /* Wait up to 10 seconds */ |
| 1265 | while (timeout--) { |
| 1266 | status = smc_read_phy_register (PHY_STAT_REG); |
| 1267 | if (status & PHY_STAT_ANEG_ACK) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1268 | /* auto-negotiate complete */ |
| 1269 | break; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1270 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1271 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1272 | smc_wait_ms (500); /* wait 500 millisecs */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1273 | |
| 1274 | /* Restart auto-negotiation if remote fault */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1275 | if (status & PHY_STAT_REM_FLT) { |
| 1276 | printf ("%s:PHY remote fault detected\n", |
| 1277 | SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1278 | |
| 1279 | /* Restart auto-negotiation */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1280 | printf ("%s:PHY restarting auto-negotiation\n", |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1281 | SMC_DEV_NAME); |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1282 | smc_write_phy_register (PHY_CNTL_REG, |
| 1283 | PHY_CNTL_ANEG_EN | |
| 1284 | PHY_CNTL_ANEG_RST | |
| 1285 | PHY_CNTL_SPEED | |
| 1286 | PHY_CNTL_DPLX); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1287 | } |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1288 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1289 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1290 | if (timeout < 1) { |
| 1291 | printf ("%s:PHY auto-negotiate timed out\n", SMC_DEV_NAME); |
| 1292 | printf ("%s:PHY auto-negotiate timed out\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1293 | failed = 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1294 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1295 | |
| 1296 | /* Fail if we detected an auto-negotiate remote fault */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1297 | if (status & PHY_STAT_REM_FLT) { |
| 1298 | printf ("%s:PHY remote fault detected\n", SMC_DEV_NAME); |
| 1299 | printf ("%s:PHY remote fault detected\n", SMC_DEV_NAME); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1300 | failed = 1; |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1301 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1302 | |
| 1303 | /* Re-Configure the Receive/Phy Control register */ |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1304 | SMC_outw (RPC_DEFAULT, RPC_REG); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1305 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1306 | smc_phy_configure_exit: |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1307 | |
| 1308 | } |
| 1309 | #endif /* !CONFIG_SMC91111_EXT_PHY */ |
| 1310 | |
| 1311 | |
| 1312 | #if SMC_DEBUG > 2 |
| 1313 | static void print_packet( byte * buf, int length ) |
| 1314 | { |
| 1315 | #if 0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1316 | int i; |
| 1317 | int remainder; |
| 1318 | int lines; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1319 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1320 | printf("Packet of length %d \n", length ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1321 | |
| 1322 | #if SMC_DEBUG > 3 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1323 | lines = length / 16; |
| 1324 | remainder = length % 16; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1325 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1326 | for ( i = 0; i < lines ; i ++ ) { |
| 1327 | int cur; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1328 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1329 | for ( cur = 0; cur < 8; cur ++ ) { |
| 1330 | byte a, b; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1331 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1332 | a = *(buf ++ ); |
| 1333 | b = *(buf ++ ); |
| 1334 | printf("%02x%02x ", a, b ); |
| 1335 | } |
| 1336 | printf("\n"); |
| 1337 | } |
| 1338 | for ( i = 0; i < remainder/2 ; i++ ) { |
| 1339 | byte a, b; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1340 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1341 | a = *(buf ++ ); |
| 1342 | b = *(buf ++ ); |
| 1343 | printf("%02x%02x ", a, b ); |
| 1344 | } |
| 1345 | printf("\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1346 | #endif |
| 1347 | #endif |
| 1348 | } |
| 1349 | #endif |
| 1350 | |
| 1351 | int eth_init(bd_t *bd) { |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1352 | return (smc_open(bd)); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | void eth_halt() { |
| 1356 | smc_close(); |
| 1357 | } |
| 1358 | |
| 1359 | int eth_rx() { |
| 1360 | return smc_rcv(); |
| 1361 | } |
| 1362 | |
| 1363 | int eth_send(volatile void *packet, int length) { |
| 1364 | return smc_send_packet(packet, length); |
| 1365 | } |
| 1366 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1367 | int smc_get_ethaddr (bd_t * bd) |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1368 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1369 | int env_size, rom_valid, env_present = 0, reg; |
| 1370 | char *s = NULL, *e, *v_mac, es[] = "11:22:33:44:55:66"; |
| 1371 | uchar s_env_mac[64], v_env_mac[6], v_rom_mac[6]; |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1372 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1373 | env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac)); |
| 1374 | if ((env_size > 0) && (env_size < sizeof (es))) { /* exit if env is bad */ |
| 1375 | printf ("\n*** ERROR: ethaddr is not set properly!!\n"); |
| 1376 | return (-1); |
| 1377 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1378 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1379 | if (env_size > 0) { |
| 1380 | env_present = 1; |
| 1381 | s = s_env_mac; |
| 1382 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1383 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1384 | for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */ |
| 1385 | v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0; |
| 1386 | if (s) |
| 1387 | s = (*e) ? e + 1 : e; |
| 1388 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1389 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1390 | rom_valid = get_rom_mac (v_rom_mac); /* get ROM mac value if any */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1391 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1392 | if (!env_present) { /* if NO env */ |
| 1393 | if (rom_valid) { /* but ROM is valid */ |
| 1394 | v_mac = v_rom_mac; |
| 1395 | sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X", |
| 1396 | v_mac[0], v_mac[1], v_mac[2], v_mac[3], |
| 1397 | v_mac[4], v_mac[5]); |
| 1398 | setenv ("ethaddr", s_env_mac); |
| 1399 | } else { /* no env, bad ROM */ |
| 1400 | printf ("\n*** ERROR: ethaddr is NOT set !!\n"); |
| 1401 | return (-1); |
| 1402 | } |
| 1403 | } else { /* good env, don't care ROM */ |
| 1404 | v_mac = v_env_mac; /* always use a good env over a ROM */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1405 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1406 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1407 | if (env_present && rom_valid) { /* if both env and ROM are good */ |
| 1408 | if (memcmp (v_env_mac, v_rom_mac, 6) != 0) { |
| 1409 | printf ("\n*** Warning: Environment and ROM MAC addresses don't match\n"); |
| 1410 | printf ("*** Using Environment MAC\n"); |
| 1411 | ----- |
| 1412 | printf ("\nWarning: MAC addresses don't match:\n"); |
| 1413 | printf ("\tHW MAC address: " |
| 1414 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 1415 | v_rom_mac[0], v_rom_mac[1], |
| 1416 | v_rom_mac[2], v_rom_mac[3], |
| 1417 | v_rom_mac[4], v_rom_mac[5] ); |
| 1418 | printf ("\t\"ethaddr\" value: " |
| 1419 | "%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 1420 | v_env_mac[0], v_env_mac[1], |
| 1421 | v_env_mac[2], v_env_mac[3], |
| 1422 | v_env_mac[4], v_env_mac[5]) ; |
| 1423 | debug ("### Set MAC addr from environment\n"); |
| 1424 | memcpy (addr, env_enetaddr, 6); |
| 1425 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1426 | } |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1427 | memcpy (bd->bi_enetaddr, v_mac, 6); /* update global address to match env (allows env changing) */ |
| 1428 | smc_set_mac_addr (v_mac); /* use old function to update smc default */ |
| 1429 | return (0); |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1432 | int get_rom_mac (char *v_rom_mac) |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1433 | { |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1434 | int is_rom_present = 0; |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1435 | |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1436 | #ifdef HARDCODE_MAC /* used for testing or to supress run time warnings */ |
| 1437 | char hw_mac_addr[] = { 0x02, 0x80, 0xad, 0x20, 0x31, 0xb8 }; |
| 1438 | |
| 1439 | memcpy (v_rom_mac, hw_mac_addr, 6); |
| 1440 | return (1); |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1441 | #else |
wdenk | 890255d | 2003-09-15 21:14:37 +0000 | [diff] [blame^] | 1442 | if (is_rom_present) { |
| 1443 | /* if eeprom contents are valid |
| 1444 | * extract mac address into hw_mac_addr, 8 or 16 bit accesses |
| 1445 | * memcpy (v_rom_mac, hc_mac_addr, 6); |
| 1446 | * return(1); |
| 1447 | */ |
| 1448 | } |
| 1449 | memset (v_rom_mac, 0, 6); |
| 1450 | return (0); |
wdenk | 3e8b7dc | 2003-06-19 23:58:30 +0000 | [diff] [blame] | 1451 | #endif |
| 1452 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1453 | #endif /* CONFIG_DRIVER_SMC91111 */ |