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