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