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 //variable record -- index by leading revision/length
59 //Revision/Length(=N*4), Address1, Data1, Address2, Data2,...,AddressN,DataN
60 static unsigned short DefaultPhyParam
[] = {
61 // 11/12/03 IP1000A v1-3 rev=0x40
62 /*--------------------------------------------------------------------------
63 (0x4000|(15*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 22, 0x85bd, 24, 0xfff2,
64 27, 0x0c10, 28, 0x0c10, 29, 0x2c10, 31, 0x0003, 23, 0x92f6,
65 31, 0x0000, 23, 0x003d, 30, 0x00de, 20, 0x20e7, 9, 0x0700,
66 --------------------------------------------------------------------------*/
67 // 12/17/03 IP1000A v1-4 rev=0x40
68 (0x4000 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
70 30, 0x005e, 9, 0x0700,
71 // 01/09/04 IP1000A v1-5 rev=0x41
72 (0x4100 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
74 30, 0x005e, 9, 0x0700,
78 static const char *ipg_brand_name
[] = {
79 "IC PLUS IP1000 1000/100/10 based NIC",
80 "Sundance Technology ST2021 based NIC",
81 "Tamarack Microelectronics TC9020/9021 based NIC",
82 "Tamarack Microelectronics TC9020/9021 based NIC",
87 static struct pci_device_id ipg_pci_tbl
[] __devinitdata
= {
88 { PCI_VDEVICE(SUNDANCE
, 0x1023), 0 },
89 { PCI_VDEVICE(SUNDANCE
, 0x2021), 1 },
90 { PCI_VDEVICE(SUNDANCE
, 0x1021), 2 },
91 { PCI_VDEVICE(DLINK
, 0x9021), 3 },
92 { PCI_VDEVICE(DLINK
, 0x4000), 4 },
93 { PCI_VDEVICE(DLINK
, 0x4020), 5 },
97 MODULE_DEVICE_TABLE(pci
, ipg_pci_tbl
);
99 static inline void __iomem
*ipg_ioaddr(struct net_device
*dev
)
101 struct ipg_nic_private
*sp
= netdev_priv(dev
);
106 static void ipg_dump_rfdlist(struct net_device
*dev
)
108 struct ipg_nic_private
*sp
= netdev_priv(dev
);
109 void __iomem
*ioaddr
= sp
->ioaddr
;
113 IPG_DEBUG_MSG("_dump_rfdlist\n");
115 printk(KERN_INFO
"rx_current = %2.2x\n", sp
->rx_current
);
116 printk(KERN_INFO
"rx_dirty = %2.2x\n", sp
->rx_dirty
);
117 printk(KERN_INFO
"RFDList start address = %16.16lx\n",
118 (unsigned long) sp
->rxd_map
);
119 printk(KERN_INFO
"RFDListPtr register = %8.8x%8.8x\n",
120 ipg_r32(IPG_RFDLISTPTR1
), ipg_r32(IPG_RFDLISTPTR0
));
122 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
123 offset
= (u32
) &sp
->rxd
[i
].next_desc
- (u32
) sp
->rxd
;
124 printk(KERN_INFO
"%2.2x %4.4x RFDNextPtr = %16.16lx\n", i
,
125 offset
, (unsigned long) sp
->rxd
[i
].next_desc
);
126 offset
= (u32
) &sp
->rxd
[i
].rfs
- (u32
) sp
->rxd
;
127 printk(KERN_INFO
"%2.2x %4.4x RFS = %16.16lx\n", i
,
128 offset
, (unsigned long) sp
->rxd
[i
].rfs
);
129 offset
= (u32
) &sp
->rxd
[i
].frag_info
- (u32
) sp
->rxd
;
130 printk(KERN_INFO
"%2.2x %4.4x frag_info = %16.16lx\n", i
,
131 offset
, (unsigned long) sp
->rxd
[i
].frag_info
);
135 static void ipg_dump_tfdlist(struct net_device
*dev
)
137 struct ipg_nic_private
*sp
= netdev_priv(dev
);
138 void __iomem
*ioaddr
= sp
->ioaddr
;
142 IPG_DEBUG_MSG("_dump_tfdlist\n");
144 printk(KERN_INFO
"tx_current = %2.2x\n", sp
->tx_current
);
145 printk(KERN_INFO
"tx_dirty = %2.2x\n", sp
->tx_dirty
);
146 printk(KERN_INFO
"TFDList start address = %16.16lx\n",
147 (unsigned long) sp
->txd_map
);
148 printk(KERN_INFO
"TFDListPtr register = %8.8x%8.8x\n",
149 ipg_r32(IPG_TFDLISTPTR1
), ipg_r32(IPG_TFDLISTPTR0
));
151 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
152 offset
= (u32
) &sp
->txd
[i
].next_desc
- (u32
) sp
->txd
;
153 printk(KERN_INFO
"%2.2x %4.4x TFDNextPtr = %16.16lx\n", i
,
154 offset
, (unsigned long) sp
->txd
[i
].next_desc
);
156 offset
= (u32
) &sp
->txd
[i
].tfc
- (u32
) sp
->txd
;
157 printk(KERN_INFO
"%2.2x %4.4x TFC = %16.16lx\n", i
,
158 offset
, (unsigned long) sp
->txd
[i
].tfc
);
159 offset
= (u32
) &sp
->txd
[i
].frag_info
- (u32
) sp
->txd
;
160 printk(KERN_INFO
"%2.2x %4.4x frag_info = %16.16lx\n", i
,
161 offset
, (unsigned long) sp
->txd
[i
].frag_info
);
166 static void ipg_write_phy_ctl(void __iomem
*ioaddr
, u8 data
)
168 ipg_w8(IPG_PC_RSVD_MASK
& data
, PHY_CTRL
);
169 ndelay(IPG_PC_PHYCTRLWAIT_NS
);
172 static void ipg_drive_phy_ctl_low_high(void __iomem
*ioaddr
, u8 data
)
174 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| data
);
175 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| data
);
178 static void send_three_state(void __iomem
*ioaddr
, u8 phyctrlpolarity
)
180 phyctrlpolarity
|= (IPG_PC_MGMTDATA
& 0) | IPG_PC_MGMTDIR
;
182 ipg_drive_phy_ctl_low_high(ioaddr
, phyctrlpolarity
);
185 static void send_end(void __iomem
*ioaddr
, u8 phyctrlpolarity
)
187 ipg_w8((IPG_PC_MGMTCLK_LO
| (IPG_PC_MGMTDATA
& 0) | IPG_PC_MGMTDIR
|
188 phyctrlpolarity
) & IPG_PC_RSVD_MASK
, PHY_CTRL
);
191 static u16
read_phy_bit(void __iomem
* ioaddr
, u8 phyctrlpolarity
)
195 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| phyctrlpolarity
);
197 bit_data
= ((ipg_r8(PHY_CTRL
) & IPG_PC_MGMTDATA
) >> 1) & 1;
199 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| phyctrlpolarity
);
205 * Read a register from the Physical Layer device located
206 * on the IPG NIC, using the IPG PHYCTRL register.
208 static int mdio_read(struct net_device
* dev
, int phy_id
, int phy_reg
)
210 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
212 * The GMII mangement frame structure for a read is as follows:
214 * |Preamble|st|op|phyad|regad|ta| data |idle|
215 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
217 * <32 1s> = 32 consecutive logic 1 values
218 * A = bit of Physical Layer device address (MSB first)
219 * R = bit of register address (MSB first)
220 * z = High impedance state
221 * D = bit of read data (MSB first)
223 * Transmission order is 'Preamble' field first, bits transmitted
224 * left to right (first to last).
230 { GMII_PREAMBLE
, 32 }, /* Preamble */
231 { GMII_ST
, 2 }, /* ST */
232 { GMII_READ
, 2 }, /* OP */
233 { phy_id
, 5 }, /* PHYAD */
234 { phy_reg
, 5 }, /* REGAD */
235 { 0x0000, 2 }, /* TA */
236 { 0x0000, 16 }, /* DATA */
237 { 0x0000, 1 } /* IDLE */
242 polarity
= ipg_r8(PHY_CTRL
);
243 polarity
&= (IPG_PC_DUPLEX_POLARITY
| IPG_PC_LINK_POLARITY
);
245 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
246 for (j
= 0; j
< 5; j
++) {
247 for (i
= 0; i
< p
[j
].len
; i
++) {
248 /* For each variable length field, the MSB must be
249 * transmitted first. Rotate through the field bits,
250 * starting with the MSB, and move each bit into the
251 * the 1st (2^1) bit position (this is the bit position
252 * corresponding to the MgmtData bit of the PhyCtrl
253 * register for the IPG).
257 * First write a '0' to bit 1 of the PhyCtrl
258 * register, then write a '1' to bit 1 of the
261 * To do this, right shift the MSB of ST by the value:
262 * [field length - 1 - #ST bits already written]
263 * then left shift this result by 1.
265 data
= (p
[j
].field
>> (p
[j
].len
- 1 - i
)) << 1;
266 data
&= IPG_PC_MGMTDATA
;
267 data
|= polarity
| IPG_PC_MGMTDIR
;
269 ipg_drive_phy_ctl_low_high(ioaddr
, data
);
273 send_three_state(ioaddr
, polarity
);
275 read_phy_bit(ioaddr
, polarity
);
278 * For a read cycle, the bits for the next two fields (TA and
279 * DATA) are driven by the PHY (the IPG reads these bits).
281 for (i
= 0; i
< p
[6].len
; i
++) {
283 (read_phy_bit(ioaddr
, polarity
) << (p
[6].len
- 1 - i
));
286 send_three_state(ioaddr
, polarity
);
287 send_three_state(ioaddr
, polarity
);
288 send_three_state(ioaddr
, polarity
);
289 send_end(ioaddr
, polarity
);
291 /* Return the value of the DATA field. */
296 * Write to a register from the Physical Layer device located
297 * on the IPG NIC, using the IPG PHYCTRL register.
299 static void mdio_write(struct net_device
*dev
, int phy_id
, int phy_reg
, int val
)
301 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
303 * The GMII mangement frame structure for a read is as follows:
305 * |Preamble|st|op|phyad|regad|ta| data |idle|
306 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
308 * <32 1s> = 32 consecutive logic 1 values
309 * A = bit of Physical Layer device address (MSB first)
310 * R = bit of register address (MSB first)
311 * z = High impedance state
312 * D = bit of write data (MSB first)
314 * Transmission order is 'Preamble' field first, bits transmitted
315 * left to right (first to last).
321 { GMII_PREAMBLE
, 32 }, /* Preamble */
322 { GMII_ST
, 2 }, /* ST */
323 { GMII_WRITE
, 2 }, /* OP */
324 { phy_id
, 5 }, /* PHYAD */
325 { phy_reg
, 5 }, /* REGAD */
326 { 0x0002, 2 }, /* TA */
327 { val
& 0xffff, 16 }, /* DATA */
328 { 0x0000, 1 } /* IDLE */
333 polarity
= ipg_r8(PHY_CTRL
);
334 polarity
&= (IPG_PC_DUPLEX_POLARITY
| IPG_PC_LINK_POLARITY
);
336 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
337 for (j
= 0; j
< 7; j
++) {
338 for (i
= 0; i
< p
[j
].len
; i
++) {
339 /* For each variable length field, the MSB must be
340 * transmitted first. Rotate through the field bits,
341 * starting with the MSB, and move each bit into the
342 * the 1st (2^1) bit position (this is the bit position
343 * corresponding to the MgmtData bit of the PhyCtrl
344 * register for the IPG).
348 * First write a '0' to bit 1 of the PhyCtrl
349 * register, then write a '1' to bit 1 of the
352 * To do this, right shift the MSB of ST by the value:
353 * [field length - 1 - #ST bits already written]
354 * then left shift this result by 1.
356 data
= (p
[j
].field
>> (p
[j
].len
- 1 - i
)) << 1;
357 data
&= IPG_PC_MGMTDATA
;
358 data
|= polarity
| IPG_PC_MGMTDIR
;
360 ipg_drive_phy_ctl_low_high(ioaddr
, data
);
364 /* The last cycle is a tri-state, so read from the PHY. */
365 for (j
= 7; j
< 8; j
++) {
366 for (i
= 0; i
< p
[j
].len
; i
++) {
367 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| polarity
);
369 p
[j
].field
|= ((ipg_r8(PHY_CTRL
) &
370 IPG_PC_MGMTDATA
) >> 1) << (p
[j
].len
- 1 - i
);
372 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| polarity
);
377 /* Set LED_Mode JES20040127EEPROM */
378 static void ipg_set_led_mode(struct net_device
*dev
)
380 struct ipg_nic_private
*sp
= netdev_priv(dev
);
381 void __iomem
*ioaddr
= sp
->ioaddr
;
384 mode
= ipg_r32(ASIC_CTRL
);
385 mode
&= ~(IPG_AC_LED_MODE_BIT_1
| IPG_AC_LED_MODE
| IPG_AC_LED_SPEED
);
387 if ((sp
->LED_Mode
& 0x03) > 1)
388 mode
|= IPG_AC_LED_MODE_BIT_1
; /* Write Asic Control Bit 29 */
390 if ((sp
->LED_Mode
& 0x01) == 1)
391 mode
|= IPG_AC_LED_MODE
; /* Write Asic Control Bit 14 */
393 if ((sp
->LED_Mode
& 0x08) == 8)
394 mode
|= IPG_AC_LED_SPEED
; /* Write Asic Control Bit 27 */
396 ipg_w32(mode
, ASIC_CTRL
);
399 /* Set PHYSet JES20040127EEPROM */
400 static void ipg_set_phy_set(struct net_device
*dev
)
402 struct ipg_nic_private
*sp
= netdev_priv(dev
);
403 void __iomem
*ioaddr
= sp
->ioaddr
;
406 physet
= ipg_r8(PHY_SET
);
407 physet
&= ~(IPG_PS_MEM_LENB9B
| IPG_PS_MEM_LEN9
| IPG_PS_NON_COMPDET
);
408 physet
|= ((sp
->LED_Mode
& 0x70) >> 4);
409 ipg_w8(physet
, PHY_SET
);
412 static int ipg_reset(struct net_device
*dev
, u32 resetflags
)
414 /* Assert functional resets via the IPG AsicCtrl
415 * register as specified by the 'resetflags' input
418 void __iomem
*ioaddr
= ipg_ioaddr(dev
); //JES20040127EEPROM:
419 unsigned int timeout_count
= 0;
421 IPG_DEBUG_MSG("_reset\n");
423 ipg_w32(ipg_r32(ASIC_CTRL
) | resetflags
, ASIC_CTRL
);
425 /* Delay added to account for problem with 10Mbps reset. */
426 mdelay(IPG_AC_RESETWAIT
);
428 while (IPG_AC_RESET_BUSY
& ipg_r32(ASIC_CTRL
)) {
429 mdelay(IPG_AC_RESETWAIT
);
430 if (++timeout_count
> IPG_AC_RESET_TIMEOUT
)
433 /* Set LED Mode in Asic Control JES20040127EEPROM */
434 ipg_set_led_mode(dev
);
436 /* Set PHYSet Register Value JES20040127EEPROM */
437 ipg_set_phy_set(dev
);
441 /* Find the GMII PHY address. */
442 static int ipg_find_phyaddr(struct net_device
*dev
)
444 unsigned int phyaddr
, i
;
446 for (i
= 0; i
< 32; i
++) {
449 /* Search for the correct PHY address among 32 possible. */
450 phyaddr
= (IPG_NIC_PHY_ADDRESS
+ i
) % 32;
452 /* 10/22/03 Grace change verify from GMII_PHY_STATUS to
456 status
= mdio_read(dev
, phyaddr
, MII_BMSR
);
458 if ((status
!= 0xFFFF) && (status
!= 0))
466 * Configure IPG based on result of IEEE 802.3 PHY
469 static int ipg_config_autoneg(struct net_device
*dev
)
471 struct ipg_nic_private
*sp
= netdev_priv(dev
);
472 void __iomem
*ioaddr
= sp
->ioaddr
;
473 unsigned int txflowcontrol
;
474 unsigned int rxflowcontrol
;
475 unsigned int fullduplex
;
481 IPG_DEBUG_MSG("_config_autoneg\n");
483 asicctrl
= ipg_r32(ASIC_CTRL
);
484 phyctrl
= ipg_r8(PHY_CTRL
);
485 mac_ctrl_val
= ipg_r32(MAC_CTRL
);
487 /* Set flags for use in resolving auto-negotation, assuming
488 * non-1000Mbps, half duplex, no flow control.
495 /* To accomodate a problem in 10Mbps operation,
496 * set a global flag if PHY running in 10Mbps mode.
500 printk(KERN_INFO
"%s: Link speed = ", dev
->name
);
502 /* Determine actual speed of operation. */
503 switch (phyctrl
& IPG_PC_LINK_SPEED
) {
504 case IPG_PC_LINK_SPEED_10MBPS
:
506 printk(KERN_INFO
"%s: 10Mbps operational mode enabled.\n",
510 case IPG_PC_LINK_SPEED_100MBPS
:
511 printk("100Mbps.\n");
513 case IPG_PC_LINK_SPEED_1000MBPS
:
514 printk("1000Mbps.\n");
518 printk("undefined!\n");
522 if (phyctrl
& IPG_PC_DUPLEX_STATUS
) {
528 /* Configure full duplex, and flow control. */
529 if (fullduplex
== 1) {
530 /* Configure IPG for full duplex operation. */
531 printk(KERN_INFO
"%s: setting full duplex, ", dev
->name
);
533 mac_ctrl_val
|= IPG_MC_DUPLEX_SELECT_FD
;
535 if (txflowcontrol
== 1) {
536 printk("TX flow control");
537 mac_ctrl_val
|= IPG_MC_TX_FLOW_CONTROL_ENABLE
;
539 printk("no TX flow control");
540 mac_ctrl_val
&= ~IPG_MC_TX_FLOW_CONTROL_ENABLE
;
543 if (rxflowcontrol
== 1) {
544 printk(", RX flow control.");
545 mac_ctrl_val
|= IPG_MC_RX_FLOW_CONTROL_ENABLE
;
547 printk(", no RX flow control.");
548 mac_ctrl_val
&= ~IPG_MC_RX_FLOW_CONTROL_ENABLE
;
553 /* Configure IPG for half duplex operation. */
554 printk(KERN_INFO
"%s: setting half duplex, "
555 "no TX flow control, no RX flow control.\n", dev
->name
);
557 mac_ctrl_val
&= ~IPG_MC_DUPLEX_SELECT_FD
&
558 ~IPG_MC_TX_FLOW_CONTROL_ENABLE
&
559 ~IPG_MC_RX_FLOW_CONTROL_ENABLE
;
561 ipg_w32(mac_ctrl_val
, MAC_CTRL
);
565 /* Determine and configure multicast operation and set
566 * receive mode for IPG.
568 static void ipg_nic_set_multicast_list(struct net_device
*dev
)
570 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
571 struct dev_mc_list
*mc_list_ptr
;
572 unsigned int hashindex
;
576 IPG_DEBUG_MSG("_nic_set_multicast_list\n");
578 receivemode
= IPG_RM_RECEIVEUNICAST
| IPG_RM_RECEIVEBROADCAST
;
580 if (dev
->flags
& IFF_PROMISC
) {
581 /* NIC to be configured in promiscuous mode. */
582 receivemode
= IPG_RM_RECEIVEALLFRAMES
;
583 } else if ((dev
->flags
& IFF_ALLMULTI
) ||
584 (dev
->flags
& IFF_MULTICAST
&
585 (dev
->mc_count
> IPG_MULTICAST_HASHTABLE_SIZE
))) {
586 /* NIC to be configured to receive all multicast
588 receivemode
|= IPG_RM_RECEIVEMULTICAST
;
589 } else if (dev
->flags
& IFF_MULTICAST
& (dev
->mc_count
> 0)) {
590 /* NIC to be configured to receive selected
591 * multicast addresses. */
592 receivemode
|= IPG_RM_RECEIVEMULTICASTHASH
;
595 /* Calculate the bits to set for the 64 bit, IPG HASHTABLE.
596 * The IPG applies a cyclic-redundancy-check (the same CRC
597 * used to calculate the frame data FCS) to the destination
598 * address all incoming multicast frames whose destination
599 * address has the multicast bit set. The least significant
600 * 6 bits of the CRC result are used as an addressing index
601 * into the hash table. If the value of the bit addressed by
602 * this index is a 1, the frame is passed to the host system.
605 /* Clear hashtable. */
606 hashtable
[0] = 0x00000000;
607 hashtable
[1] = 0x00000000;
609 /* Cycle through all multicast addresses to filter. */
610 for (mc_list_ptr
= dev
->mc_list
;
611 mc_list_ptr
!= NULL
; mc_list_ptr
= mc_list_ptr
->next
) {
612 /* Calculate CRC result for each multicast address. */
613 hashindex
= crc32_le(0xffffffff, mc_list_ptr
->dmi_addr
,
616 /* Use only the least significant 6 bits. */
617 hashindex
= hashindex
& 0x3F;
619 /* Within "hashtable", set bit number "hashindex"
622 set_bit(hashindex
, (void *)hashtable
);
625 /* Write the value of the hashtable, to the 4, 16 bit
626 * HASHTABLE IPG registers.
628 ipg_w32(hashtable
[0], HASHTABLE_0
);
629 ipg_w32(hashtable
[1], HASHTABLE_1
);
631 ipg_w8(IPG_RM_RSVD_MASK
& receivemode
, RECEIVE_MODE
);
633 IPG_DEBUG_MSG("ReceiveMode = %x\n", ipg_r8(RECEIVE_MODE
));
636 static int ipg_io_config(struct net_device
*dev
)
638 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
642 IPG_DEBUG_MSG("_io_config\n");
644 origmacctrl
= ipg_r32(MAC_CTRL
);
646 restoremacctrl
= origmacctrl
| IPG_MC_STATISTICS_ENABLE
;
648 /* Based on compilation option, determine if FCS is to be
649 * stripped on receive frames by IPG.
651 if (!IPG_STRIP_FCS_ON_RX
)
652 restoremacctrl
|= IPG_MC_RCV_FCS
;
654 /* Determine if transmitter and/or receiver are
655 * enabled so we may restore MACCTRL correctly.
657 if (origmacctrl
& IPG_MC_TX_ENABLED
)
658 restoremacctrl
|= IPG_MC_TX_ENABLE
;
660 if (origmacctrl
& IPG_MC_RX_ENABLED
)
661 restoremacctrl
|= IPG_MC_RX_ENABLE
;
663 /* Transmitter and receiver must be disabled before setting
666 ipg_w32((origmacctrl
& (IPG_MC_RX_DISABLE
| IPG_MC_TX_DISABLE
)) &
667 IPG_MC_RSVD_MASK
, MAC_CTRL
);
669 /* Now that transmitter and receiver are disabled, write
672 ipg_w32((origmacctrl
& IPG_MC_IFS_96BIT
) & IPG_MC_RSVD_MASK
, MAC_CTRL
);
674 /* Set RECEIVEMODE register. */
675 ipg_nic_set_multicast_list(dev
);
677 ipg_w16(IPG_MAX_RXFRAME_SIZE
, MAX_FRAME_SIZE
);
679 ipg_w8(IPG_RXDMAPOLLPERIOD_VALUE
, RX_DMA_POLL_PERIOD
);
680 ipg_w8(IPG_RXDMAURGENTTHRESH_VALUE
, RX_DMA_URGENT_THRESH
);
681 ipg_w8(IPG_RXDMABURSTTHRESH_VALUE
, RX_DMA_BURST_THRESH
);
682 ipg_w8(IPG_TXDMAPOLLPERIOD_VALUE
, TX_DMA_POLL_PERIOD
);
683 ipg_w8(IPG_TXDMAURGENTTHRESH_VALUE
, TX_DMA_URGENT_THRESH
);
684 ipg_w8(IPG_TXDMABURSTTHRESH_VALUE
, TX_DMA_BURST_THRESH
);
685 ipg_w16((IPG_IE_HOST_ERROR
| IPG_IE_TX_DMA_COMPLETE
|
686 IPG_IE_TX_COMPLETE
| IPG_IE_INT_REQUESTED
|
687 IPG_IE_UPDATE_STATS
| IPG_IE_LINK_EVENT
|
688 IPG_IE_RX_DMA_COMPLETE
| IPG_IE_RX_DMA_PRIORITY
), INT_ENABLE
);
689 ipg_w16(IPG_FLOWONTHRESH_VALUE
, FLOW_ON_THRESH
);
690 ipg_w16(IPG_FLOWOFFTHRESH_VALUE
, FLOW_OFF_THRESH
);
692 /* IPG multi-frag frame bug workaround.
693 * Per silicon revision B3 eratta.
695 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0200, DEBUG_CTRL
);
697 /* IPG TX poll now bug workaround.
698 * Per silicon revision B3 eratta.
700 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0010, DEBUG_CTRL
);
702 /* IPG RX poll now bug workaround.
703 * Per silicon revision B3 eratta.
705 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0020, DEBUG_CTRL
);
707 /* Now restore MACCTRL to original setting. */
708 ipg_w32(IPG_MC_RSVD_MASK
& restoremacctrl
, MAC_CTRL
);
710 /* Disable unused RMON statistics. */
711 ipg_w32(IPG_RZ_ALL
, RMON_STATISTICS_MASK
);
713 /* Disable unused MIB statistics. */
714 ipg_w32(IPG_SM_MACCONTROLFRAMESXMTD
| IPG_SM_MACCONTROLFRAMESRCVD
|
715 IPG_SM_BCSTOCTETXMTOK_BCSTFRAMESXMTDOK
| IPG_SM_TXJUMBOFRAMES
|
716 IPG_SM_MCSTOCTETXMTOK_MCSTFRAMESXMTDOK
| IPG_SM_RXJUMBOFRAMES
|
717 IPG_SM_BCSTOCTETRCVDOK_BCSTFRAMESRCVDOK
|
718 IPG_SM_UDPCHECKSUMERRORS
| IPG_SM_TCPCHECKSUMERRORS
|
719 IPG_SM_IPCHECKSUMERRORS
, STATISTICS_MASK
);
725 * Create a receive buffer within system memory and update
726 * NIC private structure appropriately.
728 static int ipg_get_rxbuff(struct net_device
*dev
, int entry
)
730 struct ipg_nic_private
*sp
= netdev_priv(dev
);
731 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
735 IPG_DEBUG_MSG("_get_rxbuff\n");
737 skb
= netdev_alloc_skb(dev
, IPG_RXSUPPORT_SIZE
+ NET_IP_ALIGN
);
739 sp
->RxBuff
[entry
] = NULL
;
743 /* Adjust the data start location within the buffer to
744 * align IP address field to a 16 byte boundary.
746 skb_reserve(skb
, NET_IP_ALIGN
);
748 /* Associate the receive buffer with the IPG NIC. */
751 /* Save the address of the sk_buff structure. */
752 sp
->RxBuff
[entry
] = skb
;
754 rxfd
->frag_info
= cpu_to_le64(pci_map_single(sp
->pdev
, skb
->data
,
755 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
));
757 /* Set the RFD fragment length. */
758 rxfragsize
= IPG_RXFRAG_SIZE
;
759 rxfd
->frag_info
|= cpu_to_le64((rxfragsize
<< 48) & IPG_RFI_FRAGLEN
);
764 static int init_rfdlist(struct net_device
*dev
)
766 struct ipg_nic_private
*sp
= netdev_priv(dev
);
767 void __iomem
*ioaddr
= sp
->ioaddr
;
770 IPG_DEBUG_MSG("_init_rfdlist\n");
772 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
773 struct ipg_rx
*rxfd
= sp
->rxd
+ i
;
776 pci_unmap_single(sp
->pdev
,
777 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
778 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
779 IPG_DEV_KFREE_SKB(sp
->RxBuff
[i
]);
780 sp
->RxBuff
[i
] = NULL
;
783 /* Clear out the RFS field. */
784 rxfd
->rfs
= 0x0000000000000000;
786 if (ipg_get_rxbuff(dev
, i
) < 0) {
788 * A receive buffer was not ready, break the
791 IPG_DEBUG_MSG("Cannot allocate Rx buffer.\n");
793 /* Just in case we cannot allocate a single RFD.
797 printk(KERN_ERR
"%s: No memory available"
798 " for RFD list.\n", dev
->name
);
803 rxfd
->next_desc
= cpu_to_le64(sp
->rxd_map
+
804 sizeof(struct ipg_rx
)*(i
+ 1));
806 sp
->rxd
[i
- 1].next_desc
= cpu_to_le64(sp
->rxd_map
);
811 /* Write the location of the RFDList to the IPG. */
812 ipg_w32((u32
) sp
->rxd_map
, RFD_LIST_PTR_0
);
813 ipg_w32(0x00000000, RFD_LIST_PTR_1
);
818 static void init_tfdlist(struct net_device
*dev
)
820 struct ipg_nic_private
*sp
= netdev_priv(dev
);
821 void __iomem
*ioaddr
= sp
->ioaddr
;
824 IPG_DEBUG_MSG("_init_tfdlist\n");
826 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
827 struct ipg_tx
*txfd
= sp
->txd
+ i
;
829 txfd
->tfc
= cpu_to_le64(IPG_TFC_TFDDONE
);
832 IPG_DEV_KFREE_SKB(sp
->TxBuff
[i
]);
833 sp
->TxBuff
[i
] = NULL
;
836 txfd
->next_desc
= cpu_to_le64(sp
->txd_map
+
837 sizeof(struct ipg_tx
)*(i
+ 1));
839 sp
->txd
[i
- 1].next_desc
= cpu_to_le64(sp
->txd_map
);
844 /* Write the location of the TFDList to the IPG. */
845 IPG_DDEBUG_MSG("Starting TFDListPtr = %8.8x\n",
847 ipg_w32((u32
) sp
->txd_map
, TFD_LIST_PTR_0
);
848 ipg_w32(0x00000000, TFD_LIST_PTR_1
);
850 sp
->ResetCurrentTFD
= 1;
854 * Free all transmit buffers which have already been transfered
855 * via DMA to the IPG.
857 static void ipg_nic_txfree(struct net_device
*dev
)
859 struct ipg_nic_private
*sp
= netdev_priv(dev
);
860 void __iomem
*ioaddr
= sp
->ioaddr
;
863 unsigned int released
, pending
;
865 txd_map
= (u64
)sp
->txd_map
;
866 curr
= ipg_r32(TFD_LIST_PTR_0
) -
867 do_div(txd_map
, sizeof(struct ipg_tx
)) - 1;
869 IPG_DEBUG_MSG("_nic_txfree\n");
871 pending
= sp
->tx_current
- sp
->tx_dirty
;
873 for (released
= 0; released
< pending
; released
++) {
874 unsigned int dirty
= sp
->tx_dirty
% IPG_TFDLIST_LENGTH
;
875 struct sk_buff
*skb
= sp
->TxBuff
[dirty
];
876 struct ipg_tx
*txfd
= sp
->txd
+ dirty
;
878 IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd
->tfc
);
880 /* Look at each TFD's TFC field beginning
881 * at the last freed TFD up to the current TFD.
882 * If the TFDDone bit is set, free the associated
888 /* Setup TFDDONE for compatible issue. */
889 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TFDDONE
);
891 /* Free the transmit buffer. */
893 pci_unmap_single(sp
->pdev
,
894 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
895 skb
->len
, PCI_DMA_TODEVICE
);
897 IPG_DEV_KFREE_SKB(skb
);
899 sp
->TxBuff
[dirty
] = NULL
;
903 sp
->tx_dirty
+= released
;
905 if (netif_queue_stopped(dev
) &&
906 (sp
->tx_current
!= (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))) {
907 netif_wake_queue(dev
);
911 static void ipg_tx_timeout(struct net_device
*dev
)
913 struct ipg_nic_private
*sp
= netdev_priv(dev
);
914 void __iomem
*ioaddr
= sp
->ioaddr
;
916 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
| IPG_AC_NETWORK
|
919 spin_lock_irq(&sp
->lock
);
921 /* Re-configure after DMA reset. */
922 if (ipg_io_config(dev
) < 0) {
923 printk(KERN_INFO
"%s: Error during re-configuration.\n",
929 spin_unlock_irq(&sp
->lock
);
931 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) & IPG_MC_RSVD_MASK
,
936 * For TxComplete interrupts, free all transmit
937 * buffers which have already been transfered via DMA
940 static void ipg_nic_txcleanup(struct net_device
*dev
)
942 struct ipg_nic_private
*sp
= netdev_priv(dev
);
943 void __iomem
*ioaddr
= sp
->ioaddr
;
946 IPG_DEBUG_MSG("_nic_txcleanup\n");
948 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
949 /* Reading the TXSTATUS register clears the
950 * TX_COMPLETE interrupt.
952 u32 txstatusdword
= ipg_r32(TX_STATUS
);
954 IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword
);
956 /* Check for Transmit errors. Error bits only valid if
957 * TX_COMPLETE bit in the TXSTATUS register is a 1.
959 if (!(txstatusdword
& IPG_TS_TX_COMPLETE
))
962 /* If in 10Mbps mode, indicate transmit is ready. */
963 if (sp
->tenmbpsmode
) {
964 netif_wake_queue(dev
);
967 /* Transmit error, increment stat counters. */
968 if (txstatusdword
& IPG_TS_TX_ERROR
) {
969 IPG_DEBUG_MSG("Transmit error.\n");
970 sp
->stats
.tx_errors
++;
973 /* Late collision, re-enable transmitter. */
974 if (txstatusdword
& IPG_TS_LATE_COLLISION
) {
975 IPG_DEBUG_MSG("Late collision on transmit.\n");
976 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
977 IPG_MC_RSVD_MASK
, MAC_CTRL
);
980 /* Maximum collisions, re-enable transmitter. */
981 if (txstatusdword
& IPG_TS_TX_MAX_COLL
) {
982 IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
983 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
984 IPG_MC_RSVD_MASK
, MAC_CTRL
);
987 /* Transmit underrun, reset and re-enable
990 if (txstatusdword
& IPG_TS_TX_UNDERRUN
) {
991 IPG_DEBUG_MSG("Transmitter underrun.\n");
992 sp
->stats
.tx_fifo_errors
++;
993 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
|
994 IPG_AC_NETWORK
| IPG_AC_FIFO
);
996 /* Re-configure after DMA reset. */
997 if (ipg_io_config(dev
) < 0) {
999 "%s: Error during re-configuration.\n",
1004 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
1005 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1009 ipg_nic_txfree(dev
);
1012 /* Provides statistical information about the IPG NIC. */
1013 static struct net_device_stats
*ipg_nic_get_stats(struct net_device
*dev
)
1015 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1016 void __iomem
*ioaddr
= sp
->ioaddr
;
1020 IPG_DEBUG_MSG("_nic_get_stats\n");
1022 /* Check to see if the NIC has been initialized via nic_open,
1023 * before trying to read statistic registers.
1025 if (!test_bit(__LINK_STATE_START
, &dev
->state
))
1028 sp
->stats
.rx_packets
+= ipg_r32(IPG_FRAMESRCVDOK
);
1029 sp
->stats
.tx_packets
+= ipg_r32(IPG_FRAMESXMTDOK
);
1030 sp
->stats
.rx_bytes
+= ipg_r32(IPG_OCTETRCVOK
);
1031 sp
->stats
.tx_bytes
+= ipg_r32(IPG_OCTETXMTOK
);
1032 temp1
= ipg_r16(IPG_FRAMESLOSTRXERRORS
);
1033 sp
->stats
.rx_errors
+= temp1
;
1034 sp
->stats
.rx_missed_errors
+= temp1
;
1035 temp1
= ipg_r32(IPG_SINGLECOLFRAMES
) + ipg_r32(IPG_MULTICOLFRAMES
) +
1036 ipg_r32(IPG_LATECOLLISIONS
);
1037 temp2
= ipg_r16(IPG_CARRIERSENSEERRORS
);
1038 sp
->stats
.collisions
+= temp1
;
1039 sp
->stats
.tx_dropped
+= ipg_r16(IPG_FRAMESABORTXSCOLLS
);
1040 sp
->stats
.tx_errors
+= ipg_r16(IPG_FRAMESWEXDEFERRAL
) +
1041 ipg_r32(IPG_FRAMESWDEFERREDXMT
) + temp1
+ temp2
;
1042 sp
->stats
.multicast
+= ipg_r32(IPG_MCSTOCTETRCVDOK
);
1044 /* detailed tx_errors */
1045 sp
->stats
.tx_carrier_errors
+= temp2
;
1047 /* detailed rx_errors */
1048 sp
->stats
.rx_length_errors
+= ipg_r16(IPG_INRANGELENGTHERRORS
) +
1049 ipg_r16(IPG_FRAMETOOLONGERRRORS
);
1050 sp
->stats
.rx_crc_errors
+= ipg_r16(IPG_FRAMECHECKSEQERRORS
);
1052 /* Unutilized IPG statistic registers. */
1053 ipg_r32(IPG_MCSTFRAMESRCVDOK
);
1058 /* Restore used receive buffers. */
1059 static int ipg_nic_rxrestore(struct net_device
*dev
)
1061 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1062 const unsigned int curr
= sp
->rx_current
;
1063 unsigned int dirty
= sp
->rx_dirty
;
1065 IPG_DEBUG_MSG("_nic_rxrestore\n");
1067 for (dirty
= sp
->rx_dirty
; curr
- dirty
> 0; dirty
++) {
1068 unsigned int entry
= dirty
% IPG_RFDLIST_LENGTH
;
1070 /* rx_copybreak may poke hole here and there. */
1071 if (sp
->RxBuff
[entry
])
1074 /* Generate a new receive buffer to replace the
1075 * current buffer (which will be released by the
1078 if (ipg_get_rxbuff(dev
, entry
) < 0) {
1079 IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
1084 /* Reset the RFS field. */
1085 sp
->rxd
[entry
].rfs
= 0x0000000000000000;
1087 sp
->rx_dirty
= dirty
;
1094 /* use jumboindex and jumbosize to control jumbo frame status
1095 initial status is jumboindex=-1 and jumbosize=0
1096 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
1097 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
1098 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
1099 previous receiving and need to continue dumping the current one
1107 Frame_NoStart_NoEnd
= 0,
1108 Frame_WithStart
= 1,
1110 Frame_WithStart_WithEnd
= 11
1113 inline void ipg_nic_rx_free_skb(struct net_device
*dev
)
1115 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1116 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1118 if (sp
->RxBuff
[entry
]) {
1119 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1121 pci_unmap_single(sp
->pdev
,
1122 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1123 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1124 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1125 sp
->RxBuff
[entry
] = NULL
;
1129 inline int ipg_nic_rx_check_frame_type(struct net_device
*dev
)
1131 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1132 struct ipg_rx
*rxfd
= sp
->rxd
+ (sp
->rx_current
% IPG_RFDLIST_LENGTH
);
1133 int type
= Frame_NoStart_NoEnd
;
1135 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
)
1136 type
+= Frame_WithStart
;
1137 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
)
1138 type
+= Frame_WithEnd
;
1142 inline int ipg_nic_rx_check_error(struct net_device
*dev
)
1144 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1145 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1146 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1148 if (IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1149 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1150 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1151 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
))) {
1152 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1153 (unsigned long) rxfd
->rfs
);
1155 /* Increment general receive error statistic. */
1156 sp
->stats
.rx_errors
++;
1158 /* Increment detailed receive error statistics. */
1159 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1160 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1162 sp
->stats
.rx_fifo_errors
++;
1165 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1166 IPG_DEBUG_MSG("RX runt occured.\n");
1167 sp
->stats
.rx_length_errors
++;
1170 /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
1171 * error count handled by a IPG statistic register.
1174 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1175 IPG_DEBUG_MSG("RX alignment error occured.\n");
1176 sp
->stats
.rx_frame_errors
++;
1179 /* Do nothing for IPG_RFS_RXFCSERROR, error count
1180 * handled by a IPG statistic register.
1183 /* Free the memory associated with the RX
1184 * buffer since it is erroneous and we will
1185 * not pass it to higher layer processes.
1187 if (sp
->RxBuff
[entry
]) {
1188 pci_unmap_single(sp
->pdev
,
1189 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1190 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1192 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1193 sp
->RxBuff
[entry
] = NULL
;
1197 return NormalPacket
;
1200 static void ipg_nic_rx_with_start_and_end(struct net_device
*dev
,
1201 struct ipg_nic_private
*sp
,
1202 struct ipg_rx
*rxfd
, unsigned entry
)
1204 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1205 struct sk_buff
*skb
;
1208 if (jumbo
->FoundStart
) {
1209 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1210 jumbo
->FoundStart
= 0;
1211 jumbo
->CurrentSize
= 0;
1215 // 1: found error, 0 no error
1216 if (ipg_nic_rx_check_error(dev
) != NormalPacket
)
1219 skb
= sp
->RxBuff
[entry
];
1223 // accept this frame and send to upper layer
1224 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1225 if (framelen
> IPG_RXFRAG_SIZE
)
1226 framelen
= IPG_RXFRAG_SIZE
;
1228 skb_put(skb
, framelen
);
1229 skb
->protocol
= eth_type_trans(skb
, dev
);
1230 skb
->ip_summed
= CHECKSUM_NONE
;
1232 dev
->last_rx
= jiffies
;
1233 sp
->RxBuff
[entry
] = NULL
;
1236 static void ipg_nic_rx_with_start(struct net_device
*dev
,
1237 struct ipg_nic_private
*sp
,
1238 struct ipg_rx
*rxfd
, unsigned entry
)
1240 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1241 struct pci_dev
*pdev
= sp
->pdev
;
1242 struct sk_buff
*skb
;
1244 // 1: found error, 0 no error
1245 if (ipg_nic_rx_check_error(dev
) != NormalPacket
)
1248 // accept this frame and send to upper layer
1249 skb
= sp
->RxBuff
[entry
];
1253 if (jumbo
->FoundStart
)
1254 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1256 pci_unmap_single(pdev
, le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1257 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1259 skb_put(skb
, IPG_RXFRAG_SIZE
);
1261 jumbo
->FoundStart
= 1;
1262 jumbo
->CurrentSize
= IPG_RXFRAG_SIZE
;
1265 sp
->RxBuff
[entry
] = NULL
;
1266 dev
->last_rx
= jiffies
;
1269 static void ipg_nic_rx_with_end(struct net_device
*dev
,
1270 struct ipg_nic_private
*sp
,
1271 struct ipg_rx
*rxfd
, unsigned entry
)
1273 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1275 //1: found error, 0 no error
1276 if (ipg_nic_rx_check_error(dev
) == NormalPacket
) {
1277 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1282 if (jumbo
->FoundStart
) {
1283 int framelen
, endframelen
;
1285 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1287 endframeLen
= framelen
- jumbo
->CurrentSize
;
1289 if (framelen > IPG_RXFRAG_SIZE)
1290 framelen=IPG_RXFRAG_SIZE;
1292 if (framelen
> IPG_RXSUPPORT_SIZE
)
1293 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1295 memcpy(skb_put(jumbo
->skb
, endframeLen
),
1296 skb
->data
, endframeLen
);
1298 jumbo
->skb
->protocol
=
1299 eth_type_trans(jumbo
->skb
, dev
);
1301 jumbo
->skb
->ip_summed
= CHECKSUM_NONE
;
1302 netif_rx(jumbo
->skb
);
1306 dev
->last_rx
= jiffies
;
1307 jumbo
->FoundStart
= 0;
1308 jumbo
->CurrentSize
= 0;
1311 ipg_nic_rx_free_skb(dev
);
1313 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1314 jumbo
->FoundStart
= 0;
1315 jumbo
->CurrentSize
= 0;
1320 static void ipg_nic_rx_no_start_no_end(struct net_device
*dev
,
1321 struct ipg_nic_private
*sp
,
1322 struct ipg_rx
*rxfd
, unsigned entry
)
1324 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1326 //1: found error, 0 no error
1327 if (ipg_nic_rx_check_error(dev
) == NormalPacket
) {
1328 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1331 if (jumbo
->FoundStart
) {
1332 jumbo
->CurrentSize
+= IPG_RXFRAG_SIZE
;
1333 if (jumbo
->CurrentSize
<= IPG_RXSUPPORT_SIZE
) {
1334 memcpy(skb_put(jumbo
->skb
,
1336 skb
->data
, IPG_RXFRAG_SIZE
);
1339 dev
->last_rx
= jiffies
;
1340 ipg_nic_rx_free_skb(dev
);
1343 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1344 jumbo
->FoundStart
= 0;
1345 jumbo
->CurrentSize
= 0;
1350 static int ipg_nic_rx(struct net_device
*dev
)
1352 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1353 unsigned int curr
= sp
->rx_current
;
1354 void __iomem
*ioaddr
= sp
->ioaddr
;
1357 IPG_DEBUG_MSG("_nic_rx\n");
1359 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1360 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1361 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1363 if (!(rxfd
->rfs
& le64_to_cpu(IPG_RFS_RFDDONE
)))
1366 switch (ipg_nic_rx_check_frame_type(dev
)) {
1367 case Frame_WithStart_WithEnd
:
1368 ipg_nic_rx_with_start_and_end(dev
, tp
, rxfd
, entry
);
1370 case Frame_WithStart
:
1371 ipg_nic_rx_with_start(dev
, tp
, rxfd
, entry
);
1374 ipg_nic_rx_with_end(dev
, tp
, rxfd
, entry
);
1376 case Frame_NoStart_NoEnd
:
1377 ipg_nic_rx_no_start_no_end(dev
, tp
, rxfd
, entry
);
1382 sp
->rx_current
= curr
;
1384 if (i
== IPG_MAXRFDPROCESS_COUNT
) {
1385 /* There are more RFDs to process, however the
1386 * allocated amount of RFD processing time has
1387 * expired. Assert Interrupt Requested to make
1388 * sure we come back to process the remaining RFDs.
1390 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1393 ipg_nic_rxrestore(dev
);
1399 static int ipg_nic_rx(struct net_device
*dev
)
1401 /* Transfer received Ethernet frames to higher network layers. */
1402 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1403 unsigned int curr
= sp
->rx_current
;
1404 void __iomem
*ioaddr
= sp
->ioaddr
;
1405 struct ipg_rx
*rxfd
;
1408 IPG_DEBUG_MSG("_nic_rx\n");
1410 #define __RFS_MASK \
1411 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1413 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1414 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1415 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1416 unsigned int framelen
;
1418 rxfd
= sp
->rxd
+ entry
;
1420 if (((rxfd
->rfs
& __RFS_MASK
) != __RFS_MASK
) || !skb
)
1423 /* Get received frame length. */
1424 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1426 /* Check for jumbo frame arrival with too small
1429 if (framelen
> IPG_RXFRAG_SIZE
) {
1431 ("RFS FrameLen > allocated fragment size.\n");
1433 framelen
= IPG_RXFRAG_SIZE
;
1436 if ((IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1437 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1438 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1439 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
)))) {
1441 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1442 (unsigned long int) rxfd
->rfs
);
1444 /* Increment general receive error statistic. */
1445 sp
->stats
.rx_errors
++;
1447 /* Increment detailed receive error statistics. */
1448 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1449 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1450 sp
->stats
.rx_fifo_errors
++;
1453 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1454 IPG_DEBUG_MSG("RX runt occured.\n");
1455 sp
->stats
.rx_length_errors
++;
1458 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXOVERSIZEDFRAME
) ;
1459 /* Do nothing, error count handled by a IPG
1460 * statistic register.
1463 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1464 IPG_DEBUG_MSG("RX alignment error occured.\n");
1465 sp
->stats
.rx_frame_errors
++;
1468 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFCSERROR
) ;
1469 /* Do nothing, error count handled by a IPG
1470 * statistic register.
1473 /* Free the memory associated with the RX
1474 * buffer since it is erroneous and we will
1475 * not pass it to higher layer processes.
1478 __le64 info
= rxfd
->frag_info
;
1480 pci_unmap_single(sp
->pdev
,
1481 le64_to_cpu(info
) & ~IPG_RFI_FRAGLEN
,
1482 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1484 IPG_DEV_KFREE_SKB(skb
);
1488 /* Adjust the new buffer length to accomodate the size
1489 * of the received frame.
1491 skb_put(skb
, framelen
);
1493 /* Set the buffer's protocol field to Ethernet. */
1494 skb
->protocol
= eth_type_trans(skb
, dev
);
1496 /* If the frame contains an IP/TCP/UDP frame,
1497 * determine if upper layer must check IP/TCP/UDP
1500 * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
1501 * VERIFICATION FOR SILICON REVISIONS B3
1504 if ((le64_to_cpu(rxfd->rfs &
1505 (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
1506 IPG_RFS_IPDETECTED))) &&
1507 !(le64_to_cpu(rxfd->rfs &
1508 (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
1509 IPG_RFS_IPERROR)))) {
1510 * Indicate IP checksums were performed
1513 skb->ip_summed = CHECKSUM_UNNECESSARY;
1517 /* The IPG encountered an error with (or
1518 * there were no) IP/TCP/UDP checksums.
1519 * This may or may not indicate an invalid
1520 * IP/TCP/UDP frame was received. Let the
1521 * upper layer decide.
1523 skb
->ip_summed
= CHECKSUM_NONE
;
1526 /* Hand off frame for higher layer processing.
1527 * The function netif_rx() releases the sk_buff
1528 * when processing completes.
1532 /* Record frame receive time (jiffies = Linux
1533 * kernel current time stamp).
1535 dev
->last_rx
= jiffies
;
1538 /* Assure RX buffer is not reused by IPG. */
1539 sp
->RxBuff
[entry
] = NULL
;
1543 * If there are more RFDs to proces and the allocated amount of RFD
1544 * processing time has expired, assert Interrupt Requested to make
1545 * sure we come back to process the remaining RFDs.
1547 if (i
== IPG_MAXRFDPROCESS_COUNT
)
1548 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1551 /* Check if the RFD list contained no receive frame data. */
1553 sp
->EmptyRFDListCount
++;
1555 while ((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RFDDONE
) &&
1556 !((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
) &&
1557 (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
))) {
1558 unsigned int entry
= curr
++ % IPG_RFDLIST_LENGTH
;
1560 rxfd
= sp
->rxd
+ entry
;
1562 IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
1564 /* An unexpected event, additional code needed to handle
1565 * properly. So for the time being, just disregard the
1569 /* Free the memory associated with the RX
1570 * buffer since it is erroneous and we will
1571 * not pass it to higher layer processes.
1573 if (sp
->RxBuff
[entry
]) {
1574 pci_unmap_single(sp
->pdev
,
1575 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1576 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1577 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1580 /* Assure RX buffer is not reused by IPG. */
1581 sp
->RxBuff
[entry
] = NULL
;
1584 sp
->rx_current
= curr
;
1586 /* Check to see if there are a minimum number of used
1587 * RFDs before restoring any (should improve performance.)
1589 if ((curr
- sp
->rx_dirty
) >= IPG_MINUSEDRFDSTOFREE
)
1590 ipg_nic_rxrestore(dev
);
1596 static void ipg_reset_after_host_error(struct work_struct
*work
)
1598 struct ipg_nic_private
*sp
=
1599 container_of(work
, struct ipg_nic_private
, task
.work
);
1600 struct net_device
*dev
= sp
->dev
;
1602 IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp
->ioaddr
+ IPG_DMACTRL
));
1605 * Acknowledge HostError interrupt by resetting
1608 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1613 if (ipg_io_config(dev
) < 0) {
1614 printk(KERN_INFO
"%s: Cannot recover from PCI error.\n",
1616 schedule_delayed_work(&sp
->task
, HZ
);
1620 static irqreturn_t
ipg_interrupt_handler(int irq
, void *dev_inst
)
1622 struct net_device
*dev
= dev_inst
;
1623 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1624 void __iomem
*ioaddr
= sp
->ioaddr
;
1625 unsigned int handled
= 0;
1628 IPG_DEBUG_MSG("_interrupt_handler\n");
1631 ipg_nic_rxrestore(dev
);
1633 /* Get interrupt source information, and acknowledge
1634 * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
1635 * IntRequested, MacControlFrame, LinkEvent) interrupts
1636 * if issued. Also, all IPG interrupts are disabled by
1637 * reading IntStatusAck.
1639 status
= ipg_r16(INT_STATUS_ACK
);
1641 IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status
);
1643 /* Shared IRQ of remove event. */
1644 if (!(status
& IPG_IS_RSVD_MASK
))
1649 if (unlikely(!netif_running(dev
)))
1652 spin_lock(&sp
->lock
);
1654 /* If RFDListEnd interrupt, restore all used RFDs. */
1655 if (status
& IPG_IS_RFD_LIST_END
) {
1656 IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
1658 /* The RFD list end indicates an RFD was encountered
1659 * with a 0 NextPtr, or with an RFDDone bit set to 1
1660 * (indicating the RFD is not read for use by the
1661 * IPG.) Try to restore all RFDs.
1663 ipg_nic_rxrestore(dev
);
1666 /* Increment the RFDlistendCount counter. */
1667 sp
->RFDlistendCount
++;
1671 /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
1672 * IntRequested interrupt, process received frames. */
1673 if ((status
& IPG_IS_RX_DMA_PRIORITY
) ||
1674 (status
& IPG_IS_RFD_LIST_END
) ||
1675 (status
& IPG_IS_RX_DMA_COMPLETE
) ||
1676 (status
& IPG_IS_INT_REQUESTED
)) {
1678 /* Increment the RFD list checked counter if interrupted
1679 * only to check the RFD list. */
1680 if (status
& (~(IPG_IS_RX_DMA_PRIORITY
| IPG_IS_RFD_LIST_END
|
1681 IPG_IS_RX_DMA_COMPLETE
| IPG_IS_INT_REQUESTED
) &
1682 (IPG_IS_HOST_ERROR
| IPG_IS_TX_DMA_COMPLETE
|
1683 IPG_IS_LINK_EVENT
| IPG_IS_TX_COMPLETE
|
1684 IPG_IS_UPDATE_STATS
)))
1685 sp
->RFDListCheckedCount
++;
1691 /* If TxDMAComplete interrupt, free used TFDs. */
1692 if (status
& IPG_IS_TX_DMA_COMPLETE
)
1693 ipg_nic_txfree(dev
);
1695 /* TxComplete interrupts indicate one of numerous actions.
1696 * Determine what action to take based on TXSTATUS register.
1698 if (status
& IPG_IS_TX_COMPLETE
)
1699 ipg_nic_txcleanup(dev
);
1701 /* If UpdateStats interrupt, update Linux Ethernet statistics */
1702 if (status
& IPG_IS_UPDATE_STATS
)
1703 ipg_nic_get_stats(dev
);
1705 /* If HostError interrupt, reset IPG. */
1706 if (status
& IPG_IS_HOST_ERROR
) {
1707 IPG_DDEBUG_MSG("HostError Interrupt\n");
1709 schedule_delayed_work(&sp
->task
, 0);
1712 /* If LinkEvent interrupt, resolve autonegotiation. */
1713 if (status
& IPG_IS_LINK_EVENT
) {
1714 if (ipg_config_autoneg(dev
) < 0)
1715 printk(KERN_INFO
"%s: Auto-negotiation error.\n",
1719 /* If MACCtrlFrame interrupt, do nothing. */
1720 if (status
& IPG_IS_MAC_CTRL_FRAME
)
1721 IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
1723 /* If RxComplete interrupt, do nothing. */
1724 if (status
& IPG_IS_RX_COMPLETE
)
1725 IPG_DEBUG_MSG("RxComplete interrupt.\n");
1727 /* If RxEarly interrupt, do nothing. */
1728 if (status
& IPG_IS_RX_EARLY
)
1729 IPG_DEBUG_MSG("RxEarly interrupt.\n");
1732 /* Re-enable IPG interrupts. */
1733 ipg_w16(IPG_IE_TX_DMA_COMPLETE
| IPG_IE_RX_DMA_COMPLETE
|
1734 IPG_IE_HOST_ERROR
| IPG_IE_INT_REQUESTED
| IPG_IE_TX_COMPLETE
|
1735 IPG_IE_LINK_EVENT
| IPG_IE_UPDATE_STATS
, INT_ENABLE
);
1737 spin_unlock(&sp
->lock
);
1739 return IRQ_RETVAL(handled
);
1742 static void ipg_rx_clear(struct ipg_nic_private
*sp
)
1746 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
1747 if (sp
->RxBuff
[i
]) {
1748 struct ipg_rx
*rxfd
= sp
->rxd
+ i
;
1750 IPG_DEV_KFREE_SKB(sp
->RxBuff
[i
]);
1751 sp
->RxBuff
[i
] = NULL
;
1752 pci_unmap_single(sp
->pdev
,
1753 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1754 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1759 static void ipg_tx_clear(struct ipg_nic_private
*sp
)
1763 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
1764 if (sp
->TxBuff
[i
]) {
1765 struct ipg_tx
*txfd
= sp
->txd
+ i
;
1767 pci_unmap_single(sp
->pdev
,
1768 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
1769 sp
->TxBuff
[i
]->len
, PCI_DMA_TODEVICE
);
1771 IPG_DEV_KFREE_SKB(sp
->TxBuff
[i
]);
1773 sp
->TxBuff
[i
] = NULL
;
1778 static int ipg_nic_open(struct net_device
*dev
)
1780 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1781 void __iomem
*ioaddr
= sp
->ioaddr
;
1782 struct pci_dev
*pdev
= sp
->pdev
;
1785 IPG_DEBUG_MSG("_nic_open\n");
1787 sp
->rx_buf_sz
= IPG_RXSUPPORT_SIZE
;
1789 /* Check for interrupt line conflicts, and request interrupt
1792 * IMPORTANT: Disable IPG interrupts prior to registering
1795 ipg_w16(0x0000, INT_ENABLE
);
1797 /* Register the interrupt line to be used by the IPG within
1800 rc
= request_irq(pdev
->irq
, &ipg_interrupt_handler
, IRQF_SHARED
,
1803 printk(KERN_INFO
"%s: Error when requesting interrupt.\n",
1808 dev
->irq
= pdev
->irq
;
1812 sp
->rxd
= dma_alloc_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
,
1813 &sp
->rxd_map
, GFP_KERNEL
);
1815 goto err_free_irq_0
;
1817 sp
->txd
= dma_alloc_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
,
1818 &sp
->txd_map
, GFP_KERNEL
);
1822 rc
= init_rfdlist(dev
);
1824 printk(KERN_INFO
"%s: Error during configuration.\n",
1831 rc
= ipg_io_config(dev
);
1833 printk(KERN_INFO
"%s: Error during configuration.\n",
1835 goto err_release_tfdlist_3
;
1838 /* Resolve autonegotiation. */
1839 if (ipg_config_autoneg(dev
) < 0)
1840 printk(KERN_INFO
"%s: Auto-negotiation error.\n", dev
->name
);
1843 /* initialize JUMBO Frame control variable */
1844 sp
->Jumbo
.FoundStart
= 0;
1845 sp
->Jumbo
.CurrentSize
= 0;
1847 dev
->mtu
= IPG_TXFRAG_SIZE
;
1850 /* Enable transmit and receive operation of the IPG. */
1851 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_RX_ENABLE
| IPG_MC_TX_ENABLE
) &
1852 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1854 netif_start_queue(dev
);
1858 err_release_tfdlist_3
:
1862 dma_free_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1864 dma_free_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1866 free_irq(pdev
->irq
, dev
);
1870 static int ipg_nic_stop(struct net_device
*dev
)
1872 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1873 void __iomem
*ioaddr
= sp
->ioaddr
;
1874 struct pci_dev
*pdev
= sp
->pdev
;
1876 IPG_DEBUG_MSG("_nic_stop\n");
1878 netif_stop_queue(dev
);
1880 IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp
->RFDlistendCount
);
1881 IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp
->rxdCheckedCount
);
1882 IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp
->EmptyRFDListCount
);
1883 IPG_DUMPTFDLIST(dev
);
1886 (void) ipg_r16(INT_STATUS_ACK
);
1888 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1890 synchronize_irq(pdev
->irq
);
1891 } while (ipg_r16(INT_ENABLE
) & IPG_IE_RSVD_MASK
);
1897 pci_free_consistent(pdev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1898 pci_free_consistent(pdev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1900 free_irq(pdev
->irq
, dev
);
1905 static int ipg_nic_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1907 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1908 void __iomem
*ioaddr
= sp
->ioaddr
;
1909 unsigned int entry
= sp
->tx_current
% IPG_TFDLIST_LENGTH
;
1910 unsigned long flags
;
1911 struct ipg_tx
*txfd
;
1913 IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
1915 /* If in 10Mbps mode, stop the transmit queue so
1916 * no more transmit frames are accepted.
1918 if (sp
->tenmbpsmode
)
1919 netif_stop_queue(dev
);
1921 if (sp
->ResetCurrentTFD
) {
1922 sp
->ResetCurrentTFD
= 0;
1926 txfd
= sp
->txd
+ entry
;
1928 sp
->TxBuff
[entry
] = skb
;
1930 /* Clear all TFC fields, except TFDDONE. */
1931 txfd
->tfc
= cpu_to_le64(IPG_TFC_TFDDONE
);
1933 /* Specify the TFC field within the TFD. */
1934 txfd
->tfc
|= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED
|
1935 (IPG_TFC_FRAMEID
& cpu_to_le64(sp
->tx_current
)) |
1936 (IPG_TFC_FRAGCOUNT
& (1 << 24)));
1938 /* Request TxComplete interrupts at an interval defined
1939 * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
1940 * Request TxComplete interrupt for every frame
1941 * if in 10Mbps mode to accomodate problem with 10Mbps
1944 if (sp
->tenmbpsmode
)
1945 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXINDICATE
);
1946 else if (!((sp
->tx_current
- sp
->tx_dirty
+ 1) >
1947 IPG_FRAMESBETWEENTXDMACOMPLETES
)) {
1948 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXDMAINDICATE
);
1950 /* Based on compilation option, determine if FCS is to be
1951 * appended to transmit frame by IPG.
1953 if (!(IPG_APPEND_FCS_ON_TX
))
1954 txfd
->tfc
|= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE
);
1956 /* Based on compilation option, determine if IP, TCP and/or
1957 * UDP checksums are to be added to transmit frame by IPG.
1959 if (IPG_ADD_IPCHECKSUM_ON_TX
)
1960 txfd
->tfc
|= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE
);
1962 if (IPG_ADD_TCPCHECKSUM_ON_TX
)
1963 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE
);
1965 if (IPG_ADD_UDPCHECKSUM_ON_TX
)
1966 txfd
->tfc
|= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE
);
1968 /* Based on compilation option, determine if VLAN tag info is to be
1969 * inserted into transmit frame by IPG.
1971 if (IPG_INSERT_MANUAL_VLAN_TAG
) {
1972 txfd
->tfc
|= cpu_to_le64(IPG_TFC_VLANTAGINSERT
|
1973 ((u64
) IPG_MANUAL_VLAN_VID
<< 32) |
1974 ((u64
) IPG_MANUAL_VLAN_CFI
<< 44) |
1975 ((u64
) IPG_MANUAL_VLAN_USERPRIORITY
<< 45));
1978 /* The fragment start location within system memory is defined
1979 * by the sk_buff structure's data field. The physical address
1980 * of this location within the system's virtual memory space
1981 * is determined using the IPG_HOST2BUS_MAP function.
1983 txfd
->frag_info
= cpu_to_le64(pci_map_single(sp
->pdev
, skb
->data
,
1984 skb
->len
, PCI_DMA_TODEVICE
));
1986 /* The length of the fragment within system memory is defined by
1987 * the sk_buff structure's len field.
1989 txfd
->frag_info
|= cpu_to_le64(IPG_TFI_FRAGLEN
&
1990 ((u64
) (skb
->len
& 0xffff) << 48));
1992 /* Clear the TFDDone bit last to indicate the TFD is ready
1993 * for transfer to the IPG.
1995 txfd
->tfc
&= cpu_to_le64(~IPG_TFC_TFDDONE
);
1997 spin_lock_irqsave(&sp
->lock
, flags
);
2003 ipg_w32(IPG_DC_TX_DMA_POLL_NOW
, DMA_CTRL
);
2005 if (sp
->tx_current
== (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))
2006 netif_wake_queue(dev
);
2008 spin_unlock_irqrestore(&sp
->lock
, flags
);
2010 return NETDEV_TX_OK
;
2013 static void ipg_set_phy_default_param(unsigned char rev
,
2014 struct net_device
*dev
, int phy_address
)
2016 unsigned short length
;
2017 unsigned char revision
;
2018 unsigned short *phy_param
;
2019 unsigned short address
, value
;
2021 phy_param
= &DefaultPhyParam
[0];
2022 length
= *phy_param
& 0x00FF;
2023 revision
= (unsigned char)((*phy_param
) >> 8);
2025 while (length
!= 0) {
2026 if (rev
== revision
) {
2027 while (length
> 1) {
2028 address
= *phy_param
;
2029 value
= *(phy_param
+ 1);
2031 mdio_write(dev
, phy_address
, address
, value
);
2036 phy_param
+= length
/ 2;
2037 length
= *phy_param
& 0x00FF;
2038 revision
= (unsigned char)((*phy_param
) >> 8);
2044 /* JES20040127EEPROM */
2045 static int read_eeprom(struct net_device
*dev
, int eep_addr
)
2047 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
2052 value
= IPG_EC_EEPROM_READOPCODE
| (eep_addr
& 0xff);
2053 ipg_w16(value
, EEPROM_CTRL
);
2055 for (i
= 0; i
< 1000; i
++) {
2059 data
= ipg_r16(EEPROM_CTRL
);
2060 if (!(data
& IPG_EC_EEPROM_BUSY
)) {
2061 ret
= ipg_r16(EEPROM_DATA
);
2068 static void ipg_init_mii(struct net_device
*dev
)
2070 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2071 struct mii_if_info
*mii_if
= &sp
->mii_if
;
2075 mii_if
->mdio_read
= mdio_read
;
2076 mii_if
->mdio_write
= mdio_write
;
2077 mii_if
->phy_id_mask
= 0x1f;
2078 mii_if
->reg_num_mask
= 0x1f;
2080 mii_if
->phy_id
= phyaddr
= ipg_find_phyaddr(dev
);
2082 if (phyaddr
!= 0x1f) {
2083 u16 mii_phyctrl
, mii_1000cr
;
2086 mii_1000cr
= mdio_read(dev
, phyaddr
, MII_CTRL1000
);
2087 mii_1000cr
|= ADVERTISE_1000FULL
| ADVERTISE_1000HALF
|
2088 GMII_PHY_1000BASETCONTROL_PreferMaster
;
2089 mdio_write(dev
, phyaddr
, MII_CTRL1000
, mii_1000cr
);
2091 mii_phyctrl
= mdio_read(dev
, phyaddr
, MII_BMCR
);
2093 /* Set default phyparam */
2094 pci_read_config_byte(sp
->pdev
, PCI_REVISION_ID
, &revisionid
);
2095 ipg_set_phy_default_param(revisionid
, dev
, phyaddr
);
2098 mii_phyctrl
|= BMCR_RESET
| BMCR_ANRESTART
;
2099 mdio_write(dev
, phyaddr
, MII_BMCR
, mii_phyctrl
);
2104 static int ipg_hw_init(struct net_device
*dev
)
2106 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2107 void __iomem
*ioaddr
= sp
->ioaddr
;
2111 /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
2112 /* Read LED Mode Configuration from EEPROM */
2113 sp
->LED_Mode
= read_eeprom(dev
, 6);
2115 /* Reset all functions within the IPG. Do not assert
2116 * RST_OUT as not compatible with some PHYs.
2118 rc
= ipg_reset(dev
, IPG_RESET_MASK
);
2124 /* Read MAC Address from EEPROM */
2125 for (i
= 0; i
< 3; i
++)
2126 sp
->station_addr
[i
] = read_eeprom(dev
, 16 + i
);
2128 for (i
= 0; i
< 3; i
++)
2129 ipg_w16(sp
->station_addr
[i
], STATION_ADDRESS_0
+ 2*i
);
2131 /* Set station address in ethernet_device structure. */
2132 dev
->dev_addr
[0] = ipg_r16(STATION_ADDRESS_0
) & 0x00ff;
2133 dev
->dev_addr
[1] = (ipg_r16(STATION_ADDRESS_0
) & 0xff00) >> 8;
2134 dev
->dev_addr
[2] = ipg_r16(STATION_ADDRESS_1
) & 0x00ff;
2135 dev
->dev_addr
[3] = (ipg_r16(STATION_ADDRESS_1
) & 0xff00) >> 8;
2136 dev
->dev_addr
[4] = ipg_r16(STATION_ADDRESS_2
) & 0x00ff;
2137 dev
->dev_addr
[5] = (ipg_r16(STATION_ADDRESS_2
) & 0xff00) >> 8;
2142 static int ipg_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2144 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2147 mutex_lock(&sp
->mii_mutex
);
2148 rc
= generic_mii_ioctl(&sp
->mii_if
, if_mii(ifr
), cmd
, NULL
);
2149 mutex_unlock(&sp
->mii_mutex
);
2154 static int ipg_nic_change_mtu(struct net_device
*dev
, int new_mtu
)
2156 /* Function to accomodate changes to Maximum Transfer Unit
2157 * (or MTU) of IPG NIC. Cannot use default function since
2158 * the default will not allow for MTU > 1500 bytes.
2161 IPG_DEBUG_MSG("_nic_change_mtu\n");
2163 /* Check that the new MTU value is between 68 (14 byte header, 46
2164 * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
2165 * corresponds to the MAXFRAMESIZE register in the IPG.
2167 if ((new_mtu
< 68) || (new_mtu
> IPG_MAX_RXFRAME_SIZE
))
2175 static int ipg_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2177 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2180 mutex_lock(&sp
->mii_mutex
);
2181 rc
= mii_ethtool_gset(&sp
->mii_if
, cmd
);
2182 mutex_unlock(&sp
->mii_mutex
);
2187 static int ipg_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2189 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2192 mutex_lock(&sp
->mii_mutex
);
2193 rc
= mii_ethtool_sset(&sp
->mii_if
, cmd
);
2194 mutex_unlock(&sp
->mii_mutex
);
2199 static int ipg_nway_reset(struct net_device
*dev
)
2201 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2204 mutex_lock(&sp
->mii_mutex
);
2205 rc
= mii_nway_restart(&sp
->mii_if
);
2206 mutex_unlock(&sp
->mii_mutex
);
2211 static struct ethtool_ops ipg_ethtool_ops
= {
2212 .get_settings
= ipg_get_settings
,
2213 .set_settings
= ipg_set_settings
,
2214 .nway_reset
= ipg_nway_reset
,
2217 static void ipg_remove(struct pci_dev
*pdev
)
2219 struct net_device
*dev
= pci_get_drvdata(pdev
);
2220 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2222 IPG_DEBUG_MSG("_remove\n");
2224 /* Un-register Ethernet device. */
2225 unregister_netdev(dev
);
2227 pci_iounmap(pdev
, sp
->ioaddr
);
2229 pci_release_regions(pdev
);
2232 pci_disable_device(pdev
);
2233 pci_set_drvdata(pdev
, NULL
);
2236 static int __devinit
ipg_probe(struct pci_dev
*pdev
,
2237 const struct pci_device_id
*id
)
2239 unsigned int i
= id
->driver_data
;
2240 struct ipg_nic_private
*sp
;
2241 struct net_device
*dev
;
2242 void __iomem
*ioaddr
;
2245 rc
= pci_enable_device(pdev
);
2249 printk(KERN_INFO
"%s: %s\n", pci_name(pdev
), ipg_brand_name
[i
]);
2251 pci_set_master(pdev
);
2253 rc
= pci_set_dma_mask(pdev
, DMA_40BIT_MASK
);
2255 rc
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
2257 printk(KERN_ERR
"%s: DMA config failed.\n",
2264 * Initialize net device.
2266 dev
= alloc_etherdev(sizeof(struct ipg_nic_private
));
2268 printk(KERN_ERR
"%s: alloc_etherdev failed\n", pci_name(pdev
));
2273 sp
= netdev_priv(dev
);
2274 spin_lock_init(&sp
->lock
);
2275 mutex_init(&sp
->mii_mutex
);
2277 /* Declare IPG NIC functions for Ethernet device methods.
2279 dev
->open
= &ipg_nic_open
;
2280 dev
->stop
= &ipg_nic_stop
;
2281 dev
->hard_start_xmit
= &ipg_nic_hard_start_xmit
;
2282 dev
->get_stats
= &ipg_nic_get_stats
;
2283 dev
->set_multicast_list
= &ipg_nic_set_multicast_list
;
2284 dev
->do_ioctl
= ipg_ioctl
;
2285 dev
->tx_timeout
= ipg_tx_timeout
;
2286 dev
->change_mtu
= &ipg_nic_change_mtu
;
2288 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2289 SET_ETHTOOL_OPS(dev
, &ipg_ethtool_ops
);
2291 rc
= pci_request_regions(pdev
, DRV_NAME
);
2293 goto err_free_dev_1
;
2295 ioaddr
= pci_iomap(pdev
, 1, pci_resource_len(pdev
, 1));
2297 printk(KERN_ERR
"%s cannot map MMIO\n", pci_name(pdev
));
2299 goto err_release_regions_2
;
2302 /* Save the pointer to the PCI device information. */
2303 sp
->ioaddr
= ioaddr
;
2307 INIT_DELAYED_WORK(&sp
->task
, ipg_reset_after_host_error
);
2309 pci_set_drvdata(pdev
, dev
);
2311 rc
= ipg_hw_init(dev
);
2315 rc
= register_netdev(dev
);
2319 printk(KERN_INFO
"Ethernet device registered as: %s\n", dev
->name
);
2324 pci_iounmap(pdev
, ioaddr
);
2325 err_release_regions_2
:
2326 pci_release_regions(pdev
);
2330 pci_disable_device(pdev
);
2334 static struct pci_driver ipg_pci_driver
= {
2335 .name
= IPG_DRIVER_NAME
,
2336 .id_table
= ipg_pci_tbl
,
2338 .remove
= __devexit_p(ipg_remove
),
2341 static int __init
ipg_init_module(void)
2343 return pci_register_driver(&ipg_pci_driver
);
2346 static void __exit
ipg_exit_module(void)
2348 pci_unregister_driver(&ipg_pci_driver
);
2351 module_init(ipg_init_module
);
2352 module_exit(ipg_exit_module
);