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" 26e5fbd977SJon Cooper #include <net/gre.h> 27e5fbd977SJon Cooper #include <net/udp_tunnel.h> 28874aeea5SJeff Kirsher #include "efx.h" 29874aeea5SJeff Kirsher #include "nic.h" 30dd40781eSBen Hutchings #include "selftest.h" 317fa8d547SShradha Shah #include "sriov.h" 32874aeea5SJeff Kirsher 33874aeea5SJeff Kirsher #include "mcdi.h" 34e5fbd977SJon Cooper #include "mcdi_pcol.h" 35874aeea5SJeff Kirsher #include "workarounds.h" 36874aeea5SJeff Kirsher 37874aeea5SJeff Kirsher /************************************************************************** 38874aeea5SJeff Kirsher * 39874aeea5SJeff Kirsher * Type name strings 40874aeea5SJeff Kirsher * 41874aeea5SJeff Kirsher ************************************************************************** 42874aeea5SJeff Kirsher */ 43874aeea5SJeff Kirsher 44874aeea5SJeff Kirsher /* Loopback mode names (see LOOPBACK_MODE()) */ 45874aeea5SJeff Kirsher const unsigned int efx_loopback_mode_max = LOOPBACK_MAX; 4618e83e4cSBen Hutchings const char *const efx_loopback_mode_names[] = { 47874aeea5SJeff Kirsher [LOOPBACK_NONE] = "NONE", 48874aeea5SJeff Kirsher [LOOPBACK_DATA] = "DATAPATH", 49874aeea5SJeff Kirsher [LOOPBACK_GMAC] = "GMAC", 50874aeea5SJeff Kirsher [LOOPBACK_XGMII] = "XGMII", 51874aeea5SJeff Kirsher [LOOPBACK_XGXS] = "XGXS", 52874aeea5SJeff Kirsher [LOOPBACK_XAUI] = "XAUI", 53874aeea5SJeff Kirsher [LOOPBACK_GMII] = "GMII", 54874aeea5SJeff Kirsher [LOOPBACK_SGMII] = "SGMII", 55874aeea5SJeff Kirsher [LOOPBACK_XGBR] = "XGBR", 56874aeea5SJeff Kirsher [LOOPBACK_XFI] = "XFI", 57874aeea5SJeff Kirsher [LOOPBACK_XAUI_FAR] = "XAUI_FAR", 58874aeea5SJeff Kirsher [LOOPBACK_GMII_FAR] = "GMII_FAR", 59874aeea5SJeff Kirsher [LOOPBACK_SGMII_FAR] = "SGMII_FAR", 60874aeea5SJeff Kirsher [LOOPBACK_XFI_FAR] = "XFI_FAR", 61874aeea5SJeff Kirsher [LOOPBACK_GPHY] = "GPHY", 62874aeea5SJeff Kirsher [LOOPBACK_PHYXS] = "PHYXS", 63874aeea5SJeff Kirsher [LOOPBACK_PCS] = "PCS", 64874aeea5SJeff Kirsher [LOOPBACK_PMAPMD] = "PMA/PMD", 65874aeea5SJeff Kirsher [LOOPBACK_XPORT] = "XPORT", 66874aeea5SJeff Kirsher [LOOPBACK_XGMII_WS] = "XGMII_WS", 67874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS] = "XAUI_WS", 68874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR", 69874aeea5SJeff Kirsher [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR", 70874aeea5SJeff Kirsher [LOOPBACK_GMII_WS] = "GMII_WS", 71874aeea5SJeff Kirsher [LOOPBACK_XFI_WS] = "XFI_WS", 72874aeea5SJeff Kirsher [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR", 73874aeea5SJeff Kirsher [LOOPBACK_PHYXS_WS] = "PHYXS_WS", 74874aeea5SJeff Kirsher }; 75874aeea5SJeff Kirsher 76874aeea5SJeff Kirsher const unsigned int efx_reset_type_max = RESET_TYPE_MAX; 7718e83e4cSBen Hutchings const char *const efx_reset_type_names[] = { 78874aeea5SJeff Kirsher [RESET_TYPE_INVISIBLE] = "INVISIBLE", 79874aeea5SJeff Kirsher [RESET_TYPE_ALL] = "ALL", 80626950dbSAlexandre Rames [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL", 81874aeea5SJeff Kirsher [RESET_TYPE_WORLD] = "WORLD", 82626950dbSAlexandre Rames [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE", 83087e9025SJon Cooper [RESET_TYPE_DATAPATH] = "DATAPATH", 84e283546cSEdward Cree [RESET_TYPE_MC_BIST] = "MC_BIST", 85874aeea5SJeff Kirsher [RESET_TYPE_DISABLE] = "DISABLE", 86874aeea5SJeff Kirsher [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG", 87874aeea5SJeff Kirsher [RESET_TYPE_INT_ERROR] = "INT_ERROR", 883de82b91SAlexandre Rames [RESET_TYPE_DMA_ERROR] = "DMA_ERROR", 89874aeea5SJeff Kirsher [RESET_TYPE_TX_SKIP] = "TX_SKIP", 90874aeea5SJeff Kirsher [RESET_TYPE_MC_FAILURE] = "MC_FAILURE", 91e283546cSEdward Cree [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)", 92874aeea5SJeff Kirsher }; 93874aeea5SJeff Kirsher 94e5fbd977SJon Cooper /* UDP tunnel type names */ 95e5fbd977SJon Cooper static const char *const efx_udp_tunnel_type_names[] = { 96e5fbd977SJon Cooper [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan", 97e5fbd977SJon Cooper [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve", 98e5fbd977SJon Cooper }; 99e5fbd977SJon Cooper 100e5fbd977SJon Cooper void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen) 101e5fbd977SJon Cooper { 102e5fbd977SJon Cooper if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) && 103e5fbd977SJon Cooper efx_udp_tunnel_type_names[type] != NULL) 104e5fbd977SJon Cooper snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]); 105e5fbd977SJon Cooper else 106e5fbd977SJon Cooper snprintf(buf, buflen, "type %d", type); 107e5fbd977SJon Cooper } 108e5fbd977SJon Cooper 109874aeea5SJeff Kirsher /* Reset workqueue. If any NIC has a hardware failure then a reset will be 110874aeea5SJeff Kirsher * queued onto this work queue. This is not a per-nic work queue, because 111874aeea5SJeff Kirsher * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised. 112874aeea5SJeff Kirsher */ 113874aeea5SJeff Kirsher static struct workqueue_struct *reset_workqueue; 114874aeea5SJeff Kirsher 11574cd60a4SJon Cooper /* How often and how many times to poll for a reset while waiting for a 11674cd60a4SJon Cooper * BIST that another function started to complete. 11774cd60a4SJon Cooper */ 11874cd60a4SJon Cooper #define BIST_WAIT_DELAY_MS 100 11974cd60a4SJon Cooper #define BIST_WAIT_DELAY_COUNT 100 12074cd60a4SJon Cooper 121874aeea5SJeff Kirsher /************************************************************************** 122874aeea5SJeff Kirsher * 123874aeea5SJeff Kirsher * Configurable values 124874aeea5SJeff Kirsher * 125874aeea5SJeff Kirsher *************************************************************************/ 126874aeea5SJeff Kirsher 127874aeea5SJeff Kirsher /* 128874aeea5SJeff Kirsher * Use separate channels for TX and RX events 129874aeea5SJeff Kirsher * 130874aeea5SJeff Kirsher * Set this to 1 to use separate channels for TX and RX. It allows us 131874aeea5SJeff Kirsher * to control interrupt affinity separately for TX and RX. 132874aeea5SJeff Kirsher * 133874aeea5SJeff Kirsher * This is only used in MSI-X interrupt mode 134874aeea5SJeff Kirsher */ 135b0fbdae1SShradha Shah bool efx_separate_tx_channels; 136b0fbdae1SShradha Shah module_param(efx_separate_tx_channels, bool, 0444); 137b0fbdae1SShradha Shah MODULE_PARM_DESC(efx_separate_tx_channels, 138874aeea5SJeff Kirsher "Use separate channels for TX and RX"); 139874aeea5SJeff Kirsher 140874aeea5SJeff Kirsher /* This is the weight assigned to each of the (per-channel) virtual 141874aeea5SJeff Kirsher * NAPI devices. 142874aeea5SJeff Kirsher */ 143874aeea5SJeff Kirsher static int napi_weight = 64; 144874aeea5SJeff Kirsher 145874aeea5SJeff Kirsher /* This is the time (in jiffies) between invocations of the hardware 146626950dbSAlexandre Rames * monitor. 147626950dbSAlexandre Rames * On Falcon-based NICs, this will: 148874aeea5SJeff Kirsher * - Check the on-board hardware monitor; 149874aeea5SJeff Kirsher * - Poll the link state and reconfigure the hardware as necessary. 150626950dbSAlexandre Rames * On Siena-based NICs for power systems with EEH support, this will give EEH a 151626950dbSAlexandre Rames * chance to start. 152874aeea5SJeff Kirsher */ 153874aeea5SJeff Kirsher static unsigned int efx_monitor_interval = 1 * HZ; 154874aeea5SJeff Kirsher 155874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 156874aeea5SJeff Kirsher * module load with ethtool. 157874aeea5SJeff Kirsher * 158874aeea5SJeff Kirsher * The default for RX should strike a balance between increasing the 159874aeea5SJeff Kirsher * round-trip latency and reducing overhead. 160874aeea5SJeff Kirsher */ 161874aeea5SJeff Kirsher static unsigned int rx_irq_mod_usec = 60; 162874aeea5SJeff Kirsher 163874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 164874aeea5SJeff Kirsher * module load with ethtool. 165874aeea5SJeff Kirsher * 166874aeea5SJeff Kirsher * This default is chosen to ensure that a 10G link does not go idle 167874aeea5SJeff Kirsher * while a TX queue is stopped after it has become full. A queue is 168874aeea5SJeff Kirsher * restarted when it drops below half full. The time this takes (assuming 169874aeea5SJeff Kirsher * worst case 3 descriptors per packet and 1024 descriptors) is 170874aeea5SJeff Kirsher * 512 / 3 * 1.2 = 205 usec. 171874aeea5SJeff Kirsher */ 172874aeea5SJeff Kirsher static unsigned int tx_irq_mod_usec = 150; 173874aeea5SJeff Kirsher 174874aeea5SJeff Kirsher /* This is the first interrupt mode to try out of: 175874aeea5SJeff Kirsher * 0 => MSI-X 176874aeea5SJeff Kirsher * 1 => MSI 177874aeea5SJeff Kirsher * 2 => legacy 178874aeea5SJeff Kirsher */ 179874aeea5SJeff Kirsher static unsigned int interrupt_mode; 180874aeea5SJeff Kirsher 181874aeea5SJeff Kirsher /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), 182874aeea5SJeff Kirsher * i.e. the number of CPUs among which we may distribute simultaneous 183874aeea5SJeff Kirsher * interrupt handling. 184874aeea5SJeff Kirsher * 185874aeea5SJeff Kirsher * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. 186cdb08f8fSBen Hutchings * The default (0) means to assign an interrupt to each core. 187874aeea5SJeff Kirsher */ 188874aeea5SJeff Kirsher static unsigned int rss_cpus; 189874aeea5SJeff Kirsher module_param(rss_cpus, uint, 0444); 190874aeea5SJeff Kirsher MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); 191874aeea5SJeff Kirsher 192b9cc977dSBen Hutchings static bool phy_flash_cfg; 193b9cc977dSBen Hutchings module_param(phy_flash_cfg, bool, 0644); 194874aeea5SJeff Kirsher MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); 195874aeea5SJeff Kirsher 196e7bed9c8SBen Hutchings static unsigned irq_adapt_low_thresh = 8000; 197874aeea5SJeff Kirsher module_param(irq_adapt_low_thresh, uint, 0644); 198874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_low_thresh, 199874aeea5SJeff Kirsher "Threshold score for reducing IRQ moderation"); 200874aeea5SJeff Kirsher 201e7bed9c8SBen Hutchings static unsigned irq_adapt_high_thresh = 16000; 202874aeea5SJeff Kirsher module_param(irq_adapt_high_thresh, uint, 0644); 203874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_high_thresh, 204874aeea5SJeff Kirsher "Threshold score for increasing IRQ moderation"); 205874aeea5SJeff Kirsher 206874aeea5SJeff Kirsher static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | 207874aeea5SJeff Kirsher NETIF_MSG_LINK | NETIF_MSG_IFDOWN | 208874aeea5SJeff Kirsher NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | 209874aeea5SJeff Kirsher NETIF_MSG_TX_ERR | NETIF_MSG_HW); 210874aeea5SJeff Kirsher module_param(debug, uint, 0); 211874aeea5SJeff Kirsher MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); 212874aeea5SJeff Kirsher 213874aeea5SJeff Kirsher /************************************************************************** 214874aeea5SJeff Kirsher * 215874aeea5SJeff Kirsher * Utility functions and prototypes 216874aeea5SJeff Kirsher * 217874aeea5SJeff Kirsher *************************************************************************/ 218874aeea5SJeff Kirsher 219261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx); 220d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx); 2217f967c01SBen Hutchings static void efx_remove_channel(struct efx_channel *channel); 222874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx); 2237f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type; 224874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx); 2257f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel); 226874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx); 227874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel); 228874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx); 229874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx); 230874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx); 231874aeea5SJeff Kirsher 232874aeea5SJeff Kirsher #define EFX_ASSERT_RESET_SERIALISED(efx) \ 233874aeea5SJeff Kirsher do { \ 234f16aeea0SBen Hutchings if ((efx->state == STATE_READY) || \ 235626950dbSAlexandre Rames (efx->state == STATE_RECOVERY) || \ 236874aeea5SJeff Kirsher (efx->state == STATE_DISABLED)) \ 237874aeea5SJeff Kirsher ASSERT_RTNL(); \ 238874aeea5SJeff Kirsher } while (0) 239874aeea5SJeff Kirsher 2408b7325b4SBen Hutchings static int efx_check_disabled(struct efx_nic *efx) 2418b7325b4SBen Hutchings { 242626950dbSAlexandre Rames if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) { 2438b7325b4SBen Hutchings netif_err(efx, drv, efx->net_dev, 2448b7325b4SBen Hutchings "device is disabled due to earlier errors\n"); 2458b7325b4SBen Hutchings return -EIO; 2468b7325b4SBen Hutchings } 2478b7325b4SBen Hutchings return 0; 2488b7325b4SBen Hutchings } 2498b7325b4SBen Hutchings 250874aeea5SJeff Kirsher /************************************************************************** 251874aeea5SJeff Kirsher * 252874aeea5SJeff Kirsher * Event queue processing 253874aeea5SJeff Kirsher * 254874aeea5SJeff Kirsher *************************************************************************/ 255874aeea5SJeff Kirsher 256874aeea5SJeff Kirsher /* Process channel's event queue 257874aeea5SJeff Kirsher * 258874aeea5SJeff Kirsher * This function is responsible for processing the event queue of a 259874aeea5SJeff Kirsher * single channel. The caller must guarantee that this function will 260874aeea5SJeff Kirsher * never be concurrently called more than once on the same channel, 261874aeea5SJeff Kirsher * though different channels may be being processed concurrently. 262874aeea5SJeff Kirsher */ 263874aeea5SJeff Kirsher static int efx_process_channel(struct efx_channel *channel, int budget) 264874aeea5SJeff Kirsher { 265c936835cSPeter Dunning struct efx_tx_queue *tx_queue; 266874aeea5SJeff Kirsher int spent; 267874aeea5SJeff Kirsher 2689f2cb71cSBen Hutchings if (unlikely(!channel->enabled)) 269874aeea5SJeff Kirsher return 0; 270874aeea5SJeff Kirsher 271c936835cSPeter Dunning efx_for_each_channel_tx_queue(tx_queue, channel) { 272c936835cSPeter Dunning tx_queue->pkts_compl = 0; 273c936835cSPeter Dunning tx_queue->bytes_compl = 0; 274c936835cSPeter Dunning } 275c936835cSPeter Dunning 276874aeea5SJeff Kirsher spent = efx_nic_process_eventq(channel, budget); 277d9ab7007SBen Hutchings if (spent && efx_channel_has_rx_queue(channel)) { 278d9ab7007SBen Hutchings struct efx_rx_queue *rx_queue = 279d9ab7007SBen Hutchings efx_channel_get_rx_queue(channel); 280874aeea5SJeff Kirsher 281ff734ef4SBen Hutchings efx_rx_flush_packet(channel); 282cce28794SJon Cooper efx_fast_push_rx_descriptors(rx_queue, true); 283d9ab7007SBen Hutchings } 284874aeea5SJeff Kirsher 285c936835cSPeter Dunning /* Update BQL */ 286c936835cSPeter Dunning efx_for_each_channel_tx_queue(tx_queue, channel) { 287c936835cSPeter Dunning if (tx_queue->bytes_compl) { 288c936835cSPeter Dunning netdev_tx_completed_queue(tx_queue->core_txq, 289c936835cSPeter Dunning tx_queue->pkts_compl, tx_queue->bytes_compl); 290c936835cSPeter Dunning } 291c936835cSPeter Dunning } 292c936835cSPeter Dunning 293874aeea5SJeff Kirsher return spent; 294874aeea5SJeff Kirsher } 295874aeea5SJeff Kirsher 296874aeea5SJeff Kirsher /* NAPI poll handler 297874aeea5SJeff Kirsher * 298874aeea5SJeff Kirsher * NAPI guarantees serialisation of polls of the same device, which 299874aeea5SJeff Kirsher * provides the guarantee required by efx_process_channel(). 300874aeea5SJeff Kirsher */ 301539de7c5SBert Kenward static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel) 302539de7c5SBert Kenward { 303539de7c5SBert Kenward int step = efx->irq_mod_step_us; 304539de7c5SBert Kenward 305539de7c5SBert Kenward if (channel->irq_mod_score < irq_adapt_low_thresh) { 306539de7c5SBert Kenward if (channel->irq_moderation_us > step) { 307539de7c5SBert Kenward channel->irq_moderation_us -= step; 308539de7c5SBert Kenward efx->type->push_irq_moderation(channel); 309539de7c5SBert Kenward } 310539de7c5SBert Kenward } else if (channel->irq_mod_score > irq_adapt_high_thresh) { 311539de7c5SBert Kenward if (channel->irq_moderation_us < 312539de7c5SBert Kenward efx->irq_rx_moderation_us) { 313539de7c5SBert Kenward channel->irq_moderation_us += step; 314539de7c5SBert Kenward efx->type->push_irq_moderation(channel); 315539de7c5SBert Kenward } 316539de7c5SBert Kenward } 317539de7c5SBert Kenward 318539de7c5SBert Kenward channel->irq_count = 0; 319539de7c5SBert Kenward channel->irq_mod_score = 0; 320539de7c5SBert Kenward } 321539de7c5SBert Kenward 322874aeea5SJeff Kirsher static int efx_poll(struct napi_struct *napi, int budget) 323874aeea5SJeff Kirsher { 324874aeea5SJeff Kirsher struct efx_channel *channel = 325874aeea5SJeff Kirsher container_of(napi, struct efx_channel, napi_str); 326874aeea5SJeff Kirsher struct efx_nic *efx = channel->efx; 327874aeea5SJeff Kirsher int spent; 328874aeea5SJeff Kirsher 329874aeea5SJeff Kirsher netif_vdbg(efx, intr, efx->net_dev, 330874aeea5SJeff Kirsher "channel %d NAPI poll executing on CPU %d\n", 331874aeea5SJeff Kirsher channel->channel, raw_smp_processor_id()); 332874aeea5SJeff Kirsher 333874aeea5SJeff Kirsher spent = efx_process_channel(channel, budget); 334874aeea5SJeff Kirsher 335874aeea5SJeff Kirsher if (spent < budget) { 3369d9a6973SBen Hutchings if (efx_channel_has_rx_queue(channel) && 337874aeea5SJeff Kirsher efx->irq_rx_adaptive && 338874aeea5SJeff Kirsher unlikely(++channel->irq_count == 1000)) { 339539de7c5SBert Kenward efx_update_irq_mod(efx, channel); 340874aeea5SJeff Kirsher } 341874aeea5SJeff Kirsher 342874aeea5SJeff Kirsher efx_filter_rfs_expire(channel); 343874aeea5SJeff Kirsher 344874aeea5SJeff Kirsher /* There is no race here; although napi_disable() will 345874aeea5SJeff Kirsher * only wait for napi_complete(), this isn't a problem 346514bedbcSBen Hutchings * since efx_nic_eventq_read_ack() will have no effect if 347874aeea5SJeff Kirsher * interrupts have already been disabled. 348874aeea5SJeff Kirsher */ 349f820c0acSBert Kenward if (napi_complete_done(napi, spent)) 350514bedbcSBen Hutchings efx_nic_eventq_read_ack(channel); 351874aeea5SJeff Kirsher } 352874aeea5SJeff Kirsher 353874aeea5SJeff Kirsher return spent; 354874aeea5SJeff Kirsher } 355874aeea5SJeff Kirsher 356874aeea5SJeff Kirsher /* Create event queue 357874aeea5SJeff Kirsher * Event queue memory allocations are done only once. If the channel 358874aeea5SJeff Kirsher * is reset, the memory buffer will be reused; this guards against 359874aeea5SJeff Kirsher * errors during channel reset and also simplifies interrupt handling. 360874aeea5SJeff Kirsher */ 361874aeea5SJeff Kirsher static int efx_probe_eventq(struct efx_channel *channel) 362874aeea5SJeff Kirsher { 363874aeea5SJeff Kirsher struct efx_nic *efx = channel->efx; 364874aeea5SJeff Kirsher unsigned long entries; 365874aeea5SJeff Kirsher 36686ee5302SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 367874aeea5SJeff Kirsher "chan %d create event queue\n", channel->channel); 368874aeea5SJeff Kirsher 369874aeea5SJeff Kirsher /* Build an event queue with room for one event per tx and rx buffer, 370874aeea5SJeff Kirsher * plus some extra for link state events and MCDI completions. */ 371874aeea5SJeff Kirsher entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128); 372e01b16a7SEdward Cree EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE); 373874aeea5SJeff Kirsher channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1; 374874aeea5SJeff Kirsher 375874aeea5SJeff Kirsher return efx_nic_probe_eventq(channel); 376874aeea5SJeff Kirsher } 377874aeea5SJeff Kirsher 378874aeea5SJeff Kirsher /* Prepare channel's event queue */ 379261e4d96SJon Cooper static int efx_init_eventq(struct efx_channel *channel) 380874aeea5SJeff Kirsher { 38115acb1ceSBen Hutchings struct efx_nic *efx = channel->efx; 382261e4d96SJon Cooper int rc; 383261e4d96SJon Cooper 384261e4d96SJon Cooper EFX_WARN_ON_PARANOID(channel->eventq_init); 385261e4d96SJon Cooper 38615acb1ceSBen Hutchings netif_dbg(efx, drv, efx->net_dev, 387874aeea5SJeff Kirsher "chan %d init event queue\n", channel->channel); 388874aeea5SJeff Kirsher 389261e4d96SJon Cooper rc = efx_nic_init_eventq(channel); 390261e4d96SJon Cooper if (rc == 0) { 39115acb1ceSBen Hutchings efx->type->push_irq_moderation(channel); 392874aeea5SJeff Kirsher channel->eventq_read_ptr = 0; 393be3fc09cSBen Hutchings channel->eventq_init = true; 394874aeea5SJeff Kirsher } 395261e4d96SJon Cooper return rc; 396261e4d96SJon Cooper } 397874aeea5SJeff Kirsher 3989f2cb71cSBen Hutchings /* Enable event queue processing and NAPI */ 39936763266SAlexandre Rames void efx_start_eventq(struct efx_channel *channel) 4009f2cb71cSBen Hutchings { 4019f2cb71cSBen Hutchings netif_dbg(channel->efx, ifup, channel->efx->net_dev, 4029f2cb71cSBen Hutchings "chan %d start event queue\n", channel->channel); 4039f2cb71cSBen Hutchings 404514bedbcSBen Hutchings /* Make sure the NAPI handler sees the enabled flag set */ 4059f2cb71cSBen Hutchings channel->enabled = true; 4069f2cb71cSBen Hutchings smp_wmb(); 4079f2cb71cSBen Hutchings 4089f2cb71cSBen Hutchings napi_enable(&channel->napi_str); 4099f2cb71cSBen Hutchings efx_nic_eventq_read_ack(channel); 4109f2cb71cSBen Hutchings } 4119f2cb71cSBen Hutchings 4129f2cb71cSBen Hutchings /* Disable event queue processing and NAPI */ 41336763266SAlexandre Rames void efx_stop_eventq(struct efx_channel *channel) 4149f2cb71cSBen Hutchings { 4159f2cb71cSBen Hutchings if (!channel->enabled) 4169f2cb71cSBen Hutchings return; 4179f2cb71cSBen Hutchings 4189f2cb71cSBen Hutchings napi_disable(&channel->napi_str); 4199f2cb71cSBen Hutchings channel->enabled = false; 4209f2cb71cSBen Hutchings } 4219f2cb71cSBen Hutchings 422874aeea5SJeff Kirsher static void efx_fini_eventq(struct efx_channel *channel) 423874aeea5SJeff Kirsher { 424be3fc09cSBen Hutchings if (!channel->eventq_init) 425be3fc09cSBen Hutchings return; 426be3fc09cSBen Hutchings 427874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 428874aeea5SJeff Kirsher "chan %d fini event queue\n", channel->channel); 429874aeea5SJeff Kirsher 430874aeea5SJeff Kirsher efx_nic_fini_eventq(channel); 431be3fc09cSBen Hutchings channel->eventq_init = false; 432874aeea5SJeff Kirsher } 433874aeea5SJeff Kirsher 434874aeea5SJeff Kirsher static void efx_remove_eventq(struct efx_channel *channel) 435874aeea5SJeff Kirsher { 436874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 437874aeea5SJeff Kirsher "chan %d remove event queue\n", channel->channel); 438874aeea5SJeff Kirsher 439874aeea5SJeff Kirsher efx_nic_remove_eventq(channel); 440874aeea5SJeff Kirsher } 441874aeea5SJeff Kirsher 442874aeea5SJeff Kirsher /************************************************************************** 443874aeea5SJeff Kirsher * 444874aeea5SJeff Kirsher * Channel handling 445874aeea5SJeff Kirsher * 446874aeea5SJeff Kirsher *************************************************************************/ 447874aeea5SJeff Kirsher 4487f967c01SBen Hutchings /* Allocate and initialise a channel structure. */ 449874aeea5SJeff Kirsher static struct efx_channel * 450874aeea5SJeff Kirsher efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) 451874aeea5SJeff Kirsher { 452874aeea5SJeff Kirsher struct efx_channel *channel; 453874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 454874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 455874aeea5SJeff Kirsher int j; 456874aeea5SJeff Kirsher 4577f967c01SBen Hutchings channel = kzalloc(sizeof(*channel), GFP_KERNEL); 4587f967c01SBen Hutchings if (!channel) 4597f967c01SBen Hutchings return NULL; 4607f967c01SBen Hutchings 4617f967c01SBen Hutchings channel->efx = efx; 4627f967c01SBen Hutchings channel->channel = i; 4637f967c01SBen Hutchings channel->type = &efx_default_channel_type; 4647f967c01SBen Hutchings 4657f967c01SBen Hutchings for (j = 0; j < EFX_TXQ_TYPES; j++) { 4667f967c01SBen Hutchings tx_queue = &channel->tx_queue[j]; 4677f967c01SBen Hutchings tx_queue->efx = efx; 4687f967c01SBen Hutchings tx_queue->queue = i * EFX_TXQ_TYPES + j; 4697f967c01SBen Hutchings tx_queue->channel = channel; 4707f967c01SBen Hutchings } 4717f967c01SBen Hutchings 4727f967c01SBen Hutchings rx_queue = &channel->rx_queue; 4737f967c01SBen Hutchings rx_queue->efx = efx; 4747aa1402eSKees Cook timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 4757f967c01SBen Hutchings 4767f967c01SBen Hutchings return channel; 4777f967c01SBen Hutchings } 4787f967c01SBen Hutchings 4797f967c01SBen Hutchings /* Allocate and initialise a channel structure, copying parameters 4807f967c01SBen Hutchings * (but not resources) from an old channel structure. 4817f967c01SBen Hutchings */ 4827f967c01SBen Hutchings static struct efx_channel * 4837f967c01SBen Hutchings efx_copy_channel(const struct efx_channel *old_channel) 4847f967c01SBen Hutchings { 4857f967c01SBen Hutchings struct efx_channel *channel; 4867f967c01SBen Hutchings struct efx_rx_queue *rx_queue; 4877f967c01SBen Hutchings struct efx_tx_queue *tx_queue; 4887f967c01SBen Hutchings int j; 4897f967c01SBen Hutchings 490874aeea5SJeff Kirsher channel = kmalloc(sizeof(*channel), GFP_KERNEL); 491874aeea5SJeff Kirsher if (!channel) 492874aeea5SJeff Kirsher return NULL; 493874aeea5SJeff Kirsher 494874aeea5SJeff Kirsher *channel = *old_channel; 495874aeea5SJeff Kirsher 496874aeea5SJeff Kirsher channel->napi_dev = NULL; 49746d054f8SBert Kenward INIT_HLIST_NODE(&channel->napi_str.napi_hash_node); 49846d054f8SBert Kenward channel->napi_str.napi_id = 0; 49946d054f8SBert Kenward channel->napi_str.state = 0; 500874aeea5SJeff Kirsher memset(&channel->eventq, 0, sizeof(channel->eventq)); 501874aeea5SJeff Kirsher 502874aeea5SJeff Kirsher for (j = 0; j < EFX_TXQ_TYPES; j++) { 503874aeea5SJeff Kirsher tx_queue = &channel->tx_queue[j]; 504874aeea5SJeff Kirsher if (tx_queue->channel) 505874aeea5SJeff Kirsher tx_queue->channel = channel; 506874aeea5SJeff Kirsher tx_queue->buffer = NULL; 507874aeea5SJeff Kirsher memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); 508874aeea5SJeff Kirsher } 509874aeea5SJeff Kirsher 510874aeea5SJeff Kirsher rx_queue = &channel->rx_queue; 5117f967c01SBen Hutchings rx_queue->buffer = NULL; 5127f967c01SBen Hutchings memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 5137aa1402eSKees Cook timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 514874aeea5SJeff Kirsher 515874aeea5SJeff Kirsher return channel; 516874aeea5SJeff Kirsher } 517874aeea5SJeff Kirsher 518874aeea5SJeff Kirsher static int efx_probe_channel(struct efx_channel *channel) 519874aeea5SJeff Kirsher { 520874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 521874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 522874aeea5SJeff Kirsher int rc; 523874aeea5SJeff Kirsher 524874aeea5SJeff Kirsher netif_dbg(channel->efx, probe, channel->efx->net_dev, 525874aeea5SJeff Kirsher "creating channel %d\n", channel->channel); 526874aeea5SJeff Kirsher 5277f967c01SBen Hutchings rc = channel->type->pre_probe(channel); 5287f967c01SBen Hutchings if (rc) 5297f967c01SBen Hutchings goto fail; 5307f967c01SBen Hutchings 531874aeea5SJeff Kirsher rc = efx_probe_eventq(channel); 532874aeea5SJeff Kirsher if (rc) 5337f967c01SBen Hutchings goto fail; 534874aeea5SJeff Kirsher 535874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) { 536874aeea5SJeff Kirsher rc = efx_probe_tx_queue(tx_queue); 537874aeea5SJeff Kirsher if (rc) 5387f967c01SBen Hutchings goto fail; 539874aeea5SJeff Kirsher } 540874aeea5SJeff Kirsher 541874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) { 542874aeea5SJeff Kirsher rc = efx_probe_rx_queue(rx_queue); 543874aeea5SJeff Kirsher if (rc) 5447f967c01SBen Hutchings goto fail; 545874aeea5SJeff Kirsher } 546874aeea5SJeff Kirsher 547874aeea5SJeff Kirsher return 0; 548874aeea5SJeff Kirsher 5497f967c01SBen Hutchings fail: 5507f967c01SBen Hutchings efx_remove_channel(channel); 551874aeea5SJeff Kirsher return rc; 552874aeea5SJeff Kirsher } 553874aeea5SJeff Kirsher 5547f967c01SBen Hutchings static void 5557f967c01SBen Hutchings efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) 5567f967c01SBen Hutchings { 5577f967c01SBen Hutchings struct efx_nic *efx = channel->efx; 5587f967c01SBen Hutchings const char *type; 5597f967c01SBen Hutchings int number; 5607f967c01SBen Hutchings 5617f967c01SBen Hutchings number = channel->channel; 5627f967c01SBen Hutchings if (efx->tx_channel_offset == 0) { 5637f967c01SBen Hutchings type = ""; 5647f967c01SBen Hutchings } else if (channel->channel < efx->tx_channel_offset) { 5657f967c01SBen Hutchings type = "-rx"; 5667f967c01SBen Hutchings } else { 5677f967c01SBen Hutchings type = "-tx"; 5687f967c01SBen Hutchings number -= efx->tx_channel_offset; 5697f967c01SBen Hutchings } 5707f967c01SBen Hutchings snprintf(buf, len, "%s%s-%d", efx->name, type, number); 5717f967c01SBen Hutchings } 572874aeea5SJeff Kirsher 573874aeea5SJeff Kirsher static void efx_set_channel_names(struct efx_nic *efx) 574874aeea5SJeff Kirsher { 575874aeea5SJeff Kirsher struct efx_channel *channel; 576874aeea5SJeff Kirsher 5777f967c01SBen Hutchings efx_for_each_channel(channel, efx) 5787f967c01SBen Hutchings channel->type->get_name(channel, 579d8291187SBen Hutchings efx->msi_context[channel->channel].name, 580d8291187SBen Hutchings sizeof(efx->msi_context[0].name)); 581874aeea5SJeff Kirsher } 582874aeea5SJeff Kirsher 583874aeea5SJeff Kirsher static int efx_probe_channels(struct efx_nic *efx) 584874aeea5SJeff Kirsher { 585874aeea5SJeff Kirsher struct efx_channel *channel; 586874aeea5SJeff Kirsher int rc; 587874aeea5SJeff Kirsher 588874aeea5SJeff Kirsher /* Restart special buffer allocation */ 589874aeea5SJeff Kirsher efx->next_buffer_table = 0; 590874aeea5SJeff Kirsher 591c92aaff1SBen Hutchings /* Probe channels in reverse, so that any 'extra' channels 592c92aaff1SBen Hutchings * use the start of the buffer table. This allows the traffic 593c92aaff1SBen Hutchings * channels to be resized without moving them or wasting the 594c92aaff1SBen Hutchings * entries before them. 595c92aaff1SBen Hutchings */ 596c92aaff1SBen Hutchings efx_for_each_channel_rev(channel, efx) { 597874aeea5SJeff Kirsher rc = efx_probe_channel(channel); 598874aeea5SJeff Kirsher if (rc) { 599874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 600874aeea5SJeff Kirsher "failed to create channel %d\n", 601874aeea5SJeff Kirsher channel->channel); 602874aeea5SJeff Kirsher goto fail; 603874aeea5SJeff Kirsher } 604874aeea5SJeff Kirsher } 605874aeea5SJeff Kirsher efx_set_channel_names(efx); 606874aeea5SJeff Kirsher 607874aeea5SJeff Kirsher return 0; 608874aeea5SJeff Kirsher 609874aeea5SJeff Kirsher fail: 610874aeea5SJeff Kirsher efx_remove_channels(efx); 611874aeea5SJeff Kirsher return rc; 612874aeea5SJeff Kirsher } 613874aeea5SJeff Kirsher 614874aeea5SJeff Kirsher /* Channels are shutdown and reinitialised whilst the NIC is running 615874aeea5SJeff Kirsher * to propagate configuration changes (mtu, checksum offload), or 616874aeea5SJeff Kirsher * to clear hardware error conditions 617874aeea5SJeff Kirsher */ 6189f2cb71cSBen Hutchings static void efx_start_datapath(struct efx_nic *efx) 619874aeea5SJeff Kirsher { 620ebfcd0fdSAndrew Rybchenko netdev_features_t old_features = efx->net_dev->features; 62185740cdfSBen Hutchings bool old_rx_scatter = efx->rx_scatter; 622874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 623874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 624874aeea5SJeff Kirsher struct efx_channel *channel; 62585740cdfSBen Hutchings size_t rx_buf_len; 626874aeea5SJeff Kirsher 627874aeea5SJeff Kirsher /* Calculate the rx buffer allocation parameters required to 628874aeea5SJeff Kirsher * support the current MTU, including padding for header 629874aeea5SJeff Kirsher * alignment and overruns. 630874aeea5SJeff Kirsher */ 63143a3739dSJon Cooper efx->rx_dma_len = (efx->rx_prefix_size + 632874aeea5SJeff Kirsher EFX_MAX_FRAME_LEN(efx->net_dev->mtu) + 633874aeea5SJeff Kirsher efx->type->rx_buffer_padding); 63485740cdfSBen Hutchings rx_buf_len = (sizeof(struct efx_rx_page_state) + 6352ec03014SAndrew Rybchenko efx->rx_ip_align + efx->rx_dma_len); 63685740cdfSBen Hutchings if (rx_buf_len <= PAGE_SIZE) { 637e8c68c0aSJon Cooper efx->rx_scatter = efx->type->always_rx_scatter; 63885740cdfSBen Hutchings efx->rx_buffer_order = 0; 63985740cdfSBen Hutchings } else if (efx->type->can_rx_scatter) { 640950c54dfSBen Hutchings BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES); 64185740cdfSBen Hutchings BUILD_BUG_ON(sizeof(struct efx_rx_page_state) + 642950c54dfSBen Hutchings 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE, 643950c54dfSBen Hutchings EFX_RX_BUF_ALIGNMENT) > 644950c54dfSBen Hutchings PAGE_SIZE); 64585740cdfSBen Hutchings efx->rx_scatter = true; 64685740cdfSBen Hutchings efx->rx_dma_len = EFX_RX_USR_BUF_SIZE; 64785740cdfSBen Hutchings efx->rx_buffer_order = 0; 64885740cdfSBen Hutchings } else { 64985740cdfSBen Hutchings efx->rx_scatter = false; 65085740cdfSBen Hutchings efx->rx_buffer_order = get_order(rx_buf_len); 65185740cdfSBen Hutchings } 65285740cdfSBen Hutchings 6531648a23fSDaniel Pieczko efx_rx_config_page_split(efx); 6541648a23fSDaniel Pieczko if (efx->rx_buffer_order) 6551648a23fSDaniel Pieczko netif_dbg(efx, drv, efx->net_dev, 6561648a23fSDaniel Pieczko "RX buf len=%u; page order=%u batch=%u\n", 6571648a23fSDaniel Pieczko efx->rx_dma_len, efx->rx_buffer_order, 6581648a23fSDaniel Pieczko efx->rx_pages_per_batch); 6591648a23fSDaniel Pieczko else 6601648a23fSDaniel Pieczko netif_dbg(efx, drv, efx->net_dev, 6611648a23fSDaniel Pieczko "RX buf len=%u step=%u bpp=%u; page batch=%u\n", 6621648a23fSDaniel Pieczko efx->rx_dma_len, efx->rx_page_buf_step, 6631648a23fSDaniel Pieczko efx->rx_bufs_per_page, efx->rx_pages_per_batch); 6642768935aSDaniel Pieczko 665ebfcd0fdSAndrew Rybchenko /* Restore previously fixed features in hw_features and remove 666ebfcd0fdSAndrew Rybchenko * features which are fixed now 667ebfcd0fdSAndrew Rybchenko */ 668ebfcd0fdSAndrew Rybchenko efx->net_dev->hw_features |= efx->net_dev->features; 669ebfcd0fdSAndrew Rybchenko efx->net_dev->hw_features &= ~efx->fixed_features; 670ebfcd0fdSAndrew Rybchenko efx->net_dev->features |= efx->fixed_features; 671ebfcd0fdSAndrew Rybchenko if (efx->net_dev->features != old_features) 672ebfcd0fdSAndrew Rybchenko netdev_features_change(efx->net_dev); 673ebfcd0fdSAndrew Rybchenko 674e8c68c0aSJon Cooper /* RX filters may also have scatter-enabled flags */ 67585740cdfSBen Hutchings if (efx->rx_scatter != old_rx_scatter) 676add72477SBen Hutchings efx->type->filter_update_rx_scatter(efx); 677874aeea5SJeff Kirsher 67814bf718fSBen Hutchings /* We must keep at least one descriptor in a TX ring empty. 67914bf718fSBen Hutchings * We could avoid this when the queue size does not exactly 68014bf718fSBen Hutchings * match the hardware ring size, but it's not that important. 68114bf718fSBen Hutchings * Therefore we stop the queue when one more skb might fill 68214bf718fSBen Hutchings * the ring completely. We wake it when half way back to 68314bf718fSBen Hutchings * empty. 68414bf718fSBen Hutchings */ 68514bf718fSBen Hutchings efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx); 68614bf718fSBen Hutchings efx->txq_wake_thresh = efx->txq_stop_thresh / 2; 68714bf718fSBen Hutchings 688874aeea5SJeff Kirsher /* Initialise the channels */ 689874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 6903881d8abSAlexandre Rames efx_for_each_channel_tx_queue(tx_queue, channel) { 691874aeea5SJeff Kirsher efx_init_tx_queue(tx_queue); 6923881d8abSAlexandre Rames atomic_inc(&efx->active_queues); 6933881d8abSAlexandre Rames } 694874aeea5SJeff Kirsher 6959f2cb71cSBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) { 696874aeea5SJeff Kirsher efx_init_rx_queue(rx_queue); 6973881d8abSAlexandre Rames atomic_inc(&efx->active_queues); 698cce28794SJon Cooper efx_stop_eventq(channel); 699cce28794SJon Cooper efx_fast_push_rx_descriptors(rx_queue, false); 700cce28794SJon Cooper efx_start_eventq(channel); 7019f2cb71cSBen Hutchings } 702874aeea5SJeff Kirsher 70385740cdfSBen Hutchings WARN_ON(channel->rx_pkt_n_frags); 704874aeea5SJeff Kirsher } 7059f2cb71cSBen Hutchings 7062ea4dc28SAlexandre Rames efx_ptp_start_datapath(efx); 7072ea4dc28SAlexandre Rames 7089f2cb71cSBen Hutchings if (netif_device_present(efx->net_dev)) 7099f2cb71cSBen Hutchings netif_tx_wake_all_queues(efx->net_dev); 710874aeea5SJeff Kirsher } 711874aeea5SJeff Kirsher 7129f2cb71cSBen Hutchings static void efx_stop_datapath(struct efx_nic *efx) 713874aeea5SJeff Kirsher { 714874aeea5SJeff Kirsher struct efx_channel *channel; 715874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 716874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 717874aeea5SJeff Kirsher int rc; 718874aeea5SJeff Kirsher 719874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 720874aeea5SJeff Kirsher BUG_ON(efx->port_enabled); 721874aeea5SJeff Kirsher 7222ea4dc28SAlexandre Rames efx_ptp_stop_datapath(efx); 7232ea4dc28SAlexandre Rames 724d8aec745SBen Hutchings /* Stop RX refill */ 725d8aec745SBen Hutchings efx_for_each_channel(channel, efx) { 726d8aec745SBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) 727d8aec745SBen Hutchings rx_queue->refill_enabled = false; 728d8aec745SBen Hutchings } 729d8aec745SBen Hutchings 730874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 7319f2cb71cSBen Hutchings /* RX packet processing is pipelined, so wait for the 7329f2cb71cSBen Hutchings * NAPI handler to complete. At least event queue 0 7339f2cb71cSBen Hutchings * might be kept active by non-data events, so don't 7349f2cb71cSBen Hutchings * use napi_synchronize() but actually disable NAPI 7359f2cb71cSBen Hutchings * temporarily. 7369f2cb71cSBen Hutchings */ 7379f2cb71cSBen Hutchings if (efx_channel_has_rx_queue(channel)) { 7389f2cb71cSBen Hutchings efx_stop_eventq(channel); 7399f2cb71cSBen Hutchings efx_start_eventq(channel); 7409f2cb71cSBen Hutchings } 741e42c3d85SBen Hutchings } 742874aeea5SJeff Kirsher 743e42c3d85SBen Hutchings rc = efx->type->fini_dmaq(efx); 7445a6681e2SEdward Cree if (rc) { 745e42c3d85SBen Hutchings netif_err(efx, drv, efx->net_dev, "failed to flush queues\n"); 746e42c3d85SBen Hutchings } else { 747e42c3d85SBen Hutchings netif_dbg(efx, drv, efx->net_dev, 748e42c3d85SBen Hutchings "successfully flushed all queues\n"); 749e42c3d85SBen Hutchings } 750e42c3d85SBen Hutchings 751e42c3d85SBen Hutchings efx_for_each_channel(channel, efx) { 752874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) 753874aeea5SJeff Kirsher efx_fini_rx_queue(rx_queue); 754874aeea5SJeff Kirsher efx_for_each_possible_channel_tx_queue(tx_queue, channel) 755874aeea5SJeff Kirsher efx_fini_tx_queue(tx_queue); 756874aeea5SJeff Kirsher } 757874aeea5SJeff Kirsher } 758874aeea5SJeff Kirsher 759874aeea5SJeff Kirsher static void efx_remove_channel(struct efx_channel *channel) 760874aeea5SJeff Kirsher { 761874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 762874aeea5SJeff Kirsher struct efx_rx_queue *rx_queue; 763874aeea5SJeff Kirsher 764874aeea5SJeff Kirsher netif_dbg(channel->efx, drv, channel->efx->net_dev, 765874aeea5SJeff Kirsher "destroy chan %d\n", channel->channel); 766874aeea5SJeff Kirsher 767874aeea5SJeff Kirsher efx_for_each_channel_rx_queue(rx_queue, channel) 768874aeea5SJeff Kirsher efx_remove_rx_queue(rx_queue); 769874aeea5SJeff Kirsher efx_for_each_possible_channel_tx_queue(tx_queue, channel) 770874aeea5SJeff Kirsher efx_remove_tx_queue(tx_queue); 771874aeea5SJeff Kirsher efx_remove_eventq(channel); 772c31e5f9fSStuart Hodgson channel->type->post_remove(channel); 773874aeea5SJeff Kirsher } 774874aeea5SJeff Kirsher 775874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx) 776874aeea5SJeff Kirsher { 777874aeea5SJeff Kirsher struct efx_channel *channel; 778874aeea5SJeff Kirsher 779874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 780874aeea5SJeff Kirsher efx_remove_channel(channel); 781874aeea5SJeff Kirsher } 782874aeea5SJeff Kirsher 783874aeea5SJeff Kirsher int 784874aeea5SJeff Kirsher efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) 785874aeea5SJeff Kirsher { 786874aeea5SJeff Kirsher struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; 787874aeea5SJeff Kirsher u32 old_rxq_entries, old_txq_entries; 7887f967c01SBen Hutchings unsigned i, next_buffer_table = 0; 789261e4d96SJon Cooper int rc, rc2; 7908b7325b4SBen Hutchings 7918b7325b4SBen Hutchings rc = efx_check_disabled(efx); 7928b7325b4SBen Hutchings if (rc) 7938b7325b4SBen Hutchings return rc; 7947f967c01SBen Hutchings 7957f967c01SBen Hutchings /* Not all channels should be reallocated. We must avoid 7967f967c01SBen Hutchings * reallocating their buffer table entries. 7977f967c01SBen Hutchings */ 7987f967c01SBen Hutchings efx_for_each_channel(channel, efx) { 7997f967c01SBen Hutchings struct efx_rx_queue *rx_queue; 8007f967c01SBen Hutchings struct efx_tx_queue *tx_queue; 8017f967c01SBen Hutchings 8027f967c01SBen Hutchings if (channel->type->copy) 8037f967c01SBen Hutchings continue; 8047f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 8057f967c01SBen Hutchings channel->eventq.index + 8067f967c01SBen Hutchings channel->eventq.entries); 8077f967c01SBen Hutchings efx_for_each_channel_rx_queue(rx_queue, channel) 8087f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 8097f967c01SBen Hutchings rx_queue->rxd.index + 8107f967c01SBen Hutchings rx_queue->rxd.entries); 8117f967c01SBen Hutchings efx_for_each_channel_tx_queue(tx_queue, channel) 8127f967c01SBen Hutchings next_buffer_table = max(next_buffer_table, 8137f967c01SBen Hutchings tx_queue->txd.index + 8147f967c01SBen Hutchings tx_queue->txd.entries); 8157f967c01SBen Hutchings } 816874aeea5SJeff Kirsher 81729c69a48SBen Hutchings efx_device_detach_sync(efx); 818874aeea5SJeff Kirsher efx_stop_all(efx); 819d8291187SBen Hutchings efx_soft_disable_interrupts(efx); 820874aeea5SJeff Kirsher 8217f967c01SBen Hutchings /* Clone channels (where possible) */ 822874aeea5SJeff Kirsher memset(other_channel, 0, sizeof(other_channel)); 823874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 8247f967c01SBen Hutchings channel = efx->channel[i]; 8257f967c01SBen Hutchings if (channel->type->copy) 8267f967c01SBen Hutchings channel = channel->type->copy(channel); 827874aeea5SJeff Kirsher if (!channel) { 828874aeea5SJeff Kirsher rc = -ENOMEM; 829874aeea5SJeff Kirsher goto out; 830874aeea5SJeff Kirsher } 831874aeea5SJeff Kirsher other_channel[i] = channel; 832874aeea5SJeff Kirsher } 833874aeea5SJeff Kirsher 834874aeea5SJeff Kirsher /* Swap entry counts and channel pointers */ 835874aeea5SJeff Kirsher old_rxq_entries = efx->rxq_entries; 836874aeea5SJeff Kirsher old_txq_entries = efx->txq_entries; 837874aeea5SJeff Kirsher efx->rxq_entries = rxq_entries; 838874aeea5SJeff Kirsher efx->txq_entries = txq_entries; 839874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 840874aeea5SJeff Kirsher channel = efx->channel[i]; 841874aeea5SJeff Kirsher efx->channel[i] = other_channel[i]; 842874aeea5SJeff Kirsher other_channel[i] = channel; 843874aeea5SJeff Kirsher } 844874aeea5SJeff Kirsher 8457f967c01SBen Hutchings /* Restart buffer table allocation */ 8467f967c01SBen Hutchings efx->next_buffer_table = next_buffer_table; 8477f967c01SBen Hutchings 8487f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) { 8497f967c01SBen Hutchings channel = efx->channel[i]; 8507f967c01SBen Hutchings if (!channel->type->copy) 8517f967c01SBen Hutchings continue; 8527f967c01SBen Hutchings rc = efx_probe_channel(channel); 853874aeea5SJeff Kirsher if (rc) 854874aeea5SJeff Kirsher goto rollback; 8557f967c01SBen Hutchings efx_init_napi_channel(efx->channel[i]); 856874aeea5SJeff Kirsher } 857874aeea5SJeff Kirsher 8587f967c01SBen Hutchings out: 8597f967c01SBen Hutchings /* Destroy unused channel structures */ 8607f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) { 8617f967c01SBen Hutchings channel = other_channel[i]; 8627f967c01SBen Hutchings if (channel && channel->type->copy) { 8637f967c01SBen Hutchings efx_fini_napi_channel(channel); 8647f967c01SBen Hutchings efx_remove_channel(channel); 8657f967c01SBen Hutchings kfree(channel); 8667f967c01SBen Hutchings } 8677f967c01SBen Hutchings } 8687f967c01SBen Hutchings 869261e4d96SJon Cooper rc2 = efx_soft_enable_interrupts(efx); 870261e4d96SJon Cooper if (rc2) { 871261e4d96SJon Cooper rc = rc ? rc : rc2; 872261e4d96SJon Cooper netif_err(efx, drv, efx->net_dev, 873261e4d96SJon Cooper "unable to restart interrupts on channel reallocation\n"); 874261e4d96SJon Cooper efx_schedule_reset(efx, RESET_TYPE_DISABLE); 875261e4d96SJon Cooper } else { 876874aeea5SJeff Kirsher efx_start_all(efx); 8779c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 878261e4d96SJon Cooper } 879874aeea5SJeff Kirsher return rc; 880874aeea5SJeff Kirsher 881874aeea5SJeff Kirsher rollback: 882874aeea5SJeff Kirsher /* Swap back */ 883874aeea5SJeff Kirsher efx->rxq_entries = old_rxq_entries; 884874aeea5SJeff Kirsher efx->txq_entries = old_txq_entries; 885874aeea5SJeff Kirsher for (i = 0; i < efx->n_channels; i++) { 886874aeea5SJeff Kirsher channel = efx->channel[i]; 887874aeea5SJeff Kirsher efx->channel[i] = other_channel[i]; 888874aeea5SJeff Kirsher other_channel[i] = channel; 889874aeea5SJeff Kirsher } 890874aeea5SJeff Kirsher goto out; 891874aeea5SJeff Kirsher } 892874aeea5SJeff Kirsher 893874aeea5SJeff Kirsher void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue) 894874aeea5SJeff Kirsher { 895874aeea5SJeff Kirsher mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100)); 896874aeea5SJeff Kirsher } 897874aeea5SJeff Kirsher 8987f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type = { 8997f967c01SBen Hutchings .pre_probe = efx_channel_dummy_op_int, 900c31e5f9fSStuart Hodgson .post_remove = efx_channel_dummy_op_void, 9017f967c01SBen Hutchings .get_name = efx_get_channel_name, 9027f967c01SBen Hutchings .copy = efx_copy_channel, 9037f967c01SBen Hutchings .keep_eventq = false, 9047f967c01SBen Hutchings }; 9057f967c01SBen Hutchings 9067f967c01SBen Hutchings int efx_channel_dummy_op_int(struct efx_channel *channel) 9077f967c01SBen Hutchings { 9087f967c01SBen Hutchings return 0; 9097f967c01SBen Hutchings } 9107f967c01SBen Hutchings 911c31e5f9fSStuart Hodgson void efx_channel_dummy_op_void(struct efx_channel *channel) 912c31e5f9fSStuart Hodgson { 913c31e5f9fSStuart Hodgson } 914c31e5f9fSStuart Hodgson 915874aeea5SJeff Kirsher /************************************************************************** 916874aeea5SJeff Kirsher * 917874aeea5SJeff Kirsher * Port handling 918874aeea5SJeff Kirsher * 919874aeea5SJeff Kirsher **************************************************************************/ 920874aeea5SJeff Kirsher 921874aeea5SJeff Kirsher /* This ensures that the kernel is kept informed (via 922874aeea5SJeff Kirsher * netif_carrier_on/off) of the link status, and also maintains the 923874aeea5SJeff Kirsher * link status's stop on the port's TX queue. 924874aeea5SJeff Kirsher */ 925874aeea5SJeff Kirsher void efx_link_status_changed(struct efx_nic *efx) 926874aeea5SJeff Kirsher { 927874aeea5SJeff Kirsher struct efx_link_state *link_state = &efx->link_state; 928874aeea5SJeff Kirsher 929874aeea5SJeff Kirsher /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure 930874aeea5SJeff Kirsher * that no events are triggered between unregister_netdev() and the 931874aeea5SJeff Kirsher * driver unloading. A more general condition is that NETDEV_CHANGE 932874aeea5SJeff Kirsher * can only be generated between NETDEV_UP and NETDEV_DOWN */ 933874aeea5SJeff Kirsher if (!netif_running(efx->net_dev)) 934874aeea5SJeff Kirsher return; 935874aeea5SJeff Kirsher 936874aeea5SJeff Kirsher if (link_state->up != netif_carrier_ok(efx->net_dev)) { 937874aeea5SJeff Kirsher efx->n_link_state_changes++; 938874aeea5SJeff Kirsher 939874aeea5SJeff Kirsher if (link_state->up) 940874aeea5SJeff Kirsher netif_carrier_on(efx->net_dev); 941874aeea5SJeff Kirsher else 942874aeea5SJeff Kirsher netif_carrier_off(efx->net_dev); 943874aeea5SJeff Kirsher } 944874aeea5SJeff Kirsher 945874aeea5SJeff Kirsher /* Status message for kernel log */ 9462aa9ef11SBen Hutchings if (link_state->up) 947874aeea5SJeff Kirsher netif_info(efx, link, efx->net_dev, 948964e6135SBen Hutchings "link up at %uMbps %s-duplex (MTU %d)\n", 949874aeea5SJeff Kirsher link_state->speed, link_state->fd ? "full" : "half", 950964e6135SBen Hutchings efx->net_dev->mtu); 9512aa9ef11SBen Hutchings else 952874aeea5SJeff Kirsher netif_info(efx, link, efx->net_dev, "link down\n"); 953874aeea5SJeff Kirsher } 954874aeea5SJeff Kirsher 955874aeea5SJeff Kirsher void efx_link_set_advertising(struct efx_nic *efx, u32 advertising) 956874aeea5SJeff Kirsher { 957874aeea5SJeff Kirsher efx->link_advertising = advertising; 958874aeea5SJeff Kirsher if (advertising) { 959874aeea5SJeff Kirsher if (advertising & ADVERTISED_Pause) 960874aeea5SJeff Kirsher efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX); 961874aeea5SJeff Kirsher else 962874aeea5SJeff Kirsher efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX); 963874aeea5SJeff Kirsher if (advertising & ADVERTISED_Asym_Pause) 964874aeea5SJeff Kirsher efx->wanted_fc ^= EFX_FC_TX; 965874aeea5SJeff Kirsher } 966874aeea5SJeff Kirsher } 967874aeea5SJeff Kirsher 968874aeea5SJeff Kirsher void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc) 969874aeea5SJeff Kirsher { 970874aeea5SJeff Kirsher efx->wanted_fc = wanted_fc; 971874aeea5SJeff Kirsher if (efx->link_advertising) { 972874aeea5SJeff Kirsher if (wanted_fc & EFX_FC_RX) 973874aeea5SJeff Kirsher efx->link_advertising |= (ADVERTISED_Pause | 974874aeea5SJeff Kirsher ADVERTISED_Asym_Pause); 975874aeea5SJeff Kirsher else 976874aeea5SJeff Kirsher efx->link_advertising &= ~(ADVERTISED_Pause | 977874aeea5SJeff Kirsher ADVERTISED_Asym_Pause); 978874aeea5SJeff Kirsher if (wanted_fc & EFX_FC_TX) 979874aeea5SJeff Kirsher efx->link_advertising ^= ADVERTISED_Asym_Pause; 980874aeea5SJeff Kirsher } 981874aeea5SJeff Kirsher } 982874aeea5SJeff Kirsher 983874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx); 984874aeea5SJeff Kirsher 9850d322413SEdward Cree /* We assume that efx->type->reconfigure_mac will always try to sync RX 9860d322413SEdward Cree * filters and therefore needs to read-lock the filter table against freeing 9870d322413SEdward Cree */ 9880d322413SEdward Cree void efx_mac_reconfigure(struct efx_nic *efx) 9890d322413SEdward Cree { 9900d322413SEdward Cree down_read(&efx->filter_sem); 9910d322413SEdward Cree efx->type->reconfigure_mac(efx); 9920d322413SEdward Cree up_read(&efx->filter_sem); 9930d322413SEdward Cree } 9940d322413SEdward Cree 995874aeea5SJeff Kirsher /* Push loopback/power/transmit disable settings to the PHY, and reconfigure 996874aeea5SJeff Kirsher * the MAC appropriately. All other PHY configuration changes are pushed 997874aeea5SJeff Kirsher * through phy_op->set_settings(), and pushed asynchronously to the MAC 998874aeea5SJeff Kirsher * through efx_monitor(). 999874aeea5SJeff Kirsher * 1000874aeea5SJeff Kirsher * Callers must hold the mac_lock 1001874aeea5SJeff Kirsher */ 1002874aeea5SJeff Kirsher int __efx_reconfigure_port(struct efx_nic *efx) 1003874aeea5SJeff Kirsher { 1004874aeea5SJeff Kirsher enum efx_phy_mode phy_mode; 1005874aeea5SJeff Kirsher int rc; 1006874aeea5SJeff Kirsher 1007874aeea5SJeff Kirsher WARN_ON(!mutex_is_locked(&efx->mac_lock)); 1008874aeea5SJeff Kirsher 1009874aeea5SJeff Kirsher /* Disable PHY transmit in mac level loopbacks */ 1010874aeea5SJeff Kirsher phy_mode = efx->phy_mode; 1011874aeea5SJeff Kirsher if (LOOPBACK_INTERNAL(efx)) 1012874aeea5SJeff Kirsher efx->phy_mode |= PHY_MODE_TX_DISABLED; 1013874aeea5SJeff Kirsher else 1014874aeea5SJeff Kirsher efx->phy_mode &= ~PHY_MODE_TX_DISABLED; 1015874aeea5SJeff Kirsher 1016874aeea5SJeff Kirsher rc = efx->type->reconfigure_port(efx); 1017874aeea5SJeff Kirsher 1018874aeea5SJeff Kirsher if (rc) 1019874aeea5SJeff Kirsher efx->phy_mode = phy_mode; 1020874aeea5SJeff Kirsher 1021874aeea5SJeff Kirsher return rc; 1022874aeea5SJeff Kirsher } 1023874aeea5SJeff Kirsher 1024874aeea5SJeff Kirsher /* Reinitialise the MAC to pick up new PHY settings, even if the port is 1025874aeea5SJeff Kirsher * disabled. */ 1026874aeea5SJeff Kirsher int efx_reconfigure_port(struct efx_nic *efx) 1027874aeea5SJeff Kirsher { 1028874aeea5SJeff Kirsher int rc; 1029874aeea5SJeff Kirsher 1030874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 1031874aeea5SJeff Kirsher 1032874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1033874aeea5SJeff Kirsher rc = __efx_reconfigure_port(efx); 1034874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1035874aeea5SJeff Kirsher 1036874aeea5SJeff Kirsher return rc; 1037874aeea5SJeff Kirsher } 1038874aeea5SJeff Kirsher 1039874aeea5SJeff Kirsher /* Asynchronous work item for changing MAC promiscuity and multicast 1040874aeea5SJeff Kirsher * hash. Avoid a drain/rx_ingress enable by reconfiguring the current 1041874aeea5SJeff Kirsher * MAC directly. */ 1042874aeea5SJeff Kirsher static void efx_mac_work(struct work_struct *data) 1043874aeea5SJeff Kirsher { 1044874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); 1045874aeea5SJeff Kirsher 1046874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 104730b81cdaSBen Hutchings if (efx->port_enabled) 10480d322413SEdward Cree efx_mac_reconfigure(efx); 1049874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1050874aeea5SJeff Kirsher } 1051874aeea5SJeff Kirsher 1052874aeea5SJeff Kirsher static int efx_probe_port(struct efx_nic *efx) 1053874aeea5SJeff Kirsher { 1054874aeea5SJeff Kirsher int rc; 1055874aeea5SJeff Kirsher 1056874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "create port\n"); 1057874aeea5SJeff Kirsher 1058874aeea5SJeff Kirsher if (phy_flash_cfg) 1059874aeea5SJeff Kirsher efx->phy_mode = PHY_MODE_SPECIAL; 1060874aeea5SJeff Kirsher 1061874aeea5SJeff Kirsher /* Connect up MAC/PHY operations table */ 1062874aeea5SJeff Kirsher rc = efx->type->probe_port(efx); 1063874aeea5SJeff Kirsher if (rc) 1064874aeea5SJeff Kirsher return rc; 1065874aeea5SJeff Kirsher 1066e332bcb3SBen Hutchings /* Initialise MAC address to permanent address */ 1067cd84ff4dSEdward Cree ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr); 1068874aeea5SJeff Kirsher 1069874aeea5SJeff Kirsher return 0; 1070874aeea5SJeff Kirsher } 1071874aeea5SJeff Kirsher 1072874aeea5SJeff Kirsher static int efx_init_port(struct efx_nic *efx) 1073874aeea5SJeff Kirsher { 1074874aeea5SJeff Kirsher int rc; 1075874aeea5SJeff Kirsher 1076874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "init port\n"); 1077874aeea5SJeff Kirsher 1078874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1079874aeea5SJeff Kirsher 1080874aeea5SJeff Kirsher rc = efx->phy_op->init(efx); 1081874aeea5SJeff Kirsher if (rc) 1082874aeea5SJeff Kirsher goto fail1; 1083874aeea5SJeff Kirsher 1084874aeea5SJeff Kirsher efx->port_initialized = true; 1085874aeea5SJeff Kirsher 1086874aeea5SJeff Kirsher /* Reconfigure the MAC before creating dma queues (required for 1087874aeea5SJeff Kirsher * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */ 10880d322413SEdward Cree efx_mac_reconfigure(efx); 1089874aeea5SJeff Kirsher 1090874aeea5SJeff Kirsher /* Ensure the PHY advertises the correct flow control settings */ 1091874aeea5SJeff Kirsher rc = efx->phy_op->reconfigure(efx); 1092267d9d73SEdward Cree if (rc && rc != -EPERM) 1093874aeea5SJeff Kirsher goto fail2; 1094874aeea5SJeff Kirsher 1095874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1096874aeea5SJeff Kirsher return 0; 1097874aeea5SJeff Kirsher 1098874aeea5SJeff Kirsher fail2: 1099874aeea5SJeff Kirsher efx->phy_op->fini(efx); 1100874aeea5SJeff Kirsher fail1: 1101874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1102874aeea5SJeff Kirsher return rc; 1103874aeea5SJeff Kirsher } 1104874aeea5SJeff Kirsher 1105874aeea5SJeff Kirsher static void efx_start_port(struct efx_nic *efx) 1106874aeea5SJeff Kirsher { 1107874aeea5SJeff Kirsher netif_dbg(efx, ifup, efx->net_dev, "start port\n"); 1108874aeea5SJeff Kirsher BUG_ON(efx->port_enabled); 1109874aeea5SJeff Kirsher 1110874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1111874aeea5SJeff Kirsher efx->port_enabled = true; 1112874aeea5SJeff Kirsher 1113d615c039SBen Hutchings /* Ensure MAC ingress/egress is enabled */ 11140d322413SEdward Cree efx_mac_reconfigure(efx); 1115874aeea5SJeff Kirsher 1116874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1117874aeea5SJeff Kirsher } 1118874aeea5SJeff Kirsher 1119d615c039SBen Hutchings /* Cancel work for MAC reconfiguration, periodic hardware monitoring 1120d615c039SBen Hutchings * and the async self-test, wait for them to finish and prevent them 1121d615c039SBen Hutchings * being scheduled again. This doesn't cover online resets, which 1122d615c039SBen Hutchings * should only be cancelled when removing the device. 1123d615c039SBen Hutchings */ 1124874aeea5SJeff Kirsher static void efx_stop_port(struct efx_nic *efx) 1125874aeea5SJeff Kirsher { 1126874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "stop port\n"); 1127874aeea5SJeff Kirsher 1128d615c039SBen Hutchings EFX_ASSERT_RESET_SERIALISED(efx); 1129d615c039SBen Hutchings 1130874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1131874aeea5SJeff Kirsher efx->port_enabled = false; 1132874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1133874aeea5SJeff Kirsher 1134874aeea5SJeff Kirsher /* Serialise against efx_set_multicast_list() */ 1135874aeea5SJeff Kirsher netif_addr_lock_bh(efx->net_dev); 1136874aeea5SJeff Kirsher netif_addr_unlock_bh(efx->net_dev); 1137d615c039SBen Hutchings 1138d615c039SBen Hutchings cancel_delayed_work_sync(&efx->monitor_work); 1139d615c039SBen Hutchings efx_selftest_async_cancel(efx); 1140d615c039SBen Hutchings cancel_work_sync(&efx->mac_work); 1141874aeea5SJeff Kirsher } 1142874aeea5SJeff Kirsher 1143874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx) 1144874aeea5SJeff Kirsher { 1145874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); 1146874aeea5SJeff Kirsher 1147874aeea5SJeff Kirsher if (!efx->port_initialized) 1148874aeea5SJeff Kirsher return; 1149874aeea5SJeff Kirsher 1150874aeea5SJeff Kirsher efx->phy_op->fini(efx); 1151874aeea5SJeff Kirsher efx->port_initialized = false; 1152874aeea5SJeff Kirsher 1153874aeea5SJeff Kirsher efx->link_state.up = false; 1154874aeea5SJeff Kirsher efx_link_status_changed(efx); 1155874aeea5SJeff Kirsher } 1156874aeea5SJeff Kirsher 1157874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx) 1158874aeea5SJeff Kirsher { 1159874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); 1160874aeea5SJeff Kirsher 1161874aeea5SJeff Kirsher efx->type->remove_port(efx); 1162874aeea5SJeff Kirsher } 1163874aeea5SJeff Kirsher 1164874aeea5SJeff Kirsher /************************************************************************** 1165874aeea5SJeff Kirsher * 1166874aeea5SJeff Kirsher * NIC handling 1167874aeea5SJeff Kirsher * 1168874aeea5SJeff Kirsher **************************************************************************/ 1169874aeea5SJeff Kirsher 11700bcf4a64SBen Hutchings static LIST_HEAD(efx_primary_list); 11710bcf4a64SBen Hutchings static LIST_HEAD(efx_unassociated_list); 11720bcf4a64SBen Hutchings 11730bcf4a64SBen Hutchings static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right) 11740bcf4a64SBen Hutchings { 11750bcf4a64SBen Hutchings return left->type == right->type && 11760bcf4a64SBen Hutchings left->vpd_sn && right->vpd_sn && 11770bcf4a64SBen Hutchings !strcmp(left->vpd_sn, right->vpd_sn); 11780bcf4a64SBen Hutchings } 11790bcf4a64SBen Hutchings 11800bcf4a64SBen Hutchings static void efx_associate(struct efx_nic *efx) 11810bcf4a64SBen Hutchings { 11820bcf4a64SBen Hutchings struct efx_nic *other, *next; 11830bcf4a64SBen Hutchings 11840bcf4a64SBen Hutchings if (efx->primary == efx) { 11850bcf4a64SBen Hutchings /* Adding primary function; look for secondaries */ 11860bcf4a64SBen Hutchings 11870bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n"); 11880bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_primary_list); 11890bcf4a64SBen Hutchings 11900bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx_unassociated_list, 11910bcf4a64SBen Hutchings node) { 11920bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 11930bcf4a64SBen Hutchings list_del(&other->node); 11940bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 11950bcf4a64SBen Hutchings "moving to secondary list of %s %s\n", 11960bcf4a64SBen Hutchings pci_name(efx->pci_dev), 11970bcf4a64SBen Hutchings efx->net_dev->name); 11980bcf4a64SBen Hutchings list_add_tail(&other->node, 11990bcf4a64SBen Hutchings &efx->secondary_list); 12000bcf4a64SBen Hutchings other->primary = efx; 12010bcf4a64SBen Hutchings } 12020bcf4a64SBen Hutchings } 12030bcf4a64SBen Hutchings } else { 12040bcf4a64SBen Hutchings /* Adding secondary function; look for primary */ 12050bcf4a64SBen Hutchings 12060bcf4a64SBen Hutchings list_for_each_entry(other, &efx_primary_list, node) { 12070bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 12080bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 12090bcf4a64SBen Hutchings "adding to secondary list of %s %s\n", 12100bcf4a64SBen Hutchings pci_name(other->pci_dev), 12110bcf4a64SBen Hutchings other->net_dev->name); 12120bcf4a64SBen Hutchings list_add_tail(&efx->node, 12130bcf4a64SBen Hutchings &other->secondary_list); 12140bcf4a64SBen Hutchings efx->primary = other; 12150bcf4a64SBen Hutchings return; 12160bcf4a64SBen Hutchings } 12170bcf4a64SBen Hutchings } 12180bcf4a64SBen Hutchings 12190bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 12200bcf4a64SBen Hutchings "adding to unassociated list\n"); 12210bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_unassociated_list); 12220bcf4a64SBen Hutchings } 12230bcf4a64SBen Hutchings } 12240bcf4a64SBen Hutchings 12250bcf4a64SBen Hutchings static void efx_dissociate(struct efx_nic *efx) 12260bcf4a64SBen Hutchings { 12270bcf4a64SBen Hutchings struct efx_nic *other, *next; 12280bcf4a64SBen Hutchings 12290bcf4a64SBen Hutchings list_del(&efx->node); 12300bcf4a64SBen Hutchings efx->primary = NULL; 12310bcf4a64SBen Hutchings 12320bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx->secondary_list, node) { 12330bcf4a64SBen Hutchings list_del(&other->node); 12340bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 12350bcf4a64SBen Hutchings "moving to unassociated list\n"); 12360bcf4a64SBen Hutchings list_add_tail(&other->node, &efx_unassociated_list); 12370bcf4a64SBen Hutchings other->primary = NULL; 12380bcf4a64SBen Hutchings } 12390bcf4a64SBen Hutchings } 12400bcf4a64SBen Hutchings 1241874aeea5SJeff Kirsher /* This configures the PCI device to enable I/O and DMA. */ 1242874aeea5SJeff Kirsher static int efx_init_io(struct efx_nic *efx) 1243874aeea5SJeff Kirsher { 1244874aeea5SJeff Kirsher struct pci_dev *pci_dev = efx->pci_dev; 1245874aeea5SJeff Kirsher dma_addr_t dma_mask = efx->type->max_dma_mask; 1246b105798fSBen Hutchings unsigned int mem_map_size = efx->type->mem_map_size(efx); 124702246a7fSShradha Shah int rc, bar; 1248874aeea5SJeff Kirsher 1249874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n"); 1250874aeea5SJeff Kirsher 125102246a7fSShradha Shah bar = efx->type->mem_bar; 125202246a7fSShradha Shah 1253874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 1254874aeea5SJeff Kirsher if (rc) { 1255874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1256874aeea5SJeff Kirsher "failed to enable PCI device\n"); 1257874aeea5SJeff Kirsher goto fail1; 1258874aeea5SJeff Kirsher } 1259874aeea5SJeff Kirsher 1260874aeea5SJeff Kirsher pci_set_master(pci_dev); 1261874aeea5SJeff Kirsher 1262874aeea5SJeff Kirsher /* Set the PCI DMA mask. Try all possibilities from our 1263874aeea5SJeff Kirsher * genuine mask down to 32 bits, because some architectures 1264874aeea5SJeff Kirsher * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit 1265874aeea5SJeff Kirsher * masks event though they reject 46 bit masks. 1266874aeea5SJeff Kirsher */ 1267874aeea5SJeff Kirsher while (dma_mask > 0x7fffffffUL) { 12689663dedaSRussell King rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask); 1269e9e01846SBen Hutchings if (rc == 0) 1270874aeea5SJeff Kirsher break; 1271874aeea5SJeff Kirsher dma_mask >>= 1; 1272874aeea5SJeff Kirsher } 1273874aeea5SJeff Kirsher if (rc) { 1274874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1275874aeea5SJeff Kirsher "could not find a suitable DMA mask\n"); 1276874aeea5SJeff Kirsher goto fail2; 1277874aeea5SJeff Kirsher } 1278874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, 1279874aeea5SJeff Kirsher "using DMA mask %llx\n", (unsigned long long) dma_mask); 1280874aeea5SJeff Kirsher 128102246a7fSShradha Shah efx->membase_phys = pci_resource_start(efx->pci_dev, bar); 128202246a7fSShradha Shah rc = pci_request_region(pci_dev, bar, "sfc"); 1283874aeea5SJeff Kirsher if (rc) { 1284874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1285874aeea5SJeff Kirsher "request for memory BAR failed\n"); 1286874aeea5SJeff Kirsher rc = -EIO; 1287874aeea5SJeff Kirsher goto fail3; 1288874aeea5SJeff Kirsher } 1289b105798fSBen Hutchings efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size); 1290874aeea5SJeff Kirsher if (!efx->membase) { 1291874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1292874aeea5SJeff Kirsher "could not map memory BAR at %llx+%x\n", 1293b105798fSBen Hutchings (unsigned long long)efx->membase_phys, mem_map_size); 1294874aeea5SJeff Kirsher rc = -ENOMEM; 1295874aeea5SJeff Kirsher goto fail4; 1296874aeea5SJeff Kirsher } 1297874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, 1298874aeea5SJeff Kirsher "memory BAR at %llx+%x (virtual %p)\n", 1299b105798fSBen Hutchings (unsigned long long)efx->membase_phys, mem_map_size, 1300b105798fSBen Hutchings efx->membase); 1301874aeea5SJeff Kirsher 1302874aeea5SJeff Kirsher return 0; 1303874aeea5SJeff Kirsher 1304874aeea5SJeff Kirsher fail4: 130502246a7fSShradha Shah pci_release_region(efx->pci_dev, bar); 1306874aeea5SJeff Kirsher fail3: 1307874aeea5SJeff Kirsher efx->membase_phys = 0; 1308874aeea5SJeff Kirsher fail2: 1309874aeea5SJeff Kirsher pci_disable_device(efx->pci_dev); 1310874aeea5SJeff Kirsher fail1: 1311874aeea5SJeff Kirsher return rc; 1312874aeea5SJeff Kirsher } 1313874aeea5SJeff Kirsher 1314874aeea5SJeff Kirsher static void efx_fini_io(struct efx_nic *efx) 1315874aeea5SJeff Kirsher { 131602246a7fSShradha Shah int bar; 131702246a7fSShradha Shah 1318874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n"); 1319874aeea5SJeff Kirsher 1320874aeea5SJeff Kirsher if (efx->membase) { 1321874aeea5SJeff Kirsher iounmap(efx->membase); 1322874aeea5SJeff Kirsher efx->membase = NULL; 1323874aeea5SJeff Kirsher } 1324874aeea5SJeff Kirsher 1325874aeea5SJeff Kirsher if (efx->membase_phys) { 132602246a7fSShradha Shah bar = efx->type->mem_bar; 132702246a7fSShradha Shah pci_release_region(efx->pci_dev, bar); 1328874aeea5SJeff Kirsher efx->membase_phys = 0; 1329874aeea5SJeff Kirsher } 1330874aeea5SJeff Kirsher 13316598dad2SDaniel Pieczko /* Don't disable bus-mastering if VFs are assigned */ 13326598dad2SDaniel Pieczko if (!pci_vfs_assigned(efx->pci_dev)) 1333874aeea5SJeff Kirsher pci_disable_device(efx->pci_dev); 1334874aeea5SJeff Kirsher } 1335874aeea5SJeff Kirsher 1336267c0157SJon Cooper void efx_set_default_rx_indir_table(struct efx_nic *efx) 1337267c0157SJon Cooper { 1338267c0157SJon Cooper size_t i; 1339267c0157SJon Cooper 1340267c0157SJon Cooper for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) 1341267c0157SJon Cooper efx->rx_indir_table[i] = 1342267c0157SJon Cooper ethtool_rxfh_indir_default(i, efx->rss_spread); 1343267c0157SJon Cooper } 1344267c0157SJon Cooper 1345a9a52506SBen Hutchings static unsigned int efx_wanted_parallelism(struct efx_nic *efx) 1346874aeea5SJeff Kirsher { 1347cdb08f8fSBen Hutchings cpumask_var_t thread_mask; 1348a16e5b24SBen Hutchings unsigned int count; 1349874aeea5SJeff Kirsher int cpu; 1350874aeea5SJeff Kirsher 1351cd2d5b52SBen Hutchings if (rss_cpus) { 1352cd2d5b52SBen Hutchings count = rss_cpus; 1353cd2d5b52SBen Hutchings } else { 1354cdb08f8fSBen Hutchings if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) { 1355a9a52506SBen Hutchings netif_warn(efx, probe, efx->net_dev, 1356a9a52506SBen Hutchings "RSS disabled due to allocation failure\n"); 1357874aeea5SJeff Kirsher return 1; 1358874aeea5SJeff Kirsher } 1359874aeea5SJeff Kirsher 1360874aeea5SJeff Kirsher count = 0; 1361874aeea5SJeff Kirsher for_each_online_cpu(cpu) { 1362cdb08f8fSBen Hutchings if (!cpumask_test_cpu(cpu, thread_mask)) { 1363874aeea5SJeff Kirsher ++count; 1364cdb08f8fSBen Hutchings cpumask_or(thread_mask, thread_mask, 136506931e62SBartosz Golaszewski topology_sibling_cpumask(cpu)); 1366874aeea5SJeff Kirsher } 1367874aeea5SJeff Kirsher } 1368874aeea5SJeff Kirsher 1369cdb08f8fSBen Hutchings free_cpumask_var(thread_mask); 1370cd2d5b52SBen Hutchings } 1371cd2d5b52SBen Hutchings 1372271a8b42SBert Kenward if (count > EFX_MAX_RX_QUEUES) { 1373271a8b42SBert Kenward netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn, 1374271a8b42SBert Kenward "Reducing number of rx queues from %u to %u.\n", 1375271a8b42SBert Kenward count, EFX_MAX_RX_QUEUES); 1376271a8b42SBert Kenward count = EFX_MAX_RX_QUEUES; 1377271a8b42SBert Kenward } 1378271a8b42SBert Kenward 1379cd2d5b52SBen Hutchings /* If RSS is requested for the PF *and* VFs then we can't write RSS 1380cd2d5b52SBen Hutchings * table entries that are inaccessible to VFs 1381cd2d5b52SBen Hutchings */ 13827fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 13837fa8d547SShradha Shah if (efx->type->sriov_wanted) { 1384d98a4ffeSShradha Shah if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 && 1385cd2d5b52SBen Hutchings count > efx_vf_size(efx)) { 1386cd2d5b52SBen Hutchings netif_warn(efx, probe, efx->net_dev, 1387cd2d5b52SBen Hutchings "Reducing number of RSS channels from %u to %u for " 1388cd2d5b52SBen Hutchings "VF support. Increase vf-msix-limit to use more " 1389cd2d5b52SBen Hutchings "channels on the PF.\n", 1390cd2d5b52SBen Hutchings count, efx_vf_size(efx)); 1391cd2d5b52SBen Hutchings count = efx_vf_size(efx); 1392cd2d5b52SBen Hutchings } 13937fa8d547SShradha Shah } 13947fa8d547SShradha Shah #endif 1395cd2d5b52SBen Hutchings 1396874aeea5SJeff Kirsher return count; 1397874aeea5SJeff Kirsher } 1398874aeea5SJeff Kirsher 1399874aeea5SJeff Kirsher /* Probe the number and type of interrupts we are able to obtain, and 1400874aeea5SJeff Kirsher * the resulting numbers of channels and RX queues. 1401874aeea5SJeff Kirsher */ 1402874aeea5SJeff Kirsher static int efx_probe_interrupts(struct efx_nic *efx) 1403874aeea5SJeff Kirsher { 14047f967c01SBen Hutchings unsigned int extra_channels = 0; 14057f967c01SBen Hutchings unsigned int i, j; 1406a16e5b24SBen Hutchings int rc; 1407874aeea5SJeff Kirsher 14087f967c01SBen Hutchings for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) 14097f967c01SBen Hutchings if (efx->extra_channel_type[i]) 14107f967c01SBen Hutchings ++extra_channels; 14117f967c01SBen Hutchings 1412874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { 1413874aeea5SJeff Kirsher struct msix_entry xentries[EFX_MAX_CHANNELS]; 1414a16e5b24SBen Hutchings unsigned int n_channels; 1415874aeea5SJeff Kirsher 1416a9a52506SBen Hutchings n_channels = efx_wanted_parallelism(efx); 1417b0fbdae1SShradha Shah if (efx_separate_tx_channels) 1418874aeea5SJeff Kirsher n_channels *= 2; 14197f967c01SBen Hutchings n_channels += extra_channels; 1420b105798fSBen Hutchings n_channels = min(n_channels, efx->max_channels); 1421874aeea5SJeff Kirsher 1422874aeea5SJeff Kirsher for (i = 0; i < n_channels; i++) 1423874aeea5SJeff Kirsher xentries[i].entry = i; 1424184603d8SAlexander Gordeev rc = pci_enable_msix_range(efx->pci_dev, 1425184603d8SAlexander Gordeev xentries, 1, n_channels); 1426184603d8SAlexander Gordeev if (rc < 0) { 1427184603d8SAlexander Gordeev /* Fall back to single channel MSI */ 1428184603d8SAlexander Gordeev netif_err(efx, drv, efx->net_dev, 1429184603d8SAlexander Gordeev "could not enable MSI-X\n"); 143062980cb6SAndrew Rybchenko if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI) 143162980cb6SAndrew Rybchenko efx->interrupt_mode = EFX_INT_MODE_MSI; 143262980cb6SAndrew Rybchenko else 143362980cb6SAndrew Rybchenko return rc; 1434184603d8SAlexander Gordeev } else if (rc < n_channels) { 1435874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1436874aeea5SJeff Kirsher "WARNING: Insufficient MSI-X vectors" 1437a16e5b24SBen Hutchings " available (%d < %u).\n", rc, n_channels); 1438874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1439874aeea5SJeff Kirsher "WARNING: Performance may be reduced.\n"); 1440874aeea5SJeff Kirsher n_channels = rc; 1441874aeea5SJeff Kirsher } 1442874aeea5SJeff Kirsher 1443184603d8SAlexander Gordeev if (rc > 0) { 1444874aeea5SJeff Kirsher efx->n_channels = n_channels; 14457f967c01SBen Hutchings if (n_channels > extra_channels) 14467f967c01SBen Hutchings n_channels -= extra_channels; 1447b0fbdae1SShradha Shah if (efx_separate_tx_channels) { 1448b0fbdae1SShradha Shah efx->n_tx_channels = min(max(n_channels / 2, 1449b0fbdae1SShradha Shah 1U), 1450b0fbdae1SShradha Shah efx->max_tx_channels); 14517f967c01SBen Hutchings efx->n_rx_channels = max(n_channels - 14527f967c01SBen Hutchings efx->n_tx_channels, 14537f967c01SBen Hutchings 1U); 1454874aeea5SJeff Kirsher } else { 1455b0fbdae1SShradha Shah efx->n_tx_channels = min(n_channels, 1456b0fbdae1SShradha Shah efx->max_tx_channels); 14577f967c01SBen Hutchings efx->n_rx_channels = n_channels; 1458874aeea5SJeff Kirsher } 14597f967c01SBen Hutchings for (i = 0; i < efx->n_channels; i++) 1460874aeea5SJeff Kirsher efx_get_channel(efx, i)->irq = 1461874aeea5SJeff Kirsher xentries[i].vector; 1462874aeea5SJeff Kirsher } 1463874aeea5SJeff Kirsher } 1464874aeea5SJeff Kirsher 1465874aeea5SJeff Kirsher /* Try single interrupt MSI */ 1466874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_MSI) { 1467874aeea5SJeff Kirsher efx->n_channels = 1; 1468874aeea5SJeff Kirsher efx->n_rx_channels = 1; 1469874aeea5SJeff Kirsher efx->n_tx_channels = 1; 1470874aeea5SJeff Kirsher rc = pci_enable_msi(efx->pci_dev); 1471874aeea5SJeff Kirsher if (rc == 0) { 1472874aeea5SJeff Kirsher efx_get_channel(efx, 0)->irq = efx->pci_dev->irq; 1473874aeea5SJeff Kirsher } else { 1474874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 1475874aeea5SJeff Kirsher "could not enable MSI\n"); 147662980cb6SAndrew Rybchenko if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY) 1477874aeea5SJeff Kirsher efx->interrupt_mode = EFX_INT_MODE_LEGACY; 147862980cb6SAndrew Rybchenko else 147962980cb6SAndrew Rybchenko return rc; 1480874aeea5SJeff Kirsher } 1481874aeea5SJeff Kirsher } 1482874aeea5SJeff Kirsher 1483874aeea5SJeff Kirsher /* Assume legacy interrupts */ 1484874aeea5SJeff Kirsher if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { 1485b0fbdae1SShradha Shah efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0); 1486874aeea5SJeff Kirsher efx->n_rx_channels = 1; 1487874aeea5SJeff Kirsher efx->n_tx_channels = 1; 1488874aeea5SJeff Kirsher efx->legacy_irq = efx->pci_dev->irq; 1489874aeea5SJeff Kirsher } 1490874aeea5SJeff Kirsher 14917f967c01SBen Hutchings /* Assign extra channels if possible */ 14927f967c01SBen Hutchings j = efx->n_channels; 14937f967c01SBen Hutchings for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { 14947f967c01SBen Hutchings if (!efx->extra_channel_type[i]) 14957f967c01SBen Hutchings continue; 14967f967c01SBen Hutchings if (efx->interrupt_mode != EFX_INT_MODE_MSIX || 14977f967c01SBen Hutchings efx->n_channels <= extra_channels) { 14987f967c01SBen Hutchings efx->extra_channel_type[i]->handle_no_channel(efx); 14997f967c01SBen Hutchings } else { 15007f967c01SBen Hutchings --j; 15017f967c01SBen Hutchings efx_get_channel(efx, j)->type = 15027f967c01SBen Hutchings efx->extra_channel_type[i]; 15037f967c01SBen Hutchings } 15047f967c01SBen Hutchings } 15057f967c01SBen Hutchings 1506cd2d5b52SBen Hutchings /* RSS might be usable on VFs even if it is disabled on the PF */ 15077fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 15087fa8d547SShradha Shah if (efx->type->sriov_wanted) { 1509327c685eSShradha Shah efx->rss_spread = ((efx->n_rx_channels > 1 || 1510d98a4ffeSShradha Shah !efx->type->sriov_wanted(efx)) ? 1511cd2d5b52SBen Hutchings efx->n_rx_channels : efx_vf_size(efx)); 15127fa8d547SShradha Shah return 0; 15137fa8d547SShradha Shah } 15147fa8d547SShradha Shah #endif 15157fa8d547SShradha Shah efx->rss_spread = efx->n_rx_channels; 1516cd2d5b52SBen Hutchings 1517874aeea5SJeff Kirsher return 0; 1518874aeea5SJeff Kirsher } 1519874aeea5SJeff Kirsher 1520261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx) 1521d8291187SBen Hutchings { 1522261e4d96SJon Cooper struct efx_channel *channel, *end_channel; 1523261e4d96SJon Cooper int rc; 1524d8291187SBen Hutchings 1525d8291187SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 1526d8291187SBen Hutchings 1527d8291187SBen Hutchings efx->irq_soft_enabled = true; 1528d8291187SBen Hutchings smp_wmb(); 1529d8291187SBen Hutchings 1530d8291187SBen Hutchings efx_for_each_channel(channel, efx) { 1531261e4d96SJon Cooper if (!channel->type->keep_eventq) { 1532261e4d96SJon Cooper rc = efx_init_eventq(channel); 1533261e4d96SJon Cooper if (rc) 1534261e4d96SJon Cooper goto fail; 1535261e4d96SJon Cooper } 1536d8291187SBen Hutchings efx_start_eventq(channel); 1537d8291187SBen Hutchings } 1538d8291187SBen Hutchings 1539d8291187SBen Hutchings efx_mcdi_mode_event(efx); 1540261e4d96SJon Cooper 1541261e4d96SJon Cooper return 0; 1542261e4d96SJon Cooper fail: 1543261e4d96SJon Cooper end_channel = channel; 1544261e4d96SJon Cooper efx_for_each_channel(channel, efx) { 1545261e4d96SJon Cooper if (channel == end_channel) 1546261e4d96SJon Cooper break; 1547261e4d96SJon Cooper efx_stop_eventq(channel); 1548261e4d96SJon Cooper if (!channel->type->keep_eventq) 1549261e4d96SJon Cooper efx_fini_eventq(channel); 1550261e4d96SJon Cooper } 1551261e4d96SJon Cooper 1552261e4d96SJon Cooper return rc; 1553d8291187SBen Hutchings } 1554d8291187SBen Hutchings 1555d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx) 1556d8291187SBen Hutchings { 1557d8291187SBen Hutchings struct efx_channel *channel; 1558d8291187SBen Hutchings 1559d8291187SBen Hutchings if (efx->state == STATE_DISABLED) 1560d8291187SBen Hutchings return; 1561d8291187SBen Hutchings 1562d8291187SBen Hutchings efx_mcdi_mode_poll(efx); 1563d8291187SBen Hutchings 1564d8291187SBen Hutchings efx->irq_soft_enabled = false; 1565d8291187SBen Hutchings smp_wmb(); 1566d8291187SBen Hutchings 1567d8291187SBen Hutchings if (efx->legacy_irq) 1568d8291187SBen Hutchings synchronize_irq(efx->legacy_irq); 1569d8291187SBen Hutchings 1570d8291187SBen Hutchings efx_for_each_channel(channel, efx) { 1571d8291187SBen Hutchings if (channel->irq) 1572d8291187SBen Hutchings synchronize_irq(channel->irq); 1573d8291187SBen Hutchings 1574d8291187SBen Hutchings efx_stop_eventq(channel); 1575d8291187SBen Hutchings if (!channel->type->keep_eventq) 1576d8291187SBen Hutchings efx_fini_eventq(channel); 1577d8291187SBen Hutchings } 1578cade715fSBen Hutchings 1579cade715fSBen Hutchings /* Flush the asynchronous MCDI request queue */ 1580cade715fSBen Hutchings efx_mcdi_flush_async(efx); 1581d8291187SBen Hutchings } 1582d8291187SBen Hutchings 1583261e4d96SJon Cooper static int efx_enable_interrupts(struct efx_nic *efx) 15849f2cb71cSBen Hutchings { 1585261e4d96SJon Cooper struct efx_channel *channel, *end_channel; 1586261e4d96SJon Cooper int rc; 15879f2cb71cSBen Hutchings 15888b7325b4SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 15898b7325b4SBen Hutchings 1590b28405b0SAlexandre Rames if (efx->eeh_disabled_legacy_irq) { 1591b28405b0SAlexandre Rames enable_irq(efx->legacy_irq); 1592b28405b0SAlexandre Rames efx->eeh_disabled_legacy_irq = false; 1593b28405b0SAlexandre Rames } 1594d8291187SBen Hutchings 159586094f7fSBen Hutchings efx->type->irq_enable_master(efx); 15969f2cb71cSBen Hutchings 15979f2cb71cSBen Hutchings efx_for_each_channel(channel, efx) { 1598261e4d96SJon Cooper if (channel->type->keep_eventq) { 1599261e4d96SJon Cooper rc = efx_init_eventq(channel); 1600261e4d96SJon Cooper if (rc) 1601261e4d96SJon Cooper goto fail; 1602261e4d96SJon Cooper } 16039f2cb71cSBen Hutchings } 16049f2cb71cSBen Hutchings 1605261e4d96SJon Cooper rc = efx_soft_enable_interrupts(efx); 1606261e4d96SJon Cooper if (rc) 1607261e4d96SJon Cooper goto fail; 1608261e4d96SJon Cooper 1609261e4d96SJon Cooper return 0; 1610261e4d96SJon Cooper 1611261e4d96SJon Cooper fail: 1612261e4d96SJon Cooper end_channel = channel; 1613261e4d96SJon Cooper efx_for_each_channel(channel, efx) { 1614261e4d96SJon Cooper if (channel == end_channel) 1615261e4d96SJon Cooper break; 1616261e4d96SJon Cooper if (channel->type->keep_eventq) 1617261e4d96SJon Cooper efx_fini_eventq(channel); 1618261e4d96SJon Cooper } 1619261e4d96SJon Cooper 1620261e4d96SJon Cooper efx->type->irq_disable_non_ev(efx); 1621261e4d96SJon Cooper 1622261e4d96SJon Cooper return rc; 16239f2cb71cSBen Hutchings } 16249f2cb71cSBen Hutchings 1625d8291187SBen Hutchings static void efx_disable_interrupts(struct efx_nic *efx) 16269f2cb71cSBen Hutchings { 16279f2cb71cSBen Hutchings struct efx_channel *channel; 16289f2cb71cSBen Hutchings 1629d8291187SBen Hutchings efx_soft_disable_interrupts(efx); 16309f2cb71cSBen Hutchings 16319f2cb71cSBen Hutchings efx_for_each_channel(channel, efx) { 1632d8291187SBen Hutchings if (channel->type->keep_eventq) 16339f2cb71cSBen Hutchings efx_fini_eventq(channel); 16349f2cb71cSBen Hutchings } 1635d8291187SBen Hutchings 163686094f7fSBen Hutchings efx->type->irq_disable_non_ev(efx); 16379f2cb71cSBen Hutchings } 16389f2cb71cSBen Hutchings 1639874aeea5SJeff Kirsher static void efx_remove_interrupts(struct efx_nic *efx) 1640874aeea5SJeff Kirsher { 1641874aeea5SJeff Kirsher struct efx_channel *channel; 1642874aeea5SJeff Kirsher 1643874aeea5SJeff Kirsher /* Remove MSI/MSI-X interrupts */ 1644874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 1645874aeea5SJeff Kirsher channel->irq = 0; 1646874aeea5SJeff Kirsher pci_disable_msi(efx->pci_dev); 1647874aeea5SJeff Kirsher pci_disable_msix(efx->pci_dev); 1648874aeea5SJeff Kirsher 1649874aeea5SJeff Kirsher /* Remove legacy interrupt */ 1650874aeea5SJeff Kirsher efx->legacy_irq = 0; 1651874aeea5SJeff Kirsher } 1652874aeea5SJeff Kirsher 1653874aeea5SJeff Kirsher static void efx_set_channels(struct efx_nic *efx) 1654874aeea5SJeff Kirsher { 1655874aeea5SJeff Kirsher struct efx_channel *channel; 1656874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 1657874aeea5SJeff Kirsher 1658874aeea5SJeff Kirsher efx->tx_channel_offset = 1659b0fbdae1SShradha Shah efx_separate_tx_channels ? 1660b0fbdae1SShradha Shah efx->n_channels - efx->n_tx_channels : 0; 1661874aeea5SJeff Kirsher 166279d68b37SStuart Hodgson /* We need to mark which channels really have RX and TX 166379d68b37SStuart Hodgson * queues, and adjust the TX queue numbers if we have separate 1664874aeea5SJeff Kirsher * RX-only and TX-only channels. 1665874aeea5SJeff Kirsher */ 1666874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 166779d68b37SStuart Hodgson if (channel->channel < efx->n_rx_channels) 166879d68b37SStuart Hodgson channel->rx_queue.core_index = channel->channel; 166979d68b37SStuart Hodgson else 167079d68b37SStuart Hodgson channel->rx_queue.core_index = -1; 167179d68b37SStuart Hodgson 1672874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 1673874aeea5SJeff Kirsher tx_queue->queue -= (efx->tx_channel_offset * 1674874aeea5SJeff Kirsher EFX_TXQ_TYPES); 1675874aeea5SJeff Kirsher } 1676874aeea5SJeff Kirsher } 1677874aeea5SJeff Kirsher 1678874aeea5SJeff Kirsher static int efx_probe_nic(struct efx_nic *efx) 1679874aeea5SJeff Kirsher { 1680874aeea5SJeff Kirsher int rc; 1681874aeea5SJeff Kirsher 1682874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); 1683874aeea5SJeff Kirsher 1684874aeea5SJeff Kirsher /* Carry out hardware-type specific initialisation */ 1685874aeea5SJeff Kirsher rc = efx->type->probe(efx); 1686874aeea5SJeff Kirsher if (rc) 1687874aeea5SJeff Kirsher return rc; 1688874aeea5SJeff Kirsher 1689b0fbdae1SShradha Shah do { 1690b0fbdae1SShradha Shah if (!efx->max_channels || !efx->max_tx_channels) { 1691b0fbdae1SShradha Shah netif_err(efx, drv, efx->net_dev, 1692b0fbdae1SShradha Shah "Insufficient resources to allocate" 1693b0fbdae1SShradha Shah " any channels\n"); 1694b0fbdae1SShradha Shah rc = -ENOSPC; 1695b0fbdae1SShradha Shah goto fail1; 1696b0fbdae1SShradha Shah } 1697b0fbdae1SShradha Shah 1698b0fbdae1SShradha Shah /* Determine the number of channels and queues by trying 1699b0fbdae1SShradha Shah * to hook in MSI-X interrupts. 1700b0fbdae1SShradha Shah */ 1701874aeea5SJeff Kirsher rc = efx_probe_interrupts(efx); 1702874aeea5SJeff Kirsher if (rc) 1703c15eed22SBen Hutchings goto fail1; 1704874aeea5SJeff Kirsher 170552ad762bSDaniel Pieczko efx_set_channels(efx); 170652ad762bSDaniel Pieczko 1707b0fbdae1SShradha Shah /* dimension_resources can fail with EAGAIN */ 1708c15eed22SBen Hutchings rc = efx->type->dimension_resources(efx); 1709b0fbdae1SShradha Shah if (rc != 0 && rc != -EAGAIN) 1710c15eed22SBen Hutchings goto fail2; 171128e47c49SBen Hutchings 1712b0fbdae1SShradha Shah if (rc == -EAGAIN) 1713b0fbdae1SShradha Shah /* try again with new max_channels */ 1714b0fbdae1SShradha Shah efx_remove_interrupts(efx); 1715b0fbdae1SShradha Shah 1716b0fbdae1SShradha Shah } while (rc == -EAGAIN); 1717b0fbdae1SShradha Shah 1718874aeea5SJeff Kirsher if (efx->n_channels > 1) 1719267c0157SJon Cooper netdev_rss_key_fill(&efx->rx_hash_key, 1720267c0157SJon Cooper sizeof(efx->rx_hash_key)); 1721267c0157SJon Cooper efx_set_default_rx_indir_table(efx); 1722874aeea5SJeff Kirsher 1723874aeea5SJeff Kirsher netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels); 1724874aeea5SJeff Kirsher netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels); 1725874aeea5SJeff Kirsher 1726874aeea5SJeff Kirsher /* Initialise the interrupt moderation settings */ 1727539de7c5SBert Kenward efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000); 17289e393b30SBen Hutchings efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, 17299e393b30SBen Hutchings true); 1730874aeea5SJeff Kirsher 1731874aeea5SJeff Kirsher return 0; 1732874aeea5SJeff Kirsher 1733c15eed22SBen Hutchings fail2: 1734c15eed22SBen Hutchings efx_remove_interrupts(efx); 1735c15eed22SBen Hutchings fail1: 1736874aeea5SJeff Kirsher efx->type->remove(efx); 1737874aeea5SJeff Kirsher return rc; 1738874aeea5SJeff Kirsher } 1739874aeea5SJeff Kirsher 1740874aeea5SJeff Kirsher static void efx_remove_nic(struct efx_nic *efx) 1741874aeea5SJeff Kirsher { 1742874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); 1743874aeea5SJeff Kirsher 1744874aeea5SJeff Kirsher efx_remove_interrupts(efx); 1745874aeea5SJeff Kirsher efx->type->remove(efx); 1746874aeea5SJeff Kirsher } 1747874aeea5SJeff Kirsher 1748add72477SBen Hutchings static int efx_probe_filters(struct efx_nic *efx) 1749add72477SBen Hutchings { 1750add72477SBen Hutchings int rc; 1751add72477SBen Hutchings 1752add72477SBen Hutchings spin_lock_init(&efx->filter_lock); 17530d322413SEdward Cree init_rwsem(&efx->filter_sem); 1754d248953aSMartin Habets mutex_lock(&efx->mac_lock); 17550d322413SEdward Cree down_write(&efx->filter_sem); 1756add72477SBen Hutchings rc = efx->type->filter_table_probe(efx); 1757add72477SBen Hutchings if (rc) 17580d322413SEdward Cree goto out_unlock; 1759add72477SBen Hutchings 1760add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL 1761add72477SBen Hutchings if (efx->type->offload_features & NETIF_F_NTUPLE) { 1762faf8dcc1SJon Cooper struct efx_channel *channel; 1763faf8dcc1SJon Cooper int i, success = 1; 1764faf8dcc1SJon Cooper 1765faf8dcc1SJon Cooper efx_for_each_channel(channel, efx) { 1766faf8dcc1SJon Cooper channel->rps_flow_id = 1767faf8dcc1SJon Cooper kcalloc(efx->type->max_rx_ip_filters, 1768faf8dcc1SJon Cooper sizeof(*channel->rps_flow_id), 1769add72477SBen Hutchings GFP_KERNEL); 1770faf8dcc1SJon Cooper if (!channel->rps_flow_id) 1771faf8dcc1SJon Cooper success = 0; 1772faf8dcc1SJon Cooper else 1773faf8dcc1SJon Cooper for (i = 0; 1774faf8dcc1SJon Cooper i < efx->type->max_rx_ip_filters; 1775faf8dcc1SJon Cooper ++i) 1776faf8dcc1SJon Cooper channel->rps_flow_id[i] = 1777faf8dcc1SJon Cooper RPS_FLOW_ID_INVALID; 1778faf8dcc1SJon Cooper } 1779faf8dcc1SJon Cooper 1780faf8dcc1SJon Cooper if (!success) { 1781faf8dcc1SJon Cooper efx_for_each_channel(channel, efx) 1782faf8dcc1SJon Cooper kfree(channel->rps_flow_id); 1783add72477SBen Hutchings efx->type->filter_table_remove(efx); 17840d322413SEdward Cree rc = -ENOMEM; 17850d322413SEdward Cree goto out_unlock; 1786add72477SBen Hutchings } 1787faf8dcc1SJon Cooper 1788faf8dcc1SJon Cooper efx->rps_expire_index = efx->rps_expire_channel = 0; 1789add72477SBen Hutchings } 1790add72477SBen Hutchings #endif 17910d322413SEdward Cree out_unlock: 17920d322413SEdward Cree up_write(&efx->filter_sem); 1793d248953aSMartin Habets mutex_unlock(&efx->mac_lock); 17940d322413SEdward Cree return rc; 1795add72477SBen Hutchings } 1796add72477SBen Hutchings 1797add72477SBen Hutchings static void efx_remove_filters(struct efx_nic *efx) 1798add72477SBen Hutchings { 1799add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL 1800faf8dcc1SJon Cooper struct efx_channel *channel; 1801faf8dcc1SJon Cooper 1802faf8dcc1SJon Cooper efx_for_each_channel(channel, efx) 1803faf8dcc1SJon Cooper kfree(channel->rps_flow_id); 1804add72477SBen Hutchings #endif 18050d322413SEdward Cree down_write(&efx->filter_sem); 1806add72477SBen Hutchings efx->type->filter_table_remove(efx); 18070d322413SEdward Cree up_write(&efx->filter_sem); 1808add72477SBen Hutchings } 1809add72477SBen Hutchings 1810add72477SBen Hutchings static void efx_restore_filters(struct efx_nic *efx) 1811add72477SBen Hutchings { 18120d322413SEdward Cree down_read(&efx->filter_sem); 1813add72477SBen Hutchings efx->type->filter_table_restore(efx); 18140d322413SEdward Cree up_read(&efx->filter_sem); 1815add72477SBen Hutchings } 1816add72477SBen Hutchings 1817874aeea5SJeff Kirsher /************************************************************************** 1818874aeea5SJeff Kirsher * 1819874aeea5SJeff Kirsher * NIC startup/shutdown 1820874aeea5SJeff Kirsher * 1821874aeea5SJeff Kirsher *************************************************************************/ 1822874aeea5SJeff Kirsher 1823874aeea5SJeff Kirsher static int efx_probe_all(struct efx_nic *efx) 1824874aeea5SJeff Kirsher { 1825874aeea5SJeff Kirsher int rc; 1826874aeea5SJeff Kirsher 1827874aeea5SJeff Kirsher rc = efx_probe_nic(efx); 1828874aeea5SJeff Kirsher if (rc) { 1829874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); 1830874aeea5SJeff Kirsher goto fail1; 1831874aeea5SJeff Kirsher } 1832874aeea5SJeff Kirsher 1833874aeea5SJeff Kirsher rc = efx_probe_port(efx); 1834874aeea5SJeff Kirsher if (rc) { 1835874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create port\n"); 1836874aeea5SJeff Kirsher goto fail2; 1837874aeea5SJeff Kirsher } 1838874aeea5SJeff Kirsher 18397e6d06f0SBen Hutchings BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); 18407e6d06f0SBen Hutchings if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { 18417e6d06f0SBen Hutchings rc = -EINVAL; 18427e6d06f0SBen Hutchings goto fail3; 18437e6d06f0SBen Hutchings } 1844874aeea5SJeff Kirsher efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE; 1845874aeea5SJeff Kirsher 18466d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 18476d8aaaf6SDaniel Pieczko rc = efx->type->vswitching_probe(efx); 18486d8aaaf6SDaniel Pieczko if (rc) /* not fatal; the PF will still work fine */ 18496d8aaaf6SDaniel Pieczko netif_warn(efx, probe, efx->net_dev, 18506d8aaaf6SDaniel Pieczko "failed to setup vswitching rc=%d;" 18516d8aaaf6SDaniel Pieczko " VFs may not function\n", rc); 18526d8aaaf6SDaniel Pieczko #endif 18536d8aaaf6SDaniel Pieczko 1854874aeea5SJeff Kirsher rc = efx_probe_filters(efx); 1855874aeea5SJeff Kirsher if (rc) { 1856874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 1857874aeea5SJeff Kirsher "failed to create filter tables\n"); 18586d8aaaf6SDaniel Pieczko goto fail4; 1859874aeea5SJeff Kirsher } 1860874aeea5SJeff Kirsher 18617f967c01SBen Hutchings rc = efx_probe_channels(efx); 18627f967c01SBen Hutchings if (rc) 18636d8aaaf6SDaniel Pieczko goto fail5; 18647f967c01SBen Hutchings 1865874aeea5SJeff Kirsher return 0; 1866874aeea5SJeff Kirsher 18676d8aaaf6SDaniel Pieczko fail5: 18687f967c01SBen Hutchings efx_remove_filters(efx); 18696d8aaaf6SDaniel Pieczko fail4: 18706d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 18716d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 18726d8aaaf6SDaniel Pieczko #endif 1873874aeea5SJeff Kirsher fail3: 1874874aeea5SJeff Kirsher efx_remove_port(efx); 1875874aeea5SJeff Kirsher fail2: 1876874aeea5SJeff Kirsher efx_remove_nic(efx); 1877874aeea5SJeff Kirsher fail1: 1878874aeea5SJeff Kirsher return rc; 1879874aeea5SJeff Kirsher } 1880874aeea5SJeff Kirsher 18818b7325b4SBen Hutchings /* If the interface is supposed to be running but is not, start 18828b7325b4SBen Hutchings * the hardware and software data path, regular activity for the port 18838b7325b4SBen Hutchings * (MAC statistics, link polling, etc.) and schedule the port to be 18848b7325b4SBen Hutchings * reconfigured. Interrupts must already be enabled. This function 18858b7325b4SBen Hutchings * is safe to call multiple times, so long as the NIC is not disabled. 18868b7325b4SBen Hutchings * Requires the RTNL lock. 18879f2cb71cSBen Hutchings */ 1888874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx) 1889874aeea5SJeff Kirsher { 1890874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 18918b7325b4SBen Hutchings BUG_ON(efx->state == STATE_DISABLED); 1892874aeea5SJeff Kirsher 1893874aeea5SJeff Kirsher /* Check that it is appropriate to restart the interface. All 1894874aeea5SJeff Kirsher * of these flags are safe to read under just the rtnl lock */ 1895e283546cSEdward Cree if (efx->port_enabled || !netif_running(efx->net_dev) || 1896e283546cSEdward Cree efx->reset_pending) 1897874aeea5SJeff Kirsher return; 1898874aeea5SJeff Kirsher 1899874aeea5SJeff Kirsher efx_start_port(efx); 19009f2cb71cSBen Hutchings efx_start_datapath(efx); 1901874aeea5SJeff Kirsher 1902626950dbSAlexandre Rames /* Start the hardware monitor if there is one */ 1903626950dbSAlexandre Rames if (efx->type->monitor != NULL) 1904874aeea5SJeff Kirsher queue_delayed_work(efx->workqueue, &efx->monitor_work, 1905874aeea5SJeff Kirsher efx_monitor_interval); 1906626950dbSAlexandre Rames 19075a6681e2SEdward Cree /* Link state detection is normally event-driven; we have 1908626950dbSAlexandre Rames * to poll now because we could have missed a change 1909626950dbSAlexandre Rames */ 1910874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1911874aeea5SJeff Kirsher if (efx->phy_op->poll(efx)) 1912874aeea5SJeff Kirsher efx_link_status_changed(efx); 1913874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1914874aeea5SJeff Kirsher 1915874aeea5SJeff Kirsher efx->type->start_stats(efx); 1916f8f3b5aeSJon Cooper efx->type->pull_stats(efx); 1917f8f3b5aeSJon Cooper spin_lock_bh(&efx->stats_lock); 1918f8f3b5aeSJon Cooper efx->type->update_stats(efx, NULL, NULL); 1919f8f3b5aeSJon Cooper spin_unlock_bh(&efx->stats_lock); 1920874aeea5SJeff Kirsher } 1921874aeea5SJeff Kirsher 19228b7325b4SBen Hutchings /* Quiesce the hardware and software data path, and regular activity 19238b7325b4SBen Hutchings * for the port without bringing the link down. Safe to call multiple 19248b7325b4SBen Hutchings * times with the NIC in almost any state, but interrupts should be 19258b7325b4SBen Hutchings * enabled. Requires the RTNL lock. 19268b7325b4SBen Hutchings */ 1927874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx) 1928874aeea5SJeff Kirsher { 1929874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 1930874aeea5SJeff Kirsher 1931874aeea5SJeff Kirsher /* port_enabled can be read safely under the rtnl lock */ 1932874aeea5SJeff Kirsher if (!efx->port_enabled) 1933874aeea5SJeff Kirsher return; 1934874aeea5SJeff Kirsher 1935f8f3b5aeSJon Cooper /* update stats before we go down so we can accurately count 1936f8f3b5aeSJon Cooper * rx_nodesc_drops 1937f8f3b5aeSJon Cooper */ 1938f8f3b5aeSJon Cooper efx->type->pull_stats(efx); 1939f8f3b5aeSJon Cooper spin_lock_bh(&efx->stats_lock); 1940f8f3b5aeSJon Cooper efx->type->update_stats(efx, NULL, NULL); 1941f8f3b5aeSJon Cooper spin_unlock_bh(&efx->stats_lock); 1942874aeea5SJeff Kirsher efx->type->stop_stats(efx); 1943874aeea5SJeff Kirsher efx_stop_port(efx); 1944874aeea5SJeff Kirsher 194529c69a48SBen Hutchings /* Stop the kernel transmit interface. This is only valid if 194629c69a48SBen Hutchings * the device is stopped or detached; otherwise the watchdog 194729c69a48SBen Hutchings * may fire immediately. 194829c69a48SBen Hutchings */ 194929c69a48SBen Hutchings WARN_ON(netif_running(efx->net_dev) && 195029c69a48SBen Hutchings netif_device_present(efx->net_dev)); 19519f2cb71cSBen Hutchings netif_tx_disable(efx->net_dev); 19529f2cb71cSBen Hutchings 19539f2cb71cSBen Hutchings efx_stop_datapath(efx); 1954874aeea5SJeff Kirsher } 1955874aeea5SJeff Kirsher 1956874aeea5SJeff Kirsher static void efx_remove_all(struct efx_nic *efx) 1957874aeea5SJeff Kirsher { 1958874aeea5SJeff Kirsher efx_remove_channels(efx); 19597f967c01SBen Hutchings efx_remove_filters(efx); 19606d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 19616d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 19626d8aaaf6SDaniel Pieczko #endif 1963874aeea5SJeff Kirsher efx_remove_port(efx); 1964874aeea5SJeff Kirsher efx_remove_nic(efx); 1965874aeea5SJeff Kirsher } 1966874aeea5SJeff Kirsher 1967874aeea5SJeff Kirsher /************************************************************************** 1968874aeea5SJeff Kirsher * 1969874aeea5SJeff Kirsher * Interrupt moderation 1970874aeea5SJeff Kirsher * 1971874aeea5SJeff Kirsher **************************************************************************/ 1972539de7c5SBert Kenward unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs) 1973874aeea5SJeff Kirsher { 1974b548f976SBen Hutchings if (usecs == 0) 1975b548f976SBen Hutchings return 0; 1976539de7c5SBert Kenward if (usecs * 1000 < efx->timer_quantum_ns) 1977874aeea5SJeff Kirsher return 1; /* never round down to 0 */ 1978539de7c5SBert Kenward return usecs * 1000 / efx->timer_quantum_ns; 1979539de7c5SBert Kenward } 1980539de7c5SBert Kenward 1981539de7c5SBert Kenward unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks) 1982539de7c5SBert Kenward { 1983539de7c5SBert Kenward /* We must round up when converting ticks to microseconds 1984539de7c5SBert Kenward * because we round down when converting the other way. 1985539de7c5SBert Kenward */ 1986539de7c5SBert Kenward return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000); 1987874aeea5SJeff Kirsher } 1988874aeea5SJeff Kirsher 1989874aeea5SJeff Kirsher /* Set interrupt moderation parameters */ 19909e393b30SBen Hutchings int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, 19919e393b30SBen Hutchings unsigned int rx_usecs, bool rx_adaptive, 19929e393b30SBen Hutchings bool rx_may_override_tx) 1993874aeea5SJeff Kirsher { 1994874aeea5SJeff Kirsher struct efx_channel *channel; 1995d95e329aSBert Kenward unsigned int timer_max_us; 1996d95e329aSBert Kenward 1997874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 1998874aeea5SJeff Kirsher 1999d95e329aSBert Kenward timer_max_us = efx->timer_max_ns / 1000; 2000d95e329aSBert Kenward 2001d95e329aSBert Kenward if (tx_usecs > timer_max_us || rx_usecs > timer_max_us) 20029e393b30SBen Hutchings return -EINVAL; 20039e393b30SBen Hutchings 2004539de7c5SBert Kenward if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 && 20059e393b30SBen Hutchings !rx_may_override_tx) { 20069e393b30SBen Hutchings netif_err(efx, drv, efx->net_dev, "Channels are shared. " 20079e393b30SBen Hutchings "RX and TX IRQ moderation must be equal\n"); 20089e393b30SBen Hutchings return -EINVAL; 20099e393b30SBen Hutchings } 20109e393b30SBen Hutchings 2011874aeea5SJeff Kirsher efx->irq_rx_adaptive = rx_adaptive; 2012539de7c5SBert Kenward efx->irq_rx_moderation_us = rx_usecs; 2013874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 2014874aeea5SJeff Kirsher if (efx_channel_has_rx_queue(channel)) 2015539de7c5SBert Kenward channel->irq_moderation_us = rx_usecs; 2016874aeea5SJeff Kirsher else if (efx_channel_has_tx_queues(channel)) 2017539de7c5SBert Kenward channel->irq_moderation_us = tx_usecs; 2018874aeea5SJeff Kirsher } 20199e393b30SBen Hutchings 20209e393b30SBen Hutchings return 0; 2021874aeea5SJeff Kirsher } 2022874aeea5SJeff Kirsher 2023a0c4faf5SBen Hutchings void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, 2024a0c4faf5SBen Hutchings unsigned int *rx_usecs, bool *rx_adaptive) 2025a0c4faf5SBen Hutchings { 2026a0c4faf5SBen Hutchings *rx_adaptive = efx->irq_rx_adaptive; 2027539de7c5SBert Kenward *rx_usecs = efx->irq_rx_moderation_us; 2028a0c4faf5SBen Hutchings 2029a0c4faf5SBen Hutchings /* If channels are shared between RX and TX, so is IRQ 2030a0c4faf5SBen Hutchings * moderation. Otherwise, IRQ moderation is the same for all 2031a0c4faf5SBen Hutchings * TX channels and is not adaptive. 2032a0c4faf5SBen Hutchings */ 2033539de7c5SBert Kenward if (efx->tx_channel_offset == 0) { 2034a0c4faf5SBen Hutchings *tx_usecs = *rx_usecs; 2035539de7c5SBert Kenward } else { 2036539de7c5SBert Kenward struct efx_channel *tx_channel; 2037539de7c5SBert Kenward 2038539de7c5SBert Kenward tx_channel = efx->channel[efx->tx_channel_offset]; 2039539de7c5SBert Kenward *tx_usecs = tx_channel->irq_moderation_us; 2040539de7c5SBert Kenward } 2041a0c4faf5SBen Hutchings } 2042a0c4faf5SBen Hutchings 2043874aeea5SJeff Kirsher /************************************************************************** 2044874aeea5SJeff Kirsher * 2045874aeea5SJeff Kirsher * Hardware monitor 2046874aeea5SJeff Kirsher * 2047874aeea5SJeff Kirsher **************************************************************************/ 2048874aeea5SJeff Kirsher 2049874aeea5SJeff Kirsher /* Run periodically off the general workqueue */ 2050874aeea5SJeff Kirsher static void efx_monitor(struct work_struct *data) 2051874aeea5SJeff Kirsher { 2052874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, 2053874aeea5SJeff Kirsher monitor_work.work); 2054874aeea5SJeff Kirsher 2055874aeea5SJeff Kirsher netif_vdbg(efx, timer, efx->net_dev, 2056874aeea5SJeff Kirsher "hardware monitor executing on CPU %d\n", 2057874aeea5SJeff Kirsher raw_smp_processor_id()); 2058874aeea5SJeff Kirsher BUG_ON(efx->type->monitor == NULL); 2059874aeea5SJeff Kirsher 2060874aeea5SJeff Kirsher /* If the mac_lock is already held then it is likely a port 2061874aeea5SJeff Kirsher * reconfiguration is already in place, which will likely do 2062874aeea5SJeff Kirsher * most of the work of monitor() anyway. */ 2063874aeea5SJeff Kirsher if (mutex_trylock(&efx->mac_lock)) { 2064874aeea5SJeff Kirsher if (efx->port_enabled) 2065874aeea5SJeff Kirsher efx->type->monitor(efx); 2066874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2067874aeea5SJeff Kirsher } 2068874aeea5SJeff Kirsher 2069874aeea5SJeff Kirsher queue_delayed_work(efx->workqueue, &efx->monitor_work, 2070874aeea5SJeff Kirsher efx_monitor_interval); 2071874aeea5SJeff Kirsher } 2072874aeea5SJeff Kirsher 2073874aeea5SJeff Kirsher /************************************************************************** 2074874aeea5SJeff Kirsher * 2075874aeea5SJeff Kirsher * ioctls 2076874aeea5SJeff Kirsher * 2077874aeea5SJeff Kirsher *************************************************************************/ 2078874aeea5SJeff Kirsher 2079874aeea5SJeff Kirsher /* Net device ioctl 2080874aeea5SJeff Kirsher * Context: process, rtnl_lock() held. 2081874aeea5SJeff Kirsher */ 2082874aeea5SJeff Kirsher static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) 2083874aeea5SJeff Kirsher { 2084874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2085874aeea5SJeff Kirsher struct mii_ioctl_data *data = if_mii(ifr); 2086874aeea5SJeff Kirsher 20877c236c43SStuart Hodgson if (cmd == SIOCSHWTSTAMP) 2088433dc9b3SBen Hutchings return efx_ptp_set_ts_config(efx, ifr); 2089433dc9b3SBen Hutchings if (cmd == SIOCGHWTSTAMP) 2090433dc9b3SBen Hutchings return efx_ptp_get_ts_config(efx, ifr); 20917c236c43SStuart Hodgson 2092874aeea5SJeff Kirsher /* Convert phy_id from older PRTAD/DEVAD format */ 2093874aeea5SJeff Kirsher if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && 2094874aeea5SJeff Kirsher (data->phy_id & 0xfc00) == 0x0400) 2095874aeea5SJeff Kirsher data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; 2096874aeea5SJeff Kirsher 2097874aeea5SJeff Kirsher return mdio_mii_ioctl(&efx->mdio, data, cmd); 2098874aeea5SJeff Kirsher } 2099874aeea5SJeff Kirsher 2100874aeea5SJeff Kirsher /************************************************************************** 2101874aeea5SJeff Kirsher * 2102874aeea5SJeff Kirsher * NAPI interface 2103874aeea5SJeff Kirsher * 2104874aeea5SJeff Kirsher **************************************************************************/ 2105874aeea5SJeff Kirsher 21067f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel) 2107874aeea5SJeff Kirsher { 21087f967c01SBen Hutchings struct efx_nic *efx = channel->efx; 2109874aeea5SJeff Kirsher 2110874aeea5SJeff Kirsher channel->napi_dev = efx->net_dev; 2111874aeea5SJeff Kirsher netif_napi_add(channel->napi_dev, &channel->napi_str, 2112874aeea5SJeff Kirsher efx_poll, napi_weight); 2113874aeea5SJeff Kirsher } 21147f967c01SBen Hutchings 21157f967c01SBen Hutchings static void efx_init_napi(struct efx_nic *efx) 21167f967c01SBen Hutchings { 21177f967c01SBen Hutchings struct efx_channel *channel; 21187f967c01SBen Hutchings 21197f967c01SBen Hutchings efx_for_each_channel(channel, efx) 21207f967c01SBen Hutchings efx_init_napi_channel(channel); 2121874aeea5SJeff Kirsher } 2122874aeea5SJeff Kirsher 2123874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel) 2124874aeea5SJeff Kirsher { 2125973334a1SEric Dumazet if (channel->napi_dev) 2126874aeea5SJeff Kirsher netif_napi_del(&channel->napi_str); 2127973334a1SEric Dumazet 2128874aeea5SJeff Kirsher channel->napi_dev = NULL; 2129874aeea5SJeff Kirsher } 2130874aeea5SJeff Kirsher 2131874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx) 2132874aeea5SJeff Kirsher { 2133874aeea5SJeff Kirsher struct efx_channel *channel; 2134874aeea5SJeff Kirsher 2135874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 2136874aeea5SJeff Kirsher efx_fini_napi_channel(channel); 2137874aeea5SJeff Kirsher } 2138874aeea5SJeff Kirsher 2139874aeea5SJeff Kirsher /************************************************************************** 2140874aeea5SJeff Kirsher * 2141874aeea5SJeff Kirsher * Kernel netpoll interface 2142874aeea5SJeff Kirsher * 2143874aeea5SJeff Kirsher *************************************************************************/ 2144874aeea5SJeff Kirsher 2145874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2146874aeea5SJeff Kirsher 2147874aeea5SJeff Kirsher /* Although in the common case interrupts will be disabled, this is not 2148874aeea5SJeff Kirsher * guaranteed. However, all our work happens inside the NAPI callback, 2149874aeea5SJeff Kirsher * so no locking is required. 2150874aeea5SJeff Kirsher */ 2151874aeea5SJeff Kirsher static void efx_netpoll(struct net_device *net_dev) 2152874aeea5SJeff Kirsher { 2153874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2154874aeea5SJeff Kirsher struct efx_channel *channel; 2155874aeea5SJeff Kirsher 2156874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) 2157874aeea5SJeff Kirsher efx_schedule_channel(channel); 2158874aeea5SJeff Kirsher } 2159874aeea5SJeff Kirsher 2160874aeea5SJeff Kirsher #endif 2161874aeea5SJeff Kirsher 2162874aeea5SJeff Kirsher /************************************************************************** 2163874aeea5SJeff Kirsher * 2164874aeea5SJeff Kirsher * Kernel net device interface 2165874aeea5SJeff Kirsher * 2166874aeea5SJeff Kirsher *************************************************************************/ 2167874aeea5SJeff Kirsher 2168874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */ 2169e340be92SShradha Shah int efx_net_open(struct net_device *net_dev) 2170874aeea5SJeff Kirsher { 2171874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 21728b7325b4SBen Hutchings int rc; 21738b7325b4SBen Hutchings 2174874aeea5SJeff Kirsher netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", 2175874aeea5SJeff Kirsher raw_smp_processor_id()); 2176874aeea5SJeff Kirsher 21778b7325b4SBen Hutchings rc = efx_check_disabled(efx); 21788b7325b4SBen Hutchings if (rc) 21798b7325b4SBen Hutchings return rc; 2180874aeea5SJeff Kirsher if (efx->phy_mode & PHY_MODE_SPECIAL) 2181874aeea5SJeff Kirsher return -EBUSY; 2182874aeea5SJeff Kirsher if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) 2183874aeea5SJeff Kirsher return -EIO; 2184874aeea5SJeff Kirsher 2185874aeea5SJeff Kirsher /* Notify the kernel of the link state polled during driver load, 2186874aeea5SJeff Kirsher * before the monitor starts running */ 2187874aeea5SJeff Kirsher efx_link_status_changed(efx); 2188874aeea5SJeff Kirsher 2189874aeea5SJeff Kirsher efx_start_all(efx); 21909c568fd8SPeter Dunning if (efx->state == STATE_DISABLED || efx->reset_pending) 21919c568fd8SPeter Dunning netif_device_detach(efx->net_dev); 2192dd40781eSBen Hutchings efx_selftest_async_start(efx); 2193874aeea5SJeff Kirsher return 0; 2194874aeea5SJeff Kirsher } 2195874aeea5SJeff Kirsher 2196874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. 2197874aeea5SJeff Kirsher * Note that the kernel will ignore our return code; this method 2198874aeea5SJeff Kirsher * should really be a void. 2199874aeea5SJeff Kirsher */ 2200e340be92SShradha Shah int efx_net_stop(struct net_device *net_dev) 2201874aeea5SJeff Kirsher { 2202874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2203874aeea5SJeff Kirsher 2204874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", 2205874aeea5SJeff Kirsher raw_smp_processor_id()); 2206874aeea5SJeff Kirsher 2207874aeea5SJeff Kirsher /* Stop the device and flush all the channels */ 2208874aeea5SJeff Kirsher efx_stop_all(efx); 2209874aeea5SJeff Kirsher 2210874aeea5SJeff Kirsher return 0; 2211874aeea5SJeff Kirsher } 2212874aeea5SJeff Kirsher 2213874aeea5SJeff Kirsher /* Context: process, dev_base_lock or RTNL held, non-blocking. */ 2214bc1f4470Sstephen hemminger static void efx_net_stats(struct net_device *net_dev, 22152aa9ef11SBen Hutchings struct rtnl_link_stats64 *stats) 2216874aeea5SJeff Kirsher { 2217874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2218874aeea5SJeff Kirsher 2219874aeea5SJeff Kirsher spin_lock_bh(&efx->stats_lock); 2220cd0ecc9aSBen Hutchings efx->type->update_stats(efx, NULL, stats); 22211cb34522SBen Hutchings spin_unlock_bh(&efx->stats_lock); 2222874aeea5SJeff Kirsher } 2223874aeea5SJeff Kirsher 2224874aeea5SJeff Kirsher /* Context: netif_tx_lock held, BHs disabled. */ 2225874aeea5SJeff Kirsher static void efx_watchdog(struct net_device *net_dev) 2226874aeea5SJeff Kirsher { 2227874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2228874aeea5SJeff Kirsher 2229874aeea5SJeff Kirsher netif_err(efx, tx_err, efx->net_dev, 2230874aeea5SJeff Kirsher "TX stuck with port_enabled=%d: resetting channels\n", 2231874aeea5SJeff Kirsher efx->port_enabled); 2232874aeea5SJeff Kirsher 2233874aeea5SJeff Kirsher efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); 2234874aeea5SJeff Kirsher } 2235874aeea5SJeff Kirsher 2236874aeea5SJeff Kirsher 2237874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */ 2238874aeea5SJeff Kirsher static int efx_change_mtu(struct net_device *net_dev, int new_mtu) 2239874aeea5SJeff Kirsher { 2240874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 22418b7325b4SBen Hutchings int rc; 2242874aeea5SJeff Kirsher 22438b7325b4SBen Hutchings rc = efx_check_disabled(efx); 22448b7325b4SBen Hutchings if (rc) 22458b7325b4SBen Hutchings return rc; 2246874aeea5SJeff Kirsher 2247874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu); 2248874aeea5SJeff Kirsher 224929c69a48SBen Hutchings efx_device_detach_sync(efx); 225029c69a48SBen Hutchings efx_stop_all(efx); 225129c69a48SBen Hutchings 2252874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 2253874aeea5SJeff Kirsher net_dev->mtu = new_mtu; 22540d322413SEdward Cree efx_mac_reconfigure(efx); 2255874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2256874aeea5SJeff Kirsher 2257874aeea5SJeff Kirsher efx_start_all(efx); 22589c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 22596c8eef4aSBen Hutchings return 0; 2260874aeea5SJeff Kirsher } 2261874aeea5SJeff Kirsher 2262874aeea5SJeff Kirsher static int efx_set_mac_address(struct net_device *net_dev, void *data) 2263874aeea5SJeff Kirsher { 2264874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2265874aeea5SJeff Kirsher struct sockaddr *addr = data; 2266e0b3ae30SBen Hutchings u8 *new_addr = addr->sa_data; 2267cfc77c2fSShradha Shah u8 old_addr[6]; 2268cfc77c2fSShradha Shah int rc; 2269874aeea5SJeff Kirsher 2270874aeea5SJeff Kirsher if (!is_valid_ether_addr(new_addr)) { 2271874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2272874aeea5SJeff Kirsher "invalid ethernet MAC address requested: %pM\n", 2273874aeea5SJeff Kirsher new_addr); 2274504f9b5aSDanny Kukawka return -EADDRNOTAVAIL; 2275874aeea5SJeff Kirsher } 2276874aeea5SJeff Kirsher 2277cfc77c2fSShradha Shah /* save old address */ 2278cfc77c2fSShradha Shah ether_addr_copy(old_addr, net_dev->dev_addr); 2279cd84ff4dSEdward Cree ether_addr_copy(net_dev->dev_addr, new_addr); 2280910c8789SShradha Shah if (efx->type->set_mac_address) { 2281910c8789SShradha Shah rc = efx->type->set_mac_address(efx); 2282cfc77c2fSShradha Shah if (rc) { 2283cfc77c2fSShradha Shah ether_addr_copy(net_dev->dev_addr, old_addr); 2284cfc77c2fSShradha Shah return rc; 2285cfc77c2fSShradha Shah } 2286cfc77c2fSShradha Shah } 2287874aeea5SJeff Kirsher 2288874aeea5SJeff Kirsher /* Reconfigure the MAC */ 2289874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 22900d322413SEdward Cree efx_mac_reconfigure(efx); 2291874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2292874aeea5SJeff Kirsher 2293874aeea5SJeff Kirsher return 0; 2294874aeea5SJeff Kirsher } 2295874aeea5SJeff Kirsher 2296874aeea5SJeff Kirsher /* Context: netif_addr_lock held, BHs disabled. */ 22970fca8c97SBen Hutchings static void efx_set_rx_mode(struct net_device *net_dev) 2298874aeea5SJeff Kirsher { 2299874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 2300874aeea5SJeff Kirsher 2301874aeea5SJeff Kirsher if (efx->port_enabled) 2302874aeea5SJeff Kirsher queue_work(efx->workqueue, &efx->mac_work); 2303874aeea5SJeff Kirsher /* Otherwise efx_start_port() will do this */ 2304874aeea5SJeff Kirsher } 2305874aeea5SJeff Kirsher 2306c8f44affSMichał Mirosław static int efx_set_features(struct net_device *net_dev, netdev_features_t data) 2307874aeea5SJeff Kirsher { 2308874aeea5SJeff Kirsher struct efx_nic *efx = netdev_priv(net_dev); 23094a53ea8aSAndrew Rybchenko int rc; 2310874aeea5SJeff Kirsher 2311874aeea5SJeff Kirsher /* If disabling RX n-tuple filtering, clear existing filters */ 23124a53ea8aSAndrew Rybchenko if (net_dev->features & ~data & NETIF_F_NTUPLE) { 23134a53ea8aSAndrew Rybchenko rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); 23144a53ea8aSAndrew Rybchenko if (rc) 23154a53ea8aSAndrew Rybchenko return rc; 23164a53ea8aSAndrew Rybchenko } 23174a53ea8aSAndrew Rybchenko 23184a53ea8aSAndrew Rybchenko /* If Rx VLAN filter is changed, update filters via mac_reconfigure */ 23194a53ea8aSAndrew Rybchenko if ((net_dev->features ^ data) & NETIF_F_HW_VLAN_CTAG_FILTER) { 23204a53ea8aSAndrew Rybchenko /* efx_set_rx_mode() will schedule MAC work to update filters 23214a53ea8aSAndrew Rybchenko * when a new features are finally set in net_dev. 23224a53ea8aSAndrew Rybchenko */ 23234a53ea8aSAndrew Rybchenko efx_set_rx_mode(net_dev); 23244a53ea8aSAndrew Rybchenko } 2325874aeea5SJeff Kirsher 2326874aeea5SJeff Kirsher return 0; 2327874aeea5SJeff Kirsher } 2328874aeea5SJeff Kirsher 2329b40296fcSWei Yongjun static int efx_get_phys_port_id(struct net_device *net_dev, 233008a7b29bSBert Kenward struct netdev_phys_item_id *ppid) 233108a7b29bSBert Kenward { 233208a7b29bSBert Kenward struct efx_nic *efx = netdev_priv(net_dev); 233308a7b29bSBert Kenward 233408a7b29bSBert Kenward if (efx->type->get_phys_port_id) 233508a7b29bSBert Kenward return efx->type->get_phys_port_id(efx, ppid); 233608a7b29bSBert Kenward else 233708a7b29bSBert Kenward return -EOPNOTSUPP; 233808a7b29bSBert Kenward } 233908a7b29bSBert Kenward 2340ac019f08SBert Kenward static int efx_get_phys_port_name(struct net_device *net_dev, 2341ac019f08SBert Kenward char *name, size_t len) 2342ac019f08SBert Kenward { 2343ac019f08SBert Kenward struct efx_nic *efx = netdev_priv(net_dev); 2344ac019f08SBert Kenward 2345ac019f08SBert Kenward if (snprintf(name, len, "p%u", efx->port_num) >= len) 2346ac019f08SBert Kenward return -EINVAL; 2347ac019f08SBert Kenward return 0; 2348ac019f08SBert Kenward } 2349ac019f08SBert Kenward 23504a53ea8aSAndrew Rybchenko static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid) 23514a53ea8aSAndrew Rybchenko { 23524a53ea8aSAndrew Rybchenko struct efx_nic *efx = netdev_priv(net_dev); 23534a53ea8aSAndrew Rybchenko 23544a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_add_vid) 23554a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_add_vid(efx, proto, vid); 23564a53ea8aSAndrew Rybchenko else 23574a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 23584a53ea8aSAndrew Rybchenko } 23594a53ea8aSAndrew Rybchenko 23604a53ea8aSAndrew Rybchenko static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid) 23614a53ea8aSAndrew Rybchenko { 23624a53ea8aSAndrew Rybchenko struct efx_nic *efx = netdev_priv(net_dev); 23634a53ea8aSAndrew Rybchenko 23644a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_kill_vid) 23654a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_kill_vid(efx, proto, vid); 23664a53ea8aSAndrew Rybchenko else 23674a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 23684a53ea8aSAndrew Rybchenko } 23694a53ea8aSAndrew Rybchenko 2370e5fbd977SJon Cooper static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in) 2371e5fbd977SJon Cooper { 2372e5fbd977SJon Cooper switch (in) { 2373e5fbd977SJon Cooper case UDP_TUNNEL_TYPE_VXLAN: 2374e5fbd977SJon Cooper return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN; 2375e5fbd977SJon Cooper case UDP_TUNNEL_TYPE_GENEVE: 2376e5fbd977SJon Cooper return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE; 2377e5fbd977SJon Cooper default: 2378e5fbd977SJon Cooper return -1; 2379e5fbd977SJon Cooper } 2380e5fbd977SJon Cooper } 2381e5fbd977SJon Cooper 2382e5fbd977SJon Cooper static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti) 2383e5fbd977SJon Cooper { 2384e5fbd977SJon Cooper struct efx_nic *efx = netdev_priv(dev); 2385e5fbd977SJon Cooper struct efx_udp_tunnel tnl; 2386e5fbd977SJon Cooper int efx_tunnel_type; 2387e5fbd977SJon Cooper 2388e5fbd977SJon Cooper efx_tunnel_type = efx_udp_tunnel_type_map(ti->type); 2389e5fbd977SJon Cooper if (efx_tunnel_type < 0) 2390e5fbd977SJon Cooper return; 2391e5fbd977SJon Cooper 2392e5fbd977SJon Cooper tnl.type = (u16)efx_tunnel_type; 2393e5fbd977SJon Cooper tnl.port = ti->port; 2394e5fbd977SJon Cooper 2395e5fbd977SJon Cooper if (efx->type->udp_tnl_add_port) 2396e5fbd977SJon Cooper (void)efx->type->udp_tnl_add_port(efx, tnl); 2397e5fbd977SJon Cooper } 2398e5fbd977SJon Cooper 2399e5fbd977SJon Cooper static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti) 2400e5fbd977SJon Cooper { 2401e5fbd977SJon Cooper struct efx_nic *efx = netdev_priv(dev); 2402e5fbd977SJon Cooper struct efx_udp_tunnel tnl; 2403e5fbd977SJon Cooper int efx_tunnel_type; 2404e5fbd977SJon Cooper 2405e5fbd977SJon Cooper efx_tunnel_type = efx_udp_tunnel_type_map(ti->type); 2406e5fbd977SJon Cooper if (efx_tunnel_type < 0) 2407e5fbd977SJon Cooper return; 2408e5fbd977SJon Cooper 2409e5fbd977SJon Cooper tnl.type = (u16)efx_tunnel_type; 2410e5fbd977SJon Cooper tnl.port = ti->port; 2411e5fbd977SJon Cooper 2412c04ca616SDan Carpenter if (efx->type->udp_tnl_del_port) 2413e5fbd977SJon Cooper (void)efx->type->udp_tnl_del_port(efx, tnl); 2414e5fbd977SJon Cooper } 2415e5fbd977SJon Cooper 24167fa8d547SShradha Shah static const struct net_device_ops efx_netdev_ops = { 2417874aeea5SJeff Kirsher .ndo_open = efx_net_open, 2418874aeea5SJeff Kirsher .ndo_stop = efx_net_stop, 2419874aeea5SJeff Kirsher .ndo_get_stats64 = efx_net_stats, 2420874aeea5SJeff Kirsher .ndo_tx_timeout = efx_watchdog, 2421874aeea5SJeff Kirsher .ndo_start_xmit = efx_hard_start_xmit, 2422874aeea5SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 2423874aeea5SJeff Kirsher .ndo_do_ioctl = efx_ioctl, 2424874aeea5SJeff Kirsher .ndo_change_mtu = efx_change_mtu, 2425874aeea5SJeff Kirsher .ndo_set_mac_address = efx_set_mac_address, 24260fca8c97SBen Hutchings .ndo_set_rx_mode = efx_set_rx_mode, 2427874aeea5SJeff Kirsher .ndo_set_features = efx_set_features, 24284a53ea8aSAndrew Rybchenko .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid, 24294a53ea8aSAndrew Rybchenko .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid, 2430cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV 24317fa8d547SShradha Shah .ndo_set_vf_mac = efx_sriov_set_vf_mac, 24327fa8d547SShradha Shah .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, 24337fa8d547SShradha Shah .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, 24347fa8d547SShradha Shah .ndo_get_vf_config = efx_sriov_get_vf_config, 24354392dc69SEdward Cree .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, 2436cd2d5b52SBen Hutchings #endif 243708a7b29bSBert Kenward .ndo_get_phys_port_id = efx_get_phys_port_id, 2438ac019f08SBert Kenward .ndo_get_phys_port_name = efx_get_phys_port_name, 2439874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2440874aeea5SJeff Kirsher .ndo_poll_controller = efx_netpoll, 2441874aeea5SJeff Kirsher #endif 2442874aeea5SJeff Kirsher .ndo_setup_tc = efx_setup_tc, 2443874aeea5SJeff Kirsher #ifdef CONFIG_RFS_ACCEL 2444874aeea5SJeff Kirsher .ndo_rx_flow_steer = efx_filter_rfs, 2445874aeea5SJeff Kirsher #endif 2446e5fbd977SJon Cooper .ndo_udp_tunnel_add = efx_udp_tunnel_add, 2447e5fbd977SJon Cooper .ndo_udp_tunnel_del = efx_udp_tunnel_del, 2448874aeea5SJeff Kirsher }; 2449874aeea5SJeff Kirsher 2450874aeea5SJeff Kirsher static void efx_update_name(struct efx_nic *efx) 2451874aeea5SJeff Kirsher { 2452874aeea5SJeff Kirsher strcpy(efx->name, efx->net_dev->name); 2453874aeea5SJeff Kirsher efx_mtd_rename(efx); 2454874aeea5SJeff Kirsher efx_set_channel_names(efx); 2455874aeea5SJeff Kirsher } 2456874aeea5SJeff Kirsher 2457874aeea5SJeff Kirsher static int efx_netdev_event(struct notifier_block *this, 2458874aeea5SJeff Kirsher unsigned long event, void *ptr) 2459874aeea5SJeff Kirsher { 2460351638e7SJiri Pirko struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); 2461874aeea5SJeff Kirsher 24627fa8d547SShradha Shah if ((net_dev->netdev_ops == &efx_netdev_ops) && 2463874aeea5SJeff Kirsher event == NETDEV_CHANGENAME) 2464874aeea5SJeff Kirsher efx_update_name(netdev_priv(net_dev)); 2465874aeea5SJeff Kirsher 2466874aeea5SJeff Kirsher return NOTIFY_DONE; 2467874aeea5SJeff Kirsher } 2468874aeea5SJeff Kirsher 2469874aeea5SJeff Kirsher static struct notifier_block efx_netdev_notifier = { 2470874aeea5SJeff Kirsher .notifier_call = efx_netdev_event, 2471874aeea5SJeff Kirsher }; 2472874aeea5SJeff Kirsher 2473874aeea5SJeff Kirsher static ssize_t 2474874aeea5SJeff Kirsher show_phy_type(struct device *dev, struct device_attribute *attr, char *buf) 2475874aeea5SJeff Kirsher { 2476874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 2477874aeea5SJeff Kirsher return sprintf(buf, "%d\n", efx->phy_type); 2478874aeea5SJeff Kirsher } 2479776fbcc9SBen Hutchings static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL); 2480874aeea5SJeff Kirsher 2481e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING 2482e7fef9b4SEdward Cree static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr, 2483e7fef9b4SEdward Cree char *buf) 2484e7fef9b4SEdward Cree { 2485e7fef9b4SEdward Cree struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 2486e7fef9b4SEdward Cree struct efx_mcdi_iface *mcdi = efx_mcdi(efx); 2487e7fef9b4SEdward Cree 2488e7fef9b4SEdward Cree return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled); 2489e7fef9b4SEdward Cree } 2490e7fef9b4SEdward Cree static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr, 2491e7fef9b4SEdward Cree const char *buf, size_t count) 2492e7fef9b4SEdward Cree { 2493e7fef9b4SEdward Cree struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 2494e7fef9b4SEdward Cree struct efx_mcdi_iface *mcdi = efx_mcdi(efx); 2495e7fef9b4SEdward Cree bool enable = count > 0 && *buf != '0'; 2496e7fef9b4SEdward Cree 2497e7fef9b4SEdward Cree mcdi->logging_enabled = enable; 2498e7fef9b4SEdward Cree return count; 2499e7fef9b4SEdward Cree } 2500e7fef9b4SEdward Cree static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log); 2501e7fef9b4SEdward Cree #endif 2502e7fef9b4SEdward Cree 2503874aeea5SJeff Kirsher static int efx_register_netdev(struct efx_nic *efx) 2504874aeea5SJeff Kirsher { 2505874aeea5SJeff Kirsher struct net_device *net_dev = efx->net_dev; 2506874aeea5SJeff Kirsher struct efx_channel *channel; 2507874aeea5SJeff Kirsher int rc; 2508874aeea5SJeff Kirsher 2509874aeea5SJeff Kirsher net_dev->watchdog_timeo = 5 * HZ; 2510874aeea5SJeff Kirsher net_dev->irq = efx->pci_dev->irq; 25117fa8d547SShradha Shah net_dev->netdev_ops = &efx_netdev_ops; 25127fa8d547SShradha Shah if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) 25138127d661SBen Hutchings net_dev->priv_flags |= IFF_UNICAST_FLT; 25147ad24ea4SWilfried Klaebe net_dev->ethtool_ops = &efx_ethtool_ops; 25157e6d06f0SBen Hutchings net_dev->gso_max_segs = EFX_TSO_MAX_SEGS; 2516cd94e519SBert Kenward net_dev->min_mtu = EFX_MIN_MTU; 2517cd94e519SBert Kenward net_dev->max_mtu = EFX_MAX_MTU; 2518874aeea5SJeff Kirsher 2519874aeea5SJeff Kirsher rtnl_lock(); 2520874aeea5SJeff Kirsher 25217153f623SBen Hutchings /* Enable resets to be scheduled and check whether any were 25227153f623SBen Hutchings * already requested. If so, the NIC is probably hosed so we 25237153f623SBen Hutchings * abort. 25247153f623SBen Hutchings */ 25257153f623SBen Hutchings efx->state = STATE_READY; 25267153f623SBen Hutchings smp_mb(); /* ensure we change state before checking reset_pending */ 25277153f623SBen Hutchings if (efx->reset_pending) { 25287153f623SBen Hutchings netif_err(efx, probe, efx->net_dev, 25297153f623SBen Hutchings "aborting probe due to scheduled reset\n"); 25307153f623SBen Hutchings rc = -EIO; 25317153f623SBen Hutchings goto fail_locked; 25327153f623SBen Hutchings } 25337153f623SBen Hutchings 2534874aeea5SJeff Kirsher rc = dev_alloc_name(net_dev, net_dev->name); 2535874aeea5SJeff Kirsher if (rc < 0) 2536874aeea5SJeff Kirsher goto fail_locked; 2537874aeea5SJeff Kirsher efx_update_name(efx); 2538874aeea5SJeff Kirsher 25398f8b3d51SBen Hutchings /* Always start with carrier off; PHY events will detect the link */ 25408f8b3d51SBen Hutchings netif_carrier_off(net_dev); 25418f8b3d51SBen Hutchings 2542874aeea5SJeff Kirsher rc = register_netdevice(net_dev); 2543874aeea5SJeff Kirsher if (rc) 2544874aeea5SJeff Kirsher goto fail_locked; 2545874aeea5SJeff Kirsher 2546874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 2547874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 2548874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 2549874aeea5SJeff Kirsher efx_init_tx_queue_core_txq(tx_queue); 2550874aeea5SJeff Kirsher } 2551874aeea5SJeff Kirsher 25520bcf4a64SBen Hutchings efx_associate(efx); 25530bcf4a64SBen Hutchings 2554874aeea5SJeff Kirsher rtnl_unlock(); 2555874aeea5SJeff Kirsher 2556874aeea5SJeff Kirsher rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); 2557874aeea5SJeff Kirsher if (rc) { 2558874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2559874aeea5SJeff Kirsher "failed to init net dev attributes\n"); 2560874aeea5SJeff Kirsher goto fail_registered; 2561874aeea5SJeff Kirsher } 2562e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING 2563e7fef9b4SEdward Cree rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging); 2564e7fef9b4SEdward Cree if (rc) { 2565e7fef9b4SEdward Cree netif_err(efx, drv, efx->net_dev, 2566e7fef9b4SEdward Cree "failed to init net dev attributes\n"); 2567e7fef9b4SEdward Cree goto fail_attr_mcdi_logging; 2568e7fef9b4SEdward Cree } 2569e7fef9b4SEdward Cree #endif 2570874aeea5SJeff Kirsher 2571874aeea5SJeff Kirsher return 0; 2572874aeea5SJeff Kirsher 2573e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING 2574e7fef9b4SEdward Cree fail_attr_mcdi_logging: 2575e7fef9b4SEdward Cree device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); 2576e7fef9b4SEdward Cree #endif 25777153f623SBen Hutchings fail_registered: 25787153f623SBen Hutchings rtnl_lock(); 25790bcf4a64SBen Hutchings efx_dissociate(efx); 25807153f623SBen Hutchings unregister_netdevice(net_dev); 2581874aeea5SJeff Kirsher fail_locked: 25827153f623SBen Hutchings efx->state = STATE_UNINIT; 2583874aeea5SJeff Kirsher rtnl_unlock(); 2584874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); 2585874aeea5SJeff Kirsher return rc; 2586874aeea5SJeff Kirsher } 2587874aeea5SJeff Kirsher 2588874aeea5SJeff Kirsher static void efx_unregister_netdev(struct efx_nic *efx) 2589874aeea5SJeff Kirsher { 2590874aeea5SJeff Kirsher if (!efx->net_dev) 2591874aeea5SJeff Kirsher return; 2592874aeea5SJeff Kirsher 2593874aeea5SJeff Kirsher BUG_ON(netdev_priv(efx->net_dev) != efx); 2594874aeea5SJeff Kirsher 2595e7fef9b4SEdward Cree if (efx_dev_registered(efx)) { 2596874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); 2597e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING 2598e7fef9b4SEdward Cree device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging); 2599e7fef9b4SEdward Cree #endif 2600874aeea5SJeff Kirsher device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); 2601e7fef9b4SEdward Cree unregister_netdev(efx->net_dev); 2602e7fef9b4SEdward Cree } 2603874aeea5SJeff Kirsher } 2604874aeea5SJeff Kirsher 2605874aeea5SJeff Kirsher /************************************************************************** 2606874aeea5SJeff Kirsher * 2607874aeea5SJeff Kirsher * Device reset and suspend 2608874aeea5SJeff Kirsher * 2609874aeea5SJeff Kirsher **************************************************************************/ 2610874aeea5SJeff Kirsher 2611874aeea5SJeff Kirsher /* Tears down the entire software state and most of the hardware state 2612874aeea5SJeff Kirsher * before reset. */ 2613874aeea5SJeff Kirsher void efx_reset_down(struct efx_nic *efx, enum reset_type method) 2614874aeea5SJeff Kirsher { 2615874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 2616874aeea5SJeff Kirsher 2617e283546cSEdward Cree if (method == RESET_TYPE_MCDI_TIMEOUT) 2618e283546cSEdward Cree efx->type->prepare_flr(efx); 2619e283546cSEdward Cree 2620874aeea5SJeff Kirsher efx_stop_all(efx); 2621d8291187SBen Hutchings efx_disable_interrupts(efx); 26225642ceefSBen Hutchings 26235642ceefSBen Hutchings mutex_lock(&efx->mac_lock); 2624087e9025SJon Cooper if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && 2625087e9025SJon Cooper method != RESET_TYPE_DATAPATH) 2626874aeea5SJeff Kirsher efx->phy_op->fini(efx); 2627874aeea5SJeff Kirsher efx->type->fini(efx); 2628874aeea5SJeff Kirsher } 2629874aeea5SJeff Kirsher 2630874aeea5SJeff Kirsher /* This function will always ensure that the locks acquired in 2631874aeea5SJeff Kirsher * efx_reset_down() are released. A failure return code indicates 2632874aeea5SJeff Kirsher * that we were unable to reinitialise the hardware, and the 2633874aeea5SJeff Kirsher * driver should be disabled. If ok is false, then the rx and tx 2634874aeea5SJeff Kirsher * engines are not restarted, pending a RESET_DISABLE. */ 2635874aeea5SJeff Kirsher int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) 2636874aeea5SJeff Kirsher { 2637874aeea5SJeff Kirsher int rc; 2638874aeea5SJeff Kirsher 2639874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 2640874aeea5SJeff Kirsher 2641e283546cSEdward Cree if (method == RESET_TYPE_MCDI_TIMEOUT) 2642e283546cSEdward Cree efx->type->finish_flr(efx); 2643e283546cSEdward Cree 2644e283546cSEdward Cree /* Ensure that SRAM is initialised even if we're disabling the device */ 2645874aeea5SJeff Kirsher rc = efx->type->init(efx); 2646874aeea5SJeff Kirsher if (rc) { 2647874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n"); 2648874aeea5SJeff Kirsher goto fail; 2649874aeea5SJeff Kirsher } 2650874aeea5SJeff Kirsher 2651874aeea5SJeff Kirsher if (!ok) 2652874aeea5SJeff Kirsher goto fail; 2653874aeea5SJeff Kirsher 2654087e9025SJon Cooper if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && 2655087e9025SJon Cooper method != RESET_TYPE_DATAPATH) { 2656874aeea5SJeff Kirsher rc = efx->phy_op->init(efx); 2657874aeea5SJeff Kirsher if (rc) 2658874aeea5SJeff Kirsher goto fail; 2659267d9d73SEdward Cree rc = efx->phy_op->reconfigure(efx); 2660267d9d73SEdward Cree if (rc && rc != -EPERM) 2661874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 2662874aeea5SJeff Kirsher "could not restore PHY settings\n"); 2663874aeea5SJeff Kirsher } 2664874aeea5SJeff Kirsher 2665261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 2666261e4d96SJon Cooper if (rc) 2667261e4d96SJon Cooper goto fail; 26686d8aaaf6SDaniel Pieczko 26696d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 26706d8aaaf6SDaniel Pieczko rc = efx->type->vswitching_restore(efx); 26716d8aaaf6SDaniel Pieczko if (rc) /* not fatal; the PF will still work fine */ 26726d8aaaf6SDaniel Pieczko netif_warn(efx, probe, efx->net_dev, 26736d8aaaf6SDaniel Pieczko "failed to restore vswitching rc=%d;" 26746d8aaaf6SDaniel Pieczko " VFs may not function\n", rc); 26756d8aaaf6SDaniel Pieczko #endif 26766d8aaaf6SDaniel Pieczko 26770d322413SEdward Cree down_read(&efx->filter_sem); 2678874aeea5SJeff Kirsher efx_restore_filters(efx); 26790d322413SEdward Cree up_read(&efx->filter_sem); 26807fa8d547SShradha Shah if (efx->type->sriov_reset) 2681d98a4ffeSShradha Shah efx->type->sriov_reset(efx); 2682874aeea5SJeff Kirsher 2683874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2684874aeea5SJeff Kirsher 2685874aeea5SJeff Kirsher efx_start_all(efx); 2686874aeea5SJeff Kirsher 2687e5fbd977SJon Cooper if (efx->type->udp_tnl_push_ports) 2688e5fbd977SJon Cooper efx->type->udp_tnl_push_ports(efx); 2689e5fbd977SJon Cooper 2690874aeea5SJeff Kirsher return 0; 2691874aeea5SJeff Kirsher 2692874aeea5SJeff Kirsher fail: 2693874aeea5SJeff Kirsher efx->port_initialized = false; 2694874aeea5SJeff Kirsher 2695874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 2696874aeea5SJeff Kirsher 2697874aeea5SJeff Kirsher return rc; 2698874aeea5SJeff Kirsher } 2699874aeea5SJeff Kirsher 2700874aeea5SJeff Kirsher /* Reset the NIC using the specified method. Note that the reset may 2701874aeea5SJeff Kirsher * fail, in which case the card will be left in an unusable state. 2702874aeea5SJeff Kirsher * 2703874aeea5SJeff Kirsher * Caller must hold the rtnl_lock. 2704874aeea5SJeff Kirsher */ 2705874aeea5SJeff Kirsher int efx_reset(struct efx_nic *efx, enum reset_type method) 2706874aeea5SJeff Kirsher { 2707874aeea5SJeff Kirsher int rc, rc2; 2708874aeea5SJeff Kirsher bool disabled; 2709874aeea5SJeff Kirsher 2710874aeea5SJeff Kirsher netif_info(efx, drv, efx->net_dev, "resetting (%s)\n", 2711874aeea5SJeff Kirsher RESET_TYPE(method)); 2712874aeea5SJeff Kirsher 2713c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 2714874aeea5SJeff Kirsher efx_reset_down(efx, method); 2715874aeea5SJeff Kirsher 2716874aeea5SJeff Kirsher rc = efx->type->reset(efx, method); 2717874aeea5SJeff Kirsher if (rc) { 2718874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n"); 2719874aeea5SJeff Kirsher goto out; 2720874aeea5SJeff Kirsher } 2721874aeea5SJeff Kirsher 2722874aeea5SJeff Kirsher /* Clear flags for the scopes we covered. We assume the NIC and 2723874aeea5SJeff Kirsher * driver are now quiescent so that there is no race here. 2724874aeea5SJeff Kirsher */ 2725e283546cSEdward Cree if (method < RESET_TYPE_MAX_METHOD) 2726874aeea5SJeff Kirsher efx->reset_pending &= -(1 << (method + 1)); 2727e283546cSEdward Cree else /* it doesn't fit into the well-ordered scope hierarchy */ 2728e283546cSEdward Cree __clear_bit(method, &efx->reset_pending); 2729874aeea5SJeff Kirsher 2730874aeea5SJeff Kirsher /* Reinitialise bus-mastering, which may have been turned off before 2731874aeea5SJeff Kirsher * the reset was scheduled. This is still appropriate, even in the 2732874aeea5SJeff Kirsher * RESET_TYPE_DISABLE since this driver generally assumes the hardware 2733874aeea5SJeff Kirsher * can respond to requests. */ 2734874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 2735874aeea5SJeff Kirsher 2736874aeea5SJeff Kirsher out: 2737874aeea5SJeff Kirsher /* Leave device stopped if necessary */ 2738626950dbSAlexandre Rames disabled = rc || 2739626950dbSAlexandre Rames method == RESET_TYPE_DISABLE || 2740626950dbSAlexandre Rames method == RESET_TYPE_RECOVER_OR_DISABLE; 2741874aeea5SJeff Kirsher rc2 = efx_reset_up(efx, method, !disabled); 2742874aeea5SJeff Kirsher if (rc2) { 2743874aeea5SJeff Kirsher disabled = true; 2744874aeea5SJeff Kirsher if (!rc) 2745874aeea5SJeff Kirsher rc = rc2; 2746874aeea5SJeff Kirsher } 2747874aeea5SJeff Kirsher 2748874aeea5SJeff Kirsher if (disabled) { 2749874aeea5SJeff Kirsher dev_close(efx->net_dev); 2750874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "has been disabled\n"); 2751874aeea5SJeff Kirsher efx->state = STATE_DISABLED; 2752874aeea5SJeff Kirsher } else { 2753874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "reset complete\n"); 27549c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 2755874aeea5SJeff Kirsher } 2756874aeea5SJeff Kirsher return rc; 2757874aeea5SJeff Kirsher } 2758874aeea5SJeff Kirsher 2759626950dbSAlexandre Rames /* Try recovery mechanisms. 2760626950dbSAlexandre Rames * For now only EEH is supported. 2761626950dbSAlexandre Rames * Returns 0 if the recovery mechanisms are unsuccessful. 2762626950dbSAlexandre Rames * Returns a non-zero value otherwise. 2763626950dbSAlexandre Rames */ 2764b28405b0SAlexandre Rames int efx_try_recovery(struct efx_nic *efx) 2765626950dbSAlexandre Rames { 2766626950dbSAlexandre Rames #ifdef CONFIG_EEH 2767626950dbSAlexandre Rames /* A PCI error can occur and not be seen by EEH because nothing 2768626950dbSAlexandre Rames * happens on the PCI bus. In this case the driver may fail and 2769626950dbSAlexandre Rames * schedule a 'recover or reset', leading to this recovery handler. 2770626950dbSAlexandre Rames * Manually call the eeh failure check function. 2771626950dbSAlexandre Rames */ 277212a89dbaSBenjamin Herrenschmidt struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev); 2773626950dbSAlexandre Rames if (eeh_dev_check_failure(eehdev)) { 2774626950dbSAlexandre Rames /* The EEH mechanisms will handle the error and reset the 2775626950dbSAlexandre Rames * device if necessary. 2776626950dbSAlexandre Rames */ 2777626950dbSAlexandre Rames return 1; 2778626950dbSAlexandre Rames } 2779626950dbSAlexandre Rames #endif 2780626950dbSAlexandre Rames return 0; 2781626950dbSAlexandre Rames } 2782626950dbSAlexandre Rames 278374cd60a4SJon Cooper static void efx_wait_for_bist_end(struct efx_nic *efx) 278474cd60a4SJon Cooper { 278574cd60a4SJon Cooper int i; 278674cd60a4SJon Cooper 278774cd60a4SJon Cooper for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) { 278874cd60a4SJon Cooper if (efx_mcdi_poll_reboot(efx)) 278974cd60a4SJon Cooper goto out; 279074cd60a4SJon Cooper msleep(BIST_WAIT_DELAY_MS); 279174cd60a4SJon Cooper } 279274cd60a4SJon Cooper 279374cd60a4SJon Cooper netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n"); 279474cd60a4SJon Cooper out: 279574cd60a4SJon Cooper /* Either way unset the BIST flag. If we found no reboot we probably 279674cd60a4SJon Cooper * won't recover, but we should try. 279774cd60a4SJon Cooper */ 279874cd60a4SJon Cooper efx->mc_bist_for_other_fn = false; 279974cd60a4SJon Cooper } 280074cd60a4SJon Cooper 2801874aeea5SJeff Kirsher /* The worker thread exists so that code that cannot sleep can 2802874aeea5SJeff Kirsher * schedule a reset for later. 2803874aeea5SJeff Kirsher */ 2804874aeea5SJeff Kirsher static void efx_reset_work(struct work_struct *data) 2805874aeea5SJeff Kirsher { 2806874aeea5SJeff Kirsher struct efx_nic *efx = container_of(data, struct efx_nic, reset_work); 2807626950dbSAlexandre Rames unsigned long pending; 2808626950dbSAlexandre Rames enum reset_type method; 2809626950dbSAlexandre Rames 2810626950dbSAlexandre Rames pending = ACCESS_ONCE(efx->reset_pending); 2811626950dbSAlexandre Rames method = fls(pending) - 1; 2812626950dbSAlexandre Rames 281374cd60a4SJon Cooper if (method == RESET_TYPE_MC_BIST) 281474cd60a4SJon Cooper efx_wait_for_bist_end(efx); 281574cd60a4SJon Cooper 2816626950dbSAlexandre Rames if ((method == RESET_TYPE_RECOVER_OR_DISABLE || 2817626950dbSAlexandre Rames method == RESET_TYPE_RECOVER_OR_ALL) && 2818626950dbSAlexandre Rames efx_try_recovery(efx)) 2819626950dbSAlexandre Rames return; 2820874aeea5SJeff Kirsher 2821874aeea5SJeff Kirsher if (!pending) 2822874aeea5SJeff Kirsher return; 2823874aeea5SJeff Kirsher 2824874aeea5SJeff Kirsher rtnl_lock(); 28257153f623SBen Hutchings 28267153f623SBen Hutchings /* We checked the state in efx_schedule_reset() but it may 28277153f623SBen Hutchings * have changed by now. Now that we have the RTNL lock, 28287153f623SBen Hutchings * it cannot change again. 28297153f623SBen Hutchings */ 28307153f623SBen Hutchings if (efx->state == STATE_READY) 2831626950dbSAlexandre Rames (void)efx_reset(efx, method); 28327153f623SBen Hutchings 2833874aeea5SJeff Kirsher rtnl_unlock(); 2834874aeea5SJeff Kirsher } 2835874aeea5SJeff Kirsher 2836874aeea5SJeff Kirsher void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) 2837874aeea5SJeff Kirsher { 2838874aeea5SJeff Kirsher enum reset_type method; 2839874aeea5SJeff Kirsher 2840626950dbSAlexandre Rames if (efx->state == STATE_RECOVERY) { 2841626950dbSAlexandre Rames netif_dbg(efx, drv, efx->net_dev, 2842626950dbSAlexandre Rames "recovering: skip scheduling %s reset\n", 2843626950dbSAlexandre Rames RESET_TYPE(type)); 2844626950dbSAlexandre Rames return; 2845626950dbSAlexandre Rames } 2846626950dbSAlexandre Rames 2847874aeea5SJeff Kirsher switch (type) { 2848874aeea5SJeff Kirsher case RESET_TYPE_INVISIBLE: 2849874aeea5SJeff Kirsher case RESET_TYPE_ALL: 2850626950dbSAlexandre Rames case RESET_TYPE_RECOVER_OR_ALL: 2851874aeea5SJeff Kirsher case RESET_TYPE_WORLD: 2852874aeea5SJeff Kirsher case RESET_TYPE_DISABLE: 2853626950dbSAlexandre Rames case RESET_TYPE_RECOVER_OR_DISABLE: 2854087e9025SJon Cooper case RESET_TYPE_DATAPATH: 285574cd60a4SJon Cooper case RESET_TYPE_MC_BIST: 2856e283546cSEdward Cree case RESET_TYPE_MCDI_TIMEOUT: 2857874aeea5SJeff Kirsher method = type; 2858874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n", 2859874aeea5SJeff Kirsher RESET_TYPE(method)); 2860874aeea5SJeff Kirsher break; 2861874aeea5SJeff Kirsher default: 2862874aeea5SJeff Kirsher method = efx->type->map_reset_reason(type); 2863874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, 2864874aeea5SJeff Kirsher "scheduling %s reset for %s\n", 2865874aeea5SJeff Kirsher RESET_TYPE(method), RESET_TYPE(type)); 2866874aeea5SJeff Kirsher break; 2867874aeea5SJeff Kirsher } 2868874aeea5SJeff Kirsher 2869874aeea5SJeff Kirsher set_bit(method, &efx->reset_pending); 28707153f623SBen Hutchings smp_mb(); /* ensure we change reset_pending before checking state */ 28717153f623SBen Hutchings 28727153f623SBen Hutchings /* If we're not READY then just leave the flags set as the cue 28737153f623SBen Hutchings * to abort probing or reschedule the reset later. 28747153f623SBen Hutchings */ 28757153f623SBen Hutchings if (ACCESS_ONCE(efx->state) != STATE_READY) 28767153f623SBen Hutchings return; 2877874aeea5SJeff Kirsher 2878874aeea5SJeff Kirsher /* efx_process_channel() will no longer read events once a 2879874aeea5SJeff Kirsher * reset is scheduled. So switch back to poll'd MCDI completions. */ 2880874aeea5SJeff Kirsher efx_mcdi_mode_poll(efx); 2881874aeea5SJeff Kirsher 2882874aeea5SJeff Kirsher queue_work(reset_workqueue, &efx->reset_work); 2883874aeea5SJeff Kirsher } 2884874aeea5SJeff Kirsher 2885874aeea5SJeff Kirsher /************************************************************************** 2886874aeea5SJeff Kirsher * 2887874aeea5SJeff Kirsher * List of NICs we support 2888874aeea5SJeff Kirsher * 2889874aeea5SJeff Kirsher **************************************************************************/ 2890874aeea5SJeff Kirsher 2891874aeea5SJeff Kirsher /* PCI device ID table */ 28929baa3c34SBenoit Taine static const struct pci_device_id efx_pci_table[] = { 2893547c474fSBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */ 2894874aeea5SJeff Kirsher .driver_data = (unsigned long) &siena_a0_nic_type}, 2895547c474fSBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */ 2896874aeea5SJeff Kirsher .driver_data = (unsigned long) &siena_a0_nic_type}, 28978127d661SBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ 28988127d661SBen Hutchings .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 28996f7f8aa6SShradha Shah {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ 29006f7f8aa6SShradha Shah .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 29013b06a00eSMateusz Wrzesinski {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ 29023b06a00eSMateusz Wrzesinski .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 2903dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */ 2904dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 2905dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */ 2906dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 2907dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */ 2908dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 2909874aeea5SJeff Kirsher {0} /* end of list */ 2910874aeea5SJeff Kirsher }; 2911874aeea5SJeff Kirsher 2912874aeea5SJeff Kirsher /************************************************************************** 2913874aeea5SJeff Kirsher * 2914874aeea5SJeff Kirsher * Dummy PHY/MAC operations 2915874aeea5SJeff Kirsher * 2916874aeea5SJeff Kirsher * Can be used for some unimplemented operations 2917874aeea5SJeff Kirsher * Needed so all function pointers are valid and do not have to be tested 2918874aeea5SJeff Kirsher * before use 2919874aeea5SJeff Kirsher * 2920874aeea5SJeff Kirsher **************************************************************************/ 2921874aeea5SJeff Kirsher int efx_port_dummy_op_int(struct efx_nic *efx) 2922874aeea5SJeff Kirsher { 2923874aeea5SJeff Kirsher return 0; 2924874aeea5SJeff Kirsher } 2925874aeea5SJeff Kirsher void efx_port_dummy_op_void(struct efx_nic *efx) {} 2926874aeea5SJeff Kirsher 2927874aeea5SJeff Kirsher static bool efx_port_dummy_op_poll(struct efx_nic *efx) 2928874aeea5SJeff Kirsher { 2929874aeea5SJeff Kirsher return false; 2930874aeea5SJeff Kirsher } 2931874aeea5SJeff Kirsher 2932874aeea5SJeff Kirsher static const struct efx_phy_operations efx_dummy_phy_operations = { 2933874aeea5SJeff Kirsher .init = efx_port_dummy_op_int, 2934874aeea5SJeff Kirsher .reconfigure = efx_port_dummy_op_int, 2935874aeea5SJeff Kirsher .poll = efx_port_dummy_op_poll, 2936874aeea5SJeff Kirsher .fini = efx_port_dummy_op_void, 2937874aeea5SJeff Kirsher }; 2938874aeea5SJeff Kirsher 2939874aeea5SJeff Kirsher /************************************************************************** 2940874aeea5SJeff Kirsher * 2941874aeea5SJeff Kirsher * Data housekeeping 2942874aeea5SJeff Kirsher * 2943874aeea5SJeff Kirsher **************************************************************************/ 2944874aeea5SJeff Kirsher 2945874aeea5SJeff Kirsher /* This zeroes out and then fills in the invariants in a struct 2946874aeea5SJeff Kirsher * efx_nic (including all sub-structures). 2947874aeea5SJeff Kirsher */ 2948adeb15aaSBen Hutchings static int efx_init_struct(struct efx_nic *efx, 2949874aeea5SJeff Kirsher struct pci_dev *pci_dev, struct net_device *net_dev) 2950874aeea5SJeff Kirsher { 29516f9f6ec2SAndrew Rybchenko int rc = -ENOMEM, i; 2952874aeea5SJeff Kirsher 2953874aeea5SJeff Kirsher /* Initialise common structures */ 29540bcf4a64SBen Hutchings INIT_LIST_HEAD(&efx->node); 29550bcf4a64SBen Hutchings INIT_LIST_HEAD(&efx->secondary_list); 2956874aeea5SJeff Kirsher spin_lock_init(&efx->biu_lock); 2957874aeea5SJeff Kirsher #ifdef CONFIG_SFC_MTD 2958874aeea5SJeff Kirsher INIT_LIST_HEAD(&efx->mtd_list); 2959874aeea5SJeff Kirsher #endif 2960874aeea5SJeff Kirsher INIT_WORK(&efx->reset_work, efx_reset_work); 2961874aeea5SJeff Kirsher INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); 2962dd40781eSBen Hutchings INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work); 2963874aeea5SJeff Kirsher efx->pci_dev = pci_dev; 2964874aeea5SJeff Kirsher efx->msg_enable = debug; 2965f16aeea0SBen Hutchings efx->state = STATE_UNINIT; 2966874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); 2967874aeea5SJeff Kirsher 2968874aeea5SJeff Kirsher efx->net_dev = net_dev; 296943a3739dSJon Cooper efx->rx_prefix_size = efx->type->rx_prefix_size; 29702ec03014SAndrew Rybchenko efx->rx_ip_align = 29712ec03014SAndrew Rybchenko NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0; 297243a3739dSJon Cooper efx->rx_packet_hash_offset = 297343a3739dSJon Cooper efx->type->rx_hash_offset - efx->type->rx_prefix_size; 2974bd9a265dSJon Cooper efx->rx_packet_ts_offset = 2975bd9a265dSJon Cooper efx->type->rx_ts_offset - efx->type->rx_prefix_size; 2976874aeea5SJeff Kirsher spin_lock_init(&efx->stats_lock); 2977874aeea5SJeff Kirsher mutex_init(&efx->mac_lock); 2978874aeea5SJeff Kirsher efx->phy_op = &efx_dummy_phy_operations; 2979874aeea5SJeff Kirsher efx->mdio.dev = net_dev; 2980874aeea5SJeff Kirsher INIT_WORK(&efx->mac_work, efx_mac_work); 29819f2cb71cSBen Hutchings init_waitqueue_head(&efx->flush_wq); 2982874aeea5SJeff Kirsher 2983874aeea5SJeff Kirsher for (i = 0; i < EFX_MAX_CHANNELS; i++) { 2984874aeea5SJeff Kirsher efx->channel[i] = efx_alloc_channel(efx, i, NULL); 2985874aeea5SJeff Kirsher if (!efx->channel[i]) 2986874aeea5SJeff Kirsher goto fail; 2987d8291187SBen Hutchings efx->msi_context[i].efx = efx; 2988d8291187SBen Hutchings efx->msi_context[i].index = i; 2989874aeea5SJeff Kirsher } 2990874aeea5SJeff Kirsher 2991874aeea5SJeff Kirsher /* Higher numbered interrupt modes are less capable! */ 29926f9f6ec2SAndrew Rybchenko if (WARN_ON_ONCE(efx->type->max_interrupt_mode > 29936f9f6ec2SAndrew Rybchenko efx->type->min_interrupt_mode)) { 29946f9f6ec2SAndrew Rybchenko rc = -EIO; 29956f9f6ec2SAndrew Rybchenko goto fail; 29966f9f6ec2SAndrew Rybchenko } 2997874aeea5SJeff Kirsher efx->interrupt_mode = max(efx->type->max_interrupt_mode, 2998874aeea5SJeff Kirsher interrupt_mode); 29996f9f6ec2SAndrew Rybchenko efx->interrupt_mode = min(efx->type->min_interrupt_mode, 30006f9f6ec2SAndrew Rybchenko interrupt_mode); 3001874aeea5SJeff Kirsher 3002874aeea5SJeff Kirsher /* Would be good to use the net_dev name, but we're too early */ 3003874aeea5SJeff Kirsher snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s", 3004874aeea5SJeff Kirsher pci_name(pci_dev)); 3005874aeea5SJeff Kirsher efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); 3006874aeea5SJeff Kirsher if (!efx->workqueue) 3007874aeea5SJeff Kirsher goto fail; 3008874aeea5SJeff Kirsher 3009874aeea5SJeff Kirsher return 0; 3010874aeea5SJeff Kirsher 3011874aeea5SJeff Kirsher fail: 3012874aeea5SJeff Kirsher efx_fini_struct(efx); 30136f9f6ec2SAndrew Rybchenko return rc; 3014874aeea5SJeff Kirsher } 3015874aeea5SJeff Kirsher 3016874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx) 3017874aeea5SJeff Kirsher { 3018874aeea5SJeff Kirsher int i; 3019874aeea5SJeff Kirsher 3020874aeea5SJeff Kirsher for (i = 0; i < EFX_MAX_CHANNELS; i++) 3021874aeea5SJeff Kirsher kfree(efx->channel[i]); 3022874aeea5SJeff Kirsher 3023ef215e64SBen Hutchings kfree(efx->vpd_sn); 3024ef215e64SBen Hutchings 3025874aeea5SJeff Kirsher if (efx->workqueue) { 3026874aeea5SJeff Kirsher destroy_workqueue(efx->workqueue); 3027874aeea5SJeff Kirsher efx->workqueue = NULL; 3028874aeea5SJeff Kirsher } 3029874aeea5SJeff Kirsher } 3030874aeea5SJeff Kirsher 3031e4d112e4SEdward Cree void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) 3032e4d112e4SEdward Cree { 3033e4d112e4SEdward Cree u64 n_rx_nodesc_trunc = 0; 3034e4d112e4SEdward Cree struct efx_channel *channel; 3035e4d112e4SEdward Cree 3036e4d112e4SEdward Cree efx_for_each_channel(channel, efx) 3037e4d112e4SEdward Cree n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; 3038e4d112e4SEdward Cree stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; 3039e4d112e4SEdward Cree stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); 3040e4d112e4SEdward Cree } 3041e4d112e4SEdward Cree 3042874aeea5SJeff Kirsher /************************************************************************** 3043874aeea5SJeff Kirsher * 3044874aeea5SJeff Kirsher * PCI interface 3045874aeea5SJeff Kirsher * 3046874aeea5SJeff Kirsher **************************************************************************/ 3047874aeea5SJeff Kirsher 3048874aeea5SJeff Kirsher /* Main body of final NIC shutdown code 3049874aeea5SJeff Kirsher * This is called only at module unload (or hotplug removal). 3050874aeea5SJeff Kirsher */ 3051874aeea5SJeff Kirsher static void efx_pci_remove_main(struct efx_nic *efx) 3052874aeea5SJeff Kirsher { 30537153f623SBen Hutchings /* Flush reset_work. It can no longer be scheduled since we 30547153f623SBen Hutchings * are not READY. 30557153f623SBen Hutchings */ 30567153f623SBen Hutchings BUG_ON(efx->state == STATE_READY); 30577153f623SBen Hutchings cancel_work_sync(&efx->reset_work); 30587153f623SBen Hutchings 3059d8291187SBen Hutchings efx_disable_interrupts(efx); 3060874aeea5SJeff Kirsher efx_nic_fini_interrupt(efx); 3061874aeea5SJeff Kirsher efx_fini_port(efx); 3062874aeea5SJeff Kirsher efx->type->fini(efx); 3063874aeea5SJeff Kirsher efx_fini_napi(efx); 3064874aeea5SJeff Kirsher efx_remove_all(efx); 3065874aeea5SJeff Kirsher } 3066874aeea5SJeff Kirsher 3067874aeea5SJeff Kirsher /* Final NIC shutdown 30682a3fc311SDaniel Pieczko * This is called only at module unload (or hotplug removal). A PF can call 30692a3fc311SDaniel Pieczko * this on its VFs to ensure they are unbound first. 3070874aeea5SJeff Kirsher */ 3071874aeea5SJeff Kirsher static void efx_pci_remove(struct pci_dev *pci_dev) 3072874aeea5SJeff Kirsher { 3073874aeea5SJeff Kirsher struct efx_nic *efx; 3074874aeea5SJeff Kirsher 3075874aeea5SJeff Kirsher efx = pci_get_drvdata(pci_dev); 3076874aeea5SJeff Kirsher if (!efx) 3077874aeea5SJeff Kirsher return; 3078874aeea5SJeff Kirsher 3079874aeea5SJeff Kirsher /* Mark the NIC as fini, then stop the interface */ 3080874aeea5SJeff Kirsher rtnl_lock(); 30810bcf4a64SBen Hutchings efx_dissociate(efx); 3082874aeea5SJeff Kirsher dev_close(efx->net_dev); 3083d8291187SBen Hutchings efx_disable_interrupts(efx); 3084ea6bb99eSEdward Cree efx->state = STATE_UNINIT; 3085874aeea5SJeff Kirsher rtnl_unlock(); 3086874aeea5SJeff Kirsher 30877fa8d547SShradha Shah if (efx->type->sriov_fini) 3088d98a4ffeSShradha Shah efx->type->sriov_fini(efx); 30897fa8d547SShradha Shah 3090874aeea5SJeff Kirsher efx_unregister_netdev(efx); 3091874aeea5SJeff Kirsher 3092874aeea5SJeff Kirsher efx_mtd_remove(efx); 3093874aeea5SJeff Kirsher 3094874aeea5SJeff Kirsher efx_pci_remove_main(efx); 3095874aeea5SJeff Kirsher 3096874aeea5SJeff Kirsher efx_fini_io(efx); 3097874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); 3098874aeea5SJeff Kirsher 3099874aeea5SJeff Kirsher efx_fini_struct(efx); 3100874aeea5SJeff Kirsher free_netdev(efx->net_dev); 3101626950dbSAlexandre Rames 3102626950dbSAlexandre Rames pci_disable_pcie_error_reporting(pci_dev); 3103874aeea5SJeff Kirsher }; 3104874aeea5SJeff Kirsher 3105460eeaa0SBen Hutchings /* NIC VPD information 3106460eeaa0SBen Hutchings * Called during probe to display the part number of the 3107460eeaa0SBen Hutchings * installed NIC. VPD is potentially very large but this should 3108460eeaa0SBen Hutchings * always appear within the first 512 bytes. 3109460eeaa0SBen Hutchings */ 3110460eeaa0SBen Hutchings #define SFC_VPD_LEN 512 3111ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx) 3112460eeaa0SBen Hutchings { 3113460eeaa0SBen Hutchings struct pci_dev *dev = efx->pci_dev; 3114460eeaa0SBen Hutchings char vpd_data[SFC_VPD_LEN]; 3115460eeaa0SBen Hutchings ssize_t vpd_size; 3116ef215e64SBen Hutchings int ro_start, ro_size, i, j; 3117460eeaa0SBen Hutchings 3118460eeaa0SBen Hutchings /* Get the vpd data from the device */ 3119460eeaa0SBen Hutchings vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data); 3120460eeaa0SBen Hutchings if (vpd_size <= 0) { 3121460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n"); 3122460eeaa0SBen Hutchings return; 3123460eeaa0SBen Hutchings } 3124460eeaa0SBen Hutchings 3125460eeaa0SBen Hutchings /* Get the Read only section */ 3126ef215e64SBen Hutchings ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA); 3127ef215e64SBen Hutchings if (ro_start < 0) { 3128460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n"); 3129460eeaa0SBen Hutchings return; 3130460eeaa0SBen Hutchings } 3131460eeaa0SBen Hutchings 3132ef215e64SBen Hutchings ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]); 3133ef215e64SBen Hutchings j = ro_size; 3134ef215e64SBen Hutchings i = ro_start + PCI_VPD_LRDT_TAG_SIZE; 3135460eeaa0SBen Hutchings if (i + j > vpd_size) 3136460eeaa0SBen Hutchings j = vpd_size - i; 3137460eeaa0SBen Hutchings 3138460eeaa0SBen Hutchings /* Get the Part number */ 3139460eeaa0SBen Hutchings i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN"); 3140460eeaa0SBen Hutchings if (i < 0) { 3141460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Part number not found\n"); 3142460eeaa0SBen Hutchings return; 3143460eeaa0SBen Hutchings } 3144460eeaa0SBen Hutchings 3145460eeaa0SBen Hutchings j = pci_vpd_info_field_size(&vpd_data[i]); 3146460eeaa0SBen Hutchings i += PCI_VPD_INFO_FLD_HDR_SIZE; 3147460eeaa0SBen Hutchings if (i + j > vpd_size) { 3148460eeaa0SBen Hutchings netif_err(efx, drv, efx->net_dev, "Incomplete part number\n"); 3149460eeaa0SBen Hutchings return; 3150460eeaa0SBen Hutchings } 3151460eeaa0SBen Hutchings 3152460eeaa0SBen Hutchings netif_info(efx, drv, efx->net_dev, 3153460eeaa0SBen Hutchings "Part Number : %.*s\n", j, &vpd_data[i]); 3154ef215e64SBen Hutchings 3155ef215e64SBen Hutchings i = ro_start + PCI_VPD_LRDT_TAG_SIZE; 3156ef215e64SBen Hutchings j = ro_size; 3157ef215e64SBen Hutchings i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN"); 3158ef215e64SBen Hutchings if (i < 0) { 3159ef215e64SBen Hutchings netif_err(efx, drv, efx->net_dev, "Serial number not found\n"); 3160ef215e64SBen Hutchings return; 3161ef215e64SBen Hutchings } 3162ef215e64SBen Hutchings 3163ef215e64SBen Hutchings j = pci_vpd_info_field_size(&vpd_data[i]); 3164ef215e64SBen Hutchings i += PCI_VPD_INFO_FLD_HDR_SIZE; 3165ef215e64SBen Hutchings if (i + j > vpd_size) { 3166ef215e64SBen Hutchings netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n"); 3167ef215e64SBen Hutchings return; 3168ef215e64SBen Hutchings } 3169ef215e64SBen Hutchings 3170ef215e64SBen Hutchings efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL); 3171ef215e64SBen Hutchings if (!efx->vpd_sn) 3172ef215e64SBen Hutchings return; 3173ef215e64SBen Hutchings 3174ef215e64SBen Hutchings snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]); 3175460eeaa0SBen Hutchings } 3176460eeaa0SBen Hutchings 3177460eeaa0SBen Hutchings 3178874aeea5SJeff Kirsher /* Main body of NIC initialisation 3179874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, theoretically). 3180874aeea5SJeff Kirsher */ 3181874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx) 3182874aeea5SJeff Kirsher { 3183874aeea5SJeff Kirsher int rc; 3184874aeea5SJeff Kirsher 3185874aeea5SJeff Kirsher /* Do start-of-day initialisation */ 3186874aeea5SJeff Kirsher rc = efx_probe_all(efx); 3187874aeea5SJeff Kirsher if (rc) 3188874aeea5SJeff Kirsher goto fail1; 3189874aeea5SJeff Kirsher 3190874aeea5SJeff Kirsher efx_init_napi(efx); 3191874aeea5SJeff Kirsher 3192874aeea5SJeff Kirsher rc = efx->type->init(efx); 3193874aeea5SJeff Kirsher if (rc) { 3194874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 3195874aeea5SJeff Kirsher "failed to initialise NIC\n"); 3196874aeea5SJeff Kirsher goto fail3; 3197874aeea5SJeff Kirsher } 3198874aeea5SJeff Kirsher 3199874aeea5SJeff Kirsher rc = efx_init_port(efx); 3200874aeea5SJeff Kirsher if (rc) { 3201874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 3202874aeea5SJeff Kirsher "failed to initialise port\n"); 3203874aeea5SJeff Kirsher goto fail4; 3204874aeea5SJeff Kirsher } 3205874aeea5SJeff Kirsher 3206874aeea5SJeff Kirsher rc = efx_nic_init_interrupt(efx); 3207874aeea5SJeff Kirsher if (rc) 3208874aeea5SJeff Kirsher goto fail5; 3209261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 3210261e4d96SJon Cooper if (rc) 3211261e4d96SJon Cooper goto fail6; 3212874aeea5SJeff Kirsher 3213874aeea5SJeff Kirsher return 0; 3214874aeea5SJeff Kirsher 3215261e4d96SJon Cooper fail6: 3216261e4d96SJon Cooper efx_nic_fini_interrupt(efx); 3217874aeea5SJeff Kirsher fail5: 3218874aeea5SJeff Kirsher efx_fini_port(efx); 3219874aeea5SJeff Kirsher fail4: 3220874aeea5SJeff Kirsher efx->type->fini(efx); 3221874aeea5SJeff Kirsher fail3: 3222874aeea5SJeff Kirsher efx_fini_napi(efx); 3223874aeea5SJeff Kirsher efx_remove_all(efx); 3224874aeea5SJeff Kirsher fail1: 3225874aeea5SJeff Kirsher return rc; 3226874aeea5SJeff Kirsher } 3227874aeea5SJeff Kirsher 32288a531400SJon Cooper static int efx_pci_probe_post_io(struct efx_nic *efx) 32298a531400SJon Cooper { 32308a531400SJon Cooper struct net_device *net_dev = efx->net_dev; 32318a531400SJon Cooper int rc = efx_pci_probe_main(efx); 32328a531400SJon Cooper 32338a531400SJon Cooper if (rc) 32348a531400SJon Cooper return rc; 32358a531400SJon Cooper 32368a531400SJon Cooper if (efx->type->sriov_init) { 32378a531400SJon Cooper rc = efx->type->sriov_init(efx); 32388a531400SJon Cooper if (rc) 32398a531400SJon Cooper netif_err(efx, probe, efx->net_dev, 32408a531400SJon Cooper "SR-IOV can't be enabled rc %d\n", rc); 32418a531400SJon Cooper } 32428a531400SJon Cooper 32438a531400SJon Cooper /* Determine netdevice features */ 32448a531400SJon Cooper net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 32458a531400SJon Cooper NETIF_F_TSO | NETIF_F_RXCSUM); 32468a531400SJon Cooper if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) 32478a531400SJon Cooper net_dev->features |= NETIF_F_TSO6; 32488a531400SJon Cooper /* Check whether device supports TSO */ 32498a531400SJon Cooper if (!efx->type->tso_versions || !efx->type->tso_versions(efx)) 32508a531400SJon Cooper net_dev->features &= ~NETIF_F_ALL_TSO; 32518a531400SJon Cooper /* Mask for features that also apply to VLAN devices */ 32528a531400SJon Cooper net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 32538a531400SJon Cooper NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 32548a531400SJon Cooper NETIF_F_RXCSUM); 32558a531400SJon Cooper 32568a531400SJon Cooper net_dev->hw_features = net_dev->features & ~efx->fixed_features; 32578a531400SJon Cooper 32588a531400SJon Cooper /* Disable VLAN filtering by default. It may be enforced if 32598a531400SJon Cooper * the feature is fixed (i.e. VLAN filters are required to 32608a531400SJon Cooper * receive VLAN tagged packets due to vPort restrictions). 32618a531400SJon Cooper */ 32628a531400SJon Cooper net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 32638a531400SJon Cooper net_dev->features |= efx->fixed_features; 32648a531400SJon Cooper 32658a531400SJon Cooper rc = efx_register_netdev(efx); 32668a531400SJon Cooper if (!rc) 32678a531400SJon Cooper return 0; 32688a531400SJon Cooper 32698a531400SJon Cooper efx_pci_remove_main(efx); 32708a531400SJon Cooper return rc; 32718a531400SJon Cooper } 32728a531400SJon Cooper 3273874aeea5SJeff Kirsher /* NIC initialisation 3274874aeea5SJeff Kirsher * 3275874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, 327673ba7b68SBen Hutchings * theoretically). It sets up PCI mappings, resets the NIC, 3277874aeea5SJeff Kirsher * sets up and registers the network devices with the kernel and hooks 3278874aeea5SJeff Kirsher * the interrupt service routine. It does not prepare the device for 3279874aeea5SJeff Kirsher * transmission; this is left to the first time one of the network 3280874aeea5SJeff Kirsher * interfaces is brought up (i.e. efx_net_open). 3281874aeea5SJeff Kirsher */ 328287d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev, 3283874aeea5SJeff Kirsher const struct pci_device_id *entry) 3284874aeea5SJeff Kirsher { 3285874aeea5SJeff Kirsher struct net_device *net_dev; 3286874aeea5SJeff Kirsher struct efx_nic *efx; 3287fadac6aaSBen Hutchings int rc; 3288874aeea5SJeff Kirsher 3289874aeea5SJeff Kirsher /* Allocate and initialise a struct net_device and struct efx_nic */ 3290874aeea5SJeff Kirsher net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES, 3291874aeea5SJeff Kirsher EFX_MAX_RX_QUEUES); 3292874aeea5SJeff Kirsher if (!net_dev) 3293874aeea5SJeff Kirsher return -ENOMEM; 3294adeb15aaSBen Hutchings efx = netdev_priv(net_dev); 3295adeb15aaSBen Hutchings efx->type = (const struct efx_nic_type *) entry->driver_data; 3296ebfcd0fdSAndrew Rybchenko efx->fixed_features |= NETIF_F_HIGHDMA; 3297eb7cfd8cSAndrew Rybchenko 3298874aeea5SJeff Kirsher pci_set_drvdata(pci_dev, efx); 3299874aeea5SJeff Kirsher SET_NETDEV_DEV(net_dev, &pci_dev->dev); 3300adeb15aaSBen Hutchings rc = efx_init_struct(efx, pci_dev, net_dev); 3301874aeea5SJeff Kirsher if (rc) 3302874aeea5SJeff Kirsher goto fail1; 3303874aeea5SJeff Kirsher 3304874aeea5SJeff Kirsher netif_info(efx, probe, efx->net_dev, 3305874aeea5SJeff Kirsher "Solarflare NIC detected\n"); 3306874aeea5SJeff Kirsher 33076f7f8aa6SShradha Shah if (!efx->type->is_vf) 3308ef215e64SBen Hutchings efx_probe_vpd_strings(efx); 3309460eeaa0SBen Hutchings 3310874aeea5SJeff Kirsher /* Set up basic I/O (BAR mappings etc) */ 3311874aeea5SJeff Kirsher rc = efx_init_io(efx); 3312874aeea5SJeff Kirsher if (rc) 3313874aeea5SJeff Kirsher goto fail2; 3314874aeea5SJeff Kirsher 33158a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 33168a531400SJon Cooper if (rc) { 33178a531400SJon Cooper /* On failure, retry once immediately. 33188a531400SJon Cooper * If we aborted probe due to a scheduled reset, dismiss it. 33198a531400SJon Cooper */ 33208a531400SJon Cooper efx->reset_pending = 0; 33218a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 33228a531400SJon Cooper if (rc) { 33238a531400SJon Cooper /* On another failure, retry once more 33248a531400SJon Cooper * after a 50-305ms delay. 33258a531400SJon Cooper */ 33268a531400SJon Cooper unsigned char r; 33278a531400SJon Cooper 33288a531400SJon Cooper get_random_bytes(&r, 1); 33298a531400SJon Cooper msleep((unsigned int)r + 50); 33308a531400SJon Cooper efx->reset_pending = 0; 33318a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 33328a531400SJon Cooper } 33338a531400SJon Cooper } 3334fadac6aaSBen Hutchings if (rc) 3335874aeea5SJeff Kirsher goto fail3; 3336874aeea5SJeff Kirsher 3337874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); 3338874aeea5SJeff Kirsher 33397c43161cSBen Hutchings /* Try to create MTDs, but allow this to fail */ 3340874aeea5SJeff Kirsher rtnl_lock(); 33417c43161cSBen Hutchings rc = efx_mtd_probe(efx); 3342874aeea5SJeff Kirsher rtnl_unlock(); 334309a04204SBert Kenward if (rc && rc != -EPERM) 33447c43161cSBen Hutchings netif_warn(efx, probe, efx->net_dev, 33457c43161cSBen Hutchings "failed to create MTDs (%d)\n", rc); 33467c43161cSBen Hutchings 3347626950dbSAlexandre Rames rc = pci_enable_pcie_error_reporting(pci_dev); 3348626950dbSAlexandre Rames if (rc && rc != -EINVAL) 334909a04204SBert Kenward netif_notice(efx, probe, efx->net_dev, 335009a04204SBert Kenward "PCIE error reporting unavailable (%d).\n", 335109a04204SBert Kenward rc); 3352626950dbSAlexandre Rames 3353e5fbd977SJon Cooper if (efx->type->udp_tnl_push_ports) 3354e5fbd977SJon Cooper efx->type->udp_tnl_push_ports(efx); 3355e5fbd977SJon Cooper 3356874aeea5SJeff Kirsher return 0; 3357874aeea5SJeff Kirsher 3358874aeea5SJeff Kirsher fail3: 3359874aeea5SJeff Kirsher efx_fini_io(efx); 3360874aeea5SJeff Kirsher fail2: 3361874aeea5SJeff Kirsher efx_fini_struct(efx); 3362874aeea5SJeff Kirsher fail1: 3363874aeea5SJeff Kirsher WARN_ON(rc > 0); 3364874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); 3365874aeea5SJeff Kirsher free_netdev(net_dev); 3366874aeea5SJeff Kirsher return rc; 3367874aeea5SJeff Kirsher } 3368874aeea5SJeff Kirsher 3369834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions 3370834e23ddSShradha Shah * enabled on success 3371834e23ddSShradha Shah */ 3372834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 3373834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) 3374834e23ddSShradha Shah { 3375834e23ddSShradha Shah int rc; 3376834e23ddSShradha Shah struct efx_nic *efx = pci_get_drvdata(dev); 3377834e23ddSShradha Shah 3378834e23ddSShradha Shah if (efx->type->sriov_configure) { 3379834e23ddSShradha Shah rc = efx->type->sriov_configure(efx, num_vfs); 3380834e23ddSShradha Shah if (rc) 3381834e23ddSShradha Shah return rc; 3382834e23ddSShradha Shah else 3383834e23ddSShradha Shah return num_vfs; 3384834e23ddSShradha Shah } else 3385834e23ddSShradha Shah return -EOPNOTSUPP; 3386834e23ddSShradha Shah } 3387834e23ddSShradha Shah #endif 3388834e23ddSShradha Shah 3389874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev) 3390874aeea5SJeff Kirsher { 3391874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 3392874aeea5SJeff Kirsher 339361da026dSBen Hutchings rtnl_lock(); 339461da026dSBen Hutchings 33956032fb56SBen Hutchings if (efx->state != STATE_DISABLED) { 3396f16aeea0SBen Hutchings efx->state = STATE_UNINIT; 3397874aeea5SJeff Kirsher 3398c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 3399874aeea5SJeff Kirsher 3400874aeea5SJeff Kirsher efx_stop_all(efx); 3401d8291187SBen Hutchings efx_disable_interrupts(efx); 34026032fb56SBen Hutchings } 3403874aeea5SJeff Kirsher 340461da026dSBen Hutchings rtnl_unlock(); 340561da026dSBen Hutchings 3406874aeea5SJeff Kirsher return 0; 3407874aeea5SJeff Kirsher } 3408874aeea5SJeff Kirsher 3409874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev) 3410874aeea5SJeff Kirsher { 3411261e4d96SJon Cooper int rc; 3412874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); 3413874aeea5SJeff Kirsher 341461da026dSBen Hutchings rtnl_lock(); 341561da026dSBen Hutchings 34166032fb56SBen Hutchings if (efx->state != STATE_DISABLED) { 3417261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 3418261e4d96SJon Cooper if (rc) 3419261e4d96SJon Cooper goto fail; 3420874aeea5SJeff Kirsher 3421874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 3422874aeea5SJeff Kirsher efx->phy_op->reconfigure(efx); 3423874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 3424874aeea5SJeff Kirsher 3425874aeea5SJeff Kirsher efx_start_all(efx); 3426874aeea5SJeff Kirsher 34279c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 3428874aeea5SJeff Kirsher 3429f16aeea0SBen Hutchings efx->state = STATE_READY; 3430874aeea5SJeff Kirsher 3431874aeea5SJeff Kirsher efx->type->resume_wol(efx); 34326032fb56SBen Hutchings } 3433874aeea5SJeff Kirsher 343461da026dSBen Hutchings rtnl_unlock(); 343561da026dSBen Hutchings 3436874aeea5SJeff Kirsher /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ 3437874aeea5SJeff Kirsher queue_work(reset_workqueue, &efx->reset_work); 3438874aeea5SJeff Kirsher 3439874aeea5SJeff Kirsher return 0; 3440261e4d96SJon Cooper 3441261e4d96SJon Cooper fail: 3442261e4d96SJon Cooper rtnl_unlock(); 3443261e4d96SJon Cooper 3444261e4d96SJon Cooper return rc; 3445874aeea5SJeff Kirsher } 3446874aeea5SJeff Kirsher 3447874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev) 3448874aeea5SJeff Kirsher { 3449874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 3450874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 3451874aeea5SJeff Kirsher 3452874aeea5SJeff Kirsher efx->type->fini(efx); 3453874aeea5SJeff Kirsher 3454874aeea5SJeff Kirsher efx->reset_pending = 0; 3455874aeea5SJeff Kirsher 3456874aeea5SJeff Kirsher pci_save_state(pci_dev); 3457874aeea5SJeff Kirsher return pci_set_power_state(pci_dev, PCI_D3hot); 3458874aeea5SJeff Kirsher } 3459874aeea5SJeff Kirsher 3460874aeea5SJeff Kirsher /* Used for both resume and restore */ 3461874aeea5SJeff Kirsher static int efx_pm_resume(struct device *dev) 3462874aeea5SJeff Kirsher { 3463874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 3464874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 3465874aeea5SJeff Kirsher int rc; 3466874aeea5SJeff Kirsher 3467874aeea5SJeff Kirsher rc = pci_set_power_state(pci_dev, PCI_D0); 3468874aeea5SJeff Kirsher if (rc) 3469874aeea5SJeff Kirsher return rc; 3470874aeea5SJeff Kirsher pci_restore_state(pci_dev); 3471874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 3472874aeea5SJeff Kirsher if (rc) 3473874aeea5SJeff Kirsher return rc; 3474874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 3475874aeea5SJeff Kirsher rc = efx->type->reset(efx, RESET_TYPE_ALL); 3476874aeea5SJeff Kirsher if (rc) 3477874aeea5SJeff Kirsher return rc; 3478874aeea5SJeff Kirsher rc = efx->type->init(efx); 3479874aeea5SJeff Kirsher if (rc) 3480874aeea5SJeff Kirsher return rc; 3481261e4d96SJon Cooper rc = efx_pm_thaw(dev); 3482261e4d96SJon Cooper return rc; 3483874aeea5SJeff Kirsher } 3484874aeea5SJeff Kirsher 3485874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev) 3486874aeea5SJeff Kirsher { 3487874aeea5SJeff Kirsher int rc; 3488874aeea5SJeff Kirsher 3489874aeea5SJeff Kirsher efx_pm_freeze(dev); 3490874aeea5SJeff Kirsher rc = efx_pm_poweroff(dev); 3491874aeea5SJeff Kirsher if (rc) 3492874aeea5SJeff Kirsher efx_pm_resume(dev); 3493874aeea5SJeff Kirsher return rc; 3494874aeea5SJeff Kirsher } 3495874aeea5SJeff Kirsher 349618e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = { 3497874aeea5SJeff Kirsher .suspend = efx_pm_suspend, 3498874aeea5SJeff Kirsher .resume = efx_pm_resume, 3499874aeea5SJeff Kirsher .freeze = efx_pm_freeze, 3500874aeea5SJeff Kirsher .thaw = efx_pm_thaw, 3501874aeea5SJeff Kirsher .poweroff = efx_pm_poweroff, 3502874aeea5SJeff Kirsher .restore = efx_pm_resume, 3503874aeea5SJeff Kirsher }; 3504874aeea5SJeff Kirsher 3505626950dbSAlexandre Rames /* A PCI error affecting this device was detected. 3506626950dbSAlexandre Rames * At this point MMIO and DMA may be disabled. 3507626950dbSAlexandre Rames * Stop the software path and request a slot reset. 3508626950dbSAlexandre Rames */ 3509debd0034Sstephen hemminger static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev, 3510626950dbSAlexandre Rames enum pci_channel_state state) 3511626950dbSAlexandre Rames { 3512626950dbSAlexandre Rames pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 3513626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3514626950dbSAlexandre Rames 3515626950dbSAlexandre Rames if (state == pci_channel_io_perm_failure) 3516626950dbSAlexandre Rames return PCI_ERS_RESULT_DISCONNECT; 3517626950dbSAlexandre Rames 3518626950dbSAlexandre Rames rtnl_lock(); 3519626950dbSAlexandre Rames 3520626950dbSAlexandre Rames if (efx->state != STATE_DISABLED) { 3521626950dbSAlexandre Rames efx->state = STATE_RECOVERY; 3522626950dbSAlexandre Rames efx->reset_pending = 0; 3523626950dbSAlexandre Rames 3524626950dbSAlexandre Rames efx_device_detach_sync(efx); 3525626950dbSAlexandre Rames 3526626950dbSAlexandre Rames efx_stop_all(efx); 3527d8291187SBen Hutchings efx_disable_interrupts(efx); 3528626950dbSAlexandre Rames 3529626950dbSAlexandre Rames status = PCI_ERS_RESULT_NEED_RESET; 3530626950dbSAlexandre Rames } else { 3531626950dbSAlexandre Rames /* If the interface is disabled we don't want to do anything 3532626950dbSAlexandre Rames * with it. 3533626950dbSAlexandre Rames */ 3534626950dbSAlexandre Rames status = PCI_ERS_RESULT_RECOVERED; 3535626950dbSAlexandre Rames } 3536626950dbSAlexandre Rames 3537626950dbSAlexandre Rames rtnl_unlock(); 3538626950dbSAlexandre Rames 3539626950dbSAlexandre Rames pci_disable_device(pdev); 3540626950dbSAlexandre Rames 3541626950dbSAlexandre Rames return status; 3542626950dbSAlexandre Rames } 3543626950dbSAlexandre Rames 3544dbedd44eSJoe Perches /* Fake a successful reset, which will be performed later in efx_io_resume. */ 3545debd0034Sstephen hemminger static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev) 3546626950dbSAlexandre Rames { 3547626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3548626950dbSAlexandre Rames pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 3549626950dbSAlexandre Rames int rc; 3550626950dbSAlexandre Rames 3551626950dbSAlexandre Rames if (pci_enable_device(pdev)) { 3552626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3553626950dbSAlexandre Rames "Cannot re-enable PCI device after reset.\n"); 3554626950dbSAlexandre Rames status = PCI_ERS_RESULT_DISCONNECT; 3555626950dbSAlexandre Rames } 3556626950dbSAlexandre Rames 3557626950dbSAlexandre Rames rc = pci_cleanup_aer_uncorrect_error_status(pdev); 3558626950dbSAlexandre Rames if (rc) { 3559626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3560626950dbSAlexandre Rames "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc); 3561626950dbSAlexandre Rames /* Non-fatal error. Continue. */ 3562626950dbSAlexandre Rames } 3563626950dbSAlexandre Rames 3564626950dbSAlexandre Rames return status; 3565626950dbSAlexandre Rames } 3566626950dbSAlexandre Rames 3567626950dbSAlexandre Rames /* Perform the actual reset and resume I/O operations. */ 3568626950dbSAlexandre Rames static void efx_io_resume(struct pci_dev *pdev) 3569626950dbSAlexandre Rames { 3570626950dbSAlexandre Rames struct efx_nic *efx = pci_get_drvdata(pdev); 3571626950dbSAlexandre Rames int rc; 3572626950dbSAlexandre Rames 3573626950dbSAlexandre Rames rtnl_lock(); 3574626950dbSAlexandre Rames 3575626950dbSAlexandre Rames if (efx->state == STATE_DISABLED) 3576626950dbSAlexandre Rames goto out; 3577626950dbSAlexandre Rames 3578626950dbSAlexandre Rames rc = efx_reset(efx, RESET_TYPE_ALL); 3579626950dbSAlexandre Rames if (rc) { 3580626950dbSAlexandre Rames netif_err(efx, hw, efx->net_dev, 3581626950dbSAlexandre Rames "efx_reset failed after PCI error (%d)\n", rc); 3582626950dbSAlexandre Rames } else { 3583626950dbSAlexandre Rames efx->state = STATE_READY; 3584626950dbSAlexandre Rames netif_dbg(efx, hw, efx->net_dev, 3585626950dbSAlexandre Rames "Done resetting and resuming IO after PCI error.\n"); 3586626950dbSAlexandre Rames } 3587626950dbSAlexandre Rames 3588626950dbSAlexandre Rames out: 3589626950dbSAlexandre Rames rtnl_unlock(); 3590626950dbSAlexandre Rames } 3591626950dbSAlexandre Rames 3592626950dbSAlexandre Rames /* For simplicity and reliability, we always require a slot reset and try to 3593626950dbSAlexandre Rames * reset the hardware when a pci error affecting the device is detected. 3594626950dbSAlexandre Rames * We leave both the link_reset and mmio_enabled callback unimplemented: 3595626950dbSAlexandre Rames * with our request for slot reset the mmio_enabled callback will never be 3596626950dbSAlexandre Rames * called, and the link_reset callback is not used by AER or EEH mechanisms. 3597626950dbSAlexandre Rames */ 3598c300366bSJulia Lawall static const struct pci_error_handlers efx_err_handlers = { 3599626950dbSAlexandre Rames .error_detected = efx_io_error_detected, 3600626950dbSAlexandre Rames .slot_reset = efx_io_slot_reset, 3601626950dbSAlexandre Rames .resume = efx_io_resume, 3602626950dbSAlexandre Rames }; 3603626950dbSAlexandre Rames 3604874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = { 3605874aeea5SJeff Kirsher .name = KBUILD_MODNAME, 3606874aeea5SJeff Kirsher .id_table = efx_pci_table, 3607874aeea5SJeff Kirsher .probe = efx_pci_probe, 3608874aeea5SJeff Kirsher .remove = efx_pci_remove, 3609874aeea5SJeff Kirsher .driver.pm = &efx_pm_ops, 3610626950dbSAlexandre Rames .err_handler = &efx_err_handlers, 3611834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 3612834e23ddSShradha Shah .sriov_configure = efx_pci_sriov_configure, 3613834e23ddSShradha Shah #endif 3614874aeea5SJeff Kirsher }; 3615874aeea5SJeff Kirsher 3616874aeea5SJeff Kirsher /************************************************************************** 3617874aeea5SJeff Kirsher * 3618874aeea5SJeff Kirsher * Kernel module interface 3619874aeea5SJeff Kirsher * 3620874aeea5SJeff Kirsher *************************************************************************/ 3621874aeea5SJeff Kirsher 3622874aeea5SJeff Kirsher module_param(interrupt_mode, uint, 0444); 3623874aeea5SJeff Kirsher MODULE_PARM_DESC(interrupt_mode, 3624874aeea5SJeff Kirsher "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); 3625874aeea5SJeff Kirsher 3626874aeea5SJeff Kirsher static int __init efx_init_module(void) 3627874aeea5SJeff Kirsher { 3628874aeea5SJeff Kirsher int rc; 3629874aeea5SJeff Kirsher 3630874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n"); 3631874aeea5SJeff Kirsher 3632874aeea5SJeff Kirsher rc = register_netdevice_notifier(&efx_netdev_notifier); 3633874aeea5SJeff Kirsher if (rc) 3634874aeea5SJeff Kirsher goto err_notifier; 3635874aeea5SJeff Kirsher 36367fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3637cd2d5b52SBen Hutchings rc = efx_init_sriov(); 3638cd2d5b52SBen Hutchings if (rc) 3639cd2d5b52SBen Hutchings goto err_sriov; 36407fa8d547SShradha Shah #endif 3641cd2d5b52SBen Hutchings 3642874aeea5SJeff Kirsher reset_workqueue = create_singlethread_workqueue("sfc_reset"); 3643874aeea5SJeff Kirsher if (!reset_workqueue) { 3644874aeea5SJeff Kirsher rc = -ENOMEM; 3645874aeea5SJeff Kirsher goto err_reset; 3646874aeea5SJeff Kirsher } 3647874aeea5SJeff Kirsher 3648874aeea5SJeff Kirsher rc = pci_register_driver(&efx_pci_driver); 3649874aeea5SJeff Kirsher if (rc < 0) 3650874aeea5SJeff Kirsher goto err_pci; 3651874aeea5SJeff Kirsher 3652874aeea5SJeff Kirsher return 0; 3653874aeea5SJeff Kirsher 3654874aeea5SJeff Kirsher err_pci: 3655874aeea5SJeff Kirsher destroy_workqueue(reset_workqueue); 3656874aeea5SJeff Kirsher err_reset: 36577fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3658cd2d5b52SBen Hutchings efx_fini_sriov(); 3659cd2d5b52SBen Hutchings err_sriov: 36607fa8d547SShradha Shah #endif 3661874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 3662874aeea5SJeff Kirsher err_notifier: 3663874aeea5SJeff Kirsher return rc; 3664874aeea5SJeff Kirsher } 3665874aeea5SJeff Kirsher 3666874aeea5SJeff Kirsher static void __exit efx_exit_module(void) 3667874aeea5SJeff Kirsher { 3668874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver unloading\n"); 3669874aeea5SJeff Kirsher 3670874aeea5SJeff Kirsher pci_unregister_driver(&efx_pci_driver); 3671874aeea5SJeff Kirsher destroy_workqueue(reset_workqueue); 36727fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV 3673cd2d5b52SBen Hutchings efx_fini_sriov(); 36747fa8d547SShradha Shah #endif 3675874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 3676874aeea5SJeff Kirsher 3677874aeea5SJeff Kirsher } 3678874aeea5SJeff Kirsher 3679874aeea5SJeff Kirsher module_init(efx_init_module); 3680874aeea5SJeff Kirsher module_exit(efx_exit_module); 3681874aeea5SJeff Kirsher 3682874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and " 3683874aeea5SJeff Kirsher "Michael Brown <mbrown@fensystems.co.uk>"); 36846a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver"); 3685874aeea5SJeff Kirsher MODULE_LICENSE("GPL"); 3686874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table); 368714077e9eSEdward Cree MODULE_VERSION(EFX_DRIVER_VERSION); 3688