25 #define DRV_NAME "3c515"
26 #define DRV_VERSION "0.99t-ac"
27 #define DRV_RELDATE "28-Oct-2002"
37 static int rx_copybreak = 200;
40 static const int mtu = 1500;
43 static int max_interrupt_work = 20;
52 #define VORTEX_BUS_MASTER
56 #define TX_RING_SIZE 16
57 #define RX_RING_SIZE 16
58 #define PKT_BUF_SZ 1536
60 #include <linux/module.h>
62 #include <linux/kernel.h>
63 #include <linux/netdevice.h>
64 #include <linux/string.h>
65 #include <linux/errno.h>
72 #include <linux/ethtool.h>
73 #include <linux/bitops.h>
75 #include <asm/uaccess.h>
91 #define DRIVER_DEBUG 1
94 static int rx_nocopy, rx_copy, queued_packet;
98 #define WAIT_TX_AVAIL 200
101 #define TX_TIMEOUT ((4*HZ)/10)
106 #define CORKSCREW_TOTAL_SIZE 0x20
111 static int corkscrew_debug = 1;
114 #define CORKSCREW_ID 10
175 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
177 #define EL3_STATUS 0x0e
222 #if defined(CORKSCREW)
335 static struct media_table {
337 unsigned int media_bits:16,
345 {
"10base2", 0, 0x10,
XCVR_AUI, (1 *
HZ) / 10},
357 (
long)
"3Com Fast EtherLink ISA" },
367 static int corkscrew_setup(
struct net_device *
dev,
int ioaddr,
370 static void corkscrew_timer(
unsigned long arg);
381 static const struct ethtool_ops netdev_ethtool_ops;
401 static int debug = -1;
408 MODULE_PARM_DESC(options,
"3c515: Bits 0-2: media type, bit 3: full duplex, bit 4: bus mastering");
409 MODULE_PARM_DESC(rx_copybreak,
"3c515 copy breakpoint for copy-only-tiny-frames");
410 MODULE_PARM_DESC(max_interrupt_work,
"3c515 maximum events handled per interrupt");
420 corkscrew_debug =
debug;
423 while (corkscrew_scan(-1))
425 return found ? 0 : -
ENODEV;
437 if (corkscrew_debug > 0 && !printed) {
446 static int check_device(
unsigned ioaddr)
453 if ((
inw(ioaddr + 0x2002) & 0x1f0) != (ioaddr & 0x1f0)) {
460 for (timer = 4; timer >= 0; timer--) {
475 list_del_init(&vp->
list);
487 static int cards_found = 0;
492 static int pnp_cards;
507 for(i=0; corkscrew_isapnp_adapters[
i].
vendor != 0; i++) {
511 corkscrew_isapnp_adapters[i].
vendor,
512 corkscrew_isapnp_adapters[i].
function,
518 pr_warning(
"pnp activate failed (out of resources?)\n");
522 if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0)) {
526 ioaddr = pnp_port_start(idev, 0);
528 if (!check_device(ioaddr)) {
533 pr_debug(
"ISAPNP reports %s at i/o 0x%x, irq %d\n",
534 (
char*) corkscrew_isapnp_adapters[i].
driver_data, ioaddr, irq);
535 pr_info(
"3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
536 inl(ioaddr + 0x2002),
inw(ioaddr + 0x2000));
540 err = corkscrew_setup(dev, ioaddr, idev, cards_found++);
550 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20) {
551 if (!check_device(ioaddr))
554 pr_info(
"3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
555 inl(ioaddr + 0x2002),
inw(ioaddr + 0x2000));
556 err = corkscrew_setup(dev, ioaddr,
NULL, cards_found++);
567 .ndo_open = corkscrew_open,
568 .ndo_stop = corkscrew_close,
569 .ndo_start_xmit = corkscrew_start_xmit,
570 .ndo_tx_timeout = corkscrew_timeout,
571 .ndo_get_stats = corkscrew_get_stats,
572 .ndo_set_rx_mode = set_rx_mode,
579 static int corkscrew_setup(
struct net_device *dev,
int ioaddr,
580 struct pnp_dev *idev,
int card_number)
592 irq =
inw(ioaddr + 0x2002) & 15;
595 irq =
inw(ioaddr + 0x2002) & 15;
600 dev->
dma =
inw(ioaddr + 0x2000) & 7;
609 vp->
options = options[card_number];
624 list_add(&vp->
list, &root_corkscrew_dev);
633 for (i = 0; i < 0x18; i++) {
638 for (timer = 4; timer >= 0; timer--) {
644 checksum ^= eeprom[
i];
646 phys_addr[
i] =
htons(eeprom[i]);
648 checksum = (checksum ^ (checksum >> 8)) & 0xff;
649 if (checksum != 0x00)
650 pr_cont(
" ***INVALID CHECKSUM %4.4x*** ", checksum);
652 if (eeprom[16] == 0x11c7) {
654 pr_cont(
", DMA %d allocation failed", dev->
dma);
661 if (corkscrew_debug && (dev->
irq <= 0 || dev->
irq > 15))
662 pr_warning(
" *** Warning: this IRQ is unlikely to work! ***\n");
665 static const char *
const ram_split[] = {
666 "5:3",
"3:1",
"1:1",
"3:5"
672 if (corkscrew_debug > 1)
673 pr_info(
" Internal config register is %4.4x, transceivers %#x.\n",
675 pr_info(
" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
686 pr_info(
" Media override to transceiver type %d (%s).\n",
707 static int corkscrew_open(
struct net_device *dev)
721 if (corkscrew_debug > 1)
722 pr_info(
"%s: Media override to transceiver %d (%s).\n",
732 if (corkscrew_debug > 1)
733 pr_debug(
"%s: Initial media type %s.\n",
739 vp->
timer.function = corkscrew_timer;
747 if (corkscrew_debug > 1) {
748 pr_debug(
"%s: corkscrew_open() InternalConfig %8.8x.\n",
753 for (i = 20; i >= 0; i--)
759 for (i = 20; i >= 0; i--)
780 if (corkscrew_debug > 1) {
782 pr_debug(
"%s: corkscrew_open() irq %d media status %4.4x.\n",
788 for (i = 0; i < 6; i++)
790 for (; i < 12; i += 2)
803 for (i = 0; i < 10; i++)
818 if (corkscrew_debug > 2)
822 if (i < (RX_RING_SIZE - 1))
824 isa_virt_to_bus(&vp->
rx_ring[i + 1]);
838 isa_virt_to_bus(&vp->
rx_ring[0]);
853 netif_start_queue(dev);
872 static void corkscrew_timer(
unsigned long data)
881 if (corkscrew_debug > 1)
882 pr_debug(
"%s: Media selection timer tick happened, %s.\n",
898 if (corkscrew_debug > 1)
899 pr_debug(
"%s: Media %s has link beat, %x.\n",
903 }
else if (corkscrew_debug > 1)
904 pr_debug(
"%s: Media %s is has no link beat, %x.\n",
911 if (corkscrew_debug > 1)
912 pr_debug(
"%s: Media %s is has no indication, %x.\n",
929 if (corkscrew_debug > 1)
930 pr_debug(
"%s: Media selection failing, using default %s port.\n",
934 if (corkscrew_debug > 1)
935 pr_debug(
"%s: Media selection failed, now trying %s port.\n",
942 media_tbl[dev->
if_port].media_bits,
956 spin_unlock_irqrestore(&vp->
lock, flags);
957 if (corkscrew_debug > 1)
958 pr_debug(
"%s: Media selection timer finished, %s.\n",
964 static void corkscrew_timeout(
struct net_device *dev)
970 pr_warning(
"%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
975 pr_warning(
"%s: Transmitter encountered 16 collisions --"
976 " network cable problem?\n", dev->
name);
977 #ifndef final_version
978 pr_debug(
" Flags; bus-master %d, full %d; dirty %d current %d.\n",
984 pr_debug(
" %d: %p length %8.8x status %8.8x\n", i,
991 for (i = 20; i >= 0; i--)
996 dev->
stats.tx_errors++;
997 dev->
stats.tx_dropped++;
998 netif_wake_queue(dev);
1009 netif_stop_queue(dev);
1015 unsigned long flags;
1024 if (corkscrew_debug > 3)
1025 pr_debug(
"%s: Trying to send a packet, Tx index %d.\n",
1037 for (i = 20; i >= 0; i--)
1041 prev_entry->
next = isa_virt_to_bus(&vp->
tx_ring[entry]);
1048 spin_unlock_irqrestore(&vp->
lock, flags);
1055 prev_entry->
status &= ~0x80000000;
1056 netif_wake_queue(dev);
1063 #ifdef VORTEX_BUS_MASTER
1076 netif_wake_queue(dev);
1087 netif_wake_queue(dev);
1099 while (--i > 0 && (tx_status =
inb(ioaddr +
TxStatus)) > 0) {
1100 if (tx_status & 0x3C) {
1101 if (corkscrew_debug > 2)
1102 pr_debug(
"%s: Tx error, status %2.2x.\n",
1103 dev->
name, tx_status);
1104 if (tx_status & 0x04)
1105 dev->
stats.tx_fifo_errors++;
1106 if (tx_status & 0x38)
1107 dev->
stats.tx_aborted_errors++;
1108 if (tx_status & 0x30) {
1111 for (j = 20; j >= 0; j--)
1133 int i = max_interrupt_work;
1138 spin_lock(&lp->
lock);
1142 if (corkscrew_debug > 4)
1143 pr_debug(
"%s: interrupt, status %4.4x, timer %d.\n",
1144 dev->
name, status, latency);
1145 if ((status & 0xE000) != 0xE000) {
1146 static int donedidthis;
1150 if (donedidthis++ > 100) {
1151 pr_err(
"%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1152 dev->
name, status, netif_running(dev));
1159 if (corkscrew_debug > 5)
1160 pr_debug(
"%s: In interrupt loop, status %4.4x.\n",
1166 if (corkscrew_debug > 5)
1167 pr_debug(
" TX room bit was handled.\n");
1170 netif_wake_queue(dev);
1175 while (lp->
cur_tx - dirty_tx > 0) {
1187 if (lp->
tx_full && (lp->
cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
1189 netif_wake_queue(dev);
1192 #ifdef VORTEX_BUS_MASTER
1196 netif_wake_queue(dev);
1210 static int DoneDidThat;
1211 if (corkscrew_debug > 4)
1213 update_stats(ioaddr, dev);
1216 if (DoneDidThat == 0 &&
inw(ioaddr +
EL3_STATUS) & StatsFull) {
1218 pr_notice(
"%s: Updating stats failed, disabling stats as an interrupt source.\n",
1220 for (win = 0; win < 8; win++) {
1223 for (reg = 0; reg < 16; reg++)
1230 UpComplete | DownComplete |
1247 pr_err(
"%s: Too much work in interrupt, status %4.4x. Disabling functions (%4.4x).\n",
1259 spin_unlock(&lp->
lock);
1261 if (corkscrew_debug > 4)
1262 pr_debug(
"%s: exiting interrupt, status %4.4x.\n", dev->
name, status);
1266 static int corkscrew_rx(
struct net_device *dev)
1272 if (corkscrew_debug > 5)
1273 pr_debug(
" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1275 while ((rx_status =
inw(ioaddr +
RxStatus)) > 0) {
1276 if (rx_status & 0x4000) {
1278 if (corkscrew_debug > 2)
1279 pr_debug(
" Rx error: status %2.2x.\n",
1281 dev->
stats.rx_errors++;
1282 if (rx_error & 0x01)
1283 dev->
stats.rx_over_errors++;
1284 if (rx_error & 0x02)
1285 dev->
stats.rx_length_errors++;
1286 if (rx_error & 0x04)
1287 dev->
stats.rx_frame_errors++;
1288 if (rx_error & 0x08)
1289 dev->
stats.rx_crc_errors++;
1290 if (rx_error & 0x10)
1291 dev->
stats.rx_length_errors++;
1294 short pkt_len = rx_status & 0x1fff;
1297 skb = netdev_alloc_skb(dev, pkt_len + 5 + 2);
1298 if (corkscrew_debug > 4)
1299 pr_debug(
"Receiving packet size %d status %4.4x.\n",
1300 pkt_len, rx_status);
1302 skb_reserve(skb, 2);
1306 (pkt_len + 3) >> 2);
1310 dev->
stats.rx_packets++;
1313 for (i = 200; i >= 0; i--)
1317 }
else if (corkscrew_debug)
1318 pr_debug(
"%s: Couldn't allocate a sk_buff of size %d.\n", dev->
name, pkt_len);
1321 dev->
stats.rx_dropped++;
1323 for (i = 200; i >= 0; i--)
1330 static int boomerang_rx(
struct net_device *dev)
1337 if (corkscrew_debug > 5)
1338 pr_debug(
" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1342 unsigned char rx_error = rx_status >> 16;
1343 if (corkscrew_debug > 2)
1344 pr_debug(
" Rx error: status %2.2x.\n",
1346 dev->
stats.rx_errors++;
1347 if (rx_error & 0x01)
1348 dev->
stats.rx_over_errors++;
1349 if (rx_error & 0x02)
1350 dev->
stats.rx_length_errors++;
1351 if (rx_error & 0x04)
1352 dev->
stats.rx_frame_errors++;
1353 if (rx_error & 0x08)
1354 dev->
stats.rx_crc_errors++;
1355 if (rx_error & 0x10)
1356 dev->
stats.rx_length_errors++;
1359 short pkt_len = rx_status & 0x1fff;
1363 if (corkscrew_debug > 4)
1364 pr_debug(
"Receiving packet size %d status %4.4x.\n",
1365 pkt_len, rx_status);
1369 if (pkt_len < rx_copybreak &&
1370 (skb = netdev_alloc_skb(dev, pkt_len + 4)) !=
NULL) {
1371 skb_reserve(skb, 2);
1385 pr_warning(
"%s: Warning -- the skbuff addresses do not match"
1386 " in boomerang_rx: %p vs. %p / %p.\n",
1396 dev->
stats.rx_packets++;
1398 entry = (++vp->
cur_rx) % RX_RING_SIZE;
1408 skb_reserve(skb, 2);
1417 static int corkscrew_close(
struct net_device *dev)
1423 netif_stop_queue(dev);
1425 if (corkscrew_debug > 1) {
1426 pr_debug(
"%s: corkscrew_close() status %4.4x, Tx status %2.2x.\n",
1429 pr_debug(
"%s: corkscrew close stats: rx_nocopy %d rx_copy %d tx_queued %d.\n",
1430 dev->
name, rx_nocopy, rx_copy, queued_packet);
1442 if (dev->
if_port == XCVR_10base2)
1450 update_stats(ioaddr, dev);
1474 unsigned long flags;
1476 if (netif_running(dev)) {
1479 spin_unlock_irqrestore(&vp->
lock, flags);
1491 static void update_stats(
int ioaddr,
struct net_device *dev)
1496 dev->
stats.tx_carrier_errors +=
inb(ioaddr + 0);
1497 dev->
stats.tx_heartbeat_errors +=
inb(ioaddr + 1);
1499 dev->
stats.collisions +=
inb(ioaddr + 3);
1500 dev->
stats.tx_window_errors +=
inb(ioaddr + 4);
1501 dev->
stats.rx_fifo_errors +=
inb(ioaddr + 5);
1502 dev->
stats.tx_packets +=
inb(ioaddr + 6);
1503 dev->
stats.tx_packets += (
inb(ioaddr + 9) & 0x30) << 4;
1524 static void set_rx_mode(
struct net_device *dev)
1530 if (corkscrew_debug > 3)
1531 pr_debug(
"%s: Setting promiscuous mode.\n",
1542 static void netdev_get_drvinfo(
struct net_device *dev,
1552 return corkscrew_debug;
1557 corkscrew_debug =
level;
1560 static const struct ethtool_ops netdev_ethtool_ops = {
1561 .get_drvinfo = netdev_get_drvinfo,
1562 .get_msglevel = netdev_get_msglevel,
1563 .set_msglevel = netdev_set_msglevel,
1570 while (!list_empty(&root_corkscrew_dev)) {