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 unsigned int released
, pending
, dirty
;
862 IPG_DEBUG_MSG("_nic_txfree\n");
864 pending
= sp
->tx_current
- sp
->tx_dirty
;
865 dirty
= sp
->tx_dirty
% IPG_TFDLIST_LENGTH
;
867 for (released
= 0; released
< pending
; released
++) {
868 struct sk_buff
*skb
= sp
->TxBuff
[dirty
];
869 struct ipg_tx
*txfd
= sp
->txd
+ dirty
;
871 IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd
->tfc
);
873 /* Look at each TFD's TFC field beginning
874 * at the last freed TFD up to the current TFD.
875 * If the TFDDone bit is set, free the associated
878 if (!(txfd
->tfc
& cpu_to_le64(IPG_TFC_TFDDONE
)))
881 /* Free the transmit buffer. */
883 pci_unmap_single(sp
->pdev
,
884 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
885 skb
->len
, PCI_DMA_TODEVICE
);
887 IPG_DEV_KFREE_SKB(skb
);
889 sp
->TxBuff
[dirty
] = NULL
;
891 dirty
= (dirty
+ 1) % IPG_TFDLIST_LENGTH
;
894 sp
->tx_dirty
+= released
;
896 if (netif_queue_stopped(dev
) &&
897 (sp
->tx_current
!= (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))) {
898 netif_wake_queue(dev
);
902 static void ipg_tx_timeout(struct net_device
*dev
)
904 struct ipg_nic_private
*sp
= netdev_priv(dev
);
905 void __iomem
*ioaddr
= sp
->ioaddr
;
907 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
| IPG_AC_NETWORK
|
910 spin_lock_irq(&sp
->lock
);
912 /* Re-configure after DMA reset. */
913 if (ipg_io_config(dev
) < 0) {
914 printk(KERN_INFO
"%s: Error during re-configuration.\n",
920 spin_unlock_irq(&sp
->lock
);
922 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) & IPG_MC_RSVD_MASK
,
927 * For TxComplete interrupts, free all transmit
928 * buffers which have already been transfered via DMA
931 static void ipg_nic_txcleanup(struct net_device
*dev
)
933 struct ipg_nic_private
*sp
= netdev_priv(dev
);
934 void __iomem
*ioaddr
= sp
->ioaddr
;
937 IPG_DEBUG_MSG("_nic_txcleanup\n");
939 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
940 /* Reading the TXSTATUS register clears the
941 * TX_COMPLETE interrupt.
943 u32 txstatusdword
= ipg_r32(TX_STATUS
);
945 IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword
);
947 /* Check for Transmit errors. Error bits only valid if
948 * TX_COMPLETE bit in the TXSTATUS register is a 1.
950 if (!(txstatusdword
& IPG_TS_TX_COMPLETE
))
953 /* If in 10Mbps mode, indicate transmit is ready. */
954 if (sp
->tenmbpsmode
) {
955 netif_wake_queue(dev
);
958 /* Transmit error, increment stat counters. */
959 if (txstatusdword
& IPG_TS_TX_ERROR
) {
960 IPG_DEBUG_MSG("Transmit error.\n");
961 sp
->stats
.tx_errors
++;
964 /* Late collision, re-enable transmitter. */
965 if (txstatusdword
& IPG_TS_LATE_COLLISION
) {
966 IPG_DEBUG_MSG("Late collision on transmit.\n");
967 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
968 IPG_MC_RSVD_MASK
, MAC_CTRL
);
971 /* Maximum collisions, re-enable transmitter. */
972 if (txstatusdword
& IPG_TS_TX_MAX_COLL
) {
973 IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
974 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
975 IPG_MC_RSVD_MASK
, MAC_CTRL
);
978 /* Transmit underrun, reset and re-enable
981 if (txstatusdword
& IPG_TS_TX_UNDERRUN
) {
982 IPG_DEBUG_MSG("Transmitter underrun.\n");
983 sp
->stats
.tx_fifo_errors
++;
984 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
|
985 IPG_AC_NETWORK
| IPG_AC_FIFO
);
987 /* Re-configure after DMA reset. */
988 if (ipg_io_config(dev
) < 0) {
990 "%s: Error during re-configuration.\n",
995 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
996 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1000 ipg_nic_txfree(dev
);
1003 /* Provides statistical information about the IPG NIC. */
1004 static struct net_device_stats
*ipg_nic_get_stats(struct net_device
*dev
)
1006 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1007 void __iomem
*ioaddr
= sp
->ioaddr
;
1011 IPG_DEBUG_MSG("_nic_get_stats\n");
1013 /* Check to see if the NIC has been initialized via nic_open,
1014 * before trying to read statistic registers.
1016 if (!test_bit(__LINK_STATE_START
, &dev
->state
))
1019 sp
->stats
.rx_packets
+= ipg_r32(IPG_FRAMESRCVDOK
);
1020 sp
->stats
.tx_packets
+= ipg_r32(IPG_FRAMESXMTDOK
);
1021 sp
->stats
.rx_bytes
+= ipg_r32(IPG_OCTETRCVOK
);
1022 sp
->stats
.tx_bytes
+= ipg_r32(IPG_OCTETXMTOK
);
1023 temp1
= ipg_r16(IPG_FRAMESLOSTRXERRORS
);
1024 sp
->stats
.rx_errors
+= temp1
;
1025 sp
->stats
.rx_missed_errors
+= temp1
;
1026 temp1
= ipg_r32(IPG_SINGLECOLFRAMES
) + ipg_r32(IPG_MULTICOLFRAMES
) +
1027 ipg_r32(IPG_LATECOLLISIONS
);
1028 temp2
= ipg_r16(IPG_CARRIERSENSEERRORS
);
1029 sp
->stats
.collisions
+= temp1
;
1030 sp
->stats
.tx_dropped
+= ipg_r16(IPG_FRAMESABORTXSCOLLS
);
1031 sp
->stats
.tx_errors
+= ipg_r16(IPG_FRAMESWEXDEFERRAL
) +
1032 ipg_r32(IPG_FRAMESWDEFERREDXMT
) + temp1
+ temp2
;
1033 sp
->stats
.multicast
+= ipg_r32(IPG_MCSTOCTETRCVDOK
);
1035 /* detailed tx_errors */
1036 sp
->stats
.tx_carrier_errors
+= temp2
;
1038 /* detailed rx_errors */
1039 sp
->stats
.rx_length_errors
+= ipg_r16(IPG_INRANGELENGTHERRORS
) +
1040 ipg_r16(IPG_FRAMETOOLONGERRRORS
);
1041 sp
->stats
.rx_crc_errors
+= ipg_r16(IPG_FRAMECHECKSEQERRORS
);
1043 /* Unutilized IPG statistic registers. */
1044 ipg_r32(IPG_MCSTFRAMESRCVDOK
);
1049 /* Restore used receive buffers. */
1050 static int ipg_nic_rxrestore(struct net_device
*dev
)
1052 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1053 const unsigned int curr
= sp
->rx_current
;
1054 unsigned int dirty
= sp
->rx_dirty
;
1056 IPG_DEBUG_MSG("_nic_rxrestore\n");
1058 for (dirty
= sp
->rx_dirty
; curr
- dirty
> 0; dirty
++) {
1059 unsigned int entry
= dirty
% IPG_RFDLIST_LENGTH
;
1061 /* rx_copybreak may poke hole here and there. */
1062 if (sp
->RxBuff
[entry
])
1065 /* Generate a new receive buffer to replace the
1066 * current buffer (which will be released by the
1069 if (ipg_get_rxbuff(dev
, entry
) < 0) {
1070 IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
1075 /* Reset the RFS field. */
1076 sp
->rxd
[entry
].rfs
= 0x0000000000000000;
1078 sp
->rx_dirty
= dirty
;
1085 /* use jumboindex and jumbosize to control jumbo frame status
1086 initial status is jumboindex=-1 and jumbosize=0
1087 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
1088 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
1089 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
1090 previous receiving and need to continue dumping the current one
1098 Frame_NoStart_NoEnd
= 0,
1099 Frame_WithStart
= 1,
1101 Frame_WithStart_WithEnd
= 11
1104 inline void ipg_nic_rx_free_skb(struct net_device
*dev
)
1106 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1107 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1109 if (sp
->RxBuff
[entry
]) {
1110 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1112 pci_unmap_single(sp
->pdev
,
1113 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1114 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1115 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1116 sp
->RxBuff
[entry
] = NULL
;
1120 inline int ipg_nic_rx_check_frame_type(struct net_device
*dev
)
1122 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1123 struct ipg_rx
*rxfd
= sp
->rxd
+ (sp
->rx_current
% IPG_RFDLIST_LENGTH
);
1124 int type
= Frame_NoStart_NoEnd
;
1126 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
)
1127 type
+= Frame_WithStart
;
1128 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
)
1129 type
+= Frame_WithEnd
;
1133 inline int ipg_nic_rx_check_error(struct net_device
*dev
)
1135 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1136 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1137 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1139 if (IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1140 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1141 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1142 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
))) {
1143 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1144 (unsigned long) rxfd
->rfs
);
1146 /* Increment general receive error statistic. */
1147 sp
->stats
.rx_errors
++;
1149 /* Increment detailed receive error statistics. */
1150 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1151 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1153 sp
->stats
.rx_fifo_errors
++;
1156 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1157 IPG_DEBUG_MSG("RX runt occured.\n");
1158 sp
->stats
.rx_length_errors
++;
1161 /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
1162 * error count handled by a IPG statistic register.
1165 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1166 IPG_DEBUG_MSG("RX alignment error occured.\n");
1167 sp
->stats
.rx_frame_errors
++;
1170 /* Do nothing for IPG_RFS_RXFCSERROR, error count
1171 * handled by a IPG statistic register.
1174 /* Free the memory associated with the RX
1175 * buffer since it is erroneous and we will
1176 * not pass it to higher layer processes.
1178 if (sp
->RxBuff
[entry
]) {
1179 pci_unmap_single(sp
->pdev
,
1180 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1181 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1183 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1184 sp
->RxBuff
[entry
] = NULL
;
1188 return NormalPacket
;
1191 static void ipg_nic_rx_with_start_and_end(struct net_device
*dev
,
1192 struct ipg_nic_private
*sp
,
1193 struct ipg_rx
*rxfd
, unsigned entry
)
1195 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1196 struct sk_buff
*skb
;
1199 if (jumbo
->FoundStart
) {
1200 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1201 jumbo
->FoundStart
= 0;
1202 jumbo
->CurrentSize
= 0;
1206 // 1: found error, 0 no error
1207 if (ipg_nic_rx_check_error(dev
) != NormalPacket
)
1210 skb
= sp
->RxBuff
[entry
];
1214 // accept this frame and send to upper layer
1215 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1216 if (framelen
> IPG_RXFRAG_SIZE
)
1217 framelen
= IPG_RXFRAG_SIZE
;
1219 skb_put(skb
, framelen
);
1220 skb
->protocol
= eth_type_trans(skb
, dev
);
1221 skb
->ip_summed
= CHECKSUM_NONE
;
1223 dev
->last_rx
= jiffies
;
1224 sp
->RxBuff
[entry
] = NULL
;
1227 static void ipg_nic_rx_with_start(struct net_device
*dev
,
1228 struct ipg_nic_private
*sp
,
1229 struct ipg_rx
*rxfd
, unsigned entry
)
1231 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1232 struct pci_dev
*pdev
= sp
->pdev
;
1233 struct sk_buff
*skb
;
1235 // 1: found error, 0 no error
1236 if (ipg_nic_rx_check_error(dev
) != NormalPacket
)
1239 // accept this frame and send to upper layer
1240 skb
= sp
->RxBuff
[entry
];
1244 if (jumbo
->FoundStart
)
1245 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1247 pci_unmap_single(pdev
, le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1248 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1250 skb_put(skb
, IPG_RXFRAG_SIZE
);
1252 jumbo
->FoundStart
= 1;
1253 jumbo
->CurrentSize
= IPG_RXFRAG_SIZE
;
1256 sp
->RxBuff
[entry
] = NULL
;
1257 dev
->last_rx
= jiffies
;
1260 static void ipg_nic_rx_with_end(struct net_device
*dev
,
1261 struct ipg_nic_private
*sp
,
1262 struct ipg_rx
*rxfd
, unsigned entry
)
1264 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1266 //1: found error, 0 no error
1267 if (ipg_nic_rx_check_error(dev
) == NormalPacket
) {
1268 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1273 if (jumbo
->FoundStart
) {
1274 int framelen
, endframelen
;
1276 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1278 endframeLen
= framelen
- jumbo
->CurrentSize
;
1280 if (framelen > IPG_RXFRAG_SIZE)
1281 framelen=IPG_RXFRAG_SIZE;
1283 if (framelen
> IPG_RXSUPPORT_SIZE
)
1284 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1286 memcpy(skb_put(jumbo
->skb
, endframeLen
),
1287 skb
->data
, endframeLen
);
1289 jumbo
->skb
->protocol
=
1290 eth_type_trans(jumbo
->skb
, dev
);
1292 jumbo
->skb
->ip_summed
= CHECKSUM_NONE
;
1293 netif_rx(jumbo
->skb
);
1297 dev
->last_rx
= jiffies
;
1298 jumbo
->FoundStart
= 0;
1299 jumbo
->CurrentSize
= 0;
1302 ipg_nic_rx_free_skb(dev
);
1304 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1305 jumbo
->FoundStart
= 0;
1306 jumbo
->CurrentSize
= 0;
1311 static void ipg_nic_rx_no_start_no_end(struct net_device
*dev
,
1312 struct ipg_nic_private
*sp
,
1313 struct ipg_rx
*rxfd
, unsigned entry
)
1315 struct SJumbo
*jumbo
= &sp
->Jumbo
;
1317 //1: found error, 0 no error
1318 if (ipg_nic_rx_check_error(dev
) == NormalPacket
) {
1319 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1322 if (jumbo
->FoundStart
) {
1323 jumbo
->CurrentSize
+= IPG_RXFRAG_SIZE
;
1324 if (jumbo
->CurrentSize
<= IPG_RXSUPPORT_SIZE
) {
1325 memcpy(skb_put(jumbo
->skb
,
1327 skb
->data
, IPG_RXFRAG_SIZE
);
1330 dev
->last_rx
= jiffies
;
1331 ipg_nic_rx_free_skb(dev
);
1334 IPG_DEV_KFREE_SKB(jumbo
->skb
);
1335 jumbo
->FoundStart
= 0;
1336 jumbo
->CurrentSize
= 0;
1341 static int ipg_nic_rx(struct net_device
*dev
)
1343 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1344 unsigned int curr
= sp
->rx_current
;
1345 void __iomem
*ioaddr
= sp
->ioaddr
;
1348 IPG_DEBUG_MSG("_nic_rx\n");
1350 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1351 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1352 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1354 if (!(rxfd
->rfs
& le64_to_cpu(IPG_RFS_RFDDONE
)))
1357 switch (ipg_nic_rx_check_frame_type(dev
)) {
1358 case Frame_WithStart_WithEnd
:
1359 ipg_nic_rx_with_start_and_end(dev
, tp
, rxfd
, entry
);
1361 case Frame_WithStart
:
1362 ipg_nic_rx_with_start(dev
, tp
, rxfd
, entry
);
1365 ipg_nic_rx_with_end(dev
, tp
, rxfd
, entry
);
1367 case Frame_NoStart_NoEnd
:
1368 ipg_nic_rx_no_start_no_end(dev
, tp
, rxfd
, entry
);
1373 sp
->rx_current
= curr
;
1375 if (i
== IPG_MAXRFDPROCESS_COUNT
) {
1376 /* There are more RFDs to process, however the
1377 * allocated amount of RFD processing time has
1378 * expired. Assert Interrupt Requested to make
1379 * sure we come back to process the remaining RFDs.
1381 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1384 ipg_nic_rxrestore(dev
);
1390 static int ipg_nic_rx(struct net_device
*dev
)
1392 /* Transfer received Ethernet frames to higher network layers. */
1393 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1394 unsigned int curr
= sp
->rx_current
;
1395 void __iomem
*ioaddr
= sp
->ioaddr
;
1396 struct ipg_rx
*rxfd
;
1399 IPG_DEBUG_MSG("_nic_rx\n");
1401 #define __RFS_MASK \
1402 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1404 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1405 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1406 struct sk_buff
*skb
= sp
->RxBuff
[entry
];
1407 unsigned int framelen
;
1409 rxfd
= sp
->rxd
+ entry
;
1411 if (((rxfd
->rfs
& __RFS_MASK
) != __RFS_MASK
) || !skb
)
1414 /* Get received frame length. */
1415 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1417 /* Check for jumbo frame arrival with too small
1420 if (framelen
> IPG_RXFRAG_SIZE
) {
1422 ("RFS FrameLen > allocated fragment size.\n");
1424 framelen
= IPG_RXFRAG_SIZE
;
1427 if ((IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1428 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1429 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1430 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
)))) {
1432 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1433 (unsigned long int) rxfd
->rfs
);
1435 /* Increment general receive error statistic. */
1436 sp
->stats
.rx_errors
++;
1438 /* Increment detailed receive error statistics. */
1439 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1440 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1441 sp
->stats
.rx_fifo_errors
++;
1444 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1445 IPG_DEBUG_MSG("RX runt occured.\n");
1446 sp
->stats
.rx_length_errors
++;
1449 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXOVERSIZEDFRAME
) ;
1450 /* Do nothing, error count handled by a IPG
1451 * statistic register.
1454 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1455 IPG_DEBUG_MSG("RX alignment error occured.\n");
1456 sp
->stats
.rx_frame_errors
++;
1459 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFCSERROR
) ;
1460 /* Do nothing, error count handled by a IPG
1461 * statistic register.
1464 /* Free the memory associated with the RX
1465 * buffer since it is erroneous and we will
1466 * not pass it to higher layer processes.
1469 __le64 info
= rxfd
->frag_info
;
1471 pci_unmap_single(sp
->pdev
,
1472 le64_to_cpu(info
) & ~IPG_RFI_FRAGLEN
,
1473 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1475 IPG_DEV_KFREE_SKB(skb
);
1479 /* Adjust the new buffer length to accomodate the size
1480 * of the received frame.
1482 skb_put(skb
, framelen
);
1484 /* Set the buffer's protocol field to Ethernet. */
1485 skb
->protocol
= eth_type_trans(skb
, dev
);
1487 /* If the frame contains an IP/TCP/UDP frame,
1488 * determine if upper layer must check IP/TCP/UDP
1491 * NOTE: DO NOT RELY ON THE TCP/UDP CHECKSUM
1492 * VERIFICATION FOR SILICON REVISIONS B3
1495 if ((le64_to_cpu(rxfd->rfs &
1496 (IPG_RFS_TCPDETECTED | IPG_RFS_UDPDETECTED |
1497 IPG_RFS_IPDETECTED))) &&
1498 !(le64_to_cpu(rxfd->rfs &
1499 (IPG_RFS_TCPERROR | IPG_RFS_UDPERROR |
1500 IPG_RFS_IPERROR)))) {
1501 * Indicate IP checksums were performed
1504 skb->ip_summed = CHECKSUM_UNNECESSARY;
1508 /* The IPG encountered an error with (or
1509 * there were no) IP/TCP/UDP checksums.
1510 * This may or may not indicate an invalid
1511 * IP/TCP/UDP frame was received. Let the
1512 * upper layer decide.
1514 skb
->ip_summed
= CHECKSUM_NONE
;
1517 /* Hand off frame for higher layer processing.
1518 * The function netif_rx() releases the sk_buff
1519 * when processing completes.
1523 /* Record frame receive time (jiffies = Linux
1524 * kernel current time stamp).
1526 dev
->last_rx
= jiffies
;
1529 /* Assure RX buffer is not reused by IPG. */
1530 sp
->RxBuff
[entry
] = NULL
;
1534 * If there are more RFDs to proces and the allocated amount of RFD
1535 * processing time has expired, assert Interrupt Requested to make
1536 * sure we come back to process the remaining RFDs.
1538 if (i
== IPG_MAXRFDPROCESS_COUNT
)
1539 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1542 /* Check if the RFD list contained no receive frame data. */
1544 sp
->EmptyRFDListCount
++;
1546 while ((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RFDDONE
) &&
1547 !((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
) &&
1548 (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
))) {
1549 unsigned int entry
= curr
++ % IPG_RFDLIST_LENGTH
;
1551 rxfd
= sp
->rxd
+ entry
;
1553 IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
1555 /* An unexpected event, additional code needed to handle
1556 * properly. So for the time being, just disregard the
1560 /* Free the memory associated with the RX
1561 * buffer since it is erroneous and we will
1562 * not pass it to higher layer processes.
1564 if (sp
->RxBuff
[entry
]) {
1565 pci_unmap_single(sp
->pdev
,
1566 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1567 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1568 IPG_DEV_KFREE_SKB(sp
->RxBuff
[entry
]);
1571 /* Assure RX buffer is not reused by IPG. */
1572 sp
->RxBuff
[entry
] = NULL
;
1575 sp
->rx_current
= curr
;
1577 /* Check to see if there are a minimum number of used
1578 * RFDs before restoring any (should improve performance.)
1580 if ((curr
- sp
->rx_dirty
) >= IPG_MINUSEDRFDSTOFREE
)
1581 ipg_nic_rxrestore(dev
);
1587 static void ipg_reset_after_host_error(struct work_struct
*work
)
1589 struct ipg_nic_private
*sp
=
1590 container_of(work
, struct ipg_nic_private
, task
.work
);
1591 struct net_device
*dev
= sp
->dev
;
1593 IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp
->ioaddr
+ IPG_DMACTRL
));
1596 * Acknowledge HostError interrupt by resetting
1599 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1604 if (ipg_io_config(dev
) < 0) {
1605 printk(KERN_INFO
"%s: Cannot recover from PCI error.\n",
1607 schedule_delayed_work(&sp
->task
, HZ
);
1611 static irqreturn_t
ipg_interrupt_handler(int irq
, void *dev_inst
)
1613 struct net_device
*dev
= dev_inst
;
1614 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1615 void __iomem
*ioaddr
= sp
->ioaddr
;
1616 unsigned int handled
= 0;
1619 IPG_DEBUG_MSG("_interrupt_handler\n");
1622 ipg_nic_rxrestore(dev
);
1624 spin_lock(&sp
->lock
);
1626 /* Get interrupt source information, and acknowledge
1627 * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
1628 * IntRequested, MacControlFrame, LinkEvent) interrupts
1629 * if issued. Also, all IPG interrupts are disabled by
1630 * reading IntStatusAck.
1632 status
= ipg_r16(INT_STATUS_ACK
);
1634 IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status
);
1636 /* Shared IRQ of remove event. */
1637 if (!(status
& IPG_IS_RSVD_MASK
))
1642 if (unlikely(!netif_running(dev
)))
1645 /* If RFDListEnd interrupt, restore all used RFDs. */
1646 if (status
& IPG_IS_RFD_LIST_END
) {
1647 IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
1649 /* The RFD list end indicates an RFD was encountered
1650 * with a 0 NextPtr, or with an RFDDone bit set to 1
1651 * (indicating the RFD is not read for use by the
1652 * IPG.) Try to restore all RFDs.
1654 ipg_nic_rxrestore(dev
);
1657 /* Increment the RFDlistendCount counter. */
1658 sp
->RFDlistendCount
++;
1662 /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
1663 * IntRequested interrupt, process received frames. */
1664 if ((status
& IPG_IS_RX_DMA_PRIORITY
) ||
1665 (status
& IPG_IS_RFD_LIST_END
) ||
1666 (status
& IPG_IS_RX_DMA_COMPLETE
) ||
1667 (status
& IPG_IS_INT_REQUESTED
)) {
1669 /* Increment the RFD list checked counter if interrupted
1670 * only to check the RFD list. */
1671 if (status
& (~(IPG_IS_RX_DMA_PRIORITY
| IPG_IS_RFD_LIST_END
|
1672 IPG_IS_RX_DMA_COMPLETE
| IPG_IS_INT_REQUESTED
) &
1673 (IPG_IS_HOST_ERROR
| IPG_IS_TX_DMA_COMPLETE
|
1674 IPG_IS_LINK_EVENT
| IPG_IS_TX_COMPLETE
|
1675 IPG_IS_UPDATE_STATS
)))
1676 sp
->RFDListCheckedCount
++;
1682 /* If TxDMAComplete interrupt, free used TFDs. */
1683 if (status
& IPG_IS_TX_DMA_COMPLETE
)
1684 ipg_nic_txfree(dev
);
1686 /* TxComplete interrupts indicate one of numerous actions.
1687 * Determine what action to take based on TXSTATUS register.
1689 if (status
& IPG_IS_TX_COMPLETE
)
1690 ipg_nic_txcleanup(dev
);
1692 /* If UpdateStats interrupt, update Linux Ethernet statistics */
1693 if (status
& IPG_IS_UPDATE_STATS
)
1694 ipg_nic_get_stats(dev
);
1696 /* If HostError interrupt, reset IPG. */
1697 if (status
& IPG_IS_HOST_ERROR
) {
1698 IPG_DDEBUG_MSG("HostError Interrupt\n");
1700 schedule_delayed_work(&sp
->task
, 0);
1703 /* If LinkEvent interrupt, resolve autonegotiation. */
1704 if (status
& IPG_IS_LINK_EVENT
) {
1705 if (ipg_config_autoneg(dev
) < 0)
1706 printk(KERN_INFO
"%s: Auto-negotiation error.\n",
1710 /* If MACCtrlFrame interrupt, do nothing. */
1711 if (status
& IPG_IS_MAC_CTRL_FRAME
)
1712 IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
1714 /* If RxComplete interrupt, do nothing. */
1715 if (status
& IPG_IS_RX_COMPLETE
)
1716 IPG_DEBUG_MSG("RxComplete interrupt.\n");
1718 /* If RxEarly interrupt, do nothing. */
1719 if (status
& IPG_IS_RX_EARLY
)
1720 IPG_DEBUG_MSG("RxEarly interrupt.\n");
1723 /* Re-enable IPG interrupts. */
1724 ipg_w16(IPG_IE_TX_DMA_COMPLETE
| IPG_IE_RX_DMA_COMPLETE
|
1725 IPG_IE_HOST_ERROR
| IPG_IE_INT_REQUESTED
| IPG_IE_TX_COMPLETE
|
1726 IPG_IE_LINK_EVENT
| IPG_IE_UPDATE_STATS
, INT_ENABLE
);
1728 spin_unlock(&sp
->lock
);
1730 return IRQ_RETVAL(handled
);
1733 static void ipg_rx_clear(struct ipg_nic_private
*sp
)
1737 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
1738 if (sp
->RxBuff
[i
]) {
1739 struct ipg_rx
*rxfd
= sp
->rxd
+ i
;
1741 IPG_DEV_KFREE_SKB(sp
->RxBuff
[i
]);
1742 sp
->RxBuff
[i
] = NULL
;
1743 pci_unmap_single(sp
->pdev
,
1744 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1745 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1750 static void ipg_tx_clear(struct ipg_nic_private
*sp
)
1754 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
1755 if (sp
->TxBuff
[i
]) {
1756 struct ipg_tx
*txfd
= sp
->txd
+ i
;
1758 pci_unmap_single(sp
->pdev
,
1759 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
1760 sp
->TxBuff
[i
]->len
, PCI_DMA_TODEVICE
);
1762 IPG_DEV_KFREE_SKB(sp
->TxBuff
[i
]);
1764 sp
->TxBuff
[i
] = NULL
;
1769 static int ipg_nic_open(struct net_device
*dev
)
1771 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1772 void __iomem
*ioaddr
= sp
->ioaddr
;
1773 struct pci_dev
*pdev
= sp
->pdev
;
1776 IPG_DEBUG_MSG("_nic_open\n");
1778 sp
->rx_buf_sz
= IPG_RXSUPPORT_SIZE
;
1780 /* Check for interrupt line conflicts, and request interrupt
1783 * IMPORTANT: Disable IPG interrupts prior to registering
1786 ipg_w16(0x0000, INT_ENABLE
);
1788 /* Register the interrupt line to be used by the IPG within
1791 rc
= request_irq(pdev
->irq
, &ipg_interrupt_handler
, IRQF_SHARED
,
1794 printk(KERN_INFO
"%s: Error when requesting interrupt.\n",
1799 dev
->irq
= pdev
->irq
;
1803 sp
->rxd
= dma_alloc_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
,
1804 &sp
->rxd_map
, GFP_KERNEL
);
1806 goto err_free_irq_0
;
1808 sp
->txd
= dma_alloc_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
,
1809 &sp
->txd_map
, GFP_KERNEL
);
1813 rc
= init_rfdlist(dev
);
1815 printk(KERN_INFO
"%s: Error during configuration.\n",
1822 rc
= ipg_io_config(dev
);
1824 printk(KERN_INFO
"%s: Error during configuration.\n",
1826 goto err_release_tfdlist_3
;
1829 /* Resolve autonegotiation. */
1830 if (ipg_config_autoneg(dev
) < 0)
1831 printk(KERN_INFO
"%s: Auto-negotiation error.\n", dev
->name
);
1834 /* initialize JUMBO Frame control variable */
1835 sp
->Jumbo
.FoundStart
= 0;
1836 sp
->Jumbo
.CurrentSize
= 0;
1838 dev
->mtu
= IPG_TXFRAG_SIZE
;
1841 /* Enable transmit and receive operation of the IPG. */
1842 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_RX_ENABLE
| IPG_MC_TX_ENABLE
) &
1843 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1845 netif_start_queue(dev
);
1849 err_release_tfdlist_3
:
1853 dma_free_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1855 dma_free_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1857 free_irq(pdev
->irq
, dev
);
1861 static int ipg_nic_stop(struct net_device
*dev
)
1863 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1864 void __iomem
*ioaddr
= sp
->ioaddr
;
1865 struct pci_dev
*pdev
= sp
->pdev
;
1867 IPG_DEBUG_MSG("_nic_stop\n");
1869 netif_stop_queue(dev
);
1871 IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp
->RFDlistendCount
);
1872 IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp
->rxdCheckedCount
);
1873 IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp
->EmptyRFDListCount
);
1874 IPG_DUMPTFDLIST(dev
);
1877 (void) ipg_r16(INT_STATUS_ACK
);
1879 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1881 synchronize_irq(pdev
->irq
);
1882 } while (ipg_r16(INT_ENABLE
) & IPG_IE_RSVD_MASK
);
1888 pci_free_consistent(pdev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1889 pci_free_consistent(pdev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1891 free_irq(pdev
->irq
, dev
);
1896 static int ipg_nic_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1898 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1899 void __iomem
*ioaddr
= sp
->ioaddr
;
1900 unsigned int entry
= sp
->tx_current
% IPG_TFDLIST_LENGTH
;
1901 unsigned long flags
;
1902 struct ipg_tx
*txfd
;
1904 IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
1906 /* If in 10Mbps mode, stop the transmit queue so
1907 * no more transmit frames are accepted.
1909 if (sp
->tenmbpsmode
)
1910 netif_stop_queue(dev
);
1912 if (sp
->ResetCurrentTFD
) {
1913 sp
->ResetCurrentTFD
= 0;
1917 txfd
= sp
->txd
+ entry
;
1919 sp
->TxBuff
[entry
] = skb
;
1921 /* Clear all TFC fields, except TFDDONE. */
1922 txfd
->tfc
= cpu_to_le64(IPG_TFC_TFDDONE
);
1924 /* Specify the TFC field within the TFD. */
1925 txfd
->tfc
|= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED
|
1926 (IPG_TFC_FRAMEID
& cpu_to_le64(sp
->tx_current
)) |
1927 (IPG_TFC_FRAGCOUNT
& (1 << 24)));
1929 /* Request TxComplete interrupts at an interval defined
1930 * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
1931 * Request TxComplete interrupt for every frame
1932 * if in 10Mbps mode to accomodate problem with 10Mbps
1935 if (sp
->tenmbpsmode
)
1936 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXINDICATE
);
1937 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXDMAINDICATE
);
1938 /* Based on compilation option, determine if FCS is to be
1939 * appended to transmit frame by IPG.
1941 if (!(IPG_APPEND_FCS_ON_TX
))
1942 txfd
->tfc
|= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE
);
1944 /* Based on compilation option, determine if IP, TCP and/or
1945 * UDP checksums are to be added to transmit frame by IPG.
1947 if (IPG_ADD_IPCHECKSUM_ON_TX
)
1948 txfd
->tfc
|= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE
);
1950 if (IPG_ADD_TCPCHECKSUM_ON_TX
)
1951 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE
);
1953 if (IPG_ADD_UDPCHECKSUM_ON_TX
)
1954 txfd
->tfc
|= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE
);
1956 /* Based on compilation option, determine if VLAN tag info is to be
1957 * inserted into transmit frame by IPG.
1959 if (IPG_INSERT_MANUAL_VLAN_TAG
) {
1960 txfd
->tfc
|= cpu_to_le64(IPG_TFC_VLANTAGINSERT
|
1961 ((u64
) IPG_MANUAL_VLAN_VID
<< 32) |
1962 ((u64
) IPG_MANUAL_VLAN_CFI
<< 44) |
1963 ((u64
) IPG_MANUAL_VLAN_USERPRIORITY
<< 45));
1966 /* The fragment start location within system memory is defined
1967 * by the sk_buff structure's data field. The physical address
1968 * of this location within the system's virtual memory space
1969 * is determined using the IPG_HOST2BUS_MAP function.
1971 txfd
->frag_info
= cpu_to_le64(pci_map_single(sp
->pdev
, skb
->data
,
1972 skb
->len
, PCI_DMA_TODEVICE
));
1974 /* The length of the fragment within system memory is defined by
1975 * the sk_buff structure's len field.
1977 txfd
->frag_info
|= cpu_to_le64(IPG_TFI_FRAGLEN
&
1978 ((u64
) (skb
->len
& 0xffff) << 48));
1980 /* Clear the TFDDone bit last to indicate the TFD is ready
1981 * for transfer to the IPG.
1983 txfd
->tfc
&= cpu_to_le64(~IPG_TFC_TFDDONE
);
1985 spin_lock_irqsave(&sp
->lock
, flags
);
1991 ipg_w32(IPG_DC_TX_DMA_POLL_NOW
, DMA_CTRL
);
1993 if (sp
->tx_current
== (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))
1994 netif_stop_queue(dev
);
1996 spin_unlock_irqrestore(&sp
->lock
, flags
);
1998 return NETDEV_TX_OK
;
2001 static void ipg_set_phy_default_param(unsigned char rev
,
2002 struct net_device
*dev
, int phy_address
)
2004 unsigned short length
;
2005 unsigned char revision
;
2006 unsigned short *phy_param
;
2007 unsigned short address
, value
;
2009 phy_param
= &DefaultPhyParam
[0];
2010 length
= *phy_param
& 0x00FF;
2011 revision
= (unsigned char)((*phy_param
) >> 8);
2013 while (length
!= 0) {
2014 if (rev
== revision
) {
2015 while (length
> 1) {
2016 address
= *phy_param
;
2017 value
= *(phy_param
+ 1);
2019 mdio_write(dev
, phy_address
, address
, value
);
2024 phy_param
+= length
/ 2;
2025 length
= *phy_param
& 0x00FF;
2026 revision
= (unsigned char)((*phy_param
) >> 8);
2032 /* JES20040127EEPROM */
2033 static int read_eeprom(struct net_device
*dev
, int eep_addr
)
2035 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
2040 value
= IPG_EC_EEPROM_READOPCODE
| (eep_addr
& 0xff);
2041 ipg_w16(value
, EEPROM_CTRL
);
2043 for (i
= 0; i
< 1000; i
++) {
2047 data
= ipg_r16(EEPROM_CTRL
);
2048 if (!(data
& IPG_EC_EEPROM_BUSY
)) {
2049 ret
= ipg_r16(EEPROM_DATA
);
2056 static void ipg_init_mii(struct net_device
*dev
)
2058 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2059 struct mii_if_info
*mii_if
= &sp
->mii_if
;
2063 mii_if
->mdio_read
= mdio_read
;
2064 mii_if
->mdio_write
= mdio_write
;
2065 mii_if
->phy_id_mask
= 0x1f;
2066 mii_if
->reg_num_mask
= 0x1f;
2068 mii_if
->phy_id
= phyaddr
= ipg_find_phyaddr(dev
);
2070 if (phyaddr
!= 0x1f) {
2071 u16 mii_phyctrl
, mii_1000cr
;
2074 mii_1000cr
= mdio_read(dev
, phyaddr
, MII_CTRL1000
);
2075 mii_1000cr
|= ADVERTISE_1000FULL
| ADVERTISE_1000HALF
|
2076 GMII_PHY_1000BASETCONTROL_PreferMaster
;
2077 mdio_write(dev
, phyaddr
, MII_CTRL1000
, mii_1000cr
);
2079 mii_phyctrl
= mdio_read(dev
, phyaddr
, MII_BMCR
);
2081 /* Set default phyparam */
2082 pci_read_config_byte(sp
->pdev
, PCI_REVISION_ID
, &revisionid
);
2083 ipg_set_phy_default_param(revisionid
, dev
, phyaddr
);
2086 mii_phyctrl
|= BMCR_RESET
| BMCR_ANRESTART
;
2087 mdio_write(dev
, phyaddr
, MII_BMCR
, mii_phyctrl
);
2092 static int ipg_hw_init(struct net_device
*dev
)
2094 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2095 void __iomem
*ioaddr
= sp
->ioaddr
;
2099 /* Read/Write and Reset EEPROM Value Jesse20040128EEPROM_VALUE */
2100 /* Read LED Mode Configuration from EEPROM */
2101 sp
->LED_Mode
= read_eeprom(dev
, 6);
2103 /* Reset all functions within the IPG. Do not assert
2104 * RST_OUT as not compatible with some PHYs.
2106 rc
= ipg_reset(dev
, IPG_RESET_MASK
);
2112 /* Read MAC Address from EEPROM */
2113 for (i
= 0; i
< 3; i
++)
2114 sp
->station_addr
[i
] = read_eeprom(dev
, 16 + i
);
2116 for (i
= 0; i
< 3; i
++)
2117 ipg_w16(sp
->station_addr
[i
], STATION_ADDRESS_0
+ 2*i
);
2119 /* Set station address in ethernet_device structure. */
2120 dev
->dev_addr
[0] = ipg_r16(STATION_ADDRESS_0
) & 0x00ff;
2121 dev
->dev_addr
[1] = (ipg_r16(STATION_ADDRESS_0
) & 0xff00) >> 8;
2122 dev
->dev_addr
[2] = ipg_r16(STATION_ADDRESS_1
) & 0x00ff;
2123 dev
->dev_addr
[3] = (ipg_r16(STATION_ADDRESS_1
) & 0xff00) >> 8;
2124 dev
->dev_addr
[4] = ipg_r16(STATION_ADDRESS_2
) & 0x00ff;
2125 dev
->dev_addr
[5] = (ipg_r16(STATION_ADDRESS_2
) & 0xff00) >> 8;
2130 static int ipg_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2132 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2135 mutex_lock(&sp
->mii_mutex
);
2136 rc
= generic_mii_ioctl(&sp
->mii_if
, if_mii(ifr
), cmd
, NULL
);
2137 mutex_unlock(&sp
->mii_mutex
);
2142 static int ipg_nic_change_mtu(struct net_device
*dev
, int new_mtu
)
2144 /* Function to accomodate changes to Maximum Transfer Unit
2145 * (or MTU) of IPG NIC. Cannot use default function since
2146 * the default will not allow for MTU > 1500 bytes.
2149 IPG_DEBUG_MSG("_nic_change_mtu\n");
2151 /* Check that the new MTU value is between 68 (14 byte header, 46
2152 * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
2153 * corresponds to the MAXFRAMESIZE register in the IPG.
2155 if ((new_mtu
< 68) || (new_mtu
> IPG_MAX_RXFRAME_SIZE
))
2163 static int ipg_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2165 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2168 mutex_lock(&sp
->mii_mutex
);
2169 rc
= mii_ethtool_gset(&sp
->mii_if
, cmd
);
2170 mutex_unlock(&sp
->mii_mutex
);
2175 static int ipg_set_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_sset(&sp
->mii_if
, cmd
);
2182 mutex_unlock(&sp
->mii_mutex
);
2187 static int ipg_nway_reset(struct net_device
*dev
)
2189 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2192 mutex_lock(&sp
->mii_mutex
);
2193 rc
= mii_nway_restart(&sp
->mii_if
);
2194 mutex_unlock(&sp
->mii_mutex
);
2199 static struct ethtool_ops ipg_ethtool_ops
= {
2200 .get_settings
= ipg_get_settings
,
2201 .set_settings
= ipg_set_settings
,
2202 .nway_reset
= ipg_nway_reset
,
2205 static void ipg_remove(struct pci_dev
*pdev
)
2207 struct net_device
*dev
= pci_get_drvdata(pdev
);
2208 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2210 IPG_DEBUG_MSG("_remove\n");
2212 /* Un-register Ethernet device. */
2213 unregister_netdev(dev
);
2215 pci_iounmap(pdev
, sp
->ioaddr
);
2217 pci_release_regions(pdev
);
2220 pci_disable_device(pdev
);
2221 pci_set_drvdata(pdev
, NULL
);
2224 static int __devinit
ipg_probe(struct pci_dev
*pdev
,
2225 const struct pci_device_id
*id
)
2227 unsigned int i
= id
->driver_data
;
2228 struct ipg_nic_private
*sp
;
2229 struct net_device
*dev
;
2230 void __iomem
*ioaddr
;
2233 rc
= pci_enable_device(pdev
);
2237 printk(KERN_INFO
"%s: %s\n", pci_name(pdev
), ipg_brand_name
[i
]);
2239 pci_set_master(pdev
);
2241 rc
= pci_set_dma_mask(pdev
, DMA_40BIT_MASK
);
2243 rc
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
2245 printk(KERN_ERR
"%s: DMA config failed.\n",
2252 * Initialize net device.
2254 dev
= alloc_etherdev(sizeof(struct ipg_nic_private
));
2256 printk(KERN_ERR
"%s: alloc_etherdev failed\n", pci_name(pdev
));
2261 sp
= netdev_priv(dev
);
2262 spin_lock_init(&sp
->lock
);
2263 mutex_init(&sp
->mii_mutex
);
2265 /* Declare IPG NIC functions for Ethernet device methods.
2267 dev
->open
= &ipg_nic_open
;
2268 dev
->stop
= &ipg_nic_stop
;
2269 dev
->hard_start_xmit
= &ipg_nic_hard_start_xmit
;
2270 dev
->get_stats
= &ipg_nic_get_stats
;
2271 dev
->set_multicast_list
= &ipg_nic_set_multicast_list
;
2272 dev
->do_ioctl
= ipg_ioctl
;
2273 dev
->tx_timeout
= ipg_tx_timeout
;
2274 dev
->change_mtu
= &ipg_nic_change_mtu
;
2276 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2277 SET_ETHTOOL_OPS(dev
, &ipg_ethtool_ops
);
2279 rc
= pci_request_regions(pdev
, DRV_NAME
);
2281 goto err_free_dev_1
;
2283 ioaddr
= pci_iomap(pdev
, 1, pci_resource_len(pdev
, 1));
2285 printk(KERN_ERR
"%s cannot map MMIO\n", pci_name(pdev
));
2287 goto err_release_regions_2
;
2290 /* Save the pointer to the PCI device information. */
2291 sp
->ioaddr
= ioaddr
;
2295 INIT_DELAYED_WORK(&sp
->task
, ipg_reset_after_host_error
);
2297 pci_set_drvdata(pdev
, dev
);
2299 rc
= ipg_hw_init(dev
);
2303 rc
= register_netdev(dev
);
2307 printk(KERN_INFO
"Ethernet device registered as: %s\n", dev
->name
);
2312 pci_iounmap(pdev
, ioaddr
);
2313 err_release_regions_2
:
2314 pci_release_regions(pdev
);
2318 pci_disable_device(pdev
);
2322 static struct pci_driver ipg_pci_driver
= {
2323 .name
= IPG_DRIVER_NAME
,
2324 .id_table
= ipg_pci_tbl
,
2326 .remove
= __devexit_p(ipg_remove
),
2329 static int __init
ipg_init_module(void)
2331 return pci_register_driver(&ipg_pci_driver
);
2334 static void __exit
ipg_exit_module(void)
2336 pci_unregister_driver(&ipg_pci_driver
);
2339 module_init(ipg_init_module
);
2340 module_exit(ipg_exit_module
);