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