47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/string.h>
51 #include <linux/errno.h>
53 #include <linux/slab.h>
55 #include <linux/pci.h>
57 #include <linux/netdevice.h>
61 #include <linux/bitops.h>
66 static unsigned int lance_portlist[]
__initdata = { 0x300, 0x320, 0x340, 0x360, 0};
93 static int lance_debug = 1;
188 #ifndef LANCE_LOG_TX_BUFFERS
189 #define LANCE_LOG_TX_BUFFERS 4
190 #define LANCE_LOG_RX_BUFFERS 4
193 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
194 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
195 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
197 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
198 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
199 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
201 #define PKT_BUF_SZ 1544
204 #define LANCE_DATA 0x10
205 #define LANCE_ADDR 0x12
206 #define LANCE_RESET 0x14
207 #define LANCE_BUS_IF 0x16
208 #define LANCE_TOTAL_SIZE 0x18
210 #define TX_TIMEOUT (HZ/5)
255 #define LANCE_MUST_PAD 0x00000001
256 #define LANCE_ENABLE_AUTOSELECT 0x00000002
257 #define LANCE_MUST_REINIT_RING 0x00000004
258 #define LANCE_MUST_UNRESET 0x00000008
259 #define LANCE_HAS_MISSED_FRAME 0x00000010
264 static struct lance_chip_type {
269 {0x0000,
"LANCE 7990",
271 {0x0003,
"PCnet/ISA 79C960",
274 {0x2260,
"PCnet/ISA+ 79C961",
277 {0x2420,
"PCnet/PCI 79C970",
285 {0x2621,
"PCnet/PCI-II 79C970A",
288 {0x0,
"PCnet (unknown)",
298 static unsigned char lance_need_isa_bounce_buffers = 1;
333 int this_dev, found = 0;
335 for (this_dev = 0; this_dev <
MAX_CARDS; this_dev++) {
336 if (
io[this_dev] == 0) {
339 printk(
KERN_NOTICE "lance.c: Module autoprobing not allowed. Append \"io=0xNNN\" value(s).\n");
342 dev = alloc_etherdev(0);
348 if (do_lance_probe(dev) == 0) {
349 dev_lance[found++] =
dev;
360 static void cleanup_card(
struct net_device *dev)
375 for (this_dev = 0; this_dev <
MAX_CARDS; this_dev++) {
398 lance_need_isa_bounce_buffers = 0;
400 for (port = lance_portlist; *
port; port++) {
407 char offset14 =
inb(ioaddr + 14);
410 if (cards[card].id_offset14 == offset14)
412 if (card < NUM_CARDS) {
413 char offset15 =
inb(ioaddr + 15);
415 if ((cards[card].id_offset14 == offset14) &&
416 (cards[card].id_offset15 == offset15))
419 if (card < NUM_CARDS) {
420 result = lance_probe1(dev, ioaddr, 0, 0);
425 r->
name = chip_table[
ver].name;
447 err = do_lance_probe(dev);
461 .ndo_get_stats = lance_get_stats,
462 .ndo_set_rx_mode = set_multicast_list,
472 unsigned long dma_channels;
473 int i, reset_val, lance_version;
474 const char *chipname;
476 unsigned char hpJ2405A = 0;
478 static int did_version;
491 if (
readw(bios + 0x12) == 0x5048) {
492 static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360};
493 int hp_port = (
readl(bios + 1) & 1) ? 0x499 : 0x99;
495 if ((
inb(hp_port) & 0xc0) == 0x80 &&
496 ioaddr_table[
inb(hp_port) & 3] == ioaddr)
497 hp_builtin = hp_port;
501 hpJ2405A = (
inb(ioaddr) == 0x08 &&
inb(ioaddr+1) == 0x00 &&
502 inb(ioaddr+2) == 0x09);
525 printk(
" LANCE chip version is %#x.\n", chip_version);
526 if ((chip_version & 0xfff) != 0x003)
528 chip_version = (chip_version >> 12) & 0xffff;
529 for (lance_version = 1; chip_table[lance_version].id_number; lance_version++) {
530 if (chip_table[lance_version].id_number == chip_version)
537 chipname = chip_table[lance_version].name;
538 printk(
"%s: %s at %#3x, ", dev->
name, chipname, ioaddr);
542 for (i = 0; i < 6; i++)
552 if (lance_debug > 6)
printk(
" (#0x%05lx)", (
unsigned long)lp);
559 if (lance_need_isa_bounce_buffers) {
571 for (i = 0; i < 6; i++)
590 }
else if (hp_builtin) {
591 static const char dma_tbl[4] = {3, 5, 6, 0};
592 static const char irq_tbl[4] = {3, 4, 5, 9};
593 unsigned char port_val =
inb(hp_builtin);
594 dev->
dma = dma_tbl[(port_val >> 4) & 3];
595 dev->
irq = irq_tbl[(port_val >> 2) & 3];
596 printk(
" HP Vectra IRQ %d DMA %d.\n", dev->
irq, dev->
dma);
597 }
else if (hpJ2405A) {
598 static const char dma_tbl[4] = {3, 5, 6, 7};
599 static const char irq_tbl[8] = {3, 4, 5, 9, 10, 11, 12, 15};
601 dev->
dma = dma_tbl[(reset_val >> 2) & 3];
602 dev->
irq = irq_tbl[(reset_val >> 4) & 7];
603 printk(
" HP J2405A IRQ %d DMA %d.\n", dev->
irq, dev->
dma);
608 dev->
dma = bus_info & 0x07;
609 dev->
irq = (bus_info >> 4) & 0x0F;
625 else if (lance_version != 0) {
626 unsigned long irq_mask;
641 printk(
", failed to detect IRQ line.\n");
652 printk(
", no DMA needed.\n");
653 }
else if (dev->
dma) {
655 printk(
"DMA %d allocation failed.\n", dev->
dma);
658 printk(
", assigned DMA %d.\n", dev->
dma);
660 for (i = 0; i < 4; i++) {
661 static const char dmas[] = { 5, 6, 7, 3 };
680 for (boguscnt = 100; boguscnt > 0; --boguscnt)
695 printk(
"DMA detection failed.\n");
700 if (lance_version == 0 && dev->
irq == 0) {
703 unsigned long irq_mask;
711 printk(
" Failed to detect the 7990 IRQ line.\n");
714 printk(
" Auto-IRQ detected IRQ%d.\n", dev->
irq);
725 if (lance_debug > 0 && did_version++ == 0)
779 if (chip_table[lp->
chip_version].flags & LANCE_ENABLE_AUTOSELECT) {
787 printk(
"%s: lance_open() irq %d dma %d tx/rx rings %#x/%#x init %#x.\n",
806 netif_start_queue (dev);
819 printk(
"%s: LANCE open after %d ticks, init block %#x csr0 %4.4x.\n",
883 lp->
rx_ring[
i].base = (
u32)isa_virt_to_bus(rx_buff) | 0x80000000;
894 for (i = 0; i < 6; i++)
903 lance_restart(
struct net_device *dev,
unsigned int csr0_bits,
int must_reinit)
909 lance_purge_ring(dev);
923 printk (
"%s: transmit timed out, status %4.4x, resetting.\n",
926 dev->
stats.tx_errors++;
927 #ifndef final_version
928 if (lance_debug > 3) {
930 printk (
" Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
931 lp->
dirty_tx, lp->
cur_tx, netif_queue_stopped(dev) ?
" (full)" :
"",
934 printk (
"%s %08x %04x %04x", i & 0x3 ?
"" :
"\n ",
938 printk (
"%s %08x %04x %04x", i & 0x3 ?
"" :
"\n ",
944 lance_restart (dev, 0x0043, 1);
947 netif_wake_queue (dev);
961 if (lance_debug > 3) {
963 printk(
"%s: lance_start_xmit() called, csr0 %4.4x.\n", dev->
name,
994 if ((
u32)isa_virt_to_bus(skb->
data) + skb->
len > 0x01000000) {
996 printk(
"%s: bouncing a high-memory packet (%#x).\n",
1013 netif_stop_queue(dev);
1016 spin_unlock_irqrestore(&lp->
devlock, flags);
1025 int csr0, ioaddr, boguscnt=10;
1041 if (lance_debug > 5)
1042 printk(
"%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
1048 if (csr0 & 0x0200) {
1051 while (dirty_tx < lp->
cur_tx) {
1060 if (status & 0x40000000) {
1063 dev->
stats.tx_errors++;
1064 if (err_status & 0x0400)
1065 dev->
stats.tx_aborted_errors++;
1066 if (err_status & 0x0800)
1067 dev->
stats.tx_carrier_errors++;
1068 if (err_status & 0x1000)
1069 dev->
stats.tx_window_errors++;
1070 if (err_status & 0x4000) {
1072 dev->
stats.tx_fifo_errors++;
1074 printk(
"%s: Tx FIFO error! Status %4.4x.\n",
1080 if (status & 0x18000000)
1081 dev->
stats.collisions++;
1082 dev->
stats.tx_packets++;
1094 #ifndef final_version
1095 if (lp->
cur_tx - dirty_tx >= TX_RING_SIZE) {
1096 printk(
"out-of-sync dirty pointer, %d vs. %d, full=%s.\n",
1098 netif_queue_stopped(dev) ?
"yes" :
"no");
1104 if (netif_queue_stopped(dev) &&
1105 dirty_tx > lp->
cur_tx - TX_RING_SIZE + 2)
1106 netif_wake_queue (dev);
1113 dev->
stats.tx_errors++;
1115 dev->
stats.rx_errors++;
1116 if (csr0 & 0x0800) {
1117 printk(
"%s: Bus master arbitration failure, status %4.4x.\n",
1127 lance_restart(dev, 0x0002, 0);
1135 if (lance_debug > 4)
1136 printk(
"%s: exiting interrupt, csr%d=%#4.4x.\n",
1152 while (lp->
rx_ring[entry].base >= 0) {
1155 if (status != 0x03) {
1161 dev->
stats.rx_errors++;
1163 dev->
stats.rx_frame_errors++;
1165 dev->
stats.rx_over_errors++;
1167 dev->
stats.rx_crc_errors++;
1169 dev->
stats.rx_fifo_errors++;
1181 dev->
stats.rx_errors++;
1185 skb = dev_alloc_skb(pkt_len+2);
1188 printk(
"%s: Memory squeeze, deferring packet.\n", dev->
name);
1193 if (i > RX_RING_SIZE -2)
1195 dev->
stats.rx_dropped++;
1203 skb_copy_to_linear_data(skb,
1208 dev->
stats.rx_packets++;
1231 netif_stop_queue (dev);
1239 if (lance_debug > 1)
1240 printk(
"%s: Shutting down ethercard, status was %2.2x.\n",
1255 lance_purge_ring(dev);
1264 if (chip_table[lp->
chip_version].flags & LANCE_HAS_MISSED_FRAME) {
1267 unsigned long flags;
1274 spin_unlock_irqrestore(&lp->
devlock, flags);
1283 static void set_multicast_list(
struct net_device *dev)
1294 short multicast_table[4];
1300 memset(multicast_table, (num_addrs == 0) ? 0 : -1,
sizeof(multicast_table));
1301 for (i = 0; i < 4; i++) {
1309 lance_restart(dev, 0x0142, 0);