Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2008 - 2009 Atheros Corporation. All rights reserved. |
| 3 | * |
| 4 | * Derived from Intel e1000 driver |
| 5 | * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 19 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "atl1c.h" |
| 23 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 24 | #define ATL1C_DRV_VERSION "1.0.1.0-NAPI" |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 25 | char atl1c_driver_name[] = "atl1c"; |
| 26 | char atl1c_driver_version[] = ATL1C_DRV_VERSION; |
| 27 | #define PCI_DEVICE_ID_ATTANSIC_L2C 0x1062 |
| 28 | #define PCI_DEVICE_ID_ATTANSIC_L1C 0x1063 |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 29 | #define PCI_DEVICE_ID_ATHEROS_L2C_B 0x2060 /* AR8152 v1.1 Fast 10/100 */ |
| 30 | #define PCI_DEVICE_ID_ATHEROS_L2C_B2 0x2062 /* AR8152 v2.0 Fast 10/100 */ |
| 31 | #define PCI_DEVICE_ID_ATHEROS_L1D 0x1073 /* AR8151 v1.0 Gigabit 1000 */ |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 32 | #define PCI_DEVICE_ID_ATHEROS_L1D_2_0 0x1083 /* AR8151 v2.0 Gigabit 1000 */ |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 33 | #define L2CB_V10 0xc0 |
| 34 | #define L2CB_V11 0xc1 |
| 35 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 36 | /* |
| 37 | * atl1c_pci_tbl - PCI Device ID Table |
| 38 | * |
| 39 | * Wildcard entries (PCI_ANY_ID) should come last |
| 40 | * Last entry must be all 0s |
| 41 | * |
| 42 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 43 | * Class, Class Mask, private data (not used) } |
| 44 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 45 | static DEFINE_PCI_DEVICE_TABLE(atl1c_pci_tbl) = { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 46 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1C)}, |
| 47 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L2C)}, |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 48 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B)}, |
| 49 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B2)}, |
| 50 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D)}, |
Chuck Ebbert | 94dde7e | 2011-02-02 15:02:08 -0800 | [diff] [blame] | 51 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D_2_0)}, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 52 | /* required last entry */ |
| 53 | { 0 } |
| 54 | }; |
| 55 | MODULE_DEVICE_TABLE(pci, atl1c_pci_tbl); |
| 56 | |
Huang, Xiong | 70c9fbd | 2012-04-17 19:32:25 +0000 | [diff] [blame] | 57 | MODULE_AUTHOR("Jie Yang"); |
| 58 | MODULE_AUTHOR("Qualcomm Atheros Inc., <nic-devel@qualcomm.com>"); |
| 59 | MODULE_DESCRIPTION("Qualcom Atheros 100/1000M Ethernet Network Driver"); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 60 | MODULE_LICENSE("GPL"); |
| 61 | MODULE_VERSION(ATL1C_DRV_VERSION); |
| 62 | |
| 63 | static int atl1c_stop_mac(struct atl1c_hw *hw); |
| 64 | static void atl1c_enable_rx_ctrl(struct atl1c_hw *hw); |
| 65 | static void atl1c_enable_tx_ctrl(struct atl1c_hw *hw); |
| 66 | static void atl1c_disable_l0s_l1(struct atl1c_hw *hw); |
| 67 | static void atl1c_set_aspm(struct atl1c_hw *hw, bool linkup); |
| 68 | static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter); |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 69 | static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 70 | int *work_done, int work_to_do); |
stephen hemminger | 0fb1e54 | 2010-10-21 07:50:49 +0000 | [diff] [blame] | 71 | static int atl1c_up(struct atl1c_adapter *adapter); |
| 72 | static void atl1c_down(struct atl1c_adapter *adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 73 | |
| 74 | static const u16 atl1c_pay_load_size[] = { |
| 75 | 128, 256, 512, 1024, 2048, 4096, |
| 76 | }; |
| 77 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 78 | |
| 79 | static const u32 atl1c_default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 80 | NETIF_MSG_LINK | NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 81 | static void atl1c_pcie_patch(struct atl1c_hw *hw) |
| 82 | { |
| 83 | u32 data; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 84 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 85 | AT_READ_REG(hw, REG_PCIE_PHYMISC, &data); |
| 86 | data |= PCIE_PHYMISC_FORCE_RCV_DET; |
| 87 | AT_WRITE_REG(hw, REG_PCIE_PHYMISC, data); |
| 88 | |
| 89 | if (hw->nic_type == athr_l2c_b && hw->revision_id == L2CB_V10) { |
| 90 | AT_READ_REG(hw, REG_PCIE_PHYMISC2, &data); |
| 91 | |
| 92 | data &= ~(PCIE_PHYMISC2_SERDES_CDR_MASK << |
| 93 | PCIE_PHYMISC2_SERDES_CDR_SHIFT); |
| 94 | data |= 3 << PCIE_PHYMISC2_SERDES_CDR_SHIFT; |
| 95 | data &= ~(PCIE_PHYMISC2_SERDES_TH_MASK << |
| 96 | PCIE_PHYMISC2_SERDES_TH_SHIFT); |
| 97 | data |= 3 << PCIE_PHYMISC2_SERDES_TH_SHIFT; |
| 98 | AT_WRITE_REG(hw, REG_PCIE_PHYMISC2, data); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* FIXME: no need any more ? */ |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 103 | /* |
| 104 | * atl1c_init_pcie - init PCIE module |
| 105 | */ |
| 106 | static void atl1c_reset_pcie(struct atl1c_hw *hw, u32 flag) |
| 107 | { |
| 108 | u32 data; |
| 109 | u32 pci_cmd; |
| 110 | struct pci_dev *pdev = hw->adapter->pdev; |
Huang, Xiong | 95f9aea | 2012-04-18 22:01:25 +0000 | [diff] [blame^] | 111 | int pos; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 112 | |
| 113 | AT_READ_REG(hw, PCI_COMMAND, &pci_cmd); |
| 114 | pci_cmd &= ~PCI_COMMAND_INTX_DISABLE; |
| 115 | pci_cmd |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | |
| 116 | PCI_COMMAND_IO); |
| 117 | AT_WRITE_REG(hw, PCI_COMMAND, pci_cmd); |
| 118 | |
| 119 | /* |
| 120 | * Clear any PowerSaveing Settings |
| 121 | */ |
| 122 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 123 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 124 | |
| 125 | /* |
| 126 | * Mask some pcie error bits |
| 127 | */ |
Huang, Xiong | 95f9aea | 2012-04-18 22:01:25 +0000 | [diff] [blame^] | 128 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); |
| 129 | pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, &data); |
| 130 | data &= ~(PCI_ERR_UNC_DLP | PCI_ERR_UNC_FCP); |
| 131 | pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, data); |
| 132 | /* clear error status */ |
| 133 | pci_write_config_word(pdev, pci_pcie_cap(pdev) + PCI_EXP_DEVSTA, |
| 134 | PCI_EXP_DEVSTA_NFED | |
| 135 | PCI_EXP_DEVSTA_FED | |
| 136 | PCI_EXP_DEVSTA_CED | |
| 137 | PCI_EXP_DEVSTA_URD); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 138 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 139 | AT_READ_REG(hw, REG_LTSSM_ID_CTRL, &data); |
| 140 | data &= ~LTSSM_ID_EN_WRO; |
| 141 | AT_WRITE_REG(hw, REG_LTSSM_ID_CTRL, data); |
| 142 | |
| 143 | atl1c_pcie_patch(hw); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 144 | if (flag & ATL1C_PCIE_L0S_L1_DISABLE) |
| 145 | atl1c_disable_l0s_l1(hw); |
| 146 | if (flag & ATL1C_PCIE_PHY_RESET) |
| 147 | AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT); |
| 148 | else |
| 149 | AT_WRITE_REG(hw, REG_GPHY_CTRL, |
| 150 | GPHY_CTRL_DEFAULT | GPHY_CTRL_EXT_RESET); |
| 151 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 152 | msleep(5); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* |
| 156 | * atl1c_irq_enable - Enable default interrupt generation settings |
| 157 | * @adapter: board private structure |
| 158 | */ |
| 159 | static inline void atl1c_irq_enable(struct atl1c_adapter *adapter) |
| 160 | { |
| 161 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
| 162 | AT_WRITE_REG(&adapter->hw, REG_ISR, 0x7FFFFFFF); |
| 163 | AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask); |
| 164 | AT_WRITE_FLUSH(&adapter->hw); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * atl1c_irq_disable - Mask off interrupt generation on the NIC |
| 170 | * @adapter: board private structure |
| 171 | */ |
| 172 | static inline void atl1c_irq_disable(struct atl1c_adapter *adapter) |
| 173 | { |
| 174 | atomic_inc(&adapter->irq_sem); |
| 175 | AT_WRITE_REG(&adapter->hw, REG_IMR, 0); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 176 | AT_WRITE_REG(&adapter->hw, REG_ISR, ISR_DIS_INT); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 177 | AT_WRITE_FLUSH(&adapter->hw); |
| 178 | synchronize_irq(adapter->pdev->irq); |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * atl1c_irq_reset - reset interrupt confiure on the NIC |
| 183 | * @adapter: board private structure |
| 184 | */ |
| 185 | static inline void atl1c_irq_reset(struct atl1c_adapter *adapter) |
| 186 | { |
| 187 | atomic_set(&adapter->irq_sem, 1); |
| 188 | atl1c_irq_enable(adapter); |
| 189 | } |
| 190 | |
| 191 | /* |
Joe Perches | c930a66 | 2009-05-31 20:44:54 +0000 | [diff] [blame] | 192 | * atl1c_wait_until_idle - wait up to AT_HW_MAX_IDLE_DELAY reads |
| 193 | * of the idle status register until the device is actually idle |
| 194 | */ |
Huang, Xiong | 969a7ee | 2012-04-18 22:01:22 +0000 | [diff] [blame] | 195 | static u32 atl1c_wait_until_idle(struct atl1c_hw *hw, u32 modu_ctrl) |
Joe Perches | c930a66 | 2009-05-31 20:44:54 +0000 | [diff] [blame] | 196 | { |
| 197 | int timeout; |
| 198 | u32 data; |
| 199 | |
| 200 | for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) { |
| 201 | AT_READ_REG(hw, REG_IDLE_STATUS, &data); |
Huang, Xiong | 969a7ee | 2012-04-18 22:01:22 +0000 | [diff] [blame] | 202 | if ((data & modu_ctrl) == 0) |
Joe Perches | c930a66 | 2009-05-31 20:44:54 +0000 | [diff] [blame] | 203 | return 0; |
| 204 | msleep(1); |
| 205 | } |
| 206 | return data; |
| 207 | } |
| 208 | |
| 209 | /* |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 210 | * atl1c_phy_config - Timer Call-back |
| 211 | * @data: pointer to netdev cast into an unsigned long |
| 212 | */ |
| 213 | static void atl1c_phy_config(unsigned long data) |
| 214 | { |
| 215 | struct atl1c_adapter *adapter = (struct atl1c_adapter *) data; |
| 216 | struct atl1c_hw *hw = &adapter->hw; |
| 217 | unsigned long flags; |
| 218 | |
| 219 | spin_lock_irqsave(&adapter->mdio_lock, flags); |
| 220 | atl1c_restart_autoneg(hw); |
| 221 | spin_unlock_irqrestore(&adapter->mdio_lock, flags); |
| 222 | } |
| 223 | |
| 224 | void atl1c_reinit_locked(struct atl1c_adapter *adapter) |
| 225 | { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 226 | WARN_ON(in_interrupt()); |
| 227 | atl1c_down(adapter); |
| 228 | atl1c_up(adapter); |
| 229 | clear_bit(__AT_RESETTING, &adapter->flags); |
| 230 | } |
| 231 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 232 | static void atl1c_check_link_status(struct atl1c_adapter *adapter) |
| 233 | { |
| 234 | struct atl1c_hw *hw = &adapter->hw; |
| 235 | struct net_device *netdev = adapter->netdev; |
| 236 | struct pci_dev *pdev = adapter->pdev; |
| 237 | int err; |
| 238 | unsigned long flags; |
| 239 | u16 speed, duplex, phy_data; |
| 240 | |
| 241 | spin_lock_irqsave(&adapter->mdio_lock, flags); |
| 242 | /* MII_BMSR must read twise */ |
| 243 | atl1c_read_phy_reg(hw, MII_BMSR, &phy_data); |
| 244 | atl1c_read_phy_reg(hw, MII_BMSR, &phy_data); |
| 245 | spin_unlock_irqrestore(&adapter->mdio_lock, flags); |
| 246 | |
| 247 | if ((phy_data & BMSR_LSTATUS) == 0) { |
| 248 | /* link down */ |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 249 | hw->hibernate = true; |
| 250 | if (atl1c_stop_mac(hw) != 0) |
| 251 | if (netif_msg_hw(adapter)) |
| 252 | dev_warn(&pdev->dev, "stop mac failed\n"); |
| 253 | atl1c_set_aspm(hw, false); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 254 | netif_carrier_off(netdev); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 255 | netif_stop_queue(netdev); |
| 256 | atl1c_phy_reset(hw); |
| 257 | atl1c_phy_init(&adapter->hw); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 258 | } else { |
| 259 | /* Link Up */ |
| 260 | hw->hibernate = false; |
| 261 | spin_lock_irqsave(&adapter->mdio_lock, flags); |
| 262 | err = atl1c_get_speed_and_duplex(hw, &speed, &duplex); |
| 263 | spin_unlock_irqrestore(&adapter->mdio_lock, flags); |
| 264 | if (unlikely(err)) |
| 265 | return; |
| 266 | /* link result is our setting */ |
| 267 | if (adapter->link_speed != speed || |
| 268 | adapter->link_duplex != duplex) { |
| 269 | adapter->link_speed = speed; |
| 270 | adapter->link_duplex = duplex; |
Jie Yang | 52fbc10 | 2009-04-27 19:42:03 +0000 | [diff] [blame] | 271 | atl1c_set_aspm(hw, true); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 272 | atl1c_enable_tx_ctrl(hw); |
| 273 | atl1c_enable_rx_ctrl(hw); |
| 274 | atl1c_setup_mac_ctrl(adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 275 | if (netif_msg_link(adapter)) |
| 276 | dev_info(&pdev->dev, |
| 277 | "%s: %s NIC Link is Up<%d Mbps %s>\n", |
| 278 | atl1c_driver_name, netdev->name, |
| 279 | adapter->link_speed, |
| 280 | adapter->link_duplex == FULL_DUPLEX ? |
| 281 | "Full Duplex" : "Half Duplex"); |
| 282 | } |
| 283 | if (!netif_carrier_ok(netdev)) |
| 284 | netif_carrier_on(netdev); |
| 285 | } |
| 286 | } |
| 287 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 288 | static void atl1c_link_chg_event(struct atl1c_adapter *adapter) |
| 289 | { |
| 290 | struct net_device *netdev = adapter->netdev; |
| 291 | struct pci_dev *pdev = adapter->pdev; |
| 292 | u16 phy_data; |
| 293 | u16 link_up; |
| 294 | |
| 295 | spin_lock(&adapter->mdio_lock); |
| 296 | atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data); |
| 297 | atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data); |
| 298 | spin_unlock(&adapter->mdio_lock); |
| 299 | link_up = phy_data & BMSR_LSTATUS; |
| 300 | /* notify upper layer link down ASAP */ |
| 301 | if (!link_up) { |
| 302 | if (netif_carrier_ok(netdev)) { |
| 303 | /* old link state: Up */ |
| 304 | netif_carrier_off(netdev); |
| 305 | if (netif_msg_link(adapter)) |
| 306 | dev_info(&pdev->dev, |
| 307 | "%s: %s NIC Link is Down\n", |
| 308 | atl1c_driver_name, netdev->name); |
| 309 | adapter->link_speed = SPEED_0; |
| 310 | } |
| 311 | } |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 312 | |
Tim Gardner | cb77183 | 2011-04-20 09:00:49 +0000 | [diff] [blame] | 313 | set_bit(ATL1C_WORK_EVENT_LINK_CHANGE, &adapter->work_event); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 314 | schedule_work(&adapter->common_task); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 317 | static void atl1c_common_task(struct work_struct *work) |
| 318 | { |
| 319 | struct atl1c_adapter *adapter; |
| 320 | struct net_device *netdev; |
| 321 | |
| 322 | adapter = container_of(work, struct atl1c_adapter, common_task); |
| 323 | netdev = adapter->netdev; |
| 324 | |
Tim Gardner | cb77183 | 2011-04-20 09:00:49 +0000 | [diff] [blame] | 325 | if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) { |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 326 | netif_device_detach(netdev); |
| 327 | atl1c_down(adapter); |
| 328 | atl1c_up(adapter); |
| 329 | netif_device_attach(netdev); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Tim Gardner | cb77183 | 2011-04-20 09:00:49 +0000 | [diff] [blame] | 332 | if (test_and_clear_bit(ATL1C_WORK_EVENT_LINK_CHANGE, |
| 333 | &adapter->work_event)) |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 334 | atl1c_check_link_status(adapter); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 338 | static void atl1c_del_timer(struct atl1c_adapter *adapter) |
| 339 | { |
| 340 | del_timer_sync(&adapter->phy_config_timer); |
| 341 | } |
| 342 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * atl1c_tx_timeout - Respond to a Tx Hang |
| 346 | * @netdev: network interface device structure |
| 347 | */ |
| 348 | static void atl1c_tx_timeout(struct net_device *netdev) |
| 349 | { |
| 350 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 351 | |
| 352 | /* Do the reset outside of interrupt context */ |
Tim Gardner | cb77183 | 2011-04-20 09:00:49 +0000 | [diff] [blame] | 353 | set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 354 | schedule_work(&adapter->common_task); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* |
| 358 | * atl1c_set_multi - Multicast and Promiscuous mode set |
| 359 | * @netdev: network interface device structure |
| 360 | * |
| 361 | * The set_multi entry point is called whenever the multicast address |
| 362 | * list or the network interface flags are updated. This routine is |
| 363 | * responsible for configuring the hardware for proper multicast, |
| 364 | * promiscuous mode, and all-multi behavior. |
| 365 | */ |
| 366 | static void atl1c_set_multi(struct net_device *netdev) |
| 367 | { |
| 368 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 369 | struct atl1c_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 370 | struct netdev_hw_addr *ha; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 371 | u32 mac_ctrl_data; |
| 372 | u32 hash_value; |
| 373 | |
| 374 | /* Check for Promiscuous and All Multicast modes */ |
| 375 | AT_READ_REG(hw, REG_MAC_CTRL, &mac_ctrl_data); |
| 376 | |
| 377 | if (netdev->flags & IFF_PROMISC) { |
| 378 | mac_ctrl_data |= MAC_CTRL_PROMIS_EN; |
| 379 | } else if (netdev->flags & IFF_ALLMULTI) { |
| 380 | mac_ctrl_data |= MAC_CTRL_MC_ALL_EN; |
| 381 | mac_ctrl_data &= ~MAC_CTRL_PROMIS_EN; |
| 382 | } else { |
| 383 | mac_ctrl_data &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN); |
| 384 | } |
| 385 | |
| 386 | AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data); |
| 387 | |
| 388 | /* clear the old settings from the multicast hash table */ |
| 389 | AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0); |
| 390 | AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0); |
| 391 | |
| 392 | /* comoute mc addresses' hash value ,and put it into hash table */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 393 | netdev_for_each_mc_addr(ha, netdev) { |
| 394 | hash_value = atl1c_hash_mc_addr(hw, ha->addr); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 395 | atl1c_hash_set(hw, hash_value); |
| 396 | } |
| 397 | } |
| 398 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 399 | static void __atl1c_vlan_mode(netdev_features_t features, u32 *mac_ctrl_data) |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 400 | { |
| 401 | if (features & NETIF_F_HW_VLAN_RX) { |
| 402 | /* enable VLAN tag insert/strip */ |
| 403 | *mac_ctrl_data |= MAC_CTRL_RMV_VLAN; |
| 404 | } else { |
| 405 | /* disable VLAN tag insert/strip */ |
| 406 | *mac_ctrl_data &= ~MAC_CTRL_RMV_VLAN; |
| 407 | } |
| 408 | } |
| 409 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 410 | static void atl1c_vlan_mode(struct net_device *netdev, |
| 411 | netdev_features_t features) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 412 | { |
| 413 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 414 | struct pci_dev *pdev = adapter->pdev; |
| 415 | u32 mac_ctrl_data = 0; |
| 416 | |
| 417 | if (netif_msg_pktdata(adapter)) |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 418 | dev_dbg(&pdev->dev, "atl1c_vlan_mode\n"); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 419 | |
| 420 | atl1c_irq_disable(adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 421 | AT_READ_REG(&adapter->hw, REG_MAC_CTRL, &mac_ctrl_data); |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 422 | __atl1c_vlan_mode(features, &mac_ctrl_data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 423 | AT_WRITE_REG(&adapter->hw, REG_MAC_CTRL, mac_ctrl_data); |
| 424 | atl1c_irq_enable(adapter); |
| 425 | } |
| 426 | |
| 427 | static void atl1c_restore_vlan(struct atl1c_adapter *adapter) |
| 428 | { |
| 429 | struct pci_dev *pdev = adapter->pdev; |
| 430 | |
| 431 | if (netif_msg_pktdata(adapter)) |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 432 | dev_dbg(&pdev->dev, "atl1c_restore_vlan\n"); |
| 433 | atl1c_vlan_mode(adapter->netdev, adapter->netdev->features); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 434 | } |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 435 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 436 | /* |
| 437 | * atl1c_set_mac - Change the Ethernet Address of the NIC |
| 438 | * @netdev: network interface device structure |
| 439 | * @p: pointer to an address structure |
| 440 | * |
| 441 | * Returns 0 on success, negative on failure |
| 442 | */ |
| 443 | static int atl1c_set_mac_addr(struct net_device *netdev, void *p) |
| 444 | { |
| 445 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 446 | struct sockaddr *addr = p; |
| 447 | |
| 448 | if (!is_valid_ether_addr(addr->sa_data)) |
| 449 | return -EADDRNOTAVAIL; |
| 450 | |
| 451 | if (netif_running(netdev)) |
| 452 | return -EBUSY; |
| 453 | |
| 454 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 455 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
Danny Kukawka | 6a214fd | 2012-02-17 05:43:30 +0000 | [diff] [blame] | 456 | netdev->addr_assign_type &= ~NET_ADDR_RANDOM; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 457 | |
| 458 | atl1c_hw_set_mac_addr(&adapter->hw); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static void atl1c_set_rxbufsize(struct atl1c_adapter *adapter, |
| 464 | struct net_device *dev) |
| 465 | { |
| 466 | int mtu = dev->mtu; |
| 467 | |
| 468 | adapter->rx_buffer_len = mtu > AT_RX_BUF_SIZE ? |
| 469 | roundup(mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, 8) : AT_RX_BUF_SIZE; |
| 470 | } |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 471 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 472 | static netdev_features_t atl1c_fix_features(struct net_device *netdev, |
| 473 | netdev_features_t features) |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 474 | { |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 475 | /* |
| 476 | * Since there is no support for separate rx/tx vlan accel |
| 477 | * enable/disable make sure tx flag is always in same state as rx. |
| 478 | */ |
| 479 | if (features & NETIF_F_HW_VLAN_RX) |
| 480 | features |= NETIF_F_HW_VLAN_TX; |
| 481 | else |
| 482 | features &= ~NETIF_F_HW_VLAN_TX; |
| 483 | |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 484 | if (netdev->mtu > MAX_TSO_FRAME_SIZE) |
| 485 | features &= ~(NETIF_F_TSO | NETIF_F_TSO6); |
| 486 | |
| 487 | return features; |
| 488 | } |
| 489 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 490 | static int atl1c_set_features(struct net_device *netdev, |
| 491 | netdev_features_t features) |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 492 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 493 | netdev_features_t changed = netdev->features ^ features; |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 494 | |
| 495 | if (changed & NETIF_F_HW_VLAN_RX) |
| 496 | atl1c_vlan_mode(netdev, features); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 501 | /* |
| 502 | * atl1c_change_mtu - Change the Maximum Transfer Unit |
| 503 | * @netdev: network interface device structure |
| 504 | * @new_mtu: new value for maximum frame size |
| 505 | * |
| 506 | * Returns 0 on success, negative on failure |
| 507 | */ |
| 508 | static int atl1c_change_mtu(struct net_device *netdev, int new_mtu) |
| 509 | { |
| 510 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
Huang, Xiong | c08b9b2 | 2012-04-18 22:01:23 +0000 | [diff] [blame] | 511 | struct atl1c_hw *hw = &adapter->hw; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 512 | int old_mtu = netdev->mtu; |
| 513 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 514 | |
Huang, Xiong | c08b9b2 | 2012-04-18 22:01:23 +0000 | [diff] [blame] | 515 | /* Fast Ethernet controller doesn't support jumbo packet */ |
| 516 | if (((hw->nic_type == athr_l2c || |
| 517 | hw->nic_type == athr_l2c_b || |
| 518 | hw->nic_type == athr_l2c_b2) && new_mtu > ETH_DATA_LEN) || |
| 519 | max_frame < ETH_ZLEN + ETH_FCS_LEN || |
| 520 | max_frame > MAX_JUMBO_FRAME_SIZE) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 521 | if (netif_msg_link(adapter)) |
| 522 | dev_warn(&adapter->pdev->dev, "invalid MTU setting\n"); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | /* set MTU */ |
| 526 | if (old_mtu != new_mtu && netif_running(netdev)) { |
| 527 | while (test_and_set_bit(__AT_RESETTING, &adapter->flags)) |
| 528 | msleep(1); |
| 529 | netdev->mtu = new_mtu; |
| 530 | adapter->hw.max_frame_size = new_mtu; |
| 531 | atl1c_set_rxbufsize(adapter, netdev); |
| 532 | atl1c_down(adapter); |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 533 | netdev_update_features(netdev); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 534 | atl1c_up(adapter); |
| 535 | clear_bit(__AT_RESETTING, &adapter->flags); |
| 536 | if (adapter->hw.ctrl_flags & ATL1C_FPGA_VERSION) { |
| 537 | u32 phy_data; |
| 538 | |
| 539 | AT_READ_REG(&adapter->hw, 0x1414, &phy_data); |
| 540 | phy_data |= 0x10000000; |
| 541 | AT_WRITE_REG(&adapter->hw, 0x1414, phy_data); |
| 542 | } |
| 543 | |
| 544 | } |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * caller should hold mdio_lock |
| 550 | */ |
| 551 | static int atl1c_mdio_read(struct net_device *netdev, int phy_id, int reg_num) |
| 552 | { |
| 553 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 554 | u16 result; |
| 555 | |
| 556 | atl1c_read_phy_reg(&adapter->hw, reg_num & MDIO_REG_ADDR_MASK, &result); |
| 557 | return result; |
| 558 | } |
| 559 | |
| 560 | static void atl1c_mdio_write(struct net_device *netdev, int phy_id, |
| 561 | int reg_num, int val) |
| 562 | { |
| 563 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 564 | |
| 565 | atl1c_write_phy_reg(&adapter->hw, reg_num & MDIO_REG_ADDR_MASK, val); |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * atl1c_mii_ioctl - |
| 570 | * @netdev: |
| 571 | * @ifreq: |
| 572 | * @cmd: |
| 573 | */ |
| 574 | static int atl1c_mii_ioctl(struct net_device *netdev, |
| 575 | struct ifreq *ifr, int cmd) |
| 576 | { |
| 577 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 578 | struct pci_dev *pdev = adapter->pdev; |
| 579 | struct mii_ioctl_data *data = if_mii(ifr); |
| 580 | unsigned long flags; |
| 581 | int retval = 0; |
| 582 | |
| 583 | if (!netif_running(netdev)) |
| 584 | return -EINVAL; |
| 585 | |
| 586 | spin_lock_irqsave(&adapter->mdio_lock, flags); |
| 587 | switch (cmd) { |
| 588 | case SIOCGMIIPHY: |
| 589 | data->phy_id = 0; |
| 590 | break; |
| 591 | |
| 592 | case SIOCGMIIREG: |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 593 | if (atl1c_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
| 594 | &data->val_out)) { |
| 595 | retval = -EIO; |
| 596 | goto out; |
| 597 | } |
| 598 | break; |
| 599 | |
| 600 | case SIOCSMIIREG: |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 601 | if (data->reg_num & ~(0x1F)) { |
| 602 | retval = -EFAULT; |
| 603 | goto out; |
| 604 | } |
| 605 | |
| 606 | dev_dbg(&pdev->dev, "<atl1c_mii_ioctl> write %x %x", |
| 607 | data->reg_num, data->val_in); |
| 608 | if (atl1c_write_phy_reg(&adapter->hw, |
| 609 | data->reg_num, data->val_in)) { |
| 610 | retval = -EIO; |
| 611 | goto out; |
| 612 | } |
| 613 | break; |
| 614 | |
| 615 | default: |
| 616 | retval = -EOPNOTSUPP; |
| 617 | break; |
| 618 | } |
| 619 | out: |
| 620 | spin_unlock_irqrestore(&adapter->mdio_lock, flags); |
| 621 | return retval; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * atl1c_ioctl - |
| 626 | * @netdev: |
| 627 | * @ifreq: |
| 628 | * @cmd: |
| 629 | */ |
| 630 | static int atl1c_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 631 | { |
| 632 | switch (cmd) { |
| 633 | case SIOCGMIIPHY: |
| 634 | case SIOCGMIIREG: |
| 635 | case SIOCSMIIREG: |
| 636 | return atl1c_mii_ioctl(netdev, ifr, cmd); |
| 637 | default: |
| 638 | return -EOPNOTSUPP; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * atl1c_alloc_queues - Allocate memory for all rings |
| 644 | * @adapter: board private structure to initialize |
| 645 | * |
| 646 | */ |
| 647 | static int __devinit atl1c_alloc_queues(struct atl1c_adapter *adapter) |
| 648 | { |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | static void atl1c_set_mac_type(struct atl1c_hw *hw) |
| 653 | { |
| 654 | switch (hw->device_id) { |
| 655 | case PCI_DEVICE_ID_ATTANSIC_L2C: |
| 656 | hw->nic_type = athr_l2c; |
| 657 | break; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 658 | case PCI_DEVICE_ID_ATTANSIC_L1C: |
| 659 | hw->nic_type = athr_l1c; |
| 660 | break; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 661 | case PCI_DEVICE_ID_ATHEROS_L2C_B: |
| 662 | hw->nic_type = athr_l2c_b; |
| 663 | break; |
| 664 | case PCI_DEVICE_ID_ATHEROS_L2C_B2: |
| 665 | hw->nic_type = athr_l2c_b2; |
| 666 | break; |
| 667 | case PCI_DEVICE_ID_ATHEROS_L1D: |
| 668 | hw->nic_type = athr_l1d; |
| 669 | break; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 670 | case PCI_DEVICE_ID_ATHEROS_L1D_2_0: |
| 671 | hw->nic_type = athr_l1d_2; |
| 672 | break; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 673 | default: |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static int atl1c_setup_mac_funcs(struct atl1c_hw *hw) |
| 679 | { |
| 680 | u32 phy_status_data; |
| 681 | u32 link_ctrl_data; |
| 682 | |
| 683 | atl1c_set_mac_type(hw); |
| 684 | AT_READ_REG(hw, REG_PHY_STATUS, &phy_status_data); |
| 685 | AT_READ_REG(hw, REG_LINK_CTRL, &link_ctrl_data); |
| 686 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 687 | hw->ctrl_flags = ATL1C_INTR_MODRT_ENABLE | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 688 | ATL1C_TXQ_MODE_ENHANCE; |
| 689 | if (link_ctrl_data & LINK_CTRL_L0S_EN) |
| 690 | hw->ctrl_flags |= ATL1C_ASPM_L0S_SUPPORT; |
| 691 | if (link_ctrl_data & LINK_CTRL_L1_EN) |
| 692 | hw->ctrl_flags |= ATL1C_ASPM_L1_SUPPORT; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 693 | if (link_ctrl_data & LINK_CTRL_EXT_SYNC) |
| 694 | hw->ctrl_flags |= ATL1C_LINK_EXT_SYNC; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 695 | hw->ctrl_flags |= ATL1C_ASPM_CTRL_MON; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 696 | |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 697 | if (hw->nic_type == athr_l1c || |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 698 | hw->nic_type == athr_l1d || |
| 699 | hw->nic_type == athr_l1d_2) |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 700 | hw->link_cap_flags |= ATL1C_LINK_CAP_1000M; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | /* |
| 704 | * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter) |
| 705 | * @adapter: board private structure to initialize |
| 706 | * |
| 707 | * atl1c_sw_init initializes the Adapter private data structure. |
| 708 | * Fields are initialized based on PCI device information and |
| 709 | * OS network device settings (MTU size). |
| 710 | */ |
| 711 | static int __devinit atl1c_sw_init(struct atl1c_adapter *adapter) |
| 712 | { |
| 713 | struct atl1c_hw *hw = &adapter->hw; |
| 714 | struct pci_dev *pdev = adapter->pdev; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 715 | u32 revision; |
| 716 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 717 | |
| 718 | adapter->wol = 0; |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 719 | device_set_wakeup_enable(&pdev->dev, false); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 720 | adapter->link_speed = SPEED_0; |
| 721 | adapter->link_duplex = FULL_DUPLEX; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 722 | adapter->tpd_ring[0].count = 1024; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 723 | adapter->rfd_ring.count = 512; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 724 | |
| 725 | hw->vendor_id = pdev->vendor; |
| 726 | hw->device_id = pdev->device; |
| 727 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 728 | hw->subsystem_id = pdev->subsystem_device; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 729 | AT_READ_REG(hw, PCI_CLASS_REVISION, &revision); |
| 730 | hw->revision_id = revision & 0xFF; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 731 | /* before link up, we assume hibernate is true */ |
| 732 | hw->hibernate = true; |
| 733 | hw->media_type = MEDIA_TYPE_AUTO_SENSOR; |
| 734 | if (atl1c_setup_mac_funcs(hw) != 0) { |
| 735 | dev_err(&pdev->dev, "set mac function pointers failed\n"); |
| 736 | return -1; |
| 737 | } |
| 738 | hw->intr_mask = IMR_NORMAL_MASK; |
| 739 | hw->phy_configured = false; |
| 740 | hw->preamble_len = 7; |
| 741 | hw->max_frame_size = adapter->netdev->mtu; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 742 | hw->autoneg_advertised = ADVERTISED_Autoneg; |
| 743 | hw->indirect_tab = 0xE4E4E4E4; |
| 744 | hw->base_cpu = 0; |
| 745 | |
| 746 | hw->ict = 50000; /* 100ms */ |
| 747 | hw->smb_timer = 200000; /* 400ms */ |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 748 | hw->rx_imt = 200; |
| 749 | hw->tx_imt = 1000; |
| 750 | |
| 751 | hw->tpd_burst = 5; |
| 752 | hw->rfd_burst = 8; |
| 753 | hw->dma_order = atl1c_dma_ord_out; |
| 754 | hw->dmar_block = atl1c_dma_req_1024; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 755 | |
| 756 | if (atl1c_alloc_queues(adapter)) { |
| 757 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 758 | return -ENOMEM; |
| 759 | } |
| 760 | /* TODO */ |
| 761 | atl1c_set_rxbufsize(adapter, adapter->netdev); |
| 762 | atomic_set(&adapter->irq_sem, 1); |
| 763 | spin_lock_init(&adapter->mdio_lock); |
| 764 | spin_lock_init(&adapter->tx_lock); |
| 765 | set_bit(__AT_DOWN, &adapter->flags); |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 770 | static inline void atl1c_clean_buffer(struct pci_dev *pdev, |
| 771 | struct atl1c_buffer *buffer_info, int in_irq) |
| 772 | { |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 773 | u16 pci_driection; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 774 | if (buffer_info->flags & ATL1C_BUFFER_FREE) |
| 775 | return; |
| 776 | if (buffer_info->dma) { |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 777 | if (buffer_info->flags & ATL1C_PCIMAP_FROMDEVICE) |
| 778 | pci_driection = PCI_DMA_FROMDEVICE; |
| 779 | else |
| 780 | pci_driection = PCI_DMA_TODEVICE; |
| 781 | |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 782 | if (buffer_info->flags & ATL1C_PCIMAP_SINGLE) |
| 783 | pci_unmap_single(pdev, buffer_info->dma, |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 784 | buffer_info->length, pci_driection); |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 785 | else if (buffer_info->flags & ATL1C_PCIMAP_PAGE) |
| 786 | pci_unmap_page(pdev, buffer_info->dma, |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 787 | buffer_info->length, pci_driection); |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 788 | } |
| 789 | if (buffer_info->skb) { |
| 790 | if (in_irq) |
| 791 | dev_kfree_skb_irq(buffer_info->skb); |
| 792 | else |
| 793 | dev_kfree_skb(buffer_info->skb); |
| 794 | } |
| 795 | buffer_info->dma = 0; |
| 796 | buffer_info->skb = NULL; |
| 797 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE); |
| 798 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 799 | /* |
| 800 | * atl1c_clean_tx_ring - Free Tx-skb |
| 801 | * @adapter: board private structure |
| 802 | */ |
| 803 | static void atl1c_clean_tx_ring(struct atl1c_adapter *adapter, |
| 804 | enum atl1c_trans_queue type) |
| 805 | { |
| 806 | struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type]; |
| 807 | struct atl1c_buffer *buffer_info; |
| 808 | struct pci_dev *pdev = adapter->pdev; |
| 809 | u16 index, ring_count; |
| 810 | |
| 811 | ring_count = tpd_ring->count; |
| 812 | for (index = 0; index < ring_count; index++) { |
| 813 | buffer_info = &tpd_ring->buffer_info[index]; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 814 | atl1c_clean_buffer(pdev, buffer_info, 0); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* Zero out Tx-buffers */ |
| 818 | memset(tpd_ring->desc, 0, sizeof(struct atl1c_tpd_desc) * |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 819 | ring_count); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 820 | atomic_set(&tpd_ring->next_to_clean, 0); |
| 821 | tpd_ring->next_to_use = 0; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * atl1c_clean_rx_ring - Free rx-reservation skbs |
| 826 | * @adapter: board private structure |
| 827 | */ |
| 828 | static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter) |
| 829 | { |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 830 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 831 | struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 832 | struct atl1c_buffer *buffer_info; |
| 833 | struct pci_dev *pdev = adapter->pdev; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 834 | int j; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 835 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 836 | for (j = 0; j < rfd_ring->count; j++) { |
| 837 | buffer_info = &rfd_ring->buffer_info[j]; |
| 838 | atl1c_clean_buffer(pdev, buffer_info, 0); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 839 | } |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 840 | /* zero out the descriptor ring */ |
| 841 | memset(rfd_ring->desc, 0, rfd_ring->size); |
| 842 | rfd_ring->next_to_clean = 0; |
| 843 | rfd_ring->next_to_use = 0; |
| 844 | rrd_ring->next_to_use = 0; |
| 845 | rrd_ring->next_to_clean = 0; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* |
| 849 | * Read / Write Ptr Initialize: |
| 850 | */ |
| 851 | static void atl1c_init_ring_ptrs(struct atl1c_adapter *adapter) |
| 852 | { |
| 853 | struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 854 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 855 | struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 856 | struct atl1c_buffer *buffer_info; |
| 857 | int i, j; |
| 858 | |
| 859 | for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) { |
| 860 | tpd_ring[i].next_to_use = 0; |
| 861 | atomic_set(&tpd_ring[i].next_to_clean, 0); |
| 862 | buffer_info = tpd_ring[i].buffer_info; |
| 863 | for (j = 0; j < tpd_ring->count; j++) |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 864 | ATL1C_SET_BUFFER_STATE(&buffer_info[i], |
| 865 | ATL1C_BUFFER_FREE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 866 | } |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 867 | rfd_ring->next_to_use = 0; |
| 868 | rfd_ring->next_to_clean = 0; |
| 869 | rrd_ring->next_to_use = 0; |
| 870 | rrd_ring->next_to_clean = 0; |
| 871 | for (j = 0; j < rfd_ring->count; j++) { |
| 872 | buffer_info = &rfd_ring->buffer_info[j]; |
| 873 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
| 877 | /* |
| 878 | * atl1c_free_ring_resources - Free Tx / RX descriptor Resources |
| 879 | * @adapter: board private structure |
| 880 | * |
| 881 | * Free all transmit software resources |
| 882 | */ |
| 883 | static void atl1c_free_ring_resources(struct atl1c_adapter *adapter) |
| 884 | { |
| 885 | struct pci_dev *pdev = adapter->pdev; |
| 886 | |
| 887 | pci_free_consistent(pdev, adapter->ring_header.size, |
| 888 | adapter->ring_header.desc, |
| 889 | adapter->ring_header.dma); |
| 890 | adapter->ring_header.desc = NULL; |
| 891 | |
| 892 | /* Note: just free tdp_ring.buffer_info, |
| 893 | * it contain rfd_ring.buffer_info, do not double free */ |
| 894 | if (adapter->tpd_ring[0].buffer_info) { |
| 895 | kfree(adapter->tpd_ring[0].buffer_info); |
| 896 | adapter->tpd_ring[0].buffer_info = NULL; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * atl1c_setup_mem_resources - allocate Tx / RX descriptor resources |
| 902 | * @adapter: board private structure |
| 903 | * |
| 904 | * Return 0 on success, negative on failure |
| 905 | */ |
| 906 | static int atl1c_setup_ring_resources(struct atl1c_adapter *adapter) |
| 907 | { |
| 908 | struct pci_dev *pdev = adapter->pdev; |
| 909 | struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 910 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 911 | struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 912 | struct atl1c_ring_header *ring_header = &adapter->ring_header; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 913 | int size; |
| 914 | int i; |
| 915 | int count = 0; |
| 916 | int rx_desc_count = 0; |
| 917 | u32 offset = 0; |
| 918 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 919 | rrd_ring->count = rfd_ring->count; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 920 | for (i = 1; i < AT_MAX_TRANSMIT_QUEUE; i++) |
| 921 | tpd_ring[i].count = tpd_ring[0].count; |
| 922 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 923 | /* 2 tpd queue, one high priority queue, |
| 924 | * another normal priority queue */ |
| 925 | size = sizeof(struct atl1c_buffer) * (tpd_ring->count * 2 + |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 926 | rfd_ring->count); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 927 | tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL); |
| 928 | if (unlikely(!tpd_ring->buffer_info)) { |
| 929 | dev_err(&pdev->dev, "kzalloc failed, size = %d\n", |
| 930 | size); |
| 931 | goto err_nomem; |
| 932 | } |
| 933 | for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) { |
| 934 | tpd_ring[i].buffer_info = |
| 935 | (struct atl1c_buffer *) (tpd_ring->buffer_info + count); |
| 936 | count += tpd_ring[i].count; |
| 937 | } |
| 938 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 939 | rfd_ring->buffer_info = |
| 940 | (struct atl1c_buffer *) (tpd_ring->buffer_info + count); |
| 941 | count += rfd_ring->count; |
| 942 | rx_desc_count += rfd_ring->count; |
| 943 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 944 | /* |
| 945 | * real ring DMA buffer |
| 946 | * each ring/block may need up to 8 bytes for alignment, hence the |
| 947 | * additional bytes tacked onto the end. |
| 948 | */ |
| 949 | ring_header->size = size = |
| 950 | sizeof(struct atl1c_tpd_desc) * tpd_ring->count * 2 + |
| 951 | sizeof(struct atl1c_rx_free_desc) * rx_desc_count + |
| 952 | sizeof(struct atl1c_recv_ret_status) * rx_desc_count + |
Huang, Xiong | 8d5c683 | 2012-04-17 19:32:29 +0000 | [diff] [blame] | 953 | 8 * 4; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 954 | |
| 955 | ring_header->desc = pci_alloc_consistent(pdev, ring_header->size, |
| 956 | &ring_header->dma); |
| 957 | if (unlikely(!ring_header->desc)) { |
| 958 | dev_err(&pdev->dev, "pci_alloc_consistend failed\n"); |
| 959 | goto err_nomem; |
| 960 | } |
| 961 | memset(ring_header->desc, 0, ring_header->size); |
| 962 | /* init TPD ring */ |
| 963 | |
| 964 | tpd_ring[0].dma = roundup(ring_header->dma, 8); |
| 965 | offset = tpd_ring[0].dma - ring_header->dma; |
| 966 | for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) { |
| 967 | tpd_ring[i].dma = ring_header->dma + offset; |
| 968 | tpd_ring[i].desc = (u8 *) ring_header->desc + offset; |
| 969 | tpd_ring[i].size = |
| 970 | sizeof(struct atl1c_tpd_desc) * tpd_ring[i].count; |
| 971 | offset += roundup(tpd_ring[i].size, 8); |
| 972 | } |
| 973 | /* init RFD ring */ |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 974 | rfd_ring->dma = ring_header->dma + offset; |
| 975 | rfd_ring->desc = (u8 *) ring_header->desc + offset; |
| 976 | rfd_ring->size = sizeof(struct atl1c_rx_free_desc) * rfd_ring->count; |
| 977 | offset += roundup(rfd_ring->size, 8); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 978 | |
| 979 | /* init RRD ring */ |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 980 | rrd_ring->dma = ring_header->dma + offset; |
| 981 | rrd_ring->desc = (u8 *) ring_header->desc + offset; |
| 982 | rrd_ring->size = sizeof(struct atl1c_recv_ret_status) * |
| 983 | rrd_ring->count; |
| 984 | offset += roundup(rrd_ring->size, 8); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 985 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 986 | return 0; |
| 987 | |
| 988 | err_nomem: |
| 989 | kfree(tpd_ring->buffer_info); |
| 990 | return -ENOMEM; |
| 991 | } |
| 992 | |
| 993 | static void atl1c_configure_des_ring(struct atl1c_adapter *adapter) |
| 994 | { |
| 995 | struct atl1c_hw *hw = &adapter->hw; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 996 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 997 | struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 998 | struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *) |
| 999 | adapter->tpd_ring; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1000 | u32 data; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1001 | |
| 1002 | /* TPD */ |
| 1003 | AT_WRITE_REG(hw, REG_TX_BASE_ADDR_HI, |
| 1004 | (u32)((tpd_ring[atl1c_trans_normal].dma & |
| 1005 | AT_DMA_HI_ADDR_MASK) >> 32)); |
| 1006 | /* just enable normal priority TX queue */ |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 1007 | AT_WRITE_REG(hw, REG_TPD_PRI0_ADDR_LO, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1008 | (u32)(tpd_ring[atl1c_trans_normal].dma & |
| 1009 | AT_DMA_LO_ADDR_MASK)); |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 1010 | AT_WRITE_REG(hw, REG_TPD_PRI1_ADDR_LO, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1011 | (u32)(tpd_ring[atl1c_trans_high].dma & |
| 1012 | AT_DMA_LO_ADDR_MASK)); |
| 1013 | AT_WRITE_REG(hw, REG_TPD_RING_SIZE, |
| 1014 | (u32)(tpd_ring[0].count & TPD_RING_SIZE_MASK)); |
| 1015 | |
| 1016 | |
| 1017 | /* RFD */ |
| 1018 | AT_WRITE_REG(hw, REG_RX_BASE_ADDR_HI, |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1019 | (u32)((rfd_ring->dma & AT_DMA_HI_ADDR_MASK) >> 32)); |
| 1020 | AT_WRITE_REG(hw, REG_RFD0_HEAD_ADDR_LO, |
| 1021 | (u32)(rfd_ring->dma & AT_DMA_LO_ADDR_MASK)); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1022 | |
| 1023 | AT_WRITE_REG(hw, REG_RFD_RING_SIZE, |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1024 | rfd_ring->count & RFD_RING_SIZE_MASK); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1025 | AT_WRITE_REG(hw, REG_RX_BUF_SIZE, |
| 1026 | adapter->rx_buffer_len & RX_BUF_SIZE_MASK); |
| 1027 | |
| 1028 | /* RRD */ |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1029 | AT_WRITE_REG(hw, REG_RRD0_HEAD_ADDR_LO, |
| 1030 | (u32)(rrd_ring->dma & AT_DMA_LO_ADDR_MASK)); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1031 | AT_WRITE_REG(hw, REG_RRD_RING_SIZE, |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1032 | (rrd_ring->count & RRD_RING_SIZE_MASK)); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1033 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1034 | if (hw->nic_type == athr_l2c_b) { |
| 1035 | AT_WRITE_REG(hw, REG_SRAM_RXF_LEN, 0x02a0L); |
| 1036 | AT_WRITE_REG(hw, REG_SRAM_TXF_LEN, 0x0100L); |
| 1037 | AT_WRITE_REG(hw, REG_SRAM_RXF_ADDR, 0x029f0000L); |
| 1038 | AT_WRITE_REG(hw, REG_SRAM_RFD0_INFO, 0x02bf02a0L); |
| 1039 | AT_WRITE_REG(hw, REG_SRAM_TXF_ADDR, 0x03bf02c0L); |
| 1040 | AT_WRITE_REG(hw, REG_SRAM_TRD_ADDR, 0x03df03c0L); |
| 1041 | AT_WRITE_REG(hw, REG_TXF_WATER_MARK, 0); /* TX watermark, to enter l1 state.*/ |
| 1042 | AT_WRITE_REG(hw, REG_RXD_DMA_CTRL, 0); /* RXD threshold.*/ |
| 1043 | } |
| 1044 | if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d_2) { |
| 1045 | /* Power Saving for L2c_B */ |
| 1046 | AT_READ_REG(hw, REG_SERDES_LOCK, &data); |
| 1047 | data |= SERDES_MAC_CLK_SLOWDOWN; |
| 1048 | data |= SERDES_PYH_CLK_SLOWDOWN; |
| 1049 | AT_WRITE_REG(hw, REG_SERDES_LOCK, data); |
| 1050 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1051 | /* Load all of base address above */ |
| 1052 | AT_WRITE_REG(hw, REG_LOAD_PTR, 1); |
| 1053 | } |
| 1054 | |
| 1055 | static void atl1c_configure_tx(struct atl1c_adapter *adapter) |
| 1056 | { |
| 1057 | struct atl1c_hw *hw = &adapter->hw; |
Huang, Xiong | 59e26ef | 2012-04-17 19:32:36 +0000 | [diff] [blame] | 1058 | int max_pay_load; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1059 | u16 tx_offload_thresh; |
| 1060 | u32 txq_ctrl_data; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1061 | |
Huang, Xiong | c08b9b2 | 2012-04-18 22:01:23 +0000 | [diff] [blame] | 1062 | tx_offload_thresh = MAX_TSO_FRAME_SIZE; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1063 | AT_WRITE_REG(hw, REG_TX_TSO_OFFLOAD_THRESH, |
| 1064 | (tx_offload_thresh >> 3) & TX_TSO_OFFLOAD_THRESH_MASK); |
Huang, Xiong | 59e26ef | 2012-04-17 19:32:36 +0000 | [diff] [blame] | 1065 | max_pay_load = pcie_get_readrq(adapter->pdev) >> 8; |
stephen hemminger | 81b504b | 2011-02-23 09:06:49 +0000 | [diff] [blame] | 1066 | hw->dmar_block = min_t(u32, max_pay_load, hw->dmar_block); |
Huang, Xiong | 59e26ef | 2012-04-17 19:32:36 +0000 | [diff] [blame] | 1067 | /* |
| 1068 | * if BIOS had changed the dam-read-max-length to an invalid value, |
| 1069 | * restore it to default value |
| 1070 | */ |
| 1071 | if (hw->dmar_block < DEVICE_CTRL_MAXRRS_MIN) { |
| 1072 | pcie_set_readrq(adapter->pdev, 128 << DEVICE_CTRL_MAXRRS_MIN); |
| 1073 | hw->dmar_block = DEVICE_CTRL_MAXRRS_MIN; |
| 1074 | } |
Huang, Xiong | c24588a | 2012-04-17 19:32:35 +0000 | [diff] [blame] | 1075 | txq_ctrl_data = |
| 1076 | hw->nic_type == athr_l2c_b || hw->nic_type == athr_l2c_b2 ? |
| 1077 | L2CB_TXQ_CFGV : L1C_TXQ_CFGV; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1078 | |
| 1079 | AT_WRITE_REG(hw, REG_TXQ_CTRL, txq_ctrl_data); |
| 1080 | } |
| 1081 | |
| 1082 | static void atl1c_configure_rx(struct atl1c_adapter *adapter) |
| 1083 | { |
| 1084 | struct atl1c_hw *hw = &adapter->hw; |
| 1085 | u32 rxq_ctrl_data; |
| 1086 | |
| 1087 | rxq_ctrl_data = (hw->rfd_burst & RXQ_RFD_BURST_NUM_MASK) << |
| 1088 | RXQ_RFD_BURST_NUM_SHIFT; |
| 1089 | |
| 1090 | if (hw->ctrl_flags & ATL1C_RX_IPV6_CHKSUM) |
| 1091 | rxq_ctrl_data |= IPV6_CHKSUM_CTRL_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1092 | |
Huang, Xiong | 9c52821 | 2012-04-18 22:01:21 +0000 | [diff] [blame] | 1093 | /* aspm for gigabit */ |
| 1094 | if (hw->nic_type != athr_l1d_2 && (hw->device_id & 1) != 0) |
| 1095 | rxq_ctrl_data = FIELD_SETX(rxq_ctrl_data, ASPM_THRUPUT_LIMIT, |
| 1096 | ASPM_THRUPUT_LIMIT_100M); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1097 | |
| 1098 | AT_WRITE_REG(hw, REG_RXQ_CTRL, rxq_ctrl_data); |
| 1099 | } |
| 1100 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1101 | static void atl1c_configure_dma(struct atl1c_adapter *adapter) |
| 1102 | { |
| 1103 | struct atl1c_hw *hw = &adapter->hw; |
| 1104 | u32 dma_ctrl_data; |
| 1105 | |
Huang, Xiong | 37bfccb | 2012-04-17 19:32:33 +0000 | [diff] [blame] | 1106 | dma_ctrl_data = FIELDX(DMA_CTRL_RORDER_MODE, DMA_CTRL_RORDER_MODE_OUT) | |
| 1107 | DMA_CTRL_RREQ_PRI_DATA | |
| 1108 | FIELDX(DMA_CTRL_RREQ_BLEN, hw->dmar_block) | |
| 1109 | FIELDX(DMA_CTRL_WDLY_CNT, DMA_CTRL_WDLY_CNT_DEF) | |
| 1110 | FIELDX(DMA_CTRL_RDLY_CNT, DMA_CTRL_RDLY_CNT_DEF); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1111 | |
| 1112 | AT_WRITE_REG(hw, REG_DMA_CTRL, dma_ctrl_data); |
| 1113 | } |
| 1114 | |
| 1115 | /* |
| 1116 | * Stop the mac, transmit and receive units |
| 1117 | * hw - Struct containing variables accessed by shared code |
| 1118 | * return : 0 or idle status (if error) |
| 1119 | */ |
| 1120 | static int atl1c_stop_mac(struct atl1c_hw *hw) |
| 1121 | { |
| 1122 | u32 data; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1123 | |
| 1124 | AT_READ_REG(hw, REG_RXQ_CTRL, &data); |
Huang, Xiong | 027392c | 2012-04-17 19:32:31 +0000 | [diff] [blame] | 1125 | data &= ~RXQ_CTRL_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1126 | AT_WRITE_REG(hw, REG_RXQ_CTRL, data); |
| 1127 | |
| 1128 | AT_READ_REG(hw, REG_TXQ_CTRL, &data); |
| 1129 | data &= ~TXQ_CTRL_EN; |
Huang, Xiong | 0cbec61 | 2012-04-17 19:32:32 +0000 | [diff] [blame] | 1130 | AT_WRITE_REG(hw, REG_TXQ_CTRL, data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1131 | |
Huang, Xiong | 969a7ee | 2012-04-18 22:01:22 +0000 | [diff] [blame] | 1132 | atl1c_wait_until_idle(hw, IDLE_STATUS_RXQ_BUSY | IDLE_STATUS_TXQ_BUSY); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1133 | |
| 1134 | AT_READ_REG(hw, REG_MAC_CTRL, &data); |
| 1135 | data &= ~(MAC_CTRL_TX_EN | MAC_CTRL_RX_EN); |
| 1136 | AT_WRITE_REG(hw, REG_MAC_CTRL, data); |
| 1137 | |
Huang, Xiong | 969a7ee | 2012-04-18 22:01:22 +0000 | [diff] [blame] | 1138 | return (int)atl1c_wait_until_idle(hw, |
| 1139 | IDLE_STATUS_TXMAC_BUSY | IDLE_STATUS_RXMAC_BUSY); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | static void atl1c_enable_rx_ctrl(struct atl1c_hw *hw) |
| 1143 | { |
| 1144 | u32 data; |
| 1145 | |
| 1146 | AT_READ_REG(hw, REG_RXQ_CTRL, &data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1147 | data |= RXQ_CTRL_EN; |
| 1148 | AT_WRITE_REG(hw, REG_RXQ_CTRL, data); |
| 1149 | } |
| 1150 | |
| 1151 | static void atl1c_enable_tx_ctrl(struct atl1c_hw *hw) |
| 1152 | { |
| 1153 | u32 data; |
| 1154 | |
| 1155 | AT_READ_REG(hw, REG_TXQ_CTRL, &data); |
| 1156 | data |= TXQ_CTRL_EN; |
| 1157 | AT_WRITE_REG(hw, REG_TXQ_CTRL, data); |
| 1158 | } |
| 1159 | |
| 1160 | /* |
| 1161 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 1162 | * hw - Struct containing variables accessed by shared code |
| 1163 | * return : 0 or idle status (if error) |
| 1164 | */ |
| 1165 | static int atl1c_reset_mac(struct atl1c_hw *hw) |
| 1166 | { |
| 1167 | struct atl1c_adapter *adapter = (struct atl1c_adapter *)hw->adapter; |
| 1168 | struct pci_dev *pdev = adapter->pdev; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1169 | u32 master_ctrl_data = 0; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1170 | |
| 1171 | AT_WRITE_REG(hw, REG_IMR, 0); |
| 1172 | AT_WRITE_REG(hw, REG_ISR, ISR_DIS_INT); |
| 1173 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1174 | atl1c_stop_mac(hw); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1175 | /* |
| 1176 | * Issue Soft Reset to the MAC. This will reset the chip's |
| 1177 | * transmit, receive, DMA. It will not effect |
| 1178 | * the current PCI configuration. The global reset bit is self- |
| 1179 | * clearing, and should clear within a microsecond. |
| 1180 | */ |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1181 | AT_READ_REG(hw, REG_MASTER_CTRL, &master_ctrl_data); |
| 1182 | master_ctrl_data |= MASTER_CTRL_OOB_DIS_OFF; |
| 1183 | AT_WRITE_REGW(hw, REG_MASTER_CTRL, ((master_ctrl_data | MASTER_CTRL_SOFT_RST) |
| 1184 | & 0xFFFF)); |
| 1185 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1186 | AT_WRITE_FLUSH(hw); |
| 1187 | msleep(10); |
| 1188 | /* Wait at least 10ms for All module to be Idle */ |
Joe Perches | c930a66 | 2009-05-31 20:44:54 +0000 | [diff] [blame] | 1189 | |
Huang, Xiong | 969a7ee | 2012-04-18 22:01:22 +0000 | [diff] [blame] | 1190 | if (atl1c_wait_until_idle(hw, IDLE_STATUS_MASK)) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1191 | dev_err(&pdev->dev, |
Joe Perches | c930a66 | 2009-05-31 20:44:54 +0000 | [diff] [blame] | 1192 | "MAC state machine can't be idle since" |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1193 | " disabled for 10ms second\n"); |
| 1194 | return -1; |
| 1195 | } |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static void atl1c_disable_l0s_l1(struct atl1c_hw *hw) |
| 1200 | { |
| 1201 | u32 pm_ctrl_data; |
| 1202 | |
| 1203 | AT_READ_REG(hw, REG_PM_CTRL, &pm_ctrl_data); |
| 1204 | pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK << |
| 1205 | PM_CTRL_L1_ENTRY_TIMER_SHIFT); |
| 1206 | pm_ctrl_data &= ~PM_CTRL_CLK_SWH_L1; |
| 1207 | pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN; |
| 1208 | pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN; |
| 1209 | pm_ctrl_data &= ~PM_CTRL_MAC_ASPM_CHK; |
| 1210 | pm_ctrl_data &= ~PM_CTRL_SERDES_PD_EX_L1; |
| 1211 | |
| 1212 | pm_ctrl_data |= PM_CTRL_SERDES_BUDS_RX_L1_EN; |
| 1213 | pm_ctrl_data |= PM_CTRL_SERDES_PLL_L1_EN; |
| 1214 | pm_ctrl_data |= PM_CTRL_SERDES_L1_EN; |
| 1215 | AT_WRITE_REG(hw, REG_PM_CTRL, pm_ctrl_data); |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | * Set ASPM state. |
| 1220 | * Enable/disable L0s/L1 depend on link state. |
| 1221 | */ |
| 1222 | static void atl1c_set_aspm(struct atl1c_hw *hw, bool linkup) |
| 1223 | { |
| 1224 | u32 pm_ctrl_data; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1225 | u32 link_ctrl_data; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1226 | u32 link_l1_timer = 0xF; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1227 | |
| 1228 | AT_READ_REG(hw, REG_PM_CTRL, &pm_ctrl_data); |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1229 | AT_READ_REG(hw, REG_LINK_CTRL, &link_ctrl_data); |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1230 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1231 | pm_ctrl_data &= ~PM_CTRL_SERDES_PD_EX_L1; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1232 | pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK << |
| 1233 | PM_CTRL_L1_ENTRY_TIMER_SHIFT); |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1234 | pm_ctrl_data &= ~(PM_CTRL_LCKDET_TIMER_MASK << |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1235 | PM_CTRL_LCKDET_TIMER_SHIFT); |
| 1236 | pm_ctrl_data |= AT_LCKDET_TIMER << PM_CTRL_LCKDET_TIMER_SHIFT; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1237 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1238 | if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d || |
| 1239 | hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) { |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1240 | link_ctrl_data &= ~LINK_CTRL_EXT_SYNC; |
| 1241 | if (!(hw->ctrl_flags & ATL1C_APS_MODE_ENABLE)) { |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1242 | if (hw->nic_type == athr_l2c_b && hw->revision_id == L2CB_V10) |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1243 | link_ctrl_data |= LINK_CTRL_EXT_SYNC; |
| 1244 | } |
| 1245 | |
| 1246 | AT_WRITE_REG(hw, REG_LINK_CTRL, link_ctrl_data); |
| 1247 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1248 | pm_ctrl_data |= PM_CTRL_RCVR_WT_TIMER; |
| 1249 | pm_ctrl_data &= ~(PM_CTRL_PM_REQ_TIMER_MASK << |
| 1250 | PM_CTRL_PM_REQ_TIMER_SHIFT); |
| 1251 | pm_ctrl_data |= AT_ASPM_L1_TIMER << |
| 1252 | PM_CTRL_PM_REQ_TIMER_SHIFT; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1253 | pm_ctrl_data &= ~PM_CTRL_SA_DLY_EN; |
| 1254 | pm_ctrl_data &= ~PM_CTRL_HOTRST; |
| 1255 | pm_ctrl_data |= 1 << PM_CTRL_L1_ENTRY_TIMER_SHIFT; |
| 1256 | pm_ctrl_data |= PM_CTRL_SERDES_PD_EX_L1; |
| 1257 | } |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1258 | pm_ctrl_data |= PM_CTRL_MAC_ASPM_CHK; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1259 | if (linkup) { |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1260 | pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN; |
| 1261 | pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN; |
| 1262 | if (hw->ctrl_flags & ATL1C_ASPM_L1_SUPPORT) |
| 1263 | pm_ctrl_data |= PM_CTRL_ASPM_L1_EN; |
| 1264 | if (hw->ctrl_flags & ATL1C_ASPM_L0S_SUPPORT) |
| 1265 | pm_ctrl_data |= PM_CTRL_ASPM_L0S_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1266 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1267 | if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d || |
| 1268 | hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) { |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1269 | if (hw->nic_type == athr_l2c_b) |
| 1270 | if (!(hw->ctrl_flags & ATL1C_APS_MODE_ENABLE)) |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1271 | pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1272 | pm_ctrl_data &= ~PM_CTRL_SERDES_L1_EN; |
| 1273 | pm_ctrl_data &= ~PM_CTRL_SERDES_PLL_L1_EN; |
| 1274 | pm_ctrl_data &= ~PM_CTRL_SERDES_BUDS_RX_L1_EN; |
| 1275 | pm_ctrl_data |= PM_CTRL_CLK_SWH_L1; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1276 | if (hw->adapter->link_speed == SPEED_100 || |
| 1277 | hw->adapter->link_speed == SPEED_1000) { |
| 1278 | pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK << |
| 1279 | PM_CTRL_L1_ENTRY_TIMER_SHIFT); |
| 1280 | if (hw->nic_type == athr_l2c_b) |
| 1281 | link_l1_timer = 7; |
| 1282 | else if (hw->nic_type == athr_l2c_b2 || |
| 1283 | hw->nic_type == athr_l1d_2) |
| 1284 | link_l1_timer = 4; |
| 1285 | pm_ctrl_data |= link_l1_timer << |
| 1286 | PM_CTRL_L1_ENTRY_TIMER_SHIFT; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1287 | } |
| 1288 | } else { |
| 1289 | pm_ctrl_data |= PM_CTRL_SERDES_L1_EN; |
| 1290 | pm_ctrl_data |= PM_CTRL_SERDES_PLL_L1_EN; |
| 1291 | pm_ctrl_data |= PM_CTRL_SERDES_BUDS_RX_L1_EN; |
| 1292 | pm_ctrl_data &= ~PM_CTRL_CLK_SWH_L1; |
| 1293 | pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN; |
| 1294 | pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN; |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1295 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1296 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1297 | } else { |
Jie Yang | 52fbc10 | 2009-04-27 19:42:03 +0000 | [diff] [blame] | 1298 | pm_ctrl_data &= ~PM_CTRL_SERDES_L1_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1299 | pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN; |
| 1300 | pm_ctrl_data &= ~PM_CTRL_SERDES_PLL_L1_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1301 | pm_ctrl_data |= PM_CTRL_CLK_SWH_L1; |
| 1302 | |
| 1303 | if (hw->ctrl_flags & ATL1C_ASPM_L1_SUPPORT) |
| 1304 | pm_ctrl_data |= PM_CTRL_ASPM_L1_EN; |
| 1305 | else |
| 1306 | pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN; |
| 1307 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1308 | AT_WRITE_REG(hw, REG_PM_CTRL, pm_ctrl_data); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1309 | |
| 1310 | return; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter) |
| 1314 | { |
| 1315 | struct atl1c_hw *hw = &adapter->hw; |
| 1316 | struct net_device *netdev = adapter->netdev; |
| 1317 | u32 mac_ctrl_data; |
| 1318 | |
| 1319 | mac_ctrl_data = MAC_CTRL_TX_EN | MAC_CTRL_RX_EN; |
| 1320 | mac_ctrl_data |= (MAC_CTRL_TX_FLOW | MAC_CTRL_RX_FLOW); |
| 1321 | |
| 1322 | if (adapter->link_duplex == FULL_DUPLEX) { |
| 1323 | hw->mac_duplex = true; |
| 1324 | mac_ctrl_data |= MAC_CTRL_DUPLX; |
| 1325 | } |
| 1326 | |
| 1327 | if (adapter->link_speed == SPEED_1000) |
| 1328 | hw->mac_speed = atl1c_mac_speed_1000; |
| 1329 | else |
| 1330 | hw->mac_speed = atl1c_mac_speed_10_100; |
| 1331 | |
| 1332 | mac_ctrl_data |= (hw->mac_speed & MAC_CTRL_SPEED_MASK) << |
| 1333 | MAC_CTRL_SPEED_SHIFT; |
| 1334 | |
| 1335 | mac_ctrl_data |= (MAC_CTRL_ADD_CRC | MAC_CTRL_PAD); |
| 1336 | mac_ctrl_data |= ((hw->preamble_len & MAC_CTRL_PRMLEN_MASK) << |
| 1337 | MAC_CTRL_PRMLEN_SHIFT); |
| 1338 | |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 1339 | __atl1c_vlan_mode(netdev->features, &mac_ctrl_data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1340 | |
| 1341 | mac_ctrl_data |= MAC_CTRL_BC_EN; |
| 1342 | if (netdev->flags & IFF_PROMISC) |
| 1343 | mac_ctrl_data |= MAC_CTRL_PROMIS_EN; |
| 1344 | if (netdev->flags & IFF_ALLMULTI) |
| 1345 | mac_ctrl_data |= MAC_CTRL_MC_ALL_EN; |
| 1346 | |
| 1347 | mac_ctrl_data |= MAC_CTRL_SINGLE_PAUSE_EN; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1348 | if (hw->nic_type == athr_l1d || hw->nic_type == athr_l2c_b2 || |
| 1349 | hw->nic_type == athr_l1d_2) { |
Luis R. Rodriguez | 496c185 | 2010-02-16 15:16:45 -0800 | [diff] [blame] | 1350 | mac_ctrl_data |= MAC_CTRL_SPEED_MODE_SW; |
| 1351 | mac_ctrl_data |= MAC_CTRL_HASH_ALG_CRC32; |
| 1352 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1353 | AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data); |
| 1354 | } |
| 1355 | |
| 1356 | /* |
| 1357 | * atl1c_configure - Configure Transmit&Receive Unit after Reset |
| 1358 | * @adapter: board private structure |
| 1359 | * |
| 1360 | * Configure the Tx /Rx unit of the MAC after a reset. |
| 1361 | */ |
| 1362 | static int atl1c_configure(struct atl1c_adapter *adapter) |
| 1363 | { |
| 1364 | struct atl1c_hw *hw = &adapter->hw; |
| 1365 | u32 master_ctrl_data = 0; |
| 1366 | u32 intr_modrt_data; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1367 | u32 data; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1368 | |
| 1369 | /* clear interrupt status */ |
| 1370 | AT_WRITE_REG(hw, REG_ISR, 0xFFFFFFFF); |
| 1371 | /* Clear any WOL status */ |
| 1372 | AT_WRITE_REG(hw, REG_WOL_CTRL, 0); |
| 1373 | /* set Interrupt Clear Timer |
| 1374 | * HW will enable self to assert interrupt event to system after |
| 1375 | * waiting x-time for software to notify it accept interrupt. |
| 1376 | */ |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1377 | |
| 1378 | data = CLK_GATING_EN_ALL; |
| 1379 | if (hw->ctrl_flags & ATL1C_CLK_GATING_EN) { |
| 1380 | if (hw->nic_type == athr_l2c_b) |
| 1381 | data &= ~CLK_GATING_RXMAC_EN; |
| 1382 | } else |
| 1383 | data = 0; |
| 1384 | AT_WRITE_REG(hw, REG_CLK_GATING_CTRL, data); |
| 1385 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1386 | AT_WRITE_REG(hw, REG_INT_RETRIG_TIMER, |
| 1387 | hw->ict & INT_RETRIG_TIMER_MASK); |
| 1388 | |
| 1389 | atl1c_configure_des_ring(adapter); |
| 1390 | |
| 1391 | if (hw->ctrl_flags & ATL1C_INTR_MODRT_ENABLE) { |
| 1392 | intr_modrt_data = (hw->tx_imt & IRQ_MODRT_TIMER_MASK) << |
| 1393 | IRQ_MODRT_TX_TIMER_SHIFT; |
| 1394 | intr_modrt_data |= (hw->rx_imt & IRQ_MODRT_TIMER_MASK) << |
| 1395 | IRQ_MODRT_RX_TIMER_SHIFT; |
| 1396 | AT_WRITE_REG(hw, REG_IRQ_MODRT_TIMER_INIT, intr_modrt_data); |
| 1397 | master_ctrl_data |= |
| 1398 | MASTER_CTRL_TX_ITIMER_EN | MASTER_CTRL_RX_ITIMER_EN; |
| 1399 | } |
| 1400 | |
| 1401 | if (hw->ctrl_flags & ATL1C_INTR_CLEAR_ON_READ) |
| 1402 | master_ctrl_data |= MASTER_CTRL_INT_RDCLR; |
| 1403 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1404 | master_ctrl_data |= MASTER_CTRL_SA_TIMER_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1405 | AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data); |
| 1406 | |
Huang, Xiong | 8d5c683 | 2012-04-17 19:32:29 +0000 | [diff] [blame] | 1407 | AT_WRITE_REG(hw, REG_SMB_STAT_TIMER, |
| 1408 | hw->smb_timer & SMB_STAT_TIMER_MASK); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1409 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1410 | /* set MTU */ |
| 1411 | AT_WRITE_REG(hw, REG_MTU, hw->max_frame_size + ETH_HLEN + |
| 1412 | VLAN_HLEN + ETH_FCS_LEN); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1413 | |
| 1414 | atl1c_configure_tx(adapter); |
| 1415 | atl1c_configure_rx(adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1416 | atl1c_configure_dma(adapter); |
| 1417 | |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | static void atl1c_update_hw_stats(struct atl1c_adapter *adapter) |
| 1422 | { |
| 1423 | u16 hw_reg_addr = 0; |
| 1424 | unsigned long *stats_item = NULL; |
| 1425 | u32 data; |
| 1426 | |
| 1427 | /* update rx status */ |
| 1428 | hw_reg_addr = REG_MAC_RX_STATUS_BIN; |
| 1429 | stats_item = &adapter->hw_stats.rx_ok; |
| 1430 | while (hw_reg_addr <= REG_MAC_RX_STATUS_END) { |
| 1431 | AT_READ_REG(&adapter->hw, hw_reg_addr, &data); |
| 1432 | *stats_item += data; |
| 1433 | stats_item++; |
| 1434 | hw_reg_addr += 4; |
| 1435 | } |
| 1436 | /* update tx status */ |
| 1437 | hw_reg_addr = REG_MAC_TX_STATUS_BIN; |
| 1438 | stats_item = &adapter->hw_stats.tx_ok; |
| 1439 | while (hw_reg_addr <= REG_MAC_TX_STATUS_END) { |
| 1440 | AT_READ_REG(&adapter->hw, hw_reg_addr, &data); |
| 1441 | *stats_item += data; |
| 1442 | stats_item++; |
| 1443 | hw_reg_addr += 4; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | /* |
| 1448 | * atl1c_get_stats - Get System Network Statistics |
| 1449 | * @netdev: network interface device structure |
| 1450 | * |
| 1451 | * Returns the address of the device statistics structure. |
| 1452 | * The statistics are actually updated from the timer callback. |
| 1453 | */ |
| 1454 | static struct net_device_stats *atl1c_get_stats(struct net_device *netdev) |
| 1455 | { |
| 1456 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 1457 | struct atl1c_hw_stats *hw_stats = &adapter->hw_stats; |
Eric Dumazet | a2c483a | 2010-08-20 02:55:16 +0000 | [diff] [blame] | 1458 | struct net_device_stats *net_stats = &netdev->stats; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1459 | |
| 1460 | atl1c_update_hw_stats(adapter); |
| 1461 | net_stats->rx_packets = hw_stats->rx_ok; |
| 1462 | net_stats->tx_packets = hw_stats->tx_ok; |
| 1463 | net_stats->rx_bytes = hw_stats->rx_byte_cnt; |
| 1464 | net_stats->tx_bytes = hw_stats->tx_byte_cnt; |
| 1465 | net_stats->multicast = hw_stats->rx_mcast; |
| 1466 | net_stats->collisions = hw_stats->tx_1_col + |
| 1467 | hw_stats->tx_2_col * 2 + |
| 1468 | hw_stats->tx_late_col + hw_stats->tx_abort_col; |
| 1469 | net_stats->rx_errors = hw_stats->rx_frag + hw_stats->rx_fcs_err + |
| 1470 | hw_stats->rx_len_err + hw_stats->rx_sz_ov + |
| 1471 | hw_stats->rx_rrd_ov + hw_stats->rx_align_err; |
| 1472 | net_stats->rx_fifo_errors = hw_stats->rx_rxf_ov; |
| 1473 | net_stats->rx_length_errors = hw_stats->rx_len_err; |
| 1474 | net_stats->rx_crc_errors = hw_stats->rx_fcs_err; |
| 1475 | net_stats->rx_frame_errors = hw_stats->rx_align_err; |
| 1476 | net_stats->rx_over_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov; |
| 1477 | |
| 1478 | net_stats->rx_missed_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov; |
| 1479 | |
| 1480 | net_stats->tx_errors = hw_stats->tx_late_col + hw_stats->tx_abort_col + |
| 1481 | hw_stats->tx_underrun + hw_stats->tx_trunc; |
| 1482 | net_stats->tx_fifo_errors = hw_stats->tx_underrun; |
| 1483 | net_stats->tx_aborted_errors = hw_stats->tx_abort_col; |
| 1484 | net_stats->tx_window_errors = hw_stats->tx_late_col; |
| 1485 | |
Eric Dumazet | a2c483a | 2010-08-20 02:55:16 +0000 | [diff] [blame] | 1486 | return net_stats; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static inline void atl1c_clear_phy_int(struct atl1c_adapter *adapter) |
| 1490 | { |
| 1491 | u16 phy_data; |
| 1492 | |
| 1493 | spin_lock(&adapter->mdio_lock); |
| 1494 | atl1c_read_phy_reg(&adapter->hw, MII_ISR, &phy_data); |
| 1495 | spin_unlock(&adapter->mdio_lock); |
| 1496 | } |
| 1497 | |
| 1498 | static bool atl1c_clean_tx_irq(struct atl1c_adapter *adapter, |
| 1499 | enum atl1c_trans_queue type) |
| 1500 | { |
| 1501 | struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *) |
| 1502 | &adapter->tpd_ring[type]; |
| 1503 | struct atl1c_buffer *buffer_info; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 1504 | struct pci_dev *pdev = adapter->pdev; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1505 | u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean); |
| 1506 | u16 hw_next_to_clean; |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 1507 | u16 reg; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1508 | |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 1509 | reg = type == atl1c_trans_high ? REG_TPD_PRI1_CIDX : REG_TPD_PRI0_CIDX; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1510 | |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 1511 | AT_READ_REGW(&adapter->hw, reg, &hw_next_to_clean); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1512 | |
| 1513 | while (next_to_clean != hw_next_to_clean) { |
| 1514 | buffer_info = &tpd_ring->buffer_info[next_to_clean]; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 1515 | atl1c_clean_buffer(pdev, buffer_info, 1); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1516 | if (++next_to_clean == tpd_ring->count) |
| 1517 | next_to_clean = 0; |
| 1518 | atomic_set(&tpd_ring->next_to_clean, next_to_clean); |
| 1519 | } |
| 1520 | |
| 1521 | if (netif_queue_stopped(adapter->netdev) && |
| 1522 | netif_carrier_ok(adapter->netdev)) { |
| 1523 | netif_wake_queue(adapter->netdev); |
| 1524 | } |
| 1525 | |
| 1526 | return true; |
| 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | * atl1c_intr - Interrupt Handler |
| 1531 | * @irq: interrupt number |
| 1532 | * @data: pointer to a network interface device structure |
| 1533 | * @pt_regs: CPU registers structure |
| 1534 | */ |
| 1535 | static irqreturn_t atl1c_intr(int irq, void *data) |
| 1536 | { |
| 1537 | struct net_device *netdev = data; |
| 1538 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 1539 | struct pci_dev *pdev = adapter->pdev; |
| 1540 | struct atl1c_hw *hw = &adapter->hw; |
| 1541 | int max_ints = AT_MAX_INT_WORK; |
| 1542 | int handled = IRQ_NONE; |
| 1543 | u32 status; |
| 1544 | u32 reg_data; |
| 1545 | |
| 1546 | do { |
| 1547 | AT_READ_REG(hw, REG_ISR, ®_data); |
| 1548 | status = reg_data & hw->intr_mask; |
| 1549 | |
| 1550 | if (status == 0 || (status & ISR_DIS_INT) != 0) { |
| 1551 | if (max_ints != AT_MAX_INT_WORK) |
| 1552 | handled = IRQ_HANDLED; |
| 1553 | break; |
| 1554 | } |
| 1555 | /* link event */ |
| 1556 | if (status & ISR_GPHY) |
| 1557 | atl1c_clear_phy_int(adapter); |
| 1558 | /* Ack ISR */ |
| 1559 | AT_WRITE_REG(hw, REG_ISR, status | ISR_DIS_INT); |
| 1560 | if (status & ISR_RX_PKT) { |
| 1561 | if (likely(napi_schedule_prep(&adapter->napi))) { |
| 1562 | hw->intr_mask &= ~ISR_RX_PKT; |
| 1563 | AT_WRITE_REG(hw, REG_IMR, hw->intr_mask); |
| 1564 | __napi_schedule(&adapter->napi); |
| 1565 | } |
| 1566 | } |
| 1567 | if (status & ISR_TX_PKT) |
| 1568 | atl1c_clean_tx_irq(adapter, atl1c_trans_normal); |
| 1569 | |
| 1570 | handled = IRQ_HANDLED; |
| 1571 | /* check if PCIE PHY Link down */ |
| 1572 | if (status & ISR_ERROR) { |
| 1573 | if (netif_msg_hw(adapter)) |
| 1574 | dev_err(&pdev->dev, |
| 1575 | "atl1c hardware error (status = 0x%x)\n", |
| 1576 | status & ISR_ERROR); |
| 1577 | /* reset MAC */ |
Dan Carpenter | 7831545 | 2012-03-07 00:02:04 +0000 | [diff] [blame] | 1578 | set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 1579 | schedule_work(&adapter->common_task); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 1580 | return IRQ_HANDLED; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | if (status & ISR_OVER) |
| 1584 | if (netif_msg_intr(adapter)) |
| 1585 | dev_warn(&pdev->dev, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1586 | "TX/RX overflow (status = 0x%x)\n", |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1587 | status & ISR_OVER); |
| 1588 | |
| 1589 | /* link event */ |
| 1590 | if (status & (ISR_GPHY | ISR_MANUAL)) { |
Eric Dumazet | a2c483a | 2010-08-20 02:55:16 +0000 | [diff] [blame] | 1591 | netdev->stats.tx_carrier_errors++; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1592 | atl1c_link_chg_event(adapter); |
| 1593 | break; |
| 1594 | } |
| 1595 | |
| 1596 | } while (--max_ints > 0); |
| 1597 | /* re-enable Interrupt*/ |
| 1598 | AT_WRITE_REG(&adapter->hw, REG_ISR, 0); |
| 1599 | return handled; |
| 1600 | } |
| 1601 | |
| 1602 | static inline void atl1c_rx_checksum(struct atl1c_adapter *adapter, |
| 1603 | struct sk_buff *skb, struct atl1c_recv_ret_status *prrs) |
| 1604 | { |
| 1605 | /* |
| 1606 | * The pid field in RRS in not correct sometimes, so we |
| 1607 | * cannot figure out if the packet is fragmented or not, |
| 1608 | * so we tell the KERNEL CHECKSUM_NONE |
| 1609 | */ |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1610 | skb_checksum_none_assert(skb); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1613 | static int atl1c_alloc_rx_buffer(struct atl1c_adapter *adapter) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1614 | { |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1615 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1616 | struct pci_dev *pdev = adapter->pdev; |
| 1617 | struct atl1c_buffer *buffer_info, *next_info; |
| 1618 | struct sk_buff *skb; |
| 1619 | void *vir_addr = NULL; |
| 1620 | u16 num_alloc = 0; |
| 1621 | u16 rfd_next_to_use, next_next; |
| 1622 | struct atl1c_rx_free_desc *rfd_desc; |
| 1623 | |
| 1624 | next_next = rfd_next_to_use = rfd_ring->next_to_use; |
| 1625 | if (++next_next == rfd_ring->count) |
| 1626 | next_next = 0; |
| 1627 | buffer_info = &rfd_ring->buffer_info[rfd_next_to_use]; |
| 1628 | next_info = &rfd_ring->buffer_info[next_next]; |
| 1629 | |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 1630 | while (next_info->flags & ATL1C_BUFFER_FREE) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1631 | rfd_desc = ATL1C_RFD_DESC(rfd_ring, rfd_next_to_use); |
| 1632 | |
Pradeep A Dalvi | 1d26643 | 2012-02-05 02:49:09 +0000 | [diff] [blame] | 1633 | skb = netdev_alloc_skb(adapter->netdev, adapter->rx_buffer_len); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1634 | if (unlikely(!skb)) { |
| 1635 | if (netif_msg_rx_err(adapter)) |
| 1636 | dev_warn(&pdev->dev, "alloc rx buffer failed\n"); |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | /* |
| 1641 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 1642 | * this will result in a 16 byte aligned IP header after |
| 1643 | * the 14 byte MAC header is removed |
| 1644 | */ |
| 1645 | vir_addr = skb->data; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 1646 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1647 | buffer_info->skb = skb; |
| 1648 | buffer_info->length = adapter->rx_buffer_len; |
| 1649 | buffer_info->dma = pci_map_single(pdev, vir_addr, |
| 1650 | buffer_info->length, |
| 1651 | PCI_DMA_FROMDEVICE); |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 1652 | ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE, |
| 1653 | ATL1C_PCIMAP_FROMDEVICE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1654 | rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 1655 | rfd_next_to_use = next_next; |
| 1656 | if (++next_next == rfd_ring->count) |
| 1657 | next_next = 0; |
| 1658 | buffer_info = &rfd_ring->buffer_info[rfd_next_to_use]; |
| 1659 | next_info = &rfd_ring->buffer_info[next_next]; |
| 1660 | num_alloc++; |
| 1661 | } |
| 1662 | |
| 1663 | if (num_alloc) { |
| 1664 | /* TODO: update mailbox here */ |
| 1665 | wmb(); |
| 1666 | rfd_ring->next_to_use = rfd_next_to_use; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1667 | AT_WRITE_REG(&adapter->hw, REG_MB_RFD0_PROD_IDX, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1668 | rfd_ring->next_to_use & MB_RFDX_PROD_IDX_MASK); |
| 1669 | } |
| 1670 | |
| 1671 | return num_alloc; |
| 1672 | } |
| 1673 | |
| 1674 | static void atl1c_clean_rrd(struct atl1c_rrd_ring *rrd_ring, |
| 1675 | struct atl1c_recv_ret_status *rrs, u16 num) |
| 1676 | { |
| 1677 | u16 i; |
| 1678 | /* the relationship between rrd and rfd is one map one */ |
| 1679 | for (i = 0; i < num; i++, rrs = ATL1C_RRD_DESC(rrd_ring, |
| 1680 | rrd_ring->next_to_clean)) { |
| 1681 | rrs->word3 &= ~RRS_RXD_UPDATED; |
| 1682 | if (++rrd_ring->next_to_clean == rrd_ring->count) |
| 1683 | rrd_ring->next_to_clean = 0; |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | static void atl1c_clean_rfd(struct atl1c_rfd_ring *rfd_ring, |
| 1688 | struct atl1c_recv_ret_status *rrs, u16 num) |
| 1689 | { |
| 1690 | u16 i; |
| 1691 | u16 rfd_index; |
| 1692 | struct atl1c_buffer *buffer_info = rfd_ring->buffer_info; |
| 1693 | |
| 1694 | rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) & |
| 1695 | RRS_RX_RFD_INDEX_MASK; |
| 1696 | for (i = 0; i < num; i++) { |
| 1697 | buffer_info[rfd_index].skb = NULL; |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 1698 | ATL1C_SET_BUFFER_STATE(&buffer_info[rfd_index], |
| 1699 | ATL1C_BUFFER_FREE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1700 | if (++rfd_index == rfd_ring->count) |
| 1701 | rfd_index = 0; |
| 1702 | } |
| 1703 | rfd_ring->next_to_clean = rfd_index; |
| 1704 | } |
| 1705 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1706 | static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1707 | int *work_done, int work_to_do) |
| 1708 | { |
| 1709 | u16 rfd_num, rfd_index; |
| 1710 | u16 count = 0; |
| 1711 | u16 length; |
| 1712 | struct pci_dev *pdev = adapter->pdev; |
| 1713 | struct net_device *netdev = adapter->netdev; |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1714 | struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 1715 | struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1716 | struct sk_buff *skb; |
| 1717 | struct atl1c_recv_ret_status *rrs; |
| 1718 | struct atl1c_buffer *buffer_info; |
| 1719 | |
| 1720 | while (1) { |
| 1721 | if (*work_done >= work_to_do) |
| 1722 | break; |
| 1723 | rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean); |
| 1724 | if (likely(RRS_RXD_IS_VALID(rrs->word3))) { |
| 1725 | rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) & |
| 1726 | RRS_RX_RFD_CNT_MASK; |
roel kluin | 37b76c6 | 2009-07-12 12:57:38 +0000 | [diff] [blame] | 1727 | if (unlikely(rfd_num != 1)) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1728 | /* TODO support mul rfd*/ |
| 1729 | if (netif_msg_rx_err(adapter)) |
| 1730 | dev_warn(&pdev->dev, |
| 1731 | "Multi rfd not support yet!\n"); |
| 1732 | goto rrs_checked; |
| 1733 | } else { |
| 1734 | break; |
| 1735 | } |
| 1736 | rrs_checked: |
| 1737 | atl1c_clean_rrd(rrd_ring, rrs, rfd_num); |
| 1738 | if (rrs->word3 & (RRS_RX_ERR_SUM | RRS_802_3_LEN_ERR)) { |
| 1739 | atl1c_clean_rfd(rfd_ring, rrs, rfd_num); |
| 1740 | if (netif_msg_rx_err(adapter)) |
| 1741 | dev_warn(&pdev->dev, |
| 1742 | "wrong packet! rrs word3 is %x\n", |
| 1743 | rrs->word3); |
| 1744 | continue; |
| 1745 | } |
| 1746 | |
| 1747 | length = le16_to_cpu((rrs->word3 >> RRS_PKT_SIZE_SHIFT) & |
| 1748 | RRS_PKT_SIZE_MASK); |
| 1749 | /* Good Receive */ |
| 1750 | if (likely(rfd_num == 1)) { |
| 1751 | rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) & |
| 1752 | RRS_RX_RFD_INDEX_MASK; |
| 1753 | buffer_info = &rfd_ring->buffer_info[rfd_index]; |
| 1754 | pci_unmap_single(pdev, buffer_info->dma, |
| 1755 | buffer_info->length, PCI_DMA_FROMDEVICE); |
| 1756 | skb = buffer_info->skb; |
| 1757 | } else { |
| 1758 | /* TODO */ |
| 1759 | if (netif_msg_rx_err(adapter)) |
| 1760 | dev_warn(&pdev->dev, |
| 1761 | "Multi rfd not support yet!\n"); |
| 1762 | break; |
| 1763 | } |
| 1764 | atl1c_clean_rfd(rfd_ring, rrs, rfd_num); |
| 1765 | skb_put(skb, length - ETH_FCS_LEN); |
| 1766 | skb->protocol = eth_type_trans(skb, netdev); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1767 | atl1c_rx_checksum(adapter, skb, rrs); |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 1768 | if (rrs->word3 & RRS_VLAN_INS) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1769 | u16 vlan; |
| 1770 | |
| 1771 | AT_TAG_TO_VLAN(rrs->vlan_tag, vlan); |
| 1772 | vlan = le16_to_cpu(vlan); |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 1773 | __vlan_hwaccel_put_tag(skb, vlan); |
| 1774 | } |
| 1775 | netif_receive_skb(skb); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1776 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1777 | (*work_done)++; |
| 1778 | count++; |
| 1779 | } |
| 1780 | if (count) |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1781 | atl1c_alloc_rx_buffer(adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | /* |
| 1785 | * atl1c_clean - NAPI Rx polling callback |
| 1786 | * @adapter: board private structure |
| 1787 | */ |
| 1788 | static int atl1c_clean(struct napi_struct *napi, int budget) |
| 1789 | { |
| 1790 | struct atl1c_adapter *adapter = |
| 1791 | container_of(napi, struct atl1c_adapter, napi); |
| 1792 | int work_done = 0; |
| 1793 | |
| 1794 | /* Keep link state information with original netdev */ |
| 1795 | if (!netif_carrier_ok(adapter->netdev)) |
| 1796 | goto quit_polling; |
| 1797 | /* just enable one RXQ */ |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 1798 | atl1c_clean_rx_irq(adapter, &work_done, budget); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1799 | |
| 1800 | if (work_done < budget) { |
| 1801 | quit_polling: |
| 1802 | napi_complete(napi); |
| 1803 | adapter->hw.intr_mask |= ISR_RX_PKT; |
| 1804 | AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask); |
| 1805 | } |
| 1806 | return work_done; |
| 1807 | } |
| 1808 | |
| 1809 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1810 | |
| 1811 | /* |
| 1812 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 1813 | * without having to re-enable interrupts. It's not called while |
| 1814 | * the interrupt routine is executing. |
| 1815 | */ |
| 1816 | static void atl1c_netpoll(struct net_device *netdev) |
| 1817 | { |
| 1818 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 1819 | |
| 1820 | disable_irq(adapter->pdev->irq); |
| 1821 | atl1c_intr(adapter->pdev->irq, netdev); |
| 1822 | enable_irq(adapter->pdev->irq); |
| 1823 | } |
| 1824 | #endif |
| 1825 | |
| 1826 | static inline u16 atl1c_tpd_avail(struct atl1c_adapter *adapter, enum atl1c_trans_queue type) |
| 1827 | { |
| 1828 | struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type]; |
| 1829 | u16 next_to_use = 0; |
| 1830 | u16 next_to_clean = 0; |
| 1831 | |
| 1832 | next_to_clean = atomic_read(&tpd_ring->next_to_clean); |
| 1833 | next_to_use = tpd_ring->next_to_use; |
| 1834 | |
| 1835 | return (u16)(next_to_clean > next_to_use) ? |
| 1836 | (next_to_clean - next_to_use - 1) : |
| 1837 | (tpd_ring->count + next_to_clean - next_to_use - 1); |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * get next usable tpd |
| 1842 | * Note: should call atl1c_tdp_avail to make sure |
| 1843 | * there is enough tpd to use |
| 1844 | */ |
| 1845 | static struct atl1c_tpd_desc *atl1c_get_tpd(struct atl1c_adapter *adapter, |
| 1846 | enum atl1c_trans_queue type) |
| 1847 | { |
| 1848 | struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type]; |
| 1849 | struct atl1c_tpd_desc *tpd_desc; |
| 1850 | u16 next_to_use = 0; |
| 1851 | |
| 1852 | next_to_use = tpd_ring->next_to_use; |
| 1853 | if (++tpd_ring->next_to_use == tpd_ring->count) |
| 1854 | tpd_ring->next_to_use = 0; |
| 1855 | tpd_desc = ATL1C_TPD_DESC(tpd_ring, next_to_use); |
| 1856 | memset(tpd_desc, 0, sizeof(struct atl1c_tpd_desc)); |
| 1857 | return tpd_desc; |
| 1858 | } |
| 1859 | |
| 1860 | static struct atl1c_buffer * |
| 1861 | atl1c_get_tx_buffer(struct atl1c_adapter *adapter, struct atl1c_tpd_desc *tpd) |
| 1862 | { |
| 1863 | struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring; |
| 1864 | |
| 1865 | return &tpd_ring->buffer_info[tpd - |
| 1866 | (struct atl1c_tpd_desc *)tpd_ring->desc]; |
| 1867 | } |
| 1868 | |
| 1869 | /* Calculate the transmit packet descript needed*/ |
| 1870 | static u16 atl1c_cal_tpd_req(const struct sk_buff *skb) |
| 1871 | { |
| 1872 | u16 tpd_req; |
| 1873 | u16 proto_hdr_len = 0; |
| 1874 | |
| 1875 | tpd_req = skb_shinfo(skb)->nr_frags + 1; |
| 1876 | |
| 1877 | if (skb_is_gso(skb)) { |
| 1878 | proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1879 | if (proto_hdr_len < skb_headlen(skb)) |
| 1880 | tpd_req++; |
| 1881 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 1882 | tpd_req++; |
| 1883 | } |
| 1884 | return tpd_req; |
| 1885 | } |
| 1886 | |
| 1887 | static int atl1c_tso_csum(struct atl1c_adapter *adapter, |
| 1888 | struct sk_buff *skb, |
| 1889 | struct atl1c_tpd_desc **tpd, |
| 1890 | enum atl1c_trans_queue type) |
| 1891 | { |
| 1892 | struct pci_dev *pdev = adapter->pdev; |
| 1893 | u8 hdr_len; |
| 1894 | u32 real_len; |
| 1895 | unsigned short offload_type; |
| 1896 | int err; |
| 1897 | |
| 1898 | if (skb_is_gso(skb)) { |
| 1899 | if (skb_header_cloned(skb)) { |
| 1900 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 1901 | if (unlikely(err)) |
| 1902 | return -1; |
| 1903 | } |
| 1904 | offload_type = skb_shinfo(skb)->gso_type; |
| 1905 | |
| 1906 | if (offload_type & SKB_GSO_TCPV4) { |
| 1907 | real_len = (((unsigned char *)ip_hdr(skb) - skb->data) |
| 1908 | + ntohs(ip_hdr(skb)->tot_len)); |
| 1909 | |
| 1910 | if (real_len < skb->len) |
| 1911 | pskb_trim(skb, real_len); |
| 1912 | |
| 1913 | hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb)); |
| 1914 | if (unlikely(skb->len == hdr_len)) { |
| 1915 | /* only xsum need */ |
| 1916 | if (netif_msg_tx_queued(adapter)) |
| 1917 | dev_warn(&pdev->dev, |
| 1918 | "IPV4 tso with zero data??\n"); |
| 1919 | goto check_sum; |
| 1920 | } else { |
| 1921 | ip_hdr(skb)->check = 0; |
| 1922 | tcp_hdr(skb)->check = ~csum_tcpudp_magic( |
| 1923 | ip_hdr(skb)->saddr, |
| 1924 | ip_hdr(skb)->daddr, |
| 1925 | 0, IPPROTO_TCP, 0); |
| 1926 | (*tpd)->word1 |= 1 << TPD_IPV4_PACKET_SHIFT; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | if (offload_type & SKB_GSO_TCPV6) { |
| 1931 | struct atl1c_tpd_ext_desc *etpd = |
| 1932 | *(struct atl1c_tpd_ext_desc **)(tpd); |
| 1933 | |
| 1934 | memset(etpd, 0, sizeof(struct atl1c_tpd_ext_desc)); |
| 1935 | *tpd = atl1c_get_tpd(adapter, type); |
| 1936 | ipv6_hdr(skb)->payload_len = 0; |
| 1937 | /* check payload == 0 byte ? */ |
| 1938 | hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb)); |
| 1939 | if (unlikely(skb->len == hdr_len)) { |
| 1940 | /* only xsum need */ |
| 1941 | if (netif_msg_tx_queued(adapter)) |
| 1942 | dev_warn(&pdev->dev, |
| 1943 | "IPV6 tso with zero data??\n"); |
| 1944 | goto check_sum; |
| 1945 | } else |
| 1946 | tcp_hdr(skb)->check = ~csum_ipv6_magic( |
| 1947 | &ipv6_hdr(skb)->saddr, |
| 1948 | &ipv6_hdr(skb)->daddr, |
| 1949 | 0, IPPROTO_TCP, 0); |
| 1950 | etpd->word1 |= 1 << TPD_LSO_EN_SHIFT; |
| 1951 | etpd->word1 |= 1 << TPD_LSO_VER_SHIFT; |
| 1952 | etpd->pkt_len = cpu_to_le32(skb->len); |
| 1953 | (*tpd)->word1 |= 1 << TPD_LSO_VER_SHIFT; |
| 1954 | } |
| 1955 | |
| 1956 | (*tpd)->word1 |= 1 << TPD_LSO_EN_SHIFT; |
| 1957 | (*tpd)->word1 |= (skb_transport_offset(skb) & TPD_TCPHDR_OFFSET_MASK) << |
| 1958 | TPD_TCPHDR_OFFSET_SHIFT; |
| 1959 | (*tpd)->word1 |= (skb_shinfo(skb)->gso_size & TPD_MSS_MASK) << |
| 1960 | TPD_MSS_SHIFT; |
| 1961 | return 0; |
| 1962 | } |
| 1963 | |
| 1964 | check_sum: |
| 1965 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
| 1966 | u8 css, cso; |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 1967 | cso = skb_checksum_start_offset(skb); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 1968 | |
| 1969 | if (unlikely(cso & 0x1)) { |
| 1970 | if (netif_msg_tx_err(adapter)) |
| 1971 | dev_err(&adapter->pdev->dev, |
| 1972 | "payload offset should not an event number\n"); |
| 1973 | return -1; |
| 1974 | } else { |
| 1975 | css = cso + skb->csum_offset; |
| 1976 | |
| 1977 | (*tpd)->word1 |= ((cso >> 1) & TPD_PLOADOFFSET_MASK) << |
| 1978 | TPD_PLOADOFFSET_SHIFT; |
| 1979 | (*tpd)->word1 |= ((css >> 1) & TPD_CCSUM_OFFSET_MASK) << |
| 1980 | TPD_CCSUM_OFFSET_SHIFT; |
| 1981 | (*tpd)->word1 |= 1 << TPD_CCSUM_EN_SHIFT; |
| 1982 | } |
| 1983 | } |
| 1984 | return 0; |
| 1985 | } |
| 1986 | |
| 1987 | static void atl1c_tx_map(struct atl1c_adapter *adapter, |
| 1988 | struct sk_buff *skb, struct atl1c_tpd_desc *tpd, |
| 1989 | enum atl1c_trans_queue type) |
| 1990 | { |
| 1991 | struct atl1c_tpd_desc *use_tpd = NULL; |
| 1992 | struct atl1c_buffer *buffer_info = NULL; |
| 1993 | u16 buf_len = skb_headlen(skb); |
| 1994 | u16 map_len = 0; |
| 1995 | u16 mapped_len = 0; |
| 1996 | u16 hdr_len = 0; |
| 1997 | u16 nr_frags; |
| 1998 | u16 f; |
| 1999 | int tso; |
| 2000 | |
| 2001 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 2002 | tso = (tpd->word1 >> TPD_LSO_EN_SHIFT) & TPD_LSO_EN_MASK; |
| 2003 | if (tso) { |
| 2004 | /* TSO */ |
| 2005 | map_len = hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 2006 | use_tpd = tpd; |
| 2007 | |
| 2008 | buffer_info = atl1c_get_tx_buffer(adapter, use_tpd); |
| 2009 | buffer_info->length = map_len; |
| 2010 | buffer_info->dma = pci_map_single(adapter->pdev, |
| 2011 | skb->data, hdr_len, PCI_DMA_TODEVICE); |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 2012 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY); |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 2013 | ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE, |
| 2014 | ATL1C_PCIMAP_TODEVICE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2015 | mapped_len += map_len; |
| 2016 | use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2017 | use_tpd->buffer_len = cpu_to_le16(buffer_info->length); |
| 2018 | } |
| 2019 | |
| 2020 | if (mapped_len < buf_len) { |
| 2021 | /* mapped_len == 0, means we should use the first tpd, |
| 2022 | which is given by caller */ |
| 2023 | if (mapped_len == 0) |
| 2024 | use_tpd = tpd; |
| 2025 | else { |
| 2026 | use_tpd = atl1c_get_tpd(adapter, type); |
| 2027 | memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc)); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2028 | } |
| 2029 | buffer_info = atl1c_get_tx_buffer(adapter, use_tpd); |
| 2030 | buffer_info->length = buf_len - mapped_len; |
| 2031 | buffer_info->dma = |
| 2032 | pci_map_single(adapter->pdev, skb->data + mapped_len, |
| 2033 | buffer_info->length, PCI_DMA_TODEVICE); |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 2034 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY); |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 2035 | ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE, |
| 2036 | ATL1C_PCIMAP_TODEVICE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2037 | use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2038 | use_tpd->buffer_len = cpu_to_le16(buffer_info->length); |
| 2039 | } |
| 2040 | |
| 2041 | for (f = 0; f < nr_frags; f++) { |
| 2042 | struct skb_frag_struct *frag; |
| 2043 | |
| 2044 | frag = &skb_shinfo(skb)->frags[f]; |
| 2045 | |
| 2046 | use_tpd = atl1c_get_tpd(adapter, type); |
| 2047 | memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc)); |
| 2048 | |
| 2049 | buffer_info = atl1c_get_tx_buffer(adapter, use_tpd); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2050 | buffer_info->length = skb_frag_size(frag); |
Ian Campbell | 8d1bb86 | 2011-08-29 23:18:20 +0000 | [diff] [blame] | 2051 | buffer_info->dma = skb_frag_dma_map(&adapter->pdev->dev, |
| 2052 | frag, 0, |
| 2053 | buffer_info->length, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 2054 | DMA_TO_DEVICE); |
Jie Yang | c6060be | 2009-11-06 00:32:05 -0800 | [diff] [blame] | 2055 | ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY); |
Jie Yang | 4b45e34 | 2009-12-06 22:56:59 +0000 | [diff] [blame] | 2056 | ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_PAGE, |
| 2057 | ATL1C_PCIMAP_TODEVICE); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2058 | use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2059 | use_tpd->buffer_len = cpu_to_le16(buffer_info->length); |
| 2060 | } |
| 2061 | |
| 2062 | /* The last tpd */ |
| 2063 | use_tpd->word1 |= 1 << TPD_EOP_SHIFT; |
| 2064 | /* The last buffer info contain the skb address, |
| 2065 | so it will be free after unmap */ |
| 2066 | buffer_info->skb = skb; |
| 2067 | } |
| 2068 | |
| 2069 | static void atl1c_tx_queue(struct atl1c_adapter *adapter, struct sk_buff *skb, |
| 2070 | struct atl1c_tpd_desc *tpd, enum atl1c_trans_queue type) |
| 2071 | { |
| 2072 | struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type]; |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 2073 | u16 reg; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2074 | |
Huang, Xiong | 0af4833 | 2012-04-17 19:32:30 +0000 | [diff] [blame] | 2075 | reg = type == atl1c_trans_high ? REG_TPD_PRI1_PIDX : REG_TPD_PRI0_PIDX; |
| 2076 | AT_WRITE_REGW(&adapter->hw, reg, tpd_ring->next_to_use); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2077 | } |
| 2078 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2079 | static netdev_tx_t atl1c_xmit_frame(struct sk_buff *skb, |
| 2080 | struct net_device *netdev) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2081 | { |
| 2082 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2083 | unsigned long flags; |
| 2084 | u16 tpd_req = 1; |
| 2085 | struct atl1c_tpd_desc *tpd; |
| 2086 | enum atl1c_trans_queue type = atl1c_trans_normal; |
| 2087 | |
| 2088 | if (test_bit(__AT_DOWN, &adapter->flags)) { |
| 2089 | dev_kfree_skb_any(skb); |
| 2090 | return NETDEV_TX_OK; |
| 2091 | } |
| 2092 | |
| 2093 | tpd_req = atl1c_cal_tpd_req(skb); |
| 2094 | if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) { |
| 2095 | if (netif_msg_pktdata(adapter)) |
| 2096 | dev_info(&adapter->pdev->dev, "tx locked\n"); |
| 2097 | return NETDEV_TX_LOCKED; |
| 2098 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2099 | |
| 2100 | if (atl1c_tpd_avail(adapter, type) < tpd_req) { |
| 2101 | /* no enough descriptor, just stop queue */ |
| 2102 | netif_stop_queue(netdev); |
| 2103 | spin_unlock_irqrestore(&adapter->tx_lock, flags); |
| 2104 | return NETDEV_TX_BUSY; |
| 2105 | } |
| 2106 | |
| 2107 | tpd = atl1c_get_tpd(adapter, type); |
| 2108 | |
| 2109 | /* do TSO and check sum */ |
| 2110 | if (atl1c_tso_csum(adapter, skb, &tpd, type) != 0) { |
| 2111 | spin_unlock_irqrestore(&adapter->tx_lock, flags); |
| 2112 | dev_kfree_skb_any(skb); |
| 2113 | return NETDEV_TX_OK; |
| 2114 | } |
| 2115 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 2116 | if (unlikely(vlan_tx_tag_present(skb))) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2117 | u16 vlan = vlan_tx_tag_get(skb); |
| 2118 | __le16 tag; |
| 2119 | |
| 2120 | vlan = cpu_to_le16(vlan); |
| 2121 | AT_VLAN_TO_TAG(vlan, tag); |
| 2122 | tpd->word1 |= 1 << TPD_INS_VTAG_SHIFT; |
| 2123 | tpd->vlan_tag = tag; |
| 2124 | } |
| 2125 | |
| 2126 | if (skb_network_offset(skb) != ETH_HLEN) |
| 2127 | tpd->word1 |= 1 << TPD_ETH_TYPE_SHIFT; /* Ethernet frame */ |
| 2128 | |
| 2129 | atl1c_tx_map(adapter, skb, tpd, type); |
| 2130 | atl1c_tx_queue(adapter, skb, tpd, type); |
| 2131 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2132 | spin_unlock_irqrestore(&adapter->tx_lock, flags); |
| 2133 | return NETDEV_TX_OK; |
| 2134 | } |
| 2135 | |
| 2136 | static void atl1c_free_irq(struct atl1c_adapter *adapter) |
| 2137 | { |
| 2138 | struct net_device *netdev = adapter->netdev; |
| 2139 | |
| 2140 | free_irq(adapter->pdev->irq, netdev); |
| 2141 | |
| 2142 | if (adapter->have_msi) |
| 2143 | pci_disable_msi(adapter->pdev); |
| 2144 | } |
| 2145 | |
| 2146 | static int atl1c_request_irq(struct atl1c_adapter *adapter) |
| 2147 | { |
| 2148 | struct pci_dev *pdev = adapter->pdev; |
| 2149 | struct net_device *netdev = adapter->netdev; |
| 2150 | int flags = 0; |
| 2151 | int err = 0; |
| 2152 | |
| 2153 | adapter->have_msi = true; |
| 2154 | err = pci_enable_msi(adapter->pdev); |
| 2155 | if (err) { |
| 2156 | if (netif_msg_ifup(adapter)) |
| 2157 | dev_err(&pdev->dev, |
| 2158 | "Unable to allocate MSI interrupt Error: %d\n", |
| 2159 | err); |
| 2160 | adapter->have_msi = false; |
Francois Romieu | 93f7fab | 2012-03-09 19:22:31 +0100 | [diff] [blame] | 2161 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2162 | |
| 2163 | if (!adapter->have_msi) |
| 2164 | flags |= IRQF_SHARED; |
Julia Lawall | 9aff7e9 | 2009-11-18 10:47:03 -0800 | [diff] [blame] | 2165 | err = request_irq(adapter->pdev->irq, atl1c_intr, flags, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2166 | netdev->name, netdev); |
| 2167 | if (err) { |
| 2168 | if (netif_msg_ifup(adapter)) |
| 2169 | dev_err(&pdev->dev, |
| 2170 | "Unable to allocate interrupt Error: %d\n", |
| 2171 | err); |
| 2172 | if (adapter->have_msi) |
| 2173 | pci_disable_msi(adapter->pdev); |
| 2174 | return err; |
| 2175 | } |
| 2176 | if (netif_msg_ifup(adapter)) |
| 2177 | dev_dbg(&pdev->dev, "atl1c_request_irq OK\n"); |
| 2178 | return err; |
| 2179 | } |
| 2180 | |
stephen hemminger | 0fb1e54 | 2010-10-21 07:50:49 +0000 | [diff] [blame] | 2181 | static int atl1c_up(struct atl1c_adapter *adapter) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2182 | { |
| 2183 | struct net_device *netdev = adapter->netdev; |
| 2184 | int num; |
| 2185 | int err; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2186 | |
| 2187 | netif_carrier_off(netdev); |
| 2188 | atl1c_init_ring_ptrs(adapter); |
| 2189 | atl1c_set_multi(netdev); |
| 2190 | atl1c_restore_vlan(adapter); |
| 2191 | |
Huang, Xiong | 9f1fd0e | 2012-04-17 19:32:26 +0000 | [diff] [blame] | 2192 | num = atl1c_alloc_rx_buffer(adapter); |
| 2193 | if (unlikely(num == 0)) { |
| 2194 | err = -ENOMEM; |
| 2195 | goto err_alloc_rx; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | if (atl1c_configure(adapter)) { |
| 2199 | err = -EIO; |
| 2200 | goto err_up; |
| 2201 | } |
| 2202 | |
| 2203 | err = atl1c_request_irq(adapter); |
| 2204 | if (unlikely(err)) |
| 2205 | goto err_up; |
| 2206 | |
| 2207 | clear_bit(__AT_DOWN, &adapter->flags); |
| 2208 | napi_enable(&adapter->napi); |
| 2209 | atl1c_irq_enable(adapter); |
| 2210 | atl1c_check_link_status(adapter); |
| 2211 | netif_start_queue(netdev); |
| 2212 | return err; |
| 2213 | |
| 2214 | err_up: |
| 2215 | err_alloc_rx: |
| 2216 | atl1c_clean_rx_ring(adapter); |
| 2217 | return err; |
| 2218 | } |
| 2219 | |
stephen hemminger | 0fb1e54 | 2010-10-21 07:50:49 +0000 | [diff] [blame] | 2220 | static void atl1c_down(struct atl1c_adapter *adapter) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2221 | { |
| 2222 | struct net_device *netdev = adapter->netdev; |
| 2223 | |
| 2224 | atl1c_del_timer(adapter); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 2225 | adapter->work_event = 0; /* clear all event */ |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2226 | /* signal that we're down so the interrupt handler does not |
| 2227 | * reschedule our watchdog timer */ |
| 2228 | set_bit(__AT_DOWN, &adapter->flags); |
| 2229 | netif_carrier_off(netdev); |
| 2230 | napi_disable(&adapter->napi); |
| 2231 | atl1c_irq_disable(adapter); |
| 2232 | atl1c_free_irq(adapter); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2233 | /* reset MAC to disable all RX/TX */ |
| 2234 | atl1c_reset_mac(&adapter->hw); |
| 2235 | msleep(1); |
| 2236 | |
| 2237 | adapter->link_speed = SPEED_0; |
| 2238 | adapter->link_duplex = -1; |
| 2239 | atl1c_clean_tx_ring(adapter, atl1c_trans_normal); |
| 2240 | atl1c_clean_tx_ring(adapter, atl1c_trans_high); |
| 2241 | atl1c_clean_rx_ring(adapter); |
| 2242 | } |
| 2243 | |
| 2244 | /* |
| 2245 | * atl1c_open - Called when a network interface is made active |
| 2246 | * @netdev: network interface device structure |
| 2247 | * |
| 2248 | * Returns 0 on success, negative value on failure |
| 2249 | * |
| 2250 | * The open entry point is called when a network interface is made |
| 2251 | * active by the system (IFF_UP). At this point all resources needed |
| 2252 | * for transmit and receive operations are allocated, the interrupt |
| 2253 | * handler is registered with the OS, the watchdog timer is started, |
| 2254 | * and the stack is notified that the interface is ready. |
| 2255 | */ |
| 2256 | static int atl1c_open(struct net_device *netdev) |
| 2257 | { |
| 2258 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2259 | int err; |
| 2260 | |
| 2261 | /* disallow open during test */ |
| 2262 | if (test_bit(__AT_TESTING, &adapter->flags)) |
| 2263 | return -EBUSY; |
| 2264 | |
| 2265 | /* allocate rx/tx dma buffer & descriptors */ |
| 2266 | err = atl1c_setup_ring_resources(adapter); |
| 2267 | if (unlikely(err)) |
| 2268 | return err; |
| 2269 | |
| 2270 | err = atl1c_up(adapter); |
| 2271 | if (unlikely(err)) |
| 2272 | goto err_up; |
| 2273 | |
| 2274 | if (adapter->hw.ctrl_flags & ATL1C_FPGA_VERSION) { |
| 2275 | u32 phy_data; |
| 2276 | |
| 2277 | AT_READ_REG(&adapter->hw, REG_MDIO_CTRL, &phy_data); |
| 2278 | phy_data |= MDIO_AP_EN; |
| 2279 | AT_WRITE_REG(&adapter->hw, REG_MDIO_CTRL, phy_data); |
| 2280 | } |
| 2281 | return 0; |
| 2282 | |
| 2283 | err_up: |
| 2284 | atl1c_free_irq(adapter); |
| 2285 | atl1c_free_ring_resources(adapter); |
| 2286 | atl1c_reset_mac(&adapter->hw); |
| 2287 | return err; |
| 2288 | } |
| 2289 | |
| 2290 | /* |
| 2291 | * atl1c_close - Disables a network interface |
| 2292 | * @netdev: network interface device structure |
| 2293 | * |
| 2294 | * Returns 0, this is not allowed to fail |
| 2295 | * |
| 2296 | * The close entry point is called when an interface is de-activated |
| 2297 | * by the OS. The hardware is still under the drivers control, but |
| 2298 | * needs to be disabled. A global MAC reset is issued to stop the |
| 2299 | * hardware, and all transmit and receive resources are freed. |
| 2300 | */ |
| 2301 | static int atl1c_close(struct net_device *netdev) |
| 2302 | { |
| 2303 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2304 | |
| 2305 | WARN_ON(test_bit(__AT_RESETTING, &adapter->flags)); |
| 2306 | atl1c_down(adapter); |
| 2307 | atl1c_free_ring_resources(adapter); |
| 2308 | return 0; |
| 2309 | } |
| 2310 | |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2311 | static int atl1c_suspend(struct device *dev) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2312 | { |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2313 | struct pci_dev *pdev = to_pci_dev(dev); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2314 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2315 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2316 | struct atl1c_hw *hw = &adapter->hw; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2317 | u32 mac_ctrl_data = 0; |
| 2318 | u32 master_ctrl_data = 0; |
jie.yang@atheros.com | 55865c6 | 2009-09-20 19:01:58 +0000 | [diff] [blame] | 2319 | u32 wol_ctrl_data = 0; |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2320 | u16 mii_intr_status_data = 0; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2321 | u32 wufc = adapter->wol; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2322 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2323 | atl1c_disable_l0s_l1(hw); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2324 | if (netif_running(netdev)) { |
| 2325 | WARN_ON(test_bit(__AT_RESETTING, &adapter->flags)); |
| 2326 | atl1c_down(adapter); |
| 2327 | } |
| 2328 | netif_device_detach(netdev); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2329 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2330 | if (wufc) |
| 2331 | if (atl1c_phy_power_saving(hw) != 0) |
| 2332 | dev_dbg(&pdev->dev, "phy power saving failed"); |
| 2333 | |
| 2334 | AT_READ_REG(hw, REG_MASTER_CTRL, &master_ctrl_data); |
| 2335 | AT_READ_REG(hw, REG_MAC_CTRL, &mac_ctrl_data); |
| 2336 | |
| 2337 | master_ctrl_data &= ~MASTER_CTRL_CLK_SEL_DIS; |
| 2338 | mac_ctrl_data &= ~(MAC_CTRL_PRMLEN_MASK << MAC_CTRL_PRMLEN_SHIFT); |
| 2339 | mac_ctrl_data |= (((u32)adapter->hw.preamble_len & |
| 2340 | MAC_CTRL_PRMLEN_MASK) << |
| 2341 | MAC_CTRL_PRMLEN_SHIFT); |
| 2342 | mac_ctrl_data &= ~(MAC_CTRL_SPEED_MASK << MAC_CTRL_SPEED_SHIFT); |
| 2343 | mac_ctrl_data &= ~MAC_CTRL_DUPLX; |
| 2344 | |
| 2345 | if (wufc) { |
| 2346 | mac_ctrl_data |= MAC_CTRL_RX_EN; |
| 2347 | if (adapter->link_speed == SPEED_1000 || |
| 2348 | adapter->link_speed == SPEED_0) { |
| 2349 | mac_ctrl_data |= atl1c_mac_speed_1000 << |
| 2350 | MAC_CTRL_SPEED_SHIFT; |
| 2351 | mac_ctrl_data |= MAC_CTRL_DUPLX; |
| 2352 | } else |
| 2353 | mac_ctrl_data |= atl1c_mac_speed_10_100 << |
| 2354 | MAC_CTRL_SPEED_SHIFT; |
| 2355 | |
| 2356 | if (adapter->link_duplex == DUPLEX_FULL) |
| 2357 | mac_ctrl_data |= MAC_CTRL_DUPLX; |
| 2358 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2359 | /* turn on magic packet wol */ |
| 2360 | if (wufc & AT_WUFC_MAG) |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2361 | wol_ctrl_data |= WOL_MAGIC_EN | WOL_MAGIC_PME_EN; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2362 | |
| 2363 | if (wufc & AT_WUFC_LNKC) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2364 | wol_ctrl_data |= WOL_LINK_CHG_EN | WOL_LINK_CHG_PME_EN; |
| 2365 | /* only link up can wake up */ |
| 2366 | if (atl1c_write_phy_reg(hw, MII_IER, IER_LINK_UP) != 0) { |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2367 | dev_dbg(&pdev->dev, "%s: read write phy " |
| 2368 | "register failed.\n", |
| 2369 | atl1c_driver_name); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | /* clear phy interrupt */ |
| 2373 | atl1c_read_phy_reg(hw, MII_ISR, &mii_intr_status_data); |
| 2374 | /* Config MAC Ctrl register */ |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 2375 | __atl1c_vlan_mode(netdev->features, &mac_ctrl_data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2376 | |
| 2377 | /* magic packet maybe Broadcast&multicast&Unicast frame */ |
| 2378 | if (wufc & AT_WUFC_MAG) |
| 2379 | mac_ctrl_data |= MAC_CTRL_BC_EN; |
| 2380 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2381 | dev_dbg(&pdev->dev, |
| 2382 | "%s: suspend MAC=0x%x\n", |
| 2383 | atl1c_driver_name, mac_ctrl_data); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2384 | AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data); |
| 2385 | AT_WRITE_REG(hw, REG_WOL_CTRL, wol_ctrl_data); |
| 2386 | AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data); |
| 2387 | |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2388 | AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT | |
| 2389 | GPHY_CTRL_EXT_RESET); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2390 | } else { |
| 2391 | AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_POWER_SAVING); |
| 2392 | master_ctrl_data |= MASTER_CTRL_CLK_SEL_DIS; |
| 2393 | mac_ctrl_data |= atl1c_mac_speed_10_100 << MAC_CTRL_SPEED_SHIFT; |
| 2394 | mac_ctrl_data |= MAC_CTRL_DUPLX; |
| 2395 | AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data); |
| 2396 | AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data); |
| 2397 | AT_WRITE_REG(hw, REG_WOL_CTRL, 0); |
| 2398 | hw->phy_configured = false; /* re-init PHY when resume */ |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2399 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2400 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2401 | return 0; |
| 2402 | } |
| 2403 | |
David S. Miller | d187c1a | 2011-05-19 18:44:41 -0400 | [diff] [blame] | 2404 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2405 | static int atl1c_resume(struct device *dev) |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2406 | { |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2407 | struct pci_dev *pdev = to_pci_dev(dev); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2408 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2409 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2410 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2411 | AT_WRITE_REG(&adapter->hw, REG_WOL_CTRL, 0); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2412 | atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE | |
| 2413 | ATL1C_PCIE_PHY_RESET); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2414 | |
| 2415 | atl1c_phy_reset(&adapter->hw); |
| 2416 | atl1c_reset_mac(&adapter->hw); |
Jie Yang | 8f574b3 | 2010-06-01 00:28:12 -0700 | [diff] [blame] | 2417 | atl1c_phy_init(&adapter->hw); |
| 2418 | |
| 2419 | #if 0 |
| 2420 | AT_READ_REG(&adapter->hw, REG_PM_CTRLSTAT, &pm_data); |
| 2421 | pm_data &= ~PM_CTRLSTAT_PME_EN; |
| 2422 | AT_WRITE_REG(&adapter->hw, REG_PM_CTRLSTAT, pm_data); |
| 2423 | #endif |
| 2424 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2425 | netif_device_attach(netdev); |
| 2426 | if (netif_running(netdev)) |
| 2427 | atl1c_up(adapter); |
| 2428 | |
| 2429 | return 0; |
| 2430 | } |
David S. Miller | d187c1a | 2011-05-19 18:44:41 -0400 | [diff] [blame] | 2431 | #endif |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2432 | |
| 2433 | static void atl1c_shutdown(struct pci_dev *pdev) |
| 2434 | { |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2435 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2436 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2437 | |
| 2438 | atl1c_suspend(&pdev->dev); |
| 2439 | pci_wake_from_d3(pdev, adapter->wol); |
| 2440 | pci_set_power_state(pdev, PCI_D3hot); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | static const struct net_device_ops atl1c_netdev_ops = { |
| 2444 | .ndo_open = atl1c_open, |
| 2445 | .ndo_stop = atl1c_close, |
| 2446 | .ndo_validate_addr = eth_validate_addr, |
| 2447 | .ndo_start_xmit = atl1c_xmit_frame, |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 2448 | .ndo_set_mac_address = atl1c_set_mac_addr, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 2449 | .ndo_set_rx_mode = atl1c_set_multi, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2450 | .ndo_change_mtu = atl1c_change_mtu, |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 2451 | .ndo_fix_features = atl1c_fix_features, |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 2452 | .ndo_set_features = atl1c_set_features, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2453 | .ndo_do_ioctl = atl1c_ioctl, |
| 2454 | .ndo_tx_timeout = atl1c_tx_timeout, |
| 2455 | .ndo_get_stats = atl1c_get_stats, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2456 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2457 | .ndo_poll_controller = atl1c_netpoll, |
| 2458 | #endif |
| 2459 | }; |
| 2460 | |
| 2461 | static int atl1c_init_netdev(struct net_device *netdev, struct pci_dev *pdev) |
| 2462 | { |
| 2463 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2464 | pci_set_drvdata(pdev, netdev); |
| 2465 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2466 | netdev->netdev_ops = &atl1c_netdev_ops; |
| 2467 | netdev->watchdog_timeo = AT_TX_WATCHDOG; |
| 2468 | atl1c_set_ethtool_ops(netdev); |
| 2469 | |
| 2470 | /* TODO: add when ready */ |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 2471 | netdev->hw_features = NETIF_F_SG | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2472 | NETIF_F_HW_CSUM | |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 2473 | NETIF_F_HW_VLAN_RX | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2474 | NETIF_F_TSO | |
| 2475 | NETIF_F_TSO6; |
Michał Mirosław | 782d640 | 2011-04-07 07:32:18 +0000 | [diff] [blame] | 2476 | netdev->features = netdev->hw_features | |
Jiri Pirko | 46facce | 2011-07-20 04:54:12 +0000 | [diff] [blame] | 2477 | NETIF_F_HW_VLAN_TX; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2478 | return 0; |
| 2479 | } |
| 2480 | |
| 2481 | /* |
| 2482 | * atl1c_probe - Device Initialization Routine |
| 2483 | * @pdev: PCI device information struct |
| 2484 | * @ent: entry in atl1c_pci_tbl |
| 2485 | * |
| 2486 | * Returns 0 on success, negative on failure |
| 2487 | * |
| 2488 | * atl1c_probe initializes an adapter identified by a pci_dev structure. |
| 2489 | * The OS initialization, configuring of the adapter private structure, |
| 2490 | * and a hardware reset occur. |
| 2491 | */ |
| 2492 | static int __devinit atl1c_probe(struct pci_dev *pdev, |
| 2493 | const struct pci_device_id *ent) |
| 2494 | { |
| 2495 | struct net_device *netdev; |
| 2496 | struct atl1c_adapter *adapter; |
| 2497 | static int cards_found; |
| 2498 | |
| 2499 | int err = 0; |
| 2500 | |
| 2501 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 2502 | err = pci_enable_device_mem(pdev); |
| 2503 | if (err) { |
| 2504 | dev_err(&pdev->dev, "cannot enable PCI device\n"); |
| 2505 | return err; |
| 2506 | } |
| 2507 | |
| 2508 | /* |
| 2509 | * The atl1c chip can DMA to 64-bit addresses, but it uses a single |
| 2510 | * shared register for the high 32 bits, so only a single, aligned, |
| 2511 | * 4 GB physical address range can be used at a time. |
| 2512 | * |
| 2513 | * Supporting 64-bit DMA on this hardware is more trouble than it's |
| 2514 | * worth. It is far easier to limit to 32-bit DMA than update |
| 2515 | * various kernel subsystems to support the mechanics required by a |
| 2516 | * fixed-high-32-bit system. |
| 2517 | */ |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2518 | if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || |
| 2519 | (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) { |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2520 | dev_err(&pdev->dev, "No usable DMA configuration,aborting\n"); |
| 2521 | goto err_dma; |
| 2522 | } |
| 2523 | |
| 2524 | err = pci_request_regions(pdev, atl1c_driver_name); |
| 2525 | if (err) { |
| 2526 | dev_err(&pdev->dev, "cannot obtain PCI resources\n"); |
| 2527 | goto err_pci_reg; |
| 2528 | } |
| 2529 | |
| 2530 | pci_set_master(pdev); |
| 2531 | |
| 2532 | netdev = alloc_etherdev(sizeof(struct atl1c_adapter)); |
| 2533 | if (netdev == NULL) { |
| 2534 | err = -ENOMEM; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2535 | goto err_alloc_etherdev; |
| 2536 | } |
| 2537 | |
| 2538 | err = atl1c_init_netdev(netdev, pdev); |
| 2539 | if (err) { |
| 2540 | dev_err(&pdev->dev, "init netdevice failed\n"); |
| 2541 | goto err_init_netdev; |
| 2542 | } |
| 2543 | adapter = netdev_priv(netdev); |
| 2544 | adapter->bd_number = cards_found; |
| 2545 | adapter->netdev = netdev; |
| 2546 | adapter->pdev = pdev; |
| 2547 | adapter->hw.adapter = adapter; |
| 2548 | adapter->msg_enable = netif_msg_init(-1, atl1c_default_msg); |
| 2549 | adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); |
| 2550 | if (!adapter->hw.hw_addr) { |
| 2551 | err = -EIO; |
| 2552 | dev_err(&pdev->dev, "cannot map device registers\n"); |
| 2553 | goto err_ioremap; |
| 2554 | } |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2555 | |
| 2556 | /* init mii data */ |
| 2557 | adapter->mii.dev = netdev; |
| 2558 | adapter->mii.mdio_read = atl1c_mdio_read; |
| 2559 | adapter->mii.mdio_write = atl1c_mdio_write; |
| 2560 | adapter->mii.phy_id_mask = 0x1f; |
| 2561 | adapter->mii.reg_num_mask = MDIO_REG_ADDR_MASK; |
| 2562 | netif_napi_add(netdev, &adapter->napi, atl1c_clean, 64); |
| 2563 | setup_timer(&adapter->phy_config_timer, atl1c_phy_config, |
| 2564 | (unsigned long)adapter); |
| 2565 | /* setup the private structure */ |
| 2566 | err = atl1c_sw_init(adapter); |
| 2567 | if (err) { |
| 2568 | dev_err(&pdev->dev, "net device private data init failed\n"); |
| 2569 | goto err_sw_init; |
| 2570 | } |
| 2571 | atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE | |
| 2572 | ATL1C_PCIE_PHY_RESET); |
| 2573 | |
| 2574 | /* Init GPHY as early as possible due to power saving issue */ |
| 2575 | atl1c_phy_reset(&adapter->hw); |
| 2576 | |
| 2577 | err = atl1c_reset_mac(&adapter->hw); |
| 2578 | if (err) { |
| 2579 | err = -EIO; |
| 2580 | goto err_reset; |
| 2581 | } |
| 2582 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2583 | /* reset the controller to |
| 2584 | * put the device in a known good starting state */ |
| 2585 | err = atl1c_phy_init(&adapter->hw); |
| 2586 | if (err) { |
| 2587 | err = -EIO; |
| 2588 | goto err_reset; |
| 2589 | } |
Danny Kukawka | 6a214fd | 2012-02-17 05:43:30 +0000 | [diff] [blame] | 2590 | if (atl1c_read_mac_addr(&adapter->hw)) { |
| 2591 | /* got a random MAC address, set NET_ADDR_RANDOM to netdev */ |
| 2592 | netdev->addr_assign_type |= NET_ADDR_RANDOM; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2593 | } |
| 2594 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
| 2595 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
| 2596 | if (netif_msg_probe(adapter)) |
hartleys | 8299117 | 2010-01-05 06:54:01 +0000 | [diff] [blame] | 2597 | dev_dbg(&pdev->dev, "mac address : %pM\n", |
| 2598 | adapter->hw.mac_addr); |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2599 | |
| 2600 | atl1c_hw_set_mac_addr(&adapter->hw); |
Jie Yang | cb19054 | 2009-12-06 23:16:58 +0000 | [diff] [blame] | 2601 | INIT_WORK(&adapter->common_task, atl1c_common_task); |
| 2602 | adapter->work_event = 0; |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2603 | err = register_netdev(netdev); |
| 2604 | if (err) { |
| 2605 | dev_err(&pdev->dev, "register netdevice failed\n"); |
| 2606 | goto err_register; |
| 2607 | } |
| 2608 | |
| 2609 | if (netif_msg_probe(adapter)) |
| 2610 | dev_info(&pdev->dev, "version %s\n", ATL1C_DRV_VERSION); |
| 2611 | cards_found++; |
| 2612 | return 0; |
| 2613 | |
| 2614 | err_reset: |
| 2615 | err_register: |
| 2616 | err_sw_init: |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2617 | iounmap(adapter->hw.hw_addr); |
| 2618 | err_init_netdev: |
| 2619 | err_ioremap: |
| 2620 | free_netdev(netdev); |
| 2621 | err_alloc_etherdev: |
| 2622 | pci_release_regions(pdev); |
| 2623 | err_pci_reg: |
| 2624 | err_dma: |
| 2625 | pci_disable_device(pdev); |
| 2626 | return err; |
| 2627 | } |
| 2628 | |
| 2629 | /* |
| 2630 | * atl1c_remove - Device Removal Routine |
| 2631 | * @pdev: PCI device information struct |
| 2632 | * |
| 2633 | * atl1c_remove is called by the PCI subsystem to alert the driver |
| 2634 | * that it should release a PCI device. The could be caused by a |
| 2635 | * Hot-Plug event, or because the driver is going to be removed from |
| 2636 | * memory. |
| 2637 | */ |
| 2638 | static void __devexit atl1c_remove(struct pci_dev *pdev) |
| 2639 | { |
| 2640 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2641 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2642 | |
| 2643 | unregister_netdev(netdev); |
| 2644 | atl1c_phy_disable(&adapter->hw); |
| 2645 | |
| 2646 | iounmap(adapter->hw.hw_addr); |
| 2647 | |
| 2648 | pci_release_regions(pdev); |
| 2649 | pci_disable_device(pdev); |
| 2650 | free_netdev(netdev); |
| 2651 | } |
| 2652 | |
| 2653 | /* |
| 2654 | * atl1c_io_error_detected - called when PCI error is detected |
| 2655 | * @pdev: Pointer to PCI device |
| 2656 | * @state: The current pci connection state |
| 2657 | * |
| 2658 | * This function is called after a PCI bus error affecting |
| 2659 | * this device has been detected. |
| 2660 | */ |
| 2661 | static pci_ers_result_t atl1c_io_error_detected(struct pci_dev *pdev, |
| 2662 | pci_channel_state_t state) |
| 2663 | { |
| 2664 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2665 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2666 | |
| 2667 | netif_device_detach(netdev); |
| 2668 | |
Dean Nelson | 005fb4f | 2009-07-31 09:13:02 +0000 | [diff] [blame] | 2669 | if (state == pci_channel_io_perm_failure) |
| 2670 | return PCI_ERS_RESULT_DISCONNECT; |
| 2671 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2672 | if (netif_running(netdev)) |
| 2673 | atl1c_down(adapter); |
| 2674 | |
| 2675 | pci_disable_device(pdev); |
| 2676 | |
| 2677 | /* Request a slot slot reset. */ |
| 2678 | return PCI_ERS_RESULT_NEED_RESET; |
| 2679 | } |
| 2680 | |
| 2681 | /* |
| 2682 | * atl1c_io_slot_reset - called after the pci bus has been reset. |
| 2683 | * @pdev: Pointer to PCI device |
| 2684 | * |
| 2685 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 2686 | * resembles the first-half of the e1000_resume routine. |
| 2687 | */ |
| 2688 | static pci_ers_result_t atl1c_io_slot_reset(struct pci_dev *pdev) |
| 2689 | { |
| 2690 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2691 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2692 | |
| 2693 | if (pci_enable_device(pdev)) { |
| 2694 | if (netif_msg_hw(adapter)) |
| 2695 | dev_err(&pdev->dev, |
| 2696 | "Cannot re-enable PCI device after reset\n"); |
| 2697 | return PCI_ERS_RESULT_DISCONNECT; |
| 2698 | } |
| 2699 | pci_set_master(pdev); |
| 2700 | |
| 2701 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 2702 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 2703 | |
| 2704 | atl1c_reset_mac(&adapter->hw); |
| 2705 | |
| 2706 | return PCI_ERS_RESULT_RECOVERED; |
| 2707 | } |
| 2708 | |
| 2709 | /* |
| 2710 | * atl1c_io_resume - called when traffic can start flowing again. |
| 2711 | * @pdev: Pointer to PCI device |
| 2712 | * |
| 2713 | * This callback is called when the error recovery driver tells us that |
| 2714 | * its OK to resume normal operation. Implementation resembles the |
| 2715 | * second-half of the atl1c_resume routine. |
| 2716 | */ |
| 2717 | static void atl1c_io_resume(struct pci_dev *pdev) |
| 2718 | { |
| 2719 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2720 | struct atl1c_adapter *adapter = netdev_priv(netdev); |
| 2721 | |
| 2722 | if (netif_running(netdev)) { |
| 2723 | if (atl1c_up(adapter)) { |
| 2724 | if (netif_msg_hw(adapter)) |
| 2725 | dev_err(&pdev->dev, |
| 2726 | "Cannot bring device back up after reset\n"); |
| 2727 | return; |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | netif_device_attach(netdev); |
| 2732 | } |
| 2733 | |
| 2734 | static struct pci_error_handlers atl1c_err_handler = { |
| 2735 | .error_detected = atl1c_io_error_detected, |
| 2736 | .slot_reset = atl1c_io_slot_reset, |
| 2737 | .resume = atl1c_io_resume, |
| 2738 | }; |
| 2739 | |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2740 | static SIMPLE_DEV_PM_OPS(atl1c_pm_ops, atl1c_suspend, atl1c_resume); |
| 2741 | |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2742 | static struct pci_driver atl1c_driver = { |
| 2743 | .name = atl1c_driver_name, |
| 2744 | .id_table = atl1c_pci_tbl, |
| 2745 | .probe = atl1c_probe, |
| 2746 | .remove = __devexit_p(atl1c_remove), |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2747 | .shutdown = atl1c_shutdown, |
Rafael J. Wysocki | 762e302 | 2010-12-22 03:07:52 +0000 | [diff] [blame] | 2748 | .err_handler = &atl1c_err_handler, |
| 2749 | .driver.pm = &atl1c_pm_ops, |
Jie Yang | 43250dd | 2009-02-18 17:24:15 -0800 | [diff] [blame] | 2750 | }; |
| 2751 | |
| 2752 | /* |
| 2753 | * atl1c_init_module - Driver Registration Routine |
| 2754 | * |
| 2755 | * atl1c_init_module is the first routine called when the driver is |
| 2756 | * loaded. All it does is register with the PCI subsystem. |
| 2757 | */ |
| 2758 | static int __init atl1c_init_module(void) |
| 2759 | { |
| 2760 | return pci_register_driver(&atl1c_driver); |
| 2761 | } |
| 2762 | |
| 2763 | /* |
| 2764 | * atl1c_exit_module - Driver Exit Cleanup Routine |
| 2765 | * |
| 2766 | * atl1c_exit_module is called just before the driver is removed |
| 2767 | * from memory. |
| 2768 | */ |
| 2769 | static void __exit atl1c_exit_module(void) |
| 2770 | { |
| 2771 | pci_unregister_driver(&atl1c_driver); |
| 2772 | } |
| 2773 | |
| 2774 | module_init(atl1c_init_module); |
| 2775 | module_exit(atl1c_exit_module); |