1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2874aeea5SJeff Kirsher /**************************************************************************** 3f7a6d2c4SBen Hutchings * Driver for Solarflare network controllers and boards 4874aeea5SJeff Kirsher * Copyright 2005-2006 Fen Systems Ltd. 5f7a6d2c4SBen Hutchings * Copyright 2005-2013 Solarflare Communications Inc. 6874aeea5SJeff Kirsher */ 7874aeea5SJeff Kirsher 8b6459415SJakub Kicinski #include <linux/filter.h> 9874aeea5SJeff Kirsher #include <linux/module.h> 10874aeea5SJeff Kirsher #include <linux/pci.h> 11874aeea5SJeff Kirsher #include <linux/netdevice.h> 12874aeea5SJeff Kirsher #include <linux/etherdevice.h> 13874aeea5SJeff Kirsher #include <linux/delay.h> 14874aeea5SJeff Kirsher #include <linux/notifier.h> 15874aeea5SJeff Kirsher #include <linux/ip.h> 16874aeea5SJeff Kirsher #include <linux/tcp.h> 17874aeea5SJeff Kirsher #include <linux/in.h> 18874aeea5SJeff Kirsher #include <linux/ethtool.h> 19874aeea5SJeff Kirsher #include <linux/topology.h> 20874aeea5SJeff Kirsher #include <linux/gfp.h> 21626950dbSAlexandre Rames #include <linux/aer.h> 22b28405b0SAlexandre Rames #include <linux/interrupt.h> 23874aeea5SJeff Kirsher #include "net_driver.h" 24e5fbd977SJon Cooper #include <net/gre.h> 25e5fbd977SJon Cooper #include <net/udp_tunnel.h> 26874aeea5SJeff Kirsher #include "efx.h" 27e1253f39SAlex Maftei (amaftei) #include "efx_common.h" 28e1253f39SAlex Maftei (amaftei) #include "efx_channels.h" 2951b35a45SEdward Cree #include "ef100.h" 30e1253f39SAlex Maftei (amaftei) #include "rx_common.h" 31e1253f39SAlex Maftei (amaftei) #include "tx_common.h" 32874aeea5SJeff Kirsher #include "nic.h" 3371827443SEdward Cree #include "io.h" 34dd40781eSBen Hutchings #include "selftest.h" 357fa8d547SShradha Shah #include "sriov.h" 36874aeea5SJeff Kirsher 37c77289b4SEdward Cree #include "mcdi_port_common.h" 38e5fbd977SJon Cooper #include "mcdi_pcol.h" 39874aeea5SJeff Kirsher #include "workarounds.h" 40874aeea5SJeff Kirsher 41874aeea5SJeff Kirsher /************************************************************************** 42874aeea5SJeff Kirsher * 43874aeea5SJeff Kirsher * Configurable values 44874aeea5SJeff Kirsher * 45874aeea5SJeff Kirsher *************************************************************************/ 46874aeea5SJeff Kirsher 47e4ff3232SEdward Cree module_param_named(interrupt_mode, efx_interrupt_mode, uint, 0444); 48e4ff3232SEdward Cree MODULE_PARM_DESC(interrupt_mode, 49e4ff3232SEdward Cree "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); 50e4ff3232SEdward Cree 5167e6398eSEdward Cree module_param(rss_cpus, uint, 0444); 5267e6398eSEdward Cree MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); 5367e6398eSEdward Cree 54874aeea5SJeff Kirsher /* 55874aeea5SJeff Kirsher * Use separate channels for TX and RX events 56874aeea5SJeff Kirsher * 57874aeea5SJeff Kirsher * Set this to 1 to use separate channels for TX and RX. It allows us 58874aeea5SJeff Kirsher * to control interrupt affinity separately for TX and RX. 59874aeea5SJeff Kirsher * 60874aeea5SJeff Kirsher * This is only used in MSI-X interrupt mode 61874aeea5SJeff Kirsher */ 62b0fbdae1SShradha Shah bool efx_separate_tx_channels; 63b0fbdae1SShradha Shah module_param(efx_separate_tx_channels, bool, 0444); 64b0fbdae1SShradha Shah MODULE_PARM_DESC(efx_separate_tx_channels, 65874aeea5SJeff Kirsher "Use separate channels for TX and RX"); 66874aeea5SJeff Kirsher 67874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 68874aeea5SJeff Kirsher * module load with ethtool. 69874aeea5SJeff Kirsher * 70874aeea5SJeff Kirsher * The default for RX should strike a balance between increasing the 71874aeea5SJeff Kirsher * round-trip latency and reducing overhead. 72874aeea5SJeff Kirsher */ 73874aeea5SJeff Kirsher static unsigned int rx_irq_mod_usec = 60; 74874aeea5SJeff Kirsher 75874aeea5SJeff Kirsher /* Initial interrupt moderation settings. They can be modified after 76874aeea5SJeff Kirsher * module load with ethtool. 77874aeea5SJeff Kirsher * 78874aeea5SJeff Kirsher * This default is chosen to ensure that a 10G link does not go idle 79874aeea5SJeff Kirsher * while a TX queue is stopped after it has become full. A queue is 80874aeea5SJeff Kirsher * restarted when it drops below half full. The time this takes (assuming 81874aeea5SJeff Kirsher * worst case 3 descriptors per packet and 1024 descriptors) is 82874aeea5SJeff Kirsher * 512 / 3 * 1.2 = 205 usec. 83874aeea5SJeff Kirsher */ 84874aeea5SJeff Kirsher static unsigned int tx_irq_mod_usec = 150; 85874aeea5SJeff Kirsher 86b9cc977dSBen Hutchings static bool phy_flash_cfg; 87b9cc977dSBen Hutchings module_param(phy_flash_cfg, bool, 0644); 88874aeea5SJeff Kirsher MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); 89874aeea5SJeff Kirsher 90874aeea5SJeff Kirsher static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | 91874aeea5SJeff Kirsher NETIF_MSG_LINK | NETIF_MSG_IFDOWN | 92874aeea5SJeff Kirsher NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | 93874aeea5SJeff Kirsher NETIF_MSG_TX_ERR | NETIF_MSG_HW); 94874aeea5SJeff Kirsher module_param(debug, uint, 0); 95874aeea5SJeff Kirsher MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); 96874aeea5SJeff Kirsher 97874aeea5SJeff Kirsher /************************************************************************** 98874aeea5SJeff Kirsher * 99874aeea5SJeff Kirsher * Utility functions and prototypes 100874aeea5SJeff Kirsher * 101874aeea5SJeff Kirsher *************************************************************************/ 102874aeea5SJeff Kirsher 103874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx); 104e45a4fedSCharles McLachlan static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog); 105e45a4fedSCharles McLachlan static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp); 106dfe44c1fSCharles McLachlan static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs, 107dfe44c1fSCharles McLachlan u32 flags); 108874aeea5SJeff Kirsher 109874aeea5SJeff Kirsher /************************************************************************** 110874aeea5SJeff Kirsher * 111874aeea5SJeff Kirsher * Port handling 112874aeea5SJeff Kirsher * 113874aeea5SJeff Kirsher **************************************************************************/ 114874aeea5SJeff Kirsher 115874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx); 116874aeea5SJeff Kirsher 117874aeea5SJeff Kirsher static int efx_probe_port(struct efx_nic *efx) 118874aeea5SJeff Kirsher { 119874aeea5SJeff Kirsher int rc; 120874aeea5SJeff Kirsher 121874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "create port\n"); 122874aeea5SJeff Kirsher 123874aeea5SJeff Kirsher if (phy_flash_cfg) 124874aeea5SJeff Kirsher efx->phy_mode = PHY_MODE_SPECIAL; 125874aeea5SJeff Kirsher 126874aeea5SJeff Kirsher /* Connect up MAC/PHY operations table */ 127874aeea5SJeff Kirsher rc = efx->type->probe_port(efx); 128874aeea5SJeff Kirsher if (rc) 129874aeea5SJeff Kirsher return rc; 130874aeea5SJeff Kirsher 131e332bcb3SBen Hutchings /* Initialise MAC address to permanent address */ 132f3956ebbSJakub Kicinski eth_hw_addr_set(efx->net_dev, efx->net_dev->perm_addr); 133874aeea5SJeff Kirsher 134874aeea5SJeff Kirsher return 0; 135874aeea5SJeff Kirsher } 136874aeea5SJeff Kirsher 137874aeea5SJeff Kirsher static int efx_init_port(struct efx_nic *efx) 138874aeea5SJeff Kirsher { 139874aeea5SJeff Kirsher int rc; 140874aeea5SJeff Kirsher 141874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "init port\n"); 142874aeea5SJeff Kirsher 143874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 144874aeea5SJeff Kirsher 145874aeea5SJeff Kirsher efx->port_initialized = true; 146874aeea5SJeff Kirsher 147874aeea5SJeff Kirsher /* Ensure the PHY advertises the correct flow control settings */ 148c77289b4SEdward Cree rc = efx_mcdi_port_reconfigure(efx); 149267d9d73SEdward Cree if (rc && rc != -EPERM) 150c77289b4SEdward Cree goto fail; 151874aeea5SJeff Kirsher 152874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 153874aeea5SJeff Kirsher return 0; 154874aeea5SJeff Kirsher 155c77289b4SEdward Cree fail: 156874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 157874aeea5SJeff Kirsher return rc; 158874aeea5SJeff Kirsher } 159874aeea5SJeff Kirsher 160874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx) 161874aeea5SJeff Kirsher { 162874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); 163874aeea5SJeff Kirsher 164874aeea5SJeff Kirsher if (!efx->port_initialized) 165874aeea5SJeff Kirsher return; 166874aeea5SJeff Kirsher 167874aeea5SJeff Kirsher efx->port_initialized = false; 168874aeea5SJeff Kirsher 169874aeea5SJeff Kirsher efx->link_state.up = false; 170874aeea5SJeff Kirsher efx_link_status_changed(efx); 171874aeea5SJeff Kirsher } 172874aeea5SJeff Kirsher 173874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx) 174874aeea5SJeff Kirsher { 175874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); 176874aeea5SJeff Kirsher 177874aeea5SJeff Kirsher efx->type->remove_port(efx); 178874aeea5SJeff Kirsher } 179874aeea5SJeff Kirsher 180874aeea5SJeff Kirsher /************************************************************************** 181874aeea5SJeff Kirsher * 182874aeea5SJeff Kirsher * NIC handling 183874aeea5SJeff Kirsher * 184874aeea5SJeff Kirsher **************************************************************************/ 185874aeea5SJeff Kirsher 1860bcf4a64SBen Hutchings static LIST_HEAD(efx_primary_list); 1870bcf4a64SBen Hutchings static LIST_HEAD(efx_unassociated_list); 1880bcf4a64SBen Hutchings 1890bcf4a64SBen Hutchings static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right) 1900bcf4a64SBen Hutchings { 1910bcf4a64SBen Hutchings return left->type == right->type && 1920bcf4a64SBen Hutchings left->vpd_sn && right->vpd_sn && 1930bcf4a64SBen Hutchings !strcmp(left->vpd_sn, right->vpd_sn); 1940bcf4a64SBen Hutchings } 1950bcf4a64SBen Hutchings 1960bcf4a64SBen Hutchings static void efx_associate(struct efx_nic *efx) 1970bcf4a64SBen Hutchings { 1980bcf4a64SBen Hutchings struct efx_nic *other, *next; 1990bcf4a64SBen Hutchings 2000bcf4a64SBen Hutchings if (efx->primary == efx) { 2010bcf4a64SBen Hutchings /* Adding primary function; look for secondaries */ 2020bcf4a64SBen Hutchings 2030bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n"); 2040bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_primary_list); 2050bcf4a64SBen Hutchings 2060bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx_unassociated_list, 2070bcf4a64SBen Hutchings node) { 2080bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 2090bcf4a64SBen Hutchings list_del(&other->node); 2100bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 2110bcf4a64SBen Hutchings "moving to secondary list of %s %s\n", 2120bcf4a64SBen Hutchings pci_name(efx->pci_dev), 2130bcf4a64SBen Hutchings efx->net_dev->name); 2140bcf4a64SBen Hutchings list_add_tail(&other->node, 2150bcf4a64SBen Hutchings &efx->secondary_list); 2160bcf4a64SBen Hutchings other->primary = efx; 2170bcf4a64SBen Hutchings } 2180bcf4a64SBen Hutchings } 2190bcf4a64SBen Hutchings } else { 2200bcf4a64SBen Hutchings /* Adding secondary function; look for primary */ 2210bcf4a64SBen Hutchings 2220bcf4a64SBen Hutchings list_for_each_entry(other, &efx_primary_list, node) { 2230bcf4a64SBen Hutchings if (efx_same_controller(efx, other)) { 2240bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 2250bcf4a64SBen Hutchings "adding to secondary list of %s %s\n", 2260bcf4a64SBen Hutchings pci_name(other->pci_dev), 2270bcf4a64SBen Hutchings other->net_dev->name); 2280bcf4a64SBen Hutchings list_add_tail(&efx->node, 2290bcf4a64SBen Hutchings &other->secondary_list); 2300bcf4a64SBen Hutchings efx->primary = other; 2310bcf4a64SBen Hutchings return; 2320bcf4a64SBen Hutchings } 2330bcf4a64SBen Hutchings } 2340bcf4a64SBen Hutchings 2350bcf4a64SBen Hutchings netif_dbg(efx, probe, efx->net_dev, 2360bcf4a64SBen Hutchings "adding to unassociated list\n"); 2370bcf4a64SBen Hutchings list_add_tail(&efx->node, &efx_unassociated_list); 2380bcf4a64SBen Hutchings } 2390bcf4a64SBen Hutchings } 2400bcf4a64SBen Hutchings 2410bcf4a64SBen Hutchings static void efx_dissociate(struct efx_nic *efx) 2420bcf4a64SBen Hutchings { 2430bcf4a64SBen Hutchings struct efx_nic *other, *next; 2440bcf4a64SBen Hutchings 2450bcf4a64SBen Hutchings list_del(&efx->node); 2460bcf4a64SBen Hutchings efx->primary = NULL; 2470bcf4a64SBen Hutchings 2480bcf4a64SBen Hutchings list_for_each_entry_safe(other, next, &efx->secondary_list, node) { 2490bcf4a64SBen Hutchings list_del(&other->node); 2500bcf4a64SBen Hutchings netif_dbg(other, probe, other->net_dev, 2510bcf4a64SBen Hutchings "moving to unassociated list\n"); 2520bcf4a64SBen Hutchings list_add_tail(&other->node, &efx_unassociated_list); 2530bcf4a64SBen Hutchings other->primary = NULL; 2540bcf4a64SBen Hutchings } 2550bcf4a64SBen Hutchings } 2560bcf4a64SBen Hutchings 257874aeea5SJeff Kirsher static int efx_probe_nic(struct efx_nic *efx) 258874aeea5SJeff Kirsher { 259874aeea5SJeff Kirsher int rc; 260874aeea5SJeff Kirsher 261874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); 262874aeea5SJeff Kirsher 263874aeea5SJeff Kirsher /* Carry out hardware-type specific initialisation */ 264874aeea5SJeff Kirsher rc = efx->type->probe(efx); 265874aeea5SJeff Kirsher if (rc) 266874aeea5SJeff Kirsher return rc; 267874aeea5SJeff Kirsher 268b0fbdae1SShradha Shah do { 269b0fbdae1SShradha Shah if (!efx->max_channels || !efx->max_tx_channels) { 270b0fbdae1SShradha Shah netif_err(efx, drv, efx->net_dev, 271b0fbdae1SShradha Shah "Insufficient resources to allocate" 272b0fbdae1SShradha Shah " any channels\n"); 273b0fbdae1SShradha Shah rc = -ENOSPC; 274b0fbdae1SShradha Shah goto fail1; 275b0fbdae1SShradha Shah } 276b0fbdae1SShradha Shah 277b0fbdae1SShradha Shah /* Determine the number of channels and queues by trying 278b0fbdae1SShradha Shah * to hook in MSI-X interrupts. 279b0fbdae1SShradha Shah */ 280874aeea5SJeff Kirsher rc = efx_probe_interrupts(efx); 281874aeea5SJeff Kirsher if (rc) 282c15eed22SBen Hutchings goto fail1; 283874aeea5SJeff Kirsher 2843990a8ffSCharles McLachlan rc = efx_set_channels(efx); 2853990a8ffSCharles McLachlan if (rc) 2863990a8ffSCharles McLachlan goto fail1; 28752ad762bSDaniel Pieczko 288b0fbdae1SShradha Shah /* dimension_resources can fail with EAGAIN */ 289c15eed22SBen Hutchings rc = efx->type->dimension_resources(efx); 290b0fbdae1SShradha Shah if (rc != 0 && rc != -EAGAIN) 291c15eed22SBen Hutchings goto fail2; 29228e47c49SBen Hutchings 293b0fbdae1SShradha Shah if (rc == -EAGAIN) 294b0fbdae1SShradha Shah /* try again with new max_channels */ 295b0fbdae1SShradha Shah efx_remove_interrupts(efx); 296b0fbdae1SShradha Shah 297b0fbdae1SShradha Shah } while (rc == -EAGAIN); 298b0fbdae1SShradha Shah 299874aeea5SJeff Kirsher if (efx->n_channels > 1) 30042356d9aSEdward Cree netdev_rss_key_fill(efx->rss_context.rx_hash_key, 30142356d9aSEdward Cree sizeof(efx->rss_context.rx_hash_key)); 30242356d9aSEdward Cree efx_set_default_rx_indir_table(efx, &efx->rss_context); 303874aeea5SJeff Kirsher 304874aeea5SJeff Kirsher /* Initialise the interrupt moderation settings */ 305539de7c5SBert Kenward efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000); 3069e393b30SBen Hutchings efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, 3079e393b30SBen Hutchings true); 308874aeea5SJeff Kirsher 309874aeea5SJeff Kirsher return 0; 310874aeea5SJeff Kirsher 311c15eed22SBen Hutchings fail2: 312c15eed22SBen Hutchings efx_remove_interrupts(efx); 313c15eed22SBen Hutchings fail1: 314874aeea5SJeff Kirsher efx->type->remove(efx); 315874aeea5SJeff Kirsher return rc; 316874aeea5SJeff Kirsher } 317874aeea5SJeff Kirsher 318874aeea5SJeff Kirsher static void efx_remove_nic(struct efx_nic *efx) 319874aeea5SJeff Kirsher { 320874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); 321874aeea5SJeff Kirsher 322874aeea5SJeff Kirsher efx_remove_interrupts(efx); 323874aeea5SJeff Kirsher efx->type->remove(efx); 324874aeea5SJeff Kirsher } 325874aeea5SJeff Kirsher 326874aeea5SJeff Kirsher /************************************************************************** 327874aeea5SJeff Kirsher * 328874aeea5SJeff Kirsher * NIC startup/shutdown 329874aeea5SJeff Kirsher * 330874aeea5SJeff Kirsher *************************************************************************/ 331874aeea5SJeff Kirsher 332874aeea5SJeff Kirsher static int efx_probe_all(struct efx_nic *efx) 333874aeea5SJeff Kirsher { 334874aeea5SJeff Kirsher int rc; 335874aeea5SJeff Kirsher 336874aeea5SJeff Kirsher rc = efx_probe_nic(efx); 337874aeea5SJeff Kirsher if (rc) { 338874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); 339874aeea5SJeff Kirsher goto fail1; 340874aeea5SJeff Kirsher } 341874aeea5SJeff Kirsher 342874aeea5SJeff Kirsher rc = efx_probe_port(efx); 343874aeea5SJeff Kirsher if (rc) { 344874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, "failed to create port\n"); 345874aeea5SJeff Kirsher goto fail2; 346874aeea5SJeff Kirsher } 347874aeea5SJeff Kirsher 3487e6d06f0SBen Hutchings BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); 3497e6d06f0SBen Hutchings if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { 3507e6d06f0SBen Hutchings rc = -EINVAL; 3517e6d06f0SBen Hutchings goto fail3; 3527e6d06f0SBen Hutchings } 353874aeea5SJeff Kirsher 3546d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 3556d8aaaf6SDaniel Pieczko rc = efx->type->vswitching_probe(efx); 3566d8aaaf6SDaniel Pieczko if (rc) /* not fatal; the PF will still work fine */ 3576d8aaaf6SDaniel Pieczko netif_warn(efx, probe, efx->net_dev, 3586d8aaaf6SDaniel Pieczko "failed to setup vswitching rc=%d;" 3596d8aaaf6SDaniel Pieczko " VFs may not function\n", rc); 3606d8aaaf6SDaniel Pieczko #endif 3616d8aaaf6SDaniel Pieczko 362874aeea5SJeff Kirsher rc = efx_probe_filters(efx); 363874aeea5SJeff Kirsher if (rc) { 364874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 365874aeea5SJeff Kirsher "failed to create filter tables\n"); 3666d8aaaf6SDaniel Pieczko goto fail4; 367874aeea5SJeff Kirsher } 368874aeea5SJeff Kirsher 3697f967c01SBen Hutchings rc = efx_probe_channels(efx); 3707f967c01SBen Hutchings if (rc) 3716d8aaaf6SDaniel Pieczko goto fail5; 3727f967c01SBen Hutchings 373813cf9d1SJonathan Cooper efx->state = STATE_NET_DOWN; 374813cf9d1SJonathan Cooper 375874aeea5SJeff Kirsher return 0; 376874aeea5SJeff Kirsher 3776d8aaaf6SDaniel Pieczko fail5: 3787f967c01SBen Hutchings efx_remove_filters(efx); 3796d8aaaf6SDaniel Pieczko fail4: 3806d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 3816d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 3826d8aaaf6SDaniel Pieczko #endif 383874aeea5SJeff Kirsher fail3: 384874aeea5SJeff Kirsher efx_remove_port(efx); 385874aeea5SJeff Kirsher fail2: 386874aeea5SJeff Kirsher efx_remove_nic(efx); 387874aeea5SJeff Kirsher fail1: 388874aeea5SJeff Kirsher return rc; 389874aeea5SJeff Kirsher } 390874aeea5SJeff Kirsher 391874aeea5SJeff Kirsher static void efx_remove_all(struct efx_nic *efx) 392874aeea5SJeff Kirsher { 393e45a4fedSCharles McLachlan rtnl_lock(); 394e45a4fedSCharles McLachlan efx_xdp_setup_prog(efx, NULL); 395e45a4fedSCharles McLachlan rtnl_unlock(); 396e45a4fedSCharles McLachlan 397874aeea5SJeff Kirsher efx_remove_channels(efx); 3987f967c01SBen Hutchings efx_remove_filters(efx); 3996d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV 4006d8aaaf6SDaniel Pieczko efx->type->vswitching_remove(efx); 4016d8aaaf6SDaniel Pieczko #endif 402874aeea5SJeff Kirsher efx_remove_port(efx); 403874aeea5SJeff Kirsher efx_remove_nic(efx); 404874aeea5SJeff Kirsher } 405874aeea5SJeff Kirsher 406874aeea5SJeff Kirsher /************************************************************************** 407874aeea5SJeff Kirsher * 408874aeea5SJeff Kirsher * Interrupt moderation 409874aeea5SJeff Kirsher * 410874aeea5SJeff Kirsher **************************************************************************/ 411539de7c5SBert Kenward unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs) 412874aeea5SJeff Kirsher { 413b548f976SBen Hutchings if (usecs == 0) 414b548f976SBen Hutchings return 0; 415539de7c5SBert Kenward if (usecs * 1000 < efx->timer_quantum_ns) 416874aeea5SJeff Kirsher return 1; /* never round down to 0 */ 417539de7c5SBert Kenward return usecs * 1000 / efx->timer_quantum_ns; 418539de7c5SBert Kenward } 419539de7c5SBert Kenward 420539de7c5SBert Kenward unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks) 421539de7c5SBert Kenward { 422539de7c5SBert Kenward /* We must round up when converting ticks to microseconds 423539de7c5SBert Kenward * because we round down when converting the other way. 424539de7c5SBert Kenward */ 425539de7c5SBert Kenward return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000); 426874aeea5SJeff Kirsher } 427874aeea5SJeff Kirsher 428874aeea5SJeff Kirsher /* Set interrupt moderation parameters */ 4299e393b30SBen Hutchings int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, 4309e393b30SBen Hutchings unsigned int rx_usecs, bool rx_adaptive, 4319e393b30SBen Hutchings bool rx_may_override_tx) 432874aeea5SJeff Kirsher { 433874aeea5SJeff Kirsher struct efx_channel *channel; 434d95e329aSBert Kenward unsigned int timer_max_us; 435d95e329aSBert Kenward 436874aeea5SJeff Kirsher EFX_ASSERT_RESET_SERIALISED(efx); 437874aeea5SJeff Kirsher 438d95e329aSBert Kenward timer_max_us = efx->timer_max_ns / 1000; 439d95e329aSBert Kenward 440d95e329aSBert Kenward if (tx_usecs > timer_max_us || rx_usecs > timer_max_us) 4419e393b30SBen Hutchings return -EINVAL; 4429e393b30SBen Hutchings 443539de7c5SBert Kenward if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 && 4449e393b30SBen Hutchings !rx_may_override_tx) { 4459e393b30SBen Hutchings netif_err(efx, drv, efx->net_dev, "Channels are shared. " 4469e393b30SBen Hutchings "RX and TX IRQ moderation must be equal\n"); 4479e393b30SBen Hutchings return -EINVAL; 4489e393b30SBen Hutchings } 4499e393b30SBen Hutchings 450874aeea5SJeff Kirsher efx->irq_rx_adaptive = rx_adaptive; 451539de7c5SBert Kenward efx->irq_rx_moderation_us = rx_usecs; 452874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 453874aeea5SJeff Kirsher if (efx_channel_has_rx_queue(channel)) 454539de7c5SBert Kenward channel->irq_moderation_us = rx_usecs; 455874aeea5SJeff Kirsher else if (efx_channel_has_tx_queues(channel)) 456539de7c5SBert Kenward channel->irq_moderation_us = tx_usecs; 4573990a8ffSCharles McLachlan else if (efx_channel_is_xdp_tx(channel)) 4583990a8ffSCharles McLachlan channel->irq_moderation_us = tx_usecs; 459874aeea5SJeff Kirsher } 4609e393b30SBen Hutchings 4619e393b30SBen Hutchings return 0; 462874aeea5SJeff Kirsher } 463874aeea5SJeff Kirsher 464a0c4faf5SBen Hutchings void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, 465a0c4faf5SBen Hutchings unsigned int *rx_usecs, bool *rx_adaptive) 466a0c4faf5SBen Hutchings { 467a0c4faf5SBen Hutchings *rx_adaptive = efx->irq_rx_adaptive; 468539de7c5SBert Kenward *rx_usecs = efx->irq_rx_moderation_us; 469a0c4faf5SBen Hutchings 470a0c4faf5SBen Hutchings /* If channels are shared between RX and TX, so is IRQ 471a0c4faf5SBen Hutchings * moderation. Otherwise, IRQ moderation is the same for all 472a0c4faf5SBen Hutchings * TX channels and is not adaptive. 473a0c4faf5SBen Hutchings */ 474539de7c5SBert Kenward if (efx->tx_channel_offset == 0) { 475a0c4faf5SBen Hutchings *tx_usecs = *rx_usecs; 476539de7c5SBert Kenward } else { 477539de7c5SBert Kenward struct efx_channel *tx_channel; 478539de7c5SBert Kenward 479539de7c5SBert Kenward tx_channel = efx->channel[efx->tx_channel_offset]; 480539de7c5SBert Kenward *tx_usecs = tx_channel->irq_moderation_us; 481539de7c5SBert Kenward } 482a0c4faf5SBen Hutchings } 483a0c4faf5SBen Hutchings 484874aeea5SJeff Kirsher /************************************************************************** 485874aeea5SJeff Kirsher * 486874aeea5SJeff Kirsher * ioctls 487874aeea5SJeff Kirsher * 488874aeea5SJeff Kirsher *************************************************************************/ 489874aeea5SJeff Kirsher 490874aeea5SJeff Kirsher /* Net device ioctl 491874aeea5SJeff Kirsher * Context: process, rtnl_lock() held. 492874aeea5SJeff Kirsher */ 493874aeea5SJeff Kirsher static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) 494874aeea5SJeff Kirsher { 4958cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 496874aeea5SJeff Kirsher struct mii_ioctl_data *data = if_mii(ifr); 497874aeea5SJeff Kirsher 4987c236c43SStuart Hodgson if (cmd == SIOCSHWTSTAMP) 499433dc9b3SBen Hutchings return efx_ptp_set_ts_config(efx, ifr); 500433dc9b3SBen Hutchings if (cmd == SIOCGHWTSTAMP) 501433dc9b3SBen Hutchings return efx_ptp_get_ts_config(efx, ifr); 5027c236c43SStuart Hodgson 503874aeea5SJeff Kirsher /* Convert phy_id from older PRTAD/DEVAD format */ 504874aeea5SJeff Kirsher if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && 505874aeea5SJeff Kirsher (data->phy_id & 0xfc00) == 0x0400) 506874aeea5SJeff Kirsher data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; 507874aeea5SJeff Kirsher 508874aeea5SJeff Kirsher return mdio_mii_ioctl(&efx->mdio, data, cmd); 509874aeea5SJeff Kirsher } 510874aeea5SJeff Kirsher 511874aeea5SJeff Kirsher /************************************************************************** 512874aeea5SJeff Kirsher * 513874aeea5SJeff Kirsher * Kernel net device interface 514874aeea5SJeff Kirsher * 515874aeea5SJeff Kirsher *************************************************************************/ 516874aeea5SJeff Kirsher 517874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */ 518e340be92SShradha Shah int efx_net_open(struct net_device *net_dev) 519874aeea5SJeff Kirsher { 5208cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 5218b7325b4SBen Hutchings int rc; 5228b7325b4SBen Hutchings 523874aeea5SJeff Kirsher netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", 524874aeea5SJeff Kirsher raw_smp_processor_id()); 525874aeea5SJeff Kirsher 5268b7325b4SBen Hutchings rc = efx_check_disabled(efx); 5278b7325b4SBen Hutchings if (rc) 5288b7325b4SBen Hutchings return rc; 529874aeea5SJeff Kirsher if (efx->phy_mode & PHY_MODE_SPECIAL) 530874aeea5SJeff Kirsher return -EBUSY; 531874aeea5SJeff Kirsher if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) 532874aeea5SJeff Kirsher return -EIO; 533874aeea5SJeff Kirsher 534874aeea5SJeff Kirsher /* Notify the kernel of the link state polled during driver load, 535874aeea5SJeff Kirsher * before the monitor starts running */ 536874aeea5SJeff Kirsher efx_link_status_changed(efx); 537874aeea5SJeff Kirsher 538874aeea5SJeff Kirsher efx_start_all(efx); 5399c568fd8SPeter Dunning if (efx->state == STATE_DISABLED || efx->reset_pending) 5409c568fd8SPeter Dunning netif_device_detach(efx->net_dev); 541813cf9d1SJonathan Cooper else 542813cf9d1SJonathan Cooper efx->state = STATE_NET_UP; 543813cf9d1SJonathan Cooper 544dd40781eSBen Hutchings efx_selftest_async_start(efx); 545874aeea5SJeff Kirsher return 0; 546874aeea5SJeff Kirsher } 547874aeea5SJeff Kirsher 548874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. 549874aeea5SJeff Kirsher * Note that the kernel will ignore our return code; this method 550874aeea5SJeff Kirsher * should really be a void. 551874aeea5SJeff Kirsher */ 552e340be92SShradha Shah int efx_net_stop(struct net_device *net_dev) 553874aeea5SJeff Kirsher { 5548cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 555874aeea5SJeff Kirsher 556874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", 557874aeea5SJeff Kirsher raw_smp_processor_id()); 558874aeea5SJeff Kirsher 559874aeea5SJeff Kirsher /* Stop the device and flush all the channels */ 560874aeea5SJeff Kirsher efx_stop_all(efx); 561874aeea5SJeff Kirsher 562874aeea5SJeff Kirsher return 0; 563874aeea5SJeff Kirsher } 564874aeea5SJeff Kirsher 5654a53ea8aSAndrew Rybchenko static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid) 5664a53ea8aSAndrew Rybchenko { 5678cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 5684a53ea8aSAndrew Rybchenko 5694a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_add_vid) 5704a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_add_vid(efx, proto, vid); 5714a53ea8aSAndrew Rybchenko else 5724a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 5734a53ea8aSAndrew Rybchenko } 5744a53ea8aSAndrew Rybchenko 5754a53ea8aSAndrew Rybchenko static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid) 5764a53ea8aSAndrew Rybchenko { 5778cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 5784a53ea8aSAndrew Rybchenko 5794a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_kill_vid) 5804a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_kill_vid(efx, proto, vid); 5814a53ea8aSAndrew Rybchenko else 5824a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 5834a53ea8aSAndrew Rybchenko } 5844a53ea8aSAndrew Rybchenko 5857fa8d547SShradha Shah static const struct net_device_ops efx_netdev_ops = { 586874aeea5SJeff Kirsher .ndo_open = efx_net_open, 587874aeea5SJeff Kirsher .ndo_stop = efx_net_stop, 588874aeea5SJeff Kirsher .ndo_get_stats64 = efx_net_stats, 589874aeea5SJeff Kirsher .ndo_tx_timeout = efx_watchdog, 590874aeea5SJeff Kirsher .ndo_start_xmit = efx_hard_start_xmit, 591874aeea5SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 592a7605370SArnd Bergmann .ndo_eth_ioctl = efx_ioctl, 593874aeea5SJeff Kirsher .ndo_change_mtu = efx_change_mtu, 594874aeea5SJeff Kirsher .ndo_set_mac_address = efx_set_mac_address, 5950fca8c97SBen Hutchings .ndo_set_rx_mode = efx_set_rx_mode, 596874aeea5SJeff Kirsher .ndo_set_features = efx_set_features, 59724b2c375SEdward Cree .ndo_features_check = efx_features_check, 5984a53ea8aSAndrew Rybchenko .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid, 5994a53ea8aSAndrew Rybchenko .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid, 600cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV 6017fa8d547SShradha Shah .ndo_set_vf_mac = efx_sriov_set_vf_mac, 6027fa8d547SShradha Shah .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, 6037fa8d547SShradha Shah .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, 6047fa8d547SShradha Shah .ndo_get_vf_config = efx_sriov_get_vf_config, 6054392dc69SEdward Cree .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, 606cd2d5b52SBen Hutchings #endif 60708a7b29bSBert Kenward .ndo_get_phys_port_id = efx_get_phys_port_id, 608ac019f08SBert Kenward .ndo_get_phys_port_name = efx_get_phys_port_name, 609874aeea5SJeff Kirsher .ndo_setup_tc = efx_setup_tc, 610874aeea5SJeff Kirsher #ifdef CONFIG_RFS_ACCEL 611874aeea5SJeff Kirsher .ndo_rx_flow_steer = efx_filter_rfs, 612874aeea5SJeff Kirsher #endif 613dfe44c1fSCharles McLachlan .ndo_xdp_xmit = efx_xdp_xmit, 614e45a4fedSCharles McLachlan .ndo_bpf = efx_xdp 615874aeea5SJeff Kirsher }; 616874aeea5SJeff Kirsher 617e45a4fedSCharles McLachlan static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog) 618e45a4fedSCharles McLachlan { 619e45a4fedSCharles McLachlan struct bpf_prog *old_prog; 620e45a4fedSCharles McLachlan 621e45a4fedSCharles McLachlan if (efx->xdp_rxq_info_failed) { 622e45a4fedSCharles McLachlan netif_err(efx, drv, efx->net_dev, 623e45a4fedSCharles McLachlan "Unable to bind XDP program due to previous failure of rxq_info\n"); 624e45a4fedSCharles McLachlan return -EINVAL; 625e45a4fedSCharles McLachlan } 626e45a4fedSCharles McLachlan 627e45a4fedSCharles McLachlan if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) { 628e45a4fedSCharles McLachlan netif_err(efx, drv, efx->net_dev, 629e45a4fedSCharles McLachlan "Unable to configure XDP with MTU of %d (max: %d)\n", 630e45a4fedSCharles McLachlan efx->net_dev->mtu, efx_xdp_max_mtu(efx)); 631e45a4fedSCharles McLachlan return -EINVAL; 632e45a4fedSCharles McLachlan } 633e45a4fedSCharles McLachlan 634e45a4fedSCharles McLachlan old_prog = rtnl_dereference(efx->xdp_prog); 635e45a4fedSCharles McLachlan rcu_assign_pointer(efx->xdp_prog, prog); 636e45a4fedSCharles McLachlan /* Release the reference that was originally passed by the caller. */ 637e45a4fedSCharles McLachlan if (old_prog) 638e45a4fedSCharles McLachlan bpf_prog_put(old_prog); 639e45a4fedSCharles McLachlan 640e45a4fedSCharles McLachlan return 0; 641e45a4fedSCharles McLachlan } 642e45a4fedSCharles McLachlan 643e45a4fedSCharles McLachlan /* Context: process, rtnl_lock() held. */ 644e45a4fedSCharles McLachlan static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp) 645e45a4fedSCharles McLachlan { 6468cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(dev); 647e45a4fedSCharles McLachlan 648e45a4fedSCharles McLachlan switch (xdp->command) { 649e45a4fedSCharles McLachlan case XDP_SETUP_PROG: 650e45a4fedSCharles McLachlan return efx_xdp_setup_prog(efx, xdp->prog); 651e45a4fedSCharles McLachlan default: 652e45a4fedSCharles McLachlan return -EINVAL; 653e45a4fedSCharles McLachlan } 654e45a4fedSCharles McLachlan } 655e45a4fedSCharles McLachlan 656dfe44c1fSCharles McLachlan static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs, 657dfe44c1fSCharles McLachlan u32 flags) 658dfe44c1fSCharles McLachlan { 6598cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(dev); 660dfe44c1fSCharles McLachlan 661dfe44c1fSCharles McLachlan if (!netif_running(dev)) 662dfe44c1fSCharles McLachlan return -EINVAL; 663dfe44c1fSCharles McLachlan 664dfe44c1fSCharles McLachlan return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH); 665dfe44c1fSCharles McLachlan } 666dfe44c1fSCharles McLachlan 667874aeea5SJeff Kirsher static void efx_update_name(struct efx_nic *efx) 668874aeea5SJeff Kirsher { 669874aeea5SJeff Kirsher strcpy(efx->name, efx->net_dev->name); 670874aeea5SJeff Kirsher efx_mtd_rename(efx); 671874aeea5SJeff Kirsher efx_set_channel_names(efx); 672874aeea5SJeff Kirsher } 673874aeea5SJeff Kirsher 674874aeea5SJeff Kirsher static int efx_netdev_event(struct notifier_block *this, 675874aeea5SJeff Kirsher unsigned long event, void *ptr) 676874aeea5SJeff Kirsher { 677351638e7SJiri Pirko struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); 678874aeea5SJeff Kirsher 6797fa8d547SShradha Shah if ((net_dev->netdev_ops == &efx_netdev_ops) && 680874aeea5SJeff Kirsher event == NETDEV_CHANGENAME) 6818cb03f4eSJonathan Cooper efx_update_name(efx_netdev_priv(net_dev)); 682874aeea5SJeff Kirsher 683874aeea5SJeff Kirsher return NOTIFY_DONE; 684874aeea5SJeff Kirsher } 685874aeea5SJeff Kirsher 686874aeea5SJeff Kirsher static struct notifier_block efx_netdev_notifier = { 687874aeea5SJeff Kirsher .notifier_call = efx_netdev_event, 688874aeea5SJeff Kirsher }; 689874aeea5SJeff Kirsher 6903880fc37SYueHaibing static ssize_t phy_type_show(struct device *dev, 6913880fc37SYueHaibing struct device_attribute *attr, char *buf) 692874aeea5SJeff Kirsher { 6933e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 694874aeea5SJeff Kirsher return sprintf(buf, "%d\n", efx->phy_type); 695874aeea5SJeff Kirsher } 6963880fc37SYueHaibing static DEVICE_ATTR_RO(phy_type); 697874aeea5SJeff Kirsher 698874aeea5SJeff Kirsher static int efx_register_netdev(struct efx_nic *efx) 699874aeea5SJeff Kirsher { 700874aeea5SJeff Kirsher struct net_device *net_dev = efx->net_dev; 701874aeea5SJeff Kirsher struct efx_channel *channel; 702874aeea5SJeff Kirsher int rc; 703874aeea5SJeff Kirsher 704874aeea5SJeff Kirsher net_dev->watchdog_timeo = 5 * HZ; 705874aeea5SJeff Kirsher net_dev->irq = efx->pci_dev->irq; 7067fa8d547SShradha Shah net_dev->netdev_ops = &efx_netdev_ops; 7077fa8d547SShradha Shah if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) 7088127d661SBen Hutchings net_dev->priv_flags |= IFF_UNICAST_FLT; 7097ad24ea4SWilfried Klaebe net_dev->ethtool_ops = &efx_ethtool_ops; 710ee8b7a11SJakub Kicinski netif_set_tso_max_segs(net_dev, EFX_TSO_MAX_SEGS); 711cd94e519SBert Kenward net_dev->min_mtu = EFX_MIN_MTU; 712cd94e519SBert Kenward net_dev->max_mtu = EFX_MAX_MTU; 713874aeea5SJeff Kirsher 714874aeea5SJeff Kirsher rtnl_lock(); 715874aeea5SJeff Kirsher 7167153f623SBen Hutchings /* Enable resets to be scheduled and check whether any were 7177153f623SBen Hutchings * already requested. If so, the NIC is probably hosed so we 7187153f623SBen Hutchings * abort. 7197153f623SBen Hutchings */ 7207153f623SBen Hutchings if (efx->reset_pending) { 721fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n"); 7227153f623SBen Hutchings rc = -EIO; 7237153f623SBen Hutchings goto fail_locked; 7247153f623SBen Hutchings } 7257153f623SBen Hutchings 726874aeea5SJeff Kirsher rc = dev_alloc_name(net_dev, net_dev->name); 727874aeea5SJeff Kirsher if (rc < 0) 728874aeea5SJeff Kirsher goto fail_locked; 729874aeea5SJeff Kirsher efx_update_name(efx); 730874aeea5SJeff Kirsher 7318f8b3d51SBen Hutchings /* Always start with carrier off; PHY events will detect the link */ 7328f8b3d51SBen Hutchings netif_carrier_off(net_dev); 7338f8b3d51SBen Hutchings 734874aeea5SJeff Kirsher rc = register_netdevice(net_dev); 735874aeea5SJeff Kirsher if (rc) 736874aeea5SJeff Kirsher goto fail_locked; 737874aeea5SJeff Kirsher 738874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 739874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 740874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 741874aeea5SJeff Kirsher efx_init_tx_queue_core_txq(tx_queue); 742874aeea5SJeff Kirsher } 743874aeea5SJeff Kirsher 7440bcf4a64SBen Hutchings efx_associate(efx); 7450bcf4a64SBen Hutchings 746813cf9d1SJonathan Cooper efx->state = STATE_NET_DOWN; 747813cf9d1SJonathan Cooper 748874aeea5SJeff Kirsher rtnl_unlock(); 749874aeea5SJeff Kirsher 750874aeea5SJeff Kirsher rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); 751874aeea5SJeff Kirsher if (rc) { 752874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 753874aeea5SJeff Kirsher "failed to init net dev attributes\n"); 754874aeea5SJeff Kirsher goto fail_registered; 755874aeea5SJeff Kirsher } 756b69f7a3eSAlex Maftei (amaftei) 757b69f7a3eSAlex Maftei (amaftei) efx_init_mcdi_logging(efx); 758874aeea5SJeff Kirsher 759874aeea5SJeff Kirsher return 0; 760874aeea5SJeff Kirsher 7617153f623SBen Hutchings fail_registered: 7627153f623SBen Hutchings rtnl_lock(); 7630bcf4a64SBen Hutchings efx_dissociate(efx); 7647153f623SBen Hutchings unregister_netdevice(net_dev); 765874aeea5SJeff Kirsher fail_locked: 7667153f623SBen Hutchings efx->state = STATE_UNINIT; 767874aeea5SJeff Kirsher rtnl_unlock(); 768874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); 769874aeea5SJeff Kirsher return rc; 770874aeea5SJeff Kirsher } 771874aeea5SJeff Kirsher 772874aeea5SJeff Kirsher static void efx_unregister_netdev(struct efx_nic *efx) 773874aeea5SJeff Kirsher { 774874aeea5SJeff Kirsher if (!efx->net_dev) 775874aeea5SJeff Kirsher return; 776874aeea5SJeff Kirsher 7778cb03f4eSJonathan Cooper if (WARN_ON(efx_netdev_priv(efx->net_dev) != efx)) 778b3fd0a86SJonathan Cooper return; 779874aeea5SJeff Kirsher 780e7fef9b4SEdward Cree if (efx_dev_registered(efx)) { 781874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); 782b69f7a3eSAlex Maftei (amaftei) efx_fini_mcdi_logging(efx); 783874aeea5SJeff Kirsher device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); 784e7fef9b4SEdward Cree unregister_netdev(efx->net_dev); 785e7fef9b4SEdward Cree } 786874aeea5SJeff Kirsher } 787874aeea5SJeff Kirsher 788874aeea5SJeff Kirsher /************************************************************************** 789874aeea5SJeff Kirsher * 790874aeea5SJeff Kirsher * List of NICs we support 791874aeea5SJeff Kirsher * 792874aeea5SJeff Kirsher **************************************************************************/ 793874aeea5SJeff Kirsher 794874aeea5SJeff Kirsher /* PCI device ID table */ 7959baa3c34SBenoit Taine static const struct pci_device_id efx_pci_table[] = { 7968127d661SBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ 7978127d661SBen Hutchings .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 7986f7f8aa6SShradha Shah {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ 7996f7f8aa6SShradha Shah .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 8003b06a00eSMateusz Wrzesinski {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ 8013b06a00eSMateusz Wrzesinski .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 802dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */ 803dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 804dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */ 805dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 806dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */ 807dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 808aae5a316SEdward Cree {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */ 809aae5a316SEdward Cree .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 810aae5a316SEdward Cree {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */ 811aae5a316SEdward Cree .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 812874aeea5SJeff Kirsher {0} /* end of list */ 813874aeea5SJeff Kirsher }; 814874aeea5SJeff Kirsher 815874aeea5SJeff Kirsher /************************************************************************** 816874aeea5SJeff Kirsher * 817874aeea5SJeff Kirsher * Data housekeeping 818874aeea5SJeff Kirsher * 819874aeea5SJeff Kirsher **************************************************************************/ 820874aeea5SJeff Kirsher 821e4d112e4SEdward Cree void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) 822e4d112e4SEdward Cree { 823e4d112e4SEdward Cree u64 n_rx_nodesc_trunc = 0; 824e4d112e4SEdward Cree struct efx_channel *channel; 825e4d112e4SEdward Cree 826e4d112e4SEdward Cree efx_for_each_channel(channel, efx) 827e4d112e4SEdward Cree n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; 828e4d112e4SEdward Cree stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; 829e4d112e4SEdward Cree stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); 830e4d112e4SEdward Cree } 831e4d112e4SEdward Cree 832874aeea5SJeff Kirsher /************************************************************************** 833874aeea5SJeff Kirsher * 834874aeea5SJeff Kirsher * PCI interface 835874aeea5SJeff Kirsher * 836874aeea5SJeff Kirsher **************************************************************************/ 837874aeea5SJeff Kirsher 838874aeea5SJeff Kirsher /* Main body of final NIC shutdown code 839874aeea5SJeff Kirsher * This is called only at module unload (or hotplug removal). 840874aeea5SJeff Kirsher */ 841874aeea5SJeff Kirsher static void efx_pci_remove_main(struct efx_nic *efx) 842874aeea5SJeff Kirsher { 8437153f623SBen Hutchings /* Flush reset_work. It can no longer be scheduled since we 8447153f623SBen Hutchings * are not READY. 8457153f623SBen Hutchings */ 846813cf9d1SJonathan Cooper WARN_ON(efx_net_active(efx->state)); 84782c64484SAlex Maftei (amaftei) efx_flush_reset_workqueue(efx); 8487153f623SBen Hutchings 849d8291187SBen Hutchings efx_disable_interrupts(efx); 850a83762d9SBert Kenward efx_clear_interrupt_affinity(efx); 851874aeea5SJeff Kirsher efx_nic_fini_interrupt(efx); 852874aeea5SJeff Kirsher efx_fini_port(efx); 853874aeea5SJeff Kirsher efx->type->fini(efx); 854874aeea5SJeff Kirsher efx_fini_napi(efx); 855874aeea5SJeff Kirsher efx_remove_all(efx); 856874aeea5SJeff Kirsher } 857874aeea5SJeff Kirsher 858874aeea5SJeff Kirsher /* Final NIC shutdown 8592a3fc311SDaniel Pieczko * This is called only at module unload (or hotplug removal). A PF can call 8602a3fc311SDaniel Pieczko * this on its VFs to ensure they are unbound first. 861874aeea5SJeff Kirsher */ 862874aeea5SJeff Kirsher static void efx_pci_remove(struct pci_dev *pci_dev) 863874aeea5SJeff Kirsher { 864*7e773594SJonathan Cooper struct efx_probe_data *probe_data; 865874aeea5SJeff Kirsher struct efx_nic *efx; 866874aeea5SJeff Kirsher 867874aeea5SJeff Kirsher efx = pci_get_drvdata(pci_dev); 868874aeea5SJeff Kirsher if (!efx) 869874aeea5SJeff Kirsher return; 870874aeea5SJeff Kirsher 871874aeea5SJeff Kirsher /* Mark the NIC as fini, then stop the interface */ 872874aeea5SJeff Kirsher rtnl_lock(); 8730bcf4a64SBen Hutchings efx_dissociate(efx); 874874aeea5SJeff Kirsher dev_close(efx->net_dev); 875d8291187SBen Hutchings efx_disable_interrupts(efx); 876ea6bb99eSEdward Cree efx->state = STATE_UNINIT; 877874aeea5SJeff Kirsher rtnl_unlock(); 878874aeea5SJeff Kirsher 8797fa8d547SShradha Shah if (efx->type->sriov_fini) 880d98a4ffeSShradha Shah efx->type->sriov_fini(efx); 8817fa8d547SShradha Shah 882874aeea5SJeff Kirsher efx_unregister_netdev(efx); 883874aeea5SJeff Kirsher 884874aeea5SJeff Kirsher efx_mtd_remove(efx); 885874aeea5SJeff Kirsher 886874aeea5SJeff Kirsher efx_pci_remove_main(efx); 887874aeea5SJeff Kirsher 88866a65128SEdward Cree efx_fini_io(efx); 889874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); 890874aeea5SJeff Kirsher 891874aeea5SJeff Kirsher efx_fini_struct(efx); 892874aeea5SJeff Kirsher free_netdev(efx->net_dev); 893*7e773594SJonathan Cooper probe_data = container_of(efx, struct efx_probe_data, efx); 894*7e773594SJonathan Cooper kfree(probe_data); 895626950dbSAlexandre Rames 896626950dbSAlexandre Rames pci_disable_pcie_error_reporting(pci_dev); 897874aeea5SJeff Kirsher }; 898874aeea5SJeff Kirsher 899460eeaa0SBen Hutchings /* NIC VPD information 900460eeaa0SBen Hutchings * Called during probe to display the part number of the 9015119e20fSHeiner Kallweit * installed NIC. 902460eeaa0SBen Hutchings */ 903ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx) 904460eeaa0SBen Hutchings { 905460eeaa0SBen Hutchings struct pci_dev *dev = efx->pci_dev; 90637838aa4SHeiner Kallweit unsigned int vpd_size, kw_len; 9075119e20fSHeiner Kallweit u8 *vpd_data; 90837838aa4SHeiner Kallweit int start; 909460eeaa0SBen Hutchings 9105119e20fSHeiner Kallweit vpd_data = pci_vpd_alloc(dev, &vpd_size); 9115119e20fSHeiner Kallweit if (IS_ERR(vpd_data)) { 9125119e20fSHeiner Kallweit pci_warn(dev, "Unable to read VPD\n"); 913460eeaa0SBen Hutchings return; 914460eeaa0SBen Hutchings } 915460eeaa0SBen Hutchings 91637838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 91737838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); 91837838aa4SHeiner Kallweit if (start < 0) 91937838aa4SHeiner Kallweit pci_err(dev, "Part number not found or incomplete\n"); 92037838aa4SHeiner Kallweit else 92137838aa4SHeiner Kallweit pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start); 922460eeaa0SBen Hutchings 92337838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 92437838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len); 92537838aa4SHeiner Kallweit if (start < 0) 92637838aa4SHeiner Kallweit pci_err(dev, "Serial number not found or incomplete\n"); 92737838aa4SHeiner Kallweit else 92837838aa4SHeiner Kallweit efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL); 929460eeaa0SBen Hutchings 9305119e20fSHeiner Kallweit kfree(vpd_data); 931460eeaa0SBen Hutchings } 932460eeaa0SBen Hutchings 933460eeaa0SBen Hutchings 934874aeea5SJeff Kirsher /* Main body of NIC initialisation 935874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, theoretically). 936874aeea5SJeff Kirsher */ 937874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx) 938874aeea5SJeff Kirsher { 939874aeea5SJeff Kirsher int rc; 940874aeea5SJeff Kirsher 941874aeea5SJeff Kirsher /* Do start-of-day initialisation */ 942874aeea5SJeff Kirsher rc = efx_probe_all(efx); 943874aeea5SJeff Kirsher if (rc) 944874aeea5SJeff Kirsher goto fail1; 945874aeea5SJeff Kirsher 946874aeea5SJeff Kirsher efx_init_napi(efx); 947874aeea5SJeff Kirsher 948193f2003SBert Kenward down_write(&efx->filter_sem); 949874aeea5SJeff Kirsher rc = efx->type->init(efx); 950193f2003SBert Kenward up_write(&efx->filter_sem); 951874aeea5SJeff Kirsher if (rc) { 952fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "failed to initialise NIC\n"); 953874aeea5SJeff Kirsher goto fail3; 954874aeea5SJeff Kirsher } 955874aeea5SJeff Kirsher 956874aeea5SJeff Kirsher rc = efx_init_port(efx); 957874aeea5SJeff Kirsher if (rc) { 958874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 959874aeea5SJeff Kirsher "failed to initialise port\n"); 960874aeea5SJeff Kirsher goto fail4; 961874aeea5SJeff Kirsher } 962874aeea5SJeff Kirsher 963874aeea5SJeff Kirsher rc = efx_nic_init_interrupt(efx); 964874aeea5SJeff Kirsher if (rc) 965874aeea5SJeff Kirsher goto fail5; 966a83762d9SBert Kenward 967a83762d9SBert Kenward efx_set_interrupt_affinity(efx); 968261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 969261e4d96SJon Cooper if (rc) 970261e4d96SJon Cooper goto fail6; 971874aeea5SJeff Kirsher 972874aeea5SJeff Kirsher return 0; 973874aeea5SJeff Kirsher 974261e4d96SJon Cooper fail6: 975a83762d9SBert Kenward efx_clear_interrupt_affinity(efx); 976261e4d96SJon Cooper efx_nic_fini_interrupt(efx); 977874aeea5SJeff Kirsher fail5: 978874aeea5SJeff Kirsher efx_fini_port(efx); 979874aeea5SJeff Kirsher fail4: 980874aeea5SJeff Kirsher efx->type->fini(efx); 981874aeea5SJeff Kirsher fail3: 982874aeea5SJeff Kirsher efx_fini_napi(efx); 983874aeea5SJeff Kirsher efx_remove_all(efx); 984874aeea5SJeff Kirsher fail1: 985874aeea5SJeff Kirsher return rc; 986874aeea5SJeff Kirsher } 987874aeea5SJeff Kirsher 9888a531400SJon Cooper static int efx_pci_probe_post_io(struct efx_nic *efx) 9898a531400SJon Cooper { 9908a531400SJon Cooper struct net_device *net_dev = efx->net_dev; 9918a531400SJon Cooper int rc = efx_pci_probe_main(efx); 9928a531400SJon Cooper 9938a531400SJon Cooper if (rc) 9948a531400SJon Cooper return rc; 9958a531400SJon Cooper 9968a531400SJon Cooper if (efx->type->sriov_init) { 9978a531400SJon Cooper rc = efx->type->sriov_init(efx); 9988a531400SJon Cooper if (rc) 999fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n", 1000fa44821aSHeiner Kallweit rc); 10018a531400SJon Cooper } 10028a531400SJon Cooper 10038a531400SJon Cooper /* Determine netdevice features */ 10048a531400SJon Cooper net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 10056978729fSEdward Cree NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL); 10068a531400SJon Cooper if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) 10078a531400SJon Cooper net_dev->features |= NETIF_F_TSO6; 10088a531400SJon Cooper /* Check whether device supports TSO */ 10098a531400SJon Cooper if (!efx->type->tso_versions || !efx->type->tso_versions(efx)) 10108a531400SJon Cooper net_dev->features &= ~NETIF_F_ALL_TSO; 10118a531400SJon Cooper /* Mask for features that also apply to VLAN devices */ 10128a531400SJon Cooper net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 10138a531400SJon Cooper NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 10148a531400SJon Cooper NETIF_F_RXCSUM); 10158a531400SJon Cooper 10166978729fSEdward Cree net_dev->hw_features |= net_dev->features & ~efx->fixed_features; 10176978729fSEdward Cree 10186978729fSEdward Cree /* Disable receiving frames with bad FCS, by default. */ 10196978729fSEdward Cree net_dev->features &= ~NETIF_F_RXALL; 10208a531400SJon Cooper 10218a531400SJon Cooper /* Disable VLAN filtering by default. It may be enforced if 10228a531400SJon Cooper * the feature is fixed (i.e. VLAN filters are required to 10238a531400SJon Cooper * receive VLAN tagged packets due to vPort restrictions). 10248a531400SJon Cooper */ 10258a531400SJon Cooper net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 10268a531400SJon Cooper net_dev->features |= efx->fixed_features; 10278a531400SJon Cooper 10288a531400SJon Cooper rc = efx_register_netdev(efx); 10298a531400SJon Cooper if (!rc) 10308a531400SJon Cooper return 0; 10318a531400SJon Cooper 10328a531400SJon Cooper efx_pci_remove_main(efx); 10338a531400SJon Cooper return rc; 10348a531400SJon Cooper } 10358a531400SJon Cooper 1036874aeea5SJeff Kirsher /* NIC initialisation 1037874aeea5SJeff Kirsher * 1038874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, 103973ba7b68SBen Hutchings * theoretically). It sets up PCI mappings, resets the NIC, 1040874aeea5SJeff Kirsher * sets up and registers the network devices with the kernel and hooks 1041874aeea5SJeff Kirsher * the interrupt service routine. It does not prepare the device for 1042874aeea5SJeff Kirsher * transmission; this is left to the first time one of the network 1043874aeea5SJeff Kirsher * interfaces is brought up (i.e. efx_net_open). 1044874aeea5SJeff Kirsher */ 104587d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev, 1046874aeea5SJeff Kirsher const struct pci_device_id *entry) 1047874aeea5SJeff Kirsher { 1048*7e773594SJonathan Cooper struct efx_probe_data *probe_data, **probe_ptr; 1049874aeea5SJeff Kirsher struct net_device *net_dev; 1050874aeea5SJeff Kirsher struct efx_nic *efx; 1051fadac6aaSBen Hutchings int rc; 1052874aeea5SJeff Kirsher 1053*7e773594SJonathan Cooper /* Allocate probe data and struct efx_nic */ 1054*7e773594SJonathan Cooper probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL); 1055*7e773594SJonathan Cooper if (!probe_data) 1056*7e773594SJonathan Cooper return -ENOMEM; 1057*7e773594SJonathan Cooper probe_data->pci_dev = pci_dev; 1058*7e773594SJonathan Cooper efx = &probe_data->efx; 1059*7e773594SJonathan Cooper 1060*7e773594SJonathan Cooper /* Allocate and initialise a struct net_device */ 1061*7e773594SJonathan Cooper net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES); 1062874aeea5SJeff Kirsher if (!net_dev) 1063874aeea5SJeff Kirsher return -ENOMEM; 1064*7e773594SJonathan Cooper probe_ptr = netdev_priv(net_dev); 1065*7e773594SJonathan Cooper *probe_ptr = probe_data; 1066*7e773594SJonathan Cooper efx->net_dev = net_dev; 1067adeb15aaSBen Hutchings efx->type = (const struct efx_nic_type *) entry->driver_data; 1068ebfcd0fdSAndrew Rybchenko efx->fixed_features |= NETIF_F_HIGHDMA; 1069eb7cfd8cSAndrew Rybchenko 1070874aeea5SJeff Kirsher pci_set_drvdata(pci_dev, efx); 1071874aeea5SJeff Kirsher SET_NETDEV_DEV(net_dev, &pci_dev->dev); 107262ac3ce5SJonathan Cooper rc = efx_init_struct(efx, pci_dev); 1073874aeea5SJeff Kirsher if (rc) 1074874aeea5SJeff Kirsher goto fail1; 107562ac3ce5SJonathan Cooper efx->mdio.dev = net_dev; 1076874aeea5SJeff Kirsher 1077fa44821aSHeiner Kallweit pci_info(pci_dev, "Solarflare NIC detected\n"); 1078874aeea5SJeff Kirsher 10796f7f8aa6SShradha Shah if (!efx->type->is_vf) 1080ef215e64SBen Hutchings efx_probe_vpd_strings(efx); 1081460eeaa0SBen Hutchings 1082874aeea5SJeff Kirsher /* Set up basic I/O (BAR mappings etc) */ 1083b1940451SAlex Maftei (amaftei) rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask, 1084b1940451SAlex Maftei (amaftei) efx->type->mem_map_size(efx)); 1085874aeea5SJeff Kirsher if (rc) 1086874aeea5SJeff Kirsher goto fail2; 1087874aeea5SJeff Kirsher 10888a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 10898a531400SJon Cooper if (rc) { 10908a531400SJon Cooper /* On failure, retry once immediately. 10918a531400SJon Cooper * If we aborted probe due to a scheduled reset, dismiss it. 10928a531400SJon Cooper */ 10938a531400SJon Cooper efx->reset_pending = 0; 10948a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 10958a531400SJon Cooper if (rc) { 10968a531400SJon Cooper /* On another failure, retry once more 10978a531400SJon Cooper * after a 50-305ms delay. 10988a531400SJon Cooper */ 10998a531400SJon Cooper unsigned char r; 11008a531400SJon Cooper 11018a531400SJon Cooper get_random_bytes(&r, 1); 11028a531400SJon Cooper msleep((unsigned int)r + 50); 11038a531400SJon Cooper efx->reset_pending = 0; 11048a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 11058a531400SJon Cooper } 11068a531400SJon Cooper } 1107fadac6aaSBen Hutchings if (rc) 1108874aeea5SJeff Kirsher goto fail3; 1109874aeea5SJeff Kirsher 1110874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); 1111874aeea5SJeff Kirsher 11127c43161cSBen Hutchings /* Try to create MTDs, but allow this to fail */ 1113874aeea5SJeff Kirsher rtnl_lock(); 11147c43161cSBen Hutchings rc = efx_mtd_probe(efx); 1115874aeea5SJeff Kirsher rtnl_unlock(); 111609a04204SBert Kenward if (rc && rc != -EPERM) 11177c43161cSBen Hutchings netif_warn(efx, probe, efx->net_dev, 11187c43161cSBen Hutchings "failed to create MTDs (%d)\n", rc); 11197c43161cSBen Hutchings 112005cfee98SMartin Habets (void)pci_enable_pcie_error_reporting(pci_dev); 1121626950dbSAlexandre Rames 1122e5fbd977SJon Cooper if (efx->type->udp_tnl_push_ports) 1123e5fbd977SJon Cooper efx->type->udp_tnl_push_ports(efx); 1124e5fbd977SJon Cooper 1125874aeea5SJeff Kirsher return 0; 1126874aeea5SJeff Kirsher 1127874aeea5SJeff Kirsher fail3: 112866a65128SEdward Cree efx_fini_io(efx); 1129874aeea5SJeff Kirsher fail2: 1130874aeea5SJeff Kirsher efx_fini_struct(efx); 1131874aeea5SJeff Kirsher fail1: 1132874aeea5SJeff Kirsher WARN_ON(rc > 0); 1133874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); 1134874aeea5SJeff Kirsher free_netdev(net_dev); 1135874aeea5SJeff Kirsher return rc; 1136874aeea5SJeff Kirsher } 1137874aeea5SJeff Kirsher 1138834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions 1139834e23ddSShradha Shah * enabled on success 1140834e23ddSShradha Shah */ 1141834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1142834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) 1143834e23ddSShradha Shah { 1144834e23ddSShradha Shah int rc; 1145834e23ddSShradha Shah struct efx_nic *efx = pci_get_drvdata(dev); 1146834e23ddSShradha Shah 1147834e23ddSShradha Shah if (efx->type->sriov_configure) { 1148834e23ddSShradha Shah rc = efx->type->sriov_configure(efx, num_vfs); 1149834e23ddSShradha Shah if (rc) 1150834e23ddSShradha Shah return rc; 1151834e23ddSShradha Shah else 1152834e23ddSShradha Shah return num_vfs; 1153834e23ddSShradha Shah } else 1154834e23ddSShradha Shah return -EOPNOTSUPP; 1155834e23ddSShradha Shah } 1156834e23ddSShradha Shah #endif 1157834e23ddSShradha Shah 1158874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev) 1159874aeea5SJeff Kirsher { 11603e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1161874aeea5SJeff Kirsher 116261da026dSBen Hutchings rtnl_lock(); 116361da026dSBen Hutchings 1164813cf9d1SJonathan Cooper if (efx_net_active(efx->state)) { 1165c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 1166874aeea5SJeff Kirsher 1167874aeea5SJeff Kirsher efx_stop_all(efx); 1168d8291187SBen Hutchings efx_disable_interrupts(efx); 1169813cf9d1SJonathan Cooper 1170813cf9d1SJonathan Cooper efx->state = efx_freeze(efx->state); 11716032fb56SBen Hutchings } 1172874aeea5SJeff Kirsher 117361da026dSBen Hutchings rtnl_unlock(); 117461da026dSBen Hutchings 1175874aeea5SJeff Kirsher return 0; 1176874aeea5SJeff Kirsher } 1177874aeea5SJeff Kirsher 1178874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev) 1179874aeea5SJeff Kirsher { 1180261e4d96SJon Cooper int rc; 11813e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1182874aeea5SJeff Kirsher 118361da026dSBen Hutchings rtnl_lock(); 118461da026dSBen Hutchings 1185813cf9d1SJonathan Cooper if (efx_frozen(efx->state)) { 1186261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 1187261e4d96SJon Cooper if (rc) 1188261e4d96SJon Cooper goto fail; 1189874aeea5SJeff Kirsher 1190874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1191c77289b4SEdward Cree efx_mcdi_port_reconfigure(efx); 1192874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1193874aeea5SJeff Kirsher 1194874aeea5SJeff Kirsher efx_start_all(efx); 1195874aeea5SJeff Kirsher 11969c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 1197874aeea5SJeff Kirsher 1198813cf9d1SJonathan Cooper efx->state = efx_thaw(efx->state); 1199874aeea5SJeff Kirsher 1200874aeea5SJeff Kirsher efx->type->resume_wol(efx); 12016032fb56SBen Hutchings } 1202874aeea5SJeff Kirsher 120361da026dSBen Hutchings rtnl_unlock(); 120461da026dSBen Hutchings 1205874aeea5SJeff Kirsher /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ 120682c64484SAlex Maftei (amaftei) efx_queue_reset_work(efx); 1207874aeea5SJeff Kirsher 1208874aeea5SJeff Kirsher return 0; 1209261e4d96SJon Cooper 1210261e4d96SJon Cooper fail: 1211261e4d96SJon Cooper rtnl_unlock(); 1212261e4d96SJon Cooper 1213261e4d96SJon Cooper return rc; 1214874aeea5SJeff Kirsher } 1215874aeea5SJeff Kirsher 1216874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev) 1217874aeea5SJeff Kirsher { 1218874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 1219874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 1220874aeea5SJeff Kirsher 1221874aeea5SJeff Kirsher efx->type->fini(efx); 1222874aeea5SJeff Kirsher 1223874aeea5SJeff Kirsher efx->reset_pending = 0; 1224874aeea5SJeff Kirsher 1225874aeea5SJeff Kirsher pci_save_state(pci_dev); 1226874aeea5SJeff Kirsher return pci_set_power_state(pci_dev, PCI_D3hot); 1227874aeea5SJeff Kirsher } 1228874aeea5SJeff Kirsher 1229874aeea5SJeff Kirsher /* Used for both resume and restore */ 1230874aeea5SJeff Kirsher static int efx_pm_resume(struct device *dev) 1231874aeea5SJeff Kirsher { 1232874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 1233874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 1234874aeea5SJeff Kirsher int rc; 1235874aeea5SJeff Kirsher 1236874aeea5SJeff Kirsher rc = pci_set_power_state(pci_dev, PCI_D0); 1237874aeea5SJeff Kirsher if (rc) 1238874aeea5SJeff Kirsher return rc; 1239874aeea5SJeff Kirsher pci_restore_state(pci_dev); 1240874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 1241874aeea5SJeff Kirsher if (rc) 1242874aeea5SJeff Kirsher return rc; 1243874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 1244874aeea5SJeff Kirsher rc = efx->type->reset(efx, RESET_TYPE_ALL); 1245874aeea5SJeff Kirsher if (rc) 1246874aeea5SJeff Kirsher return rc; 1247193f2003SBert Kenward down_write(&efx->filter_sem); 1248874aeea5SJeff Kirsher rc = efx->type->init(efx); 1249193f2003SBert Kenward up_write(&efx->filter_sem); 1250874aeea5SJeff Kirsher if (rc) 1251874aeea5SJeff Kirsher return rc; 1252261e4d96SJon Cooper rc = efx_pm_thaw(dev); 1253261e4d96SJon Cooper return rc; 1254874aeea5SJeff Kirsher } 1255874aeea5SJeff Kirsher 1256874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev) 1257874aeea5SJeff Kirsher { 1258874aeea5SJeff Kirsher int rc; 1259874aeea5SJeff Kirsher 1260874aeea5SJeff Kirsher efx_pm_freeze(dev); 1261874aeea5SJeff Kirsher rc = efx_pm_poweroff(dev); 1262874aeea5SJeff Kirsher if (rc) 1263874aeea5SJeff Kirsher efx_pm_resume(dev); 1264874aeea5SJeff Kirsher return rc; 1265874aeea5SJeff Kirsher } 1266874aeea5SJeff Kirsher 126718e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = { 1268874aeea5SJeff Kirsher .suspend = efx_pm_suspend, 1269874aeea5SJeff Kirsher .resume = efx_pm_resume, 1270874aeea5SJeff Kirsher .freeze = efx_pm_freeze, 1271874aeea5SJeff Kirsher .thaw = efx_pm_thaw, 1272874aeea5SJeff Kirsher .poweroff = efx_pm_poweroff, 1273874aeea5SJeff Kirsher .restore = efx_pm_resume, 1274874aeea5SJeff Kirsher }; 1275874aeea5SJeff Kirsher 1276874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = { 1277874aeea5SJeff Kirsher .name = KBUILD_MODNAME, 1278874aeea5SJeff Kirsher .id_table = efx_pci_table, 1279874aeea5SJeff Kirsher .probe = efx_pci_probe, 1280874aeea5SJeff Kirsher .remove = efx_pci_remove, 1281874aeea5SJeff Kirsher .driver.pm = &efx_pm_ops, 1282626950dbSAlexandre Rames .err_handler = &efx_err_handlers, 1283834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1284834e23ddSShradha Shah .sriov_configure = efx_pci_sriov_configure, 1285834e23ddSShradha Shah #endif 1286874aeea5SJeff Kirsher }; 1287874aeea5SJeff Kirsher 1288874aeea5SJeff Kirsher /************************************************************************** 1289874aeea5SJeff Kirsher * 1290874aeea5SJeff Kirsher * Kernel module interface 1291874aeea5SJeff Kirsher * 1292874aeea5SJeff Kirsher *************************************************************************/ 1293874aeea5SJeff Kirsher 1294874aeea5SJeff Kirsher static int __init efx_init_module(void) 1295874aeea5SJeff Kirsher { 1296874aeea5SJeff Kirsher int rc; 1297874aeea5SJeff Kirsher 129860bd2a2dSEdward Cree printk(KERN_INFO "Solarflare NET driver\n"); 1299874aeea5SJeff Kirsher 1300874aeea5SJeff Kirsher rc = register_netdevice_notifier(&efx_netdev_notifier); 1301874aeea5SJeff Kirsher if (rc) 1302874aeea5SJeff Kirsher goto err_notifier; 1303874aeea5SJeff Kirsher 130482c64484SAlex Maftei (amaftei) rc = efx_create_reset_workqueue(); 130582c64484SAlex Maftei (amaftei) if (rc) 1306874aeea5SJeff Kirsher goto err_reset; 1307874aeea5SJeff Kirsher 1308874aeea5SJeff Kirsher rc = pci_register_driver(&efx_pci_driver); 1309874aeea5SJeff Kirsher if (rc < 0) 1310874aeea5SJeff Kirsher goto err_pci; 1311874aeea5SJeff Kirsher 131251b35a45SEdward Cree rc = pci_register_driver(&ef100_pci_driver); 131351b35a45SEdward Cree if (rc < 0) 131451b35a45SEdward Cree goto err_pci_ef100; 131551b35a45SEdward Cree 1316874aeea5SJeff Kirsher return 0; 1317874aeea5SJeff Kirsher 131851b35a45SEdward Cree err_pci_ef100: 131951b35a45SEdward Cree pci_unregister_driver(&efx_pci_driver); 1320874aeea5SJeff Kirsher err_pci: 132182c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1322874aeea5SJeff Kirsher err_reset: 1323874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1324874aeea5SJeff Kirsher err_notifier: 1325874aeea5SJeff Kirsher return rc; 1326874aeea5SJeff Kirsher } 1327874aeea5SJeff Kirsher 1328874aeea5SJeff Kirsher static void __exit efx_exit_module(void) 1329874aeea5SJeff Kirsher { 1330874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver unloading\n"); 1331874aeea5SJeff Kirsher 133251b35a45SEdward Cree pci_unregister_driver(&ef100_pci_driver); 1333874aeea5SJeff Kirsher pci_unregister_driver(&efx_pci_driver); 133482c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1335874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1336874aeea5SJeff Kirsher 1337874aeea5SJeff Kirsher } 1338874aeea5SJeff Kirsher 1339874aeea5SJeff Kirsher module_init(efx_init_module); 1340874aeea5SJeff Kirsher module_exit(efx_exit_module); 1341874aeea5SJeff Kirsher 1342874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and " 1343874aeea5SJeff Kirsher "Michael Brown <mbrown@fensystems.co.uk>"); 13446a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver"); 1345874aeea5SJeff Kirsher MODULE_LICENSE("GPL"); 1346874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table); 1347