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