1874aeea5SJeff Kirsher /**************************************************************************** 2f7a6d2c4SBen Hutchings * Driver for Solarflare network controllers and boards 3874aeea5SJeff Kirsher * Copyright 2005-2006 Fen Systems Ltd. 4f7a6d2c4SBen Hutchings * Copyright 2005-2013 Solarflare Communications Inc. 5874aeea5SJeff Kirsher * 6874aeea5SJeff Kirsher * This program is free software; you can redistribute it and/or modify it 7874aeea5SJeff Kirsher * under the terms of the GNU General Public License version 2 as published 8874aeea5SJeff Kirsher * by the Free Software Foundation, incorporated herein by reference. 9874aeea5SJeff Kirsher */ 10874aeea5SJeff Kirsher 11874aeea5SJeff Kirsher #include <linux/module.h> 12874aeea5SJeff Kirsher #include <linux/pci.h> 13874aeea5SJeff Kirsher #include <linux/netdevice.h> 14874aeea5SJeff Kirsher #include <linux/etherdevice.h> 15874aeea5SJeff Kirsher #include <linux/delay.h> 16874aeea5SJeff Kirsher #include <linux/notifier.h> 17874aeea5SJeff Kirsher #include <linux/ip.h> 18874aeea5SJeff Kirsher #include <linux/tcp.h> 19874aeea5SJeff Kirsher #include <linux/in.h> 20874aeea5SJeff Kirsher #include <linux/ethtool.h> 21874aeea5SJeff Kirsher #include <linux/topology.h> 22874aeea5SJeff Kirsher #include <linux/gfp.h> 23626950dbSAlexandre Rames #include <linux/aer.h> 24b28405b0SAlexandre Rames #include <linux/interrupt.h> 25874aeea5SJeff Kirsher #include "net_driver.h" 26874aeea5SJeff Kirsher #include "efx.h" 27874aeea5SJeff Kirsher #include "nic.h" 28dd40781eSBen Hutchings #include "selftest.h" 297fa8d547SShradha Shah #include "sriov.h" 30874aeea5SJeff Kirsher 31874aeea5SJeff Kirsher #include "mcdi.h" 32874aeea5SJeff Kirsher #include "workarounds.h" 33874aeea5SJeff Kirsher 34874aeea5SJeff Kirsher /************************************************************************** 35874aeea5SJeff Kirsher * 36874aeea5SJeff Kirsher * Type name strings 37874aeea5SJeff Kirsher * 38874aeea5SJeff Kirsher ************************************************************************** 39874aeea5SJeff Kirsher */ 40874aeea5SJeff Kirsher 41874aeea5SJeff Kirsher /* Loopback mode names (see LOOPBACK_MODE()) */ 42874aeea5SJeff Kirsher const unsigned int efx_loopback_mode_max = LOOPBACK_MAX; 4318e83e4cSBen Hutchings const char *const efx_loopback_mode_names[] = { 44874aeea5SJeff Kirsher [LOOPBACK_NONE] = "NONE", 45874aeea5SJeff Kirsher [LOOPBACK_DATA] = "DATAPATH", 46874aeea5SJeff Kirsher [LOOPBACK_GMAC] = "GMAC", 47874aeea5SJeff Kirsher [LOOPBACK_XGMII] = "XGMII", 48874aeea5SJeff Kirsher [LOOPBACK_XGXS] = "XGXS", 49874aeea5SJeff Kirsher [LOOPBACK_XAUI] = "XAUI", 50874aeea5SJeff Kirsher [LOOPBACK_GMII] = "GMII", 51874aeea5SJeff Kirsher [LOOPBACK_SGMII] = "SGMII", 52874aeea5SJeff Kirsher [LOOPBACK_XGBR] = "XGBR", 53874aeea5SJeff Kirsher [LOOPBACK_XFI] = "XFI", 54874aeea5SJeff Kirsher [LOOPBACK_XAUI_FAR] = "XAUI_FAR", 55874aeea5SJeff Kirsher [LOOPBACK_GMII_FAR] = "GMII_FAR", 56874aeea5SJeff Kirsher [LOOPBACK_SGMII_FAR] = "SGMII_FAR", 57874aeea5SJeff Kirsher [LOOPBACK_XFI_FAR] = "XFI_FAR", 58874aeea5SJeff Kirsher [LOOPBACK_GPHY] = "GPHY", 59874aeea5SJeff Kirsher [LOOPBACK_PHYXS] = "PHYXS", 60874aeea5SJeff Kirsher [LOOPBACK_PCS] = "PCS", 61874aeea5SJeff Kirsher [LOOPBACK_PMAPMD] = "PMA/PMD", 62874aeea5SJeff Kirsher [LOOPBACK_XPORT] = "XPORT", 63874aeea5SJeff Kirsher [LOOPBACK_XGMII_WS] = "XGMII_WS", 64874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS] = "XAUI_WS", 65874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR", 66874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR", 67874aeea5SJeff Kirsher [LOOPBACK_GMII_WS] = "GMII_WS", 68874aeea5SJeff Kirsher [LOOPBACK_XFI_WS] = "XFI_WS", 69874aeea5SJeff Kirsher [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR", 70874aeea5SJeff Kirsher [LOOPBACK_PHYXS_WS] = "PHYXS_WS", 71874aeea5SJeff Kirsher }; 72874aeea5SJeff Kirsher 73874aeea5SJeff Kirsher const unsigned int efx_reset_type_max = RESET_TYPE_MAX; 7418e83e4cSBen Hutchings const char *const efx_reset_type_names[] = { 75874aeea5SJeff Kirsher [RESET_TYPE_INVISIBLE] = "INVISIBLE", 76874aeea5SJeff Kirsher [RESET_TYPE_ALL] = "ALL", 77626950dbSAlexandre Rames [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL", 78874aeea5SJeff Kirsher [RESET_TYPE_WORLD] = "WORLD", 79626950dbSAlexandre Rames [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE", 80087e9025SJon Cooper [RESET_TYPE_DATAPATH] = "DATAPATH", 81e283546cSEdward Cree [RESET_TYPE_MC_BIST] = "MC_BIST", 82874aeea5SJeff Kirsher [RESET_TYPE_DISABLE] = "DISABLE", 83874aeea5SJeff Kirsher [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG", 84874aeea5SJeff Kirsher [RESET_TYPE_INT_ERROR] = "INT_ERROR", 85874aeea5SJeff Kirsher [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY", 863de82b91SAlexandre Rames [RESET_TYPE_DMA_ERROR] = "DMA_ERROR", 87874aeea5SJeff Kirsher [RESET_TYPE_TX_SKIP] = "TX_SKIP", 88874aeea5SJeff Kirsher [RESET_TYPE_MC_FAILURE] = "MC_FAILURE", 89e283546cSEdward Cree [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)", 90874aeea5SJeff Kirsher }; 91874aeea5SJeff Kirsher 92874aeea5SJeff Kirsher /* Reset workqueue. If any NIC has a hardware failure then a reset will be 93874aeea5SJeff Kirsher * queued onto this work queue. This is not a per-nic work queue, because 94874aeea5SJeff Kirsher * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised. 95874aeea5SJeff Kirsher */ 96874aeea5SJeff Kirsher static struct workqueue_struct *reset_workqueue; 97874aeea5SJeff Kirsher 9874cd60a4SJon Cooper /* How often and how many times to poll for a reset while waiting for a 9974cd60a4SJon Cooper * BIST that another function started to complete. 10074cd60a4SJon Cooper */ 10174cd60a4SJon Cooper #define BIST_WAIT_DELAY_MS 100 10274cd60a4SJon Cooper #define BIST_WAIT_DELAY_COUNT 100 10374cd60a4SJon Cooper 104874aeea5SJeff Kirsher /************************************************************************** 105874aeea5SJeff Kirsher * 106874aeea5SJeff Kirsher * Configurable values 107874aeea5SJeff Kirsher * 108874aeea5SJeff Kirsher *************************************************************************/ 109874aeea5SJeff Kirsher 110874aeea5SJeff Kirsher /* 111874aeea5SJeff Kirsher * Use separate channels for TX and RX events 112874aeea5SJeff Kirsher * 113874aeea5SJeff Kirsher * Set this to 1 to use separate channels for TX and RX. It allows us 114874aeea5SJeff Kirsher * to control interrupt affinity separately for TX and RX. 115874aeea5SJeff Kirsher * 116874aeea5SJeff Kirsher * This is only used in MSI-X interrupt mode 117874aeea5SJeff Kirsher */ 118b9cc977dSBen Hutchings static bool separate_tx_channels; 119b9cc977dSBen Hutchings module_param(separate_tx_channels, bool, 0444); 120874aeea5SJeff Kirsher MODULE_PARM_DESC(separate_tx_channels, 121874aeea5SJeff Kirsher "Use separate channels for TX and RX"); 122874aeea5SJeff Kirsher 123874aeea5SJeff Kirsher /* This is the weight assigned to each of the (per-channel) virtual 124874aeea5SJeff Kirsher * NAPI devices. 125874aeea5SJeff Kirsher */ 126874aeea5SJeff Kirsher static int napi_weight = 64; 127874aeea5SJeff Kirsher 128874aeea5SJeff Kirsher /* This is the time (in jiffies) between invocations of the hardware 129626950dbSAlexandre Rames * monitor. 130626950dbSAlexandre Rames * On Falcon-based NICs, this will: 131874aeea5SJeff Kirsher * - Check the on-board hardware monitor; 132874aeea5SJeff Kirsher * - Poll the link state and reconfigure the hardware as necessary. 133626950dbSAlexandre Rames * On Siena-based NICs for power systems with EEH support, this will give EEH a 134626950dbSAlexandre Rames * chance to start. 135874aeea5SJeff Kirsher */ 136874aeea5SJeff Kirsher static unsigned int efx_monitor_interval = 1 * HZ; 137874aeea5SJeff Kirsher 138874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 139874aeea5SJeff Kirsher * module load with ethtool. 140874aeea5SJeff Kirsher * 141874aeea5SJeff Kirsher * The default for RX should strike a balance between increasing the 142874aeea5SJeff Kirsher * round-trip latency and reducing overhead. 143874aeea5SJeff Kirsher */ 144874aeea5SJeff Kirsher static unsigned int rx_irq_mod_usec = 60; 145874aeea5SJeff Kirsher 146874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 147874aeea5SJeff Kirsher * module load with ethtool. 148874aeea5SJeff Kirsher * 149874aeea5SJeff Kirsher * This default is chosen to ensure that a 10G link does not go idle 150874aeea5SJeff Kirsher * while a TX queue is stopped after it has become full. A queue is 151874aeea5SJeff Kirsher * restarted when it drops below half full. The time this takes (assuming 152874aeea5SJeff Kirsher * worst case 3 descriptors per packet and 1024 descriptors) is 153874aeea5SJeff Kirsher * 512 / 3 * 1.2 = 205 usec. 154874aeea5SJeff Kirsher */ 155874aeea5SJeff Kirsher static unsigned int tx_irq_mod_usec = 150; 156874aeea5SJeff Kirsher 157874aeea5SJeff Kirsher /* This is the first interrupt mode to try out of: 158874aeea5SJeff Kirsher * 0 => MSI-X 159874aeea5SJeff Kirsher * 1 => MSI 160874aeea5SJeff Kirsher * 2 => legacy 161874aeea5SJeff Kirsher */ 162874aeea5SJeff Kirsher static unsigned int interrupt_mode; 163874aeea5SJeff Kirsher 164874aeea5SJeff Kirsher /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), 165874aeea5SJeff Kirsher * i.e. the number of CPUs among which we may distribute simultaneous 166874aeea5SJeff Kirsher * interrupt handling. 167874aeea5SJeff Kirsher * 168874aeea5SJeff Kirsher * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. 169cdb08f8fSBen Hutchings * The default (0) means to assign an interrupt to each core. 170874aeea5SJeff Kirsher */ 171874aeea5SJeff Kirsher static unsigned int rss_cpus; 172874aeea5SJeff Kirsher module_param(rss_cpus, uint, 0444); 173874aeea5SJeff Kirsher MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); 174874aeea5SJeff Kirsher 175b9cc977dSBen Hutchings static bool phy_flash_cfg; 176b9cc977dSBen Hutchings module_param(phy_flash_cfg, bool, 0644); 177874aeea5SJeff Kirsher MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); 178874aeea5SJeff Kirsher 179e7bed9c8SBen Hutchings static unsigned irq_adapt_low_thresh = 8000; 180874aeea5SJeff Kirsher module_param(irq_adapt_low_thresh, uint, 0644); 181874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_low_thresh, 182874aeea5SJeff Kirsher "Threshold score for reducing IRQ moderation"); 183874aeea5SJeff Kirsher 184e7bed9c8SBen Hutchings static unsigned irq_adapt_high_thresh = 16000; 185874aeea5SJeff Kirsher module_param(irq_adapt_high_thresh, uint, 0644); 186874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_high_thresh, 187874aeea5SJeff Kirsher "Threshold score for increasing IRQ moderation"); 188874aeea5SJeff Kirsher 189874aeea5SJeff Kirsher static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | 190874aeea5SJeff Kirsher NETIF_MSG_LINK | NETIF_MSG_IFDOWN | 191874aeea5SJeff Kirsher NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | 192874aeea5SJeff Kirsher NETIF_MSG_TX_ERR | NETIF_MSG_HW); 193874aeea5SJeff Kirsher module_param(debug, uint, 0); 194874aeea5SJeff Kirsher MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); 195874aeea5SJeff Kirsher 196874aeea5SJeff Kirsher /************************************************************************** 197874aeea5SJeff Kirsher * 198874aeea5SJeff Kirsher * Utility functions and prototypes 199874aeea5SJeff Kirsher * 200874aeea5SJeff Kirsher *************************************************************************/ 201874aeea5SJeff Kirsher 202261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx); 203d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx); 2047f967c01SBen Hutchings static void efx_remove_channel(struct efx_channel *channel); 205874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx); 2067f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type; 207874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx); 2087f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel); 209874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx); 210874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel); 211874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx); 212874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx); 213874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx); 214874aeea5SJeff Kirsher 215874aeea5SJeff Kirsher #define EFX_ASSERT_RESET_SERIALISED(efx) \ 216874aeea5SJeff Kirsher do { \ 217f16aeea0SBen Hutchings if ((efx->state == STATE_READY) || \ 218626950dbSAlexandre Rames (efx->state == STATE_RECOVERY) || \ 219874aeea5SJeff Kirsher (efx->state == STATE_DISABLED)) \ 220874aeea5SJeff Kirsher ASSERT_RTNL(); \ 221874aeea5SJeff Kirsher } while (0) 222874aeea5SJeff Kirsher 2238b7325b4SBen Hutchings static int efx_check_disabled(struct efx_nic *efx) 2248b7325b4SBen Hutchings { 225626950dbSAlexandre Rames if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) { 2268b7325b4SBen Hutchings netif_err(efx, drv, efx->net_dev, 2278b7325b4SBen Hutchings "device is disabled due to earlier errors\n"); 2288b7325b4SBen Hutchings return -EIO; 2298b7325b4SBen Hutchings } 2308b7325b4SBen Hutchings return 0; 2318b7325b4SBen Hutchings } 2328b7325b4SBen Hutchings 233874aeea5SJeff Kirsher /************************************************************************** 234874aeea5SJeff Kirsher * 235874aeea5SJeff Kirsher * Event queue processing 236874aeea5SJeff Kirsher * 237874aeea5SJeff Kirsher *************************************************************************/ 238874aeea5SJeff Kirsher 239874aeea5SJeff Kirsher /* Process channel's event queue 240874aeea5SJeff Kirsher * 241874aeea5SJeff Kirsher * This function is responsible for processing the event queue of a 242874aeea5SJeff Kirsher * single channel. The caller must guarantee that this function will 243874aeea5SJeff Kirsher * never be concurrently called more than once on the same channel, 244874aeea5SJeff Kirsher * though different channels may be being processed concurrently. 245874aeea5SJeff Kirsher */ 246874aeea5SJeff Kirsher static int efx_process_channel(struct efx_channel *channel, int budget) 247874aeea5SJeff Kirsher { 248874aeea5SJeff Kirsher int spent; 249874aeea5SJeff Kirsher 2509f2cb71cSBen Hutchings if (unlikely(!channel->enabled)) 251874aeea5SJeff Kirsher return 0; 252874aeea5SJeff Kirsher 253874aeea5SJeff Kirsher spent = efx_nic_process_eventq(channel, budget); 254d9ab7007SBen Hutchings if (spent && efx_channel_has_rx_queue(channel)) { 255d9ab7007SBen Hutchings struct efx_rx_queue *rx_queue = 256d9ab7007SBen Hutchings efx_channel_get_rx_queue(channel); 257874aeea5SJeff Kirsher 258ff734ef4SBen Hutchings efx_rx_flush_packet(channel); 259cce28794SJon Cooper efx_fast_push_rx_descriptors(rx_queue, true); 260d9ab7007SBen Hutchings } 261874aeea5SJeff Kirsher 262874aeea5SJeff Kirsher return spent; 263874aeea5SJeff Kirsher } 264874aeea5SJeff Kirsher 265874aeea5SJeff Kirsher /* NAPI poll handler 266874aeea5SJeff Kirsher * 267874aeea5SJeff Kirsher * NAPI guarantees serialisation of polls of the same device, which 268874aeea5SJeff Kirsher * provides the guarantee required by efx_process_channel(). 269874aeea5SJeff Kirsher */ 270874aeea5SJeff Kirsher static int efx_poll(struct napi_struct *napi, int budget) 271874aeea5SJeff Kirsher { 272874aeea5SJeff Kirsher struct efx_channel *channel = 273874aeea5SJeff Kirsher container_of(napi, struct efx_channel, napi_str); 274874aeea5SJeff Kirsher struct efx_nic *efx = channel->efx; 275874aeea5SJeff Kirsher int spent; 276874aeea5SJeff Kirsher 27736763266SAlexandre Rames if (!efx_channel_lock_napi(channel)) 27836763266SAlexandre Rames return budget; 27936763266SAlexandre Rames 280874aeea5SJeff Kirsher netif_vdbg(efx, intr, efx->net_dev, 281874aeea5SJeff Kirsher "channel %d NAPI poll executing on CPU %d\n", 282874aeea5SJeff Kirsher channel->channel, raw_smp_processor_id()); 283874aeea5SJeff Kirsher 284874aeea5SJeff Kirsher spent = efx_process_channel(channel, budget); 285874aeea5SJeff Kirsher 286874aeea5SJeff Kirsher if (spent < budget) { 2879d9a6973SBen Hutchings if (efx_channel_has_rx_queue(channel) && 288874aeea5SJeff Kirsher efx->irq_rx_adaptive && 289874aeea5SJeff Kirsher unlikely(++channel->irq_count == 1000)) { 290874aeea5SJeff Kirsher if (unlikely(channel->irq_mod_score < 291874aeea5SJeff Kirsher irq_adapt_low_thresh)) { 292874aeea5SJeff Kirsher if (channel->irq_moderation > 1) { 293874aeea5SJeff Kirsher channel->irq_moderation -= 1; 294874aeea5SJeff Kirsher efx->type->push_irq_moderation(channel); 295874aeea5SJeff Kirsher } 296874aeea5SJeff Kirsher } else if (unlikely(channel->irq_mod_score > 297874aeea5SJeff Kirsher irq_adapt_high_thresh)) { 298874aeea5SJeff Kirsher if (channel->irq_moderation < 299874aeea5SJeff Kirsher efx->irq_rx_moderation) { 300874aeea5SJeff Kirsher channel->irq_moderation += 1; 301874aeea5SJeff Kirsher efx->type->push_irq_moderation(channel); 302874aeea5SJeff Kirsher } 303874aeea5SJeff Kirsher } 304874aeea5SJeff Kirsher channel->irq_count = 0; 305874aeea5SJeff Kirsher channel->irq_mod_score = 0; 306874aeea5SJeff Kirsher } 307874aeea5SJeff Kirsher 308874aeea5SJeff Kirsher efx_filter_rfs_expire(channel); 309874aeea5SJeff Kirsher 310874aeea5SJeff Kirsher /* There is no race here; although napi_disable() will 311874aeea5SJeff Kirsher * only wait for napi_complete(), this isn't a problem 312514bedbcSBen Hutchings * since efx_nic_eventq_read_ack() will have no effect if 313874aeea5SJeff Kirsher * interrupts have already been disabled. 314874aeea5SJeff Kirsher */ 315874aeea5SJeff Kirsher napi_complete(napi); 316514bedbcSBen Hutchings efx_nic_eventq_read_ack(channel); 317874aeea5SJeff Kirsher } 318874aeea5SJeff Kirsher 31936763266SAlexandre Rames efx_channel_unlock_napi(channel); 320874aeea5SJeff Kirsher return spent; 321874aeea5SJeff Kirsher } 322874aeea5SJeff Kirsher 323874aeea5SJeff Kirsher /* Create event queue 324874aeea5SJeff Kirsher * Event queue memory allocations are done only once. If the channel 325874aeea5SJeff Kirsher * is reset, the memory buffer will be reused; this guards against 326874aeea5SJeff Kirsher * errors during channel reset and also simplifies interrupt handling. 327874aeea5SJeff Kirsher */ 328874aeea5SJeff Kirsher static int efx_probe_eventq(struct efx_channel *channel) 329874aeea5SJeff Kirsher { 330874aeea5SJeff Kirsher struct efx_nic *efx = channel->efx; 331874aeea5SJeff Kirsher unsigned long entries; 332874aeea5SJeff Kirsher 33386ee5302SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 334874aeea5SJeff Kirsher "chan %d create event queue\n", channel->channel); 335874aeea5SJeff Kirsher 336874aeea5SJeff Kirsher /* Build an event queue with room for one event per tx and rx buffer, 337874aeea5SJeff Kirsher * plus some extra for link state events and MCDI completions. */ 338874aeea5SJeff Kirsher entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128); 339874aeea5SJeff Kirsher EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE); 340874aeea5SJeff Kirsher channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1; 341874aeea5SJeff Kirsher 342874aeea5SJeff Kirsher return efx_nic_probe_eventq(channel); 343874aeea5SJeff Kirsher } 344874aeea5SJeff Kirsher 345874aeea5SJeff Kirsher /* Prepare channel's event queue */ 346261e4d96SJon Cooper static int efx_init_eventq(struct efx_channel *channel) 347874aeea5SJeff Kirsher { 34815acb1ceSBen Hutchings struct efx_nic *efx = channel->efx; 349261e4d96SJon Cooper int rc; 350261e4d96SJon Cooper 351261e4d96SJon Cooper EFX_WARN_ON_PARANOID(channel->eventq_init); 352261e4d96SJon Cooper 35315acb1ceSBen Hutchings netif_dbg(efx, drv, efx->net_dev, 354874aeea5SJeff Kirsher "chan %d init event queue\n", channel->channel); 355874aeea5SJeff Kirsher 356261e4d96SJon Cooper rc = efx_nic_init_eventq(channel); 357261e4d96SJon Cooper if (rc == 0) { 35815acb1ceSBen Hutchings efx->type->push_irq_moderation(channel); 359874aeea5SJeff Kirsher channel->eventq_read_ptr = 0; 360be3fc09cSBen Hutchings channel->eventq_init = true; 361874aeea5SJeff Kirsher } 362261e4d96SJon Cooper return rc; 363261e4d96SJon Cooper } 364874aeea5SJeff Kirsher 3659f2cb71cSBen Hutchings /* Enable event queue processing and NAPI */ 36636763266SAlexandre Rames void efx_start_eventq(struct efx_channel *channel) 3679f2cb71cSBen Hutchings { 3689f2cb71cSBen Hutchings netif_dbg(channel->efx, ifup, channel->efx->net_dev, 3699f2cb71cSBen Hutchings "chan %d start event queue\n", channel->channel); 3709f2cb71cSBen Hutchings 371514bedbcSBen Hutchings /* Make sure the NAPI handler sees the enabled flag set */ 3729f2cb71cSBen Hutchings channel->enabled = true; 3739f2cb71cSBen Hutchings smp_wmb(); 3749f2cb71cSBen Hutchings 37536763266SAlexandre Rames efx_channel_enable(channel); 3769f2cb71cSBen Hutchings napi_enable(&channel->napi_str); 3779f2cb71cSBen Hutchings efx_nic_eventq_read_ack(channel); 3789f2cb71cSBen Hutchings } 3799f2cb71cSBen Hutchings 3809f2cb71cSBen Hutchings /* Disable event queue processing and NAPI */ 38136763266SAlexandre Rames void efx_stop_eventq(struct efx_channel *channel) 3829f2cb71cSBen Hutchings { 3839f2cb71cSBen Hutchings if (!channel->enabled) 3849f2cb71cSBen Hutchings return; 3859f2cb71cSBen Hutchings 3869f2cb71cSBen Hutchings napi_disable(&channel->napi_str); 38736763266SAlexandre Rames while (!efx_channel_disable(channel)) 38836763266SAlexandre Rames usleep_range(1000, 20000); 3899f2cb71cSBen Hutchings channel->enabled = false; 3909f2cb71cSBen Hutchings } 3919f2cb71cSBen Hutchings 392874aeea5SJeff Kirsher static void efx_fini_eventq(struct efx_channel *channel) 393874aeea5SJeff Kirsher { 394be3fc09cSBen Hutchings if (!channel->eventq_init) 395be3fc09cSBen Hutchings return; 396be3fc09cSBen Hutchings 397874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 398874aeea5SJeff Kirsher "chan %d fini event queue\n", channel->channel); 399874aeea5SJeff Kirsher 400874aeea5SJeff Kirsher efx_nic_fini_eventq(channel); 401be3fc09cSBen Hutchings channel->eventq_init = false; 402874aeea5SJeff Kirsher } 403874aeea5SJeff Kirsher 404874aeea5SJeff Kirsher static void efx_remove_eventq(struct efx_channel *channel) 405874aeea5SJeff Kirsher { 406874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 407874aeea5SJeff Kirsher "chan %d remove event queue\n", channel->channel); 408874aeea5SJeff Kirsher 409874aeea5SJeff Kirsher efx_nic_remove_eventq(channel); 410874aeea5SJeff Kirsher } 411874aeea5SJeff Kirsher 412874aeea5SJeff Kirsher /************************************************************************** 413874aeea5SJeff Kirsher * 414874aeea5SJeff Kirsher * Channel handling 415874aeea5SJeff Kirsher * 416874aeea5SJeff Kirsher *************************************************************************/ 417874aeea5SJeff Kirsher 4187f967c01SBen Hutchings /* Allocate and initialise a channel structure. */ 419874aeea5SJeff Kirsher static struct efx_channel * 420874aeea5SJeff Kirsher efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) 421874aeea5SJeff Kirsher { 422874aeea5SJeff Kirsher struct efx_channel *channel; 423874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 424874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 425874aeea5SJeff Kirsher int j; 426874aeea5SJeff Kirsher 4277f967c01SBen Hutchings channel = kzalloc(sizeof(*channel), GFP_KERNEL); 4287f967c01SBen Hutchings if (!channel) 4297f967c01SBen Hutchings return NULL; 4307f967c01SBen Hutchings 4317f967c01SBen Hutchings channel->efx = efx; 4327f967c01SBen Hutchings channel->channel = i; 4337f967c01SBen Hutchings channel->type = &efx_default_channel_type; 4347f967c01SBen Hutchings 4357f967c01SBen Hutchings for (j = 0; j < EFX_TXQ_TYPES; j++) { 4367f967c01SBen Hutchings tx_queue = &channel->tx_queue[j]; 4377f967c01SBen Hutchings tx_queue->efx = efx; 4387f967c01SBen Hutchings tx_queue->queue = i * EFX_TXQ_TYPES + j; 4397f967c01SBen Hutchings tx_queue->channel = channel; 4407f967c01SBen Hutchings } 4417f967c01SBen Hutchings 4427f967c01SBen Hutchings rx_queue = &channel->rx_queue; 4437f967c01SBen Hutchings rx_queue->efx = efx; 4447f967c01SBen Hutchings setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, 4457f967c01SBen Hutchings (unsigned long)rx_queue); 4467f967c01SBen Hutchings 4477f967c01SBen Hutchings return channel; 4487f967c01SBen Hutchings } 4497f967c01SBen Hutchings 4507f967c01SBen Hutchings /* Allocate and initialise a channel structure, copying parameters 4517f967c01SBen Hutchings * (but not resources) from an old channel structure. 4527f967c01SBen Hutchings */ 4537f967c01SBen Hutchings static struct efx_channel * 4547f967c01SBen Hutchings efx_copy_channel(const struct efx_channel *old_channel) 4557f967c01SBen Hutchings { 4567f967c01SBen Hutchings struct efx_channel *channel; 4577f967c01SBen Hutchings struct efx_rx_queue *rx_queue; 4587f967c01SBen Hutchings struct efx_tx_queue *tx_queue; 4597f967c01SBen Hutchings int j; 4607f967c01SBen Hutchings 461874aeea5SJeff Kirsher channel = kmalloc(sizeof(*channel), GFP_KERNEL); 462874aeea5SJeff Kirsher if (!channel) 463874aeea5SJeff Kirsher return NULL; 464874aeea5SJeff Kirsher 465874aeea5SJeff Kirsher *channel = *old_channel; 466874aeea5SJeff Kirsher 467874aeea5SJeff Kirsher channel->napi_dev = NULL; 468874aeea5SJeff Kirsher memset(&channel->eventq, 0, sizeof(channel->eventq)); 469874aeea5SJeff Kirsher 470874aeea5SJeff Kirsher for (j = 0; j < EFX_TXQ_TYPES; j++) { 471874aeea5SJeff Kirsher tx_queue = &channel->tx_queue[j]; 472874aeea5SJeff Kirsher if (tx_queue->channel) 473874aeea5SJeff Kirsher tx_queue->channel = channel; 474874aeea5SJeff Kirsher tx_queue->buffer = NULL; 475874aeea5SJeff Kirsher memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); 476874aeea5SJeff Kirsher } 477874aeea5SJeff Kirsher 478874aeea5SJeff Kirsher rx_queue = &channel->rx_queue; 4797f967c01SBen Hutchings rx_queue->buffer = NULL; 4807f967c01SBen Hutchings memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 481874aeea5SJeff Kirsher setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, 482874aeea5SJeff Kirsher (unsigned long)rx_queue); 483874aeea5SJeff Kirsher 484874aeea5SJeff Kirsher return channel; 485874aeea5SJeff Kirsher } 486874aeea5SJeff Kirsher 487874aeea5SJeff Kirsher static int efx_probe_channel(struct efx_channel *channel) 488874aeea5SJeff Kirsher { 489874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 490874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 491874aeea5SJeff Kirsher int rc; 492874aeea5SJeff Kirsher 493874aeea5SJeff Kirsher netif_dbg(channel->efx, probe, channel->efx->net_dev, 494874aeea5SJeff Kirsher "creating channel %d\n", channel->channel); 495874aeea5SJeff Kirsher 4967f967c01SBen Hutchings rc = channel->type->pre_probe(channel); 4977f967c01SBen Hutchings if (rc) 4987f967c01SBen Hutchings goto fail; 4997f967c01SBen Hutchings 500874aeea5SJeff Kirsher rc = efx_probe_eventq(channel); 501874aeea5SJeff Kirsher if (rc) 5027f967c01SBen Hutchings goto fail; 503874aeea5SJeff Kirsher 504874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) { 505874aeea5SJeff Kirsher rc = efx_probe_tx_queue(tx_queue); 506874aeea5SJeff Kirsher if (rc) 5077f967c01SBen Hutchings goto fail; 508874aeea5SJeff Kirsher } 509874aeea5SJeff Kirsher 510874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) { 511874aeea5SJeff Kirsher rc = efx_probe_rx_queue(rx_queue); 512874aeea5SJeff Kirsher if (rc) 5137f967c01SBen Hutchings goto fail; 514874aeea5SJeff Kirsher } 515874aeea5SJeff Kirsher 516874aeea5SJeff Kirsher return 0; 517874aeea5SJeff Kirsher 5187f967c01SBen Hutchings fail: 5197f967c01SBen Hutchings efx_remove_channel(channel); 520874aeea5SJeff Kirsher return rc; 521874aeea5SJeff Kirsher } 522874aeea5SJeff Kirsher 5237f967c01SBen Hutchings static void 5247f967c01SBen Hutchings efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) 5257f967c01SBen Hutchings { 5267f967c01SBen Hutchings struct efx_nic *efx = channel->efx; 5277f967c01SBen Hutchings const char *type; 5287f967c01SBen Hutchings int number; 5297f967c01SBen Hutchings 5307f967c01SBen Hutchings number = channel->channel; 5317f967c01SBen Hutchings if (efx->tx_channel_offset == 0) { 5327f967c01SBen Hutchings type = ""; 5337f967c01SBen Hutchings } else if (channel->channel < efx->tx_channel_offset) { 5347f967c01SBen Hutchings type = "-rx"; 5357f967c01SBen Hutchings } else { 5367f967c01SBen Hutchings type = "-tx"; 5377f967c01SBen Hutchings number -= efx->tx_channel_offset; 5387f967c01SBen Hutchings } 5397f967c01SBen Hutchings snprintf(buf, len, "%s%s-%d", efx->name, type, number); 5407f967c01SBen Hutchings } 541874aeea5SJeff Kirsher 542874aeea5SJeff Kirsher static void efx_set_channel_names(struct efx_nic *efx) 543874aeea5SJeff Kirsher { 544874aeea5SJeff Kirsher struct efx_channel *channel; 545874aeea5SJeff Kirsher 5467f967c01SBen Hutchings efx_for_each_channel(channel, efx) 5477f967c01SBen Hutchings channel->type->get_name(channel, 548d8291187SBen Hutchings efx->msi_context[channel->channel].name, 549d8291187SBen Hutchings sizeof(efx->msi_context[0].name)); 550874aeea5SJeff Kirsher } 551874aeea5SJeff Kirsher 552874aeea5SJeff Kirsher static int efx_probe_channels(struct efx_nic *efx) 553874aeea5SJeff Kirsher { 554874aeea5SJeff Kirsher struct efx_channel *channel; 555874aeea5SJeff Kirsher int rc; 556874aeea5SJeff Kirsher 557874aeea5SJeff Kirsher /* Restart special buffer allocation */ 558874aeea5SJeff Kirsher efx->next_buffer_table = 0; 559874aeea5SJeff Kirsher 560c92aaff1SBen Hutchings /* Probe channels in reverse, so that any 'extra' channels 561c92aaff1SBen Hutchings * use the start of the buffer table. This allows the traffic 562c92aaff1SBen Hutchings * channels to be resized without moving them or wasting the 563c92aaff1SBen Hutchings * entries before them. 564c92aaff1SBen Hutchings */ 565c92aaff1SBen Hutchings efx_for_each_channel_rev(channel, efx) { 566874aeea5SJeff Kirsher rc = efx_probe_channel(channel); 567874aeea5SJeff Kirsher if (rc) { 568874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 569874aeea5SJeff Kirsher "failed to create channel %d\n", 570874aeea5SJeff Kirsher channel->channel); 571874aeea5SJeff Kirsher goto fail; 572874aeea5SJeff Kirsher } 573874aeea5SJeff Kirsher } 574874aeea5SJeff Kirsher efx_set_channel_names(efx); 575874aeea5SJeff Kirsher 576874aeea5SJeff Kirsher return 0; 577874aeea5SJeff Kirsher 578874aeea5SJeff Kirsher fail: 579874aeea5SJeff Kirsher efx_remove_channels(efx); 580874aeea5SJeff Kirsher return rc; 581874aeea5SJeff Kirsher } 582874aeea5SJeff Kirsher 583874aeea5SJeff Kirsher /* Channels are shutdown and reinitialised whilst the NIC is running 584874aeea5SJeff Kirsher * to propagate configuration changes (mtu, checksum offload), or 585874aeea5SJeff Kirsher * to clear hardware error conditions 586874aeea5SJeff Kirsher */ 5879f2cb71cSBen Hutchings static void efx_start_datapath(struct efx_nic *efx) 588874aeea5SJeff Kirsher { 58985740cdfSBen Hutchings bool old_rx_scatter = efx->rx_scatter; 590874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 591874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 592874aeea5SJeff Kirsher struct efx_channel *channel; 59385740cdfSBen Hutchings size_t rx_buf_len; 594874aeea5SJeff Kirsher 595874aeea5SJeff Kirsher /* Calculate the rx buffer allocation parameters required to 596874aeea5SJeff Kirsher * support the current MTU, including padding for header 597874aeea5SJeff Kirsher * alignment and overruns. 598874aeea5SJeff Kirsher */ 59943a3739dSJon Cooper efx->rx_dma_len = (efx->rx_prefix_size + 600874aeea5SJeff Kirsher EFX_MAX_FRAME_LEN(efx->net_dev->mtu) + 601874aeea5SJeff Kirsher efx->type->rx_buffer_padding); 60285740cdfSBen Hutchings rx_buf_len = (sizeof(struct efx_rx_page_state) + 6032ec03014SAndrew Rybchenko efx->rx_ip_align + efx->rx_dma_len); 60485740cdfSBen Hutchings if (rx_buf_len <= PAGE_SIZE) { 605e8c68c0aSJon Cooper efx->rx_scatter = efx->type->always_rx_scatter; 60685740cdfSBen Hutchings efx->rx_buffer_order = 0; 60785740cdfSBen Hutchings } else if (efx->type->can_rx_scatter) { 608950c54dfSBen Hutchings BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES); 60985740cdfSBen Hutchings BUILD_BUG_ON(sizeof(struct efx_rx_page_state) + 610950c54dfSBen Hutchings 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE, 611950c54dfSBen Hutchings EFX_RX_BUF_ALIGNMENT) > 612950c54dfSBen Hutchings PAGE_SIZE); 61385740cdfSBen Hutchings efx->rx_scatter = true; 61485740cdfSBen Hutchings efx->rx_dma_len = EFX_RX_USR_BUF_SIZE; 61585740cdfSBen Hutchings efx->rx_buffer_order = 0; 61685740cdfSBen Hutchings } else { 61785740cdfSBen Hutchings efx->rx_scatter = false; 61885740cdfSBen Hutchings efx->rx_buffer_order = get_order(rx_buf_len); 61985740cdfSBen Hutchings } 62085740cdfSBen Hutchings 6211648a23fSDaniel Pieczko efx_rx_config_page_split(efx); 6221648a23fSDaniel Pieczko if (efx->rx_buffer_order) 6231648a23fSDaniel Pieczko netif_dbg(efx, drv, efx->net_dev, 6241648a23fSDaniel Pieczko "RX buf len=%u; page order=%u batch=%u\n", 6251648a23fSDaniel Pieczko efx->rx_dma_len, efx->rx_buffer_order, 6261648a23fSDaniel Pieczko efx->rx_pages_per_batch); 6271648a23fSDaniel Pieczko else 6281648a23fSDaniel Pieczko netif_dbg(efx, drv, efx->net_dev, 6291648a23fSDaniel Pieczko "RX buf len=%u step=%u bpp=%u; page batch=%u\n", 6301648a23fSDaniel Pieczko efx->rx_dma_len, efx->rx_page_buf_step, 6311648a23fSDaniel Pieczko efx->rx_bufs_per_page, efx->rx_pages_per_batch); 6322768935aSDaniel Pieczko 633e8c68c0aSJon Cooper /* RX filters may also have scatter-enabled flags */ 63485740cdfSBen Hutchings if (efx->rx_scatter != old_rx_scatter) 635add72477SBen Hutchings efx->type->filter_update_rx_scatter(efx); 636874aeea5SJeff Kirsher 63714bf718fSBen Hutchings /* We must keep at least one descriptor in a TX ring empty. 63814bf718fSBen Hutchings * We could avoid this when the queue size does not exactly 63914bf718fSBen Hutchings * match the hardware ring size, but it's not that important. 64014bf718fSBen Hutchings * Therefore we stop the queue when one more skb might fill 64114bf718fSBen Hutchings * the ring completely. We wake it when half way back to 64214bf718fSBen Hutchings * empty. 64314bf718fSBen Hutchings */ 64414bf718fSBen Hutchings efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx); 64514bf718fSBen Hutchings efx->txq_wake_thresh = efx->txq_stop_thresh / 2; 64614bf718fSBen Hutchings 647874aeea5SJeff Kirsher /* Initialise the channels */ 648874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 6493881d8abSAlexandre Rames efx_for_each_channel_tx_queue(tx_queue, channel) { 650874aeea5SJeff Kirsher efx_init_tx_queue(tx_queue); 6513881d8abSAlexandre Rames atomic_inc(&efx->active_queues); 6523881d8abSAlexandre Rames } 653874aeea5SJeff Kirsher 6549f2cb71cSBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) { 655874aeea5SJeff Kirsher efx_init_rx_queue(rx_queue); 6563881d8abSAlexandre Rames atomic_inc(&efx->active_queues); 657cce28794SJon Cooper efx_stop_eventq(channel); 658cce28794SJon Cooper efx_fast_push_rx_descriptors(rx_queue, false); 659cce28794SJon Cooper efx_start_eventq(channel); 6609f2cb71cSBen Hutchings } 661874aeea5SJeff Kirsher 66285740cdfSBen Hutchings WARN_ON(channel->rx_pkt_n_frags); 663874aeea5SJeff Kirsher } 6649f2cb71cSBen Hutchings 6652ea4dc28SAlexandre Rames efx_ptp_start_datapath(efx); 6662ea4dc28SAlexandre Rames 6679f2cb71cSBen Hutchings if (netif_device_present(efx->net_dev)) 6689f2cb71cSBen Hutchings netif_tx_wake_all_queues(efx->net_dev); 669874aeea5SJeff Kirsher } 670874aeea5SJeff Kirsher 6719f2cb71cSBen Hutchings static void efx_stop_datapath(struct efx_nic *efx) 672874aeea5SJeff Kirsher { 673874aeea5SJeff Kirsher struct efx_channel *channel; 674874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 675874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 676874aeea5SJeff Kirsher int rc; 677874aeea5SJeff Kirsher 678874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 679874aeea5SJeff Kirsher BUG_ON(efx->port_enabled); 680874aeea5SJeff Kirsher 6812ea4dc28SAlexandre Rames efx_ptp_stop_datapath(efx); 6822ea4dc28SAlexandre Rames 683d8aec745SBen Hutchings /* Stop RX refill */ 684d8aec745SBen Hutchings efx_for_each_channel(channel, efx) { 685d8aec745SBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) 686d8aec745SBen Hutchings rx_queue->refill_enabled = false; 687d8aec745SBen Hutchings } 688d8aec745SBen Hutchings 689874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 6909f2cb71cSBen Hutchings /* RX packet processing is pipelined, so wait for the 6919f2cb71cSBen Hutchings * NAPI handler to complete. At least event queue 0 6929f2cb71cSBen Hutchings * might be kept active by non-data events, so don't 6939f2cb71cSBen Hutchings * use napi_synchronize() but actually disable NAPI 6949f2cb71cSBen Hutchings * temporarily. 6959f2cb71cSBen Hutchings */ 6969f2cb71cSBen Hutchings if (efx_channel_has_rx_queue(channel)) { 6979f2cb71cSBen Hutchings efx_stop_eventq(channel); 6989f2cb71cSBen Hutchings efx_start_eventq(channel); 6999f2cb71cSBen Hutchings } 700e42c3d85SBen Hutchings } 701874aeea5SJeff Kirsher 702e42c3d85SBen Hutchings rc = efx->type->fini_dmaq(efx); 703e42c3d85SBen Hutchings if (rc && EFX_WORKAROUND_7803(efx)) { 704e42c3d85SBen Hutchings /* Schedule a reset to recover from the flush failure. The 705e42c3d85SBen Hutchings * descriptor caches reference memory we're about to free, 706e42c3d85SBen Hutchings * but falcon_reconfigure_mac_wrapper() won't reconnect 707e42c3d85SBen Hutchings * the MACs because of the pending reset. 708e42c3d85SBen Hutchings */ 709e42c3d85SBen Hutchings netif_err(efx, drv, efx->net_dev, 710e42c3d85SBen Hutchings "Resetting to recover from flush failure\n"); 711e42c3d85SBen Hutchings efx_schedule_reset(efx, RESET_TYPE_ALL); 712e42c3d85SBen Hutchings } else if (rc) { 713e42c3d85SBen Hutchings netif_err(efx, drv, efx->net_dev, "failed to flush queues\n"); 714e42c3d85SBen Hutchings } else { 715e42c3d85SBen Hutchings netif_dbg(efx, drv, efx->net_dev, 716e42c3d85SBen Hutchings "successfully flushed all queues\n"); 717e42c3d85SBen Hutchings } 718e42c3d85SBen Hutchings 719e42c3d85SBen Hutchings efx_for_each_channel(channel, efx) { 720874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) 721874aeea5SJeff Kirsher efx_fini_rx_queue(rx_queue); 722874aeea5SJeff Kirsher efx_for_each_possible_channel_tx_queue(tx_queue, channel) 723874aeea5SJeff Kirsher efx_fini_tx_queue(tx_queue); 724874aeea5SJeff Kirsher } 725874aeea5SJeff Kirsher } 726874aeea5SJeff Kirsher 727874aeea5SJeff Kirsher static void efx_remove_channel(struct efx_channel *channel) 728874aeea5SJeff Kirsher { 729874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 730874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 731874aeea5SJeff Kirsher 732874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 733874aeea5SJeff Kirsher "destroy chan %d\n", channel->channel); 734874aeea5SJeff Kirsher 735874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) 736874aeea5SJeff Kirsher efx_remove_rx_queue(rx_queue); 737874aeea5SJeff Kirsher efx_for_each_possible_channel_tx_queue(tx_queue, channel) 738874aeea5SJeff Kirsher efx_remove_tx_queue(tx_queue); 739874aeea5SJeff Kirsher efx_remove_eventq(channel); 740c31e5f9fSStuart Hodgson channel->type->post_remove(channel); 741874aeea5SJeff Kirsher } 742874aeea5SJeff Kirsher 743874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx) 744874aeea5SJeff Kirsher { 745874aeea5SJeff Kirsher struct efx_channel *channel; 746874aeea5SJeff Kirsher 747874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 748874aeea5SJeff Kirsher efx_remove_channel(channel); 749874aeea5SJeff Kirsher } 750874aeea5SJeff Kirsher 751874aeea5SJeff Kirsher int 752874aeea5SJeff Kirsher efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) 753874aeea5SJeff Kirsher { 754874aeea5SJeff Kirsher struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; 755874aeea5SJeff Kirsher u32 old_rxq_entries, old_txq_entries; 7567f967c01SBen Hutchings unsigned i, next_buffer_table = 0; 757261e4d96SJon Cooper int rc, rc2; 7588b7325b4SBen Hutchings 7598b7325b4SBen Hutchings rc = efx_check_disabled(efx); 7608b7325b4SBen Hutchings if (rc) 7618b7325b4SBen Hutchings return rc; 7627f967c01SBen Hutchings 7637f967c01SBen Hutchings /* Not all channels should be reallocated. We must avoid 7647f967c01SBen Hutchings * reallocating their buffer table entries. 7657f967c01SBen Hutchings */ 7667f967c01SBen Hutchings efx_for_each_channel(channel, efx) { 7677f967c01SBen Hutchings struct efx_rx_queue *rx_queue; 7687f967c01SBen Hutchings struct efx_tx_queue *tx_queue; 7697f967c01SBen Hutchings 7707f967c01SBen Hutchings if (channel->type->copy) 7717f967c01SBen Hutchings continue; 7727f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 7737f967c01SBen Hutchings channel->eventq.index + 7747f967c01SBen Hutchings channel->eventq.entries); 7757f967c01SBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) 7767f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 7777f967c01SBen Hutchings rx_queue->rxd.index + 7787f967c01SBen Hutchings rx_queue->rxd.entries); 7797f967c01SBen Hutchings efx_for_each_channel_tx_queue(tx_queue, channel) 7807f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 7817f967c01SBen Hutchings tx_queue->txd.index + 7827f967c01SBen Hutchings tx_queue->txd.entries); 7837f967c01SBen Hutchings } 784874aeea5SJeff Kirsher 78529c69a48SBen Hutchings efx_device_detach_sync(efx); 786874aeea5SJeff Kirsher efx_stop_all(efx); 787d8291187SBen Hutchings efx_soft_disable_interrupts(efx); 788874aeea5SJeff Kirsher 7897f967c01SBen Hutchings /* Clone channels (where possible) */ 790874aeea5SJeff Kirsher memset(other_channel, 0, sizeof(other_channel)); 791874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 7927f967c01SBen Hutchings channel = efx->channel[i]; 7937f967c01SBen Hutchings if (channel->type->copy) 7947f967c01SBen Hutchings channel = channel->type->copy(channel); 795874aeea5SJeff Kirsher if (!channel) { 796874aeea5SJeff Kirsher rc = -ENOMEM; 797874aeea5SJeff Kirsher goto out; 798874aeea5SJeff Kirsher } 799874aeea5SJeff Kirsher other_channel[i] = channel; 800874aeea5SJeff Kirsher } 801874aeea5SJeff Kirsher 802874aeea5SJeff Kirsher /* Swap entry counts and channel pointers */ 803874aeea5SJeff Kirsher old_rxq_entries = efx->rxq_entries; 804874aeea5SJeff Kirsher old_txq_entries = efx->txq_entries; 805874aeea5SJeff Kirsher efx->rxq_entries = rxq_entries; 806874aeea5SJeff Kirsher efx->txq_entries = txq_entries; 807874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 808874aeea5SJeff Kirsher channel = efx->channel[i]; 809874aeea5SJeff Kirsher efx->channel[i] = other_channel[i]; 810874aeea5SJeff Kirsher other_channel[i] = channel; 811874aeea5SJeff Kirsher } 812874aeea5SJeff Kirsher 8137f967c01SBen Hutchings /* Restart buffer table allocation */ 8147f967c01SBen Hutchings efx->next_buffer_table = next_buffer_table; 8157f967c01SBen Hutchings 8167f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) { 8177f967c01SBen Hutchings channel = efx->channel[i]; 8187f967c01SBen Hutchings if (!channel->type->copy) 8197f967c01SBen Hutchings continue; 8207f967c01SBen Hutchings rc = efx_probe_channel(channel); 821874aeea5SJeff Kirsher if (rc) 822874aeea5SJeff Kirsher goto rollback; 8237f967c01SBen Hutchings efx_init_napi_channel(efx->channel[i]); 824874aeea5SJeff Kirsher } 825874aeea5SJeff Kirsher 8267f967c01SBen Hutchings out: 8277f967c01SBen Hutchings /* Destroy unused channel structures */ 8287f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) { 8297f967c01SBen Hutchings channel = other_channel[i]; 8307f967c01SBen Hutchings if (channel && channel->type->copy) { 8317f967c01SBen Hutchings efx_fini_napi_channel(channel); 8327f967c01SBen Hutchings efx_remove_channel(channel); 8337f967c01SBen Hutchings kfree(channel); 8347f967c01SBen Hutchings } 8357f967c01SBen Hutchings } 8367f967c01SBen Hutchings 837261e4d96SJon Cooper rc2 = efx_soft_enable_interrupts(efx); 838261e4d96SJon Cooper if (rc2) { 839261e4d96SJon Cooper rc = rc ? rc : rc2; 840261e4d96SJon Cooper netif_err(efx, drv, efx->net_dev, 841261e4d96SJon Cooper "unable to restart interrupts on channel reallocation\n"); 842261e4d96SJon Cooper efx_schedule_reset(efx, RESET_TYPE_DISABLE); 843261e4d96SJon Cooper } else { 844874aeea5SJeff Kirsher efx_start_all(efx); 84529c69a48SBen Hutchings netif_device_attach(efx->net_dev); 846261e4d96SJon Cooper } 847874aeea5SJeff Kirsher return rc; 848874aeea5SJeff Kirsher 849874aeea5SJeff Kirsher rollback: 850874aeea5SJeff Kirsher /* Swap back */ 851874aeea5SJeff Kirsher efx->rxq_entries = old_rxq_entries; 852874aeea5SJeff Kirsher efx->txq_entries = old_txq_entries; 853874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 854874aeea5SJeff Kirsher channel = efx->channel[i]; 855874aeea5SJeff Kirsher efx->channel[i] = other_channel[i]; 856874aeea5SJeff Kirsher other_channel[i] = channel; 857874aeea5SJeff Kirsher } 858874aeea5SJeff Kirsher goto out; 859874aeea5SJeff Kirsher } 860874aeea5SJeff Kirsher 861874aeea5SJeff Kirsher void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue) 862874aeea5SJeff Kirsher { 863874aeea5SJeff Kirsher mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100)); 864874aeea5SJeff Kirsher } 865874aeea5SJeff Kirsher 8667f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type = { 8677f967c01SBen Hutchings .pre_probe = efx_channel_dummy_op_int, 868c31e5f9fSStuart Hodgson .post_remove = efx_channel_dummy_op_void, 8697f967c01SBen Hutchings .get_name = efx_get_channel_name, 8707f967c01SBen Hutchings .copy = efx_copy_channel, 8717f967c01SBen Hutchings .keep_eventq = false, 8727f967c01SBen Hutchings }; 8737f967c01SBen Hutchings 8747f967c01SBen Hutchings int efx_channel_dummy_op_int(struct efx_channel *channel) 8757f967c01SBen Hutchings { 8767f967c01SBen Hutchings return 0; 8777f967c01SBen Hutchings } 8787f967c01SBen Hutchings 879c31e5f9fSStuart Hodgson void efx_channel_dummy_op_void(struct efx_channel *channel) 880c31e5f9fSStuart Hodgson { 881c31e5f9fSStuart Hodgson } 882c31e5f9fSStuart Hodgson 883874aeea5SJeff Kirsher /************************************************************************** 884874aeea5SJeff Kirsher * 885874aeea5SJeff Kirsher * Port handling 886874aeea5SJeff Kirsher * 887874aeea5SJeff Kirsher **************************************************************************/ 888874aeea5SJeff Kirsher 889874aeea5SJeff Kirsher /* This ensures that the kernel is kept informed (via 890874aeea5SJeff Kirsher * netif_carrier_on/off) of the link status, and also maintains the 891874aeea5SJeff Kirsher * link status's stop on the port's TX queue. 892874aeea5SJeff Kirsher */ 893874aeea5SJeff Kirsher void efx_link_status_changed(struct efx_nic *efx) 894874aeea5SJeff Kirsher { 895874aeea5SJeff Kirsher struct efx_link_state *link_state = &efx->link_state; 896874aeea5SJeff Kirsher 897874aeea5SJeff Kirsher /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure 898874aeea5SJeff Kirsher * that no events are triggered between unregister_netdev() and the 899874aeea5SJeff Kirsher * driver unloading. A more general condition is that NETDEV_CHANGE 900874aeea5SJeff Kirsher * can only be generated between NETDEV_UP and NETDEV_DOWN */ 901874aeea5SJeff Kirsher if (!netif_running(efx->net_dev)) 902874aeea5SJeff Kirsher return; 903874aeea5SJeff Kirsher 904874aeea5SJeff Kirsher if (link_state->up != netif_carrier_ok(efx->net_dev)) { 905874aeea5SJeff Kirsher efx->n_link_state_changes++; 906874aeea5SJeff Kirsher 907874aeea5SJeff Kirsher if (link_state->up) 908874aeea5SJeff Kirsher netif_carrier_on(efx->net_dev); 909874aeea5SJeff Kirsher else 910874aeea5SJeff Kirsher netif_carrier_off(efx->net_dev); 911874aeea5SJeff Kirsher } 912874aeea5SJeff Kirsher 913874aeea5SJeff Kirsher /* Status message for kernel log */ 9142aa9ef11SBen Hutchings if (link_state->up) 915874aeea5SJeff Kirsher netif_info(efx, link, efx->net_dev, 916964e6135SBen Hutchings "link up at %uMbps %s-duplex (MTU %d)\n", 917874aeea5SJeff Kirsher link_state->speed, link_state->fd ? "full" : "half", 918964e6135SBen Hutchings efx->net_dev->mtu); 9192aa9ef11SBen Hutchings else 920874aeea5SJeff Kirsher netif_info(efx, link, efx->net_dev, "link down\n"); 921874aeea5SJeff Kirsher } 922874aeea5SJeff Kirsher 923874aeea5SJeff Kirsher void efx_link_set_advertising(struct efx_nic *efx, u32 advertising) 924874aeea5SJeff Kirsher { 925874aeea5SJeff Kirsher efx->link_advertising = advertising; 926874aeea5SJeff Kirsher if (advertising) { 927874aeea5SJeff Kirsher if (advertising & ADVERTISED_Pause) 928874aeea5SJeff Kirsher efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX); 929874aeea5SJeff Kirsher else 930874aeea5SJeff Kirsher efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX); 931874aeea5SJeff Kirsher if (advertising & ADVERTISED_Asym_Pause) 932874aeea5SJeff Kirsher efx->wanted_fc ^= EFX_FC_TX; 933874aeea5SJeff Kirsher } 934874aeea5SJeff Kirsher } 935874aeea5SJeff Kirsher 936874aeea5SJeff Kirsher void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc) 937874aeea5SJeff Kirsher { 938874aeea5SJeff Kirsher efx->wanted_fc = wanted_fc; 939874aeea5SJeff Kirsher if (efx->link_advertising) { 940874aeea5SJeff Kirsher if (wanted_fc & EFX_FC_RX) 941874aeea5SJeff Kirsher efx->link_advertising |= (ADVERTISED_Pause | 942874aeea5SJeff Kirsher ADVERTISED_Asym_Pause); 943874aeea5SJeff Kirsher else 944874aeea5SJeff Kirsher efx->link_advertising &= ~(ADVERTISED_Pause | 945874aeea5SJeff Kirsher ADVERTISED_Asym_Pause); 946874aeea5SJeff Kirsher if (wanted_fc & EFX_FC_TX) 947874aeea5SJeff Kirsher efx->link_advertising ^= ADVERTISED_Asym_Pause; 948874aeea5SJeff Kirsher } 949874aeea5SJeff Kirsher } 950874aeea5SJeff Kirsher 951874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx); 952874aeea5SJeff Kirsher 9530d322413SEdward Cree /* We assume that efx->type->reconfigure_mac will always try to sync RX 9540d322413SEdward Cree * filters and therefore needs to read-lock the filter table against freeing 9550d322413SEdward Cree */ 9560d322413SEdward Cree void efx_mac_reconfigure(struct efx_nic *efx) 9570d322413SEdward Cree { 9580d322413SEdward Cree down_read(&efx->filter_sem); 9590d322413SEdward Cree efx->type->reconfigure_mac(efx); 9600d322413SEdward Cree up_read(&efx->filter_sem); 9610d322413SEdward Cree } 9620d322413SEdward Cree 963874aeea5SJeff Kirsher /* Push loopback/power/transmit disable settings to the PHY, and reconfigure 964874aeea5SJeff Kirsher * the MAC appropriately. All other PHY configuration changes are pushed 965874aeea5SJeff Kirsher * through phy_op->set_settings(), and pushed asynchronously to the MAC 966874aeea5SJeff Kirsher * through efx_monitor(). 967874aeea5SJeff Kirsher * 968874aeea5SJeff Kirsher * Callers must hold the mac_lock 969874aeea5SJeff Kirsher */ 970874aeea5SJeff Kirsher int __efx_reconfigure_port(struct efx_nic *efx) 971874aeea5SJeff Kirsher { 972874aeea5SJeff Kirsher enum efx_phy_mode phy_mode; 973874aeea5SJeff Kirsher int rc; 974874aeea5SJeff Kirsher 975874aeea5SJeff Kirsher WARN_ON(!mutex_is_locked(&efx->mac_lock)); 976874aeea5SJeff Kirsher 977874aeea5SJeff Kirsher /* Disable PHY transmit in mac level loopbacks */ 978874aeea5SJeff Kirsher phy_mode = efx->phy_mode; 979874aeea5SJeff Kirsher if (LOOPBACK_INTERNAL(efx)) 980874aeea5SJeff Kirsher efx->phy_mode |= PHY_MODE_TX_DISABLED; 981874aeea5SJeff Kirsher else 982874aeea5SJeff Kirsher efx->phy_mode &= ~PHY_MODE_TX_DISABLED; 983874aeea5SJeff Kirsher 984874aeea5SJeff Kirsher rc = efx->type->reconfigure_port(efx); 985874aeea5SJeff Kirsher 986874aeea5SJeff Kirsher if (rc) 987874aeea5SJeff Kirsher efx->phy_mode = phy_mode; 988874aeea5SJeff Kirsher 989874aeea5SJeff Kirsher return rc; 990874aeea5SJeff Kirsher } 991874aeea5SJeff Kirsher 992874aeea5SJeff Kirsher /* Reinitialise the MAC to pick up new PHY settings, even if the port is 993874aeea5SJeff Kirsher * disabled. */ 994874aeea5SJeff Kirsher int efx_reconfigure_port(struct efx_nic *efx) 995874aeea5SJeff Kirsher { 996874aeea5SJeff Kirsher int rc; 997874aeea5SJeff Kirsher 998874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 999874aeea5SJeff Kirsher 1000874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1001874aeea5SJeff Kirsher rc = __efx_reconfigure_port(efx); 1002874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1003874aeea5SJeff Kirsher 1004874aeea5SJeff Kirsher return rc; 1005874aeea5SJeff Kirsher } 1006874aeea5SJeff Kirsher 1007874aeea5SJeff Kirsher /* Asynchronous work item for changing MAC promiscuity and multicast 1008874aeea5SJeff Kirsher * hash. Avoid a drain/rx_ingress enable by reconfiguring the current 1009874aeea5SJeff Kirsher * MAC directly. */ 1010874aeea5SJeff Kirsher static void efx_mac_work(struct work_struct *data) 1011874aeea5SJeff Kirsher { 1012874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); 1013874aeea5SJeff Kirsher 1014874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 101530b81cdaSBen Hutchings if (efx->port_enabled) 10160d322413SEdward Cree efx_mac_reconfigure(efx); 1017874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1018874aeea5SJeff Kirsher } 1019874aeea5SJeff Kirsher 1020874aeea5SJeff Kirsher static int efx_probe_port(struct efx_nic *efx) 1021874aeea5SJeff Kirsher { 1022874aeea5SJeff Kirsher int rc; 1023874aeea5SJeff Kirsher 1024874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "create port\n"); 1025874aeea5SJeff Kirsher 1026874aeea5SJeff Kirsher if (phy_flash_cfg) 1027874aeea5SJeff Kirsher efx->phy_mode = PHY_MODE_SPECIAL; 1028874aeea5SJeff Kirsher 1029874aeea5SJeff Kirsher /* Connect up MAC/PHY operations table */ 1030874aeea5SJeff Kirsher rc = efx->type->probe_port(efx); 1031874aeea5SJeff Kirsher if (rc) 1032874aeea5SJeff Kirsher return rc; 1033874aeea5SJeff Kirsher 1034e332bcb3SBen Hutchings /* Initialise MAC address to permanent address */ 1035cd84ff4dSEdward Cree ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr); 1036874aeea5SJeff Kirsher 1037874aeea5SJeff Kirsher return 0; 1038874aeea5SJeff Kirsher } 1039874aeea5SJeff Kirsher 1040874aeea5SJeff Kirsher static int efx_init_port(struct efx_nic *efx) 1041874aeea5SJeff Kirsher { 1042874aeea5SJeff Kirsher int rc; 1043874aeea5SJeff Kirsher 1044874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "init port\n"); 1045874aeea5SJeff Kirsher 1046874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1047874aeea5SJeff Kirsher 1048874aeea5SJeff Kirsher rc = efx->phy_op->init(efx); 1049874aeea5SJeff Kirsher if (rc) 1050874aeea5SJeff Kirsher goto fail1; 1051874aeea5SJeff Kirsher 1052874aeea5SJeff Kirsher efx->port_initialized = true; 1053874aeea5SJeff Kirsher 1054874aeea5SJeff Kirsher /* Reconfigure the MAC before creating dma queues (required for 1055874aeea5SJeff Kirsher * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */ 10560d322413SEdward Cree efx_mac_reconfigure(efx); 1057874aeea5SJeff Kirsher 1058874aeea5SJeff Kirsher /* Ensure the PHY advertises the correct flow control settings */ 1059874aeea5SJeff Kirsher rc = efx->phy_op->reconfigure(efx); 1060267d9d73SEdward Cree if (rc && rc != -EPERM) 1061874aeea5SJeff Kirsher goto fail2; 1062874aeea5SJeff Kirsher 1063874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1064874aeea5SJeff Kirsher return 0; 1065874aeea5SJeff Kirsher 1066874aeea5SJeff Kirsher fail2: 1067874aeea5SJeff Kirsher efx->phy_op->fini(efx); 1068874aeea5SJeff Kirsher fail1: 1069874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1070874aeea5SJeff Kirsher return rc; 1071874aeea5SJeff Kirsher } 1072874aeea5SJeff Kirsher 1073874aeea5SJeff Kirsher static void efx_start_port(struct efx_nic *efx) 1074874aeea5SJeff Kirsher { 1075874aeea5SJeff Kirsher netif_dbg(efx, ifup, efx->net_dev, "start port\n"); 1076874aeea5SJeff Kirsher BUG_ON(efx->port_enabled); 1077874aeea5SJeff Kirsher 1078874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1079874aeea5SJeff Kirsher efx->port_enabled = true; 1080874aeea5SJeff Kirsher 1081d615c039SBen Hutchings /* Ensure MAC ingress/egress is enabled */ 10820d322413SEdward Cree efx_mac_reconfigure(efx); 1083874aeea5SJeff Kirsher 1084874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1085874aeea5SJeff Kirsher } 1086874aeea5SJeff Kirsher 1087d615c039SBen Hutchings /* Cancel work for MAC reconfiguration, periodic hardware monitoring 1088d615c039SBen Hutchings * and the async self-test, wait for them to finish and prevent them 1089d615c039SBen Hutchings * being scheduled again. This doesn't cover online resets, which 1090d615c039SBen Hutchings * should only be cancelled when removing the device. 1091d615c039SBen Hutchings */ 1092874aeea5SJeff Kirsher static void efx_stop_port(struct efx_nic *efx) 1093874aeea5SJeff Kirsher { 1094874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "stop port\n"); 1095874aeea5SJeff Kirsher 1096d615c039SBen Hutchings EFX_ASSERT_RESET_SERIALISED(efx); 1097d615c039SBen Hutchings 1098874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1099874aeea5SJeff Kirsher efx->port_enabled = false; 1100874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1101874aeea5SJeff Kirsher 1102874aeea5SJeff Kirsher /* Serialise against efx_set_multicast_list() */ 1103874aeea5SJeff Kirsher netif_addr_lock_bh(efx->net_dev); 1104874aeea5SJeff Kirsher netif_addr_unlock_bh(efx->net_dev); 1105d615c039SBen Hutchings 1106d615c039SBen Hutchings cancel_delayed_work_sync(&efx->monitor_work); 1107d615c039SBen Hutchings efx_selftest_async_cancel(efx); 1108d615c039SBen Hutchings cancel_work_sync(&efx->mac_work); 1109874aeea5SJeff Kirsher } 1110874aeea5SJeff Kirsher 1111874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx) 1112874aeea5SJeff Kirsher { 1113874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); 1114874aeea5SJeff Kirsher 1115874aeea5SJeff Kirsher if (!efx->port_initialized) 1116874aeea5SJeff Kirsher return; 1117874aeea5SJeff Kirsher 1118874aeea5SJeff Kirsher efx->phy_op->fini(efx); 1119874aeea5SJeff Kirsher efx->port_initialized = false; 1120874aeea5SJeff Kirsher 1121874aeea5SJeff Kirsher efx->link_state.up = false; 1122874aeea5SJeff Kirsher efx_link_status_changed(efx); 1123874aeea5SJeff Kirsher } 1124874aeea5SJeff Kirsher 1125874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx) 1126874aeea5SJeff Kirsher { 1127874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); 1128874aeea5SJeff Kirsher 1129874aeea5SJeff Kirsher efx->type->remove_port(efx); 1130874aeea5SJeff Kirsher } 1131874aeea5SJeff Kirsher 1132874aeea5SJeff Kirsher /************************************************************************** 1133874aeea5SJeff Kirsher * 1134874aeea5SJeff Kirsher * NIC handling 1135874aeea5SJeff Kirsher * 1136874aeea5SJeff Kirsher **************************************************************************/ 1137874aeea5SJeff Kirsher 11380bcf4a64SBen Hutchings static LIST_HEAD(efx_primary_list); 11390bcf4a64SBen Hutchings static LIST_HEAD(efx_unassociated_list); 11400bcf4a64SBen Hutchings 11410bcf4a64SBen Hutchings static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right) 11420bcf4a64SBen Hutchings { 11430bcf4a64SBen Hutchings return left->type == right->type && 11440bcf4a64SBen Hutchings left->vpd_sn && right->vpd_sn && 11450bcf4a64SBen Hutchings !strcmp(left->vpd_sn, right->vpd_sn); 11460bcf4a64SBen Hutchings } 11470bcf4a64SBen Hutchings 11480bcf4a64SBen Hutchings static void efx_associate(struct efx_nic *efx) 11490bcf4a64SBen Hutchings { 11500bcf4a64SBen Hutchings struct efx_nic *other, *next; 11510bcf4a64SBen Hutchings 11520bcf4a64SBen Hutchings if (efx->primary == efx) { 11530bcf4a64SBen Hutchings /* Adding primary function; look for secondaries */ 11540bcf4a64SBen Hutchings 11550bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n"); 11560bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_primary_list); 11570bcf4a64SBen Hutchings 11580bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx_unassociated_list, 11590bcf4a64SBen Hutchings node) { 11600bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 11610bcf4a64SBen Hutchings list_del(&other->node); 11620bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 11630bcf4a64SBen Hutchings "moving to secondary list of %s %s\n", 11640bcf4a64SBen Hutchings pci_name(efx->pci_dev), 11650bcf4a64SBen Hutchings efx->net_dev->name); 11660bcf4a64SBen Hutchings list_add_tail(&other->node, 11670bcf4a64SBen Hutchings &efx->secondary_list); 11680bcf4a64SBen Hutchings other->primary = efx; 11690bcf4a64SBen Hutchings } 11700bcf4a64SBen Hutchings } 11710bcf4a64SBen Hutchings } else { 11720bcf4a64SBen Hutchings /* Adding secondary function; look for primary */ 11730bcf4a64SBen Hutchings 11740bcf4a64SBen Hutchings list_for_each_entry(other, &efx_primary_list, node) { 11750bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 11760bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 11770bcf4a64SBen Hutchings "adding to secondary list of %s %s\n", 11780bcf4a64SBen Hutchings pci_name(other->pci_dev), 11790bcf4a64SBen Hutchings other->net_dev->name); 11800bcf4a64SBen Hutchings list_add_tail(&efx->node, 11810bcf4a64SBen Hutchings &other->secondary_list); 11820bcf4a64SBen Hutchings efx->primary = other; 11830bcf4a64SBen Hutchings return; 11840bcf4a64SBen Hutchings } 11850bcf4a64SBen Hutchings } 11860bcf4a64SBen Hutchings 11870bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 11880bcf4a64SBen Hutchings "adding to unassociated list\n"); 11890bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_unassociated_list); 11900bcf4a64SBen Hutchings } 11910bcf4a64SBen Hutchings } 11920bcf4a64SBen Hutchings 11930bcf4a64SBen Hutchings static void efx_dissociate(struct efx_nic *efx) 11940bcf4a64SBen Hutchings { 11950bcf4a64SBen Hutchings struct efx_nic *other, *next; 11960bcf4a64SBen Hutchings 11970bcf4a64SBen Hutchings list_del(&efx->node); 11980bcf4a64SBen Hutchings efx->primary = NULL; 11990bcf4a64SBen Hutchings 12000bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx->secondary_list, node) { 12010bcf4a64SBen Hutchings list_del(&other->node); 12020bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 12030bcf4a64SBen Hutchings "moving to unassociated list\n"); 12040bcf4a64SBen Hutchings list_add_tail(&other->node, &efx_unassociated_list); 12050bcf4a64SBen Hutchings other->primary = NULL; 12060bcf4a64SBen Hutchings } 12070bcf4a64SBen Hutchings } 12080bcf4a64SBen Hutchings 1209874aeea5SJeff Kirsher /* This configures the PCI device to enable I/O and DMA. */ 1210874aeea5SJeff Kirsher static int efx_init_io(struct efx_nic *efx) 1211874aeea5SJeff Kirsher { 1212874aeea5SJeff Kirsher struct pci_dev *pci_dev = efx->pci_dev; 1213874aeea5SJeff Kirsher dma_addr_t dma_mask = efx->type->max_dma_mask; 1214b105798fSBen Hutchings unsigned int mem_map_size = efx->type->mem_map_size(efx); 121502246a7fSShradha Shah int rc, bar; 1216874aeea5SJeff Kirsher 1217874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n"); 1218874aeea5SJeff Kirsher 121902246a7fSShradha Shah bar = efx->type->mem_bar; 122002246a7fSShradha Shah 1221874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 1222874aeea5SJeff Kirsher if (rc) { 1223874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1224874aeea5SJeff Kirsher "failed to enable PCI device\n"); 1225874aeea5SJeff Kirsher goto fail1; 1226874aeea5SJeff Kirsher } 1227874aeea5SJeff Kirsher 1228874aeea5SJeff Kirsher pci_set_master(pci_dev); 1229874aeea5SJeff Kirsher 1230874aeea5SJeff Kirsher /* Set the PCI DMA mask. Try all possibilities from our 1231874aeea5SJeff Kirsher * genuine mask down to 32 bits, because some architectures 1232874aeea5SJeff Kirsher * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit 1233874aeea5SJeff Kirsher * masks event though they reject 46 bit masks. 1234874aeea5SJeff Kirsher */ 1235874aeea5SJeff Kirsher while (dma_mask > 0x7fffffffUL) { 12360e33d870SBen Hutchings if (dma_supported(&pci_dev->dev, dma_mask)) { 12379663dedaSRussell King rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask); 1238e9e01846SBen Hutchings if (rc == 0) 1239874aeea5SJeff Kirsher break; 1240e9e01846SBen Hutchings } 1241874aeea5SJeff Kirsher dma_mask >>= 1; 1242874aeea5SJeff Kirsher } 1243874aeea5SJeff Kirsher if (rc) { 1244874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1245874aeea5SJeff Kirsher "could not find a suitable DMA mask\n"); 1246874aeea5SJeff Kirsher goto fail2; 1247874aeea5SJeff Kirsher } 1248874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, 1249874aeea5SJeff Kirsher "using DMA mask %llx\n", (unsigned long long) dma_mask); 1250874aeea5SJeff Kirsher 125102246a7fSShradha Shah efx->membase_phys = pci_resource_start(efx->pci_dev, bar); 125202246a7fSShradha Shah rc = pci_request_region(pci_dev, bar, "sfc"); 1253874aeea5SJeff Kirsher if (rc) { 1254874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1255874aeea5SJeff Kirsher "request for memory BAR failed\n"); 1256874aeea5SJeff Kirsher rc = -EIO; 1257874aeea5SJeff Kirsher goto fail3; 1258874aeea5SJeff Kirsher } 1259b105798fSBen Hutchings efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size); 1260874aeea5SJeff Kirsher if (!efx->membase) { 1261874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1262874aeea5SJeff Kirsher "could not map memory BAR at %llx+%x\n", 1263b105798fSBen Hutchings (unsigned long long)efx->membase_phys, mem_map_size); 1264874aeea5SJeff Kirsher rc = -ENOMEM; 1265874aeea5SJeff Kirsher goto fail4; 1266874aeea5SJeff Kirsher } 1267874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, 1268874aeea5SJeff Kirsher "memory BAR at %llx+%x (virtual %p)\n", 1269b105798fSBen Hutchings (unsigned long long)efx->membase_phys, mem_map_size, 1270b105798fSBen Hutchings efx->membase); 1271874aeea5SJeff Kirsher 1272874aeea5SJeff Kirsher return 0; 1273874aeea5SJeff Kirsher 1274874aeea5SJeff Kirsher fail4: 127502246a7fSShradha Shah pci_release_region(efx->pci_dev, bar); 1276874aeea5SJeff Kirsher fail3: 1277874aeea5SJeff Kirsher efx->membase_phys = 0; 1278874aeea5SJeff Kirsher fail2: 1279874aeea5SJeff Kirsher pci_disable_device(efx->pci_dev); 1280874aeea5SJeff Kirsher fail1: 1281874aeea5SJeff Kirsher return rc; 1282874aeea5SJeff Kirsher } 1283874aeea5SJeff Kirsher 1284874aeea5SJeff Kirsher static void efx_fini_io(struct efx_nic *efx) 1285874aeea5SJeff Kirsher { 128602246a7fSShradha Shah int bar; 128702246a7fSShradha Shah 1288874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n"); 1289874aeea5SJeff Kirsher 1290874aeea5SJeff Kirsher if (efx->membase) { 1291874aeea5SJeff Kirsher iounmap(efx->membase); 1292874aeea5SJeff Kirsher efx->membase = NULL; 1293874aeea5SJeff Kirsher } 1294874aeea5SJeff Kirsher 1295874aeea5SJeff Kirsher if (efx->membase_phys) { 129602246a7fSShradha Shah bar = efx->type->mem_bar; 129702246a7fSShradha Shah pci_release_region(efx->pci_dev, bar); 1298874aeea5SJeff Kirsher efx->membase_phys = 0; 1299874aeea5SJeff Kirsher } 1300874aeea5SJeff Kirsher 1301874aeea5SJeff Kirsher pci_disable_device(efx->pci_dev); 1302874aeea5SJeff Kirsher } 1303874aeea5SJeff Kirsher 1304267c0157SJon Cooper void efx_set_default_rx_indir_table(struct efx_nic *efx) 1305267c0157SJon Cooper { 1306267c0157SJon Cooper size_t i; 1307267c0157SJon Cooper 1308267c0157SJon Cooper for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) 1309267c0157SJon Cooper efx->rx_indir_table[i] = 1310267c0157SJon Cooper ethtool_rxfh_indir_default(i, efx->rss_spread); 1311267c0157SJon Cooper } 1312267c0157SJon Cooper 1313a9a52506SBen Hutchings static unsigned int efx_wanted_parallelism(struct efx_nic *efx) 1314874aeea5SJeff Kirsher { 1315cdb08f8fSBen Hutchings cpumask_var_t thread_mask; 1316a16e5b24SBen Hutchings unsigned int count; 1317874aeea5SJeff Kirsher int cpu; 1318874aeea5SJeff Kirsher 1319cd2d5b52SBen Hutchings if (rss_cpus) { 1320cd2d5b52SBen Hutchings count = rss_cpus; 1321cd2d5b52SBen Hutchings } else { 1322cdb08f8fSBen Hutchings if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) { 1323a9a52506SBen Hutchings netif_warn(efx, probe, efx->net_dev, 1324a9a52506SBen Hutchings "RSS disabled due to allocation failure\n"); 1325874aeea5SJeff Kirsher return 1; 1326874aeea5SJeff Kirsher } 1327874aeea5SJeff Kirsher 1328874aeea5SJeff Kirsher count = 0; 1329874aeea5SJeff Kirsher for_each_online_cpu(cpu) { 1330cdb08f8fSBen Hutchings if (!cpumask_test_cpu(cpu, thread_mask)) { 1331874aeea5SJeff Kirsher ++count; 1332cdb08f8fSBen Hutchings cpumask_or(thread_mask, thread_mask, 1333cdb08f8fSBen Hutchings topology_thread_cpumask(cpu)); 1334874aeea5SJeff Kirsher } 1335874aeea5SJeff Kirsher } 1336874aeea5SJeff Kirsher 1337cdb08f8fSBen Hutchings free_cpumask_var(thread_mask); 1338cd2d5b52SBen Hutchings } 1339cd2d5b52SBen Hutchings 1340cd2d5b52SBen Hutchings /* If RSS is requested for the PF *and* VFs then we can't write RSS 1341cd2d5b52SBen Hutchings * table entries that are inaccessible to VFs 1342cd2d5b52SBen Hutchings */ 13437fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 13447fa8d547SShradha Shah if (efx->type->sriov_wanted) { 1345d98a4ffeSShradha Shah if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 && 1346cd2d5b52SBen Hutchings count > efx_vf_size(efx)) { 1347cd2d5b52SBen Hutchings netif_warn(efx, probe, efx->net_dev, 1348cd2d5b52SBen Hutchings "Reducing number of RSS channels from %u to %u for " 1349cd2d5b52SBen Hutchings "VF support. Increase vf-msix-limit to use more " 1350cd2d5b52SBen Hutchings "channels on the PF.\n", 1351cd2d5b52SBen Hutchings count, efx_vf_size(efx)); 1352cd2d5b52SBen Hutchings count = efx_vf_size(efx); 1353cd2d5b52SBen Hutchings } 13547fa8d547SShradha Shah } 13557fa8d547SShradha Shah #endif 1356cd2d5b52SBen Hutchings 1357874aeea5SJeff Kirsher return count; 1358874aeea5SJeff Kirsher } 1359874aeea5SJeff Kirsher 1360874aeea5SJeff Kirsher /* Probe the number and type of interrupts we are able to obtain, and 1361874aeea5SJeff Kirsher * the resulting numbers of channels and RX queues. 1362874aeea5SJeff Kirsher */ 1363874aeea5SJeff Kirsher static int efx_probe_interrupts(struct efx_nic *efx) 1364874aeea5SJeff Kirsher { 13657f967c01SBen Hutchings unsigned int extra_channels = 0; 13667f967c01SBen Hutchings unsigned int i, j; 1367a16e5b24SBen Hutchings int rc; 1368874aeea5SJeff Kirsher 13697f967c01SBen Hutchings for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) 13707f967c01SBen Hutchings if (efx->extra_channel_type[i]) 13717f967c01SBen Hutchings ++extra_channels; 13727f967c01SBen Hutchings 1373874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { 1374874aeea5SJeff Kirsher struct msix_entry xentries[EFX_MAX_CHANNELS]; 1375a16e5b24SBen Hutchings unsigned int n_channels; 1376874aeea5SJeff Kirsher 1377a9a52506SBen Hutchings n_channels = efx_wanted_parallelism(efx); 1378874aeea5SJeff Kirsher if (separate_tx_channels) 1379874aeea5SJeff Kirsher n_channels *= 2; 13807f967c01SBen Hutchings n_channels += extra_channels; 1381b105798fSBen Hutchings n_channels = min(n_channels, efx->max_channels); 1382874aeea5SJeff Kirsher 1383874aeea5SJeff Kirsher for (i = 0; i < n_channels; i++) 1384874aeea5SJeff Kirsher xentries[i].entry = i; 1385184603d8SAlexander Gordeev rc = pci_enable_msix_range(efx->pci_dev, 1386184603d8SAlexander Gordeev xentries, 1, n_channels); 1387184603d8SAlexander Gordeev if (rc < 0) { 1388184603d8SAlexander Gordeev /* Fall back to single channel MSI */ 1389184603d8SAlexander Gordeev efx->interrupt_mode = EFX_INT_MODE_MSI; 1390184603d8SAlexander Gordeev netif_err(efx, drv, efx->net_dev, 1391184603d8SAlexander Gordeev "could not enable MSI-X\n"); 1392184603d8SAlexander Gordeev } else if (rc < n_channels) { 1393874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1394874aeea5SJeff Kirsher "WARNING: Insufficient MSI-X vectors" 1395a16e5b24SBen Hutchings " available (%d < %u).\n", rc, n_channels); 1396874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1397874aeea5SJeff Kirsher "WARNING: Performance may be reduced.\n"); 1398874aeea5SJeff Kirsher n_channels = rc; 1399874aeea5SJeff Kirsher } 1400874aeea5SJeff Kirsher 1401184603d8SAlexander Gordeev if (rc > 0) { 1402874aeea5SJeff Kirsher efx->n_channels = n_channels; 14037f967c01SBen Hutchings if (n_channels > extra_channels) 14047f967c01SBen Hutchings n_channels -= extra_channels; 1405874aeea5SJeff Kirsher if (separate_tx_channels) { 14067f967c01SBen Hutchings efx->n_tx_channels = max(n_channels / 2, 1U); 14077f967c01SBen Hutchings efx->n_rx_channels = max(n_channels - 14087f967c01SBen Hutchings efx->n_tx_channels, 14097f967c01SBen Hutchings 1U); 1410874aeea5SJeff Kirsher } else { 14117f967c01SBen Hutchings efx->n_tx_channels = n_channels; 14127f967c01SBen Hutchings efx->n_rx_channels = n_channels; 1413874aeea5SJeff Kirsher } 14147f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) 1415874aeea5SJeff Kirsher efx_get_channel(efx, i)->irq = 1416874aeea5SJeff Kirsher xentries[i].vector; 1417874aeea5SJeff Kirsher } 1418874aeea5SJeff Kirsher } 1419874aeea5SJeff Kirsher 1420874aeea5SJeff Kirsher /* Try single interrupt MSI */ 1421874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_MSI) { 1422874aeea5SJeff Kirsher efx->n_channels = 1; 1423874aeea5SJeff Kirsher efx->n_rx_channels = 1; 1424874aeea5SJeff Kirsher efx->n_tx_channels = 1; 1425874aeea5SJeff Kirsher rc = pci_enable_msi(efx->pci_dev); 1426874aeea5SJeff Kirsher if (rc == 0) { 1427874aeea5SJeff Kirsher efx_get_channel(efx, 0)->irq = efx->pci_dev->irq; 1428874aeea5SJeff Kirsher } else { 1429874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1430874aeea5SJeff Kirsher "could not enable MSI\n"); 1431874aeea5SJeff Kirsher efx->interrupt_mode = EFX_INT_MODE_LEGACY; 1432874aeea5SJeff Kirsher } 1433874aeea5SJeff Kirsher } 1434874aeea5SJeff Kirsher 1435874aeea5SJeff Kirsher /* Assume legacy interrupts */ 1436874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { 1437874aeea5SJeff Kirsher efx->n_channels = 1 + (separate_tx_channels ? 1 : 0); 1438874aeea5SJeff Kirsher efx->n_rx_channels = 1; 1439874aeea5SJeff Kirsher efx->n_tx_channels = 1; 1440874aeea5SJeff Kirsher efx->legacy_irq = efx->pci_dev->irq; 1441874aeea5SJeff Kirsher } 1442874aeea5SJeff Kirsher 14437f967c01SBen Hutchings /* Assign extra channels if possible */ 14447f967c01SBen Hutchings j = efx->n_channels; 14457f967c01SBen Hutchings for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { 14467f967c01SBen Hutchings if (!efx->extra_channel_type[i]) 14477f967c01SBen Hutchings continue; 14487f967c01SBen Hutchings if (efx->interrupt_mode != EFX_INT_MODE_MSIX || 14497f967c01SBen Hutchings efx->n_channels <= extra_channels) { 14507f967c01SBen Hutchings efx->extra_channel_type[i]->handle_no_channel(efx); 14517f967c01SBen Hutchings } else { 14527f967c01SBen Hutchings --j; 14537f967c01SBen Hutchings efx_get_channel(efx, j)->type = 14547f967c01SBen Hutchings efx->extra_channel_type[i]; 14557f967c01SBen Hutchings } 14567f967c01SBen Hutchings } 14577f967c01SBen Hutchings 1458cd2d5b52SBen Hutchings /* RSS might be usable on VFs even if it is disabled on the PF */ 14597fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 14607fa8d547SShradha Shah if (efx->type->sriov_wanted) { 1461327c685eSShradha Shah efx->rss_spread = ((efx->n_rx_channels > 1 || 1462d98a4ffeSShradha Shah !efx->type->sriov_wanted(efx)) ? 1463cd2d5b52SBen Hutchings efx->n_rx_channels : efx_vf_size(efx)); 14647fa8d547SShradha Shah return 0; 14657fa8d547SShradha Shah } 14667fa8d547SShradha Shah #endif 14677fa8d547SShradha Shah efx->rss_spread = efx->n_rx_channels; 14686f7f8aa6SShradha Shah 1469874aeea5SJeff Kirsher return 0; 1470874aeea5SJeff Kirsher } 1471874aeea5SJeff Kirsher 1472261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx) 1473d8291187SBen Hutchings { 1474261e4d96SJon Cooper struct efx_channel *channel, *end_channel; 1475261e4d96SJon Cooper int rc; 1476d8291187SBen Hutchings 1477d8291187SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 1478d8291187SBen Hutchings 1479d8291187SBen Hutchings efx->irq_soft_enabled = true; 1480d8291187SBen Hutchings smp_wmb(); 1481d8291187SBen Hutchings 1482d8291187SBen Hutchings efx_for_each_channel(channel, efx) { 1483261e4d96SJon Cooper if (!channel->type->keep_eventq) { 1484261e4d96SJon Cooper rc = efx_init_eventq(channel); 1485261e4d96SJon Cooper if (rc) 1486261e4d96SJon Cooper goto fail; 1487261e4d96SJon Cooper } 1488d8291187SBen Hutchings efx_start_eventq(channel); 1489d8291187SBen Hutchings } 1490d8291187SBen Hutchings 1491d8291187SBen Hutchings efx_mcdi_mode_event(efx); 1492261e4d96SJon Cooper 1493261e4d96SJon Cooper return 0; 1494261e4d96SJon Cooper fail: 1495261e4d96SJon Cooper end_channel = channel; 1496261e4d96SJon Cooper efx_for_each_channel(channel, efx) { 1497261e4d96SJon Cooper if (channel == end_channel) 1498261e4d96SJon Cooper break; 1499261e4d96SJon Cooper efx_stop_eventq(channel); 1500261e4d96SJon Cooper if (!channel->type->keep_eventq) 1501261e4d96SJon Cooper efx_fini_eventq(channel); 1502261e4d96SJon Cooper } 1503261e4d96SJon Cooper 1504261e4d96SJon Cooper return rc; 1505d8291187SBen Hutchings } 1506d8291187SBen Hutchings 1507d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx) 1508d8291187SBen Hutchings { 1509d8291187SBen Hutchings struct efx_channel *channel; 1510d8291187SBen Hutchings 1511d8291187SBen Hutchings if (efx->state == STATE_DISABLED) 1512d8291187SBen Hutchings return; 1513d8291187SBen Hutchings 1514d8291187SBen Hutchings efx_mcdi_mode_poll(efx); 1515d8291187SBen Hutchings 1516d8291187SBen Hutchings efx->irq_soft_enabled = false; 1517d8291187SBen Hutchings smp_wmb(); 1518d8291187SBen Hutchings 1519d8291187SBen Hutchings if (efx->legacy_irq) 1520d8291187SBen Hutchings synchronize_irq(efx->legacy_irq); 1521d8291187SBen Hutchings 1522d8291187SBen Hutchings efx_for_each_channel(channel, efx) { 1523d8291187SBen Hutchings if (channel->irq) 1524d8291187SBen Hutchings synchronize_irq(channel->irq); 1525d8291187SBen Hutchings 1526d8291187SBen Hutchings efx_stop_eventq(channel); 1527d8291187SBen Hutchings if (!channel->type->keep_eventq) 1528d8291187SBen Hutchings efx_fini_eventq(channel); 1529d8291187SBen Hutchings } 1530cade715fSBen Hutchings 1531cade715fSBen Hutchings /* Flush the asynchronous MCDI request queue */ 1532cade715fSBen Hutchings efx_mcdi_flush_async(efx); 1533d8291187SBen Hutchings } 1534d8291187SBen Hutchings 1535261e4d96SJon Cooper static int efx_enable_interrupts(struct efx_nic *efx) 15369f2cb71cSBen Hutchings { 1537261e4d96SJon Cooper struct efx_channel *channel, *end_channel; 1538261e4d96SJon Cooper int rc; 15399f2cb71cSBen Hutchings 15408b7325b4SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 15418b7325b4SBen Hutchings 1542b28405b0SAlexandre Rames if (efx->eeh_disabled_legacy_irq) { 1543b28405b0SAlexandre Rames enable_irq(efx->legacy_irq); 1544b28405b0SAlexandre Rames efx->eeh_disabled_legacy_irq = false; 1545b28405b0SAlexandre Rames } 1546d8291187SBen Hutchings 154786094f7fSBen Hutchings efx->type->irq_enable_master(efx); 15489f2cb71cSBen Hutchings 15499f2cb71cSBen Hutchings efx_for_each_channel(channel, efx) { 1550261e4d96SJon Cooper if (channel->type->keep_eventq) { 1551261e4d96SJon Cooper rc = efx_init_eventq(channel); 1552261e4d96SJon Cooper if (rc) 1553261e4d96SJon Cooper goto fail; 1554261e4d96SJon Cooper } 15559f2cb71cSBen Hutchings } 15569f2cb71cSBen Hutchings 1557261e4d96SJon Cooper rc = efx_soft_enable_interrupts(efx); 1558261e4d96SJon Cooper if (rc) 1559261e4d96SJon Cooper goto fail; 1560261e4d96SJon Cooper 1561261e4d96SJon Cooper return 0; 1562261e4d96SJon Cooper 1563261e4d96SJon Cooper fail: 1564261e4d96SJon Cooper end_channel = channel; 1565261e4d96SJon Cooper efx_for_each_channel(channel, efx) { 1566261e4d96SJon Cooper if (channel == end_channel) 1567261e4d96SJon Cooper break; 1568261e4d96SJon Cooper if (channel->type->keep_eventq) 1569261e4d96SJon Cooper efx_fini_eventq(channel); 1570261e4d96SJon Cooper } 1571261e4d96SJon Cooper 1572261e4d96SJon Cooper efx->type->irq_disable_non_ev(efx); 1573261e4d96SJon Cooper 1574261e4d96SJon Cooper return rc; 15759f2cb71cSBen Hutchings } 15769f2cb71cSBen Hutchings 1577d8291187SBen Hutchings static void efx_disable_interrupts(struct efx_nic *efx) 15789f2cb71cSBen Hutchings { 15799f2cb71cSBen Hutchings struct efx_channel *channel; 15809f2cb71cSBen Hutchings 1581d8291187SBen Hutchings efx_soft_disable_interrupts(efx); 15829f2cb71cSBen Hutchings 15839f2cb71cSBen Hutchings efx_for_each_channel(channel, efx) { 1584d8291187SBen Hutchings if (channel->type->keep_eventq) 15859f2cb71cSBen Hutchings efx_fini_eventq(channel); 15869f2cb71cSBen Hutchings } 1587d8291187SBen Hutchings 158886094f7fSBen Hutchings efx->type->irq_disable_non_ev(efx); 15899f2cb71cSBen Hutchings } 15909f2cb71cSBen Hutchings 1591874aeea5SJeff Kirsher static void efx_remove_interrupts(struct efx_nic *efx) 1592874aeea5SJeff Kirsher { 1593874aeea5SJeff Kirsher struct efx_channel *channel; 1594874aeea5SJeff Kirsher 1595874aeea5SJeff Kirsher /* Remove MSI/MSI-X interrupts */ 1596874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 1597874aeea5SJeff Kirsher channel->irq = 0; 1598874aeea5SJeff Kirsher pci_disable_msi(efx->pci_dev); 1599874aeea5SJeff Kirsher pci_disable_msix(efx->pci_dev); 1600874aeea5SJeff Kirsher 1601874aeea5SJeff Kirsher /* Remove legacy interrupt */ 1602874aeea5SJeff Kirsher efx->legacy_irq = 0; 1603874aeea5SJeff Kirsher } 1604874aeea5SJeff Kirsher 1605874aeea5SJeff Kirsher static void efx_set_channels(struct efx_nic *efx) 1606874aeea5SJeff Kirsher { 1607874aeea5SJeff Kirsher struct efx_channel *channel; 1608874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 1609874aeea5SJeff Kirsher 1610874aeea5SJeff Kirsher efx->tx_channel_offset = 1611874aeea5SJeff Kirsher separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0; 1612874aeea5SJeff Kirsher 161379d68b37SStuart Hodgson /* We need to mark which channels really have RX and TX 161479d68b37SStuart Hodgson * queues, and adjust the TX queue numbers if we have separate 1615874aeea5SJeff Kirsher * RX-only and TX-only channels. 1616874aeea5SJeff Kirsher */ 1617874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 161879d68b37SStuart Hodgson if (channel->channel < efx->n_rx_channels) 161979d68b37SStuart Hodgson channel->rx_queue.core_index = channel->channel; 162079d68b37SStuart Hodgson else 162179d68b37SStuart Hodgson channel->rx_queue.core_index = -1; 162279d68b37SStuart Hodgson 1623874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 1624874aeea5SJeff Kirsher tx_queue->queue -= (efx->tx_channel_offset * 1625874aeea5SJeff Kirsher EFX_TXQ_TYPES); 1626874aeea5SJeff Kirsher } 1627874aeea5SJeff Kirsher } 1628874aeea5SJeff Kirsher 1629874aeea5SJeff Kirsher static int efx_probe_nic(struct efx_nic *efx) 1630874aeea5SJeff Kirsher { 1631874aeea5SJeff Kirsher int rc; 1632874aeea5SJeff Kirsher 1633874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); 1634874aeea5SJeff Kirsher 1635874aeea5SJeff Kirsher /* Carry out hardware-type specific initialisation */ 1636874aeea5SJeff Kirsher rc = efx->type->probe(efx); 1637874aeea5SJeff Kirsher if (rc) 1638874aeea5SJeff Kirsher return rc; 1639874aeea5SJeff Kirsher 1640874aeea5SJeff Kirsher /* Determine the number of channels and queues by trying to hook 1641874aeea5SJeff Kirsher * in MSI-X interrupts. */ 1642874aeea5SJeff Kirsher rc = efx_probe_interrupts(efx); 1643874aeea5SJeff Kirsher if (rc) 1644c15eed22SBen Hutchings goto fail1; 1645874aeea5SJeff Kirsher 164652ad762bSDaniel Pieczko efx_set_channels(efx); 164752ad762bSDaniel Pieczko 1648c15eed22SBen Hutchings rc = efx->type->dimension_resources(efx); 1649c15eed22SBen Hutchings if (rc) 1650c15eed22SBen Hutchings goto fail2; 165128e47c49SBen Hutchings 1652874aeea5SJeff Kirsher if (efx->n_channels > 1) 1653267c0157SJon Cooper netdev_rss_key_fill(&efx->rx_hash_key, 1654267c0157SJon Cooper sizeof(efx->rx_hash_key)); 1655267c0157SJon Cooper efx_set_default_rx_indir_table(efx); 1656874aeea5SJeff Kirsher 1657874aeea5SJeff Kirsher netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels); 1658874aeea5SJeff Kirsher netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels); 1659874aeea5SJeff Kirsher 1660874aeea5SJeff Kirsher /* Initialise the interrupt moderation settings */ 16619e393b30SBen Hutchings efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, 16629e393b30SBen Hutchings true); 1663874aeea5SJeff Kirsher 1664874aeea5SJeff Kirsher return 0; 1665874aeea5SJeff Kirsher 1666c15eed22SBen Hutchings fail2: 1667c15eed22SBen Hutchings efx_remove_interrupts(efx); 1668c15eed22SBen Hutchings fail1: 1669874aeea5SJeff Kirsher efx->type->remove(efx); 1670874aeea5SJeff Kirsher return rc; 1671874aeea5SJeff Kirsher } 1672874aeea5SJeff Kirsher 1673874aeea5SJeff Kirsher static void efx_remove_nic(struct efx_nic *efx) 1674874aeea5SJeff Kirsher { 1675874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); 1676874aeea5SJeff Kirsher 1677874aeea5SJeff Kirsher efx_remove_interrupts(efx); 1678874aeea5SJeff Kirsher efx->type->remove(efx); 1679874aeea5SJeff Kirsher } 1680874aeea5SJeff Kirsher 1681add72477SBen Hutchings static int efx_probe_filters(struct efx_nic *efx) 1682add72477SBen Hutchings { 1683add72477SBen Hutchings int rc; 1684add72477SBen Hutchings 1685add72477SBen Hutchings spin_lock_init(&efx->filter_lock); 16860d322413SEdward Cree init_rwsem(&efx->filter_sem); 16870d322413SEdward Cree down_write(&efx->filter_sem); 1688add72477SBen Hutchings rc = efx->type->filter_table_probe(efx); 1689add72477SBen Hutchings if (rc) 16900d322413SEdward Cree goto out_unlock; 1691add72477SBen Hutchings 1692add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL 1693add72477SBen Hutchings if (efx->type->offload_features & NETIF_F_NTUPLE) { 1694add72477SBen Hutchings efx->rps_flow_id = kcalloc(efx->type->max_rx_ip_filters, 1695add72477SBen Hutchings sizeof(*efx->rps_flow_id), 1696add72477SBen Hutchings GFP_KERNEL); 1697add72477SBen Hutchings if (!efx->rps_flow_id) { 1698add72477SBen Hutchings efx->type->filter_table_remove(efx); 16990d322413SEdward Cree rc = -ENOMEM; 17000d322413SEdward Cree goto out_unlock; 1701add72477SBen Hutchings } 1702add72477SBen Hutchings } 1703add72477SBen Hutchings #endif 17040d322413SEdward Cree out_unlock: 17050d322413SEdward Cree up_write(&efx->filter_sem); 17060d322413SEdward Cree return rc; 1707add72477SBen Hutchings } 1708add72477SBen Hutchings 1709add72477SBen Hutchings static void efx_remove_filters(struct efx_nic *efx) 1710add72477SBen Hutchings { 1711add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL 1712add72477SBen Hutchings kfree(efx->rps_flow_id); 1713add72477SBen Hutchings #endif 17140d322413SEdward Cree down_write(&efx->filter_sem); 1715add72477SBen Hutchings efx->type->filter_table_remove(efx); 17160d322413SEdward Cree up_write(&efx->filter_sem); 1717add72477SBen Hutchings } 1718add72477SBen Hutchings 1719add72477SBen Hutchings static void efx_restore_filters(struct efx_nic *efx) 1720add72477SBen Hutchings { 17210d322413SEdward Cree down_read(&efx->filter_sem); 1722add72477SBen Hutchings efx->type->filter_table_restore(efx); 17230d322413SEdward Cree up_read(&efx->filter_sem); 1724add72477SBen Hutchings } 1725add72477SBen Hutchings 1726874aeea5SJeff Kirsher /************************************************************************** 1727874aeea5SJeff Kirsher * 1728874aeea5SJeff Kirsher * NIC startup/shutdown 1729874aeea5SJeff Kirsher * 1730874aeea5SJeff Kirsher *************************************************************************/ 1731874aeea5SJeff Kirsher 1732874aeea5SJeff Kirsher static int efx_probe_all(struct efx_nic *efx) 1733874aeea5SJeff Kirsher { 1734874aeea5SJeff Kirsher int rc; 1735874aeea5SJeff Kirsher 1736874aeea5SJeff Kirsher rc = efx_probe_nic(efx); 1737874aeea5SJeff Kirsher if (rc) { 1738874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); 1739874aeea5SJeff Kirsher goto fail1; 1740874aeea5SJeff Kirsher } 1741874aeea5SJeff Kirsher 1742874aeea5SJeff Kirsher rc = efx_probe_port(efx); 1743874aeea5SJeff Kirsher if (rc) { 1744874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create port\n"); 1745874aeea5SJeff Kirsher goto fail2; 1746874aeea5SJeff Kirsher } 1747874aeea5SJeff Kirsher 17487e6d06f0SBen Hutchings BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); 17497e6d06f0SBen Hutchings if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { 17507e6d06f0SBen Hutchings rc = -EINVAL; 17517e6d06f0SBen Hutchings goto fail3; 17527e6d06f0SBen Hutchings } 1753874aeea5SJeff Kirsher efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE; 1754874aeea5SJeff Kirsher 17556d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 17566d8aaaf6SDaniel Pieczko rc = efx->type->vswitching_probe(efx); 17576d8aaaf6SDaniel Pieczko if (rc) /* not fatal; the PF will still work fine */ 17586d8aaaf6SDaniel Pieczko netif_warn(efx, probe, efx->net_dev, 17596d8aaaf6SDaniel Pieczko "failed to setup vswitching rc=%d;" 17606d8aaaf6SDaniel Pieczko " VFs may not function\n", rc); 17616d8aaaf6SDaniel Pieczko #endif 17626d8aaaf6SDaniel Pieczko 1763874aeea5SJeff Kirsher rc = efx_probe_filters(efx); 1764874aeea5SJeff Kirsher if (rc) { 1765874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1766874aeea5SJeff Kirsher "failed to create filter tables\n"); 17676d8aaaf6SDaniel Pieczko goto fail4; 1768874aeea5SJeff Kirsher } 1769874aeea5SJeff Kirsher 17707f967c01SBen Hutchings rc = efx_probe_channels(efx); 17717f967c01SBen Hutchings if (rc) 17726d8aaaf6SDaniel Pieczko goto fail5; 17737f967c01SBen Hutchings 1774874aeea5SJeff Kirsher return 0; 1775874aeea5SJeff Kirsher 17766d8aaaf6SDaniel Pieczko fail5: 17777f967c01SBen Hutchings efx_remove_filters(efx); 17786d8aaaf6SDaniel Pieczko fail4: 17796d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 17806d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 17816d8aaaf6SDaniel Pieczko #endif 1782874aeea5SJeff Kirsher fail3: 1783874aeea5SJeff Kirsher efx_remove_port(efx); 1784874aeea5SJeff Kirsher fail2: 1785874aeea5SJeff Kirsher efx_remove_nic(efx); 1786874aeea5SJeff Kirsher fail1: 1787874aeea5SJeff Kirsher return rc; 1788874aeea5SJeff Kirsher } 1789874aeea5SJeff Kirsher 17908b7325b4SBen Hutchings /* If the interface is supposed to be running but is not, start 17918b7325b4SBen Hutchings * the hardware and software data path, regular activity for the port 17928b7325b4SBen Hutchings * (MAC statistics, link polling, etc.) and schedule the port to be 17938b7325b4SBen Hutchings * reconfigured. Interrupts must already be enabled. This function 17948b7325b4SBen Hutchings * is safe to call multiple times, so long as the NIC is not disabled. 17958b7325b4SBen Hutchings * Requires the RTNL lock. 17969f2cb71cSBen Hutchings */ 1797874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx) 1798874aeea5SJeff Kirsher { 1799874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 18008b7325b4SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 1801874aeea5SJeff Kirsher 1802874aeea5SJeff Kirsher /* Check that it is appropriate to restart the interface. All 1803874aeea5SJeff Kirsher * of these flags are safe to read under just the rtnl lock */ 1804e283546cSEdward Cree if (efx->port_enabled || !netif_running(efx->net_dev) || 1805e283546cSEdward Cree efx->reset_pending) 1806874aeea5SJeff Kirsher return; 1807874aeea5SJeff Kirsher 1808874aeea5SJeff Kirsher efx_start_port(efx); 18099f2cb71cSBen Hutchings efx_start_datapath(efx); 1810874aeea5SJeff Kirsher 1811626950dbSAlexandre Rames /* Start the hardware monitor if there is one */ 1812626950dbSAlexandre Rames if (efx->type->monitor != NULL) 1813874aeea5SJeff Kirsher queue_delayed_work(efx->workqueue, &efx->monitor_work, 1814874aeea5SJeff Kirsher efx_monitor_interval); 1815626950dbSAlexandre Rames 1816626950dbSAlexandre Rames /* If link state detection is normally event-driven, we have 1817626950dbSAlexandre Rames * to poll now because we could have missed a change 1818626950dbSAlexandre Rames */ 1819626950dbSAlexandre Rames if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) { 1820874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1821874aeea5SJeff Kirsher if (efx->phy_op->poll(efx)) 1822874aeea5SJeff Kirsher efx_link_status_changed(efx); 1823874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1824874aeea5SJeff Kirsher } 1825874aeea5SJeff Kirsher 1826874aeea5SJeff Kirsher efx->type->start_stats(efx); 1827f8f3b5aeSJon Cooper efx->type->pull_stats(efx); 1828f8f3b5aeSJon Cooper spin_lock_bh(&efx->stats_lock); 1829f8f3b5aeSJon Cooper efx->type->update_stats(efx, NULL, NULL); 1830f8f3b5aeSJon Cooper spin_unlock_bh(&efx->stats_lock); 1831874aeea5SJeff Kirsher } 1832874aeea5SJeff Kirsher 18338b7325b4SBen Hutchings /* Quiesce the hardware and software data path, and regular activity 18348b7325b4SBen Hutchings * for the port without bringing the link down. Safe to call multiple 18358b7325b4SBen Hutchings * times with the NIC in almost any state, but interrupts should be 18368b7325b4SBen Hutchings * enabled. Requires the RTNL lock. 18378b7325b4SBen Hutchings */ 1838874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx) 1839874aeea5SJeff Kirsher { 1840874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 1841874aeea5SJeff Kirsher 1842874aeea5SJeff Kirsher /* port_enabled can be read safely under the rtnl lock */ 1843874aeea5SJeff Kirsher if (!efx->port_enabled) 1844874aeea5SJeff Kirsher return; 1845874aeea5SJeff Kirsher 1846f8f3b5aeSJon Cooper /* update stats before we go down so we can accurately count 1847f8f3b5aeSJon Cooper * rx_nodesc_drops 1848f8f3b5aeSJon Cooper */ 1849f8f3b5aeSJon Cooper efx->type->pull_stats(efx); 1850f8f3b5aeSJon Cooper spin_lock_bh(&efx->stats_lock); 1851f8f3b5aeSJon Cooper efx->type->update_stats(efx, NULL, NULL); 1852f8f3b5aeSJon Cooper spin_unlock_bh(&efx->stats_lock); 1853874aeea5SJeff Kirsher efx->type->stop_stats(efx); 1854874aeea5SJeff Kirsher efx_stop_port(efx); 1855874aeea5SJeff Kirsher 185629c69a48SBen Hutchings /* Stop the kernel transmit interface. This is only valid if 185729c69a48SBen Hutchings * the device is stopped or detached; otherwise the watchdog 185829c69a48SBen Hutchings * may fire immediately. 185929c69a48SBen Hutchings */ 186029c69a48SBen Hutchings WARN_ON(netif_running(efx->net_dev) && 186129c69a48SBen Hutchings netif_device_present(efx->net_dev)); 18629f2cb71cSBen Hutchings netif_tx_disable(efx->net_dev); 18639f2cb71cSBen Hutchings 18649f2cb71cSBen Hutchings efx_stop_datapath(efx); 1865874aeea5SJeff Kirsher } 1866874aeea5SJeff Kirsher 1867874aeea5SJeff Kirsher static void efx_remove_all(struct efx_nic *efx) 1868874aeea5SJeff Kirsher { 1869874aeea5SJeff Kirsher efx_remove_channels(efx); 18707f967c01SBen Hutchings efx_remove_filters(efx); 18716d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 18726d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 18736d8aaaf6SDaniel Pieczko #endif 1874874aeea5SJeff Kirsher efx_remove_port(efx); 1875874aeea5SJeff Kirsher efx_remove_nic(efx); 1876874aeea5SJeff Kirsher } 1877874aeea5SJeff Kirsher 1878874aeea5SJeff Kirsher /************************************************************************** 1879874aeea5SJeff Kirsher * 1880874aeea5SJeff Kirsher * Interrupt moderation 1881874aeea5SJeff Kirsher * 1882874aeea5SJeff Kirsher **************************************************************************/ 1883874aeea5SJeff Kirsher 1884cc180b69SBen Hutchings static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns) 1885874aeea5SJeff Kirsher { 1886b548f976SBen Hutchings if (usecs == 0) 1887b548f976SBen Hutchings return 0; 1888cc180b69SBen Hutchings if (usecs * 1000 < quantum_ns) 1889874aeea5SJeff Kirsher return 1; /* never round down to 0 */ 1890cc180b69SBen Hutchings return usecs * 1000 / quantum_ns; 1891874aeea5SJeff Kirsher } 1892874aeea5SJeff Kirsher 1893874aeea5SJeff Kirsher /* Set interrupt moderation parameters */ 18949e393b30SBen Hutchings int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, 18959e393b30SBen Hutchings unsigned int rx_usecs, bool rx_adaptive, 18969e393b30SBen Hutchings bool rx_may_override_tx) 1897874aeea5SJeff Kirsher { 1898874aeea5SJeff Kirsher struct efx_channel *channel; 1899cc180b69SBen Hutchings unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max * 1900cc180b69SBen Hutchings efx->timer_quantum_ns, 1901cc180b69SBen Hutchings 1000); 1902cc180b69SBen Hutchings unsigned int tx_ticks; 1903cc180b69SBen Hutchings unsigned int rx_ticks; 1904874aeea5SJeff Kirsher 1905874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 1906874aeea5SJeff Kirsher 1907cc180b69SBen Hutchings if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max) 19089e393b30SBen Hutchings return -EINVAL; 19099e393b30SBen Hutchings 1910cc180b69SBen Hutchings tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns); 1911cc180b69SBen Hutchings rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns); 1912cc180b69SBen Hutchings 19139e393b30SBen Hutchings if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 && 19149e393b30SBen Hutchings !rx_may_override_tx) { 19159e393b30SBen Hutchings netif_err(efx, drv, efx->net_dev, "Channels are shared. " 19169e393b30SBen Hutchings "RX and TX IRQ moderation must be equal\n"); 19179e393b30SBen Hutchings return -EINVAL; 19189e393b30SBen Hutchings } 19199e393b30SBen Hutchings 1920874aeea5SJeff Kirsher efx->irq_rx_adaptive = rx_adaptive; 1921874aeea5SJeff Kirsher efx->irq_rx_moderation = rx_ticks; 1922874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 1923874aeea5SJeff Kirsher if (efx_channel_has_rx_queue(channel)) 1924874aeea5SJeff Kirsher channel->irq_moderation = rx_ticks; 1925874aeea5SJeff Kirsher else if (efx_channel_has_tx_queues(channel)) 1926874aeea5SJeff Kirsher channel->irq_moderation = tx_ticks; 1927874aeea5SJeff Kirsher } 19289e393b30SBen Hutchings 19299e393b30SBen Hutchings return 0; 1930874aeea5SJeff Kirsher } 1931874aeea5SJeff Kirsher 1932a0c4faf5SBen Hutchings void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, 1933a0c4faf5SBen Hutchings unsigned int *rx_usecs, bool *rx_adaptive) 1934a0c4faf5SBen Hutchings { 1935cc180b69SBen Hutchings /* We must round up when converting ticks to microseconds 1936cc180b69SBen Hutchings * because we round down when converting the other way. 1937cc180b69SBen Hutchings */ 1938cc180b69SBen Hutchings 1939a0c4faf5SBen Hutchings *rx_adaptive = efx->irq_rx_adaptive; 1940cc180b69SBen Hutchings *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation * 1941cc180b69SBen Hutchings efx->timer_quantum_ns, 1942cc180b69SBen Hutchings 1000); 1943a0c4faf5SBen Hutchings 1944a0c4faf5SBen Hutchings /* If channels are shared between RX and TX, so is IRQ 1945a0c4faf5SBen Hutchings * moderation. Otherwise, IRQ moderation is the same for all 1946a0c4faf5SBen Hutchings * TX channels and is not adaptive. 1947a0c4faf5SBen Hutchings */ 1948a0c4faf5SBen Hutchings if (efx->tx_channel_offset == 0) 1949a0c4faf5SBen Hutchings *tx_usecs = *rx_usecs; 1950a0c4faf5SBen Hutchings else 1951cc180b69SBen Hutchings *tx_usecs = DIV_ROUND_UP( 1952a0c4faf5SBen Hutchings efx->channel[efx->tx_channel_offset]->irq_moderation * 1953cc180b69SBen Hutchings efx->timer_quantum_ns, 1954cc180b69SBen Hutchings 1000); 1955a0c4faf5SBen Hutchings } 1956a0c4faf5SBen Hutchings 1957874aeea5SJeff Kirsher /************************************************************************** 1958874aeea5SJeff Kirsher * 1959874aeea5SJeff Kirsher * Hardware monitor 1960874aeea5SJeff Kirsher * 1961874aeea5SJeff Kirsher **************************************************************************/ 1962874aeea5SJeff Kirsher 1963874aeea5SJeff Kirsher /* Run periodically off the general workqueue */ 1964874aeea5SJeff Kirsher static void efx_monitor(struct work_struct *data) 1965874aeea5SJeff Kirsher { 1966874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, 1967874aeea5SJeff Kirsher monitor_work.work); 1968874aeea5SJeff Kirsher 1969874aeea5SJeff Kirsher netif_vdbg(efx, timer, efx->net_dev, 1970874aeea5SJeff Kirsher "hardware monitor executing on CPU %d\n", 1971874aeea5SJeff Kirsher raw_smp_processor_id()); 1972874aeea5SJeff Kirsher BUG_ON(efx->type->monitor == NULL); 1973874aeea5SJeff Kirsher 1974874aeea5SJeff Kirsher /* If the mac_lock is already held then it is likely a port 1975874aeea5SJeff Kirsher * reconfiguration is already in place, which will likely do 1976874aeea5SJeff Kirsher * most of the work of monitor() anyway. */ 1977874aeea5SJeff Kirsher if (mutex_trylock(&efx->mac_lock)) { 1978874aeea5SJeff Kirsher if (efx->port_enabled) 1979874aeea5SJeff Kirsher efx->type->monitor(efx); 1980874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1981874aeea5SJeff Kirsher } 1982874aeea5SJeff Kirsher 1983874aeea5SJeff Kirsher queue_delayed_work(efx->workqueue, &efx->monitor_work, 1984874aeea5SJeff Kirsher efx_monitor_interval); 1985874aeea5SJeff Kirsher } 1986874aeea5SJeff Kirsher 1987874aeea5SJeff Kirsher /************************************************************************** 1988874aeea5SJeff Kirsher * 1989874aeea5SJeff Kirsher * ioctls 1990874aeea5SJeff Kirsher * 1991874aeea5SJeff Kirsher *************************************************************************/ 1992874aeea5SJeff Kirsher 1993874aeea5SJeff Kirsher /* Net device ioctl 1994874aeea5SJeff Kirsher * Context: process, rtnl_lock() held. 1995874aeea5SJeff Kirsher */ 1996874aeea5SJeff Kirsher static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) 1997874aeea5SJeff Kirsher { 1998874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 1999874aeea5SJeff Kirsher struct mii_ioctl_data *data = if_mii(ifr); 2000874aeea5SJeff Kirsher 20017c236c43SStuart Hodgson if (cmd == SIOCSHWTSTAMP) 2002433dc9b3SBen Hutchings return efx_ptp_set_ts_config(efx, ifr); 2003433dc9b3SBen Hutchings if (cmd == SIOCGHWTSTAMP) 2004433dc9b3SBen Hutchings return efx_ptp_get_ts_config(efx, ifr); 20057c236c43SStuart Hodgson 2006874aeea5SJeff Kirsher /* Convert phy_id from older PRTAD/DEVAD format */ 2007874aeea5SJeff Kirsher if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && 2008874aeea5SJeff Kirsher (data->phy_id & 0xfc00) == 0x0400) 2009874aeea5SJeff Kirsher data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; 2010874aeea5SJeff Kirsher 2011874aeea5SJeff Kirsher return mdio_mii_ioctl(&efx->mdio, data, cmd); 2012874aeea5SJeff Kirsher } 2013874aeea5SJeff Kirsher 2014874aeea5SJeff Kirsher /************************************************************************** 2015874aeea5SJeff Kirsher * 2016874aeea5SJeff Kirsher * NAPI interface 2017874aeea5SJeff Kirsher * 2018874aeea5SJeff Kirsher **************************************************************************/ 2019874aeea5SJeff Kirsher 20207f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel) 2021874aeea5SJeff Kirsher { 20227f967c01SBen Hutchings struct efx_nic *efx = channel->efx; 2023874aeea5SJeff Kirsher 2024874aeea5SJeff Kirsher channel->napi_dev = efx->net_dev; 2025874aeea5SJeff Kirsher netif_napi_add(channel->napi_dev, &channel->napi_str, 2026874aeea5SJeff Kirsher efx_poll, napi_weight); 202736763266SAlexandre Rames napi_hash_add(&channel->napi_str); 202836763266SAlexandre Rames efx_channel_init_lock(channel); 2029874aeea5SJeff Kirsher } 20307f967c01SBen Hutchings 20317f967c01SBen Hutchings static void efx_init_napi(struct efx_nic *efx) 20327f967c01SBen Hutchings { 20337f967c01SBen Hutchings struct efx_channel *channel; 20347f967c01SBen Hutchings 20357f967c01SBen Hutchings efx_for_each_channel(channel, efx) 20367f967c01SBen Hutchings efx_init_napi_channel(channel); 2037874aeea5SJeff Kirsher } 2038874aeea5SJeff Kirsher 2039874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel) 2040874aeea5SJeff Kirsher { 204136763266SAlexandre Rames if (channel->napi_dev) { 2042874aeea5SJeff Kirsher netif_napi_del(&channel->napi_str); 204336763266SAlexandre Rames napi_hash_del(&channel->napi_str); 204436763266SAlexandre Rames } 2045874aeea5SJeff Kirsher channel->napi_dev = NULL; 2046874aeea5SJeff Kirsher } 2047874aeea5SJeff Kirsher 2048874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx) 2049874aeea5SJeff Kirsher { 2050874aeea5SJeff Kirsher struct efx_channel *channel; 2051874aeea5SJeff Kirsher 2052874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 2053874aeea5SJeff Kirsher efx_fini_napi_channel(channel); 2054874aeea5SJeff Kirsher } 2055874aeea5SJeff Kirsher 2056874aeea5SJeff Kirsher /************************************************************************** 2057874aeea5SJeff Kirsher * 2058874aeea5SJeff Kirsher * Kernel netpoll interface 2059874aeea5SJeff Kirsher * 2060874aeea5SJeff Kirsher *************************************************************************/ 2061874aeea5SJeff Kirsher 2062874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2063874aeea5SJeff Kirsher 2064874aeea5SJeff Kirsher /* Although in the common case interrupts will be disabled, this is not 2065874aeea5SJeff Kirsher * guaranteed. However, all our work happens inside the NAPI callback, 2066874aeea5SJeff Kirsher * so no locking is required. 2067874aeea5SJeff Kirsher */ 2068874aeea5SJeff Kirsher static void efx_netpoll(struct net_device *net_dev) 2069874aeea5SJeff Kirsher { 2070874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2071874aeea5SJeff Kirsher struct efx_channel *channel; 2072874aeea5SJeff Kirsher 2073874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 2074874aeea5SJeff Kirsher efx_schedule_channel(channel); 2075874aeea5SJeff Kirsher } 2076874aeea5SJeff Kirsher 2077874aeea5SJeff Kirsher #endif 2078874aeea5SJeff Kirsher 207936763266SAlexandre Rames #ifdef CONFIG_NET_RX_BUSY_POLL 208036763266SAlexandre Rames static int efx_busy_poll(struct napi_struct *napi) 208136763266SAlexandre Rames { 208236763266SAlexandre Rames struct efx_channel *channel = 208336763266SAlexandre Rames container_of(napi, struct efx_channel, napi_str); 208436763266SAlexandre Rames struct efx_nic *efx = channel->efx; 208536763266SAlexandre Rames int budget = 4; 208636763266SAlexandre Rames int old_rx_packets, rx_packets; 208736763266SAlexandre Rames 208836763266SAlexandre Rames if (!netif_running(efx->net_dev)) 208936763266SAlexandre Rames return LL_FLUSH_FAILED; 209036763266SAlexandre Rames 209136763266SAlexandre Rames if (!efx_channel_lock_poll(channel)) 209236763266SAlexandre Rames return LL_FLUSH_BUSY; 209336763266SAlexandre Rames 209436763266SAlexandre Rames old_rx_packets = channel->rx_queue.rx_packets; 209536763266SAlexandre Rames efx_process_channel(channel, budget); 209636763266SAlexandre Rames 209736763266SAlexandre Rames rx_packets = channel->rx_queue.rx_packets - old_rx_packets; 209836763266SAlexandre Rames 209936763266SAlexandre Rames /* There is no race condition with NAPI here. 210036763266SAlexandre Rames * NAPI will automatically be rescheduled if it yielded during busy 210136763266SAlexandre Rames * polling, because it was not able to take the lock and thus returned 210236763266SAlexandre Rames * the full budget. 210336763266SAlexandre Rames */ 210436763266SAlexandre Rames efx_channel_unlock_poll(channel); 210536763266SAlexandre Rames 210636763266SAlexandre Rames return rx_packets; 210736763266SAlexandre Rames } 210836763266SAlexandre Rames #endif 210936763266SAlexandre Rames 2110874aeea5SJeff Kirsher /************************************************************************** 2111874aeea5SJeff Kirsher * 2112874aeea5SJeff Kirsher * Kernel net device interface 2113874aeea5SJeff Kirsher * 2114874aeea5SJeff Kirsher *************************************************************************/ 2115874aeea5SJeff Kirsher 2116874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */ 2117e340be92SShradha Shah int efx_net_open(struct net_device *net_dev) 2118874aeea5SJeff Kirsher { 2119874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 21208b7325b4SBen Hutchings int rc; 21218b7325b4SBen Hutchings 2122874aeea5SJeff Kirsher netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", 2123874aeea5SJeff Kirsher raw_smp_processor_id()); 2124874aeea5SJeff Kirsher 21258b7325b4SBen Hutchings rc = efx_check_disabled(efx); 21268b7325b4SBen Hutchings if (rc) 21278b7325b4SBen Hutchings return rc; 2128874aeea5SJeff Kirsher if (efx->phy_mode & PHY_MODE_SPECIAL) 2129874aeea5SJeff Kirsher return -EBUSY; 2130874aeea5SJeff Kirsher if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) 2131874aeea5SJeff Kirsher return -EIO; 2132874aeea5SJeff Kirsher 2133874aeea5SJeff Kirsher /* Notify the kernel of the link state polled during driver load, 2134874aeea5SJeff Kirsher * before the monitor starts running */ 2135874aeea5SJeff Kirsher efx_link_status_changed(efx); 2136874aeea5SJeff Kirsher 2137874aeea5SJeff Kirsher efx_start_all(efx); 2138dd40781eSBen Hutchings efx_selftest_async_start(efx); 2139874aeea5SJeff Kirsher return 0; 2140874aeea5SJeff Kirsher } 2141874aeea5SJeff Kirsher 2142874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. 2143874aeea5SJeff Kirsher * Note that the kernel will ignore our return code; this method 2144874aeea5SJeff Kirsher * should really be a void. 2145874aeea5SJeff Kirsher */ 2146e340be92SShradha Shah int efx_net_stop(struct net_device *net_dev) 2147874aeea5SJeff Kirsher { 2148874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2149874aeea5SJeff Kirsher 2150874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", 2151874aeea5SJeff Kirsher raw_smp_processor_id()); 2152874aeea5SJeff Kirsher 2153874aeea5SJeff Kirsher /* Stop the device and flush all the channels */ 2154874aeea5SJeff Kirsher efx_stop_all(efx); 2155874aeea5SJeff Kirsher 2156874aeea5SJeff Kirsher return 0; 2157874aeea5SJeff Kirsher } 2158874aeea5SJeff Kirsher 2159874aeea5SJeff Kirsher /* Context: process, dev_base_lock or RTNL held, non-blocking. */ 21602aa9ef11SBen Hutchings static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev, 21612aa9ef11SBen Hutchings struct rtnl_link_stats64 *stats) 2162874aeea5SJeff Kirsher { 2163874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2164874aeea5SJeff Kirsher 2165874aeea5SJeff Kirsher spin_lock_bh(&efx->stats_lock); 2166cd0ecc9aSBen Hutchings efx->type->update_stats(efx, NULL, stats); 21671cb34522SBen Hutchings spin_unlock_bh(&efx->stats_lock); 21681cb34522SBen Hutchings 2169874aeea5SJeff Kirsher return stats; 2170874aeea5SJeff Kirsher } 2171874aeea5SJeff Kirsher 2172874aeea5SJeff Kirsher /* Context: netif_tx_lock held, BHs disabled. */ 2173874aeea5SJeff Kirsher static void efx_watchdog(struct net_device *net_dev) 2174874aeea5SJeff Kirsher { 2175874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2176874aeea5SJeff Kirsher 2177874aeea5SJeff Kirsher netif_err(efx, tx_err, efx->net_dev, 2178874aeea5SJeff Kirsher "TX stuck with port_enabled=%d: resetting channels\n", 2179874aeea5SJeff Kirsher efx->port_enabled); 2180874aeea5SJeff Kirsher 2181874aeea5SJeff Kirsher efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); 2182874aeea5SJeff Kirsher } 2183874aeea5SJeff Kirsher 2184874aeea5SJeff Kirsher 2185874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */ 2186874aeea5SJeff Kirsher static int efx_change_mtu(struct net_device *net_dev, int new_mtu) 2187874aeea5SJeff Kirsher { 2188874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 21898b7325b4SBen Hutchings int rc; 2190874aeea5SJeff Kirsher 21918b7325b4SBen Hutchings rc = efx_check_disabled(efx); 21928b7325b4SBen Hutchings if (rc) 21938b7325b4SBen Hutchings return rc; 2194874aeea5SJeff Kirsher if (new_mtu > EFX_MAX_MTU) 2195874aeea5SJeff Kirsher return -EINVAL; 2196874aeea5SJeff Kirsher 2197874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu); 2198874aeea5SJeff Kirsher 219929c69a48SBen Hutchings efx_device_detach_sync(efx); 220029c69a48SBen Hutchings efx_stop_all(efx); 220129c69a48SBen Hutchings 2202874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 2203874aeea5SJeff Kirsher net_dev->mtu = new_mtu; 22040d322413SEdward Cree efx_mac_reconfigure(efx); 2205874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2206874aeea5SJeff Kirsher 2207874aeea5SJeff Kirsher efx_start_all(efx); 220829c69a48SBen Hutchings netif_device_attach(efx->net_dev); 22096c8eef4aSBen Hutchings return 0; 2210874aeea5SJeff Kirsher } 2211874aeea5SJeff Kirsher 2212874aeea5SJeff Kirsher static int efx_set_mac_address(struct net_device *net_dev, void *data) 2213874aeea5SJeff Kirsher { 2214874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2215874aeea5SJeff Kirsher struct sockaddr *addr = data; 2216e0b3ae30SBen Hutchings u8 *new_addr = addr->sa_data; 2217cfc77c2fSShradha Shah u8 old_addr[6]; 2218cfc77c2fSShradha Shah int rc; 2219874aeea5SJeff Kirsher 2220874aeea5SJeff Kirsher if (!is_valid_ether_addr(new_addr)) { 2221874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2222874aeea5SJeff Kirsher "invalid ethernet MAC address requested: %pM\n", 2223874aeea5SJeff Kirsher new_addr); 2224504f9b5aSDanny Kukawka return -EADDRNOTAVAIL; 2225874aeea5SJeff Kirsher } 2226874aeea5SJeff Kirsher 2227cfc77c2fSShradha Shah /* save old address */ 2228cfc77c2fSShradha Shah ether_addr_copy(old_addr, net_dev->dev_addr); 2229cd84ff4dSEdward Cree ether_addr_copy(net_dev->dev_addr, new_addr); 2230910c8789SShradha Shah if (efx->type->set_mac_address) { 2231910c8789SShradha Shah rc = efx->type->set_mac_address(efx); 2232cfc77c2fSShradha Shah if (rc) { 2233cfc77c2fSShradha Shah ether_addr_copy(net_dev->dev_addr, old_addr); 2234cfc77c2fSShradha Shah return rc; 2235cfc77c2fSShradha Shah } 2236cfc77c2fSShradha Shah } 2237874aeea5SJeff Kirsher 2238874aeea5SJeff Kirsher /* Reconfigure the MAC */ 2239874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 22400d322413SEdward Cree efx_mac_reconfigure(efx); 2241874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2242874aeea5SJeff Kirsher 2243874aeea5SJeff Kirsher return 0; 2244874aeea5SJeff Kirsher } 2245874aeea5SJeff Kirsher 2246874aeea5SJeff Kirsher /* Context: netif_addr_lock held, BHs disabled. */ 22470fca8c97SBen Hutchings static void efx_set_rx_mode(struct net_device *net_dev) 2248874aeea5SJeff Kirsher { 2249874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2250874aeea5SJeff Kirsher 2251874aeea5SJeff Kirsher if (efx->port_enabled) 2252874aeea5SJeff Kirsher queue_work(efx->workqueue, &efx->mac_work); 2253874aeea5SJeff Kirsher /* Otherwise efx_start_port() will do this */ 2254874aeea5SJeff Kirsher } 2255874aeea5SJeff Kirsher 2256c8f44affSMichał Mirosław static int efx_set_features(struct net_device *net_dev, netdev_features_t data) 2257874aeea5SJeff Kirsher { 2258874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2259874aeea5SJeff Kirsher 2260874aeea5SJeff Kirsher /* If disabling RX n-tuple filtering, clear existing filters */ 2261874aeea5SJeff Kirsher if (net_dev->features & ~data & NETIF_F_NTUPLE) 2262fbd79120SBen Hutchings return efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); 2263874aeea5SJeff Kirsher 2264874aeea5SJeff Kirsher return 0; 2265874aeea5SJeff Kirsher } 2266874aeea5SJeff Kirsher 22677fa8d547SShradha Shah static const struct net_device_ops efx_netdev_ops = { 2268874aeea5SJeff Kirsher .ndo_open = efx_net_open, 2269874aeea5SJeff Kirsher .ndo_stop = efx_net_stop, 2270874aeea5SJeff Kirsher .ndo_get_stats64 = efx_net_stats, 2271874aeea5SJeff Kirsher .ndo_tx_timeout = efx_watchdog, 2272874aeea5SJeff Kirsher .ndo_start_xmit = efx_hard_start_xmit, 2273874aeea5SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 2274874aeea5SJeff Kirsher .ndo_do_ioctl = efx_ioctl, 2275874aeea5SJeff Kirsher .ndo_change_mtu = efx_change_mtu, 2276874aeea5SJeff Kirsher .ndo_set_mac_address = efx_set_mac_address, 22770fca8c97SBen Hutchings .ndo_set_rx_mode = efx_set_rx_mode, 2278874aeea5SJeff Kirsher .ndo_set_features = efx_set_features, 2279cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV 22807fa8d547SShradha Shah .ndo_set_vf_mac = efx_sriov_set_vf_mac, 22817fa8d547SShradha Shah .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, 22827fa8d547SShradha Shah .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, 22837fa8d547SShradha Shah .ndo_get_vf_config = efx_sriov_get_vf_config, 22844392dc69SEdward Cree .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, 2285cd2d5b52SBen Hutchings #endif 2286874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2287874aeea5SJeff Kirsher .ndo_poll_controller = efx_netpoll, 2288874aeea5SJeff Kirsher #endif 2289874aeea5SJeff Kirsher .ndo_setup_tc = efx_setup_tc, 229036763266SAlexandre Rames #ifdef CONFIG_NET_RX_BUSY_POLL 229136763266SAlexandre Rames .ndo_busy_poll = efx_busy_poll, 229236763266SAlexandre Rames #endif 2293874aeea5SJeff Kirsher #ifdef CONFIG_RFS_ACCEL 2294874aeea5SJeff Kirsher .ndo_rx_flow_steer = efx_filter_rfs, 2295874aeea5SJeff Kirsher #endif 2296874aeea5SJeff Kirsher }; 2297874aeea5SJeff Kirsher 2298874aeea5SJeff Kirsher static void efx_update_name(struct efx_nic *efx) 2299874aeea5SJeff Kirsher { 2300874aeea5SJeff Kirsher strcpy(efx->name, efx->net_dev->name); 2301874aeea5SJeff Kirsher efx_mtd_rename(efx); 2302874aeea5SJeff Kirsher efx_set_channel_names(efx); 2303874aeea5SJeff Kirsher } 2304874aeea5SJeff Kirsher 2305874aeea5SJeff Kirsher static int efx_netdev_event(struct notifier_block *this, 2306874aeea5SJeff Kirsher unsigned long event, void *ptr) 2307874aeea5SJeff Kirsher { 2308351638e7SJiri Pirko struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); 2309874aeea5SJeff Kirsher 23107fa8d547SShradha Shah if ((net_dev->netdev_ops == &efx_netdev_ops) && 2311874aeea5SJeff Kirsher event == NETDEV_CHANGENAME) 2312874aeea5SJeff Kirsher efx_update_name(netdev_priv(net_dev)); 2313874aeea5SJeff Kirsher 2314874aeea5SJeff Kirsher return NOTIFY_DONE; 2315874aeea5SJeff Kirsher } 2316874aeea5SJeff Kirsher 2317874aeea5SJeff Kirsher static struct notifier_block efx_netdev_notifier = { 2318874aeea5SJeff Kirsher .notifier_call = efx_netdev_event, 2319874aeea5SJeff Kirsher }; 2320874aeea5SJeff Kirsher 2321874aeea5SJeff Kirsher static ssize_t 2322874aeea5SJeff Kirsher show_phy_type(struct device *dev, struct device_attribute *attr, char *buf) 2323874aeea5SJeff Kirsher { 2324874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 2325874aeea5SJeff Kirsher return sprintf(buf, "%d\n", efx->phy_type); 2326874aeea5SJeff Kirsher } 2327776fbcc9SBen Hutchings static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL); 2328874aeea5SJeff Kirsher 2329874aeea5SJeff Kirsher static int efx_register_netdev(struct efx_nic *efx) 2330874aeea5SJeff Kirsher { 2331874aeea5SJeff Kirsher struct net_device *net_dev = efx->net_dev; 2332874aeea5SJeff Kirsher struct efx_channel *channel; 2333874aeea5SJeff Kirsher int rc; 2334874aeea5SJeff Kirsher 2335874aeea5SJeff Kirsher net_dev->watchdog_timeo = 5 * HZ; 2336874aeea5SJeff Kirsher net_dev->irq = efx->pci_dev->irq; 23377fa8d547SShradha Shah net_dev->netdev_ops = &efx_netdev_ops; 23387fa8d547SShradha Shah if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) 23398127d661SBen Hutchings net_dev->priv_flags |= IFF_UNICAST_FLT; 23407ad24ea4SWilfried Klaebe net_dev->ethtool_ops = &efx_ethtool_ops; 23417e6d06f0SBen Hutchings net_dev->gso_max_segs = EFX_TSO_MAX_SEGS; 2342874aeea5SJeff Kirsher 2343874aeea5SJeff Kirsher rtnl_lock(); 2344874aeea5SJeff Kirsher 23457153f623SBen Hutchings /* Enable resets to be scheduled and check whether any were 23467153f623SBen Hutchings * already requested. If so, the NIC is probably hosed so we 23477153f623SBen Hutchings * abort. 23487153f623SBen Hutchings */ 23497153f623SBen Hutchings efx->state = STATE_READY; 23507153f623SBen Hutchings smp_mb(); /* ensure we change state before checking reset_pending */ 23517153f623SBen Hutchings if (efx->reset_pending) { 23527153f623SBen Hutchings netif_err(efx, probe, efx->net_dev, 23537153f623SBen Hutchings "aborting probe due to scheduled reset\n"); 23547153f623SBen Hutchings rc = -EIO; 23557153f623SBen Hutchings goto fail_locked; 23567153f623SBen Hutchings } 23577153f623SBen Hutchings 2358874aeea5SJeff Kirsher rc = dev_alloc_name(net_dev, net_dev->name); 2359874aeea5SJeff Kirsher if (rc < 0) 2360874aeea5SJeff Kirsher goto fail_locked; 2361874aeea5SJeff Kirsher efx_update_name(efx); 2362874aeea5SJeff Kirsher 23638f8b3d51SBen Hutchings /* Always start with carrier off; PHY events will detect the link */ 23648f8b3d51SBen Hutchings netif_carrier_off(net_dev); 23658f8b3d51SBen Hutchings 2366874aeea5SJeff Kirsher rc = register_netdevice(net_dev); 2367874aeea5SJeff Kirsher if (rc) 2368874aeea5SJeff Kirsher goto fail_locked; 2369874aeea5SJeff Kirsher 2370874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 2371874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 2372874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 2373874aeea5SJeff Kirsher efx_init_tx_queue_core_txq(tx_queue); 2374874aeea5SJeff Kirsher } 2375874aeea5SJeff Kirsher 23760bcf4a64SBen Hutchings efx_associate(efx); 23770bcf4a64SBen Hutchings 2378874aeea5SJeff Kirsher rtnl_unlock(); 2379874aeea5SJeff Kirsher 2380874aeea5SJeff Kirsher rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); 2381874aeea5SJeff Kirsher if (rc) { 2382874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2383874aeea5SJeff Kirsher "failed to init net dev attributes\n"); 2384874aeea5SJeff Kirsher goto fail_registered; 2385874aeea5SJeff Kirsher } 2386874aeea5SJeff Kirsher 2387874aeea5SJeff Kirsher return 0; 2388874aeea5SJeff Kirsher 23897153f623SBen Hutchings fail_registered: 23907153f623SBen Hutchings rtnl_lock(); 23910bcf4a64SBen Hutchings efx_dissociate(efx); 23927153f623SBen Hutchings unregister_netdevice(net_dev); 2393874aeea5SJeff Kirsher fail_locked: 23947153f623SBen Hutchings efx->state = STATE_UNINIT; 2395874aeea5SJeff Kirsher rtnl_unlock(); 2396874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); 2397874aeea5SJeff Kirsher return rc; 2398874aeea5SJeff Kirsher } 2399874aeea5SJeff Kirsher 2400874aeea5SJeff Kirsher static void efx_unregister_netdev(struct efx_nic *efx) 2401874aeea5SJeff Kirsher { 2402874aeea5SJeff Kirsher if (!efx->net_dev) 2403874aeea5SJeff Kirsher return; 2404874aeea5SJeff Kirsher 2405874aeea5SJeff Kirsher BUG_ON(netdev_priv(efx->net_dev) != efx); 2406874aeea5SJeff Kirsher 2407874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); 2408874aeea5SJeff Kirsher device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); 24097153f623SBen Hutchings 24107153f623SBen Hutchings rtnl_lock(); 24117153f623SBen Hutchings unregister_netdevice(efx->net_dev); 24127153f623SBen Hutchings efx->state = STATE_UNINIT; 24137153f623SBen Hutchings rtnl_unlock(); 2414874aeea5SJeff Kirsher } 2415874aeea5SJeff Kirsher 2416874aeea5SJeff Kirsher /************************************************************************** 2417874aeea5SJeff Kirsher * 2418874aeea5SJeff Kirsher * Device reset and suspend 2419874aeea5SJeff Kirsher * 2420874aeea5SJeff Kirsher **************************************************************************/ 2421874aeea5SJeff Kirsher 2422874aeea5SJeff Kirsher /* Tears down the entire software state and most of the hardware state 2423874aeea5SJeff Kirsher * before reset. */ 2424874aeea5SJeff Kirsher void efx_reset_down(struct efx_nic *efx, enum reset_type method) 2425874aeea5SJeff Kirsher { 2426874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 2427874aeea5SJeff Kirsher 2428e283546cSEdward Cree if (method == RESET_TYPE_MCDI_TIMEOUT) 2429e283546cSEdward Cree efx->type->prepare_flr(efx); 2430e283546cSEdward Cree 2431874aeea5SJeff Kirsher efx_stop_all(efx); 2432d8291187SBen Hutchings efx_disable_interrupts(efx); 24335642ceefSBen Hutchings 24345642ceefSBen Hutchings mutex_lock(&efx->mac_lock); 2435087e9025SJon Cooper if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && 2436087e9025SJon Cooper method != RESET_TYPE_DATAPATH) 2437874aeea5SJeff Kirsher efx->phy_op->fini(efx); 2438874aeea5SJeff Kirsher efx->type->fini(efx); 2439874aeea5SJeff Kirsher } 2440874aeea5SJeff Kirsher 2441874aeea5SJeff Kirsher /* This function will always ensure that the locks acquired in 2442874aeea5SJeff Kirsher * efx_reset_down() are released. A failure return code indicates 2443874aeea5SJeff Kirsher * that we were unable to reinitialise the hardware, and the 2444874aeea5SJeff Kirsher * driver should be disabled. If ok is false, then the rx and tx 2445874aeea5SJeff Kirsher * engines are not restarted, pending a RESET_DISABLE. */ 2446874aeea5SJeff Kirsher int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) 2447874aeea5SJeff Kirsher { 2448874aeea5SJeff Kirsher int rc; 2449874aeea5SJeff Kirsher 2450874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 2451874aeea5SJeff Kirsher 2452e283546cSEdward Cree if (method == RESET_TYPE_MCDI_TIMEOUT) 2453e283546cSEdward Cree efx->type->finish_flr(efx); 2454e283546cSEdward Cree 2455e283546cSEdward Cree /* Ensure that SRAM is initialised even if we're disabling the device */ 2456874aeea5SJeff Kirsher rc = efx->type->init(efx); 2457874aeea5SJeff Kirsher if (rc) { 2458874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n"); 2459874aeea5SJeff Kirsher goto fail; 2460874aeea5SJeff Kirsher } 2461874aeea5SJeff Kirsher 2462874aeea5SJeff Kirsher if (!ok) 2463874aeea5SJeff Kirsher goto fail; 2464874aeea5SJeff Kirsher 2465087e9025SJon Cooper if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && 2466087e9025SJon Cooper method != RESET_TYPE_DATAPATH) { 2467874aeea5SJeff Kirsher rc = efx->phy_op->init(efx); 2468874aeea5SJeff Kirsher if (rc) 2469874aeea5SJeff Kirsher goto fail; 2470267d9d73SEdward Cree rc = efx->phy_op->reconfigure(efx); 2471267d9d73SEdward Cree if (rc && rc != -EPERM) 2472874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2473874aeea5SJeff Kirsher "could not restore PHY settings\n"); 2474874aeea5SJeff Kirsher } 2475874aeea5SJeff Kirsher 2476261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 2477261e4d96SJon Cooper if (rc) 2478261e4d96SJon Cooper goto fail; 24796d8aaaf6SDaniel Pieczko 24806d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 24816d8aaaf6SDaniel Pieczko rc = efx->type->vswitching_restore(efx); 24826d8aaaf6SDaniel Pieczko if (rc) /* not fatal; the PF will still work fine */ 24836d8aaaf6SDaniel Pieczko netif_warn(efx, probe, efx->net_dev, 24846d8aaaf6SDaniel Pieczko "failed to restore vswitching rc=%d;" 24856d8aaaf6SDaniel Pieczko " VFs may not function\n", rc); 24866d8aaaf6SDaniel Pieczko #endif 24876d8aaaf6SDaniel Pieczko 24880d322413SEdward Cree down_read(&efx->filter_sem); 2489874aeea5SJeff Kirsher efx_restore_filters(efx); 24900d322413SEdward Cree up_read(&efx->filter_sem); 24917fa8d547SShradha Shah if (efx->type->sriov_reset) 2492d98a4ffeSShradha Shah efx->type->sriov_reset(efx); 2493874aeea5SJeff Kirsher 2494874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2495874aeea5SJeff Kirsher 2496874aeea5SJeff Kirsher efx_start_all(efx); 2497874aeea5SJeff Kirsher 2498874aeea5SJeff Kirsher return 0; 2499874aeea5SJeff Kirsher 2500874aeea5SJeff Kirsher fail: 2501874aeea5SJeff Kirsher efx->port_initialized = false; 2502874aeea5SJeff Kirsher 2503874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2504874aeea5SJeff Kirsher 2505874aeea5SJeff Kirsher return rc; 2506874aeea5SJeff Kirsher } 2507874aeea5SJeff Kirsher 2508874aeea5SJeff Kirsher /* Reset the NIC using the specified method. Note that the reset may 2509874aeea5SJeff Kirsher * fail, in which case the card will be left in an unusable state. 2510874aeea5SJeff Kirsher * 2511874aeea5SJeff Kirsher * Caller must hold the rtnl_lock. 2512874aeea5SJeff Kirsher */ 2513874aeea5SJeff Kirsher int efx_reset(struct efx_nic *efx, enum reset_type method) 2514874aeea5SJeff Kirsher { 2515874aeea5SJeff Kirsher int rc, rc2; 2516874aeea5SJeff Kirsher bool disabled; 2517874aeea5SJeff Kirsher 2518874aeea5SJeff Kirsher netif_info(efx, drv, efx->net_dev, "resetting (%s)\n", 2519874aeea5SJeff Kirsher RESET_TYPE(method)); 2520874aeea5SJeff Kirsher 2521c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 2522874aeea5SJeff Kirsher efx_reset_down(efx, method); 2523874aeea5SJeff Kirsher 2524874aeea5SJeff Kirsher rc = efx->type->reset(efx, method); 2525874aeea5SJeff Kirsher if (rc) { 2526874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n"); 2527874aeea5SJeff Kirsher goto out; 2528874aeea5SJeff Kirsher } 2529874aeea5SJeff Kirsher 2530874aeea5SJeff Kirsher /* Clear flags for the scopes we covered. We assume the NIC and 2531874aeea5SJeff Kirsher * driver are now quiescent so that there is no race here. 2532874aeea5SJeff Kirsher */ 2533e283546cSEdward Cree if (method < RESET_TYPE_MAX_METHOD) 2534874aeea5SJeff Kirsher efx->reset_pending &= -(1 << (method + 1)); 2535e283546cSEdward Cree else /* it doesn't fit into the well-ordered scope hierarchy */ 2536e283546cSEdward Cree __clear_bit(method, &efx->reset_pending); 2537874aeea5SJeff Kirsher 2538874aeea5SJeff Kirsher /* Reinitialise bus-mastering, which may have been turned off before 2539874aeea5SJeff Kirsher * the reset was scheduled. This is still appropriate, even in the 2540874aeea5SJeff Kirsher * RESET_TYPE_DISABLE since this driver generally assumes the hardware 2541874aeea5SJeff Kirsher * can respond to requests. */ 2542874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 2543874aeea5SJeff Kirsher 2544874aeea5SJeff Kirsher out: 2545874aeea5SJeff Kirsher /* Leave device stopped if necessary */ 2546626950dbSAlexandre Rames disabled = rc || 2547626950dbSAlexandre Rames method == RESET_TYPE_DISABLE || 2548626950dbSAlexandre Rames method == RESET_TYPE_RECOVER_OR_DISABLE; 2549874aeea5SJeff Kirsher rc2 = efx_reset_up(efx, method, !disabled); 2550874aeea5SJeff Kirsher if (rc2) { 2551874aeea5SJeff Kirsher disabled = true; 2552874aeea5SJeff Kirsher if (!rc) 2553874aeea5SJeff Kirsher rc = rc2; 2554874aeea5SJeff Kirsher } 2555874aeea5SJeff Kirsher 2556874aeea5SJeff Kirsher if (disabled) { 2557874aeea5SJeff Kirsher dev_close(efx->net_dev); 2558874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "has been disabled\n"); 2559874aeea5SJeff Kirsher efx->state = STATE_DISABLED; 2560874aeea5SJeff Kirsher } else { 2561874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "reset complete\n"); 2562874aeea5SJeff Kirsher netif_device_attach(efx->net_dev); 2563874aeea5SJeff Kirsher } 2564874aeea5SJeff Kirsher return rc; 2565874aeea5SJeff Kirsher } 2566874aeea5SJeff Kirsher 2567626950dbSAlexandre Rames /* Try recovery mechanisms. 2568626950dbSAlexandre Rames * For now only EEH is supported. 2569626950dbSAlexandre Rames * Returns 0 if the recovery mechanisms are unsuccessful. 2570626950dbSAlexandre Rames * Returns a non-zero value otherwise. 2571626950dbSAlexandre Rames */ 2572b28405b0SAlexandre Rames int efx_try_recovery(struct efx_nic *efx) 2573626950dbSAlexandre Rames { 2574626950dbSAlexandre Rames #ifdef CONFIG_EEH 2575626950dbSAlexandre Rames /* A PCI error can occur and not be seen by EEH because nothing 2576626950dbSAlexandre Rames * happens on the PCI bus. In this case the driver may fail and 2577626950dbSAlexandre Rames * schedule a 'recover or reset', leading to this recovery handler. 2578626950dbSAlexandre Rames * Manually call the eeh failure check function. 2579626950dbSAlexandre Rames */ 258012a89dbaSBenjamin Herrenschmidt struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev); 2581626950dbSAlexandre Rames if (eeh_dev_check_failure(eehdev)) { 2582626950dbSAlexandre Rames /* The EEH mechanisms will handle the error and reset the 2583626950dbSAlexandre Rames * device if necessary. 2584626950dbSAlexandre Rames */ 2585626950dbSAlexandre Rames return 1; 2586626950dbSAlexandre Rames } 2587626950dbSAlexandre Rames #endif 2588626950dbSAlexandre Rames return 0; 2589626950dbSAlexandre Rames } 2590626950dbSAlexandre Rames 259174cd60a4SJon Cooper static void efx_wait_for_bist_end(struct efx_nic *efx) 259274cd60a4SJon Cooper { 259374cd60a4SJon Cooper int i; 259474cd60a4SJon Cooper 259574cd60a4SJon Cooper for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) { 259674cd60a4SJon Cooper if (efx_mcdi_poll_reboot(efx)) 259774cd60a4SJon Cooper goto out; 259874cd60a4SJon Cooper msleep(BIST_WAIT_DELAY_MS); 259974cd60a4SJon Cooper } 260074cd60a4SJon Cooper 260174cd60a4SJon Cooper netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n"); 260274cd60a4SJon Cooper out: 260374cd60a4SJon Cooper /* Either way unset the BIST flag. If we found no reboot we probably 260474cd60a4SJon Cooper * won't recover, but we should try. 260574cd60a4SJon Cooper */ 260674cd60a4SJon Cooper efx->mc_bist_for_other_fn = false; 260774cd60a4SJon Cooper } 260874cd60a4SJon Cooper 2609874aeea5SJeff Kirsher /* The worker thread exists so that code that cannot sleep can 2610874aeea5SJeff Kirsher * schedule a reset for later. 2611874aeea5SJeff Kirsher */ 2612874aeea5SJeff Kirsher static void efx_reset_work(struct work_struct *data) 2613874aeea5SJeff Kirsher { 2614874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, reset_work); 2615626950dbSAlexandre Rames unsigned long pending; 2616626950dbSAlexandre Rames enum reset_type method; 2617626950dbSAlexandre Rames 2618626950dbSAlexandre Rames pending = ACCESS_ONCE(efx->reset_pending); 2619626950dbSAlexandre Rames method = fls(pending) - 1; 2620626950dbSAlexandre Rames 262174cd60a4SJon Cooper if (method == RESET_TYPE_MC_BIST) 262274cd60a4SJon Cooper efx_wait_for_bist_end(efx); 262374cd60a4SJon Cooper 2624626950dbSAlexandre Rames if ((method == RESET_TYPE_RECOVER_OR_DISABLE || 2625626950dbSAlexandre Rames method == RESET_TYPE_RECOVER_OR_ALL) && 2626626950dbSAlexandre Rames efx_try_recovery(efx)) 2627626950dbSAlexandre Rames return; 2628874aeea5SJeff Kirsher 2629874aeea5SJeff Kirsher if (!pending) 2630874aeea5SJeff Kirsher return; 2631874aeea5SJeff Kirsher 2632874aeea5SJeff Kirsher rtnl_lock(); 26337153f623SBen Hutchings 26347153f623SBen Hutchings /* We checked the state in efx_schedule_reset() but it may 26357153f623SBen Hutchings * have changed by now. Now that we have the RTNL lock, 26367153f623SBen Hutchings * it cannot change again. 26377153f623SBen Hutchings */ 26387153f623SBen Hutchings if (efx->state == STATE_READY) 2639626950dbSAlexandre Rames (void)efx_reset(efx, method); 26407153f623SBen Hutchings 2641874aeea5SJeff Kirsher rtnl_unlock(); 2642874aeea5SJeff Kirsher } 2643874aeea5SJeff Kirsher 2644874aeea5SJeff Kirsher void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) 2645874aeea5SJeff Kirsher { 2646874aeea5SJeff Kirsher enum reset_type method; 2647874aeea5SJeff Kirsher 2648626950dbSAlexandre Rames if (efx->state == STATE_RECOVERY) { 2649626950dbSAlexandre Rames netif_dbg(efx, drv, efx->net_dev, 2650626950dbSAlexandre Rames "recovering: skip scheduling %s reset\n", 2651626950dbSAlexandre Rames RESET_TYPE(type)); 2652626950dbSAlexandre Rames return; 2653626950dbSAlexandre Rames } 2654626950dbSAlexandre Rames 2655874aeea5SJeff Kirsher switch (type) { 2656874aeea5SJeff Kirsher case RESET_TYPE_INVISIBLE: 2657874aeea5SJeff Kirsher case RESET_TYPE_ALL: 2658626950dbSAlexandre Rames case RESET_TYPE_RECOVER_OR_ALL: 2659874aeea5SJeff Kirsher case RESET_TYPE_WORLD: 2660874aeea5SJeff Kirsher case RESET_TYPE_DISABLE: 2661626950dbSAlexandre Rames case RESET_TYPE_RECOVER_OR_DISABLE: 2662087e9025SJon Cooper case RESET_TYPE_DATAPATH: 266374cd60a4SJon Cooper case RESET_TYPE_MC_BIST: 2664e283546cSEdward Cree case RESET_TYPE_MCDI_TIMEOUT: 2665874aeea5SJeff Kirsher method = type; 2666874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n", 2667874aeea5SJeff Kirsher RESET_TYPE(method)); 2668874aeea5SJeff Kirsher break; 2669874aeea5SJeff Kirsher default: 2670874aeea5SJeff Kirsher method = efx->type->map_reset_reason(type); 2671874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, 2672874aeea5SJeff Kirsher "scheduling %s reset for %s\n", 2673874aeea5SJeff Kirsher RESET_TYPE(method), RESET_TYPE(type)); 2674874aeea5SJeff Kirsher break; 2675874aeea5SJeff Kirsher } 2676874aeea5SJeff Kirsher 2677874aeea5SJeff Kirsher set_bit(method, &efx->reset_pending); 26787153f623SBen Hutchings smp_mb(); /* ensure we change reset_pending before checking state */ 26797153f623SBen Hutchings 26807153f623SBen Hutchings /* If we're not READY then just leave the flags set as the cue 26817153f623SBen Hutchings * to abort probing or reschedule the reset later. 26827153f623SBen Hutchings */ 26837153f623SBen Hutchings if (ACCESS_ONCE(efx->state) != STATE_READY) 26847153f623SBen Hutchings return; 2685874aeea5SJeff Kirsher 2686874aeea5SJeff Kirsher /* efx_process_channel() will no longer read events once a 2687874aeea5SJeff Kirsher * reset is scheduled. So switch back to poll'd MCDI completions. */ 2688874aeea5SJeff Kirsher efx_mcdi_mode_poll(efx); 2689874aeea5SJeff Kirsher 2690874aeea5SJeff Kirsher queue_work(reset_workqueue, &efx->reset_work); 2691874aeea5SJeff Kirsher } 2692874aeea5SJeff Kirsher 2693874aeea5SJeff Kirsher /************************************************************************** 2694874aeea5SJeff Kirsher * 2695874aeea5SJeff Kirsher * List of NICs we support 2696874aeea5SJeff Kirsher * 2697874aeea5SJeff Kirsher **************************************************************************/ 2698874aeea5SJeff Kirsher 2699874aeea5SJeff Kirsher /* PCI device ID table */ 27009baa3c34SBenoit Taine static const struct pci_device_id efx_pci_table[] = { 27010e59e7e7SLinus Torvalds {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 27020e59e7e7SLinus Torvalds PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0), 2703874aeea5SJeff Kirsher .driver_data = (unsigned long) &falcon_a1_nic_type}, 27040e59e7e7SLinus Torvalds {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 27050e59e7e7SLinus Torvalds PCI_DEVICE_ID_SOLARFLARE_SFC4000B), 2706874aeea5SJeff Kirsher .driver_data = (unsigned long) &falcon_b0_nic_type}, 2707547c474fSBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */ 2708874aeea5SJeff Kirsher .driver_data = (unsigned long) &siena_a0_nic_type}, 2709547c474fSBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */ 2710874aeea5SJeff Kirsher .driver_data = (unsigned long) &siena_a0_nic_type}, 27118127d661SBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ 27128127d661SBen Hutchings .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 27136f7f8aa6SShradha Shah {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ 27146f7f8aa6SShradha Shah .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 27153b06a00eSMateusz Wrzesinski {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ 27163b06a00eSMateusz Wrzesinski .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 2717874aeea5SJeff Kirsher {0} /* end of list */ 2718874aeea5SJeff Kirsher }; 2719874aeea5SJeff Kirsher 2720874aeea5SJeff Kirsher /************************************************************************** 2721874aeea5SJeff Kirsher * 2722874aeea5SJeff Kirsher * Dummy PHY/MAC operations 2723874aeea5SJeff Kirsher * 2724874aeea5SJeff Kirsher * Can be used for some unimplemented operations 2725874aeea5SJeff Kirsher * Needed so all function pointers are valid and do not have to be tested 2726874aeea5SJeff Kirsher * before use 2727874aeea5SJeff Kirsher * 2728874aeea5SJeff Kirsher **************************************************************************/ 2729874aeea5SJeff Kirsher int efx_port_dummy_op_int(struct efx_nic *efx) 2730874aeea5SJeff Kirsher { 2731874aeea5SJeff Kirsher return 0; 2732874aeea5SJeff Kirsher } 2733874aeea5SJeff Kirsher void efx_port_dummy_op_void(struct efx_nic *efx) {} 2734874aeea5SJeff Kirsher 2735874aeea5SJeff Kirsher static bool efx_port_dummy_op_poll(struct efx_nic *efx) 2736874aeea5SJeff Kirsher { 2737874aeea5SJeff Kirsher return false; 2738874aeea5SJeff Kirsher } 2739874aeea5SJeff Kirsher 2740874aeea5SJeff Kirsher static const struct efx_phy_operations efx_dummy_phy_operations = { 2741874aeea5SJeff Kirsher .init = efx_port_dummy_op_int, 2742874aeea5SJeff Kirsher .reconfigure = efx_port_dummy_op_int, 2743874aeea5SJeff Kirsher .poll = efx_port_dummy_op_poll, 2744874aeea5SJeff Kirsher .fini = efx_port_dummy_op_void, 2745874aeea5SJeff Kirsher }; 2746874aeea5SJeff Kirsher 2747874aeea5SJeff Kirsher /************************************************************************** 2748874aeea5SJeff Kirsher * 2749874aeea5SJeff Kirsher * Data housekeeping 2750874aeea5SJeff Kirsher * 2751874aeea5SJeff Kirsher **************************************************************************/ 2752874aeea5SJeff Kirsher 2753874aeea5SJeff Kirsher /* This zeroes out and then fills in the invariants in a struct 2754874aeea5SJeff Kirsher * efx_nic (including all sub-structures). 2755874aeea5SJeff Kirsher */ 2756adeb15aaSBen Hutchings static int efx_init_struct(struct efx_nic *efx, 2757874aeea5SJeff Kirsher struct pci_dev *pci_dev, struct net_device *net_dev) 2758874aeea5SJeff Kirsher { 2759874aeea5SJeff Kirsher int i; 2760874aeea5SJeff Kirsher 2761874aeea5SJeff Kirsher /* Initialise common structures */ 27620bcf4a64SBen Hutchings INIT_LIST_HEAD(&efx->node); 27630bcf4a64SBen Hutchings INIT_LIST_HEAD(&efx->secondary_list); 2764874aeea5SJeff Kirsher spin_lock_init(&efx->biu_lock); 2765874aeea5SJeff Kirsher #ifdef CONFIG_SFC_MTD 2766874aeea5SJeff Kirsher INIT_LIST_HEAD(&efx->mtd_list); 2767874aeea5SJeff Kirsher #endif 2768874aeea5SJeff Kirsher INIT_WORK(&efx->reset_work, efx_reset_work); 2769874aeea5SJeff Kirsher INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); 2770dd40781eSBen Hutchings INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work); 2771874aeea5SJeff Kirsher efx->pci_dev = pci_dev; 2772874aeea5SJeff Kirsher efx->msg_enable = debug; 2773f16aeea0SBen Hutchings efx->state = STATE_UNINIT; 2774874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); 2775874aeea5SJeff Kirsher 2776874aeea5SJeff Kirsher efx->net_dev = net_dev; 277743a3739dSJon Cooper efx->rx_prefix_size = efx->type->rx_prefix_size; 27782ec03014SAndrew Rybchenko efx->rx_ip_align = 27792ec03014SAndrew Rybchenko NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0; 278043a3739dSJon Cooper efx->rx_packet_hash_offset = 278143a3739dSJon Cooper efx->type->rx_hash_offset - efx->type->rx_prefix_size; 2782bd9a265dSJon Cooper efx->rx_packet_ts_offset = 2783bd9a265dSJon Cooper efx->type->rx_ts_offset - efx->type->rx_prefix_size; 2784874aeea5SJeff Kirsher spin_lock_init(&efx->stats_lock); 2785874aeea5SJeff Kirsher mutex_init(&efx->mac_lock); 2786874aeea5SJeff Kirsher efx->phy_op = &efx_dummy_phy_operations; 2787874aeea5SJeff Kirsher efx->mdio.dev = net_dev; 2788874aeea5SJeff Kirsher INIT_WORK(&efx->mac_work, efx_mac_work); 27899f2cb71cSBen Hutchings init_waitqueue_head(&efx->flush_wq); 2790874aeea5SJeff Kirsher 2791874aeea5SJeff Kirsher for (i = 0; i < EFX_MAX_CHANNELS; i++) { 2792874aeea5SJeff Kirsher efx->channel[i] = efx_alloc_channel(efx, i, NULL); 2793874aeea5SJeff Kirsher if (!efx->channel[i]) 2794874aeea5SJeff Kirsher goto fail; 2795d8291187SBen Hutchings efx->msi_context[i].efx = efx; 2796d8291187SBen Hutchings efx->msi_context[i].index = i; 2797874aeea5SJeff Kirsher } 2798874aeea5SJeff Kirsher 2799874aeea5SJeff Kirsher /* Higher numbered interrupt modes are less capable! */ 2800874aeea5SJeff Kirsher efx->interrupt_mode = max(efx->type->max_interrupt_mode, 2801874aeea5SJeff Kirsher interrupt_mode); 2802874aeea5SJeff Kirsher 2803874aeea5SJeff Kirsher /* Would be good to use the net_dev name, but we're too early */ 2804874aeea5SJeff Kirsher snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s", 2805874aeea5SJeff Kirsher pci_name(pci_dev)); 2806874aeea5SJeff Kirsher efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); 2807874aeea5SJeff Kirsher if (!efx->workqueue) 2808874aeea5SJeff Kirsher goto fail; 2809874aeea5SJeff Kirsher 2810874aeea5SJeff Kirsher return 0; 2811874aeea5SJeff Kirsher 2812874aeea5SJeff Kirsher fail: 2813874aeea5SJeff Kirsher efx_fini_struct(efx); 2814874aeea5SJeff Kirsher return -ENOMEM; 2815874aeea5SJeff Kirsher } 2816874aeea5SJeff Kirsher 2817874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx) 2818874aeea5SJeff Kirsher { 2819874aeea5SJeff Kirsher int i; 2820874aeea5SJeff Kirsher 2821874aeea5SJeff Kirsher for (i = 0; i < EFX_MAX_CHANNELS; i++) 2822874aeea5SJeff Kirsher kfree(efx->channel[i]); 2823874aeea5SJeff Kirsher 2824ef215e64SBen Hutchings kfree(efx->vpd_sn); 2825ef215e64SBen Hutchings 2826874aeea5SJeff Kirsher if (efx->workqueue) { 2827874aeea5SJeff Kirsher destroy_workqueue(efx->workqueue); 2828874aeea5SJeff Kirsher efx->workqueue = NULL; 2829874aeea5SJeff Kirsher } 2830874aeea5SJeff Kirsher } 2831874aeea5SJeff Kirsher 2832e4d112e4SEdward Cree void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) 2833e4d112e4SEdward Cree { 2834e4d112e4SEdward Cree u64 n_rx_nodesc_trunc = 0; 2835e4d112e4SEdward Cree struct efx_channel *channel; 2836e4d112e4SEdward Cree 2837e4d112e4SEdward Cree efx_for_each_channel(channel, efx) 2838e4d112e4SEdward Cree n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; 2839e4d112e4SEdward Cree stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; 2840e4d112e4SEdward Cree stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); 2841e4d112e4SEdward Cree } 2842e4d112e4SEdward Cree 2843874aeea5SJeff Kirsher /************************************************************************** 2844874aeea5SJeff Kirsher * 2845874aeea5SJeff Kirsher * PCI interface 2846874aeea5SJeff Kirsher * 2847874aeea5SJeff Kirsher **************************************************************************/ 2848874aeea5SJeff Kirsher 2849874aeea5SJeff Kirsher /* Main body of final NIC shutdown code 2850874aeea5SJeff Kirsher * This is called only at module unload (or hotplug removal). 2851874aeea5SJeff Kirsher */ 2852874aeea5SJeff Kirsher static void efx_pci_remove_main(struct efx_nic *efx) 2853874aeea5SJeff Kirsher { 28547153f623SBen Hutchings /* Flush reset_work. It can no longer be scheduled since we 28557153f623SBen Hutchings * are not READY. 28567153f623SBen Hutchings */ 28577153f623SBen Hutchings BUG_ON(efx->state == STATE_READY); 28587153f623SBen Hutchings cancel_work_sync(&efx->reset_work); 28597153f623SBen Hutchings 2860d8291187SBen Hutchings efx_disable_interrupts(efx); 2861874aeea5SJeff Kirsher efx_nic_fini_interrupt(efx); 2862874aeea5SJeff Kirsher efx_fini_port(efx); 2863874aeea5SJeff Kirsher efx->type->fini(efx); 2864874aeea5SJeff Kirsher efx_fini_napi(efx); 2865874aeea5SJeff Kirsher efx_remove_all(efx); 2866874aeea5SJeff Kirsher } 2867874aeea5SJeff Kirsher 2868874aeea5SJeff Kirsher /* Final NIC shutdown 2869874aeea5SJeff Kirsher * This is called only at module unload (or hotplug removal). 2870874aeea5SJeff Kirsher */ 2871874aeea5SJeff Kirsher static void efx_pci_remove(struct pci_dev *pci_dev) 2872874aeea5SJeff Kirsher { 2873874aeea5SJeff Kirsher struct efx_nic *efx; 2874874aeea5SJeff Kirsher 2875874aeea5SJeff Kirsher efx = pci_get_drvdata(pci_dev); 2876874aeea5SJeff Kirsher if (!efx) 2877874aeea5SJeff Kirsher return; 2878874aeea5SJeff Kirsher 2879874aeea5SJeff Kirsher /* Mark the NIC as fini, then stop the interface */ 2880874aeea5SJeff Kirsher rtnl_lock(); 28810bcf4a64SBen Hutchings efx_dissociate(efx); 2882874aeea5SJeff Kirsher dev_close(efx->net_dev); 2883d8291187SBen Hutchings efx_disable_interrupts(efx); 2884874aeea5SJeff Kirsher rtnl_unlock(); 2885874aeea5SJeff Kirsher 28867fa8d547SShradha Shah if (efx->type->sriov_fini) 2887d98a4ffeSShradha Shah efx->type->sriov_fini(efx); 28887fa8d547SShradha Shah 2889874aeea5SJeff Kirsher efx_unregister_netdev(efx); 2890874aeea5SJeff Kirsher 2891874aeea5SJeff Kirsher efx_mtd_remove(efx); 2892874aeea5SJeff Kirsher 2893874aeea5SJeff Kirsher efx_pci_remove_main(efx); 2894874aeea5SJeff Kirsher 2895874aeea5SJeff Kirsher efx_fini_io(efx); 2896874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); 2897874aeea5SJeff Kirsher 2898874aeea5SJeff Kirsher efx_fini_struct(efx); 2899874aeea5SJeff Kirsher free_netdev(efx->net_dev); 2900626950dbSAlexandre Rames 2901626950dbSAlexandre Rames pci_disable_pcie_error_reporting(pci_dev); 2902874aeea5SJeff Kirsher }; 2903874aeea5SJeff Kirsher 2904460eeaa0SBen Hutchings /* NIC VPD information 2905460eeaa0SBen Hutchings * Called during probe to display the part number of the 2906460eeaa0SBen Hutchings * installed NIC. VPD is potentially very large but this should 2907460eeaa0SBen Hutchings * always appear within the first 512 bytes. 2908460eeaa0SBen Hutchings */ 2909460eeaa0SBen Hutchings #define SFC_VPD_LEN 512 2910ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx) 2911460eeaa0SBen Hutchings { 2912460eeaa0SBen Hutchings struct pci_dev *dev = efx->pci_dev; 2913460eeaa0SBen Hutchings char vpd_data[SFC_VPD_LEN]; 2914460eeaa0SBen Hutchings ssize_t vpd_size; 2915ef215e64SBen Hutchings int ro_start, ro_size, i, j; 2916460eeaa0SBen Hutchings 2917460eeaa0SBen Hutchings /* Get the vpd data from the device */ 2918460eeaa0SBen Hutchings vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data); 2919460eeaa0SBen Hutchings if (vpd_size <= 0) { 2920460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n"); 2921460eeaa0SBen Hutchings return; 2922460eeaa0SBen Hutchings } 2923460eeaa0SBen Hutchings 2924460eeaa0SBen Hutchings /* Get the Read only section */ 2925ef215e64SBen Hutchings ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA); 2926ef215e64SBen Hutchings if (ro_start < 0) { 2927460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n"); 2928460eeaa0SBen Hutchings return; 2929460eeaa0SBen Hutchings } 2930460eeaa0SBen Hutchings 2931ef215e64SBen Hutchings ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]); 2932ef215e64SBen Hutchings j = ro_size; 2933ef215e64SBen Hutchings i = ro_start + PCI_VPD_LRDT_TAG_SIZE; 2934460eeaa0SBen Hutchings if (i + j > vpd_size) 2935460eeaa0SBen Hutchings j = vpd_size - i; 2936460eeaa0SBen Hutchings 2937460eeaa0SBen Hutchings /* Get the Part number */ 2938460eeaa0SBen Hutchings i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN"); 2939460eeaa0SBen Hutchings if (i < 0) { 2940460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Part number not found\n"); 2941460eeaa0SBen Hutchings return; 2942460eeaa0SBen Hutchings } 2943460eeaa0SBen Hutchings 2944460eeaa0SBen Hutchings j = pci_vpd_info_field_size(&vpd_data[i]); 2945460eeaa0SBen Hutchings i += PCI_VPD_INFO_FLD_HDR_SIZE; 2946460eeaa0SBen Hutchings if (i + j > vpd_size) { 2947460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Incomplete part number\n"); 2948460eeaa0SBen Hutchings return; 2949460eeaa0SBen Hutchings } 2950460eeaa0SBen Hutchings 2951460eeaa0SBen Hutchings netif_info(efx, drv, efx->net_dev, 2952460eeaa0SBen Hutchings "Part Number : %.*s\n", j, &vpd_data[i]); 2953ef215e64SBen Hutchings 2954ef215e64SBen Hutchings i = ro_start + PCI_VPD_LRDT_TAG_SIZE; 2955ef215e64SBen Hutchings j = ro_size; 2956ef215e64SBen Hutchings i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN"); 2957ef215e64SBen Hutchings if (i < 0) { 2958ef215e64SBen Hutchings netif_err(efx, drv, efx->net_dev, "Serial number not found\n"); 2959ef215e64SBen Hutchings return; 2960ef215e64SBen Hutchings } 2961ef215e64SBen Hutchings 2962ef215e64SBen Hutchings j = pci_vpd_info_field_size(&vpd_data[i]); 2963ef215e64SBen Hutchings i += PCI_VPD_INFO_FLD_HDR_SIZE; 2964ef215e64SBen Hutchings if (i + j > vpd_size) { 2965ef215e64SBen Hutchings netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n"); 2966ef215e64SBen Hutchings return; 2967ef215e64SBen Hutchings } 2968ef215e64SBen Hutchings 2969ef215e64SBen Hutchings efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL); 2970ef215e64SBen Hutchings if (!efx->vpd_sn) 2971ef215e64SBen Hutchings return; 2972ef215e64SBen Hutchings 2973ef215e64SBen Hutchings snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]); 2974460eeaa0SBen Hutchings } 2975460eeaa0SBen Hutchings 2976460eeaa0SBen Hutchings 2977874aeea5SJeff Kirsher /* Main body of NIC initialisation 2978874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, theoretically). 2979874aeea5SJeff Kirsher */ 2980874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx) 2981874aeea5SJeff Kirsher { 2982874aeea5SJeff Kirsher int rc; 2983874aeea5SJeff Kirsher 2984874aeea5SJeff Kirsher /* Do start-of-day initialisation */ 2985874aeea5SJeff Kirsher rc = efx_probe_all(efx); 2986874aeea5SJeff Kirsher if (rc) 2987874aeea5SJeff Kirsher goto fail1; 2988874aeea5SJeff Kirsher 2989874aeea5SJeff Kirsher efx_init_napi(efx); 2990874aeea5SJeff Kirsher 2991874aeea5SJeff Kirsher rc = efx->type->init(efx); 2992874aeea5SJeff Kirsher if (rc) { 2993874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 2994874aeea5SJeff Kirsher "failed to initialise NIC\n"); 2995874aeea5SJeff Kirsher goto fail3; 2996874aeea5SJeff Kirsher } 2997874aeea5SJeff Kirsher 2998874aeea5SJeff Kirsher rc = efx_init_port(efx); 2999874aeea5SJeff Kirsher if (rc) { 3000874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 3001874aeea5SJeff Kirsher "failed to initialise port\n"); 3002874aeea5SJeff Kirsher goto fail4; 3003874aeea5SJeff Kirsher } 3004874aeea5SJeff Kirsher 3005874aeea5SJeff Kirsher rc = efx_nic_init_interrupt(efx); 3006874aeea5SJeff Kirsher if (rc) 3007874aeea5SJeff Kirsher goto fail5; 3008261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 3009261e4d96SJon Cooper if (rc) 3010261e4d96SJon Cooper goto fail6; 3011874aeea5SJeff Kirsher 3012874aeea5SJeff Kirsher return 0; 3013874aeea5SJeff Kirsher 3014261e4d96SJon Cooper fail6: 3015261e4d96SJon Cooper efx_nic_fini_interrupt(efx); 3016874aeea5SJeff Kirsher fail5: 3017874aeea5SJeff Kirsher efx_fini_port(efx); 3018874aeea5SJeff Kirsher fail4: 3019874aeea5SJeff Kirsher efx->type->fini(efx); 3020874aeea5SJeff Kirsher fail3: 3021874aeea5SJeff Kirsher efx_fini_napi(efx); 3022874aeea5SJeff Kirsher efx_remove_all(efx); 3023874aeea5SJeff Kirsher fail1: 3024874aeea5SJeff Kirsher return rc; 3025874aeea5SJeff Kirsher } 3026874aeea5SJeff Kirsher 3027874aeea5SJeff Kirsher /* NIC initialisation 3028874aeea5SJeff Kirsher * 3029874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, 303073ba7b68SBen Hutchings * theoretically). It sets up PCI mappings, resets the NIC, 3031874aeea5SJeff Kirsher * sets up and registers the network devices with the kernel and hooks 3032874aeea5SJeff Kirsher * the interrupt service routine. It does not prepare the device for 3033874aeea5SJeff Kirsher * transmission; this is left to the first time one of the network 3034874aeea5SJeff Kirsher * interfaces is brought up (i.e. efx_net_open). 3035874aeea5SJeff Kirsher */ 303687d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev, 3037874aeea5SJeff Kirsher const struct pci_device_id *entry) 3038874aeea5SJeff Kirsher { 3039874aeea5SJeff Kirsher struct net_device *net_dev; 3040874aeea5SJeff Kirsher struct efx_nic *efx; 3041fadac6aaSBen Hutchings int rc; 3042874aeea5SJeff Kirsher 3043874aeea5SJeff Kirsher /* Allocate and initialise a struct net_device and struct efx_nic */ 3044874aeea5SJeff Kirsher net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES, 3045874aeea5SJeff Kirsher EFX_MAX_RX_QUEUES); 3046874aeea5SJeff Kirsher if (!net_dev) 3047874aeea5SJeff Kirsher return -ENOMEM; 3048adeb15aaSBen Hutchings efx = netdev_priv(net_dev); 3049adeb15aaSBen Hutchings efx->type = (const struct efx_nic_type *) entry->driver_data; 3050adeb15aaSBen Hutchings net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 3051874aeea5SJeff Kirsher NETIF_F_HIGHDMA | NETIF_F_TSO | 3052874aeea5SJeff Kirsher NETIF_F_RXCSUM); 3053adeb15aaSBen Hutchings if (efx->type->offload_features & NETIF_F_V6_CSUM) 3054874aeea5SJeff Kirsher net_dev->features |= NETIF_F_TSO6; 3055874aeea5SJeff Kirsher /* Mask for features that also apply to VLAN devices */ 3056874aeea5SJeff Kirsher net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG | 3057874aeea5SJeff Kirsher NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 3058874aeea5SJeff Kirsher NETIF_F_RXCSUM); 3059874aeea5SJeff Kirsher /* All offloads can be toggled */ 3060874aeea5SJeff Kirsher net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA; 3061874aeea5SJeff Kirsher pci_set_drvdata(pci_dev, efx); 3062874aeea5SJeff Kirsher SET_NETDEV_DEV(net_dev, &pci_dev->dev); 3063adeb15aaSBen Hutchings rc = efx_init_struct(efx, pci_dev, net_dev); 3064874aeea5SJeff Kirsher if (rc) 3065874aeea5SJeff Kirsher goto fail1; 3066874aeea5SJeff Kirsher 3067874aeea5SJeff Kirsher netif_info(efx, probe, efx->net_dev, 3068874aeea5SJeff Kirsher "Solarflare NIC detected\n"); 3069874aeea5SJeff Kirsher 30706f7f8aa6SShradha Shah if (!efx->type->is_vf) 3071ef215e64SBen Hutchings efx_probe_vpd_strings(efx); 3072460eeaa0SBen Hutchings 3073874aeea5SJeff Kirsher /* Set up basic I/O (BAR mappings etc) */ 3074874aeea5SJeff Kirsher rc = efx_init_io(efx); 3075874aeea5SJeff Kirsher if (rc) 3076874aeea5SJeff Kirsher goto fail2; 3077874aeea5SJeff Kirsher 3078874aeea5SJeff Kirsher rc = efx_pci_probe_main(efx); 3079fadac6aaSBen Hutchings if (rc) 3080874aeea5SJeff Kirsher goto fail3; 3081874aeea5SJeff Kirsher 3082874aeea5SJeff Kirsher rc = efx_register_netdev(efx); 3083874aeea5SJeff Kirsher if (rc) 3084fadac6aaSBen Hutchings goto fail4; 3085874aeea5SJeff Kirsher 30867fa8d547SShradha Shah if (efx->type->sriov_init) { 3087d98a4ffeSShradha Shah rc = efx->type->sriov_init(efx); 3088cd2d5b52SBen Hutchings if (rc) 3089cd2d5b52SBen Hutchings netif_err(efx, probe, efx->net_dev, 3090cd2d5b52SBen Hutchings "SR-IOV can't be enabled rc %d\n", rc); 30917fa8d547SShradha Shah } 3092cd2d5b52SBen Hutchings 3093874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); 3094874aeea5SJeff Kirsher 30957c43161cSBen Hutchings /* Try to create MTDs, but allow this to fail */ 3096874aeea5SJeff Kirsher rtnl_lock(); 30977c43161cSBen Hutchings rc = efx_mtd_probe(efx); 3098874aeea5SJeff Kirsher rtnl_unlock(); 30997c43161cSBen Hutchings if (rc) 31007c43161cSBen Hutchings netif_warn(efx, probe, efx->net_dev, 31017c43161cSBen Hutchings "failed to create MTDs (%d)\n", rc); 31027c43161cSBen Hutchings 3103626950dbSAlexandre Rames rc = pci_enable_pcie_error_reporting(pci_dev); 3104626950dbSAlexandre Rames if (rc && rc != -EINVAL) 3105626950dbSAlexandre Rames netif_warn(efx, probe, efx->net_dev, 3106626950dbSAlexandre Rames "pci_enable_pcie_error_reporting failed (%d)\n", rc); 3107626950dbSAlexandre Rames 3108874aeea5SJeff Kirsher return 0; 3109874aeea5SJeff Kirsher 3110874aeea5SJeff Kirsher fail4: 3111fadac6aaSBen Hutchings efx_pci_remove_main(efx); 3112874aeea5SJeff Kirsher fail3: 3113874aeea5SJeff Kirsher efx_fini_io(efx); 3114874aeea5SJeff Kirsher fail2: 3115874aeea5SJeff Kirsher efx_fini_struct(efx); 3116874aeea5SJeff Kirsher fail1: 3117874aeea5SJeff Kirsher WARN_ON(rc > 0); 3118874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); 3119874aeea5SJeff Kirsher free_netdev(net_dev); 3120874aeea5SJeff Kirsher return rc; 3121874aeea5SJeff Kirsher } 3122874aeea5SJeff Kirsher 3123834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions 3124834e23ddSShradha Shah * enabled on success 3125834e23ddSShradha Shah */ 3126834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 3127834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) 3128834e23ddSShradha Shah { 3129834e23ddSShradha Shah int rc; 3130834e23ddSShradha Shah struct efx_nic *efx = pci_get_drvdata(dev); 3131834e23ddSShradha Shah 3132834e23ddSShradha Shah if (efx->type->sriov_configure) { 3133834e23ddSShradha Shah rc = efx->type->sriov_configure(efx, num_vfs); 3134834e23ddSShradha Shah if (rc) 3135834e23ddSShradha Shah return rc; 3136834e23ddSShradha Shah else 3137834e23ddSShradha Shah return num_vfs; 3138834e23ddSShradha Shah } else 3139834e23ddSShradha Shah return -EOPNOTSUPP; 3140834e23ddSShradha Shah } 3141834e23ddSShradha Shah #endif 3142834e23ddSShradha Shah 3143874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev) 3144874aeea5SJeff Kirsher { 3145874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 3146874aeea5SJeff Kirsher 314761da026dSBen Hutchings rtnl_lock(); 314861da026dSBen Hutchings 31496032fb56SBen Hutchings if (efx->state != STATE_DISABLED) { 3150f16aeea0SBen Hutchings efx->state = STATE_UNINIT; 3151874aeea5SJeff Kirsher 3152c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 3153874aeea5SJeff Kirsher 3154874aeea5SJeff Kirsher efx_stop_all(efx); 3155d8291187SBen Hutchings efx_disable_interrupts(efx); 31566032fb56SBen Hutchings } 3157874aeea5SJeff Kirsher 315861da026dSBen Hutchings rtnl_unlock(); 315961da026dSBen Hutchings 3160874aeea5SJeff Kirsher return 0; 3161874aeea5SJeff Kirsher } 3162874aeea5SJeff Kirsher 3163874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev) 3164874aeea5SJeff Kirsher { 3165261e4d96SJon Cooper int rc; 3166874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 3167874aeea5SJeff Kirsher 316861da026dSBen Hutchings rtnl_lock(); 316961da026dSBen Hutchings 31706032fb56SBen Hutchings if (efx->state != STATE_DISABLED) { 3171261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 3172261e4d96SJon Cooper if (rc) 3173261e4d96SJon Cooper goto fail; 3174874aeea5SJeff Kirsher 3175874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 3176874aeea5SJeff Kirsher efx->phy_op->reconfigure(efx); 3177874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 3178874aeea5SJeff Kirsher 3179874aeea5SJeff Kirsher efx_start_all(efx); 3180874aeea5SJeff Kirsher 3181874aeea5SJeff Kirsher netif_device_attach(efx->net_dev); 3182874aeea5SJeff Kirsher 3183f16aeea0SBen Hutchings efx->state = STATE_READY; 3184874aeea5SJeff Kirsher 3185874aeea5SJeff Kirsher efx->type->resume_wol(efx); 31866032fb56SBen Hutchings } 3187874aeea5SJeff Kirsher 318861da026dSBen Hutchings rtnl_unlock(); 318961da026dSBen Hutchings 3190874aeea5SJeff Kirsher /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ 3191874aeea5SJeff Kirsher queue_work(reset_workqueue, &efx->reset_work); 3192874aeea5SJeff Kirsher 3193874aeea5SJeff Kirsher return 0; 3194261e4d96SJon Cooper 3195261e4d96SJon Cooper fail: 3196261e4d96SJon Cooper rtnl_unlock(); 3197261e4d96SJon Cooper 3198261e4d96SJon Cooper return rc; 3199874aeea5SJeff Kirsher } 3200874aeea5SJeff Kirsher 3201874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev) 3202874aeea5SJeff Kirsher { 3203874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 3204874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 3205874aeea5SJeff Kirsher 3206874aeea5SJeff Kirsher efx->type->fini(efx); 3207874aeea5SJeff Kirsher 3208874aeea5SJeff Kirsher efx->reset_pending = 0; 3209874aeea5SJeff Kirsher 3210874aeea5SJeff Kirsher pci_save_state(pci_dev); 3211874aeea5SJeff Kirsher return pci_set_power_state(pci_dev, PCI_D3hot); 3212874aeea5SJeff Kirsher } 3213874aeea5SJeff Kirsher 3214874aeea5SJeff Kirsher /* Used for both resume and restore */ 3215874aeea5SJeff Kirsher static int efx_pm_resume(struct device *dev) 3216874aeea5SJeff Kirsher { 3217874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 3218874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 3219874aeea5SJeff Kirsher int rc; 3220874aeea5SJeff Kirsher 3221874aeea5SJeff Kirsher rc = pci_set_power_state(pci_dev, PCI_D0); 3222874aeea5SJeff Kirsher if (rc) 3223874aeea5SJeff Kirsher return rc; 3224874aeea5SJeff Kirsher pci_restore_state(pci_dev); 3225874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 3226874aeea5SJeff Kirsher if (rc) 3227874aeea5SJeff Kirsher return rc; 3228874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 3229874aeea5SJeff Kirsher rc = efx->type->reset(efx, RESET_TYPE_ALL); 3230874aeea5SJeff Kirsher if (rc) 3231874aeea5SJeff Kirsher return rc; 3232874aeea5SJeff Kirsher rc = efx->type->init(efx); 3233874aeea5SJeff Kirsher if (rc) 3234874aeea5SJeff Kirsher return rc; 3235261e4d96SJon Cooper rc = efx_pm_thaw(dev); 3236261e4d96SJon Cooper return rc; 3237874aeea5SJeff Kirsher } 3238874aeea5SJeff Kirsher 3239874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev) 3240874aeea5SJeff Kirsher { 3241874aeea5SJeff Kirsher int rc; 3242874aeea5SJeff Kirsher 3243874aeea5SJeff Kirsher efx_pm_freeze(dev); 3244874aeea5SJeff Kirsher rc = efx_pm_poweroff(dev); 3245874aeea5SJeff Kirsher if (rc) 3246874aeea5SJeff Kirsher efx_pm_resume(dev); 3247874aeea5SJeff Kirsher return rc; 3248874aeea5SJeff Kirsher } 3249874aeea5SJeff Kirsher 325018e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = { 3251874aeea5SJeff Kirsher .suspend = efx_pm_suspend, 3252874aeea5SJeff Kirsher .resume = efx_pm_resume, 3253874aeea5SJeff Kirsher .freeze = efx_pm_freeze, 3254874aeea5SJeff Kirsher .thaw = efx_pm_thaw, 3255874aeea5SJeff Kirsher .poweroff = efx_pm_poweroff, 3256874aeea5SJeff Kirsher .restore = efx_pm_resume, 3257874aeea5SJeff Kirsher }; 3258874aeea5SJeff Kirsher 3259626950dbSAlexandre Rames /* A PCI error affecting this device was detected. 3260626950dbSAlexandre Rames * At this point MMIO and DMA may be disabled. 3261626950dbSAlexandre Rames * Stop the software path and request a slot reset. 3262626950dbSAlexandre Rames */ 3263debd0034Sstephen hemminger static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev, 3264626950dbSAlexandre Rames enum pci_channel_state state) 3265626950dbSAlexandre Rames { 3266626950dbSAlexandre Rames pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 3267626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3268626950dbSAlexandre Rames 3269626950dbSAlexandre Rames if (state == pci_channel_io_perm_failure) 3270626950dbSAlexandre Rames return PCI_ERS_RESULT_DISCONNECT; 3271626950dbSAlexandre Rames 3272626950dbSAlexandre Rames rtnl_lock(); 3273626950dbSAlexandre Rames 3274626950dbSAlexandre Rames if (efx->state != STATE_DISABLED) { 3275626950dbSAlexandre Rames efx->state = STATE_RECOVERY; 3276626950dbSAlexandre Rames efx->reset_pending = 0; 3277626950dbSAlexandre Rames 3278626950dbSAlexandre Rames efx_device_detach_sync(efx); 3279626950dbSAlexandre Rames 3280626950dbSAlexandre Rames efx_stop_all(efx); 3281d8291187SBen Hutchings efx_disable_interrupts(efx); 3282626950dbSAlexandre Rames 3283626950dbSAlexandre Rames status = PCI_ERS_RESULT_NEED_RESET; 3284626950dbSAlexandre Rames } else { 3285626950dbSAlexandre Rames /* If the interface is disabled we don't want to do anything 3286626950dbSAlexandre Rames * with it. 3287626950dbSAlexandre Rames */ 3288626950dbSAlexandre Rames status = PCI_ERS_RESULT_RECOVERED; 3289626950dbSAlexandre Rames } 3290626950dbSAlexandre Rames 3291626950dbSAlexandre Rames rtnl_unlock(); 3292626950dbSAlexandre Rames 3293626950dbSAlexandre Rames pci_disable_device(pdev); 3294626950dbSAlexandre Rames 3295626950dbSAlexandre Rames return status; 3296626950dbSAlexandre Rames } 3297626950dbSAlexandre Rames 3298dbedd44eSJoe Perches /* Fake a successful reset, which will be performed later in efx_io_resume. */ 3299debd0034Sstephen hemminger static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev) 3300626950dbSAlexandre Rames { 3301626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3302626950dbSAlexandre Rames pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 3303626950dbSAlexandre Rames int rc; 3304626950dbSAlexandre Rames 3305626950dbSAlexandre Rames if (pci_enable_device(pdev)) { 3306626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3307626950dbSAlexandre Rames "Cannot re-enable PCI device after reset.\n"); 3308626950dbSAlexandre Rames status = PCI_ERS_RESULT_DISCONNECT; 3309626950dbSAlexandre Rames } 3310626950dbSAlexandre Rames 3311626950dbSAlexandre Rames rc = pci_cleanup_aer_uncorrect_error_status(pdev); 3312626950dbSAlexandre Rames if (rc) { 3313626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3314626950dbSAlexandre Rames "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc); 3315626950dbSAlexandre Rames /* Non-fatal error. Continue. */ 3316626950dbSAlexandre Rames } 3317626950dbSAlexandre Rames 3318626950dbSAlexandre Rames return status; 3319626950dbSAlexandre Rames } 3320626950dbSAlexandre Rames 3321626950dbSAlexandre Rames /* Perform the actual reset and resume I/O operations. */ 3322626950dbSAlexandre Rames static void efx_io_resume(struct pci_dev *pdev) 3323626950dbSAlexandre Rames { 3324626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3325626950dbSAlexandre Rames int rc; 3326626950dbSAlexandre Rames 3327626950dbSAlexandre Rames rtnl_lock(); 3328626950dbSAlexandre Rames 3329626950dbSAlexandre Rames if (efx->state == STATE_DISABLED) 3330626950dbSAlexandre Rames goto out; 3331626950dbSAlexandre Rames 3332626950dbSAlexandre Rames rc = efx_reset(efx, RESET_TYPE_ALL); 3333626950dbSAlexandre Rames if (rc) { 3334626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3335626950dbSAlexandre Rames "efx_reset failed after PCI error (%d)\n", rc); 3336626950dbSAlexandre Rames } else { 3337626950dbSAlexandre Rames efx->state = STATE_READY; 3338626950dbSAlexandre Rames netif_dbg(efx, hw, efx->net_dev, 3339626950dbSAlexandre Rames "Done resetting and resuming IO after PCI error.\n"); 3340626950dbSAlexandre Rames } 3341626950dbSAlexandre Rames 3342626950dbSAlexandre Rames out: 3343626950dbSAlexandre Rames rtnl_unlock(); 3344626950dbSAlexandre Rames } 3345626950dbSAlexandre Rames 3346626950dbSAlexandre Rames /* For simplicity and reliability, we always require a slot reset and try to 3347626950dbSAlexandre Rames * reset the hardware when a pci error affecting the device is detected. 3348626950dbSAlexandre Rames * We leave both the link_reset and mmio_enabled callback unimplemented: 3349626950dbSAlexandre Rames * with our request for slot reset the mmio_enabled callback will never be 3350626950dbSAlexandre Rames * called, and the link_reset callback is not used by AER or EEH mechanisms. 3351626950dbSAlexandre Rames */ 3352626950dbSAlexandre Rames static struct pci_error_handlers efx_err_handlers = { 3353626950dbSAlexandre Rames .error_detected = efx_io_error_detected, 3354626950dbSAlexandre Rames .slot_reset = efx_io_slot_reset, 3355626950dbSAlexandre Rames .resume = efx_io_resume, 3356626950dbSAlexandre Rames }; 3357626950dbSAlexandre Rames 3358874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = { 3359874aeea5SJeff Kirsher .name = KBUILD_MODNAME, 3360874aeea5SJeff Kirsher .id_table = efx_pci_table, 3361874aeea5SJeff Kirsher .probe = efx_pci_probe, 3362874aeea5SJeff Kirsher .remove = efx_pci_remove, 3363874aeea5SJeff Kirsher .driver.pm = &efx_pm_ops, 3364626950dbSAlexandre Rames .err_handler = &efx_err_handlers, 3365834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 3366834e23ddSShradha Shah .sriov_configure = efx_pci_sriov_configure, 3367834e23ddSShradha Shah #endif 3368874aeea5SJeff Kirsher }; 3369874aeea5SJeff Kirsher 3370874aeea5SJeff Kirsher /************************************************************************** 3371874aeea5SJeff Kirsher * 3372874aeea5SJeff Kirsher * Kernel module interface 3373874aeea5SJeff Kirsher * 3374874aeea5SJeff Kirsher *************************************************************************/ 3375874aeea5SJeff Kirsher 3376874aeea5SJeff Kirsher module_param(interrupt_mode, uint, 0444); 3377874aeea5SJeff Kirsher MODULE_PARM_DESC(interrupt_mode, 3378874aeea5SJeff Kirsher "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); 3379874aeea5SJeff Kirsher 3380874aeea5SJeff Kirsher static int __init efx_init_module(void) 3381874aeea5SJeff Kirsher { 3382874aeea5SJeff Kirsher int rc; 3383874aeea5SJeff Kirsher 3384874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n"); 3385874aeea5SJeff Kirsher 3386874aeea5SJeff Kirsher rc = register_netdevice_notifier(&efx_netdev_notifier); 3387874aeea5SJeff Kirsher if (rc) 3388874aeea5SJeff Kirsher goto err_notifier; 3389874aeea5SJeff Kirsher 33907fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3391cd2d5b52SBen Hutchings rc = efx_init_sriov(); 3392cd2d5b52SBen Hutchings if (rc) 3393cd2d5b52SBen Hutchings goto err_sriov; 33947fa8d547SShradha Shah #endif 3395cd2d5b52SBen Hutchings 3396874aeea5SJeff Kirsher reset_workqueue = create_singlethread_workqueue("sfc_reset"); 3397874aeea5SJeff Kirsher if (!reset_workqueue) { 3398874aeea5SJeff Kirsher rc = -ENOMEM; 3399874aeea5SJeff Kirsher goto err_reset; 3400874aeea5SJeff Kirsher } 3401874aeea5SJeff Kirsher 3402874aeea5SJeff Kirsher rc = pci_register_driver(&efx_pci_driver); 3403874aeea5SJeff Kirsher if (rc < 0) 3404874aeea5SJeff Kirsher goto err_pci; 3405874aeea5SJeff Kirsher 3406874aeea5SJeff Kirsher return 0; 3407874aeea5SJeff Kirsher 3408874aeea5SJeff Kirsher err_pci: 3409874aeea5SJeff Kirsher destroy_workqueue(reset_workqueue); 3410874aeea5SJeff Kirsher err_reset: 34117fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3412cd2d5b52SBen Hutchings efx_fini_sriov(); 3413cd2d5b52SBen Hutchings err_sriov: 34147fa8d547SShradha Shah #endif 3415874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 3416874aeea5SJeff Kirsher err_notifier: 3417874aeea5SJeff Kirsher return rc; 3418874aeea5SJeff Kirsher } 3419874aeea5SJeff Kirsher 3420874aeea5SJeff Kirsher static void __exit efx_exit_module(void) 3421874aeea5SJeff Kirsher { 3422874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver unloading\n"); 3423874aeea5SJeff Kirsher 3424874aeea5SJeff Kirsher pci_unregister_driver(&efx_pci_driver); 3425874aeea5SJeff Kirsher destroy_workqueue(reset_workqueue); 34267fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3427cd2d5b52SBen Hutchings efx_fini_sriov(); 34287fa8d547SShradha Shah #endif 3429874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 3430874aeea5SJeff Kirsher 3431874aeea5SJeff Kirsher } 3432874aeea5SJeff Kirsher 3433874aeea5SJeff Kirsher module_init(efx_init_module); 3434874aeea5SJeff Kirsher module_exit(efx_exit_module); 3435874aeea5SJeff Kirsher 3436874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and " 3437874aeea5SJeff Kirsher "Michael Brown <mbrown@fensystems.co.uk>"); 34386a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver"); 3439874aeea5SJeff Kirsher MODULE_LICENSE("GPL"); 3440874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table); 3441