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 /* free interrupts */
163 fm10k_clear_queueing_scheme(interface);
165 /* delay any future reset requests */
166 interface->last_reset = jiffies + (10 * HZ);
168 /* reset and initialize the hardware so it is in a known state */
169 err = hw->mac.ops.reset_hw(hw);
171 dev_err(&interface->pdev->dev, "reset_hw failed: %d\n", err);
175 err = hw->mac.ops.init_hw(hw);
177 dev_err(&interface->pdev->dev, "init_hw failed: %d\n", err);
181 err = fm10k_init_queueing_scheme(interface);
183 dev_err(&interface->pdev->dev, "init_queueing_scheme failed: %d\n", err);
187 /* reassociate interrupts */
188 fm10k_mbx_request_irq(interface);
190 /* update hardware address for VFs if perm_addr has changed */
191 if (hw->mac.type == fm10k_mac_vf) {
192 if (is_valid_ether_addr(hw->mac.perm_addr)) {
193 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
194 ether_addr_copy(netdev->perm_addr, hw->mac.perm_addr);
195 ether_addr_copy(netdev->dev_addr, hw->mac.perm_addr);
196 netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
199 if (hw->mac.vlan_override)
200 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
202 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
206 fm10k_ts_reset(interface);
208 if (netif_running(netdev))
211 fm10k_iov_resume(interface->pdev);
215 netif_device_detach(netdev);
219 clear_bit(__FM10K_RESETTING, &interface->state);
222 static void fm10k_reset_subtask(struct fm10k_intfc *interface)
224 if (!(interface->flags & FM10K_FLAG_RESET_REQUESTED))
227 interface->flags &= ~FM10K_FLAG_RESET_REQUESTED;
229 netdev_err(interface->netdev, "Reset interface\n");
231 fm10k_reinit(interface);
235 * fm10k_configure_swpri_map - Configure Receive SWPRI to PC mapping
236 * @interface: board private structure
238 * Configure the SWPRI to PC mapping for the port.
240 static void fm10k_configure_swpri_map(struct fm10k_intfc *interface)
242 struct net_device *netdev = interface->netdev;
243 struct fm10k_hw *hw = &interface->hw;
246 /* clear flag indicating update is needed */
247 interface->flags &= ~FM10K_FLAG_SWPRI_CONFIG;
249 /* these registers are only available on the PF */
250 if (hw->mac.type != fm10k_mac_pf)
253 /* configure SWPRI to PC map */
254 for (i = 0; i < FM10K_SWPRI_MAX; i++)
255 fm10k_write_reg(hw, FM10K_SWPRI_MAP(i),
256 netdev_get_prio_tc_map(netdev, i));
260 * fm10k_watchdog_update_host_state - Update the link status based on host.
261 * @interface: board private structure
263 static void fm10k_watchdog_update_host_state(struct fm10k_intfc *interface)
265 struct fm10k_hw *hw = &interface->hw;
268 if (test_bit(__FM10K_LINK_DOWN, &interface->state)) {
269 interface->host_ready = false;
270 if (time_is_after_jiffies(interface->link_down_event))
272 clear_bit(__FM10K_LINK_DOWN, &interface->state);
275 if (interface->flags & FM10K_FLAG_SWPRI_CONFIG) {
276 if (rtnl_trylock()) {
277 fm10k_configure_swpri_map(interface);
282 /* lock the mailbox for transmit and receive */
283 fm10k_mbx_lock(interface);
285 err = hw->mac.ops.get_host_state(hw, &interface->host_ready);
286 if (err && time_is_before_jiffies(interface->last_reset))
287 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
290 fm10k_mbx_unlock(interface);
294 * fm10k_mbx_subtask - Process upstream and downstream mailboxes
295 * @interface: board private structure
297 * This function will process both the upstream and downstream mailboxes.
299 static void fm10k_mbx_subtask(struct fm10k_intfc *interface)
301 /* process upstream mailbox and update device state */
302 fm10k_watchdog_update_host_state(interface);
304 /* process downstream mailboxes */
305 fm10k_iov_mbx(interface);
309 * fm10k_watchdog_host_is_ready - Update netdev status based on host ready
310 * @interface: board private structure
312 static void fm10k_watchdog_host_is_ready(struct fm10k_intfc *interface)
314 struct net_device *netdev = interface->netdev;
316 /* only continue if link state is currently down */
317 if (netif_carrier_ok(netdev))
320 netif_info(interface, drv, netdev, "NIC Link is up\n");
322 netif_carrier_on(netdev);
323 netif_tx_wake_all_queues(netdev);
327 * fm10k_watchdog_host_not_ready - Update netdev status based on host not ready
328 * @interface: board private structure
330 static void fm10k_watchdog_host_not_ready(struct fm10k_intfc *interface)
332 struct net_device *netdev = interface->netdev;
334 /* only continue if link state is currently up */
335 if (!netif_carrier_ok(netdev))
338 netif_info(interface, drv, netdev, "NIC Link is down\n");
340 netif_carrier_off(netdev);
341 netif_tx_stop_all_queues(netdev);
345 * fm10k_update_stats - Update the board statistics counters.
346 * @interface: board private structure
348 void fm10k_update_stats(struct fm10k_intfc *interface)
350 struct net_device_stats *net_stats = &interface->netdev->stats;
351 struct fm10k_hw *hw = &interface->hw;
352 u64 hw_csum_tx_good = 0, hw_csum_rx_good = 0, rx_length_errors = 0;
353 u64 rx_switch_errors = 0, rx_drops = 0, rx_pp_errors = 0;
354 u64 rx_link_errors = 0;
355 u64 rx_errors = 0, rx_csum_errors = 0, tx_csum_errors = 0;
356 u64 restart_queue = 0, tx_busy = 0, alloc_failed = 0;
357 u64 rx_bytes_nic = 0, rx_pkts_nic = 0, rx_drops_nic = 0;
358 u64 tx_bytes_nic = 0, tx_pkts_nic = 0;
362 /* do not allow stats update via service task for next second */
363 interface->next_stats_update = jiffies + HZ;
365 /* gather some stats to the interface struct that are per queue */
366 for (bytes = 0, pkts = 0, i = 0; i < interface->num_tx_queues; i++) {
367 struct fm10k_ring *tx_ring = interface->tx_ring[i];
369 restart_queue += tx_ring->tx_stats.restart_queue;
370 tx_busy += tx_ring->tx_stats.tx_busy;
371 tx_csum_errors += tx_ring->tx_stats.csum_err;
372 bytes += tx_ring->stats.bytes;
373 pkts += tx_ring->stats.packets;
374 hw_csum_tx_good += tx_ring->tx_stats.csum_good;
377 interface->restart_queue = restart_queue;
378 interface->tx_busy = tx_busy;
379 net_stats->tx_bytes = bytes;
380 net_stats->tx_packets = pkts;
381 interface->tx_csum_errors = tx_csum_errors;
382 interface->hw_csum_tx_good = hw_csum_tx_good;
384 /* gather some stats to the interface struct that are per queue */
385 for (bytes = 0, pkts = 0, i = 0; i < interface->num_rx_queues; i++) {
386 struct fm10k_ring *rx_ring = interface->rx_ring[i];
388 bytes += rx_ring->stats.bytes;
389 pkts += rx_ring->stats.packets;
390 alloc_failed += rx_ring->rx_stats.alloc_failed;
391 rx_csum_errors += rx_ring->rx_stats.csum_err;
392 rx_errors += rx_ring->rx_stats.errors;
393 hw_csum_rx_good += rx_ring->rx_stats.csum_good;
394 rx_switch_errors += rx_ring->rx_stats.switch_errors;
395 rx_drops += rx_ring->rx_stats.drops;
396 rx_pp_errors += rx_ring->rx_stats.pp_errors;
397 rx_link_errors += rx_ring->rx_stats.link_errors;
398 rx_length_errors += rx_ring->rx_stats.length_errors;
401 net_stats->rx_bytes = bytes;
402 net_stats->rx_packets = pkts;
403 interface->alloc_failed = alloc_failed;
404 interface->rx_csum_errors = rx_csum_errors;
405 interface->hw_csum_rx_good = hw_csum_rx_good;
406 interface->rx_switch_errors = rx_switch_errors;
407 interface->rx_drops = rx_drops;
408 interface->rx_pp_errors = rx_pp_errors;
409 interface->rx_link_errors = rx_link_errors;
410 interface->rx_length_errors = rx_length_errors;
412 hw->mac.ops.update_hw_stats(hw, &interface->stats);
414 for (i = 0; i < hw->mac.max_queues; i++) {
415 struct fm10k_hw_stats_q *q = &interface->stats.q[i];
417 tx_bytes_nic += q->tx_bytes.count;
418 tx_pkts_nic += q->tx_packets.count;
419 rx_bytes_nic += q->rx_bytes.count;
420 rx_pkts_nic += q->rx_packets.count;
421 rx_drops_nic += q->rx_drops.count;
424 interface->tx_bytes_nic = tx_bytes_nic;
425 interface->tx_packets_nic = tx_pkts_nic;
426 interface->rx_bytes_nic = rx_bytes_nic;
427 interface->rx_packets_nic = rx_pkts_nic;
428 interface->rx_drops_nic = rx_drops_nic;
430 /* Fill out the OS statistics structure */
431 net_stats->rx_errors = rx_errors;
432 net_stats->rx_dropped = interface->stats.nodesc_drop.count;
436 * fm10k_watchdog_flush_tx - flush queues on host not ready
437 * @interface - pointer to the device interface structure
439 static void fm10k_watchdog_flush_tx(struct fm10k_intfc *interface)
441 int some_tx_pending = 0;
444 /* nothing to do if carrier is up */
445 if (netif_carrier_ok(interface->netdev))
448 for (i = 0; i < interface->num_tx_queues; i++) {
449 struct fm10k_ring *tx_ring = interface->tx_ring[i];
451 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
457 /* We've lost link, so the controller stops DMA, but we've got
458 * queued Tx work that's never going to get done, so reset
459 * controller to flush Tx.
462 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
466 * fm10k_watchdog_subtask - check and bring link up
467 * @interface - pointer to the device interface structure
469 static void fm10k_watchdog_subtask(struct fm10k_intfc *interface)
471 /* if interface is down do nothing */
472 if (test_bit(__FM10K_DOWN, &interface->state) ||
473 test_bit(__FM10K_RESETTING, &interface->state))
476 if (interface->host_ready)
477 fm10k_watchdog_host_is_ready(interface);
479 fm10k_watchdog_host_not_ready(interface);
481 /* update stats only once every second */
482 if (time_is_before_jiffies(interface->next_stats_update))
483 fm10k_update_stats(interface);
485 /* flush any uncompleted work */
486 fm10k_watchdog_flush_tx(interface);
490 * fm10k_check_hang_subtask - check for hung queues and dropped interrupts
491 * @interface - pointer to the device interface structure
493 * This function serves two purposes. First it strobes the interrupt lines
494 * in order to make certain interrupts are occurring. Secondly it sets the
495 * bits needed to check for TX hangs. As a result we should immediately
496 * determine if a hang has occurred.
498 static void fm10k_check_hang_subtask(struct fm10k_intfc *interface)
502 /* If we're down or resetting, just bail */
503 if (test_bit(__FM10K_DOWN, &interface->state) ||
504 test_bit(__FM10K_RESETTING, &interface->state))
507 /* rate limit tx hang checks to only once every 2 seconds */
508 if (time_is_after_eq_jiffies(interface->next_tx_hang_check))
510 interface->next_tx_hang_check = jiffies + (2 * HZ);
512 if (netif_carrier_ok(interface->netdev)) {
513 /* Force detection of hung controller */
514 for (i = 0; i < interface->num_tx_queues; i++)
515 set_check_for_tx_hang(interface->tx_ring[i]);
517 /* Rearm all in-use q_vectors for immediate firing */
518 for (i = 0; i < interface->num_q_vectors; i++) {
519 struct fm10k_q_vector *qv = interface->q_vector[i];
521 if (!qv->tx.count && !qv->rx.count)
523 writel(FM10K_ITR_ENABLE | FM10K_ITR_PENDING2, qv->itr);
529 * fm10k_service_task - manages and runs subtasks
530 * @work: pointer to work_struct containing our data
532 static void fm10k_service_task(struct work_struct *work)
534 struct fm10k_intfc *interface;
536 interface = container_of(work, struct fm10k_intfc, service_task);
538 /* tasks run even when interface is down */
539 fm10k_mbx_subtask(interface);
540 fm10k_detach_subtask(interface);
541 fm10k_reset_subtask(interface);
543 /* tasks only run when interface is up */
544 fm10k_watchdog_subtask(interface);
545 fm10k_check_hang_subtask(interface);
546 fm10k_ts_tx_subtask(interface);
548 /* release lock on service events to allow scheduling next event */
549 fm10k_service_event_complete(interface);
553 * fm10k_configure_tx_ring - Configure Tx ring after Reset
554 * @interface: board private structure
555 * @ring: structure containing ring specific data
557 * Configure the Tx descriptor ring after a reset.
559 static void fm10k_configure_tx_ring(struct fm10k_intfc *interface,
560 struct fm10k_ring *ring)
562 struct fm10k_hw *hw = &interface->hw;
563 u64 tdba = ring->dma;
564 u32 size = ring->count * sizeof(struct fm10k_tx_desc);
565 u32 txint = FM10K_INT_MAP_DISABLE;
566 u32 txdctl = FM10K_TXDCTL_ENABLE | (1 << FM10K_TXDCTL_MAX_TIME_SHIFT);
567 u8 reg_idx = ring->reg_idx;
569 /* disable queue to avoid issues while updating state */
570 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), 0);
571 fm10k_write_flush(hw);
573 /* possible poll here to verify ring resources have been cleaned */
575 /* set location and size for descriptor ring */
576 fm10k_write_reg(hw, FM10K_TDBAL(reg_idx), tdba & DMA_BIT_MASK(32));
577 fm10k_write_reg(hw, FM10K_TDBAH(reg_idx), tdba >> 32);
578 fm10k_write_reg(hw, FM10K_TDLEN(reg_idx), size);
580 /* reset head and tail pointers */
581 fm10k_write_reg(hw, FM10K_TDH(reg_idx), 0);
582 fm10k_write_reg(hw, FM10K_TDT(reg_idx), 0);
584 /* store tail pointer */
585 ring->tail = &interface->uc_addr[FM10K_TDT(reg_idx)];
587 /* reset ntu and ntc to place SW in sync with hardwdare */
588 ring->next_to_clean = 0;
589 ring->next_to_use = 0;
592 if (ring->q_vector) {
593 txint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
594 txint |= FM10K_INT_MAP_TIMER0;
597 fm10k_write_reg(hw, FM10K_TXINT(reg_idx), txint);
599 /* enable use of FTAG bit in Tx descriptor, register is RO for VF */
600 fm10k_write_reg(hw, FM10K_PFVTCTL(reg_idx),
601 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
604 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), txdctl);
608 * fm10k_enable_tx_ring - Verify Tx ring is enabled after configuration
609 * @interface: board private structure
610 * @ring: structure containing ring specific data
612 * Verify the Tx descriptor ring is ready for transmit.
614 static void fm10k_enable_tx_ring(struct fm10k_intfc *interface,
615 struct fm10k_ring *ring)
617 struct fm10k_hw *hw = &interface->hw;
620 u8 reg_idx = ring->reg_idx;
622 /* if we are already enabled just exit */
623 if (fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx)) & FM10K_TXDCTL_ENABLE)
626 /* poll to verify queue is enabled */
628 usleep_range(1000, 2000);
629 txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx));
630 } while (!(txdctl & FM10K_TXDCTL_ENABLE) && --wait_loop);
632 netif_err(interface, drv, interface->netdev,
633 "Could not enable Tx Queue %d\n", reg_idx);
637 * fm10k_configure_tx - Configure Transmit Unit after Reset
638 * @interface: board private structure
640 * Configure the Tx unit of the MAC after a reset.
642 static void fm10k_configure_tx(struct fm10k_intfc *interface)
646 /* Setup the HW Tx Head and Tail descriptor pointers */
647 for (i = 0; i < interface->num_tx_queues; i++)
648 fm10k_configure_tx_ring(interface, interface->tx_ring[i]);
650 /* poll here to verify that Tx rings are now enabled */
651 for (i = 0; i < interface->num_tx_queues; i++)
652 fm10k_enable_tx_ring(interface, interface->tx_ring[i]);
656 * fm10k_configure_rx_ring - Configure Rx ring after Reset
657 * @interface: board private structure
658 * @ring: structure containing ring specific data
660 * Configure the Rx descriptor ring after a reset.
662 static void fm10k_configure_rx_ring(struct fm10k_intfc *interface,
663 struct fm10k_ring *ring)
665 u64 rdba = ring->dma;
666 struct fm10k_hw *hw = &interface->hw;
667 u32 size = ring->count * sizeof(union fm10k_rx_desc);
668 u32 rxqctl = FM10K_RXQCTL_ENABLE | FM10K_RXQCTL_PF;
669 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
670 u32 srrctl = FM10K_SRRCTL_BUFFER_CHAINING_EN;
671 u32 rxint = FM10K_INT_MAP_DISABLE;
672 u8 rx_pause = interface->rx_pause;
673 u8 reg_idx = ring->reg_idx;
675 /* disable queue to avoid issues while updating state */
676 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), 0);
677 fm10k_write_flush(hw);
679 /* possible poll here to verify ring resources have been cleaned */
681 /* set location and size for descriptor ring */
682 fm10k_write_reg(hw, FM10K_RDBAL(reg_idx), rdba & DMA_BIT_MASK(32));
683 fm10k_write_reg(hw, FM10K_RDBAH(reg_idx), rdba >> 32);
684 fm10k_write_reg(hw, FM10K_RDLEN(reg_idx), size);
686 /* reset head and tail pointers */
687 fm10k_write_reg(hw, FM10K_RDH(reg_idx), 0);
688 fm10k_write_reg(hw, FM10K_RDT(reg_idx), 0);
690 /* store tail pointer */
691 ring->tail = &interface->uc_addr[FM10K_RDT(reg_idx)];
693 /* reset ntu and ntc to place SW in sync with hardwdare */
694 ring->next_to_clean = 0;
695 ring->next_to_use = 0;
696 ring->next_to_alloc = 0;
698 /* Configure the Rx buffer size for one buff without split */
699 srrctl |= FM10K_RX_BUFSZ >> FM10K_SRRCTL_BSIZEPKT_SHIFT;
701 /* Configure the Rx ring to suppress loopback packets */
702 srrctl |= FM10K_SRRCTL_LOOPBACK_SUPPRESS;
703 fm10k_write_reg(hw, FM10K_SRRCTL(reg_idx), srrctl);
705 /* Enable drop on empty */
707 if (interface->pfc_en)
708 rx_pause = interface->pfc_en;
710 if (!(rx_pause & (1 << ring->qos_pc)))
711 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
713 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
715 /* assign default VLAN to queue */
716 ring->vid = hw->mac.default_vid;
718 /* if we have an active VLAN, disable default VID */
719 if (test_bit(hw->mac.default_vid, interface->active_vlans))
720 ring->vid |= FM10K_VLAN_CLEAR;
723 if (ring->q_vector) {
724 rxint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
725 rxint |= FM10K_INT_MAP_TIMER1;
728 fm10k_write_reg(hw, FM10K_RXINT(reg_idx), rxint);
731 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), rxqctl);
733 /* place buffers on ring for receive data */
734 fm10k_alloc_rx_buffers(ring, fm10k_desc_unused(ring));
738 * fm10k_update_rx_drop_en - Configures the drop enable bits for Rx rings
739 * @interface: board private structure
741 * Configure the drop enable bits for the Rx rings.
743 void fm10k_update_rx_drop_en(struct fm10k_intfc *interface)
745 struct fm10k_hw *hw = &interface->hw;
746 u8 rx_pause = interface->rx_pause;
750 if (interface->pfc_en)
751 rx_pause = interface->pfc_en;
754 for (i = 0; i < interface->num_rx_queues; i++) {
755 struct fm10k_ring *ring = interface->rx_ring[i];
756 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
757 u8 reg_idx = ring->reg_idx;
759 if (!(rx_pause & (1 << ring->qos_pc)))
760 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
762 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
767 * fm10k_configure_dglort - Configure Receive DGLORT after reset
768 * @interface: board private structure
770 * Configure the DGLORT description and RSS tables.
772 static void fm10k_configure_dglort(struct fm10k_intfc *interface)
774 struct fm10k_dglort_cfg dglort = { 0 };
775 struct fm10k_hw *hw = &interface->hw;
779 /* Fill out hash function seeds */
780 for (i = 0; i < FM10K_RSSRK_SIZE; i++)
781 fm10k_write_reg(hw, FM10K_RSSRK(0, i), interface->rssrk[i]);
783 /* Write RETA table to hardware */
784 for (i = 0; i < FM10K_RETA_SIZE; i++)
785 fm10k_write_reg(hw, FM10K_RETA(0, i), interface->reta[i]);
787 /* Generate RSS hash based on packet types, TCP/UDP
788 * port numbers and/or IPv4/v6 src and dst addresses
790 mrqc = FM10K_MRQC_IPV4 |
791 FM10K_MRQC_TCP_IPV4 |
795 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
796 mrqc |= FM10K_MRQC_UDP_IPV4;
797 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
798 mrqc |= FM10K_MRQC_UDP_IPV6;
800 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
802 /* configure default DGLORT mapping for RSS/DCB */
803 dglort.inner_rss = 1;
804 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
805 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
806 hw->mac.ops.configure_dglort_map(hw, &dglort);
808 /* assign GLORT per queue for queue mapped testing */
809 if (interface->glort_count > 64) {
810 memset(&dglort, 0, sizeof(dglort));
811 dglort.inner_rss = 1;
812 dglort.glort = interface->glort + 64;
813 dglort.idx = fm10k_dglort_pf_queue;
814 dglort.queue_l = fls(interface->num_rx_queues - 1);
815 hw->mac.ops.configure_dglort_map(hw, &dglort);
818 /* assign glort value for RSS/DCB specific to this interface */
819 memset(&dglort, 0, sizeof(dglort));
820 dglort.inner_rss = 1;
821 dglort.glort = interface->glort;
822 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
823 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
824 /* configure DGLORT mapping for RSS/DCB */
825 dglort.idx = fm10k_dglort_pf_rss;
826 if (interface->l2_accel)
827 dglort.shared_l = fls(interface->l2_accel->size);
828 hw->mac.ops.configure_dglort_map(hw, &dglort);
832 * fm10k_configure_rx - Configure Receive Unit after Reset
833 * @interface: board private structure
835 * Configure the Rx unit of the MAC after a reset.
837 static void fm10k_configure_rx(struct fm10k_intfc *interface)
841 /* Configure SWPRI to PC map */
842 fm10k_configure_swpri_map(interface);
844 /* Configure RSS and DGLORT map */
845 fm10k_configure_dglort(interface);
847 /* Setup the HW Rx Head and Tail descriptor pointers */
848 for (i = 0; i < interface->num_rx_queues; i++)
849 fm10k_configure_rx_ring(interface, interface->rx_ring[i]);
851 /* possible poll here to verify that Rx rings are now enabled */
854 static void fm10k_napi_enable_all(struct fm10k_intfc *interface)
856 struct fm10k_q_vector *q_vector;
859 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
860 q_vector = interface->q_vector[q_idx];
861 napi_enable(&q_vector->napi);
865 static irqreturn_t fm10k_msix_clean_rings(int __always_unused irq, void *data)
867 struct fm10k_q_vector *q_vector = data;
869 if (q_vector->rx.count || q_vector->tx.count)
870 napi_schedule(&q_vector->napi);
875 static irqreturn_t fm10k_msix_mbx_vf(int __always_unused irq, void *data)
877 struct fm10k_intfc *interface = data;
878 struct fm10k_hw *hw = &interface->hw;
879 struct fm10k_mbx_info *mbx = &hw->mbx;
881 /* re-enable mailbox interrupt and indicate 20us delay */
882 fm10k_write_reg(hw, FM10K_VFITR(FM10K_MBX_VECTOR),
883 FM10K_ITR_ENABLE | FM10K_MBX_INT_DELAY);
885 /* service upstream mailbox */
886 if (fm10k_mbx_trylock(interface)) {
887 mbx->ops.process(hw, mbx);
888 fm10k_mbx_unlock(interface);
891 hw->mac.get_host_state = 1;
892 fm10k_service_event_schedule(interface);
897 #ifdef CONFIG_NET_POLL_CONTROLLER
899 * fm10k_netpoll - A Polling 'interrupt' handler
900 * @netdev: network interface device structure
902 * This is used by netconsole to send skbs without having to re-enable
903 * interrupts. It's not called while the normal interrupt routine is executing.
905 void fm10k_netpoll(struct net_device *netdev)
907 struct fm10k_intfc *interface = netdev_priv(netdev);
910 /* if interface is down do nothing */
911 if (test_bit(__FM10K_DOWN, &interface->state))
914 for (i = 0; i < interface->num_q_vectors; i++)
915 fm10k_msix_clean_rings(0, interface->q_vector[i]);
919 #define FM10K_ERR_MSG(type) case (type): error = #type; break
920 static void fm10k_handle_fault(struct fm10k_intfc *interface, int type,
921 struct fm10k_fault *fault)
923 struct pci_dev *pdev = interface->pdev;
924 struct fm10k_hw *hw = &interface->hw;
925 struct fm10k_iov_data *iov_data = interface->iov_data;
929 case FM10K_PCA_FAULT:
930 switch (fault->type) {
932 error = "Unknown PCA error";
934 FM10K_ERR_MSG(PCA_NO_FAULT);
935 FM10K_ERR_MSG(PCA_UNMAPPED_ADDR);
936 FM10K_ERR_MSG(PCA_BAD_QACCESS_PF);
937 FM10K_ERR_MSG(PCA_BAD_QACCESS_VF);
938 FM10K_ERR_MSG(PCA_MALICIOUS_REQ);
939 FM10K_ERR_MSG(PCA_POISONED_TLP);
940 FM10K_ERR_MSG(PCA_TLP_ABORT);
943 case FM10K_THI_FAULT:
944 switch (fault->type) {
946 error = "Unknown THI error";
948 FM10K_ERR_MSG(THI_NO_FAULT);
949 FM10K_ERR_MSG(THI_MAL_DIS_Q_FAULT);
952 case FM10K_FUM_FAULT:
953 switch (fault->type) {
955 error = "Unknown FUM error";
957 FM10K_ERR_MSG(FUM_NO_FAULT);
958 FM10K_ERR_MSG(FUM_UNMAPPED_ADDR);
959 FM10K_ERR_MSG(FUM_BAD_VF_QACCESS);
960 FM10K_ERR_MSG(FUM_ADD_DECODE_ERR);
961 FM10K_ERR_MSG(FUM_RO_ERROR);
962 FM10K_ERR_MSG(FUM_QPRC_CRC_ERROR);
963 FM10K_ERR_MSG(FUM_CSR_TIMEOUT);
964 FM10K_ERR_MSG(FUM_INVALID_TYPE);
965 FM10K_ERR_MSG(FUM_INVALID_LENGTH);
966 FM10K_ERR_MSG(FUM_INVALID_BE);
967 FM10K_ERR_MSG(FUM_INVALID_ALIGN);
971 error = "Undocumented fault";
976 "%s Address: 0x%llx SpecInfo: 0x%x Func: %02x.%0x\n",
977 error, fault->address, fault->specinfo,
978 PCI_SLOT(fault->func), PCI_FUNC(fault->func));
980 /* For VF faults, clear out the respective LPORT, reset the queue
981 * resources, and then reconnect to the mailbox. This allows the
982 * VF in question to resume behavior. For transient faults that are
983 * the result of non-malicious behavior this will log the fault and
984 * allow the VF to resume functionality. Obviously for malicious VFs
985 * they will be able to attempt malicious behavior again. In this
986 * case, the system administrator will need to step in and manually
987 * remove or disable the VF in question.
989 if (fault->func && iov_data) {
990 int vf = fault->func - 1;
991 struct fm10k_vf_info *vf_info = &iov_data->vf_info[vf];
993 hw->iov.ops.reset_lport(hw, vf_info);
994 hw->iov.ops.reset_resources(hw, vf_info);
996 /* reset_lport disables the VF, so re-enable it */
997 hw->iov.ops.set_lport(hw, vf_info, vf,
998 FM10K_VF_FLAG_MULTI_CAPABLE);
1000 /* reset_resources will disconnect from the mbx */
1001 vf_info->mbx.ops.connect(hw, &vf_info->mbx);
1005 static void fm10k_report_fault(struct fm10k_intfc *interface, u32 eicr)
1007 struct fm10k_hw *hw = &interface->hw;
1008 struct fm10k_fault fault = { 0 };
1011 for (eicr &= FM10K_EICR_FAULT_MASK, type = FM10K_PCA_FAULT;
1013 eicr >>= 1, type += FM10K_FAULT_SIZE) {
1014 /* only check if there is an error reported */
1018 /* retrieve fault info */
1019 err = hw->mac.ops.get_fault(hw, type, &fault);
1021 dev_err(&interface->pdev->dev,
1022 "error reading fault\n");
1026 fm10k_handle_fault(interface, type, &fault);
1030 static void fm10k_reset_drop_on_empty(struct fm10k_intfc *interface, u32 eicr)
1032 struct fm10k_hw *hw = &interface->hw;
1033 const u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
1037 if (!(eicr & FM10K_EICR_MAXHOLDTIME))
1040 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(7));
1042 fm10k_write_reg(hw, FM10K_MAXHOLDQ(7), maxholdq);
1044 if (maxholdq & (1 << 31)) {
1045 if (q < FM10K_MAX_QUEUES_PF) {
1046 interface->rx_overrun_pf++;
1047 fm10k_write_reg(hw, FM10K_RXDCTL(q), rxdctl);
1049 interface->rx_overrun_vf++;
1063 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(q / 32));
1065 fm10k_write_reg(hw, FM10K_MAXHOLDQ(q / 32), maxholdq);
1069 static irqreturn_t fm10k_msix_mbx_pf(int __always_unused irq, void *data)
1071 struct fm10k_intfc *interface = data;
1072 struct fm10k_hw *hw = &interface->hw;
1073 struct fm10k_mbx_info *mbx = &hw->mbx;
1077 /* unmask any set bits related to this interrupt */
1078 eicr = fm10k_read_reg(hw, FM10K_EICR);
1079 fm10k_write_reg(hw, FM10K_EICR, eicr & (FM10K_EICR_MAILBOX |
1080 FM10K_EICR_SWITCHREADY |
1081 FM10K_EICR_SWITCHNOTREADY));
1083 /* report any faults found to the message log */
1084 fm10k_report_fault(interface, eicr);
1086 /* reset any queues disabled due to receiver overrun */
1087 fm10k_reset_drop_on_empty(interface, eicr);
1089 /* service mailboxes */
1090 if (fm10k_mbx_trylock(interface)) {
1091 err = mbx->ops.process(hw, mbx);
1092 /* handle VFLRE events */
1093 fm10k_iov_event(interface);
1094 fm10k_mbx_unlock(interface);
1097 if (err == FM10K_ERR_RESET_REQUESTED)
1098 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1100 /* if switch toggled state we should reset GLORTs */
1101 if (eicr & FM10K_EICR_SWITCHNOTREADY) {
1102 /* force link down for at least 4 seconds */
1103 interface->link_down_event = jiffies + (4 * HZ);
1104 set_bit(__FM10K_LINK_DOWN, &interface->state);
1106 /* reset dglort_map back to no config */
1107 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
1110 /* we should validate host state after interrupt event */
1111 hw->mac.get_host_state = 1;
1113 /* validate host state, and handle VF mailboxes in the service task */
1114 fm10k_service_event_schedule(interface);
1116 /* re-enable mailbox interrupt and indicate 20us delay */
1117 fm10k_write_reg(hw, FM10K_ITR(FM10K_MBX_VECTOR),
1118 FM10K_ITR_ENABLE | FM10K_MBX_INT_DELAY);
1123 void fm10k_mbx_free_irq(struct fm10k_intfc *interface)
1125 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1126 struct fm10k_hw *hw = &interface->hw;
1129 /* no mailbox IRQ to free if MSI-X is not enabled */
1130 if (!interface->msix_entries)
1133 /* disconnect the mailbox */
1134 hw->mbx.ops.disconnect(hw, &hw->mbx);
1136 /* disable Mailbox cause */
1137 if (hw->mac.type == fm10k_mac_pf) {
1138 fm10k_write_reg(hw, FM10K_EIMR,
1139 FM10K_EIMR_DISABLE(PCA_FAULT) |
1140 FM10K_EIMR_DISABLE(FUM_FAULT) |
1141 FM10K_EIMR_DISABLE(MAILBOX) |
1142 FM10K_EIMR_DISABLE(SWITCHREADY) |
1143 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
1144 FM10K_EIMR_DISABLE(SRAMERROR) |
1145 FM10K_EIMR_DISABLE(VFLR) |
1146 FM10K_EIMR_DISABLE(MAXHOLDTIME));
1147 itr_reg = FM10K_ITR(FM10K_MBX_VECTOR);
1149 itr_reg = FM10K_VFITR(FM10K_MBX_VECTOR);
1152 fm10k_write_reg(hw, itr_reg, FM10K_ITR_MASK_SET);
1154 free_irq(entry->vector, interface);
1157 static s32 fm10k_mbx_mac_addr(struct fm10k_hw *hw, u32 **results,
1158 struct fm10k_mbx_info *mbx)
1160 bool vlan_override = hw->mac.vlan_override;
1161 u16 default_vid = hw->mac.default_vid;
1162 struct fm10k_intfc *interface;
1165 err = fm10k_msg_mac_vlan_vf(hw, results, mbx);
1169 interface = container_of(hw, struct fm10k_intfc, hw);
1171 /* MAC was changed so we need reset */
1172 if (is_valid_ether_addr(hw->mac.perm_addr) &&
1173 memcmp(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN))
1174 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1176 /* VLAN override was changed, or default VLAN changed */
1177 if ((vlan_override != hw->mac.vlan_override) ||
1178 (default_vid != hw->mac.default_vid))
1179 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1184 static s32 fm10k_1588_msg_vf(struct fm10k_hw *hw, u32 **results,
1185 struct fm10k_mbx_info __always_unused *mbx)
1187 struct fm10k_intfc *interface;
1191 err = fm10k_tlv_attr_get_u64(results[FM10K_1588_MSG_TIMESTAMP],
1196 interface = container_of(hw, struct fm10k_intfc, hw);
1198 fm10k_ts_tx_hwtstamp(interface, 0, timestamp);
1203 /* generic error handler for mailbox issues */
1204 static s32 fm10k_mbx_error(struct fm10k_hw *hw, u32 **results,
1205 struct fm10k_mbx_info __always_unused *mbx)
1207 struct fm10k_intfc *interface;
1208 struct pci_dev *pdev;
1210 interface = container_of(hw, struct fm10k_intfc, hw);
1211 pdev = interface->pdev;
1213 dev_err(&pdev->dev, "Unknown message ID %u\n",
1214 **results & FM10K_TLV_ID_MASK);
1219 static const struct fm10k_msg_data vf_mbx_data[] = {
1220 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
1221 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_mbx_mac_addr),
1222 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
1223 FM10K_VF_MSG_1588_HANDLER(fm10k_1588_msg_vf),
1224 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_mbx_error),
1227 static int fm10k_mbx_request_irq_vf(struct fm10k_intfc *interface)
1229 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1230 struct net_device *dev = interface->netdev;
1231 struct fm10k_hw *hw = &interface->hw;
1234 /* Use timer0 for interrupt moderation on the mailbox */
1235 u32 itr = FM10K_INT_MAP_TIMER0 | entry->entry;
1237 /* register mailbox handlers */
1238 err = hw->mbx.ops.register_handlers(&hw->mbx, vf_mbx_data);
1242 /* request the IRQ */
1243 err = request_irq(entry->vector, fm10k_msix_mbx_vf, 0,
1244 dev->name, interface);
1246 netif_err(interface, probe, dev,
1247 "request_irq for msix_mbx failed: %d\n", err);
1251 /* map all of the interrupt sources */
1252 fm10k_write_reg(hw, FM10K_VFINT_MAP, itr);
1254 /* enable interrupt */
1255 fm10k_write_reg(hw, FM10K_VFITR(entry->entry), FM10K_ITR_ENABLE);
1260 static s32 fm10k_lport_map(struct fm10k_hw *hw, u32 **results,
1261 struct fm10k_mbx_info *mbx)
1263 struct fm10k_intfc *interface;
1264 u32 dglort_map = hw->mac.dglort_map;
1267 err = fm10k_msg_lport_map_pf(hw, results, mbx);
1271 interface = container_of(hw, struct fm10k_intfc, hw);
1273 /* we need to reset if port count was just updated */
1274 if (dglort_map != hw->mac.dglort_map)
1275 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1280 static s32 fm10k_update_pvid(struct fm10k_hw *hw, u32 **results,
1281 struct fm10k_mbx_info __always_unused *mbx)
1283 struct fm10k_intfc *interface;
1288 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1293 /* extract values from the pvid update */
1294 glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1295 pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1297 /* if glort is not valid return error */
1298 if (!fm10k_glort_valid_pf(hw, glort))
1299 return FM10K_ERR_PARAM;
1301 /* verify VID is valid */
1302 if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1303 return FM10K_ERR_PARAM;
1305 interface = container_of(hw, struct fm10k_intfc, hw);
1307 /* check to see if this belongs to one of the VFs */
1308 err = fm10k_iov_update_pvid(interface, glort, pvid);
1312 /* we need to reset if default VLAN was just updated */
1313 if (pvid != hw->mac.default_vid)
1314 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1316 hw->mac.default_vid = pvid;
1321 static s32 fm10k_1588_msg_pf(struct fm10k_hw *hw, u32 **results,
1322 struct fm10k_mbx_info __always_unused *mbx)
1324 struct fm10k_swapi_1588_timestamp timestamp;
1325 struct fm10k_iov_data *iov_data;
1326 struct fm10k_intfc *interface;
1330 err = fm10k_tlv_attr_get_le_struct(
1331 results[FM10K_PF_ATTR_ID_1588_TIMESTAMP],
1332 ×tamp, sizeof(timestamp));
1336 interface = container_of(hw, struct fm10k_intfc, hw);
1338 if (timestamp.dglort) {
1339 fm10k_ts_tx_hwtstamp(interface, timestamp.dglort,
1340 le64_to_cpu(timestamp.egress));
1344 /* either dglort or sglort must be set */
1345 if (!timestamp.sglort)
1346 return FM10K_ERR_PARAM;
1348 /* verify GLORT is at least one of the ones we own */
1349 sglort = le16_to_cpu(timestamp.sglort);
1350 if (!fm10k_glort_valid_pf(hw, sglort))
1351 return FM10K_ERR_PARAM;
1353 if (sglort == interface->glort) {
1354 fm10k_ts_tx_hwtstamp(interface, 0,
1355 le64_to_cpu(timestamp.ingress));
1359 /* if there is no iov_data then there is no mailboxes to process */
1360 if (!ACCESS_ONCE(interface->iov_data))
1361 return FM10K_ERR_PARAM;
1365 /* notify VF if this timestamp belongs to it */
1366 iov_data = interface->iov_data;
1367 vf_idx = (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE) - sglort;
1369 if (!iov_data || vf_idx >= iov_data->num_vfs) {
1370 err = FM10K_ERR_PARAM;
1374 err = hw->iov.ops.report_timestamp(hw, &iov_data->vf_info[vf_idx],
1375 le64_to_cpu(timestamp.ingress));
1383 static const struct fm10k_msg_data pf_mbx_data[] = {
1384 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1385 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1386 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_lport_map),
1387 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1388 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1389 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_update_pvid),
1390 FM10K_PF_MSG_1588_TIMESTAMP_HANDLER(fm10k_1588_msg_pf),
1391 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_mbx_error),
1394 static int fm10k_mbx_request_irq_pf(struct fm10k_intfc *interface)
1396 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1397 struct net_device *dev = interface->netdev;
1398 struct fm10k_hw *hw = &interface->hw;
1401 /* Use timer0 for interrupt moderation on the mailbox */
1402 u32 mbx_itr = FM10K_INT_MAP_TIMER0 | entry->entry;
1403 u32 other_itr = FM10K_INT_MAP_IMMEDIATE | entry->entry;
1405 /* register mailbox handlers */
1406 err = hw->mbx.ops.register_handlers(&hw->mbx, pf_mbx_data);
1410 /* request the IRQ */
1411 err = request_irq(entry->vector, fm10k_msix_mbx_pf, 0,
1412 dev->name, interface);
1414 netif_err(interface, probe, dev,
1415 "request_irq for msix_mbx failed: %d\n", err);
1419 /* Enable interrupts w/ no moderation for "other" interrupts */
1420 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), other_itr);
1421 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), other_itr);
1422 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SRAM), other_itr);
1423 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_MaxHoldTime), other_itr);
1424 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_VFLR), other_itr);
1426 /* Enable interrupts w/ moderation for mailbox */
1427 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_Mailbox), mbx_itr);
1429 /* Enable individual interrupt causes */
1430 fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
1431 FM10K_EIMR_ENABLE(FUM_FAULT) |
1432 FM10K_EIMR_ENABLE(MAILBOX) |
1433 FM10K_EIMR_ENABLE(SWITCHREADY) |
1434 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
1435 FM10K_EIMR_ENABLE(SRAMERROR) |
1436 FM10K_EIMR_ENABLE(VFLR) |
1437 FM10K_EIMR_ENABLE(MAXHOLDTIME));
1439 /* enable interrupt */
1440 fm10k_write_reg(hw, FM10K_ITR(entry->entry), FM10K_ITR_ENABLE);
1445 int fm10k_mbx_request_irq(struct fm10k_intfc *interface)
1447 struct fm10k_hw *hw = &interface->hw;
1450 /* enable Mailbox cause */
1451 if (hw->mac.type == fm10k_mac_pf)
1452 err = fm10k_mbx_request_irq_pf(interface);
1454 err = fm10k_mbx_request_irq_vf(interface);
1458 /* connect mailbox */
1459 err = hw->mbx.ops.connect(hw, &hw->mbx);
1461 /* if the mailbox failed to connect, then free IRQ */
1463 fm10k_mbx_free_irq(interface);
1469 * fm10k_qv_free_irq - release interrupts associated with queue vectors
1470 * @interface: board private structure
1472 * Release all interrupts associated with this interface
1474 void fm10k_qv_free_irq(struct fm10k_intfc *interface)
1476 int vector = interface->num_q_vectors;
1477 struct fm10k_hw *hw = &interface->hw;
1478 struct msix_entry *entry;
1480 entry = &interface->msix_entries[NON_Q_VECTORS(hw) + vector];
1483 struct fm10k_q_vector *q_vector;
1487 q_vector = interface->q_vector[vector];
1489 if (!q_vector->tx.count && !q_vector->rx.count)
1492 /* disable interrupts */
1494 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1496 free_irq(entry->vector, q_vector);
1501 * fm10k_qv_request_irq - initialize interrupts for queue vectors
1502 * @interface: board private structure
1504 * Attempts to configure interrupts using the best available
1505 * capabilities of the hardware and kernel.
1507 int fm10k_qv_request_irq(struct fm10k_intfc *interface)
1509 struct net_device *dev = interface->netdev;
1510 struct fm10k_hw *hw = &interface->hw;
1511 struct msix_entry *entry;
1515 entry = &interface->msix_entries[NON_Q_VECTORS(hw)];
1517 for (vector = 0; vector < interface->num_q_vectors; vector++) {
1518 struct fm10k_q_vector *q_vector = interface->q_vector[vector];
1520 /* name the vector */
1521 if (q_vector->tx.count && q_vector->rx.count) {
1522 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1523 "%s-TxRx-%d", dev->name, ri++);
1525 } else if (q_vector->rx.count) {
1526 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1527 "%s-rx-%d", dev->name, ri++);
1528 } else if (q_vector->tx.count) {
1529 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1530 "%s-tx-%d", dev->name, ti++);
1532 /* skip this unused q_vector */
1536 /* Assign ITR register to q_vector */
1537 q_vector->itr = (hw->mac.type == fm10k_mac_pf) ?
1538 &interface->uc_addr[FM10K_ITR(entry->entry)] :
1539 &interface->uc_addr[FM10K_VFITR(entry->entry)];
1541 /* request the IRQ */
1542 err = request_irq(entry->vector, &fm10k_msix_clean_rings, 0,
1543 q_vector->name, q_vector);
1545 netif_err(interface, probe, dev,
1546 "request_irq failed for MSIX interrupt Error: %d\n",
1551 /* Enable q_vector */
1552 writel(FM10K_ITR_ENABLE, q_vector->itr);
1560 /* wind through the ring freeing all entries and vectors */
1562 struct fm10k_q_vector *q_vector;
1566 q_vector = interface->q_vector[vector];
1568 if (!q_vector->tx.count && !q_vector->rx.count)
1571 /* disable interrupts */
1573 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1575 free_irq(entry->vector, q_vector);
1581 void fm10k_up(struct fm10k_intfc *interface)
1583 struct fm10k_hw *hw = &interface->hw;
1585 /* Enable Tx/Rx DMA */
1586 hw->mac.ops.start_hw(hw);
1588 /* configure Tx descriptor rings */
1589 fm10k_configure_tx(interface);
1591 /* configure Rx descriptor rings */
1592 fm10k_configure_rx(interface);
1594 /* configure interrupts */
1595 hw->mac.ops.update_int_moderator(hw);
1597 /* clear down bit to indicate we are ready to go */
1598 clear_bit(__FM10K_DOWN, &interface->state);
1600 /* enable polling cleanups */
1601 fm10k_napi_enable_all(interface);
1603 /* re-establish Rx filters */
1604 fm10k_restore_rx_state(interface);
1606 /* enable transmits */
1607 netif_tx_start_all_queues(interface->netdev);
1609 /* kick off the service timer now */
1610 hw->mac.get_host_state = 1;
1611 mod_timer(&interface->service_timer, jiffies);
1614 static void fm10k_napi_disable_all(struct fm10k_intfc *interface)
1616 struct fm10k_q_vector *q_vector;
1619 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
1620 q_vector = interface->q_vector[q_idx];
1621 napi_disable(&q_vector->napi);
1625 void fm10k_down(struct fm10k_intfc *interface)
1627 struct net_device *netdev = interface->netdev;
1628 struct fm10k_hw *hw = &interface->hw;
1630 /* signal that we are down to the interrupt handler and service task */
1631 set_bit(__FM10K_DOWN, &interface->state);
1633 /* call carrier off first to avoid false dev_watchdog timeouts */
1634 netif_carrier_off(netdev);
1636 /* disable transmits */
1637 netif_tx_stop_all_queues(netdev);
1638 netif_tx_disable(netdev);
1640 /* reset Rx filters */
1641 fm10k_reset_rx_state(interface);
1643 /* allow 10ms for device to quiesce */
1644 usleep_range(10000, 20000);
1646 /* disable polling routines */
1647 fm10k_napi_disable_all(interface);
1649 /* capture stats one last time before stopping interface */
1650 fm10k_update_stats(interface);
1652 /* Disable DMA engine for Tx/Rx */
1653 hw->mac.ops.stop_hw(hw);
1655 /* free any buffers still on the rings */
1656 fm10k_clean_all_tx_rings(interface);
1657 fm10k_clean_all_rx_rings(interface);
1661 * fm10k_sw_init - Initialize general software structures
1662 * @interface: host interface private structure to initialize
1664 * fm10k_sw_init initializes the interface private data structure.
1665 * Fields are initialized based on PCI device information and
1666 * OS network device settings (MTU size).
1668 static int fm10k_sw_init(struct fm10k_intfc *interface,
1669 const struct pci_device_id *ent)
1671 const struct fm10k_info *fi = fm10k_info_tbl[ent->driver_data];
1672 struct fm10k_hw *hw = &interface->hw;
1673 struct pci_dev *pdev = interface->pdev;
1674 struct net_device *netdev = interface->netdev;
1675 u32 rss_key[FM10K_RSSRK_SIZE];
1679 /* initialize back pointer */
1680 hw->back = interface;
1681 hw->hw_addr = interface->uc_addr;
1683 /* PCI config space info */
1684 hw->vendor_id = pdev->vendor;
1685 hw->device_id = pdev->device;
1686 hw->revision_id = pdev->revision;
1687 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1688 hw->subsystem_device_id = pdev->subsystem_device;
1691 memcpy(&hw->mac.ops, fi->mac_ops, sizeof(hw->mac.ops));
1692 hw->mac.type = fi->mac;
1694 /* Setup IOV handlers */
1696 memcpy(&hw->iov.ops, fi->iov_ops, sizeof(hw->iov.ops));
1698 /* Set common capability flags and settings */
1699 rss = min_t(int, FM10K_MAX_RSS_INDICES, num_online_cpus());
1700 interface->ring_feature[RING_F_RSS].limit = rss;
1701 fi->get_invariants(hw);
1703 /* pick up the PCIe bus settings for reporting later */
1704 if (hw->mac.ops.get_bus_info)
1705 hw->mac.ops.get_bus_info(hw);
1707 /* limit the usable DMA range */
1708 if (hw->mac.ops.set_dma_mask)
1709 hw->mac.ops.set_dma_mask(hw, dma_get_mask(&pdev->dev));
1711 /* update netdev with DMA restrictions */
1712 if (dma_get_mask(&pdev->dev) > DMA_BIT_MASK(32)) {
1713 netdev->features |= NETIF_F_HIGHDMA;
1714 netdev->vlan_features |= NETIF_F_HIGHDMA;
1717 /* delay any future reset requests */
1718 interface->last_reset = jiffies + (10 * HZ);
1720 /* reset and initialize the hardware so it is in a known state */
1721 err = hw->mac.ops.reset_hw(hw);
1723 dev_err(&pdev->dev, "reset_hw failed: %d\n", err);
1727 err = hw->mac.ops.init_hw(hw);
1729 dev_err(&pdev->dev, "init_hw failed: %d\n", err);
1733 /* initialize hardware statistics */
1734 hw->mac.ops.update_hw_stats(hw, &interface->stats);
1736 /* Set upper limit on IOV VFs that can be allocated */
1737 pci_sriov_set_totalvfs(pdev, hw->iov.total_vfs);
1739 /* Start with random Ethernet address */
1740 eth_random_addr(hw->mac.addr);
1742 /* Initialize MAC address from hardware */
1743 err = hw->mac.ops.read_mac_addr(hw);
1745 dev_warn(&pdev->dev,
1746 "Failed to obtain MAC address defaulting to random\n");
1747 /* tag address assignment as random */
1748 netdev->addr_assign_type |= NET_ADDR_RANDOM;
1751 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1752 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1754 if (!is_valid_ether_addr(netdev->perm_addr)) {
1755 dev_err(&pdev->dev, "Invalid MAC Address\n");
1759 /* assign BAR 4 resources for use with PTP */
1760 if (fm10k_read_reg(hw, FM10K_CTRL) & FM10K_CTRL_BAR4_ALLOWED)
1761 interface->sw_addr = ioremap(pci_resource_start(pdev, 4),
1762 pci_resource_len(pdev, 4));
1763 hw->sw_addr = interface->sw_addr;
1765 /* Only the PF can support VXLAN and NVGRE offloads */
1766 if (hw->mac.type != fm10k_mac_pf) {
1767 netdev->hw_enc_features = 0;
1768 netdev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
1769 netdev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
1772 /* initialize DCBNL interface */
1773 fm10k_dcbnl_set_ops(netdev);
1775 /* Initialize service timer and service task */
1776 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1777 setup_timer(&interface->service_timer, &fm10k_service_timer,
1778 (unsigned long)interface);
1779 INIT_WORK(&interface->service_task, fm10k_service_task);
1781 /* kick off service timer now, even when interface is down */
1782 mod_timer(&interface->service_timer, (HZ * 2) + jiffies);
1784 /* Intitialize timestamp data */
1785 fm10k_ts_init(interface);
1787 /* set default ring sizes */
1788 interface->tx_ring_count = FM10K_DEFAULT_TXD;
1789 interface->rx_ring_count = FM10K_DEFAULT_RXD;
1791 /* set default interrupt moderation */
1792 interface->tx_itr = FM10K_ITR_10K;
1793 interface->rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
1795 /* initialize vxlan_port list */
1796 INIT_LIST_HEAD(&interface->vxlan_port);
1798 netdev_rss_key_fill(rss_key, sizeof(rss_key));
1799 memcpy(interface->rssrk, rss_key, sizeof(rss_key));
1801 /* Start off interface as being down */
1802 set_bit(__FM10K_DOWN, &interface->state);
1807 static void fm10k_slot_warn(struct fm10k_intfc *interface)
1809 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
1810 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
1811 struct fm10k_hw *hw = &interface->hw;
1812 int max_gts = 0, expected_gts = 0;
1814 if (pcie_get_minimum_link(interface->pdev, &speed, &width) ||
1815 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
1816 dev_warn(&interface->pdev->dev,
1817 "Unable to determine PCI Express bandwidth.\n");
1822 case PCIE_SPEED_2_5GT:
1823 /* 8b/10b encoding reduces max throughput by 20% */
1824 max_gts = 2 * width;
1826 case PCIE_SPEED_5_0GT:
1827 /* 8b/10b encoding reduces max throughput by 20% */
1828 max_gts = 4 * width;
1830 case PCIE_SPEED_8_0GT:
1831 /* 128b/130b encoding has less than 2% impact on throughput */
1832 max_gts = 8 * width;
1835 dev_warn(&interface->pdev->dev,
1836 "Unable to determine PCI Express bandwidth.\n");
1840 dev_info(&interface->pdev->dev,
1841 "PCI Express bandwidth of %dGT/s available\n",
1843 dev_info(&interface->pdev->dev,
1844 "(Speed:%s, Width: x%d, Encoding Loss:%s, Payload:%s)\n",
1845 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
1846 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
1847 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
1850 (speed == PCIE_SPEED_2_5GT ? "20%" :
1851 speed == PCIE_SPEED_5_0GT ? "20%" :
1852 speed == PCIE_SPEED_8_0GT ? "<2%" :
1854 (hw->bus.payload == fm10k_bus_payload_128 ? "128B" :
1855 hw->bus.payload == fm10k_bus_payload_256 ? "256B" :
1856 hw->bus.payload == fm10k_bus_payload_512 ? "512B" :
1859 switch (hw->bus_caps.speed) {
1860 case fm10k_bus_speed_2500:
1861 /* 8b/10b encoding reduces max throughput by 20% */
1862 expected_gts = 2 * hw->bus_caps.width;
1864 case fm10k_bus_speed_5000:
1865 /* 8b/10b encoding reduces max throughput by 20% */
1866 expected_gts = 4 * hw->bus_caps.width;
1868 case fm10k_bus_speed_8000:
1869 /* 128b/130b encoding has less than 2% impact on throughput */
1870 expected_gts = 8 * hw->bus_caps.width;
1873 dev_warn(&interface->pdev->dev,
1874 "Unable to determine expected PCI Express bandwidth.\n");
1878 if (max_gts < expected_gts) {
1879 dev_warn(&interface->pdev->dev,
1880 "This device requires %dGT/s of bandwidth for optimal performance.\n",
1882 dev_warn(&interface->pdev->dev,
1883 "A %sslot with x%d lanes is suggested.\n",
1884 (hw->bus_caps.speed == fm10k_bus_speed_2500 ? "2.5GT/s " :
1885 hw->bus_caps.speed == fm10k_bus_speed_5000 ? "5.0GT/s " :
1886 hw->bus_caps.speed == fm10k_bus_speed_8000 ? "8.0GT/s " : ""),
1887 hw->bus_caps.width);
1892 * fm10k_probe - Device Initialization Routine
1893 * @pdev: PCI device information struct
1894 * @ent: entry in fm10k_pci_tbl
1896 * Returns 0 on success, negative on failure
1898 * fm10k_probe initializes an interface identified by a pci_dev structure.
1899 * The OS initialization, configuring of the interface private structure,
1900 * and a hardware reset occur.
1902 static int fm10k_probe(struct pci_dev *pdev,
1903 const struct pci_device_id *ent)
1905 struct net_device *netdev;
1906 struct fm10k_intfc *interface;
1909 err = pci_enable_device_mem(pdev);
1913 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
1915 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1918 "DMA configuration failed: %d\n", err);
1922 err = pci_request_selected_regions(pdev,
1923 pci_select_bars(pdev,
1928 "pci_request_selected_regions failed: %d\n", err);
1932 pci_enable_pcie_error_reporting(pdev);
1934 pci_set_master(pdev);
1935 pci_save_state(pdev);
1937 netdev = fm10k_alloc_netdev();
1940 goto err_alloc_netdev;
1943 SET_NETDEV_DEV(netdev, &pdev->dev);
1945 interface = netdev_priv(netdev);
1946 pci_set_drvdata(pdev, interface);
1948 interface->netdev = netdev;
1949 interface->pdev = pdev;
1951 interface->uc_addr = ioremap(pci_resource_start(pdev, 0),
1952 FM10K_UC_ADDR_SIZE);
1953 if (!interface->uc_addr) {
1958 err = fm10k_sw_init(interface, ent);
1962 /* enable debugfs support */
1963 fm10k_dbg_intfc_init(interface);
1965 err = fm10k_init_queueing_scheme(interface);
1969 err = fm10k_mbx_request_irq(interface);
1971 goto err_mbx_interrupt;
1973 /* final check of hardware state before registering the interface */
1974 err = fm10k_hw_ready(interface);
1978 err = register_netdev(netdev);
1982 /* carrier off reporting is important to ethtool even BEFORE open */
1983 netif_carrier_off(netdev);
1985 /* stop all the transmit queues from transmitting until link is up */
1986 netif_tx_stop_all_queues(netdev);
1988 /* Register PTP interface */
1989 fm10k_ptp_register(interface);
1991 /* print warning for non-optimal configurations */
1992 fm10k_slot_warn(interface);
1994 /* report MAC address for logging */
1995 dev_info(&pdev->dev, "%pM\n", netdev->dev_addr);
1997 /* enable SR-IOV after registering netdev to enforce PF/VF ordering */
1998 fm10k_iov_configure(pdev, 0);
2000 /* clear the service task disable bit to allow service task to start */
2001 clear_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2006 fm10k_mbx_free_irq(interface);
2008 fm10k_clear_queueing_scheme(interface);
2010 if (interface->sw_addr)
2011 iounmap(interface->sw_addr);
2012 iounmap(interface->uc_addr);
2014 free_netdev(netdev);
2016 pci_release_selected_regions(pdev,
2017 pci_select_bars(pdev, IORESOURCE_MEM));
2020 pci_disable_device(pdev);
2025 * fm10k_remove - Device Removal Routine
2026 * @pdev: PCI device information struct
2028 * fm10k_remove is called by the PCI subsystem to alert the driver
2029 * that it should release a PCI device. The could be caused by a
2030 * Hot-Plug event, or because the driver is going to be removed from
2033 static void fm10k_remove(struct pci_dev *pdev)
2035 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2036 struct net_device *netdev = interface->netdev;
2038 del_timer_sync(&interface->service_timer);
2040 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2041 cancel_work_sync(&interface->service_task);
2043 /* free netdev, this may bounce the interrupts due to setup_tc */
2044 if (netdev->reg_state == NETREG_REGISTERED)
2045 unregister_netdev(netdev);
2047 /* cleanup timestamp handling */
2048 fm10k_ptp_unregister(interface);
2051 fm10k_iov_disable(pdev);
2053 /* disable mailbox interrupt */
2054 fm10k_mbx_free_irq(interface);
2056 /* free interrupts */
2057 fm10k_clear_queueing_scheme(interface);
2059 /* remove any debugfs interfaces */
2060 fm10k_dbg_intfc_exit(interface);
2062 if (interface->sw_addr)
2063 iounmap(interface->sw_addr);
2064 iounmap(interface->uc_addr);
2066 free_netdev(netdev);
2068 pci_release_selected_regions(pdev,
2069 pci_select_bars(pdev, IORESOURCE_MEM));
2071 pci_disable_pcie_error_reporting(pdev);
2073 pci_disable_device(pdev);
2078 * fm10k_resume - Restore device to pre-sleep state
2079 * @pdev: PCI device information struct
2081 * fm10k_resume is called after the system has powered back up from a sleep
2082 * state and is ready to resume operation. This function is meant to restore
2083 * the device back to its pre-sleep state.
2085 static int fm10k_resume(struct pci_dev *pdev)
2087 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2088 struct net_device *netdev = interface->netdev;
2089 struct fm10k_hw *hw = &interface->hw;
2092 pci_set_power_state(pdev, PCI_D0);
2093 pci_restore_state(pdev);
2095 /* pci_restore_state clears dev->state_saved so call
2096 * pci_save_state to restore it.
2098 pci_save_state(pdev);
2100 err = pci_enable_device_mem(pdev);
2102 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
2105 pci_set_master(pdev);
2107 pci_wake_from_d3(pdev, false);
2109 /* refresh hw_addr in case it was dropped */
2110 hw->hw_addr = interface->uc_addr;
2112 /* reset hardware to known state */
2113 err = hw->mac.ops.init_hw(&interface->hw);
2115 dev_err(&pdev->dev, "init_hw failed: %d\n", err);
2119 /* reset statistics starting values */
2120 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
2123 fm10k_ts_reset(interface);
2127 err = fm10k_init_queueing_scheme(interface);
2129 fm10k_mbx_request_irq(interface);
2130 if (netif_running(netdev))
2131 err = fm10k_open(netdev);
2139 /* assume host is not ready, to prevent race with watchdog in case we
2140 * actually don't have connection to the switch
2142 interface->host_ready = false;
2143 fm10k_watchdog_host_not_ready(interface);
2145 /* clear the service task disable bit to allow service task to start */
2146 clear_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2147 fm10k_service_event_schedule(interface);
2149 /* restore SR-IOV interface */
2150 fm10k_iov_resume(pdev);
2152 netif_device_attach(netdev);
2158 * fm10k_suspend - Prepare the device for a system sleep state
2159 * @pdev: PCI device information struct
2161 * fm10k_suspend is meant to shutdown the device prior to the system entering
2162 * a sleep state. The fm10k hardware does not support wake on lan so the
2163 * driver simply needs to shut down the device so it is in a low power state.
2165 static int fm10k_suspend(struct pci_dev *pdev,
2166 pm_message_t __always_unused state)
2168 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2169 struct net_device *netdev = interface->netdev;
2172 netif_device_detach(netdev);
2174 fm10k_iov_suspend(pdev);
2176 /* the watchdog tasks may read registers, which will appear like a
2177 * surprise-remove event once the PCI device is disabled. This will
2178 * cause us to close the netdevice, so we don't retain the open/closed
2179 * state post-resume. Prevent this by disabling the service task while
2180 * suspended, until we actually resume.
2182 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
2183 cancel_work_sync(&interface->service_task);
2187 if (netif_running(netdev))
2188 fm10k_close(netdev);
2190 fm10k_mbx_free_irq(interface);
2192 fm10k_clear_queueing_scheme(interface);
2196 err = pci_save_state(pdev);
2200 pci_disable_device(pdev);
2201 pci_wake_from_d3(pdev, false);
2202 pci_set_power_state(pdev, PCI_D3hot);
2207 #endif /* CONFIG_PM */
2209 * fm10k_io_error_detected - called when PCI error is detected
2210 * @pdev: Pointer to PCI device
2211 * @state: The current pci connection state
2213 * This function is called after a PCI bus error affecting
2214 * this device has been detected.
2216 static pci_ers_result_t fm10k_io_error_detected(struct pci_dev *pdev,
2217 pci_channel_state_t state)
2219 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2220 struct net_device *netdev = interface->netdev;
2222 netif_device_detach(netdev);
2224 if (state == pci_channel_io_perm_failure)
2225 return PCI_ERS_RESULT_DISCONNECT;
2227 if (netif_running(netdev))
2228 fm10k_close(netdev);
2230 /* free interrupts */
2231 fm10k_clear_queueing_scheme(interface);
2233 fm10k_mbx_free_irq(interface);
2235 pci_disable_device(pdev);
2237 /* Request a slot reset. */
2238 return PCI_ERS_RESULT_NEED_RESET;
2242 * fm10k_io_slot_reset - called after the pci bus has been reset.
2243 * @pdev: Pointer to PCI device
2245 * Restart the card from scratch, as if from a cold-boot.
2247 static pci_ers_result_t fm10k_io_slot_reset(struct pci_dev *pdev)
2249 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2250 pci_ers_result_t result;
2252 if (pci_enable_device_mem(pdev)) {
2254 "Cannot re-enable PCI device after reset.\n");
2255 result = PCI_ERS_RESULT_DISCONNECT;
2257 pci_set_master(pdev);
2258 pci_restore_state(pdev);
2260 /* After second error pci->state_saved is false, this
2261 * resets it so EEH doesn't break.
2263 pci_save_state(pdev);
2265 pci_wake_from_d3(pdev, false);
2267 /* refresh hw_addr in case it was dropped */
2268 interface->hw.hw_addr = interface->uc_addr;
2270 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
2271 fm10k_service_event_schedule(interface);
2273 result = PCI_ERS_RESULT_RECOVERED;
2276 pci_cleanup_aer_uncorrect_error_status(pdev);
2282 * fm10k_io_resume - called when traffic can start flowing again.
2283 * @pdev: Pointer to PCI device
2285 * This callback is called when the error recovery driver tells us that
2286 * its OK to resume normal operation.
2288 static void fm10k_io_resume(struct pci_dev *pdev)
2290 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
2291 struct net_device *netdev = interface->netdev;
2292 struct fm10k_hw *hw = &interface->hw;
2295 /* reset hardware to known state */
2296 err = hw->mac.ops.init_hw(&interface->hw);
2298 dev_err(&pdev->dev, "init_hw failed: %d\n", err);
2302 /* reset statistics starting values */
2303 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
2305 err = fm10k_init_queueing_scheme(interface);
2307 dev_err(&interface->pdev->dev, "init_queueing_scheme failed: %d\n", err);
2311 /* reassociate interrupts */
2312 fm10k_mbx_request_irq(interface);
2315 fm10k_ts_reset(interface);
2317 if (netif_running(netdev))
2318 err = fm10k_open(netdev);
2320 /* final check of hardware state before registering the interface */
2321 err = err ? : fm10k_hw_ready(interface);
2324 netif_device_attach(netdev);
2327 static const struct pci_error_handlers fm10k_err_handler = {
2328 .error_detected = fm10k_io_error_detected,
2329 .slot_reset = fm10k_io_slot_reset,
2330 .resume = fm10k_io_resume,
2333 static struct pci_driver fm10k_driver = {
2334 .name = fm10k_driver_name,
2335 .id_table = fm10k_pci_tbl,
2336 .probe = fm10k_probe,
2337 .remove = fm10k_remove,
2339 .suspend = fm10k_suspend,
2340 .resume = fm10k_resume,
2342 .sriov_configure = fm10k_iov_configure,
2343 .err_handler = &fm10k_err_handler
2347 * fm10k_register_pci_driver - register driver interface
2349 * This funciton is called on module load in order to register the driver.
2351 int fm10k_register_pci_driver(void)
2353 return pci_register_driver(&fm10k_driver);
2357 * fm10k_unregister_pci_driver - unregister driver interface
2359 * This funciton is called on module unload in order to remove the driver.
2361 void fm10k_unregister_pci_driver(void)
2363 pci_unregister_driver(&fm10k_driver);