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
;
27 #define PCI_DEVICE_ID_ATTANSIC_L2C 0x1062
28 #define PCI_DEVICE_ID_ATTANSIC_L1C 0x1063
29 #define PCI_DEVICE_ID_ATHEROS_L2C_B 0x2060 /* AR8152 v1.1 Fast 10/100 */
30 #define PCI_DEVICE_ID_ATHEROS_L2C_B2 0x2062 /* AR8152 v2.0 Fast 10/100 */
31 #define PCI_DEVICE_ID_ATHEROS_L1D 0x1073 /* AR8151 v1.0 Gigabit 1000 */
32 #define PCI_DEVICE_ID_ATHEROS_L1D_2_0 0x1083 /* AR8151 v2.0 Gigabit 1000 */
37 * atl1c_pci_tbl - PCI Device ID Table
39 * Wildcard entries (PCI_ANY_ID) should come last
40 * Last entry must be all 0s
42 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
43 * Class, Class Mask, private data (not used) }
45 static DEFINE_PCI_DEVICE_TABLE(atl1c_pci_tbl
) = {
46 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATTANSIC_L1C
)},
47 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATTANSIC_L2C
)},
48 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATHEROS_L2C_B
)},
49 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATHEROS_L2C_B2
)},
50 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATHEROS_L1D
)},
51 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC
, PCI_DEVICE_ID_ATHEROS_L1D_2_0
)},
52 /* required last entry */
55 MODULE_DEVICE_TABLE(pci
, atl1c_pci_tbl
);
57 MODULE_AUTHOR("Jie Yang <jie.yang@atheros.com>");
58 MODULE_DESCRIPTION("Atheros 1000M Ethernet Network Driver");
59 MODULE_LICENSE("GPL");
60 MODULE_VERSION(ATL1C_DRV_VERSION
);
62 static int atl1c_stop_mac(struct atl1c_hw
*hw
);
63 static void atl1c_enable_rx_ctrl(struct atl1c_hw
*hw
);
64 static void atl1c_enable_tx_ctrl(struct atl1c_hw
*hw
);
65 static void atl1c_disable_l0s_l1(struct atl1c_hw
*hw
);
66 static void atl1c_set_aspm(struct atl1c_hw
*hw
, bool linkup
);
67 static void atl1c_setup_mac_ctrl(struct atl1c_adapter
*adapter
);
68 static void atl1c_clean_rx_irq(struct atl1c_adapter
*adapter
, u8 que
,
69 int *work_done
, int work_to_do
);
70 static int atl1c_up(struct atl1c_adapter
*adapter
);
71 static void atl1c_down(struct atl1c_adapter
*adapter
);
73 static const u16 atl1c_pay_load_size
[] = {
74 128, 256, 512, 1024, 2048, 4096,
77 static const u16 atl1c_rfd_prod_idx_regs
[AT_MAX_RECEIVE_QUEUE
] =
85 static const u16 atl1c_rfd_addr_lo_regs
[AT_MAX_RECEIVE_QUEUE
] =
87 REG_RFD0_HEAD_ADDR_LO
,
88 REG_RFD1_HEAD_ADDR_LO
,
89 REG_RFD2_HEAD_ADDR_LO
,
93 static const u16 atl1c_rrd_addr_lo_regs
[AT_MAX_RECEIVE_QUEUE
] =
95 REG_RRD0_HEAD_ADDR_LO
,
96 REG_RRD1_HEAD_ADDR_LO
,
97 REG_RRD2_HEAD_ADDR_LO
,
101 static const u32 atl1c_default_msg
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
102 NETIF_MSG_LINK
| NETIF_MSG_TIMER
| NETIF_MSG_IFDOWN
| NETIF_MSG_IFUP
;
103 static void atl1c_pcie_patch(struct atl1c_hw
*hw
)
107 AT_READ_REG(hw
, REG_PCIE_PHYMISC
, &data
);
108 data
|= PCIE_PHYMISC_FORCE_RCV_DET
;
109 AT_WRITE_REG(hw
, REG_PCIE_PHYMISC
, data
);
111 if (hw
->nic_type
== athr_l2c_b
&& hw
->revision_id
== L2CB_V10
) {
112 AT_READ_REG(hw
, REG_PCIE_PHYMISC2
, &data
);
114 data
&= ~(PCIE_PHYMISC2_SERDES_CDR_MASK
<<
115 PCIE_PHYMISC2_SERDES_CDR_SHIFT
);
116 data
|= 3 << PCIE_PHYMISC2_SERDES_CDR_SHIFT
;
117 data
&= ~(PCIE_PHYMISC2_SERDES_TH_MASK
<<
118 PCIE_PHYMISC2_SERDES_TH_SHIFT
);
119 data
|= 3 << PCIE_PHYMISC2_SERDES_TH_SHIFT
;
120 AT_WRITE_REG(hw
, REG_PCIE_PHYMISC2
, data
);
124 /* FIXME: no need any more ? */
126 * atl1c_init_pcie - init PCIE module
128 static void atl1c_reset_pcie(struct atl1c_hw
*hw
, u32 flag
)
132 struct pci_dev
*pdev
= hw
->adapter
->pdev
;
134 AT_READ_REG(hw
, PCI_COMMAND
, &pci_cmd
);
135 pci_cmd
&= ~PCI_COMMAND_INTX_DISABLE
;
136 pci_cmd
|= (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
|
138 AT_WRITE_REG(hw
, PCI_COMMAND
, pci_cmd
);
141 * Clear any PowerSaveing Settings
143 pci_enable_wake(pdev
, PCI_D3hot
, 0);
144 pci_enable_wake(pdev
, PCI_D3cold
, 0);
147 * Mask some pcie error bits
149 AT_READ_REG(hw
, REG_PCIE_UC_SEVERITY
, &data
);
150 data
&= ~PCIE_UC_SERVRITY_DLP
;
151 data
&= ~PCIE_UC_SERVRITY_FCP
;
152 AT_WRITE_REG(hw
, REG_PCIE_UC_SEVERITY
, data
);
154 AT_READ_REG(hw
, REG_LTSSM_ID_CTRL
, &data
);
155 data
&= ~LTSSM_ID_EN_WRO
;
156 AT_WRITE_REG(hw
, REG_LTSSM_ID_CTRL
, data
);
158 atl1c_pcie_patch(hw
);
159 if (flag
& ATL1C_PCIE_L0S_L1_DISABLE
)
160 atl1c_disable_l0s_l1(hw
);
161 if (flag
& ATL1C_PCIE_PHY_RESET
)
162 AT_WRITE_REG(hw
, REG_GPHY_CTRL
, GPHY_CTRL_DEFAULT
);
164 AT_WRITE_REG(hw
, REG_GPHY_CTRL
,
165 GPHY_CTRL_DEFAULT
| GPHY_CTRL_EXT_RESET
);
171 * atl1c_irq_enable - Enable default interrupt generation settings
172 * @adapter: board private structure
174 static inline void atl1c_irq_enable(struct atl1c_adapter
*adapter
)
176 if (likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
177 AT_WRITE_REG(&adapter
->hw
, REG_ISR
, 0x7FFFFFFF);
178 AT_WRITE_REG(&adapter
->hw
, REG_IMR
, adapter
->hw
.intr_mask
);
179 AT_WRITE_FLUSH(&adapter
->hw
);
184 * atl1c_irq_disable - Mask off interrupt generation on the NIC
185 * @adapter: board private structure
187 static inline void atl1c_irq_disable(struct atl1c_adapter
*adapter
)
189 atomic_inc(&adapter
->irq_sem
);
190 AT_WRITE_REG(&adapter
->hw
, REG_IMR
, 0);
191 AT_WRITE_REG(&adapter
->hw
, REG_ISR
, ISR_DIS_INT
);
192 AT_WRITE_FLUSH(&adapter
->hw
);
193 synchronize_irq(adapter
->pdev
->irq
);
197 * atl1c_irq_reset - reset interrupt confiure on the NIC
198 * @adapter: board private structure
200 static inline void atl1c_irq_reset(struct atl1c_adapter
*adapter
)
202 atomic_set(&adapter
->irq_sem
, 1);
203 atl1c_irq_enable(adapter
);
207 * atl1c_wait_until_idle - wait up to AT_HW_MAX_IDLE_DELAY reads
208 * of the idle status register until the device is actually idle
210 static u32
atl1c_wait_until_idle(struct atl1c_hw
*hw
)
215 for (timeout
= 0; timeout
< AT_HW_MAX_IDLE_DELAY
; timeout
++) {
216 AT_READ_REG(hw
, REG_IDLE_STATUS
, &data
);
217 if ((data
& IDLE_STATUS_MASK
) == 0)
225 * atl1c_phy_config - Timer Call-back
226 * @data: pointer to netdev cast into an unsigned long
228 static void atl1c_phy_config(unsigned long data
)
230 struct atl1c_adapter
*adapter
= (struct atl1c_adapter
*) data
;
231 struct atl1c_hw
*hw
= &adapter
->hw
;
234 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
235 atl1c_restart_autoneg(hw
);
236 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
239 void atl1c_reinit_locked(struct atl1c_adapter
*adapter
)
241 WARN_ON(in_interrupt());
244 clear_bit(__AT_RESETTING
, &adapter
->flags
);
247 static void atl1c_check_link_status(struct atl1c_adapter
*adapter
)
249 struct atl1c_hw
*hw
= &adapter
->hw
;
250 struct net_device
*netdev
= adapter
->netdev
;
251 struct pci_dev
*pdev
= adapter
->pdev
;
254 u16 speed
, duplex
, phy_data
;
256 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
257 /* MII_BMSR must read twise */
258 atl1c_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
259 atl1c_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
260 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
262 if ((phy_data
& BMSR_LSTATUS
) == 0) {
264 hw
->hibernate
= true;
265 if (atl1c_stop_mac(hw
) != 0)
266 if (netif_msg_hw(adapter
))
267 dev_warn(&pdev
->dev
, "stop mac failed\n");
268 atl1c_set_aspm(hw
, false);
269 netif_carrier_off(netdev
);
270 netif_stop_queue(netdev
);
272 atl1c_phy_init(&adapter
->hw
);
275 hw
->hibernate
= false;
276 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
277 err
= atl1c_get_speed_and_duplex(hw
, &speed
, &duplex
);
278 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
281 /* link result is our setting */
282 if (adapter
->link_speed
!= speed
||
283 adapter
->link_duplex
!= duplex
) {
284 adapter
->link_speed
= speed
;
285 adapter
->link_duplex
= duplex
;
286 atl1c_set_aspm(hw
, true);
287 atl1c_enable_tx_ctrl(hw
);
288 atl1c_enable_rx_ctrl(hw
);
289 atl1c_setup_mac_ctrl(adapter
);
290 if (netif_msg_link(adapter
))
292 "%s: %s NIC Link is Up<%d Mbps %s>\n",
293 atl1c_driver_name
, netdev
->name
,
295 adapter
->link_duplex
== FULL_DUPLEX
?
296 "Full Duplex" : "Half Duplex");
298 if (!netif_carrier_ok(netdev
))
299 netif_carrier_on(netdev
);
303 static void atl1c_link_chg_event(struct atl1c_adapter
*adapter
)
305 struct net_device
*netdev
= adapter
->netdev
;
306 struct pci_dev
*pdev
= adapter
->pdev
;
310 spin_lock(&adapter
->mdio_lock
);
311 atl1c_read_phy_reg(&adapter
->hw
, MII_BMSR
, &phy_data
);
312 atl1c_read_phy_reg(&adapter
->hw
, MII_BMSR
, &phy_data
);
313 spin_unlock(&adapter
->mdio_lock
);
314 link_up
= phy_data
& BMSR_LSTATUS
;
315 /* notify upper layer link down ASAP */
317 if (netif_carrier_ok(netdev
)) {
318 /* old link state: Up */
319 netif_carrier_off(netdev
);
320 if (netif_msg_link(adapter
))
322 "%s: %s NIC Link is Down\n",
323 atl1c_driver_name
, netdev
->name
);
324 adapter
->link_speed
= SPEED_0
;
328 adapter
->work_event
|= ATL1C_WORK_EVENT_LINK_CHANGE
;
329 schedule_work(&adapter
->common_task
);
332 static void atl1c_common_task(struct work_struct
*work
)
334 struct atl1c_adapter
*adapter
;
335 struct net_device
*netdev
;
337 adapter
= container_of(work
, struct atl1c_adapter
, common_task
);
338 netdev
= adapter
->netdev
;
340 if (adapter
->work_event
& ATL1C_WORK_EVENT_RESET
) {
341 adapter
->work_event
&= ~ATL1C_WORK_EVENT_RESET
;
342 netif_device_detach(netdev
);
345 netif_device_attach(netdev
);
349 if (adapter
->work_event
& ATL1C_WORK_EVENT_LINK_CHANGE
) {
350 adapter
->work_event
&= ~ATL1C_WORK_EVENT_LINK_CHANGE
;
351 atl1c_check_link_status(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 adapter
->work_event
|= ATL1C_WORK_EVENT_RESET
;
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_rx_register(struct net_device
*netdev
,
419 struct vlan_group
*grp
)
421 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
422 struct pci_dev
*pdev
= adapter
->pdev
;
423 u32 mac_ctrl_data
= 0;
425 if (netif_msg_pktdata(adapter
))
426 dev_dbg(&pdev
->dev
, "atl1c_vlan_rx_register\n");
428 atl1c_irq_disable(adapter
);
430 adapter
->vlgrp
= grp
;
431 AT_READ_REG(&adapter
->hw
, REG_MAC_CTRL
, &mac_ctrl_data
);
434 /* enable VLAN tag insert/strip */
435 mac_ctrl_data
|= MAC_CTRL_RMV_VLAN
;
437 /* disable VLAN tag insert/strip */
438 mac_ctrl_data
&= ~MAC_CTRL_RMV_VLAN
;
441 AT_WRITE_REG(&adapter
->hw
, REG_MAC_CTRL
, mac_ctrl_data
);
442 atl1c_irq_enable(adapter
);
445 static void atl1c_restore_vlan(struct atl1c_adapter
*adapter
)
447 struct pci_dev
*pdev
= adapter
->pdev
;
449 if (netif_msg_pktdata(adapter
))
450 dev_dbg(&pdev
->dev
, "atl1c_restore_vlan !");
451 atl1c_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
454 * atl1c_set_mac - Change the Ethernet Address of the NIC
455 * @netdev: network interface device structure
456 * @p: pointer to an address structure
458 * Returns 0 on success, negative on failure
460 static int atl1c_set_mac_addr(struct net_device
*netdev
, void *p
)
462 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
463 struct sockaddr
*addr
= p
;
465 if (!is_valid_ether_addr(addr
->sa_data
))
466 return -EADDRNOTAVAIL
;
468 if (netif_running(netdev
))
471 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
472 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
474 atl1c_hw_set_mac_addr(&adapter
->hw
);
479 static void atl1c_set_rxbufsize(struct atl1c_adapter
*adapter
,
480 struct net_device
*dev
)
484 adapter
->rx_buffer_len
= mtu
> AT_RX_BUF_SIZE
?
485 roundup(mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
, 8) : AT_RX_BUF_SIZE
;
488 * atl1c_change_mtu - Change the Maximum Transfer Unit
489 * @netdev: network interface device structure
490 * @new_mtu: new value for maximum frame size
492 * Returns 0 on success, negative on failure
494 static int atl1c_change_mtu(struct net_device
*netdev
, int new_mtu
)
496 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
497 int old_mtu
= netdev
->mtu
;
498 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
500 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
501 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
502 if (netif_msg_link(adapter
))
503 dev_warn(&adapter
->pdev
->dev
, "invalid MTU setting\n");
507 if (old_mtu
!= new_mtu
&& netif_running(netdev
)) {
508 while (test_and_set_bit(__AT_RESETTING
, &adapter
->flags
))
510 netdev
->mtu
= new_mtu
;
511 adapter
->hw
.max_frame_size
= new_mtu
;
512 atl1c_set_rxbufsize(adapter
, netdev
);
513 if (new_mtu
> MAX_TSO_FRAME_SIZE
) {
514 adapter
->netdev
->features
&= ~NETIF_F_TSO
;
515 adapter
->netdev
->features
&= ~NETIF_F_TSO6
;
517 adapter
->netdev
->features
|= NETIF_F_TSO
;
518 adapter
->netdev
->features
|= NETIF_F_TSO6
;
522 clear_bit(__AT_RESETTING
, &adapter
->flags
);
523 if (adapter
->hw
.ctrl_flags
& ATL1C_FPGA_VERSION
) {
526 AT_READ_REG(&adapter
->hw
, 0x1414, &phy_data
);
527 phy_data
|= 0x10000000;
528 AT_WRITE_REG(&adapter
->hw
, 0x1414, phy_data
);
536 * caller should hold mdio_lock
538 static int atl1c_mdio_read(struct net_device
*netdev
, int phy_id
, int reg_num
)
540 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
543 atl1c_read_phy_reg(&adapter
->hw
, reg_num
& MDIO_REG_ADDR_MASK
, &result
);
547 static void atl1c_mdio_write(struct net_device
*netdev
, int phy_id
,
548 int reg_num
, int val
)
550 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
552 atl1c_write_phy_reg(&adapter
->hw
, reg_num
& MDIO_REG_ADDR_MASK
, val
);
561 static int atl1c_mii_ioctl(struct net_device
*netdev
,
562 struct ifreq
*ifr
, int cmd
)
564 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
565 struct pci_dev
*pdev
= adapter
->pdev
;
566 struct mii_ioctl_data
*data
= if_mii(ifr
);
570 if (!netif_running(netdev
))
573 spin_lock_irqsave(&adapter
->mdio_lock
, flags
);
580 if (atl1c_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
588 if (data
->reg_num
& ~(0x1F)) {
593 dev_dbg(&pdev
->dev
, "<atl1c_mii_ioctl> write %x %x",
594 data
->reg_num
, data
->val_in
);
595 if (atl1c_write_phy_reg(&adapter
->hw
,
596 data
->reg_num
, data
->val_in
)) {
603 retval
= -EOPNOTSUPP
;
607 spin_unlock_irqrestore(&adapter
->mdio_lock
, flags
);
617 static int atl1c_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
623 return atl1c_mii_ioctl(netdev
, ifr
, cmd
);
630 * atl1c_alloc_queues - Allocate memory for all rings
631 * @adapter: board private structure to initialize
634 static int __devinit
atl1c_alloc_queues(struct atl1c_adapter
*adapter
)
639 static void atl1c_set_mac_type(struct atl1c_hw
*hw
)
641 switch (hw
->device_id
) {
642 case PCI_DEVICE_ID_ATTANSIC_L2C
:
643 hw
->nic_type
= athr_l2c
;
645 case PCI_DEVICE_ID_ATTANSIC_L1C
:
646 hw
->nic_type
= athr_l1c
;
648 case PCI_DEVICE_ID_ATHEROS_L2C_B
:
649 hw
->nic_type
= athr_l2c_b
;
651 case PCI_DEVICE_ID_ATHEROS_L2C_B2
:
652 hw
->nic_type
= athr_l2c_b2
;
654 case PCI_DEVICE_ID_ATHEROS_L1D
:
655 hw
->nic_type
= athr_l1d
;
657 case PCI_DEVICE_ID_ATHEROS_L1D_2_0
:
658 hw
->nic_type
= athr_l1d_2
;
665 static int atl1c_setup_mac_funcs(struct atl1c_hw
*hw
)
670 atl1c_set_mac_type(hw
);
671 AT_READ_REG(hw
, REG_PHY_STATUS
, &phy_status_data
);
672 AT_READ_REG(hw
, REG_LINK_CTRL
, &link_ctrl_data
);
674 hw
->ctrl_flags
= ATL1C_INTR_MODRT_ENABLE
|
675 ATL1C_TXQ_MODE_ENHANCE
;
676 if (link_ctrl_data
& LINK_CTRL_L0S_EN
)
677 hw
->ctrl_flags
|= ATL1C_ASPM_L0S_SUPPORT
;
678 if (link_ctrl_data
& LINK_CTRL_L1_EN
)
679 hw
->ctrl_flags
|= ATL1C_ASPM_L1_SUPPORT
;
680 if (link_ctrl_data
& LINK_CTRL_EXT_SYNC
)
681 hw
->ctrl_flags
|= ATL1C_LINK_EXT_SYNC
;
682 hw
->ctrl_flags
|= ATL1C_ASPM_CTRL_MON
;
684 if (hw
->nic_type
== athr_l1c
||
685 hw
->nic_type
== athr_l1d
||
686 hw
->nic_type
== athr_l1d_2
)
687 hw
->link_cap_flags
|= ATL1C_LINK_CAP_1000M
;
691 * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter)
692 * @adapter: board private structure to initialize
694 * atl1c_sw_init initializes the Adapter private data structure.
695 * Fields are initialized based on PCI device information and
696 * OS network device settings (MTU size).
698 static int __devinit
atl1c_sw_init(struct atl1c_adapter
*adapter
)
700 struct atl1c_hw
*hw
= &adapter
->hw
;
701 struct pci_dev
*pdev
= adapter
->pdev
;
706 device_set_wakeup_enable(&pdev
->dev
, false);
707 adapter
->link_speed
= SPEED_0
;
708 adapter
->link_duplex
= FULL_DUPLEX
;
709 adapter
->num_rx_queues
= AT_DEF_RECEIVE_QUEUE
;
710 adapter
->tpd_ring
[0].count
= 1024;
711 adapter
->rfd_ring
[0].count
= 512;
713 hw
->vendor_id
= pdev
->vendor
;
714 hw
->device_id
= pdev
->device
;
715 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
716 hw
->subsystem_id
= pdev
->subsystem_device
;
717 AT_READ_REG(hw
, PCI_CLASS_REVISION
, &revision
);
718 hw
->revision_id
= revision
& 0xFF;
719 /* before link up, we assume hibernate is true */
720 hw
->hibernate
= true;
721 hw
->media_type
= MEDIA_TYPE_AUTO_SENSOR
;
722 if (atl1c_setup_mac_funcs(hw
) != 0) {
723 dev_err(&pdev
->dev
, "set mac function pointers failed\n");
726 hw
->intr_mask
= IMR_NORMAL_MASK
;
727 hw
->phy_configured
= false;
728 hw
->preamble_len
= 7;
729 hw
->max_frame_size
= adapter
->netdev
->mtu
;
730 if (adapter
->num_rx_queues
< 2) {
731 hw
->rss_type
= atl1c_rss_disable
;
732 hw
->rss_mode
= atl1c_rss_mode_disable
;
734 hw
->rss_type
= atl1c_rss_ipv4
;
735 hw
->rss_mode
= atl1c_rss_mul_que_mul_int
;
736 hw
->rss_hash_bits
= 16;
738 hw
->autoneg_advertised
= ADVERTISED_Autoneg
;
739 hw
->indirect_tab
= 0xE4E4E4E4;
742 hw
->ict
= 50000; /* 100ms */
743 hw
->smb_timer
= 200000; /* 400ms */
745 hw
->cmb_tx_timer
= 1; /* 2 us */
751 hw
->dma_order
= atl1c_dma_ord_out
;
752 hw
->dmar_block
= atl1c_dma_req_1024
;
753 hw
->dmaw_block
= atl1c_dma_req_1024
;
754 hw
->dmar_dly_cnt
= 15;
755 hw
->dmaw_dly_cnt
= 4;
757 if (atl1c_alloc_queues(adapter
)) {
758 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
762 atl1c_set_rxbufsize(adapter
, adapter
->netdev
);
763 atomic_set(&adapter
->irq_sem
, 1);
764 spin_lock_init(&adapter
->mdio_lock
);
765 spin_lock_init(&adapter
->tx_lock
);
766 set_bit(__AT_DOWN
, &adapter
->flags
);
771 static inline void atl1c_clean_buffer(struct pci_dev
*pdev
,
772 struct atl1c_buffer
*buffer_info
, int in_irq
)
775 if (buffer_info
->flags
& ATL1C_BUFFER_FREE
)
777 if (buffer_info
->dma
) {
778 if (buffer_info
->flags
& ATL1C_PCIMAP_FROMDEVICE
)
779 pci_driection
= PCI_DMA_FROMDEVICE
;
781 pci_driection
= PCI_DMA_TODEVICE
;
783 if (buffer_info
->flags
& ATL1C_PCIMAP_SINGLE
)
784 pci_unmap_single(pdev
, buffer_info
->dma
,
785 buffer_info
->length
, pci_driection
);
786 else if (buffer_info
->flags
& ATL1C_PCIMAP_PAGE
)
787 pci_unmap_page(pdev
, buffer_info
->dma
,
788 buffer_info
->length
, pci_driection
);
790 if (buffer_info
->skb
) {
792 dev_kfree_skb_irq(buffer_info
->skb
);
794 dev_kfree_skb(buffer_info
->skb
);
796 buffer_info
->dma
= 0;
797 buffer_info
->skb
= NULL
;
798 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_FREE
);
801 * atl1c_clean_tx_ring - Free Tx-skb
802 * @adapter: board private structure
804 static void atl1c_clean_tx_ring(struct atl1c_adapter
*adapter
,
805 enum atl1c_trans_queue type
)
807 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
808 struct atl1c_buffer
*buffer_info
;
809 struct pci_dev
*pdev
= adapter
->pdev
;
810 u16 index
, ring_count
;
812 ring_count
= tpd_ring
->count
;
813 for (index
= 0; index
< ring_count
; index
++) {
814 buffer_info
= &tpd_ring
->buffer_info
[index
];
815 atl1c_clean_buffer(pdev
, buffer_info
, 0);
818 /* Zero out Tx-buffers */
819 memset(tpd_ring
->desc
, 0, sizeof(struct atl1c_tpd_desc
) *
821 atomic_set(&tpd_ring
->next_to_clean
, 0);
822 tpd_ring
->next_to_use
= 0;
826 * atl1c_clean_rx_ring - Free rx-reservation skbs
827 * @adapter: board private structure
829 static void atl1c_clean_rx_ring(struct atl1c_adapter
*adapter
)
831 struct atl1c_rfd_ring
*rfd_ring
= adapter
->rfd_ring
;
832 struct atl1c_rrd_ring
*rrd_ring
= adapter
->rrd_ring
;
833 struct atl1c_buffer
*buffer_info
;
834 struct pci_dev
*pdev
= adapter
->pdev
;
837 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
838 for (j
= 0; j
< rfd_ring
[i
].count
; j
++) {
839 buffer_info
= &rfd_ring
[i
].buffer_info
[j
];
840 atl1c_clean_buffer(pdev
, buffer_info
, 0);
842 /* zero out the descriptor ring */
843 memset(rfd_ring
[i
].desc
, 0, rfd_ring
[i
].size
);
844 rfd_ring
[i
].next_to_clean
= 0;
845 rfd_ring
[i
].next_to_use
= 0;
846 rrd_ring
[i
].next_to_use
= 0;
847 rrd_ring
[i
].next_to_clean
= 0;
852 * Read / Write Ptr Initialize:
854 static void atl1c_init_ring_ptrs(struct atl1c_adapter
*adapter
)
856 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
857 struct atl1c_rfd_ring
*rfd_ring
= adapter
->rfd_ring
;
858 struct atl1c_rrd_ring
*rrd_ring
= adapter
->rrd_ring
;
859 struct atl1c_buffer
*buffer_info
;
862 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
863 tpd_ring
[i
].next_to_use
= 0;
864 atomic_set(&tpd_ring
[i
].next_to_clean
, 0);
865 buffer_info
= tpd_ring
[i
].buffer_info
;
866 for (j
= 0; j
< tpd_ring
->count
; j
++)
867 ATL1C_SET_BUFFER_STATE(&buffer_info
[i
],
870 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
871 rfd_ring
[i
].next_to_use
= 0;
872 rfd_ring
[i
].next_to_clean
= 0;
873 rrd_ring
[i
].next_to_use
= 0;
874 rrd_ring
[i
].next_to_clean
= 0;
875 for (j
= 0; j
< rfd_ring
[i
].count
; j
++) {
876 buffer_info
= &rfd_ring
[i
].buffer_info
[j
];
877 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_FREE
);
883 * atl1c_free_ring_resources - Free Tx / RX descriptor Resources
884 * @adapter: board private structure
886 * Free all transmit software resources
888 static void atl1c_free_ring_resources(struct atl1c_adapter
*adapter
)
890 struct pci_dev
*pdev
= adapter
->pdev
;
892 pci_free_consistent(pdev
, adapter
->ring_header
.size
,
893 adapter
->ring_header
.desc
,
894 adapter
->ring_header
.dma
);
895 adapter
->ring_header
.desc
= NULL
;
897 /* Note: just free tdp_ring.buffer_info,
898 * it contain rfd_ring.buffer_info, do not double free */
899 if (adapter
->tpd_ring
[0].buffer_info
) {
900 kfree(adapter
->tpd_ring
[0].buffer_info
);
901 adapter
->tpd_ring
[0].buffer_info
= NULL
;
906 * atl1c_setup_mem_resources - allocate Tx / RX descriptor resources
907 * @adapter: board private structure
909 * Return 0 on success, negative on failure
911 static int atl1c_setup_ring_resources(struct atl1c_adapter
*adapter
)
913 struct pci_dev
*pdev
= adapter
->pdev
;
914 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
915 struct atl1c_rfd_ring
*rfd_ring
= adapter
->rfd_ring
;
916 struct atl1c_rrd_ring
*rrd_ring
= adapter
->rrd_ring
;
917 struct atl1c_ring_header
*ring_header
= &adapter
->ring_header
;
918 int num_rx_queues
= adapter
->num_rx_queues
;
922 int rx_desc_count
= 0;
925 rrd_ring
[0].count
= rfd_ring
[0].count
;
926 for (i
= 1; i
< AT_MAX_TRANSMIT_QUEUE
; i
++)
927 tpd_ring
[i
].count
= tpd_ring
[0].count
;
929 for (i
= 1; i
< adapter
->num_rx_queues
; i
++)
930 rfd_ring
[i
].count
= rrd_ring
[i
].count
= rfd_ring
[0].count
;
932 /* 2 tpd queue, one high priority queue,
933 * another normal priority queue */
934 size
= sizeof(struct atl1c_buffer
) * (tpd_ring
->count
* 2 +
935 rfd_ring
->count
* num_rx_queues
);
936 tpd_ring
->buffer_info
= kzalloc(size
, GFP_KERNEL
);
937 if (unlikely(!tpd_ring
->buffer_info
)) {
938 dev_err(&pdev
->dev
, "kzalloc failed, size = %d\n",
942 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
943 tpd_ring
[i
].buffer_info
=
944 (struct atl1c_buffer
*) (tpd_ring
->buffer_info
+ count
);
945 count
+= tpd_ring
[i
].count
;
948 for (i
= 0; i
< num_rx_queues
; i
++) {
949 rfd_ring
[i
].buffer_info
=
950 (struct atl1c_buffer
*) (tpd_ring
->buffer_info
+ count
);
951 count
+= rfd_ring
[i
].count
;
952 rx_desc_count
+= rfd_ring
[i
].count
;
955 * real ring DMA buffer
956 * each ring/block may need up to 8 bytes for alignment, hence the
957 * additional bytes tacked onto the end.
959 ring_header
->size
= size
=
960 sizeof(struct atl1c_tpd_desc
) * tpd_ring
->count
* 2 +
961 sizeof(struct atl1c_rx_free_desc
) * rx_desc_count
+
962 sizeof(struct atl1c_recv_ret_status
) * rx_desc_count
+
963 sizeof(struct atl1c_hw_stats
) +
964 8 * 4 + 8 * 2 * num_rx_queues
;
966 ring_header
->desc
= pci_alloc_consistent(pdev
, ring_header
->size
,
968 if (unlikely(!ring_header
->desc
)) {
969 dev_err(&pdev
->dev
, "pci_alloc_consistend failed\n");
972 memset(ring_header
->desc
, 0, ring_header
->size
);
975 tpd_ring
[0].dma
= roundup(ring_header
->dma
, 8);
976 offset
= tpd_ring
[0].dma
- ring_header
->dma
;
977 for (i
= 0; i
< AT_MAX_TRANSMIT_QUEUE
; i
++) {
978 tpd_ring
[i
].dma
= ring_header
->dma
+ offset
;
979 tpd_ring
[i
].desc
= (u8
*) ring_header
->desc
+ offset
;
981 sizeof(struct atl1c_tpd_desc
) * tpd_ring
[i
].count
;
982 offset
+= roundup(tpd_ring
[i
].size
, 8);
985 for (i
= 0; i
< num_rx_queues
; i
++) {
986 rfd_ring
[i
].dma
= ring_header
->dma
+ offset
;
987 rfd_ring
[i
].desc
= (u8
*) ring_header
->desc
+ offset
;
988 rfd_ring
[i
].size
= sizeof(struct atl1c_rx_free_desc
) *
990 offset
+= roundup(rfd_ring
[i
].size
, 8);
994 for (i
= 0; i
< num_rx_queues
; i
++) {
995 rrd_ring
[i
].dma
= ring_header
->dma
+ offset
;
996 rrd_ring
[i
].desc
= (u8
*) ring_header
->desc
+ offset
;
997 rrd_ring
[i
].size
= sizeof(struct atl1c_recv_ret_status
) *
999 offset
+= roundup(rrd_ring
[i
].size
, 8);
1002 adapter
->smb
.dma
= ring_header
->dma
+ offset
;
1003 adapter
->smb
.smb
= (u8
*)ring_header
->desc
+ offset
;
1007 kfree(tpd_ring
->buffer_info
);
1011 static void atl1c_configure_des_ring(struct atl1c_adapter
*adapter
)
1013 struct atl1c_hw
*hw
= &adapter
->hw
;
1014 struct atl1c_rfd_ring
*rfd_ring
= (struct atl1c_rfd_ring
*)
1016 struct atl1c_rrd_ring
*rrd_ring
= (struct atl1c_rrd_ring
*)
1018 struct atl1c_tpd_ring
*tpd_ring
= (struct atl1c_tpd_ring
*)
1020 struct atl1c_cmb
*cmb
= (struct atl1c_cmb
*) &adapter
->cmb
;
1021 struct atl1c_smb
*smb
= (struct atl1c_smb
*) &adapter
->smb
;
1026 AT_WRITE_REG(hw
, REG_TX_BASE_ADDR_HI
,
1027 (u32
)((tpd_ring
[atl1c_trans_normal
].dma
&
1028 AT_DMA_HI_ADDR_MASK
) >> 32));
1029 /* just enable normal priority TX queue */
1030 AT_WRITE_REG(hw
, REG_NTPD_HEAD_ADDR_LO
,
1031 (u32
)(tpd_ring
[atl1c_trans_normal
].dma
&
1032 AT_DMA_LO_ADDR_MASK
));
1033 AT_WRITE_REG(hw
, REG_HTPD_HEAD_ADDR_LO
,
1034 (u32
)(tpd_ring
[atl1c_trans_high
].dma
&
1035 AT_DMA_LO_ADDR_MASK
));
1036 AT_WRITE_REG(hw
, REG_TPD_RING_SIZE
,
1037 (u32
)(tpd_ring
[0].count
& TPD_RING_SIZE_MASK
));
1041 AT_WRITE_REG(hw
, REG_RX_BASE_ADDR_HI
,
1042 (u32
)((rfd_ring
[0].dma
& AT_DMA_HI_ADDR_MASK
) >> 32));
1043 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1044 AT_WRITE_REG(hw
, atl1c_rfd_addr_lo_regs
[i
],
1045 (u32
)(rfd_ring
[i
].dma
& AT_DMA_LO_ADDR_MASK
));
1047 AT_WRITE_REG(hw
, REG_RFD_RING_SIZE
,
1048 rfd_ring
[0].count
& RFD_RING_SIZE_MASK
);
1049 AT_WRITE_REG(hw
, REG_RX_BUF_SIZE
,
1050 adapter
->rx_buffer_len
& RX_BUF_SIZE_MASK
);
1053 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1054 AT_WRITE_REG(hw
, atl1c_rrd_addr_lo_regs
[i
],
1055 (u32
)(rrd_ring
[i
].dma
& AT_DMA_LO_ADDR_MASK
));
1056 AT_WRITE_REG(hw
, REG_RRD_RING_SIZE
,
1057 (rrd_ring
[0].count
& RRD_RING_SIZE_MASK
));
1060 AT_WRITE_REG(hw
, REG_CMB_BASE_ADDR_LO
, cmb
->dma
& AT_DMA_LO_ADDR_MASK
);
1063 AT_WRITE_REG(hw
, REG_SMB_BASE_ADDR_HI
,
1064 (u32
)((smb
->dma
& AT_DMA_HI_ADDR_MASK
) >> 32));
1065 AT_WRITE_REG(hw
, REG_SMB_BASE_ADDR_LO
,
1066 (u32
)(smb
->dma
& AT_DMA_LO_ADDR_MASK
));
1067 if (hw
->nic_type
== athr_l2c_b
) {
1068 AT_WRITE_REG(hw
, REG_SRAM_RXF_LEN
, 0x02a0L
);
1069 AT_WRITE_REG(hw
, REG_SRAM_TXF_LEN
, 0x0100L
);
1070 AT_WRITE_REG(hw
, REG_SRAM_RXF_ADDR
, 0x029f0000L
);
1071 AT_WRITE_REG(hw
, REG_SRAM_RFD0_INFO
, 0x02bf02a0L
);
1072 AT_WRITE_REG(hw
, REG_SRAM_TXF_ADDR
, 0x03bf02c0L
);
1073 AT_WRITE_REG(hw
, REG_SRAM_TRD_ADDR
, 0x03df03c0L
);
1074 AT_WRITE_REG(hw
, REG_TXF_WATER_MARK
, 0); /* TX watermark, to enter l1 state.*/
1075 AT_WRITE_REG(hw
, REG_RXD_DMA_CTRL
, 0); /* RXD threshold.*/
1077 if (hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l1d_2
) {
1078 /* Power Saving for L2c_B */
1079 AT_READ_REG(hw
, REG_SERDES_LOCK
, &data
);
1080 data
|= SERDES_MAC_CLK_SLOWDOWN
;
1081 data
|= SERDES_PYH_CLK_SLOWDOWN
;
1082 AT_WRITE_REG(hw
, REG_SERDES_LOCK
, data
);
1084 /* Load all of base address above */
1085 AT_WRITE_REG(hw
, REG_LOAD_PTR
, 1);
1088 static void atl1c_configure_tx(struct atl1c_adapter
*adapter
)
1090 struct atl1c_hw
*hw
= &adapter
->hw
;
1093 u16 tx_offload_thresh
;
1095 u32 extra_size
= 0; /* Jumbo frame threshold in QWORD unit */
1096 u32 max_pay_load_data
;
1098 extra_size
= ETH_HLEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
1099 tx_offload_thresh
= MAX_TX_OFFLOAD_THRESH
;
1100 AT_WRITE_REG(hw
, REG_TX_TSO_OFFLOAD_THRESH
,
1101 (tx_offload_thresh
>> 3) & TX_TSO_OFFLOAD_THRESH_MASK
);
1102 AT_READ_REG(hw
, REG_DEVICE_CTRL
, &dev_ctrl_data
);
1103 max_pay_load
= (dev_ctrl_data
>> DEVICE_CTRL_MAX_PAYLOAD_SHIFT
) &
1104 DEVICE_CTRL_MAX_PAYLOAD_MASK
;
1105 hw
->dmaw_block
= min(max_pay_load
, hw
->dmaw_block
);
1106 max_pay_load
= (dev_ctrl_data
>> DEVICE_CTRL_MAX_RREQ_SZ_SHIFT
) &
1107 DEVICE_CTRL_MAX_RREQ_SZ_MASK
;
1108 hw
->dmar_block
= min(max_pay_load
, hw
->dmar_block
);
1110 txq_ctrl_data
= (hw
->tpd_burst
& TXQ_NUM_TPD_BURST_MASK
) <<
1111 TXQ_NUM_TPD_BURST_SHIFT
;
1112 if (hw
->ctrl_flags
& ATL1C_TXQ_MODE_ENHANCE
)
1113 txq_ctrl_data
|= TXQ_CTRL_ENH_MODE
;
1114 max_pay_load_data
= (atl1c_pay_load_size
[hw
->dmar_block
] &
1115 TXQ_TXF_BURST_NUM_MASK
) << TXQ_TXF_BURST_NUM_SHIFT
;
1116 if (hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l2c_b2
)
1117 max_pay_load_data
>>= 1;
1118 txq_ctrl_data
|= max_pay_load_data
;
1120 AT_WRITE_REG(hw
, REG_TXQ_CTRL
, txq_ctrl_data
);
1123 static void atl1c_configure_rx(struct atl1c_adapter
*adapter
)
1125 struct atl1c_hw
*hw
= &adapter
->hw
;
1128 rxq_ctrl_data
= (hw
->rfd_burst
& RXQ_RFD_BURST_NUM_MASK
) <<
1129 RXQ_RFD_BURST_NUM_SHIFT
;
1131 if (hw
->ctrl_flags
& ATL1C_RX_IPV6_CHKSUM
)
1132 rxq_ctrl_data
|= IPV6_CHKSUM_CTRL_EN
;
1133 if (hw
->rss_type
== atl1c_rss_ipv4
)
1134 rxq_ctrl_data
|= RSS_HASH_IPV4
;
1135 if (hw
->rss_type
== atl1c_rss_ipv4_tcp
)
1136 rxq_ctrl_data
|= RSS_HASH_IPV4_TCP
;
1137 if (hw
->rss_type
== atl1c_rss_ipv6
)
1138 rxq_ctrl_data
|= RSS_HASH_IPV6
;
1139 if (hw
->rss_type
== atl1c_rss_ipv6_tcp
)
1140 rxq_ctrl_data
|= RSS_HASH_IPV6_TCP
;
1141 if (hw
->rss_type
!= atl1c_rss_disable
)
1142 rxq_ctrl_data
|= RRS_HASH_CTRL_EN
;
1144 rxq_ctrl_data
|= (hw
->rss_mode
& RSS_MODE_MASK
) <<
1146 rxq_ctrl_data
|= (hw
->rss_hash_bits
& RSS_HASH_BITS_MASK
) <<
1147 RSS_HASH_BITS_SHIFT
;
1148 if (hw
->ctrl_flags
& ATL1C_ASPM_CTRL_MON
)
1149 rxq_ctrl_data
|= (ASPM_THRUPUT_LIMIT_1M
&
1150 ASPM_THRUPUT_LIMIT_MASK
) << ASPM_THRUPUT_LIMIT_SHIFT
;
1152 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, rxq_ctrl_data
);
1155 static void atl1c_configure_rss(struct atl1c_adapter
*adapter
)
1157 struct atl1c_hw
*hw
= &adapter
->hw
;
1159 AT_WRITE_REG(hw
, REG_IDT_TABLE
, hw
->indirect_tab
);
1160 AT_WRITE_REG(hw
, REG_BASE_CPU_NUMBER
, hw
->base_cpu
);
1163 static void atl1c_configure_dma(struct atl1c_adapter
*adapter
)
1165 struct atl1c_hw
*hw
= &adapter
->hw
;
1168 dma_ctrl_data
= DMA_CTRL_DMAR_REQ_PRI
;
1169 if (hw
->ctrl_flags
& ATL1C_CMB_ENABLE
)
1170 dma_ctrl_data
|= DMA_CTRL_CMB_EN
;
1171 if (hw
->ctrl_flags
& ATL1C_SMB_ENABLE
)
1172 dma_ctrl_data
|= DMA_CTRL_SMB_EN
;
1174 dma_ctrl_data
|= MAC_CTRL_SMB_DIS
;
1176 switch (hw
->dma_order
) {
1177 case atl1c_dma_ord_in
:
1178 dma_ctrl_data
|= DMA_CTRL_DMAR_IN_ORDER
;
1180 case atl1c_dma_ord_enh
:
1181 dma_ctrl_data
|= DMA_CTRL_DMAR_ENH_ORDER
;
1183 case atl1c_dma_ord_out
:
1184 dma_ctrl_data
|= DMA_CTRL_DMAR_OUT_ORDER
;
1190 dma_ctrl_data
|= (((u32
)hw
->dmar_block
) & DMA_CTRL_DMAR_BURST_LEN_MASK
)
1191 << DMA_CTRL_DMAR_BURST_LEN_SHIFT
;
1192 dma_ctrl_data
|= (((u32
)hw
->dmaw_block
) & DMA_CTRL_DMAW_BURST_LEN_MASK
)
1193 << DMA_CTRL_DMAW_BURST_LEN_SHIFT
;
1194 dma_ctrl_data
|= (((u32
)hw
->dmar_dly_cnt
) & DMA_CTRL_DMAR_DLY_CNT_MASK
)
1195 << DMA_CTRL_DMAR_DLY_CNT_SHIFT
;
1196 dma_ctrl_data
|= (((u32
)hw
->dmaw_dly_cnt
) & DMA_CTRL_DMAW_DLY_CNT_MASK
)
1197 << DMA_CTRL_DMAW_DLY_CNT_SHIFT
;
1199 AT_WRITE_REG(hw
, REG_DMA_CTRL
, dma_ctrl_data
);
1203 * Stop the mac, transmit and receive units
1204 * hw - Struct containing variables accessed by shared code
1205 * return : 0 or idle status (if error)
1207 static int atl1c_stop_mac(struct atl1c_hw
*hw
)
1211 AT_READ_REG(hw
, REG_RXQ_CTRL
, &data
);
1212 data
&= ~(RXQ1_CTRL_EN
| RXQ2_CTRL_EN
|
1213 RXQ3_CTRL_EN
| RXQ_CTRL_EN
);
1214 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, data
);
1216 AT_READ_REG(hw
, REG_TXQ_CTRL
, &data
);
1217 data
&= ~TXQ_CTRL_EN
;
1218 AT_WRITE_REG(hw
, REG_TWSI_CTRL
, data
);
1220 atl1c_wait_until_idle(hw
);
1222 AT_READ_REG(hw
, REG_MAC_CTRL
, &data
);
1223 data
&= ~(MAC_CTRL_TX_EN
| MAC_CTRL_RX_EN
);
1224 AT_WRITE_REG(hw
, REG_MAC_CTRL
, data
);
1226 return (int)atl1c_wait_until_idle(hw
);
1229 static void atl1c_enable_rx_ctrl(struct atl1c_hw
*hw
)
1233 AT_READ_REG(hw
, REG_RXQ_CTRL
, &data
);
1234 switch (hw
->adapter
->num_rx_queues
) {
1236 data
|= (RXQ3_CTRL_EN
| RXQ2_CTRL_EN
| RXQ1_CTRL_EN
);
1239 data
|= (RXQ2_CTRL_EN
| RXQ1_CTRL_EN
);
1242 data
|= RXQ1_CTRL_EN
;
1247 data
|= RXQ_CTRL_EN
;
1248 AT_WRITE_REG(hw
, REG_RXQ_CTRL
, data
);
1251 static void atl1c_enable_tx_ctrl(struct atl1c_hw
*hw
)
1255 AT_READ_REG(hw
, REG_TXQ_CTRL
, &data
);
1256 data
|= TXQ_CTRL_EN
;
1257 AT_WRITE_REG(hw
, REG_TXQ_CTRL
, data
);
1261 * Reset the transmit and receive units; mask and clear all interrupts.
1262 * hw - Struct containing variables accessed by shared code
1263 * return : 0 or idle status (if error)
1265 static int atl1c_reset_mac(struct atl1c_hw
*hw
)
1267 struct atl1c_adapter
*adapter
= (struct atl1c_adapter
*)hw
->adapter
;
1268 struct pci_dev
*pdev
= adapter
->pdev
;
1269 u32 master_ctrl_data
= 0;
1271 AT_WRITE_REG(hw
, REG_IMR
, 0);
1272 AT_WRITE_REG(hw
, REG_ISR
, ISR_DIS_INT
);
1276 * Issue Soft Reset to the MAC. This will reset the chip's
1277 * transmit, receive, DMA. It will not effect
1278 * the current PCI configuration. The global reset bit is self-
1279 * clearing, and should clear within a microsecond.
1281 AT_READ_REG(hw
, REG_MASTER_CTRL
, &master_ctrl_data
);
1282 master_ctrl_data
|= MASTER_CTRL_OOB_DIS_OFF
;
1283 AT_WRITE_REGW(hw
, REG_MASTER_CTRL
, ((master_ctrl_data
| MASTER_CTRL_SOFT_RST
)
1288 /* Wait at least 10ms for All module to be Idle */
1290 if (atl1c_wait_until_idle(hw
)) {
1292 "MAC state machine can't be idle since"
1293 " disabled for 10ms second\n");
1299 static void atl1c_disable_l0s_l1(struct atl1c_hw
*hw
)
1303 AT_READ_REG(hw
, REG_PM_CTRL
, &pm_ctrl_data
);
1304 pm_ctrl_data
&= ~(PM_CTRL_L1_ENTRY_TIMER_MASK
<<
1305 PM_CTRL_L1_ENTRY_TIMER_SHIFT
);
1306 pm_ctrl_data
&= ~PM_CTRL_CLK_SWH_L1
;
1307 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1308 pm_ctrl_data
&= ~PM_CTRL_ASPM_L1_EN
;
1309 pm_ctrl_data
&= ~PM_CTRL_MAC_ASPM_CHK
;
1310 pm_ctrl_data
&= ~PM_CTRL_SERDES_PD_EX_L1
;
1312 pm_ctrl_data
|= PM_CTRL_SERDES_BUDS_RX_L1_EN
;
1313 pm_ctrl_data
|= PM_CTRL_SERDES_PLL_L1_EN
;
1314 pm_ctrl_data
|= PM_CTRL_SERDES_L1_EN
;
1315 AT_WRITE_REG(hw
, REG_PM_CTRL
, pm_ctrl_data
);
1320 * Enable/disable L0s/L1 depend on link state.
1322 static void atl1c_set_aspm(struct atl1c_hw
*hw
, bool linkup
)
1326 u32 link_l1_timer
= 0xF;
1328 AT_READ_REG(hw
, REG_PM_CTRL
, &pm_ctrl_data
);
1329 AT_READ_REG(hw
, REG_LINK_CTRL
, &link_ctrl_data
);
1331 pm_ctrl_data
&= ~PM_CTRL_SERDES_PD_EX_L1
;
1332 pm_ctrl_data
&= ~(PM_CTRL_L1_ENTRY_TIMER_MASK
<<
1333 PM_CTRL_L1_ENTRY_TIMER_SHIFT
);
1334 pm_ctrl_data
&= ~(PM_CTRL_LCKDET_TIMER_MASK
<<
1335 PM_CTRL_LCKDET_TIMER_SHIFT
);
1336 pm_ctrl_data
|= AT_LCKDET_TIMER
<< PM_CTRL_LCKDET_TIMER_SHIFT
;
1338 if (hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l1d
||
1339 hw
->nic_type
== athr_l2c_b2
|| hw
->nic_type
== athr_l1d_2
) {
1340 link_ctrl_data
&= ~LINK_CTRL_EXT_SYNC
;
1341 if (!(hw
->ctrl_flags
& ATL1C_APS_MODE_ENABLE
)) {
1342 if (hw
->nic_type
== athr_l2c_b
&& hw
->revision_id
== L2CB_V10
)
1343 link_ctrl_data
|= LINK_CTRL_EXT_SYNC
;
1346 AT_WRITE_REG(hw
, REG_LINK_CTRL
, link_ctrl_data
);
1348 pm_ctrl_data
|= PM_CTRL_RCVR_WT_TIMER
;
1349 pm_ctrl_data
&= ~(PM_CTRL_PM_REQ_TIMER_MASK
<<
1350 PM_CTRL_PM_REQ_TIMER_SHIFT
);
1351 pm_ctrl_data
|= AT_ASPM_L1_TIMER
<<
1352 PM_CTRL_PM_REQ_TIMER_SHIFT
;
1353 pm_ctrl_data
&= ~PM_CTRL_SA_DLY_EN
;
1354 pm_ctrl_data
&= ~PM_CTRL_HOTRST
;
1355 pm_ctrl_data
|= 1 << PM_CTRL_L1_ENTRY_TIMER_SHIFT
;
1356 pm_ctrl_data
|= PM_CTRL_SERDES_PD_EX_L1
;
1358 pm_ctrl_data
|= PM_CTRL_MAC_ASPM_CHK
;
1360 pm_ctrl_data
&= ~PM_CTRL_ASPM_L1_EN
;
1361 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1362 if (hw
->ctrl_flags
& ATL1C_ASPM_L1_SUPPORT
)
1363 pm_ctrl_data
|= PM_CTRL_ASPM_L1_EN
;
1364 if (hw
->ctrl_flags
& ATL1C_ASPM_L0S_SUPPORT
)
1365 pm_ctrl_data
|= PM_CTRL_ASPM_L0S_EN
;
1367 if (hw
->nic_type
== athr_l2c_b
|| hw
->nic_type
== athr_l1d
||
1368 hw
->nic_type
== athr_l2c_b2
|| hw
->nic_type
== athr_l1d_2
) {
1369 if (hw
->nic_type
== athr_l2c_b
)
1370 if (!(hw
->ctrl_flags
& ATL1C_APS_MODE_ENABLE
))
1371 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1372 pm_ctrl_data
&= ~PM_CTRL_SERDES_L1_EN
;
1373 pm_ctrl_data
&= ~PM_CTRL_SERDES_PLL_L1_EN
;
1374 pm_ctrl_data
&= ~PM_CTRL_SERDES_BUDS_RX_L1_EN
;
1375 pm_ctrl_data
|= PM_CTRL_CLK_SWH_L1
;
1376 if (hw
->adapter
->link_speed
== SPEED_100
||
1377 hw
->adapter
->link_speed
== SPEED_1000
) {
1378 pm_ctrl_data
&= ~(PM_CTRL_L1_ENTRY_TIMER_MASK
<<
1379 PM_CTRL_L1_ENTRY_TIMER_SHIFT
);
1380 if (hw
->nic_type
== athr_l2c_b
)
1382 else if (hw
->nic_type
== athr_l2c_b2
||
1383 hw
->nic_type
== athr_l1d_2
)
1385 pm_ctrl_data
|= link_l1_timer
<<
1386 PM_CTRL_L1_ENTRY_TIMER_SHIFT
;
1389 pm_ctrl_data
|= PM_CTRL_SERDES_L1_EN
;
1390 pm_ctrl_data
|= PM_CTRL_SERDES_PLL_L1_EN
;
1391 pm_ctrl_data
|= PM_CTRL_SERDES_BUDS_RX_L1_EN
;
1392 pm_ctrl_data
&= ~PM_CTRL_CLK_SWH_L1
;
1393 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1394 pm_ctrl_data
&= ~PM_CTRL_ASPM_L1_EN
;
1398 pm_ctrl_data
&= ~PM_CTRL_SERDES_L1_EN
;
1399 pm_ctrl_data
&= ~PM_CTRL_ASPM_L0S_EN
;
1400 pm_ctrl_data
&= ~PM_CTRL_SERDES_PLL_L1_EN
;
1401 pm_ctrl_data
|= PM_CTRL_CLK_SWH_L1
;
1403 if (hw
->ctrl_flags
& ATL1C_ASPM_L1_SUPPORT
)
1404 pm_ctrl_data
|= PM_CTRL_ASPM_L1_EN
;
1406 pm_ctrl_data
&= ~PM_CTRL_ASPM_L1_EN
;
1408 AT_WRITE_REG(hw
, REG_PM_CTRL
, pm_ctrl_data
);
1413 static void atl1c_setup_mac_ctrl(struct atl1c_adapter
*adapter
)
1415 struct atl1c_hw
*hw
= &adapter
->hw
;
1416 struct net_device
*netdev
= adapter
->netdev
;
1419 mac_ctrl_data
= MAC_CTRL_TX_EN
| MAC_CTRL_RX_EN
;
1420 mac_ctrl_data
|= (MAC_CTRL_TX_FLOW
| MAC_CTRL_RX_FLOW
);
1422 if (adapter
->link_duplex
== FULL_DUPLEX
) {
1423 hw
->mac_duplex
= true;
1424 mac_ctrl_data
|= MAC_CTRL_DUPLX
;
1427 if (adapter
->link_speed
== SPEED_1000
)
1428 hw
->mac_speed
= atl1c_mac_speed_1000
;
1430 hw
->mac_speed
= atl1c_mac_speed_10_100
;
1432 mac_ctrl_data
|= (hw
->mac_speed
& MAC_CTRL_SPEED_MASK
) <<
1433 MAC_CTRL_SPEED_SHIFT
;
1435 mac_ctrl_data
|= (MAC_CTRL_ADD_CRC
| MAC_CTRL_PAD
);
1436 mac_ctrl_data
|= ((hw
->preamble_len
& MAC_CTRL_PRMLEN_MASK
) <<
1437 MAC_CTRL_PRMLEN_SHIFT
);
1440 mac_ctrl_data
|= MAC_CTRL_RMV_VLAN
;
1442 mac_ctrl_data
|= MAC_CTRL_BC_EN
;
1443 if (netdev
->flags
& IFF_PROMISC
)
1444 mac_ctrl_data
|= MAC_CTRL_PROMIS_EN
;
1445 if (netdev
->flags
& IFF_ALLMULTI
)
1446 mac_ctrl_data
|= MAC_CTRL_MC_ALL_EN
;
1448 mac_ctrl_data
|= MAC_CTRL_SINGLE_PAUSE_EN
;
1449 if (hw
->nic_type
== athr_l1d
|| hw
->nic_type
== athr_l2c_b2
||
1450 hw
->nic_type
== athr_l1d_2
) {
1451 mac_ctrl_data
|= MAC_CTRL_SPEED_MODE_SW
;
1452 mac_ctrl_data
|= MAC_CTRL_HASH_ALG_CRC32
;
1454 AT_WRITE_REG(hw
, REG_MAC_CTRL
, mac_ctrl_data
);
1458 * atl1c_configure - Configure Transmit&Receive Unit after Reset
1459 * @adapter: board private structure
1461 * Configure the Tx /Rx unit of the MAC after a reset.
1463 static int atl1c_configure(struct atl1c_adapter
*adapter
)
1465 struct atl1c_hw
*hw
= &adapter
->hw
;
1466 u32 master_ctrl_data
= 0;
1467 u32 intr_modrt_data
;
1470 /* clear interrupt status */
1471 AT_WRITE_REG(hw
, REG_ISR
, 0xFFFFFFFF);
1472 /* Clear any WOL status */
1473 AT_WRITE_REG(hw
, REG_WOL_CTRL
, 0);
1474 /* set Interrupt Clear Timer
1475 * HW will enable self to assert interrupt event to system after
1476 * waiting x-time for software to notify it accept interrupt.
1479 data
= CLK_GATING_EN_ALL
;
1480 if (hw
->ctrl_flags
& ATL1C_CLK_GATING_EN
) {
1481 if (hw
->nic_type
== athr_l2c_b
)
1482 data
&= ~CLK_GATING_RXMAC_EN
;
1485 AT_WRITE_REG(hw
, REG_CLK_GATING_CTRL
, data
);
1487 AT_WRITE_REG(hw
, REG_INT_RETRIG_TIMER
,
1488 hw
->ict
& INT_RETRIG_TIMER_MASK
);
1490 atl1c_configure_des_ring(adapter
);
1492 if (hw
->ctrl_flags
& ATL1C_INTR_MODRT_ENABLE
) {
1493 intr_modrt_data
= (hw
->tx_imt
& IRQ_MODRT_TIMER_MASK
) <<
1494 IRQ_MODRT_TX_TIMER_SHIFT
;
1495 intr_modrt_data
|= (hw
->rx_imt
& IRQ_MODRT_TIMER_MASK
) <<
1496 IRQ_MODRT_RX_TIMER_SHIFT
;
1497 AT_WRITE_REG(hw
, REG_IRQ_MODRT_TIMER_INIT
, intr_modrt_data
);
1499 MASTER_CTRL_TX_ITIMER_EN
| MASTER_CTRL_RX_ITIMER_EN
;
1502 if (hw
->ctrl_flags
& ATL1C_INTR_CLEAR_ON_READ
)
1503 master_ctrl_data
|= MASTER_CTRL_INT_RDCLR
;
1505 master_ctrl_data
|= MASTER_CTRL_SA_TIMER_EN
;
1506 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, master_ctrl_data
);
1508 if (hw
->ctrl_flags
& ATL1C_CMB_ENABLE
) {
1509 AT_WRITE_REG(hw
, REG_CMB_TPD_THRESH
,
1510 hw
->cmb_tpd
& CMB_TPD_THRESH_MASK
);
1511 AT_WRITE_REG(hw
, REG_CMB_TX_TIMER
,
1512 hw
->cmb_tx_timer
& CMB_TX_TIMER_MASK
);
1515 if (hw
->ctrl_flags
& ATL1C_SMB_ENABLE
)
1516 AT_WRITE_REG(hw
, REG_SMB_STAT_TIMER
,
1517 hw
->smb_timer
& SMB_STAT_TIMER_MASK
);
1519 AT_WRITE_REG(hw
, REG_MTU
, hw
->max_frame_size
+ ETH_HLEN
+
1520 VLAN_HLEN
+ ETH_FCS_LEN
);
1522 AT_WRITE_REG(hw
, REG_HDS_CTRL
, 0);
1524 atl1c_configure_tx(adapter
);
1525 atl1c_configure_rx(adapter
);
1526 atl1c_configure_rss(adapter
);
1527 atl1c_configure_dma(adapter
);
1532 static void atl1c_update_hw_stats(struct atl1c_adapter
*adapter
)
1534 u16 hw_reg_addr
= 0;
1535 unsigned long *stats_item
= NULL
;
1538 /* update rx status */
1539 hw_reg_addr
= REG_MAC_RX_STATUS_BIN
;
1540 stats_item
= &adapter
->hw_stats
.rx_ok
;
1541 while (hw_reg_addr
<= REG_MAC_RX_STATUS_END
) {
1542 AT_READ_REG(&adapter
->hw
, hw_reg_addr
, &data
);
1543 *stats_item
+= data
;
1547 /* update tx status */
1548 hw_reg_addr
= REG_MAC_TX_STATUS_BIN
;
1549 stats_item
= &adapter
->hw_stats
.tx_ok
;
1550 while (hw_reg_addr
<= REG_MAC_TX_STATUS_END
) {
1551 AT_READ_REG(&adapter
->hw
, hw_reg_addr
, &data
);
1552 *stats_item
+= data
;
1559 * atl1c_get_stats - Get System Network Statistics
1560 * @netdev: network interface device structure
1562 * Returns the address of the device statistics structure.
1563 * The statistics are actually updated from the timer callback.
1565 static struct net_device_stats
*atl1c_get_stats(struct net_device
*netdev
)
1567 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1568 struct atl1c_hw_stats
*hw_stats
= &adapter
->hw_stats
;
1569 struct net_device_stats
*net_stats
= &netdev
->stats
;
1571 atl1c_update_hw_stats(adapter
);
1572 net_stats
->rx_packets
= hw_stats
->rx_ok
;
1573 net_stats
->tx_packets
= hw_stats
->tx_ok
;
1574 net_stats
->rx_bytes
= hw_stats
->rx_byte_cnt
;
1575 net_stats
->tx_bytes
= hw_stats
->tx_byte_cnt
;
1576 net_stats
->multicast
= hw_stats
->rx_mcast
;
1577 net_stats
->collisions
= hw_stats
->tx_1_col
+
1578 hw_stats
->tx_2_col
* 2 +
1579 hw_stats
->tx_late_col
+ hw_stats
->tx_abort_col
;
1580 net_stats
->rx_errors
= hw_stats
->rx_frag
+ hw_stats
->rx_fcs_err
+
1581 hw_stats
->rx_len_err
+ hw_stats
->rx_sz_ov
+
1582 hw_stats
->rx_rrd_ov
+ hw_stats
->rx_align_err
;
1583 net_stats
->rx_fifo_errors
= hw_stats
->rx_rxf_ov
;
1584 net_stats
->rx_length_errors
= hw_stats
->rx_len_err
;
1585 net_stats
->rx_crc_errors
= hw_stats
->rx_fcs_err
;
1586 net_stats
->rx_frame_errors
= hw_stats
->rx_align_err
;
1587 net_stats
->rx_over_errors
= hw_stats
->rx_rrd_ov
+ hw_stats
->rx_rxf_ov
;
1589 net_stats
->rx_missed_errors
= hw_stats
->rx_rrd_ov
+ hw_stats
->rx_rxf_ov
;
1591 net_stats
->tx_errors
= hw_stats
->tx_late_col
+ hw_stats
->tx_abort_col
+
1592 hw_stats
->tx_underrun
+ hw_stats
->tx_trunc
;
1593 net_stats
->tx_fifo_errors
= hw_stats
->tx_underrun
;
1594 net_stats
->tx_aborted_errors
= hw_stats
->tx_abort_col
;
1595 net_stats
->tx_window_errors
= hw_stats
->tx_late_col
;
1600 static inline void atl1c_clear_phy_int(struct atl1c_adapter
*adapter
)
1604 spin_lock(&adapter
->mdio_lock
);
1605 atl1c_read_phy_reg(&adapter
->hw
, MII_ISR
, &phy_data
);
1606 spin_unlock(&adapter
->mdio_lock
);
1609 static bool atl1c_clean_tx_irq(struct atl1c_adapter
*adapter
,
1610 enum atl1c_trans_queue type
)
1612 struct atl1c_tpd_ring
*tpd_ring
= (struct atl1c_tpd_ring
*)
1613 &adapter
->tpd_ring
[type
];
1614 struct atl1c_buffer
*buffer_info
;
1615 struct pci_dev
*pdev
= adapter
->pdev
;
1616 u16 next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
1617 u16 hw_next_to_clean
;
1621 if (type
== atl1c_trans_high
)
1622 shift
= MB_HTPD_CONS_IDX_SHIFT
;
1624 shift
= MB_NTPD_CONS_IDX_SHIFT
;
1626 AT_READ_REG(&adapter
->hw
, REG_MB_PRIO_CONS_IDX
, &data
);
1627 hw_next_to_clean
= (data
>> shift
) & MB_PRIO_PROD_IDX_MASK
;
1629 while (next_to_clean
!= hw_next_to_clean
) {
1630 buffer_info
= &tpd_ring
->buffer_info
[next_to_clean
];
1631 atl1c_clean_buffer(pdev
, buffer_info
, 1);
1632 if (++next_to_clean
== tpd_ring
->count
)
1634 atomic_set(&tpd_ring
->next_to_clean
, next_to_clean
);
1637 if (netif_queue_stopped(adapter
->netdev
) &&
1638 netif_carrier_ok(adapter
->netdev
)) {
1639 netif_wake_queue(adapter
->netdev
);
1646 * atl1c_intr - Interrupt Handler
1647 * @irq: interrupt number
1648 * @data: pointer to a network interface device structure
1649 * @pt_regs: CPU registers structure
1651 static irqreturn_t
atl1c_intr(int irq
, void *data
)
1653 struct net_device
*netdev
= data
;
1654 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1655 struct pci_dev
*pdev
= adapter
->pdev
;
1656 struct atl1c_hw
*hw
= &adapter
->hw
;
1657 int max_ints
= AT_MAX_INT_WORK
;
1658 int handled
= IRQ_NONE
;
1663 AT_READ_REG(hw
, REG_ISR
, ®_data
);
1664 status
= reg_data
& hw
->intr_mask
;
1666 if (status
== 0 || (status
& ISR_DIS_INT
) != 0) {
1667 if (max_ints
!= AT_MAX_INT_WORK
)
1668 handled
= IRQ_HANDLED
;
1672 if (status
& ISR_GPHY
)
1673 atl1c_clear_phy_int(adapter
);
1675 AT_WRITE_REG(hw
, REG_ISR
, status
| ISR_DIS_INT
);
1676 if (status
& ISR_RX_PKT
) {
1677 if (likely(napi_schedule_prep(&adapter
->napi
))) {
1678 hw
->intr_mask
&= ~ISR_RX_PKT
;
1679 AT_WRITE_REG(hw
, REG_IMR
, hw
->intr_mask
);
1680 __napi_schedule(&adapter
->napi
);
1683 if (status
& ISR_TX_PKT
)
1684 atl1c_clean_tx_irq(adapter
, atl1c_trans_normal
);
1686 handled
= IRQ_HANDLED
;
1687 /* check if PCIE PHY Link down */
1688 if (status
& ISR_ERROR
) {
1689 if (netif_msg_hw(adapter
))
1691 "atl1c hardware error (status = 0x%x)\n",
1692 status
& ISR_ERROR
);
1694 adapter
->work_event
|= ATL1C_WORK_EVENT_RESET
;
1695 schedule_work(&adapter
->common_task
);
1699 if (status
& ISR_OVER
)
1700 if (netif_msg_intr(adapter
))
1701 dev_warn(&pdev
->dev
,
1702 "TX/RX overflow (status = 0x%x)\n",
1706 if (status
& (ISR_GPHY
| ISR_MANUAL
)) {
1707 netdev
->stats
.tx_carrier_errors
++;
1708 atl1c_link_chg_event(adapter
);
1712 } while (--max_ints
> 0);
1713 /* re-enable Interrupt*/
1714 AT_WRITE_REG(&adapter
->hw
, REG_ISR
, 0);
1718 static inline void atl1c_rx_checksum(struct atl1c_adapter
*adapter
,
1719 struct sk_buff
*skb
, struct atl1c_recv_ret_status
*prrs
)
1722 * The pid field in RRS in not correct sometimes, so we
1723 * cannot figure out if the packet is fragmented or not,
1724 * so we tell the KERNEL CHECKSUM_NONE
1726 skb_checksum_none_assert(skb
);
1729 static int atl1c_alloc_rx_buffer(struct atl1c_adapter
*adapter
, const int ringid
)
1731 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
[ringid
];
1732 struct pci_dev
*pdev
= adapter
->pdev
;
1733 struct atl1c_buffer
*buffer_info
, *next_info
;
1734 struct sk_buff
*skb
;
1735 void *vir_addr
= NULL
;
1737 u16 rfd_next_to_use
, next_next
;
1738 struct atl1c_rx_free_desc
*rfd_desc
;
1740 next_next
= rfd_next_to_use
= rfd_ring
->next_to_use
;
1741 if (++next_next
== rfd_ring
->count
)
1743 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1744 next_info
= &rfd_ring
->buffer_info
[next_next
];
1746 while (next_info
->flags
& ATL1C_BUFFER_FREE
) {
1747 rfd_desc
= ATL1C_RFD_DESC(rfd_ring
, rfd_next_to_use
);
1749 skb
= dev_alloc_skb(adapter
->rx_buffer_len
);
1750 if (unlikely(!skb
)) {
1751 if (netif_msg_rx_err(adapter
))
1752 dev_warn(&pdev
->dev
, "alloc rx buffer failed\n");
1757 * Make buffer alignment 2 beyond a 16 byte boundary
1758 * this will result in a 16 byte aligned IP header after
1759 * the 14 byte MAC header is removed
1761 vir_addr
= skb
->data
;
1762 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
1763 buffer_info
->skb
= skb
;
1764 buffer_info
->length
= adapter
->rx_buffer_len
;
1765 buffer_info
->dma
= pci_map_single(pdev
, vir_addr
,
1766 buffer_info
->length
,
1767 PCI_DMA_FROMDEVICE
);
1768 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
1769 ATL1C_PCIMAP_FROMDEVICE
);
1770 rfd_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
1771 rfd_next_to_use
= next_next
;
1772 if (++next_next
== rfd_ring
->count
)
1774 buffer_info
= &rfd_ring
->buffer_info
[rfd_next_to_use
];
1775 next_info
= &rfd_ring
->buffer_info
[next_next
];
1780 /* TODO: update mailbox here */
1782 rfd_ring
->next_to_use
= rfd_next_to_use
;
1783 AT_WRITE_REG(&adapter
->hw
, atl1c_rfd_prod_idx_regs
[ringid
],
1784 rfd_ring
->next_to_use
& MB_RFDX_PROD_IDX_MASK
);
1790 static void atl1c_clean_rrd(struct atl1c_rrd_ring
*rrd_ring
,
1791 struct atl1c_recv_ret_status
*rrs
, u16 num
)
1794 /* the relationship between rrd and rfd is one map one */
1795 for (i
= 0; i
< num
; i
++, rrs
= ATL1C_RRD_DESC(rrd_ring
,
1796 rrd_ring
->next_to_clean
)) {
1797 rrs
->word3
&= ~RRS_RXD_UPDATED
;
1798 if (++rrd_ring
->next_to_clean
== rrd_ring
->count
)
1799 rrd_ring
->next_to_clean
= 0;
1803 static void atl1c_clean_rfd(struct atl1c_rfd_ring
*rfd_ring
,
1804 struct atl1c_recv_ret_status
*rrs
, u16 num
)
1808 struct atl1c_buffer
*buffer_info
= rfd_ring
->buffer_info
;
1810 rfd_index
= (rrs
->word0
>> RRS_RX_RFD_INDEX_SHIFT
) &
1811 RRS_RX_RFD_INDEX_MASK
;
1812 for (i
= 0; i
< num
; i
++) {
1813 buffer_info
[rfd_index
].skb
= NULL
;
1814 ATL1C_SET_BUFFER_STATE(&buffer_info
[rfd_index
],
1816 if (++rfd_index
== rfd_ring
->count
)
1819 rfd_ring
->next_to_clean
= rfd_index
;
1822 static void atl1c_clean_rx_irq(struct atl1c_adapter
*adapter
, u8 que
,
1823 int *work_done
, int work_to_do
)
1825 u16 rfd_num
, rfd_index
;
1828 struct pci_dev
*pdev
= adapter
->pdev
;
1829 struct net_device
*netdev
= adapter
->netdev
;
1830 struct atl1c_rfd_ring
*rfd_ring
= &adapter
->rfd_ring
[que
];
1831 struct atl1c_rrd_ring
*rrd_ring
= &adapter
->rrd_ring
[que
];
1832 struct sk_buff
*skb
;
1833 struct atl1c_recv_ret_status
*rrs
;
1834 struct atl1c_buffer
*buffer_info
;
1837 if (*work_done
>= work_to_do
)
1839 rrs
= ATL1C_RRD_DESC(rrd_ring
, rrd_ring
->next_to_clean
);
1840 if (likely(RRS_RXD_IS_VALID(rrs
->word3
))) {
1841 rfd_num
= (rrs
->word0
>> RRS_RX_RFD_CNT_SHIFT
) &
1842 RRS_RX_RFD_CNT_MASK
;
1843 if (unlikely(rfd_num
!= 1))
1844 /* TODO support mul rfd*/
1845 if (netif_msg_rx_err(adapter
))
1846 dev_warn(&pdev
->dev
,
1847 "Multi rfd not support yet!\n");
1853 atl1c_clean_rrd(rrd_ring
, rrs
, rfd_num
);
1854 if (rrs
->word3
& (RRS_RX_ERR_SUM
| RRS_802_3_LEN_ERR
)) {
1855 atl1c_clean_rfd(rfd_ring
, rrs
, rfd_num
);
1856 if (netif_msg_rx_err(adapter
))
1857 dev_warn(&pdev
->dev
,
1858 "wrong packet! rrs word3 is %x\n",
1863 length
= le16_to_cpu((rrs
->word3
>> RRS_PKT_SIZE_SHIFT
) &
1866 if (likely(rfd_num
== 1)) {
1867 rfd_index
= (rrs
->word0
>> RRS_RX_RFD_INDEX_SHIFT
) &
1868 RRS_RX_RFD_INDEX_MASK
;
1869 buffer_info
= &rfd_ring
->buffer_info
[rfd_index
];
1870 pci_unmap_single(pdev
, buffer_info
->dma
,
1871 buffer_info
->length
, PCI_DMA_FROMDEVICE
);
1872 skb
= buffer_info
->skb
;
1875 if (netif_msg_rx_err(adapter
))
1876 dev_warn(&pdev
->dev
,
1877 "Multi rfd not support yet!\n");
1880 atl1c_clean_rfd(rfd_ring
, rrs
, rfd_num
);
1881 skb_put(skb
, length
- ETH_FCS_LEN
);
1882 skb
->protocol
= eth_type_trans(skb
, netdev
);
1883 atl1c_rx_checksum(adapter
, skb
, rrs
);
1884 if (unlikely(adapter
->vlgrp
) && rrs
->word3
& RRS_VLAN_INS
) {
1887 AT_TAG_TO_VLAN(rrs
->vlan_tag
, vlan
);
1888 vlan
= le16_to_cpu(vlan
);
1889 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
, vlan
);
1891 netif_receive_skb(skb
);
1897 atl1c_alloc_rx_buffer(adapter
, que
);
1901 * atl1c_clean - NAPI Rx polling callback
1902 * @adapter: board private structure
1904 static int atl1c_clean(struct napi_struct
*napi
, int budget
)
1906 struct atl1c_adapter
*adapter
=
1907 container_of(napi
, struct atl1c_adapter
, napi
);
1910 /* Keep link state information with original netdev */
1911 if (!netif_carrier_ok(adapter
->netdev
))
1913 /* just enable one RXQ */
1914 atl1c_clean_rx_irq(adapter
, 0, &work_done
, budget
);
1916 if (work_done
< budget
) {
1918 napi_complete(napi
);
1919 adapter
->hw
.intr_mask
|= ISR_RX_PKT
;
1920 AT_WRITE_REG(&adapter
->hw
, REG_IMR
, adapter
->hw
.intr_mask
);
1925 #ifdef CONFIG_NET_POLL_CONTROLLER
1928 * Polling 'interrupt' - used by things like netconsole to send skbs
1929 * without having to re-enable interrupts. It's not called while
1930 * the interrupt routine is executing.
1932 static void atl1c_netpoll(struct net_device
*netdev
)
1934 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
1936 disable_irq(adapter
->pdev
->irq
);
1937 atl1c_intr(adapter
->pdev
->irq
, netdev
);
1938 enable_irq(adapter
->pdev
->irq
);
1942 static inline u16
atl1c_tpd_avail(struct atl1c_adapter
*adapter
, enum atl1c_trans_queue type
)
1944 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
1945 u16 next_to_use
= 0;
1946 u16 next_to_clean
= 0;
1948 next_to_clean
= atomic_read(&tpd_ring
->next_to_clean
);
1949 next_to_use
= tpd_ring
->next_to_use
;
1951 return (u16
)(next_to_clean
> next_to_use
) ?
1952 (next_to_clean
- next_to_use
- 1) :
1953 (tpd_ring
->count
+ next_to_clean
- next_to_use
- 1);
1957 * get next usable tpd
1958 * Note: should call atl1c_tdp_avail to make sure
1959 * there is enough tpd to use
1961 static struct atl1c_tpd_desc
*atl1c_get_tpd(struct atl1c_adapter
*adapter
,
1962 enum atl1c_trans_queue type
)
1964 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
1965 struct atl1c_tpd_desc
*tpd_desc
;
1966 u16 next_to_use
= 0;
1968 next_to_use
= tpd_ring
->next_to_use
;
1969 if (++tpd_ring
->next_to_use
== tpd_ring
->count
)
1970 tpd_ring
->next_to_use
= 0;
1971 tpd_desc
= ATL1C_TPD_DESC(tpd_ring
, next_to_use
);
1972 memset(tpd_desc
, 0, sizeof(struct atl1c_tpd_desc
));
1976 static struct atl1c_buffer
*
1977 atl1c_get_tx_buffer(struct atl1c_adapter
*adapter
, struct atl1c_tpd_desc
*tpd
)
1979 struct atl1c_tpd_ring
*tpd_ring
= adapter
->tpd_ring
;
1981 return &tpd_ring
->buffer_info
[tpd
-
1982 (struct atl1c_tpd_desc
*)tpd_ring
->desc
];
1985 /* Calculate the transmit packet descript needed*/
1986 static u16
atl1c_cal_tpd_req(const struct sk_buff
*skb
)
1989 u16 proto_hdr_len
= 0;
1991 tpd_req
= skb_shinfo(skb
)->nr_frags
+ 1;
1993 if (skb_is_gso(skb
)) {
1994 proto_hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1995 if (proto_hdr_len
< skb_headlen(skb
))
1997 if (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV6
)
2003 static int atl1c_tso_csum(struct atl1c_adapter
*adapter
,
2004 struct sk_buff
*skb
,
2005 struct atl1c_tpd_desc
**tpd
,
2006 enum atl1c_trans_queue type
)
2008 struct pci_dev
*pdev
= adapter
->pdev
;
2011 unsigned short offload_type
;
2014 if (skb_is_gso(skb
)) {
2015 if (skb_header_cloned(skb
)) {
2016 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2020 offload_type
= skb_shinfo(skb
)->gso_type
;
2022 if (offload_type
& SKB_GSO_TCPV4
) {
2023 real_len
= (((unsigned char *)ip_hdr(skb
) - skb
->data
)
2024 + ntohs(ip_hdr(skb
)->tot_len
));
2026 if (real_len
< skb
->len
)
2027 pskb_trim(skb
, real_len
);
2029 hdr_len
= (skb_transport_offset(skb
) + tcp_hdrlen(skb
));
2030 if (unlikely(skb
->len
== hdr_len
)) {
2031 /* only xsum need */
2032 if (netif_msg_tx_queued(adapter
))
2033 dev_warn(&pdev
->dev
,
2034 "IPV4 tso with zero data??\n");
2037 ip_hdr(skb
)->check
= 0;
2038 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(
2042 (*tpd
)->word1
|= 1 << TPD_IPV4_PACKET_SHIFT
;
2046 if (offload_type
& SKB_GSO_TCPV6
) {
2047 struct atl1c_tpd_ext_desc
*etpd
=
2048 *(struct atl1c_tpd_ext_desc
**)(tpd
);
2050 memset(etpd
, 0, sizeof(struct atl1c_tpd_ext_desc
));
2051 *tpd
= atl1c_get_tpd(adapter
, type
);
2052 ipv6_hdr(skb
)->payload_len
= 0;
2053 /* check payload == 0 byte ? */
2054 hdr_len
= (skb_transport_offset(skb
) + tcp_hdrlen(skb
));
2055 if (unlikely(skb
->len
== hdr_len
)) {
2056 /* only xsum need */
2057 if (netif_msg_tx_queued(adapter
))
2058 dev_warn(&pdev
->dev
,
2059 "IPV6 tso with zero data??\n");
2062 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(
2063 &ipv6_hdr(skb
)->saddr
,
2064 &ipv6_hdr(skb
)->daddr
,
2066 etpd
->word1
|= 1 << TPD_LSO_EN_SHIFT
;
2067 etpd
->word1
|= 1 << TPD_LSO_VER_SHIFT
;
2068 etpd
->pkt_len
= cpu_to_le32(skb
->len
);
2069 (*tpd
)->word1
|= 1 << TPD_LSO_VER_SHIFT
;
2072 (*tpd
)->word1
|= 1 << TPD_LSO_EN_SHIFT
;
2073 (*tpd
)->word1
|= (skb_transport_offset(skb
) & TPD_TCPHDR_OFFSET_MASK
) <<
2074 TPD_TCPHDR_OFFSET_SHIFT
;
2075 (*tpd
)->word1
|= (skb_shinfo(skb
)->gso_size
& TPD_MSS_MASK
) <<
2081 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
2083 cso
= skb_checksum_start_offset(skb
);
2085 if (unlikely(cso
& 0x1)) {
2086 if (netif_msg_tx_err(adapter
))
2087 dev_err(&adapter
->pdev
->dev
,
2088 "payload offset should not an event number\n");
2091 css
= cso
+ skb
->csum_offset
;
2093 (*tpd
)->word1
|= ((cso
>> 1) & TPD_PLOADOFFSET_MASK
) <<
2094 TPD_PLOADOFFSET_SHIFT
;
2095 (*tpd
)->word1
|= ((css
>> 1) & TPD_CCSUM_OFFSET_MASK
) <<
2096 TPD_CCSUM_OFFSET_SHIFT
;
2097 (*tpd
)->word1
|= 1 << TPD_CCSUM_EN_SHIFT
;
2103 static void atl1c_tx_map(struct atl1c_adapter
*adapter
,
2104 struct sk_buff
*skb
, struct atl1c_tpd_desc
*tpd
,
2105 enum atl1c_trans_queue type
)
2107 struct atl1c_tpd_desc
*use_tpd
= NULL
;
2108 struct atl1c_buffer
*buffer_info
= NULL
;
2109 u16 buf_len
= skb_headlen(skb
);
2117 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2118 tso
= (tpd
->word1
>> TPD_LSO_EN_SHIFT
) & TPD_LSO_EN_MASK
;
2121 map_len
= hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2124 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2125 buffer_info
->length
= map_len
;
2126 buffer_info
->dma
= pci_map_single(adapter
->pdev
,
2127 skb
->data
, hdr_len
, PCI_DMA_TODEVICE
);
2128 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2129 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
2130 ATL1C_PCIMAP_TODEVICE
);
2131 mapped_len
+= map_len
;
2132 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2133 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2136 if (mapped_len
< buf_len
) {
2137 /* mapped_len == 0, means we should use the first tpd,
2138 which is given by caller */
2139 if (mapped_len
== 0)
2142 use_tpd
= atl1c_get_tpd(adapter
, type
);
2143 memcpy(use_tpd
, tpd
, sizeof(struct atl1c_tpd_desc
));
2145 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2146 buffer_info
->length
= buf_len
- mapped_len
;
2148 pci_map_single(adapter
->pdev
, skb
->data
+ mapped_len
,
2149 buffer_info
->length
, PCI_DMA_TODEVICE
);
2150 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2151 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_SINGLE
,
2152 ATL1C_PCIMAP_TODEVICE
);
2153 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2154 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2157 for (f
= 0; f
< nr_frags
; f
++) {
2158 struct skb_frag_struct
*frag
;
2160 frag
= &skb_shinfo(skb
)->frags
[f
];
2162 use_tpd
= atl1c_get_tpd(adapter
, type
);
2163 memcpy(use_tpd
, tpd
, sizeof(struct atl1c_tpd_desc
));
2165 buffer_info
= atl1c_get_tx_buffer(adapter
, use_tpd
);
2166 buffer_info
->length
= frag
->size
;
2168 pci_map_page(adapter
->pdev
, frag
->page
,
2170 buffer_info
->length
,
2172 ATL1C_SET_BUFFER_STATE(buffer_info
, ATL1C_BUFFER_BUSY
);
2173 ATL1C_SET_PCIMAP_TYPE(buffer_info
, ATL1C_PCIMAP_PAGE
,
2174 ATL1C_PCIMAP_TODEVICE
);
2175 use_tpd
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2176 use_tpd
->buffer_len
= cpu_to_le16(buffer_info
->length
);
2180 use_tpd
->word1
|= 1 << TPD_EOP_SHIFT
;
2181 /* The last buffer info contain the skb address,
2182 so it will be free after unmap */
2183 buffer_info
->skb
= skb
;
2186 static void atl1c_tx_queue(struct atl1c_adapter
*adapter
, struct sk_buff
*skb
,
2187 struct atl1c_tpd_desc
*tpd
, enum atl1c_trans_queue type
)
2189 struct atl1c_tpd_ring
*tpd_ring
= &adapter
->tpd_ring
[type
];
2192 AT_READ_REG(&adapter
->hw
, REG_MB_PRIO_PROD_IDX
, &prod_data
);
2194 case atl1c_trans_high
:
2195 prod_data
&= 0xFFFF0000;
2196 prod_data
|= tpd_ring
->next_to_use
& 0xFFFF;
2198 case atl1c_trans_normal
:
2199 prod_data
&= 0x0000FFFF;
2200 prod_data
|= (tpd_ring
->next_to_use
& 0xFFFF) << 16;
2206 AT_WRITE_REG(&adapter
->hw
, REG_MB_PRIO_PROD_IDX
, prod_data
);
2209 static netdev_tx_t
atl1c_xmit_frame(struct sk_buff
*skb
,
2210 struct net_device
*netdev
)
2212 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2213 unsigned long flags
;
2215 struct atl1c_tpd_desc
*tpd
;
2216 enum atl1c_trans_queue type
= atl1c_trans_normal
;
2218 if (test_bit(__AT_DOWN
, &adapter
->flags
)) {
2219 dev_kfree_skb_any(skb
);
2220 return NETDEV_TX_OK
;
2223 tpd_req
= atl1c_cal_tpd_req(skb
);
2224 if (!spin_trylock_irqsave(&adapter
->tx_lock
, flags
)) {
2225 if (netif_msg_pktdata(adapter
))
2226 dev_info(&adapter
->pdev
->dev
, "tx locked\n");
2227 return NETDEV_TX_LOCKED
;
2229 if (skb
->mark
== 0x01)
2230 type
= atl1c_trans_high
;
2232 type
= atl1c_trans_normal
;
2234 if (atl1c_tpd_avail(adapter
, type
) < tpd_req
) {
2235 /* no enough descriptor, just stop queue */
2236 netif_stop_queue(netdev
);
2237 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2238 return NETDEV_TX_BUSY
;
2241 tpd
= atl1c_get_tpd(adapter
, type
);
2243 /* do TSO and check sum */
2244 if (atl1c_tso_csum(adapter
, skb
, &tpd
, type
) != 0) {
2245 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2246 dev_kfree_skb_any(skb
);
2247 return NETDEV_TX_OK
;
2250 if (unlikely(vlan_tx_tag_present(skb
))) {
2251 u16 vlan
= vlan_tx_tag_get(skb
);
2254 vlan
= cpu_to_le16(vlan
);
2255 AT_VLAN_TO_TAG(vlan
, tag
);
2256 tpd
->word1
|= 1 << TPD_INS_VTAG_SHIFT
;
2257 tpd
->vlan_tag
= tag
;
2260 if (skb_network_offset(skb
) != ETH_HLEN
)
2261 tpd
->word1
|= 1 << TPD_ETH_TYPE_SHIFT
; /* Ethernet frame */
2263 atl1c_tx_map(adapter
, skb
, tpd
, type
);
2264 atl1c_tx_queue(adapter
, skb
, tpd
, type
);
2266 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2267 return NETDEV_TX_OK
;
2270 static void atl1c_free_irq(struct atl1c_adapter
*adapter
)
2272 struct net_device
*netdev
= adapter
->netdev
;
2274 free_irq(adapter
->pdev
->irq
, netdev
);
2276 if (adapter
->have_msi
)
2277 pci_disable_msi(adapter
->pdev
);
2280 static int atl1c_request_irq(struct atl1c_adapter
*adapter
)
2282 struct pci_dev
*pdev
= adapter
->pdev
;
2283 struct net_device
*netdev
= adapter
->netdev
;
2287 adapter
->have_msi
= true;
2288 err
= pci_enable_msi(adapter
->pdev
);
2290 if (netif_msg_ifup(adapter
))
2292 "Unable to allocate MSI interrupt Error: %d\n",
2294 adapter
->have_msi
= false;
2296 netdev
->irq
= pdev
->irq
;
2298 if (!adapter
->have_msi
)
2299 flags
|= IRQF_SHARED
;
2300 err
= request_irq(adapter
->pdev
->irq
, atl1c_intr
, flags
,
2301 netdev
->name
, netdev
);
2303 if (netif_msg_ifup(adapter
))
2305 "Unable to allocate interrupt Error: %d\n",
2307 if (adapter
->have_msi
)
2308 pci_disable_msi(adapter
->pdev
);
2311 if (netif_msg_ifup(adapter
))
2312 dev_dbg(&pdev
->dev
, "atl1c_request_irq OK\n");
2316 static int atl1c_up(struct atl1c_adapter
*adapter
)
2318 struct net_device
*netdev
= adapter
->netdev
;
2323 netif_carrier_off(netdev
);
2324 atl1c_init_ring_ptrs(adapter
);
2325 atl1c_set_multi(netdev
);
2326 atl1c_restore_vlan(adapter
);
2328 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2329 num
= atl1c_alloc_rx_buffer(adapter
, i
);
2330 if (unlikely(num
== 0)) {
2336 if (atl1c_configure(adapter
)) {
2341 err
= atl1c_request_irq(adapter
);
2345 clear_bit(__AT_DOWN
, &adapter
->flags
);
2346 napi_enable(&adapter
->napi
);
2347 atl1c_irq_enable(adapter
);
2348 atl1c_check_link_status(adapter
);
2349 netif_start_queue(netdev
);
2354 atl1c_clean_rx_ring(adapter
);
2358 static void atl1c_down(struct atl1c_adapter
*adapter
)
2360 struct net_device
*netdev
= adapter
->netdev
;
2362 atl1c_del_timer(adapter
);
2363 adapter
->work_event
= 0; /* clear all event */
2364 /* signal that we're down so the interrupt handler does not
2365 * reschedule our watchdog timer */
2366 set_bit(__AT_DOWN
, &adapter
->flags
);
2367 netif_carrier_off(netdev
);
2368 napi_disable(&adapter
->napi
);
2369 atl1c_irq_disable(adapter
);
2370 atl1c_free_irq(adapter
);
2371 /* reset MAC to disable all RX/TX */
2372 atl1c_reset_mac(&adapter
->hw
);
2375 adapter
->link_speed
= SPEED_0
;
2376 adapter
->link_duplex
= -1;
2377 atl1c_clean_tx_ring(adapter
, atl1c_trans_normal
);
2378 atl1c_clean_tx_ring(adapter
, atl1c_trans_high
);
2379 atl1c_clean_rx_ring(adapter
);
2383 * atl1c_open - Called when a network interface is made active
2384 * @netdev: network interface device structure
2386 * Returns 0 on success, negative value on failure
2388 * The open entry point is called when a network interface is made
2389 * active by the system (IFF_UP). At this point all resources needed
2390 * for transmit and receive operations are allocated, the interrupt
2391 * handler is registered with the OS, the watchdog timer is started,
2392 * and the stack is notified that the interface is ready.
2394 static int atl1c_open(struct net_device
*netdev
)
2396 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2399 /* disallow open during test */
2400 if (test_bit(__AT_TESTING
, &adapter
->flags
))
2403 /* allocate rx/tx dma buffer & descriptors */
2404 err
= atl1c_setup_ring_resources(adapter
);
2408 err
= atl1c_up(adapter
);
2412 if (adapter
->hw
.ctrl_flags
& ATL1C_FPGA_VERSION
) {
2415 AT_READ_REG(&adapter
->hw
, REG_MDIO_CTRL
, &phy_data
);
2416 phy_data
|= MDIO_AP_EN
;
2417 AT_WRITE_REG(&adapter
->hw
, REG_MDIO_CTRL
, phy_data
);
2422 atl1c_free_irq(adapter
);
2423 atl1c_free_ring_resources(adapter
);
2424 atl1c_reset_mac(&adapter
->hw
);
2429 * atl1c_close - Disables a network interface
2430 * @netdev: network interface device structure
2432 * Returns 0, this is not allowed to fail
2434 * The close entry point is called when an interface is de-activated
2435 * by the OS. The hardware is still under the drivers control, but
2436 * needs to be disabled. A global MAC reset is issued to stop the
2437 * hardware, and all transmit and receive resources are freed.
2439 static int atl1c_close(struct net_device
*netdev
)
2441 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2443 WARN_ON(test_bit(__AT_RESETTING
, &adapter
->flags
));
2444 atl1c_down(adapter
);
2445 atl1c_free_ring_resources(adapter
);
2449 static int atl1c_suspend(struct device
*dev
)
2451 struct pci_dev
*pdev
= to_pci_dev(dev
);
2452 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2453 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2454 struct atl1c_hw
*hw
= &adapter
->hw
;
2455 u32 mac_ctrl_data
= 0;
2456 u32 master_ctrl_data
= 0;
2457 u32 wol_ctrl_data
= 0;
2458 u16 mii_intr_status_data
= 0;
2459 u32 wufc
= adapter
->wol
;
2461 atl1c_disable_l0s_l1(hw
);
2462 if (netif_running(netdev
)) {
2463 WARN_ON(test_bit(__AT_RESETTING
, &adapter
->flags
));
2464 atl1c_down(adapter
);
2466 netif_device_detach(netdev
);
2469 if (atl1c_phy_power_saving(hw
) != 0)
2470 dev_dbg(&pdev
->dev
, "phy power saving failed");
2472 AT_READ_REG(hw
, REG_MASTER_CTRL
, &master_ctrl_data
);
2473 AT_READ_REG(hw
, REG_MAC_CTRL
, &mac_ctrl_data
);
2475 master_ctrl_data
&= ~MASTER_CTRL_CLK_SEL_DIS
;
2476 mac_ctrl_data
&= ~(MAC_CTRL_PRMLEN_MASK
<< MAC_CTRL_PRMLEN_SHIFT
);
2477 mac_ctrl_data
|= (((u32
)adapter
->hw
.preamble_len
&
2478 MAC_CTRL_PRMLEN_MASK
) <<
2479 MAC_CTRL_PRMLEN_SHIFT
);
2480 mac_ctrl_data
&= ~(MAC_CTRL_SPEED_MASK
<< MAC_CTRL_SPEED_SHIFT
);
2481 mac_ctrl_data
&= ~MAC_CTRL_DUPLX
;
2484 mac_ctrl_data
|= MAC_CTRL_RX_EN
;
2485 if (adapter
->link_speed
== SPEED_1000
||
2486 adapter
->link_speed
== SPEED_0
) {
2487 mac_ctrl_data
|= atl1c_mac_speed_1000
<<
2488 MAC_CTRL_SPEED_SHIFT
;
2489 mac_ctrl_data
|= MAC_CTRL_DUPLX
;
2491 mac_ctrl_data
|= atl1c_mac_speed_10_100
<<
2492 MAC_CTRL_SPEED_SHIFT
;
2494 if (adapter
->link_duplex
== DUPLEX_FULL
)
2495 mac_ctrl_data
|= MAC_CTRL_DUPLX
;
2497 /* turn on magic packet wol */
2498 if (wufc
& AT_WUFC_MAG
)
2499 wol_ctrl_data
|= WOL_MAGIC_EN
| WOL_MAGIC_PME_EN
;
2501 if (wufc
& AT_WUFC_LNKC
) {
2502 wol_ctrl_data
|= WOL_LINK_CHG_EN
| WOL_LINK_CHG_PME_EN
;
2503 /* only link up can wake up */
2504 if (atl1c_write_phy_reg(hw
, MII_IER
, IER_LINK_UP
) != 0) {
2505 dev_dbg(&pdev
->dev
, "%s: read write phy "
2506 "register failed.\n",
2510 /* clear phy interrupt */
2511 atl1c_read_phy_reg(hw
, MII_ISR
, &mii_intr_status_data
);
2512 /* Config MAC Ctrl register */
2514 mac_ctrl_data
|= MAC_CTRL_RMV_VLAN
;
2516 /* magic packet maybe Broadcast&multicast&Unicast frame */
2517 if (wufc
& AT_WUFC_MAG
)
2518 mac_ctrl_data
|= MAC_CTRL_BC_EN
;
2521 "%s: suspend MAC=0x%x\n",
2522 atl1c_driver_name
, mac_ctrl_data
);
2523 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, master_ctrl_data
);
2524 AT_WRITE_REG(hw
, REG_WOL_CTRL
, wol_ctrl_data
);
2525 AT_WRITE_REG(hw
, REG_MAC_CTRL
, mac_ctrl_data
);
2527 AT_WRITE_REG(hw
, REG_GPHY_CTRL
, GPHY_CTRL_DEFAULT
|
2528 GPHY_CTRL_EXT_RESET
);
2530 AT_WRITE_REG(hw
, REG_GPHY_CTRL
, GPHY_CTRL_POWER_SAVING
);
2531 master_ctrl_data
|= MASTER_CTRL_CLK_SEL_DIS
;
2532 mac_ctrl_data
|= atl1c_mac_speed_10_100
<< MAC_CTRL_SPEED_SHIFT
;
2533 mac_ctrl_data
|= MAC_CTRL_DUPLX
;
2534 AT_WRITE_REG(hw
, REG_MASTER_CTRL
, master_ctrl_data
);
2535 AT_WRITE_REG(hw
, REG_MAC_CTRL
, mac_ctrl_data
);
2536 AT_WRITE_REG(hw
, REG_WOL_CTRL
, 0);
2537 hw
->phy_configured
= false; /* re-init PHY when resume */
2543 static int atl1c_resume(struct device
*dev
)
2545 struct pci_dev
*pdev
= to_pci_dev(dev
);
2546 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2547 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2549 AT_WRITE_REG(&adapter
->hw
, REG_WOL_CTRL
, 0);
2550 atl1c_reset_pcie(&adapter
->hw
, ATL1C_PCIE_L0S_L1_DISABLE
|
2551 ATL1C_PCIE_PHY_RESET
);
2553 atl1c_phy_reset(&adapter
->hw
);
2554 atl1c_reset_mac(&adapter
->hw
);
2555 atl1c_phy_init(&adapter
->hw
);
2558 AT_READ_REG(&adapter
->hw
, REG_PM_CTRLSTAT
, &pm_data
);
2559 pm_data
&= ~PM_CTRLSTAT_PME_EN
;
2560 AT_WRITE_REG(&adapter
->hw
, REG_PM_CTRLSTAT
, pm_data
);
2563 netif_device_attach(netdev
);
2564 if (netif_running(netdev
))
2570 static void atl1c_shutdown(struct pci_dev
*pdev
)
2572 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2573 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2575 atl1c_suspend(&pdev
->dev
);
2576 pci_wake_from_d3(pdev
, adapter
->wol
);
2577 pci_set_power_state(pdev
, PCI_D3hot
);
2580 static const struct net_device_ops atl1c_netdev_ops
= {
2581 .ndo_open
= atl1c_open
,
2582 .ndo_stop
= atl1c_close
,
2583 .ndo_validate_addr
= eth_validate_addr
,
2584 .ndo_start_xmit
= atl1c_xmit_frame
,
2585 .ndo_set_mac_address
= atl1c_set_mac_addr
,
2586 .ndo_set_multicast_list
= atl1c_set_multi
,
2587 .ndo_change_mtu
= atl1c_change_mtu
,
2588 .ndo_do_ioctl
= atl1c_ioctl
,
2589 .ndo_tx_timeout
= atl1c_tx_timeout
,
2590 .ndo_get_stats
= atl1c_get_stats
,
2591 .ndo_vlan_rx_register
= atl1c_vlan_rx_register
,
2592 #ifdef CONFIG_NET_POLL_CONTROLLER
2593 .ndo_poll_controller
= atl1c_netpoll
,
2597 static int atl1c_init_netdev(struct net_device
*netdev
, struct pci_dev
*pdev
)
2599 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2600 pci_set_drvdata(pdev
, netdev
);
2602 netdev
->irq
= pdev
->irq
;
2603 netdev
->netdev_ops
= &atl1c_netdev_ops
;
2604 netdev
->watchdog_timeo
= AT_TX_WATCHDOG
;
2605 atl1c_set_ethtool_ops(netdev
);
2607 /* TODO: add when ready */
2608 netdev
->features
= NETIF_F_SG
|
2610 NETIF_F_HW_VLAN_TX
|
2611 NETIF_F_HW_VLAN_RX
|
2618 * atl1c_probe - Device Initialization Routine
2619 * @pdev: PCI device information struct
2620 * @ent: entry in atl1c_pci_tbl
2622 * Returns 0 on success, negative on failure
2624 * atl1c_probe initializes an adapter identified by a pci_dev structure.
2625 * The OS initialization, configuring of the adapter private structure,
2626 * and a hardware reset occur.
2628 static int __devinit
atl1c_probe(struct pci_dev
*pdev
,
2629 const struct pci_device_id
*ent
)
2631 struct net_device
*netdev
;
2632 struct atl1c_adapter
*adapter
;
2633 static int cards_found
;
2637 /* enable device (incl. PCI PM wakeup and hotplug setup) */
2638 err
= pci_enable_device_mem(pdev
);
2640 dev_err(&pdev
->dev
, "cannot enable PCI device\n");
2645 * The atl1c chip can DMA to 64-bit addresses, but it uses a single
2646 * shared register for the high 32 bits, so only a single, aligned,
2647 * 4 GB physical address range can be used at a time.
2649 * Supporting 64-bit DMA on this hardware is more trouble than it's
2650 * worth. It is far easier to limit to 32-bit DMA than update
2651 * various kernel subsystems to support the mechanics required by a
2652 * fixed-high-32-bit system.
2654 if ((pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0) ||
2655 (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0)) {
2656 dev_err(&pdev
->dev
, "No usable DMA configuration,aborting\n");
2660 err
= pci_request_regions(pdev
, atl1c_driver_name
);
2662 dev_err(&pdev
->dev
, "cannot obtain PCI resources\n");
2666 pci_set_master(pdev
);
2668 netdev
= alloc_etherdev(sizeof(struct atl1c_adapter
));
2669 if (netdev
== NULL
) {
2671 dev_err(&pdev
->dev
, "etherdev alloc failed\n");
2672 goto err_alloc_etherdev
;
2675 err
= atl1c_init_netdev(netdev
, pdev
);
2677 dev_err(&pdev
->dev
, "init netdevice failed\n");
2678 goto err_init_netdev
;
2680 adapter
= netdev_priv(netdev
);
2681 adapter
->bd_number
= cards_found
;
2682 adapter
->netdev
= netdev
;
2683 adapter
->pdev
= pdev
;
2684 adapter
->hw
.adapter
= adapter
;
2685 adapter
->msg_enable
= netif_msg_init(-1, atl1c_default_msg
);
2686 adapter
->hw
.hw_addr
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
2687 if (!adapter
->hw
.hw_addr
) {
2689 dev_err(&pdev
->dev
, "cannot map device registers\n");
2692 netdev
->base_addr
= (unsigned long)adapter
->hw
.hw_addr
;
2695 adapter
->mii
.dev
= netdev
;
2696 adapter
->mii
.mdio_read
= atl1c_mdio_read
;
2697 adapter
->mii
.mdio_write
= atl1c_mdio_write
;
2698 adapter
->mii
.phy_id_mask
= 0x1f;
2699 adapter
->mii
.reg_num_mask
= MDIO_REG_ADDR_MASK
;
2700 netif_napi_add(netdev
, &adapter
->napi
, atl1c_clean
, 64);
2701 setup_timer(&adapter
->phy_config_timer
, atl1c_phy_config
,
2702 (unsigned long)adapter
);
2703 /* setup the private structure */
2704 err
= atl1c_sw_init(adapter
);
2706 dev_err(&pdev
->dev
, "net device private data init failed\n");
2709 atl1c_reset_pcie(&adapter
->hw
, ATL1C_PCIE_L0S_L1_DISABLE
|
2710 ATL1C_PCIE_PHY_RESET
);
2712 /* Init GPHY as early as possible due to power saving issue */
2713 atl1c_phy_reset(&adapter
->hw
);
2715 err
= atl1c_reset_mac(&adapter
->hw
);
2721 device_init_wakeup(&pdev
->dev
, 1);
2722 /* reset the controller to
2723 * put the device in a known good starting state */
2724 err
= atl1c_phy_init(&adapter
->hw
);
2729 if (atl1c_read_mac_addr(&adapter
->hw
) != 0) {
2731 dev_err(&pdev
->dev
, "get mac address failed\n");
2734 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
2735 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
2736 if (netif_msg_probe(adapter
))
2737 dev_dbg(&pdev
->dev
, "mac address : %pM\n",
2738 adapter
->hw
.mac_addr
);
2740 atl1c_hw_set_mac_addr(&adapter
->hw
);
2741 INIT_WORK(&adapter
->common_task
, atl1c_common_task
);
2742 adapter
->work_event
= 0;
2743 err
= register_netdev(netdev
);
2745 dev_err(&pdev
->dev
, "register netdevice failed\n");
2749 if (netif_msg_probe(adapter
))
2750 dev_info(&pdev
->dev
, "version %s\n", ATL1C_DRV_VERSION
);
2758 iounmap(adapter
->hw
.hw_addr
);
2761 free_netdev(netdev
);
2763 pci_release_regions(pdev
);
2766 pci_disable_device(pdev
);
2771 * atl1c_remove - Device Removal Routine
2772 * @pdev: PCI device information struct
2774 * atl1c_remove is called by the PCI subsystem to alert the driver
2775 * that it should release a PCI device. The could be caused by a
2776 * Hot-Plug event, or because the driver is going to be removed from
2779 static void __devexit
atl1c_remove(struct pci_dev
*pdev
)
2781 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2782 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2784 unregister_netdev(netdev
);
2785 atl1c_phy_disable(&adapter
->hw
);
2787 iounmap(adapter
->hw
.hw_addr
);
2789 pci_release_regions(pdev
);
2790 pci_disable_device(pdev
);
2791 free_netdev(netdev
);
2795 * atl1c_io_error_detected - called when PCI error is detected
2796 * @pdev: Pointer to PCI device
2797 * @state: The current pci connection state
2799 * This function is called after a PCI bus error affecting
2800 * this device has been detected.
2802 static pci_ers_result_t
atl1c_io_error_detected(struct pci_dev
*pdev
,
2803 pci_channel_state_t state
)
2805 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2806 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2808 netif_device_detach(netdev
);
2810 if (state
== pci_channel_io_perm_failure
)
2811 return PCI_ERS_RESULT_DISCONNECT
;
2813 if (netif_running(netdev
))
2814 atl1c_down(adapter
);
2816 pci_disable_device(pdev
);
2818 /* Request a slot slot reset. */
2819 return PCI_ERS_RESULT_NEED_RESET
;
2823 * atl1c_io_slot_reset - called after the pci bus has been reset.
2824 * @pdev: Pointer to PCI device
2826 * Restart the card from scratch, as if from a cold-boot. Implementation
2827 * resembles the first-half of the e1000_resume routine.
2829 static pci_ers_result_t
atl1c_io_slot_reset(struct pci_dev
*pdev
)
2831 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2832 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2834 if (pci_enable_device(pdev
)) {
2835 if (netif_msg_hw(adapter
))
2837 "Cannot re-enable PCI device after reset\n");
2838 return PCI_ERS_RESULT_DISCONNECT
;
2840 pci_set_master(pdev
);
2842 pci_enable_wake(pdev
, PCI_D3hot
, 0);
2843 pci_enable_wake(pdev
, PCI_D3cold
, 0);
2845 atl1c_reset_mac(&adapter
->hw
);
2847 return PCI_ERS_RESULT_RECOVERED
;
2851 * atl1c_io_resume - called when traffic can start flowing again.
2852 * @pdev: Pointer to PCI device
2854 * This callback is called when the error recovery driver tells us that
2855 * its OK to resume normal operation. Implementation resembles the
2856 * second-half of the atl1c_resume routine.
2858 static void atl1c_io_resume(struct pci_dev
*pdev
)
2860 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2861 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
2863 if (netif_running(netdev
)) {
2864 if (atl1c_up(adapter
)) {
2865 if (netif_msg_hw(adapter
))
2867 "Cannot bring device back up after reset\n");
2872 netif_device_attach(netdev
);
2875 static struct pci_error_handlers atl1c_err_handler
= {
2876 .error_detected
= atl1c_io_error_detected
,
2877 .slot_reset
= atl1c_io_slot_reset
,
2878 .resume
= atl1c_io_resume
,
2881 static SIMPLE_DEV_PM_OPS(atl1c_pm_ops
, atl1c_suspend
, atl1c_resume
);
2883 static struct pci_driver atl1c_driver
= {
2884 .name
= atl1c_driver_name
,
2885 .id_table
= atl1c_pci_tbl
,
2886 .probe
= atl1c_probe
,
2887 .remove
= __devexit_p(atl1c_remove
),
2888 .shutdown
= atl1c_shutdown
,
2889 .err_handler
= &atl1c_err_handler
,
2890 .driver
.pm
= &atl1c_pm_ops
,
2894 * atl1c_init_module - Driver Registration Routine
2896 * atl1c_init_module is the first routine called when the driver is
2897 * loaded. All it does is register with the PCI subsystem.
2899 static int __init
atl1c_init_module(void)
2901 return pci_register_driver(&atl1c_driver
);
2905 * atl1c_exit_module - Driver Exit Cleanup Routine
2907 * atl1c_exit_module is called just before the driver is removed
2910 static void __exit
atl1c_exit_module(void)
2912 pci_unregister_driver(&atl1c_driver
);
2915 module_init(atl1c_init_module
);
2916 module_exit(atl1c_exit_module
);