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");
55 MODULE_LICENSE("GPL");
58 * Variable record -- index by leading revision/length
59 * Revision/Length(=N*4), Address1, Data1, Address2, Data2,...,AddressN,DataN
61 static unsigned short DefaultPhyParam
[] = {
62 /* 11/12/03 IP1000A v1-3 rev=0x40 */
63 /*--------------------------------------------------------------------------
64 (0x4000|(15*4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 22, 0x85bd, 24, 0xfff2,
65 27, 0x0c10, 28, 0x0c10, 29, 0x2c10, 31, 0x0003, 23, 0x92f6,
66 31, 0x0000, 23, 0x003d, 30, 0x00de, 20, 0x20e7, 9, 0x0700,
67 --------------------------------------------------------------------------*/
68 /* 12/17/03 IP1000A v1-4 rev=0x40 */
69 (0x4000 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
71 30, 0x005e, 9, 0x0700,
72 /* 01/09/04 IP1000A v1-5 rev=0x41 */
73 (0x4100 | (07 * 4)), 31, 0x0001, 27, 0x01e0, 31, 0x0002, 27, 0xeb8e, 31,
75 30, 0x005e, 9, 0x0700,
79 static const char *ipg_brand_name
[] = {
80 "IC PLUS IP1000 1000/100/10 based NIC",
81 "Sundance Technology ST2021 based NIC",
82 "Tamarack Microelectronics TC9020/9021 based NIC",
83 "Tamarack Microelectronics TC9020/9021 based NIC",
88 static struct pci_device_id ipg_pci_tbl
[] __devinitdata
= {
89 { PCI_VDEVICE(SUNDANCE
, 0x1023), 0 },
90 { PCI_VDEVICE(SUNDANCE
, 0x2021), 1 },
91 { PCI_VDEVICE(SUNDANCE
, 0x1021), 2 },
92 { PCI_VDEVICE(DLINK
, 0x9021), 3 },
93 { PCI_VDEVICE(DLINK
, 0x4000), 4 },
94 { PCI_VDEVICE(DLINK
, 0x4020), 5 },
98 MODULE_DEVICE_TABLE(pci
, ipg_pci_tbl
);
100 static inline void __iomem
*ipg_ioaddr(struct net_device
*dev
)
102 struct ipg_nic_private
*sp
= netdev_priv(dev
);
107 static void ipg_dump_rfdlist(struct net_device
*dev
)
109 struct ipg_nic_private
*sp
= netdev_priv(dev
);
110 void __iomem
*ioaddr
= sp
->ioaddr
;
114 IPG_DEBUG_MSG("_dump_rfdlist\n");
116 printk(KERN_INFO
"rx_current = %2.2x\n", sp
->rx_current
);
117 printk(KERN_INFO
"rx_dirty = %2.2x\n", sp
->rx_dirty
);
118 printk(KERN_INFO
"RFDList start address = %16.16lx\n",
119 (unsigned long) sp
->rxd_map
);
120 printk(KERN_INFO
"RFDListPtr register = %8.8x%8.8x\n",
121 ipg_r32(IPG_RFDLISTPTR1
), ipg_r32(IPG_RFDLISTPTR0
));
123 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
124 offset
= (u32
) &sp
->rxd
[i
].next_desc
- (u32
) sp
->rxd
;
125 printk(KERN_INFO
"%2.2x %4.4x RFDNextPtr = %16.16lx\n", i
,
126 offset
, (unsigned long) sp
->rxd
[i
].next_desc
);
127 offset
= (u32
) &sp
->rxd
[i
].rfs
- (u32
) sp
->rxd
;
128 printk(KERN_INFO
"%2.2x %4.4x RFS = %16.16lx\n", i
,
129 offset
, (unsigned long) sp
->rxd
[i
].rfs
);
130 offset
= (u32
) &sp
->rxd
[i
].frag_info
- (u32
) sp
->rxd
;
131 printk(KERN_INFO
"%2.2x %4.4x frag_info = %16.16lx\n", i
,
132 offset
, (unsigned long) sp
->rxd
[i
].frag_info
);
136 static void ipg_dump_tfdlist(struct net_device
*dev
)
138 struct ipg_nic_private
*sp
= netdev_priv(dev
);
139 void __iomem
*ioaddr
= sp
->ioaddr
;
143 IPG_DEBUG_MSG("_dump_tfdlist\n");
145 printk(KERN_INFO
"tx_current = %2.2x\n", sp
->tx_current
);
146 printk(KERN_INFO
"tx_dirty = %2.2x\n", sp
->tx_dirty
);
147 printk(KERN_INFO
"TFDList start address = %16.16lx\n",
148 (unsigned long) sp
->txd_map
);
149 printk(KERN_INFO
"TFDListPtr register = %8.8x%8.8x\n",
150 ipg_r32(IPG_TFDLISTPTR1
), ipg_r32(IPG_TFDLISTPTR0
));
152 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
153 offset
= (u32
) &sp
->txd
[i
].next_desc
- (u32
) sp
->txd
;
154 printk(KERN_INFO
"%2.2x %4.4x TFDNextPtr = %16.16lx\n", i
,
155 offset
, (unsigned long) sp
->txd
[i
].next_desc
);
157 offset
= (u32
) &sp
->txd
[i
].tfc
- (u32
) sp
->txd
;
158 printk(KERN_INFO
"%2.2x %4.4x TFC = %16.16lx\n", i
,
159 offset
, (unsigned long) sp
->txd
[i
].tfc
);
160 offset
= (u32
) &sp
->txd
[i
].frag_info
- (u32
) sp
->txd
;
161 printk(KERN_INFO
"%2.2x %4.4x frag_info = %16.16lx\n", i
,
162 offset
, (unsigned long) sp
->txd
[i
].frag_info
);
167 static void ipg_write_phy_ctl(void __iomem
*ioaddr
, u8 data
)
169 ipg_w8(IPG_PC_RSVD_MASK
& data
, PHY_CTRL
);
170 ndelay(IPG_PC_PHYCTRLWAIT_NS
);
173 static void ipg_drive_phy_ctl_low_high(void __iomem
*ioaddr
, u8 data
)
175 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| data
);
176 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| data
);
179 static void send_three_state(void __iomem
*ioaddr
, u8 phyctrlpolarity
)
181 phyctrlpolarity
|= (IPG_PC_MGMTDATA
& 0) | IPG_PC_MGMTDIR
;
183 ipg_drive_phy_ctl_low_high(ioaddr
, phyctrlpolarity
);
186 static void send_end(void __iomem
*ioaddr
, u8 phyctrlpolarity
)
188 ipg_w8((IPG_PC_MGMTCLK_LO
| (IPG_PC_MGMTDATA
& 0) | IPG_PC_MGMTDIR
|
189 phyctrlpolarity
) & IPG_PC_RSVD_MASK
, PHY_CTRL
);
192 static u16
read_phy_bit(void __iomem
*ioaddr
, u8 phyctrlpolarity
)
196 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| phyctrlpolarity
);
198 bit_data
= ((ipg_r8(PHY_CTRL
) & IPG_PC_MGMTDATA
) >> 1) & 1;
200 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| phyctrlpolarity
);
206 * Read a register from the Physical Layer device located
207 * on the IPG NIC, using the IPG PHYCTRL register.
209 static int mdio_read(struct net_device
*dev
, int phy_id
, int phy_reg
)
211 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
213 * The GMII mangement frame structure for a read is as follows:
215 * |Preamble|st|op|phyad|regad|ta| data |idle|
216 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
218 * <32 1s> = 32 consecutive logic 1 values
219 * A = bit of Physical Layer device address (MSB first)
220 * R = bit of register address (MSB first)
221 * z = High impedance state
222 * D = bit of read data (MSB first)
224 * Transmission order is 'Preamble' field first, bits transmitted
225 * left to right (first to last).
231 { GMII_PREAMBLE
, 32 }, /* Preamble */
232 { GMII_ST
, 2 }, /* ST */
233 { GMII_READ
, 2 }, /* OP */
234 { phy_id
, 5 }, /* PHYAD */
235 { phy_reg
, 5 }, /* REGAD */
236 { 0x0000, 2 }, /* TA */
237 { 0x0000, 16 }, /* DATA */
238 { 0x0000, 1 } /* IDLE */
243 polarity
= ipg_r8(PHY_CTRL
);
244 polarity
&= (IPG_PC_DUPLEX_POLARITY
| IPG_PC_LINK_POLARITY
);
246 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
247 for (j
= 0; j
< 5; j
++) {
248 for (i
= 0; i
< p
[j
].len
; i
++) {
249 /* For each variable length field, the MSB must be
250 * transmitted first. Rotate through the field bits,
251 * starting with the MSB, and move each bit into the
252 * the 1st (2^1) bit position (this is the bit position
253 * corresponding to the MgmtData bit of the PhyCtrl
254 * register for the IPG).
258 * First write a '0' to bit 1 of the PhyCtrl
259 * register, then write a '1' to bit 1 of the
262 * To do this, right shift the MSB of ST by the value:
263 * [field length - 1 - #ST bits already written]
264 * then left shift this result by 1.
266 data
= (p
[j
].field
>> (p
[j
].len
- 1 - i
)) << 1;
267 data
&= IPG_PC_MGMTDATA
;
268 data
|= polarity
| IPG_PC_MGMTDIR
;
270 ipg_drive_phy_ctl_low_high(ioaddr
, data
);
274 send_three_state(ioaddr
, polarity
);
276 read_phy_bit(ioaddr
, polarity
);
279 * For a read cycle, the bits for the next two fields (TA and
280 * DATA) are driven by the PHY (the IPG reads these bits).
282 for (i
= 0; i
< p
[6].len
; i
++) {
284 (read_phy_bit(ioaddr
, polarity
) << (p
[6].len
- 1 - i
));
287 send_three_state(ioaddr
, polarity
);
288 send_three_state(ioaddr
, polarity
);
289 send_three_state(ioaddr
, polarity
);
290 send_end(ioaddr
, polarity
);
292 /* Return the value of the DATA field. */
297 * Write to a register from the Physical Layer device located
298 * on the IPG NIC, using the IPG PHYCTRL register.
300 static void mdio_write(struct net_device
*dev
, int phy_id
, int phy_reg
, int val
)
302 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
304 * The GMII mangement frame structure for a read is as follows:
306 * |Preamble|st|op|phyad|regad|ta| data |idle|
307 * |< 32 1s>|01|10|AAAAA|RRRRR|z0|DDDDDDDDDDDDDDDD|z |
309 * <32 1s> = 32 consecutive logic 1 values
310 * A = bit of Physical Layer device address (MSB first)
311 * R = bit of register address (MSB first)
312 * z = High impedance state
313 * D = bit of write data (MSB first)
315 * Transmission order is 'Preamble' field first, bits transmitted
316 * left to right (first to last).
322 { GMII_PREAMBLE
, 32 }, /* Preamble */
323 { GMII_ST
, 2 }, /* ST */
324 { GMII_WRITE
, 2 }, /* OP */
325 { phy_id
, 5 }, /* PHYAD */
326 { phy_reg
, 5 }, /* REGAD */
327 { 0x0002, 2 }, /* TA */
328 { val
& 0xffff, 16 }, /* DATA */
329 { 0x0000, 1 } /* IDLE */
334 polarity
= ipg_r8(PHY_CTRL
);
335 polarity
&= (IPG_PC_DUPLEX_POLARITY
| IPG_PC_LINK_POLARITY
);
337 /* Create the Preamble, ST, OP, PHYAD, and REGAD field. */
338 for (j
= 0; j
< 7; j
++) {
339 for (i
= 0; i
< p
[j
].len
; i
++) {
340 /* For each variable length field, the MSB must be
341 * transmitted first. Rotate through the field bits,
342 * starting with the MSB, and move each bit into the
343 * the 1st (2^1) bit position (this is the bit position
344 * corresponding to the MgmtData bit of the PhyCtrl
345 * register for the IPG).
349 * First write a '0' to bit 1 of the PhyCtrl
350 * register, then write a '1' to bit 1 of the
353 * To do this, right shift the MSB of ST by the value:
354 * [field length - 1 - #ST bits already written]
355 * then left shift this result by 1.
357 data
= (p
[j
].field
>> (p
[j
].len
- 1 - i
)) << 1;
358 data
&= IPG_PC_MGMTDATA
;
359 data
|= polarity
| IPG_PC_MGMTDIR
;
361 ipg_drive_phy_ctl_low_high(ioaddr
, data
);
365 /* The last cycle is a tri-state, so read from the PHY. */
366 for (j
= 7; j
< 8; j
++) {
367 for (i
= 0; i
< p
[j
].len
; i
++) {
368 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_LO
| polarity
);
370 p
[j
].field
|= ((ipg_r8(PHY_CTRL
) &
371 IPG_PC_MGMTDATA
) >> 1) << (p
[j
].len
- 1 - i
);
373 ipg_write_phy_ctl(ioaddr
, IPG_PC_MGMTCLK_HI
| polarity
);
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 static void ipg_set_phy_set(struct net_device
*dev
)
401 struct ipg_nic_private
*sp
= netdev_priv(dev
);
402 void __iomem
*ioaddr
= sp
->ioaddr
;
405 physet
= ipg_r8(PHY_SET
);
406 physet
&= ~(IPG_PS_MEM_LENB9B
| IPG_PS_MEM_LEN9
| IPG_PS_NON_COMPDET
);
407 physet
|= ((sp
->led_mode
& 0x70) >> 4);
408 ipg_w8(physet
, PHY_SET
);
411 static int ipg_reset(struct net_device
*dev
, u32 resetflags
)
413 /* Assert functional resets via the IPG AsicCtrl
414 * register as specified by the 'resetflags' input
417 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
418 unsigned int timeout_count
= 0;
420 IPG_DEBUG_MSG("_reset\n");
422 ipg_w32(ipg_r32(ASIC_CTRL
) | resetflags
, ASIC_CTRL
);
424 /* Delay added to account for problem with 10Mbps reset. */
425 mdelay(IPG_AC_RESETWAIT
);
427 while (IPG_AC_RESET_BUSY
& ipg_r32(ASIC_CTRL
)) {
428 mdelay(IPG_AC_RESETWAIT
);
429 if (++timeout_count
> IPG_AC_RESET_TIMEOUT
)
432 /* Set LED Mode in Asic Control */
433 ipg_set_led_mode(dev
);
435 /* Set PHYSet Register Value */
436 ipg_set_phy_set(dev
);
440 /* Find the GMII PHY address. */
441 static int ipg_find_phyaddr(struct net_device
*dev
)
443 unsigned int phyaddr
, i
;
445 for (i
= 0; i
< 32; i
++) {
448 /* Search for the correct PHY address among 32 possible. */
449 phyaddr
= (IPG_NIC_PHY_ADDRESS
+ i
) % 32;
451 /* 10/22/03 Grace change verify from GMII_PHY_STATUS to
455 status
= mdio_read(dev
, phyaddr
, MII_BMSR
);
457 if ((status
!= 0xFFFF) && (status
!= 0))
465 * Configure IPG based on result of IEEE 802.3 PHY
468 static int ipg_config_autoneg(struct net_device
*dev
)
470 struct ipg_nic_private
*sp
= netdev_priv(dev
);
471 void __iomem
*ioaddr
= sp
->ioaddr
;
472 unsigned int txflowcontrol
;
473 unsigned int rxflowcontrol
;
474 unsigned int fullduplex
;
480 IPG_DEBUG_MSG("_config_autoneg\n");
482 asicctrl
= ipg_r32(ASIC_CTRL
);
483 phyctrl
= ipg_r8(PHY_CTRL
);
484 mac_ctrl_val
= ipg_r32(MAC_CTRL
);
486 /* Set flags for use in resolving auto-negotation, assuming
487 * non-1000Mbps, half duplex, no flow control.
494 /* To accomodate a problem in 10Mbps operation,
495 * set a global flag if PHY running in 10Mbps mode.
499 printk(KERN_INFO
"%s: Link speed = ", dev
->name
);
501 /* Determine actual speed of operation. */
502 switch (phyctrl
& IPG_PC_LINK_SPEED
) {
503 case IPG_PC_LINK_SPEED_10MBPS
:
505 printk(KERN_INFO
"%s: 10Mbps operational mode enabled.\n",
509 case IPG_PC_LINK_SPEED_100MBPS
:
510 printk("100Mbps.\n");
512 case IPG_PC_LINK_SPEED_1000MBPS
:
513 printk("1000Mbps.\n");
517 printk("undefined!\n");
521 if (phyctrl
& IPG_PC_DUPLEX_STATUS
) {
527 /* Configure full duplex, and flow control. */
528 if (fullduplex
== 1) {
529 /* Configure IPG for full duplex operation. */
530 printk(KERN_INFO
"%s: setting full duplex, ", dev
->name
);
532 mac_ctrl_val
|= IPG_MC_DUPLEX_SELECT_FD
;
534 if (txflowcontrol
== 1) {
535 printk("TX flow control");
536 mac_ctrl_val
|= IPG_MC_TX_FLOW_CONTROL_ENABLE
;
538 printk("no TX flow control");
539 mac_ctrl_val
&= ~IPG_MC_TX_FLOW_CONTROL_ENABLE
;
542 if (rxflowcontrol
== 1) {
543 printk(", RX flow control.");
544 mac_ctrl_val
|= IPG_MC_RX_FLOW_CONTROL_ENABLE
;
546 printk(", no RX flow control.");
547 mac_ctrl_val
&= ~IPG_MC_RX_FLOW_CONTROL_ENABLE
;
552 /* Configure IPG for half duplex operation. */
553 printk(KERN_INFO
"%s: setting half duplex, "
554 "no TX flow control, no RX flow control.\n", dev
->name
);
556 mac_ctrl_val
&= ~IPG_MC_DUPLEX_SELECT_FD
&
557 ~IPG_MC_TX_FLOW_CONTROL_ENABLE
&
558 ~IPG_MC_RX_FLOW_CONTROL_ENABLE
;
560 ipg_w32(mac_ctrl_val
, MAC_CTRL
);
564 /* Determine and configure multicast operation and set
565 * receive mode for IPG.
567 static void ipg_nic_set_multicast_list(struct net_device
*dev
)
569 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
570 struct dev_mc_list
*mc_list_ptr
;
571 unsigned int hashindex
;
575 IPG_DEBUG_MSG("_nic_set_multicast_list\n");
577 receivemode
= IPG_RM_RECEIVEUNICAST
| IPG_RM_RECEIVEBROADCAST
;
579 if (dev
->flags
& IFF_PROMISC
) {
580 /* NIC to be configured in promiscuous mode. */
581 receivemode
= IPG_RM_RECEIVEALLFRAMES
;
582 } else if ((dev
->flags
& IFF_ALLMULTI
) ||
583 (dev
->flags
& IFF_MULTICAST
&
584 (dev
->mc_count
> IPG_MULTICAST_HASHTABLE_SIZE
))) {
585 /* NIC to be configured to receive all multicast
587 receivemode
|= IPG_RM_RECEIVEMULTICAST
;
588 } else if (dev
->flags
& IFF_MULTICAST
& (dev
->mc_count
> 0)) {
589 /* NIC to be configured to receive selected
590 * multicast addresses. */
591 receivemode
|= IPG_RM_RECEIVEMULTICASTHASH
;
594 /* Calculate the bits to set for the 64 bit, IPG HASHTABLE.
595 * The IPG applies a cyclic-redundancy-check (the same CRC
596 * used to calculate the frame data FCS) to the destination
597 * address all incoming multicast frames whose destination
598 * address has the multicast bit set. The least significant
599 * 6 bits of the CRC result are used as an addressing index
600 * into the hash table. If the value of the bit addressed by
601 * this index is a 1, the frame is passed to the host system.
604 /* Clear hashtable. */
605 hashtable
[0] = 0x00000000;
606 hashtable
[1] = 0x00000000;
608 /* Cycle through all multicast addresses to filter. */
609 for (mc_list_ptr
= dev
->mc_list
;
610 mc_list_ptr
!= NULL
; mc_list_ptr
= mc_list_ptr
->next
) {
611 /* Calculate CRC result for each multicast address. */
612 hashindex
= crc32_le(0xffffffff, mc_list_ptr
->dmi_addr
,
615 /* Use only the least significant 6 bits. */
616 hashindex
= hashindex
& 0x3F;
618 /* Within "hashtable", set bit number "hashindex"
621 set_bit(hashindex
, (void *)hashtable
);
624 /* Write the value of the hashtable, to the 4, 16 bit
625 * HASHTABLE IPG registers.
627 ipg_w32(hashtable
[0], HASHTABLE_0
);
628 ipg_w32(hashtable
[1], HASHTABLE_1
);
630 ipg_w8(IPG_RM_RSVD_MASK
& receivemode
, RECEIVE_MODE
);
632 IPG_DEBUG_MSG("ReceiveMode = %x\n", ipg_r8(RECEIVE_MODE
));
635 static int ipg_io_config(struct net_device
*dev
)
637 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
641 IPG_DEBUG_MSG("_io_config\n");
643 origmacctrl
= ipg_r32(MAC_CTRL
);
645 restoremacctrl
= origmacctrl
| IPG_MC_STATISTICS_ENABLE
;
647 /* Based on compilation option, determine if FCS is to be
648 * stripped on receive frames by IPG.
650 if (!IPG_STRIP_FCS_ON_RX
)
651 restoremacctrl
|= IPG_MC_RCV_FCS
;
653 /* Determine if transmitter and/or receiver are
654 * enabled so we may restore MACCTRL correctly.
656 if (origmacctrl
& IPG_MC_TX_ENABLED
)
657 restoremacctrl
|= IPG_MC_TX_ENABLE
;
659 if (origmacctrl
& IPG_MC_RX_ENABLED
)
660 restoremacctrl
|= IPG_MC_RX_ENABLE
;
662 /* Transmitter and receiver must be disabled before setting
665 ipg_w32((origmacctrl
& (IPG_MC_RX_DISABLE
| IPG_MC_TX_DISABLE
)) &
666 IPG_MC_RSVD_MASK
, MAC_CTRL
);
668 /* Now that transmitter and receiver are disabled, write
671 ipg_w32((origmacctrl
& IPG_MC_IFS_96BIT
) & IPG_MC_RSVD_MASK
, MAC_CTRL
);
673 /* Set RECEIVEMODE register. */
674 ipg_nic_set_multicast_list(dev
);
676 ipg_w16(IPG_MAX_RXFRAME_SIZE
, MAX_FRAME_SIZE
);
678 ipg_w8(IPG_RXDMAPOLLPERIOD_VALUE
, RX_DMA_POLL_PERIOD
);
679 ipg_w8(IPG_RXDMAURGENTTHRESH_VALUE
, RX_DMA_URGENT_THRESH
);
680 ipg_w8(IPG_RXDMABURSTTHRESH_VALUE
, RX_DMA_BURST_THRESH
);
681 ipg_w8(IPG_TXDMAPOLLPERIOD_VALUE
, TX_DMA_POLL_PERIOD
);
682 ipg_w8(IPG_TXDMAURGENTTHRESH_VALUE
, TX_DMA_URGENT_THRESH
);
683 ipg_w8(IPG_TXDMABURSTTHRESH_VALUE
, TX_DMA_BURST_THRESH
);
684 ipg_w16((IPG_IE_HOST_ERROR
| IPG_IE_TX_DMA_COMPLETE
|
685 IPG_IE_TX_COMPLETE
| IPG_IE_INT_REQUESTED
|
686 IPG_IE_UPDATE_STATS
| IPG_IE_LINK_EVENT
|
687 IPG_IE_RX_DMA_COMPLETE
| IPG_IE_RX_DMA_PRIORITY
), INT_ENABLE
);
688 ipg_w16(IPG_FLOWONTHRESH_VALUE
, FLOW_ON_THRESH
);
689 ipg_w16(IPG_FLOWOFFTHRESH_VALUE
, FLOW_OFF_THRESH
);
691 /* IPG multi-frag frame bug workaround.
692 * Per silicon revision B3 eratta.
694 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0200, DEBUG_CTRL
);
696 /* IPG TX poll now bug workaround.
697 * Per silicon revision B3 eratta.
699 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0010, DEBUG_CTRL
);
701 /* IPG RX poll now bug workaround.
702 * Per silicon revision B3 eratta.
704 ipg_w16(ipg_r16(DEBUG_CTRL
) | 0x0020, DEBUG_CTRL
);
706 /* Now restore MACCTRL to original setting. */
707 ipg_w32(IPG_MC_RSVD_MASK
& restoremacctrl
, MAC_CTRL
);
709 /* Disable unused RMON statistics. */
710 ipg_w32(IPG_RZ_ALL
, RMON_STATISTICS_MASK
);
712 /* Disable unused MIB statistics. */
713 ipg_w32(IPG_SM_MACCONTROLFRAMESXMTD
| IPG_SM_MACCONTROLFRAMESRCVD
|
714 IPG_SM_BCSTOCTETXMTOK_BCSTFRAMESXMTDOK
| IPG_SM_TXJUMBOFRAMES
|
715 IPG_SM_MCSTOCTETXMTOK_MCSTFRAMESXMTDOK
| IPG_SM_RXJUMBOFRAMES
|
716 IPG_SM_BCSTOCTETRCVDOK_BCSTFRAMESRCVDOK
|
717 IPG_SM_UDPCHECKSUMERRORS
| IPG_SM_TCPCHECKSUMERRORS
|
718 IPG_SM_IPCHECKSUMERRORS
, STATISTICS_MASK
);
724 * Create a receive buffer within system memory and update
725 * NIC private structure appropriately.
727 static int ipg_get_rxbuff(struct net_device
*dev
, int entry
)
729 struct ipg_nic_private
*sp
= netdev_priv(dev
);
730 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
734 IPG_DEBUG_MSG("_get_rxbuff\n");
736 skb
= netdev_alloc_skb(dev
, IPG_RXSUPPORT_SIZE
+ NET_IP_ALIGN
);
738 sp
->rx_buff
[entry
] = NULL
;
742 /* Adjust the data start location within the buffer to
743 * align IP address field to a 16 byte boundary.
745 skb_reserve(skb
, NET_IP_ALIGN
);
747 /* Associate the receive buffer with the IPG NIC. */
750 /* Save the address of the sk_buff structure. */
751 sp
->rx_buff
[entry
] = skb
;
753 rxfd
->frag_info
= cpu_to_le64(pci_map_single(sp
->pdev
, skb
->data
,
754 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
));
756 /* Set the RFD fragment length. */
757 rxfragsize
= IPG_RXFRAG_SIZE
;
758 rxfd
->frag_info
|= cpu_to_le64((rxfragsize
<< 48) & IPG_RFI_FRAGLEN
);
763 static int init_rfdlist(struct net_device
*dev
)
765 struct ipg_nic_private
*sp
= netdev_priv(dev
);
766 void __iomem
*ioaddr
= sp
->ioaddr
;
769 IPG_DEBUG_MSG("_init_rfdlist\n");
771 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
772 struct ipg_rx
*rxfd
= sp
->rxd
+ i
;
774 if (sp
->rx_buff
[i
]) {
775 pci_unmap_single(sp
->pdev
,
776 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
777 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
778 dev_kfree_skb_irq(sp
->rx_buff
[i
]);
779 sp
->rx_buff
[i
] = NULL
;
782 /* Clear out the RFS field. */
783 rxfd
->rfs
= 0x0000000000000000;
785 if (ipg_get_rxbuff(dev
, i
) < 0) {
787 * A receive buffer was not ready, break the
790 IPG_DEBUG_MSG("Cannot allocate Rx buffer.\n");
792 /* Just in case we cannot allocate a single RFD.
796 printk(KERN_ERR
"%s: No memory available"
797 " for RFD list.\n", dev
->name
);
802 rxfd
->next_desc
= cpu_to_le64(sp
->rxd_map
+
803 sizeof(struct ipg_rx
)*(i
+ 1));
805 sp
->rxd
[i
- 1].next_desc
= cpu_to_le64(sp
->rxd_map
);
810 /* Write the location of the RFDList to the IPG. */
811 ipg_w32((u32
) sp
->rxd_map
, RFD_LIST_PTR_0
);
812 ipg_w32(0x00000000, RFD_LIST_PTR_1
);
817 static void init_tfdlist(struct net_device
*dev
)
819 struct ipg_nic_private
*sp
= netdev_priv(dev
);
820 void __iomem
*ioaddr
= sp
->ioaddr
;
823 IPG_DEBUG_MSG("_init_tfdlist\n");
825 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
826 struct ipg_tx
*txfd
= sp
->txd
+ i
;
828 txfd
->tfc
= cpu_to_le64(IPG_TFC_TFDDONE
);
830 if (sp
->tx_buff
[i
]) {
831 dev_kfree_skb_irq(sp
->tx_buff
[i
]);
832 sp
->tx_buff
[i
] = NULL
;
835 txfd
->next_desc
= cpu_to_le64(sp
->txd_map
+
836 sizeof(struct ipg_tx
)*(i
+ 1));
838 sp
->txd
[i
- 1].next_desc
= cpu_to_le64(sp
->txd_map
);
843 /* Write the location of the TFDList to the IPG. */
844 IPG_DDEBUG_MSG("Starting TFDListPtr = %8.8x\n",
846 ipg_w32((u32
) sp
->txd_map
, TFD_LIST_PTR_0
);
847 ipg_w32(0x00000000, TFD_LIST_PTR_1
);
849 sp
->reset_current_tfd
= 1;
853 * Free all transmit buffers which have already been transfered
854 * via DMA to the IPG.
856 static void ipg_nic_txfree(struct net_device
*dev
)
858 struct ipg_nic_private
*sp
= netdev_priv(dev
);
859 unsigned int released
, pending
, dirty
;
861 IPG_DEBUG_MSG("_nic_txfree\n");
863 pending
= sp
->tx_current
- sp
->tx_dirty
;
864 dirty
= sp
->tx_dirty
% IPG_TFDLIST_LENGTH
;
866 for (released
= 0; released
< pending
; released
++) {
867 struct sk_buff
*skb
= sp
->tx_buff
[dirty
];
868 struct ipg_tx
*txfd
= sp
->txd
+ dirty
;
870 IPG_DEBUG_MSG("TFC = %16.16lx\n", (unsigned long) txfd
->tfc
);
872 /* Look at each TFD's TFC field beginning
873 * at the last freed TFD up to the current TFD.
874 * If the TFDDone bit is set, free the associated
877 if (!(txfd
->tfc
& cpu_to_le64(IPG_TFC_TFDDONE
)))
880 /* Free the transmit buffer. */
882 pci_unmap_single(sp
->pdev
,
883 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
884 skb
->len
, PCI_DMA_TODEVICE
);
886 dev_kfree_skb_irq(skb
);
888 sp
->tx_buff
[dirty
] = NULL
;
890 dirty
= (dirty
+ 1) % IPG_TFDLIST_LENGTH
;
893 sp
->tx_dirty
+= released
;
895 if (netif_queue_stopped(dev
) &&
896 (sp
->tx_current
!= (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))) {
897 netif_wake_queue(dev
);
901 static void ipg_tx_timeout(struct net_device
*dev
)
903 struct ipg_nic_private
*sp
= netdev_priv(dev
);
904 void __iomem
*ioaddr
= sp
->ioaddr
;
906 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
| IPG_AC_NETWORK
|
909 spin_lock_irq(&sp
->lock
);
911 /* Re-configure after DMA reset. */
912 if (ipg_io_config(dev
) < 0) {
913 printk(KERN_INFO
"%s: Error during re-configuration.\n",
919 spin_unlock_irq(&sp
->lock
);
921 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) & IPG_MC_RSVD_MASK
,
926 * For TxComplete interrupts, free all transmit
927 * buffers which have already been transfered via DMA
930 static void ipg_nic_txcleanup(struct net_device
*dev
)
932 struct ipg_nic_private
*sp
= netdev_priv(dev
);
933 void __iomem
*ioaddr
= sp
->ioaddr
;
936 IPG_DEBUG_MSG("_nic_txcleanup\n");
938 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
939 /* Reading the TXSTATUS register clears the
940 * TX_COMPLETE interrupt.
942 u32 txstatusdword
= ipg_r32(TX_STATUS
);
944 IPG_DEBUG_MSG("TxStatus = %8.8x\n", txstatusdword
);
946 /* Check for Transmit errors. Error bits only valid if
947 * TX_COMPLETE bit in the TXSTATUS register is a 1.
949 if (!(txstatusdword
& IPG_TS_TX_COMPLETE
))
952 /* If in 10Mbps mode, indicate transmit is ready. */
953 if (sp
->tenmbpsmode
) {
954 netif_wake_queue(dev
);
957 /* Transmit error, increment stat counters. */
958 if (txstatusdword
& IPG_TS_TX_ERROR
) {
959 IPG_DEBUG_MSG("Transmit error.\n");
960 sp
->stats
.tx_errors
++;
963 /* Late collision, re-enable transmitter. */
964 if (txstatusdword
& IPG_TS_LATE_COLLISION
) {
965 IPG_DEBUG_MSG("Late collision on transmit.\n");
966 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
967 IPG_MC_RSVD_MASK
, MAC_CTRL
);
970 /* Maximum collisions, re-enable transmitter. */
971 if (txstatusdword
& IPG_TS_TX_MAX_COLL
) {
972 IPG_DEBUG_MSG("Maximum collisions on transmit.\n");
973 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
974 IPG_MC_RSVD_MASK
, MAC_CTRL
);
977 /* Transmit underrun, reset and re-enable
980 if (txstatusdword
& IPG_TS_TX_UNDERRUN
) {
981 IPG_DEBUG_MSG("Transmitter underrun.\n");
982 sp
->stats
.tx_fifo_errors
++;
983 ipg_reset(dev
, IPG_AC_TX_RESET
| IPG_AC_DMA
|
984 IPG_AC_NETWORK
| IPG_AC_FIFO
);
986 /* Re-configure after DMA reset. */
987 if (ipg_io_config(dev
) < 0) {
989 "%s: Error during re-configuration.\n",
994 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_TX_ENABLE
) &
995 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1002 /* Provides statistical information about the IPG NIC. */
1003 static struct net_device_stats
*ipg_nic_get_stats(struct net_device
*dev
)
1005 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1006 void __iomem
*ioaddr
= sp
->ioaddr
;
1010 IPG_DEBUG_MSG("_nic_get_stats\n");
1012 /* Check to see if the NIC has been initialized via nic_open,
1013 * before trying to read statistic registers.
1015 if (!test_bit(__LINK_STATE_START
, &dev
->state
))
1018 sp
->stats
.rx_packets
+= ipg_r32(IPG_FRAMESRCVDOK
);
1019 sp
->stats
.tx_packets
+= ipg_r32(IPG_FRAMESXMTDOK
);
1020 sp
->stats
.rx_bytes
+= ipg_r32(IPG_OCTETRCVOK
);
1021 sp
->stats
.tx_bytes
+= ipg_r32(IPG_OCTETXMTOK
);
1022 temp1
= ipg_r16(IPG_FRAMESLOSTRXERRORS
);
1023 sp
->stats
.rx_errors
+= temp1
;
1024 sp
->stats
.rx_missed_errors
+= temp1
;
1025 temp1
= ipg_r32(IPG_SINGLECOLFRAMES
) + ipg_r32(IPG_MULTICOLFRAMES
) +
1026 ipg_r32(IPG_LATECOLLISIONS
);
1027 temp2
= ipg_r16(IPG_CARRIERSENSEERRORS
);
1028 sp
->stats
.collisions
+= temp1
;
1029 sp
->stats
.tx_dropped
+= ipg_r16(IPG_FRAMESABORTXSCOLLS
);
1030 sp
->stats
.tx_errors
+= ipg_r16(IPG_FRAMESWEXDEFERRAL
) +
1031 ipg_r32(IPG_FRAMESWDEFERREDXMT
) + temp1
+ temp2
;
1032 sp
->stats
.multicast
+= ipg_r32(IPG_MCSTOCTETRCVDOK
);
1034 /* detailed tx_errors */
1035 sp
->stats
.tx_carrier_errors
+= temp2
;
1037 /* detailed rx_errors */
1038 sp
->stats
.rx_length_errors
+= ipg_r16(IPG_INRANGELENGTHERRORS
) +
1039 ipg_r16(IPG_FRAMETOOLONGERRRORS
);
1040 sp
->stats
.rx_crc_errors
+= ipg_r16(IPG_FRAMECHECKSEQERRORS
);
1042 /* Unutilized IPG statistic registers. */
1043 ipg_r32(IPG_MCSTFRAMESRCVDOK
);
1048 /* Restore used receive buffers. */
1049 static int ipg_nic_rxrestore(struct net_device
*dev
)
1051 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1052 const unsigned int curr
= sp
->rx_current
;
1053 unsigned int dirty
= sp
->rx_dirty
;
1055 IPG_DEBUG_MSG("_nic_rxrestore\n");
1057 for (dirty
= sp
->rx_dirty
; curr
- dirty
> 0; dirty
++) {
1058 unsigned int entry
= dirty
% IPG_RFDLIST_LENGTH
;
1060 /* rx_copybreak may poke hole here and there. */
1061 if (sp
->rx_buff
[entry
])
1064 /* Generate a new receive buffer to replace the
1065 * current buffer (which will be released by the
1068 if (ipg_get_rxbuff(dev
, entry
) < 0) {
1069 IPG_DEBUG_MSG("Cannot allocate new Rx buffer.\n");
1074 /* Reset the RFS field. */
1075 sp
->rxd
[entry
].rfs
= 0x0000000000000000;
1077 sp
->rx_dirty
= dirty
;
1084 /* use jumboindex and jumbosize to control jumbo frame status
1085 * initial status is jumboindex=-1 and jumbosize=0
1086 * 1. jumboindex = -1 and jumbosize=0 : previous jumbo frame has been done.
1087 * 2. jumboindex != -1 and jumbosize != 0 : jumbo frame is not over size and receiving
1088 * 3. jumboindex = -1 and jumbosize != 0 : jumbo frame is over size, already dump
1089 * previous receiving and need to continue dumping the current one
1097 FRAME_NO_START_NO_END
= 0,
1098 FRAME_WITH_START
= 1,
1099 FRAME_WITH_END
= 10,
1100 FRAME_WITH_START_WITH_END
= 11
1103 inline void ipg_nic_rx_free_skb(struct net_device
*dev
)
1105 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1106 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1108 if (sp
->rx_buff
[entry
]) {
1109 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1111 pci_unmap_single(sp
->pdev
,
1112 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1113 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1114 dev_kfree_skb_irq(sp
->rx_buff
[entry
]);
1115 sp
->rx_buff
[entry
] = NULL
;
1119 inline int ipg_nic_rx_check_frame_type(struct net_device
*dev
)
1121 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1122 struct ipg_rx
*rxfd
= sp
->rxd
+ (sp
->rx_current
% IPG_RFDLIST_LENGTH
);
1123 int type
= FRAME_NO_START_NO_END
;
1125 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
)
1126 type
+= FRAME_WITH_START
;
1127 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
)
1128 type
+= FRAME_WITH_END
;
1132 inline int ipg_nic_rx_check_error(struct net_device
*dev
)
1134 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1135 unsigned int entry
= sp
->rx_current
% IPG_RFDLIST_LENGTH
;
1136 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1138 if (IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1139 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1140 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1141 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
))) {
1142 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1143 (unsigned long) rxfd
->rfs
);
1145 /* Increment general receive error statistic. */
1146 sp
->stats
.rx_errors
++;
1148 /* Increment detailed receive error statistics. */
1149 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1150 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1152 sp
->stats
.rx_fifo_errors
++;
1155 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1156 IPG_DEBUG_MSG("RX runt occured.\n");
1157 sp
->stats
.rx_length_errors
++;
1160 /* Do nothing for IPG_RFS_RXOVERSIZEDFRAME,
1161 * error count handled by a IPG statistic register.
1164 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1165 IPG_DEBUG_MSG("RX alignment error occured.\n");
1166 sp
->stats
.rx_frame_errors
++;
1169 /* Do nothing for IPG_RFS_RXFCSERROR, error count
1170 * handled by a IPG statistic register.
1173 /* Free the memory associated with the RX
1174 * buffer since it is erroneous and we will
1175 * not pass it to higher layer processes.
1177 if (sp
->rx_buff
[entry
]) {
1178 pci_unmap_single(sp
->pdev
,
1179 le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1180 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1182 dev_kfree_skb_irq(sp
->rx_buff
[entry
]);
1183 sp
->rx_buff
[entry
] = NULL
;
1185 return ERROR_PACKET
;
1187 return NORMAL_PACKET
;
1190 static void ipg_nic_rx_with_start_and_end(struct net_device
*dev
,
1191 struct ipg_nic_private
*sp
,
1192 struct ipg_rx
*rxfd
, unsigned entry
)
1194 struct ipg_jumbo
*jumbo
= &sp
->jumbo
;
1195 struct sk_buff
*skb
;
1198 if (jumbo
->found_start
) {
1199 dev_kfree_skb_irq(jumbo
->skb
);
1200 jumbo
->found_start
= 0;
1201 jumbo
->current_size
= 0;
1205 /* 1: found error, 0 no error */
1206 if (ipg_nic_rx_check_error(dev
) != NORMAL_PACKET
)
1209 skb
= sp
->rx_buff
[entry
];
1213 /* accept this frame and send to upper layer */
1214 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1215 if (framelen
> IPG_RXFRAG_SIZE
)
1216 framelen
= IPG_RXFRAG_SIZE
;
1218 skb_put(skb
, framelen
);
1219 skb
->protocol
= eth_type_trans(skb
, dev
);
1220 skb
->ip_summed
= CHECKSUM_NONE
;
1222 dev
->last_rx
= jiffies
;
1223 sp
->rx_buff
[entry
] = NULL
;
1226 static void ipg_nic_rx_with_start(struct net_device
*dev
,
1227 struct ipg_nic_private
*sp
,
1228 struct ipg_rx
*rxfd
, unsigned entry
)
1230 struct ipg_jumbo
*jumbo
= &sp
->jumbo
;
1231 struct pci_dev
*pdev
= sp
->pdev
;
1232 struct sk_buff
*skb
;
1234 /* 1: found error, 0 no error */
1235 if (ipg_nic_rx_check_error(dev
) != NORMAL_PACKET
)
1238 /* accept this frame and send to upper layer */
1239 skb
= sp
->rx_buff
[entry
];
1243 if (jumbo
->found_start
)
1244 dev_kfree_skb_irq(jumbo
->skb
);
1246 pci_unmap_single(pdev
, le64_to_cpu(rxfd
->frag_info
& ~IPG_RFI_FRAGLEN
),
1247 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1249 skb_put(skb
, IPG_RXFRAG_SIZE
);
1251 jumbo
->found_start
= 1;
1252 jumbo
->current_size
= IPG_RXFRAG_SIZE
;
1255 sp
->rx_buff
[entry
] = NULL
;
1256 dev
->last_rx
= jiffies
;
1259 static void ipg_nic_rx_with_end(struct net_device
*dev
,
1260 struct ipg_nic_private
*sp
,
1261 struct ipg_rx
*rxfd
, unsigned entry
)
1263 struct ipg_jumbo
*jumbo
= &sp
->jumbo
;
1265 /* 1: found error, 0 no error */
1266 if (ipg_nic_rx_check_error(dev
) == NORMAL_PACKET
) {
1267 struct sk_buff
*skb
= sp
->rx_buff
[entry
];
1272 if (jumbo
->found_start
) {
1273 int framelen
, endframelen
;
1275 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1277 endframeLen
= framelen
- jumbo
->current_size
;
1279 if (framelen > IPG_RXFRAG_SIZE)
1280 framelen=IPG_RXFRAG_SIZE;
1282 if (framelen
> IPG_RXSUPPORT_SIZE
)
1283 dev_kfree_skb_irq(jumbo
->skb
);
1285 memcpy(skb_put(jumbo
->skb
, endframeLen
),
1286 skb
->data
, endframeLen
);
1288 jumbo
->skb
->protocol
=
1289 eth_type_trans(jumbo
->skb
, dev
);
1291 jumbo
->skb
->ip_summed
= CHECKSUM_NONE
;
1292 netif_rx(jumbo
->skb
);
1296 dev
->last_rx
= jiffies
;
1297 jumbo
->found_start
= 0;
1298 jumbo
->current_size
= 0;
1301 ipg_nic_rx_free_skb(dev
);
1303 dev_kfree_skb_irq(jumbo
->skb
);
1304 jumbo
->found_start
= 0;
1305 jumbo
->current_size
= 0;
1310 static void ipg_nic_rx_no_start_no_end(struct net_device
*dev
,
1311 struct ipg_nic_private
*sp
,
1312 struct ipg_rx
*rxfd
, unsigned entry
)
1314 struct ipg_jumbo
*jumbo
= &sp
->jumbo
;
1316 /* 1: found error, 0 no error */
1317 if (ipg_nic_rx_check_error(dev
) == NORMAL_PACKET
) {
1318 struct sk_buff
*skb
= sp
->rx_buff
[entry
];
1321 if (jumbo
->found_start
) {
1322 jumbo
->current_size
+= IPG_RXFRAG_SIZE
;
1323 if (jumbo
->current_size
<= IPG_RXSUPPORT_SIZE
) {
1324 memcpy(skb_put(jumbo
->skb
,
1326 skb
->data
, IPG_RXFRAG_SIZE
);
1329 dev
->last_rx
= jiffies
;
1330 ipg_nic_rx_free_skb(dev
);
1333 dev_kfree_skb_irq(jumbo
->skb
);
1334 jumbo
->found_start
= 0;
1335 jumbo
->current_size
= 0;
1340 static int ipg_nic_rx(struct net_device
*dev
)
1342 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1343 unsigned int curr
= sp
->rx_current
;
1344 void __iomem
*ioaddr
= sp
->ioaddr
;
1347 IPG_DEBUG_MSG("_nic_rx\n");
1349 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1350 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1351 struct ipg_rx
*rxfd
= sp
->rxd
+ entry
;
1353 if (!(rxfd
->rfs
& le64_to_cpu(IPG_RFS_RFDDONE
)))
1356 switch (ipg_nic_rx_check_frame_type(dev
)) {
1357 case FRAME_WITH_START_WITH_END
:
1358 ipg_nic_rx_with_start_and_end(dev
, tp
, rxfd
, entry
);
1360 case FRAME_WITH_START
:
1361 ipg_nic_rx_with_start(dev
, tp
, rxfd
, entry
);
1363 case FRAME_WITH_END
:
1364 ipg_nic_rx_with_end(dev
, tp
, rxfd
, entry
);
1366 case FRAME_NO_START_NO_END
:
1367 ipg_nic_rx_no_start_no_end(dev
, tp
, rxfd
, entry
);
1372 sp
->rx_current
= curr
;
1374 if (i
== IPG_MAXRFDPROCESS_COUNT
) {
1375 /* There are more RFDs to process, however the
1376 * allocated amount of RFD processing time has
1377 * expired. Assert Interrupt Requested to make
1378 * sure we come back to process the remaining RFDs.
1380 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1383 ipg_nic_rxrestore(dev
);
1389 static int ipg_nic_rx(struct net_device
*dev
)
1391 /* Transfer received Ethernet frames to higher network layers. */
1392 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1393 unsigned int curr
= sp
->rx_current
;
1394 void __iomem
*ioaddr
= sp
->ioaddr
;
1395 struct ipg_rx
*rxfd
;
1398 IPG_DEBUG_MSG("_nic_rx\n");
1400 #define __RFS_MASK \
1401 cpu_to_le64(IPG_RFS_RFDDONE | IPG_RFS_FRAMESTART | IPG_RFS_FRAMEEND)
1403 for (i
= 0; i
< IPG_MAXRFDPROCESS_COUNT
; i
++, curr
++) {
1404 unsigned int entry
= curr
% IPG_RFDLIST_LENGTH
;
1405 struct sk_buff
*skb
= sp
->rx_buff
[entry
];
1406 unsigned int framelen
;
1408 rxfd
= sp
->rxd
+ entry
;
1410 if (((rxfd
->rfs
& __RFS_MASK
) != __RFS_MASK
) || !skb
)
1413 /* Get received frame length. */
1414 framelen
= le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFRAMELEN
;
1416 /* Check for jumbo frame arrival with too small
1419 if (framelen
> IPG_RXFRAG_SIZE
) {
1421 ("RFS FrameLen > allocated fragment size.\n");
1423 framelen
= IPG_RXFRAG_SIZE
;
1426 if ((IPG_DROP_ON_RX_ETH_ERRORS
&& (le64_to_cpu(rxfd
->rfs
) &
1427 (IPG_RFS_RXFIFOOVERRUN
| IPG_RFS_RXRUNTFRAME
|
1428 IPG_RFS_RXALIGNMENTERROR
| IPG_RFS_RXFCSERROR
|
1429 IPG_RFS_RXOVERSIZEDFRAME
| IPG_RFS_RXLENGTHERROR
)))) {
1431 IPG_DEBUG_MSG("Rx error, RFS = %16.16lx\n",
1432 (unsigned long int) rxfd
->rfs
);
1434 /* Increment general receive error statistic. */
1435 sp
->stats
.rx_errors
++;
1437 /* Increment detailed receive error statistics. */
1438 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFIFOOVERRUN
) {
1439 IPG_DEBUG_MSG("RX FIFO overrun occured.\n");
1440 sp
->stats
.rx_fifo_errors
++;
1443 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXRUNTFRAME
) {
1444 IPG_DEBUG_MSG("RX runt occured.\n");
1445 sp
->stats
.rx_length_errors
++;
1448 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXOVERSIZEDFRAME
) ;
1449 /* Do nothing, error count handled by a IPG
1450 * statistic register.
1453 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXALIGNMENTERROR
) {
1454 IPG_DEBUG_MSG("RX alignment error occured.\n");
1455 sp
->stats
.rx_frame_errors
++;
1458 if (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RXFCSERROR
) ;
1459 /* Do nothing, error count handled by a IPG
1460 * statistic register.
1463 /* Free the memory associated with the RX
1464 * buffer since it is erroneous and we will
1465 * not pass it to higher layer processes.
1468 __le64 info
= rxfd
->frag_info
;
1470 pci_unmap_single(sp
->pdev
,
1471 le64_to_cpu(info
) & ~IPG_RFI_FRAGLEN
,
1472 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1474 dev_kfree_skb_irq(skb
);
1478 /* Adjust the new buffer length to accomodate the size
1479 * of the received frame.
1481 skb_put(skb
, framelen
);
1483 /* Set the buffer's protocol field to Ethernet. */
1484 skb
->protocol
= eth_type_trans(skb
, dev
);
1486 /* The IPG encountered an error with (or
1487 * there were no) IP/TCP/UDP checksums.
1488 * This may or may not indicate an invalid
1489 * IP/TCP/UDP frame was received. Let the
1490 * upper layer decide.
1492 skb
->ip_summed
= CHECKSUM_NONE
;
1494 /* Hand off frame for higher layer processing.
1495 * The function netif_rx() releases the sk_buff
1496 * when processing completes.
1500 /* Record frame receive time (jiffies = Linux
1501 * kernel current time stamp).
1503 dev
->last_rx
= jiffies
;
1506 /* Assure RX buffer is not reused by IPG. */
1507 sp
->rx_buff
[entry
] = NULL
;
1511 * If there are more RFDs to proces and the allocated amount of RFD
1512 * processing time has expired, assert Interrupt Requested to make
1513 * sure we come back to process the remaining RFDs.
1515 if (i
== IPG_MAXRFDPROCESS_COUNT
)
1516 ipg_w32(ipg_r32(ASIC_CTRL
) | IPG_AC_INT_REQUEST
, ASIC_CTRL
);
1519 /* Check if the RFD list contained no receive frame data. */
1521 sp
->EmptyRFDListCount
++;
1523 while ((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_RFDDONE
) &&
1524 !((le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMESTART
) &&
1525 (le64_to_cpu(rxfd
->rfs
) & IPG_RFS_FRAMEEND
))) {
1526 unsigned int entry
= curr
++ % IPG_RFDLIST_LENGTH
;
1528 rxfd
= sp
->rxd
+ entry
;
1530 IPG_DEBUG_MSG("Frame requires multiple RFDs.\n");
1532 /* An unexpected event, additional code needed to handle
1533 * properly. So for the time being, just disregard the
1537 /* Free the memory associated with the RX
1538 * buffer since it is erroneous and we will
1539 * not pass it to higher layer processes.
1541 if (sp
->rx_buff
[entry
]) {
1542 pci_unmap_single(sp
->pdev
,
1543 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1544 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1545 dev_kfree_skb_irq(sp
->rx_buff
[entry
]);
1548 /* Assure RX buffer is not reused by IPG. */
1549 sp
->rx_buff
[entry
] = NULL
;
1552 sp
->rx_current
= curr
;
1554 /* Check to see if there are a minimum number of used
1555 * RFDs before restoring any (should improve performance.)
1557 if ((curr
- sp
->rx_dirty
) >= IPG_MINUSEDRFDSTOFREE
)
1558 ipg_nic_rxrestore(dev
);
1564 static void ipg_reset_after_host_error(struct work_struct
*work
)
1566 struct ipg_nic_private
*sp
=
1567 container_of(work
, struct ipg_nic_private
, task
.work
);
1568 struct net_device
*dev
= sp
->dev
;
1570 IPG_DDEBUG_MSG("DMACtrl = %8.8x\n", ioread32(sp
->ioaddr
+ IPG_DMACTRL
));
1573 * Acknowledge HostError interrupt by resetting
1576 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1581 if (ipg_io_config(dev
) < 0) {
1582 printk(KERN_INFO
"%s: Cannot recover from PCI error.\n",
1584 schedule_delayed_work(&sp
->task
, HZ
);
1588 static irqreturn_t
ipg_interrupt_handler(int irq
, void *dev_inst
)
1590 struct net_device
*dev
= dev_inst
;
1591 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1592 void __iomem
*ioaddr
= sp
->ioaddr
;
1593 unsigned int handled
= 0;
1596 IPG_DEBUG_MSG("_interrupt_handler\n");
1599 ipg_nic_rxrestore(dev
);
1601 spin_lock(&sp
->lock
);
1603 /* Get interrupt source information, and acknowledge
1604 * some (i.e. TxDMAComplete, RxDMAComplete, RxEarly,
1605 * IntRequested, MacControlFrame, LinkEvent) interrupts
1606 * if issued. Also, all IPG interrupts are disabled by
1607 * reading IntStatusAck.
1609 status
= ipg_r16(INT_STATUS_ACK
);
1611 IPG_DEBUG_MSG("IntStatusAck = %4.4x\n", status
);
1613 /* Shared IRQ of remove event. */
1614 if (!(status
& IPG_IS_RSVD_MASK
))
1619 if (unlikely(!netif_running(dev
)))
1622 /* If RFDListEnd interrupt, restore all used RFDs. */
1623 if (status
& IPG_IS_RFD_LIST_END
) {
1624 IPG_DEBUG_MSG("RFDListEnd Interrupt.\n");
1626 /* The RFD list end indicates an RFD was encountered
1627 * with a 0 NextPtr, or with an RFDDone bit set to 1
1628 * (indicating the RFD is not read for use by the
1629 * IPG.) Try to restore all RFDs.
1631 ipg_nic_rxrestore(dev
);
1634 /* Increment the RFDlistendCount counter. */
1635 sp
->RFDlistendCount
++;
1639 /* If RFDListEnd, RxDMAPriority, RxDMAComplete, or
1640 * IntRequested interrupt, process received frames. */
1641 if ((status
& IPG_IS_RX_DMA_PRIORITY
) ||
1642 (status
& IPG_IS_RFD_LIST_END
) ||
1643 (status
& IPG_IS_RX_DMA_COMPLETE
) ||
1644 (status
& IPG_IS_INT_REQUESTED
)) {
1646 /* Increment the RFD list checked counter if interrupted
1647 * only to check the RFD list. */
1648 if (status
& (~(IPG_IS_RX_DMA_PRIORITY
| IPG_IS_RFD_LIST_END
|
1649 IPG_IS_RX_DMA_COMPLETE
| IPG_IS_INT_REQUESTED
) &
1650 (IPG_IS_HOST_ERROR
| IPG_IS_TX_DMA_COMPLETE
|
1651 IPG_IS_LINK_EVENT
| IPG_IS_TX_COMPLETE
|
1652 IPG_IS_UPDATE_STATS
)))
1653 sp
->RFDListCheckedCount
++;
1659 /* If TxDMAComplete interrupt, free used TFDs. */
1660 if (status
& IPG_IS_TX_DMA_COMPLETE
)
1661 ipg_nic_txfree(dev
);
1663 /* TxComplete interrupts indicate one of numerous actions.
1664 * Determine what action to take based on TXSTATUS register.
1666 if (status
& IPG_IS_TX_COMPLETE
)
1667 ipg_nic_txcleanup(dev
);
1669 /* If UpdateStats interrupt, update Linux Ethernet statistics */
1670 if (status
& IPG_IS_UPDATE_STATS
)
1671 ipg_nic_get_stats(dev
);
1673 /* If HostError interrupt, reset IPG. */
1674 if (status
& IPG_IS_HOST_ERROR
) {
1675 IPG_DDEBUG_MSG("HostError Interrupt\n");
1677 schedule_delayed_work(&sp
->task
, 0);
1680 /* If LinkEvent interrupt, resolve autonegotiation. */
1681 if (status
& IPG_IS_LINK_EVENT
) {
1682 if (ipg_config_autoneg(dev
) < 0)
1683 printk(KERN_INFO
"%s: Auto-negotiation error.\n",
1687 /* If MACCtrlFrame interrupt, do nothing. */
1688 if (status
& IPG_IS_MAC_CTRL_FRAME
)
1689 IPG_DEBUG_MSG("MACCtrlFrame interrupt.\n");
1691 /* If RxComplete interrupt, do nothing. */
1692 if (status
& IPG_IS_RX_COMPLETE
)
1693 IPG_DEBUG_MSG("RxComplete interrupt.\n");
1695 /* If RxEarly interrupt, do nothing. */
1696 if (status
& IPG_IS_RX_EARLY
)
1697 IPG_DEBUG_MSG("RxEarly interrupt.\n");
1700 /* Re-enable IPG interrupts. */
1701 ipg_w16(IPG_IE_TX_DMA_COMPLETE
| IPG_IE_RX_DMA_COMPLETE
|
1702 IPG_IE_HOST_ERROR
| IPG_IE_INT_REQUESTED
| IPG_IE_TX_COMPLETE
|
1703 IPG_IE_LINK_EVENT
| IPG_IE_UPDATE_STATS
, INT_ENABLE
);
1705 spin_unlock(&sp
->lock
);
1707 return IRQ_RETVAL(handled
);
1710 static void ipg_rx_clear(struct ipg_nic_private
*sp
)
1714 for (i
= 0; i
< IPG_RFDLIST_LENGTH
; i
++) {
1715 if (sp
->rx_buff
[i
]) {
1716 struct ipg_rx
*rxfd
= sp
->rxd
+ i
;
1718 dev_kfree_skb_irq(sp
->rx_buff
[i
]);
1719 sp
->rx_buff
[i
] = NULL
;
1720 pci_unmap_single(sp
->pdev
,
1721 le64_to_cpu(rxfd
->frag_info
) & ~IPG_RFI_FRAGLEN
,
1722 sp
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1727 static void ipg_tx_clear(struct ipg_nic_private
*sp
)
1731 for (i
= 0; i
< IPG_TFDLIST_LENGTH
; i
++) {
1732 if (sp
->tx_buff
[i
]) {
1733 struct ipg_tx
*txfd
= sp
->txd
+ i
;
1735 pci_unmap_single(sp
->pdev
,
1736 le64_to_cpu(txfd
->frag_info
) & ~IPG_TFI_FRAGLEN
,
1737 sp
->tx_buff
[i
]->len
, PCI_DMA_TODEVICE
);
1739 dev_kfree_skb_irq(sp
->tx_buff
[i
]);
1741 sp
->tx_buff
[i
] = NULL
;
1746 static int ipg_nic_open(struct net_device
*dev
)
1748 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1749 void __iomem
*ioaddr
= sp
->ioaddr
;
1750 struct pci_dev
*pdev
= sp
->pdev
;
1753 IPG_DEBUG_MSG("_nic_open\n");
1755 sp
->rx_buf_sz
= IPG_RXSUPPORT_SIZE
;
1757 /* Check for interrupt line conflicts, and request interrupt
1760 * IMPORTANT: Disable IPG interrupts prior to registering
1763 ipg_w16(0x0000, INT_ENABLE
);
1765 /* Register the interrupt line to be used by the IPG within
1768 rc
= request_irq(pdev
->irq
, &ipg_interrupt_handler
, IRQF_SHARED
,
1771 printk(KERN_INFO
"%s: Error when requesting interrupt.\n",
1776 dev
->irq
= pdev
->irq
;
1780 sp
->rxd
= dma_alloc_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
,
1781 &sp
->rxd_map
, GFP_KERNEL
);
1783 goto err_free_irq_0
;
1785 sp
->txd
= dma_alloc_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
,
1786 &sp
->txd_map
, GFP_KERNEL
);
1790 rc
= init_rfdlist(dev
);
1792 printk(KERN_INFO
"%s: Error during configuration.\n",
1799 rc
= ipg_io_config(dev
);
1801 printk(KERN_INFO
"%s: Error during configuration.\n",
1803 goto err_release_tfdlist_3
;
1806 /* Resolve autonegotiation. */
1807 if (ipg_config_autoneg(dev
) < 0)
1808 printk(KERN_INFO
"%s: Auto-negotiation error.\n", dev
->name
);
1811 /* initialize JUMBO Frame control variable */
1812 sp
->jumbo
.found_start
= 0;
1813 sp
->jumbo
.current_size
= 0;
1815 dev
->mtu
= IPG_TXFRAG_SIZE
;
1818 /* Enable transmit and receive operation of the IPG. */
1819 ipg_w32((ipg_r32(MAC_CTRL
) | IPG_MC_RX_ENABLE
| IPG_MC_TX_ENABLE
) &
1820 IPG_MC_RSVD_MASK
, MAC_CTRL
);
1822 netif_start_queue(dev
);
1826 err_release_tfdlist_3
:
1830 dma_free_coherent(&pdev
->dev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1832 dma_free_coherent(&pdev
->dev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1834 free_irq(pdev
->irq
, dev
);
1838 static int ipg_nic_stop(struct net_device
*dev
)
1840 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1841 void __iomem
*ioaddr
= sp
->ioaddr
;
1842 struct pci_dev
*pdev
= sp
->pdev
;
1844 IPG_DEBUG_MSG("_nic_stop\n");
1846 netif_stop_queue(dev
);
1848 IPG_DDEBUG_MSG("RFDlistendCount = %i\n", sp
->RFDlistendCount
);
1849 IPG_DDEBUG_MSG("RFDListCheckedCount = %i\n", sp
->rxdCheckedCount
);
1850 IPG_DDEBUG_MSG("EmptyRFDListCount = %i\n", sp
->EmptyRFDListCount
);
1851 IPG_DUMPTFDLIST(dev
);
1854 (void) ipg_r16(INT_STATUS_ACK
);
1856 ipg_reset(dev
, IPG_AC_GLOBAL_RESET
| IPG_AC_HOST
| IPG_AC_DMA
);
1858 synchronize_irq(pdev
->irq
);
1859 } while (ipg_r16(INT_ENABLE
) & IPG_IE_RSVD_MASK
);
1865 pci_free_consistent(pdev
, IPG_RX_RING_BYTES
, sp
->rxd
, sp
->rxd_map
);
1866 pci_free_consistent(pdev
, IPG_TX_RING_BYTES
, sp
->txd
, sp
->txd_map
);
1868 free_irq(pdev
->irq
, dev
);
1873 static int ipg_nic_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1875 struct ipg_nic_private
*sp
= netdev_priv(dev
);
1876 void __iomem
*ioaddr
= sp
->ioaddr
;
1877 unsigned int entry
= sp
->tx_current
% IPG_TFDLIST_LENGTH
;
1878 unsigned long flags
;
1879 struct ipg_tx
*txfd
;
1881 IPG_DDEBUG_MSG("_nic_hard_start_xmit\n");
1883 /* If in 10Mbps mode, stop the transmit queue so
1884 * no more transmit frames are accepted.
1886 if (sp
->tenmbpsmode
)
1887 netif_stop_queue(dev
);
1889 if (sp
->reset_current_tfd
) {
1890 sp
->reset_current_tfd
= 0;
1894 txfd
= sp
->txd
+ entry
;
1896 sp
->tx_buff
[entry
] = skb
;
1898 /* Clear all TFC fields, except TFDDONE. */
1899 txfd
->tfc
= cpu_to_le64(IPG_TFC_TFDDONE
);
1901 /* Specify the TFC field within the TFD. */
1902 txfd
->tfc
|= cpu_to_le64(IPG_TFC_WORDALIGNDISABLED
|
1903 (IPG_TFC_FRAMEID
& cpu_to_le64(sp
->tx_current
)) |
1904 (IPG_TFC_FRAGCOUNT
& (1 << 24)));
1906 /* Request TxComplete interrupts at an interval defined
1907 * by the constant IPG_FRAMESBETWEENTXCOMPLETES.
1908 * Request TxComplete interrupt for every frame
1909 * if in 10Mbps mode to accomodate problem with 10Mbps
1912 if (sp
->tenmbpsmode
)
1913 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXINDICATE
);
1914 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TXDMAINDICATE
);
1915 /* Based on compilation option, determine if FCS is to be
1916 * appended to transmit frame by IPG.
1918 if (!(IPG_APPEND_FCS_ON_TX
))
1919 txfd
->tfc
|= cpu_to_le64(IPG_TFC_FCSAPPENDDISABLE
);
1921 /* Based on compilation option, determine if IP, TCP and/or
1922 * UDP checksums are to be added to transmit frame by IPG.
1924 if (IPG_ADD_IPCHECKSUM_ON_TX
)
1925 txfd
->tfc
|= cpu_to_le64(IPG_TFC_IPCHECKSUMENABLE
);
1927 if (IPG_ADD_TCPCHECKSUM_ON_TX
)
1928 txfd
->tfc
|= cpu_to_le64(IPG_TFC_TCPCHECKSUMENABLE
);
1930 if (IPG_ADD_UDPCHECKSUM_ON_TX
)
1931 txfd
->tfc
|= cpu_to_le64(IPG_TFC_UDPCHECKSUMENABLE
);
1933 /* Based on compilation option, determine if VLAN tag info is to be
1934 * inserted into transmit frame by IPG.
1936 if (IPG_INSERT_MANUAL_VLAN_TAG
) {
1937 txfd
->tfc
|= cpu_to_le64(IPG_TFC_VLANTAGINSERT
|
1938 ((u64
) IPG_MANUAL_VLAN_VID
<< 32) |
1939 ((u64
) IPG_MANUAL_VLAN_CFI
<< 44) |
1940 ((u64
) IPG_MANUAL_VLAN_USERPRIORITY
<< 45));
1943 /* The fragment start location within system memory is defined
1944 * by the sk_buff structure's data field. The physical address
1945 * of this location within the system's virtual memory space
1946 * is determined using the IPG_HOST2BUS_MAP function.
1948 txfd
->frag_info
= cpu_to_le64(pci_map_single(sp
->pdev
, skb
->data
,
1949 skb
->len
, PCI_DMA_TODEVICE
));
1951 /* The length of the fragment within system memory is defined by
1952 * the sk_buff structure's len field.
1954 txfd
->frag_info
|= cpu_to_le64(IPG_TFI_FRAGLEN
&
1955 ((u64
) (skb
->len
& 0xffff) << 48));
1957 /* Clear the TFDDone bit last to indicate the TFD is ready
1958 * for transfer to the IPG.
1960 txfd
->tfc
&= cpu_to_le64(~IPG_TFC_TFDDONE
);
1962 spin_lock_irqsave(&sp
->lock
, flags
);
1968 ipg_w32(IPG_DC_TX_DMA_POLL_NOW
, DMA_CTRL
);
1970 if (sp
->tx_current
== (sp
->tx_dirty
+ IPG_TFDLIST_LENGTH
))
1971 netif_stop_queue(dev
);
1973 spin_unlock_irqrestore(&sp
->lock
, flags
);
1975 return NETDEV_TX_OK
;
1978 static void ipg_set_phy_default_param(unsigned char rev
,
1979 struct net_device
*dev
, int phy_address
)
1981 unsigned short length
;
1982 unsigned char revision
;
1983 unsigned short *phy_param
;
1984 unsigned short address
, value
;
1986 phy_param
= &DefaultPhyParam
[0];
1987 length
= *phy_param
& 0x00FF;
1988 revision
= (unsigned char)((*phy_param
) >> 8);
1990 while (length
!= 0) {
1991 if (rev
== revision
) {
1992 while (length
> 1) {
1993 address
= *phy_param
;
1994 value
= *(phy_param
+ 1);
1996 mdio_write(dev
, phy_address
, address
, value
);
2001 phy_param
+= length
/ 2;
2002 length
= *phy_param
& 0x00FF;
2003 revision
= (unsigned char)((*phy_param
) >> 8);
2009 static int read_eeprom(struct net_device
*dev
, int eep_addr
)
2011 void __iomem
*ioaddr
= ipg_ioaddr(dev
);
2016 value
= IPG_EC_EEPROM_READOPCODE
| (eep_addr
& 0xff);
2017 ipg_w16(value
, EEPROM_CTRL
);
2019 for (i
= 0; i
< 1000; i
++) {
2023 data
= ipg_r16(EEPROM_CTRL
);
2024 if (!(data
& IPG_EC_EEPROM_BUSY
)) {
2025 ret
= ipg_r16(EEPROM_DATA
);
2032 static void ipg_init_mii(struct net_device
*dev
)
2034 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2035 struct mii_if_info
*mii_if
= &sp
->mii_if
;
2039 mii_if
->mdio_read
= mdio_read
;
2040 mii_if
->mdio_write
= mdio_write
;
2041 mii_if
->phy_id_mask
= 0x1f;
2042 mii_if
->reg_num_mask
= 0x1f;
2044 mii_if
->phy_id
= phyaddr
= ipg_find_phyaddr(dev
);
2046 if (phyaddr
!= 0x1f) {
2047 u16 mii_phyctrl
, mii_1000cr
;
2050 mii_1000cr
= mdio_read(dev
, phyaddr
, MII_CTRL1000
);
2051 mii_1000cr
|= ADVERTISE_1000FULL
| ADVERTISE_1000HALF
|
2052 GMII_PHY_1000BASETCONTROL_PreferMaster
;
2053 mdio_write(dev
, phyaddr
, MII_CTRL1000
, mii_1000cr
);
2055 mii_phyctrl
= mdio_read(dev
, phyaddr
, MII_BMCR
);
2057 /* Set default phyparam */
2058 pci_read_config_byte(sp
->pdev
, PCI_REVISION_ID
, &revisionid
);
2059 ipg_set_phy_default_param(revisionid
, dev
, phyaddr
);
2062 mii_phyctrl
|= BMCR_RESET
| BMCR_ANRESTART
;
2063 mdio_write(dev
, phyaddr
, MII_BMCR
, mii_phyctrl
);
2068 static int ipg_hw_init(struct net_device
*dev
)
2070 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2071 void __iomem
*ioaddr
= sp
->ioaddr
;
2075 /* Read/Write and Reset EEPROM Value */
2076 /* Read LED Mode Configuration from EEPROM */
2077 sp
->led_mode
= read_eeprom(dev
, 6);
2079 /* Reset all functions within the IPG. Do not assert
2080 * RST_OUT as not compatible with some PHYs.
2082 rc
= ipg_reset(dev
, IPG_RESET_MASK
);
2088 /* Read MAC Address from EEPROM */
2089 for (i
= 0; i
< 3; i
++)
2090 sp
->station_addr
[i
] = read_eeprom(dev
, 16 + i
);
2092 for (i
= 0; i
< 3; i
++)
2093 ipg_w16(sp
->station_addr
[i
], STATION_ADDRESS_0
+ 2*i
);
2095 /* Set station address in ethernet_device structure. */
2096 dev
->dev_addr
[0] = ipg_r16(STATION_ADDRESS_0
) & 0x00ff;
2097 dev
->dev_addr
[1] = (ipg_r16(STATION_ADDRESS_0
) & 0xff00) >> 8;
2098 dev
->dev_addr
[2] = ipg_r16(STATION_ADDRESS_1
) & 0x00ff;
2099 dev
->dev_addr
[3] = (ipg_r16(STATION_ADDRESS_1
) & 0xff00) >> 8;
2100 dev
->dev_addr
[4] = ipg_r16(STATION_ADDRESS_2
) & 0x00ff;
2101 dev
->dev_addr
[5] = (ipg_r16(STATION_ADDRESS_2
) & 0xff00) >> 8;
2106 static int ipg_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2108 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2111 mutex_lock(&sp
->mii_mutex
);
2112 rc
= generic_mii_ioctl(&sp
->mii_if
, if_mii(ifr
), cmd
, NULL
);
2113 mutex_unlock(&sp
->mii_mutex
);
2118 static int ipg_nic_change_mtu(struct net_device
*dev
, int new_mtu
)
2120 /* Function to accomodate changes to Maximum Transfer Unit
2121 * (or MTU) of IPG NIC. Cannot use default function since
2122 * the default will not allow for MTU > 1500 bytes.
2125 IPG_DEBUG_MSG("_nic_change_mtu\n");
2127 /* Check that the new MTU value is between 68 (14 byte header, 46
2128 * byte payload, 4 byte FCS) and IPG_MAX_RXFRAME_SIZE, which
2129 * corresponds to the MAXFRAMESIZE register in the IPG.
2131 if ((new_mtu
< 68) || (new_mtu
> IPG_MAX_RXFRAME_SIZE
))
2139 static int ipg_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2141 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2144 mutex_lock(&sp
->mii_mutex
);
2145 rc
= mii_ethtool_gset(&sp
->mii_if
, cmd
);
2146 mutex_unlock(&sp
->mii_mutex
);
2151 static int ipg_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2153 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2156 mutex_lock(&sp
->mii_mutex
);
2157 rc
= mii_ethtool_sset(&sp
->mii_if
, cmd
);
2158 mutex_unlock(&sp
->mii_mutex
);
2163 static int ipg_nway_reset(struct net_device
*dev
)
2165 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2168 mutex_lock(&sp
->mii_mutex
);
2169 rc
= mii_nway_restart(&sp
->mii_if
);
2170 mutex_unlock(&sp
->mii_mutex
);
2175 static struct ethtool_ops ipg_ethtool_ops
= {
2176 .get_settings
= ipg_get_settings
,
2177 .set_settings
= ipg_set_settings
,
2178 .nway_reset
= ipg_nway_reset
,
2181 static void __devexit
ipg_remove(struct pci_dev
*pdev
)
2183 struct net_device
*dev
= pci_get_drvdata(pdev
);
2184 struct ipg_nic_private
*sp
= netdev_priv(dev
);
2186 IPG_DEBUG_MSG("_remove\n");
2188 /* Un-register Ethernet device. */
2189 unregister_netdev(dev
);
2191 pci_iounmap(pdev
, sp
->ioaddr
);
2193 pci_release_regions(pdev
);
2196 pci_disable_device(pdev
);
2197 pci_set_drvdata(pdev
, NULL
);
2200 static int __devinit
ipg_probe(struct pci_dev
*pdev
,
2201 const struct pci_device_id
*id
)
2203 unsigned int i
= id
->driver_data
;
2204 struct ipg_nic_private
*sp
;
2205 struct net_device
*dev
;
2206 void __iomem
*ioaddr
;
2209 rc
= pci_enable_device(pdev
);
2213 printk(KERN_INFO
"%s: %s\n", pci_name(pdev
), ipg_brand_name
[i
]);
2215 pci_set_master(pdev
);
2217 rc
= pci_set_dma_mask(pdev
, DMA_40BIT_MASK
);
2219 rc
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
2221 printk(KERN_ERR
"%s: DMA config failed.\n",
2228 * Initialize net device.
2230 dev
= alloc_etherdev(sizeof(struct ipg_nic_private
));
2232 printk(KERN_ERR
"%s: alloc_etherdev failed\n", pci_name(pdev
));
2237 sp
= netdev_priv(dev
);
2238 spin_lock_init(&sp
->lock
);
2239 mutex_init(&sp
->mii_mutex
);
2241 /* Declare IPG NIC functions for Ethernet device methods.
2243 dev
->open
= &ipg_nic_open
;
2244 dev
->stop
= &ipg_nic_stop
;
2245 dev
->hard_start_xmit
= &ipg_nic_hard_start_xmit
;
2246 dev
->get_stats
= &ipg_nic_get_stats
;
2247 dev
->set_multicast_list
= &ipg_nic_set_multicast_list
;
2248 dev
->do_ioctl
= ipg_ioctl
;
2249 dev
->tx_timeout
= ipg_tx_timeout
;
2250 dev
->change_mtu
= &ipg_nic_change_mtu
;
2252 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2253 SET_ETHTOOL_OPS(dev
, &ipg_ethtool_ops
);
2255 rc
= pci_request_regions(pdev
, DRV_NAME
);
2257 goto err_free_dev_1
;
2259 ioaddr
= pci_iomap(pdev
, 1, pci_resource_len(pdev
, 1));
2261 printk(KERN_ERR
"%s cannot map MMIO\n", pci_name(pdev
));
2263 goto err_release_regions_2
;
2266 /* Save the pointer to the PCI device information. */
2267 sp
->ioaddr
= ioaddr
;
2271 INIT_DELAYED_WORK(&sp
->task
, ipg_reset_after_host_error
);
2273 pci_set_drvdata(pdev
, dev
);
2275 rc
= ipg_hw_init(dev
);
2279 rc
= register_netdev(dev
);
2283 printk(KERN_INFO
"Ethernet device registered as: %s\n", dev
->name
);
2288 pci_iounmap(pdev
, ioaddr
);
2289 err_release_regions_2
:
2290 pci_release_regions(pdev
);
2294 pci_disable_device(pdev
);
2298 static struct pci_driver ipg_pci_driver
= {
2299 .name
= IPG_DRIVER_NAME
,
2300 .id_table
= ipg_pci_tbl
,
2302 .remove
= __devexit_p(ipg_remove
),
2305 static int __init
ipg_init_module(void)
2307 return pci_register_driver(&ipg_pci_driver
);
2310 static void __exit
ipg_exit_module(void)
2312 pci_unregister_driver(&ipg_pci_driver
);
2315 module_init(ipg_init_module
);
2316 module_exit(ipg_exit_module
);