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