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> 21b28405b0SAlexandre Rames #include <linux/interrupt.h> 22874aeea5SJeff Kirsher #include "net_driver.h" 23e5fbd977SJon Cooper #include <net/gre.h> 24e5fbd977SJon Cooper #include <net/udp_tunnel.h> 25874aeea5SJeff Kirsher #include "efx.h" 26e1253f39SAlex Maftei (amaftei) #include "efx_common.h" 27e1253f39SAlex Maftei (amaftei) #include "efx_channels.h" 2851b35a45SEdward Cree #include "ef100.h" 29e1253f39SAlex Maftei (amaftei) #include "rx_common.h" 30e1253f39SAlex Maftei (amaftei) #include "tx_common.h" 31874aeea5SJeff Kirsher #include "nic.h" 3271827443SEdward Cree #include "io.h" 33dd40781eSBen Hutchings #include "selftest.h" 347fa8d547SShradha Shah #include "sriov.h" 35*998b85f0SMartin Habets #include "efx_devlink.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 544874aeea5SJeff Kirsher return 0; 545874aeea5SJeff Kirsher } 546874aeea5SJeff Kirsher 547874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. 548874aeea5SJeff Kirsher * Note that the kernel will ignore our return code; this method 549874aeea5SJeff Kirsher * should really be a void. 550874aeea5SJeff Kirsher */ 551e340be92SShradha Shah int efx_net_stop(struct net_device *net_dev) 552874aeea5SJeff Kirsher { 5538cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 554874aeea5SJeff Kirsher 555874aeea5SJeff Kirsher netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", 556874aeea5SJeff Kirsher raw_smp_processor_id()); 557874aeea5SJeff Kirsher 558874aeea5SJeff Kirsher /* Stop the device and flush all the channels */ 559874aeea5SJeff Kirsher efx_stop_all(efx); 560874aeea5SJeff Kirsher 561874aeea5SJeff Kirsher return 0; 562874aeea5SJeff Kirsher } 563874aeea5SJeff Kirsher 5644a53ea8aSAndrew Rybchenko static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid) 5654a53ea8aSAndrew Rybchenko { 5668cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 5674a53ea8aSAndrew Rybchenko 5684a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_add_vid) 5694a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_add_vid(efx, proto, vid); 5704a53ea8aSAndrew Rybchenko else 5714a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 5724a53ea8aSAndrew Rybchenko } 5734a53ea8aSAndrew Rybchenko 5744a53ea8aSAndrew Rybchenko static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid) 5754a53ea8aSAndrew Rybchenko { 5768cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(net_dev); 5774a53ea8aSAndrew Rybchenko 5784a53ea8aSAndrew Rybchenko if (efx->type->vlan_rx_kill_vid) 5794a53ea8aSAndrew Rybchenko return efx->type->vlan_rx_kill_vid(efx, proto, vid); 5804a53ea8aSAndrew Rybchenko else 5814a53ea8aSAndrew Rybchenko return -EOPNOTSUPP; 5824a53ea8aSAndrew Rybchenko } 5834a53ea8aSAndrew Rybchenko 5847fa8d547SShradha Shah static const struct net_device_ops efx_netdev_ops = { 585874aeea5SJeff Kirsher .ndo_open = efx_net_open, 586874aeea5SJeff Kirsher .ndo_stop = efx_net_stop, 587874aeea5SJeff Kirsher .ndo_get_stats64 = efx_net_stats, 588874aeea5SJeff Kirsher .ndo_tx_timeout = efx_watchdog, 589874aeea5SJeff Kirsher .ndo_start_xmit = efx_hard_start_xmit, 590874aeea5SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 591a7605370SArnd Bergmann .ndo_eth_ioctl = efx_ioctl, 592874aeea5SJeff Kirsher .ndo_change_mtu = efx_change_mtu, 593874aeea5SJeff Kirsher .ndo_set_mac_address = efx_set_mac_address, 5940fca8c97SBen Hutchings .ndo_set_rx_mode = efx_set_rx_mode, 595874aeea5SJeff Kirsher .ndo_set_features = efx_set_features, 59624b2c375SEdward Cree .ndo_features_check = efx_features_check, 5974a53ea8aSAndrew Rybchenko .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid, 5984a53ea8aSAndrew Rybchenko .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid, 599cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV 6007fa8d547SShradha Shah .ndo_set_vf_mac = efx_sriov_set_vf_mac, 6017fa8d547SShradha Shah .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, 6027fa8d547SShradha Shah .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, 6037fa8d547SShradha Shah .ndo_get_vf_config = efx_sriov_get_vf_config, 6044392dc69SEdward Cree .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, 605cd2d5b52SBen Hutchings #endif 60608a7b29bSBert Kenward .ndo_get_phys_port_id = efx_get_phys_port_id, 607ac019f08SBert Kenward .ndo_get_phys_port_name = efx_get_phys_port_name, 608874aeea5SJeff Kirsher .ndo_setup_tc = efx_setup_tc, 609874aeea5SJeff Kirsher #ifdef CONFIG_RFS_ACCEL 610874aeea5SJeff Kirsher .ndo_rx_flow_steer = efx_filter_rfs, 611874aeea5SJeff Kirsher #endif 612dfe44c1fSCharles McLachlan .ndo_xdp_xmit = efx_xdp_xmit, 613e45a4fedSCharles McLachlan .ndo_bpf = efx_xdp 614874aeea5SJeff Kirsher }; 615874aeea5SJeff Kirsher 616e45a4fedSCharles McLachlan static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog) 617e45a4fedSCharles McLachlan { 618e45a4fedSCharles McLachlan struct bpf_prog *old_prog; 619e45a4fedSCharles McLachlan 620e45a4fedSCharles McLachlan if (efx->xdp_rxq_info_failed) { 621e45a4fedSCharles McLachlan netif_err(efx, drv, efx->net_dev, 622e45a4fedSCharles McLachlan "Unable to bind XDP program due to previous failure of rxq_info\n"); 623e45a4fedSCharles McLachlan return -EINVAL; 624e45a4fedSCharles McLachlan } 625e45a4fedSCharles McLachlan 626e45a4fedSCharles McLachlan if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) { 627e45a4fedSCharles McLachlan netif_err(efx, drv, efx->net_dev, 628e45a4fedSCharles McLachlan "Unable to configure XDP with MTU of %d (max: %d)\n", 629e45a4fedSCharles McLachlan efx->net_dev->mtu, efx_xdp_max_mtu(efx)); 630e45a4fedSCharles McLachlan return -EINVAL; 631e45a4fedSCharles McLachlan } 632e45a4fedSCharles McLachlan 633e45a4fedSCharles McLachlan old_prog = rtnl_dereference(efx->xdp_prog); 634e45a4fedSCharles McLachlan rcu_assign_pointer(efx->xdp_prog, prog); 635e45a4fedSCharles McLachlan /* Release the reference that was originally passed by the caller. */ 636e45a4fedSCharles McLachlan if (old_prog) 637e45a4fedSCharles McLachlan bpf_prog_put(old_prog); 638e45a4fedSCharles McLachlan 639e45a4fedSCharles McLachlan return 0; 640e45a4fedSCharles McLachlan } 641e45a4fedSCharles McLachlan 642e45a4fedSCharles McLachlan /* Context: process, rtnl_lock() held. */ 643e45a4fedSCharles McLachlan static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp) 644e45a4fedSCharles McLachlan { 6458cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(dev); 646e45a4fedSCharles McLachlan 647e45a4fedSCharles McLachlan switch (xdp->command) { 648e45a4fedSCharles McLachlan case XDP_SETUP_PROG: 649e45a4fedSCharles McLachlan return efx_xdp_setup_prog(efx, xdp->prog); 650e45a4fedSCharles McLachlan default: 651e45a4fedSCharles McLachlan return -EINVAL; 652e45a4fedSCharles McLachlan } 653e45a4fedSCharles McLachlan } 654e45a4fedSCharles McLachlan 655dfe44c1fSCharles McLachlan static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs, 656dfe44c1fSCharles McLachlan u32 flags) 657dfe44c1fSCharles McLachlan { 6588cb03f4eSJonathan Cooper struct efx_nic *efx = efx_netdev_priv(dev); 659dfe44c1fSCharles McLachlan 660dfe44c1fSCharles McLachlan if (!netif_running(dev)) 661dfe44c1fSCharles McLachlan return -EINVAL; 662dfe44c1fSCharles McLachlan 663dfe44c1fSCharles McLachlan return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH); 664dfe44c1fSCharles McLachlan } 665dfe44c1fSCharles McLachlan 666874aeea5SJeff Kirsher static void efx_update_name(struct efx_nic *efx) 667874aeea5SJeff Kirsher { 668874aeea5SJeff Kirsher strcpy(efx->name, efx->net_dev->name); 669874aeea5SJeff Kirsher efx_mtd_rename(efx); 670874aeea5SJeff Kirsher efx_set_channel_names(efx); 671874aeea5SJeff Kirsher } 672874aeea5SJeff Kirsher 673874aeea5SJeff Kirsher static int efx_netdev_event(struct notifier_block *this, 674874aeea5SJeff Kirsher unsigned long event, void *ptr) 675874aeea5SJeff Kirsher { 676351638e7SJiri Pirko struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); 677874aeea5SJeff Kirsher 6787fa8d547SShradha Shah if ((net_dev->netdev_ops == &efx_netdev_ops) && 679874aeea5SJeff Kirsher event == NETDEV_CHANGENAME) 6808cb03f4eSJonathan Cooper efx_update_name(efx_netdev_priv(net_dev)); 681874aeea5SJeff Kirsher 682874aeea5SJeff Kirsher return NOTIFY_DONE; 683874aeea5SJeff Kirsher } 684874aeea5SJeff Kirsher 685874aeea5SJeff Kirsher static struct notifier_block efx_netdev_notifier = { 686874aeea5SJeff Kirsher .notifier_call = efx_netdev_event, 687874aeea5SJeff Kirsher }; 688874aeea5SJeff Kirsher 6893880fc37SYueHaibing static ssize_t phy_type_show(struct device *dev, 6903880fc37SYueHaibing struct device_attribute *attr, char *buf) 691874aeea5SJeff Kirsher { 6923e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 693874aeea5SJeff Kirsher return sprintf(buf, "%d\n", efx->phy_type); 694874aeea5SJeff Kirsher } 6953880fc37SYueHaibing static DEVICE_ATTR_RO(phy_type); 696874aeea5SJeff Kirsher 697874aeea5SJeff Kirsher static int efx_register_netdev(struct efx_nic *efx) 698874aeea5SJeff Kirsher { 699874aeea5SJeff Kirsher struct net_device *net_dev = efx->net_dev; 700874aeea5SJeff Kirsher struct efx_channel *channel; 701874aeea5SJeff Kirsher int rc; 702874aeea5SJeff Kirsher 703874aeea5SJeff Kirsher net_dev->watchdog_timeo = 5 * HZ; 704874aeea5SJeff Kirsher net_dev->irq = efx->pci_dev->irq; 7057fa8d547SShradha Shah net_dev->netdev_ops = &efx_netdev_ops; 7067fa8d547SShradha Shah if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) 7078127d661SBen Hutchings net_dev->priv_flags |= IFF_UNICAST_FLT; 7087ad24ea4SWilfried Klaebe net_dev->ethtool_ops = &efx_ethtool_ops; 709ee8b7a11SJakub Kicinski netif_set_tso_max_segs(net_dev, EFX_TSO_MAX_SEGS); 710cd94e519SBert Kenward net_dev->min_mtu = EFX_MIN_MTU; 711cd94e519SBert Kenward net_dev->max_mtu = EFX_MAX_MTU; 712874aeea5SJeff Kirsher 713874aeea5SJeff Kirsher rtnl_lock(); 714874aeea5SJeff Kirsher 7157153f623SBen Hutchings /* Enable resets to be scheduled and check whether any were 7167153f623SBen Hutchings * already requested. If so, the NIC is probably hosed so we 7177153f623SBen Hutchings * abort. 7187153f623SBen Hutchings */ 7197153f623SBen Hutchings if (efx->reset_pending) { 720fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n"); 7217153f623SBen Hutchings rc = -EIO; 7227153f623SBen Hutchings goto fail_locked; 7237153f623SBen Hutchings } 7247153f623SBen Hutchings 725874aeea5SJeff Kirsher rc = dev_alloc_name(net_dev, net_dev->name); 726874aeea5SJeff Kirsher if (rc < 0) 727874aeea5SJeff Kirsher goto fail_locked; 728874aeea5SJeff Kirsher efx_update_name(efx); 729874aeea5SJeff Kirsher 7308f8b3d51SBen Hutchings /* Always start with carrier off; PHY events will detect the link */ 7318f8b3d51SBen Hutchings netif_carrier_off(net_dev); 7328f8b3d51SBen Hutchings 733874aeea5SJeff Kirsher rc = register_netdevice(net_dev); 734874aeea5SJeff Kirsher if (rc) 735874aeea5SJeff Kirsher goto fail_locked; 736874aeea5SJeff Kirsher 737874aeea5SJeff Kirsher efx_for_each_channel(channel, efx) { 738874aeea5SJeff Kirsher struct efx_tx_queue *tx_queue; 739874aeea5SJeff Kirsher efx_for_each_channel_tx_queue(tx_queue, channel) 740874aeea5SJeff Kirsher efx_init_tx_queue_core_txq(tx_queue); 741874aeea5SJeff Kirsher } 742874aeea5SJeff Kirsher 7430bcf4a64SBen Hutchings efx_associate(efx); 7440bcf4a64SBen Hutchings 745813cf9d1SJonathan Cooper efx->state = STATE_NET_DOWN; 746813cf9d1SJonathan Cooper 747874aeea5SJeff Kirsher rtnl_unlock(); 748874aeea5SJeff Kirsher 749874aeea5SJeff Kirsher rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); 750874aeea5SJeff Kirsher if (rc) { 751874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, 752874aeea5SJeff Kirsher "failed to init net dev attributes\n"); 753874aeea5SJeff Kirsher goto fail_registered; 754874aeea5SJeff Kirsher } 755b69f7a3eSAlex Maftei (amaftei) 756b69f7a3eSAlex Maftei (amaftei) efx_init_mcdi_logging(efx); 757874aeea5SJeff Kirsher 758874aeea5SJeff Kirsher return 0; 759874aeea5SJeff Kirsher 7607153f623SBen Hutchings fail_registered: 7617153f623SBen Hutchings rtnl_lock(); 7620bcf4a64SBen Hutchings efx_dissociate(efx); 7637153f623SBen Hutchings unregister_netdevice(net_dev); 764874aeea5SJeff Kirsher fail_locked: 7657153f623SBen Hutchings efx->state = STATE_UNINIT; 766874aeea5SJeff Kirsher rtnl_unlock(); 767874aeea5SJeff Kirsher netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); 768874aeea5SJeff Kirsher return rc; 769874aeea5SJeff Kirsher } 770874aeea5SJeff Kirsher 771874aeea5SJeff Kirsher static void efx_unregister_netdev(struct efx_nic *efx) 772874aeea5SJeff Kirsher { 773874aeea5SJeff Kirsher if (!efx->net_dev) 774874aeea5SJeff Kirsher return; 775874aeea5SJeff Kirsher 7768cb03f4eSJonathan Cooper if (WARN_ON(efx_netdev_priv(efx->net_dev) != efx)) 777b3fd0a86SJonathan Cooper return; 778874aeea5SJeff Kirsher 779e7fef9b4SEdward Cree if (efx_dev_registered(efx)) { 780f029c781SWolfram Sang strscpy(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 */ 845813cf9d1SJonathan 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 { 8637e773594SJonathan Cooper struct efx_probe_data *probe_data; 864874aeea5SJeff Kirsher struct efx_nic *efx; 865874aeea5SJeff Kirsher 866874aeea5SJeff Kirsher efx = pci_get_drvdata(pci_dev); 867874aeea5SJeff Kirsher if (!efx) 868874aeea5SJeff Kirsher return; 869874aeea5SJeff Kirsher 870874aeea5SJeff Kirsher /* Mark the NIC as fini, then stop the interface */ 871874aeea5SJeff Kirsher rtnl_lock(); 8720bcf4a64SBen Hutchings efx_dissociate(efx); 873874aeea5SJeff Kirsher dev_close(efx->net_dev); 874d8291187SBen Hutchings efx_disable_interrupts(efx); 875ea6bb99eSEdward Cree efx->state = STATE_UNINIT; 876874aeea5SJeff Kirsher rtnl_unlock(); 877874aeea5SJeff Kirsher 8787fa8d547SShradha Shah if (efx->type->sriov_fini) 879d98a4ffeSShradha Shah efx->type->sriov_fini(efx); 8807fa8d547SShradha Shah 881*998b85f0SMartin Habets efx_fini_devlink_lock(efx); 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); 88998ff4c7cSJonathan Cooper pci_dbg(efx->pci_dev, "shutdown successful\n"); 890874aeea5SJeff Kirsher 891*998b85f0SMartin Habets efx_fini_devlink_and_unlock(efx); 892874aeea5SJeff Kirsher efx_fini_struct(efx); 893874aeea5SJeff Kirsher free_netdev(efx->net_dev); 8947e773594SJonathan Cooper probe_data = container_of(efx, struct efx_probe_data, efx); 8957e773594SJonathan Cooper kfree(probe_data); 896874aeea5SJeff Kirsher }; 897874aeea5SJeff Kirsher 898460eeaa0SBen Hutchings /* NIC VPD information 899460eeaa0SBen Hutchings * Called during probe to display the part number of the 9005119e20fSHeiner Kallweit * installed NIC. 901460eeaa0SBen Hutchings */ 902ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx) 903460eeaa0SBen Hutchings { 904460eeaa0SBen Hutchings struct pci_dev *dev = efx->pci_dev; 90537838aa4SHeiner Kallweit unsigned int vpd_size, kw_len; 9065119e20fSHeiner Kallweit u8 *vpd_data; 90737838aa4SHeiner Kallweit int start; 908460eeaa0SBen Hutchings 9095119e20fSHeiner Kallweit vpd_data = pci_vpd_alloc(dev, &vpd_size); 9105119e20fSHeiner Kallweit if (IS_ERR(vpd_data)) { 9115119e20fSHeiner Kallweit pci_warn(dev, "Unable to read VPD\n"); 912460eeaa0SBen Hutchings return; 913460eeaa0SBen Hutchings } 914460eeaa0SBen Hutchings 91537838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 91637838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); 91737838aa4SHeiner Kallweit if (start < 0) 91837838aa4SHeiner Kallweit pci_err(dev, "Part number not found or incomplete\n"); 91937838aa4SHeiner Kallweit else 92037838aa4SHeiner Kallweit pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start); 921460eeaa0SBen Hutchings 92237838aa4SHeiner Kallweit start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, 92337838aa4SHeiner Kallweit PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len); 92437838aa4SHeiner Kallweit if (start < 0) 92537838aa4SHeiner Kallweit pci_err(dev, "Serial number not found or incomplete\n"); 92637838aa4SHeiner Kallweit else 92737838aa4SHeiner Kallweit efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL); 928460eeaa0SBen Hutchings 9295119e20fSHeiner Kallweit kfree(vpd_data); 930460eeaa0SBen Hutchings } 931460eeaa0SBen Hutchings 932460eeaa0SBen Hutchings 933874aeea5SJeff Kirsher /* Main body of NIC initialisation 934874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, theoretically). 935874aeea5SJeff Kirsher */ 936874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx) 937874aeea5SJeff Kirsher { 938874aeea5SJeff Kirsher int rc; 939874aeea5SJeff Kirsher 940874aeea5SJeff Kirsher /* Do start-of-day initialisation */ 941874aeea5SJeff Kirsher rc = efx_probe_all(efx); 942874aeea5SJeff Kirsher if (rc) 943874aeea5SJeff Kirsher goto fail1; 944874aeea5SJeff Kirsher 945874aeea5SJeff Kirsher efx_init_napi(efx); 946874aeea5SJeff Kirsher 947193f2003SBert Kenward down_write(&efx->filter_sem); 948874aeea5SJeff Kirsher rc = efx->type->init(efx); 949193f2003SBert Kenward up_write(&efx->filter_sem); 950874aeea5SJeff Kirsher if (rc) { 951fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "failed to initialise NIC\n"); 952874aeea5SJeff Kirsher goto fail3; 953874aeea5SJeff Kirsher } 954874aeea5SJeff Kirsher 955874aeea5SJeff Kirsher rc = efx_init_port(efx); 956874aeea5SJeff Kirsher if (rc) { 957874aeea5SJeff Kirsher netif_err(efx, probe, efx->net_dev, 958874aeea5SJeff Kirsher "failed to initialise port\n"); 959874aeea5SJeff Kirsher goto fail4; 960874aeea5SJeff Kirsher } 961874aeea5SJeff Kirsher 962874aeea5SJeff Kirsher rc = efx_nic_init_interrupt(efx); 963874aeea5SJeff Kirsher if (rc) 964874aeea5SJeff Kirsher goto fail5; 965a83762d9SBert Kenward 966a83762d9SBert Kenward efx_set_interrupt_affinity(efx); 967261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 968261e4d96SJon Cooper if (rc) 969261e4d96SJon Cooper goto fail6; 970874aeea5SJeff Kirsher 971874aeea5SJeff Kirsher return 0; 972874aeea5SJeff Kirsher 973261e4d96SJon Cooper fail6: 974a83762d9SBert Kenward efx_clear_interrupt_affinity(efx); 975261e4d96SJon Cooper efx_nic_fini_interrupt(efx); 976874aeea5SJeff Kirsher fail5: 977874aeea5SJeff Kirsher efx_fini_port(efx); 978874aeea5SJeff Kirsher fail4: 979874aeea5SJeff Kirsher efx->type->fini(efx); 980874aeea5SJeff Kirsher fail3: 981874aeea5SJeff Kirsher efx_fini_napi(efx); 982874aeea5SJeff Kirsher efx_remove_all(efx); 983874aeea5SJeff Kirsher fail1: 984874aeea5SJeff Kirsher return rc; 985874aeea5SJeff Kirsher } 986874aeea5SJeff Kirsher 9878a531400SJon Cooper static int efx_pci_probe_post_io(struct efx_nic *efx) 9888a531400SJon Cooper { 9898a531400SJon Cooper struct net_device *net_dev = efx->net_dev; 9908a531400SJon Cooper int rc = efx_pci_probe_main(efx); 9918a531400SJon Cooper 9928a531400SJon Cooper if (rc) 9938a531400SJon Cooper return rc; 9948a531400SJon Cooper 9958a531400SJon Cooper if (efx->type->sriov_init) { 9968a531400SJon Cooper rc = efx->type->sriov_init(efx); 9978a531400SJon Cooper if (rc) 998fa44821aSHeiner Kallweit pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n", 999fa44821aSHeiner Kallweit rc); 10008a531400SJon Cooper } 10018a531400SJon Cooper 10028a531400SJon Cooper /* Determine netdevice features */ 1003ca4a80e4SÍñigo Huguet net_dev->features |= efx->type->offload_features; 1004ca4a80e4SÍñigo Huguet 1005ca4a80e4SÍñigo Huguet /* Add TSO features */ 1006ca4a80e4SÍñigo Huguet if (efx->type->tso_versions && efx->type->tso_versions(efx)) 1007ca4a80e4SÍñigo Huguet net_dev->features |= NETIF_F_TSO | NETIF_F_TSO6; 1008ca4a80e4SÍñigo Huguet 10098a531400SJon Cooper /* Mask for features that also apply to VLAN devices */ 10108a531400SJon Cooper net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 10118a531400SJon Cooper NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 10128a531400SJon Cooper NETIF_F_RXCSUM); 10138a531400SJon Cooper 1014ca4a80e4SÍñigo Huguet /* Determine user configurable features */ 10156978729fSEdward Cree net_dev->hw_features |= net_dev->features & ~efx->fixed_features; 10166978729fSEdward Cree 10176978729fSEdward Cree /* Disable receiving frames with bad FCS, by default. */ 10186978729fSEdward Cree net_dev->features &= ~NETIF_F_RXALL; 10198a531400SJon Cooper 10208a531400SJon Cooper /* Disable VLAN filtering by default. It may be enforced if 10218a531400SJon Cooper * the feature is fixed (i.e. VLAN filters are required to 10228a531400SJon Cooper * receive VLAN tagged packets due to vPort restrictions). 10238a531400SJon Cooper */ 10248a531400SJon Cooper net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 10258a531400SJon Cooper net_dev->features |= efx->fixed_features; 10268a531400SJon Cooper 10279b0651e4SLorenzo Bianconi net_dev->xdp_features = NETDEV_XDP_ACT_BASIC | 10289b0651e4SLorenzo Bianconi NETDEV_XDP_ACT_REDIRECT | 10299b0651e4SLorenzo Bianconi NETDEV_XDP_ACT_NDO_XMIT; 10309b0651e4SLorenzo Bianconi 1031*998b85f0SMartin Habets /* devlink creation, registration and lock */ 1032*998b85f0SMartin Habets rc = efx_probe_devlink_and_lock(efx); 1033*998b85f0SMartin Habets if (rc) 1034*998b85f0SMartin Habets pci_err(efx->pci_dev, "devlink registration failed"); 1035*998b85f0SMartin Habets 10368a531400SJon Cooper rc = efx_register_netdev(efx); 1037*998b85f0SMartin Habets efx_probe_devlink_unlock(efx); 10388a531400SJon Cooper if (!rc) 10398a531400SJon Cooper return 0; 10408a531400SJon Cooper 10418a531400SJon Cooper efx_pci_remove_main(efx); 10428a531400SJon Cooper return rc; 10438a531400SJon Cooper } 10448a531400SJon Cooper 1045874aeea5SJeff Kirsher /* NIC initialisation 1046874aeea5SJeff Kirsher * 1047874aeea5SJeff Kirsher * This is called at module load (or hotplug insertion, 104873ba7b68SBen Hutchings * theoretically). It sets up PCI mappings, resets the NIC, 1049874aeea5SJeff Kirsher * sets up and registers the network devices with the kernel and hooks 1050874aeea5SJeff Kirsher * the interrupt service routine. It does not prepare the device for 1051874aeea5SJeff Kirsher * transmission; this is left to the first time one of the network 1052874aeea5SJeff Kirsher * interfaces is brought up (i.e. efx_net_open). 1053874aeea5SJeff Kirsher */ 105487d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev, 1055874aeea5SJeff Kirsher const struct pci_device_id *entry) 1056874aeea5SJeff Kirsher { 10577e773594SJonathan Cooper struct efx_probe_data *probe_data, **probe_ptr; 1058874aeea5SJeff Kirsher struct net_device *net_dev; 1059874aeea5SJeff Kirsher struct efx_nic *efx; 1060fadac6aaSBen Hutchings int rc; 1061874aeea5SJeff Kirsher 10627e773594SJonathan Cooper /* Allocate probe data and struct efx_nic */ 10637e773594SJonathan Cooper probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL); 10647e773594SJonathan Cooper if (!probe_data) 10657e773594SJonathan Cooper return -ENOMEM; 10667e773594SJonathan Cooper probe_data->pci_dev = pci_dev; 10677e773594SJonathan Cooper efx = &probe_data->efx; 10687e773594SJonathan Cooper 10697e773594SJonathan Cooper /* Allocate and initialise a struct net_device */ 10707e773594SJonathan Cooper net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES); 10716c412da5SChristophe JAILLET if (!net_dev) { 10726c412da5SChristophe JAILLET rc = -ENOMEM; 10736c412da5SChristophe JAILLET goto fail0; 10746c412da5SChristophe JAILLET } 10757e773594SJonathan Cooper probe_ptr = netdev_priv(net_dev); 10767e773594SJonathan Cooper *probe_ptr = probe_data; 10777e773594SJonathan Cooper efx->net_dev = net_dev; 1078adeb15aaSBen Hutchings efx->type = (const struct efx_nic_type *) entry->driver_data; 1079ebfcd0fdSAndrew Rybchenko efx->fixed_features |= NETIF_F_HIGHDMA; 1080eb7cfd8cSAndrew Rybchenko 1081874aeea5SJeff Kirsher pci_set_drvdata(pci_dev, efx); 1082874aeea5SJeff Kirsher SET_NETDEV_DEV(net_dev, &pci_dev->dev); 108362ac3ce5SJonathan Cooper rc = efx_init_struct(efx, pci_dev); 1084874aeea5SJeff Kirsher if (rc) 1085874aeea5SJeff Kirsher goto fail1; 108662ac3ce5SJonathan Cooper efx->mdio.dev = net_dev; 1087874aeea5SJeff Kirsher 1088fa44821aSHeiner Kallweit pci_info(pci_dev, "Solarflare NIC detected\n"); 1089874aeea5SJeff Kirsher 10906f7f8aa6SShradha Shah if (!efx->type->is_vf) 1091ef215e64SBen Hutchings efx_probe_vpd_strings(efx); 1092460eeaa0SBen Hutchings 1093874aeea5SJeff Kirsher /* Set up basic I/O (BAR mappings etc) */ 1094b1940451SAlex Maftei (amaftei) rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask, 1095b1940451SAlex Maftei (amaftei) efx->type->mem_map_size(efx)); 1096874aeea5SJeff Kirsher if (rc) 1097874aeea5SJeff Kirsher goto fail2; 1098874aeea5SJeff Kirsher 10998a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 11008a531400SJon Cooper if (rc) { 11018a531400SJon Cooper /* On failure, retry once immediately. 11028a531400SJon Cooper * If we aborted probe due to a scheduled reset, dismiss it. 11038a531400SJon Cooper */ 11048a531400SJon Cooper efx->reset_pending = 0; 11058a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 11068a531400SJon Cooper if (rc) { 11078a531400SJon Cooper /* On another failure, retry once more 11088a531400SJon Cooper * after a 50-305ms delay. 11098a531400SJon Cooper */ 11108a531400SJon Cooper unsigned char r; 11118a531400SJon Cooper 11128a531400SJon Cooper get_random_bytes(&r, 1); 11138a531400SJon Cooper msleep((unsigned int)r + 50); 11148a531400SJon Cooper efx->reset_pending = 0; 11158a531400SJon Cooper rc = efx_pci_probe_post_io(efx); 11168a531400SJon Cooper } 11178a531400SJon Cooper } 1118fadac6aaSBen Hutchings if (rc) 1119874aeea5SJeff Kirsher goto fail3; 1120874aeea5SJeff Kirsher 1121874aeea5SJeff Kirsher netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); 1122874aeea5SJeff Kirsher 11237c43161cSBen Hutchings /* Try to create MTDs, but allow this to fail */ 1124874aeea5SJeff Kirsher rtnl_lock(); 11257c43161cSBen Hutchings rc = efx_mtd_probe(efx); 1126874aeea5SJeff Kirsher rtnl_unlock(); 112709a04204SBert Kenward if (rc && rc != -EPERM) 11287c43161cSBen Hutchings netif_warn(efx, probe, efx->net_dev, 11297c43161cSBen Hutchings "failed to create MTDs (%d)\n", rc); 11307c43161cSBen Hutchings 1131e5fbd977SJon Cooper if (efx->type->udp_tnl_push_ports) 1132e5fbd977SJon Cooper efx->type->udp_tnl_push_ports(efx); 1133e5fbd977SJon Cooper 1134874aeea5SJeff Kirsher return 0; 1135874aeea5SJeff Kirsher 1136874aeea5SJeff Kirsher fail3: 113766a65128SEdward Cree efx_fini_io(efx); 1138874aeea5SJeff Kirsher fail2: 1139874aeea5SJeff Kirsher efx_fini_struct(efx); 1140874aeea5SJeff Kirsher fail1: 1141874aeea5SJeff Kirsher WARN_ON(rc > 0); 1142874aeea5SJeff Kirsher netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); 1143874aeea5SJeff Kirsher free_netdev(net_dev); 11446c412da5SChristophe JAILLET fail0: 11456c412da5SChristophe JAILLET kfree(probe_data); 1146874aeea5SJeff Kirsher return rc; 1147874aeea5SJeff Kirsher } 1148874aeea5SJeff Kirsher 1149834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions 1150834e23ddSShradha Shah * enabled on success 1151834e23ddSShradha Shah */ 1152834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1153834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) 1154834e23ddSShradha Shah { 1155834e23ddSShradha Shah int rc; 1156834e23ddSShradha Shah struct efx_nic *efx = pci_get_drvdata(dev); 1157834e23ddSShradha Shah 1158834e23ddSShradha Shah if (efx->type->sriov_configure) { 1159834e23ddSShradha Shah rc = efx->type->sriov_configure(efx, num_vfs); 1160834e23ddSShradha Shah if (rc) 1161834e23ddSShradha Shah return rc; 1162834e23ddSShradha Shah else 1163834e23ddSShradha Shah return num_vfs; 1164834e23ddSShradha Shah } else 1165834e23ddSShradha Shah return -EOPNOTSUPP; 1166834e23ddSShradha Shah } 1167834e23ddSShradha Shah #endif 1168834e23ddSShradha Shah 1169874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev) 1170874aeea5SJeff Kirsher { 11713e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1172874aeea5SJeff Kirsher 117361da026dSBen Hutchings rtnl_lock(); 117461da026dSBen Hutchings 1175813cf9d1SJonathan Cooper if (efx_net_active(efx->state)) { 1176c2f3b8e3SDaniel Pieczko efx_device_detach_sync(efx); 1177874aeea5SJeff Kirsher 1178874aeea5SJeff Kirsher efx_stop_all(efx); 1179d8291187SBen Hutchings efx_disable_interrupts(efx); 1180813cf9d1SJonathan Cooper 1181813cf9d1SJonathan Cooper efx->state = efx_freeze(efx->state); 11826032fb56SBen Hutchings } 1183874aeea5SJeff Kirsher 118461da026dSBen Hutchings rtnl_unlock(); 118561da026dSBen Hutchings 1186874aeea5SJeff Kirsher return 0; 1187874aeea5SJeff Kirsher } 1188874aeea5SJeff Kirsher 118941e3b072SPieter Jansen van Vuuren static void efx_pci_shutdown(struct pci_dev *pci_dev) 119041e3b072SPieter Jansen van Vuuren { 119141e3b072SPieter Jansen van Vuuren struct efx_nic *efx = pci_get_drvdata(pci_dev); 119241e3b072SPieter Jansen van Vuuren 119341e3b072SPieter Jansen van Vuuren if (!efx) 119441e3b072SPieter Jansen van Vuuren return; 119541e3b072SPieter Jansen van Vuuren 119641e3b072SPieter Jansen van Vuuren efx_pm_freeze(&pci_dev->dev); 119741e3b072SPieter Jansen van Vuuren pci_disable_device(pci_dev); 119841e3b072SPieter Jansen van Vuuren } 119941e3b072SPieter Jansen van Vuuren 1200874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev) 1201874aeea5SJeff Kirsher { 1202261e4d96SJon Cooper int rc; 12033e03a8baSChuhong Yuan struct efx_nic *efx = dev_get_drvdata(dev); 1204874aeea5SJeff Kirsher 120561da026dSBen Hutchings rtnl_lock(); 120661da026dSBen Hutchings 1207813cf9d1SJonathan Cooper if (efx_frozen(efx->state)) { 1208261e4d96SJon Cooper rc = efx_enable_interrupts(efx); 1209261e4d96SJon Cooper if (rc) 1210261e4d96SJon Cooper goto fail; 1211874aeea5SJeff Kirsher 1212874aeea5SJeff Kirsher mutex_lock(&efx->mac_lock); 1213c77289b4SEdward Cree efx_mcdi_port_reconfigure(efx); 1214874aeea5SJeff Kirsher mutex_unlock(&efx->mac_lock); 1215874aeea5SJeff Kirsher 1216874aeea5SJeff Kirsher efx_start_all(efx); 1217874aeea5SJeff Kirsher 12189c568fd8SPeter Dunning efx_device_attach_if_not_resetting(efx); 1219874aeea5SJeff Kirsher 1220813cf9d1SJonathan Cooper efx->state = efx_thaw(efx->state); 1221874aeea5SJeff Kirsher 1222874aeea5SJeff Kirsher efx->type->resume_wol(efx); 12236032fb56SBen Hutchings } 1224874aeea5SJeff Kirsher 122561da026dSBen Hutchings rtnl_unlock(); 122661da026dSBen Hutchings 1227874aeea5SJeff Kirsher /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ 122882c64484SAlex Maftei (amaftei) efx_queue_reset_work(efx); 1229874aeea5SJeff Kirsher 1230874aeea5SJeff Kirsher return 0; 1231261e4d96SJon Cooper 1232261e4d96SJon Cooper fail: 1233261e4d96SJon Cooper rtnl_unlock(); 1234261e4d96SJon Cooper 1235261e4d96SJon Cooper return rc; 1236874aeea5SJeff Kirsher } 1237874aeea5SJeff Kirsher 1238874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev) 1239874aeea5SJeff Kirsher { 1240874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 1241874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 1242874aeea5SJeff Kirsher 1243874aeea5SJeff Kirsher efx->type->fini(efx); 1244874aeea5SJeff Kirsher 1245874aeea5SJeff Kirsher efx->reset_pending = 0; 1246874aeea5SJeff Kirsher 1247874aeea5SJeff Kirsher pci_save_state(pci_dev); 1248874aeea5SJeff Kirsher return pci_set_power_state(pci_dev, PCI_D3hot); 1249874aeea5SJeff Kirsher } 1250874aeea5SJeff Kirsher 1251874aeea5SJeff Kirsher /* Used for both resume and restore */ 1252874aeea5SJeff Kirsher static int efx_pm_resume(struct device *dev) 1253874aeea5SJeff Kirsher { 1254874aeea5SJeff Kirsher struct pci_dev *pci_dev = to_pci_dev(dev); 1255874aeea5SJeff Kirsher struct efx_nic *efx = pci_get_drvdata(pci_dev); 1256874aeea5SJeff Kirsher int rc; 1257874aeea5SJeff Kirsher 1258874aeea5SJeff Kirsher rc = pci_set_power_state(pci_dev, PCI_D0); 1259874aeea5SJeff Kirsher if (rc) 1260874aeea5SJeff Kirsher return rc; 1261874aeea5SJeff Kirsher pci_restore_state(pci_dev); 1262874aeea5SJeff Kirsher rc = pci_enable_device(pci_dev); 1263874aeea5SJeff Kirsher if (rc) 1264874aeea5SJeff Kirsher return rc; 1265874aeea5SJeff Kirsher pci_set_master(efx->pci_dev); 1266874aeea5SJeff Kirsher rc = efx->type->reset(efx, RESET_TYPE_ALL); 1267874aeea5SJeff Kirsher if (rc) 1268874aeea5SJeff Kirsher return rc; 1269193f2003SBert Kenward down_write(&efx->filter_sem); 1270874aeea5SJeff Kirsher rc = efx->type->init(efx); 1271193f2003SBert Kenward up_write(&efx->filter_sem); 1272874aeea5SJeff Kirsher if (rc) 1273874aeea5SJeff Kirsher return rc; 1274261e4d96SJon Cooper rc = efx_pm_thaw(dev); 1275261e4d96SJon Cooper return rc; 1276874aeea5SJeff Kirsher } 1277874aeea5SJeff Kirsher 1278874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev) 1279874aeea5SJeff Kirsher { 1280874aeea5SJeff Kirsher int rc; 1281874aeea5SJeff Kirsher 1282874aeea5SJeff Kirsher efx_pm_freeze(dev); 1283874aeea5SJeff Kirsher rc = efx_pm_poweroff(dev); 1284874aeea5SJeff Kirsher if (rc) 1285874aeea5SJeff Kirsher efx_pm_resume(dev); 1286874aeea5SJeff Kirsher return rc; 1287874aeea5SJeff Kirsher } 1288874aeea5SJeff Kirsher 128918e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = { 1290874aeea5SJeff Kirsher .suspend = efx_pm_suspend, 1291874aeea5SJeff Kirsher .resume = efx_pm_resume, 1292874aeea5SJeff Kirsher .freeze = efx_pm_freeze, 1293874aeea5SJeff Kirsher .thaw = efx_pm_thaw, 1294874aeea5SJeff Kirsher .poweroff = efx_pm_poweroff, 1295874aeea5SJeff Kirsher .restore = efx_pm_resume, 1296874aeea5SJeff Kirsher }; 1297874aeea5SJeff Kirsher 1298874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = { 1299874aeea5SJeff Kirsher .name = KBUILD_MODNAME, 1300874aeea5SJeff Kirsher .id_table = efx_pci_table, 1301874aeea5SJeff Kirsher .probe = efx_pci_probe, 1302874aeea5SJeff Kirsher .remove = efx_pci_remove, 1303874aeea5SJeff Kirsher .driver.pm = &efx_pm_ops, 130441e3b072SPieter Jansen van Vuuren .shutdown = efx_pci_shutdown, 1305626950dbSAlexandre Rames .err_handler = &efx_err_handlers, 1306834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV 1307834e23ddSShradha Shah .sriov_configure = efx_pci_sriov_configure, 1308834e23ddSShradha Shah #endif 1309874aeea5SJeff Kirsher }; 1310874aeea5SJeff Kirsher 1311874aeea5SJeff Kirsher /************************************************************************** 1312874aeea5SJeff Kirsher * 1313874aeea5SJeff Kirsher * Kernel module interface 1314874aeea5SJeff Kirsher * 1315874aeea5SJeff Kirsher *************************************************************************/ 1316874aeea5SJeff Kirsher 1317874aeea5SJeff Kirsher static int __init efx_init_module(void) 1318874aeea5SJeff Kirsher { 1319874aeea5SJeff Kirsher int rc; 1320874aeea5SJeff Kirsher 132160bd2a2dSEdward Cree printk(KERN_INFO "Solarflare NET driver\n"); 1322874aeea5SJeff Kirsher 1323874aeea5SJeff Kirsher rc = register_netdevice_notifier(&efx_netdev_notifier); 1324874aeea5SJeff Kirsher if (rc) 1325874aeea5SJeff Kirsher goto err_notifier; 1326874aeea5SJeff Kirsher 132782c64484SAlex Maftei (amaftei) rc = efx_create_reset_workqueue(); 132882c64484SAlex Maftei (amaftei) if (rc) 1329874aeea5SJeff Kirsher goto err_reset; 1330874aeea5SJeff Kirsher 1331874aeea5SJeff Kirsher rc = pci_register_driver(&efx_pci_driver); 1332874aeea5SJeff Kirsher if (rc < 0) 1333874aeea5SJeff Kirsher goto err_pci; 1334874aeea5SJeff Kirsher 133551b35a45SEdward Cree rc = pci_register_driver(&ef100_pci_driver); 133651b35a45SEdward Cree if (rc < 0) 133751b35a45SEdward Cree goto err_pci_ef100; 133851b35a45SEdward Cree 1339874aeea5SJeff Kirsher return 0; 1340874aeea5SJeff Kirsher 134151b35a45SEdward Cree err_pci_ef100: 134251b35a45SEdward Cree pci_unregister_driver(&efx_pci_driver); 1343874aeea5SJeff Kirsher err_pci: 134482c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1345874aeea5SJeff Kirsher err_reset: 1346874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1347874aeea5SJeff Kirsher err_notifier: 1348874aeea5SJeff Kirsher return rc; 1349874aeea5SJeff Kirsher } 1350874aeea5SJeff Kirsher 1351874aeea5SJeff Kirsher static void __exit efx_exit_module(void) 1352874aeea5SJeff Kirsher { 1353874aeea5SJeff Kirsher printk(KERN_INFO "Solarflare NET driver unloading\n"); 1354874aeea5SJeff Kirsher 135551b35a45SEdward Cree pci_unregister_driver(&ef100_pci_driver); 1356874aeea5SJeff Kirsher pci_unregister_driver(&efx_pci_driver); 135782c64484SAlex Maftei (amaftei) efx_destroy_reset_workqueue(); 1358874aeea5SJeff Kirsher unregister_netdevice_notifier(&efx_netdev_notifier); 1359874aeea5SJeff Kirsher 1360874aeea5SJeff Kirsher } 1361874aeea5SJeff Kirsher 1362874aeea5SJeff Kirsher module_init(efx_init_module); 1363874aeea5SJeff Kirsher module_exit(efx_exit_module); 1364874aeea5SJeff Kirsher 1365874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and " 1366874aeea5SJeff Kirsher "Michael Brown <mbrown@fensystems.co.uk>"); 13676a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver"); 1368874aeea5SJeff Kirsher MODULE_LICENSE("GPL"); 1369874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table); 1370