1e79e40c8SMengyuan Lou // SPDX-License-Identifier: GPL-2.0
2e79e40c8SMengyuan Lou /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */
3e79e40c8SMengyuan Lou
4e79e40c8SMengyuan Lou #include <linux/types.h>
5e79e40c8SMengyuan Lou #include <linux/module.h>
6e79e40c8SMengyuan Lou #include <linux/pci.h>
7e79e40c8SMengyuan Lou #include <linux/netdevice.h>
8e79e40c8SMengyuan Lou #include <linux/string.h>
9e79e40c8SMengyuan Lou #include <linux/etherdevice.h>
1002338c48SMengyuan Lou #include <net/ip.h>
11a1cf597bSMengyuan Lou #include <linux/phy.h>
1281dc0741SMengyuan Lou #include <linux/if_vlan.h>
13e79e40c8SMengyuan Lou
1402338c48SMengyuan Lou #include "../libwx/wx_type.h"
1502338c48SMengyuan Lou #include "../libwx/wx_hw.h"
16e7956139SMengyuan Lou #include "../libwx/wx_lib.h"
1702338c48SMengyuan Lou #include "ngbe_type.h"
18a1cf597bSMengyuan Lou #include "ngbe_mdio.h"
1902338c48SMengyuan Lou #include "ngbe_hw.h"
201b8d1c50SMengyuan Lou #include "ngbe_ethtool.h"
2192710fe6SJiawen Wu
22e79e40c8SMengyuan Lou char ngbe_driver_name[] = "ngbe";
23e79e40c8SMengyuan Lou
24e79e40c8SMengyuan Lou /* ngbe_pci_tbl - PCI Device ID Table
25e79e40c8SMengyuan Lou *
26e79e40c8SMengyuan Lou * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
27e79e40c8SMengyuan Lou * Class, Class Mask, private data (not used) }
28e79e40c8SMengyuan Lou */
29e79e40c8SMengyuan Lou static const struct pci_device_id ngbe_pci_tbl[] = {
30e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W), 0},
31e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A2), 0},
32e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A2S), 0},
33e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A4), 0},
34e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A4S), 0},
35e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL2), 0},
36e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S), 0},
37e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL4), 0},
38e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S), 0},
39e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860LC), 0},
40e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A1), 0},
41e79e40c8SMengyuan Lou { PCI_VDEVICE(WANGXUN, NGBE_DEV_ID_EM_WX1860A1L), 0},
42e79e40c8SMengyuan Lou /* required last entry */
43e79e40c8SMengyuan Lou { .device = 0 }
44e79e40c8SMengyuan Lou };
45e79e40c8SMengyuan Lou
4602338c48SMengyuan Lou /**
4702338c48SMengyuan Lou * ngbe_init_type_code - Initialize the shared code
48803df55dSMengyuan Lou * @wx: pointer to hardware structure
4902338c48SMengyuan Lou **/
ngbe_init_type_code(struct wx * wx)50803df55dSMengyuan Lou static void ngbe_init_type_code(struct wx *wx)
5102338c48SMengyuan Lou {
5202338c48SMengyuan Lou int wol_mask = 0, ncsi_mask = 0;
53803df55dSMengyuan Lou u16 type_mask = 0, val;
5402338c48SMengyuan Lou
559607a3e6SJiawen Wu wx->mac.type = wx_mac_em;
569607a3e6SJiawen Wu type_mask = (u16)(wx->subsystem_device_id & NGBE_OEM_MASK);
579607a3e6SJiawen Wu ncsi_mask = wx->subsystem_device_id & NGBE_NCSI_MASK;
589607a3e6SJiawen Wu wol_mask = wx->subsystem_device_id & NGBE_WOL_MASK;
5902338c48SMengyuan Lou
60803df55dSMengyuan Lou val = rd32(wx, WX_CFG_PORT_ST);
61803df55dSMengyuan Lou wx->mac_type = (val & BIT(7)) >> 7 ?
62803df55dSMengyuan Lou em_mac_type_rgmii :
63803df55dSMengyuan Lou em_mac_type_mdi;
6402338c48SMengyuan Lou
656963e463SMengyuan Lou wx->wol_hw_supported = (wol_mask == NGBE_WOL_SUP) ? 1 : 0;
66803df55dSMengyuan Lou wx->ncsi_enabled = (ncsi_mask == NGBE_NCSI_MASK ||
6702338c48SMengyuan Lou type_mask == NGBE_SUBID_OCP_CARD) ? 1 : 0;
6802338c48SMengyuan Lou
6902338c48SMengyuan Lou switch (type_mask) {
7002338c48SMengyuan Lou case NGBE_SUBID_LY_YT8521S_SFP:
7102338c48SMengyuan Lou case NGBE_SUBID_LY_M88E1512_SFP:
7202338c48SMengyuan Lou case NGBE_SUBID_YT8521S_SFP_GPIO:
7302338c48SMengyuan Lou case NGBE_SUBID_INTERNAL_YT8521S_SFP_GPIO:
74803df55dSMengyuan Lou wx->gpio_ctrl = 1;
7502338c48SMengyuan Lou break;
7602338c48SMengyuan Lou default:
77803df55dSMengyuan Lou wx->gpio_ctrl = 0;
7802338c48SMengyuan Lou break;
7902338c48SMengyuan Lou }
8002338c48SMengyuan Lou }
8102338c48SMengyuan Lou
8202338c48SMengyuan Lou /**
83803df55dSMengyuan Lou * ngbe_init_rss_key - Initialize wx RSS key
84803df55dSMengyuan Lou * @wx: device handle
8502338c48SMengyuan Lou *
8602338c48SMengyuan Lou * Allocates and initializes the RSS key if it is not allocated.
8702338c48SMengyuan Lou **/
ngbe_init_rss_key(struct wx * wx)88803df55dSMengyuan Lou static inline int ngbe_init_rss_key(struct wx *wx)
8902338c48SMengyuan Lou {
9002338c48SMengyuan Lou u32 *rss_key;
9102338c48SMengyuan Lou
92803df55dSMengyuan Lou if (!wx->rss_key) {
93803df55dSMengyuan Lou rss_key = kzalloc(WX_RSS_KEY_SIZE, GFP_KERNEL);
9402338c48SMengyuan Lou if (unlikely(!rss_key))
9502338c48SMengyuan Lou return -ENOMEM;
9602338c48SMengyuan Lou
97803df55dSMengyuan Lou netdev_rss_key_fill(rss_key, WX_RSS_KEY_SIZE);
98803df55dSMengyuan Lou wx->rss_key = rss_key;
9902338c48SMengyuan Lou }
10002338c48SMengyuan Lou
10102338c48SMengyuan Lou return 0;
10202338c48SMengyuan Lou }
10302338c48SMengyuan Lou
10402338c48SMengyuan Lou /**
10502338c48SMengyuan Lou * ngbe_sw_init - Initialize general software structures
106803df55dSMengyuan Lou * @wx: board private structure to initialize
10702338c48SMengyuan Lou **/
ngbe_sw_init(struct wx * wx)108803df55dSMengyuan Lou static int ngbe_sw_init(struct wx *wx)
10902338c48SMengyuan Lou {
110803df55dSMengyuan Lou struct pci_dev *pdev = wx->pdev;
11102338c48SMengyuan Lou u16 msix_count = 0;
11202338c48SMengyuan Lou int err = 0;
11302338c48SMengyuan Lou
1149607a3e6SJiawen Wu wx->mac.num_rar_entries = NGBE_RAR_ENTRIES;
1159607a3e6SJiawen Wu wx->mac.max_rx_queues = NGBE_MAX_RX_QUEUES;
1169607a3e6SJiawen Wu wx->mac.max_tx_queues = NGBE_MAX_TX_QUEUES;
117b97f955eSMengyuan Lou wx->mac.mcft_size = NGBE_MC_TBL_SIZE;
118361bf4f4SMengyuan Lou wx->mac.vft_size = NGBE_SP_VFT_TBL_SIZE;
119b97f955eSMengyuan Lou wx->mac.rx_pb_size = NGBE_RX_PB_SIZE;
120b97f955eSMengyuan Lou wx->mac.tx_pb_size = NGBE_TDB_PB_SZ;
12179625f45SJiawen Wu
12202338c48SMengyuan Lou /* PCI config space info */
1239607a3e6SJiawen Wu err = wx_sw_init(wx);
124*61a55071SJiawen Wu if (err < 0)
12502338c48SMengyuan Lou return err;
12602338c48SMengyuan Lou
12702338c48SMengyuan Lou /* mac type, phy type , oem type */
128803df55dSMengyuan Lou ngbe_init_type_code(wx);
12902338c48SMengyuan Lou
13002338c48SMengyuan Lou /* Set common capability flags and settings */
131803df55dSMengyuan Lou wx->max_q_vectors = NGBE_MAX_MSIX_VECTORS;
1329607a3e6SJiawen Wu err = wx_get_pcie_msix_counts(wx, &msix_count, NGBE_MAX_MSIX_VECTORS);
13302338c48SMengyuan Lou if (err)
13402338c48SMengyuan Lou dev_err(&pdev->dev, "Do not support MSI-X\n");
1359607a3e6SJiawen Wu wx->mac.max_msix_vectors = msix_count;
13602338c48SMengyuan Lou
137803df55dSMengyuan Lou if (ngbe_init_rss_key(wx))
13802338c48SMengyuan Lou return -ENOMEM;
13902338c48SMengyuan Lou
14002338c48SMengyuan Lou /* enable itr by default in dynamic mode */
141803df55dSMengyuan Lou wx->rx_itr_setting = 1;
142803df55dSMengyuan Lou wx->tx_itr_setting = 1;
14302338c48SMengyuan Lou
14402338c48SMengyuan Lou /* set default ring sizes */
145803df55dSMengyuan Lou wx->tx_ring_count = NGBE_DEFAULT_TXD;
146803df55dSMengyuan Lou wx->rx_ring_count = NGBE_DEFAULT_RXD;
14702338c48SMengyuan Lou
14802338c48SMengyuan Lou /* set default work limits */
149803df55dSMengyuan Lou wx->tx_work_limit = NGBE_DEFAULT_TX_WORK;
150803df55dSMengyuan Lou wx->rx_work_limit = NGBE_DEFAULT_RX_WORK;
15102338c48SMengyuan Lou
15202338c48SMengyuan Lou return 0;
15302338c48SMengyuan Lou }
15402338c48SMengyuan Lou
155e7956139SMengyuan Lou /**
156e7956139SMengyuan Lou * ngbe_irq_enable - Enable default interrupt generation settings
157e7956139SMengyuan Lou * @wx: board private structure
158e7956139SMengyuan Lou * @queues: enable all queues interrupts
159e7956139SMengyuan Lou **/
ngbe_irq_enable(struct wx * wx,bool queues)160e7956139SMengyuan Lou static void ngbe_irq_enable(struct wx *wx, bool queues)
161e7956139SMengyuan Lou {
162e7956139SMengyuan Lou u32 mask;
163e7956139SMengyuan Lou
164e7956139SMengyuan Lou /* enable misc interrupt */
165e7956139SMengyuan Lou mask = NGBE_PX_MISC_IEN_MASK;
166e7956139SMengyuan Lou
167e7956139SMengyuan Lou wr32(wx, WX_GPIO_DDR, WX_GPIO_DDR_0);
168e7956139SMengyuan Lou wr32(wx, WX_GPIO_INTEN, WX_GPIO_INTEN_0 | WX_GPIO_INTEN_1);
169e7956139SMengyuan Lou wr32(wx, WX_GPIO_INTTYPE_LEVEL, 0x0);
170e7956139SMengyuan Lou wr32(wx, WX_GPIO_POLARITY, wx->gpio_ctrl ? 0 : 0x3);
171e7956139SMengyuan Lou
172e7956139SMengyuan Lou wr32(wx, WX_PX_MISC_IEN, mask);
173e7956139SMengyuan Lou
174e7956139SMengyuan Lou /* mask interrupt */
175e7956139SMengyuan Lou if (queues)
176e7956139SMengyuan Lou wx_intr_enable(wx, NGBE_INTR_ALL);
177e7956139SMengyuan Lou else
178e7956139SMengyuan Lou wx_intr_enable(wx, NGBE_INTR_MISC(wx));
179e7956139SMengyuan Lou }
180e7956139SMengyuan Lou
181e7956139SMengyuan Lou /**
182e7956139SMengyuan Lou * ngbe_intr - msi/legacy mode Interrupt Handler
183e7956139SMengyuan Lou * @irq: interrupt number
184e7956139SMengyuan Lou * @data: pointer to a network interface device structure
185e7956139SMengyuan Lou **/
ngbe_intr(int __always_unused irq,void * data)186e7956139SMengyuan Lou static irqreturn_t ngbe_intr(int __always_unused irq, void *data)
187e7956139SMengyuan Lou {
188e7956139SMengyuan Lou struct wx_q_vector *q_vector;
189e7956139SMengyuan Lou struct wx *wx = data;
190e7956139SMengyuan Lou struct pci_dev *pdev;
191e7956139SMengyuan Lou u32 eicr;
192e7956139SMengyuan Lou
193e7956139SMengyuan Lou q_vector = wx->q_vector[0];
194e7956139SMengyuan Lou pdev = wx->pdev;
195e7956139SMengyuan Lou
196e7956139SMengyuan Lou eicr = wx_misc_isb(wx, WX_ISB_VEC0);
197e7956139SMengyuan Lou if (!eicr) {
198e7956139SMengyuan Lou /* shared interrupt alert!
199e7956139SMengyuan Lou * the interrupt that we masked before the EICR read.
200e7956139SMengyuan Lou */
201e7956139SMengyuan Lou if (netif_running(wx->netdev))
202e7956139SMengyuan Lou ngbe_irq_enable(wx, true);
203e7956139SMengyuan Lou return IRQ_NONE; /* Not our interrupt */
204e7956139SMengyuan Lou }
205e7956139SMengyuan Lou wx->isb_mem[WX_ISB_VEC0] = 0;
206e7956139SMengyuan Lou if (!(pdev->msi_enabled))
207e7956139SMengyuan Lou wr32(wx, WX_PX_INTA, 1);
208e7956139SMengyuan Lou
209e7956139SMengyuan Lou wx->isb_mem[WX_ISB_MISC] = 0;
210e7956139SMengyuan Lou /* would disable interrupts here but it is auto disabled */
211e7956139SMengyuan Lou napi_schedule_irqoff(&q_vector->napi);
212e7956139SMengyuan Lou
213e7956139SMengyuan Lou if (netif_running(wx->netdev))
214e7956139SMengyuan Lou ngbe_irq_enable(wx, false);
215e7956139SMengyuan Lou
216e7956139SMengyuan Lou return IRQ_HANDLED;
217e7956139SMengyuan Lou }
218e7956139SMengyuan Lou
ngbe_msix_other(int __always_unused irq,void * data)219e7956139SMengyuan Lou static irqreturn_t ngbe_msix_other(int __always_unused irq, void *data)
220e7956139SMengyuan Lou {
221e7956139SMengyuan Lou struct wx *wx = data;
222e7956139SMengyuan Lou
223e7956139SMengyuan Lou /* re-enable the original interrupt state, no lsc, no queues */
224e7956139SMengyuan Lou if (netif_running(wx->netdev))
225e7956139SMengyuan Lou ngbe_irq_enable(wx, false);
226e7956139SMengyuan Lou
227e7956139SMengyuan Lou return IRQ_HANDLED;
228e7956139SMengyuan Lou }
229e7956139SMengyuan Lou
230e7956139SMengyuan Lou /**
231e7956139SMengyuan Lou * ngbe_request_msix_irqs - Initialize MSI-X interrupts
232e7956139SMengyuan Lou * @wx: board private structure
233e7956139SMengyuan Lou *
234e7956139SMengyuan Lou * ngbe_request_msix_irqs allocates MSI-X vectors and requests
235e7956139SMengyuan Lou * interrupts from the kernel.
236e7956139SMengyuan Lou **/
ngbe_request_msix_irqs(struct wx * wx)237e7956139SMengyuan Lou static int ngbe_request_msix_irqs(struct wx *wx)
238e7956139SMengyuan Lou {
239e7956139SMengyuan Lou struct net_device *netdev = wx->netdev;
240e7956139SMengyuan Lou int vector, err;
241e7956139SMengyuan Lou
242e7956139SMengyuan Lou for (vector = 0; vector < wx->num_q_vectors; vector++) {
243e7956139SMengyuan Lou struct wx_q_vector *q_vector = wx->q_vector[vector];
244e7956139SMengyuan Lou struct msix_entry *entry = &wx->msix_entries[vector];
245e7956139SMengyuan Lou
246e7956139SMengyuan Lou if (q_vector->tx.ring && q_vector->rx.ring)
247e7956139SMengyuan Lou snprintf(q_vector->name, sizeof(q_vector->name) - 1,
248e7956139SMengyuan Lou "%s-TxRx-%d", netdev->name, entry->entry);
249e7956139SMengyuan Lou else
250e7956139SMengyuan Lou /* skip this unused q_vector */
251e7956139SMengyuan Lou continue;
252e7956139SMengyuan Lou
253e7956139SMengyuan Lou err = request_irq(entry->vector, wx_msix_clean_rings, 0,
254e7956139SMengyuan Lou q_vector->name, q_vector);
255e7956139SMengyuan Lou if (err) {
256e7956139SMengyuan Lou wx_err(wx, "request_irq failed for MSIX interrupt %s Error: %d\n",
257e7956139SMengyuan Lou q_vector->name, err);
258e7956139SMengyuan Lou goto free_queue_irqs;
259e7956139SMengyuan Lou }
260e7956139SMengyuan Lou }
261e7956139SMengyuan Lou
262e7956139SMengyuan Lou err = request_irq(wx->msix_entries[vector].vector,
263e7956139SMengyuan Lou ngbe_msix_other, 0, netdev->name, wx);
264e7956139SMengyuan Lou
265e7956139SMengyuan Lou if (err) {
266e7956139SMengyuan Lou wx_err(wx, "request_irq for msix_other failed: %d\n", err);
267e7956139SMengyuan Lou goto free_queue_irqs;
268e7956139SMengyuan Lou }
269e7956139SMengyuan Lou
270e7956139SMengyuan Lou return 0;
271e7956139SMengyuan Lou
272e7956139SMengyuan Lou free_queue_irqs:
273e7956139SMengyuan Lou while (vector) {
274e7956139SMengyuan Lou vector--;
275e7956139SMengyuan Lou free_irq(wx->msix_entries[vector].vector,
276e7956139SMengyuan Lou wx->q_vector[vector]);
277e7956139SMengyuan Lou }
278e7956139SMengyuan Lou wx_reset_interrupt_capability(wx);
279e7956139SMengyuan Lou return err;
280e7956139SMengyuan Lou }
281e7956139SMengyuan Lou
282e7956139SMengyuan Lou /**
283e7956139SMengyuan Lou * ngbe_request_irq - initialize interrupts
284e7956139SMengyuan Lou * @wx: board private structure
285e7956139SMengyuan Lou *
286e7956139SMengyuan Lou * Attempts to configure interrupts using the best available
287e7956139SMengyuan Lou * capabilities of the hardware and kernel.
288e7956139SMengyuan Lou **/
ngbe_request_irq(struct wx * wx)289e7956139SMengyuan Lou static int ngbe_request_irq(struct wx *wx)
290e7956139SMengyuan Lou {
291e7956139SMengyuan Lou struct net_device *netdev = wx->netdev;
292e7956139SMengyuan Lou struct pci_dev *pdev = wx->pdev;
293e7956139SMengyuan Lou int err;
294e7956139SMengyuan Lou
295e7956139SMengyuan Lou if (pdev->msix_enabled)
296e7956139SMengyuan Lou err = ngbe_request_msix_irqs(wx);
297e7956139SMengyuan Lou else if (pdev->msi_enabled)
298e7956139SMengyuan Lou err = request_irq(pdev->irq, ngbe_intr, 0,
299e7956139SMengyuan Lou netdev->name, wx);
300e7956139SMengyuan Lou else
301e7956139SMengyuan Lou err = request_irq(pdev->irq, ngbe_intr, IRQF_SHARED,
302e7956139SMengyuan Lou netdev->name, wx);
303e7956139SMengyuan Lou
304e7956139SMengyuan Lou if (err)
305e7956139SMengyuan Lou wx_err(wx, "request_irq failed, Error %d\n", err);
306e7956139SMengyuan Lou
307e7956139SMengyuan Lou return err;
308e7956139SMengyuan Lou }
309e7956139SMengyuan Lou
ngbe_disable_device(struct wx * wx)310a1cf597bSMengyuan Lou static void ngbe_disable_device(struct wx *wx)
311a1cf597bSMengyuan Lou {
312a1cf597bSMengyuan Lou struct net_device *netdev = wx->netdev;
313b97f955eSMengyuan Lou u32 i;
314a1cf597bSMengyuan Lou
315b97f955eSMengyuan Lou /* disable all enabled rx queues */
316b97f955eSMengyuan Lou for (i = 0; i < wx->num_rx_queues; i++)
317b97f955eSMengyuan Lou /* this call also flushes the previous write */
318b97f955eSMengyuan Lou wx_disable_rx_queue(wx, wx->rx_ring[i]);
319a1cf597bSMengyuan Lou /* disable receives */
320a1cf597bSMengyuan Lou wx_disable_rx(wx);
321b97f955eSMengyuan Lou wx_napi_disable_all(wx);
322b97f955eSMengyuan Lou netif_tx_stop_all_queues(netdev);
323a1cf597bSMengyuan Lou netif_tx_disable(netdev);
324a1cf597bSMengyuan Lou if (wx->gpio_ctrl)
325a1cf597bSMengyuan Lou ngbe_sfp_modules_txrx_powerctl(wx, false);
326e7956139SMengyuan Lou wx_irq_disable(wx);
327b97f955eSMengyuan Lou /* disable transmits in the hardware now that interrupts are off */
328b97f955eSMengyuan Lou for (i = 0; i < wx->num_tx_queues; i++) {
329b97f955eSMengyuan Lou u8 reg_idx = wx->tx_ring[i]->reg_idx;
330b97f955eSMengyuan Lou
331b97f955eSMengyuan Lou wr32(wx, WX_PX_TR_CFG(reg_idx), WX_PX_TR_CFG_SWFLSH);
332b97f955eSMengyuan Lou }
333a1cf597bSMengyuan Lou }
334a1cf597bSMengyuan Lou
ngbe_down(struct wx * wx)335803df55dSMengyuan Lou static void ngbe_down(struct wx *wx)
33602338c48SMengyuan Lou {
337a1cf597bSMengyuan Lou phy_stop(wx->phydev);
338a1cf597bSMengyuan Lou ngbe_disable_device(wx);
339b97f955eSMengyuan Lou wx_clean_all_tx_rings(wx);
340b97f955eSMengyuan Lou wx_clean_all_rx_rings(wx);
341a1cf597bSMengyuan Lou }
342a1cf597bSMengyuan Lou
ngbe_up(struct wx * wx)343a1cf597bSMengyuan Lou static void ngbe_up(struct wx *wx)
344a1cf597bSMengyuan Lou {
345e7956139SMengyuan Lou wx_configure_vectors(wx);
346e7956139SMengyuan Lou
347b97f955eSMengyuan Lou /* make sure to complete pre-operations */
348b97f955eSMengyuan Lou smp_mb__before_atomic();
349b97f955eSMengyuan Lou wx_napi_enable_all(wx);
350b97f955eSMengyuan Lou /* enable transmits */
351b97f955eSMengyuan Lou netif_tx_start_all_queues(wx->netdev);
352b97f955eSMengyuan Lou
353e7956139SMengyuan Lou /* clear any pending interrupts, may auto mask */
35459513714SJiawen Wu rd32(wx, WX_PX_IC(0));
355e7956139SMengyuan Lou rd32(wx, WX_PX_MISC_IC);
356e7956139SMengyuan Lou ngbe_irq_enable(wx, true);
357a1cf597bSMengyuan Lou if (wx->gpio_ctrl)
358a1cf597bSMengyuan Lou ngbe_sfp_modules_txrx_powerctl(wx, true);
359e7956139SMengyuan Lou
360a1cf597bSMengyuan Lou phy_start(wx->phydev);
361a1cf597bSMengyuan Lou }
36202338c48SMengyuan Lou
36302338c48SMengyuan Lou /**
36402338c48SMengyuan Lou * ngbe_open - Called when a network interface is made active
36502338c48SMengyuan Lou * @netdev: network interface device structure
36602338c48SMengyuan Lou *
36702338c48SMengyuan Lou * Returns 0 on success, negative value on failure
36802338c48SMengyuan Lou *
36902338c48SMengyuan Lou * The open entry point is called when a network interface is made
37002338c48SMengyuan Lou * active by the system (IFF_UP).
37102338c48SMengyuan Lou **/
ngbe_open(struct net_device * netdev)37202338c48SMengyuan Lou static int ngbe_open(struct net_device *netdev)
37302338c48SMengyuan Lou {
374803df55dSMengyuan Lou struct wx *wx = netdev_priv(netdev);
375a1cf597bSMengyuan Lou int err;
37602338c48SMengyuan Lou
3779607a3e6SJiawen Wu wx_control_hw(wx, true);
378e7956139SMengyuan Lou
379b97f955eSMengyuan Lou err = wx_setup_resources(wx);
380e7956139SMengyuan Lou if (err)
381e7956139SMengyuan Lou return err;
382e7956139SMengyuan Lou
383e7956139SMengyuan Lou wx_configure(wx);
384e7956139SMengyuan Lou
385e7956139SMengyuan Lou err = ngbe_request_irq(wx);
386e7956139SMengyuan Lou if (err)
387b97f955eSMengyuan Lou goto err_free_resources;
388e7956139SMengyuan Lou
389a1cf597bSMengyuan Lou err = ngbe_phy_connect(wx);
390a1cf597bSMengyuan Lou if (err)
391b97f955eSMengyuan Lou goto err_free_irq;
392b97f955eSMengyuan Lou
393b97f955eSMengyuan Lou err = netif_set_real_num_tx_queues(netdev, wx->num_tx_queues);
394b97f955eSMengyuan Lou if (err)
395b97f955eSMengyuan Lou goto err_dis_phy;
396b97f955eSMengyuan Lou
397b97f955eSMengyuan Lou err = netif_set_real_num_rx_queues(netdev, wx->num_rx_queues);
398b97f955eSMengyuan Lou if (err)
399b97f955eSMengyuan Lou goto err_dis_phy;
400b97f955eSMengyuan Lou
401a1cf597bSMengyuan Lou ngbe_up(wx);
40202338c48SMengyuan Lou
40302338c48SMengyuan Lou return 0;
404b97f955eSMengyuan Lou err_dis_phy:
405b97f955eSMengyuan Lou phy_disconnect(wx->phydev);
406b97f955eSMengyuan Lou err_free_irq:
407b97f955eSMengyuan Lou wx_free_irq(wx);
408b97f955eSMengyuan Lou err_free_resources:
409b97f955eSMengyuan Lou wx_free_resources(wx);
410e7956139SMengyuan Lou return err;
41102338c48SMengyuan Lou }
41202338c48SMengyuan Lou
41302338c48SMengyuan Lou /**
41402338c48SMengyuan Lou * ngbe_close - Disables a network interface
41502338c48SMengyuan Lou * @netdev: network interface device structure
41602338c48SMengyuan Lou *
41702338c48SMengyuan Lou * Returns 0, this is not allowed to fail
41802338c48SMengyuan Lou *
41902338c48SMengyuan Lou * The close entry point is called when an interface is de-activated
42002338c48SMengyuan Lou * by the OS. The hardware is still under the drivers control, but
42102338c48SMengyuan Lou * needs to be disabled. A global MAC reset is issued to stop the
42202338c48SMengyuan Lou * hardware, and all transmit and receive resources are freed.
42302338c48SMengyuan Lou **/
ngbe_close(struct net_device * netdev)42402338c48SMengyuan Lou static int ngbe_close(struct net_device *netdev)
42502338c48SMengyuan Lou {
426803df55dSMengyuan Lou struct wx *wx = netdev_priv(netdev);
42702338c48SMengyuan Lou
428803df55dSMengyuan Lou ngbe_down(wx);
429e7956139SMengyuan Lou wx_free_irq(wx);
430b97f955eSMengyuan Lou wx_free_resources(wx);
431a1cf597bSMengyuan Lou phy_disconnect(wx->phydev);
432803df55dSMengyuan Lou wx_control_hw(wx, false);
43302338c48SMengyuan Lou
43402338c48SMengyuan Lou return 0;
43502338c48SMengyuan Lou }
43602338c48SMengyuan Lou
ngbe_dev_shutdown(struct pci_dev * pdev,bool * enable_wake)437e79e40c8SMengyuan Lou static void ngbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake)
438e79e40c8SMengyuan Lou {
439803df55dSMengyuan Lou struct wx *wx = pci_get_drvdata(pdev);
440803df55dSMengyuan Lou struct net_device *netdev;
4416963e463SMengyuan Lou u32 wufc = wx->wol;
442e79e40c8SMengyuan Lou
443803df55dSMengyuan Lou netdev = wx->netdev;
4446963e463SMengyuan Lou rtnl_lock();
445e79e40c8SMengyuan Lou netif_device_detach(netdev);
446e79e40c8SMengyuan Lou
44702338c48SMengyuan Lou if (netif_running(netdev))
4486963e463SMengyuan Lou ngbe_close(netdev);
4496963e463SMengyuan Lou wx_clear_interrupt_scheme(wx);
45002338c48SMengyuan Lou rtnl_unlock();
4516963e463SMengyuan Lou
4526963e463SMengyuan Lou if (wufc) {
4536963e463SMengyuan Lou wx_set_rx_mode(netdev);
4546963e463SMengyuan Lou wx_configure_rx(wx);
4556963e463SMengyuan Lou wr32(wx, NGBE_PSR_WKUP_CTL, wufc);
4566963e463SMengyuan Lou } else {
4576963e463SMengyuan Lou wr32(wx, NGBE_PSR_WKUP_CTL, 0);
4586963e463SMengyuan Lou }
4596963e463SMengyuan Lou pci_wake_from_d3(pdev, !!wufc);
4606963e463SMengyuan Lou *enable_wake = !!wufc;
461803df55dSMengyuan Lou wx_control_hw(wx, false);
46202338c48SMengyuan Lou
463e79e40c8SMengyuan Lou pci_disable_device(pdev);
464e79e40c8SMengyuan Lou }
465e79e40c8SMengyuan Lou
ngbe_shutdown(struct pci_dev * pdev)466e79e40c8SMengyuan Lou static void ngbe_shutdown(struct pci_dev *pdev)
467e79e40c8SMengyuan Lou {
468803df55dSMengyuan Lou struct wx *wx = pci_get_drvdata(pdev);
469e79e40c8SMengyuan Lou bool wake;
470e79e40c8SMengyuan Lou
471803df55dSMengyuan Lou wake = !!wx->wol;
47202338c48SMengyuan Lou
473e79e40c8SMengyuan Lou ngbe_dev_shutdown(pdev, &wake);
474e79e40c8SMengyuan Lou
475e79e40c8SMengyuan Lou if (system_state == SYSTEM_POWER_OFF) {
476e79e40c8SMengyuan Lou pci_wake_from_d3(pdev, wake);
477e79e40c8SMengyuan Lou pci_set_power_state(pdev, PCI_D3hot);
478e79e40c8SMengyuan Lou }
479e79e40c8SMengyuan Lou }
480e79e40c8SMengyuan Lou
48102338c48SMengyuan Lou static const struct net_device_ops ngbe_netdev_ops = {
48202338c48SMengyuan Lou .ndo_open = ngbe_open,
48302338c48SMengyuan Lou .ndo_stop = ngbe_close,
48481dc0741SMengyuan Lou .ndo_change_mtu = wx_change_mtu,
485b97f955eSMengyuan Lou .ndo_start_xmit = wx_xmit_frame,
486b97f955eSMengyuan Lou .ndo_set_rx_mode = wx_set_rx_mode,
48750a908a0SMengyuan Lou .ndo_set_features = wx_set_features,
48802338c48SMengyuan Lou .ndo_validate_addr = eth_validate_addr,
48979625f45SJiawen Wu .ndo_set_mac_address = wx_set_mac,
490b97f955eSMengyuan Lou .ndo_get_stats64 = wx_get_stats64,
491361bf4f4SMengyuan Lou .ndo_vlan_rx_add_vid = wx_vlan_rx_add_vid,
492361bf4f4SMengyuan Lou .ndo_vlan_rx_kill_vid = wx_vlan_rx_kill_vid,
49302338c48SMengyuan Lou };
49402338c48SMengyuan Lou
495e79e40c8SMengyuan Lou /**
496e79e40c8SMengyuan Lou * ngbe_probe - Device Initialization Routine
497e79e40c8SMengyuan Lou * @pdev: PCI device information struct
498e79e40c8SMengyuan Lou * @ent: entry in ngbe_pci_tbl
499e79e40c8SMengyuan Lou *
500e79e40c8SMengyuan Lou * Returns 0 on success, negative on failure
501e79e40c8SMengyuan Lou *
502803df55dSMengyuan Lou * ngbe_probe initializes an wx identified by a pci_dev structure.
503803df55dSMengyuan Lou * The OS initialization, configuring of the wx private structure,
504e79e40c8SMengyuan Lou * and a hardware reset occur.
505e79e40c8SMengyuan Lou **/
ngbe_probe(struct pci_dev * pdev,const struct pci_device_id __always_unused * ent)506e79e40c8SMengyuan Lou static int ngbe_probe(struct pci_dev *pdev,
507e79e40c8SMengyuan Lou const struct pci_device_id __always_unused *ent)
508e79e40c8SMengyuan Lou {
509e79e40c8SMengyuan Lou struct net_device *netdev;
51002338c48SMengyuan Lou u32 e2rom_cksum_cap = 0;
511803df55dSMengyuan Lou struct wx *wx = NULL;
51202338c48SMengyuan Lou static int func_nums;
51302338c48SMengyuan Lou u16 e2rom_ver = 0;
51402338c48SMengyuan Lou u32 etrack_id = 0;
51502338c48SMengyuan Lou u32 saved_ver = 0;
516e79e40c8SMengyuan Lou int err;
517e79e40c8SMengyuan Lou
518e79e40c8SMengyuan Lou err = pci_enable_device_mem(pdev);
519e79e40c8SMengyuan Lou if (err)
520e79e40c8SMengyuan Lou return err;
521e79e40c8SMengyuan Lou
522e79e40c8SMengyuan Lou err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
523e79e40c8SMengyuan Lou if (err) {
524e79e40c8SMengyuan Lou dev_err(&pdev->dev,
525e79e40c8SMengyuan Lou "No usable DMA configuration, aborting\n");
526e79e40c8SMengyuan Lou goto err_pci_disable_dev;
527e79e40c8SMengyuan Lou }
528e79e40c8SMengyuan Lou
529e79e40c8SMengyuan Lou err = pci_request_selected_regions(pdev,
530e79e40c8SMengyuan Lou pci_select_bars(pdev, IORESOURCE_MEM),
531e79e40c8SMengyuan Lou ngbe_driver_name);
532e79e40c8SMengyuan Lou if (err) {
533e79e40c8SMengyuan Lou dev_err(&pdev->dev,
534e79e40c8SMengyuan Lou "pci_request_selected_regions failed %d\n", err);
535e79e40c8SMengyuan Lou goto err_pci_disable_dev;
536e79e40c8SMengyuan Lou }
537e79e40c8SMengyuan Lou
538e79e40c8SMengyuan Lou pci_set_master(pdev);
539e79e40c8SMengyuan Lou
540e79e40c8SMengyuan Lou netdev = devm_alloc_etherdev_mqs(&pdev->dev,
541803df55dSMengyuan Lou sizeof(struct wx),
542e79e40c8SMengyuan Lou NGBE_MAX_TX_QUEUES,
543e79e40c8SMengyuan Lou NGBE_MAX_RX_QUEUES);
544e79e40c8SMengyuan Lou if (!netdev) {
545e79e40c8SMengyuan Lou err = -ENOMEM;
546e79e40c8SMengyuan Lou goto err_pci_release_regions;
547e79e40c8SMengyuan Lou }
548e79e40c8SMengyuan Lou
549e79e40c8SMengyuan Lou SET_NETDEV_DEV(netdev, &pdev->dev);
550e79e40c8SMengyuan Lou
551803df55dSMengyuan Lou wx = netdev_priv(netdev);
5529607a3e6SJiawen Wu wx->netdev = netdev;
553803df55dSMengyuan Lou wx->pdev = pdev;
554803df55dSMengyuan Lou wx->msg_enable = BIT(3) - 1;
555e79e40c8SMengyuan Lou
556803df55dSMengyuan Lou wx->hw_addr = devm_ioremap(&pdev->dev,
557e79e40c8SMengyuan Lou pci_resource_start(pdev, 0),
558e79e40c8SMengyuan Lou pci_resource_len(pdev, 0));
559803df55dSMengyuan Lou if (!wx->hw_addr) {
560e79e40c8SMengyuan Lou err = -EIO;
561e79e40c8SMengyuan Lou goto err_pci_release_regions;
562e79e40c8SMengyuan Lou }
563e79e40c8SMengyuan Lou
5641b8d1c50SMengyuan Lou wx->driver_name = ngbe_driver_name;
5651b8d1c50SMengyuan Lou ngbe_set_ethtool_ops(netdev);
56602338c48SMengyuan Lou netdev->netdev_ops = &ngbe_netdev_ops;
56702338c48SMengyuan Lou
56850a908a0SMengyuan Lou netdev->features = NETIF_F_SG | NETIF_F_IP_CSUM |
56950a908a0SMengyuan Lou NETIF_F_TSO | NETIF_F_TSO6 |
57050a908a0SMengyuan Lou NETIF_F_RXHASH | NETIF_F_RXCSUM;
57150a908a0SMengyuan Lou netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_TSO_MANGLEID;
57250a908a0SMengyuan Lou netdev->vlan_features |= netdev->features;
57350a908a0SMengyuan Lou netdev->features |= NETIF_F_IPV6_CSUM | NETIF_F_VLAN_FEATURES;
574b97f955eSMengyuan Lou /* copy netdev features into list of user selectable features */
57550a908a0SMengyuan Lou netdev->hw_features |= netdev->features | NETIF_F_RXALL;
57650a908a0SMengyuan Lou netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
57750a908a0SMengyuan Lou netdev->features |= NETIF_F_HIGHDMA;
57850a908a0SMengyuan Lou netdev->hw_features |= NETIF_F_GRO;
57950a908a0SMengyuan Lou netdev->features |= NETIF_F_GRO;
580b97f955eSMengyuan Lou
581b97f955eSMengyuan Lou netdev->priv_flags |= IFF_UNICAST_FLT;
582b97f955eSMengyuan Lou netdev->priv_flags |= IFF_SUPP_NOFCS;
583b97f955eSMengyuan Lou
584b97f955eSMengyuan Lou netdev->min_mtu = ETH_MIN_MTU;
58581dc0741SMengyuan Lou netdev->max_mtu = WX_MAX_JUMBO_FRAME_SIZE -
58681dc0741SMengyuan Lou (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
587e79e40c8SMengyuan Lou
588803df55dSMengyuan Lou wx->bd_number = func_nums;
58902338c48SMengyuan Lou /* setup the private structure */
590803df55dSMengyuan Lou err = ngbe_sw_init(wx);
59102338c48SMengyuan Lou if (err)
59202338c48SMengyuan Lou goto err_free_mac_table;
59302338c48SMengyuan Lou
59402338c48SMengyuan Lou /* check if flash load is done after hw power up */
5959607a3e6SJiawen Wu err = wx_check_flash_load(wx, NGBE_SPI_ILDR_STATUS_PERST);
59602338c48SMengyuan Lou if (err)
59702338c48SMengyuan Lou goto err_free_mac_table;
5989607a3e6SJiawen Wu err = wx_check_flash_load(wx, NGBE_SPI_ILDR_STATUS_PWRRST);
59902338c48SMengyuan Lou if (err)
60002338c48SMengyuan Lou goto err_free_mac_table;
60102338c48SMengyuan Lou
6029607a3e6SJiawen Wu err = wx_mng_present(wx);
60302338c48SMengyuan Lou if (err) {
60402338c48SMengyuan Lou dev_err(&pdev->dev, "Management capability is not present\n");
60502338c48SMengyuan Lou goto err_free_mac_table;
60602338c48SMengyuan Lou }
60702338c48SMengyuan Lou
608803df55dSMengyuan Lou err = ngbe_reset_hw(wx);
60902338c48SMengyuan Lou if (err) {
61002338c48SMengyuan Lou dev_err(&pdev->dev, "HW Init failed: %d\n", err);
61102338c48SMengyuan Lou goto err_free_mac_table;
61202338c48SMengyuan Lou }
61302338c48SMengyuan Lou
6149607a3e6SJiawen Wu if (wx->bus.func == 0) {
6159607a3e6SJiawen Wu wr32(wx, NGBE_CALSUM_CAP_STATUS, 0x0);
6169607a3e6SJiawen Wu wr32(wx, NGBE_EEPROM_VERSION_STORE_REG, 0x0);
61702338c48SMengyuan Lou } else {
6189607a3e6SJiawen Wu e2rom_cksum_cap = rd32(wx, NGBE_CALSUM_CAP_STATUS);
6199607a3e6SJiawen Wu saved_ver = rd32(wx, NGBE_EEPROM_VERSION_STORE_REG);
62002338c48SMengyuan Lou }
62102338c48SMengyuan Lou
6229607a3e6SJiawen Wu wx_init_eeprom_params(wx);
6239607a3e6SJiawen Wu if (wx->bus.func == 0 || e2rom_cksum_cap == 0) {
62402338c48SMengyuan Lou /* make sure the EEPROM is ready */
625803df55dSMengyuan Lou err = ngbe_eeprom_chksum_hostif(wx);
62602338c48SMengyuan Lou if (err) {
62702338c48SMengyuan Lou dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
62802338c48SMengyuan Lou err = -EIO;
62902338c48SMengyuan Lou goto err_free_mac_table;
63002338c48SMengyuan Lou }
63102338c48SMengyuan Lou }
63202338c48SMengyuan Lou
633803df55dSMengyuan Lou wx->wol = 0;
6346963e463SMengyuan Lou if (wx->wol_hw_supported)
635803df55dSMengyuan Lou wx->wol = NGBE_PSR_WKUP_CTL_MAG;
63602338c48SMengyuan Lou
6376963e463SMengyuan Lou netdev->wol_enabled = !!(wx->wol);
638803df55dSMengyuan Lou wr32(wx, NGBE_PSR_WKUP_CTL, wx->wol);
639803df55dSMengyuan Lou device_set_wakeup_enable(&pdev->dev, wx->wol);
64002338c48SMengyuan Lou
64102338c48SMengyuan Lou /* Save off EEPROM version number and Option Rom version which
64202338c48SMengyuan Lou * together make a unique identify for the eeprom
64302338c48SMengyuan Lou */
64402338c48SMengyuan Lou if (saved_ver) {
64502338c48SMengyuan Lou etrack_id = saved_ver;
64602338c48SMengyuan Lou } else {
6479607a3e6SJiawen Wu wx_read_ee_hostif(wx,
6489607a3e6SJiawen Wu wx->eeprom.sw_region_offset + NGBE_EEPROM_VERSION_H,
64902338c48SMengyuan Lou &e2rom_ver);
65002338c48SMengyuan Lou etrack_id = e2rom_ver << 16;
6519607a3e6SJiawen Wu wx_read_ee_hostif(wx,
6529607a3e6SJiawen Wu wx->eeprom.sw_region_offset + NGBE_EEPROM_VERSION_L,
65302338c48SMengyuan Lou &e2rom_ver);
65402338c48SMengyuan Lou etrack_id |= e2rom_ver;
6559607a3e6SJiawen Wu wr32(wx, NGBE_EEPROM_VERSION_STORE_REG, etrack_id);
65602338c48SMengyuan Lou }
6571b8d1c50SMengyuan Lou snprintf(wx->eeprom_id, sizeof(wx->eeprom_id),
6581b8d1c50SMengyuan Lou "0x%08x", etrack_id);
65902338c48SMengyuan Lou
6609607a3e6SJiawen Wu eth_hw_addr_set(netdev, wx->mac.perm_addr);
6619607a3e6SJiawen Wu wx_mac_set_default_filter(wx, wx->mac.perm_addr);
66202338c48SMengyuan Lou
663e7956139SMengyuan Lou err = wx_init_interrupt_scheme(wx);
664e7956139SMengyuan Lou if (err)
665e7956139SMengyuan Lou goto err_free_mac_table;
666e7956139SMengyuan Lou
667a1cf597bSMengyuan Lou /* phy Interface Configuration */
668a1cf597bSMengyuan Lou err = ngbe_mdio_init(wx);
669a1cf597bSMengyuan Lou if (err)
670e7956139SMengyuan Lou goto err_clear_interrupt_scheme;
671a1cf597bSMengyuan Lou
67202338c48SMengyuan Lou err = register_netdev(netdev);
67302338c48SMengyuan Lou if (err)
67402338c48SMengyuan Lou goto err_register;
67502338c48SMengyuan Lou
676803df55dSMengyuan Lou pci_set_drvdata(pdev, wx);
677e79e40c8SMengyuan Lou
678803df55dSMengyuan Lou netif_info(wx, probe, netdev,
67902338c48SMengyuan Lou "PHY: %s, PBA No: Wang Xun GbE Family Controller\n",
680803df55dSMengyuan Lou wx->mac_type == em_mac_type_mdi ? "Internal" : "External");
681803df55dSMengyuan Lou netif_info(wx, probe, netdev, "%pM\n", netdev->dev_addr);
68202338c48SMengyuan Lou
683e79e40c8SMengyuan Lou return 0;
684e79e40c8SMengyuan Lou
68502338c48SMengyuan Lou err_register:
6869607a3e6SJiawen Wu wx_control_hw(wx, false);
687e7956139SMengyuan Lou err_clear_interrupt_scheme:
688e7956139SMengyuan Lou wx_clear_interrupt_scheme(wx);
68902338c48SMengyuan Lou err_free_mac_table:
6909607a3e6SJiawen Wu kfree(wx->mac_table);
691e79e40c8SMengyuan Lou err_pci_release_regions:
692e79e40c8SMengyuan Lou pci_release_selected_regions(pdev,
693e79e40c8SMengyuan Lou pci_select_bars(pdev, IORESOURCE_MEM));
694e79e40c8SMengyuan Lou err_pci_disable_dev:
695e79e40c8SMengyuan Lou pci_disable_device(pdev);
696e79e40c8SMengyuan Lou return err;
697e79e40c8SMengyuan Lou }
698e79e40c8SMengyuan Lou
699e79e40c8SMengyuan Lou /**
700e79e40c8SMengyuan Lou * ngbe_remove - Device Removal Routine
701e79e40c8SMengyuan Lou * @pdev: PCI device information struct
702e79e40c8SMengyuan Lou *
703e79e40c8SMengyuan Lou * ngbe_remove is called by the PCI subsystem to alert the driver
704e79e40c8SMengyuan Lou * that it should release a PCI device. The could be caused by a
705e79e40c8SMengyuan Lou * Hot-Plug event, or because the driver is going to be removed from
706e79e40c8SMengyuan Lou * memory.
707e79e40c8SMengyuan Lou **/
ngbe_remove(struct pci_dev * pdev)708e79e40c8SMengyuan Lou static void ngbe_remove(struct pci_dev *pdev)
709e79e40c8SMengyuan Lou {
710803df55dSMengyuan Lou struct wx *wx = pci_get_drvdata(pdev);
71102338c48SMengyuan Lou struct net_device *netdev;
71202338c48SMengyuan Lou
713803df55dSMengyuan Lou netdev = wx->netdev;
71402338c48SMengyuan Lou unregister_netdev(netdev);
715e79e40c8SMengyuan Lou pci_release_selected_regions(pdev,
716e79e40c8SMengyuan Lou pci_select_bars(pdev, IORESOURCE_MEM));
717e79e40c8SMengyuan Lou
7189607a3e6SJiawen Wu kfree(wx->mac_table);
719e7956139SMengyuan Lou wx_clear_interrupt_scheme(wx);
720e79e40c8SMengyuan Lou
721e79e40c8SMengyuan Lou pci_disable_device(pdev);
722e79e40c8SMengyuan Lou }
723e79e40c8SMengyuan Lou
ngbe_suspend(struct pci_dev * pdev,pm_message_t state)7246963e463SMengyuan Lou static int ngbe_suspend(struct pci_dev *pdev, pm_message_t state)
7256963e463SMengyuan Lou {
7266963e463SMengyuan Lou bool wake;
7276963e463SMengyuan Lou
7286963e463SMengyuan Lou ngbe_dev_shutdown(pdev, &wake);
7296963e463SMengyuan Lou device_set_wakeup_enable(&pdev->dev, wake);
7306963e463SMengyuan Lou
7316963e463SMengyuan Lou return 0;
7326963e463SMengyuan Lou }
7336963e463SMengyuan Lou
ngbe_resume(struct pci_dev * pdev)7346963e463SMengyuan Lou static int ngbe_resume(struct pci_dev *pdev)
7356963e463SMengyuan Lou {
7366963e463SMengyuan Lou struct net_device *netdev;
7376963e463SMengyuan Lou struct wx *wx;
7386963e463SMengyuan Lou u32 err;
7396963e463SMengyuan Lou
7406963e463SMengyuan Lou wx = pci_get_drvdata(pdev);
7416963e463SMengyuan Lou netdev = wx->netdev;
7426963e463SMengyuan Lou
7436963e463SMengyuan Lou err = pci_enable_device_mem(pdev);
7446963e463SMengyuan Lou if (err) {
7456963e463SMengyuan Lou wx_err(wx, "Cannot enable PCI device from suspend\n");
7466963e463SMengyuan Lou return err;
7476963e463SMengyuan Lou }
7486963e463SMengyuan Lou pci_set_master(pdev);
7496963e463SMengyuan Lou device_wakeup_disable(&pdev->dev);
7506963e463SMengyuan Lou
7516963e463SMengyuan Lou ngbe_reset_hw(wx);
7526963e463SMengyuan Lou rtnl_lock();
7536963e463SMengyuan Lou err = wx_init_interrupt_scheme(wx);
7546963e463SMengyuan Lou if (!err && netif_running(netdev))
7556963e463SMengyuan Lou err = ngbe_open(netdev);
7566963e463SMengyuan Lou if (!err)
7576963e463SMengyuan Lou netif_device_attach(netdev);
7586963e463SMengyuan Lou rtnl_unlock();
7596963e463SMengyuan Lou
7606963e463SMengyuan Lou return 0;
7616963e463SMengyuan Lou }
7626963e463SMengyuan Lou
763e79e40c8SMengyuan Lou static struct pci_driver ngbe_driver = {
764e79e40c8SMengyuan Lou .name = ngbe_driver_name,
765e79e40c8SMengyuan Lou .id_table = ngbe_pci_tbl,
766e79e40c8SMengyuan Lou .probe = ngbe_probe,
767e79e40c8SMengyuan Lou .remove = ngbe_remove,
7686963e463SMengyuan Lou .suspend = ngbe_suspend,
7696963e463SMengyuan Lou .resume = ngbe_resume,
770e79e40c8SMengyuan Lou .shutdown = ngbe_shutdown,
771e79e40c8SMengyuan Lou };
772e79e40c8SMengyuan Lou
773e79e40c8SMengyuan Lou module_pci_driver(ngbe_driver);
774e79e40c8SMengyuan Lou
775e79e40c8SMengyuan Lou MODULE_DEVICE_TABLE(pci, ngbe_pci_tbl);
776e79e40c8SMengyuan Lou MODULE_AUTHOR("Beijing WangXun Technology Co., Ltd, <software@net-swift.com>");
777e79e40c8SMengyuan Lou MODULE_DESCRIPTION("WangXun(R) Gigabit PCI Express Network Driver");
778e79e40c8SMengyuan Lou MODULE_LICENSE("GPL");
779