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 373*813cf9d1SJonathan Cooper efx->state = STATE_NET_DOWN; 374*813cf9d1SJonathan 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 { 495874aeea5SJeff Kirsher struct efx_nic *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 { 520874aeea5SJeff Kirsher struct efx_nic *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); 541*813cf9d1SJonathan Cooper else 542*813cf9d1SJonathan Cooper efx->state = STATE_NET_UP; 543*813cf9d1SJonathan 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 { 554874aeea5SJeff Kirsher struct efx_nic *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 { 5674a53ea8aSAndrew Rybchenko struct efx_nic *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 { 5774a53ea8aSAndrew Rybchenko struct efx_nic *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 { 646e45a4fedSCharles McLachlan struct efx_nic *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 { 659dfe44c1fSCharles McLachlan struct efx_nic *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) 681874aeea5SJeff Kirsher efx_update_name(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 746*813cf9d1SJonathan Cooper efx->state = STATE_NET_DOWN; 747*813cf9d1SJonathan 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 777874aeea5SJeff Kirsher BUG_ON(netdev_priv(efx->net_dev) != efx); 778874aeea5SJeff Kirsher 779e7fef9b4SEdward Cree if (efx_dev_registered(efx)) { 780874aeea5SJeff Kirsher strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); 781b69f7a3eSAlex Maftei (amaftei) efx_fini_mcdi_logging(efx); 782874aeea5SJeff Kirsher device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); 783e7fef9b4SEdward Cree unregister_netdev(efx->net_dev); 784e7fef9b4SEdward Cree } 785874aeea5SJeff Kirsher } 786874aeea5SJeff Kirsher 787874aeea5SJeff Kirsher /************************************************************************** 788874aeea5SJeff Kirsher * 789874aeea5SJeff Kirsher * List of NICs we support 790874aeea5SJeff Kirsher * 791874aeea5SJeff Kirsher **************************************************************************/ 792874aeea5SJeff Kirsher 793874aeea5SJeff Kirsher /* PCI device ID table */ 7949baa3c34SBenoit Taine static const struct pci_device_id efx_pci_table[] = { 7958127d661SBen Hutchings {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ 7968127d661SBen Hutchings .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 7976f7f8aa6SShradha Shah {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ 7986f7f8aa6SShradha Shah .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 7993b06a00eSMateusz Wrzesinski {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ 8003b06a00eSMateusz Wrzesinski .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 801dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */ 802dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 803dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */ 804dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 805dd248f1bSBert Kenward {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */ 806dd248f1bSBert Kenward .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 807aae5a316SEdward Cree {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */ 808aae5a316SEdward Cree .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, 809aae5a316SEdward Cree {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */ 810aae5a316SEdward Cree .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, 811874aeea5SJeff Kirsher {0} /* end of list */ 812874aeea5SJeff Kirsher }; 813874aeea5SJeff Kirsher 814874aeea5SJeff Kirsher /************************************************************************** 815874aeea5SJeff Kirsher * 816874aeea5SJeff Kirsher * Data housekeeping 817874aeea5SJeff Kirsher * 818874aeea5SJeff Kirsher **************************************************************************/ 819874aeea5SJeff Kirsher 820e4d112e4SEdward Cree void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) 821e4d112e4SEdward Cree { 822e4d112e4SEdward Cree u64 n_rx_nodesc_trunc = 0; 823e4d112e4SEdward Cree struct efx_channel *channel; 824e4d112e4SEdward Cree 825e4d112e4SEdward Cree efx_for_each_channel(channel, efx) 826e4d112e4SEdward Cree n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; 827e4d112e4SEdward Cree stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; 828e4d112e4SEdward Cree stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); 829e4d112e4SEdward Cree } 830e4d112e4SEdward Cree 831874aeea5SJeff Kirsher /************************************************************************** 832874aeea5SJeff Kirsher * 833874aeea5SJeff Kirsher * PCI interface 834874aeea5SJeff Kirsher * 835874aeea5SJeff Kirsher **************************************************************************/ 836874aeea5SJeff Kirsher 837874aeea5SJeff Kirsher /* Main body of final NIC shutdown code 838874aeea5SJeff Kirsher * This is called only at module unload (or hotplug removal). 839874aeea5SJeff Kirsher */ 840874aeea5SJeff Kirsher static void efx_pci_remove_main(struct efx_nic *efx) 841874aeea5SJeff Kirsher { 8427153f623SBen Hutchings /* Flush reset_work. It can no longer be scheduled since we 8437153f623SBen Hutchings * are not READY. 8447153f623SBen Hutchings */ 845*813cf9d1SJonathan Cooper WARN_ON(efx_net_active(efx->state)); 84682c64484SAlex Maftei (amaftei) efx_flush_reset_workqueue(efx); 8477153f623SBen Hutchings 848d8291187SBen Hutchings efx_disable_interrupts(efx); 849a83762d9SBert Kenward efx_clear_interrupt_affinity(efx); 850874aeea5SJeff Kirsher efx_nic_fini_interrupt(efx); 851874aeea5SJeff Kirsher efx_fini_port(efx); 852874aeea5SJeff Kirsher efx->type->fini(efx); 853874aeea5SJeff Kirsher efx_fini_napi(efx); 854874aeea5SJeff Kirsher efx_remove_all(efx); 855874aeea5SJeff Kirsher } 856874aeea5SJeff Kirsher 857874aeea5SJeff Kirsher /* Final NIC shutdown 8582a3fc311SDaniel Pieczko * This is called only at module unload (or hotplug removal). A PF can call 8592a3fc311SDaniel Pieczko * this on its VFs to ensure they are unbound first. 860874aeea5SJeff Kirsher */ 861874aeea5SJeff Kirsher static void efx_pci_remove(struct pci_dev *pci_dev) 862874aeea5SJeff Kirsher { 863874aeea5SJeff Kirsher struct efx_nic *efx; 864874aeea5SJeff Kirsher 865874aeea5SJeff Kirsher efx = pci_get_drvdata(pci_dev); 866874aeea5SJeff Kirsher if (!efx) 867874aeea5SJeff Kirsher return; 868874aeea5SJeff Kirsher 869874aeea5SJeff Kirsher /* Mark the NIC as fini, then stop the interface */ 870874aeea5SJeff Kirsher rtnl_lock(); 8710bcf4a64SBen Hutchings efx_dissociate(efx); 872874aeea5SJeff Kirsher dev_close(efx->net_dev); 873d8291187SBen Hutchings efx_disable_interrupts(efx); 874ea6bb99eSEdward Cree efx->state = STATE_UNINIT; 875874aeea5SJeff Kirsher rtnl_unlock(); 876874aeea5SJeff Kirsher 8777fa8d547SShradha Shah if (efx->type->sriov_fini) 878d98a4ffeSShradha Shah efx->type->sriov_fini(efx); 8797fa8d547SShradha Shah 880874aeea5SJeff Kirsher efx_unregister_netdev(efx); 881874aeea5SJeff Kirsher 882874aeea5SJeff Kirsher efx_mtd_remove(efx); 883874aeea5SJeff Kirsher 884874aeea5SJeff Kirsher efx_pci_remove_main(efx); 885874aeea5SJeff Kirsher 88666a65128SEdward Cree efx_fini_io(efx); 887874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); 888874aeea5SJeff Kirsher 889874aeea5SJeff Kirsher efx_fini_struct(efx); 890874aeea5SJeff Kirsher free_netdev(efx->net_dev); 891626950dbSAlexandre Rames 892626950dbSAlexandre Rames pci_disable_pcie_error_reporting(pci_dev); 893874aeea5SJeff Kirsher }; 894874aeea5SJeff Kirsher 895460eeaa0SBen Hutchings /* NIC VPD information 896460eeaa0SBen Hutchings * Called during probe to display the part number of the 8975119e20fSHeiner Kallweit * installed NIC. 898460eeaa0SBen Hutchings */ 899ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx) 900460eeaa0SBen Hutchings { 901460eeaa0SBen Hutchings struct pci_dev *dev = efx->pci_dev; 90237838aa4SHeiner Kallweit unsigned int vpd_size, kw_len; 9035119e20fSHeiner Kallweit u8 *vpd_data; 90437838aa4SHeiner Kallweit int start; 905460eeaa0SBen Hutchings 9065119e20fSHeiner Kallweit vpd_data = pci_vpd_alloc(dev, &vpd_size); 9075119e20fSHeiner Kallweit if (IS_ERR(vpd_data)) { 9085119e20fSHeiner Kallweit pci_warn(dev, "Unable to read VPD\n"); 909460eeaa0SBen Hutchings return; 910460eeaa0SBen Hutchings } 911460eeaa0SBen Hutchings 91237838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 91337838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); 91437838aa4SHeiner Kallweit if (start < 0) 91537838aa4SHeiner Kallweit pci_err(dev, "Part number not found or incomplete\n"); 91637838aa4SHeiner Kallweit else 91737838aa4SHeiner Kallweit pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start); 918460eeaa0SBen Hutchings 91937838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 92037838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len); 92137838aa4SHeiner Kallweit if (start < 0) 92237838aa4SHeiner Kallweit pci_err(dev, "Serial number not found or incomplete\n"); 92337838aa4SHeiner Kallweit else 92437838aa4SHeiner Kallweit efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL); 925460eeaa0SBen Hutchings 9265119e20fSHeiner Kallweit kfree(vpd_data); 927460eeaa0SBen Hutchings } 928460eeaa0SBen Hutchings 929460eeaa0SBen Hutchings 930874aeea5SJeff Kirsher /* Main body of NIC initialisation 931874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, theoretically). 932874aeea5SJeff Kirsher */ 933874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx) 934874aeea5SJeff Kirsher { 935874aeea5SJeff Kirsher int rc; 936874aeea5SJeff Kirsher 937874aeea5SJeff Kirsher /* Do start-of-day initialisation */ 938874aeea5SJeff Kirsher rc = efx_probe_all(efx); 939874aeea5SJeff Kirsher if (rc) 940874aeea5SJeff Kirsher goto fail1; 941874aeea5SJeff Kirsher 942874aeea5SJeff Kirsher efx_init_napi(efx); 943874aeea5SJeff Kirsher 944193f2003SBert Kenward down_write(&efx->filter_sem); 945874aeea5SJeff Kirsher rc = efx->type->init(efx); 946193f2003SBert Kenward up_write(&efx->filter_sem); 947874aeea5SJeff Kirsher if (rc) { 948fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "failed to initialise NIC\n"); 949874aeea5SJeff Kirsher goto fail3; 950874aeea5SJeff Kirsher } 951874aeea5SJeff Kirsher 952874aeea5SJeff Kirsher rc = efx_init_port(efx); 953874aeea5SJeff Kirsher if (rc) { 954874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 955874aeea5SJeff Kirsher "failed to initialise port\n"); 956874aeea5SJeff Kirsher goto fail4; 957874aeea5SJeff Kirsher } 958874aeea5SJeff Kirsher 959874aeea5SJeff Kirsher rc = efx_nic_init_interrupt(efx); 960874aeea5SJeff Kirsher if (rc) 961874aeea5SJeff Kirsher goto fail5; 962a83762d9SBert Kenward 963a83762d9SBert Kenward efx_set_interrupt_affinity(efx); 964261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 965261e4d96SJon Cooper if (rc) 966261e4d96SJon Cooper goto fail6; 967874aeea5SJeff Kirsher 968874aeea5SJeff Kirsher return 0; 969874aeea5SJeff Kirsher 970261e4d96SJon Cooper fail6: 971a83762d9SBert Kenward efx_clear_interrupt_affinity(efx); 972261e4d96SJon Cooper efx_nic_fini_interrupt(efx); 973874aeea5SJeff Kirsher fail5: 974874aeea5SJeff Kirsher efx_fini_port(efx); 975874aeea5SJeff Kirsher fail4: 976874aeea5SJeff Kirsher efx->type->fini(efx); 977874aeea5SJeff Kirsher fail3: 978874aeea5SJeff Kirsher efx_fini_napi(efx); 979874aeea5SJeff Kirsher efx_remove_all(efx); 980874aeea5SJeff Kirsher fail1: 981874aeea5SJeff Kirsher return rc; 982874aeea5SJeff Kirsher } 983874aeea5SJeff Kirsher 9848a531400SJon Cooper static int efx_pci_probe_post_io(struct efx_nic *efx) 9858a531400SJon Cooper { 9868a531400SJon Cooper struct net_device *net_dev = efx->net_dev; 9878a531400SJon Cooper int rc = efx_pci_probe_main(efx); 9888a531400SJon Cooper 9898a531400SJon Cooper if (rc) 9908a531400SJon Cooper return rc; 9918a531400SJon Cooper 9928a531400SJon Cooper if (efx->type->sriov_init) { 9938a531400SJon Cooper rc = efx->type->sriov_init(efx); 9948a531400SJon Cooper if (rc) 995fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n", 996fa44821aSHeiner Kallweit rc); 9978a531400SJon Cooper } 9988a531400SJon Cooper 9998a531400SJon Cooper /* Determine netdevice features */ 10008a531400SJon Cooper net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 10016978729fSEdward Cree NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL); 10028a531400SJon Cooper if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) 10038a531400SJon Cooper net_dev->features |= NETIF_F_TSO6; 10048a531400SJon Cooper /* Check whether device supports TSO */ 10058a531400SJon Cooper if (!efx->type->tso_versions || !efx->type->tso_versions(efx)) 10068a531400SJon Cooper net_dev->features &= ~NETIF_F_ALL_TSO; 10078a531400SJon Cooper /* Mask for features that also apply to VLAN devices */ 10088a531400SJon Cooper net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 10098a531400SJon Cooper NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 10108a531400SJon Cooper NETIF_F_RXCSUM); 10118a531400SJon Cooper 10126978729fSEdward Cree net_dev->hw_features |= net_dev->features & ~efx->fixed_features; 10136978729fSEdward Cree 10146978729fSEdward Cree /* Disable receiving frames with bad FCS, by default. */ 10156978729fSEdward Cree net_dev->features &= ~NETIF_F_RXALL; 10168a531400SJon Cooper 10178a531400SJon Cooper /* Disable VLAN filtering by default. It may be enforced if 10188a531400SJon Cooper * the feature is fixed (i.e. VLAN filters are required to 10198a531400SJon Cooper * receive VLAN tagged packets due to vPort restrictions). 10208a531400SJon Cooper */ 10218a531400SJon Cooper net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 10228a531400SJon Cooper net_dev->features |= efx->fixed_features; 10238a531400SJon Cooper 10248a531400SJon Cooper rc = efx_register_netdev(efx); 10258a531400SJon Cooper if (!rc) 10268a531400SJon Cooper return 0; 10278a531400SJon Cooper 10288a531400SJon Cooper efx_pci_remove_main(efx); 10298a531400SJon Cooper return rc; 10308a531400SJon Cooper } 10318a531400SJon Cooper 1032874aeea5SJeff Kirsher /* NIC initialisation 1033874aeea5SJeff Kirsher * 1034874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, 103573ba7b68SBen Hutchings * theoretically). It sets up PCI mappings, resets the NIC, 1036874aeea5SJeff Kirsher * sets up and registers the network devices with the kernel and hooks 1037874aeea5SJeff Kirsher * the interrupt service routine. It does not prepare the device for 1038874aeea5SJeff Kirsher * transmission; this is left to the first time one of the network 1039874aeea5SJeff Kirsher * interfaces is brought up (i.e. efx_net_open). 1040874aeea5SJeff Kirsher */ 104187d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev, 1042874aeea5SJeff Kirsher const struct pci_device_id *entry) 1043874aeea5SJeff Kirsher { 1044874aeea5SJeff Kirsher struct net_device *net_dev; 1045874aeea5SJeff Kirsher struct efx_nic *efx; 1046fadac6aaSBen Hutchings int rc; 1047874aeea5SJeff Kirsher 1048874aeea5SJeff Kirsher /* Allocate and initialise a struct net_device and struct efx_nic */ 1049874aeea5SJeff Kirsher net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES, 1050874aeea5SJeff Kirsher EFX_MAX_RX_QUEUES); 1051874aeea5SJeff Kirsher if (!net_dev) 1052874aeea5SJeff Kirsher return -ENOMEM; 1053adeb15aaSBen Hutchings efx = netdev_priv(net_dev); 1054adeb15aaSBen Hutchings efx->type = (const struct efx_nic_type *) entry->driver_data; 1055ebfcd0fdSAndrew Rybchenko efx->fixed_features |= NETIF_F_HIGHDMA; 1056eb7cfd8cSAndrew Rybchenko 1057874aeea5SJeff Kirsher pci_set_drvdata(pci_dev, efx); 1058874aeea5SJeff Kirsher SET_NETDEV_DEV(net_dev, &pci_dev->dev); 1059adeb15aaSBen Hutchings rc = efx_init_struct(efx, pci_dev, net_dev); 1060874aeea5SJeff Kirsher if (rc) 1061874aeea5SJeff Kirsher goto fail1; 1062874aeea5SJeff Kirsher 1063fa44821aSHeiner Kallweit pci_info(pci_dev, "Solarflare NIC detected\n"); 1064874aeea5SJeff Kirsher 10656f7f8aa6SShradha Shah if (!efx->type->is_vf) 1066ef215e64SBen Hutchings efx_probe_vpd_strings(efx); 1067460eeaa0SBen Hutchings 1068874aeea5SJeff Kirsher /* Set up basic I/O (BAR mappings etc) */ 1069b1940451SAlex Maftei (amaftei) rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask, 1070b1940451SAlex Maftei (amaftei) efx->type->mem_map_size(efx)); 1071874aeea5SJeff Kirsher if (rc) 1072874aeea5SJeff Kirsher goto fail2; 1073874aeea5SJeff Kirsher 10748a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 10758a531400SJon Cooper if (rc) { 10768a531400SJon Cooper /* On failure, retry once immediately. 10778a531400SJon Cooper * If we aborted probe due to a scheduled reset, dismiss it. 10788a531400SJon Cooper */ 10798a531400SJon Cooper efx->reset_pending = 0; 10808a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 10818a531400SJon Cooper if (rc) { 10828a531400SJon Cooper /* On another failure, retry once more 10838a531400SJon Cooper * after a 50-305ms delay. 10848a531400SJon Cooper */ 10858a531400SJon Cooper unsigned char r; 10868a531400SJon Cooper 10878a531400SJon Cooper get_random_bytes(&r, 1); 10888a531400SJon Cooper msleep((unsigned int)r + 50); 10898a531400SJon Cooper efx->reset_pending = 0; 10908a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 10918a531400SJon Cooper } 10928a531400SJon Cooper } 1093fadac6aaSBen Hutchings if (rc) 1094874aeea5SJeff Kirsher goto fail3; 1095874aeea5SJeff Kirsher 1096874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); 1097874aeea5SJeff Kirsher 10987c43161cSBen Hutchings /* Try to create MTDs, but allow this to fail */ 1099874aeea5SJeff Kirsher rtnl_lock(); 11007c43161cSBen Hutchings rc = efx_mtd_probe(efx); 1101874aeea5SJeff Kirsher rtnl_unlock(); 110209a04204SBert Kenward if (rc && rc != -EPERM) 11037c43161cSBen Hutchings netif_warn(efx, probe, efx->net_dev, 11047c43161cSBen Hutchings "failed to create MTDs (%d)\n", rc); 11057c43161cSBen Hutchings 110605cfee98SMartin Habets (void)pci_enable_pcie_error_reporting(pci_dev); 1107626950dbSAlexandre Rames 1108e5fbd977SJon Cooper if (efx->type->udp_tnl_push_ports) 1109e5fbd977SJon Cooper efx->type->udp_tnl_push_ports(efx); 1110e5fbd977SJon Cooper 1111874aeea5SJeff Kirsher return 0; 1112874aeea5SJeff Kirsher 1113874aeea5SJeff Kirsher fail3: 111466a65128SEdward Cree efx_fini_io(efx); 1115874aeea5SJeff Kirsher fail2: 1116874aeea5SJeff Kirsher efx_fini_struct(efx); 1117874aeea5SJeff Kirsher fail1: 1118874aeea5SJeff Kirsher WARN_ON(rc > 0); 1119874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); 1120874aeea5SJeff Kirsher free_netdev(net_dev); 1121874aeea5SJeff Kirsher return rc; 1122874aeea5SJeff Kirsher } 1123874aeea5SJeff Kirsher 1124834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions 1125834e23ddSShradha Shah * enabled on success 1126834e23ddSShradha Shah */ 1127834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1128834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) 1129834e23ddSShradha Shah { 1130834e23ddSShradha Shah int rc; 1131834e23ddSShradha Shah struct efx_nic *efx = pci_get_drvdata(dev); 1132834e23ddSShradha Shah 1133834e23ddSShradha Shah if (efx->type->sriov_configure) { 1134834e23ddSShradha Shah rc = efx->type->sriov_configure(efx, num_vfs); 1135834e23ddSShradha Shah if (rc) 1136834e23ddSShradha Shah return rc; 1137834e23ddSShradha Shah else 1138834e23ddSShradha Shah return num_vfs; 1139834e23ddSShradha Shah } else 1140834e23ddSShradha Shah return -EOPNOTSUPP; 1141834e23ddSShradha Shah } 1142834e23ddSShradha Shah #endif 1143834e23ddSShradha Shah 1144874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev) 1145874aeea5SJeff Kirsher { 11463e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1147874aeea5SJeff Kirsher 114861da026dSBen Hutchings rtnl_lock(); 114961da026dSBen Hutchings 1150*813cf9d1SJonathan Cooper if (efx_net_active(efx->state)) { 1151c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 1152874aeea5SJeff Kirsher 1153874aeea5SJeff Kirsher efx_stop_all(efx); 1154d8291187SBen Hutchings efx_disable_interrupts(efx); 1155*813cf9d1SJonathan Cooper 1156*813cf9d1SJonathan Cooper efx->state = efx_freeze(efx->state); 11576032fb56SBen Hutchings } 1158874aeea5SJeff Kirsher 115961da026dSBen Hutchings rtnl_unlock(); 116061da026dSBen Hutchings 1161874aeea5SJeff Kirsher return 0; 1162874aeea5SJeff Kirsher } 1163874aeea5SJeff Kirsher 1164874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev) 1165874aeea5SJeff Kirsher { 1166261e4d96SJon Cooper int rc; 11673e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1168874aeea5SJeff Kirsher 116961da026dSBen Hutchings rtnl_lock(); 117061da026dSBen Hutchings 1171*813cf9d1SJonathan Cooper if (efx_frozen(efx->state)) { 1172261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 1173261e4d96SJon Cooper if (rc) 1174261e4d96SJon Cooper goto fail; 1175874aeea5SJeff Kirsher 1176874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1177c77289b4SEdward Cree efx_mcdi_port_reconfigure(efx); 1178874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1179874aeea5SJeff Kirsher 1180874aeea5SJeff Kirsher efx_start_all(efx); 1181874aeea5SJeff Kirsher 11829c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 1183874aeea5SJeff Kirsher 1184*813cf9d1SJonathan Cooper efx->state = efx_thaw(efx->state); 1185874aeea5SJeff Kirsher 1186874aeea5SJeff Kirsher efx->type->resume_wol(efx); 11876032fb56SBen Hutchings } 1188874aeea5SJeff Kirsher 118961da026dSBen Hutchings rtnl_unlock(); 119061da026dSBen Hutchings 1191874aeea5SJeff Kirsher /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ 119282c64484SAlex Maftei (amaftei) efx_queue_reset_work(efx); 1193874aeea5SJeff Kirsher 1194874aeea5SJeff Kirsher return 0; 1195261e4d96SJon Cooper 1196261e4d96SJon Cooper fail: 1197261e4d96SJon Cooper rtnl_unlock(); 1198261e4d96SJon Cooper 1199261e4d96SJon Cooper return rc; 1200874aeea5SJeff Kirsher } 1201874aeea5SJeff Kirsher 1202874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev) 1203874aeea5SJeff Kirsher { 1204874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 1205874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 1206874aeea5SJeff Kirsher 1207874aeea5SJeff Kirsher efx->type->fini(efx); 1208874aeea5SJeff Kirsher 1209874aeea5SJeff Kirsher efx->reset_pending = 0; 1210874aeea5SJeff Kirsher 1211874aeea5SJeff Kirsher pci_save_state(pci_dev); 1212874aeea5SJeff Kirsher return pci_set_power_state(pci_dev, PCI_D3hot); 1213874aeea5SJeff Kirsher } 1214874aeea5SJeff Kirsher 1215874aeea5SJeff Kirsher /* Used for both resume and restore */ 1216874aeea5SJeff Kirsher static int efx_pm_resume(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 int rc; 1221874aeea5SJeff Kirsher 1222874aeea5SJeff Kirsher rc = pci_set_power_state(pci_dev, PCI_D0); 1223874aeea5SJeff Kirsher if (rc) 1224874aeea5SJeff Kirsher return rc; 1225874aeea5SJeff Kirsher pci_restore_state(pci_dev); 1226874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 1227874aeea5SJeff Kirsher if (rc) 1228874aeea5SJeff Kirsher return rc; 1229874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 1230874aeea5SJeff Kirsher rc = efx->type->reset(efx, RESET_TYPE_ALL); 1231874aeea5SJeff Kirsher if (rc) 1232874aeea5SJeff Kirsher return rc; 1233193f2003SBert Kenward down_write(&efx->filter_sem); 1234874aeea5SJeff Kirsher rc = efx->type->init(efx); 1235193f2003SBert Kenward up_write(&efx->filter_sem); 1236874aeea5SJeff Kirsher if (rc) 1237874aeea5SJeff Kirsher return rc; 1238261e4d96SJon Cooper rc = efx_pm_thaw(dev); 1239261e4d96SJon Cooper return rc; 1240874aeea5SJeff Kirsher } 1241874aeea5SJeff Kirsher 1242874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev) 1243874aeea5SJeff Kirsher { 1244874aeea5SJeff Kirsher int rc; 1245874aeea5SJeff Kirsher 1246874aeea5SJeff Kirsher efx_pm_freeze(dev); 1247874aeea5SJeff Kirsher rc = efx_pm_poweroff(dev); 1248874aeea5SJeff Kirsher if (rc) 1249874aeea5SJeff Kirsher efx_pm_resume(dev); 1250874aeea5SJeff Kirsher return rc; 1251874aeea5SJeff Kirsher } 1252874aeea5SJeff Kirsher 125318e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = { 1254874aeea5SJeff Kirsher .suspend = efx_pm_suspend, 1255874aeea5SJeff Kirsher .resume = efx_pm_resume, 1256874aeea5SJeff Kirsher .freeze = efx_pm_freeze, 1257874aeea5SJeff Kirsher .thaw = efx_pm_thaw, 1258874aeea5SJeff Kirsher .poweroff = efx_pm_poweroff, 1259874aeea5SJeff Kirsher .restore = efx_pm_resume, 1260874aeea5SJeff Kirsher }; 1261874aeea5SJeff Kirsher 1262874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = { 1263874aeea5SJeff Kirsher .name = KBUILD_MODNAME, 1264874aeea5SJeff Kirsher .id_table = efx_pci_table, 1265874aeea5SJeff Kirsher .probe = efx_pci_probe, 1266874aeea5SJeff Kirsher .remove = efx_pci_remove, 1267874aeea5SJeff Kirsher .driver.pm = &efx_pm_ops, 1268626950dbSAlexandre Rames .err_handler = &efx_err_handlers, 1269834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1270834e23ddSShradha Shah .sriov_configure = efx_pci_sriov_configure, 1271834e23ddSShradha Shah #endif 1272874aeea5SJeff Kirsher }; 1273874aeea5SJeff Kirsher 1274874aeea5SJeff Kirsher /************************************************************************** 1275874aeea5SJeff Kirsher * 1276874aeea5SJeff Kirsher * Kernel module interface 1277874aeea5SJeff Kirsher * 1278874aeea5SJeff Kirsher *************************************************************************/ 1279874aeea5SJeff Kirsher 1280874aeea5SJeff Kirsher static int __init efx_init_module(void) 1281874aeea5SJeff Kirsher { 1282874aeea5SJeff Kirsher int rc; 1283874aeea5SJeff Kirsher 128460bd2a2dSEdward Cree printk(KERN_INFO "Solarflare NET driver\n"); 1285874aeea5SJeff Kirsher 1286874aeea5SJeff Kirsher rc = register_netdevice_notifier(&efx_netdev_notifier); 1287874aeea5SJeff Kirsher if (rc) 1288874aeea5SJeff Kirsher goto err_notifier; 1289874aeea5SJeff Kirsher 129082c64484SAlex Maftei (amaftei) rc = efx_create_reset_workqueue(); 129182c64484SAlex Maftei (amaftei) if (rc) 1292874aeea5SJeff Kirsher goto err_reset; 1293874aeea5SJeff Kirsher 1294874aeea5SJeff Kirsher rc = pci_register_driver(&efx_pci_driver); 1295874aeea5SJeff Kirsher if (rc < 0) 1296874aeea5SJeff Kirsher goto err_pci; 1297874aeea5SJeff Kirsher 129851b35a45SEdward Cree rc = pci_register_driver(&ef100_pci_driver); 129951b35a45SEdward Cree if (rc < 0) 130051b35a45SEdward Cree goto err_pci_ef100; 130151b35a45SEdward Cree 1302874aeea5SJeff Kirsher return 0; 1303874aeea5SJeff Kirsher 130451b35a45SEdward Cree err_pci_ef100: 130551b35a45SEdward Cree pci_unregister_driver(&efx_pci_driver); 1306874aeea5SJeff Kirsher err_pci: 130782c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1308874aeea5SJeff Kirsher err_reset: 1309874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1310874aeea5SJeff Kirsher err_notifier: 1311874aeea5SJeff Kirsher return rc; 1312874aeea5SJeff Kirsher } 1313874aeea5SJeff Kirsher 1314874aeea5SJeff Kirsher static void __exit efx_exit_module(void) 1315874aeea5SJeff Kirsher { 1316874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver unloading\n"); 1317874aeea5SJeff Kirsher 131851b35a45SEdward Cree pci_unregister_driver(&ef100_pci_driver); 1319874aeea5SJeff Kirsher pci_unregister_driver(&efx_pci_driver); 132082c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1321874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1322874aeea5SJeff Kirsher 1323874aeea5SJeff Kirsher } 1324874aeea5SJeff Kirsher 1325874aeea5SJeff Kirsher module_init(efx_init_module); 1326874aeea5SJeff Kirsher module_exit(efx_exit_module); 1327874aeea5SJeff Kirsher 1328874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and " 1329874aeea5SJeff Kirsher "Michael Brown <mbrown@fensystems.co.uk>"); 13306a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver"); 1331874aeea5SJeff Kirsher MODULE_LICENSE("GPL"); 1332874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table); 1333