2 * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
3 * Copyright(c) 2006 - 2007 Chris Snook <csnook@redhat.com>
4 * Copyright(c) 2006 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@attansic.com>
28 * Attansic Technology Corp. 3F 147, Xianzheng 9th Road, Zhubei,
29 * Xinzhu 302, TAIWAN, REPUBLIC OF CHINA
31 * Chris Snook <csnook@redhat.com>
32 * Jay Cliburn <jcliburn@gmail.com>
34 * This version is adapted from the Attansic reference driver for
35 * inclusion in the Linux kernel. It is currently under heavy development.
36 * A very incomplete list of things that need to be dealt with:
40 * Add more ethtool functions.
41 * Fix abstruse irq enable/disable condition described here:
42 * http://marc.theaimsgroup.com/?l=linux-netdev&m=116398508500553&w=2
48 * interrupt coalescing
52 #include <asm/atomic.h>
53 #include <asm/byteorder.h>
55 #include <linux/compiler.h>
56 #include <linux/crc32.h>
57 #include <linux/delay.h>
58 #include <linux/dma-mapping.h>
59 #include <linux/etherdevice.h>
60 #include <linux/hardirq.h>
61 #include <linux/if_ether.h>
62 #include <linux/if_vlan.h>
64 #include <linux/interrupt.h>
66 #include <linux/irqflags.h>
67 #include <linux/irqreturn.h>
68 #include <linux/jiffies.h>
69 #include <linux/mii.h>
70 #include <linux/module.h>
71 #include <linux/moduleparam.h>
72 #include <linux/net.h>
73 #include <linux/netdevice.h>
74 #include <linux/pci.h>
75 #include <linux/pci_ids.h>
77 #include <linux/skbuff.h>
78 #include <linux/slab.h>
79 #include <linux/spinlock.h>
80 #include <linux/string.h>
81 #include <linux/tcp.h>
82 #include <linux/timer.h>
83 #include <linux/types.h>
84 #include <linux/workqueue.h>
86 #include <net/checksum.h>
90 /* Temporary hack for merging atl1 and atl2 */
94 * atl1_pci_tbl - PCI Device ID Table
96 static const struct pci_device_id atl1_pci_tbl[] = {
97 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1)},
98 /* required last entry */
101 MODULE_DEVICE_TABLE(pci, atl1_pci_tbl);
103 static const u32 atl1_default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
104 NETIF_MSG_LINK | NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP;
106 static int debug = -1;
107 module_param(debug, int, 0);
108 MODULE_PARM_DESC(debug, "Message level (0=none,...,16=all)");
111 * Reset the transmit and receive units; mask and clear all interrupts.
112 * hw - Struct containing variables accessed by shared code
113 * return : 0 or idle status (if error)
115 static s32 atl1_reset_hw(struct atl1_hw *hw)
117 struct pci_dev *pdev = hw->back->pdev;
118 struct atl1_adapter *adapter = hw->back;
123 * Clear Interrupt mask to stop board from generating
124 * interrupts & Clear any pending interrupt events
127 * iowrite32(0, hw->hw_addr + REG_IMR);
128 * iowrite32(0xffffffff, hw->hw_addr + REG_ISR);
132 * Issue Soft Reset to the MAC. This will reset the chip's
133 * transmit, receive, DMA. It will not effect
134 * the current PCI configuration. The global reset bit is self-
135 * clearing, and should clear within a microsecond.
137 iowrite32(MASTER_CTRL_SOFT_RST, hw->hw_addr + REG_MASTER_CTRL);
138 ioread32(hw->hw_addr + REG_MASTER_CTRL);
140 iowrite16(1, hw->hw_addr + REG_PHY_ENABLE);
141 ioread16(hw->hw_addr + REG_PHY_ENABLE);
143 /* delay about 1ms */
146 /* Wait at least 10ms for All module to be Idle */
147 for (i = 0; i < 10; i++) {
148 icr = ioread32(hw->hw_addr + REG_IDLE_STATUS);
153 /* FIXME: still the right way to do this? */
158 if (netif_msg_hw(adapter))
159 dev_dbg(&pdev->dev, "ICR = 0x%x\n", icr);
166 /* function about EEPROM
169 * return 0 if eeprom exist
171 static int atl1_check_eeprom_exist(struct atl1_hw *hw)
174 value = ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
175 if (value & SPI_FLASH_CTRL_EN_VPD) {
176 value &= ~SPI_FLASH_CTRL_EN_VPD;
177 iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
180 value = ioread16(hw->hw_addr + REG_PCIE_CAP_LIST);
181 return ((value & 0xFF00) == 0x6C00) ? 0 : 1;
184 static bool atl1_read_eeprom(struct atl1_hw *hw, u32 offset, u32 *p_value)
190 /* address do not align */
193 iowrite32(0, hw->hw_addr + REG_VPD_DATA);
194 control = (offset & VPD_CAP_VPD_ADDR_MASK) << VPD_CAP_VPD_ADDR_SHIFT;
195 iowrite32(control, hw->hw_addr + REG_VPD_CAP);
196 ioread32(hw->hw_addr + REG_VPD_CAP);
198 for (i = 0; i < 10; i++) {
200 control = ioread32(hw->hw_addr + REG_VPD_CAP);
201 if (control & VPD_CAP_VPD_FLAG)
204 if (control & VPD_CAP_VPD_FLAG) {
205 *p_value = ioread32(hw->hw_addr + REG_VPD_DATA);
213 * Reads the value from a PHY register
214 * hw - Struct containing variables accessed by shared code
215 * reg_addr - address of the PHY register to read
217 s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data)
222 val = ((u32) (reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
223 MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW | MDIO_CLK_25_4 <<
225 iowrite32(val, hw->hw_addr + REG_MDIO_CTRL);
226 ioread32(hw->hw_addr + REG_MDIO_CTRL);
228 for (i = 0; i < MDIO_WAIT_TIMES; i++) {
230 val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
231 if (!(val & (MDIO_START | MDIO_BUSY)))
234 if (!(val & (MDIO_START | MDIO_BUSY))) {
235 *phy_data = (u16) val;
241 #define CUSTOM_SPI_CS_SETUP 2
242 #define CUSTOM_SPI_CLK_HI 2
243 #define CUSTOM_SPI_CLK_LO 2
244 #define CUSTOM_SPI_CS_HOLD 2
245 #define CUSTOM_SPI_CS_HI 3
247 static bool atl1_spi_read(struct atl1_hw *hw, u32 addr, u32 *buf)
252 iowrite32(0, hw->hw_addr + REG_SPI_DATA);
253 iowrite32(addr, hw->hw_addr + REG_SPI_ADDR);
255 value = SPI_FLASH_CTRL_WAIT_READY |
256 (CUSTOM_SPI_CS_SETUP & SPI_FLASH_CTRL_CS_SETUP_MASK) <<
257 SPI_FLASH_CTRL_CS_SETUP_SHIFT | (CUSTOM_SPI_CLK_HI &
258 SPI_FLASH_CTRL_CLK_HI_MASK) <<
259 SPI_FLASH_CTRL_CLK_HI_SHIFT | (CUSTOM_SPI_CLK_LO &
260 SPI_FLASH_CTRL_CLK_LO_MASK) <<
261 SPI_FLASH_CTRL_CLK_LO_SHIFT | (CUSTOM_SPI_CS_HOLD &
262 SPI_FLASH_CTRL_CS_HOLD_MASK) <<
263 SPI_FLASH_CTRL_CS_HOLD_SHIFT | (CUSTOM_SPI_CS_HI &
264 SPI_FLASH_CTRL_CS_HI_MASK) <<
265 SPI_FLASH_CTRL_CS_HI_SHIFT | (1 & SPI_FLASH_CTRL_INS_MASK) <<
266 SPI_FLASH_CTRL_INS_SHIFT;
268 iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
270 value |= SPI_FLASH_CTRL_START;
271 iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
272 ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
274 for (i = 0; i < 10; i++) {
276 value = ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
277 if (!(value & SPI_FLASH_CTRL_START))
281 if (value & SPI_FLASH_CTRL_START)
284 *buf = ioread32(hw->hw_addr + REG_SPI_DATA);
290 * get_permanent_address
291 * return 0 if get valid mac address,
293 static int atl1_get_permanent_address(struct atl1_hw *hw)
298 u8 eth_addr[ETH_ALEN];
301 if (is_valid_ether_addr(hw->perm_mac_addr))
305 addr[0] = addr[1] = 0;
307 if (!atl1_check_eeprom_exist(hw)) {
310 /* Read out all EEPROM content */
313 if (atl1_read_eeprom(hw, i + 0x100, &control)) {
315 if (reg == REG_MAC_STA_ADDR)
317 else if (reg == (REG_MAC_STA_ADDR + 4))
320 } else if ((control & 0xff) == 0x5A) {
322 reg = (u16) (control >> 16);
331 *(u32 *) ð_addr[2] = swab32(addr[0]);
332 *(u16 *) ð_addr[0] = swab16(*(u16 *) &addr[1]);
333 if (is_valid_ether_addr(eth_addr)) {
334 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
340 /* see if SPI FLAGS exist ? */
341 addr[0] = addr[1] = 0;
346 if (atl1_spi_read(hw, i + 0x1f000, &control)) {
348 if (reg == REG_MAC_STA_ADDR)
350 else if (reg == (REG_MAC_STA_ADDR + 4))
353 } else if ((control & 0xff) == 0x5A) {
355 reg = (u16) (control >> 16);
365 *(u32 *) ð_addr[2] = swab32(addr[0]);
366 *(u16 *) ð_addr[0] = swab16(*(u16 *) &addr[1]);
367 if (is_valid_ether_addr(eth_addr)) {
368 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
373 * On some motherboards, the MAC address is written by the
374 * BIOS directly to the MAC register during POST, and is
375 * not stored in eeprom. If all else thus far has failed
376 * to fetch the permanent MAC address, try reading it directly.
378 addr[0] = ioread32(hw->hw_addr + REG_MAC_STA_ADDR);
379 addr[1] = ioread16(hw->hw_addr + (REG_MAC_STA_ADDR + 4));
380 *(u32 *) ð_addr[2] = swab32(addr[0]);
381 *(u16 *) ð_addr[0] = swab16(*(u16 *) &addr[1]);
382 if (is_valid_ether_addr(eth_addr)) {
383 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
391 * Reads the adapter's MAC address from the EEPROM
392 * hw - Struct containing variables accessed by shared code
394 s32 atl1_read_mac_addr(struct atl1_hw *hw)
398 if (atl1_get_permanent_address(hw))
399 random_ether_addr(hw->perm_mac_addr);
401 for (i = 0; i < ETH_ALEN; i++)
402 hw->mac_addr[i] = hw->perm_mac_addr[i];
407 * Hashes an address to determine its location in the multicast table
408 * hw - Struct containing variables accessed by shared code
409 * mc_addr - the multicast address to hash
413 * set hash value for a multicast address
414 * hash calcu processing :
415 * 1. calcu 32bit CRC for multicast address
416 * 2. reverse crc with MSB to LSB
418 u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr)
420 u32 crc32, value = 0;
423 crc32 = ether_crc_le(6, mc_addr);
424 for (i = 0; i < 32; i++)
425 value |= (((crc32 >> i) & 1) << (31 - i));
431 * Sets the bit in the multicast table corresponding to the hash value.
432 * hw - Struct containing variables accessed by shared code
433 * hash_value - Multicast address hash value
435 void atl1_hash_set(struct atl1_hw *hw, u32 hash_value)
437 u32 hash_bit, hash_reg;
441 * The HASH Table is a register array of 2 32-bit registers.
442 * It is treated like an array of 64 bits. We want to set
443 * bit BitArray[hash_value]. So we figure out what register
444 * the bit is in, read it, OR in the new bit, then write
445 * back the new value. The register is determined by the
446 * upper 7 bits of the hash value and the bit within that
447 * register are determined by the lower 5 bits of the value.
449 hash_reg = (hash_value >> 31) & 0x1;
450 hash_bit = (hash_value >> 26) & 0x1F;
451 mta = ioread32((hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
452 mta |= (1 << hash_bit);
453 iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
457 * Writes a value to a PHY register
458 * hw - Struct containing variables accessed by shared code
459 * reg_addr - address of the PHY register to write
460 * data - data to write to the PHY
462 static s32 atl1_write_phy_reg(struct atl1_hw *hw, u32 reg_addr, u16 phy_data)
467 val = ((u32) (phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
468 (reg_addr & MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
470 MDIO_START | MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
471 iowrite32(val, hw->hw_addr + REG_MDIO_CTRL);
472 ioread32(hw->hw_addr + REG_MDIO_CTRL);
474 for (i = 0; i < MDIO_WAIT_TIMES; i++) {
476 val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
477 if (!(val & (MDIO_START | MDIO_BUSY)))
481 if (!(val & (MDIO_START | MDIO_BUSY)))
488 * Make L001's PHY out of Power Saving State (bug)
489 * hw - Struct containing variables accessed by shared code
490 * when power on, L001's PHY always on Power saving State
491 * (Gigabit Link forbidden)
493 static s32 atl1_phy_leave_power_saving(struct atl1_hw *hw)
496 ret = atl1_write_phy_reg(hw, 29, 0x0029);
499 return atl1_write_phy_reg(hw, 30, 0);
503 *TODO: do something or get rid of this
506 static s32 atl1_phy_enter_power_saving(struct atl1_hw *hw)
513 ret_val = atl1_write_phy_reg(hw, ...);
514 ret_val = atl1_write_phy_reg(hw, ...);
522 * Resets the PHY and make all config validate
523 * hw - Struct containing variables accessed by shared code
525 * Sets bit 15 and 12 of the MII Control regiser (for F001 bug)
527 static s32 atl1_phy_reset(struct atl1_hw *hw)
529 struct pci_dev *pdev = hw->back->pdev;
530 struct atl1_adapter *adapter = hw->back;
534 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
535 hw->media_type == MEDIA_TYPE_1000M_FULL)
536 phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN;
538 switch (hw->media_type) {
539 case MEDIA_TYPE_100M_FULL:
541 MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 |
544 case MEDIA_TYPE_100M_HALF:
545 phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
547 case MEDIA_TYPE_10M_FULL:
549 MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET;
552 /* MEDIA_TYPE_10M_HALF: */
553 phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
558 ret_val = atl1_write_phy_reg(hw, MII_BMCR, phy_data);
562 /* pcie serdes link may be down! */
563 if (netif_msg_hw(adapter))
564 dev_dbg(&pdev->dev, "pcie phy link down\n");
566 for (i = 0; i < 25; i++) {
568 val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
569 if (!(val & (MDIO_START | MDIO_BUSY)))
573 if ((val & (MDIO_START | MDIO_BUSY)) != 0) {
574 if (netif_msg_hw(adapter))
576 "pcie link down at least 25ms\n");
584 * Configures PHY autoneg and flow control advertisement settings
585 * hw - Struct containing variables accessed by shared code
587 static s32 atl1_phy_setup_autoneg_adv(struct atl1_hw *hw)
590 s16 mii_autoneg_adv_reg;
591 s16 mii_1000t_ctrl_reg;
593 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
594 mii_autoneg_adv_reg = MII_AR_DEFAULT_CAP_MASK;
596 /* Read the MII 1000Base-T Control Register (Address 9). */
597 mii_1000t_ctrl_reg = MII_ATLX_CR_1000T_DEFAULT_CAP_MASK;
600 * First we clear all the 10/100 mb speed bits in the Auto-Neg
601 * Advertisement Register (Address 4) and the 1000 mb speed bits in
602 * the 1000Base-T Control Register (Address 9).
604 mii_autoneg_adv_reg &= ~MII_AR_SPEED_MASK;
605 mii_1000t_ctrl_reg &= ~MII_ATLX_CR_1000T_SPEED_MASK;
608 * Need to parse media_type and set up
609 * the appropriate PHY registers.
611 switch (hw->media_type) {
612 case MEDIA_TYPE_AUTO_SENSOR:
613 mii_autoneg_adv_reg |= (MII_AR_10T_HD_CAPS |
615 MII_AR_100TX_HD_CAPS |
616 MII_AR_100TX_FD_CAPS);
617 mii_1000t_ctrl_reg |= MII_ATLX_CR_1000T_FD_CAPS;
620 case MEDIA_TYPE_1000M_FULL:
621 mii_1000t_ctrl_reg |= MII_ATLX_CR_1000T_FD_CAPS;
624 case MEDIA_TYPE_100M_FULL:
625 mii_autoneg_adv_reg |= MII_AR_100TX_FD_CAPS;
628 case MEDIA_TYPE_100M_HALF:
629 mii_autoneg_adv_reg |= MII_AR_100TX_HD_CAPS;
632 case MEDIA_TYPE_10M_FULL:
633 mii_autoneg_adv_reg |= MII_AR_10T_FD_CAPS;
637 mii_autoneg_adv_reg |= MII_AR_10T_HD_CAPS;
641 /* flow control fixed to enable all */
642 mii_autoneg_adv_reg |= (MII_AR_ASM_DIR | MII_AR_PAUSE);
644 hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
645 hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
647 ret_val = atl1_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
651 ret_val = atl1_write_phy_reg(hw, MII_ATLX_CR, mii_1000t_ctrl_reg);
659 * Configures link settings.
660 * hw - Struct containing variables accessed by shared code
661 * Assumes the hardware has previously been reset and the
662 * transmitter and receiver are not enabled.
664 static s32 atl1_setup_link(struct atl1_hw *hw)
666 struct pci_dev *pdev = hw->back->pdev;
667 struct atl1_adapter *adapter = hw->back;
672 * PHY will advertise value(s) parsed from
673 * autoneg_advertised and fc
674 * no matter what autoneg is , We will not wait link result.
676 ret_val = atl1_phy_setup_autoneg_adv(hw);
678 if (netif_msg_link(adapter))
680 "error setting up autonegotiation\n");
683 /* SW.Reset , En-Auto-Neg if needed */
684 ret_val = atl1_phy_reset(hw);
686 if (netif_msg_link(adapter))
687 dev_dbg(&pdev->dev, "error resetting phy\n");
690 hw->phy_configured = true;
694 static void atl1_init_flash_opcode(struct atl1_hw *hw)
696 if (hw->flash_vendor >= ARRAY_SIZE(flash_table))
698 hw->flash_vendor = 0;
701 iowrite8(flash_table[hw->flash_vendor].cmd_program,
702 hw->hw_addr + REG_SPI_FLASH_OP_PROGRAM);
703 iowrite8(flash_table[hw->flash_vendor].cmd_sector_erase,
704 hw->hw_addr + REG_SPI_FLASH_OP_SC_ERASE);
705 iowrite8(flash_table[hw->flash_vendor].cmd_chip_erase,
706 hw->hw_addr + REG_SPI_FLASH_OP_CHIP_ERASE);
707 iowrite8(flash_table[hw->flash_vendor].cmd_rdid,
708 hw->hw_addr + REG_SPI_FLASH_OP_RDID);
709 iowrite8(flash_table[hw->flash_vendor].cmd_wren,
710 hw->hw_addr + REG_SPI_FLASH_OP_WREN);
711 iowrite8(flash_table[hw->flash_vendor].cmd_rdsr,
712 hw->hw_addr + REG_SPI_FLASH_OP_RDSR);
713 iowrite8(flash_table[hw->flash_vendor].cmd_wrsr,
714 hw->hw_addr + REG_SPI_FLASH_OP_WRSR);
715 iowrite8(flash_table[hw->flash_vendor].cmd_read,
716 hw->hw_addr + REG_SPI_FLASH_OP_READ);
720 * Performs basic configuration of the adapter.
721 * hw - Struct containing variables accessed by shared code
722 * Assumes that the controller has previously been reset and is in a
723 * post-reset uninitialized state. Initializes multicast table,
724 * and Calls routines to setup link
725 * Leaves the transmit and receive units disabled and uninitialized.
727 static s32 atl1_init_hw(struct atl1_hw *hw)
731 /* Zero out the Multicast HASH table */
732 iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE);
733 /* clear the old settings from the multicast hash table */
734 iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2));
736 atl1_init_flash_opcode(hw);
738 if (!hw->phy_configured) {
739 /* enable GPHY LinkChange Interrrupt */
740 ret_val = atl1_write_phy_reg(hw, 18, 0xC00);
743 /* make PHY out of power-saving state */
744 ret_val = atl1_phy_leave_power_saving(hw);
747 /* Call a subroutine to configure the link */
748 ret_val = atl1_setup_link(hw);
754 * Detects the current speed and duplex settings of the hardware.
755 * hw - Struct containing variables accessed by shared code
756 * speed - Speed of the connection
757 * duplex - Duplex setting of the connection
759 static s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex)
761 struct pci_dev *pdev = hw->back->pdev;
762 struct atl1_adapter *adapter = hw->back;
766 /* ; --- Read PHY Specific Status Register (17) */
767 ret_val = atl1_read_phy_reg(hw, MII_ATLX_PSSR, &phy_data);
771 if (!(phy_data & MII_ATLX_PSSR_SPD_DPLX_RESOLVED))
772 return ATLX_ERR_PHY_RES;
774 switch (phy_data & MII_ATLX_PSSR_SPEED) {
775 case MII_ATLX_PSSR_1000MBS:
778 case MII_ATLX_PSSR_100MBS:
781 case MII_ATLX_PSSR_10MBS:
785 if (netif_msg_hw(adapter))
786 dev_dbg(&pdev->dev, "error getting speed\n");
787 return ATLX_ERR_PHY_SPEED;
790 if (phy_data & MII_ATLX_PSSR_DPLX)
791 *duplex = FULL_DUPLEX;
793 *duplex = HALF_DUPLEX;
798 void atl1_set_mac_addr(struct atl1_hw *hw)
803 * 0: 6AF600DC 1: 000B
806 value = (((u32) hw->mac_addr[2]) << 24) |
807 (((u32) hw->mac_addr[3]) << 16) |
808 (((u32) hw->mac_addr[4]) << 8) | (((u32) hw->mac_addr[5]));
809 iowrite32(value, hw->hw_addr + REG_MAC_STA_ADDR);
811 value = (((u32) hw->mac_addr[0]) << 8) | (((u32) hw->mac_addr[1]));
812 iowrite32(value, (hw->hw_addr + REG_MAC_STA_ADDR) + (1 << 2));
816 * atl1_sw_init - Initialize general software structures (struct atl1_adapter)
817 * @adapter: board private structure to initialize
819 * atl1_sw_init initializes the Adapter private data structure.
820 * Fields are initialized based on PCI device information and
821 * OS network device settings (MTU size).
823 static int __devinit atl1_sw_init(struct atl1_adapter *adapter)
825 struct atl1_hw *hw = &adapter->hw;
826 struct net_device *netdev = adapter->netdev;
828 hw->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
829 hw->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
832 adapter->rx_buffer_len = (hw->max_frame_size + 7) & ~7;
833 adapter->ict = 50000; /* 100ms */
834 adapter->link_speed = SPEED_0; /* hardware init */
835 adapter->link_duplex = FULL_DUPLEX;
837 hw->phy_configured = false;
838 hw->preamble_len = 7;
848 hw->rfd_fetch_gap = 1;
849 hw->rx_jumbo_th = adapter->rx_buffer_len / 8;
850 hw->rx_jumbo_lkah = 1;
851 hw->rrd_ret_timer = 16;
853 hw->tpd_fetch_th = 16;
854 hw->txf_burst = 0x100;
855 hw->tx_jumbo_task_th = (hw->max_frame_size + 7) >> 3;
856 hw->tpd_fetch_gap = 1;
857 hw->rcb_value = atl1_rcb_64;
858 hw->dma_ord = atl1_dma_ord_enh;
859 hw->dmar_block = atl1_dma_req_256;
860 hw->dmaw_block = atl1_dma_req_256;
863 hw->cmb_rx_timer = 1; /* about 2us */
864 hw->cmb_tx_timer = 1; /* about 2us */
865 hw->smb_timer = 100000; /* about 200ms */
867 spin_lock_init(&adapter->lock);
868 spin_lock_init(&adapter->mb_lock);
873 static int mdio_read(struct net_device *netdev, int phy_id, int reg_num)
875 struct atl1_adapter *adapter = netdev_priv(netdev);
878 atl1_read_phy_reg(&adapter->hw, reg_num & 0x1f, &result);
883 static void mdio_write(struct net_device *netdev, int phy_id, int reg_num,
886 struct atl1_adapter *adapter = netdev_priv(netdev);
888 atl1_write_phy_reg(&adapter->hw, reg_num, val);
897 static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
899 struct atl1_adapter *adapter = netdev_priv(netdev);
903 if (!netif_running(netdev))
906 spin_lock_irqsave(&adapter->lock, flags);
907 retval = generic_mii_ioctl(&adapter->mii, if_mii(ifr), cmd, NULL);
908 spin_unlock_irqrestore(&adapter->lock, flags);
914 * atl1_setup_mem_resources - allocate Tx / RX descriptor resources
915 * @adapter: board private structure
917 * Return 0 on success, negative on failure
919 static s32 atl1_setup_ring_resources(struct atl1_adapter *adapter)
921 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
922 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
923 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
924 struct atl1_ring_header *ring_header = &adapter->ring_header;
925 struct pci_dev *pdev = adapter->pdev;
929 size = sizeof(struct atl1_buffer) * (tpd_ring->count + rfd_ring->count);
930 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL);
931 if (unlikely(!tpd_ring->buffer_info)) {
932 if (netif_msg_drv(adapter))
933 dev_err(&pdev->dev, "kzalloc failed , size = D%d\n",
937 rfd_ring->buffer_info =
938 (struct atl1_buffer *)(tpd_ring->buffer_info + tpd_ring->count);
941 * real ring DMA buffer
942 * each ring/block may need up to 8 bytes for alignment, hence the
943 * additional 40 bytes tacked onto the end.
945 ring_header->size = size =
946 sizeof(struct tx_packet_desc) * tpd_ring->count
947 + sizeof(struct rx_free_desc) * rfd_ring->count
948 + sizeof(struct rx_return_desc) * rrd_ring->count
949 + sizeof(struct coals_msg_block)
950 + sizeof(struct stats_msg_block)
953 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size,
955 if (unlikely(!ring_header->desc)) {
956 if (netif_msg_drv(adapter))
957 dev_err(&pdev->dev, "pci_alloc_consistent failed\n");
961 memset(ring_header->desc, 0, ring_header->size);
964 tpd_ring->dma = ring_header->dma;
965 offset = (tpd_ring->dma & 0x7) ? (8 - (ring_header->dma & 0x7)) : 0;
966 tpd_ring->dma += offset;
967 tpd_ring->desc = (u8 *) ring_header->desc + offset;
968 tpd_ring->size = sizeof(struct tx_packet_desc) * tpd_ring->count;
971 rfd_ring->dma = tpd_ring->dma + tpd_ring->size;
972 offset = (rfd_ring->dma & 0x7) ? (8 - (rfd_ring->dma & 0x7)) : 0;
973 rfd_ring->dma += offset;
974 rfd_ring->desc = (u8 *) tpd_ring->desc + (tpd_ring->size + offset);
975 rfd_ring->size = sizeof(struct rx_free_desc) * rfd_ring->count;
979 rrd_ring->dma = rfd_ring->dma + rfd_ring->size;
980 offset = (rrd_ring->dma & 0x7) ? (8 - (rrd_ring->dma & 0x7)) : 0;
981 rrd_ring->dma += offset;
982 rrd_ring->desc = (u8 *) rfd_ring->desc + (rfd_ring->size + offset);
983 rrd_ring->size = sizeof(struct rx_return_desc) * rrd_ring->count;
987 adapter->cmb.dma = rrd_ring->dma + rrd_ring->size;
988 offset = (adapter->cmb.dma & 0x7) ? (8 - (adapter->cmb.dma & 0x7)) : 0;
989 adapter->cmb.dma += offset;
990 adapter->cmb.cmb = (struct coals_msg_block *)
991 ((u8 *) rrd_ring->desc + (rrd_ring->size + offset));
994 adapter->smb.dma = adapter->cmb.dma + sizeof(struct coals_msg_block);
995 offset = (adapter->smb.dma & 0x7) ? (8 - (adapter->smb.dma & 0x7)) : 0;
996 adapter->smb.dma += offset;
997 adapter->smb.smb = (struct stats_msg_block *)
998 ((u8 *) adapter->cmb.cmb +
999 (sizeof(struct coals_msg_block) + offset));
1004 kfree(tpd_ring->buffer_info);
1008 static void atl1_init_ring_ptrs(struct atl1_adapter *adapter)
1010 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1011 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1012 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
1014 atomic_set(&tpd_ring->next_to_use, 0);
1015 atomic_set(&tpd_ring->next_to_clean, 0);
1017 rfd_ring->next_to_clean = 0;
1018 atomic_set(&rfd_ring->next_to_use, 0);
1020 rrd_ring->next_to_use = 0;
1021 atomic_set(&rrd_ring->next_to_clean, 0);
1025 * atl1_clean_rx_ring - Free RFD Buffers
1026 * @adapter: board private structure
1028 static void atl1_clean_rx_ring(struct atl1_adapter *adapter)
1030 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1031 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
1032 struct atl1_buffer *buffer_info;
1033 struct pci_dev *pdev = adapter->pdev;
1037 /* Free all the Rx ring sk_buffs */
1038 for (i = 0; i < rfd_ring->count; i++) {
1039 buffer_info = &rfd_ring->buffer_info[i];
1040 if (buffer_info->dma) {
1041 pci_unmap_page(pdev, buffer_info->dma,
1042 buffer_info->length, PCI_DMA_FROMDEVICE);
1043 buffer_info->dma = 0;
1045 if (buffer_info->skb) {
1046 dev_kfree_skb(buffer_info->skb);
1047 buffer_info->skb = NULL;
1051 size = sizeof(struct atl1_buffer) * rfd_ring->count;
1052 memset(rfd_ring->buffer_info, 0, size);
1054 /* Zero out the descriptor ring */
1055 memset(rfd_ring->desc, 0, rfd_ring->size);
1057 rfd_ring->next_to_clean = 0;
1058 atomic_set(&rfd_ring->next_to_use, 0);
1060 rrd_ring->next_to_use = 0;
1061 atomic_set(&rrd_ring->next_to_clean, 0);
1065 * atl1_clean_tx_ring - Free Tx Buffers
1066 * @adapter: board private structure
1068 static void atl1_clean_tx_ring(struct atl1_adapter *adapter)
1070 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1071 struct atl1_buffer *buffer_info;
1072 struct pci_dev *pdev = adapter->pdev;
1076 /* Free all the Tx ring sk_buffs */
1077 for (i = 0; i < tpd_ring->count; i++) {
1078 buffer_info = &tpd_ring->buffer_info[i];
1079 if (buffer_info->dma) {
1080 pci_unmap_page(pdev, buffer_info->dma,
1081 buffer_info->length, PCI_DMA_TODEVICE);
1082 buffer_info->dma = 0;
1086 for (i = 0; i < tpd_ring->count; i++) {
1087 buffer_info = &tpd_ring->buffer_info[i];
1088 if (buffer_info->skb) {
1089 dev_kfree_skb_any(buffer_info->skb);
1090 buffer_info->skb = NULL;
1094 size = sizeof(struct atl1_buffer) * tpd_ring->count;
1095 memset(tpd_ring->buffer_info, 0, size);
1097 /* Zero out the descriptor ring */
1098 memset(tpd_ring->desc, 0, tpd_ring->size);
1100 atomic_set(&tpd_ring->next_to_use, 0);
1101 atomic_set(&tpd_ring->next_to_clean, 0);
1105 * atl1_free_ring_resources - Free Tx / RX descriptor Resources
1106 * @adapter: board private structure
1108 * Free all transmit software resources
1110 static void atl1_free_ring_resources(struct atl1_adapter *adapter)
1112 struct pci_dev *pdev = adapter->pdev;
1113 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1114 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1115 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
1116 struct atl1_ring_header *ring_header = &adapter->ring_header;
1118 atl1_clean_tx_ring(adapter);
1119 atl1_clean_rx_ring(adapter);
1121 kfree(tpd_ring->buffer_info);
1122 pci_free_consistent(pdev, ring_header->size, ring_header->desc,
1125 tpd_ring->buffer_info = NULL;
1126 tpd_ring->desc = NULL;
1129 rfd_ring->buffer_info = NULL;
1130 rfd_ring->desc = NULL;
1133 rrd_ring->desc = NULL;
1137 static void atl1_setup_mac_ctrl(struct atl1_adapter *adapter)
1140 struct atl1_hw *hw = &adapter->hw;
1141 struct net_device *netdev = adapter->netdev;
1142 /* Config MAC CTRL Register */
1143 value = MAC_CTRL_TX_EN | MAC_CTRL_RX_EN;
1145 if (FULL_DUPLEX == adapter->link_duplex)
1146 value |= MAC_CTRL_DUPLX;
1148 value |= ((u32) ((SPEED_1000 == adapter->link_speed) ?
1149 MAC_CTRL_SPEED_1000 : MAC_CTRL_SPEED_10_100) <<
1150 MAC_CTRL_SPEED_SHIFT);
1152 value |= (MAC_CTRL_TX_FLOW | MAC_CTRL_RX_FLOW);
1154 value |= (MAC_CTRL_ADD_CRC | MAC_CTRL_PAD);
1155 /* preamble length */
1156 value |= (((u32) adapter->hw.preamble_len
1157 & MAC_CTRL_PRMLEN_MASK) << MAC_CTRL_PRMLEN_SHIFT);
1160 value |= MAC_CTRL_RMV_VLAN;
1162 if (adapter->rx_csum)
1163 value |= MAC_CTRL_RX_CHKSUM_EN;
1166 value |= MAC_CTRL_BC_EN;
1167 if (netdev->flags & IFF_PROMISC)
1168 value |= MAC_CTRL_PROMIS_EN;
1169 else if (netdev->flags & IFF_ALLMULTI)
1170 value |= MAC_CTRL_MC_ALL_EN;
1171 /* value |= MAC_CTRL_LOOPBACK; */
1172 iowrite32(value, hw->hw_addr + REG_MAC_CTRL);
1175 static u32 atl1_check_link(struct atl1_adapter *adapter)
1177 struct atl1_hw *hw = &adapter->hw;
1178 struct net_device *netdev = adapter->netdev;
1180 u16 speed, duplex, phy_data;
1183 /* MII_BMSR must read twice */
1184 atl1_read_phy_reg(hw, MII_BMSR, &phy_data);
1185 atl1_read_phy_reg(hw, MII_BMSR, &phy_data);
1186 if (!(phy_data & BMSR_LSTATUS)) {
1188 if (netif_carrier_ok(netdev)) {
1189 /* old link state: Up */
1190 if (netif_msg_link(adapter))
1191 dev_info(&adapter->pdev->dev, "link is down\n");
1192 adapter->link_speed = SPEED_0;
1193 netif_carrier_off(netdev);
1194 netif_stop_queue(netdev);
1200 ret_val = atl1_get_speed_and_duplex(hw, &speed, &duplex);
1204 switch (hw->media_type) {
1205 case MEDIA_TYPE_1000M_FULL:
1206 if (speed != SPEED_1000 || duplex != FULL_DUPLEX)
1209 case MEDIA_TYPE_100M_FULL:
1210 if (speed != SPEED_100 || duplex != FULL_DUPLEX)
1213 case MEDIA_TYPE_100M_HALF:
1214 if (speed != SPEED_100 || duplex != HALF_DUPLEX)
1217 case MEDIA_TYPE_10M_FULL:
1218 if (speed != SPEED_10 || duplex != FULL_DUPLEX)
1221 case MEDIA_TYPE_10M_HALF:
1222 if (speed != SPEED_10 || duplex != HALF_DUPLEX)
1227 /* link result is our setting */
1229 if (adapter->link_speed != speed
1230 || adapter->link_duplex != duplex) {
1231 adapter->link_speed = speed;
1232 adapter->link_duplex = duplex;
1233 atl1_setup_mac_ctrl(adapter);
1234 if (netif_msg_link(adapter))
1235 dev_info(&adapter->pdev->dev,
1236 "%s link is up %d Mbps %s\n",
1237 netdev->name, adapter->link_speed,
1238 adapter->link_duplex == FULL_DUPLEX ?
1239 "full duplex" : "half duplex");
1241 if (!netif_carrier_ok(netdev)) {
1242 /* Link down -> Up */
1243 netif_carrier_on(netdev);
1244 netif_wake_queue(netdev);
1249 /* change original link status */
1250 if (netif_carrier_ok(netdev)) {
1251 adapter->link_speed = SPEED_0;
1252 netif_carrier_off(netdev);
1253 netif_stop_queue(netdev);
1256 if (hw->media_type != MEDIA_TYPE_AUTO_SENSOR &&
1257 hw->media_type != MEDIA_TYPE_1000M_FULL) {
1258 switch (hw->media_type) {
1259 case MEDIA_TYPE_100M_FULL:
1260 phy_data = MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 |
1263 case MEDIA_TYPE_100M_HALF:
1264 phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
1266 case MEDIA_TYPE_10M_FULL:
1268 MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET;
1271 /* MEDIA_TYPE_10M_HALF: */
1272 phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
1275 atl1_write_phy_reg(hw, MII_BMCR, phy_data);
1279 /* auto-neg, insert timer to re-config phy */
1280 if (!adapter->phy_timer_pending) {
1281 adapter->phy_timer_pending = true;
1282 mod_timer(&adapter->phy_config_timer, jiffies + 3 * HZ);
1288 static void set_flow_ctrl_old(struct atl1_adapter *adapter)
1292 /* RFD Flow Control */
1293 value = adapter->rfd_ring.count;
1299 value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) |
1300 ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT);
1301 iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RXF_PAUSE_THRESH);
1303 /* RRD Flow Control */
1304 value = adapter->rrd_ring.count;
1309 value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) |
1310 ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT);
1311 iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RRD_PAUSE_THRESH);
1314 static void set_flow_ctrl_new(struct atl1_hw *hw)
1318 /* RXF Flow Control */
1319 value = ioread32(hw->hw_addr + REG_SRAM_RXF_LEN);
1326 value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) |
1327 ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT);
1328 iowrite32(value, hw->hw_addr + REG_RXQ_RXF_PAUSE_THRESH);
1330 /* RRD Flow Control */
1331 value = ioread32(hw->hw_addr + REG_SRAM_RRD_LEN);
1338 value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) |
1339 ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT);
1340 iowrite32(value, hw->hw_addr + REG_RXQ_RRD_PAUSE_THRESH);
1344 * atl1_configure - Configure Transmit&Receive Unit after Reset
1345 * @adapter: board private structure
1347 * Configure the Tx /Rx unit of the MAC after a reset.
1349 static u32 atl1_configure(struct atl1_adapter *adapter)
1351 struct atl1_hw *hw = &adapter->hw;
1354 /* clear interrupt status */
1355 iowrite32(0xffffffff, adapter->hw.hw_addr + REG_ISR);
1357 /* set MAC Address */
1358 value = (((u32) hw->mac_addr[2]) << 24) |
1359 (((u32) hw->mac_addr[3]) << 16) |
1360 (((u32) hw->mac_addr[4]) << 8) |
1361 (((u32) hw->mac_addr[5]));
1362 iowrite32(value, hw->hw_addr + REG_MAC_STA_ADDR);
1363 value = (((u32) hw->mac_addr[0]) << 8) | (((u32) hw->mac_addr[1]));
1364 iowrite32(value, hw->hw_addr + (REG_MAC_STA_ADDR + 4));
1368 /* HI base address */
1369 iowrite32((u32) ((adapter->tpd_ring.dma & 0xffffffff00000000ULL) >> 32),
1370 hw->hw_addr + REG_DESC_BASE_ADDR_HI);
1371 /* LO base address */
1372 iowrite32((u32) (adapter->rfd_ring.dma & 0x00000000ffffffffULL),
1373 hw->hw_addr + REG_DESC_RFD_ADDR_LO);
1374 iowrite32((u32) (adapter->rrd_ring.dma & 0x00000000ffffffffULL),
1375 hw->hw_addr + REG_DESC_RRD_ADDR_LO);
1376 iowrite32((u32) (adapter->tpd_ring.dma & 0x00000000ffffffffULL),
1377 hw->hw_addr + REG_DESC_TPD_ADDR_LO);
1378 iowrite32((u32) (adapter->cmb.dma & 0x00000000ffffffffULL),
1379 hw->hw_addr + REG_DESC_CMB_ADDR_LO);
1380 iowrite32((u32) (adapter->smb.dma & 0x00000000ffffffffULL),
1381 hw->hw_addr + REG_DESC_SMB_ADDR_LO);
1384 value = adapter->rrd_ring.count;
1386 value += adapter->rfd_ring.count;
1387 iowrite32(value, hw->hw_addr + REG_DESC_RFD_RRD_RING_SIZE);
1388 iowrite32(adapter->tpd_ring.count, hw->hw_addr +
1389 REG_DESC_TPD_RING_SIZE);
1392 iowrite32(1, hw->hw_addr + REG_LOAD_PTR);
1394 /* config Mailbox */
1395 value = ((atomic_read(&adapter->tpd_ring.next_to_use)
1396 & MB_TPD_PROD_INDX_MASK) << MB_TPD_PROD_INDX_SHIFT) |
1397 ((atomic_read(&adapter->rrd_ring.next_to_clean)
1398 & MB_RRD_CONS_INDX_MASK) << MB_RRD_CONS_INDX_SHIFT) |
1399 ((atomic_read(&adapter->rfd_ring.next_to_use)
1400 & MB_RFD_PROD_INDX_MASK) << MB_RFD_PROD_INDX_SHIFT);
1401 iowrite32(value, hw->hw_addr + REG_MAILBOX);
1403 /* config IPG/IFG */
1404 value = (((u32) hw->ipgt & MAC_IPG_IFG_IPGT_MASK)
1405 << MAC_IPG_IFG_IPGT_SHIFT) |
1406 (((u32) hw->min_ifg & MAC_IPG_IFG_MIFG_MASK)
1407 << MAC_IPG_IFG_MIFG_SHIFT) |
1408 (((u32) hw->ipgr1 & MAC_IPG_IFG_IPGR1_MASK)
1409 << MAC_IPG_IFG_IPGR1_SHIFT) |
1410 (((u32) hw->ipgr2 & MAC_IPG_IFG_IPGR2_MASK)
1411 << MAC_IPG_IFG_IPGR2_SHIFT);
1412 iowrite32(value, hw->hw_addr + REG_MAC_IPG_IFG);
1414 /* config Half-Duplex Control */
1415 value = ((u32) hw->lcol & MAC_HALF_DUPLX_CTRL_LCOL_MASK) |
1416 (((u32) hw->max_retry & MAC_HALF_DUPLX_CTRL_RETRY_MASK)
1417 << MAC_HALF_DUPLX_CTRL_RETRY_SHIFT) |
1418 MAC_HALF_DUPLX_CTRL_EXC_DEF_EN |
1419 (0xa << MAC_HALF_DUPLX_CTRL_ABEBT_SHIFT) |
1420 (((u32) hw->jam_ipg & MAC_HALF_DUPLX_CTRL_JAMIPG_MASK)
1421 << MAC_HALF_DUPLX_CTRL_JAMIPG_SHIFT);
1422 iowrite32(value, hw->hw_addr + REG_MAC_HALF_DUPLX_CTRL);
1424 /* set Interrupt Moderator Timer */
1425 iowrite16(adapter->imt, hw->hw_addr + REG_IRQ_MODU_TIMER_INIT);
1426 iowrite32(MASTER_CTRL_ITIMER_EN, hw->hw_addr + REG_MASTER_CTRL);
1428 /* set Interrupt Clear Timer */
1429 iowrite16(adapter->ict, hw->hw_addr + REG_CMBDISDMA_TIMER);
1431 /* set max frame size hw will accept */
1432 iowrite32(hw->max_frame_size, hw->hw_addr + REG_MTU);
1434 /* jumbo size & rrd retirement timer */
1435 value = (((u32) hw->rx_jumbo_th & RXQ_JMBOSZ_TH_MASK)
1436 << RXQ_JMBOSZ_TH_SHIFT) |
1437 (((u32) hw->rx_jumbo_lkah & RXQ_JMBO_LKAH_MASK)
1438 << RXQ_JMBO_LKAH_SHIFT) |
1439 (((u32) hw->rrd_ret_timer & RXQ_RRD_TIMER_MASK)
1440 << RXQ_RRD_TIMER_SHIFT);
1441 iowrite32(value, hw->hw_addr + REG_RXQ_JMBOSZ_RRDTIM);
1444 switch (hw->dev_rev) {
1449 set_flow_ctrl_old(adapter);
1452 set_flow_ctrl_new(hw);
1457 value = (((u32) hw->tpd_burst & TXQ_CTRL_TPD_BURST_NUM_MASK)
1458 << TXQ_CTRL_TPD_BURST_NUM_SHIFT) |
1459 (((u32) hw->txf_burst & TXQ_CTRL_TXF_BURST_NUM_MASK)
1460 << TXQ_CTRL_TXF_BURST_NUM_SHIFT) |
1461 (((u32) hw->tpd_fetch_th & TXQ_CTRL_TPD_FETCH_TH_MASK)
1462 << TXQ_CTRL_TPD_FETCH_TH_SHIFT) | TXQ_CTRL_ENH_MODE |
1464 iowrite32(value, hw->hw_addr + REG_TXQ_CTRL);
1466 /* min tpd fetch gap & tx jumbo packet size threshold for taskoffload */
1467 value = (((u32) hw->tx_jumbo_task_th & TX_JUMBO_TASK_TH_MASK)
1468 << TX_JUMBO_TASK_TH_SHIFT) |
1469 (((u32) hw->tpd_fetch_gap & TX_TPD_MIN_IPG_MASK)
1470 << TX_TPD_MIN_IPG_SHIFT);
1471 iowrite32(value, hw->hw_addr + REG_TX_JUMBO_TASK_TH_TPD_IPG);
1474 value = (((u32) hw->rfd_burst & RXQ_CTRL_RFD_BURST_NUM_MASK)
1475 << RXQ_CTRL_RFD_BURST_NUM_SHIFT) |
1476 (((u32) hw->rrd_burst & RXQ_CTRL_RRD_BURST_THRESH_MASK)
1477 << RXQ_CTRL_RRD_BURST_THRESH_SHIFT) |
1478 (((u32) hw->rfd_fetch_gap & RXQ_CTRL_RFD_PREF_MIN_IPG_MASK)
1479 << RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT) | RXQ_CTRL_CUT_THRU_EN |
1481 iowrite32(value, hw->hw_addr + REG_RXQ_CTRL);
1483 /* config DMA Engine */
1484 value = ((((u32) hw->dmar_block) & DMA_CTRL_DMAR_BURST_LEN_MASK)
1485 << DMA_CTRL_DMAR_BURST_LEN_SHIFT) |
1486 ((((u32) hw->dmaw_block) & DMA_CTRL_DMAW_BURST_LEN_MASK)
1487 << DMA_CTRL_DMAW_BURST_LEN_SHIFT) | DMA_CTRL_DMAR_EN |
1489 value |= (u32) hw->dma_ord;
1490 if (atl1_rcb_128 == hw->rcb_value)
1491 value |= DMA_CTRL_RCB_VALUE;
1492 iowrite32(value, hw->hw_addr + REG_DMA_CTRL);
1494 /* config CMB / SMB */
1495 value = (hw->cmb_tpd > adapter->tpd_ring.count) ?
1496 hw->cmb_tpd : adapter->tpd_ring.count;
1498 value |= hw->cmb_rrd;
1499 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TH);
1500 value = hw->cmb_rx_timer | ((u32) hw->cmb_tx_timer << 16);
1501 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TIMER);
1502 iowrite32(hw->smb_timer, hw->hw_addr + REG_SMB_TIMER);
1504 /* --- enable CMB / SMB */
1505 value = CSMB_CTRL_CMB_EN | CSMB_CTRL_SMB_EN;
1506 iowrite32(value, hw->hw_addr + REG_CSMB_CTRL);
1508 value = ioread32(adapter->hw.hw_addr + REG_ISR);
1509 if (unlikely((value & ISR_PHY_LINKDOWN) != 0))
1510 value = 1; /* config failed */
1514 /* clear all interrupt status */
1515 iowrite32(0x3fffffff, adapter->hw.hw_addr + REG_ISR);
1516 iowrite32(0, adapter->hw.hw_addr + REG_ISR);
1521 * atl1_pcie_patch - Patch for PCIE module
1523 static void atl1_pcie_patch(struct atl1_adapter *adapter)
1527 /* much vendor magic here */
1529 iowrite32(value, adapter->hw.hw_addr + 0x12FC);
1530 /* pcie flow control mode change */
1531 value = ioread32(adapter->hw.hw_addr + 0x1008);
1533 iowrite32(value, adapter->hw.hw_addr + 0x1008);
1537 * When ACPI resume on some VIA MotherBoard, the Interrupt Disable bit/0x400
1538 * on PCI Command register is disable.
1539 * The function enable this bit.
1540 * Brackett, 2006/03/15
1542 static void atl1_via_workaround(struct atl1_adapter *adapter)
1544 unsigned long value;
1546 value = ioread16(adapter->hw.hw_addr + PCI_COMMAND);
1547 if (value & PCI_COMMAND_INTX_DISABLE)
1548 value &= ~PCI_COMMAND_INTX_DISABLE;
1549 iowrite32(value, adapter->hw.hw_addr + PCI_COMMAND);
1552 static void atl1_inc_smb(struct atl1_adapter *adapter)
1554 struct stats_msg_block *smb = adapter->smb.smb;
1556 /* Fill out the OS statistics structure */
1557 adapter->soft_stats.rx_packets += smb->rx_ok;
1558 adapter->soft_stats.tx_packets += smb->tx_ok;
1559 adapter->soft_stats.rx_bytes += smb->rx_byte_cnt;
1560 adapter->soft_stats.tx_bytes += smb->tx_byte_cnt;
1561 adapter->soft_stats.multicast += smb->rx_mcast;
1562 adapter->soft_stats.collisions += (smb->tx_1_col + smb->tx_2_col * 2 +
1563 smb->tx_late_col + smb->tx_abort_col * adapter->hw.max_retry);
1566 adapter->soft_stats.rx_errors += (smb->rx_frag + smb->rx_fcs_err +
1567 smb->rx_len_err + smb->rx_sz_ov + smb->rx_rxf_ov +
1568 smb->rx_rrd_ov + smb->rx_align_err);
1569 adapter->soft_stats.rx_fifo_errors += smb->rx_rxf_ov;
1570 adapter->soft_stats.rx_length_errors += smb->rx_len_err;
1571 adapter->soft_stats.rx_crc_errors += smb->rx_fcs_err;
1572 adapter->soft_stats.rx_frame_errors += smb->rx_align_err;
1573 adapter->soft_stats.rx_missed_errors += (smb->rx_rrd_ov +
1576 adapter->soft_stats.rx_pause += smb->rx_pause;
1577 adapter->soft_stats.rx_rrd_ov += smb->rx_rrd_ov;
1578 adapter->soft_stats.rx_trunc += smb->rx_sz_ov;
1581 adapter->soft_stats.tx_errors += (smb->tx_late_col +
1582 smb->tx_abort_col + smb->tx_underrun + smb->tx_trunc);
1583 adapter->soft_stats.tx_fifo_errors += smb->tx_underrun;
1584 adapter->soft_stats.tx_aborted_errors += smb->tx_abort_col;
1585 adapter->soft_stats.tx_window_errors += smb->tx_late_col;
1587 adapter->soft_stats.excecol += smb->tx_abort_col;
1588 adapter->soft_stats.deffer += smb->tx_defer;
1589 adapter->soft_stats.scc += smb->tx_1_col;
1590 adapter->soft_stats.mcc += smb->tx_2_col;
1591 adapter->soft_stats.latecol += smb->tx_late_col;
1592 adapter->soft_stats.tx_underun += smb->tx_underrun;
1593 adapter->soft_stats.tx_trunc += smb->tx_trunc;
1594 adapter->soft_stats.tx_pause += smb->tx_pause;
1596 adapter->net_stats.rx_packets = adapter->soft_stats.rx_packets;
1597 adapter->net_stats.tx_packets = adapter->soft_stats.tx_packets;
1598 adapter->net_stats.rx_bytes = adapter->soft_stats.rx_bytes;
1599 adapter->net_stats.tx_bytes = adapter->soft_stats.tx_bytes;
1600 adapter->net_stats.multicast = adapter->soft_stats.multicast;
1601 adapter->net_stats.collisions = adapter->soft_stats.collisions;
1602 adapter->net_stats.rx_errors = adapter->soft_stats.rx_errors;
1603 adapter->net_stats.rx_over_errors =
1604 adapter->soft_stats.rx_missed_errors;
1605 adapter->net_stats.rx_length_errors =
1606 adapter->soft_stats.rx_length_errors;
1607 adapter->net_stats.rx_crc_errors = adapter->soft_stats.rx_crc_errors;
1608 adapter->net_stats.rx_frame_errors =
1609 adapter->soft_stats.rx_frame_errors;
1610 adapter->net_stats.rx_fifo_errors = adapter->soft_stats.rx_fifo_errors;
1611 adapter->net_stats.rx_missed_errors =
1612 adapter->soft_stats.rx_missed_errors;
1613 adapter->net_stats.tx_errors = adapter->soft_stats.tx_errors;
1614 adapter->net_stats.tx_fifo_errors = adapter->soft_stats.tx_fifo_errors;
1615 adapter->net_stats.tx_aborted_errors =
1616 adapter->soft_stats.tx_aborted_errors;
1617 adapter->net_stats.tx_window_errors =
1618 adapter->soft_stats.tx_window_errors;
1619 adapter->net_stats.tx_carrier_errors =
1620 adapter->soft_stats.tx_carrier_errors;
1623 static void atl1_update_mailbox(struct atl1_adapter *adapter)
1625 unsigned long flags;
1626 u32 tpd_next_to_use;
1627 u32 rfd_next_to_use;
1628 u32 rrd_next_to_clean;
1631 spin_lock_irqsave(&adapter->mb_lock, flags);
1633 tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use);
1634 rfd_next_to_use = atomic_read(&adapter->rfd_ring.next_to_use);
1635 rrd_next_to_clean = atomic_read(&adapter->rrd_ring.next_to_clean);
1637 value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) <<
1638 MB_RFD_PROD_INDX_SHIFT) |
1639 ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) <<
1640 MB_RRD_CONS_INDX_SHIFT) |
1641 ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) <<
1642 MB_TPD_PROD_INDX_SHIFT);
1643 iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX);
1645 spin_unlock_irqrestore(&adapter->mb_lock, flags);
1648 static void atl1_clean_alloc_flag(struct atl1_adapter *adapter,
1649 struct rx_return_desc *rrd, u16 offset)
1651 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1653 while (rfd_ring->next_to_clean != (rrd->buf_indx + offset)) {
1654 rfd_ring->buffer_info[rfd_ring->next_to_clean].alloced = 0;
1655 if (++rfd_ring->next_to_clean == rfd_ring->count) {
1656 rfd_ring->next_to_clean = 0;
1661 static void atl1_update_rfd_index(struct atl1_adapter *adapter,
1662 struct rx_return_desc *rrd)
1666 num_buf = (rrd->xsz.xsum_sz.pkt_size + adapter->rx_buffer_len - 1) /
1667 adapter->rx_buffer_len;
1668 if (rrd->num_buf == num_buf)
1669 /* clean alloc flag for bad rrd */
1670 atl1_clean_alloc_flag(adapter, rrd, num_buf);
1673 static void atl1_rx_checksum(struct atl1_adapter *adapter,
1674 struct rx_return_desc *rrd, struct sk_buff *skb)
1676 struct pci_dev *pdev = adapter->pdev;
1678 skb->ip_summed = CHECKSUM_NONE;
1680 if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) {
1681 if (rrd->err_flg & (ERR_FLAG_CRC | ERR_FLAG_TRUNC |
1682 ERR_FLAG_CODE | ERR_FLAG_OV)) {
1683 adapter->hw_csum_err++;
1684 if (netif_msg_rx_err(adapter))
1685 dev_printk(KERN_DEBUG, &pdev->dev,
1686 "rx checksum error\n");
1692 if (!(rrd->pkt_flg & PACKET_FLAG_IPV4))
1693 /* checksum is invalid, but it's not an IPv4 pkt, so ok */
1697 if (likely(!(rrd->err_flg &
1698 (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM)))) {
1699 skb->ip_summed = CHECKSUM_UNNECESSARY;
1700 adapter->hw_csum_good++;
1704 /* IPv4, but hardware thinks its checksum is wrong */
1705 if (netif_msg_rx_err(adapter))
1706 dev_printk(KERN_DEBUG, &pdev->dev,
1707 "hw csum wrong, pkt_flag:%x, err_flag:%x\n",
1708 rrd->pkt_flg, rrd->err_flg);
1709 skb->ip_summed = CHECKSUM_COMPLETE;
1710 skb->csum = htons(rrd->xsz.xsum_sz.rx_chksum);
1711 adapter->hw_csum_err++;
1716 * atl1_alloc_rx_buffers - Replace used receive buffers
1717 * @adapter: address of board private structure
1719 static u16 atl1_alloc_rx_buffers(struct atl1_adapter *adapter)
1721 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1722 struct pci_dev *pdev = adapter->pdev;
1724 unsigned long offset;
1725 struct atl1_buffer *buffer_info, *next_info;
1726 struct sk_buff *skb;
1728 u16 rfd_next_to_use, next_next;
1729 struct rx_free_desc *rfd_desc;
1731 next_next = rfd_next_to_use = atomic_read(&rfd_ring->next_to_use);
1732 if (++next_next == rfd_ring->count)
1734 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1735 next_info = &rfd_ring->buffer_info[next_next];
1737 while (!buffer_info->alloced && !next_info->alloced) {
1738 if (buffer_info->skb) {
1739 buffer_info->alloced = 1;
1743 rfd_desc = ATL1_RFD_DESC(rfd_ring, rfd_next_to_use);
1745 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1746 if (unlikely(!skb)) {
1747 /* Better luck next round */
1748 adapter->net_stats.rx_dropped++;
1753 * Make buffer alignment 2 beyond a 16 byte boundary
1754 * this will result in a 16 byte aligned IP header after
1755 * the 14 byte MAC header is removed
1757 skb_reserve(skb, NET_IP_ALIGN);
1759 buffer_info->alloced = 1;
1760 buffer_info->skb = skb;
1761 buffer_info->length = (u16) adapter->rx_buffer_len;
1762 page = virt_to_page(skb->data);
1763 offset = (unsigned long)skb->data & ~PAGE_MASK;
1764 buffer_info->dma = pci_map_page(pdev, page, offset,
1765 adapter->rx_buffer_len,
1766 PCI_DMA_FROMDEVICE);
1767 rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
1768 rfd_desc->buf_len = cpu_to_le16(adapter->rx_buffer_len);
1769 rfd_desc->coalese = 0;
1772 rfd_next_to_use = next_next;
1773 if (unlikely(++next_next == rfd_ring->count))
1776 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1777 next_info = &rfd_ring->buffer_info[next_next];
1783 * Force memory writes to complete before letting h/w
1784 * know there are new descriptors to fetch. (Only
1785 * applicable for weak-ordered memory model archs,
1789 atomic_set(&rfd_ring->next_to_use, (int)rfd_next_to_use);
1794 static void atl1_intr_rx(struct atl1_adapter *adapter)
1798 u16 rrd_next_to_clean;
1800 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1801 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
1802 struct atl1_buffer *buffer_info;
1803 struct rx_return_desc *rrd;
1804 struct sk_buff *skb;
1808 rrd_next_to_clean = atomic_read(&rrd_ring->next_to_clean);
1811 rrd = ATL1_RRD_DESC(rrd_ring, rrd_next_to_clean);
1813 if (likely(rrd->xsz.valid)) { /* packet valid */
1815 /* check rrd status */
1816 if (likely(rrd->num_buf == 1))
1818 else if (netif_msg_rx_err(adapter)) {
1819 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1820 "unexpected RRD buffer count\n");
1821 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1822 "rx_buf_len = %d\n",
1823 adapter->rx_buffer_len);
1824 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1825 "RRD num_buf = %d\n",
1827 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1828 "RRD pkt_len = %d\n",
1829 rrd->xsz.xsum_sz.pkt_size);
1830 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1831 "RRD pkt_flg = 0x%08X\n",
1833 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1834 "RRD err_flg = 0x%08X\n",
1836 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1837 "RRD vlan_tag = 0x%08X\n",
1841 /* rrd seems to be bad */
1842 if (unlikely(i-- > 0)) {
1843 /* rrd may not be DMAed completely */
1848 if (netif_msg_rx_err(adapter))
1849 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1851 /* see if update RFD index */
1852 if (rrd->num_buf > 1)
1853 atl1_update_rfd_index(adapter, rrd);
1857 if (++rrd_next_to_clean == rrd_ring->count)
1858 rrd_next_to_clean = 0;
1861 } else { /* current rrd still not be updated */
1866 /* clean alloc flag for bad rrd */
1867 atl1_clean_alloc_flag(adapter, rrd, 0);
1869 buffer_info = &rfd_ring->buffer_info[rrd->buf_indx];
1870 if (++rfd_ring->next_to_clean == rfd_ring->count)
1871 rfd_ring->next_to_clean = 0;
1873 /* update rrd next to clean */
1874 if (++rrd_next_to_clean == rrd_ring->count)
1875 rrd_next_to_clean = 0;
1878 if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) {
1879 if (!(rrd->err_flg &
1880 (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM
1882 /* packet error, don't need upstream */
1883 buffer_info->alloced = 0;
1890 pci_unmap_page(adapter->pdev, buffer_info->dma,
1891 buffer_info->length, PCI_DMA_FROMDEVICE);
1892 skb = buffer_info->skb;
1893 length = le16_to_cpu(rrd->xsz.xsum_sz.pkt_size);
1895 skb_put(skb, length - ETH_FCS_LEN);
1897 /* Receive Checksum Offload */
1898 atl1_rx_checksum(adapter, rrd, skb);
1899 skb->protocol = eth_type_trans(skb, adapter->netdev);
1901 if (adapter->vlgrp && (rrd->pkt_flg & PACKET_FLAG_VLAN_INS)) {
1902 u16 vlan_tag = (rrd->vlan_tag >> 4) |
1903 ((rrd->vlan_tag & 7) << 13) |
1904 ((rrd->vlan_tag & 8) << 9);
1905 vlan_hwaccel_rx(skb, adapter->vlgrp, vlan_tag);
1909 /* let protocol layer free skb */
1910 buffer_info->skb = NULL;
1911 buffer_info->alloced = 0;
1914 adapter->netdev->last_rx = jiffies;
1917 atomic_set(&rrd_ring->next_to_clean, rrd_next_to_clean);
1919 atl1_alloc_rx_buffers(adapter);
1921 /* update mailbox ? */
1923 u32 tpd_next_to_use;
1924 u32 rfd_next_to_use;
1926 spin_lock(&adapter->mb_lock);
1928 tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use);
1930 atomic_read(&adapter->rfd_ring.next_to_use);
1932 atomic_read(&adapter->rrd_ring.next_to_clean);
1933 value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) <<
1934 MB_RFD_PROD_INDX_SHIFT) |
1935 ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) <<
1936 MB_RRD_CONS_INDX_SHIFT) |
1937 ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) <<
1938 MB_TPD_PROD_INDX_SHIFT);
1939 iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX);
1940 spin_unlock(&adapter->mb_lock);
1944 static void atl1_intr_tx(struct atl1_adapter *adapter)
1946 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1947 struct atl1_buffer *buffer_info;
1948 u16 sw_tpd_next_to_clean;
1949 u16 cmb_tpd_next_to_clean;
1951 sw_tpd_next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1952 cmb_tpd_next_to_clean = le16_to_cpu(adapter->cmb.cmb->tpd_cons_idx);
1954 while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) {
1955 struct tx_packet_desc *tpd;
1957 tpd = ATL1_TPD_DESC(tpd_ring, sw_tpd_next_to_clean);
1958 buffer_info = &tpd_ring->buffer_info[sw_tpd_next_to_clean];
1959 if (buffer_info->dma) {
1960 pci_unmap_page(adapter->pdev, buffer_info->dma,
1961 buffer_info->length, PCI_DMA_TODEVICE);
1962 buffer_info->dma = 0;
1965 if (buffer_info->skb) {
1966 dev_kfree_skb_irq(buffer_info->skb);
1967 buffer_info->skb = NULL;
1970 if (++sw_tpd_next_to_clean == tpd_ring->count)
1971 sw_tpd_next_to_clean = 0;
1973 atomic_set(&tpd_ring->next_to_clean, sw_tpd_next_to_clean);
1975 if (netif_queue_stopped(adapter->netdev)
1976 && netif_carrier_ok(adapter->netdev))
1977 netif_wake_queue(adapter->netdev);
1980 static u16 atl1_tpd_avail(struct atl1_tpd_ring *tpd_ring)
1982 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1983 u16 next_to_use = atomic_read(&tpd_ring->next_to_use);
1984 return ((next_to_clean > next_to_use) ?
1985 next_to_clean - next_to_use - 1 :
1986 tpd_ring->count + next_to_clean - next_to_use - 1);
1989 static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb,
1990 struct tx_packet_desc *ptpd)
1997 if (skb_shinfo(skb)->gso_size) {
1998 if (skb_header_cloned(skb)) {
1999 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2004 if (skb->protocol == ntohs(ETH_P_IP)) {
2005 struct iphdr *iph = ip_hdr(skb);
2007 real_len = (((unsigned char *)iph - skb->data) +
2008 ntohs(iph->tot_len));
2009 if (real_len < skb->len)
2010 pskb_trim(skb, real_len);
2011 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
2012 if (skb->len == hdr_len) {
2014 tcp_hdr(skb)->check =
2015 ~csum_tcpudp_magic(iph->saddr,
2016 iph->daddr, tcp_hdrlen(skb),
2018 ptpd->word3 |= (iph->ihl & TPD_IPHL_MASK) <<
2020 ptpd->word3 |= ((tcp_hdrlen(skb) >> 2) &
2021 TPD_TCPHDRLEN_MASK) <<
2022 TPD_TCPHDRLEN_SHIFT;
2023 ptpd->word3 |= 1 << TPD_IP_CSUM_SHIFT;
2024 ptpd->word3 |= 1 << TPD_TCP_CSUM_SHIFT;
2029 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2030 iph->daddr, 0, IPPROTO_TCP, 0);
2031 ip_off = (unsigned char *)iph -
2032 (unsigned char *) skb_network_header(skb);
2033 if (ip_off == 8) /* 802.3-SNAP frame */
2034 ptpd->word3 |= 1 << TPD_ETHTYPE_SHIFT;
2035 else if (ip_off != 0)
2038 ptpd->word3 |= (iph->ihl & TPD_IPHL_MASK) <<
2040 ptpd->word3 |= ((tcp_hdrlen(skb) >> 2) &
2041 TPD_TCPHDRLEN_MASK) << TPD_TCPHDRLEN_SHIFT;
2042 ptpd->word3 |= (skb_shinfo(skb)->gso_size &
2043 TPD_MSS_MASK) << TPD_MSS_SHIFT;
2044 ptpd->word3 |= 1 << TPD_SEGMENT_EN_SHIFT;
2051 static int atl1_tx_csum(struct atl1_adapter *adapter, struct sk_buff *skb,
2052 struct tx_packet_desc *ptpd)
2056 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
2057 css = (u8) (skb->csum_start - skb_headroom(skb));
2058 cso = css + (u8) skb->csum_offset;
2059 if (unlikely(css & 0x1)) {
2060 /* L1 hardware requires an even number here */
2061 if (netif_msg_tx_err(adapter))
2062 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
2063 "payload offset not an even number\n");
2066 ptpd->word3 |= (css & TPD_PLOADOFFSET_MASK) <<
2067 TPD_PLOADOFFSET_SHIFT;
2068 ptpd->word3 |= (cso & TPD_CCSUMOFFSET_MASK) <<
2069 TPD_CCSUMOFFSET_SHIFT;
2070 ptpd->word3 |= 1 << TPD_CUST_CSUM_EN_SHIFT;
2076 static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
2077 struct tx_packet_desc *ptpd)
2080 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
2081 struct atl1_buffer *buffer_info;
2082 u16 buf_len = skb->len;
2084 unsigned long offset;
2085 unsigned int nr_frags;
2092 buf_len -= skb->data_len;
2093 nr_frags = skb_shinfo(skb)->nr_frags;
2094 next_to_use = atomic_read(&tpd_ring->next_to_use);
2095 buffer_info = &tpd_ring->buffer_info[next_to_use];
2096 if (unlikely(buffer_info->skb))
2098 /* put skb in last TPD */
2099 buffer_info->skb = NULL;
2101 retval = (ptpd->word3 >> TPD_SEGMENT_EN_SHIFT) & TPD_SEGMENT_EN_MASK;
2104 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2105 buffer_info->length = hdr_len;
2106 page = virt_to_page(skb->data);
2107 offset = (unsigned long)skb->data & ~PAGE_MASK;
2108 buffer_info->dma = pci_map_page(adapter->pdev, page,
2112 if (++next_to_use == tpd_ring->count)
2115 if (buf_len > hdr_len) {
2118 data_len = buf_len - hdr_len;
2119 nseg = (data_len + ATL1_MAX_TX_BUF_LEN - 1) /
2120 ATL1_MAX_TX_BUF_LEN;
2121 for (i = 0; i < nseg; i++) {
2123 &tpd_ring->buffer_info[next_to_use];
2124 buffer_info->skb = NULL;
2125 buffer_info->length =
2126 (ATL1_MAX_TX_BUF_LEN >=
2127 data_len) ? ATL1_MAX_TX_BUF_LEN : data_len;
2128 data_len -= buffer_info->length;
2129 page = virt_to_page(skb->data +
2130 (hdr_len + i * ATL1_MAX_TX_BUF_LEN));
2131 offset = (unsigned long)(skb->data +
2132 (hdr_len + i * ATL1_MAX_TX_BUF_LEN)) &
2134 buffer_info->dma = pci_map_page(adapter->pdev,
2135 page, offset, buffer_info->length,
2137 if (++next_to_use == tpd_ring->count)
2143 buffer_info->length = buf_len;
2144 page = virt_to_page(skb->data);
2145 offset = (unsigned long)skb->data & ~PAGE_MASK;
2146 buffer_info->dma = pci_map_page(adapter->pdev, page,
2147 offset, buf_len, PCI_DMA_TODEVICE);
2148 if (++next_to_use == tpd_ring->count)
2152 for (f = 0; f < nr_frags; f++) {
2153 struct skb_frag_struct *frag;
2156 frag = &skb_shinfo(skb)->frags[f];
2157 buf_len = frag->size;
2159 nseg = (buf_len + ATL1_MAX_TX_BUF_LEN - 1) /
2160 ATL1_MAX_TX_BUF_LEN;
2161 for (i = 0; i < nseg; i++) {
2162 buffer_info = &tpd_ring->buffer_info[next_to_use];
2163 if (unlikely(buffer_info->skb))
2165 buffer_info->skb = NULL;
2166 buffer_info->length = (buf_len > ATL1_MAX_TX_BUF_LEN) ?
2167 ATL1_MAX_TX_BUF_LEN : buf_len;
2168 buf_len -= buffer_info->length;
2169 buffer_info->dma = pci_map_page(adapter->pdev,
2171 frag->page_offset + (i * ATL1_MAX_TX_BUF_LEN),
2172 buffer_info->length, PCI_DMA_TODEVICE);
2174 if (++next_to_use == tpd_ring->count)
2179 /* last tpd's buffer-info */
2180 buffer_info->skb = skb;
2183 static void atl1_tx_queue(struct atl1_adapter *adapter, u16 count,
2184 struct tx_packet_desc *ptpd)
2187 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
2188 struct atl1_buffer *buffer_info;
2189 struct tx_packet_desc *tpd;
2192 u16 next_to_use = (u16) atomic_read(&tpd_ring->next_to_use);
2194 for (j = 0; j < count; j++) {
2195 buffer_info = &tpd_ring->buffer_info[next_to_use];
2196 tpd = ATL1_TPD_DESC(&adapter->tpd_ring, next_to_use);
2198 memcpy(tpd, ptpd, sizeof(struct tx_packet_desc));
2199 tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2200 tpd->word2 = (cpu_to_le16(buffer_info->length) &
2201 TPD_BUFLEN_MASK) << TPD_BUFLEN_SHIFT;
2204 * if this is the first packet in a TSO chain, set
2205 * TPD_HDRFLAG, otherwise, clear it.
2207 val = (tpd->word3 >> TPD_SEGMENT_EN_SHIFT) &
2208 TPD_SEGMENT_EN_MASK;
2211 tpd->word3 |= 1 << TPD_HDRFLAG_SHIFT;
2213 tpd->word3 &= ~(1 << TPD_HDRFLAG_SHIFT);
2216 if (j == (count - 1))
2217 tpd->word3 |= 1 << TPD_EOP_SHIFT;
2219 if (++next_to_use == tpd_ring->count)
2223 * Force memory writes to complete before letting h/w
2224 * know there are new descriptors to fetch. (Only
2225 * applicable for weak-ordered memory model archs,
2230 atomic_set(&tpd_ring->next_to_use, next_to_use);
2233 static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2235 struct atl1_adapter *adapter = netdev_priv(netdev);
2236 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
2241 struct tx_packet_desc *ptpd;
2244 unsigned long flags;
2245 unsigned int nr_frags = 0;
2246 unsigned int mss = 0;
2248 unsigned int proto_hdr_len;
2250 len -= skb->data_len;
2252 if (unlikely(skb->len <= 0)) {
2253 dev_kfree_skb_any(skb);
2254 return NETDEV_TX_OK;
2257 nr_frags = skb_shinfo(skb)->nr_frags;
2258 for (f = 0; f < nr_frags; f++) {
2259 frag_size = skb_shinfo(skb)->frags[f].size;
2261 count += (frag_size + ATL1_MAX_TX_BUF_LEN - 1) /
2262 ATL1_MAX_TX_BUF_LEN;
2265 mss = skb_shinfo(skb)->gso_size;
2267 if (skb->protocol == ntohs(ETH_P_IP)) {
2268 proto_hdr_len = (skb_transport_offset(skb) +
2270 if (unlikely(proto_hdr_len > len)) {
2271 dev_kfree_skb_any(skb);
2272 return NETDEV_TX_OK;
2274 /* need additional TPD ? */
2275 if (proto_hdr_len != len)
2276 count += (len - proto_hdr_len +
2277 ATL1_MAX_TX_BUF_LEN - 1) /
2278 ATL1_MAX_TX_BUF_LEN;
2282 if (!spin_trylock_irqsave(&adapter->lock, flags)) {
2283 /* Can't get lock - tell upper layer to requeue */
2284 if (netif_msg_tx_queued(adapter))
2285 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
2287 return NETDEV_TX_LOCKED;
2290 if (atl1_tpd_avail(&adapter->tpd_ring) < count) {
2291 /* not enough descriptors */
2292 netif_stop_queue(netdev);
2293 spin_unlock_irqrestore(&adapter->lock, flags);
2294 if (netif_msg_tx_queued(adapter))
2295 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
2297 return NETDEV_TX_BUSY;
2300 ptpd = ATL1_TPD_DESC(tpd_ring,
2301 (u16) atomic_read(&tpd_ring->next_to_use));
2302 memset(ptpd, 0, sizeof(struct tx_packet_desc));
2304 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
2305 vlan_tag = vlan_tx_tag_get(skb);
2306 vlan_tag = (vlan_tag << 4) | (vlan_tag >> 13) |
2307 ((vlan_tag >> 9) & 0x8);
2308 ptpd->word3 |= 1 << TPD_INS_VL_TAG_SHIFT;
2309 ptpd->word3 |= (vlan_tag & TPD_VL_TAGGED_MASK) <<
2310 TPD_VL_TAGGED_SHIFT;
2313 tso = atl1_tso(adapter, skb, ptpd);
2315 spin_unlock_irqrestore(&adapter->lock, flags);
2316 dev_kfree_skb_any(skb);
2317 return NETDEV_TX_OK;
2321 ret_val = atl1_tx_csum(adapter, skb, ptpd);
2323 spin_unlock_irqrestore(&adapter->lock, flags);
2324 dev_kfree_skb_any(skb);
2325 return NETDEV_TX_OK;
2329 atl1_tx_map(adapter, skb, ptpd);
2330 atl1_tx_queue(adapter, count, ptpd);
2331 atl1_update_mailbox(adapter);
2332 spin_unlock_irqrestore(&adapter->lock, flags);
2333 netdev->trans_start = jiffies;
2334 return NETDEV_TX_OK;
2338 * atl1_intr - Interrupt Handler
2339 * @irq: interrupt number
2340 * @data: pointer to a network interface device structure
2341 * @pt_regs: CPU registers structure
2343 static irqreturn_t atl1_intr(int irq, void *data)
2345 struct atl1_adapter *adapter = netdev_priv(data);
2349 status = adapter->cmb.cmb->int_stats;
2354 /* clear CMB interrupt status at once */
2355 adapter->cmb.cmb->int_stats = 0;
2357 if (status & ISR_GPHY) /* clear phy status */
2358 atlx_clear_phy_int(adapter);
2360 /* clear ISR status, and Enable CMB DMA/Disable Interrupt */
2361 iowrite32(status | ISR_DIS_INT, adapter->hw.hw_addr + REG_ISR);
2363 /* check if SMB intr */
2364 if (status & ISR_SMB)
2365 atl1_inc_smb(adapter);
2367 /* check if PCIE PHY Link down */
2368 if (status & ISR_PHY_LINKDOWN) {
2369 if (netif_msg_intr(adapter))
2370 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
2371 "pcie phy link down %x\n", status);
2372 if (netif_running(adapter->netdev)) { /* reset MAC */
2373 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
2374 schedule_work(&adapter->pcie_dma_to_rst_task);
2379 /* check if DMA read/write error ? */
2380 if (status & (ISR_DMAR_TO_RST | ISR_DMAW_TO_RST)) {
2381 if (netif_msg_intr(adapter))
2382 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
2383 "pcie DMA r/w error (status = 0x%x)\n",
2385 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
2386 schedule_work(&adapter->pcie_dma_to_rst_task);
2391 if (status & ISR_GPHY) {
2392 adapter->soft_stats.tx_carrier_errors++;
2393 atl1_check_for_link(adapter);
2396 /* transmit event */
2397 if (status & ISR_CMB_TX)
2398 atl1_intr_tx(adapter);
2401 if (unlikely(status & (ISR_RXF_OV | ISR_RFD_UNRUN |
2402 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
2403 ISR_HOST_RRD_OV | ISR_CMB_RX))) {
2404 if (status & (ISR_RXF_OV | ISR_RFD_UNRUN |
2405 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
2407 if (netif_msg_intr(adapter))
2408 dev_printk(KERN_DEBUG,
2409 &adapter->pdev->dev,
2410 "rx exception, ISR = 0x%x\n",
2412 atl1_intr_rx(adapter);
2418 } while ((status = adapter->cmb.cmb->int_stats));
2420 /* re-enable Interrupt */
2421 iowrite32(ISR_DIS_SMB | ISR_DIS_DMA, adapter->hw.hw_addr + REG_ISR);
2426 * atl1_watchdog - Timer Call-back
2427 * @data: pointer to netdev cast into an unsigned long
2429 static void atl1_watchdog(unsigned long data)
2431 struct atl1_adapter *adapter = (struct atl1_adapter *)data;
2433 /* Reset the timer */
2434 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2438 * atl1_phy_config - Timer Call-back
2439 * @data: pointer to netdev cast into an unsigned long
2441 static void atl1_phy_config(unsigned long data)
2443 struct atl1_adapter *adapter = (struct atl1_adapter *)data;
2444 struct atl1_hw *hw = &adapter->hw;
2445 unsigned long flags;
2447 spin_lock_irqsave(&adapter->lock, flags);
2448 adapter->phy_timer_pending = false;
2449 atl1_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
2450 atl1_write_phy_reg(hw, MII_ATLX_CR, hw->mii_1000t_ctrl_reg);
2451 atl1_write_phy_reg(hw, MII_BMCR, MII_CR_RESET | MII_CR_AUTO_NEG_EN);
2452 spin_unlock_irqrestore(&adapter->lock, flags);
2456 * Orphaned vendor comment left intact here:
2458 * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT
2459 * will assert. We do soft reset <0x1400=1> according
2460 * with the SPEC. BUT, it seemes that PCIE or DMA
2461 * state-machine will not be reset. DMAR_TO_INT will
2462 * assert again and again.
2466 static int atl1_reset(struct atl1_adapter *adapter)
2469 ret = atl1_reset_hw(&adapter->hw);
2472 return atl1_init_hw(&adapter->hw);
2475 static s32 atl1_up(struct atl1_adapter *adapter)
2477 struct net_device *netdev = adapter->netdev;
2479 int irq_flags = IRQF_SAMPLE_RANDOM;
2481 /* hardware has been reset, we need to reload some things */
2482 atlx_set_multi(netdev);
2483 atl1_init_ring_ptrs(adapter);
2484 atlx_restore_vlan(adapter);
2485 err = atl1_alloc_rx_buffers(adapter);
2487 /* no RX BUFFER allocated */
2490 if (unlikely(atl1_configure(adapter))) {
2495 err = pci_enable_msi(adapter->pdev);
2497 if (netif_msg_ifup(adapter))
2498 dev_info(&adapter->pdev->dev,
2499 "Unable to enable MSI: %d\n", err);
2500 irq_flags |= IRQF_SHARED;
2503 err = request_irq(adapter->pdev->irq, &atl1_intr, irq_flags,
2504 netdev->name, netdev);
2508 mod_timer(&adapter->watchdog_timer, jiffies);
2509 atlx_irq_enable(adapter);
2510 atl1_check_link(adapter);
2514 pci_disable_msi(adapter->pdev);
2515 /* free rx_buffers */
2516 atl1_clean_rx_ring(adapter);
2520 static void atl1_down(struct atl1_adapter *adapter)
2522 struct net_device *netdev = adapter->netdev;
2524 del_timer_sync(&adapter->watchdog_timer);
2525 del_timer_sync(&adapter->phy_config_timer);
2526 adapter->phy_timer_pending = false;
2528 atlx_irq_disable(adapter);
2529 free_irq(adapter->pdev->irq, netdev);
2530 pci_disable_msi(adapter->pdev);
2531 atl1_reset_hw(&adapter->hw);
2532 adapter->cmb.cmb->int_stats = 0;
2534 adapter->link_speed = SPEED_0;
2535 adapter->link_duplex = -1;
2536 netif_carrier_off(netdev);
2537 netif_stop_queue(netdev);
2539 atl1_clean_tx_ring(adapter);
2540 atl1_clean_rx_ring(adapter);
2543 static void atl1_tx_timeout_task(struct work_struct *work)
2545 struct atl1_adapter *adapter =
2546 container_of(work, struct atl1_adapter, tx_timeout_task);
2547 struct net_device *netdev = adapter->netdev;
2549 netif_device_detach(netdev);
2552 netif_device_attach(netdev);
2556 * atl1_change_mtu - Change the Maximum Transfer Unit
2557 * @netdev: network interface device structure
2558 * @new_mtu: new value for maximum frame size
2560 * Returns 0 on success, negative on failure
2562 static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
2564 struct atl1_adapter *adapter = netdev_priv(netdev);
2565 int old_mtu = netdev->mtu;
2566 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2568 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
2569 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2570 if (netif_msg_link(adapter))
2571 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
2575 adapter->hw.max_frame_size = max_frame;
2576 adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3;
2577 adapter->rx_buffer_len = (max_frame + 7) & ~7;
2578 adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8;
2580 netdev->mtu = new_mtu;
2581 if ((old_mtu != new_mtu) && netif_running(netdev)) {
2590 * atl1_open - Called when a network interface is made active
2591 * @netdev: network interface device structure
2593 * Returns 0 on success, negative value on failure
2595 * The open entry point is called when a network interface is made
2596 * active by the system (IFF_UP). At this point all resources needed
2597 * for transmit and receive operations are allocated, the interrupt
2598 * handler is registered with the OS, the watchdog timer is started,
2599 * and the stack is notified that the interface is ready.
2601 static int atl1_open(struct net_device *netdev)
2603 struct atl1_adapter *adapter = netdev_priv(netdev);
2606 /* allocate transmit descriptors */
2607 err = atl1_setup_ring_resources(adapter);
2611 err = atl1_up(adapter);
2618 atl1_reset(adapter);
2623 * atl1_close - Disables a network interface
2624 * @netdev: network interface device structure
2626 * Returns 0, this is not allowed to fail
2628 * The close entry point is called when an interface is de-activated
2629 * by the OS. The hardware is still under the drivers control, but
2630 * needs to be disabled. A global MAC reset is issued to stop the
2631 * hardware, and all transmit and receive resources are freed.
2633 static int atl1_close(struct net_device *netdev)
2635 struct atl1_adapter *adapter = netdev_priv(netdev);
2637 atl1_free_ring_resources(adapter);
2642 static int atl1_suspend(struct pci_dev *pdev, pm_message_t state)
2644 struct net_device *netdev = pci_get_drvdata(pdev);
2645 struct atl1_adapter *adapter = netdev_priv(netdev);
2646 struct atl1_hw *hw = &adapter->hw;
2648 u32 wufc = adapter->wol;
2650 netif_device_detach(netdev);
2651 if (netif_running(netdev))
2654 atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl);
2655 atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl);
2656 if (ctrl & BMSR_LSTATUS)
2657 wufc &= ~ATLX_WUFC_LNKC;
2659 /* reduce speed to 10/100M */
2661 atl1_phy_enter_power_saving(hw);
2662 /* if resume, let driver to re- setup link */
2663 hw->phy_configured = false;
2664 atl1_set_mac_addr(hw);
2665 atlx_set_multi(netdev);
2668 /* turn on magic packet wol */
2669 if (wufc & ATLX_WUFC_MAG)
2670 ctrl = WOL_MAGIC_EN | WOL_MAGIC_PME_EN;
2672 /* turn on Link change WOL */
2673 if (wufc & ATLX_WUFC_LNKC)
2674 ctrl |= (WOL_LINK_CHG_EN | WOL_LINK_CHG_PME_EN);
2675 iowrite32(ctrl, hw->hw_addr + REG_WOL_CTRL);
2677 /* turn on all-multi mode if wake on multicast is enabled */
2678 ctrl = ioread32(hw->hw_addr + REG_MAC_CTRL);
2679 ctrl &= ~MAC_CTRL_DBG;
2680 ctrl &= ~MAC_CTRL_PROMIS_EN;
2681 if (wufc & ATLX_WUFC_MC)
2682 ctrl |= MAC_CTRL_MC_ALL_EN;
2684 ctrl &= ~MAC_CTRL_MC_ALL_EN;
2686 /* turn on broadcast mode if wake on-BC is enabled */
2687 if (wufc & ATLX_WUFC_BC)
2688 ctrl |= MAC_CTRL_BC_EN;
2690 ctrl &= ~MAC_CTRL_BC_EN;
2693 ctrl |= MAC_CTRL_RX_EN;
2694 iowrite32(ctrl, hw->hw_addr + REG_MAC_CTRL);
2695 pci_enable_wake(pdev, PCI_D3hot, 1);
2696 pci_enable_wake(pdev, PCI_D3cold, 1);
2698 iowrite32(0, hw->hw_addr + REG_WOL_CTRL);
2699 pci_enable_wake(pdev, PCI_D3hot, 0);
2700 pci_enable_wake(pdev, PCI_D3cold, 0);
2703 pci_save_state(pdev);
2704 pci_disable_device(pdev);
2706 pci_set_power_state(pdev, PCI_D3hot);
2711 static int atl1_resume(struct pci_dev *pdev)
2713 struct net_device *netdev = pci_get_drvdata(pdev);
2714 struct atl1_adapter *adapter = netdev_priv(netdev);
2717 pci_set_power_state(pdev, PCI_D0);
2718 pci_restore_state(pdev);
2720 /* FIXME: check and handle */
2721 err = pci_enable_device(pdev);
2722 pci_enable_wake(pdev, PCI_D3hot, 0);
2723 pci_enable_wake(pdev, PCI_D3cold, 0);
2725 iowrite32(0, adapter->hw.hw_addr + REG_WOL_CTRL);
2726 atl1_reset(adapter);
2728 if (netif_running(netdev))
2730 netif_device_attach(netdev);
2732 atl1_via_workaround(adapter);
2737 #define atl1_suspend NULL
2738 #define atl1_resume NULL
2741 #ifdef CONFIG_NET_POLL_CONTROLLER
2742 static void atl1_poll_controller(struct net_device *netdev)
2744 disable_irq(netdev->irq);
2745 atl1_intr(netdev->irq, netdev);
2746 enable_irq(netdev->irq);
2751 * atl1_probe - Device Initialization Routine
2752 * @pdev: PCI device information struct
2753 * @ent: entry in atl1_pci_tbl
2755 * Returns 0 on success, negative on failure
2757 * atl1_probe initializes an adapter identified by a pci_dev structure.
2758 * The OS initialization, configuring of the adapter private structure,
2759 * and a hardware reset occur.
2761 static int __devinit atl1_probe(struct pci_dev *pdev,
2762 const struct pci_device_id *ent)
2764 struct net_device *netdev;
2765 struct atl1_adapter *adapter;
2766 static int cards_found = 0;
2769 err = pci_enable_device(pdev);
2774 * The atl1 chip can DMA to 64-bit addresses, but it uses a single
2775 * shared register for the high 32 bits, so only a single, aligned,
2776 * 4 GB physical address range can be used at a time.
2778 * Supporting 64-bit DMA on this hardware is more trouble than it's
2779 * worth. It is far easier to limit to 32-bit DMA than update
2780 * various kernel subsystems to support the mechanics required by a
2781 * fixed-high-32-bit system.
2783 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2785 dev_err(&pdev->dev, "no usable DMA configuration\n");
2789 * Mark all PCI regions associated with PCI device
2790 * pdev as being reserved by owner atl1_driver_name
2792 err = pci_request_regions(pdev, ATLX_DRIVER_NAME);
2794 goto err_request_regions;
2797 * Enables bus-mastering on the device and calls
2798 * pcibios_set_master to do the needed arch specific settings
2800 pci_set_master(pdev);
2802 netdev = alloc_etherdev(sizeof(struct atl1_adapter));
2805 goto err_alloc_etherdev;
2807 SET_NETDEV_DEV(netdev, &pdev->dev);
2809 pci_set_drvdata(pdev, netdev);
2810 adapter = netdev_priv(netdev);
2811 adapter->netdev = netdev;
2812 adapter->pdev = pdev;
2813 adapter->hw.back = adapter;
2814 adapter->msg_enable = netif_msg_init(debug, atl1_default_msg);
2816 adapter->hw.hw_addr = pci_iomap(pdev, 0, 0);
2817 if (!adapter->hw.hw_addr) {
2821 /* get device revision number */
2822 adapter->hw.dev_rev = ioread16(adapter->hw.hw_addr +
2823 (REG_MASTER_CTRL + 2));
2824 if (netif_msg_probe(adapter))
2825 dev_info(&pdev->dev, "version %s\n", ATLX_DRIVER_VERSION);
2827 /* set default ring resource counts */
2828 adapter->rfd_ring.count = adapter->rrd_ring.count = ATL1_DEFAULT_RFD;
2829 adapter->tpd_ring.count = ATL1_DEFAULT_TPD;
2831 adapter->mii.dev = netdev;
2832 adapter->mii.mdio_read = mdio_read;
2833 adapter->mii.mdio_write = mdio_write;
2834 adapter->mii.phy_id_mask = 0x1f;
2835 adapter->mii.reg_num_mask = 0x1f;
2837 netdev->open = &atl1_open;
2838 netdev->stop = &atl1_close;
2839 netdev->hard_start_xmit = &atl1_xmit_frame;
2840 netdev->get_stats = &atlx_get_stats;
2841 netdev->set_multicast_list = &atlx_set_multi;
2842 netdev->set_mac_address = &atl1_set_mac;
2843 netdev->change_mtu = &atl1_change_mtu;
2844 netdev->do_ioctl = &atlx_ioctl;
2845 netdev->tx_timeout = &atlx_tx_timeout;
2846 netdev->watchdog_timeo = 5 * HZ;
2847 #ifdef CONFIG_NET_POLL_CONTROLLER
2848 netdev->poll_controller = atl1_poll_controller;
2850 netdev->vlan_rx_register = atlx_vlan_rx_register;
2852 netdev->ethtool_ops = &atl1_ethtool_ops;
2853 adapter->bd_number = cards_found;
2855 /* setup the private structure */
2856 err = atl1_sw_init(adapter);
2860 netdev->features = NETIF_F_HW_CSUM;
2861 netdev->features |= NETIF_F_SG;
2862 netdev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
2863 netdev->features |= NETIF_F_TSO;
2864 netdev->features |= NETIF_F_LLTX;
2867 * patch for some L1 of old version,
2868 * the final version of L1 may not need these
2871 /* atl1_pcie_patch(adapter); */
2873 /* really reset GPHY core */
2874 iowrite16(0, adapter->hw.hw_addr + REG_PHY_ENABLE);
2877 * reset the controller to
2878 * put the device in a known good starting state
2880 if (atl1_reset_hw(&adapter->hw)) {
2885 /* copy the MAC address out of the EEPROM */
2886 atl1_read_mac_addr(&adapter->hw);
2887 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
2889 if (!is_valid_ether_addr(netdev->dev_addr)) {
2894 atl1_check_options(adapter);
2896 /* pre-init the MAC, and setup link */
2897 err = atl1_init_hw(&adapter->hw);
2903 atl1_pcie_patch(adapter);
2904 /* assume we have no link for now */
2905 netif_carrier_off(netdev);
2906 netif_stop_queue(netdev);
2908 init_timer(&adapter->watchdog_timer);
2909 adapter->watchdog_timer.function = &atl1_watchdog;
2910 adapter->watchdog_timer.data = (unsigned long)adapter;
2912 init_timer(&adapter->phy_config_timer);
2913 adapter->phy_config_timer.function = &atl1_phy_config;
2914 adapter->phy_config_timer.data = (unsigned long)adapter;
2915 adapter->phy_timer_pending = false;
2917 INIT_WORK(&adapter->tx_timeout_task, atl1_tx_timeout_task);
2919 INIT_WORK(&adapter->link_chg_task, atlx_link_chg_task);
2921 INIT_WORK(&adapter->pcie_dma_to_rst_task, atl1_tx_timeout_task);
2923 err = register_netdev(netdev);
2928 atl1_via_workaround(adapter);
2932 pci_iounmap(pdev, adapter->hw.hw_addr);
2934 free_netdev(netdev);
2936 pci_release_regions(pdev);
2938 err_request_regions:
2939 pci_disable_device(pdev);
2944 * atl1_remove - Device Removal Routine
2945 * @pdev: PCI device information struct
2947 * atl1_remove is called by the PCI subsystem to alert the driver
2948 * that it should release a PCI device. The could be caused by a
2949 * Hot-Plug event, or because the driver is going to be removed from
2952 static void __devexit atl1_remove(struct pci_dev *pdev)
2954 struct net_device *netdev = pci_get_drvdata(pdev);
2955 struct atl1_adapter *adapter;
2956 /* Device not available. Return. */
2960 adapter = netdev_priv(netdev);
2963 * Some atl1 boards lack persistent storage for their MAC, and get it
2964 * from the BIOS during POST. If we've been messing with the MAC
2965 * address, we need to save the permanent one.
2967 if (memcmp(adapter->hw.mac_addr, adapter->hw.perm_mac_addr, ETH_ALEN)) {
2968 memcpy(adapter->hw.mac_addr, adapter->hw.perm_mac_addr,
2970 atl1_set_mac_addr(&adapter->hw);
2973 iowrite16(0, adapter->hw.hw_addr + REG_PHY_ENABLE);
2974 unregister_netdev(netdev);
2975 pci_iounmap(pdev, adapter->hw.hw_addr);
2976 pci_release_regions(pdev);
2977 free_netdev(netdev);
2978 pci_disable_device(pdev);
2981 static struct pci_driver atl1_driver = {
2982 .name = ATLX_DRIVER_NAME,
2983 .id_table = atl1_pci_tbl,
2984 .probe = atl1_probe,
2985 .remove = __devexit_p(atl1_remove),
2986 .suspend = atl1_suspend,
2987 .resume = atl1_resume
2991 * atl1_exit_module - Driver Exit Cleanup Routine
2993 * atl1_exit_module is called just before the driver is removed
2996 static void __exit atl1_exit_module(void)
2998 pci_unregister_driver(&atl1_driver);
3002 * atl1_init_module - Driver Registration Routine
3004 * atl1_init_module is the first routine called when the driver is
3005 * loaded. All it does is register with the PCI subsystem.
3007 static int __init atl1_init_module(void)
3009 return pci_register_driver(&atl1_driver);
3012 module_init(atl1_init_module);
3013 module_exit(atl1_exit_module);
3016 char stat_string[ETH_GSTRING_LEN];
3021 #define ATL1_STAT(m) \
3022 sizeof(((struct atl1_adapter *)0)->m), offsetof(struct atl1_adapter, m)
3024 static struct atl1_stats atl1_gstrings_stats[] = {
3025 {"rx_packets", ATL1_STAT(soft_stats.rx_packets)},
3026 {"tx_packets", ATL1_STAT(soft_stats.tx_packets)},
3027 {"rx_bytes", ATL1_STAT(soft_stats.rx_bytes)},
3028 {"tx_bytes", ATL1_STAT(soft_stats.tx_bytes)},
3029 {"rx_errors", ATL1_STAT(soft_stats.rx_errors)},
3030 {"tx_errors", ATL1_STAT(soft_stats.tx_errors)},
3031 {"rx_dropped", ATL1_STAT(net_stats.rx_dropped)},
3032 {"tx_dropped", ATL1_STAT(net_stats.tx_dropped)},
3033 {"multicast", ATL1_STAT(soft_stats.multicast)},
3034 {"collisions", ATL1_STAT(soft_stats.collisions)},
3035 {"rx_length_errors", ATL1_STAT(soft_stats.rx_length_errors)},
3036 {"rx_over_errors", ATL1_STAT(soft_stats.rx_missed_errors)},
3037 {"rx_crc_errors", ATL1_STAT(soft_stats.rx_crc_errors)},
3038 {"rx_frame_errors", ATL1_STAT(soft_stats.rx_frame_errors)},
3039 {"rx_fifo_errors", ATL1_STAT(soft_stats.rx_fifo_errors)},
3040 {"rx_missed_errors", ATL1_STAT(soft_stats.rx_missed_errors)},
3041 {"tx_aborted_errors", ATL1_STAT(soft_stats.tx_aborted_errors)},
3042 {"tx_carrier_errors", ATL1_STAT(soft_stats.tx_carrier_errors)},
3043 {"tx_fifo_errors", ATL1_STAT(soft_stats.tx_fifo_errors)},
3044 {"tx_window_errors", ATL1_STAT(soft_stats.tx_window_errors)},
3045 {"tx_abort_exce_coll", ATL1_STAT(soft_stats.excecol)},
3046 {"tx_abort_late_coll", ATL1_STAT(soft_stats.latecol)},
3047 {"tx_deferred_ok", ATL1_STAT(soft_stats.deffer)},
3048 {"tx_single_coll_ok", ATL1_STAT(soft_stats.scc)},
3049 {"tx_multi_coll_ok", ATL1_STAT(soft_stats.mcc)},
3050 {"tx_underun", ATL1_STAT(soft_stats.tx_underun)},
3051 {"tx_trunc", ATL1_STAT(soft_stats.tx_trunc)},
3052 {"tx_pause", ATL1_STAT(soft_stats.tx_pause)},
3053 {"rx_pause", ATL1_STAT(soft_stats.rx_pause)},
3054 {"rx_rrd_ov", ATL1_STAT(soft_stats.rx_rrd_ov)},
3055 {"rx_trunc", ATL1_STAT(soft_stats.rx_trunc)}
3058 static void atl1_get_ethtool_stats(struct net_device *netdev,
3059 struct ethtool_stats *stats, u64 *data)
3061 struct atl1_adapter *adapter = netdev_priv(netdev);
3065 for (i = 0; i < ARRAY_SIZE(atl1_gstrings_stats); i++) {
3066 p = (char *)adapter+atl1_gstrings_stats[i].stat_offset;
3067 data[i] = (atl1_gstrings_stats[i].sizeof_stat ==
3068 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
3073 static int atl1_get_sset_count(struct net_device *netdev, int sset)
3077 return ARRAY_SIZE(atl1_gstrings_stats);
3083 static int atl1_get_settings(struct net_device *netdev,
3084 struct ethtool_cmd *ecmd)
3086 struct atl1_adapter *adapter = netdev_priv(netdev);
3087 struct atl1_hw *hw = &adapter->hw;
3089 ecmd->supported = (SUPPORTED_10baseT_Half |
3090 SUPPORTED_10baseT_Full |
3091 SUPPORTED_100baseT_Half |
3092 SUPPORTED_100baseT_Full |
3093 SUPPORTED_1000baseT_Full |
3094 SUPPORTED_Autoneg | SUPPORTED_TP);
3095 ecmd->advertising = ADVERTISED_TP;
3096 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3097 hw->media_type == MEDIA_TYPE_1000M_FULL) {
3098 ecmd->advertising |= ADVERTISED_Autoneg;
3099 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR) {
3100 ecmd->advertising |= ADVERTISED_Autoneg;
3101 ecmd->advertising |=
3102 (ADVERTISED_10baseT_Half |
3103 ADVERTISED_10baseT_Full |
3104 ADVERTISED_100baseT_Half |
3105 ADVERTISED_100baseT_Full |
3106 ADVERTISED_1000baseT_Full);
3108 ecmd->advertising |= (ADVERTISED_1000baseT_Full);
3110 ecmd->port = PORT_TP;
3111 ecmd->phy_address = 0;
3112 ecmd->transceiver = XCVR_INTERNAL;
3114 if (netif_carrier_ok(adapter->netdev)) {
3115 u16 link_speed, link_duplex;
3116 atl1_get_speed_and_duplex(hw, &link_speed, &link_duplex);
3117 ecmd->speed = link_speed;
3118 if (link_duplex == FULL_DUPLEX)
3119 ecmd->duplex = DUPLEX_FULL;
3121 ecmd->duplex = DUPLEX_HALF;
3126 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3127 hw->media_type == MEDIA_TYPE_1000M_FULL)
3128 ecmd->autoneg = AUTONEG_ENABLE;
3130 ecmd->autoneg = AUTONEG_DISABLE;
3135 static int atl1_set_settings(struct net_device *netdev,
3136 struct ethtool_cmd *ecmd)
3138 struct atl1_adapter *adapter = netdev_priv(netdev);
3139 struct atl1_hw *hw = &adapter->hw;
3142 u16 old_media_type = hw->media_type;
3144 if (netif_running(adapter->netdev)) {
3145 if (netif_msg_link(adapter))
3146 dev_dbg(&adapter->pdev->dev,
3147 "ethtool shutting down adapter\n");
3151 if (ecmd->autoneg == AUTONEG_ENABLE)
3152 hw->media_type = MEDIA_TYPE_AUTO_SENSOR;
3154 if (ecmd->speed == SPEED_1000) {
3155 if (ecmd->duplex != DUPLEX_FULL) {
3156 if (netif_msg_link(adapter))
3157 dev_warn(&adapter->pdev->dev,
3158 "1000M half is invalid\n");
3162 hw->media_type = MEDIA_TYPE_1000M_FULL;
3163 } else if (ecmd->speed == SPEED_100) {
3164 if (ecmd->duplex == DUPLEX_FULL)
3165 hw->media_type = MEDIA_TYPE_100M_FULL;
3167 hw->media_type = MEDIA_TYPE_100M_HALF;
3169 if (ecmd->duplex == DUPLEX_FULL)
3170 hw->media_type = MEDIA_TYPE_10M_FULL;
3172 hw->media_type = MEDIA_TYPE_10M_HALF;
3175 switch (hw->media_type) {
3176 case MEDIA_TYPE_AUTO_SENSOR:
3178 ADVERTISED_10baseT_Half |
3179 ADVERTISED_10baseT_Full |
3180 ADVERTISED_100baseT_Half |
3181 ADVERTISED_100baseT_Full |
3182 ADVERTISED_1000baseT_Full |
3183 ADVERTISED_Autoneg | ADVERTISED_TP;
3185 case MEDIA_TYPE_1000M_FULL:
3187 ADVERTISED_1000baseT_Full |
3188 ADVERTISED_Autoneg | ADVERTISED_TP;
3191 ecmd->advertising = 0;
3194 if (atl1_phy_setup_autoneg_adv(hw)) {
3196 if (netif_msg_link(adapter))
3197 dev_warn(&adapter->pdev->dev,
3198 "invalid ethtool speed/duplex setting\n");
3201 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3202 hw->media_type == MEDIA_TYPE_1000M_FULL)
3203 phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN;
3205 switch (hw->media_type) {
3206 case MEDIA_TYPE_100M_FULL:
3208 MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 |
3211 case MEDIA_TYPE_100M_HALF:
3212 phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
3214 case MEDIA_TYPE_10M_FULL:
3216 MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET;
3219 /* MEDIA_TYPE_10M_HALF: */
3220 phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
3224 atl1_write_phy_reg(hw, MII_BMCR, phy_data);
3227 hw->media_type = old_media_type;
3229 if (netif_running(adapter->netdev)) {
3230 if (netif_msg_link(adapter))
3231 dev_dbg(&adapter->pdev->dev,
3232 "ethtool starting adapter\n");
3234 } else if (!ret_val) {
3235 if (netif_msg_link(adapter))
3236 dev_dbg(&adapter->pdev->dev,
3237 "ethtool resetting adapter\n");
3238 atl1_reset(adapter);
3243 static void atl1_get_drvinfo(struct net_device *netdev,
3244 struct ethtool_drvinfo *drvinfo)
3246 struct atl1_adapter *adapter = netdev_priv(netdev);
3248 strncpy(drvinfo->driver, ATLX_DRIVER_NAME, sizeof(drvinfo->driver));
3249 strncpy(drvinfo->version, ATLX_DRIVER_VERSION,
3250 sizeof(drvinfo->version));
3251 strncpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
3252 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
3253 sizeof(drvinfo->bus_info));
3254 drvinfo->eedump_len = ATL1_EEDUMP_LEN;
3257 static void atl1_get_wol(struct net_device *netdev,
3258 struct ethtool_wolinfo *wol)
3260 struct atl1_adapter *adapter = netdev_priv(netdev);
3262 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
3264 if (adapter->wol & ATLX_WUFC_EX)
3265 wol->wolopts |= WAKE_UCAST;
3266 if (adapter->wol & ATLX_WUFC_MC)
3267 wol->wolopts |= WAKE_MCAST;
3268 if (adapter->wol & ATLX_WUFC_BC)
3269 wol->wolopts |= WAKE_BCAST;
3270 if (adapter->wol & ATLX_WUFC_MAG)
3271 wol->wolopts |= WAKE_MAGIC;
3275 static int atl1_set_wol(struct net_device *netdev,
3276 struct ethtool_wolinfo *wol)
3278 struct atl1_adapter *adapter = netdev_priv(netdev);
3280 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
3283 if (wol->wolopts & WAKE_UCAST)
3284 adapter->wol |= ATLX_WUFC_EX;
3285 if (wol->wolopts & WAKE_MCAST)
3286 adapter->wol |= ATLX_WUFC_MC;
3287 if (wol->wolopts & WAKE_BCAST)
3288 adapter->wol |= ATLX_WUFC_BC;
3289 if (wol->wolopts & WAKE_MAGIC)
3290 adapter->wol |= ATLX_WUFC_MAG;
3294 static u32 atl1_get_msglevel(struct net_device *netdev)
3296 struct atl1_adapter *adapter = netdev_priv(netdev);
3297 return adapter->msg_enable;
3300 static void atl1_set_msglevel(struct net_device *netdev, u32 value)
3302 struct atl1_adapter *adapter = netdev_priv(netdev);
3303 adapter->msg_enable = value;
3306 static int atl1_get_regs_len(struct net_device *netdev)
3308 return ATL1_REG_COUNT * sizeof(u32);
3311 static void atl1_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
3314 struct atl1_adapter *adapter = netdev_priv(netdev);
3315 struct atl1_hw *hw = &adapter->hw;
3319 for (i = 0; i < ATL1_REG_COUNT; i++) {
3321 * This switch statement avoids reserved regions
3322 * of register space.
3347 /* reserved region; don't read it */
3351 /* unreserved region */
3352 regbuf[i] = ioread32(hw->hw_addr + (i * sizeof(u32)));
3357 static void atl1_get_ringparam(struct net_device *netdev,
3358 struct ethtool_ringparam *ring)
3360 struct atl1_adapter *adapter = netdev_priv(netdev);
3361 struct atl1_tpd_ring *txdr = &adapter->tpd_ring;
3362 struct atl1_rfd_ring *rxdr = &adapter->rfd_ring;
3364 ring->rx_max_pending = ATL1_MAX_RFD;
3365 ring->tx_max_pending = ATL1_MAX_TPD;
3366 ring->rx_mini_max_pending = 0;
3367 ring->rx_jumbo_max_pending = 0;
3368 ring->rx_pending = rxdr->count;
3369 ring->tx_pending = txdr->count;
3370 ring->rx_mini_pending = 0;
3371 ring->rx_jumbo_pending = 0;
3374 static int atl1_set_ringparam(struct net_device *netdev,
3375 struct ethtool_ringparam *ring)
3377 struct atl1_adapter *adapter = netdev_priv(netdev);
3378 struct atl1_tpd_ring *tpdr = &adapter->tpd_ring;
3379 struct atl1_rrd_ring *rrdr = &adapter->rrd_ring;
3380 struct atl1_rfd_ring *rfdr = &adapter->rfd_ring;
3382 struct atl1_tpd_ring tpd_old, tpd_new;
3383 struct atl1_rfd_ring rfd_old, rfd_new;
3384 struct atl1_rrd_ring rrd_old, rrd_new;
3385 struct atl1_ring_header rhdr_old, rhdr_new;
3388 tpd_old = adapter->tpd_ring;
3389 rfd_old = adapter->rfd_ring;
3390 rrd_old = adapter->rrd_ring;
3391 rhdr_old = adapter->ring_header;
3393 if (netif_running(adapter->netdev))
3396 rfdr->count = (u16) max(ring->rx_pending, (u32) ATL1_MIN_RFD);
3397 rfdr->count = rfdr->count > ATL1_MAX_RFD ? ATL1_MAX_RFD :
3399 rfdr->count = (rfdr->count + 3) & ~3;
3400 rrdr->count = rfdr->count;
3402 tpdr->count = (u16) max(ring->tx_pending, (u32) ATL1_MIN_TPD);
3403 tpdr->count = tpdr->count > ATL1_MAX_TPD ? ATL1_MAX_TPD :
3405 tpdr->count = (tpdr->count + 3) & ~3;
3407 if (netif_running(adapter->netdev)) {
3408 /* try to get new resources before deleting old */
3409 err = atl1_setup_ring_resources(adapter);
3411 goto err_setup_ring;
3414 * save the new, restore the old in order to free it,
3415 * then restore the new back again
3418 rfd_new = adapter->rfd_ring;
3419 rrd_new = adapter->rrd_ring;
3420 tpd_new = adapter->tpd_ring;
3421 rhdr_new = adapter->ring_header;
3422 adapter->rfd_ring = rfd_old;
3423 adapter->rrd_ring = rrd_old;
3424 adapter->tpd_ring = tpd_old;
3425 adapter->ring_header = rhdr_old;
3426 atl1_free_ring_resources(adapter);
3427 adapter->rfd_ring = rfd_new;
3428 adapter->rrd_ring = rrd_new;
3429 adapter->tpd_ring = tpd_new;
3430 adapter->ring_header = rhdr_new;
3432 err = atl1_up(adapter);
3439 adapter->rfd_ring = rfd_old;
3440 adapter->rrd_ring = rrd_old;
3441 adapter->tpd_ring = tpd_old;
3442 adapter->ring_header = rhdr_old;
3447 static void atl1_get_pauseparam(struct net_device *netdev,
3448 struct ethtool_pauseparam *epause)
3450 struct atl1_adapter *adapter = netdev_priv(netdev);
3451 struct atl1_hw *hw = &adapter->hw;
3453 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3454 hw->media_type == MEDIA_TYPE_1000M_FULL) {
3455 epause->autoneg = AUTONEG_ENABLE;
3457 epause->autoneg = AUTONEG_DISABLE;
3459 epause->rx_pause = 1;
3460 epause->tx_pause = 1;
3463 static int atl1_set_pauseparam(struct net_device *netdev,
3464 struct ethtool_pauseparam *epause)
3466 struct atl1_adapter *adapter = netdev_priv(netdev);
3467 struct atl1_hw *hw = &adapter->hw;
3469 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3470 hw->media_type == MEDIA_TYPE_1000M_FULL) {
3471 epause->autoneg = AUTONEG_ENABLE;
3473 epause->autoneg = AUTONEG_DISABLE;
3476 epause->rx_pause = 1;
3477 epause->tx_pause = 1;
3482 /* FIXME: is this right? -- CHS */
3483 static u32 atl1_get_rx_csum(struct net_device *netdev)
3488 static void atl1_get_strings(struct net_device *netdev, u32 stringset,
3494 switch (stringset) {
3496 for (i = 0; i < ARRAY_SIZE(atl1_gstrings_stats); i++) {
3497 memcpy(p, atl1_gstrings_stats[i].stat_string,
3499 p += ETH_GSTRING_LEN;
3505 static int atl1_nway_reset(struct net_device *netdev)
3507 struct atl1_adapter *adapter = netdev_priv(netdev);
3508 struct atl1_hw *hw = &adapter->hw;
3510 if (netif_running(netdev)) {
3514 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
3515 hw->media_type == MEDIA_TYPE_1000M_FULL) {
3516 phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN;
3518 switch (hw->media_type) {
3519 case MEDIA_TYPE_100M_FULL:
3520 phy_data = MII_CR_FULL_DUPLEX |
3521 MII_CR_SPEED_100 | MII_CR_RESET;
3523 case MEDIA_TYPE_100M_HALF:
3524 phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
3526 case MEDIA_TYPE_10M_FULL:
3527 phy_data = MII_CR_FULL_DUPLEX |
3528 MII_CR_SPEED_10 | MII_CR_RESET;
3531 /* MEDIA_TYPE_10M_HALF */
3532 phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
3535 atl1_write_phy_reg(hw, MII_BMCR, phy_data);
3541 const struct ethtool_ops atl1_ethtool_ops = {
3542 .get_settings = atl1_get_settings,
3543 .set_settings = atl1_set_settings,
3544 .get_drvinfo = atl1_get_drvinfo,
3545 .get_wol = atl1_get_wol,
3546 .set_wol = atl1_set_wol,
3547 .get_msglevel = atl1_get_msglevel,
3548 .set_msglevel = atl1_set_msglevel,
3549 .get_regs_len = atl1_get_regs_len,
3550 .get_regs = atl1_get_regs,
3551 .get_ringparam = atl1_get_ringparam,
3552 .set_ringparam = atl1_set_ringparam,
3553 .get_pauseparam = atl1_get_pauseparam,
3554 .set_pauseparam = atl1_set_pauseparam,
3555 .get_rx_csum = atl1_get_rx_csum,
3556 .set_tx_csum = ethtool_op_set_tx_hw_csum,
3557 .get_link = ethtool_op_get_link,
3558 .set_sg = ethtool_op_set_sg,
3559 .get_strings = atl1_get_strings,
3560 .nway_reset = atl1_nway_reset,
3561 .get_ethtool_stats = atl1_get_ethtool_stats,
3562 .get_sset_count = atl1_get_sset_count,
3563 .set_tso = ethtool_op_set_tso,