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