1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 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,
31 * fm10k_pci_tbl - PCI Device ID Table
33 * Wildcard entries (PCI_ANY_ID) should come last
34 * Last entry must be all 0s
36 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
37 * Class, Class Mask, private data (not used) }
39 static const struct pci_device_id fm10k_pci_tbl[] = {
40 { PCI_VDEVICE(INTEL, FM10K_DEV_ID_PF), fm10k_device_pf },
41 /* required last entry */
44 MODULE_DEVICE_TABLE(pci, fm10k_pci_tbl);
46 u16 fm10k_read_pci_cfg_word(struct fm10k_hw *hw, u32 reg)
48 struct fm10k_intfc *interface = hw->back;
51 if (FM10K_REMOVED(hw->hw_addr))
54 pci_read_config_word(interface->pdev, reg, &value);
56 fm10k_write_flush(hw);
61 u32 fm10k_read_reg(struct fm10k_hw *hw, int reg)
63 u32 __iomem *hw_addr = ACCESS_ONCE(hw->hw_addr);
66 if (FM10K_REMOVED(hw_addr))
69 value = readl(&hw_addr[reg]);
70 if (!(~value) && (!reg || !(~readl(hw_addr)))) {
71 struct fm10k_intfc *interface = hw->back;
72 struct net_device *netdev = interface->netdev;
75 netif_device_detach(netdev);
76 netdev_err(netdev, "PCIe link lost, device now detached\n");
82 static int fm10k_hw_ready(struct fm10k_intfc *interface)
84 struct fm10k_hw *hw = &interface->hw;
86 fm10k_write_flush(hw);
88 return FM10K_REMOVED(hw->hw_addr) ? -ENODEV : 0;
91 void fm10k_service_event_schedule(struct fm10k_intfc *interface)
93 if (!test_bit(__FM10K_SERVICE_DISABLE, &interface->state) &&
94 !test_and_set_bit(__FM10K_SERVICE_SCHED, &interface->state))
95 schedule_work(&interface->service_task);
98 static void fm10k_service_event_complete(struct fm10k_intfc *interface)
100 BUG_ON(!test_bit(__FM10K_SERVICE_SCHED, &interface->state));
102 /* flush memory to make sure state is correct before next watchog */
103 smp_mb__before_atomic();
104 clear_bit(__FM10K_SERVICE_SCHED, &interface->state);
108 * fm10k_service_timer - Timer Call-back
109 * @data: pointer to interface cast into an unsigned long
111 static void fm10k_service_timer(unsigned long data)
113 struct fm10k_intfc *interface = (struct fm10k_intfc *)data;
115 /* Reset the timer */
116 mod_timer(&interface->service_timer, (HZ * 2) + jiffies);
118 fm10k_service_event_schedule(interface);
121 static void fm10k_detach_subtask(struct fm10k_intfc *interface)
123 struct net_device *netdev = interface->netdev;
125 /* do nothing if device is still present or hw_addr is set */
126 if (netif_device_present(netdev) || interface->hw.hw_addr)
131 if (netif_running(netdev))
137 static void fm10k_reinit(struct fm10k_intfc *interface)
139 struct net_device *netdev = interface->netdev;
140 struct fm10k_hw *hw = &interface->hw;
143 WARN_ON(in_interrupt());
145 /* put off any impending NetWatchDogTimeout */
146 netdev->trans_start = jiffies;
148 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
149 usleep_range(1000, 2000);
153 if (netif_running(netdev))
156 fm10k_mbx_free_irq(interface);
158 /* delay any future reset requests */
159 interface->last_reset = jiffies + (10 * HZ);
161 /* reset and initialize the hardware so it is in a known state */
162 err = hw->mac.ops.reset_hw(hw) ? : hw->mac.ops.init_hw(hw);
164 dev_err(&interface->pdev->dev, "init_hw failed: %d\n", err);
166 /* reassociate interrupts */
167 fm10k_mbx_request_irq(interface);
169 if (netif_running(netdev))
174 clear_bit(__FM10K_RESETTING, &interface->state);
177 static void fm10k_reset_subtask(struct fm10k_intfc *interface)
179 if (!(interface->flags & FM10K_FLAG_RESET_REQUESTED))
182 interface->flags &= ~FM10K_FLAG_RESET_REQUESTED;
184 netdev_err(interface->netdev, "Reset interface\n");
185 interface->tx_timeout_count++;
187 fm10k_reinit(interface);
191 * fm10k_configure_swpri_map - Configure Receive SWPRI to PC mapping
192 * @interface: board private structure
194 * Configure the SWPRI to PC mapping for the port.
196 static void fm10k_configure_swpri_map(struct fm10k_intfc *interface)
198 struct net_device *netdev = interface->netdev;
199 struct fm10k_hw *hw = &interface->hw;
202 /* clear flag indicating update is needed */
203 interface->flags &= ~FM10K_FLAG_SWPRI_CONFIG;
205 /* these registers are only available on the PF */
206 if (hw->mac.type != fm10k_mac_pf)
209 /* configure SWPRI to PC map */
210 for (i = 0; i < FM10K_SWPRI_MAX; i++)
211 fm10k_write_reg(hw, FM10K_SWPRI_MAP(i),
212 netdev_get_prio_tc_map(netdev, i));
216 * fm10k_watchdog_update_host_state - Update the link status based on host.
217 * @interface: board private structure
219 static void fm10k_watchdog_update_host_state(struct fm10k_intfc *interface)
221 struct fm10k_hw *hw = &interface->hw;
224 if (test_bit(__FM10K_LINK_DOWN, &interface->state)) {
225 interface->host_ready = false;
226 if (time_is_after_jiffies(interface->link_down_event))
228 clear_bit(__FM10K_LINK_DOWN, &interface->state);
231 if (interface->flags & FM10K_FLAG_SWPRI_CONFIG) {
232 if (rtnl_trylock()) {
233 fm10k_configure_swpri_map(interface);
238 /* lock the mailbox for transmit and receive */
239 fm10k_mbx_lock(interface);
241 err = hw->mac.ops.get_host_state(hw, &interface->host_ready);
242 if (err && time_is_before_jiffies(interface->last_reset))
243 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
246 fm10k_mbx_unlock(interface);
250 * fm10k_mbx_subtask - Process upstream and downstream mailboxes
251 * @interface: board private structure
253 * This function will process both the upstream and downstream mailboxes.
254 * It is necessary for us to hold the rtnl_lock while doing this as the
255 * mailbox accesses are protected by this lock.
257 static void fm10k_mbx_subtask(struct fm10k_intfc *interface)
259 /* process upstream mailbox and update device state */
260 fm10k_watchdog_update_host_state(interface);
264 * fm10k_watchdog_host_is_ready - Update netdev status based on host ready
265 * @interface: board private structure
267 static void fm10k_watchdog_host_is_ready(struct fm10k_intfc *interface)
269 struct net_device *netdev = interface->netdev;
271 /* only continue if link state is currently down */
272 if (netif_carrier_ok(netdev))
275 netif_info(interface, drv, netdev, "NIC Link is up\n");
277 netif_carrier_on(netdev);
278 netif_tx_wake_all_queues(netdev);
282 * fm10k_watchdog_host_not_ready - Update netdev status based on host not ready
283 * @interface: board private structure
285 static void fm10k_watchdog_host_not_ready(struct fm10k_intfc *interface)
287 struct net_device *netdev = interface->netdev;
289 /* only continue if link state is currently up */
290 if (!netif_carrier_ok(netdev))
293 netif_info(interface, drv, netdev, "NIC Link is down\n");
295 netif_carrier_off(netdev);
296 netif_tx_stop_all_queues(netdev);
300 * fm10k_update_stats - Update the board statistics counters.
301 * @interface: board private structure
303 void fm10k_update_stats(struct fm10k_intfc *interface)
305 struct net_device_stats *net_stats = &interface->netdev->stats;
306 struct fm10k_hw *hw = &interface->hw;
307 u64 rx_errors = 0, rx_csum_errors = 0, tx_csum_errors = 0;
308 u64 restart_queue = 0, tx_busy = 0, alloc_failed = 0;
309 u64 rx_bytes_nic = 0, rx_pkts_nic = 0, rx_drops_nic = 0;
310 u64 tx_bytes_nic = 0, tx_pkts_nic = 0;
314 /* do not allow stats update via service task for next second */
315 interface->next_stats_update = jiffies + HZ;
317 /* gather some stats to the interface struct that are per queue */
318 for (bytes = 0, pkts = 0, i = 0; i < interface->num_tx_queues; i++) {
319 struct fm10k_ring *tx_ring = interface->tx_ring[i];
321 restart_queue += tx_ring->tx_stats.restart_queue;
322 tx_busy += tx_ring->tx_stats.tx_busy;
323 tx_csum_errors += tx_ring->tx_stats.csum_err;
324 bytes += tx_ring->stats.bytes;
325 pkts += tx_ring->stats.packets;
328 interface->restart_queue = restart_queue;
329 interface->tx_busy = tx_busy;
330 net_stats->tx_bytes = bytes;
331 net_stats->tx_packets = pkts;
332 interface->tx_csum_errors = tx_csum_errors;
333 /* gather some stats to the interface struct that are per queue */
334 for (bytes = 0, pkts = 0, i = 0; i < interface->num_rx_queues; i++) {
335 struct fm10k_ring *rx_ring = interface->rx_ring[i];
337 bytes += rx_ring->stats.bytes;
338 pkts += rx_ring->stats.packets;
339 alloc_failed += rx_ring->rx_stats.alloc_failed;
340 rx_csum_errors += rx_ring->rx_stats.csum_err;
341 rx_errors += rx_ring->rx_stats.errors;
344 net_stats->rx_bytes = bytes;
345 net_stats->rx_packets = pkts;
346 interface->alloc_failed = alloc_failed;
347 interface->rx_csum_errors = rx_csum_errors;
348 interface->rx_errors = rx_errors;
350 hw->mac.ops.update_hw_stats(hw, &interface->stats);
352 for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
353 struct fm10k_hw_stats_q *q = &interface->stats.q[i];
355 tx_bytes_nic += q->tx_bytes.count;
356 tx_pkts_nic += q->tx_packets.count;
357 rx_bytes_nic += q->rx_bytes.count;
358 rx_pkts_nic += q->rx_packets.count;
359 rx_drops_nic += q->rx_drops.count;
362 interface->tx_bytes_nic = tx_bytes_nic;
363 interface->tx_packets_nic = tx_pkts_nic;
364 interface->rx_bytes_nic = rx_bytes_nic;
365 interface->rx_packets_nic = rx_pkts_nic;
366 interface->rx_drops_nic = rx_drops_nic;
368 /* Fill out the OS statistics structure */
369 net_stats->rx_errors = interface->stats.xec.count;
370 net_stats->rx_dropped = interface->stats.nodesc_drop.count;
374 * fm10k_watchdog_flush_tx - flush queues on host not ready
375 * @interface - pointer to the device interface structure
377 static void fm10k_watchdog_flush_tx(struct fm10k_intfc *interface)
379 int some_tx_pending = 0;
382 /* nothing to do if carrier is up */
383 if (netif_carrier_ok(interface->netdev))
386 for (i = 0; i < interface->num_tx_queues; i++) {
387 struct fm10k_ring *tx_ring = interface->tx_ring[i];
389 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
395 /* We've lost link, so the controller stops DMA, but we've got
396 * queued Tx work that's never going to get done, so reset
397 * controller to flush Tx.
400 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
404 * fm10k_watchdog_subtask - check and bring link up
405 * @interface - pointer to the device interface structure
407 static void fm10k_watchdog_subtask(struct fm10k_intfc *interface)
409 /* if interface is down do nothing */
410 if (test_bit(__FM10K_DOWN, &interface->state) ||
411 test_bit(__FM10K_RESETTING, &interface->state))
414 if (interface->host_ready)
415 fm10k_watchdog_host_is_ready(interface);
417 fm10k_watchdog_host_not_ready(interface);
419 /* update stats only once every second */
420 if (time_is_before_jiffies(interface->next_stats_update))
421 fm10k_update_stats(interface);
423 /* flush any uncompleted work */
424 fm10k_watchdog_flush_tx(interface);
428 * fm10k_check_hang_subtask - check for hung queues and dropped interrupts
429 * @interface - pointer to the device interface structure
431 * This function serves two purposes. First it strobes the interrupt lines
432 * in order to make certain interrupts are occurring. Secondly it sets the
433 * bits needed to check for TX hangs. As a result we should immediately
434 * determine if a hang has occurred.
436 static void fm10k_check_hang_subtask(struct fm10k_intfc *interface)
440 /* If we're down or resetting, just bail */
441 if (test_bit(__FM10K_DOWN, &interface->state) ||
442 test_bit(__FM10K_RESETTING, &interface->state))
445 /* rate limit tx hang checks to only once every 2 seconds */
446 if (time_is_after_eq_jiffies(interface->next_tx_hang_check))
448 interface->next_tx_hang_check = jiffies + (2 * HZ);
450 if (netif_carrier_ok(interface->netdev)) {
451 /* Force detection of hung controller */
452 for (i = 0; i < interface->num_tx_queues; i++)
453 set_check_for_tx_hang(interface->tx_ring[i]);
455 /* Rearm all in-use q_vectors for immediate firing */
456 for (i = 0; i < interface->num_q_vectors; i++) {
457 struct fm10k_q_vector *qv = interface->q_vector[i];
459 if (!qv->tx.count && !qv->rx.count)
461 writel(FM10K_ITR_ENABLE | FM10K_ITR_PENDING2, qv->itr);
467 * fm10k_service_task - manages and runs subtasks
468 * @work: pointer to work_struct containing our data
470 static void fm10k_service_task(struct work_struct *work)
472 struct fm10k_intfc *interface;
474 interface = container_of(work, struct fm10k_intfc, service_task);
476 /* tasks always capable of running, but must be rtnl protected */
477 fm10k_mbx_subtask(interface);
478 fm10k_detach_subtask(interface);
479 fm10k_reset_subtask(interface);
481 /* tasks only run when interface is up */
482 fm10k_watchdog_subtask(interface);
483 fm10k_check_hang_subtask(interface);
485 /* release lock on service events to allow scheduling next event */
486 fm10k_service_event_complete(interface);
490 * fm10k_configure_tx_ring - Configure Tx ring after Reset
491 * @interface: board private structure
492 * @ring: structure containing ring specific data
494 * Configure the Tx descriptor ring after a reset.
496 static void fm10k_configure_tx_ring(struct fm10k_intfc *interface,
497 struct fm10k_ring *ring)
499 struct fm10k_hw *hw = &interface->hw;
500 u64 tdba = ring->dma;
501 u32 size = ring->count * sizeof(struct fm10k_tx_desc);
502 u32 txint = FM10K_INT_MAP_DISABLE;
503 u32 txdctl = FM10K_TXDCTL_ENABLE | (1 << FM10K_TXDCTL_MAX_TIME_SHIFT);
504 u8 reg_idx = ring->reg_idx;
506 /* disable queue to avoid issues while updating state */
507 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), 0);
508 fm10k_write_flush(hw);
510 /* possible poll here to verify ring resources have been cleaned */
512 /* set location and size for descriptor ring */
513 fm10k_write_reg(hw, FM10K_TDBAL(reg_idx), tdba & DMA_BIT_MASK(32));
514 fm10k_write_reg(hw, FM10K_TDBAH(reg_idx), tdba >> 32);
515 fm10k_write_reg(hw, FM10K_TDLEN(reg_idx), size);
517 /* reset head and tail pointers */
518 fm10k_write_reg(hw, FM10K_TDH(reg_idx), 0);
519 fm10k_write_reg(hw, FM10K_TDT(reg_idx), 0);
521 /* store tail pointer */
522 ring->tail = &interface->uc_addr[FM10K_TDT(reg_idx)];
524 /* reset ntu and ntc to place SW in sync with hardwdare */
525 ring->next_to_clean = 0;
526 ring->next_to_use = 0;
529 if (ring->q_vector) {
530 txint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
531 txint |= FM10K_INT_MAP_TIMER0;
534 fm10k_write_reg(hw, FM10K_TXINT(reg_idx), txint);
536 /* enable use of FTAG bit in Tx descriptor, register is RO for VF */
537 fm10k_write_reg(hw, FM10K_PFVTCTL(reg_idx),
538 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
541 fm10k_write_reg(hw, FM10K_TXDCTL(reg_idx), txdctl);
545 * fm10k_enable_tx_ring - Verify Tx ring is enabled after configuration
546 * @interface: board private structure
547 * @ring: structure containing ring specific data
549 * Verify the Tx descriptor ring is ready for transmit.
551 static void fm10k_enable_tx_ring(struct fm10k_intfc *interface,
552 struct fm10k_ring *ring)
554 struct fm10k_hw *hw = &interface->hw;
557 u8 reg_idx = ring->reg_idx;
559 /* if we are already enabled just exit */
560 if (fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx)) & FM10K_TXDCTL_ENABLE)
563 /* poll to verify queue is enabled */
565 usleep_range(1000, 2000);
566 txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(reg_idx));
567 } while (!(txdctl & FM10K_TXDCTL_ENABLE) && --wait_loop);
569 netif_err(interface, drv, interface->netdev,
570 "Could not enable Tx Queue %d\n", reg_idx);
574 * fm10k_configure_tx - Configure Transmit Unit after Reset
575 * @interface: board private structure
577 * Configure the Tx unit of the MAC after a reset.
579 static void fm10k_configure_tx(struct fm10k_intfc *interface)
583 /* Setup the HW Tx Head and Tail descriptor pointers */
584 for (i = 0; i < interface->num_tx_queues; i++)
585 fm10k_configure_tx_ring(interface, interface->tx_ring[i]);
587 /* poll here to verify that Tx rings are now enabled */
588 for (i = 0; i < interface->num_tx_queues; i++)
589 fm10k_enable_tx_ring(interface, interface->tx_ring[i]);
593 * fm10k_configure_rx_ring - Configure Rx ring after Reset
594 * @interface: board private structure
595 * @ring: structure containing ring specific data
597 * Configure the Rx descriptor ring after a reset.
599 static void fm10k_configure_rx_ring(struct fm10k_intfc *interface,
600 struct fm10k_ring *ring)
602 u64 rdba = ring->dma;
603 struct fm10k_hw *hw = &interface->hw;
604 u32 size = ring->count * sizeof(union fm10k_rx_desc);
605 u32 rxqctl = FM10K_RXQCTL_ENABLE | FM10K_RXQCTL_PF;
606 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
607 u32 srrctl = FM10K_SRRCTL_BUFFER_CHAINING_EN;
608 u32 rxint = FM10K_INT_MAP_DISABLE;
609 u8 rx_pause = interface->rx_pause;
610 u8 reg_idx = ring->reg_idx;
612 /* disable queue to avoid issues while updating state */
613 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), 0);
614 fm10k_write_flush(hw);
616 /* possible poll here to verify ring resources have been cleaned */
618 /* set location and size for descriptor ring */
619 fm10k_write_reg(hw, FM10K_RDBAL(reg_idx), rdba & DMA_BIT_MASK(32));
620 fm10k_write_reg(hw, FM10K_RDBAH(reg_idx), rdba >> 32);
621 fm10k_write_reg(hw, FM10K_RDLEN(reg_idx), size);
623 /* reset head and tail pointers */
624 fm10k_write_reg(hw, FM10K_RDH(reg_idx), 0);
625 fm10k_write_reg(hw, FM10K_RDT(reg_idx), 0);
627 /* store tail pointer */
628 ring->tail = &interface->uc_addr[FM10K_RDT(reg_idx)];
630 /* reset ntu and ntc to place SW in sync with hardwdare */
631 ring->next_to_clean = 0;
632 ring->next_to_use = 0;
633 ring->next_to_alloc = 0;
635 /* Configure the Rx buffer size for one buff without split */
636 srrctl |= FM10K_RX_BUFSZ >> FM10K_SRRCTL_BSIZEPKT_SHIFT;
638 /* Configure the Rx ring to supress loopback packets */
639 srrctl |= FM10K_SRRCTL_LOOPBACK_SUPPRESS;
640 fm10k_write_reg(hw, FM10K_SRRCTL(reg_idx), srrctl);
642 /* Enable drop on empty */
643 #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
644 if (interface->pfc_en)
645 rx_pause = interface->pfc_en;
647 if (!(rx_pause & (1 << ring->qos_pc)))
648 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
650 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
652 /* assign default VLAN to queue */
653 ring->vid = hw->mac.default_vid;
656 if (ring->q_vector) {
657 rxint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
658 rxint |= FM10K_INT_MAP_TIMER1;
661 fm10k_write_reg(hw, FM10K_RXINT(reg_idx), rxint);
664 fm10k_write_reg(hw, FM10K_RXQCTL(reg_idx), rxqctl);
666 /* place buffers on ring for receive data */
667 fm10k_alloc_rx_buffers(ring, fm10k_desc_unused(ring));
671 * fm10k_update_rx_drop_en - Configures the drop enable bits for Rx rings
672 * @interface: board private structure
674 * Configure the drop enable bits for the Rx rings.
676 void fm10k_update_rx_drop_en(struct fm10k_intfc *interface)
678 struct fm10k_hw *hw = &interface->hw;
679 u8 rx_pause = interface->rx_pause;
682 #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
683 if (interface->pfc_en)
684 rx_pause = interface->pfc_en;
687 for (i = 0; i < interface->num_rx_queues; i++) {
688 struct fm10k_ring *ring = interface->rx_ring[i];
689 u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
690 u8 reg_idx = ring->reg_idx;
692 if (!(rx_pause & (1 << ring->qos_pc)))
693 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
695 fm10k_write_reg(hw, FM10K_RXDCTL(reg_idx), rxdctl);
700 * fm10k_configure_dglort - Configure Receive DGLORT after reset
701 * @interface: board private structure
703 * Configure the DGLORT description and RSS tables.
705 static void fm10k_configure_dglort(struct fm10k_intfc *interface)
707 struct fm10k_dglort_cfg dglort = { 0 };
708 struct fm10k_hw *hw = &interface->hw;
712 /* Fill out hash function seeds */
713 for (i = 0; i < FM10K_RSSRK_SIZE; i++)
714 fm10k_write_reg(hw, FM10K_RSSRK(0, i), interface->rssrk[i]);
716 /* Write RETA table to hardware */
717 for (i = 0; i < FM10K_RETA_SIZE; i++)
718 fm10k_write_reg(hw, FM10K_RETA(0, i), interface->reta[i]);
720 /* Generate RSS hash based on packet types, TCP/UDP
721 * port numbers and/or IPv4/v6 src and dst addresses
723 mrqc = FM10K_MRQC_IPV4 |
724 FM10K_MRQC_TCP_IPV4 |
728 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
729 mrqc |= FM10K_MRQC_UDP_IPV4;
730 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
731 mrqc |= FM10K_MRQC_UDP_IPV6;
733 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
735 /* configure default DGLORT mapping for RSS/DCB */
736 dglort.inner_rss = 1;
737 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
738 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
739 hw->mac.ops.configure_dglort_map(hw, &dglort);
741 /* assign GLORT per queue for queue mapped testing */
742 if (interface->glort_count > 64) {
743 memset(&dglort, 0, sizeof(dglort));
744 dglort.inner_rss = 1;
745 dglort.glort = interface->glort + 64;
746 dglort.idx = fm10k_dglort_pf_queue;
747 dglort.queue_l = fls(interface->num_rx_queues - 1);
748 hw->mac.ops.configure_dglort_map(hw, &dglort);
751 /* assign glort value for RSS/DCB specific to this interface */
752 memset(&dglort, 0, sizeof(dglort));
753 dglort.inner_rss = 1;
754 dglort.glort = interface->glort;
755 dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask);
756 dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask);
757 /* configure DGLORT mapping for RSS/DCB */
758 dglort.idx = fm10k_dglort_pf_rss;
759 hw->mac.ops.configure_dglort_map(hw, &dglort);
763 * fm10k_configure_rx - Configure Receive Unit after Reset
764 * @interface: board private structure
766 * Configure the Rx unit of the MAC after a reset.
768 static void fm10k_configure_rx(struct fm10k_intfc *interface)
772 /* Configure SWPRI to PC map */
773 fm10k_configure_swpri_map(interface);
775 /* Configure RSS and DGLORT map */
776 fm10k_configure_dglort(interface);
778 /* Setup the HW Rx Head and Tail descriptor pointers */
779 for (i = 0; i < interface->num_rx_queues; i++)
780 fm10k_configure_rx_ring(interface, interface->rx_ring[i]);
782 /* possible poll here to verify that Rx rings are now enabled */
785 static void fm10k_napi_enable_all(struct fm10k_intfc *interface)
787 struct fm10k_q_vector *q_vector;
790 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
791 q_vector = interface->q_vector[q_idx];
792 napi_enable(&q_vector->napi);
796 static irqreturn_t fm10k_msix_clean_rings(int irq, void *data)
798 struct fm10k_q_vector *q_vector = data;
800 if (q_vector->rx.count || q_vector->tx.count)
801 napi_schedule(&q_vector->napi);
806 #define FM10K_ERR_MSG(type) case (type): error = #type; break
807 static void fm10k_print_fault(struct fm10k_intfc *interface, int type,
808 struct fm10k_fault *fault)
810 struct pci_dev *pdev = interface->pdev;
814 case FM10K_PCA_FAULT:
815 switch (fault->type) {
817 error = "Unknown PCA error";
819 FM10K_ERR_MSG(PCA_NO_FAULT);
820 FM10K_ERR_MSG(PCA_UNMAPPED_ADDR);
821 FM10K_ERR_MSG(PCA_BAD_QACCESS_PF);
822 FM10K_ERR_MSG(PCA_BAD_QACCESS_VF);
823 FM10K_ERR_MSG(PCA_MALICIOUS_REQ);
824 FM10K_ERR_MSG(PCA_POISONED_TLP);
825 FM10K_ERR_MSG(PCA_TLP_ABORT);
828 case FM10K_THI_FAULT:
829 switch (fault->type) {
831 error = "Unknown THI error";
833 FM10K_ERR_MSG(THI_NO_FAULT);
834 FM10K_ERR_MSG(THI_MAL_DIS_Q_FAULT);
837 case FM10K_FUM_FAULT:
838 switch (fault->type) {
840 error = "Unknown FUM error";
842 FM10K_ERR_MSG(FUM_NO_FAULT);
843 FM10K_ERR_MSG(FUM_UNMAPPED_ADDR);
844 FM10K_ERR_MSG(FUM_BAD_VF_QACCESS);
845 FM10K_ERR_MSG(FUM_ADD_DECODE_ERR);
846 FM10K_ERR_MSG(FUM_RO_ERROR);
847 FM10K_ERR_MSG(FUM_QPRC_CRC_ERROR);
848 FM10K_ERR_MSG(FUM_CSR_TIMEOUT);
849 FM10K_ERR_MSG(FUM_INVALID_TYPE);
850 FM10K_ERR_MSG(FUM_INVALID_LENGTH);
851 FM10K_ERR_MSG(FUM_INVALID_BE);
852 FM10K_ERR_MSG(FUM_INVALID_ALIGN);
856 error = "Undocumented fault";
861 "%s Address: 0x%llx SpecInfo: 0x%x Func: %02x.%0x\n",
862 error, fault->address, fault->specinfo,
863 PCI_SLOT(fault->func), PCI_FUNC(fault->func));
866 static void fm10k_report_fault(struct fm10k_intfc *interface, u32 eicr)
868 struct fm10k_hw *hw = &interface->hw;
869 struct fm10k_fault fault = { 0 };
872 for (eicr &= FM10K_EICR_FAULT_MASK, type = FM10K_PCA_FAULT;
874 eicr >>= 1, type += FM10K_FAULT_SIZE) {
875 /* only check if there is an error reported */
879 /* retrieve fault info */
880 err = hw->mac.ops.get_fault(hw, type, &fault);
882 dev_err(&interface->pdev->dev,
883 "error reading fault\n");
887 fm10k_print_fault(interface, type, &fault);
891 static void fm10k_reset_drop_on_empty(struct fm10k_intfc *interface, u32 eicr)
893 struct fm10k_hw *hw = &interface->hw;
894 const u32 rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
898 if (!(eicr & FM10K_EICR_MAXHOLDTIME))
901 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(7));
903 fm10k_write_reg(hw, FM10K_MAXHOLDQ(7), maxholdq);
905 if (maxholdq & (1 << 31)) {
906 if (q < FM10K_MAX_QUEUES_PF) {
907 interface->rx_overrun_pf++;
908 fm10k_write_reg(hw, FM10K_RXDCTL(q), rxdctl);
910 interface->rx_overrun_vf++;
924 maxholdq = fm10k_read_reg(hw, FM10K_MAXHOLDQ(q / 32));
926 fm10k_write_reg(hw, FM10K_MAXHOLDQ(q / 32), maxholdq);
930 static irqreturn_t fm10k_msix_mbx_pf(int irq, void *data)
932 struct fm10k_intfc *interface = data;
933 struct fm10k_hw *hw = &interface->hw;
934 struct fm10k_mbx_info *mbx = &hw->mbx;
937 /* unmask any set bits related to this interrupt */
938 eicr = fm10k_read_reg(hw, FM10K_EICR);
939 fm10k_write_reg(hw, FM10K_EICR, eicr & (FM10K_EICR_MAILBOX |
940 FM10K_EICR_SWITCHREADY |
941 FM10K_EICR_SWITCHNOTREADY));
943 /* report any faults found to the message log */
944 fm10k_report_fault(interface, eicr);
946 /* reset any queues disabled due to receiver overrun */
947 fm10k_reset_drop_on_empty(interface, eicr);
949 /* service mailboxes */
950 if (fm10k_mbx_trylock(interface)) {
951 mbx->ops.process(hw, mbx);
952 fm10k_mbx_unlock(interface);
955 /* if switch toggled state we should reset GLORTs */
956 if (eicr & FM10K_EICR_SWITCHNOTREADY) {
957 /* force link down for at least 4 seconds */
958 interface->link_down_event = jiffies + (4 * HZ);
959 set_bit(__FM10K_LINK_DOWN, &interface->state);
961 /* reset dglort_map back to no config */
962 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
965 /* we should validate host state after interrupt event */
966 hw->mac.get_host_state = 1;
967 fm10k_service_event_schedule(interface);
969 /* re-enable mailbox interrupt and indicate 20us delay */
970 fm10k_write_reg(hw, FM10K_ITR(FM10K_MBX_VECTOR),
971 FM10K_ITR_ENABLE | FM10K_MBX_INT_DELAY);
976 void fm10k_mbx_free_irq(struct fm10k_intfc *interface)
978 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
979 struct fm10k_hw *hw = &interface->hw;
982 /* disconnect the mailbox */
983 hw->mbx.ops.disconnect(hw, &hw->mbx);
985 /* disable Mailbox cause */
986 if (hw->mac.type == fm10k_mac_pf) {
987 fm10k_write_reg(hw, FM10K_EIMR,
988 FM10K_EIMR_DISABLE(PCA_FAULT) |
989 FM10K_EIMR_DISABLE(FUM_FAULT) |
990 FM10K_EIMR_DISABLE(MAILBOX) |
991 FM10K_EIMR_DISABLE(SWITCHREADY) |
992 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
993 FM10K_EIMR_DISABLE(SRAMERROR) |
994 FM10K_EIMR_DISABLE(VFLR) |
995 FM10K_EIMR_DISABLE(MAXHOLDTIME));
996 itr_reg = FM10K_ITR(FM10K_MBX_VECTOR);
999 fm10k_write_reg(hw, itr_reg, FM10K_ITR_MASK_SET);
1001 free_irq(entry->vector, interface);
1004 /* generic error handler for mailbox issues */
1005 static s32 fm10k_mbx_error(struct fm10k_hw *hw, u32 **results,
1006 struct fm10k_mbx_info *mbx)
1008 struct fm10k_intfc *interface;
1009 struct pci_dev *pdev;
1011 interface = container_of(hw, struct fm10k_intfc, hw);
1012 pdev = interface->pdev;
1014 dev_err(&pdev->dev, "Unknown message ID %u\n",
1015 **results & FM10K_TLV_ID_MASK);
1020 static s32 fm10k_lport_map(struct fm10k_hw *hw, u32 **results,
1021 struct fm10k_mbx_info *mbx)
1023 struct fm10k_intfc *interface;
1024 u32 dglort_map = hw->mac.dglort_map;
1027 err = fm10k_msg_lport_map_pf(hw, results, mbx);
1031 interface = container_of(hw, struct fm10k_intfc, hw);
1033 /* we need to reset if port count was just updated */
1034 if (dglort_map != hw->mac.dglort_map)
1035 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1040 static s32 fm10k_update_pvid(struct fm10k_hw *hw, u32 **results,
1041 struct fm10k_mbx_info *mbx)
1043 struct fm10k_intfc *interface;
1048 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1053 /* extract values from the pvid update */
1054 glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1055 pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1057 /* if glort is not valid return error */
1058 if (!fm10k_glort_valid_pf(hw, glort))
1059 return FM10K_ERR_PARAM;
1061 /* verify VID is valid */
1062 if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1063 return FM10K_ERR_PARAM;
1065 interface = container_of(hw, struct fm10k_intfc, hw);
1067 /* we need to reset if default VLAN was just updated */
1068 if (pvid != hw->mac.default_vid)
1069 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1071 hw->mac.default_vid = pvid;
1076 static const struct fm10k_msg_data pf_mbx_data[] = {
1077 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1078 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1079 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_lport_map),
1080 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1081 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1082 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_update_pvid),
1083 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_mbx_error),
1086 static int fm10k_mbx_request_irq_pf(struct fm10k_intfc *interface)
1088 struct msix_entry *entry = &interface->msix_entries[FM10K_MBX_VECTOR];
1089 struct net_device *dev = interface->netdev;
1090 struct fm10k_hw *hw = &interface->hw;
1093 /* Use timer0 for interrupt moderation on the mailbox */
1094 u32 mbx_itr = FM10K_INT_MAP_TIMER0 | entry->entry;
1095 u32 other_itr = FM10K_INT_MAP_IMMEDIATE | entry->entry;
1097 /* register mailbox handlers */
1098 err = hw->mbx.ops.register_handlers(&hw->mbx, pf_mbx_data);
1102 /* request the IRQ */
1103 err = request_irq(entry->vector, fm10k_msix_mbx_pf, 0,
1104 dev->name, interface);
1106 netif_err(interface, probe, dev,
1107 "request_irq for msix_mbx failed: %d\n", err);
1111 /* Enable interrupts w/ no moderation for "other" interrupts */
1112 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), other_itr);
1113 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), other_itr);
1114 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_SRAM), other_itr);
1115 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_MaxHoldTime), other_itr);
1116 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_VFLR), other_itr);
1118 /* Enable interrupts w/ moderation for mailbox */
1119 fm10k_write_reg(hw, FM10K_INT_MAP(fm10k_int_Mailbox), mbx_itr);
1121 /* Enable individual interrupt causes */
1122 fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
1123 FM10K_EIMR_ENABLE(FUM_FAULT) |
1124 FM10K_EIMR_ENABLE(MAILBOX) |
1125 FM10K_EIMR_ENABLE(SWITCHREADY) |
1126 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
1127 FM10K_EIMR_ENABLE(SRAMERROR) |
1128 FM10K_EIMR_ENABLE(VFLR) |
1129 FM10K_EIMR_ENABLE(MAXHOLDTIME));
1131 /* enable interrupt */
1132 fm10k_write_reg(hw, FM10K_ITR(entry->entry), FM10K_ITR_ENABLE);
1137 int fm10k_mbx_request_irq(struct fm10k_intfc *interface)
1139 struct fm10k_hw *hw = &interface->hw;
1142 /* enable Mailbox cause */
1143 err = fm10k_mbx_request_irq_pf(interface);
1145 /* connect mailbox */
1147 err = hw->mbx.ops.connect(hw, &hw->mbx);
1153 * fm10k_qv_free_irq - release interrupts associated with queue vectors
1154 * @interface: board private structure
1156 * Release all interrupts associated with this interface
1158 void fm10k_qv_free_irq(struct fm10k_intfc *interface)
1160 int vector = interface->num_q_vectors;
1161 struct fm10k_hw *hw = &interface->hw;
1162 struct msix_entry *entry;
1164 entry = &interface->msix_entries[NON_Q_VECTORS(hw) + vector];
1167 struct fm10k_q_vector *q_vector;
1171 q_vector = interface->q_vector[vector];
1173 if (!q_vector->tx.count && !q_vector->rx.count)
1176 /* disable interrupts */
1178 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1180 free_irq(entry->vector, q_vector);
1185 * fm10k_qv_request_irq - initialize interrupts for queue vectors
1186 * @interface: board private structure
1188 * Attempts to configure interrupts using the best available
1189 * capabilities of the hardware and kernel.
1191 int fm10k_qv_request_irq(struct fm10k_intfc *interface)
1193 struct net_device *dev = interface->netdev;
1194 struct fm10k_hw *hw = &interface->hw;
1195 struct msix_entry *entry;
1199 entry = &interface->msix_entries[NON_Q_VECTORS(hw)];
1201 for (vector = 0; vector < interface->num_q_vectors; vector++) {
1202 struct fm10k_q_vector *q_vector = interface->q_vector[vector];
1204 /* name the vector */
1205 if (q_vector->tx.count && q_vector->rx.count) {
1206 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1207 "%s-TxRx-%d", dev->name, ri++);
1209 } else if (q_vector->rx.count) {
1210 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1211 "%s-rx-%d", dev->name, ri++);
1212 } else if (q_vector->tx.count) {
1213 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1214 "%s-tx-%d", dev->name, ti++);
1216 /* skip this unused q_vector */
1220 /* Assign ITR register to q_vector */
1221 q_vector->itr = &interface->uc_addr[FM10K_ITR(entry->entry)];
1223 /* request the IRQ */
1224 err = request_irq(entry->vector, &fm10k_msix_clean_rings, 0,
1225 q_vector->name, q_vector);
1227 netif_err(interface, probe, dev,
1228 "request_irq failed for MSIX interrupt Error: %d\n",
1233 /* Enable q_vector */
1234 writel(FM10K_ITR_ENABLE, q_vector->itr);
1242 /* wind through the ring freeing all entries and vectors */
1244 struct fm10k_q_vector *q_vector;
1248 q_vector = interface->q_vector[vector];
1250 if (!q_vector->tx.count && !q_vector->rx.count)
1253 /* disable interrupts */
1255 writel(FM10K_ITR_MASK_SET, q_vector->itr);
1257 free_irq(entry->vector, q_vector);
1263 void fm10k_up(struct fm10k_intfc *interface)
1265 struct fm10k_hw *hw = &interface->hw;
1267 /* Enable Tx/Rx DMA */
1268 hw->mac.ops.start_hw(hw);
1270 /* configure Tx descriptor rings */
1271 fm10k_configure_tx(interface);
1273 /* configure Rx descriptor rings */
1274 fm10k_configure_rx(interface);
1276 /* configure interrupts */
1277 hw->mac.ops.update_int_moderator(hw);
1279 /* clear down bit to indicate we are ready to go */
1280 clear_bit(__FM10K_DOWN, &interface->state);
1282 /* enable polling cleanups */
1283 fm10k_napi_enable_all(interface);
1285 /* re-establish Rx filters */
1286 fm10k_restore_rx_state(interface);
1288 /* enable transmits */
1289 netif_tx_start_all_queues(interface->netdev);
1291 /* kick off the service timer */
1292 mod_timer(&interface->service_timer, jiffies);
1295 static void fm10k_napi_disable_all(struct fm10k_intfc *interface)
1297 struct fm10k_q_vector *q_vector;
1300 for (q_idx = 0; q_idx < interface->num_q_vectors; q_idx++) {
1301 q_vector = interface->q_vector[q_idx];
1302 napi_disable(&q_vector->napi);
1306 void fm10k_down(struct fm10k_intfc *interface)
1308 struct net_device *netdev = interface->netdev;
1309 struct fm10k_hw *hw = &interface->hw;
1311 /* signal that we are down to the interrupt handler and service task */
1312 set_bit(__FM10K_DOWN, &interface->state);
1314 /* call carrier off first to avoid false dev_watchdog timeouts */
1315 netif_carrier_off(netdev);
1317 /* disable transmits */
1318 netif_tx_stop_all_queues(netdev);
1319 netif_tx_disable(netdev);
1321 /* reset Rx filters */
1322 fm10k_reset_rx_state(interface);
1324 /* allow 10ms for device to quiesce */
1325 usleep_range(10000, 20000);
1327 /* disable polling routines */
1328 fm10k_napi_disable_all(interface);
1330 del_timer_sync(&interface->service_timer);
1332 /* capture stats one last time before stopping interface */
1333 fm10k_update_stats(interface);
1335 /* Disable DMA engine for Tx/Rx */
1336 hw->mac.ops.stop_hw(hw);
1338 /* free any buffers still on the rings */
1339 fm10k_clean_all_tx_rings(interface);
1343 * fm10k_sw_init - Initialize general software structures
1344 * @interface: host interface private structure to initialize
1346 * fm10k_sw_init initializes the interface private data structure.
1347 * Fields are initialized based on PCI device information and
1348 * OS network device settings (MTU size).
1350 static int fm10k_sw_init(struct fm10k_intfc *interface,
1351 const struct pci_device_id *ent)
1353 static const u32 seed[FM10K_RSSRK_SIZE] = { 0xda565a6d, 0xc20e5b25,
1354 0x3d256741, 0xb08fa343,
1355 0xcb2bcad0, 0xb4307bae,
1356 0xa32dcb77, 0x0cf23080,
1357 0x3bb7426a, 0xfa01acbe };
1358 const struct fm10k_info *fi = fm10k_info_tbl[ent->driver_data];
1359 struct fm10k_hw *hw = &interface->hw;
1360 struct pci_dev *pdev = interface->pdev;
1361 struct net_device *netdev = interface->netdev;
1365 /* initialize back pointer */
1366 hw->back = interface;
1367 hw->hw_addr = interface->uc_addr;
1369 /* PCI config space info */
1370 hw->vendor_id = pdev->vendor;
1371 hw->device_id = pdev->device;
1372 hw->revision_id = pdev->revision;
1373 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1374 hw->subsystem_device_id = pdev->subsystem_device;
1377 memcpy(&hw->mac.ops, fi->mac_ops, sizeof(hw->mac.ops));
1378 hw->mac.type = fi->mac;
1380 /* Set common capability flags and settings */
1381 rss = min_t(int, FM10K_MAX_RSS_INDICES, num_online_cpus());
1382 interface->ring_feature[RING_F_RSS].limit = rss;
1383 fi->get_invariants(hw);
1385 /* pick up the PCIe bus settings for reporting later */
1386 if (hw->mac.ops.get_bus_info)
1387 hw->mac.ops.get_bus_info(hw);
1389 /* limit the usable DMA range */
1390 if (hw->mac.ops.set_dma_mask)
1391 hw->mac.ops.set_dma_mask(hw, dma_get_mask(&pdev->dev));
1393 /* update netdev with DMA restrictions */
1394 if (dma_get_mask(&pdev->dev) > DMA_BIT_MASK(32)) {
1395 netdev->features |= NETIF_F_HIGHDMA;
1396 netdev->vlan_features |= NETIF_F_HIGHDMA;
1399 /* delay any future reset requests */
1400 interface->last_reset = jiffies + (10 * HZ);
1402 /* reset and initialize the hardware so it is in a known state */
1403 err = hw->mac.ops.reset_hw(hw) ? : hw->mac.ops.init_hw(hw);
1405 dev_err(&pdev->dev, "init_hw failed: %d\n", err);
1409 /* initialize hardware statistics */
1410 hw->mac.ops.update_hw_stats(hw, &interface->stats);
1412 /* Start with random Ethernet address */
1413 eth_random_addr(hw->mac.addr);
1415 /* Initialize MAC address from hardware */
1416 err = hw->mac.ops.read_mac_addr(hw);
1418 dev_warn(&pdev->dev,
1419 "Failed to obtain MAC address defaulting to random\n");
1420 /* tag address assignment as random */
1421 netdev->addr_assign_type |= NET_ADDR_RANDOM;
1424 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1425 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1427 if (!is_valid_ether_addr(netdev->perm_addr)) {
1428 dev_err(&pdev->dev, "Invalid MAC Address\n");
1432 /* Only the PF can support VXLAN and NVGRE offloads */
1433 if (hw->mac.type != fm10k_mac_pf) {
1434 netdev->hw_enc_features = 0;
1435 netdev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
1436 netdev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
1439 /* Initialize service timer and service task */
1440 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1441 setup_timer(&interface->service_timer, &fm10k_service_timer,
1442 (unsigned long)interface);
1443 INIT_WORK(&interface->service_task, fm10k_service_task);
1445 /* set default ring sizes */
1446 interface->tx_ring_count = FM10K_DEFAULT_TXD;
1447 interface->rx_ring_count = FM10K_DEFAULT_RXD;
1449 /* set default interrupt moderation */
1450 interface->tx_itr = FM10K_ITR_10K;
1451 interface->rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
1453 /* initialize vxlan_port list */
1454 INIT_LIST_HEAD(&interface->vxlan_port);
1456 /* initialize RSS key */
1457 memcpy(interface->rssrk, seed, sizeof(seed));
1459 /* Start off interface as being down */
1460 set_bit(__FM10K_DOWN, &interface->state);
1465 static void fm10k_slot_warn(struct fm10k_intfc *interface)
1467 struct device *dev = &interface->pdev->dev;
1468 struct fm10k_hw *hw = &interface->hw;
1470 if (hw->mac.ops.is_slot_appropriate(hw))
1474 "For optimal performance, a %s %s slot is recommended.\n",
1475 (hw->bus_caps.width == fm10k_bus_width_pcie_x1 ? "x1" :
1476 hw->bus_caps.width == fm10k_bus_width_pcie_x4 ? "x4" :
1478 (hw->bus_caps.speed == fm10k_bus_speed_2500 ? "2.5GT/s" :
1479 hw->bus_caps.speed == fm10k_bus_speed_5000 ? "5.0GT/s" :
1482 "A slot with more lanes and/or higher speed is suggested.\n");
1486 * fm10k_probe - Device Initialization Routine
1487 * @pdev: PCI device information struct
1488 * @ent: entry in fm10k_pci_tbl
1490 * Returns 0 on success, negative on failure
1492 * fm10k_probe initializes an interface identified by a pci_dev structure.
1493 * The OS initialization, configuring of the interface private structure,
1494 * and a hardware reset occur.
1496 static int fm10k_probe(struct pci_dev *pdev,
1497 const struct pci_device_id *ent)
1499 struct net_device *netdev;
1500 struct fm10k_intfc *interface;
1501 struct fm10k_hw *hw;
1505 err = pci_enable_device_mem(pdev);
1509 /* By default fm10k only supports a 48 bit DMA mask */
1510 dma_mask = DMA_BIT_MASK(48) | dma_get_required_mask(&pdev->dev);
1512 if ((dma_mask <= DMA_BIT_MASK(32)) ||
1513 dma_set_mask_and_coherent(&pdev->dev, dma_mask)) {
1514 dma_mask &= DMA_BIT_MASK(32);
1516 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1517 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
1519 err = dma_set_coherent_mask(&pdev->dev,
1523 "No usable DMA configuration, aborting\n");
1529 err = pci_request_selected_regions(pdev,
1530 pci_select_bars(pdev,
1535 "pci_request_selected_regions failed 0x%x\n", err);
1539 pci_enable_pcie_error_reporting(pdev);
1541 pci_set_master(pdev);
1542 pci_save_state(pdev);
1544 netdev = fm10k_alloc_netdev();
1547 goto err_alloc_netdev;
1550 SET_NETDEV_DEV(netdev, &pdev->dev);
1552 interface = netdev_priv(netdev);
1553 pci_set_drvdata(pdev, interface);
1555 interface->netdev = netdev;
1556 interface->pdev = pdev;
1557 hw = &interface->hw;
1559 interface->uc_addr = ioremap(pci_resource_start(pdev, 0),
1560 FM10K_UC_ADDR_SIZE);
1561 if (!interface->uc_addr) {
1566 err = fm10k_sw_init(interface, ent);
1570 err = fm10k_init_queueing_scheme(interface);
1574 err = fm10k_mbx_request_irq(interface);
1576 goto err_mbx_interrupt;
1578 /* final check of hardware state before registering the interface */
1579 err = fm10k_hw_ready(interface);
1583 err = register_netdev(netdev);
1587 /* carrier off reporting is important to ethtool even BEFORE open */
1588 netif_carrier_off(netdev);
1590 /* stop all the transmit queues from transmitting until link is up */
1591 netif_tx_stop_all_queues(netdev);
1593 /* print bus type/speed/width info */
1594 dev_info(&pdev->dev, "(PCI Express:%s Width: %s Payload: %s)\n",
1595 (hw->bus.speed == fm10k_bus_speed_8000 ? "8.0GT/s" :
1596 hw->bus.speed == fm10k_bus_speed_5000 ? "5.0GT/s" :
1597 hw->bus.speed == fm10k_bus_speed_2500 ? "2.5GT/s" :
1599 (hw->bus.width == fm10k_bus_width_pcie_x8 ? "x8" :
1600 hw->bus.width == fm10k_bus_width_pcie_x4 ? "x4" :
1601 hw->bus.width == fm10k_bus_width_pcie_x1 ? "x1" :
1603 (hw->bus.payload == fm10k_bus_payload_128 ? "128B" :
1604 hw->bus.payload == fm10k_bus_payload_256 ? "256B" :
1605 hw->bus.payload == fm10k_bus_payload_512 ? "512B" :
1608 /* print warning for non-optimal configurations */
1609 fm10k_slot_warn(interface);
1611 /* clear the service task disable bit to allow service task to start */
1612 clear_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1617 fm10k_mbx_free_irq(interface);
1619 fm10k_clear_queueing_scheme(interface);
1621 iounmap(interface->uc_addr);
1623 free_netdev(netdev);
1625 pci_release_selected_regions(pdev,
1626 pci_select_bars(pdev, IORESOURCE_MEM));
1629 pci_disable_device(pdev);
1634 * fm10k_remove - Device Removal Routine
1635 * @pdev: PCI device information struct
1637 * fm10k_remove is called by the PCI subsystem to alert the driver
1638 * that it should release a PCI device. The could be caused by a
1639 * Hot-Plug event, or because the driver is going to be removed from
1642 static void fm10k_remove(struct pci_dev *pdev)
1644 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1645 struct net_device *netdev = interface->netdev;
1647 set_bit(__FM10K_SERVICE_DISABLE, &interface->state);
1648 cancel_work_sync(&interface->service_task);
1650 /* free netdev, this may bounce the interrupts due to setup_tc */
1651 if (netdev->reg_state == NETREG_REGISTERED)
1652 unregister_netdev(netdev);
1654 /* disable mailbox interrupt */
1655 fm10k_mbx_free_irq(interface);
1657 /* free interrupts */
1658 fm10k_clear_queueing_scheme(interface);
1660 iounmap(interface->uc_addr);
1662 free_netdev(netdev);
1664 pci_release_selected_regions(pdev,
1665 pci_select_bars(pdev, IORESOURCE_MEM));
1667 pci_disable_pcie_error_reporting(pdev);
1669 pci_disable_device(pdev);
1674 * fm10k_resume - Restore device to pre-sleep state
1675 * @pdev: PCI device information struct
1677 * fm10k_resume is called after the system has powered back up from a sleep
1678 * state and is ready to resume operation. This function is meant to restore
1679 * the device back to its pre-sleep state.
1681 static int fm10k_resume(struct pci_dev *pdev)
1683 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1684 struct net_device *netdev = interface->netdev;
1685 struct fm10k_hw *hw = &interface->hw;
1688 pci_set_power_state(pdev, PCI_D0);
1689 pci_restore_state(pdev);
1691 /* pci_restore_state clears dev->state_saved so call
1692 * pci_save_state to restore it.
1694 pci_save_state(pdev);
1696 err = pci_enable_device_mem(pdev);
1698 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
1701 pci_set_master(pdev);
1703 pci_wake_from_d3(pdev, false);
1705 /* refresh hw_addr in case it was dropped */
1706 hw->hw_addr = interface->uc_addr;
1708 /* reset hardware to known state */
1709 err = hw->mac.ops.init_hw(&interface->hw);
1713 /* reset statistics starting values */
1714 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
1718 err = fm10k_init_queueing_scheme(interface);
1720 fm10k_mbx_request_irq(interface);
1721 if (netif_running(netdev))
1722 err = fm10k_open(netdev);
1730 netif_device_attach(netdev);
1736 * fm10k_suspend - Prepare the device for a system sleep state
1737 * @pdev: PCI device information struct
1739 * fm10k_suspend is meant to shutdown the device prior to the system entering
1740 * a sleep state. The fm10k hardware does not support wake on lan so the
1741 * driver simply needs to shut down the device so it is in a low power state.
1743 static int fm10k_suspend(struct pci_dev *pdev, pm_message_t state)
1745 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1746 struct net_device *netdev = interface->netdev;
1749 netif_device_detach(netdev);
1753 if (netif_running(netdev))
1754 fm10k_close(netdev);
1756 fm10k_mbx_free_irq(interface);
1758 fm10k_clear_queueing_scheme(interface);
1762 err = pci_save_state(pdev);
1766 pci_disable_device(pdev);
1767 pci_wake_from_d3(pdev, false);
1768 pci_set_power_state(pdev, PCI_D3hot);
1773 #endif /* CONFIG_PM */
1775 * fm10k_io_error_detected - called when PCI error is detected
1776 * @pdev: Pointer to PCI device
1777 * @state: The current pci connection state
1779 * This function is called after a PCI bus error affecting
1780 * this device has been detected.
1782 static pci_ers_result_t fm10k_io_error_detected(struct pci_dev *pdev,
1783 pci_channel_state_t state)
1785 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1786 struct net_device *netdev = interface->netdev;
1788 netif_device_detach(netdev);
1790 if (state == pci_channel_io_perm_failure)
1791 return PCI_ERS_RESULT_DISCONNECT;
1793 if (netif_running(netdev))
1794 fm10k_close(netdev);
1796 fm10k_mbx_free_irq(interface);
1798 pci_disable_device(pdev);
1800 /* Request a slot reset. */
1801 return PCI_ERS_RESULT_NEED_RESET;
1805 * fm10k_io_slot_reset - called after the pci bus has been reset.
1806 * @pdev: Pointer to PCI device
1808 * Restart the card from scratch, as if from a cold-boot.
1810 static pci_ers_result_t fm10k_io_slot_reset(struct pci_dev *pdev)
1812 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1813 pci_ers_result_t result;
1815 if (pci_enable_device_mem(pdev)) {
1817 "Cannot re-enable PCI device after reset.\n");
1818 result = PCI_ERS_RESULT_DISCONNECT;
1820 pci_set_master(pdev);
1821 pci_restore_state(pdev);
1823 /* After second error pci->state_saved is false, this
1824 * resets it so EEH doesn't break.
1826 pci_save_state(pdev);
1828 pci_wake_from_d3(pdev, false);
1830 /* refresh hw_addr in case it was dropped */
1831 interface->hw.hw_addr = interface->uc_addr;
1833 interface->flags |= FM10K_FLAG_RESET_REQUESTED;
1834 fm10k_service_event_schedule(interface);
1836 result = PCI_ERS_RESULT_RECOVERED;
1839 pci_cleanup_aer_uncorrect_error_status(pdev);
1845 * fm10k_io_resume - called when traffic can start flowing again.
1846 * @pdev: Pointer to PCI device
1848 * This callback is called when the error recovery driver tells us that
1849 * its OK to resume normal operation.
1851 static void fm10k_io_resume(struct pci_dev *pdev)
1853 struct fm10k_intfc *interface = pci_get_drvdata(pdev);
1854 struct net_device *netdev = interface->netdev;
1855 struct fm10k_hw *hw = &interface->hw;
1858 /* reset hardware to known state */
1859 hw->mac.ops.init_hw(&interface->hw);
1861 /* reset statistics starting values */
1862 hw->mac.ops.rebind_hw_stats(hw, &interface->stats);
1864 /* reassociate interrupts */
1865 fm10k_mbx_request_irq(interface);
1867 if (netif_running(netdev))
1868 err = fm10k_open(netdev);
1870 /* final check of hardware state before registering the interface */
1871 err = err ? : fm10k_hw_ready(interface);
1874 netif_device_attach(netdev);
1877 static const struct pci_error_handlers fm10k_err_handler = {
1878 .error_detected = fm10k_io_error_detected,
1879 .slot_reset = fm10k_io_slot_reset,
1880 .resume = fm10k_io_resume,
1883 static struct pci_driver fm10k_driver = {
1884 .name = fm10k_driver_name,
1885 .id_table = fm10k_pci_tbl,
1886 .probe = fm10k_probe,
1887 .remove = fm10k_remove,
1889 .suspend = fm10k_suspend,
1890 .resume = fm10k_resume,
1892 .err_handler = &fm10k_err_handler
1896 * fm10k_register_pci_driver - register driver interface
1898 * This funciton is called on module load in order to register the driver.
1900 int fm10k_register_pci_driver(void)
1902 return pci_register_driver(&fm10k_driver);
1906 * fm10k_unregister_pci_driver - unregister driver interface
1908 * This funciton is called on module unload in order to remove the driver.
1910 void fm10k_unregister_pci_driver(void)
1912 pci_unregister_driver(&fm10k_driver);