wdenk | 45219c4 | 2003-05-12 21:50:16 +0000 | [diff] [blame^] | 1 | /*------------------------------------------------------------------------ |
| 2 | * lan91c96.c |
| 3 | * This is a driver for SMSC's LAN91C96 single-chip Ethernet device, based |
| 4 | * on the SMC91111 driver from U-boot. |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Rolf Offermanns <rof@sysgo.de> |
| 9 | * |
| 10 | * Copyright (C) 2001 Standard Microsystems Corporation (SMSC) |
| 11 | * Developed by Simple Network Magic Corporation (SNMC) |
| 12 | * Copyright (C) 1996 by Erik Stahlman (ES) |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 | * |
| 28 | * Information contained in this file was obtained from the LAN91C96 |
| 29 | * manual from SMC. To get a copy, if you really want one, you can find |
| 30 | * information under www.smsc.com. |
| 31 | * |
| 32 | * |
| 33 | * "Features" of the SMC chip: |
| 34 | * 6144 byte packet memory. ( for the 91C96 ) |
| 35 | * EEPROM for configuration |
| 36 | * AUI/TP selection ( mine has 10Base2/10BaseT select ) |
| 37 | * |
| 38 | * Arguments: |
| 39 | * io = for the base address |
| 40 | * irq = for the IRQ |
| 41 | * |
| 42 | * author: |
| 43 | * Erik Stahlman ( erik@vt.edu ) |
| 44 | * Daris A Nevil ( dnevil@snmc.com ) |
| 45 | * |
| 46 | * |
| 47 | * Hardware multicast code from Peter Cammaert ( pc@denkart.be ) |
| 48 | * |
| 49 | * Sources: |
| 50 | * o SMSC LAN91C96 databook (www.smsc.com) |
| 51 | * o smc91111.c (u-boot driver) |
| 52 | * o smc9194.c (linux kernel driver) |
| 53 | * o lan91c96.c (Intel Diagnostic Manager driver) |
| 54 | * |
| 55 | * History: |
| 56 | * 04/30/03 Mathijs Haarman Modified smc91111.c (u-boot version) |
| 57 | * for lan91c96 |
| 58 | *--------------------------------------------------------------------------- |
| 59 | */ |
| 60 | |
| 61 | #include <common.h> |
| 62 | #include <command.h> |
| 63 | #include "lan91c96.h" |
| 64 | #include <net.h> |
| 65 | |
| 66 | #ifdef CONFIG_DRIVER_LAN91C96 |
| 67 | |
| 68 | #if (CONFIG_COMMANDS & CFG_CMD_NET) |
| 69 | |
| 70 | /*------------------------------------------------------------------------ |
| 71 | * |
| 72 | * Configuration options, for the experienced user to change. |
| 73 | * |
| 74 | -------------------------------------------------------------------------*/ |
| 75 | |
| 76 | /* Use power-down feature of the chip */ |
| 77 | #define POWER_DOWN 0 |
| 78 | |
| 79 | /* |
| 80 | * Wait time for memory to be free. This probably shouldn't be |
| 81 | * tuned that much, as waiting for this means nothing else happens |
| 82 | * in the system |
| 83 | */ |
| 84 | #define MEMORY_WAIT_TIME 16 |
| 85 | |
| 86 | #define SMC_DEBUG 0 |
| 87 | |
| 88 | #if (SMC_DEBUG > 2 ) |
| 89 | #define PRINTK3(args...) printf(args) |
| 90 | #else |
| 91 | #define PRINTK3(args...) |
| 92 | #endif |
| 93 | |
| 94 | #if SMC_DEBUG > 1 |
| 95 | #define PRINTK2(args...) printf(args) |
| 96 | #else |
| 97 | #define PRINTK2(args...) |
| 98 | #endif |
| 99 | |
| 100 | #ifdef SMC_DEBUG |
| 101 | #define PRINTK(args...) printf(args) |
| 102 | #else |
| 103 | #define PRINTK(args...) |
| 104 | #endif |
| 105 | |
| 106 | |
| 107 | /*------------------------------------------------------------------------ |
| 108 | * |
| 109 | * The internal workings of the driver. If you are changing anything |
| 110 | * here with the SMC stuff, you should have the datasheet and know |
| 111 | * what you are doing. |
| 112 | * |
| 113 | *------------------------------------------------------------------------ |
| 114 | */ |
| 115 | #define CARDNAME "LAN91C96" |
| 116 | |
| 117 | #define SMC_BASE_ADDRESS CONFIG_LAN91C96_BASE |
| 118 | |
| 119 | #define SMC_DEV_NAME "LAN91C96" |
| 120 | #define SMC_ALLOC_MAX_TRY 5 |
| 121 | #define SMC_TX_TIMEOUT 30 |
| 122 | |
| 123 | #define ETH_ZLEN 60 |
| 124 | |
| 125 | #ifdef CONFIG_LAN91C96_USE_32_BIT |
| 126 | #define USE_32_BIT 1 |
| 127 | #else |
| 128 | #undef USE_32_BIT |
| 129 | #endif |
| 130 | |
| 131 | /*----------------------------------------------------------------- |
| 132 | * |
| 133 | * The driver can be entered at any of the following entry points. |
| 134 | * |
| 135 | *----------------------------------------------------------------- |
| 136 | */ |
| 137 | |
| 138 | extern int eth_init (bd_t * bd); |
| 139 | extern void eth_halt (void); |
| 140 | extern int eth_rx (void); |
| 141 | extern int eth_send (volatile void *packet, int length); |
| 142 | static int smc_hw_init (void); |
| 143 | |
| 144 | /* |
| 145 | * This is called by register_netdev(). It is responsible for |
| 146 | * checking the portlist for the SMC9000 series chipset. If it finds |
| 147 | * one, then it will initialize the device, find the hardware information, |
| 148 | * and sets up the appropriate device parameters. |
| 149 | * NOTE: Interrupts are *OFF* when this procedure is called. |
| 150 | * |
| 151 | * NB:This shouldn't be static since it is referred to externally. |
| 152 | */ |
| 153 | int smc_init (void); |
| 154 | |
| 155 | /* |
| 156 | * This is called by unregister_netdev(). It is responsible for |
| 157 | * cleaning up before the driver is finally unregistered and discarded. |
| 158 | */ |
| 159 | void smc_destructor (void); |
| 160 | |
| 161 | /* |
| 162 | * The kernel calls this function when someone wants to use the device, |
| 163 | * typically 'ifconfig ethX up'. |
| 164 | */ |
| 165 | static int smc_open (void); |
| 166 | |
| 167 | |
| 168 | /* |
| 169 | * This is called by the kernel in response to 'ifconfig ethX down'. It |
| 170 | * is responsible for cleaning up everything that the open routine |
| 171 | * does, and maybe putting the card into a powerdown state. |
| 172 | */ |
| 173 | static int smc_close (void); |
| 174 | |
| 175 | /* |
| 176 | * This is a separate procedure to handle the receipt of a packet, to |
| 177 | * leave the interrupt code looking slightly cleaner |
| 178 | */ |
| 179 | static int smc_rcv (void); |
| 180 | |
| 181 | |
| 182 | |
| 183 | /* ------------------------------------------------------------ |
| 184 | * Internal routines |
| 185 | * ------------------------------------------------------------ |
| 186 | */ |
| 187 | |
| 188 | static char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c }; |
| 189 | |
| 190 | /* |
| 191 | * This function must be called before smc_open() if you want to override |
| 192 | * the default mac address. |
| 193 | */ |
| 194 | |
| 195 | void smc_set_mac_addr (const char *addr) |
| 196 | { |
| 197 | int i; |
| 198 | |
| 199 | for (i = 0; i < sizeof (smc_mac_addr); i++) { |
| 200 | smc_mac_addr[i] = addr[i]; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * smc_get_macaddr is no longer used. If you want to override the default |
| 206 | * mac address, call smc_get_mac_addr as a part of the board initialisation. |
| 207 | */ |
| 208 | |
| 209 | #if 0 |
| 210 | void smc_get_macaddr (byte * addr) |
| 211 | { |
| 212 | /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */ |
| 213 | unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010); |
| 214 | int i; |
| 215 | |
| 216 | |
| 217 | for (i = 0; i < 6; i++) { |
| 218 | addr[0] = *(dnp1110_mac + 0); |
| 219 | addr[1] = *(dnp1110_mac + 1); |
| 220 | addr[2] = *(dnp1110_mac + 2); |
| 221 | addr[3] = *(dnp1110_mac + 3); |
| 222 | addr[4] = *(dnp1110_mac + 4); |
| 223 | addr[5] = *(dnp1110_mac + 5); |
| 224 | } |
| 225 | } |
| 226 | #endif /* 0 */ |
| 227 | |
| 228 | /*********************************************** |
| 229 | * Show available memory * |
| 230 | ***********************************************/ |
| 231 | void dump_memory_info (void) |
| 232 | { |
| 233 | word mem_info; |
| 234 | word old_bank; |
| 235 | |
| 236 | old_bank = SMC_inw (LAN91C96_BANK_SELECT) & 0xF; |
| 237 | |
| 238 | SMC_SELECT_BANK (0); |
| 239 | mem_info = SMC_inw (LAN91C96_MIR); |
| 240 | PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048); |
| 241 | |
| 242 | SMC_SELECT_BANK (old_bank); |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * A rather simple routine to print out a packet for debugging purposes. |
| 247 | */ |
| 248 | #if SMC_DEBUG > 2 |
| 249 | static void print_packet (byte *, int); |
| 250 | #endif |
| 251 | |
| 252 | /* #define tx_done(dev) 1 */ |
| 253 | |
| 254 | |
| 255 | |
| 256 | /* this does a soft reset on the device */ |
| 257 | static void smc_reset (void); |
| 258 | |
| 259 | /* Enable Interrupts, Receive, and Transmit */ |
| 260 | static void smc_enable (void); |
| 261 | |
| 262 | /* this puts the device in an inactive state */ |
| 263 | static void smc_shutdown (void); |
| 264 | |
| 265 | |
| 266 | static int poll4int (byte mask, int timeout) |
| 267 | { |
| 268 | int tmo = get_timer (0) + timeout * CFG_HZ; |
| 269 | int is_timeout = 0; |
| 270 | word old_bank = SMC_inw (LAN91C96_BANK_SELECT); |
| 271 | |
| 272 | PRINTK2 ("Polling...\n"); |
| 273 | SMC_SELECT_BANK (2); |
| 274 | while ((SMC_inw (LAN91C96_INT_STATS) & mask) == 0) { |
| 275 | if (get_timer (0) >= tmo) { |
| 276 | is_timeout = 1; |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /* restore old bank selection */ |
| 282 | SMC_SELECT_BANK (old_bank); |
| 283 | |
| 284 | if (is_timeout) |
| 285 | return 1; |
| 286 | else |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Function: smc_reset( void ) |
| 292 | * Purpose: |
| 293 | * This sets the SMC91111 chip to its normal state, hopefully from whatever |
| 294 | * mess that any other DOS driver has put it in. |
| 295 | * |
| 296 | * Maybe I should reset more registers to defaults in here? SOFTRST should |
| 297 | * do that for me. |
| 298 | * |
| 299 | * Method: |
| 300 | * 1. send a SOFT RESET |
| 301 | * 2. wait for it to finish |
| 302 | * 3. enable autorelease mode |
| 303 | * 4. reset the memory management unit |
| 304 | * 5. clear all interrupts |
| 305 | * |
| 306 | */ |
| 307 | static void smc_reset (void) |
| 308 | { |
| 309 | PRINTK2 ("%s:smc_reset\n", SMC_DEV_NAME); |
| 310 | |
| 311 | /* This resets the registers mostly to defaults, but doesn't |
| 312 | affect EEPROM. That seems unnecessary */ |
| 313 | SMC_SELECT_BANK (0); |
| 314 | SMC_outw (LAN91C96_RCR_SOFT_RST, LAN91C96_RCR); |
| 315 | |
| 316 | udelay (10); |
| 317 | |
| 318 | /* Disable transmit and receive functionality */ |
| 319 | SMC_outw (0, LAN91C96_RCR); |
| 320 | SMC_outw (0, LAN91C96_TCR); |
| 321 | |
| 322 | /* set the control register */ |
| 323 | SMC_SELECT_BANK (1); |
| 324 | SMC_outw (SMC_inw (LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8, |
| 325 | LAN91C96_CONTROL); |
| 326 | |
| 327 | /* Disable all interrupts */ |
| 328 | SMC_outb (0, LAN91C96_INT_MASK); |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * Function: smc_enable |
| 333 | * Purpose: let the chip talk to the outside work |
| 334 | * Method: |
| 335 | * 1. Initialize the Memory Configuration Register |
| 336 | * 2. Enable the transmitter |
| 337 | * 3. Enable the receiver |
| 338 | */ |
| 339 | static void smc_enable () |
| 340 | { |
| 341 | PRINTK2 ("%s:smc_enable\n", SMC_DEV_NAME); |
| 342 | SMC_SELECT_BANK (0); |
| 343 | |
| 344 | /* Initialize the Memory Configuration Register. See page |
| 345 | 49 of the LAN91C96 data sheet for details. */ |
| 346 | SMC_outw (LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR); |
| 347 | |
| 348 | /* Initialize the Transmit Control Register */ |
| 349 | SMC_outw (LAN91C96_TCR_TXENA, LAN91C96_TCR); |
| 350 | /* Initialize the Receive Control Register |
| 351 | * FIXME: |
| 352 | * The promiscuous bit set because I could not receive ARP reply |
| 353 | * packets from the server when I send a ARP request. It only works |
| 354 | * when I set the promiscuous bit |
| 355 | */ |
| 356 | SMC_outw (LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR); |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Function: smc_shutdown |
| 361 | * Purpose: closes down the SMC91xxx chip. |
| 362 | * Method: |
| 363 | * 1. zero the interrupt mask |
| 364 | * 2. clear the enable receive flag |
| 365 | * 3. clear the enable xmit flags |
| 366 | * |
| 367 | * TODO: |
| 368 | * (1) maybe utilize power down mode. |
| 369 | * Why not yet? Because while the chip will go into power down mode, |
| 370 | * the manual says that it will wake up in response to any I/O requests |
| 371 | * in the register space. Empirical results do not show this working. |
| 372 | */ |
| 373 | static void smc_shutdown () |
| 374 | { |
| 375 | PRINTK2 (CARDNAME ":smc_shutdown\n"); |
| 376 | |
| 377 | /* no more interrupts for me */ |
| 378 | SMC_SELECT_BANK (2); |
| 379 | SMC_outb (0, LAN91C96_INT_MASK); |
| 380 | |
| 381 | /* and tell the card to stay away from that nasty outside world */ |
| 382 | SMC_SELECT_BANK (0); |
| 383 | SMC_outb (0, LAN91C96_RCR); |
| 384 | SMC_outb (0, LAN91C96_TCR); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | /* |
| 389 | * Function: smc_hardware_send_packet(struct net_device * ) |
| 390 | * Purpose: |
| 391 | * This sends the actual packet to the SMC9xxx chip. |
| 392 | * |
| 393 | * Algorithm: |
| 394 | * First, see if a saved_skb is available. |
| 395 | * ( this should NOT be called if there is no 'saved_skb' |
| 396 | * Now, find the packet number that the chip allocated |
| 397 | * Point the data pointers at it in memory |
| 398 | * Set the length word in the chip's memory |
| 399 | * Dump the packet to chip memory |
| 400 | * Check if a last byte is needed ( odd length packet ) |
| 401 | * if so, set the control flag right |
| 402 | * Tell the card to send it |
| 403 | * Enable the transmit interrupt, so I know if it failed |
| 404 | * Free the kernel data if I actually sent it. |
| 405 | */ |
| 406 | static int smc_send_packet (volatile void *packet, int packet_length) |
| 407 | { |
| 408 | byte packet_no; |
| 409 | unsigned long ioaddr; |
| 410 | byte *buf; |
| 411 | int length; |
| 412 | int numPages; |
| 413 | int try = 0; |
| 414 | int time_out; |
| 415 | byte status; |
| 416 | |
| 417 | |
| 418 | PRINTK3 ("%s:smc_hardware_send_packet\n", SMC_DEV_NAME); |
| 419 | |
| 420 | length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN; |
| 421 | |
| 422 | /* allocate memory |
| 423 | ** The MMU wants the number of pages to be the number of 256 bytes |
| 424 | ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) ) |
| 425 | ** |
| 426 | ** The 91C111 ignores the size bits, but the code is left intact |
| 427 | ** for backwards and future compatibility. |
| 428 | ** |
| 429 | ** Pkt size for allocating is data length +6 (for additional status |
| 430 | ** words, length and ctl!) |
| 431 | ** |
| 432 | ** If odd size then last byte is included in this header. |
| 433 | */ |
| 434 | numPages = ((length & 0xfffe) + 6); |
| 435 | numPages >>= 8; /* Divide by 256 */ |
| 436 | |
| 437 | if (numPages > 7) { |
| 438 | printf ("%s: Far too big packet error. \n", SMC_DEV_NAME); |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /* now, try to allocate the memory */ |
| 443 | |
| 444 | SMC_SELECT_BANK (2); |
| 445 | SMC_outw (LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU); |
| 446 | |
| 447 | again: |
| 448 | try++; |
| 449 | time_out = MEMORY_WAIT_TIME; |
| 450 | do { |
| 451 | status = SMC_inb (LAN91C96_INT_STATS); |
| 452 | if (status & LAN91C96_IST_ALLOC_INT) { |
| 453 | |
| 454 | SMC_outb (LAN91C96_IST_ALLOC_INT, LAN91C96_INT_STATS); |
| 455 | break; |
| 456 | } |
| 457 | } while (--time_out); |
| 458 | |
| 459 | if (!time_out) { |
| 460 | PRINTK2 ("%s: memory allocation, try %d failed ...\n", |
| 461 | SMC_DEV_NAME, try); |
| 462 | if (try < SMC_ALLOC_MAX_TRY) |
| 463 | goto again; |
| 464 | else |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | PRINTK2 ("%s: memory allocation, try %d succeeded ...\n", |
| 469 | SMC_DEV_NAME, try); |
| 470 | |
| 471 | /* I can send the packet now.. */ |
| 472 | |
| 473 | ioaddr = SMC_BASE_ADDRESS; |
| 474 | |
| 475 | buf = (byte *) packet; |
| 476 | |
| 477 | /* If I get here, I _know_ there is a packet slot waiting for me */ |
| 478 | packet_no = SMC_inb (LAN91C96_ARR); |
| 479 | if (packet_no & LAN91C96_ARR_FAILED) { |
| 480 | /* or isn't there? BAD CHIP! */ |
| 481 | printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME); |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* we have a packet address, so tell the card to use it */ |
| 486 | SMC_outb (packet_no, LAN91C96_PNR); |
| 487 | |
| 488 | /* point to the beginning of the packet */ |
| 489 | SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER); |
| 490 | |
| 491 | PRINTK3 ("%s: Trying to xmit packet of length %x\n", |
| 492 | SMC_DEV_NAME, length); |
| 493 | |
| 494 | #if SMC_DEBUG > 2 |
| 495 | printf ("Transmitting Packet\n"); |
| 496 | print_packet (buf, length); |
| 497 | #endif |
| 498 | |
| 499 | /* send the packet length ( +6 for status, length and ctl byte ) |
| 500 | and the status word ( set to zeros ) */ |
| 501 | #ifdef USE_32_BIT |
| 502 | SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH); |
| 503 | #else |
| 504 | SMC_outw (0, LAN91C96_DATA_HIGH); |
| 505 | /* send the packet length ( +6 for status words, length, and ctl */ |
| 506 | SMC_outw ((length + 6), LAN91C96_DATA_HIGH); |
| 507 | #endif /* USE_32_BIT */ |
| 508 | |
| 509 | /* send the actual data |
| 510 | * I _think_ it's faster to send the longs first, and then |
| 511 | * mop up by sending the last word. It depends heavily |
| 512 | * on alignment, at least on the 486. Maybe it would be |
| 513 | * a good idea to check which is optimal? But that could take |
| 514 | * almost as much time as is saved? |
| 515 | */ |
| 516 | #ifdef USE_32_BIT |
| 517 | SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2); |
| 518 | if (length & 0x2) |
| 519 | SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))), |
| 520 | LAN91C96_DATA_HIGH); |
| 521 | #else |
| 522 | SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1); |
| 523 | #endif /* USE_32_BIT */ |
| 524 | |
| 525 | /* Send the last byte, if there is one. */ |
| 526 | if ((length & 1) == 0) { |
| 527 | SMC_outw (0, LAN91C96_DATA_HIGH); |
| 528 | } else { |
| 529 | SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH); |
| 530 | } |
| 531 | |
| 532 | /* and let the chipset deal with it */ |
| 533 | SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU); |
| 534 | |
| 535 | /* poll for TX INT */ |
| 536 | if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) { |
| 537 | /* sending failed */ |
| 538 | PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME); |
| 539 | |
| 540 | /* release packet */ |
| 541 | SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU); |
| 542 | |
| 543 | /* wait for MMU getting ready (low) */ |
| 544 | while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) { |
| 545 | udelay (10); |
| 546 | } |
| 547 | |
| 548 | PRINTK2 ("MMU ready\n"); |
| 549 | |
| 550 | |
| 551 | return 0; |
| 552 | } else { |
| 553 | /* ack. int */ |
| 554 | SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS); |
| 555 | |
| 556 | PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length); |
| 557 | |
| 558 | /* release packet */ |
| 559 | SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU); |
| 560 | |
| 561 | /* wait for MMU getting ready (low) */ |
| 562 | while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) { |
| 563 | udelay (10); |
| 564 | } |
| 565 | |
| 566 | PRINTK2 ("MMU ready\n"); |
| 567 | } |
| 568 | |
| 569 | return length; |
| 570 | } |
| 571 | |
| 572 | /*------------------------------------------------------------------------- |
| 573 | * smc_destructor( struct net_device * dev ) |
| 574 | * Input parameters: |
| 575 | * dev, pointer to the device structure |
| 576 | * |
| 577 | * Output: |
| 578 | * None. |
| 579 | *-------------------------------------------------------------------------- |
| 580 | */ |
| 581 | void smc_destructor () |
| 582 | { |
| 583 | PRINTK2 (CARDNAME ":smc_destructor\n"); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | /* |
| 588 | * Open and Initialize the board |
| 589 | * |
| 590 | * Set up everything, reset the card, etc .. |
| 591 | * |
| 592 | */ |
| 593 | static int smc_open () |
| 594 | { |
| 595 | int i; /* used to set hw ethernet address */ |
| 596 | |
| 597 | PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME); |
| 598 | |
| 599 | /* reset the hardware */ |
| 600 | |
| 601 | smc_reset (); |
| 602 | smc_enable (); |
| 603 | |
| 604 | SMC_SELECT_BANK (1); |
| 605 | |
| 606 | for (i = 0; i < 6; i += 2) { |
| 607 | word address; |
| 608 | |
| 609 | address = smc_mac_addr[i + 1] << 8; |
| 610 | address |= smc_mac_addr[i]; |
| 611 | SMC_outw (address, LAN91C96_IA0 + i); |
| 612 | } |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /*------------------------------------------------------------- |
| 617 | * |
| 618 | * smc_rcv - receive a packet from the card |
| 619 | * |
| 620 | * There is ( at least ) a packet waiting to be read from |
| 621 | * chip-memory. |
| 622 | * |
| 623 | * o Read the status |
| 624 | * o If an error, record it |
| 625 | * o otherwise, read in the packet |
| 626 | *------------------------------------------------------------- |
| 627 | */ |
| 628 | static int smc_rcv () |
| 629 | { |
| 630 | int packet_number; |
| 631 | word status; |
| 632 | word packet_length; |
| 633 | int is_error = 0; |
| 634 | |
| 635 | #ifdef USE_32_BIT |
| 636 | dword stat_len; |
| 637 | #endif |
| 638 | |
| 639 | |
| 640 | SMC_SELECT_BANK (2); |
| 641 | packet_number = SMC_inw (LAN91C96_FIFO); |
| 642 | |
| 643 | if (packet_number & LAN91C96_FIFO_RXEMPTY) { |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME); |
| 648 | /* start reading from the start of the packet */ |
| 649 | SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV | |
| 650 | LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER); |
| 651 | |
| 652 | /* First two words are status and packet_length */ |
| 653 | #ifdef USE_32_BIT |
| 654 | stat_len = SMC_inl (LAN91C96_DATA_HIGH); |
| 655 | status = stat_len & 0xffff; |
| 656 | packet_length = stat_len >> 16; |
| 657 | #else |
| 658 | status = SMC_inw (LAN91C96_DATA_HIGH); |
| 659 | packet_length = SMC_inw (LAN91C96_DATA_HIGH); |
| 660 | #endif |
| 661 | |
| 662 | packet_length &= 0x07ff; /* mask off top bits */ |
| 663 | |
| 664 | PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length); |
| 665 | |
| 666 | if (!(status & FRAME_FILTER)) { |
| 667 | /* Adjust for having already read the first two words */ |
| 668 | packet_length -= 4; /*4; */ |
| 669 | |
| 670 | |
| 671 | |
| 672 | /* set odd length for bug in LAN91C111, */ |
| 673 | /* which never sets RS_ODDFRAME */ |
| 674 | /* TODO ? */ |
| 675 | |
| 676 | |
| 677 | #ifdef USE_32_BIT |
| 678 | PRINTK3 (" Reading %d dwords (and %d bytes) \n", |
| 679 | packet_length >> 2, packet_length & 3); |
| 680 | /* QUESTION: Like in the TX routine, do I want |
| 681 | to send the DWORDs or the bytes first, or some |
| 682 | mixture. A mixture might improve already slow PIO |
| 683 | performance */ |
| 684 | SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2); |
| 685 | /* read the left over bytes */ |
| 686 | if (packet_length & 3) { |
| 687 | int i; |
| 688 | |
| 689 | byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3)); |
| 690 | dword leftover = SMC_inl (LAN91C96_DATA_HIGH); |
| 691 | |
| 692 | for (i = 0; i < (packet_length & 3); i++) |
| 693 | *tail++ = (byte) (leftover >> (8 * i)) & 0xff; |
| 694 | } |
| 695 | #else |
| 696 | PRINTK3 (" Reading %d words and %d byte(s) \n", |
| 697 | (packet_length >> 1), packet_length & 1); |
| 698 | SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1); |
| 699 | |
| 700 | #endif /* USE_32_BIT */ |
| 701 | |
| 702 | #if SMC_DEBUG > 2 |
| 703 | printf ("Receiving Packet\n"); |
| 704 | print_packet (NetRxPackets[0], packet_length); |
| 705 | #endif |
| 706 | } else { |
| 707 | /* error ... */ |
| 708 | /* TODO ? */ |
| 709 | is_error = 1; |
| 710 | } |
| 711 | |
| 712 | while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) |
| 713 | udelay (1); /* Wait until not busy */ |
| 714 | |
| 715 | /* error or good, tell the card to get rid of this packet */ |
| 716 | SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU); |
| 717 | |
| 718 | while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) |
| 719 | udelay (1); /* Wait until not busy */ |
| 720 | |
| 721 | if (!is_error) { |
| 722 | /* Pass the packet up to the protocol layers. */ |
| 723 | NetReceive (NetRxPackets[0], packet_length); |
| 724 | return packet_length; |
| 725 | } else { |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | } |
| 730 | |
| 731 | /*---------------------------------------------------- |
| 732 | * smc_close |
| 733 | * |
| 734 | * this makes the board clean up everything that it can |
| 735 | * and not talk to the outside world. Caused by |
| 736 | * an 'ifconfig ethX down' |
| 737 | * |
| 738 | -----------------------------------------------------*/ |
| 739 | static int smc_close () |
| 740 | { |
| 741 | PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME); |
| 742 | |
| 743 | /* clear everything */ |
| 744 | smc_shutdown (); |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | #if SMC_DEBUG > 2 |
| 750 | static void print_packet (byte * buf, int length) |
| 751 | { |
| 752 | #if 0 |
| 753 | int i; |
| 754 | int remainder; |
| 755 | int lines; |
| 756 | |
| 757 | printf ("Packet of length %d \n", length); |
| 758 | |
| 759 | lines = length / 16; |
| 760 | remainder = length % 16; |
| 761 | |
| 762 | for (i = 0; i < lines; i++) { |
| 763 | int cur; |
| 764 | |
| 765 | for (cur = 0; cur < 8; cur++) { |
| 766 | byte a, b; |
| 767 | |
| 768 | a = *(buf++); |
| 769 | b = *(buf++); |
| 770 | printf ("%02x%02x ", a, b); |
| 771 | } |
| 772 | printf ("\n"); |
| 773 | } |
| 774 | for (i = 0; i < remainder / 2; i++) { |
| 775 | byte a, b; |
| 776 | |
| 777 | a = *(buf++); |
| 778 | b = *(buf++); |
| 779 | printf ("%02x%02x ", a, b); |
| 780 | } |
| 781 | printf ("\n"); |
| 782 | #endif /* 0 */ |
| 783 | } |
| 784 | #endif /* SMC_DEBUG > 2 */ |
| 785 | |
| 786 | int eth_init (bd_t * bd) |
| 787 | { |
| 788 | smc_open (); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | void eth_halt () |
| 793 | { |
| 794 | smc_close (); |
| 795 | } |
| 796 | |
| 797 | int eth_rx () |
| 798 | { |
| 799 | return smc_rcv (); |
| 800 | } |
| 801 | |
| 802 | int eth_send (volatile void *packet, int length) |
| 803 | { |
| 804 | return smc_send_packet (packet, length); |
| 805 | } |
| 806 | |
| 807 | int eth_hw_init () |
| 808 | { |
| 809 | return smc_hw_init (); |
| 810 | } |
| 811 | |
| 812 | /*------------------------------------------------------------------------- |
| 813 | * smc_hw_init() |
| 814 | * |
| 815 | * Function: |
| 816 | * Reset and enable the device, check if the I/O space location |
| 817 | * is correct |
| 818 | * |
| 819 | * Input parameters: |
| 820 | * None |
| 821 | * |
| 822 | * Output: |
| 823 | * 0 --> success |
| 824 | * 1 --> error |
| 825 | *-------------------------------------------------------------------------- |
| 826 | */ |
| 827 | static int smc_hw_init () |
| 828 | { |
| 829 | unsigned short status_test; |
| 830 | |
| 831 | /* The attribute register of the LAN91C96 is located at address |
| 832 | 0x0e000000 on the lubbock platform */ |
| 833 | volatile unsigned *attaddr = (unsigned *) (0x0e000000); |
| 834 | |
| 835 | /* first reset, then enable the device. Sequence is critical */ |
| 836 | attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET; |
| 837 | udelay (100); |
| 838 | attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET; |
| 839 | attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE; |
| 840 | |
| 841 | /* force 16-bit mode */ |
| 842 | attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8; |
| 843 | udelay (100); |
| 844 | |
| 845 | /* check if the I/O address is correct, the upper byte of the |
| 846 | bank select register should read 0x33 */ |
| 847 | |
| 848 | status_test = SMC_inw (LAN91C96_BANK_SELECT); |
| 849 | if ((status_test & 0xFF00) != 0x3300) { |
| 850 | printf ("Failed to initialize ethernetchip\n"); |
| 851 | return 1; |
| 852 | } |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | #endif /* COMMANDS & CFG_NET */ |
| 857 | |
| 858 | #endif /* CONFIG_DRIVER_LAN91C96 */ |