53 #include <linux/module.h>
55 #include <linux/types.h>
56 #include <linux/errno.h>
58 #include <linux/pci.h>
60 #include <linux/kernel.h>
61 #include <linux/netdevice.h>
70 #include <linux/slab.h>
71 #include <linux/prefetch.h>
72 #include <linux/if_vlan.h>
75 #include <linux/ethtool.h>
83 #include <asm/byteorder.h>
84 #include <asm/uaccess.h>
87 #define DRV_NAME "acenic"
91 #ifdef CONFIG_ACENIC_OMIT_TIGON_I
92 #define ACE_IS_TIGON_I(ap) 0
93 #define ACE_TX_RING_ENTRIES(ap) MAX_TX_RING_ENTRIES
95 #define ACE_IS_TIGON_I(ap) (ap->version == 1)
96 #define ACE_TX_RING_ENTRIES(ap) ap->tx_ring_entries
99 #ifndef PCI_VENDOR_ID_ALTEON
100 #define PCI_VENDOR_ID_ALTEON 0x12ae
102 #ifndef PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE
103 #define PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE 0x0001
104 #define PCI_DEVICE_ID_ALTEON_ACENIC_COPPER 0x0002
106 #ifndef PCI_DEVICE_ID_3COM_3C985
107 #define PCI_DEVICE_ID_3COM_3C985 0x0001
109 #ifndef PCI_VENDOR_ID_NETGEAR
110 #define PCI_VENDOR_ID_NETGEAR 0x1385
111 #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a
113 #ifndef PCI_DEVICE_ID_NETGEAR_GA620T
114 #define PCI_DEVICE_ID_NETGEAR_GA620T 0x630a
122 #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
123 #define PCI_DEVICE_ID_FARALLON_PN9000SX 0x1a
125 #ifndef PCI_DEVICE_ID_FARALLON_PN9100T
126 #define PCI_DEVICE_ID_FARALLON_PN9100T 0xfa
128 #ifndef PCI_VENDOR_ID_SGI
129 #define PCI_VENDOR_ID_SGI 0x10a9
131 #ifndef PCI_DEVICE_ID_SGI_ACENIC
132 #define PCI_DEVICE_ID_SGI_ACENIC 0x0009
160 #define ace_sync_irq(irq) synchronize_irq(irq)
162 #ifndef offset_in_page
163 #define offset_in_page(ptr) ((unsigned long)(ptr) & ~PAGE_MASK)
166 #define ACE_MAX_MOD_PARMS 8
167 #define BOARD_IDX_STATIC 0
168 #define BOARD_IDX_OVERFLOW -1
175 #define MAX_TEXT_LEN 96*1024
176 #define MAX_RODATA_LEN 8*1024
177 #define MAX_DATA_LEN 2*1024
179 #ifndef tigon2FwReleaseLocal
180 #define tigon2FwReleaseLocal 0
331 #define RX_RING_SIZE 72
332 #define RX_MINI_SIZE 64
333 #define RX_JUMBO_SIZE 48
335 #define RX_PANIC_STD_THRES 16
336 #define RX_PANIC_STD_REFILL (3*RX_PANIC_STD_THRES)/2
337 #define RX_LOW_STD_THRES (3*RX_RING_SIZE)/4
338 #define RX_PANIC_MINI_THRES 12
339 #define RX_PANIC_MINI_REFILL (3*RX_PANIC_MINI_THRES)/2
340 #define RX_LOW_MINI_THRES (3*RX_MINI_SIZE)/4
341 #define RX_PANIC_JUMBO_THRES 6
342 #define RX_PANIC_JUMBO_REFILL (3*RX_PANIC_JUMBO_THRES)/2
343 #define RX_LOW_JUMBO_THRES (3*RX_JUMBO_SIZE)/4
350 #define ACE_MINI_SIZE 100
352 #define ACE_MINI_BUFSIZE ACE_MINI_SIZE
353 #define ACE_STD_BUFSIZE (ACE_STD_MTU + ETH_HLEN + 4)
354 #define ACE_JUMBO_BUFSIZE (ACE_JUMBO_MTU + ETH_HLEN + 4)
364 #define DEF_TX_COAL 400
365 #define DEF_TX_MAX_DESC 60
366 #define DEF_RX_COAL 120
367 #define DEF_RX_MAX_DESC 25
368 #define DEF_TX_RATIO 21
370 #define DEF_JUMBO_TX_COAL 20
371 #define DEF_JUMBO_TX_MAX_DESC 60
372 #define DEF_JUMBO_RX_COAL 30
373 #define DEF_JUMBO_RX_MAX_DESC 6
374 #define DEF_JUMBO_TX_RATIO 21
376 #if tigon2FwReleaseLocal < 20001118
384 #define TX_COAL_INTS_ONLY 1
389 #define TX_COAL_INTS_ONLY 1
393 #define DEF_STAT (2 * TICKS_PER_SEC)
408 #ifndef CONFIG_ACENIC_OMIT_TIGON_I
422 MODULE_PARM_DESC(tx_coal_tick,
"AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
423 MODULE_PARM_DESC(max_tx_desc,
"AceNIC/3C985/GA620 max number of transmit descriptors to wait");
424 MODULE_PARM_DESC(rx_coal_tick,
"AceNIC/3C985/GA620 max clock ticks to wait from first rx descriptor arrives");
425 MODULE_PARM_DESC(max_rx_desc,
"AceNIC/3C985/GA620 max number of receive descriptors to wait");
426 MODULE_PARM_DESC(tx_ratio,
"AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
431 " http://home.cern.ch/~jes/gige/acenic.html\n";
437 static const struct ethtool_ops ace_ethtool_ops = {
438 .get_settings = ace_get_settings,
439 .set_settings = ace_set_settings,
440 .get_drvinfo = ace_get_drvinfo,
446 .ndo_open = ace_open,
447 .ndo_stop = ace_close,
448 .ndo_tx_timeout = ace_watchdog,
449 .ndo_get_stats = ace_get_stats,
450 .ndo_start_xmit = ace_start_xmit,
451 .ndo_set_rx_mode = ace_set_multicast_list,
453 .ndo_set_mac_address = ace_set_mac_addr,
454 .ndo_change_mtu = ace_change_mtu,
462 static int boards_found;
470 ap = netdev_priv(dev);
472 ap->
name = pci_name(pdev);
487 goto fail_free_netdev;
501 "access - was not enabled by BIOS/Firmware\n",
524 "AceNIC %i will be disabled.\n",
525 ap->
name, boards_found);
526 goto fail_free_netdev;
562 #ifdef CONFIG_ACENIC_OMIT_TIGON_I
563 if ((
readl(&ap->
regs->HostCtrl) >> 28) == 4) {
565 " support - NIC disabled\n", dev->
name);
570 if (ace_allocate_descriptors(dev))
571 goto fail_free_netdev;
583 goto fail_free_netdev;
594 pci_set_drvdata(pdev, dev);
600 ace_init_cleanup(dev);
608 struct net_device *dev = pci_get_drvdata(pdev);
643 ringp = &ap->
skb->rx_std_skbuff[
i];
645 pci_unmap_page(ap->
pdev, mapping,
650 ap->
skb->rx_std_skbuff[
i].skb =
NULL;
657 struct sk_buff *skb = ap->
skb->rx_mini_skbuff[
i].skb;
663 ringp = &ap->
skb->rx_mini_skbuff[
i];
665 pci_unmap_page(ap->
pdev, mapping,
670 ap->
skb->rx_mini_skbuff[
i].skb =
NULL;
677 struct sk_buff *skb = ap->
skb->rx_jumbo_skbuff[
i].skb;
682 ringp = &ap->
skb->rx_jumbo_skbuff[
i];
684 pci_unmap_page(ap->
pdev, mapping,
689 ap->
skb->rx_jumbo_skbuff[
i].skb =
NULL;
694 ace_init_cleanup(dev);
698 static struct pci_driver acenic_pci_driver = {
700 .id_table = acenic_pci_tbl,
701 .probe = acenic_probe_one,
705 static int __init acenic_init(
void)
707 return pci_register_driver(&acenic_pci_driver);
710 static void __exit acenic_exit(
void)
718 static void ace_free_descriptors(
struct net_device *dev)
724 size = (
sizeof(
struct rx_desc) *
725 (RX_STD_RING_ENTRIES +
726 RX_JUMBO_RING_ENTRIES +
727 RX_MINI_RING_ENTRIES +
768 static int ace_allocate_descriptors(
struct net_device *dev)
773 size = (
sizeof(
struct rx_desc) *
774 (RX_STD_RING_ENTRIES +
775 RX_JUMBO_RING_ENTRIES +
776 RX_MINI_RING_ENTRIES +
828 ace_init_cleanup(dev);
837 static void ace_init_cleanup(
struct net_device *dev)
841 ap = netdev_priv(dev);
843 ace_free_descriptors(dev);
865 idx =
readl(®s->CmdPrd);
867 writel(*(
u32 *)(cmd), ®s->CmdRng[idx]);
870 writel(idx, ®s->CmdPrd);
883 int board_idx, ecode = 0;
885 unsigned char cache_size;
887 ap = netdev_priv(dev);
927 #ifndef CONFIG_ACENIC_OMIT_TIGON_I
978 for(i = 0; i < 4; i++) {
982 t = read_eeprom_byte(dev, 0x8c+i);
990 for(i = 4; i < 8; i++) {
994 t = read_eeprom_byte(dev, 0x8c+i);
1005 dev->
dev_addr[0] = (mac1 >> 8) & 0xff;
1007 dev->
dev_addr[2] = (mac2 >> 24) & 0xff;
1008 dev->
dev_addr[3] = (mac2 >> 16) & 0xff;
1009 dev->
dev_addr[4] = (mac2 >> 8) & 0xff;
1025 "(%i bytes) by BIOS/FW, ", cache_size);
1037 "latency: %i clks\n",
1059 dis_pci_mem_inval[board_idx]) {
1065 "write and invalidate\n");
1069 "enabled by BIOS, enabling counter measures\n");
1086 "supported, PCI write and invalidate "
1147 }
else if (!pci_set_dma_mask(pdev,
DMA_BIT_MASK(32))) {
1186 ap->last_std_rx = 0;
1187 ap->last_mini_rx = 0;
1193 ecode = ace_load_firmware(dev);
1213 set_aceaddr(&info->
cmd_ctrl.rngptr, 0x100);
1224 tmp_ptr += (
unsigned long) &(((
struct ace_info *)0)->s.stats);
1233 RX_STD_RING_ENTRIES *
sizeof(
struct rx_desc));
1243 (
sizeof(
struct rx_desc) * RX_STD_RING_ENTRIES)));
1249 RX_JUMBO_RING_ENTRIES *
sizeof(
struct rx_desc));
1258 RX_MINI_RING_ENTRIES *
sizeof(
struct rx_desc));
1264 (RX_STD_RING_ENTRIES +
1265 RX_JUMBO_RING_ENTRIES))));
1285 (RX_STD_RING_ENTRIES +
1286 RX_JUMBO_RING_ENTRIES +
1287 RX_MINI_RING_ENTRIES))));
1321 #if TX_COAL_INTS_ONLY
1352 ace_set_rxtx_parms(dev, 0);
1356 "ignoring module parameters!\n",
1358 }
else if (board_idx >= 0) {
1359 if (tx_coal_tick[board_idx])
1360 writel(tx_coal_tick[board_idx],
1362 if (max_tx_desc[board_idx])
1365 if (rx_coal_tick[board_idx])
1366 writel(rx_coal_tick[board_idx],
1368 if (max_rx_desc[board_idx])
1371 if (
trace[board_idx])
1374 if ((tx_ratio[board_idx] > 0) && (tx_ratio[board_idx] < 64))
1389 if ((board_idx >= 0) &&
link_state[board_idx]) {
1394 if (option & 0x01) {
1407 if ((option & 0x70) == 0) {
1409 "forcing auto negotiation\n", ap->
name);
1413 if ((option & 0x100) == 0)
1417 "negotiation\n", ap->
name);
1420 if ((option & 0x400) && (ap->
version >= 2)) {
1446 ace_set_txprd(regs, ap, 0);
1510 "the RX mini ring\n", ap->
name);
1515 ace_init_cleanup(dev);
1520 static void ace_set_rxtx_parms(
struct net_device *dev,
int jumbo)
1526 if (board_idx >= 0) {
1528 if (!tx_coal_tick[board_idx])
1530 if (!max_tx_desc[board_idx])
1532 if (!rx_coal_tick[board_idx])
1534 if (!max_rx_desc[board_idx])
1536 if (!tx_ratio[board_idx])
1539 if (!tx_coal_tick[board_idx])
1542 if (!max_tx_desc[board_idx])
1545 if (!rx_coal_tick[board_idx])
1548 if (!max_rx_desc[board_idx])
1551 if (!tx_ratio[board_idx])
1577 netif_wake_queue(dev);
1583 static void ace_tasklet(
unsigned long arg)
1593 printk(
"refilling buffers (current %i)\n", cur_size);
1603 printk(
"refilling mini buffers (current %i)\n",
1614 printk(
"refilling jumbo buffers (current %i)\n", cur_size);
1625 static void ace_dump_trace(
struct ace_private *ap)
1642 static void ace_load_std_rx_ring(
struct net_device *dev,
int nr_bufs)
1653 for (i = 0; i < nr_bufs; i++) {
1671 set_aceaddr(&rd->
addr, mapping);
1674 idx = (idx + 1) % RX_STD_RING_ENTRIES;
1688 ace_issue_cmd(regs, &cmd);
1700 "standard receive buffers\n");
1705 static void ace_load_mini_rx_ring(
struct net_device *dev,
int nr_bufs)
1714 for (i = 0; i < nr_bufs; i++) {
1732 set_aceaddr(&rd->
addr, mapping);
1735 idx = (idx + 1) % RX_MINI_RING_ENTRIES;
1753 "mini receive buffers\n");
1762 static void ace_load_jumbo_rx_ring(
struct net_device *dev,
int nr_bufs)
1770 for (i = 0; i < nr_bufs; i++) {
1783 ap->
skb->rx_jumbo_skbuff[
idx].skb =
skb;
1788 set_aceaddr(&rd->
addr, mapping);
1791 idx = (idx + 1) % RX_JUMBO_RING_ENTRIES;
1805 ace_issue_cmd(regs, &cmd);
1817 "jumbo receive buffers\n");
1831 ap = netdev_priv(dev);
1833 while (evtcsm != evtprd) {
1834 switch (ap->
evt_ring[evtcsm].evt) {
1851 "(%s Duplex, Flow Control: %s%s)\n",
1868 "state %02x\n", ap->
name, code);
1873 switch(ap->
evt_ring[evtcsm].code) {
1880 "error\n", ap->
name);
1895 if (ap->
skb->rx_jumbo_skbuff[i].skb) {
1898 dev_kfree_skb(ap->
skb->rx_jumbo_skbuff[i].skb);
1899 ap->
skb->rx_jumbo_skbuff[
i].skb =
NULL;
1908 ace_issue_cmd(ap->
regs, &cmd);
1936 int mini_count = 0, std_count = 0;
1943 while (idx != rxretprd) {
1948 int bd_flags, desc_type, mapsize;
1953 if (idx == rxretcsm)
1957 skbidx = retdesc->
idx;
1958 bd_flags = retdesc->
flags;
1970 rip = &ap->
skb->rx_std_skbuff[skbidx];
1976 rip = &ap->
skb->rx_jumbo_skbuff[skbidx];
1982 rip = &ap->
skb->rx_mini_skbuff[skbidx];
1989 "returned by NIC\n", dev->
name,
1996 pci_unmap_page(ap->
pdev,
2017 skb_checksum_none_assert(skb);
2022 __vlan_hwaccel_put_tag(skb, retdesc->
vlan);
2025 dev->
stats.rx_packets++;
2052 static inline void ace_tx_int(
struct net_device *dev,
2061 info = ap->
skb->tx_skbuff +
idx;
2072 dev->
stats.tx_packets++;
2079 }
while (idx != txcsm);
2081 if (netif_queue_stopped(dev))
2082 netif_wake_queue(dev);
2123 u32 txcsm, rxretcsm, rxretprd;
2155 if (rxretprd != rxretcsm)
2156 ace_rx_int(dev, rxretprd, rxretcsm);
2170 ace_tx_int(dev, txcsm, idx);
2176 if (evtcsm != evtprd) {
2177 evtcsm = ace_handle_event(dev, evtcsm, evtprd);
2185 if (netif_running(dev)) {
2187 int run_tasklet = 0;
2194 printk(
"low on std buffers %i\n", cur_size);
2196 ace_load_std_rx_ring(dev,
2209 printk(
"low on mini buffers %i\n",
2212 ace_load_mini_rx_ring(dev,
2226 printk(
"low on jumbo buffers %i\n",
2229 ace_load_jumbo_rx_ring(dev,
2260 ace_issue_cmd(regs, &cmd);
2265 ace_issue_cmd(regs, &cmd);
2275 ace_issue_cmd(regs, &cmd);
2286 ace_issue_cmd(regs, &cmd);
2289 netif_start_queue(dev);
2304 unsigned long flags;
2312 netif_stop_queue(dev);
2319 ace_issue_cmd(regs, &cmd);
2326 ace_issue_cmd(regs, &cmd);
2342 info = ap->
skb->tx_skbuff +
i;
2371 ace_issue_cmd(regs, &cmd);
2374 ace_unmask_irq(dev);
2392 info = ap->
skb->tx_skbuff +
idx;
2402 u32 flagsize,
u32 vlan_tag)
2404 #if !USE_TX_COAL_NOW
2415 desc->
addr.addrhi = addr >> 32;
2438 if (!skb_shinfo(skb)->nr_frags) {
2442 mapping = ace_map_tx_skb(ap, skb, skb, idx);
2457 ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
2463 mapping = ace_map_tx_skb(ap, skb,
NULL, idx);
2464 flagsize = (skb_headlen(skb) << 16);
2472 ace_load_tx_bd(ap, ap->
tx_ring + idx, mapping, flagsize, vlan_tag);
2476 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2480 len += skb_frag_size(frag);
2481 info = ap->
skb->tx_skbuff +
idx;
2484 mapping = skb_frag_dma_map(&ap->
pdev->dev, frag, 0,
2485 skb_frag_size(frag),
2488 flagsize = skb_frag_size(frag) << 16;
2493 if (i == skb_shinfo(skb)->nr_frags - 1) {
2508 ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
2514 ace_set_txprd(regs, ap, idx);
2517 netif_stop_queue(dev);
2526 netif_wake_queue(dev);
2560 static int ace_change_mtu(
struct net_device *dev,
int new_mtu)
2574 "support\n", dev->
name);
2578 ace_set_rxtx_parms(dev, 1);
2583 ace_set_rxtx_parms(dev, 0);
2590 ace_issue_cmd(regs, &cmd);
2621 ethtool_cmd_speed_set(ecmd,
SPEED_10);
2623 ethtool_cmd_speed_set(ecmd, 0);
2657 if (link & LNK_1000MB)
2661 if (link & LNK_100MB)
2675 if (ethtool_cmd_speed(ecmd) != speed) {
2676 link &= ~(LNK_1000MB | LNK_100MB |
LNK_10MB);
2677 switch (ethtool_cmd_speed(ecmd)) {
2693 if (link != ap->
link) {
2707 ace_issue_cmd(regs, &cmd);
2712 static void ace_get_drvinfo(
struct net_device *dev,
2731 static int ace_set_mac_addr(
struct net_device *dev,
void *
p)
2739 if(netif_running(dev))
2747 writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
2753 ace_issue_cmd(regs, &cmd);
2759 static void ace_set_multicast_list(
struct net_device *dev)
2769 ace_issue_cmd(regs, &cmd);
2775 ace_issue_cmd(regs, &cmd);
2783 ace_issue_cmd(regs, &cmd);
2789 ace_issue_cmd(regs, &cmd);
2803 ace_issue_cmd(regs, &cmd);
2808 ace_issue_cmd(regs, &cmd);
2839 tdest = (
void __iomem *) ®s->Window +
2842 for (i = 0; i < (tsize / 4); i++) {
2865 tdest = (
void __iomem *) ®s->Window +
2869 for (i = 0; i < (tsize / 4); i++) {
2888 const char *
fw_name =
"acenic/tg2.bin";
2897 "CPU is running!\n", ap->
name);
2902 fw_name =
"acenic/tg1.bin";
2911 fw_data = (
void *)fw->
data;
2931 if (load_addr < 0x4000 || load_addr >= 0x80000) {
2933 ap->
name, load_addr, fw_name);
2942 ace_clear(regs, 0x2000, 0x80000-0x2000);
2943 ace_copy(regs, &fw_data[3], load_addr, fw->
size-12);
2969 readl(®s->LocalCtrl);
2971 local =
readl(®s->LocalCtrl);
2973 writel(local, ®s->LocalCtrl);
2974 readl(®s->LocalCtrl);
2978 writel(local, ®s->LocalCtrl);
2979 readl(®s->LocalCtrl);
2983 writel(local, ®s->LocalCtrl);
2984 readl(®s->LocalCtrl);
2988 writel(local, ®s->LocalCtrl);
2989 readl(®s->LocalCtrl);
3000 local =
readl(®s->LocalCtrl);
3003 writel(local, ®s->LocalCtrl);
3004 readl(®s->LocalCtrl);
3007 for (i = 0; i < 8; i++, magic <<= 1) {
3013 writel(local, ®s->LocalCtrl);
3014 readl(®s->LocalCtrl);
3019 writel(local, ®s->LocalCtrl);
3020 readl(®s->LocalCtrl);
3024 writel(local, ®s->LocalCtrl);
3025 readl(®s->LocalCtrl);
3036 local =
readl(®s->LocalCtrl);
3038 writel(local, ®s->LocalCtrl);
3039 readl(®s->LocalCtrl);
3043 writel(local, ®s->LocalCtrl);
3044 readl(®s->LocalCtrl);
3052 readl(®s->LocalCtrl);
3064 local =
readl(®s->LocalCtrl);
3066 writel(local, ®s->LocalCtrl);
3067 readl(®s->LocalCtrl);
3071 writel(local, ®s->LocalCtrl);
3072 readl(®s->LocalCtrl);
3076 writel(local, ®s->LocalCtrl);
3077 readl(®s->LocalCtrl);
3081 writel(local, ®s->LocalCtrl);
3082 readl(®s->LocalCtrl);
3086 writel(local, ®s->LocalCtrl);
3099 unsigned long flags;
3113 if (eeprom_check_ack(regs)) {
3117 goto eeprom_read_error;
3120 eeprom_prep(regs, (offset >> 8) & 0xff);
3121 if (eeprom_check_ack(regs)) {
3126 goto eeprom_read_error;
3129 eeprom_prep(regs, offset & 0xff);
3130 if (eeprom_check_ack(regs)) {
3135 goto eeprom_read_error;
3140 if (eeprom_check_ack(regs)) {
3145 goto eeprom_read_error;
3148 for (i = 0; i < 8; i++) {
3161 result = (result << 1) |