29 #define DRV_NAME "hamachi"
30 #define DRV_VERSION "2.1"
31 #define DRV_RELDATE "Sept 11, 2006"
38 #define hamachi_debug debug
40 static int max_interrupt_work = 40;
46 static int max_rx_latency = 0x11;
47 static int max_rx_gap = 0x05;
48 static int min_rx_pkt = 0x18;
49 static int max_tx_latency = 0x00;
50 static int max_tx_gap = 0x00;
51 static int min_tx_pkt = 0x30;
57 static int rx_copybreak;
87 static int full_duplex[
MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
103 static int rx_params[
MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
119 #define TX_RING_SIZE 64
120 #define RX_RING_SIZE 512
121 #define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct hamachi_desc)
122 #define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct hamachi_desc)
141 #define TX_TIMEOUT (5*HZ)
143 #include <linux/capability.h>
144 #include <linux/module.h>
145 #include <linux/kernel.h>
146 #include <linux/string.h>
148 #include <linux/time.h>
149 #include <linux/errno.h>
152 #include <linux/pci.h>
154 #include <linux/ethtool.h>
155 #include <linux/mii.h>
156 #include <linux/netdevice.h>
159 #include <linux/ip.h>
161 #include <linux/bitops.h>
163 #include <asm/uaccess.h>
164 #include <asm/processor.h>
166 #include <asm/unaligned.h>
167 #include <asm/cache.h>
187 #define IP_OFFSET IPOPT_OFFSET
193 #define RUN_AT(x) (jiffies + (x))
201 #define cpu_to_leXX(addr) cpu_to_le64(addr)
202 #define leXX_to_cpu(addr) le64_to_cpu(addr)
204 #define cpu_to_leXX(addr) cpu_to_le32(addr)
205 #define leXX_to_cpu(addr) le32_to_cpu(addr)
406 #define PKT_BUF_SZ 1536
412 #define MAX_FRAME_SIZE 1518
416 static void hamachi_timer(
unsigned long data);
419 static const struct chip_info {
422 void (*media_timer)(
unsigned long data);
425 {0x1318, 0x0911, 0xffff, 0,
"Hamachi GNIC-II", hamachi_timer, 0},
479 #define PRIV_ALIGN 15
529 MODULE_PARM_DESC(max_interrupt_work,
"GNIC-II maximum events handled per interrupt");
532 MODULE_PARM_DESC(min_rx_pkt,
"GNIC-II minimum Rx packets processed between interrupts");
533 MODULE_PARM_DESC(max_rx_gap,
"GNIC-II maximum Rx inter-packet gap in 8.192 microsecond units");
534 MODULE_PARM_DESC(max_rx_latency,
"GNIC-II time between Rx interrupts in 8.192 microsecond units");
535 MODULE_PARM_DESC(min_tx_pkt,
"GNIC-II minimum Tx packets processed between interrupts");
536 MODULE_PARM_DESC(max_tx_gap,
"GNIC-II maximum Tx inter-packet gap in 8.192 microsecond units");
537 MODULE_PARM_DESC(max_tx_latency,
"GNIC-II time between Tx interrupts in 8.192 microsecond units");
538 MODULE_PARM_DESC(rx_copybreak,
"GNIC-II copy breakpoint for copy-only-tiny-frames");
539 MODULE_PARM_DESC(rx_params,
"GNIC-II min_rx_pkt+max_rx_gap+max_rx_latency");
541 MODULE_PARM_DESC(
options,
"GNIC-II Bits 0-3: media type, bits 4-6: as force32, bit 7: half duplex, bit 9 full duplex");
543 MODULE_PARM_DESC(force32,
"GNIC-II: Bit 0: 32 bit PCI, bit 1: disable parity, bit 2: 64 bit PCI (all boards)");
550 static void hamachi_timer(
unsigned long data);
555 static irqreturn_t hamachi_interrupt(
int irq,
void *dev_instance);
558 static void hamachi_error(
struct net_device *
dev,
int intr_status);
563 static const struct ethtool_ops ethtool_ops_no_mii;
566 .ndo_open = hamachi_open,
567 .ndo_stop = hamachi_close,
568 .ndo_start_xmit = hamachi_start_xmit,
569 .ndo_get_stats = hamachi_get_stats,
570 .ndo_set_rx_mode = set_rx_mode,
574 .ndo_tx_timeout = hamachi_tx_timeout,
575 .ndo_do_ioctl = netdev_ioctl,
596 static int printed_version;
597 if (!printed_version++)
620 goto err_out_release;
624 goto err_out_iounmap;
628 for (i = 0; i < 6; i++)
632 #if ! defined(final_version)
634 for (i = 0; i < 0x10; i++)
636 read_eeprom(ioaddr, i), i % 16 != 15 ?
" " :
"\n");
639 hmp = netdev_priv(dev);
643 hmp->
mii_if.mdio_read = mdio_read;
644 hmp->
mii_if.mdio_write = mdio_write;
645 hmp->
mii_if.phy_id_mask = 0x1f;
646 hmp->
mii_if.reg_num_mask = 0x1f;
650 goto err_out_cleardev;
656 goto err_out_unmap_tx;
666 force32 = force32 ? force32 :
667 ((option >= 0) ? ((option & 0x00000070) >> 4) : 0 );
680 for (boguscnt = 0; (!(i & 0x080)) && boguscnt < 1000; boguscnt++){
686 pci_set_drvdata(pdev, dev);
695 hmp->
mii_if.full_duplex = 1;
696 else if (option & 0x080)
697 hmp->
mii_if.full_duplex = 0;
700 hmp->
mii_if.force_media = 1;
702 if (card_idx <
MAX_UNITS && full_duplex[card_idx] > 0)
703 hmp->
mii_if.full_duplex = 1;
706 if (hmp->
mii_if.full_duplex || (option & 0x080))
710 max_rx_latency = max_rx_latency & 0x00ff;
711 max_rx_gap = max_rx_gap & 0x00ff;
712 min_rx_pkt = min_rx_pkt & 0x00ff;
713 max_tx_latency = max_tx_latency & 0x00ff;
714 max_tx_gap = max_tx_gap & 0x00ff;
715 min_tx_pkt = min_tx_pkt & 0x00ff;
717 rx_int_var = card_idx <
MAX_UNITS ? rx_params[card_idx] : -1;
719 hmp->
rx_int_var = rx_int_var >= 0 ? rx_int_var :
720 (min_rx_pkt << 16 | max_rx_gap << 8 | max_rx_latency);
721 hmp->
tx_int_var = tx_int_var >= 0 ? tx_int_var :
722 (min_tx_pkt << 16 | max_tx_gap << 8 | max_tx_latency);
738 goto err_out_unmap_rx;
746 "%2.2x, LPA %4.4x.\n",
751 if (chip_tbl[hmp->
chip_id].flags & CanHaveMII) {
752 int phy, phy_idx = 0;
753 for (phy = 0; phy < 32 && phy_idx <
MII_CNT; phy++) {
754 int mii_status = mdio_read(dev, phy,
MII_BMSR);
755 if (mii_status != 0xffff &&
756 mii_status != 0x0000) {
760 "0x%4.4x advertising %4.4x.\n",
761 dev->
name, phy, mii_status, hmp->
mii_if.advertising);
796 int bogus_cnt = 1000;
805 printk(
" EEPROM status is %2.2x after %d ticks.\n",
821 for (i = 10000; i >= 0; i--)
826 for (i = 10000; i >= 0; i--)
832 static void mdio_write(
struct net_device *dev,
int phy_id,
int location,
int value)
839 for (i = 10000; i >= 0; i--)
846 for (i = 10000; i >= 0; i--)
852 static int hamachi_open(
struct net_device *dev)
865 hamachi_init_ring(dev);
881 for (i = 0; i < 6; i++)
888 fifo_info = (
readw(ioaddr +
GPIO) & 0x00C0) >> 6;
921 hmp->
mii_if.full_duplex = 1;
949 printk(
"max_tx_latency: %d, max_tx_gap: %d, min_tx_pkt: %d\n",
950 tx_int_var & 0x00ff, (tx_int_var & 0x00ff00) >> 8,
951 (tx_int_var & 0x00ff0000) >> 16);
952 printk(
"max_rx_latency: %d, max_rx_gap: %d, min_rx_pkt: %d\n",
953 rx_int_var & 0x00ff, (rx_int_var & 0x00ff00) >> 8,
954 (rx_int_var & 0x00ff0000) >> 16);
955 printk(
"rx_int_var: %x, tx_int_var: %x\n", rx_int_var, tx_int_var);
963 netif_start_queue(dev);
988 hmp->
timer.function = hamachi_timer;
994 static inline int hamachi_tx(
struct net_device *dev)
1009 pci_unmap_single(hmp->
pci_dev,
1019 dev->
stats.tx_packets++;
1025 static void hamachi_timer(
unsigned long data)
1030 int next_tick = 10*
HZ;
1037 "%4.4x %4.4x %4.4x.\n", dev->
name,
1038 readw(ioaddr + 0x0e0),
1039 readw(ioaddr + 0x0e2),
1040 readw(ioaddr + 0x0e4),
1041 readw(ioaddr + 0x0e6),
1042 readw(ioaddr + 0x0e8),
1043 readw(ioaddr + 0x0eA));
1050 static void hamachi_tx_timeout(
struct net_device *dev)
1092 if (i >= TX_RING_SIZE - 1)
1123 pci_unmap_single(hmp->
pci_dev,
1134 skb = netdev_alloc_skb_ip_align(dev, hmp->
rx_buf_sz);
1150 dev->
stats.tx_errors++;
1157 netif_wake_queue(dev);
1162 static void hamachi_init_ring(
struct net_device *dev)
1177 (((dev->
mtu+26+7) & ~7) + 16));
1181 hmp->
rx_ring[
i].status_n_length = 0;
1190 skb_reserve(skb, 2);
1202 hmp->
tx_ring[
i].status_n_length = 0;
1228 if( !(status & 0x0001) || (status & 0x0002))
1253 if (entry >= TX_RING_SIZE-1)
1266 if( !(status & 0x0001) || (status & 0x0002))
1279 netif_wake_queue(dev);
1282 netif_stop_queue(dev);
1294 static irqreturn_t hamachi_interrupt(
int irq,
void *dev_instance)
1299 long boguscnt = max_interrupt_work;
1302 #ifndef final_version
1304 printk (
KERN_ERR "hamachi_interrupt(): irq %d for unknown device.\n", irq);
1309 spin_lock(&hmp->
lock);
1316 dev->
name, intr_status);
1318 if (intr_status == 0)
1341 pci_unmap_single(hmp->
pci_dev,
1349 if (entry >= TX_RING_SIZE-1)
1350 hmp->
tx_ring[TX_RING_SIZE-1].status_n_length |=
1352 dev->
stats.tx_packets++;
1357 netif_wake_queue(dev);
1360 netif_wake_queue(dev);
1369 hamachi_error(dev, intr_status);
1371 if (--boguscnt < 0) {
1373 dev->
name, intr_status);
1382 #ifndef final_version
1385 static int stopit = 10;
1386 if (dev->start == 0 && --stopit < 0) {
1387 printk(
KERN_ERR "%s: Emergency stop, looping startup interrupt.\n",
1394 spin_unlock(&hmp->
lock);
1400 static int hamachi_rx(
struct net_device *dev)
1408 entry, hmp->
rx_ring[entry].status_n_length);
1421 pci_dma_sync_single_for_cpu(hmp->
pci_dev,
1434 "multiple buffers, entry %#x length %d status %4.4x!\n",
1435 dev->
name, hmp->
cur_rx, data_size, desc_status);
1438 printk(
KERN_WARNING "%s: Oversized Ethernet frame -- next status %x/%x last status %x.\n",
1443 dev->
stats.rx_length_errors++;
1445 if (frame_status & 0x00380000) {
1450 dev->
stats.rx_errors++;
1451 if (frame_status & 0x00600000)
1452 dev->
stats.rx_length_errors++;
1453 if (frame_status & 0x00080000)
1454 dev->
stats.rx_frame_errors++;
1455 if (frame_status & 0x00100000)
1456 dev->
stats.rx_crc_errors++;
1457 if (frame_status < 0)
1458 dev->
stats.rx_dropped++;
1464 u32 pfck = *(
u32 *) &buf_addr[data_size - 8];
1468 #ifndef final_version
1471 " of %d, bogus_cnt %d.\n",
1472 pkt_len, data_size, boguscnt);
1476 *(
s32*)&(buf_addr[data_size - 20]),
1477 *(
s32*)&(buf_addr[data_size - 16]),
1478 *(
s32*)&(buf_addr[data_size - 12]),
1479 *(
s32*)&(buf_addr[data_size - 8]),
1480 *(
s32*)&(buf_addr[data_size - 4]));
1484 if (pkt_len < rx_copybreak &&
1485 (skb = netdev_alloc_skb(dev, pkt_len + 2)) !=
NULL) {
1488 "not good with RX_CHECKSUM\n", dev->
name);
1490 skb_reserve(skb, 2);
1491 pci_dma_sync_single_for_cpu(hmp->
pci_dev,
1496 #if 1 || USE_IP_COPYSUM
1497 skb_copy_to_linear_data(skb,
1502 + entry*
sizeof(*desc), pkt_len);
1504 pci_dma_sync_single_for_device(hmp->
pci_dev,
1509 pci_unmap_single(hmp->
pci_dev,
1520 if (pfck>>24 == 0x91 || pfck>>24 == 0x51) {
1529 u32 inv = *(
u32 *) &buf_addr[data_size - 16];
1530 u32 *
p = (
u32 *) &buf_addr[data_size - 20];
1531 register u32 crc, p_r, p_r1;
1541 crc = (p_r & 0xffff) + (p_r >> 16);
1544 crc = (p_r >> 16) + (p_r & 0xffff)
1545 + (p_r1 >> 16 & 0xff00);
1548 crc = p_r + (p_r1 >> 16);
1551 crc = p_r + (p_r1 & 0xff00) + (p_r1 >> 16);
1555 if (crc & 0xffff0000) {
1561 if (skb->
csum > crc)
1564 skb->
csum += (~crc & 0xffff);
1576 dev->
stats.rx_packets++;
1578 entry = (++hmp->
cur_rx) % RX_RING_SIZE;
1593 skb_reserve(skb, 2);
1598 if (entry >= RX_RING_SIZE-1)
1616 static void hamachi_error(
struct net_device *dev,
int intr_status)
1624 " %4.4x, Status %4.4x %4.4x Intr status %4.4x.\n",
1634 hamachi_get_stats(dev);
1636 readl(ioaddr + 0x370);
1637 readl(ioaddr + 0x3F0);
1642 dev->
name, intr_status);
1645 dev->
stats.tx_fifo_errors++;
1647 dev->
stats.rx_fifo_errors++;
1650 static int hamachi_close(
struct net_device *dev)
1657 netif_stop_queue(dev);
1660 printk(
KERN_DEBUG "%s: Shutting down ethercard, status was Tx %4.4x Rx %4.4x Int %2.2x.\n",
1694 for (
j = 0;
j < 0x50;
j++)
1710 hmp->
rx_ring[
i].status_n_length = 0;
1712 pci_unmap_single(hmp->
pci_dev,
1723 pci_unmap_single(hmp->
pci_dev,
1756 dev->
stats.multicast =
readl(ioaddr + 0x320);
1759 dev->
stats.rx_length_errors =
readl(ioaddr + 0x368);
1761 dev->
stats.rx_over_errors =
readl(ioaddr + 0x35C);
1763 dev->
stats.rx_crc_errors =
readl(ioaddr + 0x360);
1765 dev->
stats.rx_frame_errors =
readl(ioaddr + 0x364);
1767 dev->
stats.rx_missed_errors =
readl(ioaddr + 0x36C);
1772 static void set_rx_mode(
struct net_device *dev)
1789 ioaddr + 0x104 + i*8);
1794 writel(0, ioaddr + 0x104 + i*8);
1801 static int check_if_running(
struct net_device *dev)
1803 if (!netif_running(dev))
1819 spin_lock_irq(&np->
lock);
1821 spin_unlock_irq(&np->
lock);
1829 spin_lock_irq(&np->
lock);
1831 spin_unlock_irq(&np->
lock);
1835 static int hamachi_nway_reset(
struct net_device *dev)
1848 .
begin = check_if_running,
1849 .get_drvinfo = hamachi_get_drvinfo,
1850 .get_settings = hamachi_get_settings,
1851 .set_settings = hamachi_set_settings,
1852 .nway_reset = hamachi_nway_reset,
1853 .get_link = hamachi_get_link,
1856 static const struct ethtool_ops ethtool_ops_no_mii = {
1857 .begin = check_if_running,
1858 .get_drvinfo = hamachi_get_drvinfo,
1867 if (!netif_running(dev))
1888 spin_lock_irq(&np->
lock);
1890 spin_unlock_irq(&np->
lock);
1899 struct net_device *dev = pci_get_drvdata(pdev);
1912 pci_set_drvdata(pdev,
NULL);
1924 .id_table = hamachi_pci_tbl,
1925 .probe = hamachi_init_one,
1929 static int __init hamachi_init (
void)
1935 return pci_register_driver(&hamachi_driver);
1938 static void __exit hamachi_exit (
void)