blob: b95ef45051152fdefc5b04bc46f6f7d420d38c8e [file] [log] [blame]
Jie Yang43250dd2009-02-18 17:24:15 -08001/*
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 Yang8f574b32010-06-01 00:28:12 -070024#define ATL1C_DRV_VERSION "1.0.1.0-NAPI"
Jie Yang43250dd2009-02-18 17:24:15 -080025char atl1c_driver_name[] = "atl1c";
26char atl1c_driver_version[] = ATL1C_DRV_VERSION;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -080027
Jie Yang43250dd2009-02-18 17:24:15 -080028/*
29 * atl1c_pci_tbl - PCI Device ID Table
30 *
31 * Wildcard entries (PCI_ANY_ID) should come last
32 * Last entry must be all 0s
33 *
34 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
35 * Class, Class Mask, private data (not used) }
36 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000037static DEFINE_PCI_DEVICE_TABLE(atl1c_pci_tbl) = {
Jie Yang43250dd2009-02-18 17:24:15 -080038 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1C)},
39 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L2C)},
Luis R. Rodriguez496c1852010-02-16 15:16:45 -080040 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B)},
41 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B2)},
42 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D)},
Chuck Ebbert94dde7e2011-02-02 15:02:08 -080043 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D_2_0)},
Jie Yang43250dd2009-02-18 17:24:15 -080044 /* required last entry */
45 { 0 }
46};
47MODULE_DEVICE_TABLE(pci, atl1c_pci_tbl);
48
Huang, Xiong70c9fbd2012-04-17 19:32:25 +000049MODULE_AUTHOR("Jie Yang");
50MODULE_AUTHOR("Qualcomm Atheros Inc., <nic-devel@qualcomm.com>");
51MODULE_DESCRIPTION("Qualcom Atheros 100/1000M Ethernet Network Driver");
Jie Yang43250dd2009-02-18 17:24:15 -080052MODULE_LICENSE("GPL");
53MODULE_VERSION(ATL1C_DRV_VERSION);
54
55static int atl1c_stop_mac(struct atl1c_hw *hw);
Jie Yang43250dd2009-02-18 17:24:15 -080056static void atl1c_disable_l0s_l1(struct atl1c_hw *hw);
Huang, Xiong024e1e42012-04-18 22:01:28 +000057static void atl1c_set_aspm(struct atl1c_hw *hw, u16 link_speed);
Huang, Xiong25456e52012-04-25 20:41:00 +000058static void atl1c_start_mac(struct atl1c_adapter *adapter);
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +000059static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter,
Jie Yang43250dd2009-02-18 17:24:15 -080060 int *work_done, int work_to_do);
stephen hemminger0fb1e542010-10-21 07:50:49 +000061static int atl1c_up(struct atl1c_adapter *adapter);
62static void atl1c_down(struct atl1c_adapter *adapter);
Jie Yang43250dd2009-02-18 17:24:15 -080063
64static const u16 atl1c_pay_load_size[] = {
65 128, 256, 512, 1024, 2048, 4096,
66};
67
Jie Yang43250dd2009-02-18 17:24:15 -080068
69static const u32 atl1c_default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
70 NETIF_MSG_LINK | NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP;
Jie Yang8f574b32010-06-01 00:28:12 -070071static void atl1c_pcie_patch(struct atl1c_hw *hw)
72{
Huang, Xiong5cbdcc22012-04-18 22:01:27 +000073 u32 mst_data, data;
74
75 /* pclk sel could switch to 25M */
76 AT_READ_REG(hw, REG_MASTER_CTRL, &mst_data);
77 mst_data &= ~MASTER_CTRL_CLK_SEL_DIS;
78 AT_WRITE_REG(hw, REG_MASTER_CTRL, mst_data);
Jie Yang43250dd2009-02-18 17:24:15 -080079
Huang, Xiongebe22ed2012-04-18 22:01:29 +000080 /* WoL/PCIE related settings */
81 if (hw->nic_type == athr_l1c || hw->nic_type == athr_l2c) {
82 AT_READ_REG(hw, REG_PCIE_PHYMISC, &data);
83 data |= PCIE_PHYMISC_FORCE_RCV_DET;
84 AT_WRITE_REG(hw, REG_PCIE_PHYMISC, data);
85 } else { /* new dev set bit5 of MASTER */
86 if (!(mst_data & MASTER_CTRL_WAKEN_25M))
87 AT_WRITE_REG(hw, REG_MASTER_CTRL,
88 mst_data | MASTER_CTRL_WAKEN_25M);
89 }
90 /* aspm/PCIE setting only for l2cb 1.0 */
Jie Yang8f574b32010-06-01 00:28:12 -070091 if (hw->nic_type == athr_l2c_b && hw->revision_id == L2CB_V10) {
92 AT_READ_REG(hw, REG_PCIE_PHYMISC2, &data);
Huang, Xiongebe22ed2012-04-18 22:01:29 +000093 data = FIELD_SETX(data, PCIE_PHYMISC2_CDR_BW,
94 L2CB1_PCIE_PHYMISC2_CDR_BW);
95 data = FIELD_SETX(data, PCIE_PHYMISC2_L0S_TH,
96 L2CB1_PCIE_PHYMISC2_L0S_TH);
Jie Yang8f574b32010-06-01 00:28:12 -070097 AT_WRITE_REG(hw, REG_PCIE_PHYMISC2, data);
Huang, Xiongebe22ed2012-04-18 22:01:29 +000098 /* extend L1 sync timer */
99 AT_READ_REG(hw, REG_LINK_CTRL, &data);
100 data |= LINK_CTRL_EXT_SYNC;
101 AT_WRITE_REG(hw, REG_LINK_CTRL, data);
102 }
103 /* l2cb 1.x & l1d 1.x */
104 if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d) {
105 AT_READ_REG(hw, REG_PM_CTRL, &data);
106 data |= PM_CTRL_L0S_BUFSRX_EN;
107 AT_WRITE_REG(hw, REG_PM_CTRL, data);
108 /* clear vendor msg */
109 AT_READ_REG(hw, REG_DMA_DBG, &data);
110 AT_WRITE_REG(hw, REG_DMA_DBG, data & ~DMA_DBG_VENDOR_MSG);
Jie Yang8f574b32010-06-01 00:28:12 -0700111 }
112}
113
114/* FIXME: no need any more ? */
Jie Yang43250dd2009-02-18 17:24:15 -0800115/*
116 * atl1c_init_pcie - init PCIE module
117 */
118static void atl1c_reset_pcie(struct atl1c_hw *hw, u32 flag)
119{
120 u32 data;
121 u32 pci_cmd;
122 struct pci_dev *pdev = hw->adapter->pdev;
Huang, Xiong95f9aea2012-04-18 22:01:25 +0000123 int pos;
Jie Yang43250dd2009-02-18 17:24:15 -0800124
125 AT_READ_REG(hw, PCI_COMMAND, &pci_cmd);
126 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
127 pci_cmd |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
128 PCI_COMMAND_IO);
129 AT_WRITE_REG(hw, PCI_COMMAND, pci_cmd);
130
131 /*
132 * Clear any PowerSaveing Settings
133 */
134 pci_enable_wake(pdev, PCI_D3hot, 0);
135 pci_enable_wake(pdev, PCI_D3cold, 0);
Huang, Xiong87eabe62012-04-30 15:38:51 +0000136 /* wol sts read-clear */
137 AT_READ_REG(hw, REG_WOL_CTRL, &data);
138 AT_WRITE_REG(hw, REG_WOL_CTRL, 0);
Jie Yang43250dd2009-02-18 17:24:15 -0800139
140 /*
141 * Mask some pcie error bits
142 */
Huang, Xiong95f9aea2012-04-18 22:01:25 +0000143 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
144 pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, &data);
145 data &= ~(PCI_ERR_UNC_DLP | PCI_ERR_UNC_FCP);
146 pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, data);
147 /* clear error status */
148 pci_write_config_word(pdev, pci_pcie_cap(pdev) + PCI_EXP_DEVSTA,
149 PCI_EXP_DEVSTA_NFED |
150 PCI_EXP_DEVSTA_FED |
151 PCI_EXP_DEVSTA_CED |
152 PCI_EXP_DEVSTA_URD);
Jie Yang43250dd2009-02-18 17:24:15 -0800153
Jie Yang8f574b32010-06-01 00:28:12 -0700154 AT_READ_REG(hw, REG_LTSSM_ID_CTRL, &data);
155 data &= ~LTSSM_ID_EN_WRO;
156 AT_WRITE_REG(hw, REG_LTSSM_ID_CTRL, data);
157
158 atl1c_pcie_patch(hw);
Jie Yang43250dd2009-02-18 17:24:15 -0800159 if (flag & ATL1C_PCIE_L0S_L1_DISABLE)
160 atl1c_disable_l0s_l1(hw);
Jie Yang43250dd2009-02-18 17:24:15 -0800161
Jie Yang8f574b32010-06-01 00:28:12 -0700162 msleep(5);
Jie Yang43250dd2009-02-18 17:24:15 -0800163}
164
165/*
166 * atl1c_irq_enable - Enable default interrupt generation settings
167 * @adapter: board private structure
168 */
169static inline void atl1c_irq_enable(struct atl1c_adapter *adapter)
170{
171 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
172 AT_WRITE_REG(&adapter->hw, REG_ISR, 0x7FFFFFFF);
173 AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask);
174 AT_WRITE_FLUSH(&adapter->hw);
175 }
176}
177
178/*
179 * atl1c_irq_disable - Mask off interrupt generation on the NIC
180 * @adapter: board private structure
181 */
182static inline void atl1c_irq_disable(struct atl1c_adapter *adapter)
183{
184 atomic_inc(&adapter->irq_sem);
185 AT_WRITE_REG(&adapter->hw, REG_IMR, 0);
Jie Yang8f574b32010-06-01 00:28:12 -0700186 AT_WRITE_REG(&adapter->hw, REG_ISR, ISR_DIS_INT);
Jie Yang43250dd2009-02-18 17:24:15 -0800187 AT_WRITE_FLUSH(&adapter->hw);
188 synchronize_irq(adapter->pdev->irq);
189}
190
191/*
192 * atl1c_irq_reset - reset interrupt confiure on the NIC
193 * @adapter: board private structure
194 */
195static inline void atl1c_irq_reset(struct atl1c_adapter *adapter)
196{
197 atomic_set(&adapter->irq_sem, 1);
198 atl1c_irq_enable(adapter);
199}
200
201/*
Joe Perchesc930a662009-05-31 20:44:54 +0000202 * atl1c_wait_until_idle - wait up to AT_HW_MAX_IDLE_DELAY reads
203 * of the idle status register until the device is actually idle
204 */
Huang, Xiong969a7ee2012-04-18 22:01:22 +0000205static u32 atl1c_wait_until_idle(struct atl1c_hw *hw, u32 modu_ctrl)
Joe Perchesc930a662009-05-31 20:44:54 +0000206{
207 int timeout;
208 u32 data;
209
210 for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
211 AT_READ_REG(hw, REG_IDLE_STATUS, &data);
Huang, Xiong969a7ee2012-04-18 22:01:22 +0000212 if ((data & modu_ctrl) == 0)
Joe Perchesc930a662009-05-31 20:44:54 +0000213 return 0;
214 msleep(1);
215 }
216 return data;
217}
218
219/*
Jie Yang43250dd2009-02-18 17:24:15 -0800220 * atl1c_phy_config - Timer Call-back
221 * @data: pointer to netdev cast into an unsigned long
222 */
223static void atl1c_phy_config(unsigned long data)
224{
225 struct atl1c_adapter *adapter = (struct atl1c_adapter *) data;
226 struct atl1c_hw *hw = &adapter->hw;
227 unsigned long flags;
228
229 spin_lock_irqsave(&adapter->mdio_lock, flags);
230 atl1c_restart_autoneg(hw);
231 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
232}
233
234void atl1c_reinit_locked(struct atl1c_adapter *adapter)
235{
Jie Yang43250dd2009-02-18 17:24:15 -0800236 WARN_ON(in_interrupt());
237 atl1c_down(adapter);
238 atl1c_up(adapter);
239 clear_bit(__AT_RESETTING, &adapter->flags);
240}
241
Jie Yang43250dd2009-02-18 17:24:15 -0800242static void atl1c_check_link_status(struct atl1c_adapter *adapter)
243{
244 struct atl1c_hw *hw = &adapter->hw;
245 struct net_device *netdev = adapter->netdev;
246 struct pci_dev *pdev = adapter->pdev;
247 int err;
248 unsigned long flags;
249 u16 speed, duplex, phy_data;
250
251 spin_lock_irqsave(&adapter->mdio_lock, flags);
252 /* MII_BMSR must read twise */
253 atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
254 atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
255 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
256
257 if ((phy_data & BMSR_LSTATUS) == 0) {
258 /* link down */
Jie Yang8f574b32010-06-01 00:28:12 -0700259 hw->hibernate = true;
260 if (atl1c_stop_mac(hw) != 0)
261 if (netif_msg_hw(adapter))
262 dev_warn(&pdev->dev, "stop mac failed\n");
Huang, Xiong024e1e42012-04-18 22:01:28 +0000263 atl1c_set_aspm(hw, SPEED_0);
Huang, Xiong903d7ce2012-04-30 15:38:50 +0000264 atl1c_post_phy_linkchg(hw, SPEED_0);
Jie Yang43250dd2009-02-18 17:24:15 -0800265 netif_carrier_off(netdev);
Jie Yang8f574b32010-06-01 00:28:12 -0700266 netif_stop_queue(netdev);
Jie Yang43250dd2009-02-18 17:24:15 -0800267 } else {
268 /* Link Up */
269 hw->hibernate = false;
270 spin_lock_irqsave(&adapter->mdio_lock, flags);
271 err = atl1c_get_speed_and_duplex(hw, &speed, &duplex);
272 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
273 if (unlikely(err))
274 return;
275 /* link result is our setting */
276 if (adapter->link_speed != speed ||
277 adapter->link_duplex != duplex) {
278 adapter->link_speed = speed;
279 adapter->link_duplex = duplex;
Huang, Xiong024e1e42012-04-18 22:01:28 +0000280 atl1c_set_aspm(hw, speed);
Huang, Xiong903d7ce2012-04-30 15:38:50 +0000281 atl1c_post_phy_linkchg(hw, speed);
Huang, Xiong25456e52012-04-25 20:41:00 +0000282 atl1c_start_mac(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -0800283 if (netif_msg_link(adapter))
284 dev_info(&pdev->dev,
285 "%s: %s NIC Link is Up<%d Mbps %s>\n",
286 atl1c_driver_name, netdev->name,
287 adapter->link_speed,
288 adapter->link_duplex == FULL_DUPLEX ?
289 "Full Duplex" : "Half Duplex");
290 }
291 if (!netif_carrier_ok(netdev))
292 netif_carrier_on(netdev);
293 }
294}
295
Jie Yang43250dd2009-02-18 17:24:15 -0800296static void atl1c_link_chg_event(struct atl1c_adapter *adapter)
297{
298 struct net_device *netdev = adapter->netdev;
299 struct pci_dev *pdev = adapter->pdev;
300 u16 phy_data;
301 u16 link_up;
302
303 spin_lock(&adapter->mdio_lock);
304 atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
305 atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
306 spin_unlock(&adapter->mdio_lock);
307 link_up = phy_data & BMSR_LSTATUS;
308 /* notify upper layer link down ASAP */
309 if (!link_up) {
310 if (netif_carrier_ok(netdev)) {
311 /* old link state: Up */
312 netif_carrier_off(netdev);
313 if (netif_msg_link(adapter))
314 dev_info(&pdev->dev,
315 "%s: %s NIC Link is Down\n",
316 atl1c_driver_name, netdev->name);
317 adapter->link_speed = SPEED_0;
318 }
319 }
Jie Yangcb190542009-12-06 23:16:58 +0000320
Tim Gardnercb771832011-04-20 09:00:49 +0000321 set_bit(ATL1C_WORK_EVENT_LINK_CHANGE, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +0000322 schedule_work(&adapter->common_task);
Jie Yang43250dd2009-02-18 17:24:15 -0800323}
324
Jie Yangcb190542009-12-06 23:16:58 +0000325static void atl1c_common_task(struct work_struct *work)
326{
327 struct atl1c_adapter *adapter;
328 struct net_device *netdev;
329
330 adapter = container_of(work, struct atl1c_adapter, common_task);
331 netdev = adapter->netdev;
332
Huang, Xiong0aa76ce2012-04-30 15:38:55 +0000333 if (test_bit(__AT_DOWN, &adapter->flags))
334 return;
335
Tim Gardnercb771832011-04-20 09:00:49 +0000336 if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) {
Jie Yangcb190542009-12-06 23:16:58 +0000337 netif_device_detach(netdev);
338 atl1c_down(adapter);
339 atl1c_up(adapter);
340 netif_device_attach(netdev);
Jie Yangcb190542009-12-06 23:16:58 +0000341 }
342
Tim Gardnercb771832011-04-20 09:00:49 +0000343 if (test_and_clear_bit(ATL1C_WORK_EVENT_LINK_CHANGE,
344 &adapter->work_event))
Jie Yangcb190542009-12-06 23:16:58 +0000345 atl1c_check_link_status(adapter);
Jie Yangcb190542009-12-06 23:16:58 +0000346}
347
348
Jie Yang43250dd2009-02-18 17:24:15 -0800349static void atl1c_del_timer(struct atl1c_adapter *adapter)
350{
351 del_timer_sync(&adapter->phy_config_timer);
352}
353
Jie Yang43250dd2009-02-18 17:24:15 -0800354
355/*
356 * atl1c_tx_timeout - Respond to a Tx Hang
357 * @netdev: network interface device structure
358 */
359static void atl1c_tx_timeout(struct net_device *netdev)
360{
361 struct atl1c_adapter *adapter = netdev_priv(netdev);
362
363 /* Do the reset outside of interrupt context */
Tim Gardnercb771832011-04-20 09:00:49 +0000364 set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +0000365 schedule_work(&adapter->common_task);
Jie Yang43250dd2009-02-18 17:24:15 -0800366}
367
368/*
369 * atl1c_set_multi - Multicast and Promiscuous mode set
370 * @netdev: network interface device structure
371 *
372 * The set_multi entry point is called whenever the multicast address
373 * list or the network interface flags are updated. This routine is
374 * responsible for configuring the hardware for proper multicast,
375 * promiscuous mode, and all-multi behavior.
376 */
377static void atl1c_set_multi(struct net_device *netdev)
378{
379 struct atl1c_adapter *adapter = netdev_priv(netdev);
380 struct atl1c_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000381 struct netdev_hw_addr *ha;
Jie Yang43250dd2009-02-18 17:24:15 -0800382 u32 mac_ctrl_data;
383 u32 hash_value;
384
385 /* Check for Promiscuous and All Multicast modes */
386 AT_READ_REG(hw, REG_MAC_CTRL, &mac_ctrl_data);
387
388 if (netdev->flags & IFF_PROMISC) {
389 mac_ctrl_data |= MAC_CTRL_PROMIS_EN;
390 } else if (netdev->flags & IFF_ALLMULTI) {
391 mac_ctrl_data |= MAC_CTRL_MC_ALL_EN;
392 mac_ctrl_data &= ~MAC_CTRL_PROMIS_EN;
393 } else {
394 mac_ctrl_data &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN);
395 }
396
397 AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data);
398
399 /* clear the old settings from the multicast hash table */
400 AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
401 AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
402
403 /* comoute mc addresses' hash value ,and put it into hash table */
Jiri Pirko22bedad32010-04-01 21:22:57 +0000404 netdev_for_each_mc_addr(ha, netdev) {
405 hash_value = atl1c_hash_mc_addr(hw, ha->addr);
Jie Yang43250dd2009-02-18 17:24:15 -0800406 atl1c_hash_set(hw, hash_value);
407 }
408}
409
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000410static void __atl1c_vlan_mode(netdev_features_t features, u32 *mac_ctrl_data)
Jiri Pirko46facce2011-07-20 04:54:12 +0000411{
412 if (features & NETIF_F_HW_VLAN_RX) {
413 /* enable VLAN tag insert/strip */
414 *mac_ctrl_data |= MAC_CTRL_RMV_VLAN;
415 } else {
416 /* disable VLAN tag insert/strip */
417 *mac_ctrl_data &= ~MAC_CTRL_RMV_VLAN;
418 }
419}
420
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000421static void atl1c_vlan_mode(struct net_device *netdev,
422 netdev_features_t features)
Jie Yang43250dd2009-02-18 17:24:15 -0800423{
424 struct atl1c_adapter *adapter = netdev_priv(netdev);
425 struct pci_dev *pdev = adapter->pdev;
426 u32 mac_ctrl_data = 0;
427
428 if (netif_msg_pktdata(adapter))
Jiri Pirko46facce2011-07-20 04:54:12 +0000429 dev_dbg(&pdev->dev, "atl1c_vlan_mode\n");
Jie Yang43250dd2009-02-18 17:24:15 -0800430
431 atl1c_irq_disable(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -0800432 AT_READ_REG(&adapter->hw, REG_MAC_CTRL, &mac_ctrl_data);
Jiri Pirko46facce2011-07-20 04:54:12 +0000433 __atl1c_vlan_mode(features, &mac_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -0800434 AT_WRITE_REG(&adapter->hw, REG_MAC_CTRL, mac_ctrl_data);
435 atl1c_irq_enable(adapter);
436}
437
438static void atl1c_restore_vlan(struct atl1c_adapter *adapter)
439{
440 struct pci_dev *pdev = adapter->pdev;
441
442 if (netif_msg_pktdata(adapter))
Jiri Pirko46facce2011-07-20 04:54:12 +0000443 dev_dbg(&pdev->dev, "atl1c_restore_vlan\n");
444 atl1c_vlan_mode(adapter->netdev, adapter->netdev->features);
Jie Yang43250dd2009-02-18 17:24:15 -0800445}
Jiri Pirko46facce2011-07-20 04:54:12 +0000446
Jie Yang43250dd2009-02-18 17:24:15 -0800447/*
448 * atl1c_set_mac - Change the Ethernet Address of the NIC
449 * @netdev: network interface device structure
450 * @p: pointer to an address structure
451 *
452 * Returns 0 on success, negative on failure
453 */
454static int atl1c_set_mac_addr(struct net_device *netdev, void *p)
455{
456 struct atl1c_adapter *adapter = netdev_priv(netdev);
457 struct sockaddr *addr = p;
458
459 if (!is_valid_ether_addr(addr->sa_data))
460 return -EADDRNOTAVAIL;
461
462 if (netif_running(netdev))
463 return -EBUSY;
464
465 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
466 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
Danny Kukawka6a214fd2012-02-17 05:43:30 +0000467 netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
Jie Yang43250dd2009-02-18 17:24:15 -0800468
Huang, Xiong229e6b62012-04-30 15:38:53 +0000469 atl1c_hw_set_mac_addr(&adapter->hw, adapter->hw.mac_addr);
Jie Yang43250dd2009-02-18 17:24:15 -0800470
471 return 0;
472}
473
474static void atl1c_set_rxbufsize(struct atl1c_adapter *adapter,
475 struct net_device *dev)
476{
477 int mtu = dev->mtu;
478
479 adapter->rx_buffer_len = mtu > AT_RX_BUF_SIZE ?
480 roundup(mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, 8) : AT_RX_BUF_SIZE;
481}
Michał Mirosław782d6402011-04-07 07:32:18 +0000482
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000483static netdev_features_t atl1c_fix_features(struct net_device *netdev,
484 netdev_features_t features)
Michał Mirosław782d6402011-04-07 07:32:18 +0000485{
Jiri Pirko46facce2011-07-20 04:54:12 +0000486 /*
487 * Since there is no support for separate rx/tx vlan accel
488 * enable/disable make sure tx flag is always in same state as rx.
489 */
490 if (features & NETIF_F_HW_VLAN_RX)
491 features |= NETIF_F_HW_VLAN_TX;
492 else
493 features &= ~NETIF_F_HW_VLAN_TX;
494
Michał Mirosław782d6402011-04-07 07:32:18 +0000495 if (netdev->mtu > MAX_TSO_FRAME_SIZE)
496 features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
497
498 return features;
499}
500
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000501static int atl1c_set_features(struct net_device *netdev,
502 netdev_features_t features)
Jiri Pirko46facce2011-07-20 04:54:12 +0000503{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000504 netdev_features_t changed = netdev->features ^ features;
Jiri Pirko46facce2011-07-20 04:54:12 +0000505
506 if (changed & NETIF_F_HW_VLAN_RX)
507 atl1c_vlan_mode(netdev, features);
508
509 return 0;
510}
511
Jie Yang43250dd2009-02-18 17:24:15 -0800512/*
513 * atl1c_change_mtu - Change the Maximum Transfer Unit
514 * @netdev: network interface device structure
515 * @new_mtu: new value for maximum frame size
516 *
517 * Returns 0 on success, negative on failure
518 */
519static int atl1c_change_mtu(struct net_device *netdev, int new_mtu)
520{
521 struct atl1c_adapter *adapter = netdev_priv(netdev);
Huang, Xiongc08b9b22012-04-18 22:01:23 +0000522 struct atl1c_hw *hw = &adapter->hw;
Jie Yang43250dd2009-02-18 17:24:15 -0800523 int old_mtu = netdev->mtu;
524 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
525
Huang, Xiongc08b9b22012-04-18 22:01:23 +0000526 /* Fast Ethernet controller doesn't support jumbo packet */
527 if (((hw->nic_type == athr_l2c ||
528 hw->nic_type == athr_l2c_b ||
529 hw->nic_type == athr_l2c_b2) && new_mtu > ETH_DATA_LEN) ||
530 max_frame < ETH_ZLEN + ETH_FCS_LEN ||
531 max_frame > MAX_JUMBO_FRAME_SIZE) {
Jie Yang43250dd2009-02-18 17:24:15 -0800532 if (netif_msg_link(adapter))
533 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
534 return -EINVAL;
535 }
536 /* set MTU */
537 if (old_mtu != new_mtu && netif_running(netdev)) {
538 while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
539 msleep(1);
540 netdev->mtu = new_mtu;
541 adapter->hw.max_frame_size = new_mtu;
542 atl1c_set_rxbufsize(adapter, netdev);
543 atl1c_down(adapter);
Michał Mirosław782d6402011-04-07 07:32:18 +0000544 netdev_update_features(netdev);
Jie Yang43250dd2009-02-18 17:24:15 -0800545 atl1c_up(adapter);
546 clear_bit(__AT_RESETTING, &adapter->flags);
547 if (adapter->hw.ctrl_flags & ATL1C_FPGA_VERSION) {
548 u32 phy_data;
549
550 AT_READ_REG(&adapter->hw, 0x1414, &phy_data);
551 phy_data |= 0x10000000;
552 AT_WRITE_REG(&adapter->hw, 0x1414, phy_data);
553 }
554
555 }
556 return 0;
557}
558
559/*
560 * caller should hold mdio_lock
561 */
562static int atl1c_mdio_read(struct net_device *netdev, int phy_id, int reg_num)
563{
564 struct atl1c_adapter *adapter = netdev_priv(netdev);
565 u16 result;
566
Huang, Xiong2528a5d2012-04-18 22:01:31 +0000567 atl1c_read_phy_reg(&adapter->hw, reg_num, &result);
Jie Yang43250dd2009-02-18 17:24:15 -0800568 return result;
569}
570
571static void atl1c_mdio_write(struct net_device *netdev, int phy_id,
572 int reg_num, int val)
573{
574 struct atl1c_adapter *adapter = netdev_priv(netdev);
575
Huang, Xiong2528a5d2012-04-18 22:01:31 +0000576 atl1c_write_phy_reg(&adapter->hw, reg_num, val);
Jie Yang43250dd2009-02-18 17:24:15 -0800577}
578
579/*
580 * atl1c_mii_ioctl -
581 * @netdev:
582 * @ifreq:
583 * @cmd:
584 */
585static int atl1c_mii_ioctl(struct net_device *netdev,
586 struct ifreq *ifr, int cmd)
587{
588 struct atl1c_adapter *adapter = netdev_priv(netdev);
589 struct pci_dev *pdev = adapter->pdev;
590 struct mii_ioctl_data *data = if_mii(ifr);
591 unsigned long flags;
592 int retval = 0;
593
594 if (!netif_running(netdev))
595 return -EINVAL;
596
597 spin_lock_irqsave(&adapter->mdio_lock, flags);
598 switch (cmd) {
599 case SIOCGMIIPHY:
600 data->phy_id = 0;
601 break;
602
603 case SIOCGMIIREG:
Jie Yang43250dd2009-02-18 17:24:15 -0800604 if (atl1c_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
605 &data->val_out)) {
606 retval = -EIO;
607 goto out;
608 }
609 break;
610
611 case SIOCSMIIREG:
Jie Yang43250dd2009-02-18 17:24:15 -0800612 if (data->reg_num & ~(0x1F)) {
613 retval = -EFAULT;
614 goto out;
615 }
616
617 dev_dbg(&pdev->dev, "<atl1c_mii_ioctl> write %x %x",
618 data->reg_num, data->val_in);
619 if (atl1c_write_phy_reg(&adapter->hw,
620 data->reg_num, data->val_in)) {
621 retval = -EIO;
622 goto out;
623 }
624 break;
625
626 default:
627 retval = -EOPNOTSUPP;
628 break;
629 }
630out:
631 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
632 return retval;
633}
634
635/*
636 * atl1c_ioctl -
637 * @netdev:
638 * @ifreq:
639 * @cmd:
640 */
641static int atl1c_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
642{
643 switch (cmd) {
644 case SIOCGMIIPHY:
645 case SIOCGMIIREG:
646 case SIOCSMIIREG:
647 return atl1c_mii_ioctl(netdev, ifr, cmd);
648 default:
649 return -EOPNOTSUPP;
650 }
651}
652
653/*
654 * atl1c_alloc_queues - Allocate memory for all rings
655 * @adapter: board private structure to initialize
656 *
657 */
658static int __devinit atl1c_alloc_queues(struct atl1c_adapter *adapter)
659{
660 return 0;
661}
662
663static void atl1c_set_mac_type(struct atl1c_hw *hw)
664{
665 switch (hw->device_id) {
666 case PCI_DEVICE_ID_ATTANSIC_L2C:
667 hw->nic_type = athr_l2c;
668 break;
Jie Yang43250dd2009-02-18 17:24:15 -0800669 case PCI_DEVICE_ID_ATTANSIC_L1C:
670 hw->nic_type = athr_l1c;
671 break;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800672 case PCI_DEVICE_ID_ATHEROS_L2C_B:
673 hw->nic_type = athr_l2c_b;
674 break;
675 case PCI_DEVICE_ID_ATHEROS_L2C_B2:
676 hw->nic_type = athr_l2c_b2;
677 break;
678 case PCI_DEVICE_ID_ATHEROS_L1D:
679 hw->nic_type = athr_l1d;
680 break;
Jie Yang8f574b32010-06-01 00:28:12 -0700681 case PCI_DEVICE_ID_ATHEROS_L1D_2_0:
682 hw->nic_type = athr_l1d_2;
683 break;
Jie Yang43250dd2009-02-18 17:24:15 -0800684 default:
685 break;
686 }
687}
688
689static int atl1c_setup_mac_funcs(struct atl1c_hw *hw)
690{
Jie Yang43250dd2009-02-18 17:24:15 -0800691 u32 link_ctrl_data;
692
693 atl1c_set_mac_type(hw);
Jie Yang43250dd2009-02-18 17:24:15 -0800694 AT_READ_REG(hw, REG_LINK_CTRL, &link_ctrl_data);
695
Jie Yang8f574b32010-06-01 00:28:12 -0700696 hw->ctrl_flags = ATL1C_INTR_MODRT_ENABLE |
Jie Yang43250dd2009-02-18 17:24:15 -0800697 ATL1C_TXQ_MODE_ENHANCE;
Huang, Xiong024e1e42012-04-18 22:01:28 +0000698 hw->ctrl_flags |= ATL1C_ASPM_L0S_SUPPORT |
699 ATL1C_ASPM_L1_SUPPORT;
Jie Yang8f574b32010-06-01 00:28:12 -0700700 hw->ctrl_flags |= ATL1C_ASPM_CTRL_MON;
Jie Yang43250dd2009-02-18 17:24:15 -0800701
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800702 if (hw->nic_type == athr_l1c ||
Jie Yang8f574b32010-06-01 00:28:12 -0700703 hw->nic_type == athr_l1d ||
704 hw->nic_type == athr_l1d_2)
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800705 hw->link_cap_flags |= ATL1C_LINK_CAP_1000M;
Jie Yang43250dd2009-02-18 17:24:15 -0800706 return 0;
707}
Huang, Xiong903d7ce2012-04-30 15:38:50 +0000708
709struct atl1c_platform_patch {
710 u16 pci_did;
711 u8 pci_revid;
712 u16 subsystem_vid;
713 u16 subsystem_did;
714 u32 patch_flag;
715#define ATL1C_LINK_PATCH 0x1
716};
717static const struct atl1c_platform_patch plats[] __devinitdata = {
718{0x2060, 0xC1, 0x1019, 0x8152, 0x1},
719{0x2060, 0xC1, 0x1019, 0x2060, 0x1},
720{0x2060, 0xC1, 0x1019, 0xE000, 0x1},
721{0x2062, 0xC0, 0x1019, 0x8152, 0x1},
722{0x2062, 0xC0, 0x1019, 0x2062, 0x1},
723{0x2062, 0xC0, 0x1458, 0xE000, 0x1},
724{0x2062, 0xC1, 0x1019, 0x8152, 0x1},
725{0x2062, 0xC1, 0x1019, 0x2062, 0x1},
726{0x2062, 0xC1, 0x1458, 0xE000, 0x1},
727{0x2062, 0xC1, 0x1565, 0x2802, 0x1},
728{0x2062, 0xC1, 0x1565, 0x2801, 0x1},
729{0x1073, 0xC0, 0x1019, 0x8151, 0x1},
730{0x1073, 0xC0, 0x1019, 0x1073, 0x1},
731{0x1073, 0xC0, 0x1458, 0xE000, 0x1},
732{0x1083, 0xC0, 0x1458, 0xE000, 0x1},
733{0x1083, 0xC0, 0x1019, 0x8151, 0x1},
734{0x1083, 0xC0, 0x1019, 0x1083, 0x1},
735{0x1083, 0xC0, 0x1462, 0x7680, 0x1},
736{0x1083, 0xC0, 0x1565, 0x2803, 0x1},
737{0},
738};
739
740static void __devinit atl1c_patch_assign(struct atl1c_hw *hw)
741{
742 int i = 0;
743
744 hw->msi_lnkpatch = false;
745
746 while (plats[i].pci_did != 0) {
747 if (plats[i].pci_did == hw->device_id &&
748 plats[i].pci_revid == hw->revision_id &&
749 plats[i].subsystem_vid == hw->subsystem_vendor_id &&
750 plats[i].subsystem_did == hw->subsystem_id) {
751 if (plats[i].patch_flag & ATL1C_LINK_PATCH)
752 hw->msi_lnkpatch = true;
753 }
754 i++;
755 }
756}
Jie Yang43250dd2009-02-18 17:24:15 -0800757/*
758 * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter)
759 * @adapter: board private structure to initialize
760 *
761 * atl1c_sw_init initializes the Adapter private data structure.
762 * Fields are initialized based on PCI device information and
763 * OS network device settings (MTU size).
764 */
765static int __devinit atl1c_sw_init(struct atl1c_adapter *adapter)
766{
767 struct atl1c_hw *hw = &adapter->hw;
768 struct pci_dev *pdev = adapter->pdev;
Jie Yang8f574b32010-06-01 00:28:12 -0700769 u32 revision;
770
Jie Yang43250dd2009-02-18 17:24:15 -0800771
772 adapter->wol = 0;
Rafael J. Wysocki762e3022010-12-22 03:07:52 +0000773 device_set_wakeup_enable(&pdev->dev, false);
Jie Yang43250dd2009-02-18 17:24:15 -0800774 adapter->link_speed = SPEED_0;
775 adapter->link_duplex = FULL_DUPLEX;
Jie Yang43250dd2009-02-18 17:24:15 -0800776 adapter->tpd_ring[0].count = 1024;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000777 adapter->rfd_ring.count = 512;
Jie Yang43250dd2009-02-18 17:24:15 -0800778
779 hw->vendor_id = pdev->vendor;
780 hw->device_id = pdev->device;
781 hw->subsystem_vendor_id = pdev->subsystem_vendor;
782 hw->subsystem_id = pdev->subsystem_device;
Jie Yang8f574b32010-06-01 00:28:12 -0700783 AT_READ_REG(hw, PCI_CLASS_REVISION, &revision);
784 hw->revision_id = revision & 0xFF;
Jie Yang43250dd2009-02-18 17:24:15 -0800785 /* before link up, we assume hibernate is true */
786 hw->hibernate = true;
787 hw->media_type = MEDIA_TYPE_AUTO_SENSOR;
788 if (atl1c_setup_mac_funcs(hw) != 0) {
789 dev_err(&pdev->dev, "set mac function pointers failed\n");
790 return -1;
791 }
Huang, Xiong903d7ce2012-04-30 15:38:50 +0000792 atl1c_patch_assign(hw);
793
Jie Yang43250dd2009-02-18 17:24:15 -0800794 hw->intr_mask = IMR_NORMAL_MASK;
795 hw->phy_configured = false;
796 hw->preamble_len = 7;
797 hw->max_frame_size = adapter->netdev->mtu;
Jie Yang43250dd2009-02-18 17:24:15 -0800798 hw->autoneg_advertised = ADVERTISED_Autoneg;
799 hw->indirect_tab = 0xE4E4E4E4;
800 hw->base_cpu = 0;
801
802 hw->ict = 50000; /* 100ms */
803 hw->smb_timer = 200000; /* 400ms */
Jie Yang43250dd2009-02-18 17:24:15 -0800804 hw->rx_imt = 200;
805 hw->tx_imt = 1000;
806
807 hw->tpd_burst = 5;
808 hw->rfd_burst = 8;
809 hw->dma_order = atl1c_dma_ord_out;
810 hw->dmar_block = atl1c_dma_req_1024;
Jie Yang43250dd2009-02-18 17:24:15 -0800811
812 if (atl1c_alloc_queues(adapter)) {
813 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
814 return -ENOMEM;
815 }
816 /* TODO */
817 atl1c_set_rxbufsize(adapter, adapter->netdev);
818 atomic_set(&adapter->irq_sem, 1);
819 spin_lock_init(&adapter->mdio_lock);
820 spin_lock_init(&adapter->tx_lock);
821 set_bit(__AT_DOWN, &adapter->flags);
822
823 return 0;
824}
825
Jie Yangc6060be2009-11-06 00:32:05 -0800826static inline void atl1c_clean_buffer(struct pci_dev *pdev,
827 struct atl1c_buffer *buffer_info, int in_irq)
828{
Jie Yang4b45e342009-12-06 22:56:59 +0000829 u16 pci_driection;
Jie Yangc6060be2009-11-06 00:32:05 -0800830 if (buffer_info->flags & ATL1C_BUFFER_FREE)
831 return;
832 if (buffer_info->dma) {
Jie Yang4b45e342009-12-06 22:56:59 +0000833 if (buffer_info->flags & ATL1C_PCIMAP_FROMDEVICE)
834 pci_driection = PCI_DMA_FROMDEVICE;
835 else
836 pci_driection = PCI_DMA_TODEVICE;
837
Jie Yangc6060be2009-11-06 00:32:05 -0800838 if (buffer_info->flags & ATL1C_PCIMAP_SINGLE)
839 pci_unmap_single(pdev, buffer_info->dma,
Jie Yang4b45e342009-12-06 22:56:59 +0000840 buffer_info->length, pci_driection);
Jie Yangc6060be2009-11-06 00:32:05 -0800841 else if (buffer_info->flags & ATL1C_PCIMAP_PAGE)
842 pci_unmap_page(pdev, buffer_info->dma,
Jie Yang4b45e342009-12-06 22:56:59 +0000843 buffer_info->length, pci_driection);
Jie Yangc6060be2009-11-06 00:32:05 -0800844 }
845 if (buffer_info->skb) {
846 if (in_irq)
847 dev_kfree_skb_irq(buffer_info->skb);
848 else
849 dev_kfree_skb(buffer_info->skb);
850 }
851 buffer_info->dma = 0;
852 buffer_info->skb = NULL;
853 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE);
854}
Jie Yang43250dd2009-02-18 17:24:15 -0800855/*
856 * atl1c_clean_tx_ring - Free Tx-skb
857 * @adapter: board private structure
858 */
859static void atl1c_clean_tx_ring(struct atl1c_adapter *adapter,
860 enum atl1c_trans_queue type)
861{
862 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
863 struct atl1c_buffer *buffer_info;
864 struct pci_dev *pdev = adapter->pdev;
865 u16 index, ring_count;
866
867 ring_count = tpd_ring->count;
868 for (index = 0; index < ring_count; index++) {
869 buffer_info = &tpd_ring->buffer_info[index];
Jie Yangc6060be2009-11-06 00:32:05 -0800870 atl1c_clean_buffer(pdev, buffer_info, 0);
Jie Yang43250dd2009-02-18 17:24:15 -0800871 }
872
873 /* Zero out Tx-buffers */
874 memset(tpd_ring->desc, 0, sizeof(struct atl1c_tpd_desc) *
Jie Yangc6060be2009-11-06 00:32:05 -0800875 ring_count);
Jie Yang43250dd2009-02-18 17:24:15 -0800876 atomic_set(&tpd_ring->next_to_clean, 0);
877 tpd_ring->next_to_use = 0;
878}
879
880/*
881 * atl1c_clean_rx_ring - Free rx-reservation skbs
882 * @adapter: board private structure
883 */
884static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter)
885{
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000886 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
887 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800888 struct atl1c_buffer *buffer_info;
889 struct pci_dev *pdev = adapter->pdev;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000890 int j;
Jie Yang43250dd2009-02-18 17:24:15 -0800891
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000892 for (j = 0; j < rfd_ring->count; j++) {
893 buffer_info = &rfd_ring->buffer_info[j];
894 atl1c_clean_buffer(pdev, buffer_info, 0);
Jie Yang43250dd2009-02-18 17:24:15 -0800895 }
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000896 /* zero out the descriptor ring */
897 memset(rfd_ring->desc, 0, rfd_ring->size);
898 rfd_ring->next_to_clean = 0;
899 rfd_ring->next_to_use = 0;
900 rrd_ring->next_to_use = 0;
901 rrd_ring->next_to_clean = 0;
Jie Yang43250dd2009-02-18 17:24:15 -0800902}
903
904/*
905 * Read / Write Ptr Initialize:
906 */
907static void atl1c_init_ring_ptrs(struct atl1c_adapter *adapter)
908{
909 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000910 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
911 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800912 struct atl1c_buffer *buffer_info;
913 int i, j;
914
915 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
916 tpd_ring[i].next_to_use = 0;
917 atomic_set(&tpd_ring[i].next_to_clean, 0);
918 buffer_info = tpd_ring[i].buffer_info;
919 for (j = 0; j < tpd_ring->count; j++)
Jie Yangc6060be2009-11-06 00:32:05 -0800920 ATL1C_SET_BUFFER_STATE(&buffer_info[i],
921 ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -0800922 }
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000923 rfd_ring->next_to_use = 0;
924 rfd_ring->next_to_clean = 0;
925 rrd_ring->next_to_use = 0;
926 rrd_ring->next_to_clean = 0;
927 for (j = 0; j < rfd_ring->count; j++) {
928 buffer_info = &rfd_ring->buffer_info[j];
929 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -0800930 }
931}
932
933/*
934 * atl1c_free_ring_resources - Free Tx / RX descriptor Resources
935 * @adapter: board private structure
936 *
937 * Free all transmit software resources
938 */
939static void atl1c_free_ring_resources(struct atl1c_adapter *adapter)
940{
941 struct pci_dev *pdev = adapter->pdev;
942
943 pci_free_consistent(pdev, adapter->ring_header.size,
944 adapter->ring_header.desc,
945 adapter->ring_header.dma);
946 adapter->ring_header.desc = NULL;
947
948 /* Note: just free tdp_ring.buffer_info,
949 * it contain rfd_ring.buffer_info, do not double free */
950 if (adapter->tpd_ring[0].buffer_info) {
951 kfree(adapter->tpd_ring[0].buffer_info);
952 adapter->tpd_ring[0].buffer_info = NULL;
953 }
954}
955
956/*
957 * atl1c_setup_mem_resources - allocate Tx / RX descriptor resources
958 * @adapter: board private structure
959 *
960 * Return 0 on success, negative on failure
961 */
962static int atl1c_setup_ring_resources(struct atl1c_adapter *adapter)
963{
964 struct pci_dev *pdev = adapter->pdev;
965 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000966 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
967 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800968 struct atl1c_ring_header *ring_header = &adapter->ring_header;
Jie Yang43250dd2009-02-18 17:24:15 -0800969 int size;
970 int i;
971 int count = 0;
972 int rx_desc_count = 0;
973 u32 offset = 0;
974
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000975 rrd_ring->count = rfd_ring->count;
Jie Yang43250dd2009-02-18 17:24:15 -0800976 for (i = 1; i < AT_MAX_TRANSMIT_QUEUE; i++)
977 tpd_ring[i].count = tpd_ring[0].count;
978
Jie Yang43250dd2009-02-18 17:24:15 -0800979 /* 2 tpd queue, one high priority queue,
980 * another normal priority queue */
981 size = sizeof(struct atl1c_buffer) * (tpd_ring->count * 2 +
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000982 rfd_ring->count);
Jie Yang43250dd2009-02-18 17:24:15 -0800983 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL);
984 if (unlikely(!tpd_ring->buffer_info)) {
985 dev_err(&pdev->dev, "kzalloc failed, size = %d\n",
986 size);
987 goto err_nomem;
988 }
989 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
990 tpd_ring[i].buffer_info =
991 (struct atl1c_buffer *) (tpd_ring->buffer_info + count);
992 count += tpd_ring[i].count;
993 }
994
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000995 rfd_ring->buffer_info =
996 (struct atl1c_buffer *) (tpd_ring->buffer_info + count);
997 count += rfd_ring->count;
998 rx_desc_count += rfd_ring->count;
999
Jie Yang43250dd2009-02-18 17:24:15 -08001000 /*
1001 * real ring DMA buffer
1002 * each ring/block may need up to 8 bytes for alignment, hence the
1003 * additional bytes tacked onto the end.
1004 */
1005 ring_header->size = size =
1006 sizeof(struct atl1c_tpd_desc) * tpd_ring->count * 2 +
1007 sizeof(struct atl1c_rx_free_desc) * rx_desc_count +
1008 sizeof(struct atl1c_recv_ret_status) * rx_desc_count +
Huang, Xiong8d5c6832012-04-17 19:32:29 +00001009 8 * 4;
Jie Yang43250dd2009-02-18 17:24:15 -08001010
1011 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size,
1012 &ring_header->dma);
1013 if (unlikely(!ring_header->desc)) {
1014 dev_err(&pdev->dev, "pci_alloc_consistend failed\n");
1015 goto err_nomem;
1016 }
1017 memset(ring_header->desc, 0, ring_header->size);
1018 /* init TPD ring */
1019
1020 tpd_ring[0].dma = roundup(ring_header->dma, 8);
1021 offset = tpd_ring[0].dma - ring_header->dma;
1022 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
1023 tpd_ring[i].dma = ring_header->dma + offset;
1024 tpd_ring[i].desc = (u8 *) ring_header->desc + offset;
1025 tpd_ring[i].size =
1026 sizeof(struct atl1c_tpd_desc) * tpd_ring[i].count;
1027 offset += roundup(tpd_ring[i].size, 8);
1028 }
1029 /* init RFD ring */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001030 rfd_ring->dma = ring_header->dma + offset;
1031 rfd_ring->desc = (u8 *) ring_header->desc + offset;
1032 rfd_ring->size = sizeof(struct atl1c_rx_free_desc) * rfd_ring->count;
1033 offset += roundup(rfd_ring->size, 8);
Jie Yang43250dd2009-02-18 17:24:15 -08001034
1035 /* init RRD ring */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001036 rrd_ring->dma = ring_header->dma + offset;
1037 rrd_ring->desc = (u8 *) ring_header->desc + offset;
1038 rrd_ring->size = sizeof(struct atl1c_recv_ret_status) *
1039 rrd_ring->count;
1040 offset += roundup(rrd_ring->size, 8);
Jie Yang43250dd2009-02-18 17:24:15 -08001041
Jie Yang43250dd2009-02-18 17:24:15 -08001042 return 0;
1043
1044err_nomem:
1045 kfree(tpd_ring->buffer_info);
1046 return -ENOMEM;
1047}
1048
1049static void atl1c_configure_des_ring(struct atl1c_adapter *adapter)
1050{
1051 struct atl1c_hw *hw = &adapter->hw;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001052 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
1053 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001054 struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *)
1055 adapter->tpd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001056
1057 /* TPD */
1058 AT_WRITE_REG(hw, REG_TX_BASE_ADDR_HI,
1059 (u32)((tpd_ring[atl1c_trans_normal].dma &
1060 AT_DMA_HI_ADDR_MASK) >> 32));
1061 /* just enable normal priority TX queue */
Huang, Xiong0af48332012-04-17 19:32:30 +00001062 AT_WRITE_REG(hw, REG_TPD_PRI0_ADDR_LO,
Jie Yang43250dd2009-02-18 17:24:15 -08001063 (u32)(tpd_ring[atl1c_trans_normal].dma &
1064 AT_DMA_LO_ADDR_MASK));
Huang, Xiong0af48332012-04-17 19:32:30 +00001065 AT_WRITE_REG(hw, REG_TPD_PRI1_ADDR_LO,
Jie Yang43250dd2009-02-18 17:24:15 -08001066 (u32)(tpd_ring[atl1c_trans_high].dma &
1067 AT_DMA_LO_ADDR_MASK));
1068 AT_WRITE_REG(hw, REG_TPD_RING_SIZE,
1069 (u32)(tpd_ring[0].count & TPD_RING_SIZE_MASK));
1070
1071
1072 /* RFD */
1073 AT_WRITE_REG(hw, REG_RX_BASE_ADDR_HI,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001074 (u32)((rfd_ring->dma & AT_DMA_HI_ADDR_MASK) >> 32));
1075 AT_WRITE_REG(hw, REG_RFD0_HEAD_ADDR_LO,
1076 (u32)(rfd_ring->dma & AT_DMA_LO_ADDR_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001077
1078 AT_WRITE_REG(hw, REG_RFD_RING_SIZE,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001079 rfd_ring->count & RFD_RING_SIZE_MASK);
Jie Yang43250dd2009-02-18 17:24:15 -08001080 AT_WRITE_REG(hw, REG_RX_BUF_SIZE,
1081 adapter->rx_buffer_len & RX_BUF_SIZE_MASK);
1082
1083 /* RRD */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001084 AT_WRITE_REG(hw, REG_RRD0_HEAD_ADDR_LO,
1085 (u32)(rrd_ring->dma & AT_DMA_LO_ADDR_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001086 AT_WRITE_REG(hw, REG_RRD_RING_SIZE,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001087 (rrd_ring->count & RRD_RING_SIZE_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001088
Jie Yang8f574b32010-06-01 00:28:12 -07001089 if (hw->nic_type == athr_l2c_b) {
1090 AT_WRITE_REG(hw, REG_SRAM_RXF_LEN, 0x02a0L);
1091 AT_WRITE_REG(hw, REG_SRAM_TXF_LEN, 0x0100L);
1092 AT_WRITE_REG(hw, REG_SRAM_RXF_ADDR, 0x029f0000L);
1093 AT_WRITE_REG(hw, REG_SRAM_RFD0_INFO, 0x02bf02a0L);
1094 AT_WRITE_REG(hw, REG_SRAM_TXF_ADDR, 0x03bf02c0L);
1095 AT_WRITE_REG(hw, REG_SRAM_TRD_ADDR, 0x03df03c0L);
1096 AT_WRITE_REG(hw, REG_TXF_WATER_MARK, 0); /* TX watermark, to enter l1 state.*/
1097 AT_WRITE_REG(hw, REG_RXD_DMA_CTRL, 0); /* RXD threshold.*/
1098 }
Jie Yang43250dd2009-02-18 17:24:15 -08001099 /* Load all of base address above */
1100 AT_WRITE_REG(hw, REG_LOAD_PTR, 1);
1101}
1102
1103static void atl1c_configure_tx(struct atl1c_adapter *adapter)
1104{
1105 struct atl1c_hw *hw = &adapter->hw;
Huang, Xiong59e26ef2012-04-17 19:32:36 +00001106 int max_pay_load;
Jie Yang43250dd2009-02-18 17:24:15 -08001107 u16 tx_offload_thresh;
1108 u32 txq_ctrl_data;
Jie Yang43250dd2009-02-18 17:24:15 -08001109
Huang, Xiongc08b9b22012-04-18 22:01:23 +00001110 tx_offload_thresh = MAX_TSO_FRAME_SIZE;
Jie Yang43250dd2009-02-18 17:24:15 -08001111 AT_WRITE_REG(hw, REG_TX_TSO_OFFLOAD_THRESH,
1112 (tx_offload_thresh >> 3) & TX_TSO_OFFLOAD_THRESH_MASK);
Huang, Xiong59e26ef2012-04-17 19:32:36 +00001113 max_pay_load = pcie_get_readrq(adapter->pdev) >> 8;
stephen hemminger81b504b2011-02-23 09:06:49 +00001114 hw->dmar_block = min_t(u32, max_pay_load, hw->dmar_block);
Huang, Xiong59e26ef2012-04-17 19:32:36 +00001115 /*
1116 * if BIOS had changed the dam-read-max-length to an invalid value,
1117 * restore it to default value
1118 */
1119 if (hw->dmar_block < DEVICE_CTRL_MAXRRS_MIN) {
1120 pcie_set_readrq(adapter->pdev, 128 << DEVICE_CTRL_MAXRRS_MIN);
1121 hw->dmar_block = DEVICE_CTRL_MAXRRS_MIN;
1122 }
Huang, Xiongc24588a2012-04-17 19:32:35 +00001123 txq_ctrl_data =
1124 hw->nic_type == athr_l2c_b || hw->nic_type == athr_l2c_b2 ?
1125 L2CB_TXQ_CFGV : L1C_TXQ_CFGV;
Jie Yang43250dd2009-02-18 17:24:15 -08001126
1127 AT_WRITE_REG(hw, REG_TXQ_CTRL, txq_ctrl_data);
1128}
1129
1130static void atl1c_configure_rx(struct atl1c_adapter *adapter)
1131{
1132 struct atl1c_hw *hw = &adapter->hw;
1133 u32 rxq_ctrl_data;
1134
1135 rxq_ctrl_data = (hw->rfd_burst & RXQ_RFD_BURST_NUM_MASK) <<
1136 RXQ_RFD_BURST_NUM_SHIFT;
1137
1138 if (hw->ctrl_flags & ATL1C_RX_IPV6_CHKSUM)
1139 rxq_ctrl_data |= IPV6_CHKSUM_CTRL_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001140
Huang, Xiong9c528212012-04-18 22:01:21 +00001141 /* aspm for gigabit */
1142 if (hw->nic_type != athr_l1d_2 && (hw->device_id & 1) != 0)
1143 rxq_ctrl_data = FIELD_SETX(rxq_ctrl_data, ASPM_THRUPUT_LIMIT,
1144 ASPM_THRUPUT_LIMIT_100M);
Jie Yang43250dd2009-02-18 17:24:15 -08001145
1146 AT_WRITE_REG(hw, REG_RXQ_CTRL, rxq_ctrl_data);
1147}
1148
Jie Yang43250dd2009-02-18 17:24:15 -08001149static void atl1c_configure_dma(struct atl1c_adapter *adapter)
1150{
1151 struct atl1c_hw *hw = &adapter->hw;
1152 u32 dma_ctrl_data;
1153
Huang, Xiong37bfccb2012-04-17 19:32:33 +00001154 dma_ctrl_data = FIELDX(DMA_CTRL_RORDER_MODE, DMA_CTRL_RORDER_MODE_OUT) |
1155 DMA_CTRL_RREQ_PRI_DATA |
1156 FIELDX(DMA_CTRL_RREQ_BLEN, hw->dmar_block) |
1157 FIELDX(DMA_CTRL_WDLY_CNT, DMA_CTRL_WDLY_CNT_DEF) |
1158 FIELDX(DMA_CTRL_RDLY_CNT, DMA_CTRL_RDLY_CNT_DEF);
Jie Yang43250dd2009-02-18 17:24:15 -08001159
1160 AT_WRITE_REG(hw, REG_DMA_CTRL, dma_ctrl_data);
1161}
1162
1163/*
1164 * Stop the mac, transmit and receive units
1165 * hw - Struct containing variables accessed by shared code
1166 * return : 0 or idle status (if error)
1167 */
1168static int atl1c_stop_mac(struct atl1c_hw *hw)
1169{
1170 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -08001171
1172 AT_READ_REG(hw, REG_RXQ_CTRL, &data);
Huang, Xiong027392c2012-04-17 19:32:31 +00001173 data &= ~RXQ_CTRL_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001174 AT_WRITE_REG(hw, REG_RXQ_CTRL, data);
1175
1176 AT_READ_REG(hw, REG_TXQ_CTRL, &data);
1177 data &= ~TXQ_CTRL_EN;
Huang, Xiong0cbec612012-04-17 19:32:32 +00001178 AT_WRITE_REG(hw, REG_TXQ_CTRL, data);
Jie Yang43250dd2009-02-18 17:24:15 -08001179
Huang, Xiong969a7ee2012-04-18 22:01:22 +00001180 atl1c_wait_until_idle(hw, IDLE_STATUS_RXQ_BUSY | IDLE_STATUS_TXQ_BUSY);
Jie Yang43250dd2009-02-18 17:24:15 -08001181
1182 AT_READ_REG(hw, REG_MAC_CTRL, &data);
1183 data &= ~(MAC_CTRL_TX_EN | MAC_CTRL_RX_EN);
1184 AT_WRITE_REG(hw, REG_MAC_CTRL, data);
1185
Huang, Xiong969a7ee2012-04-18 22:01:22 +00001186 return (int)atl1c_wait_until_idle(hw,
1187 IDLE_STATUS_TXMAC_BUSY | IDLE_STATUS_RXMAC_BUSY);
Jie Yang43250dd2009-02-18 17:24:15 -08001188}
1189
Huang, Xiong25456e52012-04-25 20:41:00 +00001190static void atl1c_start_mac(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08001191{
Huang, Xiong25456e52012-04-25 20:41:00 +00001192 struct atl1c_hw *hw = &adapter->hw;
1193 u32 mac, txq, rxq;
Jie Yang43250dd2009-02-18 17:24:15 -08001194
Huang, Xiong25456e52012-04-25 20:41:00 +00001195 hw->mac_duplex = adapter->link_duplex == FULL_DUPLEX ? true : false;
1196 hw->mac_speed = adapter->link_speed == SPEED_1000 ?
1197 atl1c_mac_speed_1000 : atl1c_mac_speed_10_100;
Jie Yang43250dd2009-02-18 17:24:15 -08001198
Huang, Xiong25456e52012-04-25 20:41:00 +00001199 AT_READ_REG(hw, REG_TXQ_CTRL, &txq);
1200 AT_READ_REG(hw, REG_RXQ_CTRL, &rxq);
1201 AT_READ_REG(hw, REG_MAC_CTRL, &mac);
Jie Yang43250dd2009-02-18 17:24:15 -08001202
Huang, Xiong25456e52012-04-25 20:41:00 +00001203 txq |= TXQ_CTRL_EN;
1204 rxq |= RXQ_CTRL_EN;
1205 mac |= MAC_CTRL_TX_EN | MAC_CTRL_TX_FLOW |
1206 MAC_CTRL_RX_EN | MAC_CTRL_RX_FLOW |
1207 MAC_CTRL_ADD_CRC | MAC_CTRL_PAD |
1208 MAC_CTRL_BC_EN | MAC_CTRL_SINGLE_PAUSE_EN |
1209 MAC_CTRL_HASH_ALG_CRC32;
1210 if (hw->mac_duplex)
1211 mac |= MAC_CTRL_DUPLX;
1212 else
1213 mac &= ~MAC_CTRL_DUPLX;
1214 mac = FIELD_SETX(mac, MAC_CTRL_SPEED, hw->mac_speed);
1215 mac = FIELD_SETX(mac, MAC_CTRL_PRMLEN, hw->preamble_len);
1216
1217 AT_WRITE_REG(hw, REG_TXQ_CTRL, txq);
1218 AT_WRITE_REG(hw, REG_RXQ_CTRL, rxq);
1219 AT_WRITE_REG(hw, REG_MAC_CTRL, mac);
Jie Yang43250dd2009-02-18 17:24:15 -08001220}
1221
1222/*
1223 * Reset the transmit and receive units; mask and clear all interrupts.
1224 * hw - Struct containing variables accessed by shared code
1225 * return : 0 or idle status (if error)
1226 */
1227static int atl1c_reset_mac(struct atl1c_hw *hw)
1228{
1229 struct atl1c_adapter *adapter = (struct atl1c_adapter *)hw->adapter;
1230 struct pci_dev *pdev = adapter->pdev;
Huang, Xiong7737fd92012-04-25 20:27:12 +00001231 u32 ctrl_data = 0;
Jie Yang43250dd2009-02-18 17:24:15 -08001232
1233 AT_WRITE_REG(hw, REG_IMR, 0);
1234 AT_WRITE_REG(hw, REG_ISR, ISR_DIS_INT);
1235
Jie Yang8f574b32010-06-01 00:28:12 -07001236 atl1c_stop_mac(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08001237 /*
1238 * Issue Soft Reset to the MAC. This will reset the chip's
1239 * transmit, receive, DMA. It will not effect
1240 * the current PCI configuration. The global reset bit is self-
1241 * clearing, and should clear within a microsecond.
1242 */
Huang, Xiong7737fd92012-04-25 20:27:12 +00001243 AT_READ_REG(hw, REG_MASTER_CTRL, &ctrl_data);
1244 ctrl_data |= MASTER_CTRL_OOB_DIS;
1245 AT_WRITE_REG(hw, REG_MASTER_CTRL, ctrl_data | MASTER_CTRL_SOFT_RST);
Jie Yang8f574b32010-06-01 00:28:12 -07001246
Jie Yang43250dd2009-02-18 17:24:15 -08001247 AT_WRITE_FLUSH(hw);
1248 msleep(10);
1249 /* Wait at least 10ms for All module to be Idle */
Joe Perchesc930a662009-05-31 20:44:54 +00001250
Huang, Xiong969a7ee2012-04-18 22:01:22 +00001251 if (atl1c_wait_until_idle(hw, IDLE_STATUS_MASK)) {
Jie Yang43250dd2009-02-18 17:24:15 -08001252 dev_err(&pdev->dev,
Joe Perchesc930a662009-05-31 20:44:54 +00001253 "MAC state machine can't be idle since"
Jie Yang43250dd2009-02-18 17:24:15 -08001254 " disabled for 10ms second\n");
1255 return -1;
1256 }
Huang, Xiong7737fd92012-04-25 20:27:12 +00001257 AT_WRITE_REG(hw, REG_MASTER_CTRL, ctrl_data);
1258
1259 /* driver control speed/duplex */
1260 AT_READ_REG(hw, REG_MAC_CTRL, &ctrl_data);
1261 AT_WRITE_REG(hw, REG_MAC_CTRL, ctrl_data | MAC_CTRL_SPEED_MODE_SW);
1262
1263 /* clk switch setting */
1264 AT_READ_REG(hw, REG_SERDES, &ctrl_data);
1265 switch (hw->nic_type) {
1266 case athr_l2c_b:
1267 ctrl_data &= ~(SERDES_PHY_CLK_SLOWDOWN |
1268 SERDES_MAC_CLK_SLOWDOWN);
1269 AT_WRITE_REG(hw, REG_SERDES, ctrl_data);
1270 break;
1271 case athr_l2c_b2:
1272 case athr_l1d_2:
1273 ctrl_data |= SERDES_PHY_CLK_SLOWDOWN | SERDES_MAC_CLK_SLOWDOWN;
1274 AT_WRITE_REG(hw, REG_SERDES, ctrl_data);
1275 break;
1276 default:
1277 break;
1278 }
Huang, Xiongebe22ed2012-04-18 22:01:29 +00001279
Jie Yang43250dd2009-02-18 17:24:15 -08001280 return 0;
1281}
1282
1283static void atl1c_disable_l0s_l1(struct atl1c_hw *hw)
1284{
Huang, Xiong024e1e42012-04-18 22:01:28 +00001285 u16 ctrl_flags = hw->ctrl_flags;
Jie Yang43250dd2009-02-18 17:24:15 -08001286
Huang, Xiong024e1e42012-04-18 22:01:28 +00001287 hw->ctrl_flags &= ~(ATL1C_ASPM_L0S_SUPPORT | ATL1C_ASPM_L1_SUPPORT);
1288 atl1c_set_aspm(hw, SPEED_0);
1289 hw->ctrl_flags = ctrl_flags;
Jie Yang43250dd2009-02-18 17:24:15 -08001290}
1291
1292/*
1293 * Set ASPM state.
1294 * Enable/disable L0s/L1 depend on link state.
1295 */
Huang, Xiong024e1e42012-04-18 22:01:28 +00001296static void atl1c_set_aspm(struct atl1c_hw *hw, u16 link_speed)
Jie Yang43250dd2009-02-18 17:24:15 -08001297{
1298 u32 pm_ctrl_data;
Huang, Xiong024e1e42012-04-18 22:01:28 +00001299 u32 link_l1_timer;
Jie Yang43250dd2009-02-18 17:24:15 -08001300
1301 AT_READ_REG(hw, REG_PM_CTRL, &pm_ctrl_data);
Huang, Xiong024e1e42012-04-18 22:01:28 +00001302 pm_ctrl_data &= ~(PM_CTRL_ASPM_L1_EN |
1303 PM_CTRL_ASPM_L0S_EN |
1304 PM_CTRL_MAC_ASPM_CHK);
1305 /* L1 timer */
1306 if (hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) {
1307 pm_ctrl_data &= ~PMCTRL_TXL1_AFTER_L0S;
1308 link_l1_timer =
1309 link_speed == SPEED_1000 || link_speed == SPEED_100 ?
1310 L1D_PMCTRL_L1_ENTRY_TM_16US : 1;
1311 pm_ctrl_data = FIELD_SETX(pm_ctrl_data,
1312 L1D_PMCTRL_L1_ENTRY_TM, link_l1_timer);
Jie Yang43250dd2009-02-18 17:24:15 -08001313 } else {
Huang, Xiong024e1e42012-04-18 22:01:28 +00001314 link_l1_timer = hw->nic_type == athr_l2c_b ?
1315 L2CB1_PM_CTRL_L1_ENTRY_TM : L1C_PM_CTRL_L1_ENTRY_TM;
1316 if (link_speed != SPEED_1000 && link_speed != SPEED_100)
1317 link_l1_timer = 1;
1318 pm_ctrl_data = FIELD_SETX(pm_ctrl_data,
1319 PM_CTRL_L1_ENTRY_TIMER, link_l1_timer);
1320 }
Jie Yang43250dd2009-02-18 17:24:15 -08001321
Huang, Xiong024e1e42012-04-18 22:01:28 +00001322 /* L0S/L1 enable */
1323 if (hw->ctrl_flags & ATL1C_ASPM_L0S_SUPPORT)
1324 pm_ctrl_data |= PM_CTRL_ASPM_L0S_EN | PM_CTRL_MAC_ASPM_CHK;
1325 if (hw->ctrl_flags & ATL1C_ASPM_L1_SUPPORT)
1326 pm_ctrl_data |= PM_CTRL_ASPM_L1_EN | PM_CTRL_MAC_ASPM_CHK;
1327
1328 /* l2cb & l1d & l2cb2 & l1d2 */
1329 if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d ||
1330 hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) {
1331 pm_ctrl_data = FIELD_SETX(pm_ctrl_data,
1332 PM_CTRL_PM_REQ_TIMER, PM_CTRL_PM_REQ_TO_DEF);
1333 pm_ctrl_data |= PM_CTRL_RCVR_WT_TIMER |
1334 PM_CTRL_SERDES_PD_EX_L1 |
1335 PM_CTRL_CLK_SWH_L1;
1336 pm_ctrl_data &= ~(PM_CTRL_SERDES_L1_EN |
1337 PM_CTRL_SERDES_PLL_L1_EN |
1338 PM_CTRL_SERDES_BUFS_RX_L1_EN |
1339 PM_CTRL_SA_DLY_EN |
1340 PM_CTRL_HOTRST);
1341 /* disable l0s if link down or l2cb */
1342 if (link_speed == SPEED_0 || hw->nic_type == athr_l2c_b)
1343 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
1344 } else { /* l1c */
1345 pm_ctrl_data =
1346 FIELD_SETX(pm_ctrl_data, PM_CTRL_L1_ENTRY_TIMER, 0);
1347 if (link_speed != SPEED_0) {
1348 pm_ctrl_data |= PM_CTRL_SERDES_L1_EN |
1349 PM_CTRL_SERDES_PLL_L1_EN |
1350 PM_CTRL_SERDES_BUFS_RX_L1_EN;
1351 pm_ctrl_data &= ~(PM_CTRL_SERDES_PD_EX_L1 |
1352 PM_CTRL_CLK_SWH_L1 |
1353 PM_CTRL_ASPM_L0S_EN |
1354 PM_CTRL_ASPM_L1_EN);
1355 } else { /* link down */
1356 pm_ctrl_data |= PM_CTRL_CLK_SWH_L1;
1357 pm_ctrl_data &= ~(PM_CTRL_SERDES_L1_EN |
1358 PM_CTRL_SERDES_PLL_L1_EN |
1359 PM_CTRL_SERDES_BUFS_RX_L1_EN |
1360 PM_CTRL_ASPM_L0S_EN);
1361 }
Jie Yang43250dd2009-02-18 17:24:15 -08001362 }
Jie Yang43250dd2009-02-18 17:24:15 -08001363 AT_WRITE_REG(hw, REG_PM_CTRL, pm_ctrl_data);
Jie Yang8f574b32010-06-01 00:28:12 -07001364
1365 return;
Jie Yang43250dd2009-02-18 17:24:15 -08001366}
1367
Jie Yang43250dd2009-02-18 17:24:15 -08001368/*
1369 * atl1c_configure - Configure Transmit&Receive Unit after Reset
1370 * @adapter: board private structure
1371 *
1372 * Configure the Tx /Rx unit of the MAC after a reset.
1373 */
1374static int atl1c_configure(struct atl1c_adapter *adapter)
1375{
1376 struct atl1c_hw *hw = &adapter->hw;
1377 u32 master_ctrl_data = 0;
1378 u32 intr_modrt_data;
Jie Yang8f574b32010-06-01 00:28:12 -07001379 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -08001380
Huang, Xiongebe22ed2012-04-18 22:01:29 +00001381 AT_READ_REG(hw, REG_MASTER_CTRL, &master_ctrl_data);
1382 master_ctrl_data &= ~(MASTER_CTRL_TX_ITIMER_EN |
1383 MASTER_CTRL_RX_ITIMER_EN |
1384 MASTER_CTRL_INT_RDCLR);
Jie Yang43250dd2009-02-18 17:24:15 -08001385 /* clear interrupt status */
1386 AT_WRITE_REG(hw, REG_ISR, 0xFFFFFFFF);
1387 /* Clear any WOL status */
1388 AT_WRITE_REG(hw, REG_WOL_CTRL, 0);
1389 /* set Interrupt Clear Timer
1390 * HW will enable self to assert interrupt event to system after
1391 * waiting x-time for software to notify it accept interrupt.
1392 */
Jie Yang8f574b32010-06-01 00:28:12 -07001393
1394 data = CLK_GATING_EN_ALL;
1395 if (hw->ctrl_flags & ATL1C_CLK_GATING_EN) {
1396 if (hw->nic_type == athr_l2c_b)
1397 data &= ~CLK_GATING_RXMAC_EN;
1398 } else
1399 data = 0;
1400 AT_WRITE_REG(hw, REG_CLK_GATING_CTRL, data);
1401
Jie Yang43250dd2009-02-18 17:24:15 -08001402 AT_WRITE_REG(hw, REG_INT_RETRIG_TIMER,
1403 hw->ict & INT_RETRIG_TIMER_MASK);
1404
1405 atl1c_configure_des_ring(adapter);
1406
1407 if (hw->ctrl_flags & ATL1C_INTR_MODRT_ENABLE) {
1408 intr_modrt_data = (hw->tx_imt & IRQ_MODRT_TIMER_MASK) <<
1409 IRQ_MODRT_TX_TIMER_SHIFT;
1410 intr_modrt_data |= (hw->rx_imt & IRQ_MODRT_TIMER_MASK) <<
1411 IRQ_MODRT_RX_TIMER_SHIFT;
1412 AT_WRITE_REG(hw, REG_IRQ_MODRT_TIMER_INIT, intr_modrt_data);
1413 master_ctrl_data |=
1414 MASTER_CTRL_TX_ITIMER_EN | MASTER_CTRL_RX_ITIMER_EN;
1415 }
1416
1417 if (hw->ctrl_flags & ATL1C_INTR_CLEAR_ON_READ)
1418 master_ctrl_data |= MASTER_CTRL_INT_RDCLR;
1419
Jie Yang8f574b32010-06-01 00:28:12 -07001420 master_ctrl_data |= MASTER_CTRL_SA_TIMER_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001421 AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data);
1422
Huang, Xiong8d5c6832012-04-17 19:32:29 +00001423 AT_WRITE_REG(hw, REG_SMB_STAT_TIMER,
1424 hw->smb_timer & SMB_STAT_TIMER_MASK);
Jie Yang43250dd2009-02-18 17:24:15 -08001425
Jie Yang43250dd2009-02-18 17:24:15 -08001426 /* set MTU */
1427 AT_WRITE_REG(hw, REG_MTU, hw->max_frame_size + ETH_HLEN +
1428 VLAN_HLEN + ETH_FCS_LEN);
Jie Yang43250dd2009-02-18 17:24:15 -08001429
1430 atl1c_configure_tx(adapter);
1431 atl1c_configure_rx(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -08001432 atl1c_configure_dma(adapter);
1433
1434 return 0;
1435}
1436
1437static void atl1c_update_hw_stats(struct atl1c_adapter *adapter)
1438{
1439 u16 hw_reg_addr = 0;
1440 unsigned long *stats_item = NULL;
1441 u32 data;
1442
1443 /* update rx status */
1444 hw_reg_addr = REG_MAC_RX_STATUS_BIN;
1445 stats_item = &adapter->hw_stats.rx_ok;
1446 while (hw_reg_addr <= REG_MAC_RX_STATUS_END) {
1447 AT_READ_REG(&adapter->hw, hw_reg_addr, &data);
1448 *stats_item += data;
1449 stats_item++;
1450 hw_reg_addr += 4;
1451 }
1452/* update tx status */
1453 hw_reg_addr = REG_MAC_TX_STATUS_BIN;
1454 stats_item = &adapter->hw_stats.tx_ok;
1455 while (hw_reg_addr <= REG_MAC_TX_STATUS_END) {
1456 AT_READ_REG(&adapter->hw, hw_reg_addr, &data);
1457 *stats_item += data;
1458 stats_item++;
1459 hw_reg_addr += 4;
1460 }
1461}
1462
1463/*
1464 * atl1c_get_stats - Get System Network Statistics
1465 * @netdev: network interface device structure
1466 *
1467 * Returns the address of the device statistics structure.
1468 * The statistics are actually updated from the timer callback.
1469 */
1470static struct net_device_stats *atl1c_get_stats(struct net_device *netdev)
1471{
1472 struct atl1c_adapter *adapter = netdev_priv(netdev);
1473 struct atl1c_hw_stats *hw_stats = &adapter->hw_stats;
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001474 struct net_device_stats *net_stats = &netdev->stats;
Jie Yang43250dd2009-02-18 17:24:15 -08001475
1476 atl1c_update_hw_stats(adapter);
1477 net_stats->rx_packets = hw_stats->rx_ok;
1478 net_stats->tx_packets = hw_stats->tx_ok;
1479 net_stats->rx_bytes = hw_stats->rx_byte_cnt;
1480 net_stats->tx_bytes = hw_stats->tx_byte_cnt;
1481 net_stats->multicast = hw_stats->rx_mcast;
1482 net_stats->collisions = hw_stats->tx_1_col +
1483 hw_stats->tx_2_col * 2 +
1484 hw_stats->tx_late_col + hw_stats->tx_abort_col;
1485 net_stats->rx_errors = hw_stats->rx_frag + hw_stats->rx_fcs_err +
1486 hw_stats->rx_len_err + hw_stats->rx_sz_ov +
1487 hw_stats->rx_rrd_ov + hw_stats->rx_align_err;
1488 net_stats->rx_fifo_errors = hw_stats->rx_rxf_ov;
1489 net_stats->rx_length_errors = hw_stats->rx_len_err;
1490 net_stats->rx_crc_errors = hw_stats->rx_fcs_err;
1491 net_stats->rx_frame_errors = hw_stats->rx_align_err;
1492 net_stats->rx_over_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov;
1493
1494 net_stats->rx_missed_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov;
1495
1496 net_stats->tx_errors = hw_stats->tx_late_col + hw_stats->tx_abort_col +
1497 hw_stats->tx_underrun + hw_stats->tx_trunc;
1498 net_stats->tx_fifo_errors = hw_stats->tx_underrun;
1499 net_stats->tx_aborted_errors = hw_stats->tx_abort_col;
1500 net_stats->tx_window_errors = hw_stats->tx_late_col;
1501
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001502 return net_stats;
Jie Yang43250dd2009-02-18 17:24:15 -08001503}
1504
1505static inline void atl1c_clear_phy_int(struct atl1c_adapter *adapter)
1506{
1507 u16 phy_data;
1508
1509 spin_lock(&adapter->mdio_lock);
1510 atl1c_read_phy_reg(&adapter->hw, MII_ISR, &phy_data);
1511 spin_unlock(&adapter->mdio_lock);
1512}
1513
1514static bool atl1c_clean_tx_irq(struct atl1c_adapter *adapter,
1515 enum atl1c_trans_queue type)
1516{
1517 struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *)
1518 &adapter->tpd_ring[type];
1519 struct atl1c_buffer *buffer_info;
Jie Yangc6060be2009-11-06 00:32:05 -08001520 struct pci_dev *pdev = adapter->pdev;
Jie Yang43250dd2009-02-18 17:24:15 -08001521 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1522 u16 hw_next_to_clean;
Huang, Xiong0af48332012-04-17 19:32:30 +00001523 u16 reg;
Jie Yang43250dd2009-02-18 17:24:15 -08001524
Huang, Xiong0af48332012-04-17 19:32:30 +00001525 reg = type == atl1c_trans_high ? REG_TPD_PRI1_CIDX : REG_TPD_PRI0_CIDX;
Jie Yang43250dd2009-02-18 17:24:15 -08001526
Huang, Xiong0af48332012-04-17 19:32:30 +00001527 AT_READ_REGW(&adapter->hw, reg, &hw_next_to_clean);
Jie Yang43250dd2009-02-18 17:24:15 -08001528
1529 while (next_to_clean != hw_next_to_clean) {
1530 buffer_info = &tpd_ring->buffer_info[next_to_clean];
Jie Yangc6060be2009-11-06 00:32:05 -08001531 atl1c_clean_buffer(pdev, buffer_info, 1);
Jie Yang43250dd2009-02-18 17:24:15 -08001532 if (++next_to_clean == tpd_ring->count)
1533 next_to_clean = 0;
1534 atomic_set(&tpd_ring->next_to_clean, next_to_clean);
1535 }
1536
1537 if (netif_queue_stopped(adapter->netdev) &&
1538 netif_carrier_ok(adapter->netdev)) {
1539 netif_wake_queue(adapter->netdev);
1540 }
1541
1542 return true;
1543}
1544
1545/*
1546 * atl1c_intr - Interrupt Handler
1547 * @irq: interrupt number
1548 * @data: pointer to a network interface device structure
1549 * @pt_regs: CPU registers structure
1550 */
1551static irqreturn_t atl1c_intr(int irq, void *data)
1552{
1553 struct net_device *netdev = data;
1554 struct atl1c_adapter *adapter = netdev_priv(netdev);
1555 struct pci_dev *pdev = adapter->pdev;
1556 struct atl1c_hw *hw = &adapter->hw;
1557 int max_ints = AT_MAX_INT_WORK;
1558 int handled = IRQ_NONE;
1559 u32 status;
1560 u32 reg_data;
1561
1562 do {
1563 AT_READ_REG(hw, REG_ISR, &reg_data);
1564 status = reg_data & hw->intr_mask;
1565
1566 if (status == 0 || (status & ISR_DIS_INT) != 0) {
1567 if (max_ints != AT_MAX_INT_WORK)
1568 handled = IRQ_HANDLED;
1569 break;
1570 }
1571 /* link event */
1572 if (status & ISR_GPHY)
1573 atl1c_clear_phy_int(adapter);
1574 /* Ack ISR */
1575 AT_WRITE_REG(hw, REG_ISR, status | ISR_DIS_INT);
1576 if (status & ISR_RX_PKT) {
1577 if (likely(napi_schedule_prep(&adapter->napi))) {
1578 hw->intr_mask &= ~ISR_RX_PKT;
1579 AT_WRITE_REG(hw, REG_IMR, hw->intr_mask);
1580 __napi_schedule(&adapter->napi);
1581 }
1582 }
1583 if (status & ISR_TX_PKT)
1584 atl1c_clean_tx_irq(adapter, atl1c_trans_normal);
1585
1586 handled = IRQ_HANDLED;
1587 /* check if PCIE PHY Link down */
1588 if (status & ISR_ERROR) {
1589 if (netif_msg_hw(adapter))
1590 dev_err(&pdev->dev,
1591 "atl1c hardware error (status = 0x%x)\n",
1592 status & ISR_ERROR);
1593 /* reset MAC */
Dan Carpenter78315452012-03-07 00:02:04 +00001594 set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +00001595 schedule_work(&adapter->common_task);
Jie Yang8f574b32010-06-01 00:28:12 -07001596 return IRQ_HANDLED;
Jie Yang43250dd2009-02-18 17:24:15 -08001597 }
1598
1599 if (status & ISR_OVER)
1600 if (netif_msg_intr(adapter))
1601 dev_warn(&pdev->dev,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001602 "TX/RX overflow (status = 0x%x)\n",
Jie Yang43250dd2009-02-18 17:24:15 -08001603 status & ISR_OVER);
1604
1605 /* link event */
1606 if (status & (ISR_GPHY | ISR_MANUAL)) {
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001607 netdev->stats.tx_carrier_errors++;
Jie Yang43250dd2009-02-18 17:24:15 -08001608 atl1c_link_chg_event(adapter);
1609 break;
1610 }
1611
1612 } while (--max_ints > 0);
1613 /* re-enable Interrupt*/
1614 AT_WRITE_REG(&adapter->hw, REG_ISR, 0);
1615 return handled;
1616}
1617
1618static inline void atl1c_rx_checksum(struct atl1c_adapter *adapter,
1619 struct sk_buff *skb, struct atl1c_recv_ret_status *prrs)
1620{
1621 /*
1622 * The pid field in RRS in not correct sometimes, so we
1623 * cannot figure out if the packet is fragmented or not,
1624 * so we tell the KERNEL CHECKSUM_NONE
1625 */
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001626 skb_checksum_none_assert(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001627}
1628
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001629static int atl1c_alloc_rx_buffer(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08001630{
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001631 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001632 struct pci_dev *pdev = adapter->pdev;
1633 struct atl1c_buffer *buffer_info, *next_info;
1634 struct sk_buff *skb;
1635 void *vir_addr = NULL;
1636 u16 num_alloc = 0;
1637 u16 rfd_next_to_use, next_next;
1638 struct atl1c_rx_free_desc *rfd_desc;
1639
1640 next_next = rfd_next_to_use = rfd_ring->next_to_use;
1641 if (++next_next == rfd_ring->count)
1642 next_next = 0;
1643 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1644 next_info = &rfd_ring->buffer_info[next_next];
1645
Jie Yangc6060be2009-11-06 00:32:05 -08001646 while (next_info->flags & ATL1C_BUFFER_FREE) {
Jie Yang43250dd2009-02-18 17:24:15 -08001647 rfd_desc = ATL1C_RFD_DESC(rfd_ring, rfd_next_to_use);
1648
Pradeep A Dalvi1d266432012-02-05 02:49:09 +00001649 skb = netdev_alloc_skb(adapter->netdev, adapter->rx_buffer_len);
Jie Yang43250dd2009-02-18 17:24:15 -08001650 if (unlikely(!skb)) {
1651 if (netif_msg_rx_err(adapter))
1652 dev_warn(&pdev->dev, "alloc rx buffer failed\n");
1653 break;
1654 }
1655
1656 /*
1657 * Make buffer alignment 2 beyond a 16 byte boundary
1658 * this will result in a 16 byte aligned IP header after
1659 * the 14 byte MAC header is removed
1660 */
1661 vir_addr = skb->data;
Jie Yangc6060be2009-11-06 00:32:05 -08001662 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang43250dd2009-02-18 17:24:15 -08001663 buffer_info->skb = skb;
1664 buffer_info->length = adapter->rx_buffer_len;
1665 buffer_info->dma = pci_map_single(pdev, vir_addr,
1666 buffer_info->length,
1667 PCI_DMA_FROMDEVICE);
Jie Yang4b45e342009-12-06 22:56:59 +00001668 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
1669 ATL1C_PCIMAP_FROMDEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08001670 rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
1671 rfd_next_to_use = next_next;
1672 if (++next_next == rfd_ring->count)
1673 next_next = 0;
1674 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1675 next_info = &rfd_ring->buffer_info[next_next];
1676 num_alloc++;
1677 }
1678
1679 if (num_alloc) {
1680 /* TODO: update mailbox here */
1681 wmb();
1682 rfd_ring->next_to_use = rfd_next_to_use;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001683 AT_WRITE_REG(&adapter->hw, REG_MB_RFD0_PROD_IDX,
Jie Yang43250dd2009-02-18 17:24:15 -08001684 rfd_ring->next_to_use & MB_RFDX_PROD_IDX_MASK);
1685 }
1686
1687 return num_alloc;
1688}
1689
1690static void atl1c_clean_rrd(struct atl1c_rrd_ring *rrd_ring,
1691 struct atl1c_recv_ret_status *rrs, u16 num)
1692{
1693 u16 i;
1694 /* the relationship between rrd and rfd is one map one */
1695 for (i = 0; i < num; i++, rrs = ATL1C_RRD_DESC(rrd_ring,
1696 rrd_ring->next_to_clean)) {
1697 rrs->word3 &= ~RRS_RXD_UPDATED;
1698 if (++rrd_ring->next_to_clean == rrd_ring->count)
1699 rrd_ring->next_to_clean = 0;
1700 }
1701}
1702
1703static void atl1c_clean_rfd(struct atl1c_rfd_ring *rfd_ring,
1704 struct atl1c_recv_ret_status *rrs, u16 num)
1705{
1706 u16 i;
1707 u16 rfd_index;
1708 struct atl1c_buffer *buffer_info = rfd_ring->buffer_info;
1709
1710 rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) &
1711 RRS_RX_RFD_INDEX_MASK;
1712 for (i = 0; i < num; i++) {
1713 buffer_info[rfd_index].skb = NULL;
Jie Yangc6060be2009-11-06 00:32:05 -08001714 ATL1C_SET_BUFFER_STATE(&buffer_info[rfd_index],
1715 ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -08001716 if (++rfd_index == rfd_ring->count)
1717 rfd_index = 0;
1718 }
1719 rfd_ring->next_to_clean = rfd_index;
1720}
1721
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001722static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter,
Jie Yang43250dd2009-02-18 17:24:15 -08001723 int *work_done, int work_to_do)
1724{
1725 u16 rfd_num, rfd_index;
1726 u16 count = 0;
1727 u16 length;
1728 struct pci_dev *pdev = adapter->pdev;
1729 struct net_device *netdev = adapter->netdev;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001730 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
1731 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001732 struct sk_buff *skb;
1733 struct atl1c_recv_ret_status *rrs;
1734 struct atl1c_buffer *buffer_info;
1735
1736 while (1) {
1737 if (*work_done >= work_to_do)
1738 break;
1739 rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean);
1740 if (likely(RRS_RXD_IS_VALID(rrs->word3))) {
1741 rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) &
1742 RRS_RX_RFD_CNT_MASK;
roel kluin37b76c62009-07-12 12:57:38 +00001743 if (unlikely(rfd_num != 1))
Jie Yang43250dd2009-02-18 17:24:15 -08001744 /* TODO support mul rfd*/
1745 if (netif_msg_rx_err(adapter))
1746 dev_warn(&pdev->dev,
1747 "Multi rfd not support yet!\n");
1748 goto rrs_checked;
1749 } else {
1750 break;
1751 }
1752rrs_checked:
1753 atl1c_clean_rrd(rrd_ring, rrs, rfd_num);
1754 if (rrs->word3 & (RRS_RX_ERR_SUM | RRS_802_3_LEN_ERR)) {
1755 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1756 if (netif_msg_rx_err(adapter))
1757 dev_warn(&pdev->dev,
1758 "wrong packet! rrs word3 is %x\n",
1759 rrs->word3);
1760 continue;
1761 }
1762
1763 length = le16_to_cpu((rrs->word3 >> RRS_PKT_SIZE_SHIFT) &
1764 RRS_PKT_SIZE_MASK);
1765 /* Good Receive */
1766 if (likely(rfd_num == 1)) {
1767 rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) &
1768 RRS_RX_RFD_INDEX_MASK;
1769 buffer_info = &rfd_ring->buffer_info[rfd_index];
1770 pci_unmap_single(pdev, buffer_info->dma,
1771 buffer_info->length, PCI_DMA_FROMDEVICE);
1772 skb = buffer_info->skb;
1773 } else {
1774 /* TODO */
1775 if (netif_msg_rx_err(adapter))
1776 dev_warn(&pdev->dev,
1777 "Multi rfd not support yet!\n");
1778 break;
1779 }
1780 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1781 skb_put(skb, length - ETH_FCS_LEN);
1782 skb->protocol = eth_type_trans(skb, netdev);
Jie Yang43250dd2009-02-18 17:24:15 -08001783 atl1c_rx_checksum(adapter, skb, rrs);
Jiri Pirko46facce2011-07-20 04:54:12 +00001784 if (rrs->word3 & RRS_VLAN_INS) {
Jie Yang43250dd2009-02-18 17:24:15 -08001785 u16 vlan;
1786
1787 AT_TAG_TO_VLAN(rrs->vlan_tag, vlan);
1788 vlan = le16_to_cpu(vlan);
Jiri Pirko46facce2011-07-20 04:54:12 +00001789 __vlan_hwaccel_put_tag(skb, vlan);
1790 }
1791 netif_receive_skb(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001792
Jie Yang43250dd2009-02-18 17:24:15 -08001793 (*work_done)++;
1794 count++;
1795 }
1796 if (count)
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001797 atl1c_alloc_rx_buffer(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -08001798}
1799
1800/*
1801 * atl1c_clean - NAPI Rx polling callback
1802 * @adapter: board private structure
1803 */
1804static int atl1c_clean(struct napi_struct *napi, int budget)
1805{
1806 struct atl1c_adapter *adapter =
1807 container_of(napi, struct atl1c_adapter, napi);
1808 int work_done = 0;
1809
1810 /* Keep link state information with original netdev */
1811 if (!netif_carrier_ok(adapter->netdev))
1812 goto quit_polling;
1813 /* just enable one RXQ */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001814 atl1c_clean_rx_irq(adapter, &work_done, budget);
Jie Yang43250dd2009-02-18 17:24:15 -08001815
1816 if (work_done < budget) {
1817quit_polling:
1818 napi_complete(napi);
1819 adapter->hw.intr_mask |= ISR_RX_PKT;
1820 AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask);
1821 }
1822 return work_done;
1823}
1824
1825#ifdef CONFIG_NET_POLL_CONTROLLER
1826
1827/*
1828 * Polling 'interrupt' - used by things like netconsole to send skbs
1829 * without having to re-enable interrupts. It's not called while
1830 * the interrupt routine is executing.
1831 */
1832static void atl1c_netpoll(struct net_device *netdev)
1833{
1834 struct atl1c_adapter *adapter = netdev_priv(netdev);
1835
1836 disable_irq(adapter->pdev->irq);
1837 atl1c_intr(adapter->pdev->irq, netdev);
1838 enable_irq(adapter->pdev->irq);
1839}
1840#endif
1841
1842static inline u16 atl1c_tpd_avail(struct atl1c_adapter *adapter, enum atl1c_trans_queue type)
1843{
1844 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
1845 u16 next_to_use = 0;
1846 u16 next_to_clean = 0;
1847
1848 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1849 next_to_use = tpd_ring->next_to_use;
1850
1851 return (u16)(next_to_clean > next_to_use) ?
1852 (next_to_clean - next_to_use - 1) :
1853 (tpd_ring->count + next_to_clean - next_to_use - 1);
1854}
1855
1856/*
1857 * get next usable tpd
1858 * Note: should call atl1c_tdp_avail to make sure
1859 * there is enough tpd to use
1860 */
1861static struct atl1c_tpd_desc *atl1c_get_tpd(struct atl1c_adapter *adapter,
1862 enum atl1c_trans_queue type)
1863{
1864 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
1865 struct atl1c_tpd_desc *tpd_desc;
1866 u16 next_to_use = 0;
1867
1868 next_to_use = tpd_ring->next_to_use;
1869 if (++tpd_ring->next_to_use == tpd_ring->count)
1870 tpd_ring->next_to_use = 0;
1871 tpd_desc = ATL1C_TPD_DESC(tpd_ring, next_to_use);
1872 memset(tpd_desc, 0, sizeof(struct atl1c_tpd_desc));
1873 return tpd_desc;
1874}
1875
1876static struct atl1c_buffer *
1877atl1c_get_tx_buffer(struct atl1c_adapter *adapter, struct atl1c_tpd_desc *tpd)
1878{
1879 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
1880
1881 return &tpd_ring->buffer_info[tpd -
1882 (struct atl1c_tpd_desc *)tpd_ring->desc];
1883}
1884
1885/* Calculate the transmit packet descript needed*/
1886static u16 atl1c_cal_tpd_req(const struct sk_buff *skb)
1887{
1888 u16 tpd_req;
1889 u16 proto_hdr_len = 0;
1890
1891 tpd_req = skb_shinfo(skb)->nr_frags + 1;
1892
1893 if (skb_is_gso(skb)) {
1894 proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1895 if (proto_hdr_len < skb_headlen(skb))
1896 tpd_req++;
1897 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
1898 tpd_req++;
1899 }
1900 return tpd_req;
1901}
1902
1903static int atl1c_tso_csum(struct atl1c_adapter *adapter,
1904 struct sk_buff *skb,
1905 struct atl1c_tpd_desc **tpd,
1906 enum atl1c_trans_queue type)
1907{
1908 struct pci_dev *pdev = adapter->pdev;
1909 u8 hdr_len;
1910 u32 real_len;
1911 unsigned short offload_type;
1912 int err;
1913
1914 if (skb_is_gso(skb)) {
1915 if (skb_header_cloned(skb)) {
1916 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1917 if (unlikely(err))
1918 return -1;
1919 }
1920 offload_type = skb_shinfo(skb)->gso_type;
1921
1922 if (offload_type & SKB_GSO_TCPV4) {
1923 real_len = (((unsigned char *)ip_hdr(skb) - skb->data)
1924 + ntohs(ip_hdr(skb)->tot_len));
1925
1926 if (real_len < skb->len)
1927 pskb_trim(skb, real_len);
1928
1929 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1930 if (unlikely(skb->len == hdr_len)) {
1931 /* only xsum need */
1932 if (netif_msg_tx_queued(adapter))
1933 dev_warn(&pdev->dev,
1934 "IPV4 tso with zero data??\n");
1935 goto check_sum;
1936 } else {
1937 ip_hdr(skb)->check = 0;
1938 tcp_hdr(skb)->check = ~csum_tcpudp_magic(
1939 ip_hdr(skb)->saddr,
1940 ip_hdr(skb)->daddr,
1941 0, IPPROTO_TCP, 0);
1942 (*tpd)->word1 |= 1 << TPD_IPV4_PACKET_SHIFT;
1943 }
1944 }
1945
1946 if (offload_type & SKB_GSO_TCPV6) {
1947 struct atl1c_tpd_ext_desc *etpd =
1948 *(struct atl1c_tpd_ext_desc **)(tpd);
1949
1950 memset(etpd, 0, sizeof(struct atl1c_tpd_ext_desc));
1951 *tpd = atl1c_get_tpd(adapter, type);
1952 ipv6_hdr(skb)->payload_len = 0;
1953 /* check payload == 0 byte ? */
1954 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1955 if (unlikely(skb->len == hdr_len)) {
1956 /* only xsum need */
1957 if (netif_msg_tx_queued(adapter))
1958 dev_warn(&pdev->dev,
1959 "IPV6 tso with zero data??\n");
1960 goto check_sum;
1961 } else
1962 tcp_hdr(skb)->check = ~csum_ipv6_magic(
1963 &ipv6_hdr(skb)->saddr,
1964 &ipv6_hdr(skb)->daddr,
1965 0, IPPROTO_TCP, 0);
1966 etpd->word1 |= 1 << TPD_LSO_EN_SHIFT;
1967 etpd->word1 |= 1 << TPD_LSO_VER_SHIFT;
1968 etpd->pkt_len = cpu_to_le32(skb->len);
1969 (*tpd)->word1 |= 1 << TPD_LSO_VER_SHIFT;
1970 }
1971
1972 (*tpd)->word1 |= 1 << TPD_LSO_EN_SHIFT;
1973 (*tpd)->word1 |= (skb_transport_offset(skb) & TPD_TCPHDR_OFFSET_MASK) <<
1974 TPD_TCPHDR_OFFSET_SHIFT;
1975 (*tpd)->word1 |= (skb_shinfo(skb)->gso_size & TPD_MSS_MASK) <<
1976 TPD_MSS_SHIFT;
1977 return 0;
1978 }
1979
1980check_sum:
1981 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
1982 u8 css, cso;
Michał Mirosław0d0b1672010-12-14 15:24:08 +00001983 cso = skb_checksum_start_offset(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001984
1985 if (unlikely(cso & 0x1)) {
1986 if (netif_msg_tx_err(adapter))
1987 dev_err(&adapter->pdev->dev,
1988 "payload offset should not an event number\n");
1989 return -1;
1990 } else {
1991 css = cso + skb->csum_offset;
1992
1993 (*tpd)->word1 |= ((cso >> 1) & TPD_PLOADOFFSET_MASK) <<
1994 TPD_PLOADOFFSET_SHIFT;
1995 (*tpd)->word1 |= ((css >> 1) & TPD_CCSUM_OFFSET_MASK) <<
1996 TPD_CCSUM_OFFSET_SHIFT;
1997 (*tpd)->word1 |= 1 << TPD_CCSUM_EN_SHIFT;
1998 }
1999 }
2000 return 0;
2001}
2002
2003static void atl1c_tx_map(struct atl1c_adapter *adapter,
2004 struct sk_buff *skb, struct atl1c_tpd_desc *tpd,
2005 enum atl1c_trans_queue type)
2006{
2007 struct atl1c_tpd_desc *use_tpd = NULL;
2008 struct atl1c_buffer *buffer_info = NULL;
2009 u16 buf_len = skb_headlen(skb);
2010 u16 map_len = 0;
2011 u16 mapped_len = 0;
2012 u16 hdr_len = 0;
2013 u16 nr_frags;
2014 u16 f;
2015 int tso;
2016
2017 nr_frags = skb_shinfo(skb)->nr_frags;
2018 tso = (tpd->word1 >> TPD_LSO_EN_SHIFT) & TPD_LSO_EN_MASK;
2019 if (tso) {
2020 /* TSO */
2021 map_len = hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2022 use_tpd = tpd;
2023
2024 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2025 buffer_info->length = map_len;
2026 buffer_info->dma = pci_map_single(adapter->pdev,
2027 skb->data, hdr_len, PCI_DMA_TODEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08002028 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00002029 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
2030 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08002031 mapped_len += map_len;
2032 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2033 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2034 }
2035
2036 if (mapped_len < buf_len) {
2037 /* mapped_len == 0, means we should use the first tpd,
2038 which is given by caller */
2039 if (mapped_len == 0)
2040 use_tpd = tpd;
2041 else {
2042 use_tpd = atl1c_get_tpd(adapter, type);
2043 memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc));
Jie Yang43250dd2009-02-18 17:24:15 -08002044 }
2045 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2046 buffer_info->length = buf_len - mapped_len;
2047 buffer_info->dma =
2048 pci_map_single(adapter->pdev, skb->data + mapped_len,
2049 buffer_info->length, PCI_DMA_TODEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08002050 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00002051 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
2052 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08002053 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2054 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2055 }
2056
2057 for (f = 0; f < nr_frags; f++) {
2058 struct skb_frag_struct *frag;
2059
2060 frag = &skb_shinfo(skb)->frags[f];
2061
2062 use_tpd = atl1c_get_tpd(adapter, type);
2063 memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc));
2064
2065 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002066 buffer_info->length = skb_frag_size(frag);
Ian Campbell8d1bb862011-08-29 23:18:20 +00002067 buffer_info->dma = skb_frag_dma_map(&adapter->pdev->dev,
2068 frag, 0,
2069 buffer_info->length,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002070 DMA_TO_DEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08002071 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00002072 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_PAGE,
2073 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08002074 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2075 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2076 }
2077
2078 /* The last tpd */
2079 use_tpd->word1 |= 1 << TPD_EOP_SHIFT;
2080 /* The last buffer info contain the skb address,
2081 so it will be free after unmap */
2082 buffer_info->skb = skb;
2083}
2084
2085static void atl1c_tx_queue(struct atl1c_adapter *adapter, struct sk_buff *skb,
2086 struct atl1c_tpd_desc *tpd, enum atl1c_trans_queue type)
2087{
2088 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
Huang, Xiong0af48332012-04-17 19:32:30 +00002089 u16 reg;
Jie Yang43250dd2009-02-18 17:24:15 -08002090
Huang, Xiong0af48332012-04-17 19:32:30 +00002091 reg = type == atl1c_trans_high ? REG_TPD_PRI1_PIDX : REG_TPD_PRI0_PIDX;
2092 AT_WRITE_REGW(&adapter->hw, reg, tpd_ring->next_to_use);
Jie Yang43250dd2009-02-18 17:24:15 -08002093}
2094
Stephen Hemminger613573252009-08-31 19:50:58 +00002095static netdev_tx_t atl1c_xmit_frame(struct sk_buff *skb,
2096 struct net_device *netdev)
Jie Yang43250dd2009-02-18 17:24:15 -08002097{
2098 struct atl1c_adapter *adapter = netdev_priv(netdev);
2099 unsigned long flags;
2100 u16 tpd_req = 1;
2101 struct atl1c_tpd_desc *tpd;
2102 enum atl1c_trans_queue type = atl1c_trans_normal;
2103
2104 if (test_bit(__AT_DOWN, &adapter->flags)) {
2105 dev_kfree_skb_any(skb);
2106 return NETDEV_TX_OK;
2107 }
2108
2109 tpd_req = atl1c_cal_tpd_req(skb);
2110 if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
2111 if (netif_msg_pktdata(adapter))
2112 dev_info(&adapter->pdev->dev, "tx locked\n");
2113 return NETDEV_TX_LOCKED;
2114 }
Jie Yang43250dd2009-02-18 17:24:15 -08002115
2116 if (atl1c_tpd_avail(adapter, type) < tpd_req) {
2117 /* no enough descriptor, just stop queue */
2118 netif_stop_queue(netdev);
2119 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2120 return NETDEV_TX_BUSY;
2121 }
2122
2123 tpd = atl1c_get_tpd(adapter, type);
2124
2125 /* do TSO and check sum */
2126 if (atl1c_tso_csum(adapter, skb, &tpd, type) != 0) {
2127 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2128 dev_kfree_skb_any(skb);
2129 return NETDEV_TX_OK;
2130 }
2131
Jesse Grosseab6d182010-10-20 13:56:03 +00002132 if (unlikely(vlan_tx_tag_present(skb))) {
Jie Yang43250dd2009-02-18 17:24:15 -08002133 u16 vlan = vlan_tx_tag_get(skb);
2134 __le16 tag;
2135
2136 vlan = cpu_to_le16(vlan);
2137 AT_VLAN_TO_TAG(vlan, tag);
2138 tpd->word1 |= 1 << TPD_INS_VTAG_SHIFT;
2139 tpd->vlan_tag = tag;
2140 }
2141
2142 if (skb_network_offset(skb) != ETH_HLEN)
2143 tpd->word1 |= 1 << TPD_ETH_TYPE_SHIFT; /* Ethernet frame */
2144
2145 atl1c_tx_map(adapter, skb, tpd, type);
2146 atl1c_tx_queue(adapter, skb, tpd, type);
2147
Jie Yang43250dd2009-02-18 17:24:15 -08002148 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2149 return NETDEV_TX_OK;
2150}
2151
2152static void atl1c_free_irq(struct atl1c_adapter *adapter)
2153{
2154 struct net_device *netdev = adapter->netdev;
2155
2156 free_irq(adapter->pdev->irq, netdev);
2157
2158 if (adapter->have_msi)
2159 pci_disable_msi(adapter->pdev);
2160}
2161
2162static int atl1c_request_irq(struct atl1c_adapter *adapter)
2163{
2164 struct pci_dev *pdev = adapter->pdev;
2165 struct net_device *netdev = adapter->netdev;
2166 int flags = 0;
2167 int err = 0;
2168
2169 adapter->have_msi = true;
2170 err = pci_enable_msi(adapter->pdev);
2171 if (err) {
2172 if (netif_msg_ifup(adapter))
2173 dev_err(&pdev->dev,
2174 "Unable to allocate MSI interrupt Error: %d\n",
2175 err);
2176 adapter->have_msi = false;
Francois Romieu93f7fab2012-03-09 19:22:31 +01002177 }
Jie Yang43250dd2009-02-18 17:24:15 -08002178
2179 if (!adapter->have_msi)
2180 flags |= IRQF_SHARED;
Julia Lawall9aff7e92009-11-18 10:47:03 -08002181 err = request_irq(adapter->pdev->irq, atl1c_intr, flags,
Jie Yang43250dd2009-02-18 17:24:15 -08002182 netdev->name, netdev);
2183 if (err) {
2184 if (netif_msg_ifup(adapter))
2185 dev_err(&pdev->dev,
2186 "Unable to allocate interrupt Error: %d\n",
2187 err);
2188 if (adapter->have_msi)
2189 pci_disable_msi(adapter->pdev);
2190 return err;
2191 }
2192 if (netif_msg_ifup(adapter))
2193 dev_dbg(&pdev->dev, "atl1c_request_irq OK\n");
2194 return err;
2195}
2196
stephen hemminger0fb1e542010-10-21 07:50:49 +00002197static int atl1c_up(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08002198{
2199 struct net_device *netdev = adapter->netdev;
2200 int num;
2201 int err;
Jie Yang43250dd2009-02-18 17:24:15 -08002202
2203 netif_carrier_off(netdev);
2204 atl1c_init_ring_ptrs(adapter);
2205 atl1c_set_multi(netdev);
2206 atl1c_restore_vlan(adapter);
2207
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00002208 num = atl1c_alloc_rx_buffer(adapter);
2209 if (unlikely(num == 0)) {
2210 err = -ENOMEM;
2211 goto err_alloc_rx;
Jie Yang43250dd2009-02-18 17:24:15 -08002212 }
2213
2214 if (atl1c_configure(adapter)) {
2215 err = -EIO;
2216 goto err_up;
2217 }
2218
2219 err = atl1c_request_irq(adapter);
2220 if (unlikely(err))
2221 goto err_up;
2222
2223 clear_bit(__AT_DOWN, &adapter->flags);
2224 napi_enable(&adapter->napi);
2225 atl1c_irq_enable(adapter);
2226 atl1c_check_link_status(adapter);
2227 netif_start_queue(netdev);
2228 return err;
2229
2230err_up:
2231err_alloc_rx:
2232 atl1c_clean_rx_ring(adapter);
2233 return err;
2234}
2235
stephen hemminger0fb1e542010-10-21 07:50:49 +00002236static void atl1c_down(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08002237{
2238 struct net_device *netdev = adapter->netdev;
2239
2240 atl1c_del_timer(adapter);
Jie Yangcb190542009-12-06 23:16:58 +00002241 adapter->work_event = 0; /* clear all event */
Jie Yang43250dd2009-02-18 17:24:15 -08002242 /* signal that we're down so the interrupt handler does not
2243 * reschedule our watchdog timer */
2244 set_bit(__AT_DOWN, &adapter->flags);
2245 netif_carrier_off(netdev);
2246 napi_disable(&adapter->napi);
2247 atl1c_irq_disable(adapter);
2248 atl1c_free_irq(adapter);
Huang, Xiong024e1e42012-04-18 22:01:28 +00002249 /* disable ASPM if device inactive */
2250 atl1c_disable_l0s_l1(&adapter->hw);
Jie Yang43250dd2009-02-18 17:24:15 -08002251 /* reset MAC to disable all RX/TX */
2252 atl1c_reset_mac(&adapter->hw);
2253 msleep(1);
2254
2255 adapter->link_speed = SPEED_0;
2256 adapter->link_duplex = -1;
2257 atl1c_clean_tx_ring(adapter, atl1c_trans_normal);
2258 atl1c_clean_tx_ring(adapter, atl1c_trans_high);
2259 atl1c_clean_rx_ring(adapter);
2260}
2261
2262/*
2263 * atl1c_open - Called when a network interface is made active
2264 * @netdev: network interface device structure
2265 *
2266 * Returns 0 on success, negative value on failure
2267 *
2268 * The open entry point is called when a network interface is made
2269 * active by the system (IFF_UP). At this point all resources needed
2270 * for transmit and receive operations are allocated, the interrupt
2271 * handler is registered with the OS, the watchdog timer is started,
2272 * and the stack is notified that the interface is ready.
2273 */
2274static int atl1c_open(struct net_device *netdev)
2275{
2276 struct atl1c_adapter *adapter = netdev_priv(netdev);
2277 int err;
2278
2279 /* disallow open during test */
2280 if (test_bit(__AT_TESTING, &adapter->flags))
2281 return -EBUSY;
2282
2283 /* allocate rx/tx dma buffer & descriptors */
2284 err = atl1c_setup_ring_resources(adapter);
2285 if (unlikely(err))
2286 return err;
2287
2288 err = atl1c_up(adapter);
2289 if (unlikely(err))
2290 goto err_up;
2291
Jie Yang43250dd2009-02-18 17:24:15 -08002292 return 0;
2293
2294err_up:
2295 atl1c_free_irq(adapter);
2296 atl1c_free_ring_resources(adapter);
2297 atl1c_reset_mac(&adapter->hw);
2298 return err;
2299}
2300
2301/*
2302 * atl1c_close - Disables a network interface
2303 * @netdev: network interface device structure
2304 *
2305 * Returns 0, this is not allowed to fail
2306 *
2307 * The close entry point is called when an interface is de-activated
2308 * by the OS. The hardware is still under the drivers control, but
2309 * needs to be disabled. A global MAC reset is issued to stop the
2310 * hardware, and all transmit and receive resources are freed.
2311 */
2312static int atl1c_close(struct net_device *netdev)
2313{
2314 struct atl1c_adapter *adapter = netdev_priv(netdev);
2315
2316 WARN_ON(test_bit(__AT_RESETTING, &adapter->flags));
Huang, Xiong0aa76ce2012-04-30 15:38:55 +00002317 set_bit(__AT_DOWN, &adapter->flags);
2318 cancel_work_sync(&adapter->common_task);
Jie Yang43250dd2009-02-18 17:24:15 -08002319 atl1c_down(adapter);
2320 atl1c_free_ring_resources(adapter);
2321 return 0;
2322}
2323
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002324static int atl1c_suspend(struct device *dev)
Jie Yang43250dd2009-02-18 17:24:15 -08002325{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002326 struct pci_dev *pdev = to_pci_dev(dev);
Jie Yang43250dd2009-02-18 17:24:15 -08002327 struct net_device *netdev = pci_get_drvdata(pdev);
2328 struct atl1c_adapter *adapter = netdev_priv(netdev);
2329 struct atl1c_hw *hw = &adapter->hw;
Jie Yang43250dd2009-02-18 17:24:15 -08002330 u32 wufc = adapter->wol;
Jie Yang43250dd2009-02-18 17:24:15 -08002331
Jie Yang8f574b32010-06-01 00:28:12 -07002332 atl1c_disable_l0s_l1(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08002333 if (netif_running(netdev)) {
2334 WARN_ON(test_bit(__AT_RESETTING, &adapter->flags));
2335 atl1c_down(adapter);
2336 }
2337 netif_device_detach(netdev);
Jie Yang43250dd2009-02-18 17:24:15 -08002338
Jie Yang8f574b32010-06-01 00:28:12 -07002339 if (wufc)
Huang, Xiong319d0132012-04-25 20:40:59 +00002340 if (atl1c_phy_to_ps_link(hw) != 0)
Jie Yang8f574b32010-06-01 00:28:12 -07002341 dev_dbg(&pdev->dev, "phy power saving failed");
2342
Huang, Xiong319d0132012-04-25 20:40:59 +00002343 atl1c_power_saving(hw, wufc);
Huang, Xiongce5b9722012-04-25 20:27:14 +00002344
Jie Yang43250dd2009-02-18 17:24:15 -08002345 return 0;
2346}
2347
David S. Millerd187c1a2011-05-19 18:44:41 -04002348#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002349static int atl1c_resume(struct device *dev)
Jie Yang43250dd2009-02-18 17:24:15 -08002350{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002351 struct pci_dev *pdev = to_pci_dev(dev);
Jie Yang43250dd2009-02-18 17:24:15 -08002352 struct net_device *netdev = pci_get_drvdata(pdev);
2353 struct atl1c_adapter *adapter = netdev_priv(netdev);
2354
Jie Yang43250dd2009-02-18 17:24:15 -08002355 AT_WRITE_REG(&adapter->hw, REG_WOL_CTRL, 0);
Huang, Xiongce3ba0c2012-04-25 20:27:11 +00002356 atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE);
Jie Yang43250dd2009-02-18 17:24:15 -08002357
2358 atl1c_phy_reset(&adapter->hw);
2359 atl1c_reset_mac(&adapter->hw);
Jie Yang8f574b32010-06-01 00:28:12 -07002360 atl1c_phy_init(&adapter->hw);
2361
2362#if 0
2363 AT_READ_REG(&adapter->hw, REG_PM_CTRLSTAT, &pm_data);
2364 pm_data &= ~PM_CTRLSTAT_PME_EN;
2365 AT_WRITE_REG(&adapter->hw, REG_PM_CTRLSTAT, pm_data);
2366#endif
2367
Jie Yang43250dd2009-02-18 17:24:15 -08002368 netif_device_attach(netdev);
2369 if (netif_running(netdev))
2370 atl1c_up(adapter);
2371
2372 return 0;
2373}
David S. Millerd187c1a2011-05-19 18:44:41 -04002374#endif
Jie Yang43250dd2009-02-18 17:24:15 -08002375
2376static void atl1c_shutdown(struct pci_dev *pdev)
2377{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002378 struct net_device *netdev = pci_get_drvdata(pdev);
2379 struct atl1c_adapter *adapter = netdev_priv(netdev);
2380
2381 atl1c_suspend(&pdev->dev);
2382 pci_wake_from_d3(pdev, adapter->wol);
2383 pci_set_power_state(pdev, PCI_D3hot);
Jie Yang43250dd2009-02-18 17:24:15 -08002384}
2385
2386static const struct net_device_ops atl1c_netdev_ops = {
2387 .ndo_open = atl1c_open,
2388 .ndo_stop = atl1c_close,
2389 .ndo_validate_addr = eth_validate_addr,
2390 .ndo_start_xmit = atl1c_xmit_frame,
Jiri Pirko46facce2011-07-20 04:54:12 +00002391 .ndo_set_mac_address = atl1c_set_mac_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002392 .ndo_set_rx_mode = atl1c_set_multi,
Jie Yang43250dd2009-02-18 17:24:15 -08002393 .ndo_change_mtu = atl1c_change_mtu,
Michał Mirosław782d6402011-04-07 07:32:18 +00002394 .ndo_fix_features = atl1c_fix_features,
Jiri Pirko46facce2011-07-20 04:54:12 +00002395 .ndo_set_features = atl1c_set_features,
Jie Yang43250dd2009-02-18 17:24:15 -08002396 .ndo_do_ioctl = atl1c_ioctl,
2397 .ndo_tx_timeout = atl1c_tx_timeout,
2398 .ndo_get_stats = atl1c_get_stats,
Jie Yang43250dd2009-02-18 17:24:15 -08002399#ifdef CONFIG_NET_POLL_CONTROLLER
2400 .ndo_poll_controller = atl1c_netpoll,
2401#endif
2402};
2403
2404static int atl1c_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
2405{
2406 SET_NETDEV_DEV(netdev, &pdev->dev);
2407 pci_set_drvdata(pdev, netdev);
2408
Jie Yang43250dd2009-02-18 17:24:15 -08002409 netdev->netdev_ops = &atl1c_netdev_ops;
2410 netdev->watchdog_timeo = AT_TX_WATCHDOG;
2411 atl1c_set_ethtool_ops(netdev);
2412
2413 /* TODO: add when ready */
Michał Mirosław782d6402011-04-07 07:32:18 +00002414 netdev->hw_features = NETIF_F_SG |
Jie Yang43250dd2009-02-18 17:24:15 -08002415 NETIF_F_HW_CSUM |
Jiri Pirko46facce2011-07-20 04:54:12 +00002416 NETIF_F_HW_VLAN_RX |
Jie Yang43250dd2009-02-18 17:24:15 -08002417 NETIF_F_TSO |
2418 NETIF_F_TSO6;
Michał Mirosław782d6402011-04-07 07:32:18 +00002419 netdev->features = netdev->hw_features |
Jiri Pirko46facce2011-07-20 04:54:12 +00002420 NETIF_F_HW_VLAN_TX;
Jie Yang43250dd2009-02-18 17:24:15 -08002421 return 0;
2422}
2423
2424/*
2425 * atl1c_probe - Device Initialization Routine
2426 * @pdev: PCI device information struct
2427 * @ent: entry in atl1c_pci_tbl
2428 *
2429 * Returns 0 on success, negative on failure
2430 *
2431 * atl1c_probe initializes an adapter identified by a pci_dev structure.
2432 * The OS initialization, configuring of the adapter private structure,
2433 * and a hardware reset occur.
2434 */
2435static int __devinit atl1c_probe(struct pci_dev *pdev,
2436 const struct pci_device_id *ent)
2437{
2438 struct net_device *netdev;
2439 struct atl1c_adapter *adapter;
2440 static int cards_found;
2441
2442 int err = 0;
2443
2444 /* enable device (incl. PCI PM wakeup and hotplug setup) */
2445 err = pci_enable_device_mem(pdev);
2446 if (err) {
2447 dev_err(&pdev->dev, "cannot enable PCI device\n");
2448 return err;
2449 }
2450
2451 /*
2452 * The atl1c chip can DMA to 64-bit addresses, but it uses a single
2453 * shared register for the high 32 bits, so only a single, aligned,
2454 * 4 GB physical address range can be used at a time.
2455 *
2456 * Supporting 64-bit DMA on this hardware is more trouble than it's
2457 * worth. It is far easier to limit to 32-bit DMA than update
2458 * various kernel subsystems to support the mechanics required by a
2459 * fixed-high-32-bit system.
2460 */
Yang Hongyange9304382009-04-13 14:40:14 -07002461 if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
2462 (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
Jie Yang43250dd2009-02-18 17:24:15 -08002463 dev_err(&pdev->dev, "No usable DMA configuration,aborting\n");
2464 goto err_dma;
2465 }
2466
2467 err = pci_request_regions(pdev, atl1c_driver_name);
2468 if (err) {
2469 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
2470 goto err_pci_reg;
2471 }
2472
2473 pci_set_master(pdev);
2474
2475 netdev = alloc_etherdev(sizeof(struct atl1c_adapter));
2476 if (netdev == NULL) {
2477 err = -ENOMEM;
Jie Yang43250dd2009-02-18 17:24:15 -08002478 goto err_alloc_etherdev;
2479 }
2480
2481 err = atl1c_init_netdev(netdev, pdev);
2482 if (err) {
2483 dev_err(&pdev->dev, "init netdevice failed\n");
2484 goto err_init_netdev;
2485 }
2486 adapter = netdev_priv(netdev);
2487 adapter->bd_number = cards_found;
2488 adapter->netdev = netdev;
2489 adapter->pdev = pdev;
2490 adapter->hw.adapter = adapter;
2491 adapter->msg_enable = netif_msg_init(-1, atl1c_default_msg);
2492 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
2493 if (!adapter->hw.hw_addr) {
2494 err = -EIO;
2495 dev_err(&pdev->dev, "cannot map device registers\n");
2496 goto err_ioremap;
2497 }
Jie Yang43250dd2009-02-18 17:24:15 -08002498
2499 /* init mii data */
2500 adapter->mii.dev = netdev;
2501 adapter->mii.mdio_read = atl1c_mdio_read;
2502 adapter->mii.mdio_write = atl1c_mdio_write;
2503 adapter->mii.phy_id_mask = 0x1f;
Huang, Xiong929a5e92012-04-25 20:27:10 +00002504 adapter->mii.reg_num_mask = MDIO_CTRL_REG_MASK;
Jie Yang43250dd2009-02-18 17:24:15 -08002505 netif_napi_add(netdev, &adapter->napi, atl1c_clean, 64);
2506 setup_timer(&adapter->phy_config_timer, atl1c_phy_config,
2507 (unsigned long)adapter);
2508 /* setup the private structure */
2509 err = atl1c_sw_init(adapter);
2510 if (err) {
2511 dev_err(&pdev->dev, "net device private data init failed\n");
2512 goto err_sw_init;
2513 }
Huang, Xiongce3ba0c2012-04-25 20:27:11 +00002514 atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE);
Jie Yang43250dd2009-02-18 17:24:15 -08002515
2516 /* Init GPHY as early as possible due to power saving issue */
2517 atl1c_phy_reset(&adapter->hw);
2518
2519 err = atl1c_reset_mac(&adapter->hw);
2520 if (err) {
2521 err = -EIO;
2522 goto err_reset;
2523 }
2524
Jie Yang43250dd2009-02-18 17:24:15 -08002525 /* reset the controller to
2526 * put the device in a known good starting state */
2527 err = atl1c_phy_init(&adapter->hw);
2528 if (err) {
2529 err = -EIO;
2530 goto err_reset;
2531 }
Danny Kukawka6a214fd2012-02-17 05:43:30 +00002532 if (atl1c_read_mac_addr(&adapter->hw)) {
2533 /* got a random MAC address, set NET_ADDR_RANDOM to netdev */
2534 netdev->addr_assign_type |= NET_ADDR_RANDOM;
Jie Yang43250dd2009-02-18 17:24:15 -08002535 }
2536 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
2537 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
2538 if (netif_msg_probe(adapter))
hartleys82991172010-01-05 06:54:01 +00002539 dev_dbg(&pdev->dev, "mac address : %pM\n",
2540 adapter->hw.mac_addr);
Jie Yang43250dd2009-02-18 17:24:15 -08002541
Huang, Xiong229e6b62012-04-30 15:38:53 +00002542 atl1c_hw_set_mac_addr(&adapter->hw, adapter->hw.mac_addr);
Jie Yangcb190542009-12-06 23:16:58 +00002543 INIT_WORK(&adapter->common_task, atl1c_common_task);
2544 adapter->work_event = 0;
Jie Yang43250dd2009-02-18 17:24:15 -08002545 err = register_netdev(netdev);
2546 if (err) {
2547 dev_err(&pdev->dev, "register netdevice failed\n");
2548 goto err_register;
2549 }
2550
2551 if (netif_msg_probe(adapter))
2552 dev_info(&pdev->dev, "version %s\n", ATL1C_DRV_VERSION);
2553 cards_found++;
2554 return 0;
2555
2556err_reset:
2557err_register:
2558err_sw_init:
Jie Yang43250dd2009-02-18 17:24:15 -08002559 iounmap(adapter->hw.hw_addr);
2560err_init_netdev:
2561err_ioremap:
2562 free_netdev(netdev);
2563err_alloc_etherdev:
2564 pci_release_regions(pdev);
2565err_pci_reg:
2566err_dma:
2567 pci_disable_device(pdev);
2568 return err;
2569}
2570
2571/*
2572 * atl1c_remove - Device Removal Routine
2573 * @pdev: PCI device information struct
2574 *
2575 * atl1c_remove is called by the PCI subsystem to alert the driver
2576 * that it should release a PCI device. The could be caused by a
2577 * Hot-Plug event, or because the driver is going to be removed from
2578 * memory.
2579 */
2580static void __devexit atl1c_remove(struct pci_dev *pdev)
2581{
2582 struct net_device *netdev = pci_get_drvdata(pdev);
2583 struct atl1c_adapter *adapter = netdev_priv(netdev);
2584
2585 unregister_netdev(netdev);
Huang, Xiong229e6b62012-04-30 15:38:53 +00002586 /* restore permanent address */
2587 atl1c_hw_set_mac_addr(&adapter->hw, adapter->hw.perm_mac_addr);
Jie Yang43250dd2009-02-18 17:24:15 -08002588 atl1c_phy_disable(&adapter->hw);
2589
2590 iounmap(adapter->hw.hw_addr);
2591
2592 pci_release_regions(pdev);
2593 pci_disable_device(pdev);
2594 free_netdev(netdev);
2595}
2596
2597/*
2598 * atl1c_io_error_detected - called when PCI error is detected
2599 * @pdev: Pointer to PCI device
2600 * @state: The current pci connection state
2601 *
2602 * This function is called after a PCI bus error affecting
2603 * this device has been detected.
2604 */
2605static pci_ers_result_t atl1c_io_error_detected(struct pci_dev *pdev,
2606 pci_channel_state_t state)
2607{
2608 struct net_device *netdev = pci_get_drvdata(pdev);
2609 struct atl1c_adapter *adapter = netdev_priv(netdev);
2610
2611 netif_device_detach(netdev);
2612
Dean Nelson005fb4f2009-07-31 09:13:02 +00002613 if (state == pci_channel_io_perm_failure)
2614 return PCI_ERS_RESULT_DISCONNECT;
2615
Jie Yang43250dd2009-02-18 17:24:15 -08002616 if (netif_running(netdev))
2617 atl1c_down(adapter);
2618
2619 pci_disable_device(pdev);
2620
2621 /* Request a slot slot reset. */
2622 return PCI_ERS_RESULT_NEED_RESET;
2623}
2624
2625/*
2626 * atl1c_io_slot_reset - called after the pci bus has been reset.
2627 * @pdev: Pointer to PCI device
2628 *
2629 * Restart the card from scratch, as if from a cold-boot. Implementation
2630 * resembles the first-half of the e1000_resume routine.
2631 */
2632static pci_ers_result_t atl1c_io_slot_reset(struct pci_dev *pdev)
2633{
2634 struct net_device *netdev = pci_get_drvdata(pdev);
2635 struct atl1c_adapter *adapter = netdev_priv(netdev);
2636
2637 if (pci_enable_device(pdev)) {
2638 if (netif_msg_hw(adapter))
2639 dev_err(&pdev->dev,
2640 "Cannot re-enable PCI device after reset\n");
2641 return PCI_ERS_RESULT_DISCONNECT;
2642 }
2643 pci_set_master(pdev);
2644
2645 pci_enable_wake(pdev, PCI_D3hot, 0);
2646 pci_enable_wake(pdev, PCI_D3cold, 0);
2647
2648 atl1c_reset_mac(&adapter->hw);
2649
2650 return PCI_ERS_RESULT_RECOVERED;
2651}
2652
2653/*
2654 * atl1c_io_resume - called when traffic can start flowing again.
2655 * @pdev: Pointer to PCI device
2656 *
2657 * This callback is called when the error recovery driver tells us that
2658 * its OK to resume normal operation. Implementation resembles the
2659 * second-half of the atl1c_resume routine.
2660 */
2661static void atl1c_io_resume(struct pci_dev *pdev)
2662{
2663 struct net_device *netdev = pci_get_drvdata(pdev);
2664 struct atl1c_adapter *adapter = netdev_priv(netdev);
2665
2666 if (netif_running(netdev)) {
2667 if (atl1c_up(adapter)) {
2668 if (netif_msg_hw(adapter))
2669 dev_err(&pdev->dev,
2670 "Cannot bring device back up after reset\n");
2671 return;
2672 }
2673 }
2674
2675 netif_device_attach(netdev);
2676}
2677
2678static struct pci_error_handlers atl1c_err_handler = {
2679 .error_detected = atl1c_io_error_detected,
2680 .slot_reset = atl1c_io_slot_reset,
2681 .resume = atl1c_io_resume,
2682};
2683
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002684static SIMPLE_DEV_PM_OPS(atl1c_pm_ops, atl1c_suspend, atl1c_resume);
2685
Jie Yang43250dd2009-02-18 17:24:15 -08002686static struct pci_driver atl1c_driver = {
2687 .name = atl1c_driver_name,
2688 .id_table = atl1c_pci_tbl,
2689 .probe = atl1c_probe,
2690 .remove = __devexit_p(atl1c_remove),
Jie Yang43250dd2009-02-18 17:24:15 -08002691 .shutdown = atl1c_shutdown,
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002692 .err_handler = &atl1c_err_handler,
2693 .driver.pm = &atl1c_pm_ops,
Jie Yang43250dd2009-02-18 17:24:15 -08002694};
2695
2696/*
2697 * atl1c_init_module - Driver Registration Routine
2698 *
2699 * atl1c_init_module is the first routine called when the driver is
2700 * loaded. All it does is register with the PCI subsystem.
2701 */
2702static int __init atl1c_init_module(void)
2703{
2704 return pci_register_driver(&atl1c_driver);
2705}
2706
2707/*
2708 * atl1c_exit_module - Driver Exit Cleanup Routine
2709 *
2710 * atl1c_exit_module is called just before the driver is removed
2711 * from memory.
2712 */
2713static void __exit atl1c_exit_module(void)
2714{
2715 pci_unregister_driver(&atl1c_driver);
2716}
2717
2718module_init(atl1c_init_module);
2719module_exit(atl1c_exit_module);