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 #include <asm/div64.h>
30 #define IPG_RX_RING_BYTES (sizeof(struct ipg_rx) * IPG_RFDLIST_LENGTH)
31 #define IPG_TX_RING_BYTES (sizeof(struct ipg_tx) * IPG_TFDLIST_LENGTH)
32 #define IPG_RESET_MASK \
33 (IPG_AC_GLOBAL_RESET | IPG_AC_RX_RESET | IPG_AC_TX_RESET | \
34 IPG_AC_DMA | IPG_AC_FIFO | IPG_AC_NETWORK | IPG_AC_HOST | \
37 #define ipg_w32(val32,reg) iowrite32((val32), ioaddr + (reg))
38 #define ipg_w16(val16,reg) iowrite16((val16), ioaddr + (reg))
39 #define ipg_w8(val8,reg) iowrite8((val8), ioaddr + (reg))
41 #define ipg_r32(reg) ioread32(ioaddr + (reg))
42 #define ipg_r16(reg) ioread16(ioaddr + (reg))
43 #define ipg_r8(reg) ioread8(ioaddr + (reg))
45 #define JUMBO_FRAME_4k_ONLY
51 #define DRV_NAME "ipg"
53 MODULE_AUTHOR("IC Plus Corp. 2003");
54 MODULE_DESCRIPTION("IC Plus IP1000 Gigabit Ethernet Adapter Linux Driver "
56 MODULE_LICENSE("GPL");
58 static const char *ipg_brand_name[] = {
59 "IC PLUS IP1000 1000/100/10 based NIC",
60 "Sundance Technology ST2021 based NIC",
61 "Tamarack Microelectronics TC9020/9021 based NIC",
62 "Tamarack Microelectronics TC9020/9021 based NIC",
67 static struct pci_device_id ipg_pci_tbl[] __devinitdata = {
68 { PCI_VDEVICE(SUNDANCE, 0x1023), 0 },
69 { PCI_VDEVICE(SUNDANCE, 0x2021), 1 },
70 { PCI_VDEVICE(SUNDANCE, 0x1021), 2 },
71 { PCI_VDEVICE(DLINK, 0x9021), 3 },
72 { PCI_VDEVICE(DLINK, 0x4000), 4 },
73 { PCI_VDEVICE(DLINK, 0x4020), 5 },
77 MODULE_DEVICE_TABLE(pci, ipg_pci_tbl);
79 static inline void __iomem *ipg_ioaddr(struct net_device *dev)
81 struct ipg_nic_private *sp = netdev_priv(dev);
86 static void ipg_dump_rfdlist(struct net_device *dev)
88 struct ipg_nic_private *sp = netdev_priv(dev);
89 void __iomem *ioaddr = sp->ioaddr;
93 IPG_DEBUG_MSG("_dump_rfdlist\n");
95 printk(KERN_INFO "rx_current = %2.2x\n", sp->rx_current);
96 printk(KERN_INFO "rx_dirty = %2.2x\n", sp->rx_dirty);
97 printk(KERN_INFO "RFDList start address = %16.16lx\n",
98 (unsigned long) sp->rxd_map);
99 printk(KERN_INFO "RFDListPtr register = %8.8x%8.8x\n",
100 ipg_r32(IPG_RFDLISTPTR1), ipg_r32(IPG_RFDLISTPTR0));
102 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
103 offset = (u32) &sp->rxd[i].next_desc - (u32) sp->rxd;
104 printk(KERN_INFO "%2.2x %4.4x RFDNextPtr = %16.16lx\n", i,
105 offset, (unsigned long) sp->rxd[i].next_desc);
106 offset = (u32) &sp->rxd[i].rfs - (u32) sp->rxd;
107 printk(KERN_INFO "%2.2x %4.4x RFS = %16.16lx\n", i,
108 offset, (unsigned long) sp->rxd[i].rfs);
109 offset = (u32) &sp->rxd[i].frag_info - (u32) sp->rxd;
110 printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
111 offset, (unsigned long) sp->rxd[i].frag_info);
115 static void ipg_dump_tfdlist(struct net_device *dev)
117 struct ipg_nic_private *sp = netdev_priv(dev);
118 void __iomem *ioaddr = sp->ioaddr;
122 IPG_DEBUG_MSG("_dump_tfdlist\n");
124 printk(KERN_INFO "tx_current = %2.2x\n", sp->tx_current);
125 printk(KERN_INFO "tx_dirty = %2.2x\n", sp->tx_dirty);
126 printk(KERN_INFO "TFDList start address = %16.16lx\n",
127 (unsigned long) sp->txd_map);
128 printk(KERN_INFO "TFDListPtr register = %8.8x%8.8x\n",
129 ipg_r32(IPG_TFDLISTPTR1), ipg_r32(IPG_TFDLISTPTR0));
131 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
132 offset = (u32) &sp->txd[i].next_desc - (u32) sp->txd;
133 printk(KERN_INFO "%2.2x %4.4x TFDNextPtr = %16.16lx\n", i,
134 offset, (unsigned long) sp->txd[i].next_desc);
136 offset = (u32) &sp->txd[i].tfc - (u32) sp->txd;
137 printk(KERN_INFO "%2.2x %4.4x TFC = %16.16lx\n", i,
138 offset, (unsigned long) sp->txd[i].tfc);
139 offset = (u32) &sp->txd[i].frag_info - (u32) sp->txd;
140 printk(KERN_INFO "%2.2x %4.4x frag_info = %16.16lx\n", i,
141 offset, (unsigned long) sp->txd[i].frag_info);
146 static void ipg_write_phy_ctl(void __iomem *ioaddr, u8 data)
148 ipg_w8(IPG_PC_RSVD_MASK & data, PHY_CTRL);
149 ndelay(IPG_PC_PHYCTRLWAIT_NS);
152 static void ipg_drive_phy_ctl_low_high(void __iomem *ioaddr, u8 data)
154 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | data);
155 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | data);
158 static void send_three_state(void __iomem *ioaddr, u8 phyctrlpolarity)
160 phyctrlpolarity |= (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR;
162 ipg_drive_phy_ctl_low_high(ioaddr, phyctrlpolarity);
165 static void send_end(void __iomem *ioaddr, u8 phyctrlpolarity)
167 ipg_w8((IPG_PC_MGMTCLK_LO | (IPG_PC_MGMTDATA & 0) | IPG_PC_MGMTDIR |
168 phyctrlpolarity) & IPG_PC_RSVD_MASK, PHY_CTRL);
171 static u16 read_phy_bit(void __iomem * ioaddr, u8 phyctrlpolarity)
175 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | phyctrlpolarity);
177 bit_data = ((ipg_r8(PHY_CTRL) & IPG_PC_MGMTDATA) >> 1) & 1;
179 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | phyctrlpolarity);
185 * Read a register from the Physical Layer device located
186 * on the IPG NIC, using the IPG PHYCTRL register.
188 static int mdio_read(struct net_device * dev, int phy_id, int phy_reg)
190 void __iomem *ioaddr = ipg_ioaddr(dev);
192 * The GMII mangement frame structure for a read is as follows:
194 * |Preamble|st|op|phyad|regad|ta| data |idle|
195 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
197 * <32 1s> = 32 consecutive logic 1 values
198 * A = bit of Physical Layer device address (MSB first)
199 * R = bit of register address (MSB first)
200 * z = High impedance state
201 * D = bit of read data (MSB first)
203 * Transmission order is 'Preamble' field first, bits transmitted
204 * left to right (first to last).
210 { GMII_PREAMBLE, 32 }, /* Preamble */
211 { GMII_ST, 2 }, /* ST */
212 { GMII_READ, 2 }, /* OP */
213 { phy_id, 5 }, /* PHYAD */
214 { phy_reg, 5 }, /* REGAD */
215 { 0x0000, 2 }, /* TA */
216 { 0x0000, 16 }, /* DATA */
217 { 0x0000, 1 } /* IDLE */
222 polarity = ipg_r8(PHY_CTRL);
223 polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
225 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
226 for (j = 0; j < 5; j++) {
227 for (i = 0; i < p[j].len; i++) {
228 /* For each variable length field, the MSB must be
229 * transmitted first. Rotate through the field bits,
230 * starting with the MSB, and move each bit into the
231 * the 1st (2^1) bit position (this is the bit position
232 * corresponding to the MgmtData bit of the PhyCtrl
233 * register for the IPG).
237 * First write a '0' to bit 1 of the PhyCtrl
238 * register, then write a '1' to bit 1 of the
241 * To do this, right shift the MSB of ST by the value:
242 * [field length - 1 - #ST bits already written]
243 * then left shift this result by 1.
245 data = (p[j].field >> (p[j].len - 1 - i)) << 1;
246 data &= IPG_PC_MGMTDATA;
247 data |= polarity | IPG_PC_MGMTDIR;
249 ipg_drive_phy_ctl_low_high(ioaddr, data);
253 send_three_state(ioaddr, polarity);
255 read_phy_bit(ioaddr, polarity);
258 * For a read cycle, the bits for the next two fields (TA and
259 * DATA) are driven by the PHY (the IPG reads these bits).
261 for (i = 0; i < p[6].len; i++) {
263 (read_phy_bit(ioaddr, polarity) << (p[6].len - 1 - i));
266 send_three_state(ioaddr, polarity);
267 send_three_state(ioaddr, polarity);
268 send_three_state(ioaddr, polarity);
269 send_end(ioaddr, polarity);
271 /* Return the value of the DATA field. */
276 * Write to a register from the Physical Layer device located
277 * on the IPG NIC, using the IPG PHYCTRL register.
279 static void mdio_write(struct net_device *dev, int phy_id, int phy_reg, int val)
281 void __iomem *ioaddr = ipg_ioaddr(dev);
283 * The GMII mangement frame structure for a read is as follows:
285 * |Preamble|st|op|phyad|regad|ta| data |idle|
286 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
288 * <32 1s> = 32 consecutive logic 1 values
289 * A = bit of Physical Layer device address (MSB first)
290 * R = bit of register address (MSB first)
291 * z = High impedance state
292 * D = bit of write data (MSB first)
294 * Transmission order is 'Preamble' field first, bits transmitted
295 * left to right (first to last).
301 { GMII_PREAMBLE, 32 }, /* Preamble */
302 { GMII_ST, 2 }, /* ST */
303 { GMII_WRITE, 2 }, /* OP */
304 { phy_id, 5 }, /* PHYAD */
305 { phy_reg, 5 }, /* REGAD */
306 { 0x0002, 2 }, /* TA */
307 { val & 0xffff, 16 }, /* DATA */
308 { 0x0000, 1 } /* IDLE */
313 polarity = ipg_r8(PHY_CTRL);
314 polarity &= (IPG_PC_DUPLEX_POLARITY | IPG_PC_LINK_POLARITY);
316 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
317 for (j = 0; j < 7; j++) {
318 for (i = 0; i < p[j].len; i++) {
319 /* For each variable length field, the MSB must be
320 * transmitted first. Rotate through the field bits,
321 * starting with the MSB, and move each bit into the
322 * the 1st (2^1) bit position (this is the bit position
323 * corresponding to the MgmtData bit of the PhyCtrl
324 * register for the IPG).
328 * First write a '0' to bit 1 of the PhyCtrl
329 * register, then write a '1' to bit 1 of the
332 * To do this, right shift the MSB of ST by the value:
333 * [field length - 1 - #ST bits already written]
334 * then left shift this result by 1.
336 data = (p[j].field >> (p[j].len - 1 - i)) << 1;
337 data &= IPG_PC_MGMTDATA;
338 data |= polarity | IPG_PC_MGMTDIR;
340 ipg_drive_phy_ctl_low_high(ioaddr, data);
344 /* The last cycle is a tri-state, so read from the PHY. */
345 for (j = 7; j < 8; j++) {
346 for (i = 0; i < p[j].len; i++) {
347 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
349 p[j].field |= ((ipg_r8(PHY_CTRL) &
350 IPG_PC_MGMTDATA) >> 1) << (p[j].len - 1 - i);
352 ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
357 /* Set LED_Mode JES20040127EEPROM */
358 static void ipg_set_led_mode(struct net_device *dev)
360 struct ipg_nic_private *sp = netdev_priv(dev);
361 void __iomem *ioaddr = sp->ioaddr;
364 mode = ipg_r32(ASIC_CTRL);
365 mode &= ~(IPG_AC_LED_MODE_BIT_1 | IPG_AC_LED_MODE | IPG_AC_LED_SPEED);
367 if ((sp->LED_Mode & 0x03) > 1)
368 mode |= IPG_AC_LED_MODE_BIT_1; /* Write Asic Control Bit 29 */
370 if ((sp->LED_Mode & 0x01) == 1)
371 mode |= IPG_AC_LED_MODE; /* Write Asic Control Bit 14 */
373 if ((sp->LED_Mode & 0x08) == 8)
374 mode |= IPG_AC_LED_SPEED; /* Write Asic Control Bit 27 */
376 ipg_w32(mode, ASIC_CTRL);
379 /* Set PHYSet JES20040127EEPROM */
380 static void ipg_set_phy_set(struct net_device *dev)
382 struct ipg_nic_private *sp = netdev_priv(dev);
383 void __iomem *ioaddr = sp->ioaddr;
386 physet = ipg_r8(PHY_SET);
387 physet &= ~(IPG_PS_MEM_LENB9B | IPG_PS_MEM_LEN9 | IPG_PS_NON_COMPDET);
388 physet |= ((sp->LED_Mode & 0x70) >> 4);
389 ipg_w8(physet, PHY_SET);
392 static int ipg_reset(struct net_device *dev, u32 resetflags)
394 /* Assert functional resets via the IPG AsicCtrl
395 * register as specified by the 'resetflags' input
398 void __iomem *ioaddr = ipg_ioaddr(dev); //JES20040127EEPROM:
399 unsigned int timeout_count = 0;
401 IPG_DEBUG_MSG("_reset\n");
403 ipg_w32(ipg_r32(ASIC_CTRL) | resetflags, ASIC_CTRL);
405 /* Delay added to account for problem with 10Mbps reset. */
406 mdelay(IPG_AC_RESETWAIT);
408 while (IPG_AC_RESET_BUSY & ipg_r32(ASIC_CTRL)) {
409 mdelay(IPG_AC_RESETWAIT);
410 if (++timeout_count > IPG_AC_RESET_TIMEOUT)
413 /* Set LED Mode in Asic Control JES20040127EEPROM */
414 ipg_set_led_mode(dev);
416 /* Set PHYSet Register Value JES20040127EEPROM */
417 ipg_set_phy_set(dev);
421 /* Find the GMII PHY address. */
422 static int ipg_find_phyaddr(struct net_device *dev)
424 unsigned int phyaddr, i;
426 for (i = 0; i < 32; i++) {
429 /* Search for the correct PHY address among 32 possible. */
430 phyaddr = (IPG_NIC_PHY_ADDRESS + i) % 32;
432 /* 10/22/03 Grace change verify from GMII_PHY_STATUS to
436 status = mdio_read(dev, phyaddr, MII_BMSR);
438 if ((status != 0xFFFF) && (status != 0))
446 * Configure IPG based on result of IEEE 802.3 PHY
449 static int ipg_config_autoneg(struct net_device *dev)
451 struct ipg_nic_private *sp = netdev_priv(dev);
452 void __iomem *ioaddr = sp->ioaddr;
453 unsigned int txflowcontrol;
454 unsigned int rxflowcontrol;
455 unsigned int fullduplex;
461 IPG_DEBUG_MSG("_config_autoneg\n");
463 asicctrl = ipg_r32(ASIC_CTRL);
464 phyctrl = ipg_r8(PHY_CTRL);
465 mac_ctrl_val = ipg_r32(MAC_CTRL);
467 /* Set flags for use in resolving auto-negotation, assuming
468 * non-1000Mbps, half duplex, no flow control.
475 /* To accomodate a problem in 10Mbps operation,
476 * set a global flag if PHY running in 10Mbps mode.
480 printk(KERN_INFO "%s: Link speed = ", dev->name);
482 /* Determine actual speed of operation. */
483 switch (phyctrl & IPG_PC_LINK_SPEED) {
484 case IPG_PC_LINK_SPEED_10MBPS:
486 printk(KERN_INFO "%s: 10Mbps operational mode enabled.\n",
490 case IPG_PC_LINK_SPEED_100MBPS:
491 printk("100Mbps.\n");
493 case IPG_PC_LINK_SPEED_1000MBPS:
494 printk("1000Mbps.\n");
498 printk("undefined!\n");
502 if (phyctrl & IPG_PC_DUPLEX_STATUS) {
508 /* Configure full duplex, and flow control. */
509 if (fullduplex == 1) {
510 /* Configure IPG for full duplex operation. */
511 printk(KERN_INFO "%s: setting full duplex, ", dev->name);
513 mac_ctrl_val |= IPG_MC_DUPLEX_SELECT_FD;
515 if (txflowcontrol == 1) {
516 printk("TX flow control");
517 mac_ctrl_val |= IPG_MC_TX_FLOW_CONTROL_ENABLE;
519 printk("no TX flow control");
520 mac_ctrl_val &= ~IPG_MC_TX_FLOW_CONTROL_ENABLE;
523 if (rxflowcontrol == 1) {
524 printk(", RX flow control.");
525 mac_ctrl_val |= IPG_MC_RX_FLOW_CONTROL_ENABLE;
527 printk(", no RX flow control.");
528 mac_ctrl_val &= ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
533 /* Configure IPG for half duplex operation. */
534 printk(KERN_INFO "%s: setting half duplex, "
535 "no TX flow control, no RX flow control.\n", dev->name);
537 mac_ctrl_val &= ~IPG_MC_DUPLEX_SELECT_FD &
538 ~IPG_MC_TX_FLOW_CONTROL_ENABLE &
539 ~IPG_MC_RX_FLOW_CONTROL_ENABLE;
541 ipg_w32(mac_ctrl_val, MAC_CTRL);
545 /* Determine and configure multicast operation and set
546 * receive mode for IPG.
548 static void ipg_nic_set_multicast_list(struct net_device *dev)
550 void __iomem *ioaddr = ipg_ioaddr(dev);
551 struct dev_mc_list *mc_list_ptr;
552 unsigned int hashindex;
556 IPG_DEBUG_MSG("_nic_set_multicast_list\n");
558 receivemode = IPG_RM_RECEIVEUNICAST | IPG_RM_RECEIVEBROADCAST;
560 if (dev->flags & IFF_PROMISC) {
561 /* NIC to be configured in promiscuous mode. */
562 receivemode = IPG_RM_RECEIVEALLFRAMES;
563 } else if ((dev->flags & IFF_ALLMULTI) ||
564 (dev->flags & IFF_MULTICAST &
565 (dev->mc_count > IPG_MULTICAST_HASHTABLE_SIZE))) {
566 /* NIC to be configured to receive all multicast
568 receivemode |= IPG_RM_RECEIVEMULTICAST;
569 } else if (dev->flags & IFF_MULTICAST & (dev->mc_count > 0)) {
570 /* NIC to be configured to receive selected
571 * multicast addresses. */
572 receivemode |= IPG_RM_RECEIVEMULTICASTHASH;
575 /* Calculate the bits to set for the 64 bit, IPG HASHTABLE.
576 * The IPG applies a cyclic-redundancy-check (the same CRC
577 * used to calculate the frame data FCS) to the destination
578 * address all incoming multicast frames whose destination
579 * address has the multicast bit set. The least significant
580 * 6 bits of the CRC result are used as an addressing index
581 * into the hash table. If the value of the bit addressed by
582 * this index is a 1, the frame is passed to the host system.
585 /* Clear hashtable. */
586 hashtable[0] = 0x00000000;
587 hashtable[1] = 0x00000000;
589 /* Cycle through all multicast addresses to filter. */
590 for (mc_list_ptr = dev->mc_list;
591 mc_list_ptr != NULL; mc_list_ptr = mc_list_ptr->next) {
592 /* Calculate CRC result for each multicast address. */
593 hashindex = crc32_le(0xffffffff, mc_list_ptr->dmi_addr,
596 /* Use only the least significant 6 bits. */
597 hashindex = hashindex & 0x3F;
599 /* Within "hashtable", set bit number "hashindex"
602 set_bit(hashindex, (void *)hashtable);
605 /* Write the value of the hashtable, to the 4, 16 bit
606 * HASHTABLE IPG registers.
608 ipg_w32(hashtable[0], HASHTABLE_0);
609 ipg_w32(hashtable[1], HASHTABLE_1);
611 ipg_w8(IPG_RM_RSVD_MASK & receivemode, RECEIVE_MODE);
613 IPG_DEBUG_MSG("ReceiveMode = %x\n", ipg_r8(RECEIVE_MODE));
616 static int ipg_io_config(struct net_device *dev)
618 void __iomem *ioaddr = ipg_ioaddr(dev);
622 IPG_DEBUG_MSG("_io_config\n");
624 origmacctrl = ipg_r32(MAC_CTRL);
626 restoremacctrl = origmacctrl | IPG_MC_STATISTICS_ENABLE;
628 /* Based on compilation option, determine if FCS is to be
629 * stripped on receive frames by IPG.
631 if (!IPG_STRIP_FCS_ON_RX)
632 restoremacctrl |= IPG_MC_RCV_FCS;
634 /* Determine if transmitter and/or receiver are
635 * enabled so we may restore MACCTRL correctly.
637 if (origmacctrl & IPG_MC_TX_ENABLED)
638 restoremacctrl |= IPG_MC_TX_ENABLE;
640 if (origmacctrl & IPG_MC_RX_ENABLED)
641 restoremacctrl |= IPG_MC_RX_ENABLE;
643 /* Transmitter and receiver must be disabled before setting
646 ipg_w32((origmacctrl & (IPG_MC_RX_DISABLE | IPG_MC_TX_DISABLE)) &
647 IPG_MC_RSVD_MASK, MAC_CTRL);
649 /* Now that transmitter and receiver are disabled, write
652 ipg_w32((origmacctrl & IPG_MC_IFS_96BIT) & IPG_MC_RSVD_MASK, MAC_CTRL);
654 /* Set RECEIVEMODE register. */
655 ipg_nic_set_multicast_list(dev);
657 ipg_w16(IPG_MAX_RXFRAME_SIZE, MAX_FRAME_SIZE);
659 ipg_w8(IPG_RXDMAPOLLPERIOD_VALUE, RX_DMA_POLL_PERIOD);
660 ipg_w8(IPG_RXDMAURGENTTHRESH_VALUE, RX_DMA_URGENT_THRESH);
661 ipg_w8(IPG_RXDMABURSTTHRESH_VALUE, RX_DMA_BURST_THRESH);
662 ipg_w8(IPG_TXDMAPOLLPERIOD_VALUE, TX_DMA_POLL_PERIOD);
663 ipg_w8(IPG_TXDMAURGENTTHRESH_VALUE, TX_DMA_URGENT_THRESH);
664 ipg_w8(IPG_TXDMABURSTTHRESH_VALUE, TX_DMA_BURST_THRESH);
665 ipg_w16((IPG_IE_HOST_ERROR | IPG_IE_TX_DMA_COMPLETE |
666 IPG_IE_TX_COMPLETE | IPG_IE_INT_REQUESTED |
667 IPG_IE_UPDATE_STATS | IPG_IE_LINK_EVENT |
668 IPG_IE_RX_DMA_COMPLETE | IPG_IE_RX_DMA_PRIORITY), INT_ENABLE);
669 ipg_w16(IPG_FLOWONTHRESH_VALUE, FLOW_ON_THRESH);
670 ipg_w16(IPG_FLOWOFFTHRESH_VALUE, FLOW_OFF_THRESH);
672 /* IPG multi-frag frame bug workaround.
673 * Per silicon revision B3 eratta.
675 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0200, DEBUG_CTRL);
677 /* IPG TX poll now bug workaround.
678 * Per silicon revision B3 eratta.
680 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0010, DEBUG_CTRL);
682 /* IPG RX poll now bug workaround.
683 * Per silicon revision B3 eratta.
685 ipg_w16(ipg_r16(DEBUG_CTRL) | 0x0020, DEBUG_CTRL);
687 /* Now restore MACCTRL to original setting. */
688 ipg_w32(IPG_MC_RSVD_MASK & restoremacctrl, MAC_CTRL);
690 /* Disable unused RMON statistics. */
691 ipg_w32(IPG_RZ_ALL, RMON_STATISTICS_MASK);
693 /* Disable unused MIB statistics. */
694 ipg_w32(IPG_SM_MACCONTROLFRAMESXMTD | IPG_SM_MACCONTROLFRAMESRCVD |
695 IPG_SM_BCSTOCTETXMTOK_BCSTFRAMESXMTDOK | IPG_SM_TXJUMBOFRAMES |
696 IPG_SM_MCSTOCTETXMTOK_MCSTFRAMESXMTDOK | IPG_SM_RXJUMBOFRAMES |
697 IPG_SM_BCSTOCTETRCVDOK_BCSTFRAMESRCVDOK |
698 IPG_SM_UDPCHECKSUMERRORS | IPG_SM_TCPCHECKSUMERRORS |
699 IPG_SM_IPCHECKSUMERRORS, STATISTICS_MASK);
705 * Create a receive buffer within system memory and update
706 * NIC private structure appropriately.
708 static int ipg_get_rxbuff(struct net_device *dev, int entry)
710 struct ipg_nic_private *sp = netdev_priv(dev);
711 struct ipg_rx *rxfd = sp->rxd + entry;
715 IPG_DEBUG_MSG("_get_rxbuff\n");
717 skb = netdev_alloc_skb(dev, IPG_RXSUPPORT_SIZE + NET_IP_ALIGN);
719 sp->RxBuff[entry] = NULL;
723 /* Adjust the data start location within the buffer to
724 * align IP address field to a 16 byte boundary.
726 skb_reserve(skb, NET_IP_ALIGN);
728 /* Associate the receive buffer with the IPG NIC. */
731 /* Save the address of the sk_buff structure. */
732 sp->RxBuff[entry] = skb;
734 rxfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
735 sp->rx_buf_sz, PCI_DMA_FROMDEVICE));
737 /* Set the RFD fragment length. */
738 rxfragsize = IPG_RXFRAG_SIZE;
739 rxfd->frag_info |= cpu_to_le64((rxfragsize << 48) & IPG_RFI_FRAGLEN);
744 static int init_rfdlist(struct net_device *dev)
746 struct ipg_nic_private *sp = netdev_priv(dev);
747 void __iomem *ioaddr = sp->ioaddr;
750 IPG_DEBUG_MSG("_init_rfdlist\n");
752 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
753 struct ipg_rx *rxfd = sp->rxd + i;
756 pci_unmap_single(sp->pdev,
757 le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
758 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
759 IPG_DEV_KFREE_SKB(sp->RxBuff[i]);
760 sp->RxBuff[i] = NULL;
763 /* Clear out the RFS field. */
764 rxfd->rfs = 0x0000000000000000;
766 if (ipg_get_rxbuff(dev, i) < 0) {
768 * A receive buffer was not ready, break the
771 IPG_DEBUG_MSG("Cannot allocate Rx buffer.\n");
773 /* Just in case we cannot allocate a single RFD.
777 printk(KERN_ERR "%s: No memory available"
778 " for RFD list.\n", dev->name);
783 rxfd->next_desc = cpu_to_le64(sp->rxd_map +
784 sizeof(struct ipg_rx)*(i + 1));
786 sp->rxd[i - 1].next_desc = cpu_to_le64(sp->rxd_map);
791 /* Write the location of the RFDList to the IPG. */
792 ipg_w32((u32) sp->rxd_map, RFD_LIST_PTR_0);
793 ipg_w32(0x00000000, RFD_LIST_PTR_1);
798 static void init_tfdlist(struct net_device *dev)
800 struct ipg_nic_private *sp = netdev_priv(dev);
801 void __iomem *ioaddr = sp->ioaddr;
804 IPG_DEBUG_MSG("_init_tfdlist\n");
806 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
807 struct ipg_tx *txfd = sp->txd + i;
809 txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
812 IPG_DEV_KFREE_SKB(sp->TxBuff[i]);
813 sp->TxBuff[i] = NULL;
816 txfd->next_desc = cpu_to_le64(sp->txd_map +
817 sizeof(struct ipg_tx)*(i + 1));
819 sp->txd[i - 1].next_desc = cpu_to_le64(sp->txd_map);
824 /* Write the location of the TFDList to the IPG. */
825 IPG_DDEBUG_MSG("Starting TFDListPtr = %8.8x\n",
827 ipg_w32((u32) sp->txd_map, TFD_LIST_PTR_0);
828 ipg_w32(0x00000000, TFD_LIST_PTR_1);
830 sp->ResetCurrentTFD = 1;
834 * Free all transmit buffers which have already been transfered
835 * via DMA to the IPG.
837 static void ipg_nic_txfree(struct net_device *dev)
839 struct ipg_nic_private *sp = netdev_priv(dev);
840 void __iomem *ioaddr = sp->ioaddr;
843 unsigned int released, pending;
845 txd_map = (u64)sp->txd_map;
846 curr = ipg_r32(TFD_LIST_PTR_0) -
847 do_div(txd_map, sizeof(struct ipg_tx)) - 1;
849 IPG_DEBUG_MSG("_nic_txfree\n");
851 pending = sp->tx_current - sp->tx_dirty;
853 for (released = 0; released < pending; released++) {
854 unsigned int dirty = sp->tx_dirty % IPG_TFDLIST_LENGTH;
855 struct sk_buff *skb = sp->TxBuff[dirty];
856 struct ipg_tx *txfd = sp->txd + dirty;
858 IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd->tfc);
860 /* Look at each TFD's TFC field beginning
861 * at the last freed TFD up to the current TFD.
862 * If the TFDDone bit is set, free the associated
868 /* Setup TFDDONE for compatible issue. */
869 txfd->tfc |= cpu_to_le64(IPG_TFC_TFDDONE);
871 /* Free the transmit buffer. */
873 pci_unmap_single(sp->pdev,
874 le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
875 skb->len, PCI_DMA_TODEVICE);
877 IPG_DEV_KFREE_SKB(skb);
879 sp->TxBuff[dirty] = NULL;
883 sp->tx_dirty += released;
885 if (netif_queue_stopped(dev) &&
886 (sp->tx_current != (sp->tx_dirty + IPG_TFDLIST_LENGTH))) {
887 netif_wake_queue(dev);
891 static void ipg_tx_timeout(struct net_device *dev)
893 struct ipg_nic_private *sp = netdev_priv(dev);
894 void __iomem *ioaddr = sp->ioaddr;
896 ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA | IPG_AC_NETWORK |
899 spin_lock_irq(&sp->lock);
901 /* Re-configure after DMA reset. */
902 if (ipg_io_config(dev) < 0) {
903 printk(KERN_INFO "%s: Error during re-configuration.\n",
909 spin_unlock_irq(&sp->lock);
911 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) & IPG_MC_RSVD_MASK,
916 * For TxComplete interrupts, free all transmit
917 * buffers which have already been transfered via DMA
920 static void ipg_nic_txcleanup(struct net_device *dev)
922 struct ipg_nic_private *sp = netdev_priv(dev);
923 void __iomem *ioaddr = sp->ioaddr;
926 IPG_DEBUG_MSG("_nic_txcleanup\n");
928 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
929 /* Reading the TXSTATUS register clears the
930 * TX_COMPLETE interrupt.
932 u32 txstatusdword = ipg_r32(TX_STATUS);
934 IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword);
936 /* Check for Transmit errors. Error bits only valid if
937 * TX_COMPLETE bit in the TXSTATUS register is a 1.
939 if (!(txstatusdword & IPG_TS_TX_COMPLETE))
942 /* If in 10Mbps mode, indicate transmit is ready. */
943 if (sp->tenmbpsmode) {
944 netif_wake_queue(dev);
947 /* Transmit error, increment stat counters. */
948 if (txstatusdword & IPG_TS_TX_ERROR) {
949 IPG_DEBUG_MSG("Transmit error.\n");
950 sp->stats.tx_errors++;
953 /* Late collision, re-enable transmitter. */
954 if (txstatusdword & IPG_TS_LATE_COLLISION) {
955 IPG_DEBUG_MSG("Late collision on transmit.\n");
956 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
957 IPG_MC_RSVD_MASK, MAC_CTRL);
960 /* Maximum collisions, re-enable transmitter. */
961 if (txstatusdword & IPG_TS_TX_MAX_COLL) {
962 IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
963 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
964 IPG_MC_RSVD_MASK, MAC_CTRL);
967 /* Transmit underrun, reset and re-enable
970 if (txstatusdword & IPG_TS_TX_UNDERRUN) {
971 IPG_DEBUG_MSG("Transmitter underrun.\n");
972 sp->stats.tx_fifo_errors++;
973 ipg_reset(dev, IPG_AC_TX_RESET | IPG_AC_DMA |
974 IPG_AC_NETWORK | IPG_AC_FIFO);
976 /* Re-configure after DMA reset. */
977 if (ipg_io_config(dev) < 0) {
979 "%s: Error during re-configuration.\n",
984 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_TX_ENABLE) &
985 IPG_MC_RSVD_MASK, MAC_CTRL);
992 /* Provides statistical information about the IPG NIC. */
993 struct net_device_stats *ipg_nic_get_stats(struct net_device *dev)
995 struct ipg_nic_private *sp = netdev_priv(dev);
996 void __iomem *ioaddr = sp->ioaddr;
1000 IPG_DEBUG_MSG("_nic_get_stats\n");
1002 /* Check to see if the NIC has been initialized via nic_open,
1003 * before trying to read statistic registers.
1005 if (!test_bit(__LINK_STATE_START, &dev->state))
1008 sp->stats.rx_packets += ipg_r32(IPG_FRAMESRCVDOK);
1009 sp->stats.tx_packets += ipg_r32(IPG_FRAMESXMTDOK);
1010 sp->stats.rx_bytes += ipg_r32(IPG_OCTETRCVOK);
1011 sp->stats.tx_bytes += ipg_r32(IPG_OCTETXMTOK);
1012 temp1 = ipg_r16(IPG_FRAMESLOSTRXERRORS);
1013 sp->stats.rx_errors += temp1;
1014 sp->stats.rx_missed_errors += temp1;
1015 temp1 = ipg_r32(IPG_SINGLECOLFRAMES) + ipg_r32(IPG_MULTICOLFRAMES) +
1016 ipg_r32(IPG_LATECOLLISIONS);
1017 temp2 = ipg_r16(IPG_CARRIERSENSEERRORS);
1018 sp->stats.collisions += temp1;
1019 sp->stats.tx_dropped += ipg_r16(IPG_FRAMESABORTXSCOLLS);
1020 sp->stats.tx_errors += ipg_r16(IPG_FRAMESWEXDEFERRAL) +
1021 ipg_r32(IPG_FRAMESWDEFERREDXMT) + temp1 + temp2;
1022 sp->stats.multicast += ipg_r32(IPG_MCSTOCTETRCVDOK);
1024 /* detailed tx_errors */
1025 sp->stats.tx_carrier_errors += temp2;
1027 /* detailed rx_errors */
1028 sp->stats.rx_length_errors += ipg_r16(IPG_INRANGELENGTHERRORS) +
1029 ipg_r16(IPG_FRAMETOOLONGERRRORS);
1030 sp->stats.rx_crc_errors += ipg_r16(IPG_FRAMECHECKSEQERRORS);
1032 /* Unutilized IPG statistic registers. */
1033 ipg_r32(IPG_MCSTFRAMESRCVDOK);
1038 /* Restore used receive buffers. */
1039 static int ipg_nic_rxrestore(struct net_device *dev)
1041 struct ipg_nic_private *sp = netdev_priv(dev);
1042 const unsigned int curr = sp->rx_current;
1043 unsigned int dirty = sp->rx_dirty;
1045 IPG_DEBUG_MSG("_nic_rxrestore\n");
1047 for (dirty = sp->rx_dirty; curr - dirty > 0; dirty++) {
1048 unsigned int entry = dirty % IPG_RFDLIST_LENGTH;
1050 /* rx_copybreak may poke hole here and there. */
1051 if (sp->RxBuff[entry])
1054 /* Generate a new receive buffer to replace the
1055 * current buffer (which will be released by the
1058 if (ipg_get_rxbuff(dev, entry) < 0) {
1059 IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
1064 /* Reset the RFS field. */
1065 sp->rxd[entry].rfs = 0x0000000000000000;
1067 sp->rx_dirty = dirty;
1074 /* use jumboindex and jumbosize to control jumbo frame status
1075 initial status is jumboindex=-1 and jumbosize=0
1076 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
1077 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
1078 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
1079 previous receiving and need to continue dumping the current one
1087 Frame_NoStart_NoEnd = 0,
1088 Frame_WithStart = 1,
1090 Frame_WithStart_WithEnd = 11
1093 inline void ipg_nic_rx_free_skb(struct net_device *dev)
1095 struct ipg_nic_private *sp = netdev_priv(dev);
1096 unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
1098 if (sp->RxBuff[entry]) {
1099 struct ipg_rx *rxfd = sp->rxd + entry;
1101 pci_unmap_single(sp->pdev,
1102 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1103 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1104 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1105 sp->RxBuff[entry] = NULL;
1109 inline int ipg_nic_rx_check_frame_type(struct net_device *dev)
1111 struct ipg_nic_private *sp = netdev_priv(dev);
1112 struct ipg_rx *rxfd = sp->rxd + (sp->rx_current % IPG_RFDLIST_LENGTH);
1113 int type = Frame_NoStart_NoEnd;
1115 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART)
1116 type += Frame_WithStart;
1117 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND)
1118 type += Frame_WithEnd;
1122 inline int ipg_nic_rx_check_error(struct net_device *dev)
1124 struct ipg_nic_private *sp = netdev_priv(dev);
1125 unsigned int entry = sp->rx_current % IPG_RFDLIST_LENGTH;
1126 struct ipg_rx *rxfd = sp->rxd + entry;
1128 if (IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
1129 (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
1130 IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
1131 IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR))) {
1132 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1133 (unsigned long) rxfd->rfs);
1135 /* Increment general receive error statistic. */
1136 sp->stats.rx_errors++;
1138 /* Increment detailed receive error statistics. */
1139 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
1140 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1142 sp->stats.rx_fifo_errors++;
1145 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
1146 IPG_DEBUG_MSG("RX runt occured.\n");
1147 sp->stats.rx_length_errors++;
1150 /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
1151 * error count handled by a IPG statistic register.
1154 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
1155 IPG_DEBUG_MSG("RX alignment error occured.\n");
1156 sp->stats.rx_frame_errors++;
1159 /* Do nothing for IPG_RFS_RXFCSERROR, error count
1160 * handled by a IPG statistic register.
1163 /* Free the memory associated with the RX
1164 * buffer since it is erroneous and we will
1165 * not pass it to higher layer processes.
1167 if (sp->RxBuff[entry]) {
1168 pci_unmap_single(sp->pdev,
1169 le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1170 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1172 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1173 sp->RxBuff[entry] = NULL;
1177 return NormalPacket;
1180 static void ipg_nic_rx_with_start_and_end(struct net_device *dev,
1181 struct ipg_nic_private *sp,
1182 struct ipg_rx *rxfd, unsigned entry)
1184 struct SJumbo *jumbo = &sp->Jumbo;
1185 struct sk_buff *skb;
1188 if (jumbo->FoundStart) {
1189 IPG_DEV_KFREE_SKB(jumbo->skb);
1190 jumbo->FoundStart = 0;
1191 jumbo->CurrentSize = 0;
1195 // 1: found error, 0 no error
1196 if (ipg_nic_rx_check_error(dev) != NormalPacket)
1199 skb = sp->RxBuff[entry];
1203 // accept this frame and send to upper layer
1204 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1205 if (framelen > IPG_RXFRAG_SIZE)
1206 framelen = IPG_RXFRAG_SIZE;
1208 skb_put(skb, framelen);
1209 skb->protocol = eth_type_trans(skb, dev);
1210 skb->ip_summed = CHECKSUM_NONE;
1212 dev->last_rx = jiffies;
1213 sp->RxBuff[entry] = NULL;
1216 static void ipg_nic_rx_with_start(struct net_device *dev,
1217 struct ipg_nic_private *sp,
1218 struct ipg_rx *rxfd, unsigned entry)
1220 struct SJumbo *jumbo = &sp->Jumbo;
1221 struct pci_dev *pdev = sp->pdev;
1222 struct sk_buff *skb;
1224 // 1: found error, 0 no error
1225 if (ipg_nic_rx_check_error(dev) != NormalPacket)
1228 // accept this frame and send to upper layer
1229 skb = sp->RxBuff[entry];
1233 if (jumbo->FoundStart)
1234 IPG_DEV_KFREE_SKB(jumbo->skb);
1236 pci_unmap_single(pdev, le64_to_cpu(rxfd->frag_info & ~IPG_RFI_FRAGLEN),
1237 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1239 skb_put(skb, IPG_RXFRAG_SIZE);
1241 jumbo->FoundStart = 1;
1242 jumbo->CurrentSize = IPG_RXFRAG_SIZE;
1245 sp->RxBuff[entry] = NULL;
1246 dev->last_rx = jiffies;
1249 static void ipg_nic_rx_with_end(struct net_device *dev,
1250 struct ipg_nic_private *sp,
1251 struct ipg_rx *rxfd, unsigned entry)
1253 struct SJumbo *jumbo = &sp->Jumbo;
1255 //1: found error, 0 no error
1256 if (ipg_nic_rx_check_error(dev) == NormalPacket) {
1257 struct sk_buff *skb = sp->RxBuff[entry];
1262 if (jumbo->FoundStart) {
1263 int framelen, endframelen;
1265 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1267 endframeLen = framelen - jumbo->CurrentSize;
1269 if (framelen > IPG_RXFRAG_SIZE)
1270 framelen=IPG_RXFRAG_SIZE;
1272 if (framelen > IPG_RXSUPPORT_SIZE)
1273 IPG_DEV_KFREE_SKB(jumbo->skb);
1275 memcpy(skb_put(jumbo->skb, endframeLen),
1276 skb->data, endframeLen);
1278 jumbo->skb->protocol =
1279 eth_type_trans(jumbo->skb, dev);
1281 jumbo->skb->ip_summed = CHECKSUM_NONE;
1282 netif_rx(jumbo->skb);
1286 dev->last_rx = jiffies;
1287 jumbo->FoundStart = 0;
1288 jumbo->CurrentSize = 0;
1291 ipg_nic_rx_free_skb(dev);
1293 IPG_DEV_KFREE_SKB(jumbo->skb);
1294 jumbo->FoundStart = 0;
1295 jumbo->CurrentSize = 0;
1300 static void ipg_nic_rx_no_start_no_end(struct net_device *dev,
1301 struct ipg_nic_private *sp,
1302 struct ipg_rx *rxfd, unsigned entry)
1304 struct SJumbo *jumbo = &sp->Jumbo;
1306 //1: found error, 0 no error
1307 if (ipg_nic_rx_check_error(dev) == NormalPacket) {
1308 struct sk_buff *skb = sp->RxBuff[entry];
1311 if (jumbo->FoundStart) {
1312 jumbo->CurrentSize += IPG_RXFRAG_SIZE;
1313 if (jumbo->CurrentSize <= IPG_RXSUPPORT_SIZE) {
1314 memcpy(skb_put(jumbo->skb,
1316 skb->data, IPG_RXFRAG_SIZE);
1319 dev->last_rx = jiffies;
1320 ipg_nic_rx_free_skb(dev);
1323 IPG_DEV_KFREE_SKB(jumbo->skb);
1324 jumbo->FoundStart = 0;
1325 jumbo->CurrentSize = 0;
1330 static int ipg_nic_rx(struct net_device *dev)
1332 struct ipg_nic_private *sp = netdev_priv(dev);
1333 unsigned int curr = sp->rx_current;
1334 void __iomem *ioaddr = sp->ioaddr;
1337 IPG_DEBUG_MSG("_nic_rx\n");
1339 for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
1340 unsigned int entry = curr % IPG_RFDLIST_LENGTH;
1341 struct ipg_rx *rxfd = sp->rxd + entry;
1343 if (!(rxfd->rfs & le64_to_cpu(IPG_RFS_RFDDONE)))
1346 switch (ipg_nic_rx_check_frame_type(dev)) {
1347 case Frame_WithStart_WithEnd:
1348 ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry);
1350 case Frame_WithStart:
1351 ipg_nic_rx_with_start(dev, tp, rxfd, entry);
1354 ipg_nic_rx_with_end(dev, tp, rxfd, entry);
1356 case Frame_NoStart_NoEnd:
1357 ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry);
1362 sp->rx_current = curr;
1364 if (i == IPG_MAXRFDPROCESS_COUNT) {
1365 /* There are more RFDs to process, however the
1366 * allocated amount of RFD processing time has
1367 * expired. Assert Interrupt Requested to make
1368 * sure we come back to process the remaining RFDs.
1370 ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
1373 ipg_nic_rxrestore(dev);
1379 static int ipg_nic_rx(struct net_device *dev)
1381 /* Transfer received Ethernet frames to higher network layers. */
1382 struct ipg_nic_private *sp = netdev_priv(dev);
1383 unsigned int curr = sp->rx_current;
1384 void __iomem *ioaddr = sp->ioaddr;
1385 struct ipg_rx *rxfd;
1388 IPG_DEBUG_MSG("_nic_rx\n");
1390 #define __RFS_MASK \
1391 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1393 for (i = 0; i < IPG_MAXRFDPROCESS_COUNT; i++, curr++) {
1394 unsigned int entry = curr % IPG_RFDLIST_LENGTH;
1395 struct sk_buff *skb = sp->RxBuff[entry];
1396 unsigned int framelen;
1398 rxfd = sp->rxd + entry;
1400 if (((rxfd->rfs & __RFS_MASK) != __RFS_MASK) || !skb)
1403 /* Get received frame length. */
1404 framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
1406 /* Check for jumbo frame arrival with too small
1409 if (framelen > IPG_RXFRAG_SIZE) {
1411 ("RFS FrameLen > allocated fragment size.\n");
1413 framelen = IPG_RXFRAG_SIZE;
1416 if ((IPG_DROP_ON_RX_ETH_ERRORS && (le64_to_cpu(rxfd->rfs) &
1417 (IPG_RFS_RXFIFOOVERRUN | IPG_RFS_RXRUNTFRAME |
1418 IPG_RFS_RXALIGNMENTERROR | IPG_RFS_RXFCSERROR |
1419 IPG_RFS_RXOVERSIZEDFRAME | IPG_RFS_RXLENGTHERROR)))) {
1421 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1422 (unsigned long int) rxfd->rfs);
1424 /* Increment general receive error statistic. */
1425 sp->stats.rx_errors++;
1427 /* Increment detailed receive error statistics. */
1428 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFIFOOVERRUN) {
1429 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1430 sp->stats.rx_fifo_errors++;
1433 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXRUNTFRAME) {
1434 IPG_DEBUG_MSG("RX runt occured.\n");
1435 sp->stats.rx_length_errors++;
1438 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXOVERSIZEDFRAME) ;
1439 /* Do nothing, error count handled by a IPG
1440 * statistic register.
1443 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXALIGNMENTERROR) {
1444 IPG_DEBUG_MSG("RX alignment error occured.\n");
1445 sp->stats.rx_frame_errors++;
1448 if (le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFCSERROR) ;
1449 /* Do nothing, error count handled by a IPG
1450 * statistic register.
1453 /* Free the memory associated with the RX
1454 * buffer since it is erroneous and we will
1455 * not pass it to higher layer processes.
1458 __le64 info = rxfd->frag_info;
1460 pci_unmap_single(sp->pdev,
1461 le64_to_cpu(info) & ~IPG_RFI_FRAGLEN,
1462 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1464 IPG_DEV_KFREE_SKB(skb);
1468 /* Adjust the new buffer length to accomodate the size
1469 * of the received frame.
1471 skb_put(skb, framelen);
1473 /* Set the buffer's protocol field to Ethernet. */
1474 skb->protocol = eth_type_trans(skb, dev);
1476 /* If the frame contains an IP/TCP/UDP frame,
1477 * determine if upper layer must check IP/TCP/UDP
1480 * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
1481 * VERIFICATION FOR SILICON REVISIONS B3
1484 if ((le64_to_cpu(rxfd->rfs &
1485 (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
1486 IPG_RFS_IPDETECTED))) &&
1487 !(le64_to_cpu(rxfd->rfs &
1488 (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
1489 IPG_RFS_IPERROR)))) {
1490 * Indicate IP checksums were performed
1493 skb->ip_summed = CHECKSUM_UNNECESSARY;
1497 /* The IPG encountered an error with (or
1498 * there were no) IP/TCP/UDP checksums.
1499 * This may or may not indicate an invalid
1500 * IP/TCP/UDP frame was received. Let the
1501 * upper layer decide.
1503 skb->ip_summed = CHECKSUM_NONE;
1506 /* Hand off frame for higher layer processing.
1507 * The function netif_rx() releases the sk_buff
1508 * when processing completes.
1512 /* Record frame receive time (jiffies = Linux
1513 * kernel current time stamp).
1515 dev->last_rx = jiffies;
1518 /* Assure RX buffer is not reused by IPG. */
1519 sp->RxBuff[entry] = NULL;
1523 * If there are more RFDs to proces and the allocated amount of RFD
1524 * processing time has expired, assert Interrupt Requested to make
1525 * sure we come back to process the remaining RFDs.
1527 if (i == IPG_MAXRFDPROCESS_COUNT)
1528 ipg_w32(ipg_r32(ASIC_CTRL) | IPG_AC_INT_REQUEST, ASIC_CTRL);
1531 /* Check if the RFD list contained no receive frame data. */
1533 sp->EmptyRFDListCount++;
1535 while ((le64_to_cpu(rxfd->rfs) & IPG_RFS_RFDDONE) &&
1536 !((le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMESTART) &&
1537 (le64_to_cpu(rxfd->rfs) & IPG_RFS_FRAMEEND))) {
1538 unsigned int entry = curr++ % IPG_RFDLIST_LENGTH;
1540 rxfd = sp->rxd + entry;
1542 IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
1544 /* An unexpected event, additional code needed to handle
1545 * properly. So for the time being, just disregard the
1549 /* Free the memory associated with the RX
1550 * buffer since it is erroneous and we will
1551 * not pass it to higher layer processes.
1553 if (sp->RxBuff[entry]) {
1554 pci_unmap_single(sp->pdev,
1555 le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
1556 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1557 IPG_DEV_KFREE_SKB(sp->RxBuff[entry]);
1560 /* Assure RX buffer is not reused by IPG. */
1561 sp->RxBuff[entry] = NULL;
1564 sp->rx_current = curr;
1566 /* Check to see if there are a minimum number of used
1567 * RFDs before restoring any (should improve performance.)
1569 if ((curr - sp->rx_dirty) >= IPG_MINUSEDRFDSTOFREE)
1570 ipg_nic_rxrestore(dev);
1576 static void ipg_reset_after_host_error(struct work_struct *work)
1578 struct ipg_nic_private *sp =
1579 container_of(work, struct ipg_nic_private, task.work);
1580 struct net_device *dev = sp->dev;
1582 IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp->ioaddr + IPG_DMACTRL));
1585 * Acknowledge HostError interrupt by resetting
1588 ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
1593 if (ipg_io_config(dev) < 0) {
1594 printk(KERN_INFO "%s: Cannot recover from PCI error.\n",
1596 schedule_delayed_work(&sp->task, HZ);
1600 static irqreturn_t ipg_interrupt_handler(int irq, void *dev_inst)
1602 struct net_device *dev = dev_inst;
1603 struct ipg_nic_private *sp = netdev_priv(dev);
1604 void __iomem *ioaddr = sp->ioaddr;
1605 unsigned int handled = 0;
1608 IPG_DEBUG_MSG("_interrupt_handler\n");
1611 ipg_nic_rxrestore(dev);
1613 /* Get interrupt source information, and acknowledge
1614 * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
1615 * IntRequested, MacControlFrame, LinkEvent) interrupts
1616 * if issued. Also, all IPG interrupts are disabled by
1617 * reading IntStatusAck.
1619 status = ipg_r16(INT_STATUS_ACK);
1621 IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status);
1623 /* Shared IRQ of remove event. */
1624 if (!(status & IPG_IS_RSVD_MASK))
1629 if (unlikely(!netif_running(dev)))
1632 spin_lock(&sp->lock);
1634 /* If RFDListEnd interrupt, restore all used RFDs. */
1635 if (status & IPG_IS_RFD_LIST_END) {
1636 IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
1638 /* The RFD list end indicates an RFD was encountered
1639 * with a 0 NextPtr, or with an RFDDone bit set to 1
1640 * (indicating the RFD is not read for use by the
1641 * IPG.) Try to restore all RFDs.
1643 ipg_nic_rxrestore(dev);
1646 /* Increment the RFDlistendCount counter. */
1647 sp->RFDlistendCount++;
1651 /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
1652 * IntRequested interrupt, process received frames. */
1653 if ((status & IPG_IS_RX_DMA_PRIORITY) ||
1654 (status & IPG_IS_RFD_LIST_END) ||
1655 (status & IPG_IS_RX_DMA_COMPLETE) ||
1656 (status & IPG_IS_INT_REQUESTED)) {
1658 /* Increment the RFD list checked counter if interrupted
1659 * only to check the RFD list. */
1660 if (status & (~(IPG_IS_RX_DMA_PRIORITY | IPG_IS_RFD_LIST_END |
1661 IPG_IS_RX_DMA_COMPLETE | IPG_IS_INT_REQUESTED) &
1662 (IPG_IS_HOST_ERROR | IPG_IS_TX_DMA_COMPLETE |
1663 IPG_IS_LINK_EVENT | IPG_IS_TX_COMPLETE |
1664 IPG_IS_UPDATE_STATS)))
1665 sp->RFDListCheckedCount++;
1671 /* If TxDMAComplete interrupt, free used TFDs. */
1672 if (status & IPG_IS_TX_DMA_COMPLETE)
1673 ipg_nic_txfree(dev);
1675 /* TxComplete interrupts indicate one of numerous actions.
1676 * Determine what action to take based on TXSTATUS register.
1678 if (status & IPG_IS_TX_COMPLETE)
1679 ipg_nic_txcleanup(dev);
1681 /* If UpdateStats interrupt, update Linux Ethernet statistics */
1682 if (status & IPG_IS_UPDATE_STATS)
1683 ipg_nic_get_stats(dev);
1685 /* If HostError interrupt, reset IPG. */
1686 if (status & IPG_IS_HOST_ERROR) {
1687 IPG_DDEBUG_MSG("HostError Interrupt\n");
1689 schedule_delayed_work(&sp->task, 0);
1692 /* If LinkEvent interrupt, resolve autonegotiation. */
1693 if (status & IPG_IS_LINK_EVENT) {
1694 if (ipg_config_autoneg(dev) < 0)
1695 printk(KERN_INFO "%s: Auto-negotiation error.\n",
1699 /* If MACCtrlFrame interrupt, do nothing. */
1700 if (status & IPG_IS_MAC_CTRL_FRAME)
1701 IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
1703 /* If RxComplete interrupt, do nothing. */
1704 if (status & IPG_IS_RX_COMPLETE)
1705 IPG_DEBUG_MSG("RxComplete interrupt.\n");
1707 /* If RxEarly interrupt, do nothing. */
1708 if (status & IPG_IS_RX_EARLY)
1709 IPG_DEBUG_MSG("RxEarly interrupt.\n");
1712 /* Re-enable IPG interrupts. */
1713 ipg_w16(IPG_IE_TX_DMA_COMPLETE | IPG_IE_RX_DMA_COMPLETE |
1714 IPG_IE_HOST_ERROR | IPG_IE_INT_REQUESTED | IPG_IE_TX_COMPLETE |
1715 IPG_IE_LINK_EVENT | IPG_IE_UPDATE_STATS, INT_ENABLE);
1717 spin_unlock(&sp->lock);
1719 return IRQ_RETVAL(handled);
1722 static void ipg_rx_clear(struct ipg_nic_private *sp)
1726 for (i = 0; i < IPG_RFDLIST_LENGTH; i++) {
1727 if (sp->RxBuff[i]) {
1728 struct ipg_rx *rxfd = sp->rxd + i;
1730 IPG_DEV_KFREE_SKB(sp->RxBuff[i]);
1731 sp->RxBuff[i] = NULL;
1732 pci_unmap_single(sp->pdev,
1733 le64_to_cpu(rxfd->frag_info) & ~IPG_RFI_FRAGLEN,
1734 sp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1739 static void ipg_tx_clear(struct ipg_nic_private *sp)
1743 for (i = 0; i < IPG_TFDLIST_LENGTH; i++) {
1744 if (sp->TxBuff[i]) {
1745 struct ipg_tx *txfd = sp->txd + i;
1747 pci_unmap_single(sp->pdev,
1748 le64_to_cpu(txfd->frag_info) & ~IPG_TFI_FRAGLEN,
1749 sp->TxBuff[i]->len, PCI_DMA_TODEVICE);
1751 IPG_DEV_KFREE_SKB(sp->TxBuff[i]);
1753 sp->TxBuff[i] = NULL;
1758 static int ipg_nic_open(struct net_device *dev)
1760 struct ipg_nic_private *sp = netdev_priv(dev);
1761 void __iomem *ioaddr = sp->ioaddr;
1762 struct pci_dev *pdev = sp->pdev;
1765 IPG_DEBUG_MSG("_nic_open\n");
1767 sp->rx_buf_sz = IPG_RXSUPPORT_SIZE;
1769 /* Check for interrupt line conflicts, and request interrupt
1772 * IMPORTANT: Disable IPG interrupts prior to registering
1775 ipg_w16(0x0000, INT_ENABLE);
1777 /* Register the interrupt line to be used by the IPG within
1780 rc = request_irq(pdev->irq, &ipg_interrupt_handler, IRQF_SHARED,
1783 printk(KERN_INFO "%s: Error when requesting interrupt.\n",
1788 dev->irq = pdev->irq;
1792 sp->rxd = dma_alloc_coherent(&pdev->dev, IPG_RX_RING_BYTES,
1793 &sp->rxd_map, GFP_KERNEL);
1795 goto err_free_irq_0;
1797 sp->txd = dma_alloc_coherent(&pdev->dev, IPG_TX_RING_BYTES,
1798 &sp->txd_map, GFP_KERNEL);
1802 rc = init_rfdlist(dev);
1804 printk(KERN_INFO "%s: Error during configuration.\n",
1811 rc = ipg_io_config(dev);
1813 printk(KERN_INFO "%s: Error during configuration.\n",
1815 goto err_release_tfdlist_3;
1818 /* Resolve autonegotiation. */
1819 if (ipg_config_autoneg(dev) < 0)
1820 printk(KERN_INFO "%s: Auto-negotiation error.\n", dev->name);
1823 /* initialize JUMBO Frame control variable */
1824 sp->Jumbo.FoundStart = 0;
1825 sp->Jumbo.CurrentSize = 0;
1827 dev->mtu = IPG_TXFRAG_SIZE;
1830 /* Enable transmit and receive operation of the IPG. */
1831 ipg_w32((ipg_r32(MAC_CTRL) | IPG_MC_RX_ENABLE | IPG_MC_TX_ENABLE) &
1832 IPG_MC_RSVD_MASK, MAC_CTRL);
1834 netif_start_queue(dev);
1838 err_release_tfdlist_3:
1842 dma_free_coherent(&pdev->dev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
1844 dma_free_coherent(&pdev->dev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
1846 free_irq(pdev->irq, dev);
1850 static int ipg_nic_stop(struct net_device *dev)
1852 struct ipg_nic_private *sp = netdev_priv(dev);
1853 void __iomem *ioaddr = sp->ioaddr;
1854 struct pci_dev *pdev = sp->pdev;
1856 IPG_DEBUG_MSG("_nic_stop\n");
1858 netif_stop_queue(dev);
1860 IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp->RFDlistendCount);
1861 IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp->rxdCheckedCount);
1862 IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp->EmptyRFDListCount);
1863 IPG_DUMPTFDLIST(dev);
1866 (void) ipg_r16(INT_STATUS_ACK);
1868 ipg_reset(dev, IPG_AC_GLOBAL_RESET | IPG_AC_HOST | IPG_AC_DMA);
1870 synchronize_irq(pdev->irq);
1871 } while (ipg_r16(INT_ENABLE) & IPG_IE_RSVD_MASK);
1877 pci_free_consistent(pdev, IPG_RX_RING_BYTES, sp->rxd, sp->rxd_map);
1878 pci_free_consistent(pdev, IPG_TX_RING_BYTES, sp->txd, sp->txd_map);
1880 free_irq(pdev->irq, dev);
1885 static int ipg_nic_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1887 struct ipg_nic_private *sp = netdev_priv(dev);
1888 void __iomem *ioaddr = sp->ioaddr;
1889 unsigned int entry = sp->tx_current % IPG_TFDLIST_LENGTH;
1890 unsigned long flags;
1891 struct ipg_tx *txfd;
1893 IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
1895 /* If in 10Mbps mode, stop the transmit queue so
1896 * no more transmit frames are accepted.
1898 if (sp->tenmbpsmode)
1899 netif_stop_queue(dev);
1901 if (sp->ResetCurrentTFD) {
1902 sp->ResetCurrentTFD = 0;
1906 txfd = sp->txd + entry;
1908 sp->TxBuff[entry] = skb;
1910 /* Clear all TFC fields, except TFDDONE. */
1911 txfd->tfc = cpu_to_le64(IPG_TFC_TFDDONE);
1913 /* Specify the TFC field within the TFD. */
1914 txfd->tfc |= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED |
1915 (IPG_TFC_FRAMEID & cpu_to_le64(sp->tx_current)) |
1916 (IPG_TFC_FRAGCOUNT & (1 << 24)));
1918 /* Request TxComplete interrupts at an interval defined
1919 * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
1920 * Request TxComplete interrupt for every frame
1921 * if in 10Mbps mode to accomodate problem with 10Mbps
1924 if (sp->tenmbpsmode)
1925 txfd->tfc |= cpu_to_le64(IPG_TFC_TXINDICATE);
1926 else if (!((sp->tx_current - sp->tx_dirty + 1) >
1927 IPG_FRAMESBETWEENTXDMACOMPLETES)) {
1928 txfd->tfc |= cpu_to_le64(IPG_TFC_TXDMAINDICATE);
1930 /* Based on compilation option, determine if FCS is to be
1931 * appended to transmit frame by IPG.
1933 if (!(IPG_APPEND_FCS_ON_TX))
1934 txfd->tfc |= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE);
1936 /* Based on compilation option, determine if IP, TCP and/or
1937 * UDP checksums are to be added to transmit frame by IPG.
1939 if (IPG_ADD_IPCHECKSUM_ON_TX)
1940 txfd->tfc |= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE);
1942 if (IPG_ADD_TCPCHECKSUM_ON_TX)
1943 txfd->tfc |= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE);
1945 if (IPG_ADD_UDPCHECKSUM_ON_TX)
1946 txfd->tfc |= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE);
1948 /* Based on compilation option, determine if VLAN tag info is to be
1949 * inserted into transmit frame by IPG.
1951 if (IPG_INSERT_MANUAL_VLAN_TAG) {
1952 txfd->tfc |= cpu_to_le64(IPG_TFC_VLANTAGINSERT |
1953 ((u64) IPG_MANUAL_VLAN_VID << 32) |
1954 ((u64) IPG_MANUAL_VLAN_CFI << 44) |
1955 ((u64) IPG_MANUAL_VLAN_USERPRIORITY << 45));
1958 /* The fragment start location within system memory is defined
1959 * by the sk_buff structure's data field. The physical address
1960 * of this location within the system's virtual memory space
1961 * is determined using the IPG_HOST2BUS_MAP function.
1963 txfd->frag_info = cpu_to_le64(pci_map_single(sp->pdev, skb->data,
1964 skb->len, PCI_DMA_TODEVICE));
1966 /* The length of the fragment within system memory is defined by
1967 * the sk_buff structure's len field.
1969 txfd->frag_info |= cpu_to_le64(IPG_TFI_FRAGLEN &
1970 ((u64) (skb->len & 0xffff) << 48));
1972 /* Clear the TFDDone bit last to indicate the TFD is ready
1973 * for transfer to the IPG.
1975 txfd->tfc &= cpu_to_le64(~IPG_TFC_TFDDONE);
1977 spin_lock_irqsave(&sp->lock, flags);
1983 ipg_w32(IPG_DC_TX_DMA_POLL_NOW, DMA_CTRL);
1985 if (sp->tx_current == (sp->tx_dirty + IPG_TFDLIST_LENGTH))
1986 netif_wake_queue(dev);
1988 spin_unlock_irqrestore(&sp->lock, flags);
1990 return NETDEV_TX_OK;
1993 static void ipg_set_phy_default_param(unsigned char rev,
1994 struct net_device *dev, int phy_address)
1996 unsigned short length;
1997 unsigned char revision;
1998 unsigned short *phy_param;
1999 unsigned short address, value;
2001 phy_param = &DefaultPhyParam[0];
2002 length = *phy_param & 0x00FF;
2003 revision = (unsigned char)((*phy_param) >> 8);
2005 while (length != 0) {
2006 if (rev == revision) {
2007 while (length > 1) {
2008 address = *phy_param;
2009 value = *(phy_param + 1);
2011 mdio_write(dev, phy_address, address, value);
2016 phy_param += length / 2;
2017 length = *phy_param & 0x00FF;
2018 revision = (unsigned char)((*phy_param) >> 8);
2024 /* JES20040127EEPROM */
2025 static int read_eeprom(struct net_device *dev, int eep_addr)
2027 void __iomem *ioaddr = ipg_ioaddr(dev);
2032 value = IPG_EC_EEPROM_READOPCODE | (eep_addr & 0xff);
2033 ipg_w16(value, EEPROM_CTRL);
2035 for (i = 0; i < 1000; i++) {
2039 data = ipg_r16(EEPROM_CTRL);
2040 if (!(data & IPG_EC_EEPROM_BUSY)) {
2041 ret = ipg_r16(EEPROM_DATA);
2048 static void ipg_init_mii(struct net_device *dev)
2050 struct ipg_nic_private *sp = netdev_priv(dev);
2051 struct mii_if_info *mii_if = &sp->mii_if;
2055 mii_if->mdio_read = mdio_read;
2056 mii_if->mdio_write = mdio_write;
2057 mii_if->phy_id_mask = 0x1f;
2058 mii_if->reg_num_mask = 0x1f;
2060 mii_if->phy_id = phyaddr = ipg_find_phyaddr(dev);
2062 if (phyaddr != 0x1f) {
2063 u16 mii_phyctrl, mii_1000cr;
2066 mii_1000cr = mdio_read(dev, phyaddr, MII_CTRL1000);
2067 mii_1000cr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF |
2068 GMII_PHY_1000BASETCONTROL_PreferMaster;
2069 mdio_write(dev, phyaddr, MII_CTRL1000, mii_1000cr);
2071 mii_phyctrl = mdio_read(dev, phyaddr, MII_BMCR);
2073 /* Set default phyparam */
2074 pci_read_config_byte(sp->pdev, PCI_REVISION_ID, &revisionid);
2075 ipg_set_phy_default_param(revisionid, dev, phyaddr);
2078 mii_phyctrl |= BMCR_RESET | BMCR_ANRESTART;
2079 mdio_write(dev, phyaddr, MII_BMCR, mii_phyctrl);
2084 static int ipg_hw_init(struct net_device *dev)
2086 struct ipg_nic_private *sp = netdev_priv(dev);
2087 void __iomem *ioaddr = sp->ioaddr;
2091 /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
2092 /* Read LED Mode Configuration from EEPROM */
2093 sp->LED_Mode = read_eeprom(dev, 6);
2095 /* Reset all functions within the IPG. Do not assert
2096 * RST_OUT as not compatible with some PHYs.
2098 rc = ipg_reset(dev, IPG_RESET_MASK);
2104 /* Read MAC Address from EEPROM */
2105 for (i = 0; i < 3; i++)
2106 sp->station_addr[i] = read_eeprom(dev, 16 + i);
2108 for (i = 0; i < 3; i++)
2109 ipg_w16(sp->station_addr[i], STATION_ADDRESS_0 + 2*i);
2111 /* Set station address in ethernet_device structure. */
2112 dev->dev_addr[0] = ipg_r16(STATION_ADDRESS_0) & 0x00ff;
2113 dev->dev_addr[1] = (ipg_r16(STATION_ADDRESS_0) & 0xff00) >> 8;
2114 dev->dev_addr[2] = ipg_r16(STATION_ADDRESS_1) & 0x00ff;
2115 dev->dev_addr[3] = (ipg_r16(STATION_ADDRESS_1) & 0xff00) >> 8;
2116 dev->dev_addr[4] = ipg_r16(STATION_ADDRESS_2) & 0x00ff;
2117 dev->dev_addr[5] = (ipg_r16(STATION_ADDRESS_2) & 0xff00) >> 8;
2122 static int ipg_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2124 struct ipg_nic_private *sp = netdev_priv(dev);
2127 mutex_lock(&sp->mii_mutex);
2128 rc = generic_mii_ioctl(&sp->mii_if, if_mii(ifr), cmd, NULL);
2129 mutex_unlock(&sp->mii_mutex);
2134 static int ipg_nic_change_mtu(struct net_device *dev, int new_mtu)
2136 /* Function to accomodate changes to Maximum Transfer Unit
2137 * (or MTU) of IPG NIC. Cannot use default function since
2138 * the default will not allow for MTU > 1500 bytes.
2141 IPG_DEBUG_MSG("_nic_change_mtu\n");
2143 /* Check that the new MTU value is between 68 (14 byte header, 46
2144 * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
2145 * corresponds to the MAXFRAMESIZE register in the IPG.
2147 if ((new_mtu < 68) || (new_mtu > IPG_MAX_RXFRAME_SIZE))
2155 static int ipg_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2157 struct ipg_nic_private *sp = netdev_priv(dev);
2160 mutex_lock(&sp->mii_mutex);
2161 rc = mii_ethtool_gset(&sp->mii_if, cmd);
2162 mutex_unlock(&sp->mii_mutex);
2167 static int ipg_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2169 struct ipg_nic_private *sp = netdev_priv(dev);
2172 mutex_lock(&sp->mii_mutex);
2173 rc = mii_ethtool_sset(&sp->mii_if, cmd);
2174 mutex_unlock(&sp->mii_mutex);
2179 static int ipg_nway_reset(struct net_device *dev)
2181 struct ipg_nic_private *sp = netdev_priv(dev);
2184 mutex_lock(&sp->mii_mutex);
2185 rc = mii_nway_restart(&sp->mii_if);
2186 mutex_unlock(&sp->mii_mutex);
2191 static struct ethtool_ops ipg_ethtool_ops = {
2192 .get_settings = ipg_get_settings,
2193 .set_settings = ipg_set_settings,
2194 .nway_reset = ipg_nway_reset,
2197 static void ipg_remove(struct pci_dev *pdev)
2199 struct net_device *dev = pci_get_drvdata(pdev);
2200 struct ipg_nic_private *sp = netdev_priv(dev);
2202 IPG_DEBUG_MSG("_remove\n");
2204 /* Un-register Ethernet device. */
2205 unregister_netdev(dev);
2207 pci_iounmap(pdev, sp->ioaddr);
2209 pci_release_regions(pdev);
2212 pci_disable_device(pdev);
2213 pci_set_drvdata(pdev, NULL);
2216 static int __devinit ipg_probe(struct pci_dev *pdev,
2217 const struct pci_device_id *id)
2219 unsigned int i = id->driver_data;
2220 struct ipg_nic_private *sp;
2221 struct net_device *dev;
2222 void __iomem *ioaddr;
2225 rc = pci_enable_device(pdev);
2229 printk(KERN_INFO "%s: %s\n", pci_name(pdev), ipg_brand_name[i]);
2231 pci_set_master(pdev);
2233 rc = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
2235 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2237 printk(KERN_ERR "%s: DMA config failed.\n",
2244 * Initialize net device.
2246 dev = alloc_etherdev(sizeof(struct ipg_nic_private));
2248 printk(KERN_ERR "%s: alloc_etherdev failed\n", pci_name(pdev));
2253 sp = netdev_priv(dev);
2254 spin_lock_init(&sp->lock);
2255 mutex_init(&sp->mii_mutex);
2257 /* Declare IPG NIC functions for Ethernet device methods.
2259 dev->open = &ipg_nic_open;
2260 dev->stop = &ipg_nic_stop;
2261 dev->hard_start_xmit = &ipg_nic_hard_start_xmit;
2262 dev->get_stats = &ipg_nic_get_stats;
2263 dev->set_multicast_list = &ipg_nic_set_multicast_list;
2264 dev->do_ioctl = ipg_ioctl;
2265 dev->tx_timeout = ipg_tx_timeout;
2266 dev->change_mtu = &ipg_nic_change_mtu;
2268 SET_NETDEV_DEV(dev, &pdev->dev);
2269 SET_ETHTOOL_OPS(dev, &ipg_ethtool_ops);
2271 rc = pci_request_regions(pdev, DRV_NAME);
2273 goto err_free_dev_1;
2275 ioaddr = pci_iomap(pdev, 1, pci_resource_len(pdev, 1));
2277 printk(KERN_ERR "%s cannot map MMIO\n", pci_name(pdev));
2279 goto err_release_regions_2;
2282 /* Save the pointer to the PCI device information. */
2283 sp->ioaddr = ioaddr;
2287 INIT_DELAYED_WORK(&sp->task, ipg_reset_after_host_error);
2289 pci_set_drvdata(pdev, dev);
2291 rc = ipg_hw_init(dev);
2295 rc = register_netdev(dev);
2299 printk(KERN_INFO "Ethernet device registered as: %s\n", dev->name);
2304 pci_iounmap(pdev, ioaddr);
2305 err_release_regions_2:
2306 pci_release_regions(pdev);
2310 pci_disable_device(pdev);
2314 static struct pci_driver ipg_pci_driver = {
2315 .name = IPG_DRIVER_NAME,
2316 .id_table = ipg_pci_tbl,
2318 .remove = __devexit_p(ipg_remove),
2321 static int __init ipg_init_module(void)
2323 return pci_register_driver(&ipg_pci_driver);
2326 static void __exit ipg_exit_module(void)
2328 pci_unregister_driver(&ipg_pci_driver);
2331 module_init(ipg_init_module);
2332 module_exit(ipg_exit_module);