1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */ 3 4 #include <linux/types.h> 5 #include <linux/module.h> 6 #include <linux/pci.h> 7 #include <linux/netdevice.h> 8 #include <linux/string.h> 9 #include <linux/aer.h> 10 #include <linux/etherdevice.h> 11 #include <net/ip.h> 12 #include <linux/phy.h> 13 14 #include "../libwx/wx_type.h" 15 #include "../libwx/wx_hw.h" 16 #include "../libwx/wx_lib.h" 17 #include "ngbe_type.h" 18 #include "ngbe_mdio.h" 19 #include "ngbe_hw.h" 20 #include "ngbe_ethtool.h" 21 22 char ngbe_driver_name[] = "ngbe"; 23 24 /* ngbe_pci_tbl - PCI Device ID Table 25 * 26 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, 27 * Class, Class Mask, private data (not used) } 28 */ 29 static const struct pci_device_id ngbe_pci_tbl[] = { 30 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W), 0}, 31 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A2), 0}, 32 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A2S), 0}, 33 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A4), 0}, 34 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A4S), 0}, 35 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL2), 0}, 36 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S), 0}, 37 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL4), 0}, 38 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S), 0}, 39 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860LC), 0}, 40 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A1), 0}, 41 { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A1L), 0}, 42 /* required last entry */ 43 { .device = 0 } 44 }; 45 46 /** 47 * ngbe_init_type_code - Initialize the shared code 48 * @wx: pointer to hardware structure 49 **/ 50 static void ngbe_init_type_code(struct wx *wx) 51 { 52 int wol_mask = 0, ncsi_mask = 0; 53 u16 type_mask = 0, val; 54 55 wx->mac.type = wx_mac_em; 56 type_mask = (u16)(wx->subsystem_device_id & NGBE_OEM_MASK); 57 ncsi_mask = wx->subsystem_device_id & NGBE_NCSI_MASK; 58 wol_mask = wx->subsystem_device_id & NGBE_WOL_MASK; 59 60 val = rd32(wx, WX_CFG_PORT_ST); 61 wx->mac_type = (val & BIT(7)) >> 7 ? 62 em_mac_type_rgmii : 63 em_mac_type_mdi; 64 65 wx->wol_enabled = (wol_mask == NGBE_WOL_SUP) ? 1 : 0; 66 wx->ncsi_enabled = (ncsi_mask == NGBE_NCSI_MASK || 67 type_mask == NGBE_SUBID_OCP_CARD) ? 1 : 0; 68 69 switch (type_mask) { 70 case NGBE_SUBID_LY_YT8521S_SFP: 71 case NGBE_SUBID_LY_M88E1512_SFP: 72 case NGBE_SUBID_YT8521S_SFP_GPIO: 73 case NGBE_SUBID_INTERNAL_YT8521S_SFP_GPIO: 74 wx->gpio_ctrl = 1; 75 break; 76 default: 77 wx->gpio_ctrl = 0; 78 break; 79 } 80 } 81 82 /** 83 * ngbe_init_rss_key - Initialize wx RSS key 84 * @wx: device handle 85 * 86 * Allocates and initializes the RSS key if it is not allocated. 87 **/ 88 static inline int ngbe_init_rss_key(struct wx *wx) 89 { 90 u32 *rss_key; 91 92 if (!wx->rss_key) { 93 rss_key = kzalloc(WX_RSS_KEY_SIZE, GFP_KERNEL); 94 if (unlikely(!rss_key)) 95 return -ENOMEM; 96 97 netdev_rss_key_fill(rss_key, WX_RSS_KEY_SIZE); 98 wx->rss_key = rss_key; 99 } 100 101 return 0; 102 } 103 104 /** 105 * ngbe_sw_init - Initialize general software structures 106 * @wx: board private structure to initialize 107 **/ 108 static int ngbe_sw_init(struct wx *wx) 109 { 110 struct pci_dev *pdev = wx->pdev; 111 u16 msix_count = 0; 112 int err = 0; 113 114 wx->mac.num_rar_entries = NGBE_RAR_ENTRIES; 115 wx->mac.max_rx_queues = NGBE_MAX_RX_QUEUES; 116 wx->mac.max_tx_queues = NGBE_MAX_TX_QUEUES; 117 wx->mac.mcft_size = NGBE_MC_TBL_SIZE; 118 wx->mac.rx_pb_size = NGBE_RX_PB_SIZE; 119 wx->mac.tx_pb_size = NGBE_TDB_PB_SZ; 120 121 /* PCI config space info */ 122 err = wx_sw_init(wx); 123 if (err < 0) { 124 wx_err(wx, "read of internal subsystem device id failed\n"); 125 return err; 126 } 127 128 /* mac type, phy type , oem type */ 129 ngbe_init_type_code(wx); 130 131 /* Set common capability flags and settings */ 132 wx->max_q_vectors = NGBE_MAX_MSIX_VECTORS; 133 err = wx_get_pcie_msix_counts(wx, &msix_count, NGBE_MAX_MSIX_VECTORS); 134 if (err) 135 dev_err(&pdev->dev, "Do not support MSI-X\n"); 136 wx->mac.max_msix_vectors = msix_count; 137 138 if (ngbe_init_rss_key(wx)) 139 return -ENOMEM; 140 141 /* enable itr by default in dynamic mode */ 142 wx->rx_itr_setting = 1; 143 wx->tx_itr_setting = 1; 144 145 /* set default ring sizes */ 146 wx->tx_ring_count = NGBE_DEFAULT_TXD; 147 wx->rx_ring_count = NGBE_DEFAULT_RXD; 148 149 /* set default work limits */ 150 wx->tx_work_limit = NGBE_DEFAULT_TX_WORK; 151 wx->rx_work_limit = NGBE_DEFAULT_RX_WORK; 152 153 return 0; 154 } 155 156 /** 157 * ngbe_irq_enable - Enable default interrupt generation settings 158 * @wx: board private structure 159 * @queues: enable all queues interrupts 160 **/ 161 static void ngbe_irq_enable(struct wx *wx, bool queues) 162 { 163 u32 mask; 164 165 /* enable misc interrupt */ 166 mask = NGBE_PX_MISC_IEN_MASK; 167 168 wr32(wx, WX_GPIO_DDR, WX_GPIO_DDR_0); 169 wr32(wx, WX_GPIO_INTEN, WX_GPIO_INTEN_0 | WX_GPIO_INTEN_1); 170 wr32(wx, WX_GPIO_INTTYPE_LEVEL, 0x0); 171 wr32(wx, WX_GPIO_POLARITY, wx->gpio_ctrl ? 0 : 0x3); 172 173 wr32(wx, WX_PX_MISC_IEN, mask); 174 175 /* mask interrupt */ 176 if (queues) 177 wx_intr_enable(wx, NGBE_INTR_ALL); 178 else 179 wx_intr_enable(wx, NGBE_INTR_MISC(wx)); 180 } 181 182 /** 183 * ngbe_intr - msi/legacy mode Interrupt Handler 184 * @irq: interrupt number 185 * @data: pointer to a network interface device structure 186 **/ 187 static irqreturn_t ngbe_intr(int __always_unused irq, void *data) 188 { 189 struct wx_q_vector *q_vector; 190 struct wx *wx = data; 191 struct pci_dev *pdev; 192 u32 eicr; 193 194 q_vector = wx->q_vector[0]; 195 pdev = wx->pdev; 196 197 eicr = wx_misc_isb(wx, WX_ISB_VEC0); 198 if (!eicr) { 199 /* shared interrupt alert! 200 * the interrupt that we masked before the EICR read. 201 */ 202 if (netif_running(wx->netdev)) 203 ngbe_irq_enable(wx, true); 204 return IRQ_NONE; /* Not our interrupt */ 205 } 206 wx->isb_mem[WX_ISB_VEC0] = 0; 207 if (!(pdev->msi_enabled)) 208 wr32(wx, WX_PX_INTA, 1); 209 210 wx->isb_mem[WX_ISB_MISC] = 0; 211 /* would disable interrupts here but it is auto disabled */ 212 napi_schedule_irqoff(&q_vector->napi); 213 214 if (netif_running(wx->netdev)) 215 ngbe_irq_enable(wx, false); 216 217 return IRQ_HANDLED; 218 } 219 220 static irqreturn_t ngbe_msix_other(int __always_unused irq, void *data) 221 { 222 struct wx *wx = data; 223 224 /* re-enable the original interrupt state, no lsc, no queues */ 225 if (netif_running(wx->netdev)) 226 ngbe_irq_enable(wx, false); 227 228 return IRQ_HANDLED; 229 } 230 231 /** 232 * ngbe_request_msix_irqs - Initialize MSI-X interrupts 233 * @wx: board private structure 234 * 235 * ngbe_request_msix_irqs allocates MSI-X vectors and requests 236 * interrupts from the kernel. 237 **/ 238 static int ngbe_request_msix_irqs(struct wx *wx) 239 { 240 struct net_device *netdev = wx->netdev; 241 int vector, err; 242 243 for (vector = 0; vector < wx->num_q_vectors; vector++) { 244 struct wx_q_vector *q_vector = wx->q_vector[vector]; 245 struct msix_entry *entry = &wx->msix_entries[vector]; 246 247 if (q_vector->tx.ring && q_vector->rx.ring) 248 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 249 "%s-TxRx-%d", netdev->name, entry->entry); 250 else 251 /* skip this unused q_vector */ 252 continue; 253 254 err = request_irq(entry->vector, wx_msix_clean_rings, 0, 255 q_vector->name, q_vector); 256 if (err) { 257 wx_err(wx, "request_irq failed for MSIX interrupt %s Error: %d\n", 258 q_vector->name, err); 259 goto free_queue_irqs; 260 } 261 } 262 263 err = request_irq(wx->msix_entries[vector].vector, 264 ngbe_msix_other, 0, netdev->name, wx); 265 266 if (err) { 267 wx_err(wx, "request_irq for msix_other failed: %d\n", err); 268 goto free_queue_irqs; 269 } 270 271 return 0; 272 273 free_queue_irqs: 274 while (vector) { 275 vector--; 276 free_irq(wx->msix_entries[vector].vector, 277 wx->q_vector[vector]); 278 } 279 wx_reset_interrupt_capability(wx); 280 return err; 281 } 282 283 /** 284 * ngbe_request_irq - initialize interrupts 285 * @wx: board private structure 286 * 287 * Attempts to configure interrupts using the best available 288 * capabilities of the hardware and kernel. 289 **/ 290 static int ngbe_request_irq(struct wx *wx) 291 { 292 struct net_device *netdev = wx->netdev; 293 struct pci_dev *pdev = wx->pdev; 294 int err; 295 296 if (pdev->msix_enabled) 297 err = ngbe_request_msix_irqs(wx); 298 else if (pdev->msi_enabled) 299 err = request_irq(pdev->irq, ngbe_intr, 0, 300 netdev->name, wx); 301 else 302 err = request_irq(pdev->irq, ngbe_intr, IRQF_SHARED, 303 netdev->name, wx); 304 305 if (err) 306 wx_err(wx, "request_irq failed, Error %d\n", err); 307 308 return err; 309 } 310 311 static void ngbe_disable_device(struct wx *wx) 312 { 313 struct net_device *netdev = wx->netdev; 314 u32 i; 315 316 /* disable all enabled rx queues */ 317 for (i = 0; i < wx->num_rx_queues; i++) 318 /* this call also flushes the previous write */ 319 wx_disable_rx_queue(wx, wx->rx_ring[i]); 320 /* disable receives */ 321 wx_disable_rx(wx); 322 wx_napi_disable_all(wx); 323 netif_tx_stop_all_queues(netdev); 324 netif_tx_disable(netdev); 325 if (wx->gpio_ctrl) 326 ngbe_sfp_modules_txrx_powerctl(wx, false); 327 wx_irq_disable(wx); 328 /* disable transmits in the hardware now that interrupts are off */ 329 for (i = 0; i < wx->num_tx_queues; i++) { 330 u8 reg_idx = wx->tx_ring[i]->reg_idx; 331 332 wr32(wx, WX_PX_TR_CFG(reg_idx), WX_PX_TR_CFG_SWFLSH); 333 } 334 } 335 336 static void ngbe_down(struct wx *wx) 337 { 338 phy_stop(wx->phydev); 339 ngbe_disable_device(wx); 340 wx_clean_all_tx_rings(wx); 341 wx_clean_all_rx_rings(wx); 342 } 343 344 static void ngbe_up(struct wx *wx) 345 { 346 wx_configure_vectors(wx); 347 348 /* make sure to complete pre-operations */ 349 smp_mb__before_atomic(); 350 wx_napi_enable_all(wx); 351 /* enable transmits */ 352 netif_tx_start_all_queues(wx->netdev); 353 354 /* clear any pending interrupts, may auto mask */ 355 rd32(wx, WX_PX_IC); 356 rd32(wx, WX_PX_MISC_IC); 357 ngbe_irq_enable(wx, true); 358 if (wx->gpio_ctrl) 359 ngbe_sfp_modules_txrx_powerctl(wx, true); 360 361 phy_start(wx->phydev); 362 } 363 364 /** 365 * ngbe_open - Called when a network interface is made active 366 * @netdev: network interface device structure 367 * 368 * Returns 0 on success, negative value on failure 369 * 370 * The open entry point is called when a network interface is made 371 * active by the system (IFF_UP). 372 **/ 373 static int ngbe_open(struct net_device *netdev) 374 { 375 struct wx *wx = netdev_priv(netdev); 376 int err; 377 378 wx_control_hw(wx, true); 379 380 err = wx_setup_resources(wx); 381 if (err) 382 return err; 383 384 wx_configure(wx); 385 386 err = ngbe_request_irq(wx); 387 if (err) 388 goto err_free_resources; 389 390 err = ngbe_phy_connect(wx); 391 if (err) 392 goto err_free_irq; 393 394 err = netif_set_real_num_tx_queues(netdev, wx->num_tx_queues); 395 if (err) 396 goto err_dis_phy; 397 398 err = netif_set_real_num_rx_queues(netdev, wx->num_rx_queues); 399 if (err) 400 goto err_dis_phy; 401 402 ngbe_up(wx); 403 404 return 0; 405 err_dis_phy: 406 phy_disconnect(wx->phydev); 407 err_free_irq: 408 wx_free_irq(wx); 409 err_free_resources: 410 wx_free_resources(wx); 411 return err; 412 } 413 414 /** 415 * ngbe_close - Disables a network interface 416 * @netdev: network interface device structure 417 * 418 * Returns 0, this is not allowed to fail 419 * 420 * The close entry point is called when an interface is de-activated 421 * by the OS. The hardware is still under the drivers control, but 422 * needs to be disabled. A global MAC reset is issued to stop the 423 * hardware, and all transmit and receive resources are freed. 424 **/ 425 static int ngbe_close(struct net_device *netdev) 426 { 427 struct wx *wx = netdev_priv(netdev); 428 429 ngbe_down(wx); 430 wx_free_irq(wx); 431 wx_free_resources(wx); 432 phy_disconnect(wx->phydev); 433 wx_control_hw(wx, false); 434 435 return 0; 436 } 437 438 static void ngbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake) 439 { 440 struct wx *wx = pci_get_drvdata(pdev); 441 struct net_device *netdev; 442 443 netdev = wx->netdev; 444 netif_device_detach(netdev); 445 446 rtnl_lock(); 447 if (netif_running(netdev)) 448 ngbe_down(wx); 449 rtnl_unlock(); 450 wx_control_hw(wx, false); 451 452 pci_disable_device(pdev); 453 } 454 455 static void ngbe_shutdown(struct pci_dev *pdev) 456 { 457 struct wx *wx = pci_get_drvdata(pdev); 458 bool wake; 459 460 wake = !!wx->wol; 461 462 ngbe_dev_shutdown(pdev, &wake); 463 464 if (system_state == SYSTEM_POWER_OFF) { 465 pci_wake_from_d3(pdev, wake); 466 pci_set_power_state(pdev, PCI_D3hot); 467 } 468 } 469 470 static const struct net_device_ops ngbe_netdev_ops = { 471 .ndo_open = ngbe_open, 472 .ndo_stop = ngbe_close, 473 .ndo_start_xmit = wx_xmit_frame, 474 .ndo_set_rx_mode = wx_set_rx_mode, 475 .ndo_validate_addr = eth_validate_addr, 476 .ndo_set_mac_address = wx_set_mac, 477 .ndo_get_stats64 = wx_get_stats64, 478 }; 479 480 /** 481 * ngbe_probe - Device Initialization Routine 482 * @pdev: PCI device information struct 483 * @ent: entry in ngbe_pci_tbl 484 * 485 * Returns 0 on success, negative on failure 486 * 487 * ngbe_probe initializes an wx identified by a pci_dev structure. 488 * The OS initialization, configuring of the wx private structure, 489 * and a hardware reset occur. 490 **/ 491 static int ngbe_probe(struct pci_dev *pdev, 492 const struct pci_device_id __always_unused *ent) 493 { 494 struct net_device *netdev; 495 u32 e2rom_cksum_cap = 0; 496 struct wx *wx = NULL; 497 static int func_nums; 498 u16 e2rom_ver = 0; 499 u32 etrack_id = 0; 500 u32 saved_ver = 0; 501 int err; 502 503 err = pci_enable_device_mem(pdev); 504 if (err) 505 return err; 506 507 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 508 if (err) { 509 dev_err(&pdev->dev, 510 "No usable DMA configuration, aborting\n"); 511 goto err_pci_disable_dev; 512 } 513 514 err = pci_request_selected_regions(pdev, 515 pci_select_bars(pdev, IORESOURCE_MEM), 516 ngbe_driver_name); 517 if (err) { 518 dev_err(&pdev->dev, 519 "pci_request_selected_regions failed %d\n", err); 520 goto err_pci_disable_dev; 521 } 522 523 pci_enable_pcie_error_reporting(pdev); 524 pci_set_master(pdev); 525 526 netdev = devm_alloc_etherdev_mqs(&pdev->dev, 527 sizeof(struct wx), 528 NGBE_MAX_TX_QUEUES, 529 NGBE_MAX_RX_QUEUES); 530 if (!netdev) { 531 err = -ENOMEM; 532 goto err_pci_release_regions; 533 } 534 535 SET_NETDEV_DEV(netdev, &pdev->dev); 536 537 wx = netdev_priv(netdev); 538 wx->netdev = netdev; 539 wx->pdev = pdev; 540 wx->msg_enable = BIT(3) - 1; 541 542 wx->hw_addr = devm_ioremap(&pdev->dev, 543 pci_resource_start(pdev, 0), 544 pci_resource_len(pdev, 0)); 545 if (!wx->hw_addr) { 546 err = -EIO; 547 goto err_pci_release_regions; 548 } 549 550 wx->driver_name = ngbe_driver_name; 551 ngbe_set_ethtool_ops(netdev); 552 netdev->netdev_ops = &ngbe_netdev_ops; 553 554 netdev->features |= NETIF_F_HIGHDMA; 555 netdev->features = NETIF_F_SG; 556 557 /* copy netdev features into list of user selectable features */ 558 netdev->hw_features |= netdev->features | 559 NETIF_F_RXALL; 560 561 netdev->priv_flags |= IFF_UNICAST_FLT; 562 netdev->priv_flags |= IFF_SUPP_NOFCS; 563 564 netdev->min_mtu = ETH_MIN_MTU; 565 netdev->max_mtu = NGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); 566 567 wx->bd_number = func_nums; 568 /* setup the private structure */ 569 err = ngbe_sw_init(wx); 570 if (err) 571 goto err_free_mac_table; 572 573 /* check if flash load is done after hw power up */ 574 err = wx_check_flash_load(wx, NGBE_SPI_ILDR_STATUS_PERST); 575 if (err) 576 goto err_free_mac_table; 577 err = wx_check_flash_load(wx, NGBE_SPI_ILDR_STATUS_PWRRST); 578 if (err) 579 goto err_free_mac_table; 580 581 err = wx_mng_present(wx); 582 if (err) { 583 dev_err(&pdev->dev, "Management capability is not present\n"); 584 goto err_free_mac_table; 585 } 586 587 err = ngbe_reset_hw(wx); 588 if (err) { 589 dev_err(&pdev->dev, "HW Init failed: %d\n", err); 590 goto err_free_mac_table; 591 } 592 593 if (wx->bus.func == 0) { 594 wr32(wx, NGBE_CALSUM_CAP_STATUS, 0x0); 595 wr32(wx, NGBE_EEPROM_VERSION_STORE_REG, 0x0); 596 } else { 597 e2rom_cksum_cap = rd32(wx, NGBE_CALSUM_CAP_STATUS); 598 saved_ver = rd32(wx, NGBE_EEPROM_VERSION_STORE_REG); 599 } 600 601 wx_init_eeprom_params(wx); 602 if (wx->bus.func == 0 || e2rom_cksum_cap == 0) { 603 /* make sure the EEPROM is ready */ 604 err = ngbe_eeprom_chksum_hostif(wx); 605 if (err) { 606 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); 607 err = -EIO; 608 goto err_free_mac_table; 609 } 610 } 611 612 wx->wol = 0; 613 if (wx->wol_enabled) 614 wx->wol = NGBE_PSR_WKUP_CTL_MAG; 615 616 wx->wol_enabled = !!(wx->wol); 617 wr32(wx, NGBE_PSR_WKUP_CTL, wx->wol); 618 619 device_set_wakeup_enable(&pdev->dev, wx->wol); 620 621 /* Save off EEPROM version number and Option Rom version which 622 * together make a unique identify for the eeprom 623 */ 624 if (saved_ver) { 625 etrack_id = saved_ver; 626 } else { 627 wx_read_ee_hostif(wx, 628 wx->eeprom.sw_region_offset + NGBE_EEPROM_VERSION_H, 629 &e2rom_ver); 630 etrack_id = e2rom_ver << 16; 631 wx_read_ee_hostif(wx, 632 wx->eeprom.sw_region_offset + NGBE_EEPROM_VERSION_L, 633 &e2rom_ver); 634 etrack_id |= e2rom_ver; 635 wr32(wx, NGBE_EEPROM_VERSION_STORE_REG, etrack_id); 636 } 637 snprintf(wx->eeprom_id, sizeof(wx->eeprom_id), 638 "0x%08x", etrack_id); 639 640 eth_hw_addr_set(netdev, wx->mac.perm_addr); 641 wx_mac_set_default_filter(wx, wx->mac.perm_addr); 642 643 err = wx_init_interrupt_scheme(wx); 644 if (err) 645 goto err_free_mac_table; 646 647 /* phy Interface Configuration */ 648 err = ngbe_mdio_init(wx); 649 if (err) 650 goto err_clear_interrupt_scheme; 651 652 err = register_netdev(netdev); 653 if (err) 654 goto err_register; 655 656 pci_set_drvdata(pdev, wx); 657 658 netif_info(wx, probe, netdev, 659 "PHY: %s, PBA No: Wang Xun GbE Family Controller\n", 660 wx->mac_type == em_mac_type_mdi ? "Internal" : "External"); 661 netif_info(wx, probe, netdev, "%pM\n", netdev->dev_addr); 662 663 return 0; 664 665 err_register: 666 wx_control_hw(wx, false); 667 err_clear_interrupt_scheme: 668 wx_clear_interrupt_scheme(wx); 669 err_free_mac_table: 670 kfree(wx->mac_table); 671 err_pci_release_regions: 672 pci_disable_pcie_error_reporting(pdev); 673 pci_release_selected_regions(pdev, 674 pci_select_bars(pdev, IORESOURCE_MEM)); 675 err_pci_disable_dev: 676 pci_disable_device(pdev); 677 return err; 678 } 679 680 /** 681 * ngbe_remove - Device Removal Routine 682 * @pdev: PCI device information struct 683 * 684 * ngbe_remove is called by the PCI subsystem to alert the driver 685 * that it should release a PCI device. The could be caused by a 686 * Hot-Plug event, or because the driver is going to be removed from 687 * memory. 688 **/ 689 static void ngbe_remove(struct pci_dev *pdev) 690 { 691 struct wx *wx = pci_get_drvdata(pdev); 692 struct net_device *netdev; 693 694 netdev = wx->netdev; 695 unregister_netdev(netdev); 696 pci_release_selected_regions(pdev, 697 pci_select_bars(pdev, IORESOURCE_MEM)); 698 699 kfree(wx->mac_table); 700 wx_clear_interrupt_scheme(wx); 701 pci_disable_pcie_error_reporting(pdev); 702 703 pci_disable_device(pdev); 704 } 705 706 static struct pci_driver ngbe_driver = { 707 .name = ngbe_driver_name, 708 .id_table = ngbe_pci_tbl, 709 .probe = ngbe_probe, 710 .remove = ngbe_remove, 711 .shutdown = ngbe_shutdown, 712 }; 713 714 module_pci_driver(ngbe_driver); 715 716 MODULE_DEVICE_TABLE(pci, ngbe_pci_tbl); 717 MODULE_AUTHOR("Beijing WangXun Technology Co., Ltd, <software@net-swift.com>"); 718 MODULE_DESCRIPTION("WangXun(R) Gigabit PCI Express Network Driver"); 719 MODULE_LICENSE("GPL"); 720