29 #define DRV_NAME "starfire"
30 #define DRV_VERSION "2.1"
31 #define DRV_RELDATE "July 6, 2008"
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/pci.h>
37 #include <linux/netdevice.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/if_vlan.h>
47 #include <asm/processor.h>
48 #include <asm/uaccess.h>
55 #define HAS_BROKEN_FIRMWARE
60 #ifdef HAS_BROKEN_FIRMWARE
61 #define PADDING_MASK 3
69 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
77 static int intr_latency;
78 static int small_frames;
81 static int max_interrupt_work = 20;
85 static const int multicast_filter_limit = 512;
87 static int enable_hw_cksum = 1;
89 #define PKT_BUF_SZ 1536
104 #if defined(__ia64__) || defined(__alpha__) || defined(__sparc__)
107 static int rx_copybreak ;
112 #define DMA_BURST_SIZE 64
114 #define DMA_BURST_SIZE 128
122 #define RX_RING_SIZE 256
123 #define TX_RING_SIZE 32
125 #define DONE_Q_SIZE 1024
127 #define QUEUE_ALIGN 256
129 #if RX_RING_SIZE > 256
130 #define RX_Q_ENTRIES Rx2048QEntries
132 #define RX_Q_ENTRIES Rx256QEntries
137 #define TX_TIMEOUT (2 * HZ)
139 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
142 #define netdrv_addr_t __le64
143 #define cpu_to_dma(x) cpu_to_le64(x)
144 #define dma_to_cpu(x) le64_to_cpu(x)
145 #define RX_DESC_Q_ADDR_SIZE RxDescQAddr64bit
146 #define TX_DESC_Q_ADDR_SIZE TxDescQAddr64bit
147 #define RX_COMPL_Q_ADDR_SIZE RxComplQAddr64bit
148 #define TX_COMPL_Q_ADDR_SIZE TxComplQAddr64bit
149 #define RX_DESC_ADDR_SIZE RxDescAddr64bit
151 #define netdrv_addr_t __le32
152 #define cpu_to_dma(x) cpu_to_le32(x)
153 #define dma_to_cpu(x) le32_to_cpu(x)
154 #define RX_DESC_Q_ADDR_SIZE RxDescQAddr32bit
155 #define TX_DESC_Q_ADDR_SIZE TxDescQAddr32bit
156 #define RX_COMPL_Q_ADDR_SIZE RxComplQAddr32bit
157 #define TX_COMPL_Q_ADDR_SIZE TxComplQAddr32bit
158 #define RX_DESC_ADDR_SIZE RxDescAddr32bit
161 #define skb_first_frag_len(skb) skb_headlen(skb)
162 #define skb_num_frags(skb) (skb_shinfo(skb)->nr_frags + 1)
165 #define FIRMWARE_RX "adaptec/starfire_rx.bin"
166 #define FIRMWARE_TX "adaptec/starfire_tx.bin"
187 MODULE_PARM_DESC(max_interrupt_work,
"Maximum events handled per interrupt");
190 MODULE_PARM_DESC(rx_copybreak,
"Copy breakpoint for copy-only-tiny-frames");
191 MODULE_PARM_DESC(intr_latency,
"Maximum interrupt latency, in microseconds");
192 MODULE_PARM_DESC(small_frames,
"Maximum size of receive frames that bypass interrupt latency (0,64,128,256,512)");
193 MODULE_PARM_DESC(enable_hw_cksum,
"Enable/disable hardware cksum support (0/1)");
295 static const struct chip_info {
476 #define RxComplType RxComplType3
479 #define RxComplType RxComplType2
501 #define TX_DESC_TYPE TxDescType2
504 #define TX_DESC_TYPE TxDescType1
506 #define TX_DESC_SPACING TxDescSpaceUnlim
583 static void netdev_error(
struct net_device *
dev,
int intr_status);
587 static void netdev_error(
struct net_device *
dev,
int intr_status);
597 static int netdev_vlan_rx_add_vid(
struct net_device *
dev,
unsigned short vid)
601 spin_lock(&np->
lock);
603 printk(
"%s: Adding vlanid %d to vlan filter\n", dev->
name, vid);
604 set_bit(vid, np->active_vlans);
606 spin_unlock(&np->
lock);
611 static int netdev_vlan_rx_kill_vid(
struct net_device *dev,
unsigned short vid)
615 spin_lock(&np->
lock);
617 printk(
"%s: removing vlanid %d from vlan filter\n", dev->
name, vid);
620 spin_unlock(&np->
lock);
628 .ndo_open = netdev_open,
629 .ndo_stop = netdev_close,
630 .ndo_start_xmit = start_tx,
633 .ndo_set_rx_mode = set_rx_mode,
634 .ndo_do_ioctl = netdev_ioctl,
639 .ndo_vlan_rx_add_vid = netdev_vlan_rx_add_vid,
640 .ndo_vlan_rx_kill_vid = netdev_vlan_rx_kill_vid,
653 int drv_flags, io_size;
658 static int printed_version;
659 if (!printed_version++)
669 dev_err(d,
"no PCI MEM resources, aborting\n");
673 dev = alloc_etherdev(
sizeof(*np));
682 dev_err(d,
"cannot reserve PCI resources, aborting\n");
683 goto err_out_free_netdev;
686 base =
ioremap(ioaddr, io_size);
688 dev_err(d,
"cannot remap %#x @ %#lx, aborting\n",
690 goto err_out_free_res;
712 for (i = 0; i < 6; i++)
715 #if ! defined(final_version)
717 for (i = 0; i < 0x20; i++)
720 i % 16 != 15 ?
" " :
"\n");
731 while (--boguscnt > 0) {
737 printk(
"%s: chipset reset never completed!\n", dev->
name);
741 np = netdev_priv(dev);
745 pci_set_drvdata(pdev, dev);
750 np->
mii_if.mdio_read = mdio_read;
751 np->
mii_if.mdio_write = mdio_write;
752 np->
mii_if.phy_id_mask = 0x1f;
753 np->
mii_if.reg_num_mask = 0x1f;
755 drv_flags = netdrv_tbl[chip_idx].drv_flags;
763 if (small_frames > 0) {
765 switch (small_frames) {
777 if (small_frames > 512)
778 printk(
"Adjusting small_frames down to 512\n");
793 goto err_out_cleardev;
796 dev->
name, netdrv_tbl[chip_idx].name, base,
800 int phy, phy_idx = 0;
802 for (phy = 0; phy < 32 && phy_idx <
PHY_CNT; phy++) {
806 while (--boguscnt > 0)
810 printk(
"%s: PHY#%d reset never completed!\n", dev->
name, phy);
813 mii_status = mdio_read(dev, phy,
MII_BMSR);
814 if (mii_status != 0) {
818 "%#4.4x advertising %#4.4x.\n",
819 dev->
name, phy, mii_status, np->
mii_if.advertising);
831 printk(
KERN_INFO "%s: scatter-gather and hardware TCP cksumming %s.\n",
832 dev->
name, enable_hw_cksum ?
"enabled" :
"disabled");
836 pci_set_drvdata(pdev,
NULL);
851 int result, boguscnt=1000;
854 result =
readl(mdio_addr);
855 }
while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);
858 if ((result & 0xffff) == 0xffff)
860 return result & 0xffff;
864 static void mdio_write(
struct net_device *dev,
int phy_id,
int location,
int value)
873 static int netdev_open(
struct net_device *dev)
875 const struct firmware *fw_rx, *fw_tx;
876 const __be32 *fw_rx_data, *fw_tx_data;
879 const int irq = np->
pci_dev->irq;
881 size_t tx_size, rx_size;
882 size_t tx_done_q_size, rx_done_q_size, tx_ring_size, rx_ring_size;
903 np->
queue_mem_size = tx_done_q_size + rx_done_q_size + tx_ring_size + rx_ring_size;
963 for (i = 0; i < 6; i++)
970 for (i = 1; i < 16; i++) {
989 napi_enable(&np->
napi);
991 netif_start_queue(dev);
1023 if (fw_rx->
size % 4) {
1035 if (fw_tx->
size % 4) {
1041 fw_rx_data = (
const __be32 *)&fw_rx->
data[0];
1042 fw_tx_data = (
const __be32 *)&fw_tx->
data[0];
1043 rx_size = fw_rx->
size / 4;
1044 tx_size = fw_tx->
size / 4;
1047 for (i = 0; i < rx_size; i++)
1049 for (i = 0; i < tx_size; i++)
1051 if (enable_hw_cksum)
1073 static void check_duplex(
struct net_device *dev)
1077 int silly_count = 1000;
1082 while (--silly_count && mdio_read(dev, np->
phys[0],
MII_BMCR) & BMCR_RESET)
1085 printk(
"%s: MII reset failed!\n", dev->
name);
1091 if (!np->
mii_if.force_media) {
1097 if (np->
mii_if.full_duplex)
1102 np->
mii_if.full_duplex ?
"full" :
"half");
1132 dev->
stats.tx_errors++;
1133 netif_wake_queue(dev);
1138 static void init_ring(
struct net_device *dev)
1193 netif_stop_queue(dev);
1197 #if defined(ZEROCOPY) && defined(HAS_BROKEN_FIRMWARE)
1222 dev->
stats.tx_compressed++;
1229 const skb_frag_t *this_frag = &skb_shinfo(skb)->frags[i - 1];
1230 status |= skb_frag_size(this_frag);
1233 skb_frag_address(this_frag),
1234 skb_frag_size(this_frag),
1254 if (np->
cur_tx % (TX_RING_SIZE / 2) == 0)
1268 netif_stop_queue(dev);
1281 int boguscnt = max_interrupt_work;
1291 dev->
name, intr_status);
1293 if (intr_status == 0 || intr_status == (
u32) -1)
1313 "%s: interrupt while in poll!\n",
1327 dev->
name, consumer);
1333 if ((tx_status & 0xe0000000) == 0xa0000000) {
1334 dev->
stats.tx_packets++;
1335 }
else if ((tx_status & 0xe0000000) == 0x80000000) {
1345 entry = (entry + np->
tx_info[
entry].used_slots) % TX_RING_SIZE;
1348 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1351 skb_frag_size(&skb_shinfo(skb)->frags[i]),
1365 if (netif_queue_stopped(dev) &&
1368 netif_wake_queue(dev);
1377 netdev_media_change(dev);
1381 netdev_error(dev, intr_status);
1383 if (--boguscnt < 0) {
1387 dev->
name, intr_status);
1403 static int __netdev_rx(
struct net_device *dev,
int *quota)
1418 if (!(desc_status &
RxOK)) {
1422 dev->
stats.rx_errors++;
1424 dev->
stats.rx_fifo_errors++;
1435 entry = (desc_status >> 16) & 0x7ff;
1438 printk(
KERN_DEBUG " netdev_rx() normal Rx pkt length %d, quota %d.\n", pkt_len, *quota);
1441 if (pkt_len < rx_copybreak &&
1442 (skb = netdev_alloc_skb(dev, pkt_len + 2)) !=
NULL) {
1443 skb_reserve(skb, 2);
1444 pci_dma_sync_single_for_cpu(np->
pci_dev,
1447 skb_copy_to_linear_data(skb, np->
rx_info[entry].skb->data, pkt_len);
1448 pci_dma_sync_single_for_device(np->
pci_dev,
1459 #ifndef final_version
1475 dev->
stats.rx_compressed++;
1499 __vlan_hwaccel_put_tag(skb, vlid);
1503 dev->
stats.rx_packets++;
1518 refill_rx_ring(dev);
1521 retcode, np->
rx_done, desc_status);
1536 if (__netdev_rx(dev, "a))
1553 return budget - quota;
1556 static void refill_rx_ring(
struct net_device *dev)
1566 skb = netdev_alloc_skb(dev, np->
rx_buf_sz);
1575 if (entry == RX_RING_SIZE - 1)
1583 static void netdev_media_change(
struct net_device *dev)
1589 u32 new_intr_timer_ctrl;
1606 np->
mii_if.full_duplex = 1;
1609 np->
mii_if.full_duplex = 0;
1612 np->
mii_if.full_duplex = 1;
1615 np->
mii_if.full_duplex = 0;
1624 np->
mii_if.full_duplex = 1;
1626 np->
mii_if.full_duplex = 0;
1632 np->
mii_if.full_duplex ?
"full" :
"half");
1635 if (np->
mii_if.full_duplex)
1637 if (np->
tx_mode != new_tx_mode) {
1658 static void netdev_error(
struct net_device *dev,
int intr_status)
1666 printk(
KERN_NOTICE "%s: PCI bus congestion, increasing Tx FIFO threshold to %d bytes\n",
1672 dev->
stats.rx_fifo_errors++;
1673 dev->
stats.rx_errors++;
1676 dev->
stats.tx_fifo_errors++;
1677 dev->
stats.tx_errors++;
1681 dev->
name, intr_status);
1691 dev->
stats.tx_bytes =
readl(ioaddr + 0x57010);
1692 dev->
stats.rx_bytes =
readl(ioaddr + 0x57044);
1693 dev->
stats.tx_packets =
readl(ioaddr + 0x57000);
1694 dev->
stats.tx_aborted_errors =
1695 readl(ioaddr + 0x57024) +
readl(ioaddr + 0x57028);
1696 dev->
stats.tx_window_errors =
readl(ioaddr + 0x57018);
1697 dev->
stats.collisions =
1698 readl(ioaddr + 0x57004) +
readl(ioaddr + 0x57008);
1703 dev->
stats.rx_crc_errors =
readl(ioaddr + 0x5703C);
1704 dev->
stats.rx_frame_errors =
readl(ioaddr + 0x57040);
1705 dev->
stats.rx_length_errors =
readl(ioaddr + 0x57058);
1706 dev->
stats.rx_missed_errors =
readl(ioaddr + 0x5707C);
1720 if (vlan_count == 32)
1722 writew(vid, filter_addr);
1726 if (vlan_count == 32) {
1728 while (vlan_count < 32) {
1738 static void set_rx_mode(
struct net_device *dev)
1747 rx_mode |= set_vlan_mode(np);
1780 memset(mc_filter, 0,
sizeof(mc_filter));
1785 __le32 *fptr = (
__le32 *) &mc_filter[(bit_nr >> 4) & ~1];
1790 filter_addr = ioaddr + PerfFilterTable + 2 * 16;
1792 for (i = 2; i < 16; i++) {
1797 for (filter_addr = ioaddr +
HashTable, i = 0; i < 32; filter_addr+= 16, i++)
1798 writew(mc_filter[i], filter_addr);
1804 static int check_if_running(
struct net_device *dev)
1806 if (!netif_running(dev))
1822 spin_lock_irq(&np->
lock);
1824 spin_unlock_irq(&np->
lock);
1832 spin_lock_irq(&np->
lock);
1834 spin_unlock_irq(&np->
lock);
1839 static int nway_reset(
struct net_device *dev)
1862 .
begin = check_if_running,
1878 if (!netif_running(dev))
1881 spin_lock_irq(&np->
lock);
1883 spin_unlock_irq(&np->
lock);
1891 static int netdev_close(
struct net_device *dev)
1897 netif_stop_queue(dev);
1899 napi_disable(&np->
napi);
1919 for (i = 0; i < 8 ; i++)
1927 for (i = 0; i < 8 ; i++) {
1940 dev_kfree_skb(np->
rx_info[i].skb);
1963 struct net_device *dev = pci_get_drvdata(pdev);
1965 if (netif_running(dev)) {
1976 static int starfire_resume(
struct pci_dev *pdev)
1978 struct net_device *dev = pci_get_drvdata(pdev);
1983 if (netif_running(dev)) {
1995 struct net_device *dev = pci_get_drvdata(pdev);
2013 pci_set_drvdata(pdev,
NULL);
2020 .probe = starfire_init_one,
2023 .suspend = starfire_suspend,
2024 .resume = starfire_resume,
2026 .id_table = starfire_pci_tbl,
2030 static int __init starfire_init (
void)
2041 return pci_register_driver(&starfire_driver);
2045 static void __exit starfire_cleanup (
void)