Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Driver for Solarflare network controllers and boards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright 2005-2006 Fen Systems Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright 2005-2013 Solarflare Communications Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/aer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include "net_driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <net/gre.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <net/udp_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include "efx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include "efx_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include "efx_channels.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include "ef100.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "rx_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include "tx_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include "nic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include "selftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include "sriov.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include "mcdi_port_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include "mcdi_pcol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include "workarounds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * Configurable values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) module_param_named(interrupt_mode, efx_interrupt_mode, uint, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) MODULE_PARM_DESC(interrupt_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 		 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) module_param(rss_cpus, uint, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  * Use separate channels for TX and RX events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  * Set this to 1 to use separate channels for TX and RX. It allows us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * to control interrupt affinity separately for TX and RX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * This is only used in MSI-X interrupt mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) bool efx_separate_tx_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) module_param(efx_separate_tx_channels, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) MODULE_PARM_DESC(efx_separate_tx_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		 "Use separate channels for TX and RX");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /* Initial interrupt moderation settings.  They can be modified after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * module load with ethtool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * The default for RX should strike a balance between increasing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * round-trip latency and reducing overhead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static unsigned int rx_irq_mod_usec = 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /* Initial interrupt moderation settings.  They can be modified after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * module load with ethtool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * This default is chosen to ensure that a 10G link does not go idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * while a TX queue is stopped after it has become full.  A queue is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * restarted when it drops below half full.  The time this takes (assuming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * worst case 3 descriptors per packet and 1024 descriptors) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  *   512 / 3 * 1.2 = 205 usec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static unsigned int tx_irq_mod_usec = 150;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static bool phy_flash_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) module_param(phy_flash_cfg, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) module_param(debug, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * Utility functions and prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static void efx_remove_port(struct efx_nic *efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 			u32 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define EFX_ASSERT_RESET_SERIALISED(efx)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		if ((efx->state == STATE_READY) ||	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		    (efx->state == STATE_RECOVERY) ||	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		    (efx->state == STATE_DISABLED))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			ASSERT_RTNL();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  * Port handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static void efx_fini_port(struct efx_nic *efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static int efx_probe_port(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	netif_dbg(efx, probe, efx->net_dev, "create port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	if (phy_flash_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		efx->phy_mode = PHY_MODE_SPECIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	/* Connect up MAC/PHY operations table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	rc = efx->type->probe_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	/* Initialise MAC address to permanent address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static int efx_init_port(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	netif_dbg(efx, drv, efx->net_dev, "init port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	efx->port_initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/* Ensure the PHY advertises the correct flow control settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	rc = efx_mcdi_port_reconfigure(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	if (rc && rc != -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) static void efx_fini_port(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	if (!efx->port_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	efx->port_initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	efx->link_state.up = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	efx_link_status_changed(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static void efx_remove_port(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	efx->type->remove_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  * NIC handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static LIST_HEAD(efx_primary_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) static LIST_HEAD(efx_unassociated_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	return left->type == right->type &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		left->vpd_sn && right->vpd_sn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		!strcmp(left->vpd_sn, right->vpd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static void efx_associate(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	struct efx_nic *other, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (efx->primary == efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		/* Adding primary function; look for secondaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		list_add_tail(&efx->node, &efx_primary_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		list_for_each_entry_safe(other, next, &efx_unassociated_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 					 node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			if (efx_same_controller(efx, other)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 				list_del(&other->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 				netif_dbg(other, probe, other->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 					  "moving to secondary list of %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 					  pci_name(efx->pci_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 					  efx->net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 				list_add_tail(&other->node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 					      &efx->secondary_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 				other->primary = efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		/* Adding secondary function; look for primary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		list_for_each_entry(other, &efx_primary_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			if (efx_same_controller(efx, other)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 				netif_dbg(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 					  "adding to secondary list of %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 					  pci_name(other->pci_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 					  other->net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 				list_add_tail(&efx->node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 					      &other->secondary_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 				efx->primary = other;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		netif_dbg(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			  "adding to unassociated list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		list_add_tail(&efx->node, &efx_unassociated_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static void efx_dissociate(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	struct efx_nic *other, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	list_del(&efx->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	efx->primary = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		list_del(&other->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		netif_dbg(other, probe, other->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			  "moving to unassociated list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		list_add_tail(&other->node, &efx_unassociated_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		other->primary = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) static int efx_probe_nic(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	/* Carry out hardware-type specific initialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	rc = efx->type->probe(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		if (!efx->max_channels || !efx->max_tx_channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 				  "Insufficient resources to allocate"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 				  " any channels\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 			rc = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		/* Determine the number of channels and queues by trying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		 * to hook in MSI-X interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		rc = efx_probe_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 			goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		rc = efx_set_channels(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		/* dimension_resources can fail with EAGAIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		rc = efx->type->dimension_resources(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		if (rc != 0 && rc != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		if (rc == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			/* try again with new max_channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			efx_remove_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	} while (rc == -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (efx->n_channels > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		netdev_rss_key_fill(efx->rss_context.rx_hash_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 				    sizeof(efx->rss_context.rx_hash_key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	efx_set_default_rx_indir_table(efx, &efx->rss_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	/* Initialise the interrupt moderation settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 				true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	efx_remove_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	efx->type->remove(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static void efx_remove_nic(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	efx_remove_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	efx->type->remove(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335)  * NIC startup/shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) static int efx_probe_all(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	rc = efx_probe_nic(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	rc = efx_probe_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		netif_err(efx, probe, efx->net_dev, "failed to create port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	rc = efx->type->vswitching_probe(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	if (rc) /* not fatal; the PF will still work fine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		netif_warn(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			   "failed to setup vswitching rc=%d;"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			   " VFs may not function\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	rc = efx_probe_filters(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		netif_err(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			  "failed to create filter tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	rc = efx_probe_channels(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		goto fail5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)  fail5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	efx_remove_filters(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  fail4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	efx->type->vswitching_remove(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	efx_remove_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)  fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	efx_remove_nic(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) static void efx_remove_all(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	efx_xdp_setup_prog(efx, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	efx_remove_channels(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	efx_remove_filters(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	efx->type->vswitching_remove(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	efx_remove_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	efx_remove_nic(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * Interrupt moderation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	if (usecs == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (usecs * 1000 < efx->timer_quantum_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		return 1; /* never round down to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	return usecs * 1000 / efx->timer_quantum_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	/* We must round up when converting ticks to microseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	 * because we round down when converting the other way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) /* Set interrupt moderation parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			    unsigned int rx_usecs, bool rx_adaptive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 			    bool rx_may_override_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	unsigned int timer_max_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	EFX_ASSERT_RESET_SERIALISED(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	timer_max_us = efx->timer_max_ns / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	    !rx_may_override_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		netif_err(efx, drv, efx->net_dev, "Channels are shared. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			  "RX and TX IRQ moderation must be equal\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	efx->irq_rx_adaptive = rx_adaptive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	efx->irq_rx_moderation_us = rx_usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		if (efx_channel_has_rx_queue(channel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			channel->irq_moderation_us = rx_usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		else if (efx_channel_has_tx_queues(channel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			channel->irq_moderation_us = tx_usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		else if (efx_channel_is_xdp_tx(channel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			channel->irq_moderation_us = tx_usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 			    unsigned int *rx_usecs, bool *rx_adaptive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	*rx_adaptive = efx->irq_rx_adaptive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	*rx_usecs = efx->irq_rx_moderation_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	/* If channels are shared between RX and TX, so is IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	 * moderation.  Otherwise, IRQ moderation is the same for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	 * TX channels and is not adaptive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (efx->tx_channel_offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		*tx_usecs = *rx_usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		struct efx_channel *tx_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		tx_channel = efx->channel[efx->tx_channel_offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		*tx_usecs = tx_channel->irq_moderation_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491)  * ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) /* Net device ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  * Context: process, rtnl_lock() held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	struct efx_nic *efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	struct mii_ioctl_data *data = if_mii(ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	if (cmd == SIOCSHWTSTAMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		return efx_ptp_set_ts_config(efx, ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	if (cmd == SIOCGHWTSTAMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		return efx_ptp_get_ts_config(efx, ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	/* Convert phy_id from older PRTAD/DEVAD format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	    (data->phy_id & 0xfc00) == 0x0400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	return mdio_mii_ioctl(&efx->mdio, data, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518)  * Kernel net device interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) /* Context: process, rtnl_lock() held. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) int efx_net_open(struct net_device *net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	struct efx_nic *efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		  raw_smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	rc = efx_check_disabled(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	if (efx->phy_mode & PHY_MODE_SPECIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	/* Notify the kernel of the link state polled during driver load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	 * before the monitor starts running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	efx_link_status_changed(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	efx_start_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	if (efx->state == STATE_DISABLED || efx->reset_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		netif_device_detach(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	efx_selftest_async_start(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) /* Context: process, rtnl_lock() held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  * Note that the kernel will ignore our return code; this method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  * should really be a void.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) int efx_net_stop(struct net_device *net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	struct efx_nic *efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		  raw_smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	/* Stop the device and flush all the channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	efx_stop_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	struct efx_nic *efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	if (efx->type->vlan_rx_add_vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		return efx->type->vlan_rx_add_vid(efx, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct efx_nic *efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	if (efx->type->vlan_rx_kill_vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return efx->type->vlan_rx_kill_vid(efx, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) static const struct net_device_ops efx_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	.ndo_open		= efx_net_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	.ndo_stop		= efx_net_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	.ndo_get_stats64	= efx_net_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	.ndo_tx_timeout		= efx_watchdog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	.ndo_start_xmit		= efx_hard_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	.ndo_validate_addr	= eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	.ndo_do_ioctl		= efx_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	.ndo_change_mtu		= efx_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	.ndo_set_mac_address	= efx_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	.ndo_set_rx_mode	= efx_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	.ndo_set_features	= efx_set_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	.ndo_features_check	= efx_features_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	.ndo_vlan_rx_add_vid	= efx_vlan_rx_add_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	.ndo_vlan_rx_kill_vid	= efx_vlan_rx_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	.ndo_set_vf_mac		= efx_sriov_set_vf_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	.ndo_set_vf_vlan	= efx_sriov_set_vf_vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	.ndo_set_vf_spoofchk	= efx_sriov_set_vf_spoofchk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	.ndo_get_vf_config	= efx_sriov_get_vf_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	.ndo_set_vf_link_state  = efx_sriov_set_vf_link_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	.ndo_get_phys_port_id   = efx_get_phys_port_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	.ndo_get_phys_port_name	= efx_get_phys_port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	.ndo_setup_tc		= efx_setup_tc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) #ifdef CONFIG_RFS_ACCEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	.ndo_rx_flow_steer	= efx_filter_rfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	.ndo_udp_tunnel_add	= udp_tunnel_nic_add_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	.ndo_udp_tunnel_del	= udp_tunnel_nic_del_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	.ndo_xdp_xmit		= efx_xdp_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	.ndo_bpf		= efx_xdp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	struct bpf_prog *old_prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	if (efx->xdp_rxq_info_failed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			  "Unable to bind XDP program due to previous failure of rxq_info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			  "Unable to configure XDP with MTU of %d (max: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			  efx->net_dev->mtu, efx_xdp_max_mtu(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	old_prog = rtnl_dereference(efx->xdp_prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	rcu_assign_pointer(efx->xdp_prog, prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	/* Release the reference that was originally passed by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	if (old_prog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		bpf_prog_put(old_prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) /* Context: process, rtnl_lock() held. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	struct efx_nic *efx = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	switch (xdp->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	case XDP_SETUP_PROG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		return efx_xdp_setup_prog(efx, xdp->prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 			u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	struct efx_nic *efx = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (!netif_running(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static void efx_update_name(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	strcpy(efx->name, efx->net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	efx_mtd_rename(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	efx_set_channel_names(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) static int efx_netdev_event(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			    unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	if ((net_dev->netdev_ops == &efx_netdev_ops) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	    event == NETDEV_CHANGENAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		efx_update_name(netdev_priv(net_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) static struct notifier_block efx_netdev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	.notifier_call = efx_netdev_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	struct efx_nic *efx = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	return sprintf(buf, "%d\n", efx->phy_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) static int efx_register_netdev(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	struct net_device *net_dev = efx->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	net_dev->watchdog_timeo = 5 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	net_dev->irq = efx->pci_dev->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	net_dev->netdev_ops = &efx_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		net_dev->priv_flags |= IFF_UNICAST_FLT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	net_dev->ethtool_ops = &efx_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	net_dev->min_mtu = EFX_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	net_dev->max_mtu = EFX_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	/* Enable resets to be scheduled and check whether any were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	 * already requested.  If so, the NIC is probably hosed so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	 * abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	efx->state = STATE_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	smp_mb(); /* ensure we change state before checking reset_pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	if (efx->reset_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		netif_err(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			  "aborting probe due to scheduled reset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		goto fail_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	rc = dev_alloc_name(net_dev, net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		goto fail_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	efx_update_name(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	/* Always start with carrier off; PHY events will detect the link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	netif_carrier_off(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	rc = register_netdevice(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		goto fail_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		struct efx_tx_queue *tx_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		efx_for_each_channel_tx_queue(tx_queue, channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			efx_init_tx_queue_core_txq(tx_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	efx_associate(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			  "failed to init net dev attributes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		goto fail_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	efx_init_mcdi_logging(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) fail_registered:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	efx_dissociate(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	unregister_netdevice(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) fail_locked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	efx->state = STATE_UNINIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) static void efx_unregister_netdev(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (!efx->net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	BUG_ON(netdev_priv(efx->net_dev) != efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (efx_dev_registered(efx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		efx_fini_mcdi_logging(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		unregister_netdev(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794)  * List of NICs we support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) /* PCI device ID table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) static const struct pci_device_id efx_pci_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803),	/* SFC9020 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 .driver_data = (unsigned long) &siena_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813),	/* SFL9021 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 .driver_data = (unsigned long) &siena_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903),  /* SFC9120 PF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903),  /* SFC9120 VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923),  /* SFC9140 PF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923),  /* SFC9140 VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03),  /* SFC9220 PF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03),  /* SFC9220 VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03),  /* SFC9250 PF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03),  /* SFC9250 VF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	{0}			/* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  * Data housekeeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	u64 n_rx_nodesc_trunc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	efx_for_each_channel(channel, efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)  * PCI interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) /* Main body of final NIC shutdown code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)  * This is called only at module unload (or hotplug removal).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) static void efx_pci_remove_main(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	/* Flush reset_work. It can no longer be scheduled since we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	 * are not READY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	BUG_ON(efx->state == STATE_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	efx_flush_reset_workqueue(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	efx_disable_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	efx_clear_interrupt_affinity(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	efx_nic_fini_interrupt(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	efx_fini_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	efx->type->fini(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	efx_fini_napi(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	efx_remove_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) /* Final NIC shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  * This is called only at module unload (or hotplug removal).  A PF can call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  * this on its VFs to ensure they are unbound first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) static void efx_pci_remove(struct pci_dev *pci_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	struct efx_nic *efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	efx = pci_get_drvdata(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	if (!efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	/* Mark the NIC as fini, then stop the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	efx_dissociate(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	dev_close(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	efx_disable_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	efx->state = STATE_UNINIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (efx->type->sriov_fini)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		efx->type->sriov_fini(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	efx_unregister_netdev(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	efx_mtd_remove(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	efx_pci_remove_main(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	efx_fini_io(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	efx_fini_struct(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	free_netdev(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	pci_disable_pcie_error_reporting(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) /* NIC VPD information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)  * Called during probe to display the part number of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)  * installed NIC.  VPD is potentially very large but this should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  * always appear within the first 512 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) #define SFC_VPD_LEN 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static void efx_probe_vpd_strings(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	struct pci_dev *dev = efx->pci_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	char vpd_data[SFC_VPD_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	ssize_t vpd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	int ro_start, ro_size, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	/* Get the vpd data from the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (vpd_size <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	/* Get the Read only section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (ro_start < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	j = ro_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	if (i + j > vpd_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		j = vpd_size - i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	/* Get the Part number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	if (i < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		netif_err(efx, drv, efx->net_dev, "Part number not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	j = pci_vpd_info_field_size(&vpd_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	if (i + j > vpd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	netif_info(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		   "Part Number : %.*s\n", j, &vpd_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	j = ro_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	if (i < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	j = pci_vpd_info_field_size(&vpd_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if (i + j > vpd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	if (!efx->vpd_sn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) /* Main body of NIC initialisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)  * This is called at module load (or hotplug insertion, theoretically).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) static int efx_pci_probe_main(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	/* Do start-of-day initialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	rc = efx_probe_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	efx_init_napi(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	down_write(&efx->filter_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	rc = efx->type->init(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	up_write(&efx->filter_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		netif_err(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			  "failed to initialise NIC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	rc = efx_init_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		netif_err(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			  "failed to initialise port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	rc = efx_nic_init_interrupt(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		goto fail5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	efx_set_interrupt_affinity(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	rc = efx_enable_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		goto fail6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  fail6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	efx_clear_interrupt_affinity(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	efx_nic_fini_interrupt(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)  fail5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	efx_fini_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)  fail4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	efx->type->fini(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	efx_fini_napi(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	efx_remove_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)  fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static int efx_pci_probe_post_io(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	struct net_device *net_dev = efx->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	int rc = efx_pci_probe_main(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	if (efx->type->sriov_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		rc = efx->type->sriov_init(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			netif_err(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 				  "SR-IOV can't be enabled rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	/* Determine netdevice features */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			      NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		net_dev->features |= NETIF_F_TSO6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	/* Check whether device supports TSO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		net_dev->features &= ~NETIF_F_ALL_TSO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	/* Mask for features that also apply to VLAN devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 				   NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 				   NETIF_F_RXCSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	/* Disable receiving frames with bad FCS, by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	net_dev->features &= ~NETIF_F_RXALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	/* Disable VLAN filtering by default.  It may be enforced if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	 * the feature is fixed (i.e. VLAN filters are required to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	 * receive VLAN tagged packets due to vPort restrictions).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	net_dev->features |= efx->fixed_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	rc = efx_register_netdev(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	efx_pci_remove_main(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) /* NIC initialisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)  * This is called at module load (or hotplug insertion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)  * theoretically).  It sets up PCI mappings, resets the NIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)  * sets up and registers the network devices with the kernel and hooks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)  * the interrupt service routine.  It does not prepare the device for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)  * transmission; this is left to the first time one of the network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)  * interfaces is brought up (i.e. efx_net_open).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) static int efx_pci_probe(struct pci_dev *pci_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			 const struct pci_device_id *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	struct net_device *net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	struct efx_nic *efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	/* Allocate and initialise a struct net_device and struct efx_nic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 				     EFX_MAX_RX_QUEUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (!net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	efx = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	efx->type = (const struct efx_nic_type *) entry->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	efx->fixed_features |= NETIF_F_HIGHDMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	pci_set_drvdata(pci_dev, efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	SET_NETDEV_DEV(net_dev, &pci_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	rc = efx_init_struct(efx, pci_dev, net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	netif_info(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		   "Solarflare NIC detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	if (!efx->type->is_vf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		efx_probe_vpd_strings(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	/* Set up basic I/O (BAR mappings etc) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			 efx->type->mem_map_size(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	rc = efx_pci_probe_post_io(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		/* On failure, retry once immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		 * If we aborted probe due to a scheduled reset, dismiss it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		efx->reset_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		rc = efx_pci_probe_post_io(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			/* On another failure, retry once more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			 * after a 50-305ms delay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 			unsigned char r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 			get_random_bytes(&r, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 			msleep((unsigned int)r + 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 			efx->reset_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			rc = efx_pci_probe_post_io(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	/* Try to create MTDs, but allow this to fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	rc = efx_mtd_probe(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (rc && rc != -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		netif_warn(efx, probe, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			   "failed to create MTDs (%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	(void)pci_enable_pcie_error_reporting(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (efx->type->udp_tnl_push_ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		efx->type->udp_tnl_push_ports(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)  fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	efx_fini_io(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)  fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	efx_fini_struct(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)  fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	WARN_ON(rc > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	free_netdev(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) /* efx_pci_sriov_configure returns the actual number of Virtual Functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)  * enabled on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	struct efx_nic *efx = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	if (efx->type->sriov_configure) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		rc = efx->type->sriov_configure(efx, num_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			return num_vfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static int efx_pm_freeze(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	struct efx_nic *efx = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	if (efx->state != STATE_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		efx->state = STATE_UNINIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		efx_device_detach_sync(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		efx_stop_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		efx_disable_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) static int efx_pm_thaw(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	struct efx_nic *efx = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	if (efx->state != STATE_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		rc = efx_enable_interrupts(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 		mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		efx_mcdi_port_reconfigure(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		efx_start_all(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		efx_device_attach_if_not_resetting(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		efx->state = STATE_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		efx->type->resume_wol(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	/* Reschedule any quenched resets scheduled during efx_pm_freeze() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	efx_queue_reset_work(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) static int efx_pm_poweroff(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	struct pci_dev *pci_dev = to_pci_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	efx->type->fini(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	efx->reset_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	pci_save_state(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	return pci_set_power_state(pci_dev, PCI_D3hot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) /* Used for both resume and restore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) static int efx_pm_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct pci_dev *pci_dev = to_pci_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	rc = pci_set_power_state(pci_dev, PCI_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	pci_restore_state(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	rc = pci_enable_device(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	pci_set_master(efx->pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	rc = efx->type->reset(efx, RESET_TYPE_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	down_write(&efx->filter_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	rc = efx->type->init(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	up_write(&efx->filter_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	rc = efx_pm_thaw(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) static int efx_pm_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	efx_pm_freeze(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	rc = efx_pm_poweroff(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		efx_pm_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static const struct dev_pm_ops efx_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	.suspend	= efx_pm_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	.resume		= efx_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	.freeze		= efx_pm_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	.thaw		= efx_pm_thaw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	.poweroff	= efx_pm_poweroff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	.restore	= efx_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) static struct pci_driver efx_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	.name		= KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	.id_table	= efx_pci_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	.probe		= efx_pci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	.remove		= efx_pci_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	.driver.pm	= &efx_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	.err_handler	= &efx_err_handlers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	.sriov_configure = efx_pci_sriov_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)  * Kernel module interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)  *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) static int __init efx_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	printk(KERN_INFO "Solarflare NET driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	rc = register_netdevice_notifier(&efx_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		goto err_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	rc = efx_init_sriov();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		goto err_sriov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	rc = efx_create_reset_workqueue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	rc = pci_register_driver(&efx_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		goto err_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	rc = pci_register_driver(&ef100_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		goto err_pci_ef100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)  err_pci_ef100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	pci_unregister_driver(&efx_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)  err_pci:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	efx_destroy_reset_workqueue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)  err_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	efx_fini_sriov();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)  err_sriov:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	unregister_netdevice_notifier(&efx_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)  err_notifier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) static void __exit efx_exit_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	printk(KERN_INFO "Solarflare NET driver unloading\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	pci_unregister_driver(&ef100_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	pci_unregister_driver(&efx_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	efx_destroy_reset_workqueue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) #ifdef CONFIG_SFC_SRIOV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	efx_fini_sriov();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	unregister_netdevice_notifier(&efx_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) module_init(efx_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) module_exit(efx_exit_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) MODULE_AUTHOR("Solarflare Communications and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	      "Michael Brown <mbrown@fensystems.co.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) MODULE_DESCRIPTION("Solarflare network driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) MODULE_DEVICE_TABLE(pci, efx_pci_table);