1/* 3c527.c: 3Com Etherlink/MC32 driver for Linux 2.4 and 2.6. 2 * 3 * (c) Copyright 1998 Red Hat Software Inc 4 * Written by Alan Cox. 5 * Further debugging by Carl Drougge. 6 * Initial SMP support by Felipe W Damasio <felipewd@terra.com.br> 7 * Heavily modified by Richard Procter <rnp@paradise.net.nz> 8 * 9 * Based on skeleton.c written 1993-94 by Donald Becker and ne2.c 10 * (for the MCA stuff) written by Wim Dumon. 11 * 12 * Thanks to 3Com for making this possible by providing me with the 13 * documentation. 14 * 15 * This software may be used and distributed according to the terms 16 * of the GNU General Public License, incorporated herein by reference. 17 * 18 */ 19 20#define DRV_NAME "3c527" 21#define DRV_VERSION "0.7-SMP" 22#define DRV_RELDATE "2003/09/21" 23 24static const char *version = 25DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Richard Procter <rnp@paradise.net.nz>\n"; 26 27/** 28 * DOC: Traps for the unwary 29 * 30 * The diagram (Figure 1-1) and the POS summary disagree with the 31 * "Interrupt Level" section in the manual. 32 * 33 * The manual contradicts itself when describing the minimum number 34 * buffers in the 'configure lists' command. 35 * My card accepts a buffer config of 4/4. 36 * 37 * Setting the SAV BP bit does not save bad packets, but 38 * only enables RX on-card stats collection. 39 * 40 * The documentation in places seems to miss things. In actual fact 41 * I've always eventually found everything is documented, it just 42 * requires careful study. 43 * 44 * DOC: Theory Of Operation 45 * 46 * The 3com 3c527 is a 32bit MCA bus mastering adapter with a large 47 * amount of on board intelligence that housekeeps a somewhat dumber 48 * Intel NIC. For performance we want to keep the transmit queue deep 49 * as the card can transmit packets while fetching others from main 50 * memory by bus master DMA. Transmission and reception are driven by 51 * circular buffer queues. 52 * 53 * The mailboxes can be used for controlling how the card traverses 54 * its buffer rings, but are used only for inital setup in this 55 * implementation. The exec mailbox allows a variety of commands to 56 * be executed. Each command must complete before the next is 57 * executed. Primarily we use the exec mailbox for controlling the 58 * multicast lists. We have to do a certain amount of interesting 59 * hoop jumping as the multicast list changes can occur in interrupt 60 * state when the card has an exec command pending. We defer such 61 * events until the command completion interrupt. 62 * 63 * A copy break scheme (taken from 3c59x.c) is employed whereby 64 * received frames exceeding a configurable length are passed 65 * directly to the higher networking layers without incuring a copy, 66 * in what amounts to a time/space trade-off. 67 * 68 * The card also keeps a large amount of statistical information 69 * on-board. In a perfect world, these could be used safely at no 70 * cost. However, lacking information to the contrary, processing 71 * them without races would involve so much extra complexity as to 72 * make it unworthwhile to do so. In the end, a hybrid SW/HW 73 * implementation was made necessary --- see mc32_update_stats(). 74 * 75 * DOC: Notes 76 * 77 * It should be possible to use two or more cards, but at this stage 78 * only by loading two copies of the same module. 79 * 80 * The on-board 82586 NIC has trouble receiving multiple 81 * back-to-back frames and so is likely to drop packets from fast 82 * senders. 83**/ 84 85#include <linux/module.h> 86 87#include <linux/errno.h> 88#include <linux/netdevice.h> 89#include <linux/etherdevice.h> 90#include <linux/if_ether.h> 91#include <linux/init.h> 92#include <linux/kernel.h> 93#include <linux/types.h> 94#include <linux/fcntl.h> 95#include <linux/interrupt.h> 96#include <linux/mca-legacy.h> 97#include <linux/ioport.h> 98#include <linux/in.h> 99#include <linux/skbuff.h> 100#include <linux/slab.h> 101#include <linux/string.h> 102#include <linux/wait.h> 103#include <linux/ethtool.h> 104#include <linux/completion.h> 105#include <linux/bitops.h> 106#include <linux/semaphore.h> 107 108#include <asm/uaccess.h> 109#include <asm/system.h> 110#include <asm/io.h> 111#include <asm/dma.h> 112 113#include "3c527.h" 114 115MODULE_LICENSE("GPL"); 116 117/* 118 * The name of the card. Is used for messages and in the requests for 119 * io regions, irqs and dma channels 120 */ 121static const char* cardname = DRV_NAME; 122 123/* use 0 for production, 1 for verification, >2 for debug */ 124#ifndef NET_DEBUG 125#define NET_DEBUG 2 126#endif 127 128static unsigned int mc32_debug = NET_DEBUG; 129 130/* The number of low I/O ports used by the ethercard. */ 131#define MC32_IO_EXTENT 8 132 133/* As implemented, values must be a power-of-2 -- 4/8/16/32 */ 134#define TX_RING_LEN 32 /* Typically the card supports 37 */ 135#define RX_RING_LEN 8 /* " " " */ 136 137/* Copy break point, see above for details. 138 * Setting to > 1512 effectively disables this feature. */ 139#define RX_COPYBREAK 200 /* Value from 3c59x.c */ 140 141static const int WORKAROUND_82586=1; 142 143/* Pointers to buffers and their on-card records */ 144struct mc32_ring_desc 145{ 146 volatile struct skb_header *p; 147 struct sk_buff *skb; 148}; 149 150/* Information that needs to be kept for each board. */ 151struct mc32_local 152{ 153 int slot; 154 155 u32 base; 156 volatile struct mc32_mailbox *rx_box; 157 volatile struct mc32_mailbox *tx_box; 158 volatile struct mc32_mailbox *exec_box; 159 volatile struct mc32_stats *stats; /* Start of on-card statistics */ 160 u16 tx_chain; /* Transmit list start offset */ 161 u16 rx_chain; /* Receive list start offset */ 162 u16 tx_len; /* Transmit list count */ 163 u16 rx_len; /* Receive list count */ 164 165 u16 xceiver_desired_state; /* HALTED or RUNNING */ 166 u16 cmd_nonblocking; /* Thread is uninterested in command result */ 167 u16 mc_reload_wait; /* A multicast load request is pending */ 168 u32 mc_list_valid; /* True when the mclist is set */ 169 170 struct mc32_ring_desc tx_ring[TX_RING_LEN]; /* Host Transmit ring */ 171 struct mc32_ring_desc rx_ring[RX_RING_LEN]; /* Host Receive ring */ 172 173 atomic_t tx_count; /* buffers left */ 174 atomic_t tx_ring_head; /* index to tx en-queue end */ 175 u16 tx_ring_tail; /* index to tx de-queue end */ 176 177 u16 rx_ring_tail; /* index to rx de-queue end */ 178 179 struct semaphore cmd_mutex; /* Serialises issuing of execute commands */ 180 struct completion execution_cmd; /* Card has completed an execute command */ 181 struct completion xceiver_cmd; /* Card has completed a tx or rx command */ 182}; 183 184/* The station (ethernet) address prefix, used for a sanity check. */ 185#define SA_ADDR0 0x02 186#define SA_ADDR1 0x60 187#define SA_ADDR2 0xAC 188 189struct mca_adapters_t { 190 unsigned int id; 191 char *name; 192}; 193 194static const struct mca_adapters_t mc32_adapters[] = { 195 { 0x0041, "3COM EtherLink MC/32" }, 196 { 0x8EF5, "IBM High Performance Lan Adapter" }, 197 { 0x0000, NULL } 198}; 199 200 201/* Macros for ring index manipulations */ 202static inline u16 next_rx(u16 rx) { return (rx+1)&(RX_RING_LEN-1); }; 203static inline u16 prev_rx(u16 rx) { return (rx-1)&(RX_RING_LEN-1); }; 204 205static inline u16 next_tx(u16 tx) { return (tx+1)&(TX_RING_LEN-1); }; 206 207 208/* Index to functions, as function prototypes. */ 209static int mc32_probe1(struct net_device *dev, int ioaddr); 210static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len); 211static int mc32_open(struct net_device *dev); 212static void mc32_timeout(struct net_device *dev); 213static netdev_tx_t mc32_send_packet(struct sk_buff *skb, 214 struct net_device *dev); 215static irqreturn_t mc32_interrupt(int irq, void *dev_id); 216static int mc32_close(struct net_device *dev); 217static struct net_device_stats *mc32_get_stats(struct net_device *dev); 218static void mc32_set_multicast_list(struct net_device *dev); 219static void mc32_reset_multicast_list(struct net_device *dev); 220static const struct ethtool_ops netdev_ethtool_ops; 221 222static void cleanup_card(struct net_device *dev) 223{ 224 struct mc32_local *lp = netdev_priv(dev); 225 unsigned slot = lp->slot; 226 mca_mark_as_unused(slot); 227 mca_set_adapter_name(slot, NULL); 228 free_irq(dev->irq, dev); 229 release_region(dev->base_addr, MC32_IO_EXTENT); 230} 231 232/** 233 * mc32_probe - Search for supported boards 234 * @unit: interface number to use 235 * 236 * Because MCA bus is a real bus and we can scan for cards we could do a 237 * single scan for all boards here. Right now we use the passed in device 238 * structure and scan for only one board. This needs fixing for modules 239 * in particular. 240 */ 241 242struct net_device *__init mc32_probe(int unit) 243{ 244 struct net_device *dev = alloc_etherdev(sizeof(struct mc32_local)); 245 static int current_mca_slot = -1; 246 int i; 247 int err; 248 249 if (!dev) 250 return ERR_PTR(-ENOMEM); 251 252 if (unit >= 0) 253 sprintf(dev->name, "eth%d", unit); 254 255 /* Do not check any supplied i/o locations. 256 POS registers usually don't fail :) */ 257 258 /* MCA cards have POS registers. 259 Autodetecting MCA cards is extremely simple. 260 Just search for the card. */ 261 262 for(i = 0; (mc32_adapters[i].name != NULL); i++) { 263 current_mca_slot = 264 mca_find_unused_adapter(mc32_adapters[i].id, 0); 265 266 if(current_mca_slot != MCA_NOTFOUND) { 267 if(!mc32_probe1(dev, current_mca_slot)) 268 { 269 mca_set_adapter_name(current_mca_slot, 270 mc32_adapters[i].name); 271 mca_mark_as_used(current_mca_slot); 272 err = register_netdev(dev); 273 if (err) { 274 cleanup_card(dev); 275 free_netdev(dev); 276 dev = ERR_PTR(err); 277 } 278 return dev; 279 } 280 281 } 282 } 283 free_netdev(dev); 284 return ERR_PTR(-ENODEV); 285} 286 287static const struct net_device_ops netdev_ops = { 288 .ndo_open = mc32_open, 289 .ndo_stop = mc32_close, 290 .ndo_start_xmit = mc32_send_packet, 291 .ndo_get_stats = mc32_get_stats, 292 .ndo_set_multicast_list = mc32_set_multicast_list, 293 .ndo_tx_timeout = mc32_timeout, 294 .ndo_change_mtu = eth_change_mtu, 295 .ndo_set_mac_address = eth_mac_addr, 296 .ndo_validate_addr = eth_validate_addr, 297}; 298 299/** 300 * mc32_probe1 - Check a given slot for a board and test the card 301 * @dev: Device structure to fill in 302 * @slot: The MCA bus slot being used by this card 303 * 304 * Decode the slot data and configure the card structures. Having done this we 305 * can reset the card and configure it. The card does a full self test cycle 306 * in firmware so we have to wait for it to return and post us either a 307 * failure case or some addresses we use to find the board internals. 308 */ 309 310static int __init mc32_probe1(struct net_device *dev, int slot) 311{ 312 static unsigned version_printed; 313 int i, err; 314 u8 POS; 315 u32 base; 316 struct mc32_local *lp = netdev_priv(dev); 317 static u16 mca_io_bases[]={ 318 0x7280,0x7290, 319 0x7680,0x7690, 320 0x7A80,0x7A90, 321 0x7E80,0x7E90 322 }; 323 static u32 mca_mem_bases[]={ 324 0x00C0000, 325 0x00C4000, 326 0x00C8000, 327 0x00CC000, 328 0x00D0000, 329 0x00D4000, 330 0x00D8000, 331 0x00DC000 332 }; 333 static char *failures[]={ 334 "Processor instruction", 335 "Processor data bus", 336 "Processor data bus", 337 "Processor data bus", 338 "Adapter bus", 339 "ROM checksum", 340 "Base RAM", 341 "Extended RAM", 342 "82586 internal loopback", 343 "82586 initialisation failure", 344 "Adapter list configuration error" 345 }; 346 347 /* Time to play MCA games */ 348 349 if (mc32_debug && version_printed++ == 0) 350 pr_debug("%s", version); 351 352 pr_info("%s: %s found in slot %d: ", dev->name, cardname, slot); 353 354 POS = mca_read_stored_pos(slot, 2); 355 356 if(!(POS&1)) 357 { 358 pr_cont("disabled.\n"); 359 return -ENODEV; 360 } 361 362 /* Fill in the 'dev' fields. */ 363 dev->base_addr = mca_io_bases[(POS>>1)&7]; 364 dev->mem_start = mca_mem_bases[(POS>>4)&7]; 365 366 POS = mca_read_stored_pos(slot, 4); 367 if(!(POS&1)) 368 { 369 pr_cont("memory window disabled.\n"); 370 return -ENODEV; 371 } 372 373 POS = mca_read_stored_pos(slot, 5); 374 375 i=(POS>>4)&3; 376 if(i==3) 377 { 378 pr_cont("invalid memory window.\n"); 379 return -ENODEV; 380 } 381 382 i*=16384; 383 i+=16384; 384 385 dev->mem_end=dev->mem_start + i; 386 387 dev->irq = ((POS>>2)&3)+9; 388 389 if(!request_region(dev->base_addr, MC32_IO_EXTENT, cardname)) 390 { 391 pr_cont("io 0x%3lX, which is busy.\n", dev->base_addr); 392 return -EBUSY; 393 } 394 395 pr_cont("io 0x%3lX irq %d mem 0x%lX (%dK)\n", 396 dev->base_addr, dev->irq, dev->mem_start, i/1024); 397 398 399 /* We ought to set the cache line size here.. */ 400 401 402 /* 403 * Go PROM browsing 404 */ 405 406 /* Retrieve and print the ethernet address. */ 407 for (i = 0; i < 6; i++) 408 { 409 mca_write_pos(slot, 6, i+12); 410 mca_write_pos(slot, 7, 0); 411 412 dev->dev_addr[i] = mca_read_pos(slot,3); 413 } 414 415 pr_info("%s: Address %pM ", dev->name, dev->dev_addr); 416 417 mca_write_pos(slot, 6, 0); 418 mca_write_pos(slot, 7, 0); 419 420 POS = mca_read_stored_pos(slot, 4); 421 422 if(POS&2) 423 pr_cont(": BNC port selected.\n"); 424 else 425 pr_cont(": AUI port selected.\n"); 426 427 POS=inb(dev->base_addr+HOST_CTRL); 428 POS|=HOST_CTRL_ATTN|HOST_CTRL_RESET; 429 POS&=~HOST_CTRL_INTE; 430 outb(POS, dev->base_addr+HOST_CTRL); 431 /* Reset adapter */ 432 udelay(100); 433 /* Reset off */ 434 POS&=~(HOST_CTRL_ATTN|HOST_CTRL_RESET); 435 outb(POS, dev->base_addr+HOST_CTRL); 436 437 udelay(300); 438 439 /* 440 * Grab the IRQ 441 */ 442 443 err = request_irq(dev->irq, mc32_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM, DRV_NAME, dev); 444 if (err) { 445 release_region(dev->base_addr, MC32_IO_EXTENT); 446 pr_err("%s: unable to get IRQ %d.\n", DRV_NAME, dev->irq); 447 goto err_exit_ports; 448 } 449 450 memset(lp, 0, sizeof(struct mc32_local)); 451 lp->slot = slot; 452 453 i=0; 454 455 base = inb(dev->base_addr); 456 457 while(base == 0xFF) 458 { 459 i++; 460 if(i == 1000) 461 { 462 pr_err("%s: failed to boot adapter.\n", dev->name); 463 err = -ENODEV; 464 goto err_exit_irq; 465 } 466 udelay(1000); 467 if(inb(dev->base_addr+2)&(1<<5)) 468 base = inb(dev->base_addr); 469 } 470 471 if(base>0) 472 { 473 if(base < 0x0C) 474 pr_err("%s: %s%s.\n", dev->name, failures[base-1], 475 base<0x0A?" test failure":""); 476 else 477 pr_err("%s: unknown failure %d.\n", dev->name, base); 478 err = -ENODEV; 479 goto err_exit_irq; 480 } 481 482 base=0; 483 for(i=0;i<4;i++) 484 { 485 int n=0; 486 487 while(!(inb(dev->base_addr+2)&(1<<5))) 488 { 489 n++; 490 udelay(50); 491 if(n>100) 492 { 493 pr_err("%s: mailbox read fail (%d).\n", dev->name, i); 494 err = -ENODEV; 495 goto err_exit_irq; 496 } 497 } 498 499 base|=(inb(dev->base_addr)<<(8*i)); 500 } 501 502 lp->exec_box=isa_bus_to_virt(dev->mem_start+base); 503 504 base=lp->exec_box->data[1]<<16|lp->exec_box->data[0]; 505 506 lp->base = dev->mem_start+base; 507 508 lp->rx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[2]); 509 lp->tx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[3]); 510 511 lp->stats = isa_bus_to_virt(lp->base + lp->exec_box->data[5]); 512 513 /* 514 * Descriptor chains (card relative) 515 */ 516 517 lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ 518 lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ 519 lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ 520 lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ 521 522 init_MUTEX_LOCKED(&lp->cmd_mutex); 523 init_completion(&lp->execution_cmd); 524 init_completion(&lp->xceiver_cmd); 525 526 pr_info("%s: Firmware Rev %d. %d RX buffers, %d TX buffers. Base of 0x%08X.\n", 527 dev->name, lp->exec_box->data[12], lp->rx_len, lp->tx_len, lp->base); 528 529 dev->netdev_ops = &netdev_ops; 530 dev->watchdog_timeo = HZ*5; /* Board does all the work */ 531 dev->ethtool_ops = &netdev_ethtool_ops; 532 533 return 0; 534 535err_exit_irq: 536 free_irq(dev->irq, dev); 537err_exit_ports: 538 release_region(dev->base_addr, MC32_IO_EXTENT); 539 return err; 540} 541 542 543/** 544 * mc32_ready_poll - wait until we can feed it a command 545 * @dev: The device to wait for 546 * 547 * Wait until the card becomes ready to accept a command via the 548 * command register. This tells us nothing about the completion 549 * status of any pending commands and takes very little time at all. 550 */ 551 552static inline void mc32_ready_poll(struct net_device *dev) 553{ 554 int ioaddr = dev->base_addr; 555 while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR)); 556} 557 558 559/** 560 * mc32_command_nowait - send a command non blocking 561 * @dev: The 3c527 to issue the command to 562 * @cmd: The command word to write to the mailbox 563 * @data: A data block if the command expects one 564 * @len: Length of the data block 565 * 566 * Send a command from interrupt state. If there is a command 567 * currently being executed then we return an error of -1. It 568 * simply isn't viable to wait around as commands may be 569 * slow. This can theoretically be starved on SMP, but it's hard 570 * to see a realistic situation. We do not wait for the command 571 * to complete --- we rely on the interrupt handler to tidy up 572 * after us. 573 */ 574 575static int mc32_command_nowait(struct net_device *dev, u16 cmd, void *data, int len) 576{ 577 struct mc32_local *lp = netdev_priv(dev); 578 int ioaddr = dev->base_addr; 579 int ret = -1; 580 581 if (down_trylock(&lp->cmd_mutex) == 0) 582 { 583 lp->cmd_nonblocking=1; 584 lp->exec_box->mbox=0; 585 lp->exec_box->mbox=cmd; 586 memcpy((void *)lp->exec_box->data, data, len); 587 barrier(); /* the memcpy forgot the volatile so be sure */ 588 589 /* Send the command */ 590 mc32_ready_poll(dev); 591 outb(1<<6, ioaddr+HOST_CMD); 592 593 ret = 0; 594 595 /* Interrupt handler will signal mutex on completion */ 596 } 597 598 return ret; 599} 600 601 602/** 603 * mc32_command - send a command and sleep until completion 604 * @dev: The 3c527 card to issue the command to 605 * @cmd: The command word to write to the mailbox 606 * @data: A data block if the command expects one 607 * @len: Length of the data block 608 * 609 * Sends exec commands in a user context. This permits us to wait around 610 * for the replies and also to wait for the command buffer to complete 611 * from a previous command before we execute our command. After our 612 * command completes we will attempt any pending multicast reload 613 * we blocked off by hogging the exec buffer. 614 * 615 * You feed the card a command, you wait, it interrupts you get a 616 * reply. All well and good. The complication arises because you use 617 * commands for filter list changes which come in at bh level from things 618 * like IPV6 group stuff. 619 */ 620 621static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len) 622{ 623 struct mc32_local *lp = netdev_priv(dev); 624 int ioaddr = dev->base_addr; 625 int ret = 0; 626 627 down(&lp->cmd_mutex); 628 629 /* 630 * My Turn 631 */ 632 633 lp->cmd_nonblocking=0; 634 lp->exec_box->mbox=0; 635 lp->exec_box->mbox=cmd; 636 memcpy((void *)lp->exec_box->data, data, len); 637 barrier(); /* the memcpy forgot the volatile so be sure */ 638 639 mc32_ready_poll(dev); 640 outb(1<<6, ioaddr+HOST_CMD); 641 642 wait_for_completion(&lp->execution_cmd); 643 644 if(lp->exec_box->mbox&(1<<13)) 645 ret = -1; 646 647 up(&lp->cmd_mutex); 648 649 /* 650 * A multicast set got blocked - try it now 651 */ 652 653 if(lp->mc_reload_wait) 654 { 655 mc32_reset_multicast_list(dev); 656 } 657 658 return ret; 659} 660 661 662/** 663 * mc32_start_transceiver - tell board to restart tx/rx 664 * @dev: The 3c527 card to issue the command to 665 * 666 * This may be called from the interrupt state, where it is used 667 * to restart the rx ring if the card runs out of rx buffers. 668 * 669 * We must first check if it's ok to (re)start the transceiver. See 670 * mc32_close for details. 671 */ 672 673static void mc32_start_transceiver(struct net_device *dev) { 674 675 struct mc32_local *lp = netdev_priv(dev); 676 int ioaddr = dev->base_addr; 677 678 /* Ignore RX overflow on device closure */ 679 if (lp->xceiver_desired_state==HALTED) 680 return; 681 682 /* Give the card the offset to the post-EOL-bit RX descriptor */ 683 mc32_ready_poll(dev); 684 lp->rx_box->mbox=0; 685 lp->rx_box->data[0]=lp->rx_ring[prev_rx(lp->rx_ring_tail)].p->next; 686 outb(HOST_CMD_START_RX, ioaddr+HOST_CMD); 687 688 mc32_ready_poll(dev); 689 lp->tx_box->mbox=0; 690 outb(HOST_CMD_RESTRT_TX, ioaddr+HOST_CMD); /* card ignores this on RX restart */ 691 692 /* We are not interrupted on start completion */ 693} 694 695 696/** 697 * mc32_halt_transceiver - tell board to stop tx/rx 698 * @dev: The 3c527 card to issue the command to 699 * 700 * We issue the commands to halt the card's transceiver. In fact, 701 * after some experimenting we now simply tell the card to 702 * suspend. When issuing aborts occasionally odd things happened. 703 * 704 * We then sleep until the card has notified us that both rx and 705 * tx have been suspended. 706 */ 707 708static void mc32_halt_transceiver(struct net_device *dev) 709{ 710 struct mc32_local *lp = netdev_priv(dev); 711 int ioaddr = dev->base_addr; 712 713 mc32_ready_poll(dev); 714 lp->rx_box->mbox=0; 715 outb(HOST_CMD_SUSPND_RX, ioaddr+HOST_CMD); 716 wait_for_completion(&lp->xceiver_cmd); 717 718 mc32_ready_poll(dev); 719 lp->tx_box->mbox=0; 720 outb(HOST_CMD_SUSPND_TX, ioaddr+HOST_CMD); 721 wait_for_completion(&lp->xceiver_cmd); 722} 723 724 725/** 726 * mc32_load_rx_ring - load the ring of receive buffers 727 * @dev: 3c527 to build the ring for 728 * 729 * This initialises the on-card and driver datastructures to 730 * the point where mc32_start_transceiver() can be called. 731 * 732 * The card sets up the receive ring for us. We are required to use the 733 * ring it provides, although the size of the ring is configurable. 734 * 735 * We allocate an sk_buff for each ring entry in turn and 736 * initialise its house-keeping info. At the same time, we read 737 * each 'next' pointer in our rx_ring array. This reduces slow 738 * shared-memory reads and makes it easy to access predecessor 739 * descriptors. 740 * 741 * We then set the end-of-list bit for the last entry so that the 742 * card will know when it has run out of buffers. 743 */ 744 745static int mc32_load_rx_ring(struct net_device *dev) 746{ 747 struct mc32_local *lp = netdev_priv(dev); 748 int i; 749 u16 rx_base; 750 volatile struct skb_header *p; 751 752 rx_base=lp->rx_chain; 753 754 for(i=0; i<RX_RING_LEN; i++) { 755 lp->rx_ring[i].skb=alloc_skb(1532, GFP_KERNEL); 756 if (lp->rx_ring[i].skb==NULL) { 757 for (;i>=0;i--) 758 kfree_skb(lp->rx_ring[i].skb); 759 return -ENOBUFS; 760 } 761 skb_reserve(lp->rx_ring[i].skb, 18); 762 763 p=isa_bus_to_virt(lp->base+rx_base); 764 765 p->control=0; 766 p->data=isa_virt_to_bus(lp->rx_ring[i].skb->data); 767 p->status=0; 768 p->length=1532; 769 770 lp->rx_ring[i].p=p; 771 rx_base=p->next; 772 } 773 774 lp->rx_ring[i-1].p->control |= CONTROL_EOL; 775 776 lp->rx_ring_tail=0; 777 778 return 0; 779} 780 781 782/** 783 * mc32_flush_rx_ring - free the ring of receive buffers 784 * @lp: Local data of 3c527 to flush the rx ring of 785 * 786 * Free the buffer for each ring slot. This may be called 787 * before mc32_load_rx_ring(), eg. on error in mc32_open(). 788 * Requires rx skb pointers to point to a valid skb, or NULL. 789 */ 790 791static void mc32_flush_rx_ring(struct net_device *dev) 792{ 793 struct mc32_local *lp = netdev_priv(dev); 794 int i; 795 796 for(i=0; i < RX_RING_LEN; i++) 797 { 798 if (lp->rx_ring[i].skb) { 799 dev_kfree_skb(lp->rx_ring[i].skb); 800 lp->rx_ring[i].skb = NULL; 801 } 802 lp->rx_ring[i].p=NULL; 803 } 804} 805 806 807/** 808 * mc32_load_tx_ring - load transmit ring 809 * @dev: The 3c527 card to issue the command to 810 * 811 * This sets up the host transmit data-structures. 812 * 813 * First, we obtain from the card it's current postion in the tx 814 * ring, so that we will know where to begin transmitting 815 * packets. 816 * 817 * Then, we read the 'next' pointers from the on-card tx ring into 818 * our tx_ring array to reduce slow shared-mem reads. Finally, we 819 * intitalise the tx house keeping variables. 820 * 821 */ 822 823static void mc32_load_tx_ring(struct net_device *dev) 824{ 825 struct mc32_local *lp = netdev_priv(dev); 826 volatile struct skb_header *p; 827 int i; 828 u16 tx_base; 829 830 tx_base=lp->tx_box->data[0]; 831 832 for(i=0 ; i<TX_RING_LEN ; i++) 833 { 834 p=isa_bus_to_virt(lp->base+tx_base); 835 lp->tx_ring[i].p=p; 836 lp->tx_ring[i].skb=NULL; 837 838 tx_base=p->next; 839 } 840 841 /* -1 so that tx_ring_head cannot "lap" tx_ring_tail */ 842 /* see mc32_tx_ring */ 843 844 atomic_set(&lp->tx_count, TX_RING_LEN-1); 845 atomic_set(&lp->tx_ring_head, 0); 846 lp->tx_ring_tail=0; 847} 848 849 850/** 851 * mc32_flush_tx_ring - free transmit ring 852 * @lp: Local data of 3c527 to flush the tx ring of 853 * 854 * If the ring is non-empty, zip over the it, freeing any 855 * allocated skb_buffs. The tx ring house-keeping variables are 856 * then reset. Requires rx skb pointers to point to a valid skb, 857 * or NULL. 858 */ 859 860static void mc32_flush_tx_ring(struct net_device *dev) 861{ 862 struct mc32_local *lp = netdev_priv(dev); 863 int i; 864 865 for (i=0; i < TX_RING_LEN; i++) 866 { 867 if (lp->tx_ring[i].skb) 868 { 869 dev_kfree_skb(lp->tx_ring[i].skb); 870 lp->tx_ring[i].skb = NULL; 871 } 872 } 873 874 atomic_set(&lp->tx_count, 0); 875 atomic_set(&lp->tx_ring_head, 0); 876 lp->tx_ring_tail=0; 877} 878 879 880 881static int mc32_open(struct net_device *dev) 882{ 883 int ioaddr = dev->base_addr; 884 struct mc32_local *lp = netdev_priv(dev); 885 u8 one=1; 886 u8 regs; 887 u16 descnumbuffs[2] = {TX_RING_LEN, RX_RING_LEN}; 888 889 /* 890 * Interrupts enabled 891 */ 892 893 regs=inb(ioaddr+HOST_CTRL); 894 regs|=HOST_CTRL_INTE; 895 outb(regs, ioaddr+HOST_CTRL); 896 897 /* 898 * Allow ourselves to issue commands 899 */ 900 901 up(&lp->cmd_mutex); 902 903 904 /* 905 * Send the indications on command 906 */ 907 908 mc32_command(dev, 4, &one, 2); 909 910 /* 911 * Poke it to make sure it's really dead. 912 */ 913 914 mc32_halt_transceiver(dev); 915 mc32_flush_tx_ring(dev); 916 917 /* 918 * Ask card to set up on-card descriptors to our spec 919 */ 920 921 if(mc32_command(dev, 8, descnumbuffs, 4)) { 922 pr_info("%s: %s rejected our buffer configuration!\n", 923 dev->name, cardname); 924 mc32_close(dev); 925 return -ENOBUFS; 926 } 927 928 /* Report new configuration */ 929 mc32_command(dev, 6, NULL, 0); 930 931 lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ 932 lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ 933 lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ 934 lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ 935 936 /* Set Network Address */ 937 mc32_command(dev, 1, dev->dev_addr, 6); 938 939 /* Set the filters */ 940 mc32_set_multicast_list(dev); 941 942 if (WORKAROUND_82586) { 943 u16 zero_word=0; 944 mc32_command(dev, 0x0D, &zero_word, 2); 945 } 946 947 mc32_load_tx_ring(dev); 948 949 if(mc32_load_rx_ring(dev)) 950 { 951 mc32_close(dev); 952 return -ENOBUFS; 953 } 954 955 lp->xceiver_desired_state = RUNNING; 956 957 /* And finally, set the ball rolling... */ 958 mc32_start_transceiver(dev); 959 960 netif_start_queue(dev); 961 962 return 0; 963} 964 965 966/** 967 * mc32_timeout - handle a timeout from the network layer 968 * @dev: 3c527 that timed out 969 * 970 * Handle a timeout on transmit from the 3c527. This normally means 971 * bad things as the hardware handles cable timeouts and mess for 972 * us. 973 * 974 */ 975 976static void mc32_timeout(struct net_device *dev) 977{ 978 pr_warning("%s: transmit timed out?\n", dev->name); 979 /* Try to restart the adaptor. */ 980 netif_wake_queue(dev); 981} 982 983 984/** 985 * mc32_send_packet - queue a frame for transmit 986 * @skb: buffer to transmit 987 * @dev: 3c527 to send it out of 988 * 989 * Transmit a buffer. This normally means throwing the buffer onto 990 * the transmit queue as the queue is quite large. If the queue is 991 * full then we set tx_busy and return. Once the interrupt handler 992 * gets messages telling it to reclaim transmit queue entries, we will 993 * clear tx_busy and the kernel will start calling this again. 994 * 995 * We do not disable interrupts or acquire any locks; this can 996 * run concurrently with mc32_tx_ring(), and the function itself 997 * is serialised at a higher layer. However, similarly for the 998 * card itself, we must ensure that we update tx_ring_head only 999 * after we've established a valid packet on the tx ring (and 1000 * before we let the card "see" it, to prevent it racing with the 1001 * irq handler). 1002 * 1003 */ 1004 1005static netdev_tx_t mc32_send_packet(struct sk_buff *skb, 1006 struct net_device *dev) 1007{ 1008 struct mc32_local *lp = netdev_priv(dev); 1009 u32 head = atomic_read(&lp->tx_ring_head); 1010 1011 volatile struct skb_header *p, *np; 1012 1013 netif_stop_queue(dev); 1014 1015 if(atomic_read(&lp->tx_count)==0) { 1016 return NETDEV_TX_BUSY; 1017 } 1018 1019 if (skb_padto(skb, ETH_ZLEN)) { 1020 netif_wake_queue(dev); 1021 return NETDEV_TX_OK; 1022 } 1023 1024 atomic_dec(&lp->tx_count); 1025 1026 /* P is the last sending/sent buffer as a pointer */ 1027 p=lp->tx_ring[head].p; 1028 1029 head = next_tx(head); 1030 1031 /* NP is the buffer we will be loading */ 1032 np=lp->tx_ring[head].p; 1033 1034 /* We will need this to flush the buffer out */ 1035 lp->tx_ring[head].skb=skb; 1036 1037 np->length = unlikely(skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len; 1038 np->data = isa_virt_to_bus(skb->data); 1039 np->status = 0; 1040 np->control = CONTROL_EOP | CONTROL_EOL; 1041 wmb(); 1042 1043 /* 1044 * The new frame has been setup; we can now 1045 * let the interrupt handler and card "see" it 1046 */ 1047 1048 atomic_set(&lp->tx_ring_head, head); 1049 p->control &= ~CONTROL_EOL; 1050 1051 netif_wake_queue(dev); 1052 return NETDEV_TX_OK; 1053} 1054 1055 1056/** 1057 * mc32_update_stats - pull off the on board statistics 1058 * @dev: 3c527 to service 1059 * 1060 * 1061 * Query and reset the on-card stats. There's the small possibility 1062 * of a race here, which would result in an underestimation of 1063 * actual errors. As such, we'd prefer to keep all our stats 1064 * collection in software. As a rule, we do. However it can't be 1065 * used for rx errors and collisions as, by default, the card discards 1066 * bad rx packets. 1067 * 1068 * Setting the SAV BP in the rx filter command supposedly 1069 * stops this behaviour. However, testing shows that it only seems to 1070 * enable the collation of on-card rx statistics --- the driver 1071 * never sees an RX descriptor with an error status set. 1072 * 1073 */ 1074 1075static void mc32_update_stats(struct net_device *dev) 1076{ 1077 struct mc32_local *lp = netdev_priv(dev); 1078 volatile struct mc32_stats *st = lp->stats; 1079 1080 u32 rx_errors=0; 1081 1082 rx_errors+=dev->stats.rx_crc_errors +=st->rx_crc_errors; 1083 st->rx_crc_errors=0; 1084 rx_errors+=dev->stats.rx_fifo_errors +=st->rx_overrun_errors; 1085 st->rx_overrun_errors=0; 1086 rx_errors+=dev->stats.rx_frame_errors +=st->rx_alignment_errors; 1087 st->rx_alignment_errors=0; 1088 rx_errors+=dev->stats.rx_length_errors+=st->rx_tooshort_errors; 1089 st->rx_tooshort_errors=0; 1090 rx_errors+=dev->stats.rx_missed_errors+=st->rx_outofresource_errors; 1091 st->rx_outofresource_errors=0; 1092 dev->stats.rx_errors=rx_errors; 1093 1094 /* Number of packets which saw one collision */ 1095 dev->stats.collisions+=st->dataC[10]; 1096 st->dataC[10]=0; 1097 1098 /* Number of packets which saw 2--15 collisions */ 1099 dev->stats.collisions+=st->dataC[11]; 1100 st->dataC[11]=0; 1101} 1102 1103 1104/** 1105 * mc32_rx_ring - process the receive ring 1106 * @dev: 3c527 that needs its receive ring processing 1107 * 1108 * 1109 * We have received one or more indications from the card that a 1110 * receive has completed. The buffer ring thus contains dirty 1111 * entries. We walk the ring by iterating over the circular rx_ring 1112 * array, starting at the next dirty buffer (which happens to be the 1113 * one we finished up at last time around). 1114 * 1115 * For each completed packet, we will either copy it and pass it up 1116 * the stack or, if the packet is near MTU sized, we allocate 1117 * another buffer and flip the old one up the stack. 1118 * 1119 * We must succeed in keeping a buffer on the ring. If necessary we 1120 * will toss a received packet rather than lose a ring entry. Once 1121 * the first uncompleted descriptor is found, we move the 1122 * End-Of-List bit to include the buffers just processed. 1123 * 1124 */ 1125 1126static void mc32_rx_ring(struct net_device *dev) 1127{ 1128 struct mc32_local *lp = netdev_priv(dev); 1129 volatile struct skb_header *p; 1130 u16 rx_ring_tail; 1131 u16 rx_old_tail; 1132 int x=0; 1133 1134 rx_old_tail = rx_ring_tail = lp->rx_ring_tail; 1135 1136 do 1137 { 1138 p=lp->rx_ring[rx_ring_tail].p; 1139 1140 if(!(p->status & (1<<7))) { /* Not COMPLETED */ 1141 break; 1142 } 1143 if(p->status & (1<<6)) /* COMPLETED_OK */ 1144 { 1145 1146 u16 length=p->length; 1147 struct sk_buff *skb; 1148 struct sk_buff *newskb; 1149 1150 /* Try to save time by avoiding a copy on big frames */ 1151 1152 if ((length > RX_COPYBREAK) && 1153 ((newskb=dev_alloc_skb(1532)) != NULL)) 1154 { 1155 skb=lp->rx_ring[rx_ring_tail].skb; 1156 skb_put(skb, length); 1157 1158 skb_reserve(newskb,18); 1159 lp->rx_ring[rx_ring_tail].skb=newskb; 1160 p->data=isa_virt_to_bus(newskb->data); 1161 } 1162 else 1163 { 1164 skb=dev_alloc_skb(length+2); 1165 1166 if(skb==NULL) { 1167 dev->stats.rx_dropped++; 1168 goto dropped; 1169 } 1170 1171 skb_reserve(skb,2); 1172 memcpy(skb_put(skb, length), 1173 lp->rx_ring[rx_ring_tail].skb->data, length); 1174 } 1175 1176 skb->protocol=eth_type_trans(skb,dev); 1177 dev->stats.rx_packets++; 1178 dev->stats.rx_bytes += length; 1179 netif_rx(skb); 1180 } 1181 1182 dropped: 1183 p->length = 1532; 1184 p->status = 0; 1185 1186 rx_ring_tail=next_rx(rx_ring_tail); 1187 } 1188 while(x++<48); 1189 1190 /* If there was actually a frame to be processed, place the EOL bit */ 1191 /* at the descriptor prior to the one to be filled next */ 1192 1193 if (rx_ring_tail != rx_old_tail) 1194 { 1195 lp->rx_ring[prev_rx(rx_ring_tail)].p->control |= CONTROL_EOL; 1196 lp->rx_ring[prev_rx(rx_old_tail)].p->control &= ~CONTROL_EOL; 1197 1198 lp->rx_ring_tail=rx_ring_tail; 1199 } 1200} 1201 1202 1203/** 1204 * mc32_tx_ring - process completed transmits 1205 * @dev: 3c527 that needs its transmit ring processing 1206 * 1207 * 1208 * This operates in a similar fashion to mc32_rx_ring. We iterate 1209 * over the transmit ring. For each descriptor which has been 1210 * processed by the card, we free its associated buffer and note 1211 * any errors. This continues until the transmit ring is emptied 1212 * or we reach a descriptor that hasn't yet been processed by the 1213 * card. 1214 * 1215 */ 1216 1217static void mc32_tx_ring(struct net_device *dev) 1218{ 1219 struct mc32_local *lp = netdev_priv(dev); 1220 volatile struct skb_header *np; 1221 1222 /* 1223 * We rely on head==tail to mean 'queue empty'. 1224 * This is why lp->tx_count=TX_RING_LEN-1: in order to prevent 1225 * tx_ring_head wrapping to tail and confusing a 'queue empty' 1226 * condition with 'queue full' 1227 */ 1228 1229 while (lp->tx_ring_tail != atomic_read(&lp->tx_ring_head)) 1230 { 1231 u16 t; 1232 1233 t=next_tx(lp->tx_ring_tail); 1234 np=lp->tx_ring[t].p; 1235 1236 if(!(np->status & (1<<7))) 1237 { 1238 /* Not COMPLETED */ 1239 break; 1240 } 1241 dev->stats.tx_packets++; 1242 if(!(np->status & (1<<6))) /* Not COMPLETED_OK */ 1243 { 1244 dev->stats.tx_errors++; 1245 1246 switch(np->status&0x0F) 1247 { 1248 case 1: 1249 dev->stats.tx_aborted_errors++; 1250 break; /* Max collisions */ 1251 case 2: 1252 dev->stats.tx_fifo_errors++; 1253 break; 1254 case 3: 1255 dev->stats.tx_carrier_errors++; 1256 break; 1257 case 4: 1258 dev->stats.tx_window_errors++; 1259 break; /* CTS Lost */ 1260 case 5: 1261 dev->stats.tx_aborted_errors++; 1262 break; /* Transmit timeout */ 1263 } 1264 } 1265 /* Packets are sent in order - this is 1266 basically a FIFO queue of buffers matching 1267 the card ring */ 1268 dev->stats.tx_bytes+=lp->tx_ring[t].skb->len; 1269 dev_kfree_skb_irq(lp->tx_ring[t].skb); 1270 lp->tx_ring[t].skb=NULL; 1271 atomic_inc(&lp->tx_count); 1272 netif_wake_queue(dev); 1273 1274 lp->tx_ring_tail=t; 1275 } 1276 1277} 1278 1279 1280/** 1281 * mc32_interrupt - handle an interrupt from a 3c527 1282 * @irq: Interrupt number 1283 * @dev_id: 3c527 that requires servicing 1284 * @regs: Registers (unused) 1285 * 1286 * 1287 * An interrupt is raised whenever the 3c527 writes to the command 1288 * register. This register contains the message it wishes to send us 1289 * packed into a single byte field. We keep reading status entries 1290 * until we have processed all the control items, but simply count 1291 * transmit and receive reports. When all reports are in we empty the 1292 * transceiver rings as appropriate. This saves the overhead of 1293 * multiple command requests. 1294 * 1295 * Because MCA is level-triggered, we shouldn't miss indications. 1296 * Therefore, we needn't ask the card to suspend interrupts within 1297 * this handler. The card receives an implicit acknowledgment of the 1298 * current interrupt when we read the command register. 1299 * 1300 */ 1301 1302static irqreturn_t mc32_interrupt(int irq, void *dev_id) 1303{ 1304 struct net_device *dev = dev_id; 1305 struct mc32_local *lp; 1306 int ioaddr, status, boguscount = 0; 1307 int rx_event = 0; 1308 int tx_event = 0; 1309 1310 ioaddr = dev->base_addr; 1311 lp = netdev_priv(dev); 1312 1313 /* See whats cooking */ 1314 1315 while((inb(ioaddr+HOST_STATUS)&HOST_STATUS_CWR) && boguscount++<2000) 1316 { 1317 status=inb(ioaddr+HOST_CMD); 1318 1319 pr_debug("Status TX%d RX%d EX%d OV%d BC%d\n", 1320 (status&7), (status>>3)&7, (status>>6)&1, 1321 (status>>7)&1, boguscount); 1322 1323 switch(status&7) 1324 { 1325 case 0: 1326 break; 1327 case 6: /* TX fail */ 1328 case 2: /* TX ok */ 1329 tx_event = 1; 1330 break; 1331 case 3: /* Halt */ 1332 case 4: /* Abort */ 1333 complete(&lp->xceiver_cmd); 1334 break; 1335 default: 1336 pr_notice("%s: strange tx ack %d\n", dev->name, status&7); 1337 } 1338 status>>=3; 1339 switch(status&7) 1340 { 1341 case 0: 1342 break; 1343 case 2: /* RX */ 1344 rx_event=1; 1345 break; 1346 case 3: /* Halt */ 1347 case 4: /* Abort */ 1348 complete(&lp->xceiver_cmd); 1349 break; 1350 case 6: 1351 /* Out of RX buffers stat */ 1352 /* Must restart rx */ 1353 dev->stats.rx_dropped++; 1354 mc32_rx_ring(dev); 1355 mc32_start_transceiver(dev); 1356 break; 1357 default: 1358 pr_notice("%s: strange rx ack %d\n", 1359 dev->name, status&7); 1360 } 1361 status>>=3; 1362 if(status&1) 1363 { 1364 /* 1365 * No thread is waiting: we need to tidy 1366 * up ourself. 1367 */ 1368 1369 if (lp->cmd_nonblocking) { 1370 up(&lp->cmd_mutex); 1371 if (lp->mc_reload_wait) 1372 mc32_reset_multicast_list(dev); 1373 } 1374 else complete(&lp->execution_cmd); 1375 } 1376 if(status&2) 1377 { 1378 /* 1379 * We get interrupted once per 1380 * counter that is about to overflow. 1381 */ 1382 1383 mc32_update_stats(dev); 1384 } 1385 } 1386 1387 1388 /* 1389 * Process the transmit and receive rings 1390 */ 1391 1392 if(tx_event) 1393 mc32_tx_ring(dev); 1394 1395 if(rx_event) 1396 mc32_rx_ring(dev); 1397 1398 return IRQ_HANDLED; 1399} 1400 1401 1402/** 1403 * mc32_close - user configuring the 3c527 down 1404 * @dev: 3c527 card to shut down 1405 * 1406 * The 3c527 is a bus mastering device. We must be careful how we 1407 * shut it down. It may also be running shared interrupt so we have 1408 * to be sure to silence it properly 1409 * 1410 * We indicate that the card is closing to the rest of the 1411 * driver. Otherwise, it is possible that the card may run out 1412 * of receive buffers and restart the transceiver while we're 1413 * trying to close it. 1414 * 1415 * We abort any receive and transmits going on and then wait until 1416 * any pending exec commands have completed in other code threads. 1417 * In theory we can't get here while that is true, in practice I am 1418 * paranoid 1419 * 1420 * We turn off the interrupt enable for the board to be sure it can't 1421 * intefere with other devices. 1422 */ 1423 1424static int mc32_close(struct net_device *dev) 1425{ 1426 struct mc32_local *lp = netdev_priv(dev); 1427 int ioaddr = dev->base_addr; 1428 1429 u8 regs; 1430 u16 one=1; 1431 1432 lp->xceiver_desired_state = HALTED; 1433 netif_stop_queue(dev); 1434 1435 /* 1436 * Send the indications on command (handy debug check) 1437 */ 1438 1439 mc32_command(dev, 4, &one, 2); 1440 1441 /* Shut down the transceiver */ 1442 1443 mc32_halt_transceiver(dev); 1444 1445 /* Ensure we issue no more commands beyond this point */ 1446 1447 down(&lp->cmd_mutex); 1448 1449 /* Ok the card is now stopping */ 1450 1451 regs=inb(ioaddr+HOST_CTRL); 1452 regs&=~HOST_CTRL_INTE; 1453 outb(regs, ioaddr+HOST_CTRL); 1454 1455 mc32_flush_rx_ring(dev); 1456 mc32_flush_tx_ring(dev); 1457 1458 mc32_update_stats(dev); 1459 1460 return 0; 1461} 1462 1463 1464/** 1465 * mc32_get_stats - hand back stats to network layer 1466 * @dev: The 3c527 card to handle 1467 * 1468 * We've collected all the stats we can in software already. Now 1469 * it's time to update those kept on-card and return the lot. 1470 * 1471 */ 1472 1473static struct net_device_stats *mc32_get_stats(struct net_device *dev) 1474{ 1475 mc32_update_stats(dev); 1476 return &dev->stats; 1477} 1478 1479 1480/** 1481 * do_mc32_set_multicast_list - attempt to update multicasts 1482 * @dev: 3c527 device to load the list on 1483 * @retry: indicates this is not the first call. 1484 * 1485 * 1486 * Actually set or clear the multicast filter for this adaptor. The 1487 * locking issues are handled by this routine. We have to track 1488 * state as it may take multiple calls to get the command sequence 1489 * completed. We just keep trying to schedule the loads until we 1490 * manage to process them all. 1491 * 1492 * num_addrs == -1 Promiscuous mode, receive all packets 1493 * 1494 * num_addrs == 0 Normal mode, clear multicast list 1495 * 1496 * num_addrs > 0 Multicast mode, receive normal and MC packets, 1497 * and do best-effort filtering. 1498 * 1499 * See mc32_update_stats() regards setting the SAV BP bit. 1500 * 1501 */ 1502 1503static void do_mc32_set_multicast_list(struct net_device *dev, int retry) 1504{ 1505 struct mc32_local *lp = netdev_priv(dev); 1506 u16 filt = (1<<2); /* Save Bad Packets, for stats purposes */ 1507 1508 if ((dev->flags&IFF_PROMISC) || 1509 (dev->flags&IFF_ALLMULTI) || 1510 netdev_mc_count(dev) > 10) 1511 /* Enable promiscuous mode */ 1512 filt |= 1; 1513 else if (!netdev_mc_empty(dev)) 1514 { 1515 unsigned char block[62]; 1516 unsigned char *bp; 1517 struct netdev_hw_addr *ha; 1518 1519 if(retry==0) 1520 lp->mc_list_valid = 0; 1521 if(!lp->mc_list_valid) 1522 { 1523 block[1]=0; 1524 block[0]=netdev_mc_count(dev); 1525 bp=block+2; 1526 1527 netdev_for_each_mc_addr(ha, dev) { 1528 memcpy(bp, ha->addr, 6); 1529 bp+=6; 1530 } 1531 if(mc32_command_nowait(dev, 2, block, 1532 2+6*netdev_mc_count(dev))==-1) 1533 { 1534 lp->mc_reload_wait = 1; 1535 return; 1536 } 1537 lp->mc_list_valid=1; 1538 } 1539 } 1540 1541 if(mc32_command_nowait(dev, 0, &filt, 2)==-1) 1542 { 1543 lp->mc_reload_wait = 1; 1544 } 1545 else { 1546 lp->mc_reload_wait = 0; 1547 } 1548} 1549 1550 1551/** 1552 * mc32_set_multicast_list - queue multicast list update 1553 * @dev: The 3c527 to use 1554 * 1555 * Commence loading the multicast list. This is called when the kernel 1556 * changes the lists. It will override any pending list we are trying to 1557 * load. 1558 */ 1559 1560static void mc32_set_multicast_list(struct net_device *dev) 1561{ 1562 do_mc32_set_multicast_list(dev,0); 1563} 1564 1565 1566/** 1567 * mc32_reset_multicast_list - reset multicast list 1568 * @dev: The 3c527 to use 1569 * 1570 * Attempt the next step in loading the multicast lists. If this attempt 1571 * fails to complete then it will be scheduled and this function called 1572 * again later from elsewhere. 1573 */ 1574 1575static void mc32_reset_multicast_list(struct net_device *dev) 1576{ 1577 do_mc32_set_multicast_list(dev,1); 1578} 1579 1580static void netdev_get_drvinfo(struct net_device *dev, 1581 struct ethtool_drvinfo *info) 1582{ 1583 strcpy(info->driver, DRV_NAME); 1584 strcpy(info->version, DRV_VERSION); 1585 sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr); 1586} 1587 1588static u32 netdev_get_msglevel(struct net_device *dev) 1589{ 1590 return mc32_debug; 1591} 1592 1593static void netdev_set_msglevel(struct net_device *dev, u32 level) 1594{ 1595 mc32_debug = level; 1596} 1597 1598static const struct ethtool_ops netdev_ethtool_ops = { 1599 .get_drvinfo = netdev_get_drvinfo, 1600 .get_msglevel = netdev_get_msglevel, 1601 .set_msglevel = netdev_set_msglevel, 1602}; 1603 1604#ifdef MODULE 1605 1606static struct net_device *this_device; 1607 1608/** 1609 * init_module - entry point 1610 * 1611 * Probe and locate a 3c527 card. This really should probe and locate 1612 * all the 3c527 cards in the machine not just one of them. Yes you can 1613 * insmod multiple modules for now but it's a hack. 1614 */ 1615 1616int __init init_module(void) 1617{ 1618 this_device = mc32_probe(-1); 1619 if (IS_ERR(this_device)) 1620 return PTR_ERR(this_device); 1621 return 0; 1622} 1623 1624/** 1625 * cleanup_module - free resources for an unload 1626 * 1627 * Unloading time. We release the MCA bus resources and the interrupt 1628 * at which point everything is ready to unload. The card must be stopped 1629 * at this point or we would not have been called. When we unload we 1630 * leave the card stopped but not totally shut down. When the card is 1631 * initialized it must be rebooted or the rings reloaded before any 1632 * transmit operations are allowed to start scribbling into memory. 1633 */ 1634 1635void __exit cleanup_module(void) 1636{ 1637 unregister_netdev(this_device); 1638 cleanup_card(this_device); 1639 free_netdev(this_device); 1640} 1641 1642#endif /* MODULE */ 1643