1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21 #include <linux/module.h>
22 #include <linux/aer.h>
26 static const struct fm10k_info *fm10k_info_tbl[] = {
27 [fm10k_device_pf] = &fm10k_pf_info,
28 [fm10k_device_vf] = &fm10k_vf_info,
32 * fm10k_pci_tbl - PCI Device ID Table
34 * Wildcard entries (PCI_ANY_ID) should come last
35 * Last entry must be all 0s
37 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
38 * Class, Class Mask, private data (not used) }
40 static const struct pci_device_id fm10k_pci_tbl[] = {
41 { PCI_VDEVICE(INTEL, FM10K_DEV_ID_PF), fm10k_device_pf },
42 { PCI_VDEVICE(INTEL, FM10K_DEV_ID_VF), fm10k_device_vf },
43 /* required last entry */
46 MODULE_DEVICE_TABLE(pci, fm10k_pci_tbl);
48 u16 fm10k_read_pci_cfg_word(struct fm10k_hw *hw, u32 reg)
50 struct fm10k_intfc *interface = hw->back;
53 if (FM10K_REMOVED(hw->hw_addr))
56 pci_read_config_word(interface->pdev, reg, &value);
58 fm10k_write_flush(hw);
63 u32 fm10k_read_reg(struct fm10k_hw *hw, int reg)
65 u32 __iomem *hw_addr = ACCESS_ONCE(hw->hw_addr);
68 if (FM10K_REMOVED(hw_addr))
71 value = readl(&hw_addr[reg]);
72 if (!(~value) && (!reg || !(~readl(hw_addr)))) {
73 struct fm10k_intfc *interface = hw->back;
74 struct net_device *netdev = interface->netdev;
77 netif_device_detach(netdev);
78 netdev_err(netdev, "PCIe link lost, device now detached\n");
84 static int fm10k_hw_ready(struct fm10k_intfc *interface)
86 struct fm10k_hw *hw = &interface->hw;
88 fm10k_write_flush(hw);
90 return FM10K_REMOVED(hw->hw_addr) ? -ENODEV : 0;
93 void fm10k_service_event_schedule(struct fm10k_intfc *interface)
95 if (!test_bit(__FM10K_SERVICE_DISABLE, &interface->state) &&
96 !test_and_set_bit(__FM10K_SERVICE_SCHED, &interface->state))
97 queue_work(fm10k_workqueue, &interface->service_task);
100 static void fm10k_service_event_complete(struct fm10k_intfc *interface)
102 BUG_ON(!test_bit(__FM10K_SERVICE_SCHED, &interface->state));
104 /* flush memory to make sure state is correct before next watchog */
105 smp_mb__before_atomic();
106 clear_bit(__FM10K_SERVICE_SCHED, &interface->state);
110 * fm10k_service_timer - Timer Call-back
111 * @data: pointer to interface cast into an unsigned long
113 static void fm10k_service_timer(unsigned long data)
115 struct fm10k_intfc *interface = (struct fm10k_intfc *)data;
117 /* Reset the timer */
118 mod_timer(&interface->service_timer, (HZ * 2) + jiffies);
120 fm10k_service_event_schedule(interface);
123 static void fm10k_detach_subtask(struct fm10k_intfc *interface)
125 struct net_device *netdev = interface->netdev;
127 /* do nothing if device is still present or hw_addr is set */
128 if (netif_device_present(netdev) || interface->hw.hw_addr)
133 if (netif_running(netdev))
139 static void fm10k_reinit(struct fm10k_intfc *interface)
141 struct net_device *netdev = interface->netdev;
142 struct fm10k_hw *hw = &interface->hw;
145 WARN_ON(in_interrupt());
147 /* put off any impending NetWatchDogTimeout */
148 netdev->trans_start = jiffies;
150 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
151 usleep_range(1000, 2000);
155 fm10k_iov_suspend(interface->pdev);
157 if (netif_running(netdev))
160 fm10k_mbx_free_irq(interface);
162 /* delay any future reset requests */
163 interface->last_reset = jiffies + (10 * HZ);
165 /* reset and initialize the hardware so it is in a known state */
166 err = hw->mac.ops.reset_hw(hw) ? : hw->mac.ops.init_hw(hw);
168 dev_err(&interface->pdev->dev, "init_hw failed: %d\n", err);
170 /* reassociate interrupts */
171 fm10k_mbx_request_irq(interface);
173 /* update hardware address for VFs if perm_addr has changed */
174 if (hw->mac.type == fm10k_mac_vf) {
175 if (is_valid_ether_addr(hw->mac.perm_addr)) {
176 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
177 ether_addr_copy(netdev->perm_addr, hw->mac.perm_addr);
178 ether_addr_copy(netdev->dev_addr, hw->mac.perm_addr);
179 netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
182 if (hw->mac.vlan_override)
183 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
185 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
189 fm10k_ts_reset(interface);
191 if (netif_running(netdev))
194 fm10k_iov_resume(interface->pdev);
198 clear_bit(__FM10K_RESETTING, &interface->state);
201 static void fm10k_reset_subtask(struct fm10k_intfc *interface)
203 if (!(interface->flags & FM10K_FLAG_RESET_REQUESTED))
206 interface->flags &= ~FM10K_FLAG_RESET_REQUESTED;
208 netdev_err(interface->netdev, "Reset interface\n");
210 fm10k_reinit(interface);
214 * fm10k_configure_swpri_map - Configure Receive SWPRI to PC mapping
215 * @interface: board private structure
217 * Configure the SWPRI to PC mapping for the port.
219 static void fm10k_configure_swpri_map(struct fm10k_intfc *interface)
221 struct net_device *netdev = interface->netdev;
222 struct fm10k_hw *hw = &interface->hw;
225 /* clear flag indicating update is needed */
226 interface->flags &= ~FM10K_FLAG_SWPRI_CONFIG;
228 /* these registers are only available on the PF */
229 if (hw->mac.type != fm10k_mac_pf)
232 /* configure SWPRI to PC map */
233 for (i = 0; i < FM10K_SWPRI_MAX; i++)
234 fm10k_write_reg(hw, FM10K_SWPRI_MAP(i),
235 netdev_get_prio_tc_map(netdev, i));
239 * fm10k_watchdog_update_host_state - Update the link status based on host.
240 * @interface: board private structure
242 static void fm10k_watchdog_update_host_state(struct fm10k_intfc *interface)
244 struct fm10k_hw *hw = &interface->hw;
247 if (test_bit(__FM10K_LINK_DOWN, &interface->state)) {
248 interface->host_ready = false;
249 if (time_is_after_jiffies(interface->link_down_event))
251 clear_bit(__FM10K_LINK_DOWN, &interface->state);
254 if (interface->flags & FM10K_FLAG_SWPRI_CONFIG) {
255 if (rtnl_trylock()) {
256 fm10k_configure_swpri_map(interface);
261 /* lock the mailbox for transmit and receive */
262 fm10k_mbx_lock(interface);
264 err = hw->mac.ops.get_host_state(hw, &interface->host_ready);
265 if (err && time_is_before_jiffies(interface->last_reset))
266 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
269 fm10k_mbx_unlock(interface);
273 * fm10k_mbx_subtask - Process upstream and downstream mailboxes
274 * @interface: board private structure
276 * This function will process both the upstream and downstream mailboxes.
277 * It is necessary for us to hold the rtnl_lock while doing this as the
278 * mailbox accesses are protected by this lock.
280 static void fm10k_mbx_subtask(struct fm10k_intfc *interface)
282 /* process upstream mailbox and update device state */
283 fm10k_watchdog_update_host_state(interface);
285 /* process downstream mailboxes */
286 fm10k_iov_mbx(interface);
290 * fm10k_watchdog_host_is_ready - Update netdev status based on host ready
291 * @interface: board private structure
293 static void fm10k_watchdog_host_is_ready(struct fm10k_intfc *interface)
295 struct net_device *netdev = interface->netdev;
297 /* only continue if link state is currently down */
298 if (netif_carrier_ok(netdev))
301 netif_info(interface, drv, netdev, "NIC Link is up\n");
303 netif_carrier_on(netdev);
304 netif_tx_wake_all_queues(netdev);
308 * fm10k_watchdog_host_not_ready - Update netdev status based on host not ready
309 * @interface: board private structure
311 static void fm10k_watchdog_host_not_ready(struct fm10k_intfc *interface)
313 struct net_device *netdev = interface->netdev;
315 /* only continue if link state is currently up */
316 if (!netif_carrier_ok(netdev))
319 netif_info(interface, drv, netdev, "NIC Link is down\n");
321 netif_carrier_off(netdev);
322 netif_tx_stop_all_queues(netdev);
326 * fm10k_update_stats - Update the board statistics counters.
327 * @interface: board private structure
329 void fm10k_update_stats(struct fm10k_intfc *interface)
331 struct net_device_stats *net_stats = &interface->netdev->stats;
332 struct fm10k_hw *hw = &interface->hw;
333 u64 rx_errors = 0, rx_csum_errors = 0, tx_csum_errors = 0;
334 u64 restart_queue = 0, tx_busy = 0, alloc_failed = 0;
335 u64 rx_bytes_nic = 0, rx_pkts_nic = 0, rx_drops_nic = 0;
336 u64 tx_bytes_nic = 0, tx_pkts_nic = 0;
340 /* do not allow stats update via service task for next second */
341 interface->next_stats_update = jiffies + HZ;
343 /* gather some stats to the interface struct that are per queue */
344 for (bytes = 0, pkts = 0, i = 0; i < interface->num_tx_queues; i++) {
345 struct fm10k_ring *tx_ring = interface->tx_ring[i];
347 restart_queue += tx_ring->tx_stats.restart_queue;
348 tx_busy += tx_ring->tx_stats.tx_busy;
349 tx_csum_errors += tx_ring->tx_stats.csum_err;
350 bytes += tx_ring->stats.bytes;
351 pkts += tx_ring->stats.packets;
354 interface->restart_queue = restart_queue;
355 interface->tx_busy = tx_busy;
356 net_stats->tx_bytes = bytes;
357 net_stats->tx_packets = pkts;
358 interface->tx_csum_errors = tx_csum_errors;
359 /* gather some stats to the interface struct that are per queue */
360 for (bytes = 0, pkts = 0, i = 0; i < interface->num_rx_queues; i++) {
361 struct fm10k_ring *rx_ring = interface->rx_ring[i];
363 bytes += rx_ring->stats.bytes;
364 pkts += rx_ring->stats.packets;
365 alloc_failed += rx_ring->rx_stats.alloc_failed;
366 rx_csum_errors += rx_ring->rx_stats.csum_err;
367 rx_errors += rx_ring->rx_stats.errors;
370 net_stats->rx_bytes = bytes;
371 net_stats->rx_packets = pkts;
372 interface->alloc_failed = alloc_failed;
373 interface->rx_csum_errors = rx_csum_errors;
375 hw->mac.ops.update_hw_stats(hw, &interface->stats);
377 for (i = 0; i < hw->mac.max_queues; i++) {
378 struct fm10k_hw_stats_q *q = &interface->stats.q[i];
380 tx_bytes_nic += q->tx_bytes.count;
381 tx_pkts_nic += q->tx_packets.count;
382 rx_bytes_nic += q->rx_bytes.count;
383 rx_pkts_nic += q->rx_packets.count;
384 rx_drops_nic += q->rx_drops.count;
387 interface->tx_bytes_nic = tx_bytes_nic;
388 interface->tx_packets_nic = tx_pkts_nic;
389 interface->rx_bytes_nic = rx_bytes_nic;
390 interface->rx_packets_nic = rx_pkts_nic;
391 interface->rx_drops_nic = rx_drops_nic;
393 /* Fill out the OS statistics structure */
394 net_stats->rx_errors = rx_errors;
395 net_stats->rx_dropped = interface->stats.nodesc_drop.count;
399 * fm10k_watchdog_flush_tx - flush queues on host not ready
400 * @interface - pointer to the device interface structure
402 static void fm10k_watchdog_flush_tx(struct fm10k_intfc *interface)
404 int some_tx_pending = 0;
407 /* nothing to do if carrier is up */
408 if (netif_carrier_ok(interface->netdev))
411 for (i = 0; i < interface->num_tx_queues; i++) {
412 struct fm10k_ring *tx_ring = interface->tx_ring[i];
414 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
420 /* We've lost link, so the controller stops DMA, but we've got
421 * queued Tx work that's never going to get done, so reset
422 * controller to flush Tx.
425 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
429 * fm10k_watchdog_subtask - check and bring link up
430 * @interface - pointer to the device interface structure
432 static void fm10k_watchdog_subtask(struct fm10k_intfc *interface)
434 /* if interface is down do nothing */
435 if (test_bit(__FM10K_DOWN, &interface->state) ||
436 test_bit(__FM10K_RESETTING, &interface->state))
439 if (interface->host_ready)
440 fm10k_watchdog_host_is_ready(interface);
442 fm10k_watchdog_host_not_ready(interface);
444 /* update stats only once every second */
445 if (time_is_before_jiffies(interface->next_stats_update))
446 fm10k_update_stats(interface);
448 /* flush any uncompleted work */
449 fm10k_watchdog_flush_tx(interface);
453 * fm10k_check_hang_subtask - check for hung queues and dropped interrupts
454 * @interface - pointer to the device interface structure
456 * This function serves two purposes. First it strobes the interrupt lines
457 * in order to make certain interrupts are occurring. Secondly it sets the
458 * bits needed to check for TX hangs. As a result we should immediately
459 * determine if a hang has occurred.
461 static void fm10k_check_hang_subtask(struct fm10k_intfc *interface)
465 /* If we're down or resetting, just bail */
466 if (test_bit(__FM10K_DOWN, &interface->state) ||
467 test_bit(__FM10K_RESETTING, &interface->state))
470 /* rate limit tx hang checks to only once every 2 seconds */
471 if (time_is_after_eq_jiffies(interface->next_tx_hang_check))
473 interface->next_tx_hang_check = jiffies + (2 * HZ);
475 if (netif_carrier_ok(interface->netdev)) {
476 /* Force detection of hung controller */
477 for (i = 0; i < interface->num_tx_queues; i++)
478 set_check_for_tx_hang(interface->tx_ring[i]);
480 /* Rearm all in-use q_vectors for immediate firing */
481 for (i = 0; i < interface->num_q_vectors; i++) {
482 struct fm10k_q_vector *qv = interface->q_vector[i];
484 if (!qv->tx.count && !qv->rx.count)
486 writel(FM10K_ITR_ENABLE | FM10K_ITR_PENDING2, qv->itr);
492 * fm10k_service_task - manages and runs subtasks
493 * @work: pointer to work_struct containing our data
495 static void fm10k_service_task(struct work_struct *work)
497 struct fm10k_intfc *interface;
499 interface = container_of(work, struct fm10k_intfc, service_task);
501 /* tasks always capable of running, but must be rtnl protected */
502 fm10k_mbx_subtask(interface);
503 fm10k_detach_subtask(interface);
504 fm10k_reset_subtask(interface);
506 /* tasks only run when interface is up */
507 fm10k_watchdog_subtask(interface);
508 fm10k_check_hang_subtask(interface);
509 fm10k_ts_tx_subtask(interface);
511 /* release lock on service events to allow scheduling next event */
512 fm10k_service_event_complete(interface);
516 * fm10k_configure_tx_ring - Configure Tx ring after Reset
517 * @interface: board private structure
518 * @ring: structure containing ring specific data
520 * Configure the Tx descriptor ring after a reset.
522 static void fm10k_configure_tx_ring(struct fm10k_intfc *interface,
523 struct fm10k_ring *ring)
525 struct fm10k_hw *hw = &interface->hw;
526 u64 tdba = ring->dma;
527 u32 size = ring->count * sizeof(struct fm10k_tx_desc);
528 u32 txint = FM10K_INT_MAP_DISABLE;
529 u32 txdctl = FM10K_TXDCTL_ENABLE | (1 << FM10K_TXDCTL_MAX_TIME_SHIFT);
530 u8 reg_idx = ring->reg_idx;
532 /* disable queue to avoid issues while updating state */
533 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), 0);
534 fm10k_write_flush(hw);
536 /* possible poll here to verify ring resources have been cleaned */
538 /* set location and size for descriptor ring */
539 fm10k_write_reg(hw, FM10K_TDBAL(reg_idx), tdba & DMA_BIT_MASK(32));
540 fm10k_write_reg(hw, FM10K_TDBAH(reg_idx), tdba >> 32);
541 fm10k_write_reg(hw, FM10K_TDLEN(reg_idx), size);
543 /* reset head and tail pointers */
544 fm10k_write_reg(hw, FM10K_TDH(reg_idx), 0);
545 fm10k_write_reg(hw, FM10K_TDT(reg_idx), 0);
547 /* store tail pointer */
548 ring->tail = &interface->uc_addr[FM10K_TDT(reg_idx)];
550 /* reset ntu and ntc to place SW in sync with hardwdare */
551 ring->next_to_clean = 0;
552 ring->next_to_use = 0;
555 if (ring->q_vector) {
556 txint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
557 txint |= FM10K_INT_MAP_TIMER0;
560 fm10k_write_reg(hw, FM10K_TXINT(reg_idx), txint);
562 /* enable use of FTAG bit in Tx descriptor, register is RO for VF */
563 fm10k_write_reg(hw, FM10K_PFVTCTL(reg_idx),
564 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
567 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), txdctl);
571 * fm10k_enable_tx_ring - Verify Tx ring is enabled after configuration
572 * @interface: board private structure
573 * @ring: structure containing ring specific data
575 * Verify the Tx descriptor ring is ready for transmit.
577 static void fm10k_enable_tx_ring(struct fm10k_intfc *interface,
578 struct fm10k_ring *ring)
580 struct fm10k_hw *hw = &interface->hw;
583 u8 reg_idx = ring->reg_idx;
585 /* if we are already enabled just exit */
586 if (fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx)) & FM10K_TXDCTL_ENABLE)
589 /* poll to verify queue is enabled */
591 usleep_range(1000, 2000);
592 txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx));
593 } while (!(txdctl & FM10K_TXDCTL_ENABLE) && --wait_loop);
595 netif_err(interface, drv, interface->netdev,
596 "Could not enable Tx Queue %d\n", reg_idx);
600 * fm10k_configure_tx - Configure Transmit Unit after Reset
601 * @interface: board private structure
603 * Configure the Tx unit of the MAC after a reset.
605 static void fm10k_configure_tx(struct fm10k_intfc *interface)
609 /* Setup the HW Tx Head and Tail descriptor pointers */
610 for (i = 0; i < interface->num_tx_queues; i++)
611 fm10k_configure_tx_ring(interface, interface->tx_ring[i]);
613 /* poll here to verify that Tx rings are now enabled */
614 for (i = 0; i < interface->num_tx_queues; i++)
615 fm10k_enable_tx_ring(interface, interface->tx_ring[i]);
619 * fm10k_configure_rx_ring - Configure Rx ring after Reset
620 * @interface: board private structure
621 * @ring: structure containing ring specific data
623 * Configure the Rx descriptor ring after a reset.
625 static void fm10k_configure_rx_ring(struct fm10k_intfc *interface,
626 struct fm10k_ring *ring)
628 u64 rdba = ring->dma;
629 struct fm10k_hw *hw = &interface->hw;
630 u32 size = ring->count * sizeof(union fm10k_rx_desc);
631 u32 rxqctl = FM10K_RXQCTL_ENABLE | FM10K_RXQCTL_PF;
632 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
633 u32 srrctl = FM10K_SRRCTL_BUFFER_CHAINING_EN;
634 u32 rxint = FM10K_INT_MAP_DISABLE;
635 u8 rx_pause = interface->rx_pause;
636 u8 reg_idx = ring->reg_idx;
638 /* disable queue to avoid issues while updating state */
639 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), 0);
640 fm10k_write_flush(hw);
642 /* possible poll here to verify ring resources have been cleaned */
644 /* set location and size for descriptor ring */
645 fm10k_write_reg(hw, FM10K_RDBAL(reg_idx), rdba & DMA_BIT_MASK(32));
646 fm10k_write_reg(hw, FM10K_RDBAH(reg_idx), rdba >> 32);
647 fm10k_write_reg(hw, FM10K_RDLEN(reg_idx), size);
649 /* reset head and tail pointers */
650 fm10k_write_reg(hw, FM10K_RDH(reg_idx), 0);
651 fm10k_write_reg(hw, FM10K_RDT(reg_idx), 0);
653 /* store tail pointer */
654 ring->tail = &interface->uc_addr[FM10K_RDT(reg_idx)];
656 /* reset ntu and ntc to place SW in sync with hardwdare */
657 ring->next_to_clean = 0;
658 ring->next_to_use = 0;
659 ring->next_to_alloc = 0;
661 /* Configure the Rx buffer size for one buff without split */
662 srrctl |= FM10K_RX_BUFSZ >> FM10K_SRRCTL_BSIZEPKT_SHIFT;
664 /* Configure the Rx ring to suppress loopback packets */
665 srrctl |= FM10K_SRRCTL_LOOPBACK_SUPPRESS;
666 fm10k_write_reg(hw, FM10K_SRRCTL(reg_idx), srrctl);
668 /* Enable drop on empty */
670 if (interface->pfc_en)
671 rx_pause = interface->pfc_en;
673 if (!(rx_pause & (1 << ring->qos_pc)))
674 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
676 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
678 /* assign default VLAN to queue */
679 ring->vid = hw->mac.default_vid;
682 if (ring->q_vector) {
683 rxint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
684 rxint |= FM10K_INT_MAP_TIMER1;
687 fm10k_write_reg(hw, FM10K_RXINT(reg_idx), rxint);
690 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), rxqctl);
692 /* place buffers on ring for receive data */
693 fm10k_alloc_rx_buffers(ring, fm10k_desc_unused(ring));
697 * fm10k_update_rx_drop_en - Configures the drop enable bits for Rx rings
698 * @interface: board private structure
700 * Configure the drop enable bits for the Rx rings.
702 void fm10k_update_rx_drop_en(struct fm10k_intfc *interface)
704 struct fm10k_hw *hw = &interface->hw;
705 u8 rx_pause = interface->rx_pause;
709 if (interface->pfc_en)
710 rx_pause = interface->pfc_en;
713 for (i = 0; i < interface->num_rx_queues; i++) {
714 struct fm10k_ring *ring = interface->rx_ring[i];
715 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
716 u8 reg_idx = ring->reg_idx;
718 if (!(rx_pause & (1 << ring->qos_pc)))
719 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
721 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
726 * fm10k_configure_dglort - Configure Receive DGLORT after reset
727 * @interface: board private structure
729 * Configure the DGLORT description and RSS tables.
731 static void fm10k_configure_dglort(struct fm10k_intfc *interface)
733 struct fm10k_dglort_cfg dglort = { 0 };
734 struct fm10k_hw *hw = &interface->hw;
738 /* Fill out hash function seeds */
739 for (i = 0; i < FM10K_RSSRK_SIZE; i++)
740 fm10k_write_reg(hw, FM10K_RSSRK(0, i), interface->rssrk[i]);
742 /* Write RETA table to hardware */
743 for (i = 0; i < FM10K_RETA_SIZE; i++)
744 fm10k_write_reg(hw, FM10K_RETA(0, i), interface->reta[i]);
746 /* Generate RSS hash based on packet types, TCP/UDP
747 * port numbers and/or IPv4/v6 src and dst addresses
749 mrqc = FM10K_MRQC_IPV4 |
750 FM10K_MRQC_TCP_IPV4 |
754 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
755 mrqc |= FM10K_MRQC_UDP_IPV4;
756 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
757 mrqc |= FM10K_MRQC_UDP_IPV6;
759 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
761 /* configure default DGLORT mapping for RSS/DCB */
762 dglort.inner_rss = 1;
763 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
764 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
765 hw->mac.ops.configure_dglort_map(hw, &dglort);
767 /* assign GLORT per queue for queue mapped testing */
768 if (interface->glort_count > 64) {
769 memset(&dglort, 0, sizeof(dglort));
770 dglort.inner_rss = 1;
771 dglort.glort = interface->glort + 64;
772 dglort.idx = fm10k_dglort_pf_queue;
773 dglort.queue_l = fls(interface->num_rx_queues - 1);
774 hw->mac.ops.configure_dglort_map(hw, &dglort);
777 /* assign glort value for RSS/DCB specific to this interface */
778 memset(&dglort, 0, sizeof(dglort));
779 dglort.inner_rss = 1;
780 dglort.glort = interface->glort;
781 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
782 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
783 /* configure DGLORT mapping for RSS/DCB */
784 dglort.idx = fm10k_dglort_pf_rss;
785 if (interface->l2_accel)
786 dglort.shared_l = fls(interface->l2_accel->size);
787 hw->mac.ops.configure_dglort_map(hw, &dglort);
791 * fm10k_configure_rx - Configure Receive Unit after Reset
792 * @interface: board private structure
794 * Configure the Rx unit of the MAC after a reset.
796 static void fm10k_configure_rx(struct fm10k_intfc *interface)
800 /* Configure SWPRI to PC map */
801 fm10k_configure_swpri_map(interface);
803 /* Configure RSS and DGLORT map */
804 fm10k_configure_dglort(interface);
806 /* Setup the HW Rx Head and Tail descriptor pointers */
807 for (i = 0; i < interface->num_rx_queues; i++)
808 fm10k_configure_rx_ring(interface, interface->rx_ring[i]);
810 /* possible poll here to verify that Rx rings are now enabled */
813 static void fm10k_napi_enable_all(struct fm10k_intfc *interface)
815 struct fm10k_q_vector *q_vector;
818 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
819 q_vector = interface->q_vector[q_idx];
820 napi_enable(&q_vector->napi);
824 static irqreturn_t fm10k_msix_clean_rings(int __always_unused irq, void *data)
826 struct fm10k_q_vector *q_vector = data;
828 if (q_vector->rx.count || q_vector->tx.count)
829 napi_schedule(&q_vector->napi);
834 static irqreturn_t fm10k_msix_mbx_vf(int __always_unused irq, void *data)
836 struct fm10k_intfc *interface = data;
837 struct fm10k_hw *hw = &interface->hw;
838 struct fm10k_mbx_info *mbx = &hw->mbx;
840 /* re-enable mailbox interrupt and indicate 20us delay */
841 fm10k_write_reg(hw, FM10K_VFITR(FM10K_MBX_VECTOR),
842 FM10K_ITR_ENABLE | FM10K_MBX_INT_DELAY);
844 /* service upstream mailbox */
845 if (fm10k_mbx_trylock(interface)) {
846 mbx->ops.process(hw, mbx);
847 fm10k_mbx_unlock(interface);
850 hw->mac.get_host_state = 1;
851 fm10k_service_event_schedule(interface);
856 #ifdef CONFIG_NET_POLL_CONTROLLER
858 * fm10k_netpoll - A Polling 'interrupt' handler
859 * @netdev: network interface device structure
861 * This is used by netconsole to send skbs without having to re-enable
862 * interrupts. It's not called while the normal interrupt routine is executing.
864 void fm10k_netpoll(struct net_device *netdev)
866 struct fm10k_intfc *interface = netdev_priv(netdev);
869 /* if interface is down do nothing */
870 if (test_bit(__FM10K_DOWN, &interface->state))
873 for (i = 0; i < interface->num_q_vectors; i++)
874 fm10k_msix_clean_rings(0, interface->q_vector[i]);
878 #define FM10K_ERR_MSG(type) case (type): error = #type; break
879 static void fm10k_print_fault(struct fm10k_intfc *interface, int type,
880 struct fm10k_fault *fault)
882 struct pci_dev *pdev = interface->pdev;
886 case FM10K_PCA_FAULT:
887 switch (fault->type) {
889 error = "Unknown PCA error";
891 FM10K_ERR_MSG(PCA_NO_FAULT);
892 FM10K_ERR_MSG(PCA_UNMAPPED_ADDR);
893 FM10K_ERR_MSG(PCA_BAD_QACCESS_PF);
894 FM10K_ERR_MSG(PCA_BAD_QACCESS_VF);
895 FM10K_ERR_MSG(PCA_MALICIOUS_REQ);
896 FM10K_ERR_MSG(PCA_POISONED_TLP);
897 FM10K_ERR_MSG(PCA_TLP_ABORT);
900 case FM10K_THI_FAULT:
901 switch (fault->type) {
903 error = "Unknown THI error";
905 FM10K_ERR_MSG(THI_NO_FAULT);
906 FM10K_ERR_MSG(THI_MAL_DIS_Q_FAULT);
909 case FM10K_FUM_FAULT:
910 switch (fault->type) {
912 error = "Unknown FUM error";
914 FM10K_ERR_MSG(FUM_NO_FAULT);
915 FM10K_ERR_MSG(FUM_UNMAPPED_ADDR);
916 FM10K_ERR_MSG(FUM_BAD_VF_QACCESS);
917 FM10K_ERR_MSG(FUM_ADD_DECODE_ERR);
918 FM10K_ERR_MSG(FUM_RO_ERROR);
919 FM10K_ERR_MSG(FUM_QPRC_CRC_ERROR);
920 FM10K_ERR_MSG(FUM_CSR_TIMEOUT);
921 FM10K_ERR_MSG(FUM_INVALID_TYPE);
922 FM10K_ERR_MSG(FUM_INVALID_LENGTH);
923 FM10K_ERR_MSG(FUM_INVALID_BE);
924 FM10K_ERR_MSG(FUM_INVALID_ALIGN);
928 error = "Undocumented fault";
933 "%s Address: 0x%llx SpecInfo: 0x%x Func: %02x.%0x\n",
934 error, fault->address, fault->specinfo,
935 PCI_SLOT(fault->func), PCI_FUNC(fault->func));
938 static void fm10k_report_fault(struct fm10k_intfc *interface, u32 eicr)
940 struct fm10k_hw *hw = &interface->hw;
941 struct fm10k_fault fault = { 0 };
944 for (eicr &= FM10K_EICR_FAULT_MASK, type = FM10K_PCA_FAULT;
946 eicr >>= 1, type += FM10K_FAULT_SIZE) {
947 /* only check if there is an error reported */
951 /* retrieve fault info */
952 err = hw->mac.ops.get_fault(hw, type, &fault);
954 dev_err(&interface->pdev->dev,
955 "error reading fault\n");
959 fm10k_print_fault(interface, type, &fault);
963 static void fm10k_reset_drop_on_empty(struct fm10k_intfc *interface, u32 eicr)
965 struct fm10k_hw *hw = &interface->hw;
966 const u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
970 if (!(eicr & FM10K_EICR_MAXHOLDTIME))
973 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(7));
975 fm10k_write_reg(hw, FM10K_MAXHOLDQ(7), maxholdq);
977 if (maxholdq & (1 << 31)) {
978 if (q < FM10K_MAX_QUEUES_PF) {
979 interface->rx_overrun_pf++;
980 fm10k_write_reg(hw, FM10K_RXDCTL(q), rxdctl);
982 interface->rx_overrun_vf++;
996 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(q / 32));
998 fm10k_write_reg(hw, FM10K_MAXHOLDQ(q / 32), maxholdq);
1002 static irqreturn_t fm10k_msix_mbx_pf(int __always_unused irq, void *data)
1004 struct fm10k_intfc *interface = data;
1005 struct fm10k_hw *hw = &interface->hw;
1006 struct fm10k_mbx_info *mbx = &hw->mbx;
1009 /* unmask any set bits related to this interrupt */
1010 eicr = fm10k_read_reg(hw, FM10K_EICR);
1011 fm10k_write_reg(hw, FM10K_EICR, eicr & (FM10K_EICR_MAILBOX |
1012 FM10K_EICR_SWITCHREADY |
1013 FM10K_EICR_SWITCHNOTREADY));
1015 /* report any faults found to the message log */
1016 fm10k_report_fault(interface, eicr);
1018 /* reset any queues disabled due to receiver overrun */
1019 fm10k_reset_drop_on_empty(interface, eicr);
1021 /* service mailboxes */
1022 if (fm10k_mbx_trylock(interface)) {
1023 mbx->ops.process(hw, mbx);
1024 /* handle VFLRE events */
1025 fm10k_iov_event(interface);
1026 fm10k_mbx_unlock(interface);
1029 /* if switch toggled state we should reset GLORTs */
1030 if (eicr & FM10K_EICR_SWITCHNOTREADY) {
1031 /* force link down for at least 4 seconds */
1032 interface->link_down_event = jiffies + (4 * HZ);
1033 set_bit(__FM10K_LINK_DOWN, &interface->state);
1035 /* reset dglort_map back to no config */
1036 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
1039 /* we should validate host state after interrupt event */
1040 hw->mac.get_host_state = 1;
1042 /* validate host state, and handle VF mailboxes in the service task */
1043 fm10k_service_event_schedule(interface);
1045 /* re-enable mailbox interrupt and indicate 20us delay */
1046 fm10k_write_reg(hw, FM10K_ITR(FM10K_MBX_VECTOR),
1047 FM10K_ITR_ENABLE | FM10K_MBX_INT_DELAY);
1052 void fm10k_mbx_free_irq(struct fm10k_intfc *interface)
1054 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1055 struct fm10k_hw *hw = &interface->hw;
1058 /* disconnect the mailbox */
1059 hw->mbx.ops.disconnect(hw, &hw->mbx);
1061 /* disable Mailbox cause */
1062 if (hw->mac.type == fm10k_mac_pf) {
1063 fm10k_write_reg(hw, FM10K_EIMR,
1064 FM10K_EIMR_DISABLE(PCA_FAULT) |
1065 FM10K_EIMR_DISABLE(FUM_FAULT) |
1066 FM10K_EIMR_DISABLE(MAILBOX) |
1067 FM10K_EIMR_DISABLE(SWITCHREADY) |
1068 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
1069 FM10K_EIMR_DISABLE(SRAMERROR) |
1070 FM10K_EIMR_DISABLE(VFLR) |
1071 FM10K_EIMR_DISABLE(MAXHOLDTIME));
1072 itr_reg = FM10K_ITR(FM10K_MBX_VECTOR);
1074 itr_reg = FM10K_VFITR(FM10K_MBX_VECTOR);
1077 fm10k_write_reg(hw, itr_reg, FM10K_ITR_MASK_SET);
1079 free_irq(entry->vector, interface);
1082 static s32 fm10k_mbx_mac_addr(struct fm10k_hw *hw, u32 **results,
1083 struct fm10k_mbx_info *mbx)
1085 bool vlan_override = hw->mac.vlan_override;
1086 u16 default_vid = hw->mac.default_vid;
1087 struct fm10k_intfc *interface;
1090 err = fm10k_msg_mac_vlan_vf(hw, results, mbx);
1094 interface = container_of(hw, struct fm10k_intfc, hw);
1096 /* MAC was changed so we need reset */
1097 if (is_valid_ether_addr(hw->mac.perm_addr) &&
1098 memcmp(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN))
1099 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1101 /* VLAN override was changed, or default VLAN changed */
1102 if ((vlan_override != hw->mac.vlan_override) ||
1103 (default_vid != hw->mac.default_vid))
1104 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1109 static s32 fm10k_1588_msg_vf(struct fm10k_hw *hw, u32 **results,
1110 struct fm10k_mbx_info __always_unused *mbx)
1112 struct fm10k_intfc *interface;
1116 err = fm10k_tlv_attr_get_u64(results[FM10K_1588_MSG_TIMESTAMP],
1121 interface = container_of(hw, struct fm10k_intfc, hw);
1123 fm10k_ts_tx_hwtstamp(interface, 0, timestamp);
1128 /* generic error handler for mailbox issues */
1129 static s32 fm10k_mbx_error(struct fm10k_hw *hw, u32 **results,
1130 struct fm10k_mbx_info __always_unused *mbx)
1132 struct fm10k_intfc *interface;
1133 struct pci_dev *pdev;
1135 interface = container_of(hw, struct fm10k_intfc, hw);
1136 pdev = interface->pdev;
1138 dev_err(&pdev->dev, "Unknown message ID %u\n",
1139 **results & FM10K_TLV_ID_MASK);
1144 static const struct fm10k_msg_data vf_mbx_data[] = {
1145 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
1146 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_mbx_mac_addr),
1147 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
1148 FM10K_VF_MSG_1588_HANDLER(fm10k_1588_msg_vf),
1149 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_mbx_error),
1152 static int fm10k_mbx_request_irq_vf(struct fm10k_intfc *interface)
1154 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1155 struct net_device *dev = interface->netdev;
1156 struct fm10k_hw *hw = &interface->hw;
1159 /* Use timer0 for interrupt moderation on the mailbox */
1160 u32 itr = FM10K_INT_MAP_TIMER0 | entry->entry;
1162 /* register mailbox handlers */
1163 err = hw->mbx.ops.register_handlers(&hw->mbx, vf_mbx_data);
1167 /* request the IRQ */
1168 err = request_irq(entry->vector, fm10k_msix_mbx_vf, 0,
1169 dev->name, interface);
1171 netif_err(interface, probe, dev,
1172 "request_irq for msix_mbx failed: %d\n", err);
1176 /* map all of the interrupt sources */
1177 fm10k_write_reg(hw, FM10K_VFINT_MAP, itr);
1179 /* enable interrupt */
1180 fm10k_write_reg(hw, FM10K_VFITR(entry->entry), FM10K_ITR_ENABLE);
1185 static s32 fm10k_lport_map(struct fm10k_hw *hw, u32 **results,
1186 struct fm10k_mbx_info *mbx)
1188 struct fm10k_intfc *interface;
1189 u32 dglort_map = hw->mac.dglort_map;
1192 err = fm10k_msg_lport_map_pf(hw, results, mbx);
1196 interface = container_of(hw, struct fm10k_intfc, hw);
1198 /* we need to reset if port count was just updated */
1199 if (dglort_map != hw->mac.dglort_map)
1200 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1205 static s32 fm10k_update_pvid(struct fm10k_hw *hw, u32 **results,
1206 struct fm10k_mbx_info __always_unused *mbx)
1208 struct fm10k_intfc *interface;
1213 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1218 /* extract values from the pvid update */
1219 glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1220 pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1222 /* if glort is not valid return error */
1223 if (!fm10k_glort_valid_pf(hw, glort))
1224 return FM10K_ERR_PARAM;
1226 /* verify VID is valid */
1227 if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1228 return FM10K_ERR_PARAM;
1230 interface = container_of(hw, struct fm10k_intfc, hw);
1232 /* check to see if this belongs to one of the VFs */
1233 err = fm10k_iov_update_pvid(interface, glort, pvid);
1237 /* we need to reset if default VLAN was just updated */
1238 if (pvid != hw->mac.default_vid)
1239 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1241 hw->mac.default_vid = pvid;
1246 static s32 fm10k_1588_msg_pf(struct fm10k_hw *hw, u32 **results,
1247 struct fm10k_mbx_info __always_unused *mbx)
1249 struct fm10k_swapi_1588_timestamp timestamp;
1250 struct fm10k_iov_data *iov_data;
1251 struct fm10k_intfc *interface;
1255 err = fm10k_tlv_attr_get_le_struct(
1256 results[FM10K_PF_ATTR_ID_1588_TIMESTAMP],
1257 ×tamp, sizeof(timestamp));
1261 interface = container_of(hw, struct fm10k_intfc, hw);
1263 if (timestamp.dglort) {
1264 fm10k_ts_tx_hwtstamp(interface, timestamp.dglort,
1265 le64_to_cpu(timestamp.egress));
1269 /* either dglort or sglort must be set */
1270 if (!timestamp.sglort)
1271 return FM10K_ERR_PARAM;
1273 /* verify GLORT is at least one of the ones we own */
1274 sglort = le16_to_cpu(timestamp.sglort);
1275 if (!fm10k_glort_valid_pf(hw, sglort))
1276 return FM10K_ERR_PARAM;
1278 if (sglort == interface->glort) {
1279 fm10k_ts_tx_hwtstamp(interface, 0,
1280 le64_to_cpu(timestamp.ingress));
1284 /* if there is no iov_data then there is no mailboxes to process */
1285 if (!ACCESS_ONCE(interface->iov_data))
1286 return FM10K_ERR_PARAM;
1290 /* notify VF if this timestamp belongs to it */
1291 iov_data = interface->iov_data;
1292 vf_idx = (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE) - sglort;
1294 if (!iov_data || vf_idx >= iov_data->num_vfs) {
1295 err = FM10K_ERR_PARAM;
1299 err = hw->iov.ops.report_timestamp(hw, &iov_data->vf_info[vf_idx],
1300 le64_to_cpu(timestamp.ingress));
1308 static const struct fm10k_msg_data pf_mbx_data[] = {
1309 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1310 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1311 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_lport_map),
1312 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1313 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1314 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_update_pvid),
1315 FM10K_PF_MSG_1588_TIMESTAMP_HANDLER(fm10k_1588_msg_pf),
1316 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_mbx_error),
1319 static int fm10k_mbx_request_irq_pf(struct fm10k_intfc *interface)
1321 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1322 struct net_device *dev = interface->netdev;
1323 struct fm10k_hw *hw = &interface->hw;
1326 /* Use timer0 for interrupt moderation on the mailbox */
1327 u32 mbx_itr = FM10K_INT_MAP_TIMER0 | entry->entry;
1328 u32 other_itr = FM10K_INT_MAP_IMMEDIATE | entry->entry;
1330 /* register mailbox handlers */
1331 err = hw->mbx.ops.register_handlers(&hw->mbx, pf_mbx_data);
1335 /* request the IRQ */
1336 err = request_irq(entry->vector, fm10k_msix_mbx_pf, 0,
1337 dev->name, interface);
1339 netif_err(interface, probe, dev,
1340 "request_irq for msix_mbx failed: %d\n", err);
1344 /* Enable interrupts w/ no moderation for "other" interrupts */
1345 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), other_itr);
1346 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), other_itr);
1347 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SRAM), other_itr);
1348 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_MaxHoldTime), other_itr);
1349 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_VFLR), other_itr);
1351 /* Enable interrupts w/ moderation for mailbox */
1352 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_Mailbox), mbx_itr);
1354 /* Enable individual interrupt causes */
1355 fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
1356 FM10K_EIMR_ENABLE(FUM_FAULT) |
1357 FM10K_EIMR_ENABLE(MAILBOX) |
1358 FM10K_EIMR_ENABLE(SWITCHREADY) |
1359 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
1360 FM10K_EIMR_ENABLE(SRAMERROR) |
1361 FM10K_EIMR_ENABLE(VFLR) |
1362 FM10K_EIMR_ENABLE(MAXHOLDTIME));
1364 /* enable interrupt */
1365 fm10k_write_reg(hw, FM10K_ITR(entry->entry), FM10K_ITR_ENABLE);
1370 int fm10k_mbx_request_irq(struct fm10k_intfc *interface)
1372 struct fm10k_hw *hw = &interface->hw;
1375 /* enable Mailbox cause */
1376 if (hw->mac.type == fm10k_mac_pf)
1377 err = fm10k_mbx_request_irq_pf(interface);
1379 err = fm10k_mbx_request_irq_vf(interface);
1381 /* connect mailbox */
1383 err = hw->mbx.ops.connect(hw, &hw->mbx);
1389 * fm10k_qv_free_irq - release interrupts associated with queue vectors
1390 * @interface: board private structure
1392 * Release all interrupts associated with this interface
1394 void fm10k_qv_free_irq(struct fm10k_intfc *interface)
1396 int vector = interface->num_q_vectors;
1397 struct fm10k_hw *hw = &interface->hw;
1398 struct msix_entry *entry;
1400 entry = &interface->msix_entries[NON_Q_VECTORS(hw) + vector];
1403 struct fm10k_q_vector *q_vector;
1407 q_vector = interface->q_vector[vector];
1409 if (!q_vector->tx.count && !q_vector->rx.count)
1412 /* disable interrupts */
1414 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1416 free_irq(entry->vector, q_vector);
1421 * fm10k_qv_request_irq - initialize interrupts for queue vectors
1422 * @interface: board private structure
1424 * Attempts to configure interrupts using the best available
1425 * capabilities of the hardware and kernel.
1427 int fm10k_qv_request_irq(struct fm10k_intfc *interface)
1429 struct net_device *dev = interface->netdev;
1430 struct fm10k_hw *hw = &interface->hw;
1431 struct msix_entry *entry;
1435 entry = &interface->msix_entries[NON_Q_VECTORS(hw)];
1437 for (vector = 0; vector < interface->num_q_vectors; vector++) {
1438 struct fm10k_q_vector *q_vector = interface->q_vector[vector];
1440 /* name the vector */
1441 if (q_vector->tx.count && q_vector->rx.count) {
1442 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1443 "%s-TxRx-%d", dev->name, ri++);
1445 } else if (q_vector->rx.count) {
1446 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1447 "%s-rx-%d", dev->name, ri++);
1448 } else if (q_vector->tx.count) {
1449 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1450 "%s-tx-%d", dev->name, ti++);
1452 /* skip this unused q_vector */
1456 /* Assign ITR register to q_vector */
1457 q_vector->itr = (hw->mac.type == fm10k_mac_pf) ?
1458 &interface->uc_addr[FM10K_ITR(entry->entry)] :
1459 &interface->uc_addr[FM10K_VFITR(entry->entry)];
1461 /* request the IRQ */
1462 err = request_irq(entry->vector, &fm10k_msix_clean_rings, 0,
1463 q_vector->name, q_vector);
1465 netif_err(interface, probe, dev,
1466 "request_irq failed for MSIX interrupt Error: %d\n",
1471 /* Enable q_vector */
1472 writel(FM10K_ITR_ENABLE, q_vector->itr);
1480 /* wind through the ring freeing all entries and vectors */
1482 struct fm10k_q_vector *q_vector;
1486 q_vector = interface->q_vector[vector];
1488 if (!q_vector->tx.count && !q_vector->rx.count)
1491 /* disable interrupts */
1493 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1495 free_irq(entry->vector, q_vector);
1501 void fm10k_up(struct fm10k_intfc *interface)
1503 struct fm10k_hw *hw = &interface->hw;
1505 /* Enable Tx/Rx DMA */
1506 hw->mac.ops.start_hw(hw);
1508 /* configure Tx descriptor rings */
1509 fm10k_configure_tx(interface);
1511 /* configure Rx descriptor rings */
1512 fm10k_configure_rx(interface);
1514 /* configure interrupts */
1515 hw->mac.ops.update_int_moderator(hw);
1517 /* clear down bit to indicate we are ready to go */
1518 clear_bit(__FM10K_DOWN, &interface->state);
1520 /* enable polling cleanups */
1521 fm10k_napi_enable_all(interface);
1523 /* re-establish Rx filters */
1524 fm10k_restore_rx_state(interface);
1526 /* enable transmits */
1527 netif_tx_start_all_queues(interface->netdev);
1529 /* kick off the service timer now */
1530 hw->mac.get_host_state = 1;
1531 mod_timer(&interface->service_timer, jiffies);
1534 static void fm10k_napi_disable_all(struct fm10k_intfc *interface)
1536 struct fm10k_q_vector *q_vector;
1539 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
1540 q_vector = interface->q_vector[q_idx];
1541 napi_disable(&q_vector->napi);
1545 void fm10k_down(struct fm10k_intfc *interface)
1547 struct net_device *netdev = interface->netdev;
1548 struct fm10k_hw *hw = &interface->hw;
1550 /* signal that we are down to the interrupt handler and service task */
1551 set_bit(__FM10K_DOWN, &interface->state);
1553 /* call carrier off first to avoid false dev_watchdog timeouts */
1554 netif_carrier_off(netdev);
1556 /* disable transmits */
1557 netif_tx_stop_all_queues(netdev);
1558 netif_tx_disable(netdev);
1560 /* reset Rx filters */
1561 fm10k_reset_rx_state(interface);
1563 /* allow 10ms for device to quiesce */
1564 usleep_range(10000, 20000);
1566 /* disable polling routines */
1567 fm10k_napi_disable_all(interface);
1569 /* capture stats one last time before stopping interface */
1570 fm10k_update_stats(interface);
1572 /* Disable DMA engine for Tx/Rx */
1573 hw->mac.ops.stop_hw(hw);
1575 /* free any buffers still on the rings */
1576 fm10k_clean_all_tx_rings(interface);
1577 fm10k_clean_all_rx_rings(interface);
1581 * fm10k_sw_init - Initialize general software structures
1582 * @interface: host interface private structure to initialize
1584 * fm10k_sw_init initializes the interface private data structure.
1585 * Fields are initialized based on PCI device information and
1586 * OS network device settings (MTU size).
1588 static int fm10k_sw_init(struct fm10k_intfc *interface,
1589 const struct pci_device_id *ent)
1591 const struct fm10k_info *fi = fm10k_info_tbl[ent->driver_data];
1592 struct fm10k_hw *hw = &interface->hw;
1593 struct pci_dev *pdev = interface->pdev;
1594 struct net_device *netdev = interface->netdev;
1595 u32 rss_key[FM10K_RSSRK_SIZE];
1599 /* initialize back pointer */
1600 hw->back = interface;
1601 hw->hw_addr = interface->uc_addr;
1603 /* PCI config space info */
1604 hw->vendor_id = pdev->vendor;
1605 hw->device_id = pdev->device;
1606 hw->revision_id = pdev->revision;
1607 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1608 hw->subsystem_device_id = pdev->subsystem_device;
1611 memcpy(&hw->mac.ops, fi->mac_ops, sizeof(hw->mac.ops));
1612 hw->mac.type = fi->mac;
1614 /* Setup IOV handlers */
1616 memcpy(&hw->iov.ops, fi->iov_ops, sizeof(hw->iov.ops));
1618 /* Set common capability flags and settings */
1619 rss = min_t(int, FM10K_MAX_RSS_INDICES, num_online_cpus());
1620 interface->ring_feature[RING_F_RSS].limit = rss;
1621 fi->get_invariants(hw);
1623 /* pick up the PCIe bus settings for reporting later */
1624 if (hw->mac.ops.get_bus_info)
1625 hw->mac.ops.get_bus_info(hw);
1627 /* limit the usable DMA range */
1628 if (hw->mac.ops.set_dma_mask)
1629 hw->mac.ops.set_dma_mask(hw, dma_get_mask(&pdev->dev));
1631 /* update netdev with DMA restrictions */
1632 if (dma_get_mask(&pdev->dev) > DMA_BIT_MASK(32)) {
1633 netdev->features |= NETIF_F_HIGHDMA;
1634 netdev->vlan_features |= NETIF_F_HIGHDMA;
1637 /* delay any future reset requests */
1638 interface->last_reset = jiffies + (10 * HZ);
1640 /* reset and initialize the hardware so it is in a known state */
1641 err = hw->mac.ops.reset_hw(hw) ? : hw->mac.ops.init_hw(hw);
1643 dev_err(&pdev->dev, "init_hw failed: %d\n", err);
1647 /* initialize hardware statistics */
1648 hw->mac.ops.update_hw_stats(hw, &interface->stats);
1650 /* Set upper limit on IOV VFs that can be allocated */
1651 pci_sriov_set_totalvfs(pdev, hw->iov.total_vfs);
1653 /* Start with random Ethernet address */
1654 eth_random_addr(hw->mac.addr);
1656 /* Initialize MAC address from hardware */
1657 err = hw->mac.ops.read_mac_addr(hw);
1659 dev_warn(&pdev->dev,
1660 "Failed to obtain MAC address defaulting to random\n");
1661 /* tag address assignment as random */
1662 netdev->addr_assign_type |= NET_ADDR_RANDOM;
1665 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1666 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1668 if (!is_valid_ether_addr(netdev->perm_addr)) {
1669 dev_err(&pdev->dev, "Invalid MAC Address\n");
1673 /* assign BAR 4 resources for use with PTP */
1674 if (fm10k_read_reg(hw, FM10K_CTRL) & FM10K_CTRL_BAR4_ALLOWED)
1675 interface->sw_addr = ioremap(pci_resource_start(pdev, 4),
1676 pci_resource_len(pdev, 4));
1677 hw->sw_addr = interface->sw_addr;
1679 /* Only the PF can support VXLAN and NVGRE offloads */
1680 if (hw->mac.type != fm10k_mac_pf) {
1681 netdev->hw_enc_features = 0;
1682 netdev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
1683 netdev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
1686 /* initialize DCBNL interface */
1687 fm10k_dcbnl_set_ops(netdev);
1689 /* Initialize service timer and service task */
1690 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1691 setup_timer(&interface->service_timer, &fm10k_service_timer,
1692 (unsigned long)interface);
1693 INIT_WORK(&interface->service_task, fm10k_service_task);
1695 /* kick off service timer now, even when interface is down */
1696 mod_timer(&interface->service_timer, (HZ * 2) + jiffies);
1698 /* Intitialize timestamp data */
1699 fm10k_ts_init(interface);
1701 /* set default ring sizes */
1702 interface->tx_ring_count = FM10K_DEFAULT_TXD;
1703 interface->rx_ring_count = FM10K_DEFAULT_RXD;
1705 /* set default interrupt moderation */
1706 interface->tx_itr = FM10K_ITR_10K;
1707 interface->rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
1709 /* initialize vxlan_port list */
1710 INIT_LIST_HEAD(&interface->vxlan_port);
1712 netdev_rss_key_fill(rss_key, sizeof(rss_key));
1713 memcpy(interface->rssrk, rss_key, sizeof(rss_key));
1715 /* Start off interface as being down */
1716 set_bit(__FM10K_DOWN, &interface->state);
1721 static void fm10k_slot_warn(struct fm10k_intfc *interface)
1723 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
1724 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
1725 struct fm10k_hw *hw = &interface->hw;
1726 int max_gts = 0, expected_gts = 0;
1728 if (pcie_get_minimum_link(interface->pdev, &speed, &width) ||
1729 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
1730 dev_warn(&interface->pdev->dev,
1731 "Unable to determine PCI Express bandwidth.\n");
1736 case PCIE_SPEED_2_5GT:
1737 /* 8b/10b encoding reduces max throughput by 20% */
1738 max_gts = 2 * width;
1740 case PCIE_SPEED_5_0GT:
1741 /* 8b/10b encoding reduces max throughput by 20% */
1742 max_gts = 4 * width;
1744 case PCIE_SPEED_8_0GT:
1745 /* 128b/130b encoding has less than 2% impact on throughput */
1746 max_gts = 8 * width;
1749 dev_warn(&interface->pdev->dev,
1750 "Unable to determine PCI Express bandwidth.\n");
1754 dev_info(&interface->pdev->dev,
1755 "PCI Express bandwidth of %dGT/s available\n",
1757 dev_info(&interface->pdev->dev,
1758 "(Speed:%s, Width: x%d, Encoding Loss:%s, Payload:%s)\n",
1759 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
1760 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
1761 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
1764 (speed == PCIE_SPEED_2_5GT ? "20%" :
1765 speed == PCIE_SPEED_5_0GT ? "20%" :
1766 speed == PCIE_SPEED_8_0GT ? "<2%" :
1768 (hw->bus.payload == fm10k_bus_payload_128 ? "128B" :
1769 hw->bus.payload == fm10k_bus_payload_256 ? "256B" :
1770 hw->bus.payload == fm10k_bus_payload_512 ? "512B" :
1773 switch (hw->bus_caps.speed) {
1774 case fm10k_bus_speed_2500:
1775 /* 8b/10b encoding reduces max throughput by 20% */
1776 expected_gts = 2 * hw->bus_caps.width;
1778 case fm10k_bus_speed_5000:
1779 /* 8b/10b encoding reduces max throughput by 20% */
1780 expected_gts = 4 * hw->bus_caps.width;
1782 case fm10k_bus_speed_8000:
1783 /* 128b/130b encoding has less than 2% impact on throughput */
1784 expected_gts = 8 * hw->bus_caps.width;
1787 dev_warn(&interface->pdev->dev,
1788 "Unable to determine expected PCI Express bandwidth.\n");
1792 if (max_gts < expected_gts) {
1793 dev_warn(&interface->pdev->dev,
1794 "This device requires %dGT/s of bandwidth for optimal performance.\n",
1796 dev_warn(&interface->pdev->dev,
1797 "A %sslot with x%d lanes is suggested.\n",
1798 (hw->bus_caps.speed == fm10k_bus_speed_2500 ? "2.5GT/s " :
1799 hw->bus_caps.speed == fm10k_bus_speed_5000 ? "5.0GT/s " :
1800 hw->bus_caps.speed == fm10k_bus_speed_8000 ? "8.0GT/s " : ""),
1801 hw->bus_caps.width);
1806 * fm10k_probe - Device Initialization Routine
1807 * @pdev: PCI device information struct
1808 * @ent: entry in fm10k_pci_tbl
1810 * Returns 0 on success, negative on failure
1812 * fm10k_probe initializes an interface identified by a pci_dev structure.
1813 * The OS initialization, configuring of the interface private structure,
1814 * and a hardware reset occur.
1816 static int fm10k_probe(struct pci_dev *pdev,
1817 const struct pci_device_id *ent)
1819 struct net_device *netdev;
1820 struct fm10k_intfc *interface;
1823 err = pci_enable_device_mem(pdev);
1827 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
1829 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1832 "DMA configuration failed: %d\n", err);
1836 err = pci_request_selected_regions(pdev,
1837 pci_select_bars(pdev,
1842 "pci_request_selected_regions failed: %d\n", err);
1846 pci_enable_pcie_error_reporting(pdev);
1848 pci_set_master(pdev);
1849 pci_save_state(pdev);
1851 netdev = fm10k_alloc_netdev();
1854 goto err_alloc_netdev;
1857 SET_NETDEV_DEV(netdev, &pdev->dev);
1859 interface = netdev_priv(netdev);
1860 pci_set_drvdata(pdev, interface);
1862 interface->netdev = netdev;
1863 interface->pdev = pdev;
1865 interface->uc_addr = ioremap(pci_resource_start(pdev, 0),
1866 FM10K_UC_ADDR_SIZE);
1867 if (!interface->uc_addr) {
1872 err = fm10k_sw_init(interface, ent);
1876 /* enable debugfs support */
1877 fm10k_dbg_intfc_init(interface);
1879 err = fm10k_init_queueing_scheme(interface);
1883 err = fm10k_mbx_request_irq(interface);
1885 goto err_mbx_interrupt;
1887 /* final check of hardware state before registering the interface */
1888 err = fm10k_hw_ready(interface);
1892 err = register_netdev(netdev);
1896 /* carrier off reporting is important to ethtool even BEFORE open */
1897 netif_carrier_off(netdev);
1899 /* stop all the transmit queues from transmitting until link is up */
1900 netif_tx_stop_all_queues(netdev);
1902 /* Register PTP interface */
1903 fm10k_ptp_register(interface);
1905 /* print warning for non-optimal configurations */
1906 fm10k_slot_warn(interface);
1908 /* enable SR-IOV after registering netdev to enforce PF/VF ordering */
1909 fm10k_iov_configure(pdev, 0);
1911 /* clear the service task disable bit to allow service task to start */
1912 clear_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1917 fm10k_mbx_free_irq(interface);
1919 fm10k_clear_queueing_scheme(interface);
1921 if (interface->sw_addr)
1922 iounmap(interface->sw_addr);
1923 iounmap(interface->uc_addr);
1925 free_netdev(netdev);
1927 pci_release_selected_regions(pdev,
1928 pci_select_bars(pdev, IORESOURCE_MEM));
1931 pci_disable_device(pdev);
1936 * fm10k_remove - Device Removal Routine
1937 * @pdev: PCI device information struct
1939 * fm10k_remove is called by the PCI subsystem to alert the driver
1940 * that it should release a PCI device. The could be caused by a
1941 * Hot-Plug event, or because the driver is going to be removed from
1944 static void fm10k_remove(struct pci_dev *pdev)
1946 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1947 struct net_device *netdev = interface->netdev;
1949 del_timer_sync(&interface->service_timer);
1951 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1952 cancel_work_sync(&interface->service_task);
1954 /* free netdev, this may bounce the interrupts due to setup_tc */
1955 if (netdev->reg_state == NETREG_REGISTERED)
1956 unregister_netdev(netdev);
1958 /* cleanup timestamp handling */
1959 fm10k_ptp_unregister(interface);
1962 fm10k_iov_disable(pdev);
1964 /* disable mailbox interrupt */
1965 fm10k_mbx_free_irq(interface);
1967 /* free interrupts */
1968 fm10k_clear_queueing_scheme(interface);
1970 /* remove any debugfs interfaces */
1971 fm10k_dbg_intfc_exit(interface);
1973 if (interface->sw_addr)
1974 iounmap(interface->sw_addr);
1975 iounmap(interface->uc_addr);
1977 free_netdev(netdev);
1979 pci_release_selected_regions(pdev,
1980 pci_select_bars(pdev, IORESOURCE_MEM));
1982 pci_disable_pcie_error_reporting(pdev);
1984 pci_disable_device(pdev);
1989 * fm10k_resume - Restore device to pre-sleep state
1990 * @pdev: PCI device information struct
1992 * fm10k_resume is called after the system has powered back up from a sleep
1993 * state and is ready to resume operation. This function is meant to restore
1994 * the device back to its pre-sleep state.
1996 static int fm10k_resume(struct pci_dev *pdev)
1998 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1999 struct net_device *netdev = interface->netdev;
2000 struct fm10k_hw *hw = &interface->hw;
2003 pci_set_power_state(pdev, PCI_D0);
2004 pci_restore_state(pdev);
2006 /* pci_restore_state clears dev->state_saved so call
2007 * pci_save_state to restore it.
2009 pci_save_state(pdev);
2011 err = pci_enable_device_mem(pdev);
2013 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
2016 pci_set_master(pdev);
2018 pci_wake_from_d3(pdev, false);
2020 /* refresh hw_addr in case it was dropped */
2021 hw->hw_addr = interface->uc_addr;
2023 /* reset hardware to known state */
2024 err = hw->mac.ops.init_hw(&interface->hw);
2028 /* reset statistics starting values */
2029 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
2032 fm10k_ts_reset(interface);
2036 err = fm10k_init_queueing_scheme(interface);
2038 fm10k_mbx_request_irq(interface);
2039 if (netif_running(netdev))
2040 err = fm10k_open(netdev);
2048 /* assume host is not ready, to prevent race with watchdog in case we
2049 * actually don't have connection to the switch
2051 interface->host_ready = false;
2052 fm10k_watchdog_host_not_ready(interface);
2054 /* clear the service task disable bit to allow service task to start */
2055 clear_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2056 fm10k_service_event_schedule(interface);
2058 /* restore SR-IOV interface */
2059 fm10k_iov_resume(pdev);
2061 netif_device_attach(netdev);
2067 * fm10k_suspend - Prepare the device for a system sleep state
2068 * @pdev: PCI device information struct
2070 * fm10k_suspend is meant to shutdown the device prior to the system entering
2071 * a sleep state. The fm10k hardware does not support wake on lan so the
2072 * driver simply needs to shut down the device so it is in a low power state.
2074 static int fm10k_suspend(struct pci_dev *pdev,
2075 pm_message_t __always_unused state)
2077 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2078 struct net_device *netdev = interface->netdev;
2081 netif_device_detach(netdev);
2083 fm10k_iov_suspend(pdev);
2085 /* the watchdog tasks may read registers, which will appear like a
2086 * surprise-remove event once the PCI device is disabled. This will
2087 * cause us to close the netdevice, so we don't retain the open/closed
2088 * state post-resume. Prevent this by disabling the service task while
2089 * suspended, until we actually resume.
2091 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2092 cancel_work_sync(&interface->service_task);
2096 if (netif_running(netdev))
2097 fm10k_close(netdev);
2099 fm10k_mbx_free_irq(interface);
2101 fm10k_clear_queueing_scheme(interface);
2105 err = pci_save_state(pdev);
2109 pci_disable_device(pdev);
2110 pci_wake_from_d3(pdev, false);
2111 pci_set_power_state(pdev, PCI_D3hot);
2116 #endif /* CONFIG_PM */
2118 * fm10k_io_error_detected - called when PCI error is detected
2119 * @pdev: Pointer to PCI device
2120 * @state: The current pci connection state
2122 * This function is called after a PCI bus error affecting
2123 * this device has been detected.
2125 static pci_ers_result_t fm10k_io_error_detected(struct pci_dev *pdev,
2126 pci_channel_state_t state)
2128 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2129 struct net_device *netdev = interface->netdev;
2131 netif_device_detach(netdev);
2133 if (state == pci_channel_io_perm_failure)
2134 return PCI_ERS_RESULT_DISCONNECT;
2136 if (netif_running(netdev))
2137 fm10k_close(netdev);
2139 fm10k_mbx_free_irq(interface);
2141 pci_disable_device(pdev);
2143 /* Request a slot reset. */
2144 return PCI_ERS_RESULT_NEED_RESET;
2148 * fm10k_io_slot_reset - called after the pci bus has been reset.
2149 * @pdev: Pointer to PCI device
2151 * Restart the card from scratch, as if from a cold-boot.
2153 static pci_ers_result_t fm10k_io_slot_reset(struct pci_dev *pdev)
2155 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2156 pci_ers_result_t result;
2158 if (pci_enable_device_mem(pdev)) {
2160 "Cannot re-enable PCI device after reset.\n");
2161 result = PCI_ERS_RESULT_DISCONNECT;
2163 pci_set_master(pdev);
2164 pci_restore_state(pdev);
2166 /* After second error pci->state_saved is false, this
2167 * resets it so EEH doesn't break.
2169 pci_save_state(pdev);
2171 pci_wake_from_d3(pdev, false);
2173 /* refresh hw_addr in case it was dropped */
2174 interface->hw.hw_addr = interface->uc_addr;
2176 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
2177 fm10k_service_event_schedule(interface);
2179 result = PCI_ERS_RESULT_RECOVERED;
2182 pci_cleanup_aer_uncorrect_error_status(pdev);
2188 * fm10k_io_resume - called when traffic can start flowing again.
2189 * @pdev: Pointer to PCI device
2191 * This callback is called when the error recovery driver tells us that
2192 * its OK to resume normal operation.
2194 static void fm10k_io_resume(struct pci_dev *pdev)
2196 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2197 struct net_device *netdev = interface->netdev;
2198 struct fm10k_hw *hw = &interface->hw;
2201 /* reset hardware to known state */
2202 hw->mac.ops.init_hw(&interface->hw);
2204 /* reset statistics starting values */
2205 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
2207 /* reassociate interrupts */
2208 fm10k_mbx_request_irq(interface);
2211 fm10k_ts_reset(interface);
2213 if (netif_running(netdev))
2214 err = fm10k_open(netdev);
2216 /* final check of hardware state before registering the interface */
2217 err = err ? : fm10k_hw_ready(interface);
2220 netif_device_attach(netdev);
2223 static const struct pci_error_handlers fm10k_err_handler = {
2224 .error_detected = fm10k_io_error_detected,
2225 .slot_reset = fm10k_io_slot_reset,
2226 .resume = fm10k_io_resume,
2229 static struct pci_driver fm10k_driver = {
2230 .name = fm10k_driver_name,
2231 .id_table = fm10k_pci_tbl,
2232 .probe = fm10k_probe,
2233 .remove = fm10k_remove,
2235 .suspend = fm10k_suspend,
2236 .resume = fm10k_resume,
2238 .sriov_configure = fm10k_iov_configure,
2239 .err_handler = &fm10k_err_handler
2243 * fm10k_register_pci_driver - register driver interface
2245 * This funciton is called on module load in order to register the driver.
2247 int fm10k_register_pci_driver(void)
2249 return pci_register_driver(&fm10k_driver);
2253 * fm10k_unregister_pci_driver - unregister driver interface
2255 * This funciton is called on module unload in order to remove the driver.
2257 void fm10k_unregister_pci_driver(void)
2259 pci_unregister_driver(&fm10k_driver);