2 * Copyright(c) 2008 - 2009 Atheros Corporation. All rights reserved.
4 * Derived from Intel e1000 driver
5 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
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)
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
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.
24 #define ATL1C_DRV_VERSION "1.0.1.0-NAPI"
25 char atl1c_driver_name
[] = "atl1c";
26 char atl1c_driver_version
[] = ATL1C_DRV_VERSION
;
29 * atl1c_pci_tbl - PCI Device ID Table
31 * Wildcard entries (PCI_ANY_ID) should come last
32 * Last entry must be all 0s
34 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
35 * Class, Class Mask, private data (not used) }
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 */
47 MODULE_DEVICE_TABLE(pci
, atl1c_pci_tbl
);
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
);
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
);
68 static const u16 atl1c_pay_load_size
[] = {
69 128, 256, 512, 1024, 2048, 4096,
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
)
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
);
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
);
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
);
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
);
118 /* FIXME: no need any more ? */
120 * atl1c_init_pcie - init PCIE module
122 static void atl1c_reset_pcie(struct atl1c_hw
*hw
, u32 flag
)
126 struct pci_dev
*pdev
= hw
->adapter
->pdev
;
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
|
133 AT_WRITE_REG(hw
, PCI_COMMAND
, pci_cmd
);
136 * Clear any PowerSaveing Settings
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);
145 * Mask some pcie error bits
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 pci_write_config_word(pdev
, pci_pcie_cap(pdev
) + PCI_EXP_DEVSTA
,
153 PCI_EXP_DEVSTA_NFED
|
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
);
162 atl1c_pcie_patch(hw
);
163 if (flag
& ATL1C_PCIE_L0S_L1_DISABLE
)
164 atl1c_disable_l0s_l1(hw
);
170 * atl1c_irq_enable - Enable default interrupt generation settings
171 * @adapter: board private structure
173 static inline void atl1c_irq_enable(struct atl1c_adapter
*adapter
)
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
);
183 * atl1c_irq_disable - Mask off interrupt generation on the NIC
184 * @adapter: board private structure
186 static inline void atl1c_irq_disable(struct atl1c_adapter
*adapter
)
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
);
196 * atl1c_irq_reset - reset interrupt confiure on the NIC
197 * @adapter: board private structure
199 static inline void atl1c_irq_reset(struct atl1c_adapter
*adapter
)
201 atomic_set(&adapter
->irq_sem
, 1);
202 atl1c_irq_enable(adapter
);
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
209 static u32
atl1c_wait_until_idle(struct atl1c_hw
*hw
, u32 modu_ctrl
)
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)
224 * atl1c_phy_config - Timer Call-back
225 * @data: pointer to netdev cast into an unsigned long
227 static void atl1c_phy_config(unsigned long data
)
229 struct atl1c_adapter
*adapter
= (struct atl1c_adapter
*) data
;
230 struct atl1c_hw
*hw
= &adapter
->hw
;
233 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
234 atl1c_restart_autoneg(hw
);
235 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
238 void atl1c_reinit_locked(struct atl1c_adapter
*adapter
)
240 WARN_ON(in_interrupt());
243 clear_bit(__AT_RESETTING
, &adapter
->flags
);
246 static void atl1c_check_link_status(struct atl1c_adapter
*adapter
)
248 struct atl1c_hw
*hw
= &adapter
->hw
;
249 struct net_device
*netdev
= adapter
->netdev
;
250 struct pci_dev
*pdev
= adapter
->pdev
;
253 u16 speed
, duplex
, phy_data
;
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
);
261 if ((phy_data
& BMSR_LSTATUS
) == 0) {
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
);
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
);
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
))
290 "%s: %s NIC Link is Up<%d Mbps %s>\n",
291 atl1c_driver_name
, netdev
->name
,
293 adapter
->link_duplex
== FULL_DUPLEX
?
294 "Full Duplex" : "Half Duplex");
296 if (!netif_carrier_ok(netdev
))
297 netif_carrier_on(netdev
);
301 static void atl1c_link_chg_event(struct atl1c_adapter
*adapter
)
303 struct net_device
*netdev
= adapter
->netdev
;
304 struct pci_dev
*pdev
= adapter
->pdev
;
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 */
315 if (netif_carrier_ok(netdev
)) {
316 /* old link state: Up */
317 netif_carrier_off(netdev
);
318 if (netif_msg_link(adapter
))
320 "%s: %s NIC Link is Down\n",
321 atl1c_driver_name
, netdev
->name
);
322 adapter
->link_speed
= SPEED_0
;
326 set_bit(ATL1C_WORK_EVENT_LINK_CHANGE
, &adapter
->work_event
);
327 schedule_work(&adapter
->common_task
);
330 static void atl1c_common_task(struct work_struct
*work
)
332 struct atl1c_adapter
*adapter
;
333 struct net_device
*netdev
;
335 adapter
= container_of(work
, struct atl1c_adapter
, common_task
);
336 netdev
= adapter
->netdev
;
338 if (test_bit(__AT_DOWN
, &adapter
->flags
))
341 if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET
, &adapter
->work_event
)) {
342 netif_device_detach(netdev
);
345 netif_device_attach(netdev
);
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
);
357 static void atl1c_del_timer(struct atl1c_adapter
*adapter
)
359 del_timer_sync(&adapter
->phy_config_timer
);
364 * atl1c_tx_timeout - Respond to a Tx Hang
365 * @netdev: network interface device structure
367 static void atl1c_tx_timeout(struct net_device
*netdev
)
369 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
371 /* Do the reset outside of interrupt context */
372 set_bit(ATL1C_WORK_EVENT_RESET
, &adapter
->work_event
);
373 schedule_work(&adapter
->common_task
);
377 * atl1c_set_multi - Multicast and Promiscuous mode set
378 * @netdev: network interface device structure
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.
385 static void atl1c_set_multi(struct net_device
*netdev
)
387 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
388 struct atl1c_hw
*hw
= &adapter
->hw
;
389 struct netdev_hw_addr
*ha
;
393 /* Check for Promiscuous and All Multicast modes */
394 AT_READ_REG(hw
, REG_MAC_CTRL
, &mac_ctrl_data
);
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
;
402 mac_ctrl_data
&= ~(MAC_CTRL_PROMIS_EN
| MAC_CTRL_MC_ALL_EN
);
405 AT_WRITE_REG(hw
, REG_MAC_CTRL
, mac_ctrl_data
);
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);
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
);
418 static void __atl1c_vlan_mode(netdev_features_t features
, u32
*mac_ctrl_data
)
420 if (features
& NETIF_F_HW_VLAN_RX
) {
421 /* enable VLAN tag insert/strip */
422 *mac_ctrl_data
|= MAC_CTRL_RMV_VLAN
;
424 /* disable VLAN tag insert/strip */
425 *mac_ctrl_data
&= ~MAC_CTRL_RMV_VLAN
;
429 static void atl1c_vlan_mode(struct net_device
*netdev
,
430 netdev_features_t features
)
432 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
433 struct pci_dev
*pdev
= adapter
->pdev
;
434 u32 mac_ctrl_data
= 0;
436 if (netif_msg_pktdata(adapter
))
437 dev_dbg(&pdev
->dev
, "atl1c_vlan_mode\n");
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
);
446 static void atl1c_restore_vlan(struct atl1c_adapter
*adapter
)
448 struct pci_dev
*pdev
= adapter
->pdev
;
450 if (netif_msg_pktdata(adapter
))
451 dev_dbg(&pdev
->dev
, "atl1c_restore_vlan\n");
452 atl1c_vlan_mode(adapter
->netdev
, adapter
->netdev
->features
);
456 * atl1c_set_mac - Change the Ethernet Address of the NIC
457 * @netdev: network interface device structure
458 * @p: pointer to an address structure
460 * Returns 0 on success, negative on failure
462 static int atl1c_set_mac_addr(struct net_device
*netdev
, void *p
)
464 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
465 struct sockaddr
*addr
= p
;
467 if (!is_valid_ether_addr(addr
->sa_data
))
468 return -EADDRNOTAVAIL
;
470 if (netif_running(netdev
))
473 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
474 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
475 netdev
->addr_assign_type
&= ~NET_ADDR_RANDOM
;
477 atl1c_hw_set_mac_addr(&adapter
->hw
, adapter
->hw
.mac_addr
);
482 static void atl1c_set_rxbufsize(struct atl1c_adapter
*adapter
,
483 struct net_device
*dev
)
487 adapter
->rx_buffer_len
= mtu
> AT_RX_BUF_SIZE
?
488 roundup(mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
, 8) : AT_RX_BUF_SIZE
;
491 static netdev_features_t
atl1c_fix_features(struct net_device
*netdev
,
492 netdev_features_t features
)
495 * Since there is no support for separate rx/tx vlan accel
496 * enable/disable make sure tx flag is always in same state as rx.
498 if (features
& NETIF_F_HW_VLAN_RX
)
499 features
|= NETIF_F_HW_VLAN_TX
;
501 features
&= ~NETIF_F_HW_VLAN_TX
;
503 if (netdev
->mtu
> MAX_TSO_FRAME_SIZE
)
504 features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
509 static int atl1c_set_features(struct net_device
*netdev
,
510 netdev_features_t features
)
512 netdev_features_t changed
= netdev
->features
^ features
;
514 if (changed
& NETIF_F_HW_VLAN_RX
)
515 atl1c_vlan_mode(netdev
, features
);
521 * atl1c_change_mtu - Change the Maximum Transfer Unit
522 * @netdev: network interface device structure
523 * @new_mtu: new value for maximum frame size
525 * Returns 0 on success, negative on failure
527 static int atl1c_change_mtu(struct net_device
*netdev
, int new_mtu
)
529 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
530 struct atl1c_hw
*hw
= &adapter
->hw
;
531 int old_mtu
= netdev
->mtu
;
532 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
534 /* Fast Ethernet controller doesn't support jumbo packet */
535 if (((hw
->nic_type
== athr_l2c
||
536 hw
->nic_type
== athr_l2c_b
||
537 hw
->nic_type
== athr_l2c_b2
) && new_mtu
> ETH_DATA_LEN
) ||
538 max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
||
539 max_frame
> MAX_JUMBO_FRAME_SIZE
) {
540 if (netif_msg_link(adapter
))
541 dev_warn(&adapter
->pdev
->dev
, "invalid MTU setting\n");
545 if (old_mtu
!= new_mtu
&& netif_running(netdev
)) {
546 while (test_and_set_bit(__AT_RESETTING
, &adapter
->flags
))
548 netdev
->mtu
= new_mtu
;
549 adapter
->hw
.max_frame_size
= new_mtu
;
550 atl1c_set_rxbufsize(adapter
, netdev
);
552 netdev_update_features(netdev
);
554 clear_bit(__AT_RESETTING
, &adapter
->flags
);
560 * caller should hold mdio_lock
562 static int atl1c_mdio_read(struct net_device
*netdev
, int phy_id
, int reg_num
)
564 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
567 atl1c_read_phy_reg(&adapter
->hw
, reg_num
, &result
);
571 static void atl1c_mdio_write(struct net_device
*netdev
, int phy_id
,
572 int reg_num
, int val
)
574 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
576 atl1c_write_phy_reg(&adapter
->hw
, reg_num
, val
);
585 static int atl1c_mii_ioctl(struct net_device
*netdev
,
586 struct ifreq
*ifr
, int cmd
)
588 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
589 struct pci_dev
*pdev
= adapter
->pdev
;
590 struct mii_ioctl_data
*data
= if_mii(ifr
);
594 if (!netif_running(netdev
))
597 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
604 if (atl1c_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
612 if (data
->reg_num
& ~(0x1F)) {
617 dev_dbg(&pdev
->dev
, "<atl1c_mii_ioctl> write %x %x",
618 data
->reg_num
, data
->val_in
);
619 if (atl1c_write_phy_reg(&adapter
->hw
,
620 data
->reg_num
, data
->val_in
)) {
627 retval
= -EOPNOTSUPP
;
631 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
641 static int atl1c_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
647 return atl1c_mii_ioctl(netdev
, ifr
, cmd
);
654 * atl1c_alloc_queues - Allocate memory for all rings
655 * @adapter: board private structure to initialize
658 static int __devinit
atl1c_alloc_queues(struct atl1c_adapter
*adapter
)
663 static void atl1c_set_mac_type(struct atl1c_hw
*hw
)
665 switch (hw
->device_id
) {
666 case PCI_DEVICE_ID_ATTANSIC_L2C
:
667 hw
->nic_type
= athr_l2c
;
669 case PCI_DEVICE_ID_ATTANSIC_L1C
:
670 hw
->nic_type
= athr_l1c
;
672 case PCI_DEVICE_ID_ATHEROS_L2C_B
:
673 hw
->nic_type
= athr_l2c_b
;
675 case PCI_DEVICE_ID_ATHEROS_L2C_B2
:
676 hw
->nic_type
= athr_l2c_b2
;
678 case PCI_DEVICE_ID_ATHEROS_L1D
:
679 hw
->nic_type
= athr_l1d
;
681 case PCI_DEVICE_ID_ATHEROS_L1D_2_0
:
682 hw
->nic_type
= athr_l1d_2
;
689 static int atl1c_setup_mac_funcs(struct atl1c_hw
*hw
)
693 atl1c_set_mac_type(hw
);
694 AT_READ_REG(hw
, REG_LINK_CTRL
, &link_ctrl_data
);
696 hw
->ctrl_flags
= ATL1C_INTR_MODRT_ENABLE
|
697 ATL1C_TXQ_MODE_ENHANCE
;
698 hw
->ctrl_flags
|= ATL1C_ASPM_L0S_SUPPORT
|
699 ATL1C_ASPM_L1_SUPPORT
;
700 hw
->ctrl_flags
|= ATL1C_ASPM_CTRL_MON
;
702 if (hw
->nic_type
== athr_l1c
||
703 hw
->nic_type
== athr_l1d
||
704 hw
->nic_type
== athr_l1d_2
)
705 hw
->link_cap_flags
|= ATL1C_LINK_CAP_1000M
;
709 struct atl1c_platform_patch
{
715 #define ATL1C_LINK_PATCH 0x1
717 static const struct atl1c_platform_patch plats
[] __devinitdata
= {
718 {0x2060, 0xC1, 0x1019, 0x8152, 0x1},
719 {0x2060, 0xC1, 0x1019, 0x2060, 0x1},
720 {0x2060, 0xC1, 0x1019, 0xE000, 0x1},
721 {0x2062, 0xC0, 0x1019, 0x8152, 0x1},
722 {0x2062, 0xC0, 0x1019, 0x2062, 0x1},
723 {0x2062, 0xC0, 0x1458, 0xE000, 0x1},
724 {0x2062, 0xC1, 0x1019, 0x8152, 0x1},
725 {0x2062, 0xC1, 0x1019, 0x2062, 0x1},
726 {0x2062, 0xC1, 0x1458, 0xE000, 0x1},
727 {0x2062, 0xC1, 0x1565, 0x2802, 0x1},
728 {0x2062, 0xC1, 0x1565, 0x2801, 0x1},
729 {0x1073, 0xC0, 0x1019, 0x8151, 0x1},
730 {0x1073, 0xC0, 0x1019, 0x1073, 0x1},
731 {0x1073, 0xC0, 0x1458, 0xE000, 0x1},
732 {0x1083, 0xC0, 0x1458, 0xE000, 0x1},
733 {0x1083, 0xC0, 0x1019, 0x8151, 0x1},
734 {0x1083, 0xC0, 0x1019, 0x1083, 0x1},
735 {0x1083, 0xC0, 0x1462, 0x7680, 0x1},
736 {0x1083, 0xC0, 0x1565, 0x2803, 0x1},
740 static void __devinit
atl1c_patch_assign(struct atl1c_hw
*hw
)
744 hw
->msi_lnkpatch
= false;
746 while (plats
[i
].pci_did
!= 0) {
747 if (plats
[i
].pci_did
== hw
->device_id
&&
748 plats
[i
].pci_revid
== hw
->revision_id
&&
749 plats
[i
].subsystem_vid
== hw
->subsystem_vendor_id
&&
750 plats
[i
].subsystem_did
== hw
->subsystem_id
) {
751 if (plats
[i
].patch_flag
& ATL1C_LINK_PATCH
)
752 hw
->msi_lnkpatch
= true;
758 * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter)
759 * @adapter: board private structure to initialize
761 * atl1c_sw_init initializes the Adapter private data structure.
762 * Fields are initialized based on PCI device information and
763 * OS network device settings (MTU size).
765 static int __devinit
atl1c_sw_init(struct atl1c_adapter
*adapter
)
767 struct atl1c_hw
*hw
= &adapter
->hw
;
768 struct pci_dev
*pdev
= adapter
->pdev
;
773 device_set_wakeup_enable(&pdev
->dev
, false);
774 adapter
->link_speed
= SPEED_0
;
775 adapter
->link_duplex
= FULL_DUPLEX
;
776 adapter
->tpd_ring
[0].count
= 1024;
777 adapter
->rfd_ring
.count
= 512;
779 hw
->vendor_id
= pdev
->vendor
;
780 hw
->device_id
= pdev
->device
;
781 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
782 hw
->subsystem_id
= pdev
->subsystem_device
;
783 AT_READ_REG(hw
, PCI_CLASS_REVISION
, &revision
);
784 hw
->revision_id
= revision
& 0xFF;
785 /* before link up, we assume hibernate is true */
786 hw
->hibernate
= true;
787 hw
->media_type
= MEDIA_TYPE_AUTO_SENSOR
;
788 if (atl1c_setup_mac_funcs(hw
) != 0) {
789 dev_err(&pdev
->dev
, "set mac function pointers failed\n");
792 atl1c_patch_assign(hw
);
794 hw
->intr_mask
= IMR_NORMAL_MASK
;
795 hw
->phy_configured
= false;
796 hw
->preamble_len
= 7;
797 hw
->max_frame_size
= adapter
->netdev
->mtu
;
798 hw
->autoneg_advertised
= ADVERTISED_Autoneg
;
799 hw
->indirect_tab
= 0xE4E4E4E4;
802 hw
->ict
= 50000; /* 100ms */
803 hw
->smb_timer
= 200000; /* 400ms */
809 hw
->dma_order
= atl1c_dma_ord_out
;
810 hw
->dmar_block
= atl1c_dma_req_1024
;
812 if (atl1c_alloc_queues(adapter
)) {
813 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
817 atl1c_set_rxbufsize(adapter
, adapter
->netdev
);
818 atomic_set(&adapter
->irq_sem
, 1);
819 spin_lock_init(&adapter
->mdio_lock
);
820 spin_lock_init(&adapter
->tx_lock
);
821 set_bit(__AT_DOWN
, &adapter
->flags
);
826 static inline void atl1c_clean_buffer(struct pci_dev
*pdev
,
827 struct atl1c_buffer
*buffer_info
, int in_irq
)
830 if (buffer_info
->flags
& ATL1C_BUFFER_FREE
)
832 if (buffer_info
->dma
) {
833 if (buffer_info
->flags
& ATL1C_PCIMAP_FROMDEVICE
)
834 pci_driection
= PCI_DMA_FROMDEVICE
;
836 pci_driection
= PCI_DMA_TODEVICE
;
838 if (buffer_info
->flags
& ATL1C_PCIMAP_SINGLE
)
839 pci_unmap_single(pdev
, buffer_info
->dma
,
840 buffer_info
->length
, pci_driection
);
841 else if (buffer_info
->flags
& ATL1C_PCIMAP_PAGE
)
842 pci_unmap_page(pdev
, buffer_info
->dma
,
843 buffer_info
->length
, pci_driection
);
845 if (buffer_info
->skb
) {
847 dev_kfree_skb_irq(buffer_info
->skb
);
849 dev_kfree_skb(buffer_info
->skb
);
851 buffer_info
->dma
= 0;
852 buffer_info
->skb
= NULL
;
853 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_FREE
);
856 * atl1c_clean_tx_ring - Free Tx-skb
857 * @adapter: board private structure
859 static void atl1c_clean_tx_ring(struct atl1c_adapter
*adapter
,
860 enum atl1c_trans_queue type
)
862 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
863 struct atl1c_buffer
*buffer_info
;
864 struct pci_dev
*pdev
= adapter
->pdev
;
865 u16 index
, ring_count
;
867 ring_count
= tpd_ring
->count
;
868 for (index
= 0; index
< ring_count
; index
++) {
869 buffer_info
= &tpd_ring
->buffer_info
[index
];
870 atl1c_clean_buffer(pdev
, buffer_info
, 0);
873 /* Zero out Tx-buffers */
874 memset(tpd_ring
->desc
, 0, sizeof(struct atl1c_tpd_desc
) *
876 atomic_set(&tpd_ring
->next_to_clean
, 0);
877 tpd_ring
->next_to_use
= 0;
881 * atl1c_clean_rx_ring - Free rx-reservation skbs
882 * @adapter: board private structure
884 static void atl1c_clean_rx_ring(struct atl1c_adapter
*adapter
)
886 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
887 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
888 struct atl1c_buffer
*buffer_info
;
889 struct pci_dev
*pdev
= adapter
->pdev
;
892 for (j
= 0; j
< rfd_ring
->count
; j
++) {
893 buffer_info
= &rfd_ring
->buffer_info
[j
];
894 atl1c_clean_buffer(pdev
, buffer_info
, 0);
896 /* zero out the descriptor ring */
897 memset(rfd_ring
->desc
, 0, rfd_ring
->size
);
898 rfd_ring
->next_to_clean
= 0;
899 rfd_ring
->next_to_use
= 0;
900 rrd_ring
->next_to_use
= 0;
901 rrd_ring
->next_to_clean
= 0;
905 * Read / Write Ptr Initialize:
907 static void atl1c_init_ring_ptrs(struct atl1c_adapter
*adapter
)
909 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
910 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
911 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
912 struct atl1c_buffer
*buffer_info
;
915 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
916 tpd_ring
[i
].next_to_use
= 0;
917 atomic_set(&tpd_ring
[i
].next_to_clean
, 0);
918 buffer_info
= tpd_ring
[i
].buffer_info
;
919 for (j
= 0; j
< tpd_ring
->count
; j
++)
920 ATL1C_SET_BUFFER_STATE(&buffer_info
[i
],
923 rfd_ring
->next_to_use
= 0;
924 rfd_ring
->next_to_clean
= 0;
925 rrd_ring
->next_to_use
= 0;
926 rrd_ring
->next_to_clean
= 0;
927 for (j
= 0; j
< rfd_ring
->count
; j
++) {
928 buffer_info
= &rfd_ring
->buffer_info
[j
];
929 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_FREE
);
934 * atl1c_free_ring_resources - Free Tx / RX descriptor Resources
935 * @adapter: board private structure
937 * Free all transmit software resources
939 static void atl1c_free_ring_resources(struct atl1c_adapter
*adapter
)
941 struct pci_dev
*pdev
= adapter
->pdev
;
943 pci_free_consistent(pdev
, adapter
->ring_header
.size
,
944 adapter
->ring_header
.desc
,
945 adapter
->ring_header
.dma
);
946 adapter
->ring_header
.desc
= NULL
;
948 /* Note: just free tdp_ring.buffer_info,
949 * it contain rfd_ring.buffer_info, do not double free */
950 if (adapter
->tpd_ring
[0].buffer_info
) {
951 kfree(adapter
->tpd_ring
[0].buffer_info
);
952 adapter
->tpd_ring
[0].buffer_info
= NULL
;
957 * atl1c_setup_mem_resources - allocate Tx / RX descriptor resources
958 * @adapter: board private structure
960 * Return 0 on success, negative on failure
962 static int atl1c_setup_ring_resources(struct atl1c_adapter
*adapter
)
964 struct pci_dev
*pdev
= adapter
->pdev
;
965 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
966 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
967 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
968 struct atl1c_ring_header
*ring_header
= &adapter
->ring_header
;
972 int rx_desc_count
= 0;
975 rrd_ring
->count
= rfd_ring
->count
;
976 for (i
= 1; i
< AT_MAX_TRANSMIT_QUEUE
; i
++)
977 tpd_ring
[i
].count
= tpd_ring
[0].count
;
979 /* 2 tpd queue, one high priority queue,
980 * another normal priority queue */
981 size
= sizeof(struct atl1c_buffer
) * (tpd_ring
->count
* 2 +
983 tpd_ring
->buffer_info
= kzalloc(size
, GFP_KERNEL
);
984 if (unlikely(!tpd_ring
->buffer_info
)) {
985 dev_err(&pdev
->dev
, "kzalloc failed, size = %d\n",
989 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
990 tpd_ring
[i
].buffer_info
=
991 (struct atl1c_buffer
*) (tpd_ring
->buffer_info
+ count
);
992 count
+= tpd_ring
[i
].count
;
995 rfd_ring
->buffer_info
=
996 (struct atl1c_buffer
*) (tpd_ring
->buffer_info
+ count
);
997 count
+= rfd_ring
->count
;
998 rx_desc_count
+= rfd_ring
->count
;
1001 * real ring DMA buffer
1002 * each ring/block may need up to 8 bytes for alignment, hence the
1003 * additional bytes tacked onto the end.
1005 ring_header
->size
= size
=
1006 sizeof(struct atl1c_tpd_desc
) * tpd_ring
->count
* 2 +
1007 sizeof(struct atl1c_rx_free_desc
) * rx_desc_count
+
1008 sizeof(struct atl1c_recv_ret_status
) * rx_desc_count
+
1011 ring_header
->desc
= pci_alloc_consistent(pdev
, ring_header
->size
,
1013 if (unlikely(!ring_header
->desc
)) {
1014 dev_err(&pdev
->dev
, "pci_alloc_consistend failed\n");
1017 memset(ring_header
->desc
, 0, ring_header
->size
);
1020 tpd_ring
[0].dma
= roundup(ring_header
->dma
, 8);
1021 offset
= tpd_ring
[0].dma
- ring_header
->dma
;
1022 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
1023 tpd_ring
[i
].dma
= ring_header
->dma
+ offset
;
1024 tpd_ring
[i
].desc
= (u8
*) ring_header
->desc
+ offset
;
1026 sizeof(struct atl1c_tpd_desc
) * tpd_ring
[i
].count
;
1027 offset
+= roundup(tpd_ring
[i
].size
, 8);
1030 rfd_ring
->dma
= ring_header
->dma
+ offset
;
1031 rfd_ring
->desc
= (u8
*) ring_header
->desc
+ offset
;
1032 rfd_ring
->size
= sizeof(struct atl1c_rx_free_desc
) * rfd_ring
->count
;
1033 offset
+= roundup(rfd_ring
->size
, 8);
1036 rrd_ring
->dma
= ring_header
->dma
+ offset
;
1037 rrd_ring
->desc
= (u8
*) ring_header
->desc
+ offset
;
1038 rrd_ring
->size
= sizeof(struct atl1c_recv_ret_status
) *
1040 offset
+= roundup(rrd_ring
->size
, 8);
1045 kfree(tpd_ring
->buffer_info
);
1049 static void atl1c_configure_des_ring(struct atl1c_adapter
*adapter
)
1051 struct atl1c_hw
*hw
= &adapter
->hw
;
1052 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1053 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1054 struct atl1c_tpd_ring
*tpd_ring
= (struct atl1c_tpd_ring
*)
1058 AT_WRITE_REG(hw
, REG_TX_BASE_ADDR_HI
,
1059 (u32
)((tpd_ring
[atl1c_trans_normal
].dma
&
1060 AT_DMA_HI_ADDR_MASK
) >> 32));
1061 /* just enable normal priority TX queue */
1062 AT_WRITE_REG(hw
, REG_TPD_PRI0_ADDR_LO
,
1063 (u32
)(tpd_ring
[atl1c_trans_normal
].dma
&
1064 AT_DMA_LO_ADDR_MASK
));
1065 AT_WRITE_REG(hw
, REG_TPD_PRI1_ADDR_LO
,
1066 (u32
)(tpd_ring
[atl1c_trans_high
].dma
&
1067 AT_DMA_LO_ADDR_MASK
));
1068 AT_WRITE_REG(hw
, REG_TPD_RING_SIZE
,
1069 (u32
)(tpd_ring
[0].count
& TPD_RING_SIZE_MASK
));
1073 AT_WRITE_REG(hw
, REG_RX_BASE_ADDR_HI
,
1074 (u32
)((rfd_ring
->dma
& AT_DMA_HI_ADDR_MASK
) >> 32));
1075 AT_WRITE_REG(hw
, REG_RFD0_HEAD_ADDR_LO
,
1076 (u32
)(rfd_ring
->dma
& AT_DMA_LO_ADDR_MASK
));
1078 AT_WRITE_REG(hw
, REG_RFD_RING_SIZE
,
1079 rfd_ring
->count
& RFD_RING_SIZE_MASK
);
1080 AT_WRITE_REG(hw
, REG_RX_BUF_SIZE
,
1081 adapter
->rx_buffer_len
& RX_BUF_SIZE_MASK
);
1084 AT_WRITE_REG(hw
, REG_RRD0_HEAD_ADDR_LO
,
1085 (u32
)(rrd_ring
->dma
& AT_DMA_LO_ADDR_MASK
));
1086 AT_WRITE_REG(hw
, REG_RRD_RING_SIZE
,
1087 (rrd_ring
->count
& RRD_RING_SIZE_MASK
));
1089 if (hw
->nic_type
== athr_l2c_b
) {
1090 AT_WRITE_REG(hw
, REG_SRAM_RXF_LEN
, 0x02a0L
);
1091 AT_WRITE_REG(hw
, REG_SRAM_TXF_LEN
, 0x0100L
);
1092 AT_WRITE_REG(hw
, REG_SRAM_RXF_ADDR
, 0x029f0000L
);
1093 AT_WRITE_REG(hw
, REG_SRAM_RFD0_INFO
, 0x02bf02a0L
);
1094 AT_WRITE_REG(hw
, REG_SRAM_TXF_ADDR
, 0x03bf02c0L
);
1095 AT_WRITE_REG(hw
, REG_SRAM_TRD_ADDR
, 0x03df03c0L
);
1096 AT_WRITE_REG(hw
, REG_TXF_WATER_MARK
, 0); /* TX watermark, to enter l1 state.*/
1097 AT_WRITE_REG(hw
, REG_RXD_DMA_CTRL
, 0); /* RXD threshold.*/
1099 /* Load all of base address above */
1100 AT_WRITE_REG(hw
, REG_LOAD_PTR
, 1);
1103 static void atl1c_configure_tx(struct atl1c_adapter
*adapter
)
1105 struct atl1c_hw
*hw
= &adapter
->hw
;
1107 u16 tx_offload_thresh
;
1110 tx_offload_thresh
= MAX_TSO_FRAME_SIZE
;
1111 AT_WRITE_REG(hw
, REG_TX_TSO_OFFLOAD_THRESH
,
1112 (tx_offload_thresh
>> 3) & TX_TSO_OFFLOAD_THRESH_MASK
);
1113 max_pay_load
= pcie_get_readrq(adapter
->pdev
) >> 8;
1114 hw
->dmar_block
= min_t(u32
, max_pay_load
, hw
->dmar_block
);
1116 * if BIOS had changed the dam-read-max-length to an invalid value,
1117 * restore it to default value
1119 if (hw
->dmar_block
< DEVICE_CTRL_MAXRRS_MIN
) {
1120 pcie_set_readrq(adapter
->pdev
, 128 << DEVICE_CTRL_MAXRRS_MIN
);
1121 hw
->dmar_block
= DEVICE_CTRL_MAXRRS_MIN
;
1124 hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l2c_b2
?
1125 L2CB_TXQ_CFGV
: L1C_TXQ_CFGV
;
1127 AT_WRITE_REG(hw
, REG_TXQ_CTRL
, txq_ctrl_data
);
1130 static void atl1c_configure_rx(struct atl1c_adapter
*adapter
)
1132 struct atl1c_hw
*hw
= &adapter
->hw
;
1135 rxq_ctrl_data
= (hw
->rfd_burst
& RXQ_RFD_BURST_NUM_MASK
) <<
1136 RXQ_RFD_BURST_NUM_SHIFT
;
1138 if (hw
->ctrl_flags
& ATL1C_RX_IPV6_CHKSUM
)
1139 rxq_ctrl_data
|= IPV6_CHKSUM_CTRL_EN
;
1141 /* aspm for gigabit */
1142 if (hw
->nic_type
!= athr_l1d_2
&& (hw
->device_id
& 1) != 0)
1143 rxq_ctrl_data
= FIELD_SETX(rxq_ctrl_data
, ASPM_THRUPUT_LIMIT
,
1144 ASPM_THRUPUT_LIMIT_100M
);
1146 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, rxq_ctrl_data
);
1149 static void atl1c_configure_dma(struct atl1c_adapter
*adapter
)
1151 struct atl1c_hw
*hw
= &adapter
->hw
;
1154 dma_ctrl_data
= FIELDX(DMA_CTRL_RORDER_MODE
, DMA_CTRL_RORDER_MODE_OUT
) |
1155 DMA_CTRL_RREQ_PRI_DATA
|
1156 FIELDX(DMA_CTRL_RREQ_BLEN
, hw
->dmar_block
) |
1157 FIELDX(DMA_CTRL_WDLY_CNT
, DMA_CTRL_WDLY_CNT_DEF
) |
1158 FIELDX(DMA_CTRL_RDLY_CNT
, DMA_CTRL_RDLY_CNT_DEF
);
1160 AT_WRITE_REG(hw
, REG_DMA_CTRL
, dma_ctrl_data
);
1164 * Stop the mac, transmit and receive units
1165 * hw - Struct containing variables accessed by shared code
1166 * return : 0 or idle status (if error)
1168 static int atl1c_stop_mac(struct atl1c_hw
*hw
)
1172 AT_READ_REG(hw
, REG_RXQ_CTRL
, &data
);
1173 data
&= ~RXQ_CTRL_EN
;
1174 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, data
);
1176 AT_READ_REG(hw
, REG_TXQ_CTRL
, &data
);
1177 data
&= ~TXQ_CTRL_EN
;
1178 AT_WRITE_REG(hw
, REG_TXQ_CTRL
, data
);
1180 atl1c_wait_until_idle(hw
, IDLE_STATUS_RXQ_BUSY
| IDLE_STATUS_TXQ_BUSY
);
1182 AT_READ_REG(hw
, REG_MAC_CTRL
, &data
);
1183 data
&= ~(MAC_CTRL_TX_EN
| MAC_CTRL_RX_EN
);
1184 AT_WRITE_REG(hw
, REG_MAC_CTRL
, data
);
1186 return (int)atl1c_wait_until_idle(hw
,
1187 IDLE_STATUS_TXMAC_BUSY
| IDLE_STATUS_RXMAC_BUSY
);
1190 static void atl1c_start_mac(struct atl1c_adapter
*adapter
)
1192 struct atl1c_hw
*hw
= &adapter
->hw
;
1195 hw
->mac_duplex
= adapter
->link_duplex
== FULL_DUPLEX
? true : false;
1196 hw
->mac_speed
= adapter
->link_speed
== SPEED_1000
?
1197 atl1c_mac_speed_1000
: atl1c_mac_speed_10_100
;
1199 AT_READ_REG(hw
, REG_TXQ_CTRL
, &txq
);
1200 AT_READ_REG(hw
, REG_RXQ_CTRL
, &rxq
);
1201 AT_READ_REG(hw
, REG_MAC_CTRL
, &mac
);
1205 mac
|= MAC_CTRL_TX_EN
| MAC_CTRL_TX_FLOW
|
1206 MAC_CTRL_RX_EN
| MAC_CTRL_RX_FLOW
|
1207 MAC_CTRL_ADD_CRC
| MAC_CTRL_PAD
|
1208 MAC_CTRL_BC_EN
| MAC_CTRL_SINGLE_PAUSE_EN
|
1209 MAC_CTRL_HASH_ALG_CRC32
;
1211 mac
|= MAC_CTRL_DUPLX
;
1213 mac
&= ~MAC_CTRL_DUPLX
;
1214 mac
= FIELD_SETX(mac
, MAC_CTRL_SPEED
, hw
->mac_speed
);
1215 mac
= FIELD_SETX(mac
, MAC_CTRL_PRMLEN
, hw
->preamble_len
);
1217 AT_WRITE_REG(hw
, REG_TXQ_CTRL
, txq
);
1218 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, rxq
);
1219 AT_WRITE_REG(hw
, REG_MAC_CTRL
, mac
);
1223 * Reset the transmit and receive units; mask and clear all interrupts.
1224 * hw - Struct containing variables accessed by shared code
1225 * return : 0 or idle status (if error)
1227 static int atl1c_reset_mac(struct atl1c_hw
*hw
)
1229 struct atl1c_adapter
*adapter
= (struct atl1c_adapter
*)hw
->adapter
;
1230 struct pci_dev
*pdev
= adapter
->pdev
;
1235 * Issue Soft Reset to the MAC. This will reset the chip's
1236 * transmit, receive, DMA. It will not effect
1237 * the current PCI configuration. The global reset bit is self-
1238 * clearing, and should clear within a microsecond.
1240 AT_READ_REG(hw
, REG_MASTER_CTRL
, &ctrl_data
);
1241 ctrl_data
|= MASTER_CTRL_OOB_DIS
;
1242 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, ctrl_data
| MASTER_CTRL_SOFT_RST
);
1246 /* Wait at least 10ms for All module to be Idle */
1248 if (atl1c_wait_until_idle(hw
, IDLE_STATUS_MASK
)) {
1250 "MAC state machine can't be idle since"
1251 " disabled for 10ms second\n");
1254 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, ctrl_data
);
1256 /* driver control speed/duplex */
1257 AT_READ_REG(hw
, REG_MAC_CTRL
, &ctrl_data
);
1258 AT_WRITE_REG(hw
, REG_MAC_CTRL
, ctrl_data
| MAC_CTRL_SPEED_MODE_SW
);
1260 /* clk switch setting */
1261 AT_READ_REG(hw
, REG_SERDES
, &ctrl_data
);
1262 switch (hw
->nic_type
) {
1264 ctrl_data
&= ~(SERDES_PHY_CLK_SLOWDOWN
|
1265 SERDES_MAC_CLK_SLOWDOWN
);
1266 AT_WRITE_REG(hw
, REG_SERDES
, ctrl_data
);
1270 ctrl_data
|= SERDES_PHY_CLK_SLOWDOWN
| SERDES_MAC_CLK_SLOWDOWN
;
1271 AT_WRITE_REG(hw
, REG_SERDES
, ctrl_data
);
1280 static void atl1c_disable_l0s_l1(struct atl1c_hw
*hw
)
1282 u16 ctrl_flags
= hw
->ctrl_flags
;
1284 hw
->ctrl_flags
&= ~(ATL1C_ASPM_L0S_SUPPORT
| ATL1C_ASPM_L1_SUPPORT
);
1285 atl1c_set_aspm(hw
, SPEED_0
);
1286 hw
->ctrl_flags
= ctrl_flags
;
1291 * Enable/disable L0s/L1 depend on link state.
1293 static void atl1c_set_aspm(struct atl1c_hw
*hw
, u16 link_speed
)
1298 AT_READ_REG(hw
, REG_PM_CTRL
, &pm_ctrl_data
);
1299 pm_ctrl_data
&= ~(PM_CTRL_ASPM_L1_EN
|
1300 PM_CTRL_ASPM_L0S_EN
|
1301 PM_CTRL_MAC_ASPM_CHK
);
1303 if (hw
->nic_type
== athr_l2c_b2
|| hw
->nic_type
== athr_l1d_2
) {
1304 pm_ctrl_data
&= ~PMCTRL_TXL1_AFTER_L0S
;
1306 link_speed
== SPEED_1000
|| link_speed
== SPEED_100
?
1307 L1D_PMCTRL_L1_ENTRY_TM_16US
: 1;
1308 pm_ctrl_data
= FIELD_SETX(pm_ctrl_data
,
1309 L1D_PMCTRL_L1_ENTRY_TM
, link_l1_timer
);
1311 link_l1_timer
= hw
->nic_type
== athr_l2c_b
?
1312 L2CB1_PM_CTRL_L1_ENTRY_TM
: L1C_PM_CTRL_L1_ENTRY_TM
;
1313 if (link_speed
!= SPEED_1000
&& link_speed
!= SPEED_100
)
1315 pm_ctrl_data
= FIELD_SETX(pm_ctrl_data
,
1316 PM_CTRL_L1_ENTRY_TIMER
, link_l1_timer
);
1320 if ((hw
->ctrl_flags
& ATL1C_ASPM_L0S_SUPPORT
) && link_speed
!= SPEED_0
)
1321 pm_ctrl_data
|= PM_CTRL_ASPM_L0S_EN
| PM_CTRL_MAC_ASPM_CHK
;
1322 if (hw
->ctrl_flags
& ATL1C_ASPM_L1_SUPPORT
)
1323 pm_ctrl_data
|= PM_CTRL_ASPM_L1_EN
| PM_CTRL_MAC_ASPM_CHK
;
1325 /* l2cb & l1d & l2cb2 & l1d2 */
1326 if (hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l1d
||
1327 hw
->nic_type
== athr_l2c_b2
|| hw
->nic_type
== athr_l1d_2
) {
1328 pm_ctrl_data
= FIELD_SETX(pm_ctrl_data
,
1329 PM_CTRL_PM_REQ_TIMER
, PM_CTRL_PM_REQ_TO_DEF
);
1330 pm_ctrl_data
|= PM_CTRL_RCVR_WT_TIMER
|
1331 PM_CTRL_SERDES_PD_EX_L1
|
1333 pm_ctrl_data
&= ~(PM_CTRL_SERDES_L1_EN
|
1334 PM_CTRL_SERDES_PLL_L1_EN
|
1335 PM_CTRL_SERDES_BUFS_RX_L1_EN
|
1338 /* disable l0s if link down or l2cb */
1339 if (link_speed
== SPEED_0
|| hw
->nic_type
== athr_l2c_b
)
1340 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1343 FIELD_SETX(pm_ctrl_data
, PM_CTRL_L1_ENTRY_TIMER
, 0);
1344 if (link_speed
!= SPEED_0
) {
1345 pm_ctrl_data
|= PM_CTRL_SERDES_L1_EN
|
1346 PM_CTRL_SERDES_PLL_L1_EN
|
1347 PM_CTRL_SERDES_BUFS_RX_L1_EN
;
1348 pm_ctrl_data
&= ~(PM_CTRL_SERDES_PD_EX_L1
|
1349 PM_CTRL_CLK_SWH_L1
|
1350 PM_CTRL_ASPM_L0S_EN
|
1351 PM_CTRL_ASPM_L1_EN
);
1352 } else { /* link down */
1353 pm_ctrl_data
|= PM_CTRL_CLK_SWH_L1
;
1354 pm_ctrl_data
&= ~(PM_CTRL_SERDES_L1_EN
|
1355 PM_CTRL_SERDES_PLL_L1_EN
|
1356 PM_CTRL_SERDES_BUFS_RX_L1_EN
|
1357 PM_CTRL_ASPM_L0S_EN
);
1360 AT_WRITE_REG(hw
, REG_PM_CTRL
, pm_ctrl_data
);
1366 * atl1c_configure - Configure Transmit&Receive Unit after Reset
1367 * @adapter: board private structure
1369 * Configure the Tx /Rx unit of the MAC after a reset.
1371 static int atl1c_configure_mac(struct atl1c_adapter
*adapter
)
1373 struct atl1c_hw
*hw
= &adapter
->hw
;
1374 u32 master_ctrl_data
= 0;
1375 u32 intr_modrt_data
;
1378 AT_READ_REG(hw
, REG_MASTER_CTRL
, &master_ctrl_data
);
1379 master_ctrl_data
&= ~(MASTER_CTRL_TX_ITIMER_EN
|
1380 MASTER_CTRL_RX_ITIMER_EN
|
1381 MASTER_CTRL_INT_RDCLR
);
1382 /* clear interrupt status */
1383 AT_WRITE_REG(hw
, REG_ISR
, 0xFFFFFFFF);
1384 /* Clear any WOL status */
1385 AT_WRITE_REG(hw
, REG_WOL_CTRL
, 0);
1386 /* set Interrupt Clear Timer
1387 * HW will enable self to assert interrupt event to system after
1388 * waiting x-time for software to notify it accept interrupt.
1391 data
= CLK_GATING_EN_ALL
;
1392 if (hw
->ctrl_flags
& ATL1C_CLK_GATING_EN
) {
1393 if (hw
->nic_type
== athr_l2c_b
)
1394 data
&= ~CLK_GATING_RXMAC_EN
;
1397 AT_WRITE_REG(hw
, REG_CLK_GATING_CTRL
, data
);
1399 AT_WRITE_REG(hw
, REG_INT_RETRIG_TIMER
,
1400 hw
->ict
& INT_RETRIG_TIMER_MASK
);
1402 atl1c_configure_des_ring(adapter
);
1404 if (hw
->ctrl_flags
& ATL1C_INTR_MODRT_ENABLE
) {
1405 intr_modrt_data
= (hw
->tx_imt
& IRQ_MODRT_TIMER_MASK
) <<
1406 IRQ_MODRT_TX_TIMER_SHIFT
;
1407 intr_modrt_data
|= (hw
->rx_imt
& IRQ_MODRT_TIMER_MASK
) <<
1408 IRQ_MODRT_RX_TIMER_SHIFT
;
1409 AT_WRITE_REG(hw
, REG_IRQ_MODRT_TIMER_INIT
, intr_modrt_data
);
1411 MASTER_CTRL_TX_ITIMER_EN
| MASTER_CTRL_RX_ITIMER_EN
;
1414 if (hw
->ctrl_flags
& ATL1C_INTR_CLEAR_ON_READ
)
1415 master_ctrl_data
|= MASTER_CTRL_INT_RDCLR
;
1417 master_ctrl_data
|= MASTER_CTRL_SA_TIMER_EN
;
1418 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, master_ctrl_data
);
1420 AT_WRITE_REG(hw
, REG_SMB_STAT_TIMER
,
1421 hw
->smb_timer
& SMB_STAT_TIMER_MASK
);
1424 AT_WRITE_REG(hw
, REG_MTU
, hw
->max_frame_size
+ ETH_HLEN
+
1425 VLAN_HLEN
+ ETH_FCS_LEN
);
1427 atl1c_configure_tx(adapter
);
1428 atl1c_configure_rx(adapter
);
1429 atl1c_configure_dma(adapter
);
1434 static int atl1c_configure(struct atl1c_adapter
*adapter
)
1436 struct net_device
*netdev
= adapter
->netdev
;
1439 atl1c_init_ring_ptrs(adapter
);
1440 atl1c_set_multi(netdev
);
1441 atl1c_restore_vlan(adapter
);
1443 num
= atl1c_alloc_rx_buffer(adapter
);
1444 if (unlikely(num
== 0))
1447 if (atl1c_configure_mac(adapter
))
1453 static void atl1c_update_hw_stats(struct atl1c_adapter
*adapter
)
1455 u16 hw_reg_addr
= 0;
1456 unsigned long *stats_item
= NULL
;
1459 /* update rx status */
1460 hw_reg_addr
= REG_MAC_RX_STATUS_BIN
;
1461 stats_item
= &adapter
->hw_stats
.rx_ok
;
1462 while (hw_reg_addr
<= REG_MAC_RX_STATUS_END
) {
1463 AT_READ_REG(&adapter
->hw
, hw_reg_addr
, &data
);
1464 *stats_item
+= data
;
1468 /* update tx status */
1469 hw_reg_addr
= REG_MAC_TX_STATUS_BIN
;
1470 stats_item
= &adapter
->hw_stats
.tx_ok
;
1471 while (hw_reg_addr
<= REG_MAC_TX_STATUS_END
) {
1472 AT_READ_REG(&adapter
->hw
, hw_reg_addr
, &data
);
1473 *stats_item
+= data
;
1480 * atl1c_get_stats - Get System Network Statistics
1481 * @netdev: network interface device structure
1483 * Returns the address of the device statistics structure.
1484 * The statistics are actually updated from the timer callback.
1486 static struct net_device_stats
*atl1c_get_stats(struct net_device
*netdev
)
1488 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1489 struct atl1c_hw_stats
*hw_stats
= &adapter
->hw_stats
;
1490 struct net_device_stats
*net_stats
= &netdev
->stats
;
1492 atl1c_update_hw_stats(adapter
);
1493 net_stats
->rx_packets
= hw_stats
->rx_ok
;
1494 net_stats
->tx_packets
= hw_stats
->tx_ok
;
1495 net_stats
->rx_bytes
= hw_stats
->rx_byte_cnt
;
1496 net_stats
->tx_bytes
= hw_stats
->tx_byte_cnt
;
1497 net_stats
->multicast
= hw_stats
->rx_mcast
;
1498 net_stats
->collisions
= hw_stats
->tx_1_col
+
1499 hw_stats
->tx_2_col
* 2 +
1500 hw_stats
->tx_late_col
+ hw_stats
->tx_abort_col
;
1501 net_stats
->rx_errors
= hw_stats
->rx_frag
+ hw_stats
->rx_fcs_err
+
1502 hw_stats
->rx_len_err
+ hw_stats
->rx_sz_ov
+
1503 hw_stats
->rx_rrd_ov
+ hw_stats
->rx_align_err
;
1504 net_stats
->rx_fifo_errors
= hw_stats
->rx_rxf_ov
;
1505 net_stats
->rx_length_errors
= hw_stats
->rx_len_err
;
1506 net_stats
->rx_crc_errors
= hw_stats
->rx_fcs_err
;
1507 net_stats
->rx_frame_errors
= hw_stats
->rx_align_err
;
1508 net_stats
->rx_over_errors
= hw_stats
->rx_rrd_ov
+ hw_stats
->rx_rxf_ov
;
1510 net_stats
->rx_missed_errors
= hw_stats
->rx_rrd_ov
+ hw_stats
->rx_rxf_ov
;
1512 net_stats
->tx_errors
= hw_stats
->tx_late_col
+ hw_stats
->tx_abort_col
+
1513 hw_stats
->tx_underrun
+ hw_stats
->tx_trunc
;
1514 net_stats
->tx_fifo_errors
= hw_stats
->tx_underrun
;
1515 net_stats
->tx_aborted_errors
= hw_stats
->tx_abort_col
;
1516 net_stats
->tx_window_errors
= hw_stats
->tx_late_col
;
1521 static inline void atl1c_clear_phy_int(struct atl1c_adapter
*adapter
)
1525 spin_lock(&adapter
->mdio_lock
);
1526 atl1c_read_phy_reg(&adapter
->hw
, MII_ISR
, &phy_data
);
1527 spin_unlock(&adapter
->mdio_lock
);
1530 static bool atl1c_clean_tx_irq(struct atl1c_adapter
*adapter
,
1531 enum atl1c_trans_queue type
)
1533 struct atl1c_tpd_ring
*tpd_ring
= (struct atl1c_tpd_ring
*)
1534 &adapter
->tpd_ring
[type
];
1535 struct atl1c_buffer
*buffer_info
;
1536 struct pci_dev
*pdev
= adapter
->pdev
;
1537 u16 next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
1538 u16 hw_next_to_clean
;
1541 reg
= type
== atl1c_trans_high
? REG_TPD_PRI1_CIDX
: REG_TPD_PRI0_CIDX
;
1543 AT_READ_REGW(&adapter
->hw
, reg
, &hw_next_to_clean
);
1545 while (next_to_clean
!= hw_next_to_clean
) {
1546 buffer_info
= &tpd_ring
->buffer_info
[next_to_clean
];
1547 atl1c_clean_buffer(pdev
, buffer_info
, 1);
1548 if (++next_to_clean
== tpd_ring
->count
)
1550 atomic_set(&tpd_ring
->next_to_clean
, next_to_clean
);
1553 if (netif_queue_stopped(adapter
->netdev
) &&
1554 netif_carrier_ok(adapter
->netdev
)) {
1555 netif_wake_queue(adapter
->netdev
);
1562 * atl1c_intr - Interrupt Handler
1563 * @irq: interrupt number
1564 * @data: pointer to a network interface device structure
1565 * @pt_regs: CPU registers structure
1567 static irqreturn_t
atl1c_intr(int irq
, void *data
)
1569 struct net_device
*netdev
= data
;
1570 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1571 struct pci_dev
*pdev
= adapter
->pdev
;
1572 struct atl1c_hw
*hw
= &adapter
->hw
;
1573 int max_ints
= AT_MAX_INT_WORK
;
1574 int handled
= IRQ_NONE
;
1579 AT_READ_REG(hw
, REG_ISR
, ®_data
);
1580 status
= reg_data
& hw
->intr_mask
;
1582 if (status
== 0 || (status
& ISR_DIS_INT
) != 0) {
1583 if (max_ints
!= AT_MAX_INT_WORK
)
1584 handled
= IRQ_HANDLED
;
1588 if (status
& ISR_GPHY
)
1589 atl1c_clear_phy_int(adapter
);
1591 AT_WRITE_REG(hw
, REG_ISR
, status
| ISR_DIS_INT
);
1592 if (status
& ISR_RX_PKT
) {
1593 if (likely(napi_schedule_prep(&adapter
->napi
))) {
1594 hw
->intr_mask
&= ~ISR_RX_PKT
;
1595 AT_WRITE_REG(hw
, REG_IMR
, hw
->intr_mask
);
1596 __napi_schedule(&adapter
->napi
);
1599 if (status
& ISR_TX_PKT
)
1600 atl1c_clean_tx_irq(adapter
, atl1c_trans_normal
);
1602 handled
= IRQ_HANDLED
;
1603 /* check if PCIE PHY Link down */
1604 if (status
& ISR_ERROR
) {
1605 if (netif_msg_hw(adapter
))
1607 "atl1c hardware error (status = 0x%x)\n",
1608 status
& ISR_ERROR
);
1610 set_bit(ATL1C_WORK_EVENT_RESET
, &adapter
->work_event
);
1611 schedule_work(&adapter
->common_task
);
1615 if (status
& ISR_OVER
)
1616 if (netif_msg_intr(adapter
))
1617 dev_warn(&pdev
->dev
,
1618 "TX/RX overflow (status = 0x%x)\n",
1622 if (status
& (ISR_GPHY
| ISR_MANUAL
)) {
1623 netdev
->stats
.tx_carrier_errors
++;
1624 atl1c_link_chg_event(adapter
);
1628 } while (--max_ints
> 0);
1629 /* re-enable Interrupt*/
1630 AT_WRITE_REG(&adapter
->hw
, REG_ISR
, 0);
1634 static inline void atl1c_rx_checksum(struct atl1c_adapter
*adapter
,
1635 struct sk_buff
*skb
, struct atl1c_recv_ret_status
*prrs
)
1638 * The pid field in RRS in not correct sometimes, so we
1639 * cannot figure out if the packet is fragmented or not,
1640 * so we tell the KERNEL CHECKSUM_NONE
1642 skb_checksum_none_assert(skb
);
1645 static int atl1c_alloc_rx_buffer(struct atl1c_adapter
*adapter
)
1647 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1648 struct pci_dev
*pdev
= adapter
->pdev
;
1649 struct atl1c_buffer
*buffer_info
, *next_info
;
1650 struct sk_buff
*skb
;
1651 void *vir_addr
= NULL
;
1653 u16 rfd_next_to_use
, next_next
;
1654 struct atl1c_rx_free_desc
*rfd_desc
;
1656 next_next
= rfd_next_to_use
= rfd_ring
->next_to_use
;
1657 if (++next_next
== rfd_ring
->count
)
1659 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1660 next_info
= &rfd_ring
->buffer_info
[next_next
];
1662 while (next_info
->flags
& ATL1C_BUFFER_FREE
) {
1663 rfd_desc
= ATL1C_RFD_DESC(rfd_ring
, rfd_next_to_use
);
1665 skb
= netdev_alloc_skb(adapter
->netdev
, adapter
->rx_buffer_len
);
1666 if (unlikely(!skb
)) {
1667 if (netif_msg_rx_err(adapter
))
1668 dev_warn(&pdev
->dev
, "alloc rx buffer failed\n");
1673 * Make buffer alignment 2 beyond a 16 byte boundary
1674 * this will result in a 16 byte aligned IP header after
1675 * the 14 byte MAC header is removed
1677 vir_addr
= skb
->data
;
1678 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
1679 buffer_info
->skb
= skb
;
1680 buffer_info
->length
= adapter
->rx_buffer_len
;
1681 buffer_info
->dma
= pci_map_single(pdev
, vir_addr
,
1682 buffer_info
->length
,
1683 PCI_DMA_FROMDEVICE
);
1684 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
1685 ATL1C_PCIMAP_FROMDEVICE
);
1686 rfd_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
1687 rfd_next_to_use
= next_next
;
1688 if (++next_next
== rfd_ring
->count
)
1690 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1691 next_info
= &rfd_ring
->buffer_info
[next_next
];
1696 /* TODO: update mailbox here */
1698 rfd_ring
->next_to_use
= rfd_next_to_use
;
1699 AT_WRITE_REG(&adapter
->hw
, REG_MB_RFD0_PROD_IDX
,
1700 rfd_ring
->next_to_use
& MB_RFDX_PROD_IDX_MASK
);
1706 static void atl1c_clean_rrd(struct atl1c_rrd_ring
*rrd_ring
,
1707 struct atl1c_recv_ret_status
*rrs
, u16 num
)
1710 /* the relationship between rrd and rfd is one map one */
1711 for (i
= 0; i
< num
; i
++, rrs
= ATL1C_RRD_DESC(rrd_ring
,
1712 rrd_ring
->next_to_clean
)) {
1713 rrs
->word3
&= ~RRS_RXD_UPDATED
;
1714 if (++rrd_ring
->next_to_clean
== rrd_ring
->count
)
1715 rrd_ring
->next_to_clean
= 0;
1719 static void atl1c_clean_rfd(struct atl1c_rfd_ring
*rfd_ring
,
1720 struct atl1c_recv_ret_status
*rrs
, u16 num
)
1724 struct atl1c_buffer
*buffer_info
= rfd_ring
->buffer_info
;
1726 rfd_index
= (rrs
->word0
>> RRS_RX_RFD_INDEX_SHIFT
) &
1727 RRS_RX_RFD_INDEX_MASK
;
1728 for (i
= 0; i
< num
; i
++) {
1729 buffer_info
[rfd_index
].skb
= NULL
;
1730 ATL1C_SET_BUFFER_STATE(&buffer_info
[rfd_index
],
1732 if (++rfd_index
== rfd_ring
->count
)
1735 rfd_ring
->next_to_clean
= rfd_index
;
1738 static void atl1c_clean_rx_irq(struct atl1c_adapter
*adapter
,
1739 int *work_done
, int work_to_do
)
1741 u16 rfd_num
, rfd_index
;
1744 struct pci_dev
*pdev
= adapter
->pdev
;
1745 struct net_device
*netdev
= adapter
->netdev
;
1746 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
;
1747 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
;
1748 struct sk_buff
*skb
;
1749 struct atl1c_recv_ret_status
*rrs
;
1750 struct atl1c_buffer
*buffer_info
;
1753 if (*work_done
>= work_to_do
)
1755 rrs
= ATL1C_RRD_DESC(rrd_ring
, rrd_ring
->next_to_clean
);
1756 if (likely(RRS_RXD_IS_VALID(rrs
->word3
))) {
1757 rfd_num
= (rrs
->word0
>> RRS_RX_RFD_CNT_SHIFT
) &
1758 RRS_RX_RFD_CNT_MASK
;
1759 if (unlikely(rfd_num
!= 1))
1760 /* TODO support mul rfd*/
1761 if (netif_msg_rx_err(adapter
))
1762 dev_warn(&pdev
->dev
,
1763 "Multi rfd not support yet!\n");
1769 atl1c_clean_rrd(rrd_ring
, rrs
, rfd_num
);
1770 if (rrs
->word3
& (RRS_RX_ERR_SUM
| RRS_802_3_LEN_ERR
)) {
1771 atl1c_clean_rfd(rfd_ring
, rrs
, rfd_num
);
1772 if (netif_msg_rx_err(adapter
))
1773 dev_warn(&pdev
->dev
,
1774 "wrong packet! rrs word3 is %x\n",
1779 length
= le16_to_cpu((rrs
->word3
>> RRS_PKT_SIZE_SHIFT
) &
1782 if (likely(rfd_num
== 1)) {
1783 rfd_index
= (rrs
->word0
>> RRS_RX_RFD_INDEX_SHIFT
) &
1784 RRS_RX_RFD_INDEX_MASK
;
1785 buffer_info
= &rfd_ring
->buffer_info
[rfd_index
];
1786 pci_unmap_single(pdev
, buffer_info
->dma
,
1787 buffer_info
->length
, PCI_DMA_FROMDEVICE
);
1788 skb
= buffer_info
->skb
;
1791 if (netif_msg_rx_err(adapter
))
1792 dev_warn(&pdev
->dev
,
1793 "Multi rfd not support yet!\n");
1796 atl1c_clean_rfd(rfd_ring
, rrs
, rfd_num
);
1797 skb_put(skb
, length
- ETH_FCS_LEN
);
1798 skb
->protocol
= eth_type_trans(skb
, netdev
);
1799 atl1c_rx_checksum(adapter
, skb
, rrs
);
1800 if (rrs
->word3
& RRS_VLAN_INS
) {
1803 AT_TAG_TO_VLAN(rrs
->vlan_tag
, vlan
);
1804 vlan
= le16_to_cpu(vlan
);
1805 __vlan_hwaccel_put_tag(skb
, vlan
);
1807 netif_receive_skb(skb
);
1813 atl1c_alloc_rx_buffer(adapter
);
1817 * atl1c_clean - NAPI Rx polling callback
1818 * @adapter: board private structure
1820 static int atl1c_clean(struct napi_struct
*napi
, int budget
)
1822 struct atl1c_adapter
*adapter
=
1823 container_of(napi
, struct atl1c_adapter
, napi
);
1826 /* Keep link state information with original netdev */
1827 if (!netif_carrier_ok(adapter
->netdev
))
1829 /* just enable one RXQ */
1830 atl1c_clean_rx_irq(adapter
, &work_done
, budget
);
1832 if (work_done
< budget
) {
1834 napi_complete(napi
);
1835 adapter
->hw
.intr_mask
|= ISR_RX_PKT
;
1836 AT_WRITE_REG(&adapter
->hw
, REG_IMR
, adapter
->hw
.intr_mask
);
1841 #ifdef CONFIG_NET_POLL_CONTROLLER
1844 * Polling 'interrupt' - used by things like netconsole to send skbs
1845 * without having to re-enable interrupts. It's not called while
1846 * the interrupt routine is executing.
1848 static void atl1c_netpoll(struct net_device
*netdev
)
1850 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1852 disable_irq(adapter
->pdev
->irq
);
1853 atl1c_intr(adapter
->pdev
->irq
, netdev
);
1854 enable_irq(adapter
->pdev
->irq
);
1858 static inline u16
atl1c_tpd_avail(struct atl1c_adapter
*adapter
, enum atl1c_trans_queue type
)
1860 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
1861 u16 next_to_use
= 0;
1862 u16 next_to_clean
= 0;
1864 next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
1865 next_to_use
= tpd_ring
->next_to_use
;
1867 return (u16
)(next_to_clean
> next_to_use
) ?
1868 (next_to_clean
- next_to_use
- 1) :
1869 (tpd_ring
->count
+ next_to_clean
- next_to_use
- 1);
1873 * get next usable tpd
1874 * Note: should call atl1c_tdp_avail to make sure
1875 * there is enough tpd to use
1877 static struct atl1c_tpd_desc
*atl1c_get_tpd(struct atl1c_adapter
*adapter
,
1878 enum atl1c_trans_queue type
)
1880 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
1881 struct atl1c_tpd_desc
*tpd_desc
;
1882 u16 next_to_use
= 0;
1884 next_to_use
= tpd_ring
->next_to_use
;
1885 if (++tpd_ring
->next_to_use
== tpd_ring
->count
)
1886 tpd_ring
->next_to_use
= 0;
1887 tpd_desc
= ATL1C_TPD_DESC(tpd_ring
, next_to_use
);
1888 memset(tpd_desc
, 0, sizeof(struct atl1c_tpd_desc
));
1892 static struct atl1c_buffer
*
1893 atl1c_get_tx_buffer(struct atl1c_adapter
*adapter
, struct atl1c_tpd_desc
*tpd
)
1895 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
1897 return &tpd_ring
->buffer_info
[tpd
-
1898 (struct atl1c_tpd_desc
*)tpd_ring
->desc
];
1901 /* Calculate the transmit packet descript needed*/
1902 static u16
atl1c_cal_tpd_req(const struct sk_buff
*skb
)
1905 u16 proto_hdr_len
= 0;
1907 tpd_req
= skb_shinfo(skb
)->nr_frags
+ 1;
1909 if (skb_is_gso(skb
)) {
1910 proto_hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1911 if (proto_hdr_len
< skb_headlen(skb
))
1913 if (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV6
)
1919 static int atl1c_tso_csum(struct atl1c_adapter
*adapter
,
1920 struct sk_buff
*skb
,
1921 struct atl1c_tpd_desc
**tpd
,
1922 enum atl1c_trans_queue type
)
1924 struct pci_dev
*pdev
= adapter
->pdev
;
1927 unsigned short offload_type
;
1930 if (skb_is_gso(skb
)) {
1931 if (skb_header_cloned(skb
)) {
1932 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
1936 offload_type
= skb_shinfo(skb
)->gso_type
;
1938 if (offload_type
& SKB_GSO_TCPV4
) {
1939 real_len
= (((unsigned char *)ip_hdr(skb
) - skb
->data
)
1940 + ntohs(ip_hdr(skb
)->tot_len
));
1942 if (real_len
< skb
->len
)
1943 pskb_trim(skb
, real_len
);
1945 hdr_len
= (skb_transport_offset(skb
) + tcp_hdrlen(skb
));
1946 if (unlikely(skb
->len
== hdr_len
)) {
1947 /* only xsum need */
1948 if (netif_msg_tx_queued(adapter
))
1949 dev_warn(&pdev
->dev
,
1950 "IPV4 tso with zero data??\n");
1953 ip_hdr(skb
)->check
= 0;
1954 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(
1958 (*tpd
)->word1
|= 1 << TPD_IPV4_PACKET_SHIFT
;
1962 if (offload_type
& SKB_GSO_TCPV6
) {
1963 struct atl1c_tpd_ext_desc
*etpd
=
1964 *(struct atl1c_tpd_ext_desc
**)(tpd
);
1966 memset(etpd
, 0, sizeof(struct atl1c_tpd_ext_desc
));
1967 *tpd
= atl1c_get_tpd(adapter
, type
);
1968 ipv6_hdr(skb
)->payload_len
= 0;
1969 /* check payload == 0 byte ? */
1970 hdr_len
= (skb_transport_offset(skb
) + tcp_hdrlen(skb
));
1971 if (unlikely(skb
->len
== hdr_len
)) {
1972 /* only xsum need */
1973 if (netif_msg_tx_queued(adapter
))
1974 dev_warn(&pdev
->dev
,
1975 "IPV6 tso with zero data??\n");
1978 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(
1979 &ipv6_hdr(skb
)->saddr
,
1980 &ipv6_hdr(skb
)->daddr
,
1982 etpd
->word1
|= 1 << TPD_LSO_EN_SHIFT
;
1983 etpd
->word1
|= 1 << TPD_LSO_VER_SHIFT
;
1984 etpd
->pkt_len
= cpu_to_le32(skb
->len
);
1985 (*tpd
)->word1
|= 1 << TPD_LSO_VER_SHIFT
;
1988 (*tpd
)->word1
|= 1 << TPD_LSO_EN_SHIFT
;
1989 (*tpd
)->word1
|= (skb_transport_offset(skb
) & TPD_TCPHDR_OFFSET_MASK
) <<
1990 TPD_TCPHDR_OFFSET_SHIFT
;
1991 (*tpd
)->word1
|= (skb_shinfo(skb
)->gso_size
& TPD_MSS_MASK
) <<
1997 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
1999 cso
= skb_checksum_start_offset(skb
);
2001 if (unlikely(cso
& 0x1)) {
2002 if (netif_msg_tx_err(adapter
))
2003 dev_err(&adapter
->pdev
->dev
,
2004 "payload offset should not an event number\n");
2007 css
= cso
+ skb
->csum_offset
;
2009 (*tpd
)->word1
|= ((cso
>> 1) & TPD_PLOADOFFSET_MASK
) <<
2010 TPD_PLOADOFFSET_SHIFT
;
2011 (*tpd
)->word1
|= ((css
>> 1) & TPD_CCSUM_OFFSET_MASK
) <<
2012 TPD_CCSUM_OFFSET_SHIFT
;
2013 (*tpd
)->word1
|= 1 << TPD_CCSUM_EN_SHIFT
;
2019 static void atl1c_tx_map(struct atl1c_adapter
*adapter
,
2020 struct sk_buff
*skb
, struct atl1c_tpd_desc
*tpd
,
2021 enum atl1c_trans_queue type
)
2023 struct atl1c_tpd_desc
*use_tpd
= NULL
;
2024 struct atl1c_buffer
*buffer_info
= NULL
;
2025 u16 buf_len
= skb_headlen(skb
);
2033 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2034 tso
= (tpd
->word1
>> TPD_LSO_EN_SHIFT
) & TPD_LSO_EN_MASK
;
2037 map_len
= hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2040 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2041 buffer_info
->length
= map_len
;
2042 buffer_info
->dma
= pci_map_single(adapter
->pdev
,
2043 skb
->data
, hdr_len
, PCI_DMA_TODEVICE
);
2044 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2045 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
2046 ATL1C_PCIMAP_TODEVICE
);
2047 mapped_len
+= map_len
;
2048 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2049 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2052 if (mapped_len
< buf_len
) {
2053 /* mapped_len == 0, means we should use the first tpd,
2054 which is given by caller */
2055 if (mapped_len
== 0)
2058 use_tpd
= atl1c_get_tpd(adapter
, type
);
2059 memcpy(use_tpd
, tpd
, sizeof(struct atl1c_tpd_desc
));
2061 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2062 buffer_info
->length
= buf_len
- mapped_len
;
2064 pci_map_single(adapter
->pdev
, skb
->data
+ mapped_len
,
2065 buffer_info
->length
, PCI_DMA_TODEVICE
);
2066 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2067 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
2068 ATL1C_PCIMAP_TODEVICE
);
2069 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2070 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2073 for (f
= 0; f
< nr_frags
; f
++) {
2074 struct skb_frag_struct
*frag
;
2076 frag
= &skb_shinfo(skb
)->frags
[f
];
2078 use_tpd
= atl1c_get_tpd(adapter
, type
);
2079 memcpy(use_tpd
, tpd
, sizeof(struct atl1c_tpd_desc
));
2081 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2082 buffer_info
->length
= skb_frag_size(frag
);
2083 buffer_info
->dma
= skb_frag_dma_map(&adapter
->pdev
->dev
,
2085 buffer_info
->length
,
2087 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2088 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_PAGE
,
2089 ATL1C_PCIMAP_TODEVICE
);
2090 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2091 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2095 use_tpd
->word1
|= 1 << TPD_EOP_SHIFT
;
2096 /* The last buffer info contain the skb address,
2097 so it will be free after unmap */
2098 buffer_info
->skb
= skb
;
2101 static void atl1c_tx_queue(struct atl1c_adapter
*adapter
, struct sk_buff
*skb
,
2102 struct atl1c_tpd_desc
*tpd
, enum atl1c_trans_queue type
)
2104 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
2107 reg
= type
== atl1c_trans_high
? REG_TPD_PRI1_PIDX
: REG_TPD_PRI0_PIDX
;
2108 AT_WRITE_REGW(&adapter
->hw
, reg
, tpd_ring
->next_to_use
);
2111 static netdev_tx_t
atl1c_xmit_frame(struct sk_buff
*skb
,
2112 struct net_device
*netdev
)
2114 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2115 unsigned long flags
;
2117 struct atl1c_tpd_desc
*tpd
;
2118 enum atl1c_trans_queue type
= atl1c_trans_normal
;
2120 if (test_bit(__AT_DOWN
, &adapter
->flags
)) {
2121 dev_kfree_skb_any(skb
);
2122 return NETDEV_TX_OK
;
2125 tpd_req
= atl1c_cal_tpd_req(skb
);
2126 if (!spin_trylock_irqsave(&adapter
->tx_lock
, flags
)) {
2127 if (netif_msg_pktdata(adapter
))
2128 dev_info(&adapter
->pdev
->dev
, "tx locked\n");
2129 return NETDEV_TX_LOCKED
;
2132 if (atl1c_tpd_avail(adapter
, type
) < tpd_req
) {
2133 /* no enough descriptor, just stop queue */
2134 netif_stop_queue(netdev
);
2135 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2136 return NETDEV_TX_BUSY
;
2139 tpd
= atl1c_get_tpd(adapter
, type
);
2141 /* do TSO and check sum */
2142 if (atl1c_tso_csum(adapter
, skb
, &tpd
, type
) != 0) {
2143 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2144 dev_kfree_skb_any(skb
);
2145 return NETDEV_TX_OK
;
2148 if (unlikely(vlan_tx_tag_present(skb
))) {
2149 u16 vlan
= vlan_tx_tag_get(skb
);
2152 vlan
= cpu_to_le16(vlan
);
2153 AT_VLAN_TO_TAG(vlan
, tag
);
2154 tpd
->word1
|= 1 << TPD_INS_VTAG_SHIFT
;
2155 tpd
->vlan_tag
= tag
;
2158 if (skb_network_offset(skb
) != ETH_HLEN
)
2159 tpd
->word1
|= 1 << TPD_ETH_TYPE_SHIFT
; /* Ethernet frame */
2161 atl1c_tx_map(adapter
, skb
, tpd
, type
);
2162 atl1c_tx_queue(adapter
, skb
, tpd
, type
);
2164 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2165 return NETDEV_TX_OK
;
2168 static void atl1c_free_irq(struct atl1c_adapter
*adapter
)
2170 struct net_device
*netdev
= adapter
->netdev
;
2172 free_irq(adapter
->pdev
->irq
, netdev
);
2174 if (adapter
->have_msi
)
2175 pci_disable_msi(adapter
->pdev
);
2178 static int atl1c_request_irq(struct atl1c_adapter
*adapter
)
2180 struct pci_dev
*pdev
= adapter
->pdev
;
2181 struct net_device
*netdev
= adapter
->netdev
;
2185 adapter
->have_msi
= true;
2186 err
= pci_enable_msi(adapter
->pdev
);
2188 if (netif_msg_ifup(adapter
))
2190 "Unable to allocate MSI interrupt Error: %d\n",
2192 adapter
->have_msi
= false;
2195 if (!adapter
->have_msi
)
2196 flags
|= IRQF_SHARED
;
2197 err
= request_irq(adapter
->pdev
->irq
, atl1c_intr
, flags
,
2198 netdev
->name
, netdev
);
2200 if (netif_msg_ifup(adapter
))
2202 "Unable to allocate interrupt Error: %d\n",
2204 if (adapter
->have_msi
)
2205 pci_disable_msi(adapter
->pdev
);
2208 if (netif_msg_ifup(adapter
))
2209 dev_dbg(&pdev
->dev
, "atl1c_request_irq OK\n");
2214 static void atl1c_reset_dma_ring(struct atl1c_adapter
*adapter
)
2216 /* release tx-pending skbs and reset tx/rx ring index */
2217 atl1c_clean_tx_ring(adapter
, atl1c_trans_normal
);
2218 atl1c_clean_tx_ring(adapter
, atl1c_trans_high
);
2219 atl1c_clean_rx_ring(adapter
);
2222 static int atl1c_up(struct atl1c_adapter
*adapter
)
2224 struct net_device
*netdev
= adapter
->netdev
;
2227 netif_carrier_off(netdev
);
2229 err
= atl1c_configure(adapter
);
2233 err
= atl1c_request_irq(adapter
);
2237 atl1c_check_link_status(adapter
);
2238 clear_bit(__AT_DOWN
, &adapter
->flags
);
2239 napi_enable(&adapter
->napi
);
2240 atl1c_irq_enable(adapter
);
2241 netif_start_queue(netdev
);
2245 atl1c_clean_rx_ring(adapter
);
2249 static void atl1c_down(struct atl1c_adapter
*adapter
)
2251 struct net_device
*netdev
= adapter
->netdev
;
2253 atl1c_del_timer(adapter
);
2254 adapter
->work_event
= 0; /* clear all event */
2255 /* signal that we're down so the interrupt handler does not
2256 * reschedule our watchdog timer */
2257 set_bit(__AT_DOWN
, &adapter
->flags
);
2258 netif_carrier_off(netdev
);
2259 napi_disable(&adapter
->napi
);
2260 atl1c_irq_disable(adapter
);
2261 atl1c_free_irq(adapter
);
2262 /* disable ASPM if device inactive */
2263 atl1c_disable_l0s_l1(&adapter
->hw
);
2264 /* reset MAC to disable all RX/TX */
2265 atl1c_reset_mac(&adapter
->hw
);
2268 adapter
->link_speed
= SPEED_0
;
2269 adapter
->link_duplex
= -1;
2270 atl1c_reset_dma_ring(adapter
);
2274 * atl1c_open - Called when a network interface is made active
2275 * @netdev: network interface device structure
2277 * Returns 0 on success, negative value on failure
2279 * The open entry point is called when a network interface is made
2280 * active by the system (IFF_UP). At this point all resources needed
2281 * for transmit and receive operations are allocated, the interrupt
2282 * handler is registered with the OS, the watchdog timer is started,
2283 * and the stack is notified that the interface is ready.
2285 static int atl1c_open(struct net_device
*netdev
)
2287 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2290 /* disallow open during test */
2291 if (test_bit(__AT_TESTING
, &adapter
->flags
))
2294 /* allocate rx/tx dma buffer & descriptors */
2295 err
= atl1c_setup_ring_resources(adapter
);
2299 err
= atl1c_up(adapter
);
2306 atl1c_free_irq(adapter
);
2307 atl1c_free_ring_resources(adapter
);
2308 atl1c_reset_mac(&adapter
->hw
);
2313 * atl1c_close - Disables a network interface
2314 * @netdev: network interface device structure
2316 * Returns 0, this is not allowed to fail
2318 * The close entry point is called when an interface is de-activated
2319 * by the OS. The hardware is still under the drivers control, but
2320 * needs to be disabled. A global MAC reset is issued to stop the
2321 * hardware, and all transmit and receive resources are freed.
2323 static int atl1c_close(struct net_device
*netdev
)
2325 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2327 WARN_ON(test_bit(__AT_RESETTING
, &adapter
->flags
));
2328 set_bit(__AT_DOWN
, &adapter
->flags
);
2329 cancel_work_sync(&adapter
->common_task
);
2330 atl1c_down(adapter
);
2331 atl1c_free_ring_resources(adapter
);
2335 static int atl1c_suspend(struct device
*dev
)
2337 struct pci_dev
*pdev
= to_pci_dev(dev
);
2338 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2339 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2340 struct atl1c_hw
*hw
= &adapter
->hw
;
2341 u32 wufc
= adapter
->wol
;
2343 atl1c_disable_l0s_l1(hw
);
2344 if (netif_running(netdev
)) {
2345 WARN_ON(test_bit(__AT_RESETTING
, &adapter
->flags
));
2346 atl1c_down(adapter
);
2348 netif_device_detach(netdev
);
2351 if (atl1c_phy_to_ps_link(hw
) != 0)
2352 dev_dbg(&pdev
->dev
, "phy power saving failed");
2354 atl1c_power_saving(hw
, wufc
);
2359 #ifdef CONFIG_PM_SLEEP
2360 static int atl1c_resume(struct device
*dev
)
2362 struct pci_dev
*pdev
= to_pci_dev(dev
);
2363 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2364 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2366 AT_WRITE_REG(&adapter
->hw
, REG_WOL_CTRL
, 0);
2367 atl1c_reset_pcie(&adapter
->hw
, ATL1C_PCIE_L0S_L1_DISABLE
);
2369 atl1c_phy_reset(&adapter
->hw
);
2370 atl1c_reset_mac(&adapter
->hw
);
2371 atl1c_phy_init(&adapter
->hw
);
2374 AT_READ_REG(&adapter
->hw
, REG_PM_CTRLSTAT
, &pm_data
);
2375 pm_data
&= ~PM_CTRLSTAT_PME_EN
;
2376 AT_WRITE_REG(&adapter
->hw
, REG_PM_CTRLSTAT
, pm_data
);
2379 netif_device_attach(netdev
);
2380 if (netif_running(netdev
))
2387 static void atl1c_shutdown(struct pci_dev
*pdev
)
2389 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2390 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2392 atl1c_suspend(&pdev
->dev
);
2393 pci_wake_from_d3(pdev
, adapter
->wol
);
2394 pci_set_power_state(pdev
, PCI_D3hot
);
2397 static const struct net_device_ops atl1c_netdev_ops
= {
2398 .ndo_open
= atl1c_open
,
2399 .ndo_stop
= atl1c_close
,
2400 .ndo_validate_addr
= eth_validate_addr
,
2401 .ndo_start_xmit
= atl1c_xmit_frame
,
2402 .ndo_set_mac_address
= atl1c_set_mac_addr
,
2403 .ndo_set_rx_mode
= atl1c_set_multi
,
2404 .ndo_change_mtu
= atl1c_change_mtu
,
2405 .ndo_fix_features
= atl1c_fix_features
,
2406 .ndo_set_features
= atl1c_set_features
,
2407 .ndo_do_ioctl
= atl1c_ioctl
,
2408 .ndo_tx_timeout
= atl1c_tx_timeout
,
2409 .ndo_get_stats
= atl1c_get_stats
,
2410 #ifdef CONFIG_NET_POLL_CONTROLLER
2411 .ndo_poll_controller
= atl1c_netpoll
,
2415 static int atl1c_init_netdev(struct net_device
*netdev
, struct pci_dev
*pdev
)
2417 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2418 pci_set_drvdata(pdev
, netdev
);
2420 netdev
->netdev_ops
= &atl1c_netdev_ops
;
2421 netdev
->watchdog_timeo
= AT_TX_WATCHDOG
;
2422 atl1c_set_ethtool_ops(netdev
);
2424 /* TODO: add when ready */
2425 netdev
->hw_features
= NETIF_F_SG
|
2427 NETIF_F_HW_VLAN_RX
|
2430 netdev
->features
= netdev
->hw_features
|
2436 * atl1c_probe - Device Initialization Routine
2437 * @pdev: PCI device information struct
2438 * @ent: entry in atl1c_pci_tbl
2440 * Returns 0 on success, negative on failure
2442 * atl1c_probe initializes an adapter identified by a pci_dev structure.
2443 * The OS initialization, configuring of the adapter private structure,
2444 * and a hardware reset occur.
2446 static int __devinit
atl1c_probe(struct pci_dev
*pdev
,
2447 const struct pci_device_id
*ent
)
2449 struct net_device
*netdev
;
2450 struct atl1c_adapter
*adapter
;
2451 static int cards_found
;
2455 /* enable device (incl. PCI PM wakeup and hotplug setup) */
2456 err
= pci_enable_device_mem(pdev
);
2458 dev_err(&pdev
->dev
, "cannot enable PCI device\n");
2463 * The atl1c chip can DMA to 64-bit addresses, but it uses a single
2464 * shared register for the high 32 bits, so only a single, aligned,
2465 * 4 GB physical address range can be used at a time.
2467 * Supporting 64-bit DMA on this hardware is more trouble than it's
2468 * worth. It is far easier to limit to 32-bit DMA than update
2469 * various kernel subsystems to support the mechanics required by a
2470 * fixed-high-32-bit system.
2472 if ((pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0) ||
2473 (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0)) {
2474 dev_err(&pdev
->dev
, "No usable DMA configuration,aborting\n");
2478 err
= pci_request_regions(pdev
, atl1c_driver_name
);
2480 dev_err(&pdev
->dev
, "cannot obtain PCI resources\n");
2484 pci_set_master(pdev
);
2486 netdev
= alloc_etherdev(sizeof(struct atl1c_adapter
));
2487 if (netdev
== NULL
) {
2489 goto err_alloc_etherdev
;
2492 err
= atl1c_init_netdev(netdev
, pdev
);
2494 dev_err(&pdev
->dev
, "init netdevice failed\n");
2495 goto err_init_netdev
;
2497 adapter
= netdev_priv(netdev
);
2498 adapter
->bd_number
= cards_found
;
2499 adapter
->netdev
= netdev
;
2500 adapter
->pdev
= pdev
;
2501 adapter
->hw
.adapter
= adapter
;
2502 adapter
->msg_enable
= netif_msg_init(-1, atl1c_default_msg
);
2503 adapter
->hw
.hw_addr
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
2504 if (!adapter
->hw
.hw_addr
) {
2506 dev_err(&pdev
->dev
, "cannot map device registers\n");
2511 adapter
->mii
.dev
= netdev
;
2512 adapter
->mii
.mdio_read
= atl1c_mdio_read
;
2513 adapter
->mii
.mdio_write
= atl1c_mdio_write
;
2514 adapter
->mii
.phy_id_mask
= 0x1f;
2515 adapter
->mii
.reg_num_mask
= MDIO_CTRL_REG_MASK
;
2516 netif_napi_add(netdev
, &adapter
->napi
, atl1c_clean
, 64);
2517 setup_timer(&adapter
->phy_config_timer
, atl1c_phy_config
,
2518 (unsigned long)adapter
);
2519 /* setup the private structure */
2520 err
= atl1c_sw_init(adapter
);
2522 dev_err(&pdev
->dev
, "net device private data init failed\n");
2525 atl1c_reset_pcie(&adapter
->hw
, ATL1C_PCIE_L0S_L1_DISABLE
);
2527 /* Init GPHY as early as possible due to power saving issue */
2528 atl1c_phy_reset(&adapter
->hw
);
2530 err
= atl1c_reset_mac(&adapter
->hw
);
2536 /* reset the controller to
2537 * put the device in a known good starting state */
2538 err
= atl1c_phy_init(&adapter
->hw
);
2543 if (atl1c_read_mac_addr(&adapter
->hw
)) {
2544 /* got a random MAC address, set NET_ADDR_RANDOM to netdev */
2545 netdev
->addr_assign_type
|= NET_ADDR_RANDOM
;
2547 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
2548 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
2549 if (netif_msg_probe(adapter
))
2550 dev_dbg(&pdev
->dev
, "mac address : %pM\n",
2551 adapter
->hw
.mac_addr
);
2553 atl1c_hw_set_mac_addr(&adapter
->hw
, adapter
->hw
.mac_addr
);
2554 INIT_WORK(&adapter
->common_task
, atl1c_common_task
);
2555 adapter
->work_event
= 0;
2556 err
= register_netdev(netdev
);
2558 dev_err(&pdev
->dev
, "register netdevice failed\n");
2562 if (netif_msg_probe(adapter
))
2563 dev_info(&pdev
->dev
, "version %s\n", ATL1C_DRV_VERSION
);
2570 iounmap(adapter
->hw
.hw_addr
);
2573 free_netdev(netdev
);
2575 pci_release_regions(pdev
);
2578 pci_disable_device(pdev
);
2583 * atl1c_remove - Device Removal Routine
2584 * @pdev: PCI device information struct
2586 * atl1c_remove is called by the PCI subsystem to alert the driver
2587 * that it should release a PCI device. The could be caused by a
2588 * Hot-Plug event, or because the driver is going to be removed from
2591 static void __devexit
atl1c_remove(struct pci_dev
*pdev
)
2593 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2594 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2596 unregister_netdev(netdev
);
2597 /* restore permanent address */
2598 atl1c_hw_set_mac_addr(&adapter
->hw
, adapter
->hw
.perm_mac_addr
);
2599 atl1c_phy_disable(&adapter
->hw
);
2601 iounmap(adapter
->hw
.hw_addr
);
2603 pci_release_regions(pdev
);
2604 pci_disable_device(pdev
);
2605 free_netdev(netdev
);
2609 * atl1c_io_error_detected - called when PCI error is detected
2610 * @pdev: Pointer to PCI device
2611 * @state: The current pci connection state
2613 * This function is called after a PCI bus error affecting
2614 * this device has been detected.
2616 static pci_ers_result_t
atl1c_io_error_detected(struct pci_dev
*pdev
,
2617 pci_channel_state_t state
)
2619 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2620 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2622 netif_device_detach(netdev
);
2624 if (state
== pci_channel_io_perm_failure
)
2625 return PCI_ERS_RESULT_DISCONNECT
;
2627 if (netif_running(netdev
))
2628 atl1c_down(adapter
);
2630 pci_disable_device(pdev
);
2632 /* Request a slot slot reset. */
2633 return PCI_ERS_RESULT_NEED_RESET
;
2637 * atl1c_io_slot_reset - called after the pci bus has been reset.
2638 * @pdev: Pointer to PCI device
2640 * Restart the card from scratch, as if from a cold-boot. Implementation
2641 * resembles the first-half of the e1000_resume routine.
2643 static pci_ers_result_t
atl1c_io_slot_reset(struct pci_dev
*pdev
)
2645 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2646 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2648 if (pci_enable_device(pdev
)) {
2649 if (netif_msg_hw(adapter
))
2651 "Cannot re-enable PCI device after reset\n");
2652 return PCI_ERS_RESULT_DISCONNECT
;
2654 pci_set_master(pdev
);
2656 pci_enable_wake(pdev
, PCI_D3hot
, 0);
2657 pci_enable_wake(pdev
, PCI_D3cold
, 0);
2659 atl1c_reset_mac(&adapter
->hw
);
2661 return PCI_ERS_RESULT_RECOVERED
;
2665 * atl1c_io_resume - called when traffic can start flowing again.
2666 * @pdev: Pointer to PCI device
2668 * This callback is called when the error recovery driver tells us that
2669 * its OK to resume normal operation. Implementation resembles the
2670 * second-half of the atl1c_resume routine.
2672 static void atl1c_io_resume(struct pci_dev
*pdev
)
2674 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2675 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2677 if (netif_running(netdev
)) {
2678 if (atl1c_up(adapter
)) {
2679 if (netif_msg_hw(adapter
))
2681 "Cannot bring device back up after reset\n");
2686 netif_device_attach(netdev
);
2689 static struct pci_error_handlers atl1c_err_handler
= {
2690 .error_detected
= atl1c_io_error_detected
,
2691 .slot_reset
= atl1c_io_slot_reset
,
2692 .resume
= atl1c_io_resume
,
2695 static SIMPLE_DEV_PM_OPS(atl1c_pm_ops
, atl1c_suspend
, atl1c_resume
);
2697 static struct pci_driver atl1c_driver
= {
2698 .name
= atl1c_driver_name
,
2699 .id_table
= atl1c_pci_tbl
,
2700 .probe
= atl1c_probe
,
2701 .remove
= __devexit_p(atl1c_remove
),
2702 .shutdown
= atl1c_shutdown
,
2703 .err_handler
= &atl1c_err_handler
,
2704 .driver
.pm
= &atl1c_pm_ops
,
2708 * atl1c_init_module - Driver Registration Routine
2710 * atl1c_init_module is the first routine called when the driver is
2711 * loaded. All it does is register with the PCI subsystem.
2713 static int __init
atl1c_init_module(void)
2715 return pci_register_driver(&atl1c_driver
);
2719 * atl1c_exit_module - Driver Exit Cleanup Routine
2721 * atl1c_exit_module is called just before the driver is removed
2724 static void __exit
atl1c_exit_module(void)
2726 pci_unregister_driver(&atl1c_driver
);
2729 module_init(atl1c_init_module
);
2730 module_exit(atl1c_exit_module
);