1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2018 Solarflare Communications Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
11 #include "net_driver.h"
12 #include <linux/module.h>
13 #include <linux/netdevice.h>
14 #include "efx_common.h"
15 #include "efx_channels.h"
19 #include "rx_common.h"
20 #include "tx_common.h"
23 #include "mcdi_pcol.h"
25 static unsigned int debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
26 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
27 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
28 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
29 module_param(debug, uint, 0);
30 MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
32 /* This is the time (in jiffies) between invocations of the hardware
34 * On Falcon-based NICs, this will:
35 * - Check the on-board hardware monitor;
36 * - Poll the link state and reconfigure the hardware as necessary.
37 * On Siena-based NICs for power systems with EEH support, this will give EEH a
40 static unsigned int efx_monitor_interval = 1 * HZ;
42 /* How often and how many times to poll for a reset while waiting for a
43 * BIST that another function started to complete.
45 #define BIST_WAIT_DELAY_MS 100
46 #define BIST_WAIT_DELAY_COUNT 100
48 /* Default stats update time */
49 #define STATS_PERIOD_MS_DEFAULT 1000
51 const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
52 const char *const efx_reset_type_names[] = {
53 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
54 [RESET_TYPE_ALL] = "ALL",
55 [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
56 [RESET_TYPE_WORLD] = "WORLD",
57 [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
58 [RESET_TYPE_DATAPATH] = "DATAPATH",
59 [RESET_TYPE_MC_BIST] = "MC_BIST",
60 [RESET_TYPE_DISABLE] = "DISABLE",
61 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
62 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
63 [RESET_TYPE_DMA_ERROR] = "DMA_ERROR",
64 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
65 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
66 [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)",
69 #define RESET_TYPE(type) \
70 STRING_TABLE_LOOKUP(type, efx_reset_type)
72 /* Loopback mode names (see LOOPBACK_MODE()) */
73 const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
74 const char *const efx_loopback_mode_names[] = {
75 [LOOPBACK_NONE] = "NONE",
76 [LOOPBACK_DATA] = "DATAPATH",
77 [LOOPBACK_GMAC] = "GMAC",
78 [LOOPBACK_XGMII] = "XGMII",
79 [LOOPBACK_XGXS] = "XGXS",
80 [LOOPBACK_XAUI] = "XAUI",
81 [LOOPBACK_GMII] = "GMII",
82 [LOOPBACK_SGMII] = "SGMII",
83 [LOOPBACK_XGBR] = "XGBR",
84 [LOOPBACK_XFI] = "XFI",
85 [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
86 [LOOPBACK_GMII_FAR] = "GMII_FAR",
87 [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
88 [LOOPBACK_XFI_FAR] = "XFI_FAR",
89 [LOOPBACK_GPHY] = "GPHY",
90 [LOOPBACK_PHYXS] = "PHYXS",
91 [LOOPBACK_PCS] = "PCS",
92 [LOOPBACK_PMAPMD] = "PMA/PMD",
93 [LOOPBACK_XPORT] = "XPORT",
94 [LOOPBACK_XGMII_WS] = "XGMII_WS",
95 [LOOPBACK_XAUI_WS] = "XAUI_WS",
96 [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
97 [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
98 [LOOPBACK_GMII_WS] = "GMII_WS",
99 [LOOPBACK_XFI_WS] = "XFI_WS",
100 [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
101 [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
104 /* Reset workqueue. If any NIC has a hardware failure then a reset will be
105 * queued onto this work queue. This is not a per-nic work queue, because
106 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
108 static struct workqueue_struct *reset_workqueue;
110 int efx_create_reset_workqueue(void)
112 reset_workqueue = create_singlethread_workqueue("sfc_reset");
113 if (!reset_workqueue) {
114 printk(KERN_ERR "Failed to create reset workqueue\n");
121 void efx_queue_reset_work(struct efx_nic *efx)
123 queue_work(reset_workqueue, &efx->reset_work);
126 void efx_flush_reset_workqueue(struct efx_nic *efx)
128 cancel_work_sync(&efx->reset_work);
131 void efx_destroy_reset_workqueue(void)
133 if (reset_workqueue) {
134 destroy_workqueue(reset_workqueue);
135 reset_workqueue = NULL;
139 /* We assume that efx->type->reconfigure_mac will always try to sync RX
140 * filters and therefore needs to read-lock the filter table against freeing
142 void efx_mac_reconfigure(struct efx_nic *efx)
144 if (efx->type->reconfigure_mac) {
145 down_read(&efx->filter_sem);
146 efx->type->reconfigure_mac(efx);
147 up_read(&efx->filter_sem);
151 /* Asynchronous work item for changing MAC promiscuity and multicast
152 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
155 static void efx_mac_work(struct work_struct *data)
157 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
159 mutex_lock(&efx->mac_lock);
160 if (efx->port_enabled)
161 efx_mac_reconfigure(efx);
162 mutex_unlock(&efx->mac_lock);
165 /* This ensures that the kernel is kept informed (via
166 * netif_carrier_on/off) of the link status, and also maintains the
167 * link status's stop on the port's TX queue.
169 void efx_link_status_changed(struct efx_nic *efx)
171 struct efx_link_state *link_state = &efx->link_state;
173 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
174 * that no events are triggered between unregister_netdev() and the
175 * driver unloading. A more general condition is that NETDEV_CHANGE
176 * can only be generated between NETDEV_UP and NETDEV_DOWN
178 if (!netif_running(efx->net_dev))
181 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
182 efx->n_link_state_changes++;
185 netif_carrier_on(efx->net_dev);
187 netif_carrier_off(efx->net_dev);
190 /* Status message for kernel log */
192 netif_info(efx, link, efx->net_dev,
193 "link up at %uMbps %s-duplex (MTU %d)\n",
194 link_state->speed, link_state->fd ? "full" : "half",
197 netif_info(efx, link, efx->net_dev, "link down\n");
200 /**************************************************************************
204 **************************************************************************/
206 /* Run periodically off the general workqueue */
207 static void efx_monitor(struct work_struct *data)
209 struct efx_nic *efx = container_of(data, struct efx_nic,
212 netif_vdbg(efx, timer, efx->net_dev,
213 "hardware monitor executing on CPU %d\n",
214 raw_smp_processor_id());
215 BUG_ON(efx->type->monitor == NULL);
217 /* If the mac_lock is already held then it is likely a port
218 * reconfiguration is already in place, which will likely do
219 * most of the work of monitor() anyway.
221 if (mutex_trylock(&efx->mac_lock)) {
222 if (efx->port_enabled && efx->type->monitor)
223 efx->type->monitor(efx);
224 mutex_unlock(&efx->mac_lock);
227 efx_start_monitor(efx);
230 void efx_start_monitor(struct efx_nic *efx)
232 if (efx->type->monitor)
233 queue_delayed_work(efx->workqueue, &efx->monitor_work,
234 efx_monitor_interval);
237 /**************************************************************************
239 * Event queue processing
241 *************************************************************************/
243 /* Channels are shutdown and reinitialised whilst the NIC is running
244 * to propagate configuration changes (mtu, checksum offload), or
245 * to clear hardware error conditions
247 static void efx_start_datapath(struct efx_nic *efx)
249 netdev_features_t old_features = efx->net_dev->features;
250 bool old_rx_scatter = efx->rx_scatter;
253 /* Calculate the rx buffer allocation parameters required to
254 * support the current MTU, including padding for header
255 * alignment and overruns.
257 efx->rx_dma_len = (efx->rx_prefix_size +
258 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
259 efx->type->rx_buffer_padding);
260 rx_buf_len = (sizeof(struct efx_rx_page_state) + XDP_PACKET_HEADROOM +
261 efx->rx_ip_align + efx->rx_dma_len);
262 if (rx_buf_len <= PAGE_SIZE) {
263 efx->rx_scatter = efx->type->always_rx_scatter;
264 efx->rx_buffer_order = 0;
265 } else if (efx->type->can_rx_scatter) {
266 BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
267 BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
268 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
269 EFX_RX_BUF_ALIGNMENT) >
271 efx->rx_scatter = true;
272 efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
273 efx->rx_buffer_order = 0;
275 efx->rx_scatter = false;
276 efx->rx_buffer_order = get_order(rx_buf_len);
279 efx_rx_config_page_split(efx);
280 if (efx->rx_buffer_order)
281 netif_dbg(efx, drv, efx->net_dev,
282 "RX buf len=%u; page order=%u batch=%u\n",
283 efx->rx_dma_len, efx->rx_buffer_order,
284 efx->rx_pages_per_batch);
286 netif_dbg(efx, drv, efx->net_dev,
287 "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
288 efx->rx_dma_len, efx->rx_page_buf_step,
289 efx->rx_bufs_per_page, efx->rx_pages_per_batch);
291 /* Restore previously fixed features in hw_features and remove
292 * features which are fixed now
294 efx->net_dev->hw_features |= efx->net_dev->features;
295 efx->net_dev->hw_features &= ~efx->fixed_features;
296 efx->net_dev->features |= efx->fixed_features;
297 if (efx->net_dev->features != old_features)
298 netdev_features_change(efx->net_dev);
300 /* RX filters may also have scatter-enabled flags */
301 if ((efx->rx_scatter != old_rx_scatter) &&
302 efx->type->filter_update_rx_scatter)
303 efx->type->filter_update_rx_scatter(efx);
305 /* We must keep at least one descriptor in a TX ring empty.
306 * We could avoid this when the queue size does not exactly
307 * match the hardware ring size, but it's not that important.
308 * Therefore we stop the queue when one more skb might fill
309 * the ring completely. We wake it when half way back to
312 efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
313 efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
315 /* Initialise the channels */
316 efx_start_channels(efx);
318 efx_ptp_start_datapath(efx);
320 if (netif_device_present(efx->net_dev))
321 netif_tx_wake_all_queues(efx->net_dev);
324 static void efx_stop_datapath(struct efx_nic *efx)
326 EFX_ASSERT_RESET_SERIALISED(efx);
327 BUG_ON(efx->port_enabled);
329 efx_ptp_stop_datapath(efx);
331 efx_stop_channels(efx);
334 /**************************************************************************
338 **************************************************************************/
340 static void efx_start_port(struct efx_nic *efx)
342 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
343 BUG_ON(efx->port_enabled);
345 mutex_lock(&efx->mac_lock);
346 efx->port_enabled = true;
348 /* Ensure MAC ingress/egress is enabled */
349 efx_mac_reconfigure(efx);
351 mutex_unlock(&efx->mac_lock);
354 /* Cancel work for MAC reconfiguration, periodic hardware monitoring
355 * and the async self-test, wait for them to finish and prevent them
356 * being scheduled again. This doesn't cover online resets, which
357 * should only be cancelled when removing the device.
359 static void efx_stop_port(struct efx_nic *efx)
361 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
363 EFX_ASSERT_RESET_SERIALISED(efx);
365 mutex_lock(&efx->mac_lock);
366 efx->port_enabled = false;
367 mutex_unlock(&efx->mac_lock);
369 /* Serialise against efx_set_multicast_list() */
370 netif_addr_lock_bh(efx->net_dev);
371 netif_addr_unlock_bh(efx->net_dev);
373 cancel_delayed_work_sync(&efx->monitor_work);
374 efx_selftest_async_cancel(efx);
375 cancel_work_sync(&efx->mac_work);
378 /* If the interface is supposed to be running but is not, start
379 * the hardware and software data path, regular activity for the port
380 * (MAC statistics, link polling, etc.) and schedule the port to be
381 * reconfigured. Interrupts must already be enabled. This function
382 * is safe to call multiple times, so long as the NIC is not disabled.
383 * Requires the RTNL lock.
385 void efx_start_all(struct efx_nic *efx)
387 EFX_ASSERT_RESET_SERIALISED(efx);
388 BUG_ON(efx->state == STATE_DISABLED);
390 /* Check that it is appropriate to restart the interface. All
391 * of these flags are safe to read under just the rtnl lock
393 if (efx->port_enabled || !netif_running(efx->net_dev) ||
398 efx_start_datapath(efx);
400 /* Start the hardware monitor if there is one */
401 efx_start_monitor(efx);
403 /* Link state detection is normally event-driven; we have
404 * to poll now because we could have missed a change
406 mutex_lock(&efx->mac_lock);
407 if (efx->phy_op->poll(efx))
408 efx_link_status_changed(efx);
409 mutex_unlock(&efx->mac_lock);
411 if (efx->type->start_stats) {
412 efx->type->start_stats(efx);
413 efx->type->pull_stats(efx);
414 spin_lock_bh(&efx->stats_lock);
415 efx->type->update_stats(efx, NULL, NULL);
416 spin_unlock_bh(&efx->stats_lock);
420 /* Quiesce the hardware and software data path, and regular activity
421 * for the port without bringing the link down. Safe to call multiple
422 * times with the NIC in almost any state, but interrupts should be
423 * enabled. Requires the RTNL lock.
425 void efx_stop_all(struct efx_nic *efx)
427 EFX_ASSERT_RESET_SERIALISED(efx);
429 /* port_enabled can be read safely under the rtnl lock */
430 if (!efx->port_enabled)
433 if (efx->type->update_stats) {
434 /* update stats before we go down so we can accurately count
437 efx->type->pull_stats(efx);
438 spin_lock_bh(&efx->stats_lock);
439 efx->type->update_stats(efx, NULL, NULL);
440 spin_unlock_bh(&efx->stats_lock);
441 efx->type->stop_stats(efx);
446 /* Stop the kernel transmit interface. This is only valid if
447 * the device is stopped or detached; otherwise the watchdog
448 * may fire immediately.
450 WARN_ON(netif_running(efx->net_dev) &&
451 netif_device_present(efx->net_dev));
452 netif_tx_disable(efx->net_dev);
454 efx_stop_datapath(efx);
457 /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
458 * the MAC appropriately. All other PHY configuration changes are pushed
459 * through phy_op->set_settings(), and pushed asynchronously to the MAC
460 * through efx_monitor().
462 * Callers must hold the mac_lock
464 int __efx_reconfigure_port(struct efx_nic *efx)
466 enum efx_phy_mode phy_mode;
469 WARN_ON(!mutex_is_locked(&efx->mac_lock));
471 /* Disable PHY transmit in mac level loopbacks */
472 phy_mode = efx->phy_mode;
473 if (LOOPBACK_INTERNAL(efx))
474 efx->phy_mode |= PHY_MODE_TX_DISABLED;
476 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
478 if (efx->type->reconfigure_port)
479 rc = efx->type->reconfigure_port(efx);
482 efx->phy_mode = phy_mode;
487 /* Reinitialise the MAC to pick up new PHY settings, even if the port is
490 int efx_reconfigure_port(struct efx_nic *efx)
494 EFX_ASSERT_RESET_SERIALISED(efx);
496 mutex_lock(&efx->mac_lock);
497 rc = __efx_reconfigure_port(efx);
498 mutex_unlock(&efx->mac_lock);
503 /**************************************************************************
505 * Device reset and suspend
507 **************************************************************************/
509 static void efx_wait_for_bist_end(struct efx_nic *efx)
513 for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
514 if (efx_mcdi_poll_reboot(efx))
516 msleep(BIST_WAIT_DELAY_MS);
519 netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
521 /* Either way unset the BIST flag. If we found no reboot we probably
522 * won't recover, but we should try.
524 efx->mc_bist_for_other_fn = false;
527 /* Try recovery mechanisms.
528 * For now only EEH is supported.
529 * Returns 0 if the recovery mechanisms are unsuccessful.
530 * Returns a non-zero value otherwise.
532 int efx_try_recovery(struct efx_nic *efx)
535 /* A PCI error can occur and not be seen by EEH because nothing
536 * happens on the PCI bus. In this case the driver may fail and
537 * schedule a 'recover or reset', leading to this recovery handler.
538 * Manually call the eeh failure check function.
540 struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
541 if (eeh_dev_check_failure(eehdev)) {
542 /* The EEH mechanisms will handle the error and reset the
543 * device if necessary.
551 /* Tears down the entire software state and most of the hardware state
554 void efx_reset_down(struct efx_nic *efx, enum reset_type method)
556 EFX_ASSERT_RESET_SERIALISED(efx);
558 if (method == RESET_TYPE_MCDI_TIMEOUT)
559 efx->type->prepare_flr(efx);
562 efx_disable_interrupts(efx);
564 mutex_lock(&efx->mac_lock);
565 down_write(&efx->filter_sem);
566 mutex_lock(&efx->rss_lock);
567 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
568 method != RESET_TYPE_DATAPATH)
569 efx->phy_op->fini(efx);
570 efx->type->fini(efx);
573 /* This function will always ensure that the locks acquired in
574 * efx_reset_down() are released. A failure return code indicates
575 * that we were unable to reinitialise the hardware, and the
576 * driver should be disabled. If ok is false, then the rx and tx
577 * engines are not restarted, pending a RESET_DISABLE.
579 int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
583 EFX_ASSERT_RESET_SERIALISED(efx);
585 if (method == RESET_TYPE_MCDI_TIMEOUT)
586 efx->type->finish_flr(efx);
588 /* Ensure that SRAM is initialised even if we're disabling the device */
589 rc = efx->type->init(efx);
591 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
598 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
599 method != RESET_TYPE_DATAPATH) {
600 rc = efx->phy_op->init(efx);
603 rc = efx->phy_op->reconfigure(efx);
604 if (rc && rc != -EPERM)
605 netif_err(efx, drv, efx->net_dev,
606 "could not restore PHY settings\n");
609 rc = efx_enable_interrupts(efx);
613 #ifdef CONFIG_SFC_SRIOV
614 rc = efx->type->vswitching_restore(efx);
615 if (rc) /* not fatal; the PF will still work fine */
616 netif_warn(efx, probe, efx->net_dev,
617 "failed to restore vswitching rc=%d;"
618 " VFs may not function\n", rc);
621 if (efx->type->rx_restore_rss_contexts)
622 efx->type->rx_restore_rss_contexts(efx);
623 mutex_unlock(&efx->rss_lock);
624 efx->type->filter_table_restore(efx);
625 up_write(&efx->filter_sem);
626 if (efx->type->sriov_reset)
627 efx->type->sriov_reset(efx);
629 mutex_unlock(&efx->mac_lock);
633 if (efx->type->udp_tnl_push_ports)
634 efx->type->udp_tnl_push_ports(efx);
639 efx->port_initialized = false;
641 mutex_unlock(&efx->rss_lock);
642 up_write(&efx->filter_sem);
643 mutex_unlock(&efx->mac_lock);
648 /* Reset the NIC using the specified method. Note that the reset may
649 * fail, in which case the card will be left in an unusable state.
651 * Caller must hold the rtnl_lock.
653 int efx_reset(struct efx_nic *efx, enum reset_type method)
658 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
661 efx_device_detach_sync(efx);
662 efx_reset_down(efx, method);
664 rc = efx->type->reset(efx, method);
666 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
670 /* Clear flags for the scopes we covered. We assume the NIC and
671 * driver are now quiescent so that there is no race here.
673 if (method < RESET_TYPE_MAX_METHOD)
674 efx->reset_pending &= -(1 << (method + 1));
675 else /* it doesn't fit into the well-ordered scope hierarchy */
676 __clear_bit(method, &efx->reset_pending);
678 /* Reinitialise bus-mastering, which may have been turned off before
679 * the reset was scheduled. This is still appropriate, even in the
680 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
681 * can respond to requests.
683 pci_set_master(efx->pci_dev);
686 /* Leave device stopped if necessary */
688 method == RESET_TYPE_DISABLE ||
689 method == RESET_TYPE_RECOVER_OR_DISABLE;
690 rc2 = efx_reset_up(efx, method, !disabled);
698 dev_close(efx->net_dev);
699 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
700 efx->state = STATE_DISABLED;
702 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
703 efx_device_attach_if_not_resetting(efx);
708 /* The worker thread exists so that code that cannot sleep can
709 * schedule a reset for later.
711 static void efx_reset_work(struct work_struct *data)
713 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
714 unsigned long pending;
715 enum reset_type method;
717 pending = READ_ONCE(efx->reset_pending);
718 method = fls(pending) - 1;
720 if (method == RESET_TYPE_MC_BIST)
721 efx_wait_for_bist_end(efx);
723 if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
724 method == RESET_TYPE_RECOVER_OR_ALL) &&
725 efx_try_recovery(efx))
733 /* We checked the state in efx_schedule_reset() but it may
734 * have changed by now. Now that we have the RTNL lock,
735 * it cannot change again.
737 if (efx->state == STATE_READY)
738 (void)efx_reset(efx, method);
743 void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
745 enum reset_type method;
747 if (efx->state == STATE_RECOVERY) {
748 netif_dbg(efx, drv, efx->net_dev,
749 "recovering: skip scheduling %s reset\n",
755 case RESET_TYPE_INVISIBLE:
757 case RESET_TYPE_RECOVER_OR_ALL:
758 case RESET_TYPE_WORLD:
759 case RESET_TYPE_DISABLE:
760 case RESET_TYPE_RECOVER_OR_DISABLE:
761 case RESET_TYPE_DATAPATH:
762 case RESET_TYPE_MC_BIST:
763 case RESET_TYPE_MCDI_TIMEOUT:
765 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
769 method = efx->type->map_reset_reason(type);
770 netif_dbg(efx, drv, efx->net_dev,
771 "scheduling %s reset for %s\n",
772 RESET_TYPE(method), RESET_TYPE(type));
776 set_bit(method, &efx->reset_pending);
777 smp_mb(); /* ensure we change reset_pending before checking state */
779 /* If we're not READY then just leave the flags set as the cue
780 * to abort probing or reschedule the reset later.
782 if (READ_ONCE(efx->state) != STATE_READY)
785 /* efx_process_channel() will no longer read events once a
786 * reset is scheduled. So switch back to poll'd MCDI completions.
788 efx_mcdi_mode_poll(efx);
790 efx_queue_reset_work(efx);
793 /**************************************************************************
795 * Dummy PHY/MAC operations
797 * Can be used for some unimplemented operations
798 * Needed so all function pointers are valid and do not have to be tested
801 **************************************************************************/
802 int efx_port_dummy_op_int(struct efx_nic *efx)
806 void efx_port_dummy_op_void(struct efx_nic *efx) {}
808 static bool efx_port_dummy_op_poll(struct efx_nic *efx)
813 static const struct efx_phy_operations efx_dummy_phy_operations = {
814 .init = efx_port_dummy_op_int,
815 .reconfigure = efx_port_dummy_op_int,
816 .poll = efx_port_dummy_op_poll,
817 .fini = efx_port_dummy_op_void,
820 /**************************************************************************
824 **************************************************************************/
826 /* This zeroes out and then fills in the invariants in a struct
827 * efx_nic (including all sub-structures).
829 int efx_init_struct(struct efx_nic *efx,
830 struct pci_dev *pci_dev, struct net_device *net_dev)
834 /* Initialise common structures */
835 INIT_LIST_HEAD(&efx->node);
836 INIT_LIST_HEAD(&efx->secondary_list);
837 spin_lock_init(&efx->biu_lock);
838 #ifdef CONFIG_SFC_MTD
839 INIT_LIST_HEAD(&efx->mtd_list);
841 INIT_WORK(&efx->reset_work, efx_reset_work);
842 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
843 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
844 efx->pci_dev = pci_dev;
845 efx->msg_enable = debug;
846 efx->state = STATE_UNINIT;
847 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
849 efx->net_dev = net_dev;
850 efx->rx_prefix_size = efx->type->rx_prefix_size;
852 NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
853 efx->rx_packet_hash_offset =
854 efx->type->rx_hash_offset - efx->type->rx_prefix_size;
855 efx->rx_packet_ts_offset =
856 efx->type->rx_ts_offset - efx->type->rx_prefix_size;
857 INIT_LIST_HEAD(&efx->rss_context.list);
858 mutex_init(&efx->rss_lock);
859 spin_lock_init(&efx->stats_lock);
860 efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
861 efx->num_mac_stats = MC_CMD_MAC_NSTATS;
862 BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
863 mutex_init(&efx->mac_lock);
864 #ifdef CONFIG_RFS_ACCEL
865 mutex_init(&efx->rps_mutex);
866 spin_lock_init(&efx->rps_hash_lock);
867 /* Failure to allocate is not fatal, but may degrade ARFS performance */
868 efx->rps_hash_table = kcalloc(EFX_ARFS_HASH_TABLE_SIZE,
869 sizeof(*efx->rps_hash_table), GFP_KERNEL);
871 efx->phy_op = &efx_dummy_phy_operations;
872 efx->mdio.dev = net_dev;
873 INIT_WORK(&efx->mac_work, efx_mac_work);
874 init_waitqueue_head(&efx->flush_wq);
876 rc = efx_init_channels(efx);
880 /* Would be good to use the net_dev name, but we're too early */
881 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
883 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
884 if (!efx->workqueue) {
892 efx_fini_struct(efx);
896 void efx_fini_struct(struct efx_nic *efx)
898 #ifdef CONFIG_RFS_ACCEL
899 kfree(efx->rps_hash_table);
902 efx_fini_channels(efx);
906 if (efx->workqueue) {
907 destroy_workqueue(efx->workqueue);
908 efx->workqueue = NULL;
912 /* This configures the PCI device to enable I/O and DMA. */
913 int efx_init_io(struct efx_nic *efx, int bar, dma_addr_t dma_mask,
914 unsigned int mem_map_size)
916 struct pci_dev *pci_dev = efx->pci_dev;
919 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
921 rc = pci_enable_device(pci_dev);
923 netif_err(efx, probe, efx->net_dev,
924 "failed to enable PCI device\n");
928 pci_set_master(pci_dev);
930 /* Set the PCI DMA mask. Try all possibilities from our
931 * genuine mask down to 32 bits, because some architectures
932 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
933 * masks event though they reject 46 bit masks.
935 while (dma_mask > 0x7fffffffUL) {
936 rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
942 netif_err(efx, probe, efx->net_dev,
943 "could not find a suitable DMA mask\n");
946 netif_dbg(efx, probe, efx->net_dev,
947 "using DMA mask %llx\n", (unsigned long long)dma_mask);
949 efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
950 if (!efx->membase_phys) {
951 netif_err(efx, probe, efx->net_dev,
952 "ERROR: No BAR%d mapping from the BIOS. "
953 "Try pci=realloc on the kernel command line\n", bar);
958 rc = pci_request_region(pci_dev, bar, "sfc");
960 netif_err(efx, probe, efx->net_dev,
961 "request for memory BAR failed\n");
966 efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
968 netif_err(efx, probe, efx->net_dev,
969 "could not map memory BAR at %llx+%x\n",
970 (unsigned long long)efx->membase_phys, mem_map_size);
974 netif_dbg(efx, probe, efx->net_dev,
975 "memory BAR at %llx+%x (virtual %p)\n",
976 (unsigned long long)efx->membase_phys, mem_map_size,
982 pci_release_region(efx->pci_dev, bar);
984 efx->membase_phys = 0;
986 pci_disable_device(efx->pci_dev);
991 void efx_fini_io(struct efx_nic *efx, int bar)
993 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
996 iounmap(efx->membase);
1000 if (efx->membase_phys) {
1001 pci_release_region(efx->pci_dev, bar);
1002 efx->membase_phys = 0;
1005 /* Don't disable bus-mastering if VFs are assigned */
1006 if (!pci_vfs_assigned(efx->pci_dev))
1007 pci_disable_device(efx->pci_dev);
1010 #ifdef CONFIG_SFC_MCDI_LOGGING
1011 static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
1014 struct efx_nic *efx = dev_get_drvdata(dev);
1015 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
1017 return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
1020 static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
1021 const char *buf, size_t count)
1023 struct efx_nic *efx = dev_get_drvdata(dev);
1024 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
1025 bool enable = count > 0 && *buf != '0';
1027 mcdi->logging_enabled = enable;
1031 static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
1033 void efx_init_mcdi_logging(struct efx_nic *efx)
1035 int rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
1038 netif_warn(efx, drv, efx->net_dev,
1039 "failed to init net dev attributes\n");
1043 void efx_fini_mcdi_logging(struct efx_nic *efx)
1045 device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);