1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2015 - 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/etherdevice.h>
10 #include <linux/phylink.h>
11 #include <net/ip.h>
12 #include <linux/if_vlan.h>
13
14 #include "../libwx/wx_type.h"
15 #include "../libwx/wx_lib.h"
16 #include "../libwx/wx_hw.h"
17 #include "txgbe_type.h"
18 #include "txgbe_hw.h"
19 #include "txgbe_phy.h"
20 #include "txgbe_irq.h"
21 #include "txgbe_fdir.h"
22 #include "txgbe_ethtool.h"
23
24 char txgbe_driver_name[] = "txgbe";
25
26 /* txgbe_pci_tbl - PCI Device ID Table
27 *
28 * Wildcard entries (PCI_ANY_ID) should come last
29 * Last entry must be all 0s
30 *
31 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
32 * Class, Class Mask, private data (not used) }
33 */
34 static const struct pci_device_id txgbe_pci_tbl[] = {
35 { PCI_VDEVICE(WANGXUN, TXGBE_DEV_ID_SP1000), 0},
36 { PCI_VDEVICE(WANGXUN, TXGBE_DEV_ID_WX1820), 0},
37 /* required last entry */
38 { .device = 0 }
39 };
40
41 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
42
txgbe_check_minimum_link(struct wx * wx)43 static void txgbe_check_minimum_link(struct wx *wx)
44 {
45 struct pci_dev *pdev;
46
47 pdev = wx->pdev;
48 pcie_print_link_status(pdev);
49 }
50
51 /**
52 * txgbe_enumerate_functions - Get the number of ports this device has
53 * @wx: wx structure
54 *
55 * This function enumerates the phsyical functions co-located on a single slot,
56 * in order to determine how many ports a device has. This is most useful in
57 * determining the required GT/s of PCIe bandwidth necessary for optimal
58 * performance.
59 **/
txgbe_enumerate_functions(struct wx * wx)60 static int txgbe_enumerate_functions(struct wx *wx)
61 {
62 struct pci_dev *entry, *pdev = wx->pdev;
63 int physfns = 0;
64
65 list_for_each_entry(entry, &pdev->bus->devices, bus_list) {
66 /* When the devices on the bus don't all match our device ID,
67 * we can't reliably determine the correct number of
68 * functions. This can occur if a function has been direct
69 * attached to a virtual machine using VT-d.
70 */
71 if (entry->vendor != pdev->vendor ||
72 entry->device != pdev->device)
73 return -EINVAL;
74
75 physfns++;
76 }
77
78 return physfns;
79 }
80
txgbe_up_complete(struct wx * wx)81 static void txgbe_up_complete(struct wx *wx)
82 {
83 struct net_device *netdev = wx->netdev;
84
85 wx_control_hw(wx, true);
86 wx_configure_vectors(wx);
87
88 /* make sure to complete pre-operations */
89 smp_mb__before_atomic();
90 wx_napi_enable_all(wx);
91
92 phylink_start(wx->phylink);
93
94 /* clear any pending interrupts, may auto mask */
95 rd32(wx, WX_PX_IC(0));
96 rd32(wx, WX_PX_IC(1));
97 rd32(wx, WX_PX_MISC_IC);
98 txgbe_irq_enable(wx, true);
99
100 /* enable transmits */
101 netif_tx_start_all_queues(netdev);
102 }
103
txgbe_reset(struct wx * wx)104 static void txgbe_reset(struct wx *wx)
105 {
106 struct net_device *netdev = wx->netdev;
107 u8 old_addr[ETH_ALEN];
108 int err;
109
110 err = txgbe_reset_hw(wx);
111 if (err != 0)
112 wx_err(wx, "Hardware Error: %d\n", err);
113
114 wx_start_hw(wx);
115 /* do not flush user set addresses */
116 memcpy(old_addr, &wx->mac_table[0].addr, netdev->addr_len);
117 wx_flush_sw_mac_table(wx);
118 wx_mac_set_default_filter(wx, old_addr);
119 }
120
txgbe_disable_device(struct wx * wx)121 static void txgbe_disable_device(struct wx *wx)
122 {
123 struct net_device *netdev = wx->netdev;
124 u32 i;
125
126 wx_disable_pcie_master(wx);
127 /* disable receives */
128 wx_disable_rx(wx);
129
130 /* disable all enabled rx queues */
131 for (i = 0; i < wx->num_rx_queues; i++)
132 /* this call also flushes the previous write */
133 wx_disable_rx_queue(wx, wx->rx_ring[i]);
134
135 netif_tx_stop_all_queues(netdev);
136 netif_tx_disable(netdev);
137
138 wx_irq_disable(wx);
139 wx_napi_disable_all(wx);
140
141 if (wx->bus.func < 2)
142 wr32m(wx, TXGBE_MIS_PRB_CTL, TXGBE_MIS_PRB_CTL_LAN_UP(wx->bus.func), 0);
143 else
144 wx_err(wx, "%s: invalid bus lan id %d\n",
145 __func__, wx->bus.func);
146
147 if (!(((wx->subsystem_device_id & WX_NCSI_MASK) == WX_NCSI_SUP) ||
148 ((wx->subsystem_device_id & WX_WOL_MASK) == WX_WOL_SUP))) {
149 /* disable mac transmiter */
150 wr32m(wx, WX_MAC_TX_CFG, WX_MAC_TX_CFG_TE, 0);
151 }
152
153 /* disable transmits in the hardware now that interrupts are off */
154 for (i = 0; i < wx->num_tx_queues; i++) {
155 u8 reg_idx = wx->tx_ring[i]->reg_idx;
156
157 wr32(wx, WX_PX_TR_CFG(reg_idx), WX_PX_TR_CFG_SWFLSH);
158 }
159
160 /* Disable the Tx DMA engine */
161 wr32m(wx, WX_TDM_CTL, WX_TDM_CTL_TE, 0);
162
163 wx_update_stats(wx);
164 }
165
txgbe_down(struct wx * wx)166 void txgbe_down(struct wx *wx)
167 {
168 txgbe_disable_device(wx);
169 txgbe_reset(wx);
170 phylink_stop(wx->phylink);
171
172 wx_clean_all_tx_rings(wx);
173 wx_clean_all_rx_rings(wx);
174 }
175
txgbe_up(struct wx * wx)176 void txgbe_up(struct wx *wx)
177 {
178 wx_configure(wx);
179 txgbe_up_complete(wx);
180 }
181
182 /**
183 * txgbe_init_type_code - Initialize the shared code
184 * @wx: pointer to hardware structure
185 **/
txgbe_init_type_code(struct wx * wx)186 static void txgbe_init_type_code(struct wx *wx)
187 {
188 u8 device_type = wx->subsystem_device_id & 0xF0;
189
190 switch (wx->device_id) {
191 case TXGBE_DEV_ID_SP1000:
192 case TXGBE_DEV_ID_WX1820:
193 wx->mac.type = wx_mac_sp;
194 break;
195 default:
196 wx->mac.type = wx_mac_unknown;
197 break;
198 }
199
200 switch (device_type) {
201 case TXGBE_ID_SFP:
202 wx->media_type = sp_media_fiber;
203 break;
204 case TXGBE_ID_XAUI:
205 case TXGBE_ID_SGMII:
206 wx->media_type = sp_media_copper;
207 break;
208 case TXGBE_ID_KR_KX_KX4:
209 case TXGBE_ID_MAC_XAUI:
210 case TXGBE_ID_MAC_SGMII:
211 wx->media_type = sp_media_backplane;
212 break;
213 case TXGBE_ID_SFI_XAUI:
214 if (wx->bus.func == 0)
215 wx->media_type = sp_media_fiber;
216 else
217 wx->media_type = sp_media_copper;
218 break;
219 default:
220 wx->media_type = sp_media_unknown;
221 break;
222 }
223 }
224
225 /**
226 * txgbe_sw_init - Initialize general software structures (struct wx)
227 * @wx: board private structure to initialize
228 **/
txgbe_sw_init(struct wx * wx)229 static int txgbe_sw_init(struct wx *wx)
230 {
231 u16 msix_count = 0;
232 int err;
233
234 wx->mac.num_rar_entries = TXGBE_SP_RAR_ENTRIES;
235 wx->mac.max_tx_queues = TXGBE_SP_MAX_TX_QUEUES;
236 wx->mac.max_rx_queues = TXGBE_SP_MAX_RX_QUEUES;
237 wx->mac.mcft_size = TXGBE_SP_MC_TBL_SIZE;
238 wx->mac.vft_size = TXGBE_SP_VFT_TBL_SIZE;
239 wx->mac.rx_pb_size = TXGBE_SP_RX_PB_SIZE;
240 wx->mac.tx_pb_size = TXGBE_SP_TDB_PB_SZ;
241
242 /* PCI config space info */
243 err = wx_sw_init(wx);
244 if (err < 0)
245 return err;
246
247 txgbe_init_type_code(wx);
248
249 /* Set common capability flags and settings */
250 wx->max_q_vectors = TXGBE_MAX_MSIX_VECTORS;
251 err = wx_get_pcie_msix_counts(wx, &msix_count, TXGBE_MAX_MSIX_VECTORS);
252 if (err)
253 wx_err(wx, "Do not support MSI-X\n");
254 wx->mac.max_msix_vectors = msix_count;
255
256 wx->ring_feature[RING_F_RSS].limit = min_t(int, TXGBE_MAX_RSS_INDICES,
257 num_online_cpus());
258 wx->rss_enabled = true;
259
260 wx->ring_feature[RING_F_FDIR].limit = min_t(int, TXGBE_MAX_FDIR_INDICES,
261 num_online_cpus());
262 set_bit(WX_FLAG_FDIR_CAPABLE, wx->flags);
263 set_bit(WX_FLAG_FDIR_HASH, wx->flags);
264 wx->atr_sample_rate = TXGBE_DEFAULT_ATR_SAMPLE_RATE;
265 wx->atr = txgbe_atr;
266 wx->configure_fdir = txgbe_configure_fdir;
267
268 /* enable itr by default in dynamic mode */
269 wx->rx_itr_setting = 1;
270 wx->tx_itr_setting = 1;
271
272 /* set default ring sizes */
273 wx->tx_ring_count = TXGBE_DEFAULT_TXD;
274 wx->rx_ring_count = TXGBE_DEFAULT_RXD;
275
276 /* set default work limits */
277 wx->tx_work_limit = TXGBE_DEFAULT_TX_WORK;
278 wx->rx_work_limit = TXGBE_DEFAULT_RX_WORK;
279
280 wx->do_reset = txgbe_do_reset;
281
282 return 0;
283 }
284
txgbe_init_fdir(struct txgbe * txgbe)285 static void txgbe_init_fdir(struct txgbe *txgbe)
286 {
287 txgbe->fdir_filter_count = 0;
288 spin_lock_init(&txgbe->fdir_perfect_lock);
289 }
290
291 /**
292 * txgbe_open - Called when a network interface is made active
293 * @netdev: network interface device structure
294 *
295 * Returns 0 on success, negative value on failure
296 *
297 * The open entry point is called when a network interface is made
298 * active by the system (IFF_UP).
299 **/
txgbe_open(struct net_device * netdev)300 static int txgbe_open(struct net_device *netdev)
301 {
302 struct wx *wx = netdev_priv(netdev);
303 int err;
304
305 err = wx_setup_resources(wx);
306 if (err)
307 goto err_reset;
308
309 wx_configure(wx);
310
311 err = txgbe_request_queue_irqs(wx);
312 if (err)
313 goto err_free_resources;
314
315 /* Notify the stack of the actual queue counts. */
316 err = netif_set_real_num_tx_queues(netdev, wx->num_tx_queues);
317 if (err)
318 goto err_free_irq;
319
320 err = netif_set_real_num_rx_queues(netdev, wx->num_rx_queues);
321 if (err)
322 goto err_free_irq;
323
324 txgbe_up_complete(wx);
325
326 return 0;
327
328 err_free_irq:
329 wx_free_irq(wx);
330 err_free_resources:
331 wx_free_resources(wx);
332 err_reset:
333 txgbe_reset(wx);
334
335 return err;
336 }
337
338 /**
339 * txgbe_close_suspend - actions necessary to both suspend and close flows
340 * @wx: the private wx struct
341 *
342 * This function should contain the necessary work common to both suspending
343 * and closing of the device.
344 */
txgbe_close_suspend(struct wx * wx)345 static void txgbe_close_suspend(struct wx *wx)
346 {
347 txgbe_disable_device(wx);
348 wx_free_resources(wx);
349 }
350
351 /**
352 * txgbe_close - Disables a network interface
353 * @netdev: network interface device structure
354 *
355 * Returns 0, this is not allowed to fail
356 *
357 * The close entry point is called when an interface is de-activated
358 * by the OS. The hardware is still under the drivers control, but
359 * needs to be disabled. A global MAC reset is issued to stop the
360 * hardware, and all transmit and receive resources are freed.
361 **/
txgbe_close(struct net_device * netdev)362 static int txgbe_close(struct net_device *netdev)
363 {
364 struct wx *wx = netdev_priv(netdev);
365
366 txgbe_down(wx);
367 wx_free_irq(wx);
368 wx_free_resources(wx);
369 txgbe_fdir_filter_exit(wx);
370 wx_control_hw(wx, false);
371
372 return 0;
373 }
374
txgbe_dev_shutdown(struct pci_dev * pdev)375 static void txgbe_dev_shutdown(struct pci_dev *pdev)
376 {
377 struct wx *wx = pci_get_drvdata(pdev);
378 struct net_device *netdev;
379
380 netdev = wx->netdev;
381 netif_device_detach(netdev);
382
383 rtnl_lock();
384 if (netif_running(netdev))
385 txgbe_close_suspend(wx);
386 rtnl_unlock();
387
388 wx_control_hw(wx, false);
389
390 pci_disable_device(pdev);
391 }
392
txgbe_shutdown(struct pci_dev * pdev)393 static void txgbe_shutdown(struct pci_dev *pdev)
394 {
395 txgbe_dev_shutdown(pdev);
396
397 if (system_state == SYSTEM_POWER_OFF) {
398 pci_wake_from_d3(pdev, false);
399 pci_set_power_state(pdev, PCI_D3hot);
400 }
401 }
402
403 /**
404 * txgbe_setup_tc - routine to configure net_device for multiple traffic
405 * classes.
406 *
407 * @dev: net device to configure
408 * @tc: number of traffic classes to enable
409 */
txgbe_setup_tc(struct net_device * dev,u8 tc)410 int txgbe_setup_tc(struct net_device *dev, u8 tc)
411 {
412 struct wx *wx = netdev_priv(dev);
413 struct txgbe *txgbe = wx->priv;
414
415 /* Hardware has to reinitialize queues and interrupts to
416 * match packet buffer alignment. Unfortunately, the
417 * hardware is not flexible enough to do this dynamically.
418 */
419 if (netif_running(dev))
420 txgbe_close(dev);
421 else
422 txgbe_reset(wx);
423
424 txgbe_free_misc_irq(txgbe);
425 wx_clear_interrupt_scheme(wx);
426
427 if (tc)
428 netdev_set_num_tc(dev, tc);
429 else
430 netdev_reset_tc(dev);
431
432 wx_init_interrupt_scheme(wx);
433 txgbe_setup_misc_irq(txgbe);
434
435 if (netif_running(dev))
436 txgbe_open(dev);
437
438 return 0;
439 }
440
txgbe_reinit_locked(struct wx * wx)441 static void txgbe_reinit_locked(struct wx *wx)
442 {
443 int err = 0;
444
445 netif_trans_update(wx->netdev);
446
447 err = wx_set_state_reset(wx);
448 if (err) {
449 wx_err(wx, "wait device reset timeout\n");
450 return;
451 }
452
453 txgbe_down(wx);
454 txgbe_up(wx);
455
456 clear_bit(WX_STATE_RESETTING, wx->state);
457 }
458
txgbe_do_reset(struct net_device * netdev)459 void txgbe_do_reset(struct net_device *netdev)
460 {
461 struct wx *wx = netdev_priv(netdev);
462
463 if (netif_running(netdev))
464 txgbe_reinit_locked(wx);
465 else
466 txgbe_reset(wx);
467 }
468
469 static const struct net_device_ops txgbe_netdev_ops = {
470 .ndo_open = txgbe_open,
471 .ndo_stop = txgbe_close,
472 .ndo_change_mtu = wx_change_mtu,
473 .ndo_start_xmit = wx_xmit_frame,
474 .ndo_set_rx_mode = wx_set_rx_mode,
475 .ndo_set_features = wx_set_features,
476 .ndo_fix_features = wx_fix_features,
477 .ndo_validate_addr = eth_validate_addr,
478 .ndo_set_mac_address = wx_set_mac,
479 .ndo_get_stats64 = wx_get_stats64,
480 .ndo_vlan_rx_add_vid = wx_vlan_rx_add_vid,
481 .ndo_vlan_rx_kill_vid = wx_vlan_rx_kill_vid,
482 };
483
484 /**
485 * txgbe_probe - Device Initialization Routine
486 * @pdev: PCI device information struct
487 * @ent: entry in txgbe_pci_tbl
488 *
489 * Returns 0 on success, negative on failure
490 *
491 * txgbe_probe initializes an adapter identified by a pci_dev structure.
492 * The OS initialization, configuring of the wx private structure,
493 * and a hardware reset occur.
494 **/
txgbe_probe(struct pci_dev * pdev,const struct pci_device_id __always_unused * ent)495 static int txgbe_probe(struct pci_dev *pdev,
496 const struct pci_device_id __always_unused *ent)
497 {
498 struct net_device *netdev;
499 int err, expected_gts;
500 struct wx *wx = NULL;
501 struct txgbe *txgbe;
502
503 u16 eeprom_verh = 0, eeprom_verl = 0, offset = 0;
504 u16 eeprom_cfg_blkh = 0, eeprom_cfg_blkl = 0;
505 u16 build = 0, major = 0, patch = 0;
506 u32 etrack_id = 0;
507
508 err = pci_enable_device_mem(pdev);
509 if (err)
510 return err;
511
512 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
513 if (err) {
514 dev_err(&pdev->dev,
515 "No usable DMA configuration, aborting\n");
516 goto err_pci_disable_dev;
517 }
518
519 err = pci_request_selected_regions(pdev,
520 pci_select_bars(pdev, IORESOURCE_MEM),
521 txgbe_driver_name);
522 if (err) {
523 dev_err(&pdev->dev,
524 "pci_request_selected_regions failed 0x%x\n", err);
525 goto err_pci_disable_dev;
526 }
527
528 pci_set_master(pdev);
529
530 netdev = devm_alloc_etherdev_mqs(&pdev->dev,
531 sizeof(struct wx),
532 TXGBE_MAX_TX_QUEUES,
533 TXGBE_MAX_RX_QUEUES);
534 if (!netdev) {
535 err = -ENOMEM;
536 goto err_pci_release_regions;
537 }
538
539 SET_NETDEV_DEV(netdev, &pdev->dev);
540
541 wx = netdev_priv(netdev);
542 wx->netdev = netdev;
543 wx->pdev = pdev;
544
545 wx->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
546
547 wx->hw_addr = devm_ioremap(&pdev->dev,
548 pci_resource_start(pdev, 0),
549 pci_resource_len(pdev, 0));
550 if (!wx->hw_addr) {
551 err = -EIO;
552 goto err_pci_release_regions;
553 }
554
555 wx->driver_name = txgbe_driver_name;
556 txgbe_set_ethtool_ops(netdev);
557 netdev->netdev_ops = &txgbe_netdev_ops;
558
559 /* setup the private structure */
560 err = txgbe_sw_init(wx);
561 if (err)
562 goto err_pci_release_regions;
563
564 /* check if flash load is done after hw power up */
565 err = wx_check_flash_load(wx, TXGBE_SPI_ILDR_STATUS_PERST);
566 if (err)
567 goto err_free_mac_table;
568 err = wx_check_flash_load(wx, TXGBE_SPI_ILDR_STATUS_PWRRST);
569 if (err)
570 goto err_free_mac_table;
571
572 err = wx_mng_present(wx);
573 if (err) {
574 dev_err(&pdev->dev, "Management capability is not present\n");
575 goto err_free_mac_table;
576 }
577
578 err = txgbe_reset_hw(wx);
579 if (err) {
580 dev_err(&pdev->dev, "HW Init failed: %d\n", err);
581 goto err_free_mac_table;
582 }
583
584 netdev->features = NETIF_F_SG |
585 NETIF_F_TSO |
586 NETIF_F_TSO6 |
587 NETIF_F_RXHASH |
588 NETIF_F_RXCSUM |
589 NETIF_F_HW_CSUM;
590
591 netdev->gso_partial_features = NETIF_F_GSO_ENCAP_ALL;
592 netdev->features |= netdev->gso_partial_features;
593 netdev->features |= NETIF_F_SCTP_CRC;
594 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
595 netdev->hw_enc_features |= netdev->vlan_features;
596 netdev->features |= NETIF_F_VLAN_FEATURES;
597 /* copy netdev features into list of user selectable features */
598 netdev->hw_features |= netdev->features | NETIF_F_RXALL;
599 netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
600 netdev->features |= NETIF_F_HIGHDMA;
601 netdev->hw_features |= NETIF_F_GRO;
602 netdev->features |= NETIF_F_GRO;
603
604 netdev->priv_flags |= IFF_UNICAST_FLT;
605 netdev->priv_flags |= IFF_SUPP_NOFCS;
606 netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
607
608 netdev->min_mtu = ETH_MIN_MTU;
609 netdev->max_mtu = WX_MAX_JUMBO_FRAME_SIZE -
610 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
611
612 /* make sure the EEPROM is good */
613 err = txgbe_validate_eeprom_checksum(wx, NULL);
614 if (err != 0) {
615 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
616 wr32(wx, WX_MIS_RST, WX_MIS_RST_SW_RST);
617 err = -EIO;
618 goto err_free_mac_table;
619 }
620
621 eth_hw_addr_set(netdev, wx->mac.perm_addr);
622 wx_mac_set_default_filter(wx, wx->mac.perm_addr);
623
624 err = wx_init_interrupt_scheme(wx);
625 if (err)
626 goto err_free_mac_table;
627
628 /* Save off EEPROM version number and Option Rom version which
629 * together make a unique identify for the eeprom
630 */
631 wx_read_ee_hostif(wx,
632 wx->eeprom.sw_region_offset + TXGBE_EEPROM_VERSION_H,
633 &eeprom_verh);
634 wx_read_ee_hostif(wx,
635 wx->eeprom.sw_region_offset + TXGBE_EEPROM_VERSION_L,
636 &eeprom_verl);
637 etrack_id = (eeprom_verh << 16) | eeprom_verl;
638
639 wx_read_ee_hostif(wx,
640 wx->eeprom.sw_region_offset + TXGBE_ISCSI_BOOT_CONFIG,
641 &offset);
642
643 /* Make sure offset to SCSI block is valid */
644 if (!(offset == 0x0) && !(offset == 0xffff)) {
645 wx_read_ee_hostif(wx, offset + 0x84, &eeprom_cfg_blkh);
646 wx_read_ee_hostif(wx, offset + 0x83, &eeprom_cfg_blkl);
647
648 /* Only display Option Rom if exist */
649 if (eeprom_cfg_blkl && eeprom_cfg_blkh) {
650 major = eeprom_cfg_blkl >> 8;
651 build = (eeprom_cfg_blkl << 8) | (eeprom_cfg_blkh >> 8);
652 patch = eeprom_cfg_blkh & 0x00ff;
653
654 snprintf(wx->eeprom_id, sizeof(wx->eeprom_id),
655 "0x%08x, %d.%d.%d", etrack_id, major, build,
656 patch);
657 } else {
658 snprintf(wx->eeprom_id, sizeof(wx->eeprom_id),
659 "0x%08x", etrack_id);
660 }
661 } else {
662 snprintf(wx->eeprom_id, sizeof(wx->eeprom_id),
663 "0x%08x", etrack_id);
664 }
665
666 if (etrack_id < 0x20010)
667 dev_warn(&pdev->dev, "Please upgrade the firmware to 0x20010 or above.\n");
668
669 txgbe = devm_kzalloc(&pdev->dev, sizeof(*txgbe), GFP_KERNEL);
670 if (!txgbe) {
671 err = -ENOMEM;
672 goto err_release_hw;
673 }
674
675 txgbe->wx = wx;
676 wx->priv = txgbe;
677
678 txgbe_init_fdir(txgbe);
679
680 err = txgbe_setup_misc_irq(txgbe);
681 if (err)
682 goto err_release_hw;
683
684 err = txgbe_init_phy(txgbe);
685 if (err)
686 goto err_free_misc_irq;
687
688 err = register_netdev(netdev);
689 if (err)
690 goto err_remove_phy;
691
692 pci_set_drvdata(pdev, wx);
693
694 netif_tx_stop_all_queues(netdev);
695
696 /* calculate the expected PCIe bandwidth required for optimal
697 * performance. Note that some older parts will never have enough
698 * bandwidth due to being older generation PCIe parts. We clamp these
699 * parts to ensure that no warning is displayed, as this could confuse
700 * users otherwise.
701 */
702 expected_gts = txgbe_enumerate_functions(wx) * 10;
703
704 /* don't check link if we failed to enumerate functions */
705 if (expected_gts > 0)
706 txgbe_check_minimum_link(wx);
707 else
708 dev_warn(&pdev->dev, "Failed to enumerate PF devices.\n");
709
710 return 0;
711
712 err_remove_phy:
713 txgbe_remove_phy(txgbe);
714 err_free_misc_irq:
715 txgbe_free_misc_irq(txgbe);
716 err_release_hw:
717 wx_clear_interrupt_scheme(wx);
718 wx_control_hw(wx, false);
719 err_free_mac_table:
720 kfree(wx->rss_key);
721 kfree(wx->mac_table);
722 err_pci_release_regions:
723 pci_release_selected_regions(pdev,
724 pci_select_bars(pdev, IORESOURCE_MEM));
725 err_pci_disable_dev:
726 pci_disable_device(pdev);
727 return err;
728 }
729
730 /**
731 * txgbe_remove - Device Removal Routine
732 * @pdev: PCI device information struct
733 *
734 * txgbe_remove is called by the PCI subsystem to alert the driver
735 * that it should release a PCI device. The could be caused by a
736 * Hot-Plug event, or because the driver is going to be removed from
737 * memory.
738 **/
txgbe_remove(struct pci_dev * pdev)739 static void txgbe_remove(struct pci_dev *pdev)
740 {
741 struct wx *wx = pci_get_drvdata(pdev);
742 struct txgbe *txgbe = wx->priv;
743 struct net_device *netdev;
744
745 netdev = wx->netdev;
746 unregister_netdev(netdev);
747
748 txgbe_remove_phy(txgbe);
749 txgbe_free_misc_irq(txgbe);
750 wx_free_isb_resources(wx);
751
752 pci_release_selected_regions(pdev,
753 pci_select_bars(pdev, IORESOURCE_MEM));
754
755 kfree(wx->rss_key);
756 kfree(wx->mac_table);
757 wx_clear_interrupt_scheme(wx);
758
759 pci_disable_device(pdev);
760 }
761
762 static struct pci_driver txgbe_driver = {
763 .name = txgbe_driver_name,
764 .id_table = txgbe_pci_tbl,
765 .probe = txgbe_probe,
766 .remove = txgbe_remove,
767 .shutdown = txgbe_shutdown,
768 };
769
770 module_pci_driver(txgbe_driver);
771
772 MODULE_DEVICE_TABLE(pci, txgbe_pci_tbl);
773 MODULE_AUTHOR("Beijing WangXun Technology Co., Ltd, <[email protected]>");
774 MODULE_DESCRIPTION("WangXun(R) 10 Gigabit PCI Express Network Driver");
775 MODULE_LICENSE("GPL");
776