26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #define DRV_NAME "yellowfin"
29 #define DRV_VERSION "2.1"
30 #define DRV_RELDATE "Sep 11, 2006"
37 static int max_interrupt_work = 20;
42 static int dma_ctrl = 0x004A0263;
45 static int dma_ctrl = 0x00CAC277;
48 static const int dma_ctrl = 0x004A0263;
54 static int rx_copybreak;
62 static int full_duplex[
MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
73 #define TX_RING_SIZE 16
74 #define TX_QUEUE_SIZE 12
75 #define RX_RING_SIZE 64
76 #define STATUS_TOTAL_SIZE TX_RING_SIZE*sizeof(struct tx_status_words)
77 #define TX_TOTAL_SIZE 2*TX_RING_SIZE*sizeof(struct yellowfin_desc)
78 #define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct yellowfin_desc)
82 #define TX_TIMEOUT (2*HZ)
83 #define PKT_BUF_SZ 1536
85 #define yellowfin_debug debug
87 #include <linux/module.h>
88 #include <linux/kernel.h>
89 #include <linux/string.h>
91 #include <linux/errno.h>
94 #include <linux/pci.h>
96 #include <linux/mii.h>
97 #include <linux/netdevice.h>
100 #include <linux/ethtool.h>
102 #include <linux/bitops.h>
103 #include <asm/uaccess.h>
104 #include <asm/processor.h>
105 #include <asm/unaligned.h>
124 MODULE_PARM_DESC(max_interrupt_work,
"G-NIC maximum events handled per interrupt");
127 MODULE_PARM_DESC(rx_copybreak,
"G-NIC copy breakpoint for copy-only-tiny-frames");
130 MODULE_PARM_DESC(gx_fix,
"G-NIC: enable GX server chipset bug workaround (0-1)");
232 {
"Yellowfin G-NIC Gigabit Ethernet", { 0x07021000, 0xffffffff},
234 {
"Symbios SYM83C885", { 0x07011000, 0xffffffff},
304 #define PRIV_ALIGN 31
346 static void yellowfin_timer(
unsigned long data);
351 static irqreturn_t yellowfin_interrupt(
int irq,
void *dev_instance);
353 static void yellowfin_error(
struct net_device *
dev,
int intr_status);
359 .ndo_open = yellowfin_open,
360 .ndo_stop = yellowfin_close,
361 .ndo_start_xmit = yellowfin_start_xmit,
362 .ndo_set_rx_mode = set_rx_mode,
366 .ndo_do_ioctl = netdev_ioctl,
367 .ndo_tx_timeout = yellowfin_tx_timeout,
391 static int printed_version;
392 if (!printed_version++)
399 dev = alloc_etherdev(
sizeof(*np));
405 np = netdev_priv(dev);
408 goto err_out_free_netdev;
414 goto err_out_free_res;
419 for (i = 0; i < 6; i++)
422 int ee_offset = (
read_eeprom(ioaddr, 6) == 0xff ? 0x100 : 0);
423 for (i = 0; i < 6; i++)
430 pci_set_drvdata(pdev, dev);
440 goto err_out_cleardev;
446 goto err_out_unmap_tx;
452 goto err_out_unmap_rx;
483 goto err_out_unmap_status;
485 netdev_info(dev,
"%s type %8x at %p, %pM, IRQ %d\n",
486 pci_id_tbl[chip_idx].
name,
491 int phy, phy_idx = 0;
492 for (phy = 0; phy < 32 && phy_idx <
MII_CNT; phy++) {
493 int mii_status = mdio_read(ioaddr, phy, 1);
494 if (mii_status != 0xffff && mii_status != 0x0000) {
497 netdev_info(dev,
"MII PHY found at address %d, status 0x%04x advertising %04x\n",
508 err_out_unmap_status:
516 pci_set_drvdata(pdev,
NULL);
527 int bogus_cnt = 10000;
540 static int mdio_read(
void __iomem *ioaddr,
int phy_id,
int location)
546 for (i = 10000; i >= 0; i--)
552 static void mdio_write(
void __iomem *ioaddr,
int phy_id,
int location,
int value)
560 for (i = 10000; i >= 0; i--)
566 static int yellowfin_open(
struct net_device *dev)
569 const int irq = yp->
pci_dev->irq;
580 rc = yellowfin_init_ring(dev);
587 for (i = 0; i < 6; i++)
612 netif_start_queue(dev);
640 yp->
timer.function = yellowfin_timer;
650 static void yellowfin_timer(
unsigned long data)
655 int next_tick = 60*
HZ;
668 yp->
phys[0], bmsr, lpa);
684 static void yellowfin_tx_timeout(
struct net_device *dev)
689 netdev_warn(dev,
"Yellowfin transmit timed out at %d/%d Tx status %04x, Rx status %04x, resetting...\n",
716 netif_wake_queue (dev);
719 dev->
stats.tx_errors++;
723 static int yellowfin_init_ring(
struct net_device *dev)
750 if (i != RX_RING_SIZE) {
751 for (j = 0; j <
i; j++)
815 netif_stop_queue (dev);
824 int cacheline_end = ((
unsigned long)skb->
data + skb->
len) % 32;
826 if (cacheline_end > 24 || cacheline_end == 0) {
827 len = skb->
len + 32 - cacheline_end + 1;
828 if (skb_padto(skb, len)) {
830 netif_wake_queue(dev);
841 if (entry >= TX_RING_SIZE-1) {
844 yp->
tx_ring[TX_RING_SIZE-1].dbdma_cmd =
853 yp->
tx_ring[entry<<1].request_cnt = len;
866 yp->
tx_ring[entry<<1].dbdma_cmd =
877 netif_start_queue (dev);
890 static irqreturn_t yellowfin_interrupt(
int irq,
void *dev_instance)
895 int boguscnt = max_interrupt_work;
896 unsigned int handled = 0;
898 yp = netdev_priv(dev);
901 spin_lock (&yp->
lock);
910 if (intr_status == 0)
924 if (yp->
tx_ring[entry].result_status == 0)
927 dev->
stats.tx_packets++;
939 netif_wake_queue(dev);
952 #ifndef final_version
964 if (tx_errs & 0xF810) {
966 #ifndef final_version
971 dev->
stats.tx_errors++;
972 if (tx_errs & 0xF800) dev->
stats.tx_aborted_errors++;
973 if (tx_errs & 0x0800) dev->
stats.tx_carrier_errors++;
974 if (tx_errs & 0x2000) dev->
stats.tx_window_errors++;
975 if (tx_errs & 0x8000) dev->
stats.tx_fifo_errors++;
977 #ifndef final_version
983 dev->
stats.collisions += tx_errs & 15;
984 dev->
stats.tx_packets++;
996 #ifndef final_version
997 if (yp->
cur_tx - dirty_tx > TX_RING_SIZE) {
998 netdev_err(dev,
"Out-of-sync dirty pointer, %d vs. %d, full=%d\n",
1008 netif_wake_queue(dev);
1017 if (intr_status & 0x2ee)
1018 yellowfin_error(dev, intr_status);
1020 if (--boguscnt < 0) {
1021 netdev_warn(dev,
"Too much work at interrupt, status=%#04x\n",
1031 spin_unlock (&yp->
lock);
1037 static int yellowfin_rx(
struct net_device *dev)
1045 entry, yp->
rx_ring[entry].result_status);
1048 yp->
rx_ring[entry].result_status);
1065 buf_addr = rx_skb->
data;
1068 frame_status = get_unaligned_le16(&(buf_addr[data_size - 2]));
1071 __func__, frame_status);
1074 if ( ! (desc_status &
RX_EOP)) {
1076 netdev_warn(dev,
"Oversized Ethernet frame spanned multiple buffers, status %04x, data_size %d!\n",
1077 desc_status, data_size);
1078 dev->
stats.rx_length_errors++;
1083 __func__, frame_status);
1084 dev->
stats.rx_errors++;
1085 if (frame_status & 0x0060) dev->
stats.rx_length_errors++;
1086 if (frame_status & 0x0008) dev->
stats.rx_frame_errors++;
1087 if (frame_status & 0x0010) dev->
stats.rx_crc_errors++;
1088 if (frame_status < 0) dev->
stats.rx_dropped++;
1090 ((buf_addr[data_size-1] & 0x85) || buf_addr[data_size-2] & 0xC0)) {
1093 dev->
stats.rx_errors++;
1094 if (status1 & 0xC0) dev->
stats.rx_length_errors++;
1095 if (status2 & 0x03) dev->
stats.rx_frame_errors++;
1096 if (status2 & 0x04) dev->
stats.rx_crc_errors++;
1097 if (status2 & 0x80) dev->
stats.rx_dropped++;
1105 "\377\377\377\377\377\377", 6) != 0) {
1106 if (bogus_rx++ == 0)
1107 netdev_warn(dev,
"Bad frame to %pM\n",
1113 (yp->
chip_id ? 7 : 8 + buf_addr[data_size - 8]);
1116 #ifndef final_version
1119 __func__, pkt_len, data_size, boguscnt);
1123 if (pkt_len > rx_copybreak) {
1124 skb_put(skb = rx_skb, pkt_len);
1131 skb = netdev_alloc_skb(dev, pkt_len + 2);
1134 skb_reserve(skb, 2);
1135 skb_copy_to_linear_data(skb, rx_skb->
data, pkt_len);
1137 pci_dma_sync_single_for_device(yp->
pci_dev,
1144 dev->
stats.rx_packets++;
1147 entry = (++yp->
cur_rx) % RX_RING_SIZE;
1158 skb_reserve(skb, 2);
1165 yp->
rx_ring[entry - 1].dbdma_cmd =
1168 yp->
rx_ring[RX_RING_SIZE - 1].dbdma_cmd =
1176 static void yellowfin_error(
struct net_device *dev,
int intr_status)
1178 netdev_err(dev,
"Something Wicked happened! %04x\n", intr_status);
1181 dev->
stats.tx_errors++;
1183 dev->
stats.rx_errors++;
1186 static int yellowfin_close(
struct net_device *dev)
1192 netif_stop_queue (dev);
1213 #if defined(__i386__)
1217 for (i = 0; i < TX_RING_SIZE*2; i++)
1234 yp->
rx_ring[i].result_status);
1240 for (j = 0; j < 0x50; j++)
1279 static void set_rx_mode(
struct net_device *dev)
1298 memset(hash_table, 0,
sizeof(hash_table));
1306 hash_table[bit >> 4] |= (1 <<
bit);
1308 hash_table[bit >> 4] |= (1 <<
bit);
1310 hash_table[bit >> 4] |= (1 <<
bit);
1313 hash_table[bit >> 4] |= (1 <<
bit);
1316 for (i = 0; i < 4; i++)
1359 np->
medialock = (value & 0x9000) ? 0 : 1;
1377 struct net_device *dev = pci_get_drvdata(pdev);
1381 np = netdev_priv(dev);
1394 pci_set_drvdata(pdev,
NULL);
1398 static struct pci_driver yellowfin_driver = {
1400 .id_table = yellowfin_pci_tbl,
1401 .probe = yellowfin_init_one,
1406 static int __init yellowfin_init (
void)
1412 return pci_register_driver(&yellowfin_driver);
1416 static void __exit yellowfin_cleanup (
void)