2 * ipg.c: Device Driver for the IP1000 Gigabit Ethernet Adapter
4 * Copyright (C) 2003, 2007 IC Plus Corp
9 * Sundance Technology, Inc.
11 * craig_rich@sundanceti.com
16 * http://www.icplus.com.tw
17 * sorbica@icplus.com.tw
20 * http://www.icplus.com.tw
23 #include <linux/crc32.h>
24 #include <linux/ethtool.h>
25 #include <linux/mii.h>
26 #include <linux/mutex.h>
28 #define IPG_RX_RING_BYTES (sizeof(struct ipg_rx) * IPG_RFDLIST_LENGTH)
29 #define IPG_TX_RING_BYTES (sizeof(struct ipg_tx) * IPG_TFDLIST_LENGTH)
30 #define IPG_RESET_MASK \
31 (IPG_AC_GLOBAL_RESET | IPG_AC_RX_RESET | IPG_AC_TX_RESET | \
32 IPG_AC_DMA | IPG_AC_FIFO | IPG_AC_NETWORK | IPG_AC_HOST | \
35 #define ipg_w32(val32,reg) iowrite32((val32), ioaddr + (reg))
36 #define ipg_w16(val16,reg) iowrite16((val16), ioaddr + (reg))
37 #define ipg_w8(val8,reg) iowrite8((val8), ioaddr + (reg))
39 #define ipg_r32(reg) ioread32(ioaddr + (reg))
40 #define ipg_r16(reg) ioread16(ioaddr + (reg))
41 #define ipg_r8(reg) ioread8(ioaddr + (reg))
43 #define JUMBO_FRAME_4k_ONLY
49 #define DRV_NAME "ipg"
51 MODULE_AUTHOR("IC Plus Corp. 2003");
52 MODULE_DESCRIPTION("IC Plus IP1000 Gigabit Ethernet Adapter Linux Driver "
54 MODULE_LICENSE("GPL");
56 static const char *ipg_brand_name[] = {
57 "IC PLUS IP1000 1000/100/10 based NIC",
58 "Sundance Technology ST2021 based NIC",
59 "Tamarack Microelectronics TC9020/9021 based NIC",
60 "Tamarack Microelectronics TC9020/9021 based NIC",
65 static struct pci_device_id ipg_pci_tbl[] __devinitdata = {
66 { PCI_VDEVICE(SUNDANCE, 0x1023), 0 },
67 { PCI_VDEVICE(SUNDANCE, 0x2021), 1 },
68 { PCI_VDEVICE(SUNDANCE, 0x1021), 2 },
69 { PCI_VDEVICE(DLINK, 0x9021), 3 },
70 { PCI_VDEVICE(DLINK, 0x4000), 4 },
71 { PCI_VDEVICE(DLINK, 0x4020), 5 },
75 MODULE_DEVICE_TABLE(pci, ipg_pci_tbl);
77 static inline void __iomem *ipg_ioaddr(struct net_device *dev)
79 struct ipg_nic_private *sp = netdev_priv(dev);
84 static void ipg_dump_rfdlist(struct net_device *dev)
86 struct ipg_nic_private *sp = netdev_priv(dev);
87 void __iomem *ioaddr = sp->ioaddr;
91 IPG_DEBUG_MSG("_dump_rfdlist\n");
93 printk(KERN_INFO "rx_current = %2.2x\n", sp->rx_current);
94 printk(KERN_INFO "rx_dirty = %2.2x\n", sp->rx_dirty);
95 printk(KERN_INFO "RFDList start address = %16.16lx\n",
96 (unsigned long) sp->rxd_map);
97 printk(KERN_INFO "RFDListPtr register = %8.8x%8.8x\n",
98 ipg_r32(IPG_RFDLISTPTR1), ipg_r32(IPG_RFDLISTPTR0));
100 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
101 offset = (u32) &sp->rxd[i].next_desc - (u32) sp->rxd;
102 printk(KERN_INFO "%2.2x %4.4x RFDNextPtr = %16.16lx\n", i,
103 offset, (unsigned long) sp->rxd[i].next_desc);
104 offset = (u32) &sp->rxd[i].rfs - (u32) sp->rxd;
105 printk(KERN_INFO "%2.2x %4.4x RFS = %16.16lx\n", i,
106 offset, (unsigned long) sp->rxd[i].rfs);
107 offset = (u32) &sp->rxd[i].frag_info - (u32) sp->rxd;
108 printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
109 offset, (unsigned long) sp->rxd[i].frag_info);
113 static void ipg_dump_tfdlist(struct net_device *dev)
115 struct ipg_nic_private *sp = netdev_priv(dev);
116 void __iomem *ioaddr = sp->ioaddr;
120 IPG_DEBUG_MSG("_dump_tfdlist\n");
122 printk(KERN_INFO "tx_current = %2.2x\n", sp->tx_current);
123 printk(KERN_INFO "tx_dirty = %2.2x\n", sp->tx_dirty);
124 printk(KERN_INFO "TFDList start address = %16.16lx\n",
125 (unsigned long) sp->txd_map);
126 printk(KERN_INFO "TFDListPtr register = %8.8x%8.8x\n",
127 ipg_r32(IPG_TFDLISTPTR1), ipg_r32(IPG_TFDLISTPTR0));
129 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
130 offset = (u32) &sp->txd[i].next_desc - (u32) sp->txd;
131 printk(KERN_INFO "%2.2x %4.4x TFDNextPtr = %16.16lx\n", i,
132 offset, (unsigned long) sp->txd[i].next_desc);
134 offset = (u32) &sp->txd[i].tfc - (u32) sp->txd;
135 printk(KERN_INFO "%2.2x %4.4x TFC = %16.16lx\n", i,
136 offset, (unsigned long) sp->txd[i].tfc);
137 offset = (u32) &sp->txd[i].frag_info - (u32) sp->txd;
138 printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
139 offset, (unsigned long) sp->txd[i].frag_info);
144 static void ipg_write_phy_ctl(void __iomem *ioaddr, u8 data)
146 ipg_w8(IPG_PC_RSVD_MASK & data, PHY_CTRL);
147 ndelay(IPG_PC_PHYCTRLWAIT_NS);
150 static void ipg_drive_phy_ctl_low_high(void __iomem *ioaddr, u8 data)
152 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | data);
153 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | data);
156 static void send_three_state(void __iomem *ioaddr, u8 phyctrlpolarity)
158 phyctrlpolarity |= (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR;
160 ipg_drive_phy_ctl_low_high(ioaddr, phyctrlpolarity);
163 static void send_end(void __iomem *ioaddr, u8 phyctrlpolarity)
165 ipg_w8((IPG_PC_MGMTCLK_LO | (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR |
166 phyctrlpolarity) & IPG_PC_RSVD_MASK, PHY_CTRL);
169 static u16 read_phy_bit(void __iomem * ioaddr, u8 phyctrlpolarity)
173 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | phyctrlpolarity);
175 bit_data = ((ipg_r8(PHY_CTRL) & IPG_PC_MGMTDATA) >> 1) & 1;
177 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | phyctrlpolarity);
183 * Read a register from the Physical Layer device located
184 * on the IPG NIC, using the IPG PHYCTRL register.
186 static int mdio_read(struct net_device * dev, int phy_id, int phy_reg)
188 void __iomem *ioaddr = ipg_ioaddr(dev);
190 * The GMII mangement frame structure for a read is as follows:
192 * |Preamble|st|op|phyad|regad|ta| data |idle|
193 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
195 * <32 1s> = 32 consecutive logic 1 values
196 * A = bit of Physical Layer device address (MSB first)
197 * R = bit of register address (MSB first)
198 * z = High impedance state
199 * D = bit of read data (MSB first)
201 * Transmission order is 'Preamble' field first, bits transmitted
202 * left to right (first to last).
208 { GMII_PREAMBLE, 32 }, /* Preamble */
209 { GMII_ST, 2 }, /* ST */
210 { GMII_READ, 2 }, /* OP */
211 { phy_id, 5 }, /* PHYAD */
212 { phy_reg, 5 }, /* REGAD */
213 { 0x0000, 2 }, /* TA */
214 { 0x0000, 16 }, /* DATA */
215 { 0x0000, 1 } /* IDLE */
220 polarity = ipg_r8(PHY_CTRL);
221 polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
223 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
224 for (j = 0; j < 5; j++) {
225 for (i = 0; i < p[j].len; i++) {
226 /* For each variable length field, the MSB must be
227 * transmitted first. Rotate through the field bits,
228 * starting with the MSB, and move each bit into the
229 * the 1st (2^1) bit position (this is the bit position
230 * corresponding to the MgmtData bit of the PhyCtrl
231 * register for the IPG).
235 * First write a '0' to bit 1 of the PhyCtrl
236 * register, then write a '1' to bit 1 of the
239 * To do this, right shift the MSB of ST by the value:
240 * [field length - 1 - #ST bits already written]
241 * then left shift this result by 1.
243 data = (p[j].field >> (p[j].len - 1 - i)) << 1;
244 data &= IPG_PC_MGMTDATA;
245 data |= polarity | IPG_PC_MGMTDIR;
247 ipg_drive_phy_ctl_low_high(ioaddr, data);
251 send_three_state(ioaddr, polarity);
253 read_phy_bit(ioaddr, polarity);
256 * For a read cycle, the bits for the next two fields (TA and
257 * DATA) are driven by the PHY (the IPG reads these bits).
259 for (i = 0; i < p[6].len; i++) {
261 (read_phy_bit(ioaddr, polarity) << (p[6].len - 1 - i));
264 send_three_state(ioaddr, polarity);
265 send_three_state(ioaddr, polarity);
266 send_three_state(ioaddr, polarity);
267 send_end(ioaddr, polarity);
269 /* Return the value of the DATA field. */
274 * Write to a register from the Physical Layer device located
275 * on the IPG NIC, using the IPG PHYCTRL register.
277 static void mdio_write(struct net_device *dev, int phy_id, int phy_reg, int val)
279 void __iomem *ioaddr = ipg_ioaddr(dev);
281 * The GMII mangement frame structure for a read is as follows:
283 * |Preamble|st|op|phyad|regad|ta| data |idle|
284 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
286 * <32 1s> = 32 consecutive logic 1 values
287 * A = bit of Physical Layer device address (MSB first)
288 * R = bit of register address (MSB first)
289 * z = High impedance state
290 * D = bit of write data (MSB first)
292 * Transmission order is 'Preamble' field first, bits transmitted
293 * left to right (first to last).
299 { GMII_PREAMBLE, 32 }, /* Preamble */
300 { GMII_ST, 2 }, /* ST */
301 { GMII_WRITE, 2 }, /* OP */
302 { phy_id, 5 }, /* PHYAD */
303 { phy_reg, 5 }, /* REGAD */
304 { 0x0002, 2 }, /* TA */
305 { val & 0xffff, 16 }, /* DATA */
306 { 0x0000, 1 } /* IDLE */
311 polarity = ipg_r8(PHY_CTRL);
312 polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
314 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
315 for (j = 0; j < 7; j++) {
316 for (i = 0; i < p[j].len; i++) {
317 /* For each variable length field, the MSB must be
318 * transmitted first. Rotate through the field bits,
319 * starting with the MSB, and move each bit into the
320 * the 1st (2^1) bit position (this is the bit position
321 * corresponding to the MgmtData bit of the PhyCtrl
322 * register for the IPG).
326 * First write a '0' to bit 1 of the PhyCtrl
327 * register, then write a '1' to bit 1 of the
330 * To do this, right shift the MSB of ST by the value:
331 * [field length - 1 - #ST bits already written]
332 * then left shift this result by 1.
334 data = (p[j].field >> (p[j].len - 1 - i)) << 1;
335 data &= IPG_PC_MGMTDATA;
336 data |= polarity | IPG_PC_MGMTDIR;
338 ipg_drive_phy_ctl_low_high(ioaddr, data);
342 /* The last cycle is a tri-state, so read from the PHY. */
343 for (j = 7; j < 8; j++) {
344 for (i = 0; i < p[j].len; i++) {
345 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
347 p[j].field |= ((ipg_r8(PHY_CTRL) &
348 IPG_PC_MGMTDATA) >> 1) << (p[j].len - 1 - i);
350 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
355 /* Set LED_Mode JES20040127EEPROM */
356 static void ipg_set_led_mode(struct net_device *dev)
358 struct ipg_nic_private *sp = netdev_priv(dev);
359 void __iomem *ioaddr = sp->ioaddr;
362 mode = ipg_r32(ASIC_CTRL);
363 mode &= ~(IPG_AC_LED_MODE_BIT_1 | IPG_AC_LED_MODE | IPG_AC_LED_SPEED);
365 if ((sp->LED_Mode & 0x03) > 1)
366 mode |= IPG_AC_LED_MODE_BIT_1; /* Write Asic Control Bit 29 */
368 if ((sp->LED_Mode & 0x01) == 1)
369 mode |= IPG_AC_LED_MODE; /* Write Asic Control Bit 14 */
371 if ((sp->LED_Mode & 0x08) == 8)
372 mode |= IPG_AC_LED_SPEED; /* Write Asic Control Bit 27 */
374 ipg_w32(mode, ASIC_CTRL);
377 /* Set PHYSet JES20040127EEPROM */
378 static void ipg_set_phy_set(struct net_device *dev)
380 struct ipg_nic_private *sp = netdev_priv(dev);
381 void __iomem *ioaddr = sp->ioaddr;
384 physet = ipg_r8(PHY_SET);
385 physet &= ~(IPG_PS_MEM_LENB9B | IPG_PS_MEM_LEN9 | IPG_PS_NON_COMPDET);
386 physet |= ((sp->LED_Mode & 0x70) >> 4);
387 ipg_w8(physet, PHY_SET);
390 static int ipg_reset(struct net_device *dev, u32 resetflags)
392 /* Assert functional resets via the IPG AsicCtrl
393 * register as specified by the 'resetflags' input
396 void __iomem *ioaddr = ipg_ioaddr(dev); //JES20040127EEPROM:
397 unsigned int timeout_count = 0;
399 IPG_DEBUG_MSG("_reset\n");
401 ipg_w32(ipg_r32(ASIC_CTRL) | resetflags, ASIC_CTRL);
403 /* Delay added to account for problem with 10Mbps reset. */
404 mdelay(IPG_AC_RESETWAIT);
406 while (IPG_AC_RESET_BUSY & ipg_r32(ASIC_CTRL)) {
407 mdelay(IPG_AC_RESETWAIT);
408 if (++timeout_count > IPG_AC_RESET_TIMEOUT)
411 /* Set LED Mode in Asic Control JES20040127EEPROM */
412 ipg_set_led_mode(dev);
414 /* Set PHYSet Register Value JES20040127EEPROM */
415 ipg_set_phy_set(dev);
419 /* Find the GMII PHY address. */
420 static int ipg_find_phyaddr(struct net_device *dev)
422 unsigned int phyaddr, i;
424 for (i = 0; i < 32; i++) {
427 /* Search for the correct PHY address among 32 possible. */
428 phyaddr = (IPG_NIC_PHY_ADDRESS + i) % 32;
430 /* 10/22/03 Grace change verify from GMII_PHY_STATUS to
434 status = mdio_read(dev, phyaddr, MII_BMSR);
436 if ((status != 0xFFFF) && (status != 0))
444 * Configure IPG based on result of IEEE 802.3 PHY
447 static int ipg_config_autoneg(struct net_device *dev)
449 struct ipg_nic_private *sp = netdev_priv(dev);
450 void __iomem *ioaddr = sp->ioaddr;
451 unsigned int txflowcontrol;
452 unsigned int rxflowcontrol;
453 unsigned int fullduplex;
459 IPG_DEBUG_MSG("_config_autoneg\n");
461 asicctrl = ipg_r32(ASIC_CTRL);
462 phyctrl = ipg_r8(PHY_CTRL);
463 mac_ctrl_val = ipg_r32(MAC_CTRL);
465 /* Set flags for use in resolving auto-negotation, assuming
466 * non-1000Mbps, half duplex, no flow control.
473 /* To accomodate a problem in 10Mbps operation,
474 * set a global flag if PHY running in 10Mbps mode.
478 printk(KERN_INFO "%s: Link speed = ", dev->name);
480 /* Determine actual speed of operation. */
481 switch (phyctrl & IPG_PC_LINK_SPEED) {
482 case IPG_PC_LINK_SPEED_10MBPS:
484 printk(KERN_INFO "%s: 10Mbps operational mode enabled.\n",
488 case IPG_PC_LINK_SPEED_100MBPS:
489 printk("100Mbps.\n");
491 case IPG_PC_LINK_SPEED_1000MBPS:
492 printk("1000Mbps.\n");
496 printk("undefined!\n");
500 if (phyctrl & IPG_PC_DUPLEX_STATUS) {
506 /* Configure full duplex, and flow control. */
507 if (fullduplex == 1) {
508 /* Configure IPG for full duplex operation. */
509 printk(KERN_INFO "%s: setting full duplex, ", dev->name);
511 mac_ctrl_val |= IPG_MC_DUPLEX_SELECT_FD;
513 if (txflowcontrol == 1) {
514 printk("TX flow control");
515 mac_ctrl_val |= IPG_MC_TX_FLOW_CONTROL_ENABLE;
517 printk("no TX flow control");
518 mac_ctrl_val &= ~IPG_MC_TX_FLOW_CONTROL_ENABLE;
521 if (rxflowcontrol == 1) {
522 printk(", RX flow control.");
523 mac_ctrl_val |= IPG_MC_RX_FLOW_CONTROL_ENABLE;
525 printk(", no RX flow control.");
526 mac_ctrl_val &= ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
531 /* Configure IPG for half duplex operation. */
532 printk(KERN_INFO "%s: setting half duplex, "
533 "no TX flow control, no RX flow control.\n", dev->name);
535 mac_ctrl_val &= ~IPG_MC_DUPLEX_SELECT_FD &
536 ~IPG_MC_TX_FLOW_CONTROL_ENABLE &
537 ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
539 ipg_w32(mac_ctrl_val, MAC_CTRL);
543 /* Determine and configure multicast operation and set
544 * receive mode for IPG.
546 static void ipg_nic_set_multicast_list(struct net_device *dev)
548 void __iomem *ioaddr = ipg_ioaddr(dev);
549 struct dev_mc_list *mc_list_ptr;
550 unsigned int hashindex;
554 IPG_DEBUG_MSG("_nic_set_multicast_list\n");
556 receivemode = IPG_RM_RECEIVEUNICAST | IPG_RM_RECEIVEBROADCAST;
558 if (dev->flags & IFF_PROMISC) {
559 /* NIC to be configured in promiscuous mode. */
560 receivemode = IPG_RM_RECEIVEALLFRAMES;
561 } else if ((dev->flags & IFF_ALLMULTI) ||
562 (dev->flags & IFF_MULTICAST &
563 (dev->mc_count > IPG_MULTICAST_HASHTABLE_SIZE))) {
564 /* NIC to be configured to receive all multicast
566 receivemode |= IPG_RM_RECEIVEMULTICAST;
567 } else if (dev->flags & IFF_MULTICAST & (dev->mc_count > 0)) {
568 /* NIC to be configured to receive selected
569 * multicast addresses. */
570 receivemode |= IPG_RM_RECEIVEMULTICASTHASH;
573 /* Calculate the bits to set for the 64 bit, IPG HASHTABLE.
574 * The IPG applies a cyclic-redundancy-check (the same CRC
575 * used to calculate the frame data FCS) to the destination
576 * address all incoming multicast frames whose destination
577 * address has the multicast bit set. The least significant
578 * 6 bits of the CRC result are used as an addressing index
579 * into the hash table. If the value of the bit addressed by
580 * this index is a 1, the frame is passed to the host system.
583 /* Clear hashtable. */
584 hashtable[0] = 0x00000000;
585 hashtable[1] = 0x00000000;
587 /* Cycle through all multicast addresses to filter. */
588 for (mc_list_ptr = dev->mc_list;
589 mc_list_ptr != NULL; mc_list_ptr = mc_list_ptr->next) {
590 /* Calculate CRC result for each multicast address. */
591 hashindex = crc32_le(0xffffffff, mc_list_ptr->dmi_addr,
594 /* Use only the least significant 6 bits. */
595 hashindex = hashindex & 0x3F;
597 /* Within "hashtable", set bit number "hashindex"
600 set_bit(hashindex, (void *)hashtable);
603 /* Write the value of the hashtable, to the 4, 16 bit
604 * HASHTABLE IPG registers.
606 ipg_w32(hashtable[0], HASHTABLE_0);
607 ipg_w32(hashtable[1], HASHTABLE_1);
609 ipg_w8(IPG_RM_RSVD_MASK & receivemode, RECEIVE_MODE);
611 IPG_DEBUG_MSG("ReceiveMode = %x\n", ipg_r8(RECEIVE_MODE));
614 static int ipg_io_config(struct net_device *dev)
616 void __iomem *ioaddr = ipg_ioaddr(dev);
620 IPG_DEBUG_MSG("_io_config\n");
622 origmacctrl = ipg_r32(MAC_CTRL);
624 restoremacctrl = origmacctrl | IPG_MC_STATISTICS_ENABLE;
626 /* Based on compilation option, determine if FCS is to be
627 * stripped on receive frames by IPG.
629 if (!IPG_STRIP_FCS_ON_RX)
630 restoremacctrl |= IPG_MC_RCV_FCS;
632 /* Determine if transmitter and/or receiver are
633 * enabled so we may restore MACCTRL correctly.
635 if (origmacctrl & IPG_MC_TX_ENABLED)
636 restoremacctrl |= IPG_MC_TX_ENABLE;
638 if (origmacctrl & IPG_MC_RX_ENABLED)
639 restoremacctrl |= IPG_MC_RX_ENABLE;
641 /* Transmitter and receiver must be disabled before setting
644 ipg_w32((origmacctrl & (IPG_MC_RX_DISABLE | IPG_MC_TX_DISABLE)) &
645 IPG_MC_RSVD_MASK, MAC_CTRL);
647 /* Now that transmitter and receiver are disabled, write
650 ipg_w32((origmacctrl & IPG_MC_IFS_96BIT) & IPG_MC_RSVD_MASK, MAC_CTRL);
652 /* Set RECEIVEMODE register. */
653 ipg_nic_set_multicast_list(dev);
655 ipg_w16(IPG_MAX_RXFRAME_SIZE, MAX_FRAME_SIZE);
657 ipg_w8(IPG_RXDMAPOLLPERIOD_VALUE, RX_DMA_POLL_PERIOD);
658 ipg_w8(IPG_RXDMAURGENTTHRESH_VALUE, RX_DMA_URGENT_THRESH);
659 ipg_w8(IPG_RXDMABURSTTHRESH_VALUE, RX_DMA_BURST_THRESH);
660 ipg_w8(IPG_TXDMAPOLLPERIOD_VALUE, TX_DMA_POLL_PERIOD);
661 ipg_w8(IPG_TXDMAURGENTTHRESH_VALUE, TX_DMA_URGENT_THRESH);
662 ipg_w8(IPG_TXDMABURSTTHRESH_VALUE, TX_DMA_BURST_THRESH);
663 ipg_w16((IPG_IE_HOST_ERROR | IPG_IE_TX_DMA_COMPLETE |
664 IPG_IE_TX_COMPLETE | IPG_IE_INT_REQUESTED |
665 IPG_IE_UPDATE_STATS | IPG_IE_LINK_EVENT |
666 IPG_IE_RX_DMA_COMPLETE | IPG_IE_RX_DMA_PRIORITY), INT_ENABLE);
667 ipg_w16(IPG_FLOWONTHRESH_VALUE, FLOW_ON_THRESH);
668 ipg_w16(IPG_FLOWOFFTHRESH_VALUE, FLOW_OFF_THRESH);
670 /* IPG multi-frag frame bug workaround.
671 * Per silicon revision B3 eratta.
673 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0200, DEBUG_CTRL);
675 /* IPG TX poll now bug workaround.
676 * Per silicon revision B3 eratta.
678 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0010, DEBUG_CTRL);
680 /* IPG RX poll now bug workaround.
681 * Per silicon revision B3 eratta.
683 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0020, DEBUG_CTRL);
685 /* Now restore MACCTRL to original setting. */
686 ipg_w32(IPG_MC_RSVD_MASK & restoremacctrl, MAC_CTRL);
688 /* Disable unused RMON statistics. */
689 ipg_w32(IPG_RZ_ALL, RMON_STATISTICS_MASK);
691 /* Disable unused MIB statistics. */
692 ipg_w32(IPG_SM_MACCONTROLFRAMESXMTD | IPG_SM_MACCONTROLFRAMESRCVD |
693 IPG_SM_BCSTOCTETXMTOK_BCSTFRAMESXMTDOK | IPG_SM_TXJUMBOFRAMES |
694 IPG_SM_MCSTOCTETXMTOK_MCSTFRAMESXMTDOK | IPG_SM_RXJUMBOFRAMES |
695 IPG_SM_BCSTOCTETRCVDOK_BCSTFRAMESRCVDOK |
696 IPG_SM_UDPCHECKSUMERRORS | IPG_SM_TCPCHECKSUMERRORS |
697 IPG_SM_IPCHECKSUMERRORS, STATISTICS_MASK);
703 * Create a receive buffer within system memory and update
704 * NIC private structure appropriately.
706 static int ipg_get_rxbuff(struct net_device *dev, int entry)
708 struct ipg_nic_private *sp = netdev_priv(dev);
709 struct ipg_rx *rxfd = sp->rxd + entry;
713 IPG_DEBUG_MSG("_get_rxbuff\n");
715 skb = netdev_alloc_skb(dev, IPG_RXSUPPORT_SIZE + NET_IP_ALIGN);
717 sp->RxBuff[entry] = NULL;
721 /* Adjust the data start location within the buffer to
722 * align IP address field to a 16 byte boundary.
724 skb_reserve(skb, NET_IP_ALIGN);
726 /* Associate the receive buffer with the IPG NIC. */
729 /* Save the address of the sk_buff structure. */
730 sp->RxBuff[entry] = skb;
732 rxfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
733 sp->rx_buf_sz, PCI_DMA_FROMDEVICE));
735 /* Set the RFD fragment length. */
736 rxfragsize = IPG_RXFRAG_SIZE;
737 rxfd->frag_info |= cpu_to_le64((rxfragsize << 48) & IPG_RFI_FRAGLEN);
742 static int init_rfdlist(struct net_device *dev)
744 struct ipg_nic_private *sp = netdev_priv(dev);
745 void __iomem *ioaddr = sp->ioaddr;
748 IPG_DEBUG_MSG("_init_rfdlist\n");
750 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
751 struct ipg_rx *rxfd = sp->rxd + i;
754 pci_unmap_single(sp->pdev,
755 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
756 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
757 IPG_DEV_KFREE_SKB(sp->RxBuff[i]);
758 sp->RxBuff[i] = NULL;
761 /* Clear out the RFS field. */
762 rxfd->rfs = 0x0000000000000000;
764 if (ipg_get_rxbuff(dev, i) < 0) {
766 * A receive buffer was not ready, break the
769 IPG_DEBUG_MSG("Cannot allocate Rx buffer.\n");
771 /* Just in case we cannot allocate a single RFD.
775 printk(KERN_ERR "%s: No memory available"
776 " for RFD list.\n", dev->name);
781 rxfd->next_desc = cpu_to_le64(sp->rxd_map +
782 sizeof(struct ipg_rx)*(i + 1));
784 sp->rxd[i - 1].next_desc = cpu_to_le64(sp->rxd_map);
789 /* Write the location of the RFDList to the IPG. */
790 ipg_w32((u32) sp->rxd_map, RFD_LIST_PTR_0);
791 ipg_w32(0x00000000, RFD_LIST_PTR_1);
796 static void init_tfdlist(struct net_device *dev)
798 struct ipg_nic_private *sp = netdev_priv(dev);
799 void __iomem *ioaddr = sp->ioaddr;
802 IPG_DEBUG_MSG("_init_tfdlist\n");
804 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
805 struct ipg_tx *txfd = sp->txd + i;
807 txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
810 IPG_DEV_KFREE_SKB(sp->TxBuff[i]);
811 sp->TxBuff[i] = NULL;
814 txfd->next_desc = cpu_to_le64(sp->txd_map +
815 sizeof(struct ipg_tx)*(i + 1));
817 sp->txd[i - 1].next_desc = cpu_to_le64(sp->txd_map);
822 /* Write the location of the TFDList to the IPG. */
823 IPG_DDEBUG_MSG("Starting TFDListPtr = %8.8x\n",
825 ipg_w32((u32) sp->txd_map, TFD_LIST_PTR_0);
826 ipg_w32(0x00000000, TFD_LIST_PTR_1);
828 sp->ResetCurrentTFD = 1;
832 * Free all transmit buffers which have already been transfered
833 * via DMA to the IPG.
835 static void ipg_nic_txfree(struct net_device *dev)
837 struct ipg_nic_private *sp = netdev_priv(dev);
838 void __iomem *ioaddr = sp->ioaddr;
839 const unsigned int curr = ipg_r32(TFD_LIST_PTR_0) -
840 (sp->txd_map / sizeof(struct ipg_tx)) - 1;
841 unsigned int released, pending;
843 IPG_DEBUG_MSG("_nic_txfree\n");
845 pending = sp->tx_current - sp->tx_dirty;
847 for (released = 0; released < pending; released++) {
848 unsigned int dirty = sp->tx_dirty % IPG_TFDLIST_LENGTH;
849 struct sk_buff *skb = sp->TxBuff[dirty];
850 struct ipg_tx *txfd = sp->txd + dirty;
852 IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd->tfc);
854 /* Look at each TFD's TFC field beginning
855 * at the last freed TFD up to the current TFD.
856 * If the TFDDone bit is set, free the associated
862 /* Setup TFDDONE for compatible issue. */
863 txfd->tfc |= cpu_to_le64(IPG_TFC_TFDDONE);
865 /* Free the transmit buffer. */
867 pci_unmap_single(sp->pdev,
868 le64_to_cpu(txfd->frag_info & ~IPG_TFI_FRAGLEN),
869 skb->len, PCI_DMA_TODEVICE);
871 IPG_DEV_KFREE_SKB(skb);
873 sp->TxBuff[dirty] = NULL;
877 sp->tx_dirty += released;
879 if (netif_queue_stopped(dev) &&
880 (sp->tx_current != (sp->tx_dirty + IPG_TFDLIST_LENGTH))) {
881 netif_wake_queue(dev);
885 static void ipg_tx_timeout(struct net_device *dev)
887 struct ipg_nic_private *sp = netdev_priv(dev);
888 void __iomem *ioaddr = sp->ioaddr;
890 ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA | IPG_AC_NETWORK |
893 spin_lock_irq(&sp->lock);
895 /* Re-configure after DMA reset. */
896 if (ipg_io_config(dev) < 0) {
897 printk(KERN_INFO "%s: Error during re-configuration.\n",
903 spin_unlock_irq(&sp->lock);
905 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) & IPG_MC_RSVD_MASK,
910 * For TxComplete interrupts, free all transmit
911 * buffers which have already been transfered via DMA
914 static void ipg_nic_txcleanup(struct net_device *dev)
916 struct ipg_nic_private *sp = netdev_priv(dev);
917 void __iomem *ioaddr = sp->ioaddr;
920 IPG_DEBUG_MSG("_nic_txcleanup\n");
922 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
923 /* Reading the TXSTATUS register clears the
924 * TX_COMPLETE interrupt.
926 u32 txstatusdword = ipg_r32(TX_STATUS);
928 IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword);
930 /* Check for Transmit errors. Error bits only valid if
931 * TX_COMPLETE bit in the TXSTATUS register is a 1.
933 if (!(txstatusdword & IPG_TS_TX_COMPLETE))
936 /* If in 10Mbps mode, indicate transmit is ready. */
937 if (sp->tenmbpsmode) {
938 netif_wake_queue(dev);
941 /* Transmit error, increment stat counters. */
942 if (txstatusdword & IPG_TS_TX_ERROR) {
943 IPG_DEBUG_MSG("Transmit error.\n");
944 sp->stats.tx_errors++;
947 /* Late collision, re-enable transmitter. */
948 if (txstatusdword & IPG_TS_LATE_COLLISION) {
949 IPG_DEBUG_MSG("Late collision on transmit.\n");
950 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
951 IPG_MC_RSVD_MASK, MAC_CTRL);
954 /* Maximum collisions, re-enable transmitter. */
955 if (txstatusdword & IPG_TS_TX_MAX_COLL) {
956 IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
957 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
958 IPG_MC_RSVD_MASK, MAC_CTRL);
961 /* Transmit underrun, reset and re-enable
964 if (txstatusdword & IPG_TS_TX_UNDERRUN) {
965 IPG_DEBUG_MSG("Transmitter underrun.\n");
966 sp->stats.tx_fifo_errors++;
967 ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA |
968 IPG_AC_NETWORK | IPG_AC_FIFO);
970 /* Re-configure after DMA reset. */
971 if (ipg_io_config(dev) < 0) {
973 "%s: Error during re-configuration.\n",
978 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
979 IPG_MC_RSVD_MASK, MAC_CTRL);
986 /* Provides statistical information about the IPG NIC. */
987 struct net_device_stats *ipg_nic_get_stats(struct net_device *dev)
989 struct ipg_nic_private *sp = netdev_priv(dev);
990 void __iomem *ioaddr = sp->ioaddr;
994 IPG_DEBUG_MSG("_nic_get_stats\n");
996 /* Check to see if the NIC has been initialized via nic_open,
997 * before trying to read statistic registers.
999 if (!test_bit(__LINK_STATE_START, &dev->state))
1002 sp->stats.rx_packets += ipg_r32(IPG_FRAMESRCVDOK);
1003 sp->stats.tx_packets += ipg_r32(IPG_FRAMESXMTDOK);
1004 sp->stats.rx_bytes += ipg_r32(IPG_OCTETRCVOK);
1005 sp->stats.tx_bytes += ipg_r32(IPG_OCTETXMTOK);
1006 temp1 = ipg_r16(IPG_FRAMESLOSTRXERRORS);
1007 sp->stats.rx_errors += temp1;
1008 sp->stats.rx_missed_errors += temp1;
1009 temp1 = ipg_r32(IPG_SINGLECOLFRAMES) + ipg_r32(IPG_MULTICOLFRAMES) +
1010 ipg_r32(IPG_LATECOLLISIONS);
1011 temp2 = ipg_r16(IPG_CARRIERSENSEERRORS);
1012 sp->stats.collisions += temp1;
1013 sp->stats.tx_dropped += ipg_r16(IPG_FRAMESABORTXSCOLLS);
1014 sp->stats.tx_errors += ipg_r16(IPG_FRAMESWEXDEFERRAL) +
1015 ipg_r32(IPG_FRAMESWDEFERREDXMT) + temp1 + temp2;
1016 sp->stats.multicast += ipg_r32(IPG_MCSTOCTETRCVDOK);
1018 /* detailed tx_errors */
1019 sp->stats.tx_carrier_errors += temp2;
1021 /* detailed rx_errors */
1022 sp->stats.rx_length_errors += ipg_r16(IPG_INRANGELENGTHERRORS) +
1023 ipg_r16(IPG_FRAMETOOLONGERRRORS);
1024 sp->stats.rx_crc_errors += ipg_r16(IPG_FRAMECHECKSEQERRORS);
1026 /* Unutilized IPG statistic registers. */
1027 ipg_r32(IPG_MCSTFRAMESRCVDOK);
1032 /* Restore used receive buffers. */
1033 static int ipg_nic_rxrestore(struct net_device *dev)
1035 struct ipg_nic_private *sp = netdev_priv(dev);
1036 const unsigned int curr = sp->rx_current;
1037 unsigned int dirty = sp->rx_dirty;
1039 IPG_DEBUG_MSG("_nic_rxrestore\n");
1041 for (dirty = sp->rx_dirty; curr - dirty > 0; dirty++) {
1042 unsigned int entry = dirty % IPG_RFDLIST_LENGTH;
1044 /* rx_copybreak may poke hole here and there. */
1045 if (sp->RxBuff[entry])
1048 /* Generate a new receive buffer to replace the
1049 * current buffer (which will be released by the
1052 if (ipg_get_rxbuff(dev, entry) < 0) {
1053 IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
1058 /* Reset the RFS field. */
1059 sp->rxd[entry].rfs = 0x0000000000000000;
1061 sp->rx_dirty = dirty;
1068 /* use jumboindex and jumbosize to control jumbo frame status
1069 initial status is jumboindex=-1 and jumbosize=0
1070 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
1071 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
1072 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
1073 previous receiving and need to continue dumping the current one
1081 Frame_NoStart_NoEnd = 0,
1082 Frame_WithStart = 1,
1084 Frame_WithStart_WithEnd = 11
1087 inline void ipg_nic_rx_free_skb(struct net_device *dev)
1089 struct ipg_nic_private *sp = netdev_priv(dev);
1090 unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
1092 if (sp->RxBuff[entry]) {
1093 struct ipg_rx *rxfd = sp->rxd + entry;
1095 pci_unmap_single(sp->pdev,
1096 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1097 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1098 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1099 sp->RxBuff[entry] = NULL;
1103 inline int ipg_nic_rx_check_frame_type(struct net_device *dev)
1105 struct ipg_nic_private *sp = netdev_priv(dev);
1106 struct ipg_rx *rxfd = sp->rxd + (sp->rx_current % IPG_RFDLIST_LENGTH);
1107 int type = Frame_NoStart_NoEnd;
1109 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART)
1110 type += Frame_WithStart;
1111 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND)
1112 type += Frame_WithEnd;
1116 inline int ipg_nic_rx_check_error(struct net_device *dev)
1118 struct ipg_nic_private *sp = netdev_priv(dev);
1119 unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
1120 struct ipg_rx *rxfd = sp->rxd + entry;
1122 if (IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
1123 (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
1124 IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
1125 IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))) {
1126 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1127 (unsigned long) rxfd->rfs);
1129 /* Increment general receive error statistic. */
1130 sp->stats.rx_errors++;
1132 /* Increment detailed receive error statistics. */
1133 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
1134 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1136 sp->stats.rx_fifo_errors++;
1139 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
1140 IPG_DEBUG_MSG("RX runt occured.\n");
1141 sp->stats.rx_length_errors++;
1144 /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
1145 * error count handled by a IPG statistic register.
1148 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
1149 IPG_DEBUG_MSG("RX alignment error occured.\n");
1150 sp->stats.rx_frame_errors++;
1153 /* Do nothing for IPG_RFS_RXFCSERROR, error count
1154 * handled by a IPG statistic register.
1157 /* Free the memory associated with the RX
1158 * buffer since it is erroneous and we will
1159 * not pass it to higher layer processes.
1161 if (sp->RxBuff[entry]) {
1162 pci_unmap_single(sp->pdev,
1163 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1164 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1166 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1167 sp->RxBuff[entry] = NULL;
1171 return NormalPacket;
1174 static void ipg_nic_rx_with_start_and_end(struct net_device *dev,
1175 struct ipg_nic_private *sp,
1176 struct ipg_rx *rxfd, unsigned entry)
1178 struct SJumbo *jumbo = &sp->Jumbo;
1179 struct sk_buff *skb;
1182 if (jumbo->FoundStart) {
1183 IPG_DEV_KFREE_SKB(jumbo->skb);
1184 jumbo->FoundStart = 0;
1185 jumbo->CurrentSize = 0;
1189 // 1: found error, 0 no error
1190 if (ipg_nic_rx_check_error(dev) != NormalPacket)
1193 skb = sp->RxBuff[entry];
1197 // accept this frame and send to upper layer
1198 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1199 if (framelen > IPG_RXFRAG_SIZE)
1200 framelen = IPG_RXFRAG_SIZE;
1202 skb_put(skb, framelen);
1203 skb->protocol = eth_type_trans(skb, dev);
1204 skb->ip_summed = CHECKSUM_NONE;
1206 dev->last_rx = jiffies;
1207 sp->RxBuff[entry] = NULL;
1210 static void ipg_nic_rx_with_start(struct net_device *dev,
1211 struct ipg_nic_private *sp,
1212 struct ipg_rx *rxfd, unsigned entry)
1214 struct SJumbo *jumbo = &sp->Jumbo;
1215 struct pci_dev *pdev = sp->pdev;
1216 struct sk_buff *skb;
1218 // 1: found error, 0 no error
1219 if (ipg_nic_rx_check_error(dev) != NormalPacket)
1222 // accept this frame and send to upper layer
1223 skb = sp->RxBuff[entry];
1227 if (jumbo->FoundStart)
1228 IPG_DEV_KFREE_SKB(jumbo->skb);
1230 pci_unmap_single(pdev, le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1231 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1233 skb_put(skb, IPG_RXFRAG_SIZE);
1235 jumbo->FoundStart = 1;
1236 jumbo->CurrentSize = IPG_RXFRAG_SIZE;
1239 sp->RxBuff[entry] = NULL;
1240 dev->last_rx = jiffies;
1243 static void ipg_nic_rx_with_end(struct net_device *dev,
1244 struct ipg_nic_private *sp,
1245 struct ipg_rx *rxfd, unsigned entry)
1247 struct SJumbo *jumbo = &sp->Jumbo;
1249 //1: found error, 0 no error
1250 if (ipg_nic_rx_check_error(dev) == NormalPacket) {
1251 struct sk_buff *skb = sp->RxBuff[entry];
1256 if (jumbo->FoundStart) {
1257 int framelen, endframelen;
1259 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1261 endframeLen = framelen - jumbo->CurrentSize;
1263 if (framelen > IPG_RXFRAG_SIZE)
1264 framelen=IPG_RXFRAG_SIZE;
1266 if (framelen > IPG_RXSUPPORT_SIZE)
1267 IPG_DEV_KFREE_SKB(jumbo->skb);
1269 memcpy(skb_put(jumbo->skb, endframeLen),
1270 skb->data, endframeLen);
1272 jumbo->skb->protocol =
1273 eth_type_trans(jumbo->skb, dev);
1275 jumbo->skb->ip_summed = CHECKSUM_NONE;
1276 netif_rx(jumbo->skb);
1280 dev->last_rx = jiffies;
1281 jumbo->FoundStart = 0;
1282 jumbo->CurrentSize = 0;
1285 ipg_nic_rx_free_skb(dev);
1287 IPG_DEV_KFREE_SKB(jumbo->skb);
1288 jumbo->FoundStart = 0;
1289 jumbo->CurrentSize = 0;
1294 static void ipg_nic_rx_no_start_no_end(struct net_device *dev,
1295 struct ipg_nic_private *sp,
1296 struct ipg_rx *rxfd, unsigned entry)
1298 struct SJumbo *jumbo = &sp->Jumbo;
1300 //1: found error, 0 no error
1301 if (ipg_nic_rx_check_error(dev) == NormalPacket) {
1302 struct sk_buff *skb = sp->RxBuff[entry];
1305 if (jumbo->FoundStart) {
1306 jumbo->CurrentSize += IPG_RXFRAG_SIZE;
1307 if (jumbo->CurrentSize <= IPG_RXSUPPORT_SIZE) {
1308 memcpy(skb_put(jumbo->skb,
1310 skb->data, IPG_RXFRAG_SIZE);
1313 dev->last_rx = jiffies;
1314 ipg_nic_rx_free_skb(dev);
1317 IPG_DEV_KFREE_SKB(jumbo->skb);
1318 jumbo->FoundStart = 0;
1319 jumbo->CurrentSize = 0;
1324 static int ipg_nic_rx(struct net_device *dev)
1326 struct ipg_nic_private *sp = netdev_priv(dev);
1327 unsigned int curr = sp->rx_current;
1328 void __iomem *ioaddr = sp->ioaddr;
1331 IPG_DEBUG_MSG("_nic_rx\n");
1333 for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
1334 unsigned int entry = curr % IPG_RFDLIST_LENGTH;
1335 struct ipg_rx *rxfd = sp->rxd + entry;
1337 if (!(rxfd->rfs & le64_to_cpu(IPG_RFS_RFDDONE)))
1340 switch (ipg_nic_rx_check_frame_type(dev)) {
1341 case Frame_WithStart_WithEnd:
1342 ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry);
1344 case Frame_WithStart:
1345 ipg_nic_rx_with_start(dev, tp, rxfd, entry);
1348 ipg_nic_rx_with_end(dev, tp, rxfd, entry);
1350 case Frame_NoStart_NoEnd:
1351 ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry);
1356 sp->rx_current = curr;
1358 if (i == IPG_MAXRFDPROCESS_COUNT) {
1359 /* There are more RFDs to process, however the
1360 * allocated amount of RFD processing time has
1361 * expired. Assert Interrupt Requested to make
1362 * sure we come back to process the remaining RFDs.
1364 ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
1367 ipg_nic_rxrestore(dev);
1373 static int ipg_nic_rx(struct net_device *dev)
1375 /* Transfer received Ethernet frames to higher network layers. */
1376 struct ipg_nic_private *sp = netdev_priv(dev);
1377 unsigned int curr = sp->rx_current;
1378 void __iomem *ioaddr = sp->ioaddr;
1379 struct ipg_rx *rxfd;
1382 IPG_DEBUG_MSG("_nic_rx\n");
1384 #define __RFS_MASK \
1385 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1387 for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
1388 unsigned int entry = curr % IPG_RFDLIST_LENGTH;
1389 struct sk_buff *skb = sp->RxBuff[entry];
1390 unsigned int framelen;
1392 rxfd = sp->rxd + entry;
1394 if (((rxfd->rfs & __RFS_MASK) != __RFS_MASK) || !skb)
1397 /* Get received frame length. */
1398 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1400 /* Check for jumbo frame arrival with too small
1403 if (framelen > IPG_RXFRAG_SIZE) {
1405 ("RFS FrameLen > allocated fragment size.\n");
1407 framelen = IPG_RXFRAG_SIZE;
1410 if ((IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs &
1411 (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
1412 IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
1413 IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))))) {
1415 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1416 (unsigned long int) rxfd->rfs);
1418 /* Increment general receive error statistic. */
1419 sp->stats.rx_errors++;
1421 /* Increment detailed receive error statistics. */
1422 if (le64_to_cpu(rxfd->rfs & IPG_RFS_RXFIFOOVERRUN)) {
1423 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1424 sp->stats.rx_fifo_errors++;
1427 if (le64_to_cpu(rxfd->rfs & IPG_RFS_RXRUNTFRAME)) {
1428 IPG_DEBUG_MSG("RX runt occured.\n");
1429 sp->stats.rx_length_errors++;
1432 if (le64_to_cpu(rxfd->rfs & IPG_RFS_RXOVERSIZEDFRAME)) ;
1433 /* Do nothing, error count handled by a IPG
1434 * statistic register.
1437 if (le64_to_cpu(rxfd->rfs & IPG_RFS_RXALIGNMENTERROR)) {
1438 IPG_DEBUG_MSG("RX alignment error occured.\n");
1439 sp->stats.rx_frame_errors++;
1442 if (le64_to_cpu(rxfd->rfs & IPG_RFS_RXFCSERROR)) ;
1443 /* Do nothing, error count handled by a IPG
1444 * statistic register.
1447 /* Free the memory associated with the RX
1448 * buffer since it is erroneous and we will
1449 * not pass it to higher layer processes.
1452 u64 info = rxfd->frag_info;
1454 pci_unmap_single(sp->pdev,
1455 le64_to_cpu(info & ~IPG_RFI_FRAGLEN),
1456 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1458 IPG_DEV_KFREE_SKB(skb);
1462 /* Adjust the new buffer length to accomodate the size
1463 * of the received frame.
1465 skb_put(skb, framelen);
1467 /* Set the buffer's protocol field to Ethernet. */
1468 skb->protocol = eth_type_trans(skb, dev);
1470 /* If the frame contains an IP/TCP/UDP frame,
1471 * determine if upper layer must check IP/TCP/UDP
1474 * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
1475 * VERIFICATION FOR SILICON REVISIONS B3
1478 if ((le64_to_cpu(rxfd->rfs &
1479 (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
1480 IPG_RFS_IPDETECTED))) &&
1481 !(le64_to_cpu(rxfd->rfs &
1482 (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
1483 IPG_RFS_IPERROR)))) {
1484 * Indicate IP checksums were performed
1487 skb->ip_summed = CHECKSUM_UNNECESSARY;
1491 /* The IPG encountered an error with (or
1492 * there were no) IP/TCP/UDP checksums.
1493 * This may or may not indicate an invalid
1494 * IP/TCP/UDP frame was received. Let the
1495 * upper layer decide.
1497 skb->ip_summed = CHECKSUM_NONE;
1500 /* Hand off frame for higher layer processing.
1501 * The function netif_rx() releases the sk_buff
1502 * when processing completes.
1506 /* Record frame receive time (jiffies = Linux
1507 * kernel current time stamp).
1509 dev->last_rx = jiffies;
1512 /* Assure RX buffer is not reused by IPG. */
1513 sp->RxBuff[entry] = NULL;
1517 * If there are more RFDs to proces and the allocated amount of RFD
1518 * processing time has expired, assert Interrupt Requested to make
1519 * sure we come back to process the remaining RFDs.
1521 if (i == IPG_MAXRFDPROCESS_COUNT)
1522 ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
1525 /* Check if the RFD list contained no receive frame data. */
1527 sp->EmptyRFDListCount++;
1529 while ((le64_to_cpu(rxfd->rfs & IPG_RFS_RFDDONE)) &&
1530 !((le64_to_cpu(rxfd->rfs & IPG_RFS_FRAMESTART)) &&
1531 (le64_to_cpu(rxfd->rfs & IPG_RFS_FRAMEEND)))) {
1532 unsigned int entry = curr++ % IPG_RFDLIST_LENGTH;
1534 rxfd = sp->rxd + entry;
1536 IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
1538 /* An unexpected event, additional code needed to handle
1539 * properly. So for the time being, just disregard the
1543 /* Free the memory associated with the RX
1544 * buffer since it is erroneous and we will
1545 * not pass it to higher layer processes.
1547 if (sp->RxBuff[entry]) {
1548 pci_unmap_single(sp->pdev,
1549 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1550 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1551 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1554 /* Assure RX buffer is not reused by IPG. */
1555 sp->RxBuff[entry] = NULL;
1558 sp->rx_current = curr;
1560 /* Check to see if there are a minimum number of used
1561 * RFDs before restoring any (should improve performance.)
1563 if ((curr - sp->rx_dirty) >= IPG_MINUSEDRFDSTOFREE)
1564 ipg_nic_rxrestore(dev);
1570 static void ipg_reset_after_host_error(struct work_struct *work)
1572 struct ipg_nic_private *sp =
1573 container_of(work, struct ipg_nic_private, task.work);
1574 struct net_device *dev = sp->dev;
1576 IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp->ioaddr + IPG_DMACTRL));
1579 * Acknowledge HostError interrupt by resetting
1582 ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
1587 if (ipg_io_config(dev) < 0) {
1588 printk(KERN_INFO "%s: Cannot recover from PCI error.\n",
1590 schedule_delayed_work(&sp->task, HZ);
1594 static irqreturn_t ipg_interrupt_handler(int irq, void *dev_inst)
1596 struct net_device *dev = dev_inst;
1597 struct ipg_nic_private *sp = netdev_priv(dev);
1598 void __iomem *ioaddr = sp->ioaddr;
1599 unsigned int handled = 0;
1602 IPG_DEBUG_MSG("_interrupt_handler\n");
1605 ipg_nic_rxrestore(dev);
1607 /* Get interrupt source information, and acknowledge
1608 * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
1609 * IntRequested, MacControlFrame, LinkEvent) interrupts
1610 * if issued. Also, all IPG interrupts are disabled by
1611 * reading IntStatusAck.
1613 status = ipg_r16(INT_STATUS_ACK);
1615 IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status);
1617 /* Shared IRQ of remove event. */
1618 if (!(status & IPG_IS_RSVD_MASK))
1623 if (unlikely(!netif_running(dev)))
1626 spin_lock(&sp->lock);
1628 /* If RFDListEnd interrupt, restore all used RFDs. */
1629 if (status & IPG_IS_RFD_LIST_END) {
1630 IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
1632 /* The RFD list end indicates an RFD was encountered
1633 * with a 0 NextPtr, or with an RFDDone bit set to 1
1634 * (indicating the RFD is not read for use by the
1635 * IPG.) Try to restore all RFDs.
1637 ipg_nic_rxrestore(dev);
1640 /* Increment the RFDlistendCount counter. */
1641 sp->RFDlistendCount++;
1645 /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
1646 * IntRequested interrupt, process received frames. */
1647 if ((status & IPG_IS_RX_DMA_PRIORITY) ||
1648 (status & IPG_IS_RFD_LIST_END) ||
1649 (status & IPG_IS_RX_DMA_COMPLETE) ||
1650 (status & IPG_IS_INT_REQUESTED)) {
1652 /* Increment the RFD list checked counter if interrupted
1653 * only to check the RFD list. */
1654 if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
1655 IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
1656 (IPG_IS_HOST_ERROR | IPG_IS_TX_DMA_COMPLETE |
1657 IPG_IS_LINK_EVENT | IPG_IS_TX_COMPLETE |
1658 IPG_IS_UPDATE_STATS)))
1659 sp->RFDListCheckedCount++;
1665 /* If TxDMAComplete interrupt, free used TFDs. */
1666 if (status & IPG_IS_TX_DMA_COMPLETE)
1667 ipg_nic_txfree(dev);
1669 /* TxComplete interrupts indicate one of numerous actions.
1670 * Determine what action to take based on TXSTATUS register.
1672 if (status & IPG_IS_TX_COMPLETE)
1673 ipg_nic_txcleanup(dev);
1675 /* If UpdateStats interrupt, update Linux Ethernet statistics */
1676 if (status & IPG_IS_UPDATE_STATS)
1677 ipg_nic_get_stats(dev);
1679 /* If HostError interrupt, reset IPG. */
1680 if (status & IPG_IS_HOST_ERROR) {
1681 IPG_DDEBUG_MSG("HostError Interrupt\n");
1683 schedule_delayed_work(&sp->task, 0);
1686 /* If LinkEvent interrupt, resolve autonegotiation. */
1687 if (status & IPG_IS_LINK_EVENT) {
1688 if (ipg_config_autoneg(dev) < 0)
1689 printk(KERN_INFO "%s: Auto-negotiation error.\n",
1693 /* If MACCtrlFrame interrupt, do nothing. */
1694 if (status & IPG_IS_MAC_CTRL_FRAME)
1695 IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
1697 /* If RxComplete interrupt, do nothing. */
1698 if (status & IPG_IS_RX_COMPLETE)
1699 IPG_DEBUG_MSG("RxComplete interrupt.\n");
1701 /* If RxEarly interrupt, do nothing. */
1702 if (status & IPG_IS_RX_EARLY)
1703 IPG_DEBUG_MSG("RxEarly interrupt.\n");
1706 /* Re-enable IPG interrupts. */
1707 ipg_w16(IPG_IE_TX_DMA_COMPLETE | IPG_IE_RX_DMA_COMPLETE |
1708 IPG_IE_HOST_ERROR | IPG_IE_INT_REQUESTED | IPG_IE_TX_COMPLETE |
1709 IPG_IE_LINK_EVENT | IPG_IE_UPDATE_STATS, INT_ENABLE);
1711 spin_unlock(&sp->lock);
1713 return IRQ_RETVAL(handled);
1716 static void ipg_rx_clear(struct ipg_nic_private *sp)
1720 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
1721 if (sp->RxBuff[i]) {
1722 struct ipg_rx *rxfd = sp->rxd + i;
1724 IPG_DEV_KFREE_SKB(sp->RxBuff[i]);
1725 sp->RxBuff[i] = NULL;
1726 pci_unmap_single(sp->pdev,
1727 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1728 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1733 static void ipg_tx_clear(struct ipg_nic_private *sp)
1737 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
1738 if (sp->TxBuff[i]) {
1739 struct ipg_tx *txfd = sp->txd + i;
1741 pci_unmap_single(sp->pdev,
1742 le64_to_cpu(txfd->frag_info & ~IPG_TFI_FRAGLEN),
1743 sp->TxBuff[i]->len, PCI_DMA_TODEVICE);
1745 IPG_DEV_KFREE_SKB(sp->TxBuff[i]);
1747 sp->TxBuff[i] = NULL;
1752 static int ipg_nic_open(struct net_device *dev)
1754 struct ipg_nic_private *sp = netdev_priv(dev);
1755 void __iomem *ioaddr = sp->ioaddr;
1756 struct pci_dev *pdev = sp->pdev;
1759 IPG_DEBUG_MSG("_nic_open\n");
1761 sp->rx_buf_sz = IPG_RXSUPPORT_SIZE;
1763 /* Check for interrupt line conflicts, and request interrupt
1766 * IMPORTANT: Disable IPG interrupts prior to registering
1769 ipg_w16(0x0000, INT_ENABLE);
1771 /* Register the interrupt line to be used by the IPG within
1774 rc = request_irq(pdev->irq, &ipg_interrupt_handler, IRQF_SHARED,
1777 printk(KERN_INFO "%s: Error when requesting interrupt.\n",
1782 dev->irq = pdev->irq;
1786 sp->rxd = dma_alloc_coherent(&pdev->dev, IPG_RX_RING_BYTES,
1787 &sp->rxd_map, GFP_KERNEL);
1789 goto err_free_irq_0;
1791 sp->txd = dma_alloc_coherent(&pdev->dev, IPG_TX_RING_BYTES,
1792 &sp->txd_map, GFP_KERNEL);
1796 rc = init_rfdlist(dev);
1798 printk(KERN_INFO "%s: Error during configuration.\n",
1805 rc = ipg_io_config(dev);
1807 printk(KERN_INFO "%s: Error during configuration.\n",
1809 goto err_release_tfdlist_3;
1812 /* Resolve autonegotiation. */
1813 if (ipg_config_autoneg(dev) < 0)
1814 printk(KERN_INFO "%s: Auto-negotiation error.\n", dev->name);
1817 /* initialize JUMBO Frame control variable */
1818 sp->Jumbo.FoundStart = 0;
1819 sp->Jumbo.CurrentSize = 0;
1821 dev->mtu = IPG_TXFRAG_SIZE;
1824 /* Enable transmit and receive operation of the IPG. */
1825 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_RX_ENABLE | IPG_MC_TX_ENABLE) &
1826 IPG_MC_RSVD_MASK, MAC_CTRL);
1828 netif_start_queue(dev);
1832 err_release_tfdlist_3:
1836 dma_free_coherent(&pdev->dev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
1838 dma_free_coherent(&pdev->dev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
1840 free_irq(pdev->irq, dev);
1844 static int ipg_nic_stop(struct net_device *dev)
1846 struct ipg_nic_private *sp = netdev_priv(dev);
1847 void __iomem *ioaddr = sp->ioaddr;
1848 struct pci_dev *pdev = sp->pdev;
1850 IPG_DEBUG_MSG("_nic_stop\n");
1852 netif_stop_queue(dev);
1854 IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp->RFDlistendCount);
1855 IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp->rxdCheckedCount);
1856 IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp->EmptyRFDListCount);
1857 IPG_DUMPTFDLIST(dev);
1860 (void) ipg_r16(INT_STATUS_ACK);
1862 ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
1864 synchronize_irq(pdev->irq);
1865 } while (ipg_r16(INT_ENABLE) & IPG_IE_RSVD_MASK);
1871 pci_free_consistent(pdev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
1872 pci_free_consistent(pdev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
1874 free_irq(pdev->irq, dev);
1879 static int ipg_nic_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1881 struct ipg_nic_private *sp = netdev_priv(dev);
1882 void __iomem *ioaddr = sp->ioaddr;
1883 unsigned int entry = sp->tx_current % IPG_TFDLIST_LENGTH;
1884 unsigned long flags;
1885 struct ipg_tx *txfd;
1887 IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
1889 /* If in 10Mbps mode, stop the transmit queue so
1890 * no more transmit frames are accepted.
1892 if (sp->tenmbpsmode)
1893 netif_stop_queue(dev);
1895 if (sp->ResetCurrentTFD) {
1896 sp->ResetCurrentTFD = 0;
1900 txfd = sp->txd + entry;
1902 sp->TxBuff[entry] = skb;
1904 /* Clear all TFC fields, except TFDDONE. */
1905 txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
1907 /* Specify the TFC field within the TFD. */
1908 txfd->tfc |= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED |
1909 (IPG_TFC_FRAMEID & cpu_to_le64(sp->tx_current)) |
1910 (IPG_TFC_FRAGCOUNT & (1 << 24)));
1912 /* Request TxComplete interrupts at an interval defined
1913 * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
1914 * Request TxComplete interrupt for every frame
1915 * if in 10Mbps mode to accomodate problem with 10Mbps
1918 if (sp->tenmbpsmode)
1919 txfd->tfc |= cpu_to_le64(IPG_TFC_TXINDICATE);
1920 else if (!((sp->tx_current - sp->tx_dirty + 1) >
1921 IPG_FRAMESBETWEENTXDMACOMPLETES)) {
1922 txfd->tfc |= cpu_to_le64(IPG_TFC_TXDMAINDICATE);
1924 /* Based on compilation option, determine if FCS is to be
1925 * appended to transmit frame by IPG.
1927 if (!(IPG_APPEND_FCS_ON_TX))
1928 txfd->tfc |= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE);
1930 /* Based on compilation option, determine if IP, TCP and/or
1931 * UDP checksums are to be added to transmit frame by IPG.
1933 if (IPG_ADD_IPCHECKSUM_ON_TX)
1934 txfd->tfc |= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE);
1936 if (IPG_ADD_TCPCHECKSUM_ON_TX)
1937 txfd->tfc |= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE);
1939 if (IPG_ADD_UDPCHECKSUM_ON_TX)
1940 txfd->tfc |= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE);
1942 /* Based on compilation option, determine if VLAN tag info is to be
1943 * inserted into transmit frame by IPG.
1945 if (IPG_INSERT_MANUAL_VLAN_TAG) {
1946 txfd->tfc |= cpu_to_le64(IPG_TFC_VLANTAGINSERT |
1947 ((u64) IPG_MANUAL_VLAN_VID << 32) |
1948 ((u64) IPG_MANUAL_VLAN_CFI << 44) |
1949 ((u64) IPG_MANUAL_VLAN_USERPRIORITY << 45));
1952 /* The fragment start location within system memory is defined
1953 * by the sk_buff structure's data field. The physical address
1954 * of this location within the system's virtual memory space
1955 * is determined using the IPG_HOST2BUS_MAP function.
1957 txfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
1958 skb->len, PCI_DMA_TODEVICE));
1960 /* The length of the fragment within system memory is defined by
1961 * the sk_buff structure's len field.
1963 txfd->frag_info |= cpu_to_le64(IPG_TFI_FRAGLEN &
1964 ((u64) (skb->len & 0xffff) << 48));
1966 /* Clear the TFDDone bit last to indicate the TFD is ready
1967 * for transfer to the IPG.
1969 txfd->tfc &= cpu_to_le64(~IPG_TFC_TFDDONE);
1971 spin_lock_irqsave(&sp->lock, flags);
1977 ipg_w32(IPG_DC_TX_DMA_POLL_NOW, DMA_CTRL);
1979 if (sp->tx_current == (sp->tx_dirty + IPG_TFDLIST_LENGTH))
1980 netif_wake_queue(dev);
1982 spin_unlock_irqrestore(&sp->lock, flags);
1984 return NETDEV_TX_OK;
1987 static void ipg_set_phy_default_param(unsigned char rev,
1988 struct net_device *dev, int phy_address)
1990 unsigned short length;
1991 unsigned char revision;
1992 unsigned short *phy_param;
1993 unsigned short address, value;
1995 phy_param = &DefaultPhyParam[0];
1996 length = *phy_param & 0x00FF;
1997 revision = (unsigned char)((*phy_param) >> 8);
1999 while (length != 0) {
2000 if (rev == revision) {
2001 while (length > 1) {
2002 address = *phy_param;
2003 value = *(phy_param + 1);
2005 mdio_write(dev, phy_address, address, value);
2010 phy_param += length / 2;
2011 length = *phy_param & 0x00FF;
2012 revision = (unsigned char)((*phy_param) >> 8);
2018 /* JES20040127EEPROM */
2019 static int read_eeprom(struct net_device *dev, int eep_addr)
2021 void __iomem *ioaddr = ipg_ioaddr(dev);
2026 value = IPG_EC_EEPROM_READOPCODE | (eep_addr & 0xff);
2027 ipg_w16(value, EEPROM_CTRL);
2029 for (i = 0; i < 1000; i++) {
2033 data = ipg_r16(EEPROM_CTRL);
2034 if (!(data & IPG_EC_EEPROM_BUSY)) {
2035 ret = ipg_r16(EEPROM_DATA);
2042 static void ipg_init_mii(struct net_device *dev)
2044 struct ipg_nic_private *sp = netdev_priv(dev);
2045 struct mii_if_info *mii_if = &sp->mii_if;
2049 mii_if->mdio_read = mdio_read;
2050 mii_if->mdio_write = mdio_write;
2051 mii_if->phy_id_mask = 0x1f;
2052 mii_if->reg_num_mask = 0x1f;
2054 mii_if->phy_id = phyaddr = ipg_find_phyaddr(dev);
2056 if (phyaddr != 0x1f) {
2057 u16 mii_phyctrl, mii_1000cr;
2060 mii_1000cr = mdio_read(dev, phyaddr, MII_CTRL1000);
2061 mii_1000cr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF |
2062 GMII_PHY_1000BASETCONTROL_PreferMaster;
2063 mdio_write(dev, phyaddr, MII_CTRL1000, mii_1000cr);
2065 mii_phyctrl = mdio_read(dev, phyaddr, MII_BMCR);
2067 /* Set default phyparam */
2068 pci_read_config_byte(sp->pdev, PCI_REVISION_ID, &revisionid);
2069 ipg_set_phy_default_param(revisionid, dev, phyaddr);
2072 mii_phyctrl |= BMCR_RESET | BMCR_ANRESTART;
2073 mdio_write(dev, phyaddr, MII_BMCR, mii_phyctrl);
2078 static int ipg_hw_init(struct net_device *dev)
2080 struct ipg_nic_private *sp = netdev_priv(dev);
2081 void __iomem *ioaddr = sp->ioaddr;
2085 /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
2086 /* Read LED Mode Configuration from EEPROM */
2087 sp->LED_Mode = read_eeprom(dev, 6);
2089 /* Reset all functions within the IPG. Do not assert
2090 * RST_OUT as not compatible with some PHYs.
2092 rc = ipg_reset(dev, IPG_RESET_MASK);
2098 /* Read MAC Address from EEPROM */
2099 for (i = 0; i < 3; i++)
2100 sp->station_addr[i] = read_eeprom(dev, 16 + i);
2102 for (i = 0; i < 3; i++)
2103 ipg_w16(sp->station_addr[i], STATION_ADDRESS_0 + 2*i);
2105 /* Set station address in ethernet_device structure. */
2106 dev->dev_addr[0] = ipg_r16(STATION_ADDRESS_0) & 0x00ff;
2107 dev->dev_addr[1] = (ipg_r16(STATION_ADDRESS_0) & 0xff00) >> 8;
2108 dev->dev_addr[2] = ipg_r16(STATION_ADDRESS_1) & 0x00ff;
2109 dev->dev_addr[3] = (ipg_r16(STATION_ADDRESS_1) & 0xff00) >> 8;
2110 dev->dev_addr[4] = ipg_r16(STATION_ADDRESS_2) & 0x00ff;
2111 dev->dev_addr[5] = (ipg_r16(STATION_ADDRESS_2) & 0xff00) >> 8;
2116 static int ipg_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2118 struct ipg_nic_private *sp = netdev_priv(dev);
2121 mutex_lock(&sp->mii_mutex);
2122 rc = generic_mii_ioctl(&sp->mii_if, if_mii(ifr), cmd, NULL);
2123 mutex_unlock(&sp->mii_mutex);
2128 static int ipg_nic_change_mtu(struct net_device *dev, int new_mtu)
2130 /* Function to accomodate changes to Maximum Transfer Unit
2131 * (or MTU) of IPG NIC. Cannot use default function since
2132 * the default will not allow for MTU > 1500 bytes.
2135 IPG_DEBUG_MSG("_nic_change_mtu\n");
2137 /* Check that the new MTU value is between 68 (14 byte header, 46
2138 * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
2139 * corresponds to the MAXFRAMESIZE register in the IPG.
2141 if ((new_mtu < 68) || (new_mtu > IPG_MAX_RXFRAME_SIZE))
2149 static int ipg_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2151 struct ipg_nic_private *sp = netdev_priv(dev);
2154 mutex_lock(&sp->mii_mutex);
2155 rc = mii_ethtool_gset(&sp->mii_if, cmd);
2156 mutex_unlock(&sp->mii_mutex);
2161 static int ipg_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2163 struct ipg_nic_private *sp = netdev_priv(dev);
2166 mutex_lock(&sp->mii_mutex);
2167 rc = mii_ethtool_sset(&sp->mii_if, cmd);
2168 mutex_unlock(&sp->mii_mutex);
2173 static int ipg_nway_reset(struct net_device *dev)
2175 struct ipg_nic_private *sp = netdev_priv(dev);
2178 mutex_lock(&sp->mii_mutex);
2179 rc = mii_nway_restart(&sp->mii_if);
2180 mutex_unlock(&sp->mii_mutex);
2185 static struct ethtool_ops ipg_ethtool_ops = {
2186 .get_settings = ipg_get_settings,
2187 .set_settings = ipg_set_settings,
2188 .nway_reset = ipg_nway_reset,
2191 static void ipg_remove(struct pci_dev *pdev)
2193 struct net_device *dev = pci_get_drvdata(pdev);
2194 struct ipg_nic_private *sp = netdev_priv(dev);
2196 IPG_DEBUG_MSG("_remove\n");
2198 /* Un-register Ethernet device. */
2199 unregister_netdev(dev);
2201 pci_iounmap(pdev, sp->ioaddr);
2203 pci_release_regions(pdev);
2206 pci_disable_device(pdev);
2207 pci_set_drvdata(pdev, NULL);
2210 static int __devinit ipg_probe(struct pci_dev *pdev,
2211 const struct pci_device_id *id)
2213 unsigned int i = id->driver_data;
2214 struct ipg_nic_private *sp;
2215 struct net_device *dev;
2216 void __iomem *ioaddr;
2219 rc = pci_enable_device(pdev);
2223 printk(KERN_INFO "%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
2225 pci_set_master(pdev);
2227 rc = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
2229 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2231 printk(KERN_ERR "%s: DMA config failed.\n",
2238 * Initialize net device.
2240 dev = alloc_etherdev(sizeof(struct ipg_nic_private));
2242 printk(KERN_ERR "%s: alloc_etherdev failed\n", pci_name(pdev));
2247 sp = netdev_priv(dev);
2248 spin_lock_init(&sp->lock);
2249 mutex_init(&sp->mii_mutex);
2251 /* Declare IPG NIC functions for Ethernet device methods.
2253 dev->open = &ipg_nic_open;
2254 dev->stop = &ipg_nic_stop;
2255 dev->hard_start_xmit = &ipg_nic_hard_start_xmit;
2256 dev->get_stats = &ipg_nic_get_stats;
2257 dev->set_multicast_list = &ipg_nic_set_multicast_list;
2258 dev->do_ioctl = ipg_ioctl;
2259 dev->tx_timeout = ipg_tx_timeout;
2260 dev->change_mtu = &ipg_nic_change_mtu;
2262 SET_NETDEV_DEV(dev, &pdev->dev);
2263 SET_ETHTOOL_OPS(dev, &ipg_ethtool_ops);
2265 rc = pci_request_regions(pdev, DRV_NAME);
2267 goto err_free_dev_1;
2269 ioaddr = pci_iomap(pdev, 1, pci_resource_len(pdev, 1));
2271 printk(KERN_ERR "%s cannot map MMIO\n", pci_name(pdev));
2273 goto err_release_regions_2;
2276 /* Save the pointer to the PCI device information. */
2277 sp->ioaddr = ioaddr;
2281 INIT_DELAYED_WORK(&sp->task, ipg_reset_after_host_error);
2283 pci_set_drvdata(pdev, dev);
2285 rc = ipg_hw_init(dev);
2289 rc = register_netdev(dev);
2293 printk(KERN_INFO "Ethernet device registered as: %s\n", dev->name);
2298 pci_iounmap(pdev, ioaddr);
2299 err_release_regions_2:
2300 pci_release_regions(pdev);
2304 pci_disable_device(pdev);
2308 static struct pci_driver ipg_pci_driver = {
2309 .name = IPG_DRIVER_NAME,
2310 .id_table = ipg_pci_tbl,
2312 .remove = __devexit_p(ipg_remove),
2315 static int __init ipg_init_module(void)
2317 return pci_register_driver(&ipg_pci_driver);
2320 static void __exit ipg_exit_module(void)
2322 pci_unregister_driver(&ipg_pci_driver);
2325 module_init(ipg_init_module);
2326 module_exit(ipg_exit_module);