2 * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
3 * Copyright(c) 2006 - 2007 Chris Snook <csnook@redhat.com>
4 * Copyright(c) 2006 - 2008 Jay Cliburn <jcliburn@gmail.com>
6 * Derived from Intel e1000 driver
7 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
26 * Contact Information:
27 * Xiong Huang <xiong.huang@atheros.com>
28 * Jie Yang <jie.yang@atheros.com>
29 * Chris Snook <csnook@redhat.com>
30 * Jay Cliburn <jcliburn@gmail.com>
32 * This version is adapted from the Attansic reference driver.
35 * Add more ethtool functions.
36 * Fix abstruse irq enable/disable condition described here:
37 * http://marc.theaimsgroup.com/?l=linux-netdev&m=116398508500553&w=2
43 * interrupt coalescing
47 #include <asm/atomic.h>
48 #include <asm/byteorder.h>
50 #include <linux/compiler.h>
51 #include <linux/crc32.h>
52 #include <linux/delay.h>
53 #include <linux/dma-mapping.h>
54 #include <linux/etherdevice.h>
55 #include <linux/hardirq.h>
56 #include <linux/if_ether.h>
57 #include <linux/if_vlan.h>
59 #include <linux/interrupt.h>
61 #include <linux/irqflags.h>
62 #include <linux/irqreturn.h>
63 #include <linux/jiffies.h>
64 #include <linux/mii.h>
65 #include <linux/module.h>
66 #include <linux/moduleparam.h>
67 #include <linux/net.h>
68 #include <linux/netdevice.h>
69 #include <linux/pci.h>
70 #include <linux/pci_ids.h>
72 #include <linux/skbuff.h>
73 #include <linux/slab.h>
74 #include <linux/spinlock.h>
75 #include <linux/string.h>
76 #include <linux/tcp.h>
77 #include <linux/timer.h>
78 #include <linux/types.h>
79 #include <linux/workqueue.h>
81 #include <net/checksum.h>
85 #define ATLX_DRIVER_VERSION "2.1.3"
86 MODULE_AUTHOR("Xiong Huang <xiong.huang@atheros.com>, \
87 Chris Snook <csnook@redhat.com>, Jay Cliburn <jcliburn@gmail.com>");
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(ATLX_DRIVER_VERSION
);
91 /* Temporary hack for merging atl1 and atl2 */
95 * This is the only thing that needs to be changed to adjust the
96 * maximum number of ports that the driver can manage.
98 #define ATL1_MAX_NIC 4
100 #define OPTION_UNSET -1
101 #define OPTION_DISABLED 0
102 #define OPTION_ENABLED 1
104 #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
107 * Interrupt Moderate Timer in units of 2 us
109 * Valid Range: 10-65535
111 * Default Value: 100 (200us)
113 static int __devinitdata int_mod_timer
[ATL1_MAX_NIC
+1] = ATL1_PARAM_INIT
;
114 static unsigned int num_int_mod_timer
;
115 module_param_array_named(int_mod_timer
, int_mod_timer
, int,
116 &num_int_mod_timer
, 0);
117 MODULE_PARM_DESC(int_mod_timer
, "Interrupt moderator timer");
119 #define DEFAULT_INT_MOD_CNT 100 /* 200us */
120 #define MAX_INT_MOD_CNT 65000
121 #define MIN_INT_MOD_CNT 50
124 enum { enable_option
, range_option
, list_option
} type
;
129 struct { /* range_option info */
133 struct { /* list_option info */
135 struct atl1_opt_list
{
143 static int __devinit
atl1_validate_option(int *value
, struct atl1_option
*opt
,
144 struct pci_dev
*pdev
)
146 if (*value
== OPTION_UNSET
) {
155 dev_info(&pdev
->dev
, "%s enabled\n", opt
->name
);
157 case OPTION_DISABLED
:
158 dev_info(&pdev
->dev
, "%s disabled\n", opt
->name
);
163 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
164 dev_info(&pdev
->dev
, "%s set to %i\n", opt
->name
,
171 struct atl1_opt_list
*ent
;
173 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
174 ent
= &opt
->arg
.l
.p
[i
];
175 if (*value
== ent
->i
) {
176 if (ent
->str
[0] != '\0')
177 dev_info(&pdev
->dev
, "%s\n",
189 dev_info(&pdev
->dev
, "invalid %s specified (%i) %s\n",
190 opt
->name
, *value
, opt
->err
);
196 * atl1_check_options - Range Checking for Command Line Parameters
197 * @adapter: board private structure
199 * This routine checks all command line parameters for valid user
200 * input. If an invalid value is given, or if no user specified
201 * value exists, a default value is used. The final value is stored
202 * in a variable in the adapter structure.
204 static void __devinit
atl1_check_options(struct atl1_adapter
*adapter
)
206 struct pci_dev
*pdev
= adapter
->pdev
;
207 int bd
= adapter
->bd_number
;
208 if (bd
>= ATL1_MAX_NIC
) {
209 dev_notice(&pdev
->dev
, "no configuration for board#%i\n", bd
);
210 dev_notice(&pdev
->dev
, "using defaults for all values\n");
212 { /* Interrupt Moderate Timer */
213 struct atl1_option opt
= {
214 .type
= range_option
,
215 .name
= "Interrupt Moderator Timer",
216 .err
= "using default of "
217 __MODULE_STRING(DEFAULT_INT_MOD_CNT
),
218 .def
= DEFAULT_INT_MOD_CNT
,
219 .arg
= {.r
= {.min
= MIN_INT_MOD_CNT
,
220 .max
= MAX_INT_MOD_CNT
} }
223 if (num_int_mod_timer
> bd
) {
224 val
= int_mod_timer
[bd
];
225 atl1_validate_option(&val
, &opt
, pdev
);
226 adapter
->imt
= (u16
) val
;
228 adapter
->imt
= (u16
) (opt
.def
);
233 * atl1_pci_tbl - PCI Device ID Table
235 static const struct pci_device_id atl1_pci_tbl
[] = {
236 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATTANSIC_L1
)},
237 /* required last entry */
240 MODULE_DEVICE_TABLE(pci
, atl1_pci_tbl
);
242 static const u32 atl1_default_msg
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
243 NETIF_MSG_LINK
| NETIF_MSG_TIMER
| NETIF_MSG_IFDOWN
| NETIF_MSG_IFUP
;
245 static int debug
= -1;
246 module_param(debug
, int, 0);
247 MODULE_PARM_DESC(debug
, "Message level (0=none,...,16=all)");
250 * Reset the transmit and receive units; mask and clear all interrupts.
251 * hw - Struct containing variables accessed by shared code
252 * return : 0 or idle status (if error)
254 static s32
atl1_reset_hw(struct atl1_hw
*hw
)
256 struct pci_dev
*pdev
= hw
->back
->pdev
;
257 struct atl1_adapter
*adapter
= hw
->back
;
262 * Clear Interrupt mask to stop board from generating
263 * interrupts & Clear any pending interrupt events
266 * iowrite32(0, hw->hw_addr + REG_IMR);
267 * iowrite32(0xffffffff, hw->hw_addr + REG_ISR);
271 * Issue Soft Reset to the MAC. This will reset the chip's
272 * transmit, receive, DMA. It will not effect
273 * the current PCI configuration. The global reset bit is self-
274 * clearing, and should clear within a microsecond.
276 iowrite32(MASTER_CTRL_SOFT_RST
, hw
->hw_addr
+ REG_MASTER_CTRL
);
277 ioread32(hw
->hw_addr
+ REG_MASTER_CTRL
);
279 iowrite16(1, hw
->hw_addr
+ REG_PHY_ENABLE
);
280 ioread16(hw
->hw_addr
+ REG_PHY_ENABLE
);
282 /* delay about 1ms */
285 /* Wait at least 10ms for All module to be Idle */
286 for (i
= 0; i
< 10; i
++) {
287 icr
= ioread32(hw
->hw_addr
+ REG_IDLE_STATUS
);
292 /* FIXME: still the right way to do this? */
297 if (netif_msg_hw(adapter
))
298 dev_dbg(&pdev
->dev
, "ICR = 0x%x\n", icr
);
305 /* function about EEPROM
308 * return 0 if eeprom exist
310 static int atl1_check_eeprom_exist(struct atl1_hw
*hw
)
313 value
= ioread32(hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
314 if (value
& SPI_FLASH_CTRL_EN_VPD
) {
315 value
&= ~SPI_FLASH_CTRL_EN_VPD
;
316 iowrite32(value
, hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
319 value
= ioread16(hw
->hw_addr
+ REG_PCIE_CAP_LIST
);
320 return ((value
& 0xFF00) == 0x6C00) ? 0 : 1;
323 static bool atl1_read_eeprom(struct atl1_hw
*hw
, u32 offset
, u32
*p_value
)
329 /* address do not align */
332 iowrite32(0, hw
->hw_addr
+ REG_VPD_DATA
);
333 control
= (offset
& VPD_CAP_VPD_ADDR_MASK
) << VPD_CAP_VPD_ADDR_SHIFT
;
334 iowrite32(control
, hw
->hw_addr
+ REG_VPD_CAP
);
335 ioread32(hw
->hw_addr
+ REG_VPD_CAP
);
337 for (i
= 0; i
< 10; i
++) {
339 control
= ioread32(hw
->hw_addr
+ REG_VPD_CAP
);
340 if (control
& VPD_CAP_VPD_FLAG
)
343 if (control
& VPD_CAP_VPD_FLAG
) {
344 *p_value
= ioread32(hw
->hw_addr
+ REG_VPD_DATA
);
352 * Reads the value from a PHY register
353 * hw - Struct containing variables accessed by shared code
354 * reg_addr - address of the PHY register to read
356 s32
atl1_read_phy_reg(struct atl1_hw
*hw
, u16 reg_addr
, u16
*phy_data
)
361 val
= ((u32
) (reg_addr
& MDIO_REG_ADDR_MASK
)) << MDIO_REG_ADDR_SHIFT
|
362 MDIO_START
| MDIO_SUP_PREAMBLE
| MDIO_RW
| MDIO_CLK_25_4
<<
364 iowrite32(val
, hw
->hw_addr
+ REG_MDIO_CTRL
);
365 ioread32(hw
->hw_addr
+ REG_MDIO_CTRL
);
367 for (i
= 0; i
< MDIO_WAIT_TIMES
; i
++) {
369 val
= ioread32(hw
->hw_addr
+ REG_MDIO_CTRL
);
370 if (!(val
& (MDIO_START
| MDIO_BUSY
)))
373 if (!(val
& (MDIO_START
| MDIO_BUSY
))) {
374 *phy_data
= (u16
) val
;
380 #define CUSTOM_SPI_CS_SETUP 2
381 #define CUSTOM_SPI_CLK_HI 2
382 #define CUSTOM_SPI_CLK_LO 2
383 #define CUSTOM_SPI_CS_HOLD 2
384 #define CUSTOM_SPI_CS_HI 3
386 static bool atl1_spi_read(struct atl1_hw
*hw
, u32 addr
, u32
*buf
)
391 iowrite32(0, hw
->hw_addr
+ REG_SPI_DATA
);
392 iowrite32(addr
, hw
->hw_addr
+ REG_SPI_ADDR
);
394 value
= SPI_FLASH_CTRL_WAIT_READY
|
395 (CUSTOM_SPI_CS_SETUP
& SPI_FLASH_CTRL_CS_SETUP_MASK
) <<
396 SPI_FLASH_CTRL_CS_SETUP_SHIFT
| (CUSTOM_SPI_CLK_HI
&
397 SPI_FLASH_CTRL_CLK_HI_MASK
) <<
398 SPI_FLASH_CTRL_CLK_HI_SHIFT
| (CUSTOM_SPI_CLK_LO
&
399 SPI_FLASH_CTRL_CLK_LO_MASK
) <<
400 SPI_FLASH_CTRL_CLK_LO_SHIFT
| (CUSTOM_SPI_CS_HOLD
&
401 SPI_FLASH_CTRL_CS_HOLD_MASK
) <<
402 SPI_FLASH_CTRL_CS_HOLD_SHIFT
| (CUSTOM_SPI_CS_HI
&
403 SPI_FLASH_CTRL_CS_HI_MASK
) <<
404 SPI_FLASH_CTRL_CS_HI_SHIFT
| (1 & SPI_FLASH_CTRL_INS_MASK
) <<
405 SPI_FLASH_CTRL_INS_SHIFT
;
407 iowrite32(value
, hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
409 value
|= SPI_FLASH_CTRL_START
;
410 iowrite32(value
, hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
411 ioread32(hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
413 for (i
= 0; i
< 10; i
++) {
415 value
= ioread32(hw
->hw_addr
+ REG_SPI_FLASH_CTRL
);
416 if (!(value
& SPI_FLASH_CTRL_START
))
420 if (value
& SPI_FLASH_CTRL_START
)
423 *buf
= ioread32(hw
->hw_addr
+ REG_SPI_DATA
);
429 * get_permanent_address
430 * return 0 if get valid mac address,
432 static int atl1_get_permanent_address(struct atl1_hw
*hw
)
437 u8 eth_addr
[ETH_ALEN
];
440 if (is_valid_ether_addr(hw
->perm_mac_addr
))
444 addr
[0] = addr
[1] = 0;
446 if (!atl1_check_eeprom_exist(hw
)) {
449 /* Read out all EEPROM content */
452 if (atl1_read_eeprom(hw
, i
+ 0x100, &control
)) {
454 if (reg
== REG_MAC_STA_ADDR
)
456 else if (reg
== (REG_MAC_STA_ADDR
+ 4))
459 } else if ((control
& 0xff) == 0x5A) {
461 reg
= (u16
) (control
>> 16);
470 *(u32
*) ð_addr
[2] = swab32(addr
[0]);
471 *(u16
*) ð_addr
[0] = swab16(*(u16
*) &addr
[1]);
472 if (is_valid_ether_addr(eth_addr
)) {
473 memcpy(hw
->perm_mac_addr
, eth_addr
, ETH_ALEN
);
478 /* see if SPI FLAGS exist ? */
479 addr
[0] = addr
[1] = 0;
484 if (atl1_spi_read(hw
, i
+ 0x1f000, &control
)) {
486 if (reg
== REG_MAC_STA_ADDR
)
488 else if (reg
== (REG_MAC_STA_ADDR
+ 4))
491 } else if ((control
& 0xff) == 0x5A) {
493 reg
= (u16
) (control
>> 16);
503 *(u32
*) ð_addr
[2] = swab32(addr
[0]);
504 *(u16
*) ð_addr
[0] = swab16(*(u16
*) &addr
[1]);
505 if (is_valid_ether_addr(eth_addr
)) {
506 memcpy(hw
->perm_mac_addr
, eth_addr
, ETH_ALEN
);
511 * On some motherboards, the MAC address is written by the
512 * BIOS directly to the MAC register during POST, and is
513 * not stored in eeprom. If all else thus far has failed
514 * to fetch the permanent MAC address, try reading it directly.
516 addr
[0] = ioread32(hw
->hw_addr
+ REG_MAC_STA_ADDR
);
517 addr
[1] = ioread16(hw
->hw_addr
+ (REG_MAC_STA_ADDR
+ 4));
518 *(u32
*) ð_addr
[2] = swab32(addr
[0]);
519 *(u16
*) ð_addr
[0] = swab16(*(u16
*) &addr
[1]);
520 if (is_valid_ether_addr(eth_addr
)) {
521 memcpy(hw
->perm_mac_addr
, eth_addr
, ETH_ALEN
);
529 * Reads the adapter's MAC address from the EEPROM
530 * hw - Struct containing variables accessed by shared code
532 static s32
atl1_read_mac_addr(struct atl1_hw
*hw
)
536 if (atl1_get_permanent_address(hw
))
537 random_ether_addr(hw
->perm_mac_addr
);
539 for (i
= 0; i
< ETH_ALEN
; i
++)
540 hw
->mac_addr
[i
] = hw
->perm_mac_addr
[i
];
545 * Hashes an address to determine its location in the multicast table
546 * hw - Struct containing variables accessed by shared code
547 * mc_addr - the multicast address to hash
551 * set hash value for a multicast address
552 * hash calcu processing :
553 * 1. calcu 32bit CRC for multicast address
554 * 2. reverse crc with MSB to LSB
556 u32
atl1_hash_mc_addr(struct atl1_hw
*hw
, u8
*mc_addr
)
558 u32 crc32
, value
= 0;
561 crc32
= ether_crc_le(6, mc_addr
);
562 for (i
= 0; i
< 32; i
++)
563 value
|= (((crc32
>> i
) & 1) << (31 - i
));
569 * Sets the bit in the multicast table corresponding to the hash value.
570 * hw - Struct containing variables accessed by shared code
571 * hash_value - Multicast address hash value
573 void atl1_hash_set(struct atl1_hw
*hw
, u32 hash_value
)
575 u32 hash_bit
, hash_reg
;
579 * The HASH Table is a register array of 2 32-bit registers.
580 * It is treated like an array of 64 bits. We want to set
581 * bit BitArray[hash_value]. So we figure out what register
582 * the bit is in, read it, OR in the new bit, then write
583 * back the new value. The register is determined by the
584 * upper 7 bits of the hash value and the bit within that
585 * register are determined by the lower 5 bits of the value.
587 hash_reg
= (hash_value
>> 31) & 0x1;
588 hash_bit
= (hash_value
>> 26) & 0x1F;
589 mta
= ioread32((hw
->hw_addr
+ REG_RX_HASH_TABLE
) + (hash_reg
<< 2));
590 mta
|= (1 << hash_bit
);
591 iowrite32(mta
, (hw
->hw_addr
+ REG_RX_HASH_TABLE
) + (hash_reg
<< 2));
595 * Writes a value to a PHY register
596 * hw - Struct containing variables accessed by shared code
597 * reg_addr - address of the PHY register to write
598 * data - data to write to the PHY
600 static s32
atl1_write_phy_reg(struct atl1_hw
*hw
, u32 reg_addr
, u16 phy_data
)
605 val
= ((u32
) (phy_data
& MDIO_DATA_MASK
)) << MDIO_DATA_SHIFT
|
606 (reg_addr
& MDIO_REG_ADDR_MASK
) << MDIO_REG_ADDR_SHIFT
|
608 MDIO_START
| MDIO_CLK_25_4
<< MDIO_CLK_SEL_SHIFT
;
609 iowrite32(val
, hw
->hw_addr
+ REG_MDIO_CTRL
);
610 ioread32(hw
->hw_addr
+ REG_MDIO_CTRL
);
612 for (i
= 0; i
< MDIO_WAIT_TIMES
; i
++) {
614 val
= ioread32(hw
->hw_addr
+ REG_MDIO_CTRL
);
615 if (!(val
& (MDIO_START
| MDIO_BUSY
)))
619 if (!(val
& (MDIO_START
| MDIO_BUSY
)))
626 * Make L001's PHY out of Power Saving State (bug)
627 * hw - Struct containing variables accessed by shared code
628 * when power on, L001's PHY always on Power saving State
629 * (Gigabit Link forbidden)
631 static s32
atl1_phy_leave_power_saving(struct atl1_hw
*hw
)
634 ret
= atl1_write_phy_reg(hw
, 29, 0x0029);
637 return atl1_write_phy_reg(hw
, 30, 0);
641 * Resets the PHY and make all config validate
642 * hw - Struct containing variables accessed by shared code
644 * Sets bit 15 and 12 of the MII Control regiser (for F001 bug)
646 static s32
atl1_phy_reset(struct atl1_hw
*hw
)
648 struct pci_dev
*pdev
= hw
->back
->pdev
;
649 struct atl1_adapter
*adapter
= hw
->back
;
653 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
654 hw
->media_type
== MEDIA_TYPE_1000M_FULL
)
655 phy_data
= MII_CR_RESET
| MII_CR_AUTO_NEG_EN
;
657 switch (hw
->media_type
) {
658 case MEDIA_TYPE_100M_FULL
:
660 MII_CR_FULL_DUPLEX
| MII_CR_SPEED_100
|
663 case MEDIA_TYPE_100M_HALF
:
664 phy_data
= MII_CR_SPEED_100
| MII_CR_RESET
;
666 case MEDIA_TYPE_10M_FULL
:
668 MII_CR_FULL_DUPLEX
| MII_CR_SPEED_10
| MII_CR_RESET
;
671 /* MEDIA_TYPE_10M_HALF: */
672 phy_data
= MII_CR_SPEED_10
| MII_CR_RESET
;
677 ret_val
= atl1_write_phy_reg(hw
, MII_BMCR
, phy_data
);
681 /* pcie serdes link may be down! */
682 if (netif_msg_hw(adapter
))
683 dev_dbg(&pdev
->dev
, "pcie phy link down\n");
685 for (i
= 0; i
< 25; i
++) {
687 val
= ioread32(hw
->hw_addr
+ REG_MDIO_CTRL
);
688 if (!(val
& (MDIO_START
| MDIO_BUSY
)))
692 if ((val
& (MDIO_START
| MDIO_BUSY
)) != 0) {
693 if (netif_msg_hw(adapter
))
695 "pcie link down at least 25ms\n");
703 * Configures PHY autoneg and flow control advertisement settings
704 * hw - Struct containing variables accessed by shared code
706 static s32
atl1_phy_setup_autoneg_adv(struct atl1_hw
*hw
)
709 s16 mii_autoneg_adv_reg
;
710 s16 mii_1000t_ctrl_reg
;
712 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
713 mii_autoneg_adv_reg
= MII_AR_DEFAULT_CAP_MASK
;
715 /* Read the MII 1000Base-T Control Register (Address 9). */
716 mii_1000t_ctrl_reg
= MII_ATLX_CR_1000T_DEFAULT_CAP_MASK
;
719 * First we clear all the 10/100 mb speed bits in the Auto-Neg
720 * Advertisement Register (Address 4) and the 1000 mb speed bits in
721 * the 1000Base-T Control Register (Address 9).
723 mii_autoneg_adv_reg
&= ~MII_AR_SPEED_MASK
;
724 mii_1000t_ctrl_reg
&= ~MII_ATLX_CR_1000T_SPEED_MASK
;
727 * Need to parse media_type and set up
728 * the appropriate PHY registers.
730 switch (hw
->media_type
) {
731 case MEDIA_TYPE_AUTO_SENSOR
:
732 mii_autoneg_adv_reg
|= (MII_AR_10T_HD_CAPS
|
734 MII_AR_100TX_HD_CAPS
|
735 MII_AR_100TX_FD_CAPS
);
736 mii_1000t_ctrl_reg
|= MII_ATLX_CR_1000T_FD_CAPS
;
739 case MEDIA_TYPE_1000M_FULL
:
740 mii_1000t_ctrl_reg
|= MII_ATLX_CR_1000T_FD_CAPS
;
743 case MEDIA_TYPE_100M_FULL
:
744 mii_autoneg_adv_reg
|= MII_AR_100TX_FD_CAPS
;
747 case MEDIA_TYPE_100M_HALF
:
748 mii_autoneg_adv_reg
|= MII_AR_100TX_HD_CAPS
;
751 case MEDIA_TYPE_10M_FULL
:
752 mii_autoneg_adv_reg
|= MII_AR_10T_FD_CAPS
;
756 mii_autoneg_adv_reg
|= MII_AR_10T_HD_CAPS
;
760 /* flow control fixed to enable all */
761 mii_autoneg_adv_reg
|= (MII_AR_ASM_DIR
| MII_AR_PAUSE
);
763 hw
->mii_autoneg_adv_reg
= mii_autoneg_adv_reg
;
764 hw
->mii_1000t_ctrl_reg
= mii_1000t_ctrl_reg
;
766 ret_val
= atl1_write_phy_reg(hw
, MII_ADVERTISE
, mii_autoneg_adv_reg
);
770 ret_val
= atl1_write_phy_reg(hw
, MII_ATLX_CR
, mii_1000t_ctrl_reg
);
778 * Configures link settings.
779 * hw - Struct containing variables accessed by shared code
780 * Assumes the hardware has previously been reset and the
781 * transmitter and receiver are not enabled.
783 static s32
atl1_setup_link(struct atl1_hw
*hw
)
785 struct pci_dev
*pdev
= hw
->back
->pdev
;
786 struct atl1_adapter
*adapter
= hw
->back
;
791 * PHY will advertise value(s) parsed from
792 * autoneg_advertised and fc
793 * no matter what autoneg is , We will not wait link result.
795 ret_val
= atl1_phy_setup_autoneg_adv(hw
);
797 if (netif_msg_link(adapter
))
799 "error setting up autonegotiation\n");
802 /* SW.Reset , En-Auto-Neg if needed */
803 ret_val
= atl1_phy_reset(hw
);
805 if (netif_msg_link(adapter
))
806 dev_dbg(&pdev
->dev
, "error resetting phy\n");
809 hw
->phy_configured
= true;
813 static void atl1_init_flash_opcode(struct atl1_hw
*hw
)
815 if (hw
->flash_vendor
>= ARRAY_SIZE(flash_table
))
817 hw
->flash_vendor
= 0;
820 iowrite8(flash_table
[hw
->flash_vendor
].cmd_program
,
821 hw
->hw_addr
+ REG_SPI_FLASH_OP_PROGRAM
);
822 iowrite8(flash_table
[hw
->flash_vendor
].cmd_sector_erase
,
823 hw
->hw_addr
+ REG_SPI_FLASH_OP_SC_ERASE
);
824 iowrite8(flash_table
[hw
->flash_vendor
].cmd_chip_erase
,
825 hw
->hw_addr
+ REG_SPI_FLASH_OP_CHIP_ERASE
);
826 iowrite8(flash_table
[hw
->flash_vendor
].cmd_rdid
,
827 hw
->hw_addr
+ REG_SPI_FLASH_OP_RDID
);
828 iowrite8(flash_table
[hw
->flash_vendor
].cmd_wren
,
829 hw
->hw_addr
+ REG_SPI_FLASH_OP_WREN
);
830 iowrite8(flash_table
[hw
->flash_vendor
].cmd_rdsr
,
831 hw
->hw_addr
+ REG_SPI_FLASH_OP_RDSR
);
832 iowrite8(flash_table
[hw
->flash_vendor
].cmd_wrsr
,
833 hw
->hw_addr
+ REG_SPI_FLASH_OP_WRSR
);
834 iowrite8(flash_table
[hw
->flash_vendor
].cmd_read
,
835 hw
->hw_addr
+ REG_SPI_FLASH_OP_READ
);
839 * Performs basic configuration of the adapter.
840 * hw - Struct containing variables accessed by shared code
841 * Assumes that the controller has previously been reset and is in a
842 * post-reset uninitialized state. Initializes multicast table,
843 * and Calls routines to setup link
844 * Leaves the transmit and receive units disabled and uninitialized.
846 static s32
atl1_init_hw(struct atl1_hw
*hw
)
850 /* Zero out the Multicast HASH table */
851 iowrite32(0, hw
->hw_addr
+ REG_RX_HASH_TABLE
);
852 /* clear the old settings from the multicast hash table */
853 iowrite32(0, (hw
->hw_addr
+ REG_RX_HASH_TABLE
) + (1 << 2));
855 atl1_init_flash_opcode(hw
);
857 if (!hw
->phy_configured
) {
858 /* enable GPHY LinkChange Interrrupt */
859 ret_val
= atl1_write_phy_reg(hw
, 18, 0xC00);
862 /* make PHY out of power-saving state */
863 ret_val
= atl1_phy_leave_power_saving(hw
);
866 /* Call a subroutine to configure the link */
867 ret_val
= atl1_setup_link(hw
);
873 * Detects the current speed and duplex settings of the hardware.
874 * hw - Struct containing variables accessed by shared code
875 * speed - Speed of the connection
876 * duplex - Duplex setting of the connection
878 static s32
atl1_get_speed_and_duplex(struct atl1_hw
*hw
, u16
*speed
, u16
*duplex
)
880 struct pci_dev
*pdev
= hw
->back
->pdev
;
881 struct atl1_adapter
*adapter
= hw
->back
;
885 /* ; --- Read PHY Specific Status Register (17) */
886 ret_val
= atl1_read_phy_reg(hw
, MII_ATLX_PSSR
, &phy_data
);
890 if (!(phy_data
& MII_ATLX_PSSR_SPD_DPLX_RESOLVED
))
891 return ATLX_ERR_PHY_RES
;
893 switch (phy_data
& MII_ATLX_PSSR_SPEED
) {
894 case MII_ATLX_PSSR_1000MBS
:
897 case MII_ATLX_PSSR_100MBS
:
900 case MII_ATLX_PSSR_10MBS
:
904 if (netif_msg_hw(adapter
))
905 dev_dbg(&pdev
->dev
, "error getting speed\n");
906 return ATLX_ERR_PHY_SPEED
;
909 if (phy_data
& MII_ATLX_PSSR_DPLX
)
910 *duplex
= FULL_DUPLEX
;
912 *duplex
= HALF_DUPLEX
;
917 void atl1_set_mac_addr(struct atl1_hw
*hw
)
922 * 0: 6AF600DC 1: 000B
925 value
= (((u32
) hw
->mac_addr
[2]) << 24) |
926 (((u32
) hw
->mac_addr
[3]) << 16) |
927 (((u32
) hw
->mac_addr
[4]) << 8) | (((u32
) hw
->mac_addr
[5]));
928 iowrite32(value
, hw
->hw_addr
+ REG_MAC_STA_ADDR
);
930 value
= (((u32
) hw
->mac_addr
[0]) << 8) | (((u32
) hw
->mac_addr
[1]));
931 iowrite32(value
, (hw
->hw_addr
+ REG_MAC_STA_ADDR
) + (1 << 2));
935 * atl1_sw_init - Initialize general software structures (struct atl1_adapter)
936 * @adapter: board private structure to initialize
938 * atl1_sw_init initializes the Adapter private data structure.
939 * Fields are initialized based on PCI device information and
940 * OS network device settings (MTU size).
942 static int __devinit
atl1_sw_init(struct atl1_adapter
*adapter
)
944 struct atl1_hw
*hw
= &adapter
->hw
;
945 struct net_device
*netdev
= adapter
->netdev
;
947 hw
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
948 hw
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
951 adapter
->rx_buffer_len
= (hw
->max_frame_size
+ 7) & ~7;
952 adapter
->ict
= 50000; /* 100ms */
953 adapter
->link_speed
= SPEED_0
; /* hardware init */
954 adapter
->link_duplex
= FULL_DUPLEX
;
956 hw
->phy_configured
= false;
957 hw
->preamble_len
= 7;
967 hw
->rfd_fetch_gap
= 1;
968 hw
->rx_jumbo_th
= adapter
->rx_buffer_len
/ 8;
969 hw
->rx_jumbo_lkah
= 1;
970 hw
->rrd_ret_timer
= 16;
972 hw
->tpd_fetch_th
= 16;
973 hw
->txf_burst
= 0x100;
974 hw
->tx_jumbo_task_th
= (hw
->max_frame_size
+ 7) >> 3;
975 hw
->tpd_fetch_gap
= 1;
976 hw
->rcb_value
= atl1_rcb_64
;
977 hw
->dma_ord
= atl1_dma_ord_enh
;
978 hw
->dmar_block
= atl1_dma_req_256
;
979 hw
->dmaw_block
= atl1_dma_req_256
;
982 hw
->cmb_rx_timer
= 1; /* about 2us */
983 hw
->cmb_tx_timer
= 1; /* about 2us */
984 hw
->smb_timer
= 100000; /* about 200ms */
986 spin_lock_init(&adapter
->lock
);
987 spin_lock_init(&adapter
->mb_lock
);
992 static int mdio_read(struct net_device
*netdev
, int phy_id
, int reg_num
)
994 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
997 atl1_read_phy_reg(&adapter
->hw
, reg_num
& 0x1f, &result
);
1002 static void mdio_write(struct net_device
*netdev
, int phy_id
, int reg_num
,
1005 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
1007 atl1_write_phy_reg(&adapter
->hw
, reg_num
, val
);
1016 static int atl1_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1018 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
1019 unsigned long flags
;
1022 if (!netif_running(netdev
))
1025 spin_lock_irqsave(&adapter
->lock
, flags
);
1026 retval
= generic_mii_ioctl(&adapter
->mii
, if_mii(ifr
), cmd
, NULL
);
1027 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1033 * atl1_setup_mem_resources - allocate Tx / RX descriptor resources
1034 * @adapter: board private structure
1036 * Return 0 on success, negative on failure
1038 static s32
atl1_setup_ring_resources(struct atl1_adapter
*adapter
)
1040 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
1041 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1042 struct atl1_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1043 struct atl1_ring_header
*ring_header
= &adapter
->ring_header
;
1044 struct pci_dev
*pdev
= adapter
->pdev
;
1048 size
= sizeof(struct atl1_buffer
) * (tpd_ring
->count
+ rfd_ring
->count
);
1049 tpd_ring
->buffer_info
= kzalloc(size
, GFP_KERNEL
);
1050 if (unlikely(!tpd_ring
->buffer_info
)) {
1051 if (netif_msg_drv(adapter
))
1052 dev_err(&pdev
->dev
, "kzalloc failed , size = D%d\n",
1056 rfd_ring
->buffer_info
=
1057 (struct atl1_buffer
*)(tpd_ring
->buffer_info
+ tpd_ring
->count
);
1060 * real ring DMA buffer
1061 * each ring/block may need up to 8 bytes for alignment, hence the
1062 * additional 40 bytes tacked onto the end.
1064 ring_header
->size
= size
=
1065 sizeof(struct tx_packet_desc
) * tpd_ring
->count
1066 + sizeof(struct rx_free_desc
) * rfd_ring
->count
1067 + sizeof(struct rx_return_desc
) * rrd_ring
->count
1068 + sizeof(struct coals_msg_block
)
1069 + sizeof(struct stats_msg_block
)
1072 ring_header
->desc
= pci_alloc_consistent(pdev
, ring_header
->size
,
1074 if (unlikely(!ring_header
->desc
)) {
1075 if (netif_msg_drv(adapter
))
1076 dev_err(&pdev
->dev
, "pci_alloc_consistent failed\n");
1080 memset(ring_header
->desc
, 0, ring_header
->size
);
1083 tpd_ring
->dma
= ring_header
->dma
;
1084 offset
= (tpd_ring
->dma
& 0x7) ? (8 - (ring_header
->dma
& 0x7)) : 0;
1085 tpd_ring
->dma
+= offset
;
1086 tpd_ring
->desc
= (u8
*) ring_header
->desc
+ offset
;
1087 tpd_ring
->size
= sizeof(struct tx_packet_desc
) * tpd_ring
->count
;
1090 rfd_ring
->dma
= tpd_ring
->dma
+ tpd_ring
->size
;
1091 offset
= (rfd_ring
->dma
& 0x7) ? (8 - (rfd_ring
->dma
& 0x7)) : 0;
1092 rfd_ring
->dma
+= offset
;
1093 rfd_ring
->desc
= (u8
*) tpd_ring
->desc
+ (tpd_ring
->size
+ offset
);
1094 rfd_ring
->size
= sizeof(struct rx_free_desc
) * rfd_ring
->count
;
1098 rrd_ring
->dma
= rfd_ring
->dma
+ rfd_ring
->size
;
1099 offset
= (rrd_ring
->dma
& 0x7) ? (8 - (rrd_ring
->dma
& 0x7)) : 0;
1100 rrd_ring
->dma
+= offset
;
1101 rrd_ring
->desc
= (u8
*) rfd_ring
->desc
+ (rfd_ring
->size
+ offset
);
1102 rrd_ring
->size
= sizeof(struct rx_return_desc
) * rrd_ring
->count
;
1106 adapter
->cmb
.dma
= rrd_ring
->dma
+ rrd_ring
->size
;
1107 offset
= (adapter
->cmb
.dma
& 0x7) ? (8 - (adapter
->cmb
.dma
& 0x7)) : 0;
1108 adapter
->cmb
.dma
+= offset
;
1109 adapter
->cmb
.cmb
= (struct coals_msg_block
*)
1110 ((u8
*) rrd_ring
->desc
+ (rrd_ring
->size
+ offset
));
1113 adapter
->smb
.dma
= adapter
->cmb
.dma
+ sizeof(struct coals_msg_block
);
1114 offset
= (adapter
->smb
.dma
& 0x7) ? (8 - (adapter
->smb
.dma
& 0x7)) : 0;
1115 adapter
->smb
.dma
+= offset
;
1116 adapter
->smb
.smb
= (struct stats_msg_block
*)
1117 ((u8
*) adapter
->cmb
.cmb
+
1118 (sizeof(struct coals_msg_block
) + offset
));
1123 kfree(tpd_ring
->buffer_info
);
1127 static void atl1_init_ring_ptrs(struct atl1_adapter
*adapter
)
1129 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
1130 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1131 struct atl1_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1133 atomic_set(&tpd_ring
->next_to_use
, 0);
1134 atomic_set(&tpd_ring
->next_to_clean
, 0);
1136 rfd_ring
->next_to_clean
= 0;
1137 atomic_set(&rfd_ring
->next_to_use
, 0);
1139 rrd_ring
->next_to_use
= 0;
1140 atomic_set(&rrd_ring
->next_to_clean
, 0);
1144 * atl1_clean_rx_ring - Free RFD Buffers
1145 * @adapter: board private structure
1147 static void atl1_clean_rx_ring(struct atl1_adapter
*adapter
)
1149 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1150 struct atl1_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1151 struct atl1_buffer
*buffer_info
;
1152 struct pci_dev
*pdev
= adapter
->pdev
;
1156 /* Free all the Rx ring sk_buffs */
1157 for (i
= 0; i
< rfd_ring
->count
; i
++) {
1158 buffer_info
= &rfd_ring
->buffer_info
[i
];
1159 if (buffer_info
->dma
) {
1160 pci_unmap_page(pdev
, buffer_info
->dma
,
1161 buffer_info
->length
, PCI_DMA_FROMDEVICE
);
1162 buffer_info
->dma
= 0;
1164 if (buffer_info
->skb
) {
1165 dev_kfree_skb(buffer_info
->skb
);
1166 buffer_info
->skb
= NULL
;
1170 size
= sizeof(struct atl1_buffer
) * rfd_ring
->count
;
1171 memset(rfd_ring
->buffer_info
, 0, size
);
1173 /* Zero out the descriptor ring */
1174 memset(rfd_ring
->desc
, 0, rfd_ring
->size
);
1176 rfd_ring
->next_to_clean
= 0;
1177 atomic_set(&rfd_ring
->next_to_use
, 0);
1179 rrd_ring
->next_to_use
= 0;
1180 atomic_set(&rrd_ring
->next_to_clean
, 0);
1184 * atl1_clean_tx_ring - Free Tx Buffers
1185 * @adapter: board private structure
1187 static void atl1_clean_tx_ring(struct atl1_adapter
*adapter
)
1189 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
1190 struct atl1_buffer
*buffer_info
;
1191 struct pci_dev
*pdev
= adapter
->pdev
;
1195 /* Free all the Tx ring sk_buffs */
1196 for (i
= 0; i
< tpd_ring
->count
; i
++) {
1197 buffer_info
= &tpd_ring
->buffer_info
[i
];
1198 if (buffer_info
->dma
) {
1199 pci_unmap_page(pdev
, buffer_info
->dma
,
1200 buffer_info
->length
, PCI_DMA_TODEVICE
);
1201 buffer_info
->dma
= 0;
1205 for (i
= 0; i
< tpd_ring
->count
; i
++) {
1206 buffer_info
= &tpd_ring
->buffer_info
[i
];
1207 if (buffer_info
->skb
) {
1208 dev_kfree_skb_any(buffer_info
->skb
);
1209 buffer_info
->skb
= NULL
;
1213 size
= sizeof(struct atl1_buffer
) * tpd_ring
->count
;
1214 memset(tpd_ring
->buffer_info
, 0, size
);
1216 /* Zero out the descriptor ring */
1217 memset(tpd_ring
->desc
, 0, tpd_ring
->size
);
1219 atomic_set(&tpd_ring
->next_to_use
, 0);
1220 atomic_set(&tpd_ring
->next_to_clean
, 0);
1224 * atl1_free_ring_resources - Free Tx / RX descriptor Resources
1225 * @adapter: board private structure
1227 * Free all transmit software resources
1229 static void atl1_free_ring_resources(struct atl1_adapter
*adapter
)
1231 struct pci_dev
*pdev
= adapter
->pdev
;
1232 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
1233 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1234 struct atl1_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1235 struct atl1_ring_header
*ring_header
= &adapter
->ring_header
;
1237 atl1_clean_tx_ring(adapter
);
1238 atl1_clean_rx_ring(adapter
);
1240 kfree(tpd_ring
->buffer_info
);
1241 pci_free_consistent(pdev
, ring_header
->size
, ring_header
->desc
,
1244 tpd_ring
->buffer_info
= NULL
;
1245 tpd_ring
->desc
= NULL
;
1248 rfd_ring
->buffer_info
= NULL
;
1249 rfd_ring
->desc
= NULL
;
1252 rrd_ring
->desc
= NULL
;
1256 static void atl1_setup_mac_ctrl(struct atl1_adapter
*adapter
)
1259 struct atl1_hw
*hw
= &adapter
->hw
;
1260 struct net_device
*netdev
= adapter
->netdev
;
1261 /* Config MAC CTRL Register */
1262 value
= MAC_CTRL_TX_EN
| MAC_CTRL_RX_EN
;
1264 if (FULL_DUPLEX
== adapter
->link_duplex
)
1265 value
|= MAC_CTRL_DUPLX
;
1267 value
|= ((u32
) ((SPEED_1000
== adapter
->link_speed
) ?
1268 MAC_CTRL_SPEED_1000
: MAC_CTRL_SPEED_10_100
) <<
1269 MAC_CTRL_SPEED_SHIFT
);
1271 value
|= (MAC_CTRL_TX_FLOW
| MAC_CTRL_RX_FLOW
);
1273 value
|= (MAC_CTRL_ADD_CRC
| MAC_CTRL_PAD
);
1274 /* preamble length */
1275 value
|= (((u32
) adapter
->hw
.preamble_len
1276 & MAC_CTRL_PRMLEN_MASK
) << MAC_CTRL_PRMLEN_SHIFT
);
1279 value
|= MAC_CTRL_RMV_VLAN
;
1281 if (adapter->rx_csum)
1282 value |= MAC_CTRL_RX_CHKSUM_EN;
1285 value
|= MAC_CTRL_BC_EN
;
1286 if (netdev
->flags
& IFF_PROMISC
)
1287 value
|= MAC_CTRL_PROMIS_EN
;
1288 else if (netdev
->flags
& IFF_ALLMULTI
)
1289 value
|= MAC_CTRL_MC_ALL_EN
;
1290 /* value |= MAC_CTRL_LOOPBACK; */
1291 iowrite32(value
, hw
->hw_addr
+ REG_MAC_CTRL
);
1294 static u32
atl1_check_link(struct atl1_adapter
*adapter
)
1296 struct atl1_hw
*hw
= &adapter
->hw
;
1297 struct net_device
*netdev
= adapter
->netdev
;
1299 u16 speed
, duplex
, phy_data
;
1302 /* MII_BMSR must read twice */
1303 atl1_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
1304 atl1_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
1305 if (!(phy_data
& BMSR_LSTATUS
)) {
1307 if (netif_carrier_ok(netdev
)) {
1308 /* old link state: Up */
1309 if (netif_msg_link(adapter
))
1310 dev_info(&adapter
->pdev
->dev
, "link is down\n");
1311 adapter
->link_speed
= SPEED_0
;
1312 netif_carrier_off(netdev
);
1318 ret_val
= atl1_get_speed_and_duplex(hw
, &speed
, &duplex
);
1322 switch (hw
->media_type
) {
1323 case MEDIA_TYPE_1000M_FULL
:
1324 if (speed
!= SPEED_1000
|| duplex
!= FULL_DUPLEX
)
1327 case MEDIA_TYPE_100M_FULL
:
1328 if (speed
!= SPEED_100
|| duplex
!= FULL_DUPLEX
)
1331 case MEDIA_TYPE_100M_HALF
:
1332 if (speed
!= SPEED_100
|| duplex
!= HALF_DUPLEX
)
1335 case MEDIA_TYPE_10M_FULL
:
1336 if (speed
!= SPEED_10
|| duplex
!= FULL_DUPLEX
)
1339 case MEDIA_TYPE_10M_HALF
:
1340 if (speed
!= SPEED_10
|| duplex
!= HALF_DUPLEX
)
1345 /* link result is our setting */
1347 if (adapter
->link_speed
!= speed
1348 || adapter
->link_duplex
!= duplex
) {
1349 adapter
->link_speed
= speed
;
1350 adapter
->link_duplex
= duplex
;
1351 atl1_setup_mac_ctrl(adapter
);
1352 if (netif_msg_link(adapter
))
1353 dev_info(&adapter
->pdev
->dev
,
1354 "%s link is up %d Mbps %s\n",
1355 netdev
->name
, adapter
->link_speed
,
1356 adapter
->link_duplex
== FULL_DUPLEX
?
1357 "full duplex" : "half duplex");
1359 if (!netif_carrier_ok(netdev
)) {
1360 /* Link down -> Up */
1361 netif_carrier_on(netdev
);
1366 /* change original link status */
1367 if (netif_carrier_ok(netdev
)) {
1368 adapter
->link_speed
= SPEED_0
;
1369 netif_carrier_off(netdev
);
1370 netif_stop_queue(netdev
);
1373 if (hw
->media_type
!= MEDIA_TYPE_AUTO_SENSOR
&&
1374 hw
->media_type
!= MEDIA_TYPE_1000M_FULL
) {
1375 switch (hw
->media_type
) {
1376 case MEDIA_TYPE_100M_FULL
:
1377 phy_data
= MII_CR_FULL_DUPLEX
| MII_CR_SPEED_100
|
1380 case MEDIA_TYPE_100M_HALF
:
1381 phy_data
= MII_CR_SPEED_100
| MII_CR_RESET
;
1383 case MEDIA_TYPE_10M_FULL
:
1385 MII_CR_FULL_DUPLEX
| MII_CR_SPEED_10
| MII_CR_RESET
;
1388 /* MEDIA_TYPE_10M_HALF: */
1389 phy_data
= MII_CR_SPEED_10
| MII_CR_RESET
;
1392 atl1_write_phy_reg(hw
, MII_BMCR
, phy_data
);
1396 /* auto-neg, insert timer to re-config phy */
1397 if (!adapter
->phy_timer_pending
) {
1398 adapter
->phy_timer_pending
= true;
1399 mod_timer(&adapter
->phy_config_timer
,
1400 round_jiffies(jiffies
+ 3 * HZ
));
1406 static void set_flow_ctrl_old(struct atl1_adapter
*adapter
)
1410 /* RFD Flow Control */
1411 value
= adapter
->rfd_ring
.count
;
1417 value
= ((hi
& RXQ_RXF_PAUSE_TH_HI_MASK
) << RXQ_RXF_PAUSE_TH_HI_SHIFT
) |
1418 ((lo
& RXQ_RXF_PAUSE_TH_LO_MASK
) << RXQ_RXF_PAUSE_TH_LO_SHIFT
);
1419 iowrite32(value
, adapter
->hw
.hw_addr
+ REG_RXQ_RXF_PAUSE_THRESH
);
1421 /* RRD Flow Control */
1422 value
= adapter
->rrd_ring
.count
;
1427 value
= ((hi
& RXQ_RRD_PAUSE_TH_HI_MASK
) << RXQ_RRD_PAUSE_TH_HI_SHIFT
) |
1428 ((lo
& RXQ_RRD_PAUSE_TH_LO_MASK
) << RXQ_RRD_PAUSE_TH_LO_SHIFT
);
1429 iowrite32(value
, adapter
->hw
.hw_addr
+ REG_RXQ_RRD_PAUSE_THRESH
);
1432 static void set_flow_ctrl_new(struct atl1_hw
*hw
)
1436 /* RXF Flow Control */
1437 value
= ioread32(hw
->hw_addr
+ REG_SRAM_RXF_LEN
);
1444 value
= ((hi
& RXQ_RXF_PAUSE_TH_HI_MASK
) << RXQ_RXF_PAUSE_TH_HI_SHIFT
) |
1445 ((lo
& RXQ_RXF_PAUSE_TH_LO_MASK
) << RXQ_RXF_PAUSE_TH_LO_SHIFT
);
1446 iowrite32(value
, hw
->hw_addr
+ REG_RXQ_RXF_PAUSE_THRESH
);
1448 /* RRD Flow Control */
1449 value
= ioread32(hw
->hw_addr
+ REG_SRAM_RRD_LEN
);
1456 value
= ((hi
& RXQ_RRD_PAUSE_TH_HI_MASK
) << RXQ_RRD_PAUSE_TH_HI_SHIFT
) |
1457 ((lo
& RXQ_RRD_PAUSE_TH_LO_MASK
) << RXQ_RRD_PAUSE_TH_LO_SHIFT
);
1458 iowrite32(value
, hw
->hw_addr
+ REG_RXQ_RRD_PAUSE_THRESH
);
1462 * atl1_configure - Configure Transmit&Receive Unit after Reset
1463 * @adapter: board private structure
1465 * Configure the Tx /Rx unit of the MAC after a reset.
1467 static u32
atl1_configure(struct atl1_adapter
*adapter
)
1469 struct atl1_hw
*hw
= &adapter
->hw
;
1472 /* clear interrupt status */
1473 iowrite32(0xffffffff, adapter
->hw
.hw_addr
+ REG_ISR
);
1475 /* set MAC Address */
1476 value
= (((u32
) hw
->mac_addr
[2]) << 24) |
1477 (((u32
) hw
->mac_addr
[3]) << 16) |
1478 (((u32
) hw
->mac_addr
[4]) << 8) |
1479 (((u32
) hw
->mac_addr
[5]));
1480 iowrite32(value
, hw
->hw_addr
+ REG_MAC_STA_ADDR
);
1481 value
= (((u32
) hw
->mac_addr
[0]) << 8) | (((u32
) hw
->mac_addr
[1]));
1482 iowrite32(value
, hw
->hw_addr
+ (REG_MAC_STA_ADDR
+ 4));
1486 /* HI base address */
1487 iowrite32((u32
) ((adapter
->tpd_ring
.dma
& 0xffffffff00000000ULL
) >> 32),
1488 hw
->hw_addr
+ REG_DESC_BASE_ADDR_HI
);
1489 /* LO base address */
1490 iowrite32((u32
) (adapter
->rfd_ring
.dma
& 0x00000000ffffffffULL
),
1491 hw
->hw_addr
+ REG_DESC_RFD_ADDR_LO
);
1492 iowrite32((u32
) (adapter
->rrd_ring
.dma
& 0x00000000ffffffffULL
),
1493 hw
->hw_addr
+ REG_DESC_RRD_ADDR_LO
);
1494 iowrite32((u32
) (adapter
->tpd_ring
.dma
& 0x00000000ffffffffULL
),
1495 hw
->hw_addr
+ REG_DESC_TPD_ADDR_LO
);
1496 iowrite32((u32
) (adapter
->cmb
.dma
& 0x00000000ffffffffULL
),
1497 hw
->hw_addr
+ REG_DESC_CMB_ADDR_LO
);
1498 iowrite32((u32
) (adapter
->smb
.dma
& 0x00000000ffffffffULL
),
1499 hw
->hw_addr
+ REG_DESC_SMB_ADDR_LO
);
1502 value
= adapter
->rrd_ring
.count
;
1504 value
+= adapter
->rfd_ring
.count
;
1505 iowrite32(value
, hw
->hw_addr
+ REG_DESC_RFD_RRD_RING_SIZE
);
1506 iowrite32(adapter
->tpd_ring
.count
, hw
->hw_addr
+
1507 REG_DESC_TPD_RING_SIZE
);
1510 iowrite32(1, hw
->hw_addr
+ REG_LOAD_PTR
);
1512 /* config Mailbox */
1513 value
= ((atomic_read(&adapter
->tpd_ring
.next_to_use
)
1514 & MB_TPD_PROD_INDX_MASK
) << MB_TPD_PROD_INDX_SHIFT
) |
1515 ((atomic_read(&adapter
->rrd_ring
.next_to_clean
)
1516 & MB_RRD_CONS_INDX_MASK
) << MB_RRD_CONS_INDX_SHIFT
) |
1517 ((atomic_read(&adapter
->rfd_ring
.next_to_use
)
1518 & MB_RFD_PROD_INDX_MASK
) << MB_RFD_PROD_INDX_SHIFT
);
1519 iowrite32(value
, hw
->hw_addr
+ REG_MAILBOX
);
1521 /* config IPG/IFG */
1522 value
= (((u32
) hw
->ipgt
& MAC_IPG_IFG_IPGT_MASK
)
1523 << MAC_IPG_IFG_IPGT_SHIFT
) |
1524 (((u32
) hw
->min_ifg
& MAC_IPG_IFG_MIFG_MASK
)
1525 << MAC_IPG_IFG_MIFG_SHIFT
) |
1526 (((u32
) hw
->ipgr1
& MAC_IPG_IFG_IPGR1_MASK
)
1527 << MAC_IPG_IFG_IPGR1_SHIFT
) |
1528 (((u32
) hw
->ipgr2
& MAC_IPG_IFG_IPGR2_MASK
)
1529 << MAC_IPG_IFG_IPGR2_SHIFT
);
1530 iowrite32(value
, hw
->hw_addr
+ REG_MAC_IPG_IFG
);
1532 /* config Half-Duplex Control */
1533 value
= ((u32
) hw
->lcol
& MAC_HALF_DUPLX_CTRL_LCOL_MASK
) |
1534 (((u32
) hw
->max_retry
& MAC_HALF_DUPLX_CTRL_RETRY_MASK
)
1535 << MAC_HALF_DUPLX_CTRL_RETRY_SHIFT
) |
1536 MAC_HALF_DUPLX_CTRL_EXC_DEF_EN
|
1537 (0xa << MAC_HALF_DUPLX_CTRL_ABEBT_SHIFT
) |
1538 (((u32
) hw
->jam_ipg
& MAC_HALF_DUPLX_CTRL_JAMIPG_MASK
)
1539 << MAC_HALF_DUPLX_CTRL_JAMIPG_SHIFT
);
1540 iowrite32(value
, hw
->hw_addr
+ REG_MAC_HALF_DUPLX_CTRL
);
1542 /* set Interrupt Moderator Timer */
1543 iowrite16(adapter
->imt
, hw
->hw_addr
+ REG_IRQ_MODU_TIMER_INIT
);
1544 iowrite32(MASTER_CTRL_ITIMER_EN
, hw
->hw_addr
+ REG_MASTER_CTRL
);
1546 /* set Interrupt Clear Timer */
1547 iowrite16(adapter
->ict
, hw
->hw_addr
+ REG_CMBDISDMA_TIMER
);
1549 /* set max frame size hw will accept */
1550 iowrite32(hw
->max_frame_size
, hw
->hw_addr
+ REG_MTU
);
1552 /* jumbo size & rrd retirement timer */
1553 value
= (((u32
) hw
->rx_jumbo_th
& RXQ_JMBOSZ_TH_MASK
)
1554 << RXQ_JMBOSZ_TH_SHIFT
) |
1555 (((u32
) hw
->rx_jumbo_lkah
& RXQ_JMBO_LKAH_MASK
)
1556 << RXQ_JMBO_LKAH_SHIFT
) |
1557 (((u32
) hw
->rrd_ret_timer
& RXQ_RRD_TIMER_MASK
)
1558 << RXQ_RRD_TIMER_SHIFT
);
1559 iowrite32(value
, hw
->hw_addr
+ REG_RXQ_JMBOSZ_RRDTIM
);
1562 switch (hw
->dev_rev
) {
1567 set_flow_ctrl_old(adapter
);
1570 set_flow_ctrl_new(hw
);
1575 value
= (((u32
) hw
->tpd_burst
& TXQ_CTRL_TPD_BURST_NUM_MASK
)
1576 << TXQ_CTRL_TPD_BURST_NUM_SHIFT
) |
1577 (((u32
) hw
->txf_burst
& TXQ_CTRL_TXF_BURST_NUM_MASK
)
1578 << TXQ_CTRL_TXF_BURST_NUM_SHIFT
) |
1579 (((u32
) hw
->tpd_fetch_th
& TXQ_CTRL_TPD_FETCH_TH_MASK
)
1580 << TXQ_CTRL_TPD_FETCH_TH_SHIFT
) | TXQ_CTRL_ENH_MODE
|
1582 iowrite32(value
, hw
->hw_addr
+ REG_TXQ_CTRL
);
1584 /* min tpd fetch gap & tx jumbo packet size threshold for taskoffload */
1585 value
= (((u32
) hw
->tx_jumbo_task_th
& TX_JUMBO_TASK_TH_MASK
)
1586 << TX_JUMBO_TASK_TH_SHIFT
) |
1587 (((u32
) hw
->tpd_fetch_gap
& TX_TPD_MIN_IPG_MASK
)
1588 << TX_TPD_MIN_IPG_SHIFT
);
1589 iowrite32(value
, hw
->hw_addr
+ REG_TX_JUMBO_TASK_TH_TPD_IPG
);
1592 value
= (((u32
) hw
->rfd_burst
& RXQ_CTRL_RFD_BURST_NUM_MASK
)
1593 << RXQ_CTRL_RFD_BURST_NUM_SHIFT
) |
1594 (((u32
) hw
->rrd_burst
& RXQ_CTRL_RRD_BURST_THRESH_MASK
)
1595 << RXQ_CTRL_RRD_BURST_THRESH_SHIFT
) |
1596 (((u32
) hw
->rfd_fetch_gap
& RXQ_CTRL_RFD_PREF_MIN_IPG_MASK
)
1597 << RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT
) | RXQ_CTRL_CUT_THRU_EN
|
1599 iowrite32(value
, hw
->hw_addr
+ REG_RXQ_CTRL
);
1601 /* config DMA Engine */
1602 value
= ((((u32
) hw
->dmar_block
) & DMA_CTRL_DMAR_BURST_LEN_MASK
)
1603 << DMA_CTRL_DMAR_BURST_LEN_SHIFT
) |
1604 ((((u32
) hw
->dmaw_block
) & DMA_CTRL_DMAW_BURST_LEN_MASK
)
1605 << DMA_CTRL_DMAW_BURST_LEN_SHIFT
) | DMA_CTRL_DMAR_EN
|
1607 value
|= (u32
) hw
->dma_ord
;
1608 if (atl1_rcb_128
== hw
->rcb_value
)
1609 value
|= DMA_CTRL_RCB_VALUE
;
1610 iowrite32(value
, hw
->hw_addr
+ REG_DMA_CTRL
);
1612 /* config CMB / SMB */
1613 value
= (hw
->cmb_tpd
> adapter
->tpd_ring
.count
) ?
1614 hw
->cmb_tpd
: adapter
->tpd_ring
.count
;
1616 value
|= hw
->cmb_rrd
;
1617 iowrite32(value
, hw
->hw_addr
+ REG_CMB_WRITE_TH
);
1618 value
= hw
->cmb_rx_timer
| ((u32
) hw
->cmb_tx_timer
<< 16);
1619 iowrite32(value
, hw
->hw_addr
+ REG_CMB_WRITE_TIMER
);
1620 iowrite32(hw
->smb_timer
, hw
->hw_addr
+ REG_SMB_TIMER
);
1622 /* --- enable CMB / SMB */
1623 value
= CSMB_CTRL_CMB_EN
| CSMB_CTRL_SMB_EN
;
1624 iowrite32(value
, hw
->hw_addr
+ REG_CSMB_CTRL
);
1626 value
= ioread32(adapter
->hw
.hw_addr
+ REG_ISR
);
1627 if (unlikely((value
& ISR_PHY_LINKDOWN
) != 0))
1628 value
= 1; /* config failed */
1632 /* clear all interrupt status */
1633 iowrite32(0x3fffffff, adapter
->hw
.hw_addr
+ REG_ISR
);
1634 iowrite32(0, adapter
->hw
.hw_addr
+ REG_ISR
);
1639 * atl1_pcie_patch - Patch for PCIE module
1641 static void atl1_pcie_patch(struct atl1_adapter
*adapter
)
1645 /* much vendor magic here */
1647 iowrite32(value
, adapter
->hw
.hw_addr
+ 0x12FC);
1648 /* pcie flow control mode change */
1649 value
= ioread32(adapter
->hw
.hw_addr
+ 0x1008);
1651 iowrite32(value
, adapter
->hw
.hw_addr
+ 0x1008);
1655 * When ACPI resume on some VIA MotherBoard, the Interrupt Disable bit/0x400
1656 * on PCI Command register is disable.
1657 * The function enable this bit.
1658 * Brackett, 2006/03/15
1660 static void atl1_via_workaround(struct atl1_adapter
*adapter
)
1662 unsigned long value
;
1664 value
= ioread16(adapter
->hw
.hw_addr
+ PCI_COMMAND
);
1665 if (value
& PCI_COMMAND_INTX_DISABLE
)
1666 value
&= ~PCI_COMMAND_INTX_DISABLE
;
1667 iowrite32(value
, adapter
->hw
.hw_addr
+ PCI_COMMAND
);
1670 static void atl1_inc_smb(struct atl1_adapter
*adapter
)
1672 struct net_device
*netdev
= adapter
->netdev
;
1673 struct stats_msg_block
*smb
= adapter
->smb
.smb
;
1675 /* Fill out the OS statistics structure */
1676 adapter
->soft_stats
.rx_packets
+= smb
->rx_ok
;
1677 adapter
->soft_stats
.tx_packets
+= smb
->tx_ok
;
1678 adapter
->soft_stats
.rx_bytes
+= smb
->rx_byte_cnt
;
1679 adapter
->soft_stats
.tx_bytes
+= smb
->tx_byte_cnt
;
1680 adapter
->soft_stats
.multicast
+= smb
->rx_mcast
;
1681 adapter
->soft_stats
.collisions
+= (smb
->tx_1_col
+ smb
->tx_2_col
* 2 +
1682 smb
->tx_late_col
+ smb
->tx_abort_col
* adapter
->hw
.max_retry
);
1685 adapter
->soft_stats
.rx_errors
+= (smb
->rx_frag
+ smb
->rx_fcs_err
+
1686 smb
->rx_len_err
+ smb
->rx_sz_ov
+ smb
->rx_rxf_ov
+
1687 smb
->rx_rrd_ov
+ smb
->rx_align_err
);
1688 adapter
->soft_stats
.rx_fifo_errors
+= smb
->rx_rxf_ov
;
1689 adapter
->soft_stats
.rx_length_errors
+= smb
->rx_len_err
;
1690 adapter
->soft_stats
.rx_crc_errors
+= smb
->rx_fcs_err
;
1691 adapter
->soft_stats
.rx_frame_errors
+= smb
->rx_align_err
;
1692 adapter
->soft_stats
.rx_missed_errors
+= (smb
->rx_rrd_ov
+
1695 adapter
->soft_stats
.rx_pause
+= smb
->rx_pause
;
1696 adapter
->soft_stats
.rx_rrd_ov
+= smb
->rx_rrd_ov
;
1697 adapter
->soft_stats
.rx_trunc
+= smb
->rx_sz_ov
;
1700 adapter
->soft_stats
.tx_errors
+= (smb
->tx_late_col
+
1701 smb
->tx_abort_col
+ smb
->tx_underrun
+ smb
->tx_trunc
);
1702 adapter
->soft_stats
.tx_fifo_errors
+= smb
->tx_underrun
;
1703 adapter
->soft_stats
.tx_aborted_errors
+= smb
->tx_abort_col
;
1704 adapter
->soft_stats
.tx_window_errors
+= smb
->tx_late_col
;
1706 adapter
->soft_stats
.excecol
+= smb
->tx_abort_col
;
1707 adapter
->soft_stats
.deffer
+= smb
->tx_defer
;
1708 adapter
->soft_stats
.scc
+= smb
->tx_1_col
;
1709 adapter
->soft_stats
.mcc
+= smb
->tx_2_col
;
1710 adapter
->soft_stats
.latecol
+= smb
->tx_late_col
;
1711 adapter
->soft_stats
.tx_underun
+= smb
->tx_underrun
;
1712 adapter
->soft_stats
.tx_trunc
+= smb
->tx_trunc
;
1713 adapter
->soft_stats
.tx_pause
+= smb
->tx_pause
;
1715 netdev
->stats
.rx_packets
= adapter
->soft_stats
.rx_packets
;
1716 netdev
->stats
.tx_packets
= adapter
->soft_stats
.tx_packets
;
1717 netdev
->stats
.rx_bytes
= adapter
->soft_stats
.rx_bytes
;
1718 netdev
->stats
.tx_bytes
= adapter
->soft_stats
.tx_bytes
;
1719 netdev
->stats
.multicast
= adapter
->soft_stats
.multicast
;
1720 netdev
->stats
.collisions
= adapter
->soft_stats
.collisions
;
1721 netdev
->stats
.rx_errors
= adapter
->soft_stats
.rx_errors
;
1722 netdev
->stats
.rx_over_errors
=
1723 adapter
->soft_stats
.rx_missed_errors
;
1724 netdev
->stats
.rx_length_errors
=
1725 adapter
->soft_stats
.rx_length_errors
;
1726 netdev
->stats
.rx_crc_errors
= adapter
->soft_stats
.rx_crc_errors
;
1727 netdev
->stats
.rx_frame_errors
=
1728 adapter
->soft_stats
.rx_frame_errors
;
1729 netdev
->stats
.rx_fifo_errors
= adapter
->soft_stats
.rx_fifo_errors
;
1730 netdev
->stats
.rx_missed_errors
=
1731 adapter
->soft_stats
.rx_missed_errors
;
1732 netdev
->stats
.tx_errors
= adapter
->soft_stats
.tx_errors
;
1733 netdev
->stats
.tx_fifo_errors
= adapter
->soft_stats
.tx_fifo_errors
;
1734 netdev
->stats
.tx_aborted_errors
=
1735 adapter
->soft_stats
.tx_aborted_errors
;
1736 netdev
->stats
.tx_window_errors
=
1737 adapter
->soft_stats
.tx_window_errors
;
1738 netdev
->stats
.tx_carrier_errors
=
1739 adapter
->soft_stats
.tx_carrier_errors
;
1742 static void atl1_update_mailbox(struct atl1_adapter
*adapter
)
1744 unsigned long flags
;
1745 u32 tpd_next_to_use
;
1746 u32 rfd_next_to_use
;
1747 u32 rrd_next_to_clean
;
1750 spin_lock_irqsave(&adapter
->mb_lock
, flags
);
1752 tpd_next_to_use
= atomic_read(&adapter
->tpd_ring
.next_to_use
);
1753 rfd_next_to_use
= atomic_read(&adapter
->rfd_ring
.next_to_use
);
1754 rrd_next_to_clean
= atomic_read(&adapter
->rrd_ring
.next_to_clean
);
1756 value
= ((rfd_next_to_use
& MB_RFD_PROD_INDX_MASK
) <<
1757 MB_RFD_PROD_INDX_SHIFT
) |
1758 ((rrd_next_to_clean
& MB_RRD_CONS_INDX_MASK
) <<
1759 MB_RRD_CONS_INDX_SHIFT
) |
1760 ((tpd_next_to_use
& MB_TPD_PROD_INDX_MASK
) <<
1761 MB_TPD_PROD_INDX_SHIFT
);
1762 iowrite32(value
, adapter
->hw
.hw_addr
+ REG_MAILBOX
);
1764 spin_unlock_irqrestore(&adapter
->mb_lock
, flags
);
1767 static void atl1_clean_alloc_flag(struct atl1_adapter
*adapter
,
1768 struct rx_return_desc
*rrd
, u16 offset
)
1770 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1772 while (rfd_ring
->next_to_clean
!= (rrd
->buf_indx
+ offset
)) {
1773 rfd_ring
->buffer_info
[rfd_ring
->next_to_clean
].alloced
= 0;
1774 if (++rfd_ring
->next_to_clean
== rfd_ring
->count
) {
1775 rfd_ring
->next_to_clean
= 0;
1780 static void atl1_update_rfd_index(struct atl1_adapter
*adapter
,
1781 struct rx_return_desc
*rrd
)
1785 num_buf
= (rrd
->xsz
.xsum_sz
.pkt_size
+ adapter
->rx_buffer_len
- 1) /
1786 adapter
->rx_buffer_len
;
1787 if (rrd
->num_buf
== num_buf
)
1788 /* clean alloc flag for bad rrd */
1789 atl1_clean_alloc_flag(adapter
, rrd
, num_buf
);
1792 static void atl1_rx_checksum(struct atl1_adapter
*adapter
,
1793 struct rx_return_desc
*rrd
, struct sk_buff
*skb
)
1795 struct pci_dev
*pdev
= adapter
->pdev
;
1798 * The L1 hardware contains a bug that erroneously sets the
1799 * PACKET_FLAG_ERR and ERR_FLAG_L4_CHKSUM bits whenever a
1800 * fragmented IP packet is received, even though the packet
1801 * is perfectly valid and its checksum is correct. There's
1802 * no way to distinguish between one of these good packets
1803 * and a packet that actually contains a TCP/UDP checksum
1804 * error, so all we can do is allow it to be handed up to
1805 * the higher layers and let it be sorted out there.
1808 skb
->ip_summed
= CHECKSUM_NONE
;
1810 if (unlikely(rrd
->pkt_flg
& PACKET_FLAG_ERR
)) {
1811 if (rrd
->err_flg
& (ERR_FLAG_CRC
| ERR_FLAG_TRUNC
|
1812 ERR_FLAG_CODE
| ERR_FLAG_OV
)) {
1813 adapter
->hw_csum_err
++;
1814 if (netif_msg_rx_err(adapter
))
1815 dev_printk(KERN_DEBUG
, &pdev
->dev
,
1816 "rx checksum error\n");
1822 if (!(rrd
->pkt_flg
& PACKET_FLAG_IPV4
))
1823 /* checksum is invalid, but it's not an IPv4 pkt, so ok */
1827 if (likely(!(rrd
->err_flg
&
1828 (ERR_FLAG_IP_CHKSUM
| ERR_FLAG_L4_CHKSUM
)))) {
1829 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1830 adapter
->hw_csum_good
++;
1838 * atl1_alloc_rx_buffers - Replace used receive buffers
1839 * @adapter: address of board private structure
1841 static u16
atl1_alloc_rx_buffers(struct atl1_adapter
*adapter
)
1843 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1844 struct pci_dev
*pdev
= adapter
->pdev
;
1846 unsigned long offset
;
1847 struct atl1_buffer
*buffer_info
, *next_info
;
1848 struct sk_buff
*skb
;
1850 u16 rfd_next_to_use
, next_next
;
1851 struct rx_free_desc
*rfd_desc
;
1853 next_next
= rfd_next_to_use
= atomic_read(&rfd_ring
->next_to_use
);
1854 if (++next_next
== rfd_ring
->count
)
1856 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1857 next_info
= &rfd_ring
->buffer_info
[next_next
];
1859 while (!buffer_info
->alloced
&& !next_info
->alloced
) {
1860 if (buffer_info
->skb
) {
1861 buffer_info
->alloced
= 1;
1865 rfd_desc
= ATL1_RFD_DESC(rfd_ring
, rfd_next_to_use
);
1867 skb
= netdev_alloc_skb(adapter
->netdev
,
1868 adapter
->rx_buffer_len
+ NET_IP_ALIGN
);
1869 if (unlikely(!skb
)) {
1870 /* Better luck next round */
1871 adapter
->netdev
->stats
.rx_dropped
++;
1876 * Make buffer alignment 2 beyond a 16 byte boundary
1877 * this will result in a 16 byte aligned IP header after
1878 * the 14 byte MAC header is removed
1880 skb_reserve(skb
, NET_IP_ALIGN
);
1882 buffer_info
->alloced
= 1;
1883 buffer_info
->skb
= skb
;
1884 buffer_info
->length
= (u16
) adapter
->rx_buffer_len
;
1885 page
= virt_to_page(skb
->data
);
1886 offset
= (unsigned long)skb
->data
& ~PAGE_MASK
;
1887 buffer_info
->dma
= pci_map_page(pdev
, page
, offset
,
1888 adapter
->rx_buffer_len
,
1889 PCI_DMA_FROMDEVICE
);
1890 rfd_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
1891 rfd_desc
->buf_len
= cpu_to_le16(adapter
->rx_buffer_len
);
1892 rfd_desc
->coalese
= 0;
1895 rfd_next_to_use
= next_next
;
1896 if (unlikely(++next_next
== rfd_ring
->count
))
1899 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1900 next_info
= &rfd_ring
->buffer_info
[next_next
];
1906 * Force memory writes to complete before letting h/w
1907 * know there are new descriptors to fetch. (Only
1908 * applicable for weak-ordered memory model archs,
1912 atomic_set(&rfd_ring
->next_to_use
, (int)rfd_next_to_use
);
1917 static void atl1_intr_rx(struct atl1_adapter
*adapter
)
1921 u16 rrd_next_to_clean
;
1923 struct atl1_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1924 struct atl1_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1925 struct atl1_buffer
*buffer_info
;
1926 struct rx_return_desc
*rrd
;
1927 struct sk_buff
*skb
;
1931 rrd_next_to_clean
= atomic_read(&rrd_ring
->next_to_clean
);
1934 rrd
= ATL1_RRD_DESC(rrd_ring
, rrd_next_to_clean
);
1936 if (likely(rrd
->xsz
.valid
)) { /* packet valid */
1938 /* check rrd status */
1939 if (likely(rrd
->num_buf
== 1))
1941 else if (netif_msg_rx_err(adapter
)) {
1942 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1943 "unexpected RRD buffer count\n");
1944 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1945 "rx_buf_len = %d\n",
1946 adapter
->rx_buffer_len
);
1947 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1948 "RRD num_buf = %d\n",
1950 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1951 "RRD pkt_len = %d\n",
1952 rrd
->xsz
.xsum_sz
.pkt_size
);
1953 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1954 "RRD pkt_flg = 0x%08X\n",
1956 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1957 "RRD err_flg = 0x%08X\n",
1959 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1960 "RRD vlan_tag = 0x%08X\n",
1964 /* rrd seems to be bad */
1965 if (unlikely(i
-- > 0)) {
1966 /* rrd may not be DMAed completely */
1971 if (netif_msg_rx_err(adapter
))
1972 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
1974 /* see if update RFD index */
1975 if (rrd
->num_buf
> 1)
1976 atl1_update_rfd_index(adapter
, rrd
);
1980 if (++rrd_next_to_clean
== rrd_ring
->count
)
1981 rrd_next_to_clean
= 0;
1984 } else { /* current rrd still not be updated */
1989 /* clean alloc flag for bad rrd */
1990 atl1_clean_alloc_flag(adapter
, rrd
, 0);
1992 buffer_info
= &rfd_ring
->buffer_info
[rrd
->buf_indx
];
1993 if (++rfd_ring
->next_to_clean
== rfd_ring
->count
)
1994 rfd_ring
->next_to_clean
= 0;
1996 /* update rrd next to clean */
1997 if (++rrd_next_to_clean
== rrd_ring
->count
)
1998 rrd_next_to_clean
= 0;
2001 if (unlikely(rrd
->pkt_flg
& PACKET_FLAG_ERR
)) {
2002 if (!(rrd
->err_flg
&
2003 (ERR_FLAG_IP_CHKSUM
| ERR_FLAG_L4_CHKSUM
2005 /* packet error, don't need upstream */
2006 buffer_info
->alloced
= 0;
2013 pci_unmap_page(adapter
->pdev
, buffer_info
->dma
,
2014 buffer_info
->length
, PCI_DMA_FROMDEVICE
);
2015 buffer_info
->dma
= 0;
2016 skb
= buffer_info
->skb
;
2017 length
= le16_to_cpu(rrd
->xsz
.xsum_sz
.pkt_size
);
2019 skb_put(skb
, length
- ETH_FCS_LEN
);
2021 /* Receive Checksum Offload */
2022 atl1_rx_checksum(adapter
, rrd
, skb
);
2023 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
2025 if (adapter
->vlgrp
&& (rrd
->pkt_flg
& PACKET_FLAG_VLAN_INS
)) {
2026 u16 vlan_tag
= (rrd
->vlan_tag
>> 4) |
2027 ((rrd
->vlan_tag
& 7) << 13) |
2028 ((rrd
->vlan_tag
& 8) << 9);
2029 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, vlan_tag
);
2033 /* let protocol layer free skb */
2034 buffer_info
->skb
= NULL
;
2035 buffer_info
->alloced
= 0;
2039 atomic_set(&rrd_ring
->next_to_clean
, rrd_next_to_clean
);
2041 atl1_alloc_rx_buffers(adapter
);
2043 /* update mailbox ? */
2045 u32 tpd_next_to_use
;
2046 u32 rfd_next_to_use
;
2048 spin_lock(&adapter
->mb_lock
);
2050 tpd_next_to_use
= atomic_read(&adapter
->tpd_ring
.next_to_use
);
2052 atomic_read(&adapter
->rfd_ring
.next_to_use
);
2054 atomic_read(&adapter
->rrd_ring
.next_to_clean
);
2055 value
= ((rfd_next_to_use
& MB_RFD_PROD_INDX_MASK
) <<
2056 MB_RFD_PROD_INDX_SHIFT
) |
2057 ((rrd_next_to_clean
& MB_RRD_CONS_INDX_MASK
) <<
2058 MB_RRD_CONS_INDX_SHIFT
) |
2059 ((tpd_next_to_use
& MB_TPD_PROD_INDX_MASK
) <<
2060 MB_TPD_PROD_INDX_SHIFT
);
2061 iowrite32(value
, adapter
->hw
.hw_addr
+ REG_MAILBOX
);
2062 spin_unlock(&adapter
->mb_lock
);
2066 static void atl1_intr_tx(struct atl1_adapter
*adapter
)
2068 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
2069 struct atl1_buffer
*buffer_info
;
2070 u16 sw_tpd_next_to_clean
;
2071 u16 cmb_tpd_next_to_clean
;
2073 sw_tpd_next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
2074 cmb_tpd_next_to_clean
= le16_to_cpu(adapter
->cmb
.cmb
->tpd_cons_idx
);
2076 while (cmb_tpd_next_to_clean
!= sw_tpd_next_to_clean
) {
2077 struct tx_packet_desc
*tpd
;
2079 tpd
= ATL1_TPD_DESC(tpd_ring
, sw_tpd_next_to_clean
);
2080 buffer_info
= &tpd_ring
->buffer_info
[sw_tpd_next_to_clean
];
2081 if (buffer_info
->dma
) {
2082 pci_unmap_page(adapter
->pdev
, buffer_info
->dma
,
2083 buffer_info
->length
, PCI_DMA_TODEVICE
);
2084 buffer_info
->dma
= 0;
2087 if (buffer_info
->skb
) {
2088 dev_kfree_skb_irq(buffer_info
->skb
);
2089 buffer_info
->skb
= NULL
;
2092 if (++sw_tpd_next_to_clean
== tpd_ring
->count
)
2093 sw_tpd_next_to_clean
= 0;
2095 atomic_set(&tpd_ring
->next_to_clean
, sw_tpd_next_to_clean
);
2097 if (netif_queue_stopped(adapter
->netdev
)
2098 && netif_carrier_ok(adapter
->netdev
))
2099 netif_wake_queue(adapter
->netdev
);
2102 static u16
atl1_tpd_avail(struct atl1_tpd_ring
*tpd_ring
)
2104 u16 next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
2105 u16 next_to_use
= atomic_read(&tpd_ring
->next_to_use
);
2106 return ((next_to_clean
> next_to_use
) ?
2107 next_to_clean
- next_to_use
- 1 :
2108 tpd_ring
->count
+ next_to_clean
- next_to_use
- 1);
2111 static int atl1_tso(struct atl1_adapter
*adapter
, struct sk_buff
*skb
,
2112 struct tx_packet_desc
*ptpd
)
2118 if (skb_shinfo(skb
)->gso_size
) {
2119 if (skb_header_cloned(skb
)) {
2120 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2125 if (skb
->protocol
== htons(ETH_P_IP
)) {
2126 struct iphdr
*iph
= ip_hdr(skb
);
2128 real_len
= (((unsigned char *)iph
- skb
->data
) +
2129 ntohs(iph
->tot_len
));
2130 if (real_len
< skb
->len
)
2131 pskb_trim(skb
, real_len
);
2132 hdr_len
= (skb_transport_offset(skb
) + tcp_hdrlen(skb
));
2133 if (skb
->len
== hdr_len
) {
2135 tcp_hdr(skb
)->check
=
2136 ~csum_tcpudp_magic(iph
->saddr
,
2137 iph
->daddr
, tcp_hdrlen(skb
),
2139 ptpd
->word3
|= (iph
->ihl
& TPD_IPHL_MASK
) <<
2141 ptpd
->word3
|= ((tcp_hdrlen(skb
) >> 2) &
2142 TPD_TCPHDRLEN_MASK
) <<
2143 TPD_TCPHDRLEN_SHIFT
;
2144 ptpd
->word3
|= 1 << TPD_IP_CSUM_SHIFT
;
2145 ptpd
->word3
|= 1 << TPD_TCP_CSUM_SHIFT
;
2150 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2151 iph
->daddr
, 0, IPPROTO_TCP
, 0);
2152 ip_off
= (unsigned char *)iph
-
2153 (unsigned char *) skb_network_header(skb
);
2154 if (ip_off
== 8) /* 802.3-SNAP frame */
2155 ptpd
->word3
|= 1 << TPD_ETHTYPE_SHIFT
;
2156 else if (ip_off
!= 0)
2159 ptpd
->word3
|= (iph
->ihl
& TPD_IPHL_MASK
) <<
2161 ptpd
->word3
|= ((tcp_hdrlen(skb
) >> 2) &
2162 TPD_TCPHDRLEN_MASK
) << TPD_TCPHDRLEN_SHIFT
;
2163 ptpd
->word3
|= (skb_shinfo(skb
)->gso_size
&
2164 TPD_MSS_MASK
) << TPD_MSS_SHIFT
;
2165 ptpd
->word3
|= 1 << TPD_SEGMENT_EN_SHIFT
;
2172 static int atl1_tx_csum(struct atl1_adapter
*adapter
, struct sk_buff
*skb
,
2173 struct tx_packet_desc
*ptpd
)
2177 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
2178 css
= (u8
) (skb
->csum_start
- skb_headroom(skb
));
2179 cso
= css
+ (u8
) skb
->csum_offset
;
2180 if (unlikely(css
& 0x1)) {
2181 /* L1 hardware requires an even number here */
2182 if (netif_msg_tx_err(adapter
))
2183 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
2184 "payload offset not an even number\n");
2187 ptpd
->word3
|= (css
& TPD_PLOADOFFSET_MASK
) <<
2188 TPD_PLOADOFFSET_SHIFT
;
2189 ptpd
->word3
|= (cso
& TPD_CCSUMOFFSET_MASK
) <<
2190 TPD_CCSUMOFFSET_SHIFT
;
2191 ptpd
->word3
|= 1 << TPD_CUST_CSUM_EN_SHIFT
;
2197 static void atl1_tx_map(struct atl1_adapter
*adapter
, struct sk_buff
*skb
,
2198 struct tx_packet_desc
*ptpd
)
2200 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
2201 struct atl1_buffer
*buffer_info
;
2202 u16 buf_len
= skb
->len
;
2204 unsigned long offset
;
2205 unsigned int nr_frags
;
2212 buf_len
-= skb
->data_len
;
2213 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2214 next_to_use
= atomic_read(&tpd_ring
->next_to_use
);
2215 buffer_info
= &tpd_ring
->buffer_info
[next_to_use
];
2216 BUG_ON(buffer_info
->skb
);
2217 /* put skb in last TPD */
2218 buffer_info
->skb
= NULL
;
2220 retval
= (ptpd
->word3
>> TPD_SEGMENT_EN_SHIFT
) & TPD_SEGMENT_EN_MASK
;
2223 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2224 buffer_info
->length
= hdr_len
;
2225 page
= virt_to_page(skb
->data
);
2226 offset
= (unsigned long)skb
->data
& ~PAGE_MASK
;
2227 buffer_info
->dma
= pci_map_page(adapter
->pdev
, page
,
2231 if (++next_to_use
== tpd_ring
->count
)
2234 if (buf_len
> hdr_len
) {
2237 data_len
= buf_len
- hdr_len
;
2238 nseg
= (data_len
+ ATL1_MAX_TX_BUF_LEN
- 1) /
2239 ATL1_MAX_TX_BUF_LEN
;
2240 for (i
= 0; i
< nseg
; i
++) {
2242 &tpd_ring
->buffer_info
[next_to_use
];
2243 buffer_info
->skb
= NULL
;
2244 buffer_info
->length
=
2245 (ATL1_MAX_TX_BUF_LEN
>=
2246 data_len
) ? ATL1_MAX_TX_BUF_LEN
: data_len
;
2247 data_len
-= buffer_info
->length
;
2248 page
= virt_to_page(skb
->data
+
2249 (hdr_len
+ i
* ATL1_MAX_TX_BUF_LEN
));
2250 offset
= (unsigned long)(skb
->data
+
2251 (hdr_len
+ i
* ATL1_MAX_TX_BUF_LEN
)) &
2253 buffer_info
->dma
= pci_map_page(adapter
->pdev
,
2254 page
, offset
, buffer_info
->length
,
2256 if (++next_to_use
== tpd_ring
->count
)
2262 buffer_info
->length
= buf_len
;
2263 page
= virt_to_page(skb
->data
);
2264 offset
= (unsigned long)skb
->data
& ~PAGE_MASK
;
2265 buffer_info
->dma
= pci_map_page(adapter
->pdev
, page
,
2266 offset
, buf_len
, PCI_DMA_TODEVICE
);
2267 if (++next_to_use
== tpd_ring
->count
)
2271 for (f
= 0; f
< nr_frags
; f
++) {
2272 struct skb_frag_struct
*frag
;
2275 frag
= &skb_shinfo(skb
)->frags
[f
];
2276 buf_len
= frag
->size
;
2278 nseg
= (buf_len
+ ATL1_MAX_TX_BUF_LEN
- 1) /
2279 ATL1_MAX_TX_BUF_LEN
;
2280 for (i
= 0; i
< nseg
; i
++) {
2281 buffer_info
= &tpd_ring
->buffer_info
[next_to_use
];
2282 BUG_ON(buffer_info
->skb
);
2284 buffer_info
->skb
= NULL
;
2285 buffer_info
->length
= (buf_len
> ATL1_MAX_TX_BUF_LEN
) ?
2286 ATL1_MAX_TX_BUF_LEN
: buf_len
;
2287 buf_len
-= buffer_info
->length
;
2288 buffer_info
->dma
= pci_map_page(adapter
->pdev
,
2290 frag
->page_offset
+ (i
* ATL1_MAX_TX_BUF_LEN
),
2291 buffer_info
->length
, PCI_DMA_TODEVICE
);
2293 if (++next_to_use
== tpd_ring
->count
)
2298 /* last tpd's buffer-info */
2299 buffer_info
->skb
= skb
;
2302 static void atl1_tx_queue(struct atl1_adapter
*adapter
, u16 count
,
2303 struct tx_packet_desc
*ptpd
)
2305 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
2306 struct atl1_buffer
*buffer_info
;
2307 struct tx_packet_desc
*tpd
;
2310 u16 next_to_use
= (u16
) atomic_read(&tpd_ring
->next_to_use
);
2312 for (j
= 0; j
< count
; j
++) {
2313 buffer_info
= &tpd_ring
->buffer_info
[next_to_use
];
2314 tpd
= ATL1_TPD_DESC(&adapter
->tpd_ring
, next_to_use
);
2316 memcpy(tpd
, ptpd
, sizeof(struct tx_packet_desc
));
2317 tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2318 tpd
->word2
&= ~(TPD_BUFLEN_MASK
<< TPD_BUFLEN_SHIFT
);
2319 tpd
->word2
|= (cpu_to_le16(buffer_info
->length
) &
2320 TPD_BUFLEN_MASK
) << TPD_BUFLEN_SHIFT
;
2323 * if this is the first packet in a TSO chain, set
2324 * TPD_HDRFLAG, otherwise, clear it.
2326 val
= (tpd
->word3
>> TPD_SEGMENT_EN_SHIFT
) &
2327 TPD_SEGMENT_EN_MASK
;
2330 tpd
->word3
|= 1 << TPD_HDRFLAG_SHIFT
;
2332 tpd
->word3
&= ~(1 << TPD_HDRFLAG_SHIFT
);
2335 if (j
== (count
- 1))
2336 tpd
->word3
|= 1 << TPD_EOP_SHIFT
;
2338 if (++next_to_use
== tpd_ring
->count
)
2342 * Force memory writes to complete before letting h/w
2343 * know there are new descriptors to fetch. (Only
2344 * applicable for weak-ordered memory model archs,
2349 atomic_set(&tpd_ring
->next_to_use
, next_to_use
);
2352 static netdev_tx_t
atl1_xmit_frame(struct sk_buff
*skb
,
2353 struct net_device
*netdev
)
2355 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2356 struct atl1_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
;
2361 struct tx_packet_desc
*ptpd
;
2364 unsigned int nr_frags
= 0;
2365 unsigned int mss
= 0;
2367 unsigned int proto_hdr_len
;
2369 len
-= skb
->data_len
;
2371 if (unlikely(skb
->len
<= 0)) {
2372 dev_kfree_skb_any(skb
);
2373 return NETDEV_TX_OK
;
2376 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2377 for (f
= 0; f
< nr_frags
; f
++) {
2378 frag_size
= skb_shinfo(skb
)->frags
[f
].size
;
2380 count
+= (frag_size
+ ATL1_MAX_TX_BUF_LEN
- 1) /
2381 ATL1_MAX_TX_BUF_LEN
;
2384 mss
= skb_shinfo(skb
)->gso_size
;
2386 if (skb
->protocol
== htons(ETH_P_IP
)) {
2387 proto_hdr_len
= (skb_transport_offset(skb
) +
2389 if (unlikely(proto_hdr_len
> len
)) {
2390 dev_kfree_skb_any(skb
);
2391 return NETDEV_TX_OK
;
2393 /* need additional TPD ? */
2394 if (proto_hdr_len
!= len
)
2395 count
+= (len
- proto_hdr_len
+
2396 ATL1_MAX_TX_BUF_LEN
- 1) /
2397 ATL1_MAX_TX_BUF_LEN
;
2401 if (atl1_tpd_avail(&adapter
->tpd_ring
) < count
) {
2402 /* not enough descriptors */
2403 netif_stop_queue(netdev
);
2404 if (netif_msg_tx_queued(adapter
))
2405 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
2407 return NETDEV_TX_BUSY
;
2410 ptpd
= ATL1_TPD_DESC(tpd_ring
,
2411 (u16
) atomic_read(&tpd_ring
->next_to_use
));
2412 memset(ptpd
, 0, sizeof(struct tx_packet_desc
));
2414 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
2415 vlan_tag
= vlan_tx_tag_get(skb
);
2416 vlan_tag
= (vlan_tag
<< 4) | (vlan_tag
>> 13) |
2417 ((vlan_tag
>> 9) & 0x8);
2418 ptpd
->word3
|= 1 << TPD_INS_VL_TAG_SHIFT
;
2419 ptpd
->word2
|= (vlan_tag
& TPD_VLANTAG_MASK
) <<
2423 tso
= atl1_tso(adapter
, skb
, ptpd
);
2425 dev_kfree_skb_any(skb
);
2426 return NETDEV_TX_OK
;
2430 ret_val
= atl1_tx_csum(adapter
, skb
, ptpd
);
2432 dev_kfree_skb_any(skb
);
2433 return NETDEV_TX_OK
;
2437 atl1_tx_map(adapter
, skb
, ptpd
);
2438 atl1_tx_queue(adapter
, count
, ptpd
);
2439 atl1_update_mailbox(adapter
);
2441 return NETDEV_TX_OK
;
2445 * atl1_intr - Interrupt Handler
2446 * @irq: interrupt number
2447 * @data: pointer to a network interface device structure
2448 * @pt_regs: CPU registers structure
2450 static irqreturn_t
atl1_intr(int irq
, void *data
)
2452 struct atl1_adapter
*adapter
= netdev_priv(data
);
2456 status
= adapter
->cmb
.cmb
->int_stats
;
2461 /* clear CMB interrupt status at once */
2462 adapter
->cmb
.cmb
->int_stats
= 0;
2464 if (status
& ISR_GPHY
) /* clear phy status */
2465 atlx_clear_phy_int(adapter
);
2467 /* clear ISR status, and Enable CMB DMA/Disable Interrupt */
2468 iowrite32(status
| ISR_DIS_INT
, adapter
->hw
.hw_addr
+ REG_ISR
);
2470 /* check if SMB intr */
2471 if (status
& ISR_SMB
)
2472 atl1_inc_smb(adapter
);
2474 /* check if PCIE PHY Link down */
2475 if (status
& ISR_PHY_LINKDOWN
) {
2476 if (netif_msg_intr(adapter
))
2477 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
2478 "pcie phy link down %x\n", status
);
2479 if (netif_running(adapter
->netdev
)) { /* reset MAC */
2480 iowrite32(0, adapter
->hw
.hw_addr
+ REG_IMR
);
2481 schedule_work(&adapter
->pcie_dma_to_rst_task
);
2486 /* check if DMA read/write error ? */
2487 if (status
& (ISR_DMAR_TO_RST
| ISR_DMAW_TO_RST
)) {
2488 if (netif_msg_intr(adapter
))
2489 dev_printk(KERN_DEBUG
, &adapter
->pdev
->dev
,
2490 "pcie DMA r/w error (status = 0x%x)\n",
2492 iowrite32(0, adapter
->hw
.hw_addr
+ REG_IMR
);
2493 schedule_work(&adapter
->pcie_dma_to_rst_task
);
2498 if (status
& ISR_GPHY
) {
2499 adapter
->soft_stats
.tx_carrier_errors
++;
2500 atl1_check_for_link(adapter
);
2503 /* transmit event */
2504 if (status
& ISR_CMB_TX
)
2505 atl1_intr_tx(adapter
);
2508 if (unlikely(status
& (ISR_RXF_OV
| ISR_RFD_UNRUN
|
2509 ISR_RRD_OV
| ISR_HOST_RFD_UNRUN
|
2510 ISR_HOST_RRD_OV
| ISR_CMB_RX
))) {
2511 if (status
& (ISR_RXF_OV
| ISR_RFD_UNRUN
|
2512 ISR_RRD_OV
| ISR_HOST_RFD_UNRUN
|
2514 if (netif_msg_intr(adapter
))
2515 dev_printk(KERN_DEBUG
,
2516 &adapter
->pdev
->dev
,
2517 "rx exception, ISR = 0x%x\n",
2519 atl1_intr_rx(adapter
);
2525 } while ((status
= adapter
->cmb
.cmb
->int_stats
));
2527 /* re-enable Interrupt */
2528 iowrite32(ISR_DIS_SMB
| ISR_DIS_DMA
, adapter
->hw
.hw_addr
+ REG_ISR
);
2534 * atl1_phy_config - Timer Call-back
2535 * @data: pointer to netdev cast into an unsigned long
2537 static void atl1_phy_config(unsigned long data
)
2539 struct atl1_adapter
*adapter
= (struct atl1_adapter
*)data
;
2540 struct atl1_hw
*hw
= &adapter
->hw
;
2541 unsigned long flags
;
2543 spin_lock_irqsave(&adapter
->lock
, flags
);
2544 adapter
->phy_timer_pending
= false;
2545 atl1_write_phy_reg(hw
, MII_ADVERTISE
, hw
->mii_autoneg_adv_reg
);
2546 atl1_write_phy_reg(hw
, MII_ATLX_CR
, hw
->mii_1000t_ctrl_reg
);
2547 atl1_write_phy_reg(hw
, MII_BMCR
, MII_CR_RESET
| MII_CR_AUTO_NEG_EN
);
2548 spin_unlock_irqrestore(&adapter
->lock
, flags
);
2552 * Orphaned vendor comment left intact here:
2554 * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT
2555 * will assert. We do soft reset <0x1400=1> according
2556 * with the SPEC. BUT, it seemes that PCIE or DMA
2557 * state-machine will not be reset. DMAR_TO_INT will
2558 * assert again and again.
2562 static int atl1_reset(struct atl1_adapter
*adapter
)
2565 ret
= atl1_reset_hw(&adapter
->hw
);
2568 return atl1_init_hw(&adapter
->hw
);
2571 static s32
atl1_up(struct atl1_adapter
*adapter
)
2573 struct net_device
*netdev
= adapter
->netdev
;
2575 int irq_flags
= IRQF_SAMPLE_RANDOM
;
2577 /* hardware has been reset, we need to reload some things */
2578 atlx_set_multi(netdev
);
2579 atl1_init_ring_ptrs(adapter
);
2580 atlx_restore_vlan(adapter
);
2581 err
= atl1_alloc_rx_buffers(adapter
);
2583 /* no RX BUFFER allocated */
2586 if (unlikely(atl1_configure(adapter
))) {
2591 err
= pci_enable_msi(adapter
->pdev
);
2593 if (netif_msg_ifup(adapter
))
2594 dev_info(&adapter
->pdev
->dev
,
2595 "Unable to enable MSI: %d\n", err
);
2596 irq_flags
|= IRQF_SHARED
;
2599 err
= request_irq(adapter
->pdev
->irq
, &atl1_intr
, irq_flags
,
2600 netdev
->name
, netdev
);
2604 atlx_irq_enable(adapter
);
2605 atl1_check_link(adapter
);
2606 netif_start_queue(netdev
);
2610 pci_disable_msi(adapter
->pdev
);
2611 /* free rx_buffers */
2612 atl1_clean_rx_ring(adapter
);
2616 static void atl1_down(struct atl1_adapter
*adapter
)
2618 struct net_device
*netdev
= adapter
->netdev
;
2620 netif_stop_queue(netdev
);
2621 del_timer_sync(&adapter
->phy_config_timer
);
2622 adapter
->phy_timer_pending
= false;
2624 atlx_irq_disable(adapter
);
2625 free_irq(adapter
->pdev
->irq
, netdev
);
2626 pci_disable_msi(adapter
->pdev
);
2627 atl1_reset_hw(&adapter
->hw
);
2628 adapter
->cmb
.cmb
->int_stats
= 0;
2630 adapter
->link_speed
= SPEED_0
;
2631 adapter
->link_duplex
= -1;
2632 netif_carrier_off(netdev
);
2634 atl1_clean_tx_ring(adapter
);
2635 atl1_clean_rx_ring(adapter
);
2638 static void atl1_tx_timeout_task(struct work_struct
*work
)
2640 struct atl1_adapter
*adapter
=
2641 container_of(work
, struct atl1_adapter
, tx_timeout_task
);
2642 struct net_device
*netdev
= adapter
->netdev
;
2644 netif_device_detach(netdev
);
2647 netif_device_attach(netdev
);
2651 * atl1_change_mtu - Change the Maximum Transfer Unit
2652 * @netdev: network interface device structure
2653 * @new_mtu: new value for maximum frame size
2655 * Returns 0 on success, negative on failure
2657 static int atl1_change_mtu(struct net_device
*netdev
, int new_mtu
)
2659 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2660 int old_mtu
= netdev
->mtu
;
2661 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
2663 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
2664 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
2665 if (netif_msg_link(adapter
))
2666 dev_warn(&adapter
->pdev
->dev
, "invalid MTU setting\n");
2670 adapter
->hw
.max_frame_size
= max_frame
;
2671 adapter
->hw
.tx_jumbo_task_th
= (max_frame
+ 7) >> 3;
2672 adapter
->rx_buffer_len
= (max_frame
+ 7) & ~7;
2673 adapter
->hw
.rx_jumbo_th
= adapter
->rx_buffer_len
/ 8;
2675 netdev
->mtu
= new_mtu
;
2676 if ((old_mtu
!= new_mtu
) && netif_running(netdev
)) {
2685 * atl1_open - Called when a network interface is made active
2686 * @netdev: network interface device structure
2688 * Returns 0 on success, negative value on failure
2690 * The open entry point is called when a network interface is made
2691 * active by the system (IFF_UP). At this point all resources needed
2692 * for transmit and receive operations are allocated, the interrupt
2693 * handler is registered with the OS, the watchdog timer is started,
2694 * and the stack is notified that the interface is ready.
2696 static int atl1_open(struct net_device
*netdev
)
2698 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2701 netif_carrier_off(netdev
);
2703 /* allocate transmit descriptors */
2704 err
= atl1_setup_ring_resources(adapter
);
2708 err
= atl1_up(adapter
);
2715 atl1_reset(adapter
);
2720 * atl1_close - Disables a network interface
2721 * @netdev: network interface device structure
2723 * Returns 0, this is not allowed to fail
2725 * The close entry point is called when an interface is de-activated
2726 * by the OS. The hardware is still under the drivers control, but
2727 * needs to be disabled. A global MAC reset is issued to stop the
2728 * hardware, and all transmit and receive resources are freed.
2730 static int atl1_close(struct net_device
*netdev
)
2732 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2734 atl1_free_ring_resources(adapter
);
2739 static int atl1_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2741 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2742 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2743 struct atl1_hw
*hw
= &adapter
->hw
;
2745 u32 wufc
= adapter
->wol
;
2751 netif_device_detach(netdev
);
2752 if (netif_running(netdev
))
2755 retval
= pci_save_state(pdev
);
2759 atl1_read_phy_reg(hw
, MII_BMSR
, (u16
*) & ctrl
);
2760 atl1_read_phy_reg(hw
, MII_BMSR
, (u16
*) & ctrl
);
2761 val
= ctrl
& BMSR_LSTATUS
;
2763 wufc
&= ~ATLX_WUFC_LNKC
;
2766 val
= atl1_get_speed_and_duplex(hw
, &speed
, &duplex
);
2768 if (netif_msg_ifdown(adapter
))
2769 dev_printk(KERN_DEBUG
, &pdev
->dev
,
2770 "error getting speed/duplex\n");
2776 /* enable magic packet WOL */
2777 if (wufc
& ATLX_WUFC_MAG
)
2778 ctrl
|= (WOL_MAGIC_EN
| WOL_MAGIC_PME_EN
);
2779 iowrite32(ctrl
, hw
->hw_addr
+ REG_WOL_CTRL
);
2780 ioread32(hw
->hw_addr
+ REG_WOL_CTRL
);
2782 /* configure the mac */
2783 ctrl
= MAC_CTRL_RX_EN
;
2784 ctrl
|= ((u32
)((speed
== SPEED_1000
) ? MAC_CTRL_SPEED_1000
:
2785 MAC_CTRL_SPEED_10_100
) << MAC_CTRL_SPEED_SHIFT
);
2786 if (duplex
== FULL_DUPLEX
)
2787 ctrl
|= MAC_CTRL_DUPLX
;
2788 ctrl
|= (((u32
)adapter
->hw
.preamble_len
&
2789 MAC_CTRL_PRMLEN_MASK
) << MAC_CTRL_PRMLEN_SHIFT
);
2791 ctrl
|= MAC_CTRL_RMV_VLAN
;
2792 if (wufc
& ATLX_WUFC_MAG
)
2793 ctrl
|= MAC_CTRL_BC_EN
;
2794 iowrite32(ctrl
, hw
->hw_addr
+ REG_MAC_CTRL
);
2795 ioread32(hw
->hw_addr
+ REG_MAC_CTRL
);
2798 ctrl
= ioread32(hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2799 ctrl
|= PCIE_PHYMISC_FORCE_RCV_DET
;
2800 iowrite32(ctrl
, hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2801 ioread32(hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2803 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), 1);
2808 ctrl
|= (WOL_LINK_CHG_EN
| WOL_LINK_CHG_PME_EN
);
2809 iowrite32(ctrl
, hw
->hw_addr
+ REG_WOL_CTRL
);
2810 ioread32(hw
->hw_addr
+ REG_WOL_CTRL
);
2811 iowrite32(0, hw
->hw_addr
+ REG_MAC_CTRL
);
2812 ioread32(hw
->hw_addr
+ REG_MAC_CTRL
);
2813 hw
->phy_configured
= false;
2814 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), 1);
2819 iowrite32(0, hw
->hw_addr
+ REG_WOL_CTRL
);
2820 ioread32(hw
->hw_addr
+ REG_WOL_CTRL
);
2821 ctrl
= ioread32(hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2822 ctrl
|= PCIE_PHYMISC_FORCE_RCV_DET
;
2823 iowrite32(ctrl
, hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2824 ioread32(hw
->hw_addr
+ REG_PCIE_PHYMISC
);
2825 hw
->phy_configured
= false;
2826 pci_enable_wake(pdev
, pci_choose_state(pdev
, state
), 0);
2828 if (netif_running(netdev
))
2829 pci_disable_msi(adapter
->pdev
);
2830 pci_disable_device(pdev
);
2831 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2836 static int atl1_resume(struct pci_dev
*pdev
)
2838 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2839 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
2842 pci_set_power_state(pdev
, PCI_D0
);
2843 pci_restore_state(pdev
);
2845 err
= pci_enable_device(pdev
);
2847 if (netif_msg_ifup(adapter
))
2848 dev_printk(KERN_DEBUG
, &pdev
->dev
,
2849 "error enabling pci device\n");
2853 pci_set_master(pdev
);
2854 iowrite32(0, adapter
->hw
.hw_addr
+ REG_WOL_CTRL
);
2855 pci_enable_wake(pdev
, PCI_D3hot
, 0);
2856 pci_enable_wake(pdev
, PCI_D3cold
, 0);
2858 atl1_reset_hw(&adapter
->hw
);
2859 adapter
->cmb
.cmb
->int_stats
= 0;
2861 if (netif_running(netdev
))
2863 netif_device_attach(netdev
);
2868 #define atl1_suspend NULL
2869 #define atl1_resume NULL
2872 static void atl1_shutdown(struct pci_dev
*pdev
)
2875 atl1_suspend(pdev
, PMSG_SUSPEND
);
2879 #ifdef CONFIG_NET_POLL_CONTROLLER
2880 static void atl1_poll_controller(struct net_device
*netdev
)
2882 disable_irq(netdev
->irq
);
2883 atl1_intr(netdev
->irq
, netdev
);
2884 enable_irq(netdev
->irq
);
2888 static const struct net_device_ops atl1_netdev_ops
= {
2889 .ndo_open
= atl1_open
,
2890 .ndo_stop
= atl1_close
,
2891 .ndo_start_xmit
= atl1_xmit_frame
,
2892 .ndo_set_multicast_list
= atlx_set_multi
,
2893 .ndo_validate_addr
= eth_validate_addr
,
2894 .ndo_set_mac_address
= atl1_set_mac
,
2895 .ndo_change_mtu
= atl1_change_mtu
,
2896 .ndo_do_ioctl
= atlx_ioctl
,
2897 .ndo_tx_timeout
= atlx_tx_timeout
,
2898 .ndo_vlan_rx_register
= atlx_vlan_rx_register
,
2899 #ifdef CONFIG_NET_POLL_CONTROLLER
2900 .ndo_poll_controller
= atl1_poll_controller
,
2905 * atl1_probe - Device Initialization Routine
2906 * @pdev: PCI device information struct
2907 * @ent: entry in atl1_pci_tbl
2909 * Returns 0 on success, negative on failure
2911 * atl1_probe initializes an adapter identified by a pci_dev structure.
2912 * The OS initialization, configuring of the adapter private structure,
2913 * and a hardware reset occur.
2915 static int __devinit
atl1_probe(struct pci_dev
*pdev
,
2916 const struct pci_device_id
*ent
)
2918 struct net_device
*netdev
;
2919 struct atl1_adapter
*adapter
;
2920 static int cards_found
= 0;
2923 err
= pci_enable_device(pdev
);
2928 * The atl1 chip can DMA to 64-bit addresses, but it uses a single
2929 * shared register for the high 32 bits, so only a single, aligned,
2930 * 4 GB physical address range can be used at a time.
2932 * Supporting 64-bit DMA on this hardware is more trouble than it's
2933 * worth. It is far easier to limit to 32-bit DMA than update
2934 * various kernel subsystems to support the mechanics required by a
2935 * fixed-high-32-bit system.
2937 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2939 dev_err(&pdev
->dev
, "no usable DMA configuration\n");
2943 * Mark all PCI regions associated with PCI device
2944 * pdev as being reserved by owner atl1_driver_name
2946 err
= pci_request_regions(pdev
, ATLX_DRIVER_NAME
);
2948 goto err_request_regions
;
2951 * Enables bus-mastering on the device and calls
2952 * pcibios_set_master to do the needed arch specific settings
2954 pci_set_master(pdev
);
2956 netdev
= alloc_etherdev(sizeof(struct atl1_adapter
));
2959 goto err_alloc_etherdev
;
2961 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2963 pci_set_drvdata(pdev
, netdev
);
2964 adapter
= netdev_priv(netdev
);
2965 adapter
->netdev
= netdev
;
2966 adapter
->pdev
= pdev
;
2967 adapter
->hw
.back
= adapter
;
2968 adapter
->msg_enable
= netif_msg_init(debug
, atl1_default_msg
);
2970 adapter
->hw
.hw_addr
= pci_iomap(pdev
, 0, 0);
2971 if (!adapter
->hw
.hw_addr
) {
2975 /* get device revision number */
2976 adapter
->hw
.dev_rev
= ioread16(adapter
->hw
.hw_addr
+
2977 (REG_MASTER_CTRL
+ 2));
2978 if (netif_msg_probe(adapter
))
2979 dev_info(&pdev
->dev
, "version %s\n", ATLX_DRIVER_VERSION
);
2981 /* set default ring resource counts */
2982 adapter
->rfd_ring
.count
= adapter
->rrd_ring
.count
= ATL1_DEFAULT_RFD
;
2983 adapter
->tpd_ring
.count
= ATL1_DEFAULT_TPD
;
2985 adapter
->mii
.dev
= netdev
;
2986 adapter
->mii
.mdio_read
= mdio_read
;
2987 adapter
->mii
.mdio_write
= mdio_write
;
2988 adapter
->mii
.phy_id_mask
= 0x1f;
2989 adapter
->mii
.reg_num_mask
= 0x1f;
2991 netdev
->netdev_ops
= &atl1_netdev_ops
;
2992 netdev
->watchdog_timeo
= 5 * HZ
;
2994 netdev
->ethtool_ops
= &atl1_ethtool_ops
;
2995 adapter
->bd_number
= cards_found
;
2997 /* setup the private structure */
2998 err
= atl1_sw_init(adapter
);
3002 netdev
->features
= NETIF_F_HW_CSUM
;
3003 netdev
->features
|= NETIF_F_SG
;
3004 netdev
->features
|= (NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
);
3007 * patch for some L1 of old version,
3008 * the final version of L1 may not need these
3011 /* atl1_pcie_patch(adapter); */
3013 /* really reset GPHY core */
3014 iowrite16(0, adapter
->hw
.hw_addr
+ REG_PHY_ENABLE
);
3017 * reset the controller to
3018 * put the device in a known good starting state
3020 if (atl1_reset_hw(&adapter
->hw
)) {
3025 /* copy the MAC address out of the EEPROM */
3026 atl1_read_mac_addr(&adapter
->hw
);
3027 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
3029 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3034 atl1_check_options(adapter
);
3036 /* pre-init the MAC, and setup link */
3037 err
= atl1_init_hw(&adapter
->hw
);
3043 atl1_pcie_patch(adapter
);
3044 /* assume we have no link for now */
3045 netif_carrier_off(netdev
);
3046 netif_stop_queue(netdev
);
3048 setup_timer(&adapter
->phy_config_timer
, &atl1_phy_config
,
3049 (unsigned long)adapter
);
3050 adapter
->phy_timer_pending
= false;
3052 INIT_WORK(&adapter
->tx_timeout_task
, atl1_tx_timeout_task
);
3054 INIT_WORK(&adapter
->link_chg_task
, atlx_link_chg_task
);
3056 INIT_WORK(&adapter
->pcie_dma_to_rst_task
, atl1_tx_timeout_task
);
3058 err
= register_netdev(netdev
);
3063 atl1_via_workaround(adapter
);
3067 pci_iounmap(pdev
, adapter
->hw
.hw_addr
);
3069 free_netdev(netdev
);
3071 pci_release_regions(pdev
);
3073 err_request_regions
:
3074 pci_disable_device(pdev
);
3079 * atl1_remove - Device Removal Routine
3080 * @pdev: PCI device information struct
3082 * atl1_remove is called by the PCI subsystem to alert the driver
3083 * that it should release a PCI device. The could be caused by a
3084 * Hot-Plug event, or because the driver is going to be removed from
3087 static void __devexit
atl1_remove(struct pci_dev
*pdev
)
3089 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3090 struct atl1_adapter
*adapter
;
3091 /* Device not available. Return. */
3095 adapter
= netdev_priv(netdev
);
3098 * Some atl1 boards lack persistent storage for their MAC, and get it
3099 * from the BIOS during POST. If we've been messing with the MAC
3100 * address, we need to save the permanent one.
3102 if (memcmp(adapter
->hw
.mac_addr
, adapter
->hw
.perm_mac_addr
, ETH_ALEN
)) {
3103 memcpy(adapter
->hw
.mac_addr
, adapter
->hw
.perm_mac_addr
,
3105 atl1_set_mac_addr(&adapter
->hw
);
3108 iowrite16(0, adapter
->hw
.hw_addr
+ REG_PHY_ENABLE
);
3109 unregister_netdev(netdev
);
3110 pci_iounmap(pdev
, adapter
->hw
.hw_addr
);
3111 pci_release_regions(pdev
);
3112 free_netdev(netdev
);
3113 pci_disable_device(pdev
);
3116 static struct pci_driver atl1_driver
= {
3117 .name
= ATLX_DRIVER_NAME
,
3118 .id_table
= atl1_pci_tbl
,
3119 .probe
= atl1_probe
,
3120 .remove
= __devexit_p(atl1_remove
),
3121 .suspend
= atl1_suspend
,
3122 .resume
= atl1_resume
,
3123 .shutdown
= atl1_shutdown
3127 * atl1_exit_module - Driver Exit Cleanup Routine
3129 * atl1_exit_module is called just before the driver is removed
3132 static void __exit
atl1_exit_module(void)
3134 pci_unregister_driver(&atl1_driver
);
3138 * atl1_init_module - Driver Registration Routine
3140 * atl1_init_module is the first routine called when the driver is
3141 * loaded. All it does is register with the PCI subsystem.
3143 static int __init
atl1_init_module(void)
3145 return pci_register_driver(&atl1_driver
);
3148 module_init(atl1_init_module
);
3149 module_exit(atl1_exit_module
);
3152 char stat_string
[ETH_GSTRING_LEN
];
3157 #define ATL1_STAT(m) \
3158 sizeof(((struct atl1_adapter *)0)->m), offsetof(struct atl1_adapter, m)
3160 static struct atl1_stats atl1_gstrings_stats
[] = {
3161 {"rx_packets", ATL1_STAT(soft_stats
.rx_packets
)},
3162 {"tx_packets", ATL1_STAT(soft_stats
.tx_packets
)},
3163 {"rx_bytes", ATL1_STAT(soft_stats
.rx_bytes
)},
3164 {"tx_bytes", ATL1_STAT(soft_stats
.tx_bytes
)},
3165 {"rx_errors", ATL1_STAT(soft_stats
.rx_errors
)},
3166 {"tx_errors", ATL1_STAT(soft_stats
.tx_errors
)},
3167 {"multicast", ATL1_STAT(soft_stats
.multicast
)},
3168 {"collisions", ATL1_STAT(soft_stats
.collisions
)},
3169 {"rx_length_errors", ATL1_STAT(soft_stats
.rx_length_errors
)},
3170 {"rx_over_errors", ATL1_STAT(soft_stats
.rx_missed_errors
)},
3171 {"rx_crc_errors", ATL1_STAT(soft_stats
.rx_crc_errors
)},
3172 {"rx_frame_errors", ATL1_STAT(soft_stats
.rx_frame_errors
)},
3173 {"rx_fifo_errors", ATL1_STAT(soft_stats
.rx_fifo_errors
)},
3174 {"rx_missed_errors", ATL1_STAT(soft_stats
.rx_missed_errors
)},
3175 {"tx_aborted_errors", ATL1_STAT(soft_stats
.tx_aborted_errors
)},
3176 {"tx_carrier_errors", ATL1_STAT(soft_stats
.tx_carrier_errors
)},
3177 {"tx_fifo_errors", ATL1_STAT(soft_stats
.tx_fifo_errors
)},
3178 {"tx_window_errors", ATL1_STAT(soft_stats
.tx_window_errors
)},
3179 {"tx_abort_exce_coll", ATL1_STAT(soft_stats
.excecol
)},
3180 {"tx_abort_late_coll", ATL1_STAT(soft_stats
.latecol
)},
3181 {"tx_deferred_ok", ATL1_STAT(soft_stats
.deffer
)},
3182 {"tx_single_coll_ok", ATL1_STAT(soft_stats
.scc
)},
3183 {"tx_multi_coll_ok", ATL1_STAT(soft_stats
.mcc
)},
3184 {"tx_underun", ATL1_STAT(soft_stats
.tx_underun
)},
3185 {"tx_trunc", ATL1_STAT(soft_stats
.tx_trunc
)},
3186 {"tx_pause", ATL1_STAT(soft_stats
.tx_pause
)},
3187 {"rx_pause", ATL1_STAT(soft_stats
.rx_pause
)},
3188 {"rx_rrd_ov", ATL1_STAT(soft_stats
.rx_rrd_ov
)},
3189 {"rx_trunc", ATL1_STAT(soft_stats
.rx_trunc
)}
3192 static void atl1_get_ethtool_stats(struct net_device
*netdev
,
3193 struct ethtool_stats
*stats
, u64
*data
)
3195 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3199 for (i
= 0; i
< ARRAY_SIZE(atl1_gstrings_stats
); i
++) {
3200 p
= (char *)adapter
+atl1_gstrings_stats
[i
].stat_offset
;
3201 data
[i
] = (atl1_gstrings_stats
[i
].sizeof_stat
==
3202 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
3207 static int atl1_get_sset_count(struct net_device
*netdev
, int sset
)
3211 return ARRAY_SIZE(atl1_gstrings_stats
);
3217 static int atl1_get_settings(struct net_device
*netdev
,
3218 struct ethtool_cmd
*ecmd
)
3220 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3221 struct atl1_hw
*hw
= &adapter
->hw
;
3223 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
3224 SUPPORTED_10baseT_Full
|
3225 SUPPORTED_100baseT_Half
|
3226 SUPPORTED_100baseT_Full
|
3227 SUPPORTED_1000baseT_Full
|
3228 SUPPORTED_Autoneg
| SUPPORTED_TP
);
3229 ecmd
->advertising
= ADVERTISED_TP
;
3230 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3231 hw
->media_type
== MEDIA_TYPE_1000M_FULL
) {
3232 ecmd
->advertising
|= ADVERTISED_Autoneg
;
3233 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
) {
3234 ecmd
->advertising
|= ADVERTISED_Autoneg
;
3235 ecmd
->advertising
|=
3236 (ADVERTISED_10baseT_Half
|
3237 ADVERTISED_10baseT_Full
|
3238 ADVERTISED_100baseT_Half
|
3239 ADVERTISED_100baseT_Full
|
3240 ADVERTISED_1000baseT_Full
);
3242 ecmd
->advertising
|= (ADVERTISED_1000baseT_Full
);
3244 ecmd
->port
= PORT_TP
;
3245 ecmd
->phy_address
= 0;
3246 ecmd
->transceiver
= XCVR_INTERNAL
;
3248 if (netif_carrier_ok(adapter
->netdev
)) {
3249 u16 link_speed
, link_duplex
;
3250 atl1_get_speed_and_duplex(hw
, &link_speed
, &link_duplex
);
3251 ecmd
->speed
= link_speed
;
3252 if (link_duplex
== FULL_DUPLEX
)
3253 ecmd
->duplex
= DUPLEX_FULL
;
3255 ecmd
->duplex
= DUPLEX_HALF
;
3260 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3261 hw
->media_type
== MEDIA_TYPE_1000M_FULL
)
3262 ecmd
->autoneg
= AUTONEG_ENABLE
;
3264 ecmd
->autoneg
= AUTONEG_DISABLE
;
3269 static int atl1_set_settings(struct net_device
*netdev
,
3270 struct ethtool_cmd
*ecmd
)
3272 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3273 struct atl1_hw
*hw
= &adapter
->hw
;
3276 u16 old_media_type
= hw
->media_type
;
3278 if (netif_running(adapter
->netdev
)) {
3279 if (netif_msg_link(adapter
))
3280 dev_dbg(&adapter
->pdev
->dev
,
3281 "ethtool shutting down adapter\n");
3285 if (ecmd
->autoneg
== AUTONEG_ENABLE
)
3286 hw
->media_type
= MEDIA_TYPE_AUTO_SENSOR
;
3288 if (ecmd
->speed
== SPEED_1000
) {
3289 if (ecmd
->duplex
!= DUPLEX_FULL
) {
3290 if (netif_msg_link(adapter
))
3291 dev_warn(&adapter
->pdev
->dev
,
3292 "1000M half is invalid\n");
3296 hw
->media_type
= MEDIA_TYPE_1000M_FULL
;
3297 } else if (ecmd
->speed
== SPEED_100
) {
3298 if (ecmd
->duplex
== DUPLEX_FULL
)
3299 hw
->media_type
= MEDIA_TYPE_100M_FULL
;
3301 hw
->media_type
= MEDIA_TYPE_100M_HALF
;
3303 if (ecmd
->duplex
== DUPLEX_FULL
)
3304 hw
->media_type
= MEDIA_TYPE_10M_FULL
;
3306 hw
->media_type
= MEDIA_TYPE_10M_HALF
;
3309 switch (hw
->media_type
) {
3310 case MEDIA_TYPE_AUTO_SENSOR
:
3312 ADVERTISED_10baseT_Half
|
3313 ADVERTISED_10baseT_Full
|
3314 ADVERTISED_100baseT_Half
|
3315 ADVERTISED_100baseT_Full
|
3316 ADVERTISED_1000baseT_Full
|
3317 ADVERTISED_Autoneg
| ADVERTISED_TP
;
3319 case MEDIA_TYPE_1000M_FULL
:
3321 ADVERTISED_1000baseT_Full
|
3322 ADVERTISED_Autoneg
| ADVERTISED_TP
;
3325 ecmd
->advertising
= 0;
3328 if (atl1_phy_setup_autoneg_adv(hw
)) {
3330 if (netif_msg_link(adapter
))
3331 dev_warn(&adapter
->pdev
->dev
,
3332 "invalid ethtool speed/duplex setting\n");
3335 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3336 hw
->media_type
== MEDIA_TYPE_1000M_FULL
)
3337 phy_data
= MII_CR_RESET
| MII_CR_AUTO_NEG_EN
;
3339 switch (hw
->media_type
) {
3340 case MEDIA_TYPE_100M_FULL
:
3342 MII_CR_FULL_DUPLEX
| MII_CR_SPEED_100
|
3345 case MEDIA_TYPE_100M_HALF
:
3346 phy_data
= MII_CR_SPEED_100
| MII_CR_RESET
;
3348 case MEDIA_TYPE_10M_FULL
:
3350 MII_CR_FULL_DUPLEX
| MII_CR_SPEED_10
| MII_CR_RESET
;
3353 /* MEDIA_TYPE_10M_HALF: */
3354 phy_data
= MII_CR_SPEED_10
| MII_CR_RESET
;
3358 atl1_write_phy_reg(hw
, MII_BMCR
, phy_data
);
3361 hw
->media_type
= old_media_type
;
3363 if (netif_running(adapter
->netdev
)) {
3364 if (netif_msg_link(adapter
))
3365 dev_dbg(&adapter
->pdev
->dev
,
3366 "ethtool starting adapter\n");
3368 } else if (!ret_val
) {
3369 if (netif_msg_link(adapter
))
3370 dev_dbg(&adapter
->pdev
->dev
,
3371 "ethtool resetting adapter\n");
3372 atl1_reset(adapter
);
3377 static void atl1_get_drvinfo(struct net_device
*netdev
,
3378 struct ethtool_drvinfo
*drvinfo
)
3380 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3382 strlcpy(drvinfo
->driver
, ATLX_DRIVER_NAME
, sizeof(drvinfo
->driver
));
3383 strlcpy(drvinfo
->version
, ATLX_DRIVER_VERSION
,
3384 sizeof(drvinfo
->version
));
3385 strlcpy(drvinfo
->fw_version
, "N/A", sizeof(drvinfo
->fw_version
));
3386 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
3387 sizeof(drvinfo
->bus_info
));
3388 drvinfo
->eedump_len
= ATL1_EEDUMP_LEN
;
3391 static void atl1_get_wol(struct net_device
*netdev
,
3392 struct ethtool_wolinfo
*wol
)
3394 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3396 wol
->supported
= WAKE_MAGIC
;
3398 if (adapter
->wol
& ATLX_WUFC_MAG
)
3399 wol
->wolopts
|= WAKE_MAGIC
;
3403 static int atl1_set_wol(struct net_device
*netdev
,
3404 struct ethtool_wolinfo
*wol
)
3406 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3408 if (wol
->wolopts
& (WAKE_PHY
| WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
|
3409 WAKE_ARP
| WAKE_MAGICSECURE
))
3412 if (wol
->wolopts
& WAKE_MAGIC
)
3413 adapter
->wol
|= ATLX_WUFC_MAG
;
3417 static u32
atl1_get_msglevel(struct net_device
*netdev
)
3419 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3420 return adapter
->msg_enable
;
3423 static void atl1_set_msglevel(struct net_device
*netdev
, u32 value
)
3425 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3426 adapter
->msg_enable
= value
;
3429 static int atl1_get_regs_len(struct net_device
*netdev
)
3431 return ATL1_REG_COUNT
* sizeof(u32
);
3434 static void atl1_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
3437 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3438 struct atl1_hw
*hw
= &adapter
->hw
;
3442 for (i
= 0; i
< ATL1_REG_COUNT
; i
++) {
3444 * This switch statement avoids reserved regions
3445 * of register space.
3470 /* reserved region; don't read it */
3474 /* unreserved region */
3475 regbuf
[i
] = ioread32(hw
->hw_addr
+ (i
* sizeof(u32
)));
3480 static void atl1_get_ringparam(struct net_device
*netdev
,
3481 struct ethtool_ringparam
*ring
)
3483 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3484 struct atl1_tpd_ring
*txdr
= &adapter
->tpd_ring
;
3485 struct atl1_rfd_ring
*rxdr
= &adapter
->rfd_ring
;
3487 ring
->rx_max_pending
= ATL1_MAX_RFD
;
3488 ring
->tx_max_pending
= ATL1_MAX_TPD
;
3489 ring
->rx_mini_max_pending
= 0;
3490 ring
->rx_jumbo_max_pending
= 0;
3491 ring
->rx_pending
= rxdr
->count
;
3492 ring
->tx_pending
= txdr
->count
;
3493 ring
->rx_mini_pending
= 0;
3494 ring
->rx_jumbo_pending
= 0;
3497 static int atl1_set_ringparam(struct net_device
*netdev
,
3498 struct ethtool_ringparam
*ring
)
3500 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3501 struct atl1_tpd_ring
*tpdr
= &adapter
->tpd_ring
;
3502 struct atl1_rrd_ring
*rrdr
= &adapter
->rrd_ring
;
3503 struct atl1_rfd_ring
*rfdr
= &adapter
->rfd_ring
;
3505 struct atl1_tpd_ring tpd_old
, tpd_new
;
3506 struct atl1_rfd_ring rfd_old
, rfd_new
;
3507 struct atl1_rrd_ring rrd_old
, rrd_new
;
3508 struct atl1_ring_header rhdr_old
, rhdr_new
;
3511 tpd_old
= adapter
->tpd_ring
;
3512 rfd_old
= adapter
->rfd_ring
;
3513 rrd_old
= adapter
->rrd_ring
;
3514 rhdr_old
= adapter
->ring_header
;
3516 if (netif_running(adapter
->netdev
))
3519 rfdr
->count
= (u16
) max(ring
->rx_pending
, (u32
) ATL1_MIN_RFD
);
3520 rfdr
->count
= rfdr
->count
> ATL1_MAX_RFD
? ATL1_MAX_RFD
:
3522 rfdr
->count
= (rfdr
->count
+ 3) & ~3;
3523 rrdr
->count
= rfdr
->count
;
3525 tpdr
->count
= (u16
) max(ring
->tx_pending
, (u32
) ATL1_MIN_TPD
);
3526 tpdr
->count
= tpdr
->count
> ATL1_MAX_TPD
? ATL1_MAX_TPD
:
3528 tpdr
->count
= (tpdr
->count
+ 3) & ~3;
3530 if (netif_running(adapter
->netdev
)) {
3531 /* try to get new resources before deleting old */
3532 err
= atl1_setup_ring_resources(adapter
);
3534 goto err_setup_ring
;
3537 * save the new, restore the old in order to free it,
3538 * then restore the new back again
3541 rfd_new
= adapter
->rfd_ring
;
3542 rrd_new
= adapter
->rrd_ring
;
3543 tpd_new
= adapter
->tpd_ring
;
3544 rhdr_new
= adapter
->ring_header
;
3545 adapter
->rfd_ring
= rfd_old
;
3546 adapter
->rrd_ring
= rrd_old
;
3547 adapter
->tpd_ring
= tpd_old
;
3548 adapter
->ring_header
= rhdr_old
;
3549 atl1_free_ring_resources(adapter
);
3550 adapter
->rfd_ring
= rfd_new
;
3551 adapter
->rrd_ring
= rrd_new
;
3552 adapter
->tpd_ring
= tpd_new
;
3553 adapter
->ring_header
= rhdr_new
;
3555 err
= atl1_up(adapter
);
3562 adapter
->rfd_ring
= rfd_old
;
3563 adapter
->rrd_ring
= rrd_old
;
3564 adapter
->tpd_ring
= tpd_old
;
3565 adapter
->ring_header
= rhdr_old
;
3570 static void atl1_get_pauseparam(struct net_device
*netdev
,
3571 struct ethtool_pauseparam
*epause
)
3573 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3574 struct atl1_hw
*hw
= &adapter
->hw
;
3576 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3577 hw
->media_type
== MEDIA_TYPE_1000M_FULL
) {
3578 epause
->autoneg
= AUTONEG_ENABLE
;
3580 epause
->autoneg
= AUTONEG_DISABLE
;
3582 epause
->rx_pause
= 1;
3583 epause
->tx_pause
= 1;
3586 static int atl1_set_pauseparam(struct net_device
*netdev
,
3587 struct ethtool_pauseparam
*epause
)
3589 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3590 struct atl1_hw
*hw
= &adapter
->hw
;
3592 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3593 hw
->media_type
== MEDIA_TYPE_1000M_FULL
) {
3594 epause
->autoneg
= AUTONEG_ENABLE
;
3596 epause
->autoneg
= AUTONEG_DISABLE
;
3599 epause
->rx_pause
= 1;
3600 epause
->tx_pause
= 1;
3605 /* FIXME: is this right? -- CHS */
3606 static u32
atl1_get_rx_csum(struct net_device
*netdev
)
3611 static void atl1_get_strings(struct net_device
*netdev
, u32 stringset
,
3617 switch (stringset
) {
3619 for (i
= 0; i
< ARRAY_SIZE(atl1_gstrings_stats
); i
++) {
3620 memcpy(p
, atl1_gstrings_stats
[i
].stat_string
,
3622 p
+= ETH_GSTRING_LEN
;
3628 static int atl1_nway_reset(struct net_device
*netdev
)
3630 struct atl1_adapter
*adapter
= netdev_priv(netdev
);
3631 struct atl1_hw
*hw
= &adapter
->hw
;
3633 if (netif_running(netdev
)) {
3637 if (hw
->media_type
== MEDIA_TYPE_AUTO_SENSOR
||
3638 hw
->media_type
== MEDIA_TYPE_1000M_FULL
) {
3639 phy_data
= MII_CR_RESET
| MII_CR_AUTO_NEG_EN
;
3641 switch (hw
->media_type
) {
3642 case MEDIA_TYPE_100M_FULL
:
3643 phy_data
= MII_CR_FULL_DUPLEX
|
3644 MII_CR_SPEED_100
| MII_CR_RESET
;
3646 case MEDIA_TYPE_100M_HALF
:
3647 phy_data
= MII_CR_SPEED_100
| MII_CR_RESET
;
3649 case MEDIA_TYPE_10M_FULL
:
3650 phy_data
= MII_CR_FULL_DUPLEX
|
3651 MII_CR_SPEED_10
| MII_CR_RESET
;
3654 /* MEDIA_TYPE_10M_HALF */
3655 phy_data
= MII_CR_SPEED_10
| MII_CR_RESET
;
3658 atl1_write_phy_reg(hw
, MII_BMCR
, phy_data
);
3664 const struct ethtool_ops atl1_ethtool_ops
= {
3665 .get_settings
= atl1_get_settings
,
3666 .set_settings
= atl1_set_settings
,
3667 .get_drvinfo
= atl1_get_drvinfo
,
3668 .get_wol
= atl1_get_wol
,
3669 .set_wol
= atl1_set_wol
,
3670 .get_msglevel
= atl1_get_msglevel
,
3671 .set_msglevel
= atl1_set_msglevel
,
3672 .get_regs_len
= atl1_get_regs_len
,
3673 .get_regs
= atl1_get_regs
,
3674 .get_ringparam
= atl1_get_ringparam
,
3675 .set_ringparam
= atl1_set_ringparam
,
3676 .get_pauseparam
= atl1_get_pauseparam
,
3677 .set_pauseparam
= atl1_set_pauseparam
,
3678 .get_rx_csum
= atl1_get_rx_csum
,
3679 .set_tx_csum
= ethtool_op_set_tx_hw_csum
,
3680 .get_link
= ethtool_op_get_link
,
3681 .set_sg
= ethtool_op_set_sg
,
3682 .get_strings
= atl1_get_strings
,
3683 .nway_reset
= atl1_nway_reset
,
3684 .get_ethtool_stats
= atl1_get_ethtool_stats
,
3685 .get_sset_count
= atl1_get_sset_count
,
3686 .set_tso
= ethtool_op_set_tso
,