blob: 2458e4c8b8d933de81941dac37ceab427d6db15e [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;
27#define PCI_DEVICE_ID_ATTANSIC_L2C 0x1062
28#define PCI_DEVICE_ID_ATTANSIC_L1C 0x1063
Luis R. Rodriguez496c1852010-02-16 15:16:45 -080029#define PCI_DEVICE_ID_ATHEROS_L2C_B 0x2060 /* AR8152 v1.1 Fast 10/100 */
30#define PCI_DEVICE_ID_ATHEROS_L2C_B2 0x2062 /* AR8152 v2.0 Fast 10/100 */
31#define PCI_DEVICE_ID_ATHEROS_L1D 0x1073 /* AR8151 v1.0 Gigabit 1000 */
Jie Yang8f574b32010-06-01 00:28:12 -070032#define PCI_DEVICE_ID_ATHEROS_L1D_2_0 0x1083 /* AR8151 v2.0 Gigabit 1000 */
Luis R. Rodriguez496c1852010-02-16 15:16:45 -080033#define L2CB_V10 0xc0
34#define L2CB_V11 0xc1
35
Jie Yang43250dd2009-02-18 17:24:15 -080036/*
37 * atl1c_pci_tbl - PCI Device ID Table
38 *
39 * Wildcard entries (PCI_ANY_ID) should come last
40 * Last entry must be all 0s
41 *
42 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
43 * Class, Class Mask, private data (not used) }
44 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000045static DEFINE_PCI_DEVICE_TABLE(atl1c_pci_tbl) = {
Jie Yang43250dd2009-02-18 17:24:15 -080046 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1C)},
47 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L2C)},
Luis R. Rodriguez496c1852010-02-16 15:16:45 -080048 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B)},
49 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L2C_B2)},
50 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D)},
Chuck Ebbert94dde7e2011-02-02 15:02:08 -080051 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATHEROS_L1D_2_0)},
Jie Yang43250dd2009-02-18 17:24:15 -080052 /* required last entry */
53 { 0 }
54};
55MODULE_DEVICE_TABLE(pci, atl1c_pci_tbl);
56
Huang, Xiong70c9fbd2012-04-17 19:32:25 +000057MODULE_AUTHOR("Jie Yang");
58MODULE_AUTHOR("Qualcomm Atheros Inc., <nic-devel@qualcomm.com>");
59MODULE_DESCRIPTION("Qualcom Atheros 100/1000M Ethernet Network Driver");
Jie Yang43250dd2009-02-18 17:24:15 -080060MODULE_LICENSE("GPL");
61MODULE_VERSION(ATL1C_DRV_VERSION);
62
63static int atl1c_stop_mac(struct atl1c_hw *hw);
64static void atl1c_enable_rx_ctrl(struct atl1c_hw *hw);
65static void atl1c_enable_tx_ctrl(struct atl1c_hw *hw);
66static void atl1c_disable_l0s_l1(struct atl1c_hw *hw);
67static void atl1c_set_aspm(struct atl1c_hw *hw, bool linkup);
68static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter);
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +000069static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter,
Jie Yang43250dd2009-02-18 17:24:15 -080070 int *work_done, int work_to_do);
stephen hemminger0fb1e542010-10-21 07:50:49 +000071static int atl1c_up(struct atl1c_adapter *adapter);
72static void atl1c_down(struct atl1c_adapter *adapter);
Jie Yang43250dd2009-02-18 17:24:15 -080073
74static const u16 atl1c_pay_load_size[] = {
75 128, 256, 512, 1024, 2048, 4096,
76};
77
Jie Yang43250dd2009-02-18 17:24:15 -080078
79static const u32 atl1c_default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
80 NETIF_MSG_LINK | NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP;
Jie Yang8f574b32010-06-01 00:28:12 -070081static void atl1c_pcie_patch(struct atl1c_hw *hw)
82{
83 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -080084
Jie Yang8f574b32010-06-01 00:28:12 -070085 AT_READ_REG(hw, REG_PCIE_PHYMISC, &data);
86 data |= PCIE_PHYMISC_FORCE_RCV_DET;
87 AT_WRITE_REG(hw, REG_PCIE_PHYMISC, data);
88
89 if (hw->nic_type == athr_l2c_b && hw->revision_id == L2CB_V10) {
90 AT_READ_REG(hw, REG_PCIE_PHYMISC2, &data);
91
92 data &= ~(PCIE_PHYMISC2_SERDES_CDR_MASK <<
93 PCIE_PHYMISC2_SERDES_CDR_SHIFT);
94 data |= 3 << PCIE_PHYMISC2_SERDES_CDR_SHIFT;
95 data &= ~(PCIE_PHYMISC2_SERDES_TH_MASK <<
96 PCIE_PHYMISC2_SERDES_TH_SHIFT);
97 data |= 3 << PCIE_PHYMISC2_SERDES_TH_SHIFT;
98 AT_WRITE_REG(hw, REG_PCIE_PHYMISC2, data);
99 }
100}
101
102/* FIXME: no need any more ? */
Jie Yang43250dd2009-02-18 17:24:15 -0800103/*
104 * atl1c_init_pcie - init PCIE module
105 */
106static void atl1c_reset_pcie(struct atl1c_hw *hw, u32 flag)
107{
108 u32 data;
109 u32 pci_cmd;
110 struct pci_dev *pdev = hw->adapter->pdev;
111
112 AT_READ_REG(hw, PCI_COMMAND, &pci_cmd);
113 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
114 pci_cmd |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
115 PCI_COMMAND_IO);
116 AT_WRITE_REG(hw, PCI_COMMAND, pci_cmd);
117
118 /*
119 * Clear any PowerSaveing Settings
120 */
121 pci_enable_wake(pdev, PCI_D3hot, 0);
122 pci_enable_wake(pdev, PCI_D3cold, 0);
123
124 /*
125 * Mask some pcie error bits
126 */
127 AT_READ_REG(hw, REG_PCIE_UC_SEVERITY, &data);
128 data &= ~PCIE_UC_SERVRITY_DLP;
129 data &= ~PCIE_UC_SERVRITY_FCP;
130 AT_WRITE_REG(hw, REG_PCIE_UC_SEVERITY, data);
131
Jie Yang8f574b32010-06-01 00:28:12 -0700132 AT_READ_REG(hw, REG_LTSSM_ID_CTRL, &data);
133 data &= ~LTSSM_ID_EN_WRO;
134 AT_WRITE_REG(hw, REG_LTSSM_ID_CTRL, data);
135
136 atl1c_pcie_patch(hw);
Jie Yang43250dd2009-02-18 17:24:15 -0800137 if (flag & ATL1C_PCIE_L0S_L1_DISABLE)
138 atl1c_disable_l0s_l1(hw);
139 if (flag & ATL1C_PCIE_PHY_RESET)
140 AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT);
141 else
142 AT_WRITE_REG(hw, REG_GPHY_CTRL,
143 GPHY_CTRL_DEFAULT | GPHY_CTRL_EXT_RESET);
144
Jie Yang8f574b32010-06-01 00:28:12 -0700145 msleep(5);
Jie Yang43250dd2009-02-18 17:24:15 -0800146}
147
148/*
149 * atl1c_irq_enable - Enable default interrupt generation settings
150 * @adapter: board private structure
151 */
152static inline void atl1c_irq_enable(struct atl1c_adapter *adapter)
153{
154 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
155 AT_WRITE_REG(&adapter->hw, REG_ISR, 0x7FFFFFFF);
156 AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask);
157 AT_WRITE_FLUSH(&adapter->hw);
158 }
159}
160
161/*
162 * atl1c_irq_disable - Mask off interrupt generation on the NIC
163 * @adapter: board private structure
164 */
165static inline void atl1c_irq_disable(struct atl1c_adapter *adapter)
166{
167 atomic_inc(&adapter->irq_sem);
168 AT_WRITE_REG(&adapter->hw, REG_IMR, 0);
Jie Yang8f574b32010-06-01 00:28:12 -0700169 AT_WRITE_REG(&adapter->hw, REG_ISR, ISR_DIS_INT);
Jie Yang43250dd2009-02-18 17:24:15 -0800170 AT_WRITE_FLUSH(&adapter->hw);
171 synchronize_irq(adapter->pdev->irq);
172}
173
174/*
175 * atl1c_irq_reset - reset interrupt confiure on the NIC
176 * @adapter: board private structure
177 */
178static inline void atl1c_irq_reset(struct atl1c_adapter *adapter)
179{
180 atomic_set(&adapter->irq_sem, 1);
181 atl1c_irq_enable(adapter);
182}
183
184/*
Joe Perchesc930a662009-05-31 20:44:54 +0000185 * atl1c_wait_until_idle - wait up to AT_HW_MAX_IDLE_DELAY reads
186 * of the idle status register until the device is actually idle
187 */
188static u32 atl1c_wait_until_idle(struct atl1c_hw *hw)
189{
190 int timeout;
191 u32 data;
192
193 for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
194 AT_READ_REG(hw, REG_IDLE_STATUS, &data);
195 if ((data & IDLE_STATUS_MASK) == 0)
196 return 0;
197 msleep(1);
198 }
199 return data;
200}
201
202/*
Jie Yang43250dd2009-02-18 17:24:15 -0800203 * atl1c_phy_config - Timer Call-back
204 * @data: pointer to netdev cast into an unsigned long
205 */
206static void atl1c_phy_config(unsigned long data)
207{
208 struct atl1c_adapter *adapter = (struct atl1c_adapter *) data;
209 struct atl1c_hw *hw = &adapter->hw;
210 unsigned long flags;
211
212 spin_lock_irqsave(&adapter->mdio_lock, flags);
213 atl1c_restart_autoneg(hw);
214 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
215}
216
217void atl1c_reinit_locked(struct atl1c_adapter *adapter)
218{
Jie Yang43250dd2009-02-18 17:24:15 -0800219 WARN_ON(in_interrupt());
220 atl1c_down(adapter);
221 atl1c_up(adapter);
222 clear_bit(__AT_RESETTING, &adapter->flags);
223}
224
Jie Yang43250dd2009-02-18 17:24:15 -0800225static void atl1c_check_link_status(struct atl1c_adapter *adapter)
226{
227 struct atl1c_hw *hw = &adapter->hw;
228 struct net_device *netdev = adapter->netdev;
229 struct pci_dev *pdev = adapter->pdev;
230 int err;
231 unsigned long flags;
232 u16 speed, duplex, phy_data;
233
234 spin_lock_irqsave(&adapter->mdio_lock, flags);
235 /* MII_BMSR must read twise */
236 atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
237 atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
238 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
239
240 if ((phy_data & BMSR_LSTATUS) == 0) {
241 /* link down */
Jie Yang8f574b32010-06-01 00:28:12 -0700242 hw->hibernate = true;
243 if (atl1c_stop_mac(hw) != 0)
244 if (netif_msg_hw(adapter))
245 dev_warn(&pdev->dev, "stop mac failed\n");
246 atl1c_set_aspm(hw, false);
Jie Yang43250dd2009-02-18 17:24:15 -0800247 netif_carrier_off(netdev);
Jie Yang8f574b32010-06-01 00:28:12 -0700248 netif_stop_queue(netdev);
249 atl1c_phy_reset(hw);
250 atl1c_phy_init(&adapter->hw);
Jie Yang43250dd2009-02-18 17:24:15 -0800251 } else {
252 /* Link Up */
253 hw->hibernate = false;
254 spin_lock_irqsave(&adapter->mdio_lock, flags);
255 err = atl1c_get_speed_and_duplex(hw, &speed, &duplex);
256 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
257 if (unlikely(err))
258 return;
259 /* link result is our setting */
260 if (adapter->link_speed != speed ||
261 adapter->link_duplex != duplex) {
262 adapter->link_speed = speed;
263 adapter->link_duplex = duplex;
Jie Yang52fbc102009-04-27 19:42:03 +0000264 atl1c_set_aspm(hw, true);
Jie Yang43250dd2009-02-18 17:24:15 -0800265 atl1c_enable_tx_ctrl(hw);
266 atl1c_enable_rx_ctrl(hw);
267 atl1c_setup_mac_ctrl(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -0800268 if (netif_msg_link(adapter))
269 dev_info(&pdev->dev,
270 "%s: %s NIC Link is Up<%d Mbps %s>\n",
271 atl1c_driver_name, netdev->name,
272 adapter->link_speed,
273 adapter->link_duplex == FULL_DUPLEX ?
274 "Full Duplex" : "Half Duplex");
275 }
276 if (!netif_carrier_ok(netdev))
277 netif_carrier_on(netdev);
278 }
279}
280
Jie Yang43250dd2009-02-18 17:24:15 -0800281static void atl1c_link_chg_event(struct atl1c_adapter *adapter)
282{
283 struct net_device *netdev = adapter->netdev;
284 struct pci_dev *pdev = adapter->pdev;
285 u16 phy_data;
286 u16 link_up;
287
288 spin_lock(&adapter->mdio_lock);
289 atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
290 atl1c_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
291 spin_unlock(&adapter->mdio_lock);
292 link_up = phy_data & BMSR_LSTATUS;
293 /* notify upper layer link down ASAP */
294 if (!link_up) {
295 if (netif_carrier_ok(netdev)) {
296 /* old link state: Up */
297 netif_carrier_off(netdev);
298 if (netif_msg_link(adapter))
299 dev_info(&pdev->dev,
300 "%s: %s NIC Link is Down\n",
301 atl1c_driver_name, netdev->name);
302 adapter->link_speed = SPEED_0;
303 }
304 }
Jie Yangcb190542009-12-06 23:16:58 +0000305
Tim Gardnercb771832011-04-20 09:00:49 +0000306 set_bit(ATL1C_WORK_EVENT_LINK_CHANGE, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +0000307 schedule_work(&adapter->common_task);
Jie Yang43250dd2009-02-18 17:24:15 -0800308}
309
Jie Yangcb190542009-12-06 23:16:58 +0000310static void atl1c_common_task(struct work_struct *work)
311{
312 struct atl1c_adapter *adapter;
313 struct net_device *netdev;
314
315 adapter = container_of(work, struct atl1c_adapter, common_task);
316 netdev = adapter->netdev;
317
Tim Gardnercb771832011-04-20 09:00:49 +0000318 if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) {
Jie Yangcb190542009-12-06 23:16:58 +0000319 netif_device_detach(netdev);
320 atl1c_down(adapter);
321 atl1c_up(adapter);
322 netif_device_attach(netdev);
Jie Yangcb190542009-12-06 23:16:58 +0000323 }
324
Tim Gardnercb771832011-04-20 09:00:49 +0000325 if (test_and_clear_bit(ATL1C_WORK_EVENT_LINK_CHANGE,
326 &adapter->work_event))
Jie Yangcb190542009-12-06 23:16:58 +0000327 atl1c_check_link_status(adapter);
Jie Yangcb190542009-12-06 23:16:58 +0000328}
329
330
Jie Yang43250dd2009-02-18 17:24:15 -0800331static void atl1c_del_timer(struct atl1c_adapter *adapter)
332{
333 del_timer_sync(&adapter->phy_config_timer);
334}
335
Jie Yang43250dd2009-02-18 17:24:15 -0800336
337/*
338 * atl1c_tx_timeout - Respond to a Tx Hang
339 * @netdev: network interface device structure
340 */
341static void atl1c_tx_timeout(struct net_device *netdev)
342{
343 struct atl1c_adapter *adapter = netdev_priv(netdev);
344
345 /* Do the reset outside of interrupt context */
Tim Gardnercb771832011-04-20 09:00:49 +0000346 set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +0000347 schedule_work(&adapter->common_task);
Jie Yang43250dd2009-02-18 17:24:15 -0800348}
349
350/*
351 * atl1c_set_multi - Multicast and Promiscuous mode set
352 * @netdev: network interface device structure
353 *
354 * The set_multi entry point is called whenever the multicast address
355 * list or the network interface flags are updated. This routine is
356 * responsible for configuring the hardware for proper multicast,
357 * promiscuous mode, and all-multi behavior.
358 */
359static void atl1c_set_multi(struct net_device *netdev)
360{
361 struct atl1c_adapter *adapter = netdev_priv(netdev);
362 struct atl1c_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000363 struct netdev_hw_addr *ha;
Jie Yang43250dd2009-02-18 17:24:15 -0800364 u32 mac_ctrl_data;
365 u32 hash_value;
366
367 /* Check for Promiscuous and All Multicast modes */
368 AT_READ_REG(hw, REG_MAC_CTRL, &mac_ctrl_data);
369
370 if (netdev->flags & IFF_PROMISC) {
371 mac_ctrl_data |= MAC_CTRL_PROMIS_EN;
372 } else if (netdev->flags & IFF_ALLMULTI) {
373 mac_ctrl_data |= MAC_CTRL_MC_ALL_EN;
374 mac_ctrl_data &= ~MAC_CTRL_PROMIS_EN;
375 } else {
376 mac_ctrl_data &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN);
377 }
378
379 AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data);
380
381 /* clear the old settings from the multicast hash table */
382 AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
383 AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
384
385 /* comoute mc addresses' hash value ,and put it into hash table */
Jiri Pirko22bedad32010-04-01 21:22:57 +0000386 netdev_for_each_mc_addr(ha, netdev) {
387 hash_value = atl1c_hash_mc_addr(hw, ha->addr);
Jie Yang43250dd2009-02-18 17:24:15 -0800388 atl1c_hash_set(hw, hash_value);
389 }
390}
391
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000392static void __atl1c_vlan_mode(netdev_features_t features, u32 *mac_ctrl_data)
Jiri Pirko46facce2011-07-20 04:54:12 +0000393{
394 if (features & NETIF_F_HW_VLAN_RX) {
395 /* enable VLAN tag insert/strip */
396 *mac_ctrl_data |= MAC_CTRL_RMV_VLAN;
397 } else {
398 /* disable VLAN tag insert/strip */
399 *mac_ctrl_data &= ~MAC_CTRL_RMV_VLAN;
400 }
401}
402
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000403static void atl1c_vlan_mode(struct net_device *netdev,
404 netdev_features_t features)
Jie Yang43250dd2009-02-18 17:24:15 -0800405{
406 struct atl1c_adapter *adapter = netdev_priv(netdev);
407 struct pci_dev *pdev = adapter->pdev;
408 u32 mac_ctrl_data = 0;
409
410 if (netif_msg_pktdata(adapter))
Jiri Pirko46facce2011-07-20 04:54:12 +0000411 dev_dbg(&pdev->dev, "atl1c_vlan_mode\n");
Jie Yang43250dd2009-02-18 17:24:15 -0800412
413 atl1c_irq_disable(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -0800414 AT_READ_REG(&adapter->hw, REG_MAC_CTRL, &mac_ctrl_data);
Jiri Pirko46facce2011-07-20 04:54:12 +0000415 __atl1c_vlan_mode(features, &mac_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -0800416 AT_WRITE_REG(&adapter->hw, REG_MAC_CTRL, mac_ctrl_data);
417 atl1c_irq_enable(adapter);
418}
419
420static void atl1c_restore_vlan(struct atl1c_adapter *adapter)
421{
422 struct pci_dev *pdev = adapter->pdev;
423
424 if (netif_msg_pktdata(adapter))
Jiri Pirko46facce2011-07-20 04:54:12 +0000425 dev_dbg(&pdev->dev, "atl1c_restore_vlan\n");
426 atl1c_vlan_mode(adapter->netdev, adapter->netdev->features);
Jie Yang43250dd2009-02-18 17:24:15 -0800427}
Jiri Pirko46facce2011-07-20 04:54:12 +0000428
Jie Yang43250dd2009-02-18 17:24:15 -0800429/*
430 * atl1c_set_mac - Change the Ethernet Address of the NIC
431 * @netdev: network interface device structure
432 * @p: pointer to an address structure
433 *
434 * Returns 0 on success, negative on failure
435 */
436static int atl1c_set_mac_addr(struct net_device *netdev, void *p)
437{
438 struct atl1c_adapter *adapter = netdev_priv(netdev);
439 struct sockaddr *addr = p;
440
441 if (!is_valid_ether_addr(addr->sa_data))
442 return -EADDRNOTAVAIL;
443
444 if (netif_running(netdev))
445 return -EBUSY;
446
447 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
448 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
Danny Kukawka6a214fd2012-02-17 05:43:30 +0000449 netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
Jie Yang43250dd2009-02-18 17:24:15 -0800450
451 atl1c_hw_set_mac_addr(&adapter->hw);
452
453 return 0;
454}
455
456static void atl1c_set_rxbufsize(struct atl1c_adapter *adapter,
457 struct net_device *dev)
458{
459 int mtu = dev->mtu;
460
461 adapter->rx_buffer_len = mtu > AT_RX_BUF_SIZE ?
462 roundup(mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, 8) : AT_RX_BUF_SIZE;
463}
Michał Mirosław782d6402011-04-07 07:32:18 +0000464
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000465static netdev_features_t atl1c_fix_features(struct net_device *netdev,
466 netdev_features_t features)
Michał Mirosław782d6402011-04-07 07:32:18 +0000467{
Jiri Pirko46facce2011-07-20 04:54:12 +0000468 /*
469 * Since there is no support for separate rx/tx vlan accel
470 * enable/disable make sure tx flag is always in same state as rx.
471 */
472 if (features & NETIF_F_HW_VLAN_RX)
473 features |= NETIF_F_HW_VLAN_TX;
474 else
475 features &= ~NETIF_F_HW_VLAN_TX;
476
Michał Mirosław782d6402011-04-07 07:32:18 +0000477 if (netdev->mtu > MAX_TSO_FRAME_SIZE)
478 features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
479
480 return features;
481}
482
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000483static int atl1c_set_features(struct net_device *netdev,
484 netdev_features_t features)
Jiri Pirko46facce2011-07-20 04:54:12 +0000485{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000486 netdev_features_t changed = netdev->features ^ features;
Jiri Pirko46facce2011-07-20 04:54:12 +0000487
488 if (changed & NETIF_F_HW_VLAN_RX)
489 atl1c_vlan_mode(netdev, features);
490
491 return 0;
492}
493
Jie Yang43250dd2009-02-18 17:24:15 -0800494/*
495 * atl1c_change_mtu - Change the Maximum Transfer Unit
496 * @netdev: network interface device structure
497 * @new_mtu: new value for maximum frame size
498 *
499 * Returns 0 on success, negative on failure
500 */
501static int atl1c_change_mtu(struct net_device *netdev, int new_mtu)
502{
503 struct atl1c_adapter *adapter = netdev_priv(netdev);
504 int old_mtu = netdev->mtu;
505 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
506
507 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
508 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
509 if (netif_msg_link(adapter))
510 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
511 return -EINVAL;
512 }
513 /* set MTU */
514 if (old_mtu != new_mtu && netif_running(netdev)) {
515 while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
516 msleep(1);
517 netdev->mtu = new_mtu;
518 adapter->hw.max_frame_size = new_mtu;
519 atl1c_set_rxbufsize(adapter, netdev);
520 atl1c_down(adapter);
Michał Mirosław782d6402011-04-07 07:32:18 +0000521 netdev_update_features(netdev);
Jie Yang43250dd2009-02-18 17:24:15 -0800522 atl1c_up(adapter);
523 clear_bit(__AT_RESETTING, &adapter->flags);
524 if (adapter->hw.ctrl_flags & ATL1C_FPGA_VERSION) {
525 u32 phy_data;
526
527 AT_READ_REG(&adapter->hw, 0x1414, &phy_data);
528 phy_data |= 0x10000000;
529 AT_WRITE_REG(&adapter->hw, 0x1414, phy_data);
530 }
531
532 }
533 return 0;
534}
535
536/*
537 * caller should hold mdio_lock
538 */
539static int atl1c_mdio_read(struct net_device *netdev, int phy_id, int reg_num)
540{
541 struct atl1c_adapter *adapter = netdev_priv(netdev);
542 u16 result;
543
544 atl1c_read_phy_reg(&adapter->hw, reg_num & MDIO_REG_ADDR_MASK, &result);
545 return result;
546}
547
548static void atl1c_mdio_write(struct net_device *netdev, int phy_id,
549 int reg_num, int val)
550{
551 struct atl1c_adapter *adapter = netdev_priv(netdev);
552
553 atl1c_write_phy_reg(&adapter->hw, reg_num & MDIO_REG_ADDR_MASK, val);
554}
555
556/*
557 * atl1c_mii_ioctl -
558 * @netdev:
559 * @ifreq:
560 * @cmd:
561 */
562static int atl1c_mii_ioctl(struct net_device *netdev,
563 struct ifreq *ifr, int cmd)
564{
565 struct atl1c_adapter *adapter = netdev_priv(netdev);
566 struct pci_dev *pdev = adapter->pdev;
567 struct mii_ioctl_data *data = if_mii(ifr);
568 unsigned long flags;
569 int retval = 0;
570
571 if (!netif_running(netdev))
572 return -EINVAL;
573
574 spin_lock_irqsave(&adapter->mdio_lock, flags);
575 switch (cmd) {
576 case SIOCGMIIPHY:
577 data->phy_id = 0;
578 break;
579
580 case SIOCGMIIREG:
Jie Yang43250dd2009-02-18 17:24:15 -0800581 if (atl1c_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
582 &data->val_out)) {
583 retval = -EIO;
584 goto out;
585 }
586 break;
587
588 case SIOCSMIIREG:
Jie Yang43250dd2009-02-18 17:24:15 -0800589 if (data->reg_num & ~(0x1F)) {
590 retval = -EFAULT;
591 goto out;
592 }
593
594 dev_dbg(&pdev->dev, "<atl1c_mii_ioctl> write %x %x",
595 data->reg_num, data->val_in);
596 if (atl1c_write_phy_reg(&adapter->hw,
597 data->reg_num, data->val_in)) {
598 retval = -EIO;
599 goto out;
600 }
601 break;
602
603 default:
604 retval = -EOPNOTSUPP;
605 break;
606 }
607out:
608 spin_unlock_irqrestore(&adapter->mdio_lock, flags);
609 return retval;
610}
611
612/*
613 * atl1c_ioctl -
614 * @netdev:
615 * @ifreq:
616 * @cmd:
617 */
618static int atl1c_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
619{
620 switch (cmd) {
621 case SIOCGMIIPHY:
622 case SIOCGMIIREG:
623 case SIOCSMIIREG:
624 return atl1c_mii_ioctl(netdev, ifr, cmd);
625 default:
626 return -EOPNOTSUPP;
627 }
628}
629
630/*
631 * atl1c_alloc_queues - Allocate memory for all rings
632 * @adapter: board private structure to initialize
633 *
634 */
635static int __devinit atl1c_alloc_queues(struct atl1c_adapter *adapter)
636{
637 return 0;
638}
639
640static void atl1c_set_mac_type(struct atl1c_hw *hw)
641{
642 switch (hw->device_id) {
643 case PCI_DEVICE_ID_ATTANSIC_L2C:
644 hw->nic_type = athr_l2c;
645 break;
Jie Yang43250dd2009-02-18 17:24:15 -0800646 case PCI_DEVICE_ID_ATTANSIC_L1C:
647 hw->nic_type = athr_l1c;
648 break;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800649 case PCI_DEVICE_ID_ATHEROS_L2C_B:
650 hw->nic_type = athr_l2c_b;
651 break;
652 case PCI_DEVICE_ID_ATHEROS_L2C_B2:
653 hw->nic_type = athr_l2c_b2;
654 break;
655 case PCI_DEVICE_ID_ATHEROS_L1D:
656 hw->nic_type = athr_l1d;
657 break;
Jie Yang8f574b32010-06-01 00:28:12 -0700658 case PCI_DEVICE_ID_ATHEROS_L1D_2_0:
659 hw->nic_type = athr_l1d_2;
660 break;
Jie Yang43250dd2009-02-18 17:24:15 -0800661 default:
662 break;
663 }
664}
665
666static int atl1c_setup_mac_funcs(struct atl1c_hw *hw)
667{
668 u32 phy_status_data;
669 u32 link_ctrl_data;
670
671 atl1c_set_mac_type(hw);
672 AT_READ_REG(hw, REG_PHY_STATUS, &phy_status_data);
673 AT_READ_REG(hw, REG_LINK_CTRL, &link_ctrl_data);
674
Jie Yang8f574b32010-06-01 00:28:12 -0700675 hw->ctrl_flags = ATL1C_INTR_MODRT_ENABLE |
Jie Yang43250dd2009-02-18 17:24:15 -0800676 ATL1C_TXQ_MODE_ENHANCE;
677 if (link_ctrl_data & LINK_CTRL_L0S_EN)
678 hw->ctrl_flags |= ATL1C_ASPM_L0S_SUPPORT;
679 if (link_ctrl_data & LINK_CTRL_L1_EN)
680 hw->ctrl_flags |= ATL1C_ASPM_L1_SUPPORT;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800681 if (link_ctrl_data & LINK_CTRL_EXT_SYNC)
682 hw->ctrl_flags |= ATL1C_LINK_EXT_SYNC;
Jie Yang8f574b32010-06-01 00:28:12 -0700683 hw->ctrl_flags |= ATL1C_ASPM_CTRL_MON;
Jie Yang43250dd2009-02-18 17:24:15 -0800684
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800685 if (hw->nic_type == athr_l1c ||
Jie Yang8f574b32010-06-01 00:28:12 -0700686 hw->nic_type == athr_l1d ||
687 hw->nic_type == athr_l1d_2)
Luis R. Rodriguez496c1852010-02-16 15:16:45 -0800688 hw->link_cap_flags |= ATL1C_LINK_CAP_1000M;
Jie Yang43250dd2009-02-18 17:24:15 -0800689 return 0;
690}
691/*
692 * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter)
693 * @adapter: board private structure to initialize
694 *
695 * atl1c_sw_init initializes the Adapter private data structure.
696 * Fields are initialized based on PCI device information and
697 * OS network device settings (MTU size).
698 */
699static int __devinit atl1c_sw_init(struct atl1c_adapter *adapter)
700{
701 struct atl1c_hw *hw = &adapter->hw;
702 struct pci_dev *pdev = adapter->pdev;
Jie Yang8f574b32010-06-01 00:28:12 -0700703 u32 revision;
704
Jie Yang43250dd2009-02-18 17:24:15 -0800705
706 adapter->wol = 0;
Rafael J. Wysocki762e3022010-12-22 03:07:52 +0000707 device_set_wakeup_enable(&pdev->dev, false);
Jie Yang43250dd2009-02-18 17:24:15 -0800708 adapter->link_speed = SPEED_0;
709 adapter->link_duplex = FULL_DUPLEX;
Jie Yang43250dd2009-02-18 17:24:15 -0800710 adapter->tpd_ring[0].count = 1024;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000711 adapter->rfd_ring.count = 512;
Jie Yang43250dd2009-02-18 17:24:15 -0800712
713 hw->vendor_id = pdev->vendor;
714 hw->device_id = pdev->device;
715 hw->subsystem_vendor_id = pdev->subsystem_vendor;
716 hw->subsystem_id = pdev->subsystem_device;
Jie Yang8f574b32010-06-01 00:28:12 -0700717 AT_READ_REG(hw, PCI_CLASS_REVISION, &revision);
718 hw->revision_id = revision & 0xFF;
Jie Yang43250dd2009-02-18 17:24:15 -0800719 /* before link up, we assume hibernate is true */
720 hw->hibernate = true;
721 hw->media_type = MEDIA_TYPE_AUTO_SENSOR;
722 if (atl1c_setup_mac_funcs(hw) != 0) {
723 dev_err(&pdev->dev, "set mac function pointers failed\n");
724 return -1;
725 }
726 hw->intr_mask = IMR_NORMAL_MASK;
727 hw->phy_configured = false;
728 hw->preamble_len = 7;
729 hw->max_frame_size = adapter->netdev->mtu;
Jie Yang43250dd2009-02-18 17:24:15 -0800730 hw->autoneg_advertised = ADVERTISED_Autoneg;
731 hw->indirect_tab = 0xE4E4E4E4;
732 hw->base_cpu = 0;
733
734 hw->ict = 50000; /* 100ms */
735 hw->smb_timer = 200000; /* 400ms */
Jie Yang43250dd2009-02-18 17:24:15 -0800736 hw->rx_imt = 200;
737 hw->tx_imt = 1000;
738
739 hw->tpd_burst = 5;
740 hw->rfd_burst = 8;
741 hw->dma_order = atl1c_dma_ord_out;
742 hw->dmar_block = atl1c_dma_req_1024;
Jie Yang43250dd2009-02-18 17:24:15 -0800743 hw->dmar_dly_cnt = 15;
744 hw->dmaw_dly_cnt = 4;
745
746 if (atl1c_alloc_queues(adapter)) {
747 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
748 return -ENOMEM;
749 }
750 /* TODO */
751 atl1c_set_rxbufsize(adapter, adapter->netdev);
752 atomic_set(&adapter->irq_sem, 1);
753 spin_lock_init(&adapter->mdio_lock);
754 spin_lock_init(&adapter->tx_lock);
755 set_bit(__AT_DOWN, &adapter->flags);
756
757 return 0;
758}
759
Jie Yangc6060be2009-11-06 00:32:05 -0800760static inline void atl1c_clean_buffer(struct pci_dev *pdev,
761 struct atl1c_buffer *buffer_info, int in_irq)
762{
Jie Yang4b45e342009-12-06 22:56:59 +0000763 u16 pci_driection;
Jie Yangc6060be2009-11-06 00:32:05 -0800764 if (buffer_info->flags & ATL1C_BUFFER_FREE)
765 return;
766 if (buffer_info->dma) {
Jie Yang4b45e342009-12-06 22:56:59 +0000767 if (buffer_info->flags & ATL1C_PCIMAP_FROMDEVICE)
768 pci_driection = PCI_DMA_FROMDEVICE;
769 else
770 pci_driection = PCI_DMA_TODEVICE;
771
Jie Yangc6060be2009-11-06 00:32:05 -0800772 if (buffer_info->flags & ATL1C_PCIMAP_SINGLE)
773 pci_unmap_single(pdev, buffer_info->dma,
Jie Yang4b45e342009-12-06 22:56:59 +0000774 buffer_info->length, pci_driection);
Jie Yangc6060be2009-11-06 00:32:05 -0800775 else if (buffer_info->flags & ATL1C_PCIMAP_PAGE)
776 pci_unmap_page(pdev, buffer_info->dma,
Jie Yang4b45e342009-12-06 22:56:59 +0000777 buffer_info->length, pci_driection);
Jie Yangc6060be2009-11-06 00:32:05 -0800778 }
779 if (buffer_info->skb) {
780 if (in_irq)
781 dev_kfree_skb_irq(buffer_info->skb);
782 else
783 dev_kfree_skb(buffer_info->skb);
784 }
785 buffer_info->dma = 0;
786 buffer_info->skb = NULL;
787 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE);
788}
Jie Yang43250dd2009-02-18 17:24:15 -0800789/*
790 * atl1c_clean_tx_ring - Free Tx-skb
791 * @adapter: board private structure
792 */
793static void atl1c_clean_tx_ring(struct atl1c_adapter *adapter,
794 enum atl1c_trans_queue type)
795{
796 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
797 struct atl1c_buffer *buffer_info;
798 struct pci_dev *pdev = adapter->pdev;
799 u16 index, ring_count;
800
801 ring_count = tpd_ring->count;
802 for (index = 0; index < ring_count; index++) {
803 buffer_info = &tpd_ring->buffer_info[index];
Jie Yangc6060be2009-11-06 00:32:05 -0800804 atl1c_clean_buffer(pdev, buffer_info, 0);
Jie Yang43250dd2009-02-18 17:24:15 -0800805 }
806
807 /* Zero out Tx-buffers */
808 memset(tpd_ring->desc, 0, sizeof(struct atl1c_tpd_desc) *
Jie Yangc6060be2009-11-06 00:32:05 -0800809 ring_count);
Jie Yang43250dd2009-02-18 17:24:15 -0800810 atomic_set(&tpd_ring->next_to_clean, 0);
811 tpd_ring->next_to_use = 0;
812}
813
814/*
815 * atl1c_clean_rx_ring - Free rx-reservation skbs
816 * @adapter: board private structure
817 */
818static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter)
819{
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000820 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
821 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800822 struct atl1c_buffer *buffer_info;
823 struct pci_dev *pdev = adapter->pdev;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000824 int j;
Jie Yang43250dd2009-02-18 17:24:15 -0800825
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000826 for (j = 0; j < rfd_ring->count; j++) {
827 buffer_info = &rfd_ring->buffer_info[j];
828 atl1c_clean_buffer(pdev, buffer_info, 0);
Jie Yang43250dd2009-02-18 17:24:15 -0800829 }
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000830 /* zero out the descriptor ring */
831 memset(rfd_ring->desc, 0, rfd_ring->size);
832 rfd_ring->next_to_clean = 0;
833 rfd_ring->next_to_use = 0;
834 rrd_ring->next_to_use = 0;
835 rrd_ring->next_to_clean = 0;
Jie Yang43250dd2009-02-18 17:24:15 -0800836}
837
838/*
839 * Read / Write Ptr Initialize:
840 */
841static void atl1c_init_ring_ptrs(struct atl1c_adapter *adapter)
842{
843 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000844 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
845 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800846 struct atl1c_buffer *buffer_info;
847 int i, j;
848
849 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
850 tpd_ring[i].next_to_use = 0;
851 atomic_set(&tpd_ring[i].next_to_clean, 0);
852 buffer_info = tpd_ring[i].buffer_info;
853 for (j = 0; j < tpd_ring->count; j++)
Jie Yangc6060be2009-11-06 00:32:05 -0800854 ATL1C_SET_BUFFER_STATE(&buffer_info[i],
855 ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -0800856 }
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000857 rfd_ring->next_to_use = 0;
858 rfd_ring->next_to_clean = 0;
859 rrd_ring->next_to_use = 0;
860 rrd_ring->next_to_clean = 0;
861 for (j = 0; j < rfd_ring->count; j++) {
862 buffer_info = &rfd_ring->buffer_info[j];
863 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -0800864 }
865}
866
867/*
868 * atl1c_free_ring_resources - Free Tx / RX descriptor Resources
869 * @adapter: board private structure
870 *
871 * Free all transmit software resources
872 */
873static void atl1c_free_ring_resources(struct atl1c_adapter *adapter)
874{
875 struct pci_dev *pdev = adapter->pdev;
876
877 pci_free_consistent(pdev, adapter->ring_header.size,
878 adapter->ring_header.desc,
879 adapter->ring_header.dma);
880 adapter->ring_header.desc = NULL;
881
882 /* Note: just free tdp_ring.buffer_info,
883 * it contain rfd_ring.buffer_info, do not double free */
884 if (adapter->tpd_ring[0].buffer_info) {
885 kfree(adapter->tpd_ring[0].buffer_info);
886 adapter->tpd_ring[0].buffer_info = NULL;
887 }
888}
889
890/*
891 * atl1c_setup_mem_resources - allocate Tx / RX descriptor resources
892 * @adapter: board private structure
893 *
894 * Return 0 on success, negative on failure
895 */
896static int atl1c_setup_ring_resources(struct atl1c_adapter *adapter)
897{
898 struct pci_dev *pdev = adapter->pdev;
899 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000900 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
901 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800902 struct atl1c_ring_header *ring_header = &adapter->ring_header;
Jie Yang43250dd2009-02-18 17:24:15 -0800903 int size;
904 int i;
905 int count = 0;
906 int rx_desc_count = 0;
907 u32 offset = 0;
908
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000909 rrd_ring->count = rfd_ring->count;
Jie Yang43250dd2009-02-18 17:24:15 -0800910 for (i = 1; i < AT_MAX_TRANSMIT_QUEUE; i++)
911 tpd_ring[i].count = tpd_ring[0].count;
912
Jie Yang43250dd2009-02-18 17:24:15 -0800913 /* 2 tpd queue, one high priority queue,
914 * another normal priority queue */
915 size = sizeof(struct atl1c_buffer) * (tpd_ring->count * 2 +
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000916 rfd_ring->count);
Jie Yang43250dd2009-02-18 17:24:15 -0800917 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL);
918 if (unlikely(!tpd_ring->buffer_info)) {
919 dev_err(&pdev->dev, "kzalloc failed, size = %d\n",
920 size);
921 goto err_nomem;
922 }
923 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
924 tpd_ring[i].buffer_info =
925 (struct atl1c_buffer *) (tpd_ring->buffer_info + count);
926 count += tpd_ring[i].count;
927 }
928
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000929 rfd_ring->buffer_info =
930 (struct atl1c_buffer *) (tpd_ring->buffer_info + count);
931 count += rfd_ring->count;
932 rx_desc_count += rfd_ring->count;
933
Jie Yang43250dd2009-02-18 17:24:15 -0800934 /*
935 * real ring DMA buffer
936 * each ring/block may need up to 8 bytes for alignment, hence the
937 * additional bytes tacked onto the end.
938 */
939 ring_header->size = size =
940 sizeof(struct atl1c_tpd_desc) * tpd_ring->count * 2 +
941 sizeof(struct atl1c_rx_free_desc) * rx_desc_count +
942 sizeof(struct atl1c_recv_ret_status) * rx_desc_count +
Huang, Xiong8d5c6832012-04-17 19:32:29 +0000943 8 * 4;
Jie Yang43250dd2009-02-18 17:24:15 -0800944
945 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size,
946 &ring_header->dma);
947 if (unlikely(!ring_header->desc)) {
948 dev_err(&pdev->dev, "pci_alloc_consistend failed\n");
949 goto err_nomem;
950 }
951 memset(ring_header->desc, 0, ring_header->size);
952 /* init TPD ring */
953
954 tpd_ring[0].dma = roundup(ring_header->dma, 8);
955 offset = tpd_ring[0].dma - ring_header->dma;
956 for (i = 0; i < AT_MAX_TRANSMIT_QUEUE; i++) {
957 tpd_ring[i].dma = ring_header->dma + offset;
958 tpd_ring[i].desc = (u8 *) ring_header->desc + offset;
959 tpd_ring[i].size =
960 sizeof(struct atl1c_tpd_desc) * tpd_ring[i].count;
961 offset += roundup(tpd_ring[i].size, 8);
962 }
963 /* init RFD ring */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000964 rfd_ring->dma = ring_header->dma + offset;
965 rfd_ring->desc = (u8 *) ring_header->desc + offset;
966 rfd_ring->size = sizeof(struct atl1c_rx_free_desc) * rfd_ring->count;
967 offset += roundup(rfd_ring->size, 8);
Jie Yang43250dd2009-02-18 17:24:15 -0800968
969 /* init RRD ring */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000970 rrd_ring->dma = ring_header->dma + offset;
971 rrd_ring->desc = (u8 *) ring_header->desc + offset;
972 rrd_ring->size = sizeof(struct atl1c_recv_ret_status) *
973 rrd_ring->count;
974 offset += roundup(rrd_ring->size, 8);
Jie Yang43250dd2009-02-18 17:24:15 -0800975
Jie Yang43250dd2009-02-18 17:24:15 -0800976 return 0;
977
978err_nomem:
979 kfree(tpd_ring->buffer_info);
980 return -ENOMEM;
981}
982
983static void atl1c_configure_des_ring(struct atl1c_adapter *adapter)
984{
985 struct atl1c_hw *hw = &adapter->hw;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +0000986 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
987 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -0800988 struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *)
989 adapter->tpd_ring;
Jie Yang8f574b32010-06-01 00:28:12 -0700990 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -0800991
992 /* TPD */
993 AT_WRITE_REG(hw, REG_TX_BASE_ADDR_HI,
994 (u32)((tpd_ring[atl1c_trans_normal].dma &
995 AT_DMA_HI_ADDR_MASK) >> 32));
996 /* just enable normal priority TX queue */
Huang, Xiong0af48332012-04-17 19:32:30 +0000997 AT_WRITE_REG(hw, REG_TPD_PRI0_ADDR_LO,
Jie Yang43250dd2009-02-18 17:24:15 -0800998 (u32)(tpd_ring[atl1c_trans_normal].dma &
999 AT_DMA_LO_ADDR_MASK));
Huang, Xiong0af48332012-04-17 19:32:30 +00001000 AT_WRITE_REG(hw, REG_TPD_PRI1_ADDR_LO,
Jie Yang43250dd2009-02-18 17:24:15 -08001001 (u32)(tpd_ring[atl1c_trans_high].dma &
1002 AT_DMA_LO_ADDR_MASK));
1003 AT_WRITE_REG(hw, REG_TPD_RING_SIZE,
1004 (u32)(tpd_ring[0].count & TPD_RING_SIZE_MASK));
1005
1006
1007 /* RFD */
1008 AT_WRITE_REG(hw, REG_RX_BASE_ADDR_HI,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001009 (u32)((rfd_ring->dma & AT_DMA_HI_ADDR_MASK) >> 32));
1010 AT_WRITE_REG(hw, REG_RFD0_HEAD_ADDR_LO,
1011 (u32)(rfd_ring->dma & AT_DMA_LO_ADDR_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001012
1013 AT_WRITE_REG(hw, REG_RFD_RING_SIZE,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001014 rfd_ring->count & RFD_RING_SIZE_MASK);
Jie Yang43250dd2009-02-18 17:24:15 -08001015 AT_WRITE_REG(hw, REG_RX_BUF_SIZE,
1016 adapter->rx_buffer_len & RX_BUF_SIZE_MASK);
1017
1018 /* RRD */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001019 AT_WRITE_REG(hw, REG_RRD0_HEAD_ADDR_LO,
1020 (u32)(rrd_ring->dma & AT_DMA_LO_ADDR_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001021 AT_WRITE_REG(hw, REG_RRD_RING_SIZE,
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001022 (rrd_ring->count & RRD_RING_SIZE_MASK));
Jie Yang43250dd2009-02-18 17:24:15 -08001023
Jie Yang8f574b32010-06-01 00:28:12 -07001024 if (hw->nic_type == athr_l2c_b) {
1025 AT_WRITE_REG(hw, REG_SRAM_RXF_LEN, 0x02a0L);
1026 AT_WRITE_REG(hw, REG_SRAM_TXF_LEN, 0x0100L);
1027 AT_WRITE_REG(hw, REG_SRAM_RXF_ADDR, 0x029f0000L);
1028 AT_WRITE_REG(hw, REG_SRAM_RFD0_INFO, 0x02bf02a0L);
1029 AT_WRITE_REG(hw, REG_SRAM_TXF_ADDR, 0x03bf02c0L);
1030 AT_WRITE_REG(hw, REG_SRAM_TRD_ADDR, 0x03df03c0L);
1031 AT_WRITE_REG(hw, REG_TXF_WATER_MARK, 0); /* TX watermark, to enter l1 state.*/
1032 AT_WRITE_REG(hw, REG_RXD_DMA_CTRL, 0); /* RXD threshold.*/
1033 }
1034 if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d_2) {
1035 /* Power Saving for L2c_B */
1036 AT_READ_REG(hw, REG_SERDES_LOCK, &data);
1037 data |= SERDES_MAC_CLK_SLOWDOWN;
1038 data |= SERDES_PYH_CLK_SLOWDOWN;
1039 AT_WRITE_REG(hw, REG_SERDES_LOCK, data);
1040 }
Jie Yang43250dd2009-02-18 17:24:15 -08001041 /* Load all of base address above */
1042 AT_WRITE_REG(hw, REG_LOAD_PTR, 1);
1043}
1044
1045static void atl1c_configure_tx(struct atl1c_adapter *adapter)
1046{
1047 struct atl1c_hw *hw = &adapter->hw;
1048 u32 dev_ctrl_data;
1049 u32 max_pay_load;
1050 u16 tx_offload_thresh;
1051 u32 txq_ctrl_data;
Jie Yang43250dd2009-02-18 17:24:15 -08001052
Jie Yang43250dd2009-02-18 17:24:15 -08001053 tx_offload_thresh = MAX_TX_OFFLOAD_THRESH;
1054 AT_WRITE_REG(hw, REG_TX_TSO_OFFLOAD_THRESH,
1055 (tx_offload_thresh >> 3) & TX_TSO_OFFLOAD_THRESH_MASK);
1056 AT_READ_REG(hw, REG_DEVICE_CTRL, &dev_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -08001057 max_pay_load = (dev_ctrl_data >> DEVICE_CTRL_MAX_RREQ_SZ_SHIFT) &
1058 DEVICE_CTRL_MAX_RREQ_SZ_MASK;
stephen hemminger81b504b2011-02-23 09:06:49 +00001059 hw->dmar_block = min_t(u32, max_pay_load, hw->dmar_block);
Jie Yang43250dd2009-02-18 17:24:15 -08001060
Huang, Xiongc24588a2012-04-17 19:32:35 +00001061 txq_ctrl_data =
1062 hw->nic_type == athr_l2c_b || hw->nic_type == athr_l2c_b2 ?
1063 L2CB_TXQ_CFGV : L1C_TXQ_CFGV;
Jie Yang43250dd2009-02-18 17:24:15 -08001064
1065 AT_WRITE_REG(hw, REG_TXQ_CTRL, txq_ctrl_data);
1066}
1067
1068static void atl1c_configure_rx(struct atl1c_adapter *adapter)
1069{
1070 struct atl1c_hw *hw = &adapter->hw;
1071 u32 rxq_ctrl_data;
1072
1073 rxq_ctrl_data = (hw->rfd_burst & RXQ_RFD_BURST_NUM_MASK) <<
1074 RXQ_RFD_BURST_NUM_SHIFT;
1075
1076 if (hw->ctrl_flags & ATL1C_RX_IPV6_CHKSUM)
1077 rxq_ctrl_data |= IPV6_CHKSUM_CTRL_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001078
Jie Yang43250dd2009-02-18 17:24:15 -08001079 if (hw->ctrl_flags & ATL1C_ASPM_CTRL_MON)
Jie Yang8f574b32010-06-01 00:28:12 -07001080 rxq_ctrl_data |= (ASPM_THRUPUT_LIMIT_1M &
Jie Yang43250dd2009-02-18 17:24:15 -08001081 ASPM_THRUPUT_LIMIT_MASK) << ASPM_THRUPUT_LIMIT_SHIFT;
1082
1083 AT_WRITE_REG(hw, REG_RXQ_CTRL, rxq_ctrl_data);
1084}
1085
Jie Yang43250dd2009-02-18 17:24:15 -08001086static void atl1c_configure_dma(struct atl1c_adapter *adapter)
1087{
1088 struct atl1c_hw *hw = &adapter->hw;
1089 u32 dma_ctrl_data;
1090
Huang, Xiong37bfccb2012-04-17 19:32:33 +00001091 dma_ctrl_data = FIELDX(DMA_CTRL_RORDER_MODE, DMA_CTRL_RORDER_MODE_OUT) |
1092 DMA_CTRL_RREQ_PRI_DATA |
1093 FIELDX(DMA_CTRL_RREQ_BLEN, hw->dmar_block) |
1094 FIELDX(DMA_CTRL_WDLY_CNT, DMA_CTRL_WDLY_CNT_DEF) |
1095 FIELDX(DMA_CTRL_RDLY_CNT, DMA_CTRL_RDLY_CNT_DEF);
Jie Yang43250dd2009-02-18 17:24:15 -08001096
1097 AT_WRITE_REG(hw, REG_DMA_CTRL, dma_ctrl_data);
1098}
1099
1100/*
1101 * Stop the mac, transmit and receive units
1102 * hw - Struct containing variables accessed by shared code
1103 * return : 0 or idle status (if error)
1104 */
1105static int atl1c_stop_mac(struct atl1c_hw *hw)
1106{
1107 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -08001108
1109 AT_READ_REG(hw, REG_RXQ_CTRL, &data);
Huang, Xiong027392c2012-04-17 19:32:31 +00001110 data &= ~RXQ_CTRL_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001111 AT_WRITE_REG(hw, REG_RXQ_CTRL, data);
1112
1113 AT_READ_REG(hw, REG_TXQ_CTRL, &data);
1114 data &= ~TXQ_CTRL_EN;
Huang, Xiong0cbec612012-04-17 19:32:32 +00001115 AT_WRITE_REG(hw, REG_TXQ_CTRL, data);
Jie Yang43250dd2009-02-18 17:24:15 -08001116
Joe Perchesc930a662009-05-31 20:44:54 +00001117 atl1c_wait_until_idle(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08001118
1119 AT_READ_REG(hw, REG_MAC_CTRL, &data);
1120 data &= ~(MAC_CTRL_TX_EN | MAC_CTRL_RX_EN);
1121 AT_WRITE_REG(hw, REG_MAC_CTRL, data);
1122
Joe Perchesc930a662009-05-31 20:44:54 +00001123 return (int)atl1c_wait_until_idle(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08001124}
1125
1126static void atl1c_enable_rx_ctrl(struct atl1c_hw *hw)
1127{
1128 u32 data;
1129
1130 AT_READ_REG(hw, REG_RXQ_CTRL, &data);
Jie Yang43250dd2009-02-18 17:24:15 -08001131 data |= RXQ_CTRL_EN;
1132 AT_WRITE_REG(hw, REG_RXQ_CTRL, data);
1133}
1134
1135static void atl1c_enable_tx_ctrl(struct atl1c_hw *hw)
1136{
1137 u32 data;
1138
1139 AT_READ_REG(hw, REG_TXQ_CTRL, &data);
1140 data |= TXQ_CTRL_EN;
1141 AT_WRITE_REG(hw, REG_TXQ_CTRL, data);
1142}
1143
1144/*
1145 * Reset the transmit and receive units; mask and clear all interrupts.
1146 * hw - Struct containing variables accessed by shared code
1147 * return : 0 or idle status (if error)
1148 */
1149static int atl1c_reset_mac(struct atl1c_hw *hw)
1150{
1151 struct atl1c_adapter *adapter = (struct atl1c_adapter *)hw->adapter;
1152 struct pci_dev *pdev = adapter->pdev;
Jie Yang8f574b32010-06-01 00:28:12 -07001153 u32 master_ctrl_data = 0;
Jie Yang43250dd2009-02-18 17:24:15 -08001154
1155 AT_WRITE_REG(hw, REG_IMR, 0);
1156 AT_WRITE_REG(hw, REG_ISR, ISR_DIS_INT);
1157
Jie Yang8f574b32010-06-01 00:28:12 -07001158 atl1c_stop_mac(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08001159 /*
1160 * Issue Soft Reset to the MAC. This will reset the chip's
1161 * transmit, receive, DMA. It will not effect
1162 * the current PCI configuration. The global reset bit is self-
1163 * clearing, and should clear within a microsecond.
1164 */
Jie Yang8f574b32010-06-01 00:28:12 -07001165 AT_READ_REG(hw, REG_MASTER_CTRL, &master_ctrl_data);
1166 master_ctrl_data |= MASTER_CTRL_OOB_DIS_OFF;
1167 AT_WRITE_REGW(hw, REG_MASTER_CTRL, ((master_ctrl_data | MASTER_CTRL_SOFT_RST)
1168 & 0xFFFF));
1169
Jie Yang43250dd2009-02-18 17:24:15 -08001170 AT_WRITE_FLUSH(hw);
1171 msleep(10);
1172 /* Wait at least 10ms for All module to be Idle */
Joe Perchesc930a662009-05-31 20:44:54 +00001173
1174 if (atl1c_wait_until_idle(hw)) {
Jie Yang43250dd2009-02-18 17:24:15 -08001175 dev_err(&pdev->dev,
Joe Perchesc930a662009-05-31 20:44:54 +00001176 "MAC state machine can't be idle since"
Jie Yang43250dd2009-02-18 17:24:15 -08001177 " disabled for 10ms second\n");
1178 return -1;
1179 }
1180 return 0;
1181}
1182
1183static void atl1c_disable_l0s_l1(struct atl1c_hw *hw)
1184{
1185 u32 pm_ctrl_data;
1186
1187 AT_READ_REG(hw, REG_PM_CTRL, &pm_ctrl_data);
1188 pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK <<
1189 PM_CTRL_L1_ENTRY_TIMER_SHIFT);
1190 pm_ctrl_data &= ~PM_CTRL_CLK_SWH_L1;
1191 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
1192 pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN;
1193 pm_ctrl_data &= ~PM_CTRL_MAC_ASPM_CHK;
1194 pm_ctrl_data &= ~PM_CTRL_SERDES_PD_EX_L1;
1195
1196 pm_ctrl_data |= PM_CTRL_SERDES_BUDS_RX_L1_EN;
1197 pm_ctrl_data |= PM_CTRL_SERDES_PLL_L1_EN;
1198 pm_ctrl_data |= PM_CTRL_SERDES_L1_EN;
1199 AT_WRITE_REG(hw, REG_PM_CTRL, pm_ctrl_data);
1200}
1201
1202/*
1203 * Set ASPM state.
1204 * Enable/disable L0s/L1 depend on link state.
1205 */
1206static void atl1c_set_aspm(struct atl1c_hw *hw, bool linkup)
1207{
1208 u32 pm_ctrl_data;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001209 u32 link_ctrl_data;
Jie Yang8f574b32010-06-01 00:28:12 -07001210 u32 link_l1_timer = 0xF;
Jie Yang43250dd2009-02-18 17:24:15 -08001211
1212 AT_READ_REG(hw, REG_PM_CTRL, &pm_ctrl_data);
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001213 AT_READ_REG(hw, REG_LINK_CTRL, &link_ctrl_data);
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001214
Jie Yang8f574b32010-06-01 00:28:12 -07001215 pm_ctrl_data &= ~PM_CTRL_SERDES_PD_EX_L1;
Jie Yang43250dd2009-02-18 17:24:15 -08001216 pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK <<
1217 PM_CTRL_L1_ENTRY_TIMER_SHIFT);
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001218 pm_ctrl_data &= ~(PM_CTRL_LCKDET_TIMER_MASK <<
Jie Yang8f574b32010-06-01 00:28:12 -07001219 PM_CTRL_LCKDET_TIMER_SHIFT);
1220 pm_ctrl_data |= AT_LCKDET_TIMER << PM_CTRL_LCKDET_TIMER_SHIFT;
Jie Yang43250dd2009-02-18 17:24:15 -08001221
Jie Yang8f574b32010-06-01 00:28:12 -07001222 if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d ||
1223 hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) {
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001224 link_ctrl_data &= ~LINK_CTRL_EXT_SYNC;
1225 if (!(hw->ctrl_flags & ATL1C_APS_MODE_ENABLE)) {
Jie Yang8f574b32010-06-01 00:28:12 -07001226 if (hw->nic_type == athr_l2c_b && hw->revision_id == L2CB_V10)
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001227 link_ctrl_data |= LINK_CTRL_EXT_SYNC;
1228 }
1229
1230 AT_WRITE_REG(hw, REG_LINK_CTRL, link_ctrl_data);
1231
Jie Yang8f574b32010-06-01 00:28:12 -07001232 pm_ctrl_data |= PM_CTRL_RCVR_WT_TIMER;
1233 pm_ctrl_data &= ~(PM_CTRL_PM_REQ_TIMER_MASK <<
1234 PM_CTRL_PM_REQ_TIMER_SHIFT);
1235 pm_ctrl_data |= AT_ASPM_L1_TIMER <<
1236 PM_CTRL_PM_REQ_TIMER_SHIFT;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001237 pm_ctrl_data &= ~PM_CTRL_SA_DLY_EN;
1238 pm_ctrl_data &= ~PM_CTRL_HOTRST;
1239 pm_ctrl_data |= 1 << PM_CTRL_L1_ENTRY_TIMER_SHIFT;
1240 pm_ctrl_data |= PM_CTRL_SERDES_PD_EX_L1;
1241 }
Jie Yang8f574b32010-06-01 00:28:12 -07001242 pm_ctrl_data |= PM_CTRL_MAC_ASPM_CHK;
Jie Yang43250dd2009-02-18 17:24:15 -08001243 if (linkup) {
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001244 pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN;
1245 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
1246 if (hw->ctrl_flags & ATL1C_ASPM_L1_SUPPORT)
1247 pm_ctrl_data |= PM_CTRL_ASPM_L1_EN;
1248 if (hw->ctrl_flags & ATL1C_ASPM_L0S_SUPPORT)
1249 pm_ctrl_data |= PM_CTRL_ASPM_L0S_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001250
Jie Yang8f574b32010-06-01 00:28:12 -07001251 if (hw->nic_type == athr_l2c_b || hw->nic_type == athr_l1d ||
1252 hw->nic_type == athr_l2c_b2 || hw->nic_type == athr_l1d_2) {
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001253 if (hw->nic_type == athr_l2c_b)
1254 if (!(hw->ctrl_flags & ATL1C_APS_MODE_ENABLE))
Jie Yang8f574b32010-06-01 00:28:12 -07001255 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001256 pm_ctrl_data &= ~PM_CTRL_SERDES_L1_EN;
1257 pm_ctrl_data &= ~PM_CTRL_SERDES_PLL_L1_EN;
1258 pm_ctrl_data &= ~PM_CTRL_SERDES_BUDS_RX_L1_EN;
1259 pm_ctrl_data |= PM_CTRL_CLK_SWH_L1;
Jie Yang8f574b32010-06-01 00:28:12 -07001260 if (hw->adapter->link_speed == SPEED_100 ||
1261 hw->adapter->link_speed == SPEED_1000) {
1262 pm_ctrl_data &= ~(PM_CTRL_L1_ENTRY_TIMER_MASK <<
1263 PM_CTRL_L1_ENTRY_TIMER_SHIFT);
1264 if (hw->nic_type == athr_l2c_b)
1265 link_l1_timer = 7;
1266 else if (hw->nic_type == athr_l2c_b2 ||
1267 hw->nic_type == athr_l1d_2)
1268 link_l1_timer = 4;
1269 pm_ctrl_data |= link_l1_timer <<
1270 PM_CTRL_L1_ENTRY_TIMER_SHIFT;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001271 }
1272 } else {
1273 pm_ctrl_data |= PM_CTRL_SERDES_L1_EN;
1274 pm_ctrl_data |= PM_CTRL_SERDES_PLL_L1_EN;
1275 pm_ctrl_data |= PM_CTRL_SERDES_BUDS_RX_L1_EN;
1276 pm_ctrl_data &= ~PM_CTRL_CLK_SWH_L1;
1277 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
1278 pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN;
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001279
Jie Yang8f574b32010-06-01 00:28:12 -07001280 }
Jie Yang43250dd2009-02-18 17:24:15 -08001281 } else {
Jie Yang52fbc102009-04-27 19:42:03 +00001282 pm_ctrl_data &= ~PM_CTRL_SERDES_L1_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001283 pm_ctrl_data &= ~PM_CTRL_ASPM_L0S_EN;
1284 pm_ctrl_data &= ~PM_CTRL_SERDES_PLL_L1_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001285 pm_ctrl_data |= PM_CTRL_CLK_SWH_L1;
1286
1287 if (hw->ctrl_flags & ATL1C_ASPM_L1_SUPPORT)
1288 pm_ctrl_data |= PM_CTRL_ASPM_L1_EN;
1289 else
1290 pm_ctrl_data &= ~PM_CTRL_ASPM_L1_EN;
1291 }
Jie Yang43250dd2009-02-18 17:24:15 -08001292 AT_WRITE_REG(hw, REG_PM_CTRL, pm_ctrl_data);
Jie Yang8f574b32010-06-01 00:28:12 -07001293
1294 return;
Jie Yang43250dd2009-02-18 17:24:15 -08001295}
1296
1297static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter)
1298{
1299 struct atl1c_hw *hw = &adapter->hw;
1300 struct net_device *netdev = adapter->netdev;
1301 u32 mac_ctrl_data;
1302
1303 mac_ctrl_data = MAC_CTRL_TX_EN | MAC_CTRL_RX_EN;
1304 mac_ctrl_data |= (MAC_CTRL_TX_FLOW | MAC_CTRL_RX_FLOW);
1305
1306 if (adapter->link_duplex == FULL_DUPLEX) {
1307 hw->mac_duplex = true;
1308 mac_ctrl_data |= MAC_CTRL_DUPLX;
1309 }
1310
1311 if (adapter->link_speed == SPEED_1000)
1312 hw->mac_speed = atl1c_mac_speed_1000;
1313 else
1314 hw->mac_speed = atl1c_mac_speed_10_100;
1315
1316 mac_ctrl_data |= (hw->mac_speed & MAC_CTRL_SPEED_MASK) <<
1317 MAC_CTRL_SPEED_SHIFT;
1318
1319 mac_ctrl_data |= (MAC_CTRL_ADD_CRC | MAC_CTRL_PAD);
1320 mac_ctrl_data |= ((hw->preamble_len & MAC_CTRL_PRMLEN_MASK) <<
1321 MAC_CTRL_PRMLEN_SHIFT);
1322
Jiri Pirko46facce2011-07-20 04:54:12 +00001323 __atl1c_vlan_mode(netdev->features, &mac_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -08001324
1325 mac_ctrl_data |= MAC_CTRL_BC_EN;
1326 if (netdev->flags & IFF_PROMISC)
1327 mac_ctrl_data |= MAC_CTRL_PROMIS_EN;
1328 if (netdev->flags & IFF_ALLMULTI)
1329 mac_ctrl_data |= MAC_CTRL_MC_ALL_EN;
1330
1331 mac_ctrl_data |= MAC_CTRL_SINGLE_PAUSE_EN;
Jie Yang8f574b32010-06-01 00:28:12 -07001332 if (hw->nic_type == athr_l1d || hw->nic_type == athr_l2c_b2 ||
1333 hw->nic_type == athr_l1d_2) {
Luis R. Rodriguez496c1852010-02-16 15:16:45 -08001334 mac_ctrl_data |= MAC_CTRL_SPEED_MODE_SW;
1335 mac_ctrl_data |= MAC_CTRL_HASH_ALG_CRC32;
1336 }
Jie Yang43250dd2009-02-18 17:24:15 -08001337 AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data);
1338}
1339
1340/*
1341 * atl1c_configure - Configure Transmit&Receive Unit after Reset
1342 * @adapter: board private structure
1343 *
1344 * Configure the Tx /Rx unit of the MAC after a reset.
1345 */
1346static int atl1c_configure(struct atl1c_adapter *adapter)
1347{
1348 struct atl1c_hw *hw = &adapter->hw;
1349 u32 master_ctrl_data = 0;
1350 u32 intr_modrt_data;
Jie Yang8f574b32010-06-01 00:28:12 -07001351 u32 data;
Jie Yang43250dd2009-02-18 17:24:15 -08001352
1353 /* clear interrupt status */
1354 AT_WRITE_REG(hw, REG_ISR, 0xFFFFFFFF);
1355 /* Clear any WOL status */
1356 AT_WRITE_REG(hw, REG_WOL_CTRL, 0);
1357 /* set Interrupt Clear Timer
1358 * HW will enable self to assert interrupt event to system after
1359 * waiting x-time for software to notify it accept interrupt.
1360 */
Jie Yang8f574b32010-06-01 00:28:12 -07001361
1362 data = CLK_GATING_EN_ALL;
1363 if (hw->ctrl_flags & ATL1C_CLK_GATING_EN) {
1364 if (hw->nic_type == athr_l2c_b)
1365 data &= ~CLK_GATING_RXMAC_EN;
1366 } else
1367 data = 0;
1368 AT_WRITE_REG(hw, REG_CLK_GATING_CTRL, data);
1369
Jie Yang43250dd2009-02-18 17:24:15 -08001370 AT_WRITE_REG(hw, REG_INT_RETRIG_TIMER,
1371 hw->ict & INT_RETRIG_TIMER_MASK);
1372
1373 atl1c_configure_des_ring(adapter);
1374
1375 if (hw->ctrl_flags & ATL1C_INTR_MODRT_ENABLE) {
1376 intr_modrt_data = (hw->tx_imt & IRQ_MODRT_TIMER_MASK) <<
1377 IRQ_MODRT_TX_TIMER_SHIFT;
1378 intr_modrt_data |= (hw->rx_imt & IRQ_MODRT_TIMER_MASK) <<
1379 IRQ_MODRT_RX_TIMER_SHIFT;
1380 AT_WRITE_REG(hw, REG_IRQ_MODRT_TIMER_INIT, intr_modrt_data);
1381 master_ctrl_data |=
1382 MASTER_CTRL_TX_ITIMER_EN | MASTER_CTRL_RX_ITIMER_EN;
1383 }
1384
1385 if (hw->ctrl_flags & ATL1C_INTR_CLEAR_ON_READ)
1386 master_ctrl_data |= MASTER_CTRL_INT_RDCLR;
1387
Jie Yang8f574b32010-06-01 00:28:12 -07001388 master_ctrl_data |= MASTER_CTRL_SA_TIMER_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08001389 AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data);
1390
Huang, Xiong8d5c6832012-04-17 19:32:29 +00001391 AT_WRITE_REG(hw, REG_SMB_STAT_TIMER,
1392 hw->smb_timer & SMB_STAT_TIMER_MASK);
Jie Yang43250dd2009-02-18 17:24:15 -08001393
Jie Yang43250dd2009-02-18 17:24:15 -08001394 /* set MTU */
1395 AT_WRITE_REG(hw, REG_MTU, hw->max_frame_size + ETH_HLEN +
1396 VLAN_HLEN + ETH_FCS_LEN);
Jie Yang43250dd2009-02-18 17:24:15 -08001397
1398 atl1c_configure_tx(adapter);
1399 atl1c_configure_rx(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -08001400 atl1c_configure_dma(adapter);
1401
1402 return 0;
1403}
1404
1405static void atl1c_update_hw_stats(struct atl1c_adapter *adapter)
1406{
1407 u16 hw_reg_addr = 0;
1408 unsigned long *stats_item = NULL;
1409 u32 data;
1410
1411 /* update rx status */
1412 hw_reg_addr = REG_MAC_RX_STATUS_BIN;
1413 stats_item = &adapter->hw_stats.rx_ok;
1414 while (hw_reg_addr <= REG_MAC_RX_STATUS_END) {
1415 AT_READ_REG(&adapter->hw, hw_reg_addr, &data);
1416 *stats_item += data;
1417 stats_item++;
1418 hw_reg_addr += 4;
1419 }
1420/* update tx status */
1421 hw_reg_addr = REG_MAC_TX_STATUS_BIN;
1422 stats_item = &adapter->hw_stats.tx_ok;
1423 while (hw_reg_addr <= REG_MAC_TX_STATUS_END) {
1424 AT_READ_REG(&adapter->hw, hw_reg_addr, &data);
1425 *stats_item += data;
1426 stats_item++;
1427 hw_reg_addr += 4;
1428 }
1429}
1430
1431/*
1432 * atl1c_get_stats - Get System Network Statistics
1433 * @netdev: network interface device structure
1434 *
1435 * Returns the address of the device statistics structure.
1436 * The statistics are actually updated from the timer callback.
1437 */
1438static struct net_device_stats *atl1c_get_stats(struct net_device *netdev)
1439{
1440 struct atl1c_adapter *adapter = netdev_priv(netdev);
1441 struct atl1c_hw_stats *hw_stats = &adapter->hw_stats;
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001442 struct net_device_stats *net_stats = &netdev->stats;
Jie Yang43250dd2009-02-18 17:24:15 -08001443
1444 atl1c_update_hw_stats(adapter);
1445 net_stats->rx_packets = hw_stats->rx_ok;
1446 net_stats->tx_packets = hw_stats->tx_ok;
1447 net_stats->rx_bytes = hw_stats->rx_byte_cnt;
1448 net_stats->tx_bytes = hw_stats->tx_byte_cnt;
1449 net_stats->multicast = hw_stats->rx_mcast;
1450 net_stats->collisions = hw_stats->tx_1_col +
1451 hw_stats->tx_2_col * 2 +
1452 hw_stats->tx_late_col + hw_stats->tx_abort_col;
1453 net_stats->rx_errors = hw_stats->rx_frag + hw_stats->rx_fcs_err +
1454 hw_stats->rx_len_err + hw_stats->rx_sz_ov +
1455 hw_stats->rx_rrd_ov + hw_stats->rx_align_err;
1456 net_stats->rx_fifo_errors = hw_stats->rx_rxf_ov;
1457 net_stats->rx_length_errors = hw_stats->rx_len_err;
1458 net_stats->rx_crc_errors = hw_stats->rx_fcs_err;
1459 net_stats->rx_frame_errors = hw_stats->rx_align_err;
1460 net_stats->rx_over_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov;
1461
1462 net_stats->rx_missed_errors = hw_stats->rx_rrd_ov + hw_stats->rx_rxf_ov;
1463
1464 net_stats->tx_errors = hw_stats->tx_late_col + hw_stats->tx_abort_col +
1465 hw_stats->tx_underrun + hw_stats->tx_trunc;
1466 net_stats->tx_fifo_errors = hw_stats->tx_underrun;
1467 net_stats->tx_aborted_errors = hw_stats->tx_abort_col;
1468 net_stats->tx_window_errors = hw_stats->tx_late_col;
1469
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001470 return net_stats;
Jie Yang43250dd2009-02-18 17:24:15 -08001471}
1472
1473static inline void atl1c_clear_phy_int(struct atl1c_adapter *adapter)
1474{
1475 u16 phy_data;
1476
1477 spin_lock(&adapter->mdio_lock);
1478 atl1c_read_phy_reg(&adapter->hw, MII_ISR, &phy_data);
1479 spin_unlock(&adapter->mdio_lock);
1480}
1481
1482static bool atl1c_clean_tx_irq(struct atl1c_adapter *adapter,
1483 enum atl1c_trans_queue type)
1484{
1485 struct atl1c_tpd_ring *tpd_ring = (struct atl1c_tpd_ring *)
1486 &adapter->tpd_ring[type];
1487 struct atl1c_buffer *buffer_info;
Jie Yangc6060be2009-11-06 00:32:05 -08001488 struct pci_dev *pdev = adapter->pdev;
Jie Yang43250dd2009-02-18 17:24:15 -08001489 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1490 u16 hw_next_to_clean;
Huang, Xiong0af48332012-04-17 19:32:30 +00001491 u16 reg;
Jie Yang43250dd2009-02-18 17:24:15 -08001492
Huang, Xiong0af48332012-04-17 19:32:30 +00001493 reg = type == atl1c_trans_high ? REG_TPD_PRI1_CIDX : REG_TPD_PRI0_CIDX;
Jie Yang43250dd2009-02-18 17:24:15 -08001494
Huang, Xiong0af48332012-04-17 19:32:30 +00001495 AT_READ_REGW(&adapter->hw, reg, &hw_next_to_clean);
Jie Yang43250dd2009-02-18 17:24:15 -08001496
1497 while (next_to_clean != hw_next_to_clean) {
1498 buffer_info = &tpd_ring->buffer_info[next_to_clean];
Jie Yangc6060be2009-11-06 00:32:05 -08001499 atl1c_clean_buffer(pdev, buffer_info, 1);
Jie Yang43250dd2009-02-18 17:24:15 -08001500 if (++next_to_clean == tpd_ring->count)
1501 next_to_clean = 0;
1502 atomic_set(&tpd_ring->next_to_clean, next_to_clean);
1503 }
1504
1505 if (netif_queue_stopped(adapter->netdev) &&
1506 netif_carrier_ok(adapter->netdev)) {
1507 netif_wake_queue(adapter->netdev);
1508 }
1509
1510 return true;
1511}
1512
1513/*
1514 * atl1c_intr - Interrupt Handler
1515 * @irq: interrupt number
1516 * @data: pointer to a network interface device structure
1517 * @pt_regs: CPU registers structure
1518 */
1519static irqreturn_t atl1c_intr(int irq, void *data)
1520{
1521 struct net_device *netdev = data;
1522 struct atl1c_adapter *adapter = netdev_priv(netdev);
1523 struct pci_dev *pdev = adapter->pdev;
1524 struct atl1c_hw *hw = &adapter->hw;
1525 int max_ints = AT_MAX_INT_WORK;
1526 int handled = IRQ_NONE;
1527 u32 status;
1528 u32 reg_data;
1529
1530 do {
1531 AT_READ_REG(hw, REG_ISR, &reg_data);
1532 status = reg_data & hw->intr_mask;
1533
1534 if (status == 0 || (status & ISR_DIS_INT) != 0) {
1535 if (max_ints != AT_MAX_INT_WORK)
1536 handled = IRQ_HANDLED;
1537 break;
1538 }
1539 /* link event */
1540 if (status & ISR_GPHY)
1541 atl1c_clear_phy_int(adapter);
1542 /* Ack ISR */
1543 AT_WRITE_REG(hw, REG_ISR, status | ISR_DIS_INT);
1544 if (status & ISR_RX_PKT) {
1545 if (likely(napi_schedule_prep(&adapter->napi))) {
1546 hw->intr_mask &= ~ISR_RX_PKT;
1547 AT_WRITE_REG(hw, REG_IMR, hw->intr_mask);
1548 __napi_schedule(&adapter->napi);
1549 }
1550 }
1551 if (status & ISR_TX_PKT)
1552 atl1c_clean_tx_irq(adapter, atl1c_trans_normal);
1553
1554 handled = IRQ_HANDLED;
1555 /* check if PCIE PHY Link down */
1556 if (status & ISR_ERROR) {
1557 if (netif_msg_hw(adapter))
1558 dev_err(&pdev->dev,
1559 "atl1c hardware error (status = 0x%x)\n",
1560 status & ISR_ERROR);
1561 /* reset MAC */
Dan Carpenter78315452012-03-07 00:02:04 +00001562 set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
Jie Yangcb190542009-12-06 23:16:58 +00001563 schedule_work(&adapter->common_task);
Jie Yang8f574b32010-06-01 00:28:12 -07001564 return IRQ_HANDLED;
Jie Yang43250dd2009-02-18 17:24:15 -08001565 }
1566
1567 if (status & ISR_OVER)
1568 if (netif_msg_intr(adapter))
1569 dev_warn(&pdev->dev,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001570 "TX/RX overflow (status = 0x%x)\n",
Jie Yang43250dd2009-02-18 17:24:15 -08001571 status & ISR_OVER);
1572
1573 /* link event */
1574 if (status & (ISR_GPHY | ISR_MANUAL)) {
Eric Dumazeta2c483a2010-08-20 02:55:16 +00001575 netdev->stats.tx_carrier_errors++;
Jie Yang43250dd2009-02-18 17:24:15 -08001576 atl1c_link_chg_event(adapter);
1577 break;
1578 }
1579
1580 } while (--max_ints > 0);
1581 /* re-enable Interrupt*/
1582 AT_WRITE_REG(&adapter->hw, REG_ISR, 0);
1583 return handled;
1584}
1585
1586static inline void atl1c_rx_checksum(struct atl1c_adapter *adapter,
1587 struct sk_buff *skb, struct atl1c_recv_ret_status *prrs)
1588{
1589 /*
1590 * The pid field in RRS in not correct sometimes, so we
1591 * cannot figure out if the packet is fragmented or not,
1592 * so we tell the KERNEL CHECKSUM_NONE
1593 */
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001594 skb_checksum_none_assert(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001595}
1596
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001597static int atl1c_alloc_rx_buffer(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08001598{
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001599 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001600 struct pci_dev *pdev = adapter->pdev;
1601 struct atl1c_buffer *buffer_info, *next_info;
1602 struct sk_buff *skb;
1603 void *vir_addr = NULL;
1604 u16 num_alloc = 0;
1605 u16 rfd_next_to_use, next_next;
1606 struct atl1c_rx_free_desc *rfd_desc;
1607
1608 next_next = rfd_next_to_use = rfd_ring->next_to_use;
1609 if (++next_next == rfd_ring->count)
1610 next_next = 0;
1611 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1612 next_info = &rfd_ring->buffer_info[next_next];
1613
Jie Yangc6060be2009-11-06 00:32:05 -08001614 while (next_info->flags & ATL1C_BUFFER_FREE) {
Jie Yang43250dd2009-02-18 17:24:15 -08001615 rfd_desc = ATL1C_RFD_DESC(rfd_ring, rfd_next_to_use);
1616
Pradeep A Dalvi1d266432012-02-05 02:49:09 +00001617 skb = netdev_alloc_skb(adapter->netdev, adapter->rx_buffer_len);
Jie Yang43250dd2009-02-18 17:24:15 -08001618 if (unlikely(!skb)) {
1619 if (netif_msg_rx_err(adapter))
1620 dev_warn(&pdev->dev, "alloc rx buffer failed\n");
1621 break;
1622 }
1623
1624 /*
1625 * Make buffer alignment 2 beyond a 16 byte boundary
1626 * this will result in a 16 byte aligned IP header after
1627 * the 14 byte MAC header is removed
1628 */
1629 vir_addr = skb->data;
Jie Yangc6060be2009-11-06 00:32:05 -08001630 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang43250dd2009-02-18 17:24:15 -08001631 buffer_info->skb = skb;
1632 buffer_info->length = adapter->rx_buffer_len;
1633 buffer_info->dma = pci_map_single(pdev, vir_addr,
1634 buffer_info->length,
1635 PCI_DMA_FROMDEVICE);
Jie Yang4b45e342009-12-06 22:56:59 +00001636 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
1637 ATL1C_PCIMAP_FROMDEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08001638 rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
1639 rfd_next_to_use = next_next;
1640 if (++next_next == rfd_ring->count)
1641 next_next = 0;
1642 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1643 next_info = &rfd_ring->buffer_info[next_next];
1644 num_alloc++;
1645 }
1646
1647 if (num_alloc) {
1648 /* TODO: update mailbox here */
1649 wmb();
1650 rfd_ring->next_to_use = rfd_next_to_use;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001651 AT_WRITE_REG(&adapter->hw, REG_MB_RFD0_PROD_IDX,
Jie Yang43250dd2009-02-18 17:24:15 -08001652 rfd_ring->next_to_use & MB_RFDX_PROD_IDX_MASK);
1653 }
1654
1655 return num_alloc;
1656}
1657
1658static void atl1c_clean_rrd(struct atl1c_rrd_ring *rrd_ring,
1659 struct atl1c_recv_ret_status *rrs, u16 num)
1660{
1661 u16 i;
1662 /* the relationship between rrd and rfd is one map one */
1663 for (i = 0; i < num; i++, rrs = ATL1C_RRD_DESC(rrd_ring,
1664 rrd_ring->next_to_clean)) {
1665 rrs->word3 &= ~RRS_RXD_UPDATED;
1666 if (++rrd_ring->next_to_clean == rrd_ring->count)
1667 rrd_ring->next_to_clean = 0;
1668 }
1669}
1670
1671static void atl1c_clean_rfd(struct atl1c_rfd_ring *rfd_ring,
1672 struct atl1c_recv_ret_status *rrs, u16 num)
1673{
1674 u16 i;
1675 u16 rfd_index;
1676 struct atl1c_buffer *buffer_info = rfd_ring->buffer_info;
1677
1678 rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) &
1679 RRS_RX_RFD_INDEX_MASK;
1680 for (i = 0; i < num; i++) {
1681 buffer_info[rfd_index].skb = NULL;
Jie Yangc6060be2009-11-06 00:32:05 -08001682 ATL1C_SET_BUFFER_STATE(&buffer_info[rfd_index],
1683 ATL1C_BUFFER_FREE);
Jie Yang43250dd2009-02-18 17:24:15 -08001684 if (++rfd_index == rfd_ring->count)
1685 rfd_index = 0;
1686 }
1687 rfd_ring->next_to_clean = rfd_index;
1688}
1689
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001690static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter,
Jie Yang43250dd2009-02-18 17:24:15 -08001691 int *work_done, int work_to_do)
1692{
1693 u16 rfd_num, rfd_index;
1694 u16 count = 0;
1695 u16 length;
1696 struct pci_dev *pdev = adapter->pdev;
1697 struct net_device *netdev = adapter->netdev;
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001698 struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring;
1699 struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring;
Jie Yang43250dd2009-02-18 17:24:15 -08001700 struct sk_buff *skb;
1701 struct atl1c_recv_ret_status *rrs;
1702 struct atl1c_buffer *buffer_info;
1703
1704 while (1) {
1705 if (*work_done >= work_to_do)
1706 break;
1707 rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean);
1708 if (likely(RRS_RXD_IS_VALID(rrs->word3))) {
1709 rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) &
1710 RRS_RX_RFD_CNT_MASK;
roel kluin37b76c62009-07-12 12:57:38 +00001711 if (unlikely(rfd_num != 1))
Jie Yang43250dd2009-02-18 17:24:15 -08001712 /* TODO support mul rfd*/
1713 if (netif_msg_rx_err(adapter))
1714 dev_warn(&pdev->dev,
1715 "Multi rfd not support yet!\n");
1716 goto rrs_checked;
1717 } else {
1718 break;
1719 }
1720rrs_checked:
1721 atl1c_clean_rrd(rrd_ring, rrs, rfd_num);
1722 if (rrs->word3 & (RRS_RX_ERR_SUM | RRS_802_3_LEN_ERR)) {
1723 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1724 if (netif_msg_rx_err(adapter))
1725 dev_warn(&pdev->dev,
1726 "wrong packet! rrs word3 is %x\n",
1727 rrs->word3);
1728 continue;
1729 }
1730
1731 length = le16_to_cpu((rrs->word3 >> RRS_PKT_SIZE_SHIFT) &
1732 RRS_PKT_SIZE_MASK);
1733 /* Good Receive */
1734 if (likely(rfd_num == 1)) {
1735 rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) &
1736 RRS_RX_RFD_INDEX_MASK;
1737 buffer_info = &rfd_ring->buffer_info[rfd_index];
1738 pci_unmap_single(pdev, buffer_info->dma,
1739 buffer_info->length, PCI_DMA_FROMDEVICE);
1740 skb = buffer_info->skb;
1741 } else {
1742 /* TODO */
1743 if (netif_msg_rx_err(adapter))
1744 dev_warn(&pdev->dev,
1745 "Multi rfd not support yet!\n");
1746 break;
1747 }
1748 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1749 skb_put(skb, length - ETH_FCS_LEN);
1750 skb->protocol = eth_type_trans(skb, netdev);
Jie Yang43250dd2009-02-18 17:24:15 -08001751 atl1c_rx_checksum(adapter, skb, rrs);
Jiri Pirko46facce2011-07-20 04:54:12 +00001752 if (rrs->word3 & RRS_VLAN_INS) {
Jie Yang43250dd2009-02-18 17:24:15 -08001753 u16 vlan;
1754
1755 AT_TAG_TO_VLAN(rrs->vlan_tag, vlan);
1756 vlan = le16_to_cpu(vlan);
Jiri Pirko46facce2011-07-20 04:54:12 +00001757 __vlan_hwaccel_put_tag(skb, vlan);
1758 }
1759 netif_receive_skb(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001760
Jie Yang43250dd2009-02-18 17:24:15 -08001761 (*work_done)++;
1762 count++;
1763 }
1764 if (count)
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001765 atl1c_alloc_rx_buffer(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -08001766}
1767
1768/*
1769 * atl1c_clean - NAPI Rx polling callback
1770 * @adapter: board private structure
1771 */
1772static int atl1c_clean(struct napi_struct *napi, int budget)
1773{
1774 struct atl1c_adapter *adapter =
1775 container_of(napi, struct atl1c_adapter, napi);
1776 int work_done = 0;
1777
1778 /* Keep link state information with original netdev */
1779 if (!netif_carrier_ok(adapter->netdev))
1780 goto quit_polling;
1781 /* just enable one RXQ */
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00001782 atl1c_clean_rx_irq(adapter, &work_done, budget);
Jie Yang43250dd2009-02-18 17:24:15 -08001783
1784 if (work_done < budget) {
1785quit_polling:
1786 napi_complete(napi);
1787 adapter->hw.intr_mask |= ISR_RX_PKT;
1788 AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask);
1789 }
1790 return work_done;
1791}
1792
1793#ifdef CONFIG_NET_POLL_CONTROLLER
1794
1795/*
1796 * Polling 'interrupt' - used by things like netconsole to send skbs
1797 * without having to re-enable interrupts. It's not called while
1798 * the interrupt routine is executing.
1799 */
1800static void atl1c_netpoll(struct net_device *netdev)
1801{
1802 struct atl1c_adapter *adapter = netdev_priv(netdev);
1803
1804 disable_irq(adapter->pdev->irq);
1805 atl1c_intr(adapter->pdev->irq, netdev);
1806 enable_irq(adapter->pdev->irq);
1807}
1808#endif
1809
1810static inline u16 atl1c_tpd_avail(struct atl1c_adapter *adapter, enum atl1c_trans_queue type)
1811{
1812 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
1813 u16 next_to_use = 0;
1814 u16 next_to_clean = 0;
1815
1816 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1817 next_to_use = tpd_ring->next_to_use;
1818
1819 return (u16)(next_to_clean > next_to_use) ?
1820 (next_to_clean - next_to_use - 1) :
1821 (tpd_ring->count + next_to_clean - next_to_use - 1);
1822}
1823
1824/*
1825 * get next usable tpd
1826 * Note: should call atl1c_tdp_avail to make sure
1827 * there is enough tpd to use
1828 */
1829static struct atl1c_tpd_desc *atl1c_get_tpd(struct atl1c_adapter *adapter,
1830 enum atl1c_trans_queue type)
1831{
1832 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
1833 struct atl1c_tpd_desc *tpd_desc;
1834 u16 next_to_use = 0;
1835
1836 next_to_use = tpd_ring->next_to_use;
1837 if (++tpd_ring->next_to_use == tpd_ring->count)
1838 tpd_ring->next_to_use = 0;
1839 tpd_desc = ATL1C_TPD_DESC(tpd_ring, next_to_use);
1840 memset(tpd_desc, 0, sizeof(struct atl1c_tpd_desc));
1841 return tpd_desc;
1842}
1843
1844static struct atl1c_buffer *
1845atl1c_get_tx_buffer(struct atl1c_adapter *adapter, struct atl1c_tpd_desc *tpd)
1846{
1847 struct atl1c_tpd_ring *tpd_ring = adapter->tpd_ring;
1848
1849 return &tpd_ring->buffer_info[tpd -
1850 (struct atl1c_tpd_desc *)tpd_ring->desc];
1851}
1852
1853/* Calculate the transmit packet descript needed*/
1854static u16 atl1c_cal_tpd_req(const struct sk_buff *skb)
1855{
1856 u16 tpd_req;
1857 u16 proto_hdr_len = 0;
1858
1859 tpd_req = skb_shinfo(skb)->nr_frags + 1;
1860
1861 if (skb_is_gso(skb)) {
1862 proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1863 if (proto_hdr_len < skb_headlen(skb))
1864 tpd_req++;
1865 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
1866 tpd_req++;
1867 }
1868 return tpd_req;
1869}
1870
1871static int atl1c_tso_csum(struct atl1c_adapter *adapter,
1872 struct sk_buff *skb,
1873 struct atl1c_tpd_desc **tpd,
1874 enum atl1c_trans_queue type)
1875{
1876 struct pci_dev *pdev = adapter->pdev;
1877 u8 hdr_len;
1878 u32 real_len;
1879 unsigned short offload_type;
1880 int err;
1881
1882 if (skb_is_gso(skb)) {
1883 if (skb_header_cloned(skb)) {
1884 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1885 if (unlikely(err))
1886 return -1;
1887 }
1888 offload_type = skb_shinfo(skb)->gso_type;
1889
1890 if (offload_type & SKB_GSO_TCPV4) {
1891 real_len = (((unsigned char *)ip_hdr(skb) - skb->data)
1892 + ntohs(ip_hdr(skb)->tot_len));
1893
1894 if (real_len < skb->len)
1895 pskb_trim(skb, real_len);
1896
1897 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1898 if (unlikely(skb->len == hdr_len)) {
1899 /* only xsum need */
1900 if (netif_msg_tx_queued(adapter))
1901 dev_warn(&pdev->dev,
1902 "IPV4 tso with zero data??\n");
1903 goto check_sum;
1904 } else {
1905 ip_hdr(skb)->check = 0;
1906 tcp_hdr(skb)->check = ~csum_tcpudp_magic(
1907 ip_hdr(skb)->saddr,
1908 ip_hdr(skb)->daddr,
1909 0, IPPROTO_TCP, 0);
1910 (*tpd)->word1 |= 1 << TPD_IPV4_PACKET_SHIFT;
1911 }
1912 }
1913
1914 if (offload_type & SKB_GSO_TCPV6) {
1915 struct atl1c_tpd_ext_desc *etpd =
1916 *(struct atl1c_tpd_ext_desc **)(tpd);
1917
1918 memset(etpd, 0, sizeof(struct atl1c_tpd_ext_desc));
1919 *tpd = atl1c_get_tpd(adapter, type);
1920 ipv6_hdr(skb)->payload_len = 0;
1921 /* check payload == 0 byte ? */
1922 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1923 if (unlikely(skb->len == hdr_len)) {
1924 /* only xsum need */
1925 if (netif_msg_tx_queued(adapter))
1926 dev_warn(&pdev->dev,
1927 "IPV6 tso with zero data??\n");
1928 goto check_sum;
1929 } else
1930 tcp_hdr(skb)->check = ~csum_ipv6_magic(
1931 &ipv6_hdr(skb)->saddr,
1932 &ipv6_hdr(skb)->daddr,
1933 0, IPPROTO_TCP, 0);
1934 etpd->word1 |= 1 << TPD_LSO_EN_SHIFT;
1935 etpd->word1 |= 1 << TPD_LSO_VER_SHIFT;
1936 etpd->pkt_len = cpu_to_le32(skb->len);
1937 (*tpd)->word1 |= 1 << TPD_LSO_VER_SHIFT;
1938 }
1939
1940 (*tpd)->word1 |= 1 << TPD_LSO_EN_SHIFT;
1941 (*tpd)->word1 |= (skb_transport_offset(skb) & TPD_TCPHDR_OFFSET_MASK) <<
1942 TPD_TCPHDR_OFFSET_SHIFT;
1943 (*tpd)->word1 |= (skb_shinfo(skb)->gso_size & TPD_MSS_MASK) <<
1944 TPD_MSS_SHIFT;
1945 return 0;
1946 }
1947
1948check_sum:
1949 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
1950 u8 css, cso;
Michał Mirosław0d0b1672010-12-14 15:24:08 +00001951 cso = skb_checksum_start_offset(skb);
Jie Yang43250dd2009-02-18 17:24:15 -08001952
1953 if (unlikely(cso & 0x1)) {
1954 if (netif_msg_tx_err(adapter))
1955 dev_err(&adapter->pdev->dev,
1956 "payload offset should not an event number\n");
1957 return -1;
1958 } else {
1959 css = cso + skb->csum_offset;
1960
1961 (*tpd)->word1 |= ((cso >> 1) & TPD_PLOADOFFSET_MASK) <<
1962 TPD_PLOADOFFSET_SHIFT;
1963 (*tpd)->word1 |= ((css >> 1) & TPD_CCSUM_OFFSET_MASK) <<
1964 TPD_CCSUM_OFFSET_SHIFT;
1965 (*tpd)->word1 |= 1 << TPD_CCSUM_EN_SHIFT;
1966 }
1967 }
1968 return 0;
1969}
1970
1971static void atl1c_tx_map(struct atl1c_adapter *adapter,
1972 struct sk_buff *skb, struct atl1c_tpd_desc *tpd,
1973 enum atl1c_trans_queue type)
1974{
1975 struct atl1c_tpd_desc *use_tpd = NULL;
1976 struct atl1c_buffer *buffer_info = NULL;
1977 u16 buf_len = skb_headlen(skb);
1978 u16 map_len = 0;
1979 u16 mapped_len = 0;
1980 u16 hdr_len = 0;
1981 u16 nr_frags;
1982 u16 f;
1983 int tso;
1984
1985 nr_frags = skb_shinfo(skb)->nr_frags;
1986 tso = (tpd->word1 >> TPD_LSO_EN_SHIFT) & TPD_LSO_EN_MASK;
1987 if (tso) {
1988 /* TSO */
1989 map_len = hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1990 use_tpd = tpd;
1991
1992 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
1993 buffer_info->length = map_len;
1994 buffer_info->dma = pci_map_single(adapter->pdev,
1995 skb->data, hdr_len, PCI_DMA_TODEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08001996 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00001997 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
1998 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08001999 mapped_len += map_len;
2000 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2001 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2002 }
2003
2004 if (mapped_len < buf_len) {
2005 /* mapped_len == 0, means we should use the first tpd,
2006 which is given by caller */
2007 if (mapped_len == 0)
2008 use_tpd = tpd;
2009 else {
2010 use_tpd = atl1c_get_tpd(adapter, type);
2011 memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc));
Jie Yang43250dd2009-02-18 17:24:15 -08002012 }
2013 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2014 buffer_info->length = buf_len - mapped_len;
2015 buffer_info->dma =
2016 pci_map_single(adapter->pdev, skb->data + mapped_len,
2017 buffer_info->length, PCI_DMA_TODEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08002018 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00002019 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_SINGLE,
2020 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08002021 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2022 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2023 }
2024
2025 for (f = 0; f < nr_frags; f++) {
2026 struct skb_frag_struct *frag;
2027
2028 frag = &skb_shinfo(skb)->frags[f];
2029
2030 use_tpd = atl1c_get_tpd(adapter, type);
2031 memcpy(use_tpd, tpd, sizeof(struct atl1c_tpd_desc));
2032
2033 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002034 buffer_info->length = skb_frag_size(frag);
Ian Campbell8d1bb862011-08-29 23:18:20 +00002035 buffer_info->dma = skb_frag_dma_map(&adapter->pdev->dev,
2036 frag, 0,
2037 buffer_info->length,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002038 DMA_TO_DEVICE);
Jie Yangc6060be2009-11-06 00:32:05 -08002039 ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_BUSY);
Jie Yang4b45e342009-12-06 22:56:59 +00002040 ATL1C_SET_PCIMAP_TYPE(buffer_info, ATL1C_PCIMAP_PAGE,
2041 ATL1C_PCIMAP_TODEVICE);
Jie Yang43250dd2009-02-18 17:24:15 -08002042 use_tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
2043 use_tpd->buffer_len = cpu_to_le16(buffer_info->length);
2044 }
2045
2046 /* The last tpd */
2047 use_tpd->word1 |= 1 << TPD_EOP_SHIFT;
2048 /* The last buffer info contain the skb address,
2049 so it will be free after unmap */
2050 buffer_info->skb = skb;
2051}
2052
2053static void atl1c_tx_queue(struct atl1c_adapter *adapter, struct sk_buff *skb,
2054 struct atl1c_tpd_desc *tpd, enum atl1c_trans_queue type)
2055{
2056 struct atl1c_tpd_ring *tpd_ring = &adapter->tpd_ring[type];
Huang, Xiong0af48332012-04-17 19:32:30 +00002057 u16 reg;
Jie Yang43250dd2009-02-18 17:24:15 -08002058
Huang, Xiong0af48332012-04-17 19:32:30 +00002059 reg = type == atl1c_trans_high ? REG_TPD_PRI1_PIDX : REG_TPD_PRI0_PIDX;
2060 AT_WRITE_REGW(&adapter->hw, reg, tpd_ring->next_to_use);
Jie Yang43250dd2009-02-18 17:24:15 -08002061}
2062
Stephen Hemminger613573252009-08-31 19:50:58 +00002063static netdev_tx_t atl1c_xmit_frame(struct sk_buff *skb,
2064 struct net_device *netdev)
Jie Yang43250dd2009-02-18 17:24:15 -08002065{
2066 struct atl1c_adapter *adapter = netdev_priv(netdev);
2067 unsigned long flags;
2068 u16 tpd_req = 1;
2069 struct atl1c_tpd_desc *tpd;
2070 enum atl1c_trans_queue type = atl1c_trans_normal;
2071
2072 if (test_bit(__AT_DOWN, &adapter->flags)) {
2073 dev_kfree_skb_any(skb);
2074 return NETDEV_TX_OK;
2075 }
2076
2077 tpd_req = atl1c_cal_tpd_req(skb);
2078 if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
2079 if (netif_msg_pktdata(adapter))
2080 dev_info(&adapter->pdev->dev, "tx locked\n");
2081 return NETDEV_TX_LOCKED;
2082 }
Jie Yang43250dd2009-02-18 17:24:15 -08002083
2084 if (atl1c_tpd_avail(adapter, type) < tpd_req) {
2085 /* no enough descriptor, just stop queue */
2086 netif_stop_queue(netdev);
2087 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2088 return NETDEV_TX_BUSY;
2089 }
2090
2091 tpd = atl1c_get_tpd(adapter, type);
2092
2093 /* do TSO and check sum */
2094 if (atl1c_tso_csum(adapter, skb, &tpd, type) != 0) {
2095 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2096 dev_kfree_skb_any(skb);
2097 return NETDEV_TX_OK;
2098 }
2099
Jesse Grosseab6d182010-10-20 13:56:03 +00002100 if (unlikely(vlan_tx_tag_present(skb))) {
Jie Yang43250dd2009-02-18 17:24:15 -08002101 u16 vlan = vlan_tx_tag_get(skb);
2102 __le16 tag;
2103
2104 vlan = cpu_to_le16(vlan);
2105 AT_VLAN_TO_TAG(vlan, tag);
2106 tpd->word1 |= 1 << TPD_INS_VTAG_SHIFT;
2107 tpd->vlan_tag = tag;
2108 }
2109
2110 if (skb_network_offset(skb) != ETH_HLEN)
2111 tpd->word1 |= 1 << TPD_ETH_TYPE_SHIFT; /* Ethernet frame */
2112
2113 atl1c_tx_map(adapter, skb, tpd, type);
2114 atl1c_tx_queue(adapter, skb, tpd, type);
2115
Jie Yang43250dd2009-02-18 17:24:15 -08002116 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2117 return NETDEV_TX_OK;
2118}
2119
2120static void atl1c_free_irq(struct atl1c_adapter *adapter)
2121{
2122 struct net_device *netdev = adapter->netdev;
2123
2124 free_irq(adapter->pdev->irq, netdev);
2125
2126 if (adapter->have_msi)
2127 pci_disable_msi(adapter->pdev);
2128}
2129
2130static int atl1c_request_irq(struct atl1c_adapter *adapter)
2131{
2132 struct pci_dev *pdev = adapter->pdev;
2133 struct net_device *netdev = adapter->netdev;
2134 int flags = 0;
2135 int err = 0;
2136
2137 adapter->have_msi = true;
2138 err = pci_enable_msi(adapter->pdev);
2139 if (err) {
2140 if (netif_msg_ifup(adapter))
2141 dev_err(&pdev->dev,
2142 "Unable to allocate MSI interrupt Error: %d\n",
2143 err);
2144 adapter->have_msi = false;
Francois Romieu93f7fab2012-03-09 19:22:31 +01002145 }
Jie Yang43250dd2009-02-18 17:24:15 -08002146
2147 if (!adapter->have_msi)
2148 flags |= IRQF_SHARED;
Julia Lawall9aff7e92009-11-18 10:47:03 -08002149 err = request_irq(adapter->pdev->irq, atl1c_intr, flags,
Jie Yang43250dd2009-02-18 17:24:15 -08002150 netdev->name, netdev);
2151 if (err) {
2152 if (netif_msg_ifup(adapter))
2153 dev_err(&pdev->dev,
2154 "Unable to allocate interrupt Error: %d\n",
2155 err);
2156 if (adapter->have_msi)
2157 pci_disable_msi(adapter->pdev);
2158 return err;
2159 }
2160 if (netif_msg_ifup(adapter))
2161 dev_dbg(&pdev->dev, "atl1c_request_irq OK\n");
2162 return err;
2163}
2164
stephen hemminger0fb1e542010-10-21 07:50:49 +00002165static int atl1c_up(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08002166{
2167 struct net_device *netdev = adapter->netdev;
2168 int num;
2169 int err;
Jie Yang43250dd2009-02-18 17:24:15 -08002170
2171 netif_carrier_off(netdev);
2172 atl1c_init_ring_ptrs(adapter);
2173 atl1c_set_multi(netdev);
2174 atl1c_restore_vlan(adapter);
2175
Huang, Xiong9f1fd0e2012-04-17 19:32:26 +00002176 num = atl1c_alloc_rx_buffer(adapter);
2177 if (unlikely(num == 0)) {
2178 err = -ENOMEM;
2179 goto err_alloc_rx;
Jie Yang43250dd2009-02-18 17:24:15 -08002180 }
2181
2182 if (atl1c_configure(adapter)) {
2183 err = -EIO;
2184 goto err_up;
2185 }
2186
2187 err = atl1c_request_irq(adapter);
2188 if (unlikely(err))
2189 goto err_up;
2190
2191 clear_bit(__AT_DOWN, &adapter->flags);
2192 napi_enable(&adapter->napi);
2193 atl1c_irq_enable(adapter);
2194 atl1c_check_link_status(adapter);
2195 netif_start_queue(netdev);
2196 return err;
2197
2198err_up:
2199err_alloc_rx:
2200 atl1c_clean_rx_ring(adapter);
2201 return err;
2202}
2203
stephen hemminger0fb1e542010-10-21 07:50:49 +00002204static void atl1c_down(struct atl1c_adapter *adapter)
Jie Yang43250dd2009-02-18 17:24:15 -08002205{
2206 struct net_device *netdev = adapter->netdev;
2207
2208 atl1c_del_timer(adapter);
Jie Yangcb190542009-12-06 23:16:58 +00002209 adapter->work_event = 0; /* clear all event */
Jie Yang43250dd2009-02-18 17:24:15 -08002210 /* signal that we're down so the interrupt handler does not
2211 * reschedule our watchdog timer */
2212 set_bit(__AT_DOWN, &adapter->flags);
2213 netif_carrier_off(netdev);
2214 napi_disable(&adapter->napi);
2215 atl1c_irq_disable(adapter);
2216 atl1c_free_irq(adapter);
Jie Yang43250dd2009-02-18 17:24:15 -08002217 /* reset MAC to disable all RX/TX */
2218 atl1c_reset_mac(&adapter->hw);
2219 msleep(1);
2220
2221 adapter->link_speed = SPEED_0;
2222 adapter->link_duplex = -1;
2223 atl1c_clean_tx_ring(adapter, atl1c_trans_normal);
2224 atl1c_clean_tx_ring(adapter, atl1c_trans_high);
2225 atl1c_clean_rx_ring(adapter);
2226}
2227
2228/*
2229 * atl1c_open - Called when a network interface is made active
2230 * @netdev: network interface device structure
2231 *
2232 * Returns 0 on success, negative value on failure
2233 *
2234 * The open entry point is called when a network interface is made
2235 * active by the system (IFF_UP). At this point all resources needed
2236 * for transmit and receive operations are allocated, the interrupt
2237 * handler is registered with the OS, the watchdog timer is started,
2238 * and the stack is notified that the interface is ready.
2239 */
2240static int atl1c_open(struct net_device *netdev)
2241{
2242 struct atl1c_adapter *adapter = netdev_priv(netdev);
2243 int err;
2244
2245 /* disallow open during test */
2246 if (test_bit(__AT_TESTING, &adapter->flags))
2247 return -EBUSY;
2248
2249 /* allocate rx/tx dma buffer & descriptors */
2250 err = atl1c_setup_ring_resources(adapter);
2251 if (unlikely(err))
2252 return err;
2253
2254 err = atl1c_up(adapter);
2255 if (unlikely(err))
2256 goto err_up;
2257
2258 if (adapter->hw.ctrl_flags & ATL1C_FPGA_VERSION) {
2259 u32 phy_data;
2260
2261 AT_READ_REG(&adapter->hw, REG_MDIO_CTRL, &phy_data);
2262 phy_data |= MDIO_AP_EN;
2263 AT_WRITE_REG(&adapter->hw, REG_MDIO_CTRL, phy_data);
2264 }
2265 return 0;
2266
2267err_up:
2268 atl1c_free_irq(adapter);
2269 atl1c_free_ring_resources(adapter);
2270 atl1c_reset_mac(&adapter->hw);
2271 return err;
2272}
2273
2274/*
2275 * atl1c_close - Disables a network interface
2276 * @netdev: network interface device structure
2277 *
2278 * Returns 0, this is not allowed to fail
2279 *
2280 * The close entry point is called when an interface is de-activated
2281 * by the OS. The hardware is still under the drivers control, but
2282 * needs to be disabled. A global MAC reset is issued to stop the
2283 * hardware, and all transmit and receive resources are freed.
2284 */
2285static int atl1c_close(struct net_device *netdev)
2286{
2287 struct atl1c_adapter *adapter = netdev_priv(netdev);
2288
2289 WARN_ON(test_bit(__AT_RESETTING, &adapter->flags));
2290 atl1c_down(adapter);
2291 atl1c_free_ring_resources(adapter);
2292 return 0;
2293}
2294
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002295static int atl1c_suspend(struct device *dev)
Jie Yang43250dd2009-02-18 17:24:15 -08002296{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002297 struct pci_dev *pdev = to_pci_dev(dev);
Jie Yang43250dd2009-02-18 17:24:15 -08002298 struct net_device *netdev = pci_get_drvdata(pdev);
2299 struct atl1c_adapter *adapter = netdev_priv(netdev);
2300 struct atl1c_hw *hw = &adapter->hw;
Jie Yang8f574b32010-06-01 00:28:12 -07002301 u32 mac_ctrl_data = 0;
2302 u32 master_ctrl_data = 0;
jie.yang@atheros.com55865c62009-09-20 19:01:58 +00002303 u32 wol_ctrl_data = 0;
Jie Yang8f574b32010-06-01 00:28:12 -07002304 u16 mii_intr_status_data = 0;
Jie Yang43250dd2009-02-18 17:24:15 -08002305 u32 wufc = adapter->wol;
Jie Yang43250dd2009-02-18 17:24:15 -08002306
Jie Yang8f574b32010-06-01 00:28:12 -07002307 atl1c_disable_l0s_l1(hw);
Jie Yang43250dd2009-02-18 17:24:15 -08002308 if (netif_running(netdev)) {
2309 WARN_ON(test_bit(__AT_RESETTING, &adapter->flags));
2310 atl1c_down(adapter);
2311 }
2312 netif_device_detach(netdev);
Jie Yang43250dd2009-02-18 17:24:15 -08002313
Jie Yang8f574b32010-06-01 00:28:12 -07002314 if (wufc)
2315 if (atl1c_phy_power_saving(hw) != 0)
2316 dev_dbg(&pdev->dev, "phy power saving failed");
2317
2318 AT_READ_REG(hw, REG_MASTER_CTRL, &master_ctrl_data);
2319 AT_READ_REG(hw, REG_MAC_CTRL, &mac_ctrl_data);
2320
2321 master_ctrl_data &= ~MASTER_CTRL_CLK_SEL_DIS;
2322 mac_ctrl_data &= ~(MAC_CTRL_PRMLEN_MASK << MAC_CTRL_PRMLEN_SHIFT);
2323 mac_ctrl_data |= (((u32)adapter->hw.preamble_len &
2324 MAC_CTRL_PRMLEN_MASK) <<
2325 MAC_CTRL_PRMLEN_SHIFT);
2326 mac_ctrl_data &= ~(MAC_CTRL_SPEED_MASK << MAC_CTRL_SPEED_SHIFT);
2327 mac_ctrl_data &= ~MAC_CTRL_DUPLX;
2328
2329 if (wufc) {
2330 mac_ctrl_data |= MAC_CTRL_RX_EN;
2331 if (adapter->link_speed == SPEED_1000 ||
2332 adapter->link_speed == SPEED_0) {
2333 mac_ctrl_data |= atl1c_mac_speed_1000 <<
2334 MAC_CTRL_SPEED_SHIFT;
2335 mac_ctrl_data |= MAC_CTRL_DUPLX;
2336 } else
2337 mac_ctrl_data |= atl1c_mac_speed_10_100 <<
2338 MAC_CTRL_SPEED_SHIFT;
2339
2340 if (adapter->link_duplex == DUPLEX_FULL)
2341 mac_ctrl_data |= MAC_CTRL_DUPLX;
2342
Jie Yang43250dd2009-02-18 17:24:15 -08002343 /* turn on magic packet wol */
2344 if (wufc & AT_WUFC_MAG)
Jie Yang8f574b32010-06-01 00:28:12 -07002345 wol_ctrl_data |= WOL_MAGIC_EN | WOL_MAGIC_PME_EN;
Jie Yang43250dd2009-02-18 17:24:15 -08002346
2347 if (wufc & AT_WUFC_LNKC) {
Jie Yang43250dd2009-02-18 17:24:15 -08002348 wol_ctrl_data |= WOL_LINK_CHG_EN | WOL_LINK_CHG_PME_EN;
2349 /* only link up can wake up */
2350 if (atl1c_write_phy_reg(hw, MII_IER, IER_LINK_UP) != 0) {
Jie Yang8f574b32010-06-01 00:28:12 -07002351 dev_dbg(&pdev->dev, "%s: read write phy "
2352 "register failed.\n",
2353 atl1c_driver_name);
Jie Yang43250dd2009-02-18 17:24:15 -08002354 }
2355 }
2356 /* clear phy interrupt */
2357 atl1c_read_phy_reg(hw, MII_ISR, &mii_intr_status_data);
2358 /* Config MAC Ctrl register */
Jiri Pirko46facce2011-07-20 04:54:12 +00002359 __atl1c_vlan_mode(netdev->features, &mac_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -08002360
2361 /* magic packet maybe Broadcast&multicast&Unicast frame */
2362 if (wufc & AT_WUFC_MAG)
2363 mac_ctrl_data |= MAC_CTRL_BC_EN;
2364
Jie Yang8f574b32010-06-01 00:28:12 -07002365 dev_dbg(&pdev->dev,
2366 "%s: suspend MAC=0x%x\n",
2367 atl1c_driver_name, mac_ctrl_data);
Jie Yang43250dd2009-02-18 17:24:15 -08002368 AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data);
2369 AT_WRITE_REG(hw, REG_WOL_CTRL, wol_ctrl_data);
2370 AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data);
2371
Jie Yang8f574b32010-06-01 00:28:12 -07002372 AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT |
2373 GPHY_CTRL_EXT_RESET);
Jie Yang8f574b32010-06-01 00:28:12 -07002374 } else {
2375 AT_WRITE_REG(hw, REG_GPHY_CTRL, GPHY_CTRL_POWER_SAVING);
2376 master_ctrl_data |= MASTER_CTRL_CLK_SEL_DIS;
2377 mac_ctrl_data |= atl1c_mac_speed_10_100 << MAC_CTRL_SPEED_SHIFT;
2378 mac_ctrl_data |= MAC_CTRL_DUPLX;
2379 AT_WRITE_REG(hw, REG_MASTER_CTRL, master_ctrl_data);
2380 AT_WRITE_REG(hw, REG_MAC_CTRL, mac_ctrl_data);
2381 AT_WRITE_REG(hw, REG_WOL_CTRL, 0);
2382 hw->phy_configured = false; /* re-init PHY when resume */
Jie Yang43250dd2009-02-18 17:24:15 -08002383 }
Jie Yang43250dd2009-02-18 17:24:15 -08002384
Jie Yang43250dd2009-02-18 17:24:15 -08002385 return 0;
2386}
2387
David S. Millerd187c1a2011-05-19 18:44:41 -04002388#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002389static int atl1c_resume(struct device *dev)
Jie Yang43250dd2009-02-18 17:24:15 -08002390{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002391 struct pci_dev *pdev = to_pci_dev(dev);
Jie Yang43250dd2009-02-18 17:24:15 -08002392 struct net_device *netdev = pci_get_drvdata(pdev);
2393 struct atl1c_adapter *adapter = netdev_priv(netdev);
2394
Jie Yang43250dd2009-02-18 17:24:15 -08002395 AT_WRITE_REG(&adapter->hw, REG_WOL_CTRL, 0);
Jie Yang8f574b32010-06-01 00:28:12 -07002396 atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE |
2397 ATL1C_PCIE_PHY_RESET);
Jie Yang43250dd2009-02-18 17:24:15 -08002398
2399 atl1c_phy_reset(&adapter->hw);
2400 atl1c_reset_mac(&adapter->hw);
Jie Yang8f574b32010-06-01 00:28:12 -07002401 atl1c_phy_init(&adapter->hw);
2402
2403#if 0
2404 AT_READ_REG(&adapter->hw, REG_PM_CTRLSTAT, &pm_data);
2405 pm_data &= ~PM_CTRLSTAT_PME_EN;
2406 AT_WRITE_REG(&adapter->hw, REG_PM_CTRLSTAT, pm_data);
2407#endif
2408
Jie Yang43250dd2009-02-18 17:24:15 -08002409 netif_device_attach(netdev);
2410 if (netif_running(netdev))
2411 atl1c_up(adapter);
2412
2413 return 0;
2414}
David S. Millerd187c1a2011-05-19 18:44:41 -04002415#endif
Jie Yang43250dd2009-02-18 17:24:15 -08002416
2417static void atl1c_shutdown(struct pci_dev *pdev)
2418{
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002419 struct net_device *netdev = pci_get_drvdata(pdev);
2420 struct atl1c_adapter *adapter = netdev_priv(netdev);
2421
2422 atl1c_suspend(&pdev->dev);
2423 pci_wake_from_d3(pdev, adapter->wol);
2424 pci_set_power_state(pdev, PCI_D3hot);
Jie Yang43250dd2009-02-18 17:24:15 -08002425}
2426
2427static const struct net_device_ops atl1c_netdev_ops = {
2428 .ndo_open = atl1c_open,
2429 .ndo_stop = atl1c_close,
2430 .ndo_validate_addr = eth_validate_addr,
2431 .ndo_start_xmit = atl1c_xmit_frame,
Jiri Pirko46facce2011-07-20 04:54:12 +00002432 .ndo_set_mac_address = atl1c_set_mac_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002433 .ndo_set_rx_mode = atl1c_set_multi,
Jie Yang43250dd2009-02-18 17:24:15 -08002434 .ndo_change_mtu = atl1c_change_mtu,
Michał Mirosław782d6402011-04-07 07:32:18 +00002435 .ndo_fix_features = atl1c_fix_features,
Jiri Pirko46facce2011-07-20 04:54:12 +00002436 .ndo_set_features = atl1c_set_features,
Jie Yang43250dd2009-02-18 17:24:15 -08002437 .ndo_do_ioctl = atl1c_ioctl,
2438 .ndo_tx_timeout = atl1c_tx_timeout,
2439 .ndo_get_stats = atl1c_get_stats,
Jie Yang43250dd2009-02-18 17:24:15 -08002440#ifdef CONFIG_NET_POLL_CONTROLLER
2441 .ndo_poll_controller = atl1c_netpoll,
2442#endif
2443};
2444
2445static int atl1c_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
2446{
2447 SET_NETDEV_DEV(netdev, &pdev->dev);
2448 pci_set_drvdata(pdev, netdev);
2449
Jie Yang43250dd2009-02-18 17:24:15 -08002450 netdev->netdev_ops = &atl1c_netdev_ops;
2451 netdev->watchdog_timeo = AT_TX_WATCHDOG;
2452 atl1c_set_ethtool_ops(netdev);
2453
2454 /* TODO: add when ready */
Michał Mirosław782d6402011-04-07 07:32:18 +00002455 netdev->hw_features = NETIF_F_SG |
Jie Yang43250dd2009-02-18 17:24:15 -08002456 NETIF_F_HW_CSUM |
Jiri Pirko46facce2011-07-20 04:54:12 +00002457 NETIF_F_HW_VLAN_RX |
Jie Yang43250dd2009-02-18 17:24:15 -08002458 NETIF_F_TSO |
2459 NETIF_F_TSO6;
Michał Mirosław782d6402011-04-07 07:32:18 +00002460 netdev->features = netdev->hw_features |
Jiri Pirko46facce2011-07-20 04:54:12 +00002461 NETIF_F_HW_VLAN_TX;
Jie Yang43250dd2009-02-18 17:24:15 -08002462 return 0;
2463}
2464
2465/*
2466 * atl1c_probe - Device Initialization Routine
2467 * @pdev: PCI device information struct
2468 * @ent: entry in atl1c_pci_tbl
2469 *
2470 * Returns 0 on success, negative on failure
2471 *
2472 * atl1c_probe initializes an adapter identified by a pci_dev structure.
2473 * The OS initialization, configuring of the adapter private structure,
2474 * and a hardware reset occur.
2475 */
2476static int __devinit atl1c_probe(struct pci_dev *pdev,
2477 const struct pci_device_id *ent)
2478{
2479 struct net_device *netdev;
2480 struct atl1c_adapter *adapter;
2481 static int cards_found;
2482
2483 int err = 0;
2484
2485 /* enable device (incl. PCI PM wakeup and hotplug setup) */
2486 err = pci_enable_device_mem(pdev);
2487 if (err) {
2488 dev_err(&pdev->dev, "cannot enable PCI device\n");
2489 return err;
2490 }
2491
2492 /*
2493 * The atl1c chip can DMA to 64-bit addresses, but it uses a single
2494 * shared register for the high 32 bits, so only a single, aligned,
2495 * 4 GB physical address range can be used at a time.
2496 *
2497 * Supporting 64-bit DMA on this hardware is more trouble than it's
2498 * worth. It is far easier to limit to 32-bit DMA than update
2499 * various kernel subsystems to support the mechanics required by a
2500 * fixed-high-32-bit system.
2501 */
Yang Hongyange9304382009-04-13 14:40:14 -07002502 if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
2503 (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
Jie Yang43250dd2009-02-18 17:24:15 -08002504 dev_err(&pdev->dev, "No usable DMA configuration,aborting\n");
2505 goto err_dma;
2506 }
2507
2508 err = pci_request_regions(pdev, atl1c_driver_name);
2509 if (err) {
2510 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
2511 goto err_pci_reg;
2512 }
2513
2514 pci_set_master(pdev);
2515
2516 netdev = alloc_etherdev(sizeof(struct atl1c_adapter));
2517 if (netdev == NULL) {
2518 err = -ENOMEM;
Jie Yang43250dd2009-02-18 17:24:15 -08002519 goto err_alloc_etherdev;
2520 }
2521
2522 err = atl1c_init_netdev(netdev, pdev);
2523 if (err) {
2524 dev_err(&pdev->dev, "init netdevice failed\n");
2525 goto err_init_netdev;
2526 }
2527 adapter = netdev_priv(netdev);
2528 adapter->bd_number = cards_found;
2529 adapter->netdev = netdev;
2530 adapter->pdev = pdev;
2531 adapter->hw.adapter = adapter;
2532 adapter->msg_enable = netif_msg_init(-1, atl1c_default_msg);
2533 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
2534 if (!adapter->hw.hw_addr) {
2535 err = -EIO;
2536 dev_err(&pdev->dev, "cannot map device registers\n");
2537 goto err_ioremap;
2538 }
Jie Yang43250dd2009-02-18 17:24:15 -08002539
2540 /* init mii data */
2541 adapter->mii.dev = netdev;
2542 adapter->mii.mdio_read = atl1c_mdio_read;
2543 adapter->mii.mdio_write = atl1c_mdio_write;
2544 adapter->mii.phy_id_mask = 0x1f;
2545 adapter->mii.reg_num_mask = MDIO_REG_ADDR_MASK;
2546 netif_napi_add(netdev, &adapter->napi, atl1c_clean, 64);
2547 setup_timer(&adapter->phy_config_timer, atl1c_phy_config,
2548 (unsigned long)adapter);
2549 /* setup the private structure */
2550 err = atl1c_sw_init(adapter);
2551 if (err) {
2552 dev_err(&pdev->dev, "net device private data init failed\n");
2553 goto err_sw_init;
2554 }
2555 atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE |
2556 ATL1C_PCIE_PHY_RESET);
2557
2558 /* Init GPHY as early as possible due to power saving issue */
2559 atl1c_phy_reset(&adapter->hw);
2560
2561 err = atl1c_reset_mac(&adapter->hw);
2562 if (err) {
2563 err = -EIO;
2564 goto err_reset;
2565 }
2566
Jie Yang43250dd2009-02-18 17:24:15 -08002567 /* reset the controller to
2568 * put the device in a known good starting state */
2569 err = atl1c_phy_init(&adapter->hw);
2570 if (err) {
2571 err = -EIO;
2572 goto err_reset;
2573 }
Danny Kukawka6a214fd2012-02-17 05:43:30 +00002574 if (atl1c_read_mac_addr(&adapter->hw)) {
2575 /* got a random MAC address, set NET_ADDR_RANDOM to netdev */
2576 netdev->addr_assign_type |= NET_ADDR_RANDOM;
Jie Yang43250dd2009-02-18 17:24:15 -08002577 }
2578 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
2579 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
2580 if (netif_msg_probe(adapter))
hartleys82991172010-01-05 06:54:01 +00002581 dev_dbg(&pdev->dev, "mac address : %pM\n",
2582 adapter->hw.mac_addr);
Jie Yang43250dd2009-02-18 17:24:15 -08002583
2584 atl1c_hw_set_mac_addr(&adapter->hw);
Jie Yangcb190542009-12-06 23:16:58 +00002585 INIT_WORK(&adapter->common_task, atl1c_common_task);
2586 adapter->work_event = 0;
Jie Yang43250dd2009-02-18 17:24:15 -08002587 err = register_netdev(netdev);
2588 if (err) {
2589 dev_err(&pdev->dev, "register netdevice failed\n");
2590 goto err_register;
2591 }
2592
2593 if (netif_msg_probe(adapter))
2594 dev_info(&pdev->dev, "version %s\n", ATL1C_DRV_VERSION);
2595 cards_found++;
2596 return 0;
2597
2598err_reset:
2599err_register:
2600err_sw_init:
Jie Yang43250dd2009-02-18 17:24:15 -08002601 iounmap(adapter->hw.hw_addr);
2602err_init_netdev:
2603err_ioremap:
2604 free_netdev(netdev);
2605err_alloc_etherdev:
2606 pci_release_regions(pdev);
2607err_pci_reg:
2608err_dma:
2609 pci_disable_device(pdev);
2610 return err;
2611}
2612
2613/*
2614 * atl1c_remove - Device Removal Routine
2615 * @pdev: PCI device information struct
2616 *
2617 * atl1c_remove is called by the PCI subsystem to alert the driver
2618 * that it should release a PCI device. The could be caused by a
2619 * Hot-Plug event, or because the driver is going to be removed from
2620 * memory.
2621 */
2622static void __devexit atl1c_remove(struct pci_dev *pdev)
2623{
2624 struct net_device *netdev = pci_get_drvdata(pdev);
2625 struct atl1c_adapter *adapter = netdev_priv(netdev);
2626
2627 unregister_netdev(netdev);
2628 atl1c_phy_disable(&adapter->hw);
2629
2630 iounmap(adapter->hw.hw_addr);
2631
2632 pci_release_regions(pdev);
2633 pci_disable_device(pdev);
2634 free_netdev(netdev);
2635}
2636
2637/*
2638 * atl1c_io_error_detected - called when PCI error is detected
2639 * @pdev: Pointer to PCI device
2640 * @state: The current pci connection state
2641 *
2642 * This function is called after a PCI bus error affecting
2643 * this device has been detected.
2644 */
2645static pci_ers_result_t atl1c_io_error_detected(struct pci_dev *pdev,
2646 pci_channel_state_t state)
2647{
2648 struct net_device *netdev = pci_get_drvdata(pdev);
2649 struct atl1c_adapter *adapter = netdev_priv(netdev);
2650
2651 netif_device_detach(netdev);
2652
Dean Nelson005fb4f2009-07-31 09:13:02 +00002653 if (state == pci_channel_io_perm_failure)
2654 return PCI_ERS_RESULT_DISCONNECT;
2655
Jie Yang43250dd2009-02-18 17:24:15 -08002656 if (netif_running(netdev))
2657 atl1c_down(adapter);
2658
2659 pci_disable_device(pdev);
2660
2661 /* Request a slot slot reset. */
2662 return PCI_ERS_RESULT_NEED_RESET;
2663}
2664
2665/*
2666 * atl1c_io_slot_reset - called after the pci bus has been reset.
2667 * @pdev: Pointer to PCI device
2668 *
2669 * Restart the card from scratch, as if from a cold-boot. Implementation
2670 * resembles the first-half of the e1000_resume routine.
2671 */
2672static pci_ers_result_t atl1c_io_slot_reset(struct pci_dev *pdev)
2673{
2674 struct net_device *netdev = pci_get_drvdata(pdev);
2675 struct atl1c_adapter *adapter = netdev_priv(netdev);
2676
2677 if (pci_enable_device(pdev)) {
2678 if (netif_msg_hw(adapter))
2679 dev_err(&pdev->dev,
2680 "Cannot re-enable PCI device after reset\n");
2681 return PCI_ERS_RESULT_DISCONNECT;
2682 }
2683 pci_set_master(pdev);
2684
2685 pci_enable_wake(pdev, PCI_D3hot, 0);
2686 pci_enable_wake(pdev, PCI_D3cold, 0);
2687
2688 atl1c_reset_mac(&adapter->hw);
2689
2690 return PCI_ERS_RESULT_RECOVERED;
2691}
2692
2693/*
2694 * atl1c_io_resume - called when traffic can start flowing again.
2695 * @pdev: Pointer to PCI device
2696 *
2697 * This callback is called when the error recovery driver tells us that
2698 * its OK to resume normal operation. Implementation resembles the
2699 * second-half of the atl1c_resume routine.
2700 */
2701static void atl1c_io_resume(struct pci_dev *pdev)
2702{
2703 struct net_device *netdev = pci_get_drvdata(pdev);
2704 struct atl1c_adapter *adapter = netdev_priv(netdev);
2705
2706 if (netif_running(netdev)) {
2707 if (atl1c_up(adapter)) {
2708 if (netif_msg_hw(adapter))
2709 dev_err(&pdev->dev,
2710 "Cannot bring device back up after reset\n");
2711 return;
2712 }
2713 }
2714
2715 netif_device_attach(netdev);
2716}
2717
2718static struct pci_error_handlers atl1c_err_handler = {
2719 .error_detected = atl1c_io_error_detected,
2720 .slot_reset = atl1c_io_slot_reset,
2721 .resume = atl1c_io_resume,
2722};
2723
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002724static SIMPLE_DEV_PM_OPS(atl1c_pm_ops, atl1c_suspend, atl1c_resume);
2725
Jie Yang43250dd2009-02-18 17:24:15 -08002726static struct pci_driver atl1c_driver = {
2727 .name = atl1c_driver_name,
2728 .id_table = atl1c_pci_tbl,
2729 .probe = atl1c_probe,
2730 .remove = __devexit_p(atl1c_remove),
Jie Yang43250dd2009-02-18 17:24:15 -08002731 .shutdown = atl1c_shutdown,
Rafael J. Wysocki762e3022010-12-22 03:07:52 +00002732 .err_handler = &atl1c_err_handler,
2733 .driver.pm = &atl1c_pm_ops,
Jie Yang43250dd2009-02-18 17:24:15 -08002734};
2735
2736/*
2737 * atl1c_init_module - Driver Registration Routine
2738 *
2739 * atl1c_init_module is the first routine called when the driver is
2740 * loaded. All it does is register with the PCI subsystem.
2741 */
2742static int __init atl1c_init_module(void)
2743{
2744 return pci_register_driver(&atl1c_driver);
2745}
2746
2747/*
2748 * atl1c_exit_module - Driver Exit Cleanup Routine
2749 *
2750 * atl1c_exit_module is called just before the driver is removed
2751 * from memory.
2752 */
2753static void __exit atl1c_exit_module(void)
2754{
2755 pci_unregister_driver(&atl1c_driver);
2756}
2757
2758module_init(atl1c_init_module);
2759module_exit(atl1c_exit_module);