Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 2 | * Driver for Solarflare network controllers and boards |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 4 | * Copyright 2005-2013 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/pci.h> |
| 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/etherdevice.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/notifier.h> |
| 17 | #include <linux/ip.h> |
| 18 | #include <linux/tcp.h> |
| 19 | #include <linux/in.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 20 | #include <linux/ethtool.h> |
Ben Hutchings | aa6ef27 | 2008-07-18 19:03:10 +0100 | [diff] [blame] | 21 | #include <linux/topology.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 23 | #include <linux/aer.h> |
Alexandre Rames | b28405b | 2013-03-21 16:41:43 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 25 | #include "net_driver.h" |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 26 | #include <net/gre.h> |
| 27 | #include <net/udp_tunnel.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 28 | #include "efx.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 29 | #include "nic.h" |
Ben Hutchings | dd40781 | 2012-02-28 23:40:21 +0000 | [diff] [blame] | 30 | #include "selftest.h" |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 31 | #include "sriov.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 32 | |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 33 | #include "mcdi.h" |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 34 | #include "mcdi_pcol.h" |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 35 | #include "workarounds.h" |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 36 | |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 37 | /************************************************************************** |
| 38 | * |
| 39 | * Type name strings |
| 40 | * |
| 41 | ************************************************************************** |
| 42 | */ |
| 43 | |
| 44 | /* Loopback mode names (see LOOPBACK_MODE()) */ |
| 45 | const unsigned int efx_loopback_mode_max = LOOPBACK_MAX; |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 46 | const char *const efx_loopback_mode_names[] = { |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 47 | [LOOPBACK_NONE] = "NONE", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 48 | [LOOPBACK_DATA] = "DATAPATH", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 49 | [LOOPBACK_GMAC] = "GMAC", |
| 50 | [LOOPBACK_XGMII] = "XGMII", |
| 51 | [LOOPBACK_XGXS] = "XGXS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 52 | [LOOPBACK_XAUI] = "XAUI", |
| 53 | [LOOPBACK_GMII] = "GMII", |
| 54 | [LOOPBACK_SGMII] = "SGMII", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 55 | [LOOPBACK_XGBR] = "XGBR", |
| 56 | [LOOPBACK_XFI] = "XFI", |
| 57 | [LOOPBACK_XAUI_FAR] = "XAUI_FAR", |
| 58 | [LOOPBACK_GMII_FAR] = "GMII_FAR", |
| 59 | [LOOPBACK_SGMII_FAR] = "SGMII_FAR", |
| 60 | [LOOPBACK_XFI_FAR] = "XFI_FAR", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 61 | [LOOPBACK_GPHY] = "GPHY", |
| 62 | [LOOPBACK_PHYXS] = "PHYXS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 63 | [LOOPBACK_PCS] = "PCS", |
| 64 | [LOOPBACK_PMAPMD] = "PMA/PMD", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 65 | [LOOPBACK_XPORT] = "XPORT", |
| 66 | [LOOPBACK_XGMII_WS] = "XGMII_WS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 67 | [LOOPBACK_XAUI_WS] = "XAUI_WS", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 68 | [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR", |
| 69 | [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 70 | [LOOPBACK_GMII_WS] = "GMII_WS", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 71 | [LOOPBACK_XFI_WS] = "XFI_WS", |
| 72 | [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 73 | [LOOPBACK_PHYXS_WS] = "PHYXS_WS", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 76 | const unsigned int efx_reset_type_max = RESET_TYPE_MAX; |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 77 | const char *const efx_reset_type_names[] = { |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 78 | [RESET_TYPE_INVISIBLE] = "INVISIBLE", |
| 79 | [RESET_TYPE_ALL] = "ALL", |
| 80 | [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL", |
| 81 | [RESET_TYPE_WORLD] = "WORLD", |
| 82 | [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE", |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 83 | [RESET_TYPE_DATAPATH] = "DATAPATH", |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 84 | [RESET_TYPE_MC_BIST] = "MC_BIST", |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 85 | [RESET_TYPE_DISABLE] = "DISABLE", |
| 86 | [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG", |
| 87 | [RESET_TYPE_INT_ERROR] = "INT_ERROR", |
Alexandre Rames | 3de82b9 | 2013-06-13 11:36:15 +0100 | [diff] [blame] | 88 | [RESET_TYPE_DMA_ERROR] = "DMA_ERROR", |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 89 | [RESET_TYPE_TX_SKIP] = "TX_SKIP", |
| 90 | [RESET_TYPE_MC_FAILURE] = "MC_FAILURE", |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 91 | [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 94 | /* UDP tunnel type names */ |
| 95 | static const char *const efx_udp_tunnel_type_names[] = { |
| 96 | [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan", |
| 97 | [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve", |
| 98 | }; |
| 99 | |
| 100 | void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen) |
| 101 | { |
| 102 | if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) && |
| 103 | efx_udp_tunnel_type_names[type] != NULL) |
| 104 | snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]); |
| 105 | else |
| 106 | snprintf(buf, buflen, "type %d", type); |
| 107 | } |
| 108 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 109 | /* Reset workqueue. If any NIC has a hardware failure then a reset will be |
| 110 | * queued onto this work queue. This is not a per-nic work queue, because |
| 111 | * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised. |
| 112 | */ |
| 113 | static struct workqueue_struct *reset_workqueue; |
| 114 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 115 | /* How often and how many times to poll for a reset while waiting for a |
| 116 | * BIST that another function started to complete. |
| 117 | */ |
| 118 | #define BIST_WAIT_DELAY_MS 100 |
| 119 | #define BIST_WAIT_DELAY_COUNT 100 |
| 120 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 121 | /************************************************************************** |
| 122 | * |
| 123 | * Configurable values |
| 124 | * |
| 125 | *************************************************************************/ |
| 126 | |
| 127 | /* |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 128 | * Use separate channels for TX and RX events |
| 129 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 130 | * Set this to 1 to use separate channels for TX and RX. It allows us |
| 131 | * to control interrupt affinity separately for TX and RX. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 132 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 133 | * This is only used in MSI-X interrupt mode |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 134 | */ |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 135 | bool efx_separate_tx_channels; |
| 136 | module_param(efx_separate_tx_channels, bool, 0444); |
| 137 | MODULE_PARM_DESC(efx_separate_tx_channels, |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 138 | "Use separate channels for TX and RX"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 139 | |
| 140 | /* This is the weight assigned to each of the (per-channel) virtual |
| 141 | * NAPI devices. |
| 142 | */ |
| 143 | static int napi_weight = 64; |
| 144 | |
| 145 | /* This is the time (in jiffies) between invocations of the hardware |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 146 | * monitor. |
| 147 | * On Falcon-based NICs, this will: |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 148 | * - Check the on-board hardware monitor; |
| 149 | * - Poll the link state and reconfigure the hardware as necessary. |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 150 | * On Siena-based NICs for power systems with EEH support, this will give EEH a |
| 151 | * chance to start. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 152 | */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 153 | static unsigned int efx_monitor_interval = 1 * HZ; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 154 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | /* Initial interrupt moderation settings. They can be modified after |
| 156 | * module load with ethtool. |
| 157 | * |
| 158 | * The default for RX should strike a balance between increasing the |
| 159 | * round-trip latency and reducing overhead. |
| 160 | */ |
| 161 | static unsigned int rx_irq_mod_usec = 60; |
| 162 | |
| 163 | /* Initial interrupt moderation settings. They can be modified after |
| 164 | * module load with ethtool. |
| 165 | * |
| 166 | * This default is chosen to ensure that a 10G link does not go idle |
| 167 | * while a TX queue is stopped after it has become full. A queue is |
| 168 | * restarted when it drops below half full. The time this takes (assuming |
| 169 | * worst case 3 descriptors per packet and 1024 descriptors) is |
| 170 | * 512 / 3 * 1.2 = 205 usec. |
| 171 | */ |
| 172 | static unsigned int tx_irq_mod_usec = 150; |
| 173 | |
| 174 | /* This is the first interrupt mode to try out of: |
| 175 | * 0 => MSI-X |
| 176 | * 1 => MSI |
| 177 | * 2 => legacy |
| 178 | */ |
| 179 | static unsigned int interrupt_mode; |
| 180 | |
| 181 | /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), |
| 182 | * i.e. the number of CPUs among which we may distribute simultaneous |
| 183 | * interrupt handling. |
| 184 | * |
| 185 | * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. |
Ben Hutchings | cdb08f8 | 2011-12-20 01:08:05 +0000 | [diff] [blame] | 186 | * The default (0) means to assign an interrupt to each core. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 187 | */ |
| 188 | static unsigned int rss_cpus; |
| 189 | module_param(rss_cpus, uint, 0444); |
| 190 | MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); |
| 191 | |
Ben Hutchings | b9cc977 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 192 | static bool phy_flash_cfg; |
| 193 | module_param(phy_flash_cfg, bool, 0644); |
Ben Hutchings | 84ae48f | 2008-12-12 21:34:54 -0800 | [diff] [blame] | 194 | MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); |
| 195 | |
Ben Hutchings | e7bed9c | 2012-02-28 18:44:13 +0000 | [diff] [blame] | 196 | static unsigned irq_adapt_low_thresh = 8000; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 197 | module_param(irq_adapt_low_thresh, uint, 0644); |
| 198 | MODULE_PARM_DESC(irq_adapt_low_thresh, |
| 199 | "Threshold score for reducing IRQ moderation"); |
| 200 | |
Ben Hutchings | e7bed9c | 2012-02-28 18:44:13 +0000 | [diff] [blame] | 201 | static unsigned irq_adapt_high_thresh = 16000; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 202 | module_param(irq_adapt_high_thresh, uint, 0644); |
| 203 | MODULE_PARM_DESC(irq_adapt_high_thresh, |
| 204 | "Threshold score for increasing IRQ moderation"); |
| 205 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 206 | static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 207 | NETIF_MSG_LINK | NETIF_MSG_IFDOWN | |
| 208 | NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | |
| 209 | NETIF_MSG_TX_ERR | NETIF_MSG_HW); |
| 210 | module_param(debug, uint, 0); |
| 211 | MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); |
| 212 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 213 | /************************************************************************** |
| 214 | * |
| 215 | * Utility functions and prototypes |
| 216 | * |
| 217 | *************************************************************************/ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 218 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 219 | static int efx_soft_enable_interrupts(struct efx_nic *efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 220 | static void efx_soft_disable_interrupts(struct efx_nic *efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 221 | static void efx_remove_channel(struct efx_channel *channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 222 | static void efx_remove_channels(struct efx_nic *efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 223 | static const struct efx_channel_type efx_default_channel_type; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 224 | static void efx_remove_port(struct efx_nic *efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 225 | static void efx_init_napi_channel(struct efx_channel *channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 226 | static void efx_fini_napi(struct efx_nic *efx); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 227 | static void efx_fini_napi_channel(struct efx_channel *channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 228 | static void efx_fini_struct(struct efx_nic *efx); |
| 229 | static void efx_start_all(struct efx_nic *efx); |
| 230 | static void efx_stop_all(struct efx_nic *efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 231 | |
| 232 | #define EFX_ASSERT_RESET_SERIALISED(efx) \ |
| 233 | do { \ |
Ben Hutchings | f16aeea | 2012-07-27 19:31:16 +0100 | [diff] [blame] | 234 | if ((efx->state == STATE_READY) || \ |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 235 | (efx->state == STATE_RECOVERY) || \ |
Ben Hutchings | 332c1ce | 2009-11-25 16:08:52 +0000 | [diff] [blame] | 236 | (efx->state == STATE_DISABLED)) \ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 237 | ASSERT_RTNL(); \ |
| 238 | } while (0) |
| 239 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 240 | static int efx_check_disabled(struct efx_nic *efx) |
| 241 | { |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 242 | if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) { |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 243 | netif_err(efx, drv, efx->net_dev, |
| 244 | "device is disabled due to earlier errors\n"); |
| 245 | return -EIO; |
| 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 250 | /************************************************************************** |
| 251 | * |
| 252 | * Event queue processing |
| 253 | * |
| 254 | *************************************************************************/ |
| 255 | |
| 256 | /* Process channel's event queue |
| 257 | * |
| 258 | * This function is responsible for processing the event queue of a |
| 259 | * single channel. The caller must guarantee that this function will |
| 260 | * never be concurrently called more than once on the same channel, |
| 261 | * though different channels may be being processed concurrently. |
| 262 | */ |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 263 | static int efx_process_channel(struct efx_channel *channel, int budget) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 264 | { |
Peter Dunning | c936835 | 2015-07-08 10:05:10 +0100 | [diff] [blame] | 265 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 266 | int spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 267 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 268 | if (unlikely(!channel->enabled)) |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 269 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 270 | |
Peter Dunning | c936835 | 2015-07-08 10:05:10 +0100 | [diff] [blame] | 271 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 272 | tx_queue->pkts_compl = 0; |
| 273 | tx_queue->bytes_compl = 0; |
| 274 | } |
| 275 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 276 | spent = efx_nic_process_eventq(channel, budget); |
Ben Hutchings | d9ab700 | 2012-02-13 23:29:16 +0000 | [diff] [blame] | 277 | if (spent && efx_channel_has_rx_queue(channel)) { |
| 278 | struct efx_rx_queue *rx_queue = |
| 279 | efx_channel_get_rx_queue(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 280 | |
Ben Hutchings | ff734ef | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 281 | efx_rx_flush_packet(channel); |
Jon Cooper | cce2879 | 2013-10-02 11:04:14 +0100 | [diff] [blame] | 282 | efx_fast_push_rx_descriptors(rx_queue, true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Peter Dunning | c936835 | 2015-07-08 10:05:10 +0100 | [diff] [blame] | 285 | /* Update BQL */ |
| 286 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 287 | if (tx_queue->bytes_compl) { |
| 288 | netdev_tx_completed_queue(tx_queue->core_txq, |
| 289 | tx_queue->pkts_compl, tx_queue->bytes_compl); |
| 290 | } |
| 291 | } |
| 292 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 293 | return spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 296 | /* NAPI poll handler |
| 297 | * |
| 298 | * NAPI guarantees serialisation of polls of the same device, which |
| 299 | * provides the guarantee required by efx_process_channel(). |
| 300 | */ |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 301 | static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel) |
| 302 | { |
| 303 | int step = efx->irq_mod_step_us; |
| 304 | |
| 305 | if (channel->irq_mod_score < irq_adapt_low_thresh) { |
| 306 | if (channel->irq_moderation_us > step) { |
| 307 | channel->irq_moderation_us -= step; |
| 308 | efx->type->push_irq_moderation(channel); |
| 309 | } |
| 310 | } else if (channel->irq_mod_score > irq_adapt_high_thresh) { |
| 311 | if (channel->irq_moderation_us < |
| 312 | efx->irq_rx_moderation_us) { |
| 313 | channel->irq_moderation_us += step; |
| 314 | efx->type->push_irq_moderation(channel); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | channel->irq_count = 0; |
| 319 | channel->irq_mod_score = 0; |
| 320 | } |
| 321 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 322 | static int efx_poll(struct napi_struct *napi, int budget) |
| 323 | { |
| 324 | struct efx_channel *channel = |
| 325 | container_of(napi, struct efx_channel, napi_str); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 326 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 327 | int spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 328 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 329 | netif_vdbg(efx, intr, efx->net_dev, |
| 330 | "channel %d NAPI poll executing on CPU %d\n", |
| 331 | channel->channel, raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 332 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 333 | spent = efx_process_channel(channel, budget); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 334 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 335 | if (spent < budget) { |
Ben Hutchings | 9d9a697 | 2012-02-10 23:01:48 +0000 | [diff] [blame] | 336 | if (efx_channel_has_rx_queue(channel) && |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 337 | efx->irq_rx_adaptive && |
| 338 | unlikely(++channel->irq_count == 1000)) { |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 339 | efx_update_irq_mod(efx, channel); |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 342 | efx_filter_rfs_expire(channel); |
| 343 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 344 | /* There is no race here; although napi_disable() will |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 345 | * only wait for napi_complete(), this isn't a problem |
Ben Hutchings | 514bedb | 2012-10-05 19:30:16 +0100 | [diff] [blame] | 346 | * since efx_nic_eventq_read_ack() will have no effect if |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 347 | * interrupts have already been disabled. |
| 348 | */ |
Bert Kenward | f820c0a | 2017-02-06 16:50:55 +0000 | [diff] [blame] | 349 | if (napi_complete_done(napi, spent)) |
| 350 | efx_nic_eventq_read_ack(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 353 | return spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 356 | /* Create event queue |
| 357 | * Event queue memory allocations are done only once. If the channel |
| 358 | * is reset, the memory buffer will be reused; this guards against |
| 359 | * errors during channel reset and also simplifies interrupt handling. |
| 360 | */ |
| 361 | static int efx_probe_eventq(struct efx_channel *channel) |
| 362 | { |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 363 | struct efx_nic *efx = channel->efx; |
| 364 | unsigned long entries; |
| 365 | |
Ben Hutchings | 86ee530 | 2012-01-09 19:51:22 +0000 | [diff] [blame] | 366 | netif_dbg(efx, probe, efx->net_dev, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 367 | "chan %d create event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 368 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 369 | /* Build an event queue with room for one event per tx and rx buffer, |
| 370 | * plus some extra for link state events and MCDI completions. */ |
| 371 | entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128); |
Edward Cree | e01b16a | 2016-12-02 15:51:33 +0000 | [diff] [blame] | 372 | EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE); |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 373 | channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1; |
| 374 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 375 | return efx_nic_probe_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* Prepare channel's event queue */ |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 379 | static int efx_init_eventq(struct efx_channel *channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 380 | { |
Ben Hutchings | 15acb1c | 2013-05-01 16:30:17 +0100 | [diff] [blame] | 381 | struct efx_nic *efx = channel->efx; |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 382 | int rc; |
| 383 | |
| 384 | EFX_WARN_ON_PARANOID(channel->eventq_init); |
| 385 | |
Ben Hutchings | 15acb1c | 2013-05-01 16:30:17 +0100 | [diff] [blame] | 386 | netif_dbg(efx, drv, efx->net_dev, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 387 | "chan %d init event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 388 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 389 | rc = efx_nic_init_eventq(channel); |
| 390 | if (rc == 0) { |
Ben Hutchings | 15acb1c | 2013-05-01 16:30:17 +0100 | [diff] [blame] | 391 | efx->type->push_irq_moderation(channel); |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 392 | channel->eventq_read_ptr = 0; |
| 393 | channel->eventq_init = true; |
| 394 | } |
| 395 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 398 | /* Enable event queue processing and NAPI */ |
Alexandre Rames | 3676326 | 2014-07-22 14:03:25 +0100 | [diff] [blame] | 399 | void efx_start_eventq(struct efx_channel *channel) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 400 | { |
| 401 | netif_dbg(channel->efx, ifup, channel->efx->net_dev, |
| 402 | "chan %d start event queue\n", channel->channel); |
| 403 | |
Ben Hutchings | 514bedb | 2012-10-05 19:30:16 +0100 | [diff] [blame] | 404 | /* Make sure the NAPI handler sees the enabled flag set */ |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 405 | channel->enabled = true; |
| 406 | smp_wmb(); |
| 407 | |
| 408 | napi_enable(&channel->napi_str); |
| 409 | efx_nic_eventq_read_ack(channel); |
| 410 | } |
| 411 | |
| 412 | /* Disable event queue processing and NAPI */ |
Alexandre Rames | 3676326 | 2014-07-22 14:03:25 +0100 | [diff] [blame] | 413 | void efx_stop_eventq(struct efx_channel *channel) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 414 | { |
| 415 | if (!channel->enabled) |
| 416 | return; |
| 417 | |
| 418 | napi_disable(&channel->napi_str); |
| 419 | channel->enabled = false; |
| 420 | } |
| 421 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 422 | static void efx_fini_eventq(struct efx_channel *channel) |
| 423 | { |
Ben Hutchings | be3fc09 | 2012-10-08 18:21:51 +0100 | [diff] [blame] | 424 | if (!channel->eventq_init) |
| 425 | return; |
| 426 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 427 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 428 | "chan %d fini event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 429 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 430 | efx_nic_fini_eventq(channel); |
Ben Hutchings | be3fc09 | 2012-10-08 18:21:51 +0100 | [diff] [blame] | 431 | channel->eventq_init = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void efx_remove_eventq(struct efx_channel *channel) |
| 435 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 436 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 437 | "chan %d remove event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 438 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 439 | efx_nic_remove_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /************************************************************************** |
| 443 | * |
| 444 | * Channel handling |
| 445 | * |
| 446 | *************************************************************************/ |
| 447 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 448 | /* Allocate and initialise a channel structure. */ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 449 | static struct efx_channel * |
| 450 | efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) |
| 451 | { |
| 452 | struct efx_channel *channel; |
| 453 | struct efx_rx_queue *rx_queue; |
| 454 | struct efx_tx_queue *tx_queue; |
| 455 | int j; |
| 456 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 457 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); |
| 458 | if (!channel) |
| 459 | return NULL; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 460 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 461 | channel->efx = efx; |
| 462 | channel->channel = i; |
| 463 | channel->type = &efx_default_channel_type; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 464 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 465 | for (j = 0; j < EFX_TXQ_TYPES; j++) { |
| 466 | tx_queue = &channel->tx_queue[j]; |
| 467 | tx_queue->efx = efx; |
| 468 | tx_queue->queue = i * EFX_TXQ_TYPES + j; |
| 469 | tx_queue->channel = channel; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 472 | rx_queue = &channel->rx_queue; |
| 473 | rx_queue->efx = efx; |
| 474 | setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, |
| 475 | (unsigned long)rx_queue); |
| 476 | |
| 477 | return channel; |
| 478 | } |
| 479 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 480 | /* Allocate and initialise a channel structure, copying parameters |
| 481 | * (but not resources) from an old channel structure. |
| 482 | */ |
| 483 | static struct efx_channel * |
| 484 | efx_copy_channel(const struct efx_channel *old_channel) |
| 485 | { |
| 486 | struct efx_channel *channel; |
| 487 | struct efx_rx_queue *rx_queue; |
| 488 | struct efx_tx_queue *tx_queue; |
| 489 | int j; |
| 490 | |
| 491 | channel = kmalloc(sizeof(*channel), GFP_KERNEL); |
| 492 | if (!channel) |
| 493 | return NULL; |
| 494 | |
| 495 | *channel = *old_channel; |
| 496 | |
| 497 | channel->napi_dev = NULL; |
Bert Kenward | 46d054f | 2016-11-11 15:56:51 +0000 | [diff] [blame] | 498 | INIT_HLIST_NODE(&channel->napi_str.napi_hash_node); |
| 499 | channel->napi_str.napi_id = 0; |
| 500 | channel->napi_str.state = 0; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 501 | memset(&channel->eventq, 0, sizeof(channel->eventq)); |
| 502 | |
| 503 | for (j = 0; j < EFX_TXQ_TYPES; j++) { |
| 504 | tx_queue = &channel->tx_queue[j]; |
| 505 | if (tx_queue->channel) |
| 506 | tx_queue->channel = channel; |
| 507 | tx_queue->buffer = NULL; |
| 508 | memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); |
| 509 | } |
| 510 | |
| 511 | rx_queue = &channel->rx_queue; |
| 512 | rx_queue->buffer = NULL; |
| 513 | memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); |
| 514 | setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, |
| 515 | (unsigned long)rx_queue); |
| 516 | |
| 517 | return channel; |
| 518 | } |
| 519 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 520 | static int efx_probe_channel(struct efx_channel *channel) |
| 521 | { |
| 522 | struct efx_tx_queue *tx_queue; |
| 523 | struct efx_rx_queue *rx_queue; |
| 524 | int rc; |
| 525 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 526 | netif_dbg(channel->efx, probe, channel->efx->net_dev, |
| 527 | "creating channel %d\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 528 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 529 | rc = channel->type->pre_probe(channel); |
| 530 | if (rc) |
| 531 | goto fail; |
| 532 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 533 | rc = efx_probe_eventq(channel); |
| 534 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 535 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 536 | |
| 537 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 538 | rc = efx_probe_tx_queue(tx_queue); |
| 539 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 540 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 544 | rc = efx_probe_rx_queue(rx_queue); |
| 545 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 546 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 549 | return 0; |
| 550 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 551 | fail: |
| 552 | efx_remove_channel(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 553 | return rc; |
| 554 | } |
| 555 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 556 | static void |
| 557 | efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) |
| 558 | { |
| 559 | struct efx_nic *efx = channel->efx; |
| 560 | const char *type; |
| 561 | int number; |
| 562 | |
| 563 | number = channel->channel; |
| 564 | if (efx->tx_channel_offset == 0) { |
| 565 | type = ""; |
| 566 | } else if (channel->channel < efx->tx_channel_offset) { |
| 567 | type = "-rx"; |
| 568 | } else { |
| 569 | type = "-tx"; |
| 570 | number -= efx->tx_channel_offset; |
| 571 | } |
| 572 | snprintf(buf, len, "%s%s-%d", efx->name, type, number); |
| 573 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 574 | |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 575 | static void efx_set_channel_names(struct efx_nic *efx) |
| 576 | { |
| 577 | struct efx_channel *channel; |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 578 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 579 | efx_for_each_channel(channel, efx) |
| 580 | channel->type->get_name(channel, |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 581 | efx->msi_context[channel->channel].name, |
| 582 | sizeof(efx->msi_context[0].name)); |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 585 | static int efx_probe_channels(struct efx_nic *efx) |
| 586 | { |
| 587 | struct efx_channel *channel; |
| 588 | int rc; |
| 589 | |
| 590 | /* Restart special buffer allocation */ |
| 591 | efx->next_buffer_table = 0; |
| 592 | |
Ben Hutchings | c92aaff | 2012-02-21 23:22:00 +0000 | [diff] [blame] | 593 | /* Probe channels in reverse, so that any 'extra' channels |
| 594 | * use the start of the buffer table. This allows the traffic |
| 595 | * channels to be resized without moving them or wasting the |
| 596 | * entries before them. |
| 597 | */ |
| 598 | efx_for_each_channel_rev(channel, efx) { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 599 | rc = efx_probe_channel(channel); |
| 600 | if (rc) { |
| 601 | netif_err(efx, probe, efx->net_dev, |
| 602 | "failed to create channel %d\n", |
| 603 | channel->channel); |
| 604 | goto fail; |
| 605 | } |
| 606 | } |
| 607 | efx_set_channel_names(efx); |
| 608 | |
| 609 | return 0; |
| 610 | |
| 611 | fail: |
| 612 | efx_remove_channels(efx); |
| 613 | return rc; |
| 614 | } |
| 615 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 616 | /* Channels are shutdown and reinitialised whilst the NIC is running |
| 617 | * to propagate configuration changes (mtu, checksum offload), or |
| 618 | * to clear hardware error conditions |
| 619 | */ |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 620 | static void efx_start_datapath(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 621 | { |
Andrew Rybchenko | ebfcd0f | 2016-06-15 17:43:20 +0100 | [diff] [blame] | 622 | netdev_features_t old_features = efx->net_dev->features; |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 623 | bool old_rx_scatter = efx->rx_scatter; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 624 | struct efx_tx_queue *tx_queue; |
| 625 | struct efx_rx_queue *rx_queue; |
| 626 | struct efx_channel *channel; |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 627 | size_t rx_buf_len; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 628 | |
Ben Hutchings | f7f13b0 | 2008-05-16 21:15:06 +0100 | [diff] [blame] | 629 | /* Calculate the rx buffer allocation parameters required to |
| 630 | * support the current MTU, including padding for header |
| 631 | * alignment and overruns. |
| 632 | */ |
Jon Cooper | 43a3739 | 2012-10-18 15:49:54 +0100 | [diff] [blame] | 633 | efx->rx_dma_len = (efx->rx_prefix_size + |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 634 | EFX_MAX_FRAME_LEN(efx->net_dev->mtu) + |
| 635 | efx->type->rx_buffer_padding); |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 636 | rx_buf_len = (sizeof(struct efx_rx_page_state) + |
Andrew Rybchenko | 2ec0301 | 2013-11-16 11:02:27 +0400 | [diff] [blame] | 637 | efx->rx_ip_align + efx->rx_dma_len); |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 638 | if (rx_buf_len <= PAGE_SIZE) { |
Jon Cooper | e8c68c0 | 2013-03-08 10:18:28 +0000 | [diff] [blame] | 639 | efx->rx_scatter = efx->type->always_rx_scatter; |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 640 | efx->rx_buffer_order = 0; |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 641 | } else if (efx->type->can_rx_scatter) { |
Ben Hutchings | 950c54d | 2013-05-13 12:01:22 +0000 | [diff] [blame] | 642 | BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES); |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 643 | BUILD_BUG_ON(sizeof(struct efx_rx_page_state) + |
Ben Hutchings | 950c54d | 2013-05-13 12:01:22 +0000 | [diff] [blame] | 644 | 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE, |
| 645 | EFX_RX_BUF_ALIGNMENT) > |
| 646 | PAGE_SIZE); |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 647 | efx->rx_scatter = true; |
| 648 | efx->rx_dma_len = EFX_RX_USR_BUF_SIZE; |
| 649 | efx->rx_buffer_order = 0; |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 650 | } else { |
| 651 | efx->rx_scatter = false; |
| 652 | efx->rx_buffer_order = get_order(rx_buf_len); |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Daniel Pieczko | 1648a23 | 2013-02-13 10:54:41 +0000 | [diff] [blame] | 655 | efx_rx_config_page_split(efx); |
| 656 | if (efx->rx_buffer_order) |
| 657 | netif_dbg(efx, drv, efx->net_dev, |
| 658 | "RX buf len=%u; page order=%u batch=%u\n", |
| 659 | efx->rx_dma_len, efx->rx_buffer_order, |
| 660 | efx->rx_pages_per_batch); |
| 661 | else |
| 662 | netif_dbg(efx, drv, efx->net_dev, |
| 663 | "RX buf len=%u step=%u bpp=%u; page batch=%u\n", |
| 664 | efx->rx_dma_len, efx->rx_page_buf_step, |
| 665 | efx->rx_bufs_per_page, efx->rx_pages_per_batch); |
Daniel Pieczko | 2768935 | 2013-02-13 10:54:41 +0000 | [diff] [blame] | 666 | |
Andrew Rybchenko | ebfcd0f | 2016-06-15 17:43:20 +0100 | [diff] [blame] | 667 | /* Restore previously fixed features in hw_features and remove |
| 668 | * features which are fixed now |
| 669 | */ |
| 670 | efx->net_dev->hw_features |= efx->net_dev->features; |
| 671 | efx->net_dev->hw_features &= ~efx->fixed_features; |
| 672 | efx->net_dev->features |= efx->fixed_features; |
| 673 | if (efx->net_dev->features != old_features) |
| 674 | netdev_features_change(efx->net_dev); |
| 675 | |
Jon Cooper | e8c68c0 | 2013-03-08 10:18:28 +0000 | [diff] [blame] | 676 | /* RX filters may also have scatter-enabled flags */ |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 677 | if (efx->rx_scatter != old_rx_scatter) |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 678 | efx->type->filter_update_rx_scatter(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 679 | |
Ben Hutchings | 14bf718 | 2012-05-22 01:27:58 +0100 | [diff] [blame] | 680 | /* We must keep at least one descriptor in a TX ring empty. |
| 681 | * We could avoid this when the queue size does not exactly |
| 682 | * match the hardware ring size, but it's not that important. |
| 683 | * Therefore we stop the queue when one more skb might fill |
| 684 | * the ring completely. We wake it when half way back to |
| 685 | * empty. |
| 686 | */ |
| 687 | efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx); |
| 688 | efx->txq_wake_thresh = efx->txq_stop_thresh / 2; |
| 689 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 690 | /* Initialise the channels */ |
| 691 | efx_for_each_channel(channel, efx) { |
Alexandre Rames | 3881d8a | 2013-06-10 11:03:21 +0100 | [diff] [blame] | 692 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 693 | efx_init_tx_queue(tx_queue); |
Alexandre Rames | 3881d8a | 2013-06-10 11:03:21 +0100 | [diff] [blame] | 694 | atomic_inc(&efx->active_queues); |
| 695 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 696 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 697 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 698 | efx_init_rx_queue(rx_queue); |
Alexandre Rames | 3881d8a | 2013-06-10 11:03:21 +0100 | [diff] [blame] | 699 | atomic_inc(&efx->active_queues); |
Jon Cooper | cce2879 | 2013-10-02 11:04:14 +0100 | [diff] [blame] | 700 | efx_stop_eventq(channel); |
| 701 | efx_fast_push_rx_descriptors(rx_queue, false); |
| 702 | efx_start_eventq(channel); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 703 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 704 | |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 705 | WARN_ON(channel->rx_pkt_n_frags); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 706 | } |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 707 | |
Alexandre Rames | 2ea4dc2 | 2013-11-08 10:20:31 +0000 | [diff] [blame] | 708 | efx_ptp_start_datapath(efx); |
| 709 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 710 | if (netif_device_present(efx->net_dev)) |
| 711 | netif_tx_wake_all_queues(efx->net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 714 | static void efx_stop_datapath(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 715 | { |
| 716 | struct efx_channel *channel; |
| 717 | struct efx_tx_queue *tx_queue; |
| 718 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 719 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 720 | |
| 721 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 722 | BUG_ON(efx->port_enabled); |
| 723 | |
Alexandre Rames | 2ea4dc2 | 2013-11-08 10:20:31 +0000 | [diff] [blame] | 724 | efx_ptp_stop_datapath(efx); |
| 725 | |
Ben Hutchings | d8aec74 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 726 | /* Stop RX refill */ |
| 727 | efx_for_each_channel(channel, efx) { |
| 728 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 729 | rx_queue->refill_enabled = false; |
| 730 | } |
| 731 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 732 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 733 | /* RX packet processing is pipelined, so wait for the |
| 734 | * NAPI handler to complete. At least event queue 0 |
| 735 | * might be kept active by non-data events, so don't |
| 736 | * use napi_synchronize() but actually disable NAPI |
| 737 | * temporarily. |
| 738 | */ |
| 739 | if (efx_channel_has_rx_queue(channel)) { |
| 740 | efx_stop_eventq(channel); |
| 741 | efx_start_eventq(channel); |
| 742 | } |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 743 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 744 | |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 745 | rc = efx->type->fini_dmaq(efx); |
Edward Cree | 5a6681e | 2016-11-28 18:55:34 +0000 | [diff] [blame] | 746 | if (rc) { |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 747 | netif_err(efx, drv, efx->net_dev, "failed to flush queues\n"); |
| 748 | } else { |
| 749 | netif_dbg(efx, drv, efx->net_dev, |
| 750 | "successfully flushed all queues\n"); |
| 751 | } |
| 752 | |
| 753 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 754 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 755 | efx_fini_rx_queue(rx_queue); |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 756 | efx_for_each_possible_channel_tx_queue(tx_queue, channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 757 | efx_fini_tx_queue(tx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | static void efx_remove_channel(struct efx_channel *channel) |
| 762 | { |
| 763 | struct efx_tx_queue *tx_queue; |
| 764 | struct efx_rx_queue *rx_queue; |
| 765 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 766 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 767 | "destroy chan %d\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 768 | |
| 769 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 770 | efx_remove_rx_queue(rx_queue); |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 771 | efx_for_each_possible_channel_tx_queue(tx_queue, channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 772 | efx_remove_tx_queue(tx_queue); |
| 773 | efx_remove_eventq(channel); |
Stuart Hodgson | c31e5f9 | 2012-07-18 09:52:11 +0100 | [diff] [blame] | 774 | channel->type->post_remove(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 777 | static void efx_remove_channels(struct efx_nic *efx) |
| 778 | { |
| 779 | struct efx_channel *channel; |
| 780 | |
| 781 | efx_for_each_channel(channel, efx) |
| 782 | efx_remove_channel(channel); |
| 783 | } |
| 784 | |
| 785 | int |
| 786 | efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) |
| 787 | { |
| 788 | struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; |
| 789 | u32 old_rxq_entries, old_txq_entries; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 790 | unsigned i, next_buffer_table = 0; |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 791 | int rc, rc2; |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 792 | |
| 793 | rc = efx_check_disabled(efx); |
| 794 | if (rc) |
| 795 | return rc; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 796 | |
| 797 | /* Not all channels should be reallocated. We must avoid |
| 798 | * reallocating their buffer table entries. |
| 799 | */ |
| 800 | efx_for_each_channel(channel, efx) { |
| 801 | struct efx_rx_queue *rx_queue; |
| 802 | struct efx_tx_queue *tx_queue; |
| 803 | |
| 804 | if (channel->type->copy) |
| 805 | continue; |
| 806 | next_buffer_table = max(next_buffer_table, |
| 807 | channel->eventq.index + |
| 808 | channel->eventq.entries); |
| 809 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 810 | next_buffer_table = max(next_buffer_table, |
| 811 | rx_queue->rxd.index + |
| 812 | rx_queue->rxd.entries); |
| 813 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 814 | next_buffer_table = max(next_buffer_table, |
| 815 | tx_queue->txd.index + |
| 816 | tx_queue->txd.entries); |
| 817 | } |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 818 | |
Ben Hutchings | 29c69a4 | 2013-01-28 19:01:06 +0000 | [diff] [blame] | 819 | efx_device_detach_sync(efx); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 820 | efx_stop_all(efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 821 | efx_soft_disable_interrupts(efx); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 822 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 823 | /* Clone channels (where possible) */ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 824 | memset(other_channel, 0, sizeof(other_channel)); |
| 825 | for (i = 0; i < efx->n_channels; i++) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 826 | channel = efx->channel[i]; |
| 827 | if (channel->type->copy) |
| 828 | channel = channel->type->copy(channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 829 | if (!channel) { |
| 830 | rc = -ENOMEM; |
| 831 | goto out; |
| 832 | } |
| 833 | other_channel[i] = channel; |
| 834 | } |
| 835 | |
| 836 | /* Swap entry counts and channel pointers */ |
| 837 | old_rxq_entries = efx->rxq_entries; |
| 838 | old_txq_entries = efx->txq_entries; |
| 839 | efx->rxq_entries = rxq_entries; |
| 840 | efx->txq_entries = txq_entries; |
| 841 | for (i = 0; i < efx->n_channels; i++) { |
| 842 | channel = efx->channel[i]; |
| 843 | efx->channel[i] = other_channel[i]; |
| 844 | other_channel[i] = channel; |
| 845 | } |
| 846 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 847 | /* Restart buffer table allocation */ |
| 848 | efx->next_buffer_table = next_buffer_table; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 849 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 850 | for (i = 0; i < efx->n_channels; i++) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 851 | channel = efx->channel[i]; |
| 852 | if (!channel->type->copy) |
| 853 | continue; |
| 854 | rc = efx_probe_channel(channel); |
| 855 | if (rc) |
| 856 | goto rollback; |
| 857 | efx_init_napi_channel(efx->channel[i]); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 858 | } |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 859 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 860 | out: |
| 861 | /* Destroy unused channel structures */ |
| 862 | for (i = 0; i < efx->n_channels; i++) { |
| 863 | channel = other_channel[i]; |
| 864 | if (channel && channel->type->copy) { |
| 865 | efx_fini_napi_channel(channel); |
| 866 | efx_remove_channel(channel); |
| 867 | kfree(channel); |
| 868 | } |
| 869 | } |
| 870 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 871 | rc2 = efx_soft_enable_interrupts(efx); |
| 872 | if (rc2) { |
| 873 | rc = rc ? rc : rc2; |
| 874 | netif_err(efx, drv, efx->net_dev, |
| 875 | "unable to restart interrupts on channel reallocation\n"); |
| 876 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 877 | } else { |
| 878 | efx_start_all(efx); |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 879 | efx_device_attach_if_not_resetting(efx); |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 880 | } |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 881 | return rc; |
| 882 | |
| 883 | rollback: |
| 884 | /* Swap back */ |
| 885 | efx->rxq_entries = old_rxq_entries; |
| 886 | efx->txq_entries = old_txq_entries; |
| 887 | for (i = 0; i < efx->n_channels; i++) { |
| 888 | channel = efx->channel[i]; |
| 889 | efx->channel[i] = other_channel[i]; |
| 890 | other_channel[i] = channel; |
| 891 | } |
| 892 | goto out; |
| 893 | } |
| 894 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 895 | void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 896 | { |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 897 | mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 898 | } |
| 899 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 900 | static const struct efx_channel_type efx_default_channel_type = { |
| 901 | .pre_probe = efx_channel_dummy_op_int, |
Stuart Hodgson | c31e5f9 | 2012-07-18 09:52:11 +0100 | [diff] [blame] | 902 | .post_remove = efx_channel_dummy_op_void, |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 903 | .get_name = efx_get_channel_name, |
| 904 | .copy = efx_copy_channel, |
| 905 | .keep_eventq = false, |
| 906 | }; |
| 907 | |
| 908 | int efx_channel_dummy_op_int(struct efx_channel *channel) |
| 909 | { |
| 910 | return 0; |
| 911 | } |
| 912 | |
Stuart Hodgson | c31e5f9 | 2012-07-18 09:52:11 +0100 | [diff] [blame] | 913 | void efx_channel_dummy_op_void(struct efx_channel *channel) |
| 914 | { |
| 915 | } |
| 916 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 917 | /************************************************************************** |
| 918 | * |
| 919 | * Port handling |
| 920 | * |
| 921 | **************************************************************************/ |
| 922 | |
| 923 | /* This ensures that the kernel is kept informed (via |
| 924 | * netif_carrier_on/off) of the link status, and also maintains the |
| 925 | * link status's stop on the port's TX queue. |
| 926 | */ |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 927 | void efx_link_status_changed(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 928 | { |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 929 | struct efx_link_state *link_state = &efx->link_state; |
| 930 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 931 | /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure |
| 932 | * that no events are triggered between unregister_netdev() and the |
| 933 | * driver unloading. A more general condition is that NETDEV_CHANGE |
| 934 | * can only be generated between NETDEV_UP and NETDEV_DOWN */ |
| 935 | if (!netif_running(efx->net_dev)) |
| 936 | return; |
| 937 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 938 | if (link_state->up != netif_carrier_ok(efx->net_dev)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 939 | efx->n_link_state_changes++; |
| 940 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 941 | if (link_state->up) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 942 | netif_carrier_on(efx->net_dev); |
| 943 | else |
| 944 | netif_carrier_off(efx->net_dev); |
| 945 | } |
| 946 | |
| 947 | /* Status message for kernel log */ |
Ben Hutchings | 2aa9ef1 | 2012-01-09 19:53:41 +0000 | [diff] [blame] | 948 | if (link_state->up) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 949 | netif_info(efx, link, efx->net_dev, |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 950 | "link up at %uMbps %s-duplex (MTU %d)\n", |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 951 | link_state->speed, link_state->fd ? "full" : "half", |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 952 | efx->net_dev->mtu); |
Ben Hutchings | 2aa9ef1 | 2012-01-09 19:53:41 +0000 | [diff] [blame] | 953 | else |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 954 | netif_info(efx, link, efx->net_dev, "link down\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 957 | void efx_link_set_advertising(struct efx_nic *efx, u32 advertising) |
| 958 | { |
| 959 | efx->link_advertising = advertising; |
| 960 | if (advertising) { |
| 961 | if (advertising & ADVERTISED_Pause) |
| 962 | efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX); |
| 963 | else |
| 964 | efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX); |
| 965 | if (advertising & ADVERTISED_Asym_Pause) |
| 966 | efx->wanted_fc ^= EFX_FC_TX; |
| 967 | } |
| 968 | } |
| 969 | |
David S. Miller | b5626946 | 2011-05-17 17:53:22 -0400 | [diff] [blame] | 970 | void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc) |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 971 | { |
| 972 | efx->wanted_fc = wanted_fc; |
| 973 | if (efx->link_advertising) { |
| 974 | if (wanted_fc & EFX_FC_RX) |
| 975 | efx->link_advertising |= (ADVERTISED_Pause | |
| 976 | ADVERTISED_Asym_Pause); |
| 977 | else |
| 978 | efx->link_advertising &= ~(ADVERTISED_Pause | |
| 979 | ADVERTISED_Asym_Pause); |
| 980 | if (wanted_fc & EFX_FC_TX) |
| 981 | efx->link_advertising ^= ADVERTISED_Asym_Pause; |
| 982 | } |
| 983 | } |
| 984 | |
Ben Hutchings | 115122a | 2009-03-04 09:52:52 +0000 | [diff] [blame] | 985 | static void efx_fini_port(struct efx_nic *efx); |
| 986 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 987 | /* We assume that efx->type->reconfigure_mac will always try to sync RX |
| 988 | * filters and therefore needs to read-lock the filter table against freeing |
| 989 | */ |
| 990 | void efx_mac_reconfigure(struct efx_nic *efx) |
| 991 | { |
| 992 | down_read(&efx->filter_sem); |
| 993 | efx->type->reconfigure_mac(efx); |
| 994 | up_read(&efx->filter_sem); |
| 995 | } |
| 996 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 997 | /* Push loopback/power/transmit disable settings to the PHY, and reconfigure |
| 998 | * the MAC appropriately. All other PHY configuration changes are pushed |
| 999 | * through phy_op->set_settings(), and pushed asynchronously to the MAC |
| 1000 | * through efx_monitor(). |
| 1001 | * |
| 1002 | * Callers must hold the mac_lock |
| 1003 | */ |
| 1004 | int __efx_reconfigure_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1005 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1006 | enum efx_phy_mode phy_mode; |
| 1007 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1008 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1009 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1010 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1011 | /* Disable PHY transmit in mac level loopbacks */ |
| 1012 | phy_mode = efx->phy_mode; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1013 | if (LOOPBACK_INTERNAL(efx)) |
| 1014 | efx->phy_mode |= PHY_MODE_TX_DISABLED; |
| 1015 | else |
| 1016 | efx->phy_mode &= ~PHY_MODE_TX_DISABLED; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1017 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1018 | rc = efx->type->reconfigure_port(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1019 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1020 | if (rc) |
| 1021 | efx->phy_mode = phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1022 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1023 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /* Reinitialise the MAC to pick up new PHY settings, even if the port is |
| 1027 | * disabled. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1028 | int efx_reconfigure_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1029 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1030 | int rc; |
| 1031 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1032 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1033 | |
| 1034 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1035 | rc = __efx_reconfigure_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1036 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1037 | |
| 1038 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1041 | /* Asynchronous work item for changing MAC promiscuity and multicast |
| 1042 | * hash. Avoid a drain/rx_ingress enable by reconfiguring the current |
| 1043 | * MAC directly. */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1044 | static void efx_mac_work(struct work_struct *data) |
| 1045 | { |
| 1046 | struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); |
| 1047 | |
| 1048 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 30b81cd | 2011-09-13 19:47:48 +0100 | [diff] [blame] | 1049 | if (efx->port_enabled) |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1050 | efx_mac_reconfigure(efx); |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1051 | mutex_unlock(&efx->mac_lock); |
| 1052 | } |
| 1053 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1054 | static int efx_probe_port(struct efx_nic *efx) |
| 1055 | { |
| 1056 | int rc; |
| 1057 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1058 | netif_dbg(efx, probe, efx->net_dev, "create port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1059 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 1060 | if (phy_flash_cfg) |
| 1061 | efx->phy_mode = PHY_MODE_SPECIAL; |
| 1062 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1063 | /* Connect up MAC/PHY operations table */ |
| 1064 | rc = efx->type->probe_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1065 | if (rc) |
Ben Hutchings | e42de26 | 2010-09-10 06:41:19 +0000 | [diff] [blame] | 1066 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1067 | |
Ben Hutchings | e332bcb | 2011-12-20 01:22:51 +0000 | [diff] [blame] | 1068 | /* Initialise MAC address to permanent address */ |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1069 | ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1070 | |
| 1071 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static int efx_init_port(struct efx_nic *efx) |
| 1075 | { |
| 1076 | int rc; |
| 1077 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1078 | netif_dbg(efx, drv, efx->net_dev, "init port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1079 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1080 | mutex_lock(&efx->mac_lock); |
| 1081 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1082 | rc = efx->phy_op->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1083 | if (rc) |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1084 | goto fail1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1085 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1086 | efx->port_initialized = true; |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1087 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1088 | /* Reconfigure the MAC before creating dma queues (required for |
| 1089 | * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */ |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1090 | efx_mac_reconfigure(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1091 | |
| 1092 | /* Ensure the PHY advertises the correct flow control settings */ |
| 1093 | rc = efx->phy_op->reconfigure(efx); |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 1094 | if (rc && rc != -EPERM) |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1095 | goto fail2; |
| 1096 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1097 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1098 | return 0; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1099 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1100 | fail2: |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1101 | efx->phy_op->fini(efx); |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1102 | fail1: |
| 1103 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1104 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1107 | static void efx_start_port(struct efx_nic *efx) |
| 1108 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1109 | netif_dbg(efx, ifup, efx->net_dev, "start port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1110 | BUG_ON(efx->port_enabled); |
| 1111 | |
| 1112 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1113 | efx->port_enabled = true; |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1114 | |
Ben Hutchings | d615c03 | 2013-10-08 17:33:20 +0100 | [diff] [blame] | 1115 | /* Ensure MAC ingress/egress is enabled */ |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1116 | efx_mac_reconfigure(efx); |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1117 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1118 | mutex_unlock(&efx->mac_lock); |
| 1119 | } |
| 1120 | |
Ben Hutchings | d615c03 | 2013-10-08 17:33:20 +0100 | [diff] [blame] | 1121 | /* Cancel work for MAC reconfiguration, periodic hardware monitoring |
| 1122 | * and the async self-test, wait for them to finish and prevent them |
| 1123 | * being scheduled again. This doesn't cover online resets, which |
| 1124 | * should only be cancelled when removing the device. |
| 1125 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1126 | static void efx_stop_port(struct efx_nic *efx) |
| 1127 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1128 | netif_dbg(efx, ifdown, efx->net_dev, "stop port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1129 | |
Ben Hutchings | d615c03 | 2013-10-08 17:33:20 +0100 | [diff] [blame] | 1130 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1131 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1132 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1133 | efx->port_enabled = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1134 | mutex_unlock(&efx->mac_lock); |
| 1135 | |
| 1136 | /* Serialise against efx_set_multicast_list() */ |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 1137 | netif_addr_lock_bh(efx->net_dev); |
| 1138 | netif_addr_unlock_bh(efx->net_dev); |
Ben Hutchings | d615c03 | 2013-10-08 17:33:20 +0100 | [diff] [blame] | 1139 | |
| 1140 | cancel_delayed_work_sync(&efx->monitor_work); |
| 1141 | efx_selftest_async_cancel(efx); |
| 1142 | cancel_work_sync(&efx->mac_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static void efx_fini_port(struct efx_nic *efx) |
| 1146 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1147 | netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1148 | |
| 1149 | if (!efx->port_initialized) |
| 1150 | return; |
| 1151 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1152 | efx->phy_op->fini(efx); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1153 | efx->port_initialized = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1154 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1155 | efx->link_state.up = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1156 | efx_link_status_changed(efx); |
| 1157 | } |
| 1158 | |
| 1159 | static void efx_remove_port(struct efx_nic *efx) |
| 1160 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1161 | netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1162 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1163 | efx->type->remove_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | /************************************************************************** |
| 1167 | * |
| 1168 | * NIC handling |
| 1169 | * |
| 1170 | **************************************************************************/ |
| 1171 | |
Ben Hutchings | 0bcf4a6 | 2013-10-18 19:21:45 +0100 | [diff] [blame] | 1172 | static LIST_HEAD(efx_primary_list); |
| 1173 | static LIST_HEAD(efx_unassociated_list); |
| 1174 | |
| 1175 | static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right) |
| 1176 | { |
| 1177 | return left->type == right->type && |
| 1178 | left->vpd_sn && right->vpd_sn && |
| 1179 | !strcmp(left->vpd_sn, right->vpd_sn); |
| 1180 | } |
| 1181 | |
| 1182 | static void efx_associate(struct efx_nic *efx) |
| 1183 | { |
| 1184 | struct efx_nic *other, *next; |
| 1185 | |
| 1186 | if (efx->primary == efx) { |
| 1187 | /* Adding primary function; look for secondaries */ |
| 1188 | |
| 1189 | netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n"); |
| 1190 | list_add_tail(&efx->node, &efx_primary_list); |
| 1191 | |
| 1192 | list_for_each_entry_safe(other, next, &efx_unassociated_list, |
| 1193 | node) { |
| 1194 | if (efx_same_controller(efx, other)) { |
| 1195 | list_del(&other->node); |
| 1196 | netif_dbg(other, probe, other->net_dev, |
| 1197 | "moving to secondary list of %s %s\n", |
| 1198 | pci_name(efx->pci_dev), |
| 1199 | efx->net_dev->name); |
| 1200 | list_add_tail(&other->node, |
| 1201 | &efx->secondary_list); |
| 1202 | other->primary = efx; |
| 1203 | } |
| 1204 | } |
| 1205 | } else { |
| 1206 | /* Adding secondary function; look for primary */ |
| 1207 | |
| 1208 | list_for_each_entry(other, &efx_primary_list, node) { |
| 1209 | if (efx_same_controller(efx, other)) { |
| 1210 | netif_dbg(efx, probe, efx->net_dev, |
| 1211 | "adding to secondary list of %s %s\n", |
| 1212 | pci_name(other->pci_dev), |
| 1213 | other->net_dev->name); |
| 1214 | list_add_tail(&efx->node, |
| 1215 | &other->secondary_list); |
| 1216 | efx->primary = other; |
| 1217 | return; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | netif_dbg(efx, probe, efx->net_dev, |
| 1222 | "adding to unassociated list\n"); |
| 1223 | list_add_tail(&efx->node, &efx_unassociated_list); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | static void efx_dissociate(struct efx_nic *efx) |
| 1228 | { |
| 1229 | struct efx_nic *other, *next; |
| 1230 | |
| 1231 | list_del(&efx->node); |
| 1232 | efx->primary = NULL; |
| 1233 | |
| 1234 | list_for_each_entry_safe(other, next, &efx->secondary_list, node) { |
| 1235 | list_del(&other->node); |
| 1236 | netif_dbg(other, probe, other->net_dev, |
| 1237 | "moving to unassociated list\n"); |
| 1238 | list_add_tail(&other->node, &efx_unassociated_list); |
| 1239 | other->primary = NULL; |
| 1240 | } |
| 1241 | } |
| 1242 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1243 | /* This configures the PCI device to enable I/O and DMA. */ |
| 1244 | static int efx_init_io(struct efx_nic *efx) |
| 1245 | { |
| 1246 | struct pci_dev *pci_dev = efx->pci_dev; |
| 1247 | dma_addr_t dma_mask = efx->type->max_dma_mask; |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1248 | unsigned int mem_map_size = efx->type->mem_map_size(efx); |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1249 | int rc, bar; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1250 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1251 | netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1252 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1253 | bar = efx->type->mem_bar; |
| 1254 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1255 | rc = pci_enable_device(pci_dev); |
| 1256 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1257 | netif_err(efx, probe, efx->net_dev, |
| 1258 | "failed to enable PCI device\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1259 | goto fail1; |
| 1260 | } |
| 1261 | |
| 1262 | pci_set_master(pci_dev); |
| 1263 | |
| 1264 | /* Set the PCI DMA mask. Try all possibilities from our |
| 1265 | * genuine mask down to 32 bits, because some architectures |
| 1266 | * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit |
| 1267 | * masks event though they reject 46 bit masks. |
| 1268 | */ |
| 1269 | while (dma_mask > 0x7fffffffUL) { |
Christoph Hellwig | 8722b8f | 2015-11-10 14:45:42 -0800 | [diff] [blame] | 1270 | rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask); |
| 1271 | if (rc == 0) |
| 1272 | break; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1273 | dma_mask >>= 1; |
| 1274 | } |
| 1275 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1276 | netif_err(efx, probe, efx->net_dev, |
| 1277 | "could not find a suitable DMA mask\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1278 | goto fail2; |
| 1279 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1280 | netif_dbg(efx, probe, efx->net_dev, |
| 1281 | "using DMA mask %llx\n", (unsigned long long) dma_mask); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1282 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1283 | efx->membase_phys = pci_resource_start(efx->pci_dev, bar); |
| 1284 | rc = pci_request_region(pci_dev, bar, "sfc"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1285 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1286 | netif_err(efx, probe, efx->net_dev, |
| 1287 | "request for memory BAR failed\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1288 | rc = -EIO; |
| 1289 | goto fail3; |
| 1290 | } |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1291 | efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1292 | if (!efx->membase) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1293 | netif_err(efx, probe, efx->net_dev, |
| 1294 | "could not map memory BAR at %llx+%x\n", |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1295 | (unsigned long long)efx->membase_phys, mem_map_size); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1296 | rc = -ENOMEM; |
| 1297 | goto fail4; |
| 1298 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1299 | netif_dbg(efx, probe, efx->net_dev, |
| 1300 | "memory BAR at %llx+%x (virtual %p)\n", |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1301 | (unsigned long long)efx->membase_phys, mem_map_size, |
| 1302 | efx->membase); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1303 | |
| 1304 | return 0; |
| 1305 | |
| 1306 | fail4: |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1307 | pci_release_region(efx->pci_dev, bar); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1308 | fail3: |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 1309 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1310 | fail2: |
| 1311 | pci_disable_device(efx->pci_dev); |
| 1312 | fail1: |
| 1313 | return rc; |
| 1314 | } |
| 1315 | |
| 1316 | static void efx_fini_io(struct efx_nic *efx) |
| 1317 | { |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1318 | int bar; |
| 1319 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1320 | netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1321 | |
| 1322 | if (efx->membase) { |
| 1323 | iounmap(efx->membase); |
| 1324 | efx->membase = NULL; |
| 1325 | } |
| 1326 | |
| 1327 | if (efx->membase_phys) { |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1328 | bar = efx->type->mem_bar; |
| 1329 | pci_release_region(efx->pci_dev, bar); |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 1330 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 1333 | /* Don't disable bus-mastering if VFs are assigned */ |
| 1334 | if (!pci_vfs_assigned(efx->pci_dev)) |
| 1335 | pci_disable_device(efx->pci_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1338 | void efx_set_default_rx_indir_table(struct efx_nic *efx) |
| 1339 | { |
| 1340 | size_t i; |
| 1341 | |
| 1342 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) |
| 1343 | efx->rx_indir_table[i] = |
| 1344 | ethtool_rxfh_indir_default(i, efx->rss_spread); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
Ben Hutchings | a9a52506 | 2012-02-14 20:15:57 +0000 | [diff] [blame] | 1347 | static unsigned int efx_wanted_parallelism(struct efx_nic *efx) |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1348 | { |
Ben Hutchings | cdb08f8 | 2011-12-20 01:08:05 +0000 | [diff] [blame] | 1349 | cpumask_var_t thread_mask; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1350 | unsigned int count; |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1351 | int cpu; |
| 1352 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1353 | if (rss_cpus) { |
| 1354 | count = rss_cpus; |
| 1355 | } else { |
| 1356 | if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) { |
| 1357 | netif_warn(efx, probe, efx->net_dev, |
| 1358 | "RSS disabled due to allocation failure\n"); |
| 1359 | return 1; |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1360 | } |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1361 | |
| 1362 | count = 0; |
| 1363 | for_each_online_cpu(cpu) { |
| 1364 | if (!cpumask_test_cpu(cpu, thread_mask)) { |
| 1365 | ++count; |
| 1366 | cpumask_or(thread_mask, thread_mask, |
Bartosz Golaszewski | 06931e6 | 2015-05-26 15:11:28 +0200 | [diff] [blame] | 1367 | topology_sibling_cpumask(cpu)); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | free_cpumask_var(thread_mask); |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
Bert Kenward | 271a8b4 | 2017-04-12 17:06:52 +0100 | [diff] [blame] | 1374 | if (count > EFX_MAX_RX_QUEUES) { |
| 1375 | netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn, |
| 1376 | "Reducing number of rx queues from %u to %u.\n", |
| 1377 | count, EFX_MAX_RX_QUEUES); |
| 1378 | count = EFX_MAX_RX_QUEUES; |
| 1379 | } |
| 1380 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1381 | /* If RSS is requested for the PF *and* VFs then we can't write RSS |
| 1382 | * table entries that are inaccessible to VFs |
| 1383 | */ |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 1384 | #ifdef CONFIG_SFC_SRIOV |
| 1385 | if (efx->type->sriov_wanted) { |
| 1386 | if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 && |
| 1387 | count > efx_vf_size(efx)) { |
| 1388 | netif_warn(efx, probe, efx->net_dev, |
| 1389 | "Reducing number of RSS channels from %u to %u for " |
| 1390 | "VF support. Increase vf-msix-limit to use more " |
| 1391 | "channels on the PF.\n", |
| 1392 | count, efx_vf_size(efx)); |
| 1393 | count = efx_vf_size(efx); |
| 1394 | } |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1395 | } |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 1396 | #endif |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1397 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1398 | return count; |
| 1399 | } |
| 1400 | |
| 1401 | /* Probe the number and type of interrupts we are able to obtain, and |
| 1402 | * the resulting numbers of channels and RX queues. |
| 1403 | */ |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1404 | static int efx_probe_interrupts(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1405 | { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1406 | unsigned int extra_channels = 0; |
| 1407 | unsigned int i, j; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1408 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1409 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1410 | for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) |
| 1411 | if (efx->extra_channel_type[i]) |
| 1412 | ++extra_channels; |
| 1413 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1414 | if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1415 | struct msix_entry xentries[EFX_MAX_CHANNELS]; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1416 | unsigned int n_channels; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1417 | |
Ben Hutchings | a9a52506 | 2012-02-14 20:15:57 +0000 | [diff] [blame] | 1418 | n_channels = efx_wanted_parallelism(efx); |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1419 | if (efx_separate_tx_channels) |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1420 | n_channels *= 2; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1421 | n_channels += extra_channels; |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1422 | n_channels = min(n_channels, efx->max_channels); |
Ben Hutchings | aa6ef27 | 2008-07-18 19:03:10 +0100 | [diff] [blame] | 1423 | |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1424 | for (i = 0; i < n_channels; i++) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1425 | xentries[i].entry = i; |
Alexander Gordeev | 184603d | 2014-02-18 11:12:00 +0100 | [diff] [blame] | 1426 | rc = pci_enable_msix_range(efx->pci_dev, |
| 1427 | xentries, 1, n_channels); |
| 1428 | if (rc < 0) { |
| 1429 | /* Fall back to single channel MSI */ |
Alexander Gordeev | 184603d | 2014-02-18 11:12:00 +0100 | [diff] [blame] | 1430 | netif_err(efx, drv, efx->net_dev, |
| 1431 | "could not enable MSI-X\n"); |
Andrew Rybchenko | 62980cb | 2017-02-13 14:59:04 +0000 | [diff] [blame] | 1432 | if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI) |
| 1433 | efx->interrupt_mode = EFX_INT_MODE_MSI; |
| 1434 | else |
| 1435 | return rc; |
Alexander Gordeev | 184603d | 2014-02-18 11:12:00 +0100 | [diff] [blame] | 1436 | } else if (rc < n_channels) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1437 | netif_err(efx, drv, efx->net_dev, |
| 1438 | "WARNING: Insufficient MSI-X vectors" |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1439 | " available (%d < %u).\n", rc, n_channels); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1440 | netif_err(efx, drv, efx->net_dev, |
| 1441 | "WARNING: Performance may be reduced.\n"); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1442 | n_channels = rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1443 | } |
| 1444 | |
Alexander Gordeev | 184603d | 2014-02-18 11:12:00 +0100 | [diff] [blame] | 1445 | if (rc > 0) { |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1446 | efx->n_channels = n_channels; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1447 | if (n_channels > extra_channels) |
| 1448 | n_channels -= extra_channels; |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1449 | if (efx_separate_tx_channels) { |
| 1450 | efx->n_tx_channels = min(max(n_channels / 2, |
| 1451 | 1U), |
| 1452 | efx->max_tx_channels); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1453 | efx->n_rx_channels = max(n_channels - |
| 1454 | efx->n_tx_channels, |
| 1455 | 1U); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1456 | } else { |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1457 | efx->n_tx_channels = min(n_channels, |
| 1458 | efx->max_tx_channels); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1459 | efx->n_rx_channels = n_channels; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1460 | } |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1461 | for (i = 0; i < efx->n_channels; i++) |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1462 | efx_get_channel(efx, i)->irq = |
| 1463 | xentries[i].vector; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | /* Try single interrupt MSI */ |
| 1468 | if (efx->interrupt_mode == EFX_INT_MODE_MSI) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 1469 | efx->n_channels = 1; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1470 | efx->n_rx_channels = 1; |
| 1471 | efx->n_tx_channels = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1472 | rc = pci_enable_msi(efx->pci_dev); |
| 1473 | if (rc == 0) { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1474 | efx_get_channel(efx, 0)->irq = efx->pci_dev->irq; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1475 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1476 | netif_err(efx, drv, efx->net_dev, |
| 1477 | "could not enable MSI\n"); |
Andrew Rybchenko | 62980cb | 2017-02-13 14:59:04 +0000 | [diff] [blame] | 1478 | if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY) |
| 1479 | efx->interrupt_mode = EFX_INT_MODE_LEGACY; |
| 1480 | else |
| 1481 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | /* Assume legacy interrupts */ |
| 1486 | if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1487 | efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1488 | efx->n_rx_channels = 1; |
| 1489 | efx->n_tx_channels = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1490 | efx->legacy_irq = efx->pci_dev->irq; |
| 1491 | } |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1492 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1493 | /* Assign extra channels if possible */ |
| 1494 | j = efx->n_channels; |
| 1495 | for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { |
| 1496 | if (!efx->extra_channel_type[i]) |
| 1497 | continue; |
| 1498 | if (efx->interrupt_mode != EFX_INT_MODE_MSIX || |
| 1499 | efx->n_channels <= extra_channels) { |
| 1500 | efx->extra_channel_type[i]->handle_no_channel(efx); |
| 1501 | } else { |
| 1502 | --j; |
| 1503 | efx_get_channel(efx, j)->type = |
| 1504 | efx->extra_channel_type[i]; |
| 1505 | } |
| 1506 | } |
| 1507 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1508 | /* RSS might be usable on VFs even if it is disabled on the PF */ |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 1509 | #ifdef CONFIG_SFC_SRIOV |
| 1510 | if (efx->type->sriov_wanted) { |
| 1511 | efx->rss_spread = ((efx->n_rx_channels > 1 || |
| 1512 | !efx->type->sriov_wanted(efx)) ? |
| 1513 | efx->n_rx_channels : efx_vf_size(efx)); |
| 1514 | return 0; |
| 1515 | } |
| 1516 | #endif |
| 1517 | efx->rss_spread = efx->n_rx_channels; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1518 | |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1519 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1520 | } |
| 1521 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1522 | static int efx_soft_enable_interrupts(struct efx_nic *efx) |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1523 | { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1524 | struct efx_channel *channel, *end_channel; |
| 1525 | int rc; |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1526 | |
| 1527 | BUG_ON(efx->state == STATE_DISABLED); |
| 1528 | |
| 1529 | efx->irq_soft_enabled = true; |
| 1530 | smp_wmb(); |
| 1531 | |
| 1532 | efx_for_each_channel(channel, efx) { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1533 | if (!channel->type->keep_eventq) { |
| 1534 | rc = efx_init_eventq(channel); |
| 1535 | if (rc) |
| 1536 | goto fail; |
| 1537 | } |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1538 | efx_start_eventq(channel); |
| 1539 | } |
| 1540 | |
| 1541 | efx_mcdi_mode_event(efx); |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1542 | |
| 1543 | return 0; |
| 1544 | fail: |
| 1545 | end_channel = channel; |
| 1546 | efx_for_each_channel(channel, efx) { |
| 1547 | if (channel == end_channel) |
| 1548 | break; |
| 1549 | efx_stop_eventq(channel); |
| 1550 | if (!channel->type->keep_eventq) |
| 1551 | efx_fini_eventq(channel); |
| 1552 | } |
| 1553 | |
| 1554 | return rc; |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | static void efx_soft_disable_interrupts(struct efx_nic *efx) |
| 1558 | { |
| 1559 | struct efx_channel *channel; |
| 1560 | |
| 1561 | if (efx->state == STATE_DISABLED) |
| 1562 | return; |
| 1563 | |
| 1564 | efx_mcdi_mode_poll(efx); |
| 1565 | |
| 1566 | efx->irq_soft_enabled = false; |
| 1567 | smp_wmb(); |
| 1568 | |
| 1569 | if (efx->legacy_irq) |
| 1570 | synchronize_irq(efx->legacy_irq); |
| 1571 | |
| 1572 | efx_for_each_channel(channel, efx) { |
| 1573 | if (channel->irq) |
| 1574 | synchronize_irq(channel->irq); |
| 1575 | |
| 1576 | efx_stop_eventq(channel); |
| 1577 | if (!channel->type->keep_eventq) |
| 1578 | efx_fini_eventq(channel); |
| 1579 | } |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 1580 | |
| 1581 | /* Flush the asynchronous MCDI request queue */ |
| 1582 | efx_mcdi_flush_async(efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1583 | } |
| 1584 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1585 | static int efx_enable_interrupts(struct efx_nic *efx) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1586 | { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1587 | struct efx_channel *channel, *end_channel; |
| 1588 | int rc; |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1589 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 1590 | BUG_ON(efx->state == STATE_DISABLED); |
| 1591 | |
Alexandre Rames | b28405b | 2013-03-21 16:41:43 +0000 | [diff] [blame] | 1592 | if (efx->eeh_disabled_legacy_irq) { |
| 1593 | enable_irq(efx->legacy_irq); |
| 1594 | efx->eeh_disabled_legacy_irq = false; |
| 1595 | } |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1596 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1597 | efx->type->irq_enable_master(efx); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1598 | |
| 1599 | efx_for_each_channel(channel, efx) { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1600 | if (channel->type->keep_eventq) { |
| 1601 | rc = efx_init_eventq(channel); |
| 1602 | if (rc) |
| 1603 | goto fail; |
| 1604 | } |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 1607 | rc = efx_soft_enable_interrupts(efx); |
| 1608 | if (rc) |
| 1609 | goto fail; |
| 1610 | |
| 1611 | return 0; |
| 1612 | |
| 1613 | fail: |
| 1614 | end_channel = channel; |
| 1615 | efx_for_each_channel(channel, efx) { |
| 1616 | if (channel == end_channel) |
| 1617 | break; |
| 1618 | if (channel->type->keep_eventq) |
| 1619 | efx_fini_eventq(channel); |
| 1620 | } |
| 1621 | |
| 1622 | efx->type->irq_disable_non_ev(efx); |
| 1623 | |
| 1624 | return rc; |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1627 | static void efx_disable_interrupts(struct efx_nic *efx) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1628 | { |
| 1629 | struct efx_channel *channel; |
| 1630 | |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1631 | efx_soft_disable_interrupts(efx); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1632 | |
| 1633 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1634 | if (channel->type->keep_eventq) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1635 | efx_fini_eventq(channel); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1636 | } |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 1637 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1638 | efx->type->irq_disable_non_ev(efx); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1641 | static void efx_remove_interrupts(struct efx_nic *efx) |
| 1642 | { |
| 1643 | struct efx_channel *channel; |
| 1644 | |
| 1645 | /* Remove MSI/MSI-X interrupts */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 1646 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1647 | channel->irq = 0; |
| 1648 | pci_disable_msi(efx->pci_dev); |
| 1649 | pci_disable_msix(efx->pci_dev); |
| 1650 | |
| 1651 | /* Remove legacy interrupt */ |
| 1652 | efx->legacy_irq = 0; |
| 1653 | } |
| 1654 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 1655 | static void efx_set_channels(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1656 | { |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1657 | struct efx_channel *channel; |
| 1658 | struct efx_tx_queue *tx_queue; |
| 1659 | |
Ben Hutchings | 9765343 | 2011-01-12 18:26:56 +0000 | [diff] [blame] | 1660 | efx->tx_channel_offset = |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1661 | efx_separate_tx_channels ? |
| 1662 | efx->n_channels - efx->n_tx_channels : 0; |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1663 | |
Stuart Hodgson | 79d68b3 | 2012-07-16 17:08:33 +0100 | [diff] [blame] | 1664 | /* We need to mark which channels really have RX and TX |
| 1665 | * queues, and adjust the TX queue numbers if we have separate |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1666 | * RX-only and TX-only channels. |
| 1667 | */ |
| 1668 | efx_for_each_channel(channel, efx) { |
Stuart Hodgson | 79d68b3 | 2012-07-16 17:08:33 +0100 | [diff] [blame] | 1669 | if (channel->channel < efx->n_rx_channels) |
| 1670 | channel->rx_queue.core_index = channel->channel; |
| 1671 | else |
| 1672 | channel->rx_queue.core_index = -1; |
| 1673 | |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1674 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 1675 | tx_queue->queue -= (efx->tx_channel_offset * |
| 1676 | EFX_TXQ_TYPES); |
| 1677 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | static int efx_probe_nic(struct efx_nic *efx) |
| 1681 | { |
| 1682 | int rc; |
| 1683 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1684 | netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1685 | |
| 1686 | /* Carry out hardware-type specific initialisation */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1687 | rc = efx->type->probe(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1688 | if (rc) |
| 1689 | return rc; |
| 1690 | |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1691 | do { |
| 1692 | if (!efx->max_channels || !efx->max_tx_channels) { |
| 1693 | netif_err(efx, drv, efx->net_dev, |
| 1694 | "Insufficient resources to allocate" |
| 1695 | " any channels\n"); |
| 1696 | rc = -ENOSPC; |
| 1697 | goto fail1; |
| 1698 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1699 | |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1700 | /* Determine the number of channels and queues by trying |
| 1701 | * to hook in MSI-X interrupts. |
| 1702 | */ |
| 1703 | rc = efx_probe_interrupts(efx); |
| 1704 | if (rc) |
| 1705 | goto fail1; |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 1706 | |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1707 | efx_set_channels(efx); |
| 1708 | |
| 1709 | /* dimension_resources can fail with EAGAIN */ |
| 1710 | rc = efx->type->dimension_resources(efx); |
| 1711 | if (rc != 0 && rc != -EAGAIN) |
| 1712 | goto fail2; |
| 1713 | |
| 1714 | if (rc == -EAGAIN) |
| 1715 | /* try again with new max_channels */ |
| 1716 | efx_remove_interrupts(efx); |
| 1717 | |
| 1718 | } while (rc == -EAGAIN); |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 1719 | |
Ben Hutchings | 5d3a6fc | 2010-06-25 07:05:43 +0000 | [diff] [blame] | 1720 | if (efx->n_channels > 1) |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1721 | netdev_rss_key_fill(&efx->rx_hash_key, |
| 1722 | sizeof(efx->rx_hash_key)); |
| 1723 | efx_set_default_rx_indir_table(efx); |
Ben Hutchings | 5d3a6fc | 2010-06-25 07:05:43 +0000 | [diff] [blame] | 1724 | |
Ben Hutchings | c4f4adc | 2010-09-27 08:31:07 +0000 | [diff] [blame] | 1725 | netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels); |
| 1726 | netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1727 | |
| 1728 | /* Initialise the interrupt moderation settings */ |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1729 | efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000); |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1730 | efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, |
| 1731 | true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1732 | |
| 1733 | return 0; |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1734 | |
Ben Hutchings | c15eed2 | 2013-08-29 00:45:48 +0100 | [diff] [blame] | 1735 | fail2: |
| 1736 | efx_remove_interrupts(efx); |
| 1737 | fail1: |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1738 | efx->type->remove(efx); |
| 1739 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | static void efx_remove_nic(struct efx_nic *efx) |
| 1743 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1744 | netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1745 | |
| 1746 | efx_remove_interrupts(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1747 | efx->type->remove(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1750 | static int efx_probe_filters(struct efx_nic *efx) |
| 1751 | { |
| 1752 | int rc; |
| 1753 | |
| 1754 | spin_lock_init(&efx->filter_lock); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1755 | init_rwsem(&efx->filter_sem); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 1756 | mutex_lock(&efx->mac_lock); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1757 | down_write(&efx->filter_sem); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1758 | rc = efx->type->filter_table_probe(efx); |
| 1759 | if (rc) |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1760 | goto out_unlock; |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1761 | |
| 1762 | #ifdef CONFIG_RFS_ACCEL |
| 1763 | if (efx->type->offload_features & NETIF_F_NTUPLE) { |
Jon Cooper | faf8dcc | 2016-05-31 19:12:32 +0100 | [diff] [blame] | 1764 | struct efx_channel *channel; |
| 1765 | int i, success = 1; |
| 1766 | |
| 1767 | efx_for_each_channel(channel, efx) { |
| 1768 | channel->rps_flow_id = |
| 1769 | kcalloc(efx->type->max_rx_ip_filters, |
| 1770 | sizeof(*channel->rps_flow_id), |
| 1771 | GFP_KERNEL); |
| 1772 | if (!channel->rps_flow_id) |
| 1773 | success = 0; |
| 1774 | else |
| 1775 | for (i = 0; |
| 1776 | i < efx->type->max_rx_ip_filters; |
| 1777 | ++i) |
| 1778 | channel->rps_flow_id[i] = |
| 1779 | RPS_FLOW_ID_INVALID; |
| 1780 | } |
| 1781 | |
| 1782 | if (!success) { |
| 1783 | efx_for_each_channel(channel, efx) |
| 1784 | kfree(channel->rps_flow_id); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1785 | efx->type->filter_table_remove(efx); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1786 | rc = -ENOMEM; |
| 1787 | goto out_unlock; |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1788 | } |
Jon Cooper | faf8dcc | 2016-05-31 19:12:32 +0100 | [diff] [blame] | 1789 | |
| 1790 | efx->rps_expire_index = efx->rps_expire_channel = 0; |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1791 | } |
| 1792 | #endif |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1793 | out_unlock: |
| 1794 | up_write(&efx->filter_sem); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 1795 | mutex_unlock(&efx->mac_lock); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1796 | return rc; |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | static void efx_remove_filters(struct efx_nic *efx) |
| 1800 | { |
| 1801 | #ifdef CONFIG_RFS_ACCEL |
Jon Cooper | faf8dcc | 2016-05-31 19:12:32 +0100 | [diff] [blame] | 1802 | struct efx_channel *channel; |
| 1803 | |
| 1804 | efx_for_each_channel(channel, efx) |
| 1805 | kfree(channel->rps_flow_id); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1806 | #endif |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1807 | down_write(&efx->filter_sem); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1808 | efx->type->filter_table_remove(efx); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1809 | up_write(&efx->filter_sem); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | static void efx_restore_filters(struct efx_nic *efx) |
| 1813 | { |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1814 | down_read(&efx->filter_sem); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1815 | efx->type->filter_table_restore(efx); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 1816 | up_read(&efx->filter_sem); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1819 | /************************************************************************** |
| 1820 | * |
| 1821 | * NIC startup/shutdown |
| 1822 | * |
| 1823 | *************************************************************************/ |
| 1824 | |
| 1825 | static int efx_probe_all(struct efx_nic *efx) |
| 1826 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1827 | int rc; |
| 1828 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1829 | rc = efx_probe_nic(efx); |
| 1830 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1831 | netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1832 | goto fail1; |
| 1833 | } |
| 1834 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1835 | rc = efx_probe_port(efx); |
| 1836 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1837 | netif_err(efx, probe, efx->net_dev, "failed to create port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1838 | goto fail2; |
| 1839 | } |
| 1840 | |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 1841 | BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); |
| 1842 | if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { |
| 1843 | rc = -EINVAL; |
| 1844 | goto fail3; |
| 1845 | } |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 1846 | efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1847 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1848 | #ifdef CONFIG_SFC_SRIOV |
| 1849 | rc = efx->type->vswitching_probe(efx); |
| 1850 | if (rc) /* not fatal; the PF will still work fine */ |
| 1851 | netif_warn(efx, probe, efx->net_dev, |
| 1852 | "failed to setup vswitching rc=%d;" |
| 1853 | " VFs may not function\n", rc); |
| 1854 | #endif |
| 1855 | |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1856 | rc = efx_probe_filters(efx); |
| 1857 | if (rc) { |
| 1858 | netif_err(efx, probe, efx->net_dev, |
| 1859 | "failed to create filter tables\n"); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1860 | goto fail4; |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1863 | rc = efx_probe_channels(efx); |
| 1864 | if (rc) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1865 | goto fail5; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1866 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1867 | return 0; |
| 1868 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1869 | fail5: |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1870 | efx_remove_filters(efx); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1871 | fail4: |
| 1872 | #ifdef CONFIG_SFC_SRIOV |
| 1873 | efx->type->vswitching_remove(efx); |
| 1874 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1875 | fail3: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1876 | efx_remove_port(efx); |
| 1877 | fail2: |
| 1878 | efx_remove_nic(efx); |
| 1879 | fail1: |
| 1880 | return rc; |
| 1881 | } |
| 1882 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 1883 | /* If the interface is supposed to be running but is not, start |
| 1884 | * the hardware and software data path, regular activity for the port |
| 1885 | * (MAC statistics, link polling, etc.) and schedule the port to be |
| 1886 | * reconfigured. Interrupts must already be enabled. This function |
| 1887 | * is safe to call multiple times, so long as the NIC is not disabled. |
| 1888 | * Requires the RTNL lock. |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1889 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1890 | static void efx_start_all(struct efx_nic *efx) |
| 1891 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1892 | EFX_ASSERT_RESET_SERIALISED(efx); |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 1893 | BUG_ON(efx->state == STATE_DISABLED); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1894 | |
| 1895 | /* Check that it is appropriate to restart the interface. All |
| 1896 | * of these flags are safe to read under just the rtnl lock */ |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 1897 | if (efx->port_enabled || !netif_running(efx->net_dev) || |
| 1898 | efx->reset_pending) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1899 | return; |
| 1900 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1901 | efx_start_port(efx); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1902 | efx_start_datapath(efx); |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 1903 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 1904 | /* Start the hardware monitor if there is one */ |
| 1905 | if (efx->type->monitor != NULL) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1906 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 1907 | efx_monitor_interval); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 1908 | |
Edward Cree | 5a6681e | 2016-11-28 18:55:34 +0000 | [diff] [blame] | 1909 | /* Link state detection is normally event-driven; we have |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 1910 | * to poll now because we could have missed a change |
| 1911 | */ |
Edward Cree | 5a6681e | 2016-11-28 18:55:34 +0000 | [diff] [blame] | 1912 | mutex_lock(&efx->mac_lock); |
| 1913 | if (efx->phy_op->poll(efx)) |
| 1914 | efx_link_status_changed(efx); |
| 1915 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1916 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1917 | efx->type->start_stats(efx); |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 1918 | efx->type->pull_stats(efx); |
| 1919 | spin_lock_bh(&efx->stats_lock); |
| 1920 | efx->type->update_stats(efx, NULL, NULL); |
| 1921 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1922 | } |
| 1923 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 1924 | /* Quiesce the hardware and software data path, and regular activity |
| 1925 | * for the port without bringing the link down. Safe to call multiple |
| 1926 | * times with the NIC in almost any state, but interrupts should be |
| 1927 | * enabled. Requires the RTNL lock. |
| 1928 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1929 | static void efx_stop_all(struct efx_nic *efx) |
| 1930 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1931 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1932 | |
| 1933 | /* port_enabled can be read safely under the rtnl lock */ |
| 1934 | if (!efx->port_enabled) |
| 1935 | return; |
| 1936 | |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 1937 | /* update stats before we go down so we can accurately count |
| 1938 | * rx_nodesc_drops |
| 1939 | */ |
| 1940 | efx->type->pull_stats(efx); |
| 1941 | spin_lock_bh(&efx->stats_lock); |
| 1942 | efx->type->update_stats(efx, NULL, NULL); |
| 1943 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1944 | efx->type->stop_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1945 | efx_stop_port(efx); |
| 1946 | |
Ben Hutchings | 29c69a4 | 2013-01-28 19:01:06 +0000 | [diff] [blame] | 1947 | /* Stop the kernel transmit interface. This is only valid if |
| 1948 | * the device is stopped or detached; otherwise the watchdog |
| 1949 | * may fire immediately. |
| 1950 | */ |
| 1951 | WARN_ON(netif_running(efx->net_dev) && |
| 1952 | netif_device_present(efx->net_dev)); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1953 | netif_tx_disable(efx->net_dev); |
| 1954 | |
| 1955 | efx_stop_datapath(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | static void efx_remove_all(struct efx_nic *efx) |
| 1959 | { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 1960 | efx_remove_channels(efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1961 | efx_remove_filters(efx); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1962 | #ifdef CONFIG_SFC_SRIOV |
| 1963 | efx->type->vswitching_remove(efx); |
| 1964 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1965 | efx_remove_port(efx); |
| 1966 | efx_remove_nic(efx); |
| 1967 | } |
| 1968 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1969 | /************************************************************************** |
| 1970 | * |
| 1971 | * Interrupt moderation |
| 1972 | * |
| 1973 | **************************************************************************/ |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1974 | unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs) |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1975 | { |
Ben Hutchings | b548f97 | 2011-09-05 07:41:44 +0000 | [diff] [blame] | 1976 | if (usecs == 0) |
| 1977 | return 0; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1978 | if (usecs * 1000 < efx->timer_quantum_ns) |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1979 | return 1; /* never round down to 0 */ |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1980 | return usecs * 1000 / efx->timer_quantum_ns; |
| 1981 | } |
| 1982 | |
| 1983 | unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks) |
| 1984 | { |
| 1985 | /* We must round up when converting ticks to microseconds |
| 1986 | * because we round down when converting the other way. |
| 1987 | */ |
| 1988 | return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000); |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1991 | /* Set interrupt moderation parameters */ |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1992 | int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, |
| 1993 | unsigned int rx_usecs, bool rx_adaptive, |
| 1994 | bool rx_may_override_tx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1995 | { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1996 | struct efx_channel *channel; |
Bert Kenward | d95e329 | 2016-08-11 13:02:36 +0100 | [diff] [blame] | 1997 | unsigned int timer_max_us; |
| 1998 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1999 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 2000 | |
Bert Kenward | d95e329 | 2016-08-11 13:02:36 +0100 | [diff] [blame] | 2001 | timer_max_us = efx->timer_max_ns / 1000; |
| 2002 | |
| 2003 | if (tx_usecs > timer_max_us || rx_usecs > timer_max_us) |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 2004 | return -EINVAL; |
| 2005 | |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2006 | if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 && |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 2007 | !rx_may_override_tx) { |
| 2008 | netif_err(efx, drv, efx->net_dev, "Channels are shared. " |
| 2009 | "RX and TX IRQ moderation must be equal\n"); |
| 2010 | return -EINVAL; |
| 2011 | } |
| 2012 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 2013 | efx->irq_rx_adaptive = rx_adaptive; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2014 | efx->irq_rx_moderation_us = rx_usecs; |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 2015 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 525da90 | 2011-02-07 23:04:38 +0000 | [diff] [blame] | 2016 | if (efx_channel_has_rx_queue(channel)) |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2017 | channel->irq_moderation_us = rx_usecs; |
Ben Hutchings | 525da90 | 2011-02-07 23:04:38 +0000 | [diff] [blame] | 2018 | else if (efx_channel_has_tx_queues(channel)) |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2019 | channel->irq_moderation_us = tx_usecs; |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 2020 | } |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 2021 | |
| 2022 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2023 | } |
| 2024 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 2025 | void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, |
| 2026 | unsigned int *rx_usecs, bool *rx_adaptive) |
| 2027 | { |
| 2028 | *rx_adaptive = efx->irq_rx_adaptive; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2029 | *rx_usecs = efx->irq_rx_moderation_us; |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 2030 | |
| 2031 | /* If channels are shared between RX and TX, so is IRQ |
| 2032 | * moderation. Otherwise, IRQ moderation is the same for all |
| 2033 | * TX channels and is not adaptive. |
| 2034 | */ |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2035 | if (efx->tx_channel_offset == 0) { |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 2036 | *tx_usecs = *rx_usecs; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 2037 | } else { |
| 2038 | struct efx_channel *tx_channel; |
| 2039 | |
| 2040 | tx_channel = efx->channel[efx->tx_channel_offset]; |
| 2041 | *tx_usecs = tx_channel->irq_moderation_us; |
| 2042 | } |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2045 | /************************************************************************** |
| 2046 | * |
| 2047 | * Hardware monitor |
| 2048 | * |
| 2049 | **************************************************************************/ |
| 2050 | |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 2051 | /* Run periodically off the general workqueue */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2052 | static void efx_monitor(struct work_struct *data) |
| 2053 | { |
| 2054 | struct efx_nic *efx = container_of(data, struct efx_nic, |
| 2055 | monitor_work.work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2056 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2057 | netif_vdbg(efx, timer, efx->net_dev, |
| 2058 | "hardware monitor executing on CPU %d\n", |
| 2059 | raw_smp_processor_id()); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2060 | BUG_ON(efx->type->monitor == NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2061 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2062 | /* If the mac_lock is already held then it is likely a port |
| 2063 | * reconfiguration is already in place, which will likely do |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 2064 | * most of the work of monitor() anyway. */ |
| 2065 | if (mutex_trylock(&efx->mac_lock)) { |
| 2066 | if (efx->port_enabled) |
| 2067 | efx->type->monitor(efx); |
| 2068 | mutex_unlock(&efx->mac_lock); |
| 2069 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2070 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2071 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 2072 | efx_monitor_interval); |
| 2073 | } |
| 2074 | |
| 2075 | /************************************************************************** |
| 2076 | * |
| 2077 | * ioctls |
| 2078 | * |
| 2079 | *************************************************************************/ |
| 2080 | |
| 2081 | /* Net device ioctl |
| 2082 | * Context: process, rtnl_lock() held. |
| 2083 | */ |
| 2084 | static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) |
| 2085 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2086 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 2087 | struct mii_ioctl_data *data = if_mii(ifr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2088 | |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 2089 | if (cmd == SIOCSHWTSTAMP) |
Ben Hutchings | 433dc9b | 2013-11-14 01:26:21 +0000 | [diff] [blame] | 2090 | return efx_ptp_set_ts_config(efx, ifr); |
| 2091 | if (cmd == SIOCGHWTSTAMP) |
| 2092 | return efx_ptp_get_ts_config(efx, ifr); |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 2093 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 2094 | /* Convert phy_id from older PRTAD/DEVAD format */ |
| 2095 | if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && |
| 2096 | (data->phy_id & 0xfc00) == 0x0400) |
| 2097 | data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; |
| 2098 | |
| 2099 | return mdio_mii_ioctl(&efx->mdio, data, cmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | /************************************************************************** |
| 2103 | * |
| 2104 | * NAPI interface |
| 2105 | * |
| 2106 | **************************************************************************/ |
| 2107 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2108 | static void efx_init_napi_channel(struct efx_channel *channel) |
| 2109 | { |
| 2110 | struct efx_nic *efx = channel->efx; |
| 2111 | |
| 2112 | channel->napi_dev = efx->net_dev; |
| 2113 | netif_napi_add(channel->napi_dev, &channel->napi_str, |
| 2114 | efx_poll, napi_weight); |
| 2115 | } |
| 2116 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2117 | static void efx_init_napi(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2118 | { |
| 2119 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2120 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2121 | efx_for_each_channel(channel, efx) |
| 2122 | efx_init_napi_channel(channel); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | static void efx_fini_napi_channel(struct efx_channel *channel) |
| 2126 | { |
Eric Dumazet | 973334a | 2016-11-16 06:01:47 -0800 | [diff] [blame] | 2127 | if (channel->napi_dev) |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2128 | netif_napi_del(&channel->napi_str); |
Eric Dumazet | 973334a | 2016-11-16 06:01:47 -0800 | [diff] [blame] | 2129 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2130 | channel->napi_dev = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static void efx_fini_napi(struct efx_nic *efx) |
| 2134 | { |
| 2135 | struct efx_channel *channel; |
| 2136 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2137 | efx_for_each_channel(channel, efx) |
| 2138 | efx_fini_napi_channel(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /************************************************************************** |
| 2142 | * |
| 2143 | * Kernel netpoll interface |
| 2144 | * |
| 2145 | *************************************************************************/ |
| 2146 | |
| 2147 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2148 | |
| 2149 | /* Although in the common case interrupts will be disabled, this is not |
| 2150 | * guaranteed. However, all our work happens inside the NAPI callback, |
| 2151 | * so no locking is required. |
| 2152 | */ |
| 2153 | static void efx_netpoll(struct net_device *net_dev) |
| 2154 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2155 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2156 | struct efx_channel *channel; |
| 2157 | |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 2158 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2159 | efx_schedule_channel(channel); |
| 2160 | } |
| 2161 | |
| 2162 | #endif |
| 2163 | |
| 2164 | /************************************************************************** |
| 2165 | * |
| 2166 | * Kernel net device interface |
| 2167 | * |
| 2168 | *************************************************************************/ |
| 2169 | |
| 2170 | /* Context: process, rtnl_lock() held. */ |
Shradha Shah | e340be9 | 2015-05-20 11:11:03 +0100 | [diff] [blame] | 2171 | int efx_net_open(struct net_device *net_dev) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2172 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2173 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 2174 | int rc; |
| 2175 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2176 | netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", |
| 2177 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2178 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 2179 | rc = efx_check_disabled(efx); |
| 2180 | if (rc) |
| 2181 | return rc; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 2182 | if (efx->phy_mode & PHY_MODE_SPECIAL) |
| 2183 | return -EBUSY; |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2184 | if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) |
| 2185 | return -EIO; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 2186 | |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 2187 | /* Notify the kernel of the link state polled during driver load, |
| 2188 | * before the monitor starts running */ |
| 2189 | efx_link_status_changed(efx); |
| 2190 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2191 | efx_start_all(efx); |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 2192 | if (efx->state == STATE_DISABLED || efx->reset_pending) |
| 2193 | netif_device_detach(efx->net_dev); |
Ben Hutchings | dd40781 | 2012-02-28 23:40:21 +0000 | [diff] [blame] | 2194 | efx_selftest_async_start(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2195 | return 0; |
| 2196 | } |
| 2197 | |
| 2198 | /* Context: process, rtnl_lock() held. |
| 2199 | * Note that the kernel will ignore our return code; this method |
| 2200 | * should really be a void. |
| 2201 | */ |
Shradha Shah | e340be9 | 2015-05-20 11:11:03 +0100 | [diff] [blame] | 2202 | int efx_net_stop(struct net_device *net_dev) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2203 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2204 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2205 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2206 | netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", |
| 2207 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2208 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 2209 | /* Stop the device and flush all the channels */ |
| 2210 | efx_stop_all(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2211 | |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 2215 | /* Context: process, dev_base_lock or RTNL held, non-blocking. */ |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 2216 | static void efx_net_stats(struct net_device *net_dev, |
| 2217 | struct rtnl_link_stats64 *stats) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2218 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2219 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2220 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2221 | spin_lock_bh(&efx->stats_lock); |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 2222 | efx->type->update_stats(efx, NULL, stats); |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 2223 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /* Context: netif_tx_lock held, BHs disabled. */ |
| 2227 | static void efx_watchdog(struct net_device *net_dev) |
| 2228 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2229 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2230 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2231 | netif_err(efx, tx_err, efx->net_dev, |
| 2232 | "TX stuck with port_enabled=%d: resetting channels\n", |
| 2233 | efx->port_enabled); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2234 | |
Ben Hutchings | 739bb23d | 2008-11-04 20:35:36 +0000 | [diff] [blame] | 2235 | efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | /* Context: process, rtnl_lock() held. */ |
| 2240 | static int efx_change_mtu(struct net_device *net_dev, int new_mtu) |
| 2241 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2242 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 2243 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2244 | |
Ben Hutchings | 8b7325b | 2012-07-27 20:46:41 +0100 | [diff] [blame] | 2245 | rc = efx_check_disabled(efx); |
| 2246 | if (rc) |
| 2247 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2248 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2249 | netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2250 | |
Ben Hutchings | 29c69a4 | 2013-01-28 19:01:06 +0000 | [diff] [blame] | 2251 | efx_device_detach_sync(efx); |
| 2252 | efx_stop_all(efx); |
| 2253 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2254 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2255 | net_dev->mtu = new_mtu; |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 2256 | efx_mac_reconfigure(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2257 | mutex_unlock(&efx->mac_lock); |
| 2258 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2259 | efx_start_all(efx); |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 2260 | efx_device_attach_if_not_resetting(efx); |
Ben Hutchings | 6c8eef4 | 2012-01-09 19:54:16 +0000 | [diff] [blame] | 2261 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | static int efx_set_mac_address(struct net_device *net_dev, void *data) |
| 2265 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2266 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2267 | struct sockaddr *addr = data; |
Ben Hutchings | e0b3ae3 | 2014-02-12 18:59:54 +0000 | [diff] [blame] | 2268 | u8 *new_addr = addr->sa_data; |
Shradha Shah | cfc77c2 | 2015-05-20 11:09:30 +0100 | [diff] [blame] | 2269 | u8 old_addr[6]; |
| 2270 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2271 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2272 | if (!is_valid_ether_addr(new_addr)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2273 | netif_err(efx, drv, efx->net_dev, |
| 2274 | "invalid ethernet MAC address requested: %pM\n", |
| 2275 | new_addr); |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 2276 | return -EADDRNOTAVAIL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2277 | } |
| 2278 | |
Shradha Shah | cfc77c2 | 2015-05-20 11:09:30 +0100 | [diff] [blame] | 2279 | /* save old address */ |
| 2280 | ether_addr_copy(old_addr, net_dev->dev_addr); |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 2281 | ether_addr_copy(net_dev->dev_addr, new_addr); |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 2282 | if (efx->type->set_mac_address) { |
| 2283 | rc = efx->type->set_mac_address(efx); |
Shradha Shah | cfc77c2 | 2015-05-20 11:09:30 +0100 | [diff] [blame] | 2284 | if (rc) { |
| 2285 | ether_addr_copy(net_dev->dev_addr, old_addr); |
| 2286 | return rc; |
| 2287 | } |
| 2288 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2289 | |
| 2290 | /* Reconfigure the MAC */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2291 | mutex_lock(&efx->mac_lock); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 2292 | efx_mac_reconfigure(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2293 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2294 | |
| 2295 | return 0; |
| 2296 | } |
| 2297 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 2298 | /* Context: netif_addr_lock held, BHs disabled. */ |
Ben Hutchings | 0fca8c9 | 2012-01-09 19:54:44 +0000 | [diff] [blame] | 2299 | static void efx_set_rx_mode(struct net_device *net_dev) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2300 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2301 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2302 | |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 2303 | if (efx->port_enabled) |
| 2304 | queue_work(efx->workqueue, &efx->mac_work); |
| 2305 | /* Otherwise efx_start_port() will do this */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2306 | } |
| 2307 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 2308 | static int efx_set_features(struct net_device *net_dev, netdev_features_t data) |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2309 | { |
| 2310 | struct efx_nic *efx = netdev_priv(net_dev); |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 2311 | int rc; |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2312 | |
| 2313 | /* If disabling RX n-tuple filtering, clear existing filters */ |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 2314 | if (net_dev->features & ~data & NETIF_F_NTUPLE) { |
| 2315 | rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); |
| 2316 | if (rc) |
| 2317 | return rc; |
| 2318 | } |
| 2319 | |
| 2320 | /* If Rx VLAN filter is changed, update filters via mac_reconfigure */ |
| 2321 | if ((net_dev->features ^ data) & NETIF_F_HW_VLAN_CTAG_FILTER) { |
| 2322 | /* efx_set_rx_mode() will schedule MAC work to update filters |
| 2323 | * when a new features are finally set in net_dev. |
| 2324 | */ |
| 2325 | efx_set_rx_mode(net_dev); |
| 2326 | } |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2327 | |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
Wei Yongjun | b40296f | 2017-01-11 16:16:12 +0000 | [diff] [blame] | 2331 | static int efx_get_phys_port_id(struct net_device *net_dev, |
| 2332 | struct netdev_phys_item_id *ppid) |
Bert Kenward | 08a7b29b | 2017-01-10 16:23:33 +0000 | [diff] [blame] | 2333 | { |
| 2334 | struct efx_nic *efx = netdev_priv(net_dev); |
| 2335 | |
| 2336 | if (efx->type->get_phys_port_id) |
| 2337 | return efx->type->get_phys_port_id(efx, ppid); |
| 2338 | else |
| 2339 | return -EOPNOTSUPP; |
| 2340 | } |
| 2341 | |
Bert Kenward | ac019f0 | 2017-01-10 16:23:56 +0000 | [diff] [blame] | 2342 | static int efx_get_phys_port_name(struct net_device *net_dev, |
| 2343 | char *name, size_t len) |
| 2344 | { |
| 2345 | struct efx_nic *efx = netdev_priv(net_dev); |
| 2346 | |
| 2347 | if (snprintf(name, len, "p%u", efx->port_num) >= len) |
| 2348 | return -EINVAL; |
| 2349 | return 0; |
| 2350 | } |
| 2351 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 2352 | static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid) |
| 2353 | { |
| 2354 | struct efx_nic *efx = netdev_priv(net_dev); |
| 2355 | |
| 2356 | if (efx->type->vlan_rx_add_vid) |
| 2357 | return efx->type->vlan_rx_add_vid(efx, proto, vid); |
| 2358 | else |
| 2359 | return -EOPNOTSUPP; |
| 2360 | } |
| 2361 | |
| 2362 | static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid) |
| 2363 | { |
| 2364 | struct efx_nic *efx = netdev_priv(net_dev); |
| 2365 | |
| 2366 | if (efx->type->vlan_rx_kill_vid) |
| 2367 | return efx->type->vlan_rx_kill_vid(efx, proto, vid); |
| 2368 | else |
| 2369 | return -EOPNOTSUPP; |
| 2370 | } |
| 2371 | |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 2372 | static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in) |
| 2373 | { |
| 2374 | switch (in) { |
| 2375 | case UDP_TUNNEL_TYPE_VXLAN: |
| 2376 | return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN; |
| 2377 | case UDP_TUNNEL_TYPE_GENEVE: |
| 2378 | return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE; |
| 2379 | default: |
| 2380 | return -1; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti) |
| 2385 | { |
| 2386 | struct efx_nic *efx = netdev_priv(dev); |
| 2387 | struct efx_udp_tunnel tnl; |
| 2388 | int efx_tunnel_type; |
| 2389 | |
| 2390 | efx_tunnel_type = efx_udp_tunnel_type_map(ti->type); |
| 2391 | if (efx_tunnel_type < 0) |
| 2392 | return; |
| 2393 | |
| 2394 | tnl.type = (u16)efx_tunnel_type; |
| 2395 | tnl.port = ti->port; |
| 2396 | |
| 2397 | if (efx->type->udp_tnl_add_port) |
| 2398 | (void)efx->type->udp_tnl_add_port(efx, tnl); |
| 2399 | } |
| 2400 | |
| 2401 | static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti) |
| 2402 | { |
| 2403 | struct efx_nic *efx = netdev_priv(dev); |
| 2404 | struct efx_udp_tunnel tnl; |
| 2405 | int efx_tunnel_type; |
| 2406 | |
| 2407 | efx_tunnel_type = efx_udp_tunnel_type_map(ti->type); |
| 2408 | if (efx_tunnel_type < 0) |
| 2409 | return; |
| 2410 | |
| 2411 | tnl.type = (u16)efx_tunnel_type; |
| 2412 | tnl.port = ti->port; |
| 2413 | |
Dan Carpenter | c04ca61 | 2017-03-22 12:10:02 +0300 | [diff] [blame] | 2414 | if (efx->type->udp_tnl_del_port) |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 2415 | (void)efx->type->udp_tnl_del_port(efx, tnl); |
| 2416 | } |
| 2417 | |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 2418 | static const struct net_device_ops efx_netdev_ops = { |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2419 | .ndo_open = efx_net_open, |
| 2420 | .ndo_stop = efx_net_stop, |
Ben Hutchings | 4472702 | 2010-06-08 07:21:12 +0000 | [diff] [blame] | 2421 | .ndo_get_stats64 = efx_net_stats, |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2422 | .ndo_tx_timeout = efx_watchdog, |
| 2423 | .ndo_start_xmit = efx_hard_start_xmit, |
| 2424 | .ndo_validate_addr = eth_validate_addr, |
| 2425 | .ndo_do_ioctl = efx_ioctl, |
| 2426 | .ndo_change_mtu = efx_change_mtu, |
| 2427 | .ndo_set_mac_address = efx_set_mac_address, |
Ben Hutchings | 0fca8c9 | 2012-01-09 19:54:44 +0000 | [diff] [blame] | 2428 | .ndo_set_rx_mode = efx_set_rx_mode, |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2429 | .ndo_set_features = efx_set_features, |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 2430 | .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid, |
| 2431 | .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2432 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 2433 | .ndo_set_vf_mac = efx_sriov_set_vf_mac, |
| 2434 | .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, |
| 2435 | .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, |
| 2436 | .ndo_get_vf_config = efx_sriov_get_vf_config, |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 2437 | .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2438 | #endif |
Bert Kenward | 08a7b29b | 2017-01-10 16:23:33 +0000 | [diff] [blame] | 2439 | .ndo_get_phys_port_id = efx_get_phys_port_id, |
Bert Kenward | ac019f0 | 2017-01-10 16:23:56 +0000 | [diff] [blame] | 2440 | .ndo_get_phys_port_name = efx_get_phys_port_name, |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2441 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2442 | .ndo_poll_controller = efx_netpoll, |
| 2443 | #endif |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 2444 | .ndo_setup_tc = efx_setup_tc, |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 2445 | #ifdef CONFIG_RFS_ACCEL |
| 2446 | .ndo_rx_flow_steer = efx_filter_rfs, |
| 2447 | #endif |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 2448 | .ndo_udp_tunnel_add = efx_udp_tunnel_add, |
| 2449 | .ndo_udp_tunnel_del = efx_udp_tunnel_del, |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2450 | }; |
| 2451 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2452 | static void efx_update_name(struct efx_nic *efx) |
| 2453 | { |
| 2454 | strcpy(efx->name, efx->net_dev->name); |
| 2455 | efx_mtd_rename(efx); |
| 2456 | efx_set_channel_names(efx); |
| 2457 | } |
| 2458 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2459 | static int efx_netdev_event(struct notifier_block *this, |
| 2460 | unsigned long event, void *ptr) |
| 2461 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 2462 | struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2463 | |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 2464 | if ((net_dev->netdev_ops == &efx_netdev_ops) && |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2465 | event == NETDEV_CHANGENAME) |
| 2466 | efx_update_name(netdev_priv(net_dev)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2467 | |
| 2468 | return NOTIFY_DONE; |
| 2469 | } |
| 2470 | |
| 2471 | static struct notifier_block efx_netdev_notifier = { |
| 2472 | .notifier_call = efx_netdev_event, |
| 2473 | }; |
| 2474 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2475 | static ssize_t |
| 2476 | show_phy_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 2477 | { |
| 2478 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2479 | return sprintf(buf, "%d\n", efx->phy_type); |
| 2480 | } |
Ben Hutchings | 776fbcc | 2013-06-18 17:45:40 +0100 | [diff] [blame] | 2481 | static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL); |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2482 | |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 2483 | #ifdef CONFIG_SFC_MCDI_LOGGING |
| 2484 | static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr, |
| 2485 | char *buf) |
| 2486 | { |
| 2487 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2488 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 2489 | |
| 2490 | return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled); |
| 2491 | } |
| 2492 | static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr, |
| 2493 | const char *buf, size_t count) |
| 2494 | { |
| 2495 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2496 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 2497 | bool enable = count > 0 && *buf != '0'; |
| 2498 | |
| 2499 | mcdi->logging_enabled = enable; |
| 2500 | return count; |
| 2501 | } |
| 2502 | static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log); |
| 2503 | #endif |
| 2504 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2505 | static int efx_register_netdev(struct efx_nic *efx) |
| 2506 | { |
| 2507 | struct net_device *net_dev = efx->net_dev; |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2508 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2509 | int rc; |
| 2510 | |
| 2511 | net_dev->watchdog_timeo = 5 * HZ; |
| 2512 | net_dev->irq = efx->pci_dev->irq; |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 2513 | net_dev->netdev_ops = &efx_netdev_ops; |
| 2514 | if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2515 | net_dev->priv_flags |= IFF_UNICAST_FLT; |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 2516 | net_dev->ethtool_ops = &efx_ethtool_ops; |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 2517 | net_dev->gso_max_segs = EFX_TSO_MAX_SEGS; |
Bert Kenward | cd94e51 | 2016-10-18 17:47:45 +0100 | [diff] [blame] | 2518 | net_dev->min_mtu = EFX_MIN_MTU; |
| 2519 | net_dev->max_mtu = EFX_MAX_MTU; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2520 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2521 | rtnl_lock(); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2522 | |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2523 | /* Enable resets to be scheduled and check whether any were |
| 2524 | * already requested. If so, the NIC is probably hosed so we |
| 2525 | * abort. |
| 2526 | */ |
| 2527 | efx->state = STATE_READY; |
| 2528 | smp_mb(); /* ensure we change state before checking reset_pending */ |
| 2529 | if (efx->reset_pending) { |
| 2530 | netif_err(efx, probe, efx->net_dev, |
| 2531 | "aborting probe due to scheduled reset\n"); |
| 2532 | rc = -EIO; |
| 2533 | goto fail_locked; |
| 2534 | } |
| 2535 | |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2536 | rc = dev_alloc_name(net_dev, net_dev->name); |
| 2537 | if (rc < 0) |
| 2538 | goto fail_locked; |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2539 | efx_update_name(efx); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2540 | |
Ben Hutchings | 8f8b3d5 | 2012-08-24 18:04:38 +0100 | [diff] [blame] | 2541 | /* Always start with carrier off; PHY events will detect the link */ |
| 2542 | netif_carrier_off(net_dev); |
| 2543 | |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2544 | rc = register_netdevice(net_dev); |
| 2545 | if (rc) |
| 2546 | goto fail_locked; |
| 2547 | |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2548 | efx_for_each_channel(channel, efx) { |
| 2549 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | 60031fc | 2011-01-12 18:39:40 +0000 | [diff] [blame] | 2550 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 2551 | efx_init_tx_queue_core_txq(tx_queue); |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Ben Hutchings | 0bcf4a6 | 2013-10-18 19:21:45 +0100 | [diff] [blame] | 2554 | efx_associate(efx); |
| 2555 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2556 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2557 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2558 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 2559 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2560 | netif_err(efx, drv, efx->net_dev, |
| 2561 | "failed to init net dev attributes\n"); |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2562 | goto fail_registered; |
| 2563 | } |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 2564 | #ifdef CONFIG_SFC_MCDI_LOGGING |
| 2565 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging); |
| 2566 | if (rc) { |
| 2567 | netif_err(efx, drv, efx->net_dev, |
| 2568 | "failed to init net dev attributes\n"); |
| 2569 | goto fail_attr_mcdi_logging; |
| 2570 | } |
| 2571 | #endif |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2572 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2573 | return 0; |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2574 | |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 2575 | #ifdef CONFIG_SFC_MCDI_LOGGING |
| 2576 | fail_attr_mcdi_logging: |
| 2577 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 2578 | #endif |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2579 | fail_registered: |
| 2580 | rtnl_lock(); |
Ben Hutchings | 0bcf4a6 | 2013-10-18 19:21:45 +0100 | [diff] [blame] | 2581 | efx_dissociate(efx); |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2582 | unregister_netdevice(net_dev); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2583 | fail_locked: |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2584 | efx->state = STATE_UNINIT; |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2585 | rtnl_unlock(); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2586 | netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2587 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | static void efx_unregister_netdev(struct efx_nic *efx) |
| 2591 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2592 | if (!efx->net_dev) |
| 2593 | return; |
| 2594 | |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2595 | BUG_ON(netdev_priv(efx->net_dev) != efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2596 | |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 2597 | if (efx_dev_registered(efx)) { |
| 2598 | strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); |
| 2599 | #ifdef CONFIG_SFC_MCDI_LOGGING |
| 2600 | device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging); |
| 2601 | #endif |
| 2602 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 2603 | unregister_netdev(efx->net_dev); |
| 2604 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | /************************************************************************** |
| 2608 | * |
| 2609 | * Device reset and suspend |
| 2610 | * |
| 2611 | **************************************************************************/ |
| 2612 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2613 | /* Tears down the entire software state and most of the hardware state |
| 2614 | * before reset. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2615 | void efx_reset_down(struct efx_nic *efx, enum reset_type method) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2616 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2617 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 2618 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2619 | if (method == RESET_TYPE_MCDI_TIMEOUT) |
| 2620 | efx->type->prepare_flr(efx); |
| 2621 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2622 | efx_stop_all(efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 2623 | efx_disable_interrupts(efx); |
Ben Hutchings | 5642cee | 2012-07-27 19:35:52 +0100 | [diff] [blame] | 2624 | |
| 2625 | mutex_lock(&efx->mac_lock); |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 2626 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && |
| 2627 | method != RESET_TYPE_DATAPATH) |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 2628 | efx->phy_op->fini(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2629 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2630 | } |
| 2631 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2632 | /* This function will always ensure that the locks acquired in |
| 2633 | * efx_reset_down() are released. A failure return code indicates |
| 2634 | * that we were unable to reinitialise the hardware, and the |
| 2635 | * driver should be disabled. If ok is false, then the rx and tx |
| 2636 | * engines are not restarted, pending a RESET_DISABLE. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2637 | int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2638 | { |
| 2639 | int rc; |
| 2640 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2641 | EFX_ASSERT_RESET_SERIALISED(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2642 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2643 | if (method == RESET_TYPE_MCDI_TIMEOUT) |
| 2644 | efx->type->finish_flr(efx); |
| 2645 | |
| 2646 | /* Ensure that SRAM is initialised even if we're disabling the device */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2647 | rc = efx->type->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2648 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2649 | netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n"); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2650 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2653 | if (!ok) |
| 2654 | goto fail; |
| 2655 | |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 2656 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && |
| 2657 | method != RESET_TYPE_DATAPATH) { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2658 | rc = efx->phy_op->init(efx); |
| 2659 | if (rc) |
| 2660 | goto fail; |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 2661 | rc = efx->phy_op->reconfigure(efx); |
| 2662 | if (rc && rc != -EPERM) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2663 | netif_err(efx, drv, efx->net_dev, |
| 2664 | "could not restore PHY settings\n"); |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 2667 | rc = efx_enable_interrupts(efx); |
| 2668 | if (rc) |
| 2669 | goto fail; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 2670 | |
| 2671 | #ifdef CONFIG_SFC_SRIOV |
| 2672 | rc = efx->type->vswitching_restore(efx); |
| 2673 | if (rc) /* not fatal; the PF will still work fine */ |
| 2674 | netif_warn(efx, probe, efx->net_dev, |
| 2675 | "failed to restore vswitching rc=%d;" |
| 2676 | " VFs may not function\n", rc); |
| 2677 | #endif |
| 2678 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 2679 | down_read(&efx->filter_sem); |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 2680 | efx_restore_filters(efx); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 2681 | up_read(&efx->filter_sem); |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 2682 | if (efx->type->sriov_reset) |
| 2683 | efx->type->sriov_reset(efx); |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2684 | |
| 2685 | mutex_unlock(&efx->mac_lock); |
| 2686 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2687 | efx_start_all(efx); |
| 2688 | |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 2689 | if (efx->type->udp_tnl_push_ports) |
| 2690 | efx->type->udp_tnl_push_ports(efx); |
| 2691 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2692 | return 0; |
| 2693 | |
| 2694 | fail: |
| 2695 | efx->port_initialized = false; |
| 2696 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2697 | mutex_unlock(&efx->mac_lock); |
| 2698 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2699 | return rc; |
| 2700 | } |
| 2701 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2702 | /* Reset the NIC using the specified method. Note that the reset may |
| 2703 | * fail, in which case the card will be left in an unusable state. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2704 | * |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2705 | * Caller must hold the rtnl_lock. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2706 | */ |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2707 | int efx_reset(struct efx_nic *efx, enum reset_type method) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2708 | { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2709 | int rc, rc2; |
| 2710 | bool disabled; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2711 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2712 | netif_info(efx, drv, efx->net_dev, "resetting (%s)\n", |
| 2713 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2714 | |
Daniel Pieczko | c2f3b8e | 2012-10-17 13:21:23 +0100 | [diff] [blame] | 2715 | efx_device_detach_sync(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2716 | efx_reset_down(efx, method); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2717 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2718 | rc = efx->type->reset(efx, method); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2719 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2720 | netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n"); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2721 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2722 | } |
| 2723 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2724 | /* Clear flags for the scopes we covered. We assume the NIC and |
| 2725 | * driver are now quiescent so that there is no race here. |
| 2726 | */ |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2727 | if (method < RESET_TYPE_MAX_METHOD) |
| 2728 | efx->reset_pending &= -(1 << (method + 1)); |
| 2729 | else /* it doesn't fit into the well-ordered scope hierarchy */ |
| 2730 | __clear_bit(method, &efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2731 | |
| 2732 | /* Reinitialise bus-mastering, which may have been turned off before |
| 2733 | * the reset was scheduled. This is still appropriate, even in the |
| 2734 | * RESET_TYPE_DISABLE since this driver generally assumes the hardware |
| 2735 | * can respond to requests. */ |
| 2736 | pci_set_master(efx->pci_dev); |
| 2737 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2738 | out: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2739 | /* Leave device stopped if necessary */ |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2740 | disabled = rc || |
| 2741 | method == RESET_TYPE_DISABLE || |
| 2742 | method == RESET_TYPE_RECOVER_OR_DISABLE; |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2743 | rc2 = efx_reset_up(efx, method, !disabled); |
| 2744 | if (rc2) { |
| 2745 | disabled = true; |
| 2746 | if (!rc) |
| 2747 | rc = rc2; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2748 | } |
| 2749 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2750 | if (disabled) { |
Ben Hutchings | f49a458 | 2010-04-28 09:01:33 +0000 | [diff] [blame] | 2751 | dev_close(efx->net_dev); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2752 | netif_err(efx, drv, efx->net_dev, "has been disabled\n"); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2753 | efx->state = STATE_DISABLED; |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2754 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2755 | netif_dbg(efx, drv, efx->net_dev, "reset complete\n"); |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 2756 | efx_device_attach_if_not_resetting(efx); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2757 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2758 | return rc; |
| 2759 | } |
| 2760 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2761 | /* Try recovery mechanisms. |
| 2762 | * For now only EEH is supported. |
| 2763 | * Returns 0 if the recovery mechanisms are unsuccessful. |
| 2764 | * Returns a non-zero value otherwise. |
| 2765 | */ |
Alexandre Rames | b28405b | 2013-03-21 16:41:43 +0000 | [diff] [blame] | 2766 | int efx_try_recovery(struct efx_nic *efx) |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2767 | { |
| 2768 | #ifdef CONFIG_EEH |
| 2769 | /* A PCI error can occur and not be seen by EEH because nothing |
| 2770 | * happens on the PCI bus. In this case the driver may fail and |
| 2771 | * schedule a 'recover or reset', leading to this recovery handler. |
| 2772 | * Manually call the eeh failure check function. |
| 2773 | */ |
Benjamin Herrenschmidt | 12a89db | 2015-03-23 14:00:47 +1100 | [diff] [blame] | 2774 | struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2775 | if (eeh_dev_check_failure(eehdev)) { |
| 2776 | /* The EEH mechanisms will handle the error and reset the |
| 2777 | * device if necessary. |
| 2778 | */ |
| 2779 | return 1; |
| 2780 | } |
| 2781 | #endif |
| 2782 | return 0; |
| 2783 | } |
| 2784 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 2785 | static void efx_wait_for_bist_end(struct efx_nic *efx) |
| 2786 | { |
| 2787 | int i; |
| 2788 | |
| 2789 | for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) { |
| 2790 | if (efx_mcdi_poll_reboot(efx)) |
| 2791 | goto out; |
| 2792 | msleep(BIST_WAIT_DELAY_MS); |
| 2793 | } |
| 2794 | |
| 2795 | netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n"); |
| 2796 | out: |
| 2797 | /* Either way unset the BIST flag. If we found no reboot we probably |
| 2798 | * won't recover, but we should try. |
| 2799 | */ |
| 2800 | efx->mc_bist_for_other_fn = false; |
| 2801 | } |
| 2802 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2803 | /* The worker thread exists so that code that cannot sleep can |
| 2804 | * schedule a reset for later. |
| 2805 | */ |
| 2806 | static void efx_reset_work(struct work_struct *data) |
| 2807 | { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2808 | struct efx_nic *efx = container_of(data, struct efx_nic, reset_work); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2809 | unsigned long pending; |
| 2810 | enum reset_type method; |
| 2811 | |
| 2812 | pending = ACCESS_ONCE(efx->reset_pending); |
| 2813 | method = fls(pending) - 1; |
| 2814 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 2815 | if (method == RESET_TYPE_MC_BIST) |
| 2816 | efx_wait_for_bist_end(efx); |
| 2817 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2818 | if ((method == RESET_TYPE_RECOVER_OR_DISABLE || |
| 2819 | method == RESET_TYPE_RECOVER_OR_ALL) && |
| 2820 | efx_try_recovery(efx)) |
| 2821 | return; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2822 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2823 | if (!pending) |
Steve Hodgson | 319ba64 | 2010-06-01 11:17:24 +0000 | [diff] [blame] | 2824 | return; |
| 2825 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2826 | rtnl_lock(); |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2827 | |
| 2828 | /* We checked the state in efx_schedule_reset() but it may |
| 2829 | * have changed by now. Now that we have the RTNL lock, |
| 2830 | * it cannot change again. |
| 2831 | */ |
| 2832 | if (efx->state == STATE_READY) |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2833 | (void)efx_reset(efx, method); |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2834 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2835 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) |
| 2839 | { |
| 2840 | enum reset_type method; |
| 2841 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2842 | if (efx->state == STATE_RECOVERY) { |
| 2843 | netif_dbg(efx, drv, efx->net_dev, |
| 2844 | "recovering: skip scheduling %s reset\n", |
| 2845 | RESET_TYPE(type)); |
| 2846 | return; |
| 2847 | } |
| 2848 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2849 | switch (type) { |
| 2850 | case RESET_TYPE_INVISIBLE: |
| 2851 | case RESET_TYPE_ALL: |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2852 | case RESET_TYPE_RECOVER_OR_ALL: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2853 | case RESET_TYPE_WORLD: |
| 2854 | case RESET_TYPE_DISABLE: |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 2855 | case RESET_TYPE_RECOVER_OR_DISABLE: |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 2856 | case RESET_TYPE_DATAPATH: |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 2857 | case RESET_TYPE_MC_BIST: |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2858 | case RESET_TYPE_MCDI_TIMEOUT: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2859 | method = type; |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2860 | netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n", |
| 2861 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2862 | break; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2863 | default: |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2864 | method = efx->type->map_reset_reason(type); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2865 | netif_dbg(efx, drv, efx->net_dev, |
| 2866 | "scheduling %s reset for %s\n", |
| 2867 | RESET_TYPE(method), RESET_TYPE(type)); |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2868 | break; |
| 2869 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2870 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2871 | set_bit(method, &efx->reset_pending); |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 2872 | smp_mb(); /* ensure we change reset_pending before checking state */ |
| 2873 | |
| 2874 | /* If we're not READY then just leave the flags set as the cue |
| 2875 | * to abort probing or reschedule the reset later. |
| 2876 | */ |
| 2877 | if (ACCESS_ONCE(efx->state) != STATE_READY) |
| 2878 | return; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2879 | |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2880 | /* efx_process_channel() will no longer read events once a |
| 2881 | * reset is scheduled. So switch back to poll'd MCDI completions. */ |
| 2882 | efx_mcdi_mode_poll(efx); |
| 2883 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2884 | queue_work(reset_workqueue, &efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | /************************************************************************** |
| 2888 | * |
| 2889 | * List of NICs we support |
| 2890 | * |
| 2891 | **************************************************************************/ |
| 2892 | |
| 2893 | /* PCI device ID table */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 2894 | static const struct pci_device_id efx_pci_table[] = { |
Ben Hutchings | 547c474 | 2011-12-02 18:23:56 +0000 | [diff] [blame] | 2895 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */ |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2896 | .driver_data = (unsigned long) &siena_a0_nic_type}, |
Ben Hutchings | 547c474 | 2011-12-02 18:23:56 +0000 | [diff] [blame] | 2897 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */ |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2898 | .driver_data = (unsigned long) &siena_a0_nic_type}, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2899 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ |
| 2900 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 2901 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ |
| 2902 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, |
Mateusz Wrzesinski | 3b06a00 | 2014-07-14 08:38:49 +0100 | [diff] [blame] | 2903 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ |
| 2904 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, |
Bert Kenward | dd248f1 | 2015-11-30 09:05:47 +0000 | [diff] [blame] | 2905 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */ |
| 2906 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, |
| 2907 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */ |
| 2908 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, |
| 2909 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */ |
| 2910 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2911 | {0} /* end of list */ |
| 2912 | }; |
| 2913 | |
| 2914 | /************************************************************************** |
| 2915 | * |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 2916 | * Dummy PHY/MAC operations |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2917 | * |
Ben Hutchings | 01aad7b | 2008-09-01 12:48:36 +0100 | [diff] [blame] | 2918 | * Can be used for some unimplemented operations |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2919 | * Needed so all function pointers are valid and do not have to be tested |
| 2920 | * before use |
| 2921 | * |
| 2922 | **************************************************************************/ |
| 2923 | int efx_port_dummy_op_int(struct efx_nic *efx) |
| 2924 | { |
| 2925 | return 0; |
| 2926 | } |
| 2927 | void efx_port_dummy_op_void(struct efx_nic *efx) {} |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 2928 | |
| 2929 | static bool efx_port_dummy_op_poll(struct efx_nic *efx) |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 2930 | { |
| 2931 | return false; |
| 2932 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2933 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2934 | static const struct efx_phy_operations efx_dummy_phy_operations = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2935 | .init = efx_port_dummy_op_int, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2936 | .reconfigure = efx_port_dummy_op_int, |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 2937 | .poll = efx_port_dummy_op_poll, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2938 | .fini = efx_port_dummy_op_void, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2939 | }; |
| 2940 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2941 | /************************************************************************** |
| 2942 | * |
| 2943 | * Data housekeeping |
| 2944 | * |
| 2945 | **************************************************************************/ |
| 2946 | |
| 2947 | /* This zeroes out and then fills in the invariants in a struct |
| 2948 | * efx_nic (including all sub-structures). |
| 2949 | */ |
Ben Hutchings | adeb15a | 2012-08-02 01:39:38 +0100 | [diff] [blame] | 2950 | static int efx_init_struct(struct efx_nic *efx, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2951 | struct pci_dev *pci_dev, struct net_device *net_dev) |
| 2952 | { |
Andrew Rybchenko | 6f9f6ec | 2017-02-13 14:57:39 +0000 | [diff] [blame] | 2953 | int rc = -ENOMEM, i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2954 | |
| 2955 | /* Initialise common structures */ |
Ben Hutchings | 0bcf4a6 | 2013-10-18 19:21:45 +0100 | [diff] [blame] | 2956 | INIT_LIST_HEAD(&efx->node); |
| 2957 | INIT_LIST_HEAD(&efx->secondary_list); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2958 | spin_lock_init(&efx->biu_lock); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 2959 | #ifdef CONFIG_SFC_MTD |
| 2960 | INIT_LIST_HEAD(&efx->mtd_list); |
| 2961 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2962 | INIT_WORK(&efx->reset_work, efx_reset_work); |
| 2963 | INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); |
Ben Hutchings | dd40781 | 2012-02-28 23:40:21 +0000 | [diff] [blame] | 2964 | INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2965 | efx->pci_dev = pci_dev; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2966 | efx->msg_enable = debug; |
Ben Hutchings | f16aeea | 2012-07-27 19:31:16 +0100 | [diff] [blame] | 2967 | efx->state = STATE_UNINIT; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2968 | strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2969 | |
| 2970 | efx->net_dev = net_dev; |
Jon Cooper | 43a3739 | 2012-10-18 15:49:54 +0100 | [diff] [blame] | 2971 | efx->rx_prefix_size = efx->type->rx_prefix_size; |
Andrew Rybchenko | 2ec0301 | 2013-11-16 11:02:27 +0400 | [diff] [blame] | 2972 | efx->rx_ip_align = |
| 2973 | NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0; |
Jon Cooper | 43a3739 | 2012-10-18 15:49:54 +0100 | [diff] [blame] | 2974 | efx->rx_packet_hash_offset = |
| 2975 | efx->type->rx_hash_offset - efx->type->rx_prefix_size; |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 2976 | efx->rx_packet_ts_offset = |
| 2977 | efx->type->rx_ts_offset - efx->type->rx_prefix_size; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2978 | spin_lock_init(&efx->stats_lock); |
| 2979 | mutex_init(&efx->mac_lock); |
| 2980 | efx->phy_op = &efx_dummy_phy_operations; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 2981 | efx->mdio.dev = net_dev; |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 2982 | INIT_WORK(&efx->mac_work, efx_mac_work); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 2983 | init_waitqueue_head(&efx->flush_wq); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2984 | |
| 2985 | for (i = 0; i < EFX_MAX_CHANNELS; i++) { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 2986 | efx->channel[i] = efx_alloc_channel(efx, i, NULL); |
| 2987 | if (!efx->channel[i]) |
| 2988 | goto fail; |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 2989 | efx->msi_context[i].efx = efx; |
| 2990 | efx->msi_context[i].index = i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2991 | } |
| 2992 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2993 | /* Higher numbered interrupt modes are less capable! */ |
Andrew Rybchenko | 6f9f6ec | 2017-02-13 14:57:39 +0000 | [diff] [blame] | 2994 | if (WARN_ON_ONCE(efx->type->max_interrupt_mode > |
| 2995 | efx->type->min_interrupt_mode)) { |
| 2996 | rc = -EIO; |
| 2997 | goto fail; |
| 2998 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2999 | efx->interrupt_mode = max(efx->type->max_interrupt_mode, |
| 3000 | interrupt_mode); |
Andrew Rybchenko | 6f9f6ec | 2017-02-13 14:57:39 +0000 | [diff] [blame] | 3001 | efx->interrupt_mode = min(efx->type->min_interrupt_mode, |
| 3002 | interrupt_mode); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3003 | |
Ben Hutchings | 6977dc6 | 2008-12-26 13:44:39 -0800 | [diff] [blame] | 3004 | /* Would be good to use the net_dev name, but we're too early */ |
| 3005 | snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s", |
| 3006 | pci_name(pci_dev)); |
| 3007 | efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 3008 | if (!efx->workqueue) |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 3009 | goto fail; |
Ben Hutchings | 8d9853d | 2008-07-18 19:01:20 +0100 | [diff] [blame] | 3010 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3011 | return 0; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 3012 | |
| 3013 | fail: |
| 3014 | efx_fini_struct(efx); |
Andrew Rybchenko | 6f9f6ec | 2017-02-13 14:57:39 +0000 | [diff] [blame] | 3015 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | static void efx_fini_struct(struct efx_nic *efx) |
| 3019 | { |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 3020 | int i; |
| 3021 | |
| 3022 | for (i = 0; i < EFX_MAX_CHANNELS; i++) |
| 3023 | kfree(efx->channel[i]); |
| 3024 | |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3025 | kfree(efx->vpd_sn); |
| 3026 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3027 | if (efx->workqueue) { |
| 3028 | destroy_workqueue(efx->workqueue); |
| 3029 | efx->workqueue = NULL; |
| 3030 | } |
| 3031 | } |
| 3032 | |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 3033 | void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) |
| 3034 | { |
| 3035 | u64 n_rx_nodesc_trunc = 0; |
| 3036 | struct efx_channel *channel; |
| 3037 | |
| 3038 | efx_for_each_channel(channel, efx) |
| 3039 | n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; |
| 3040 | stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; |
| 3041 | stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); |
| 3042 | } |
| 3043 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3044 | /************************************************************************** |
| 3045 | * |
| 3046 | * PCI interface |
| 3047 | * |
| 3048 | **************************************************************************/ |
| 3049 | |
| 3050 | /* Main body of final NIC shutdown code |
| 3051 | * This is called only at module unload (or hotplug removal). |
| 3052 | */ |
| 3053 | static void efx_pci_remove_main(struct efx_nic *efx) |
| 3054 | { |
Ben Hutchings | 7153f62 | 2012-07-27 20:50:52 +0100 | [diff] [blame] | 3055 | /* Flush reset_work. It can no longer be scheduled since we |
| 3056 | * are not READY. |
| 3057 | */ |
| 3058 | BUG_ON(efx->state == STATE_READY); |
| 3059 | cancel_work_sync(&efx->reset_work); |
| 3060 | |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 3061 | efx_disable_interrupts(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 3062 | efx_nic_fini_interrupt(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3063 | efx_fini_port(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 3064 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3065 | efx_fini_napi(efx); |
| 3066 | efx_remove_all(efx); |
| 3067 | } |
| 3068 | |
| 3069 | /* Final NIC shutdown |
Daniel Pieczko | 2a3fc31 | 2015-06-02 11:40:46 +0100 | [diff] [blame] | 3070 | * This is called only at module unload (or hotplug removal). A PF can call |
| 3071 | * this on its VFs to ensure they are unbound first. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3072 | */ |
| 3073 | static void efx_pci_remove(struct pci_dev *pci_dev) |
| 3074 | { |
| 3075 | struct efx_nic *efx; |
| 3076 | |
| 3077 | efx = pci_get_drvdata(pci_dev); |
| 3078 | if (!efx) |
| 3079 | return; |
| 3080 | |
| 3081 | /* Mark the NIC as fini, then stop the interface */ |
| 3082 | rtnl_lock(); |
Ben Hutchings | 0bcf4a6 | 2013-10-18 19:21:45 +0100 | [diff] [blame] | 3083 | efx_dissociate(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3084 | dev_close(efx->net_dev); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 3085 | efx_disable_interrupts(efx); |
Edward Cree | ea6bb99 | 2015-06-15 18:27:54 +0100 | [diff] [blame] | 3086 | efx->state = STATE_UNINIT; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3087 | rtnl_unlock(); |
| 3088 | |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3089 | if (efx->type->sriov_fini) |
| 3090 | efx->type->sriov_fini(efx); |
| 3091 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3092 | efx_unregister_netdev(efx); |
| 3093 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 3094 | efx_mtd_remove(efx); |
| 3095 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3096 | efx_pci_remove_main(efx); |
| 3097 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3098 | efx_fini_io(efx); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3099 | netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3100 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3101 | efx_fini_struct(efx); |
| 3102 | free_netdev(efx->net_dev); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3103 | |
| 3104 | pci_disable_pcie_error_reporting(pci_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3105 | }; |
| 3106 | |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3107 | /* NIC VPD information |
| 3108 | * Called during probe to display the part number of the |
| 3109 | * installed NIC. VPD is potentially very large but this should |
| 3110 | * always appear within the first 512 bytes. |
| 3111 | */ |
| 3112 | #define SFC_VPD_LEN 512 |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3113 | static void efx_probe_vpd_strings(struct efx_nic *efx) |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3114 | { |
| 3115 | struct pci_dev *dev = efx->pci_dev; |
| 3116 | char vpd_data[SFC_VPD_LEN]; |
| 3117 | ssize_t vpd_size; |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3118 | int ro_start, ro_size, i, j; |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3119 | |
| 3120 | /* Get the vpd data from the device */ |
| 3121 | vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data); |
| 3122 | if (vpd_size <= 0) { |
| 3123 | netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n"); |
| 3124 | return; |
| 3125 | } |
| 3126 | |
| 3127 | /* Get the Read only section */ |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3128 | ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA); |
| 3129 | if (ro_start < 0) { |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3130 | netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n"); |
| 3131 | return; |
| 3132 | } |
| 3133 | |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3134 | ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]); |
| 3135 | j = ro_size; |
| 3136 | i = ro_start + PCI_VPD_LRDT_TAG_SIZE; |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3137 | if (i + j > vpd_size) |
| 3138 | j = vpd_size - i; |
| 3139 | |
| 3140 | /* Get the Part number */ |
| 3141 | i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN"); |
| 3142 | if (i < 0) { |
| 3143 | netif_err(efx, drv, efx->net_dev, "Part number not found\n"); |
| 3144 | return; |
| 3145 | } |
| 3146 | |
| 3147 | j = pci_vpd_info_field_size(&vpd_data[i]); |
| 3148 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 3149 | if (i + j > vpd_size) { |
| 3150 | netif_err(efx, drv, efx->net_dev, "Incomplete part number\n"); |
| 3151 | return; |
| 3152 | } |
| 3153 | |
| 3154 | netif_info(efx, drv, efx->net_dev, |
| 3155 | "Part Number : %.*s\n", j, &vpd_data[i]); |
Ben Hutchings | ef215e6 | 2013-12-05 20:13:22 +0000 | [diff] [blame] | 3156 | |
| 3157 | i = ro_start + PCI_VPD_LRDT_TAG_SIZE; |
| 3158 | j = ro_size; |
| 3159 | i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN"); |
| 3160 | if (i < 0) { |
| 3161 | netif_err(efx, drv, efx->net_dev, "Serial number not found\n"); |
| 3162 | return; |
| 3163 | } |
| 3164 | |
| 3165 | j = pci_vpd_info_field_size(&vpd_data[i]); |
| 3166 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 3167 | if (i + j > vpd_size) { |
| 3168 | netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n"); |
| 3169 | return; |
| 3170 | } |
| 3171 | |
| 3172 | efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL); |
| 3173 | if (!efx->vpd_sn) |
| 3174 | return; |
| 3175 | |
| 3176 | snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]); |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3180 | /* Main body of NIC initialisation |
| 3181 | * This is called at module load (or hotplug insertion, theoretically). |
| 3182 | */ |
| 3183 | static int efx_pci_probe_main(struct efx_nic *efx) |
| 3184 | { |
| 3185 | int rc; |
| 3186 | |
| 3187 | /* Do start-of-day initialisation */ |
| 3188 | rc = efx_probe_all(efx); |
| 3189 | if (rc) |
| 3190 | goto fail1; |
| 3191 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 3192 | efx_init_napi(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3193 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 3194 | rc = efx->type->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3195 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3196 | netif_err(efx, probe, efx->net_dev, |
| 3197 | "failed to initialise NIC\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 3198 | goto fail3; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | rc = efx_init_port(efx); |
| 3202 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3203 | netif_err(efx, probe, efx->net_dev, |
| 3204 | "failed to initialise port\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 3205 | goto fail4; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3206 | } |
| 3207 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 3208 | rc = efx_nic_init_interrupt(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3209 | if (rc) |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 3210 | goto fail5; |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3211 | rc = efx_enable_interrupts(efx); |
| 3212 | if (rc) |
| 3213 | goto fail6; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3214 | |
| 3215 | return 0; |
| 3216 | |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3217 | fail6: |
| 3218 | efx_nic_fini_interrupt(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 3219 | fail5: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3220 | efx_fini_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3221 | fail4: |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 3222 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3223 | fail3: |
| 3224 | efx_fini_napi(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3225 | efx_remove_all(efx); |
| 3226 | fail1: |
| 3227 | return rc; |
| 3228 | } |
| 3229 | |
Jon Cooper | 8a53140 | 2017-02-08 16:51:18 +0000 | [diff] [blame] | 3230 | static int efx_pci_probe_post_io(struct efx_nic *efx) |
| 3231 | { |
| 3232 | struct net_device *net_dev = efx->net_dev; |
| 3233 | int rc = efx_pci_probe_main(efx); |
| 3234 | |
| 3235 | if (rc) |
| 3236 | return rc; |
| 3237 | |
| 3238 | if (efx->type->sriov_init) { |
| 3239 | rc = efx->type->sriov_init(efx); |
| 3240 | if (rc) |
| 3241 | netif_err(efx, probe, efx->net_dev, |
| 3242 | "SR-IOV can't be enabled rc %d\n", rc); |
| 3243 | } |
| 3244 | |
| 3245 | /* Determine netdevice features */ |
| 3246 | net_dev->features |= (efx->type->offload_features | NETIF_F_SG | |
| 3247 | NETIF_F_TSO | NETIF_F_RXCSUM); |
| 3248 | if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) |
| 3249 | net_dev->features |= NETIF_F_TSO6; |
| 3250 | /* Check whether device supports TSO */ |
| 3251 | if (!efx->type->tso_versions || !efx->type->tso_versions(efx)) |
| 3252 | net_dev->features &= ~NETIF_F_ALL_TSO; |
| 3253 | /* Mask for features that also apply to VLAN devices */ |
| 3254 | net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | |
| 3255 | NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | |
| 3256 | NETIF_F_RXCSUM); |
| 3257 | |
| 3258 | net_dev->hw_features = net_dev->features & ~efx->fixed_features; |
| 3259 | |
| 3260 | /* Disable VLAN filtering by default. It may be enforced if |
| 3261 | * the feature is fixed (i.e. VLAN filters are required to |
| 3262 | * receive VLAN tagged packets due to vPort restrictions). |
| 3263 | */ |
| 3264 | net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 3265 | net_dev->features |= efx->fixed_features; |
| 3266 | |
| 3267 | rc = efx_register_netdev(efx); |
| 3268 | if (!rc) |
| 3269 | return 0; |
| 3270 | |
| 3271 | efx_pci_remove_main(efx); |
| 3272 | return rc; |
| 3273 | } |
| 3274 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3275 | /* NIC initialisation |
| 3276 | * |
| 3277 | * This is called at module load (or hotplug insertion, |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 3278 | * theoretically). It sets up PCI mappings, resets the NIC, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3279 | * sets up and registers the network devices with the kernel and hooks |
| 3280 | * the interrupt service routine. It does not prepare the device for |
| 3281 | * transmission; this is left to the first time one of the network |
| 3282 | * interfaces is brought up (i.e. efx_net_open). |
| 3283 | */ |
Bill Pemberton | 87d1fc1 | 2012-12-03 09:23:32 -0500 | [diff] [blame] | 3284 | static int efx_pci_probe(struct pci_dev *pci_dev, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 3285 | const struct pci_device_id *entry) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3286 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3287 | struct net_device *net_dev; |
| 3288 | struct efx_nic *efx; |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 3289 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3290 | |
| 3291 | /* Allocate and initialise a struct net_device and struct efx_nic */ |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 3292 | net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES, |
| 3293 | EFX_MAX_RX_QUEUES); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3294 | if (!net_dev) |
| 3295 | return -ENOMEM; |
Ben Hutchings | adeb15a | 2012-08-02 01:39:38 +0100 | [diff] [blame] | 3296 | efx = netdev_priv(net_dev); |
| 3297 | efx->type = (const struct efx_nic_type *) entry->driver_data; |
Andrew Rybchenko | ebfcd0f | 2016-06-15 17:43:20 +0100 | [diff] [blame] | 3298 | efx->fixed_features |= NETIF_F_HIGHDMA; |
Andrew Rybchenko | eb7cfd8 | 2016-06-15 17:51:36 +0100 | [diff] [blame] | 3299 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3300 | pci_set_drvdata(pci_dev, efx); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3301 | SET_NETDEV_DEV(net_dev, &pci_dev->dev); |
Ben Hutchings | adeb15a | 2012-08-02 01:39:38 +0100 | [diff] [blame] | 3302 | rc = efx_init_struct(efx, pci_dev, net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3303 | if (rc) |
| 3304 | goto fail1; |
| 3305 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3306 | netif_info(efx, probe, efx->net_dev, |
Ben Hutchings | ff79c8a | 2011-07-13 16:21:24 +0100 | [diff] [blame] | 3307 | "Solarflare NIC detected\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3308 | |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 3309 | if (!efx->type->is_vf) |
| 3310 | efx_probe_vpd_strings(efx); |
Ben Hutchings | 460eeaa | 2012-03-05 15:35:39 +0000 | [diff] [blame] | 3311 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3312 | /* Set up basic I/O (BAR mappings etc) */ |
| 3313 | rc = efx_init_io(efx); |
| 3314 | if (rc) |
| 3315 | goto fail2; |
| 3316 | |
Jon Cooper | 8a53140 | 2017-02-08 16:51:18 +0000 | [diff] [blame] | 3317 | rc = efx_pci_probe_post_io(efx); |
| 3318 | if (rc) { |
| 3319 | /* On failure, retry once immediately. |
| 3320 | * If we aborted probe due to a scheduled reset, dismiss it. |
| 3321 | */ |
| 3322 | efx->reset_pending = 0; |
| 3323 | rc = efx_pci_probe_post_io(efx); |
| 3324 | if (rc) { |
| 3325 | /* On another failure, retry once more |
| 3326 | * after a 50-305ms delay. |
| 3327 | */ |
| 3328 | unsigned char r; |
| 3329 | |
| 3330 | get_random_bytes(&r, 1); |
| 3331 | msleep((unsigned int)r + 50); |
| 3332 | efx->reset_pending = 0; |
| 3333 | rc = efx_pci_probe_post_io(efx); |
| 3334 | } |
| 3335 | } |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 3336 | if (rc) |
| 3337 | goto fail3; |
Steve Hodgson | fa402b2 | 2008-12-12 22:08:16 -0800 | [diff] [blame] | 3338 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3339 | netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 3340 | |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 3341 | /* Try to create MTDs, but allow this to fail */ |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 3342 | rtnl_lock(); |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 3343 | rc = efx_mtd_probe(efx); |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 3344 | rtnl_unlock(); |
Bert Kenward | 09a0420 | 2015-12-23 08:58:15 +0000 | [diff] [blame] | 3345 | if (rc && rc != -EPERM) |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 3346 | netif_warn(efx, probe, efx->net_dev, |
| 3347 | "failed to create MTDs (%d)\n", rc); |
| 3348 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3349 | rc = pci_enable_pcie_error_reporting(pci_dev); |
| 3350 | if (rc && rc != -EINVAL) |
Bert Kenward | 09a0420 | 2015-12-23 08:58:15 +0000 | [diff] [blame] | 3351 | netif_notice(efx, probe, efx->net_dev, |
| 3352 | "PCIE error reporting unavailable (%d).\n", |
| 3353 | rc); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3354 | |
Jon Cooper | e5fbd97 | 2017-02-08 16:52:10 +0000 | [diff] [blame] | 3355 | if (efx->type->udp_tnl_push_ports) |
| 3356 | efx->type->udp_tnl_push_ports(efx); |
| 3357 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3358 | return 0; |
| 3359 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3360 | fail3: |
| 3361 | efx_fini_io(efx); |
| 3362 | fail2: |
| 3363 | efx_fini_struct(efx); |
| 3364 | fail1: |
Steve Hodgson | 5e2a911 | 2010-02-12 12:32:27 -0800 | [diff] [blame] | 3365 | WARN_ON(rc > 0); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 3366 | netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3367 | free_netdev(net_dev); |
| 3368 | return rc; |
| 3369 | } |
| 3370 | |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 3371 | /* efx_pci_sriov_configure returns the actual number of Virtual Functions |
| 3372 | * enabled on success |
| 3373 | */ |
| 3374 | #ifdef CONFIG_SFC_SRIOV |
| 3375 | static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) |
| 3376 | { |
| 3377 | int rc; |
| 3378 | struct efx_nic *efx = pci_get_drvdata(dev); |
| 3379 | |
| 3380 | if (efx->type->sriov_configure) { |
| 3381 | rc = efx->type->sriov_configure(efx, num_vfs); |
| 3382 | if (rc) |
| 3383 | return rc; |
| 3384 | else |
| 3385 | return num_vfs; |
| 3386 | } else |
| 3387 | return -EOPNOTSUPP; |
| 3388 | } |
| 3389 | #endif |
| 3390 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3391 | static int efx_pm_freeze(struct device *dev) |
| 3392 | { |
| 3393 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 3394 | |
Ben Hutchings | 61da026 | 2012-07-27 19:35:39 +0100 | [diff] [blame] | 3395 | rtnl_lock(); |
| 3396 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3397 | if (efx->state != STATE_DISABLED) { |
| 3398 | efx->state = STATE_UNINIT; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3399 | |
Daniel Pieczko | c2f3b8e | 2012-10-17 13:21:23 +0100 | [diff] [blame] | 3400 | efx_device_detach_sync(efx); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3401 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3402 | efx_stop_all(efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 3403 | efx_disable_interrupts(efx); |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3404 | } |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3405 | |
Ben Hutchings | 61da026 | 2012-07-27 19:35:39 +0100 | [diff] [blame] | 3406 | rtnl_unlock(); |
| 3407 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3408 | return 0; |
| 3409 | } |
| 3410 | |
| 3411 | static int efx_pm_thaw(struct device *dev) |
| 3412 | { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3413 | int rc; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3414 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 3415 | |
Ben Hutchings | 61da026 | 2012-07-27 19:35:39 +0100 | [diff] [blame] | 3416 | rtnl_lock(); |
| 3417 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3418 | if (efx->state != STATE_DISABLED) { |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3419 | rc = efx_enable_interrupts(efx); |
| 3420 | if (rc) |
| 3421 | goto fail; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3422 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3423 | mutex_lock(&efx->mac_lock); |
| 3424 | efx->phy_op->reconfigure(efx); |
| 3425 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3426 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3427 | efx_start_all(efx); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3428 | |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 3429 | efx_device_attach_if_not_resetting(efx); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3430 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3431 | efx->state = STATE_READY; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3432 | |
Ben Hutchings | 6032fb5 | 2012-07-27 19:35:47 +0100 | [diff] [blame] | 3433 | efx->type->resume_wol(efx); |
| 3434 | } |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3435 | |
Ben Hutchings | 61da026 | 2012-07-27 19:35:39 +0100 | [diff] [blame] | 3436 | rtnl_unlock(); |
| 3437 | |
Steve Hodgson | 319ba64 | 2010-06-01 11:17:24 +0000 | [diff] [blame] | 3438 | /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ |
| 3439 | queue_work(reset_workqueue, &efx->reset_work); |
| 3440 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3441 | return 0; |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3442 | |
| 3443 | fail: |
| 3444 | rtnl_unlock(); |
| 3445 | |
| 3446 | return rc; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | static int efx_pm_poweroff(struct device *dev) |
| 3450 | { |
| 3451 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 3452 | struct efx_nic *efx = pci_get_drvdata(pci_dev); |
| 3453 | |
| 3454 | efx->type->fini(efx); |
| 3455 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 3456 | efx->reset_pending = 0; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3457 | |
| 3458 | pci_save_state(pci_dev); |
| 3459 | return pci_set_power_state(pci_dev, PCI_D3hot); |
| 3460 | } |
| 3461 | |
| 3462 | /* Used for both resume and restore */ |
| 3463 | static int efx_pm_resume(struct device *dev) |
| 3464 | { |
| 3465 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 3466 | struct efx_nic *efx = pci_get_drvdata(pci_dev); |
| 3467 | int rc; |
| 3468 | |
| 3469 | rc = pci_set_power_state(pci_dev, PCI_D0); |
| 3470 | if (rc) |
| 3471 | return rc; |
| 3472 | pci_restore_state(pci_dev); |
| 3473 | rc = pci_enable_device(pci_dev); |
| 3474 | if (rc) |
| 3475 | return rc; |
| 3476 | pci_set_master(efx->pci_dev); |
| 3477 | rc = efx->type->reset(efx, RESET_TYPE_ALL); |
| 3478 | if (rc) |
| 3479 | return rc; |
| 3480 | rc = efx->type->init(efx); |
| 3481 | if (rc) |
| 3482 | return rc; |
Jon Cooper | 261e4d9 | 2013-04-15 18:51:54 +0100 | [diff] [blame] | 3483 | rc = efx_pm_thaw(dev); |
| 3484 | return rc; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | static int efx_pm_suspend(struct device *dev) |
| 3488 | { |
| 3489 | int rc; |
| 3490 | |
| 3491 | efx_pm_freeze(dev); |
| 3492 | rc = efx_pm_poweroff(dev); |
| 3493 | if (rc) |
| 3494 | efx_pm_resume(dev); |
| 3495 | return rc; |
| 3496 | } |
| 3497 | |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 3498 | static const struct dev_pm_ops efx_pm_ops = { |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3499 | .suspend = efx_pm_suspend, |
| 3500 | .resume = efx_pm_resume, |
| 3501 | .freeze = efx_pm_freeze, |
| 3502 | .thaw = efx_pm_thaw, |
| 3503 | .poweroff = efx_pm_poweroff, |
| 3504 | .restore = efx_pm_resume, |
| 3505 | }; |
| 3506 | |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3507 | /* A PCI error affecting this device was detected. |
| 3508 | * At this point MMIO and DMA may be disabled. |
| 3509 | * Stop the software path and request a slot reset. |
| 3510 | */ |
stephen hemminger | debd003 | 2013-03-16 06:57:51 +0000 | [diff] [blame] | 3511 | static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev, |
| 3512 | enum pci_channel_state state) |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3513 | { |
| 3514 | pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; |
| 3515 | struct efx_nic *efx = pci_get_drvdata(pdev); |
| 3516 | |
| 3517 | if (state == pci_channel_io_perm_failure) |
| 3518 | return PCI_ERS_RESULT_DISCONNECT; |
| 3519 | |
| 3520 | rtnl_lock(); |
| 3521 | |
| 3522 | if (efx->state != STATE_DISABLED) { |
| 3523 | efx->state = STATE_RECOVERY; |
| 3524 | efx->reset_pending = 0; |
| 3525 | |
| 3526 | efx_device_detach_sync(efx); |
| 3527 | |
| 3528 | efx_stop_all(efx); |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 3529 | efx_disable_interrupts(efx); |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3530 | |
| 3531 | status = PCI_ERS_RESULT_NEED_RESET; |
| 3532 | } else { |
| 3533 | /* If the interface is disabled we don't want to do anything |
| 3534 | * with it. |
| 3535 | */ |
| 3536 | status = PCI_ERS_RESULT_RECOVERED; |
| 3537 | } |
| 3538 | |
| 3539 | rtnl_unlock(); |
| 3540 | |
| 3541 | pci_disable_device(pdev); |
| 3542 | |
| 3543 | return status; |
| 3544 | } |
| 3545 | |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 3546 | /* Fake a successful reset, which will be performed later in efx_io_resume. */ |
stephen hemminger | debd003 | 2013-03-16 06:57:51 +0000 | [diff] [blame] | 3547 | static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev) |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3548 | { |
| 3549 | struct efx_nic *efx = pci_get_drvdata(pdev); |
| 3550 | pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; |
| 3551 | int rc; |
| 3552 | |
| 3553 | if (pci_enable_device(pdev)) { |
| 3554 | netif_err(efx, hw, efx->net_dev, |
| 3555 | "Cannot re-enable PCI device after reset.\n"); |
| 3556 | status = PCI_ERS_RESULT_DISCONNECT; |
| 3557 | } |
| 3558 | |
| 3559 | rc = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 3560 | if (rc) { |
| 3561 | netif_err(efx, hw, efx->net_dev, |
| 3562 | "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc); |
| 3563 | /* Non-fatal error. Continue. */ |
| 3564 | } |
| 3565 | |
| 3566 | return status; |
| 3567 | } |
| 3568 | |
| 3569 | /* Perform the actual reset and resume I/O operations. */ |
| 3570 | static void efx_io_resume(struct pci_dev *pdev) |
| 3571 | { |
| 3572 | struct efx_nic *efx = pci_get_drvdata(pdev); |
| 3573 | int rc; |
| 3574 | |
| 3575 | rtnl_lock(); |
| 3576 | |
| 3577 | if (efx->state == STATE_DISABLED) |
| 3578 | goto out; |
| 3579 | |
| 3580 | rc = efx_reset(efx, RESET_TYPE_ALL); |
| 3581 | if (rc) { |
| 3582 | netif_err(efx, hw, efx->net_dev, |
| 3583 | "efx_reset failed after PCI error (%d)\n", rc); |
| 3584 | } else { |
| 3585 | efx->state = STATE_READY; |
| 3586 | netif_dbg(efx, hw, efx->net_dev, |
| 3587 | "Done resetting and resuming IO after PCI error.\n"); |
| 3588 | } |
| 3589 | |
| 3590 | out: |
| 3591 | rtnl_unlock(); |
| 3592 | } |
| 3593 | |
| 3594 | /* For simplicity and reliability, we always require a slot reset and try to |
| 3595 | * reset the hardware when a pci error affecting the device is detected. |
| 3596 | * We leave both the link_reset and mmio_enabled callback unimplemented: |
| 3597 | * with our request for slot reset the mmio_enabled callback will never be |
| 3598 | * called, and the link_reset callback is not used by AER or EEH mechanisms. |
| 3599 | */ |
Julia Lawall | c300366b | 2015-11-14 11:06:57 +0100 | [diff] [blame] | 3600 | static const struct pci_error_handlers efx_err_handlers = { |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3601 | .error_detected = efx_io_error_detected, |
| 3602 | .slot_reset = efx_io_slot_reset, |
| 3603 | .resume = efx_io_resume, |
| 3604 | }; |
| 3605 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3606 | static struct pci_driver efx_pci_driver = { |
Ben Hutchings | c5d5f5f | 2010-06-23 11:30:26 +0000 | [diff] [blame] | 3607 | .name = KBUILD_MODNAME, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3608 | .id_table = efx_pci_table, |
| 3609 | .probe = efx_pci_probe, |
| 3610 | .remove = efx_pci_remove, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 3611 | .driver.pm = &efx_pm_ops, |
Alexandre Rames | 626950d | 2013-01-14 17:20:22 +0000 | [diff] [blame] | 3612 | .err_handler = &efx_err_handlers, |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 3613 | #ifdef CONFIG_SFC_SRIOV |
| 3614 | .sriov_configure = efx_pci_sriov_configure, |
| 3615 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3616 | }; |
| 3617 | |
| 3618 | /************************************************************************** |
| 3619 | * |
| 3620 | * Kernel module interface |
| 3621 | * |
| 3622 | *************************************************************************/ |
| 3623 | |
| 3624 | module_param(interrupt_mode, uint, 0444); |
| 3625 | MODULE_PARM_DESC(interrupt_mode, |
| 3626 | "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); |
| 3627 | |
| 3628 | static int __init efx_init_module(void) |
| 3629 | { |
| 3630 | int rc; |
| 3631 | |
| 3632 | printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n"); |
| 3633 | |
| 3634 | rc = register_netdevice_notifier(&efx_netdev_notifier); |
| 3635 | if (rc) |
| 3636 | goto err_notifier; |
| 3637 | |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3638 | #ifdef CONFIG_SFC_SRIOV |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 3639 | rc = efx_init_sriov(); |
| 3640 | if (rc) |
| 3641 | goto err_sriov; |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3642 | #endif |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 3643 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 3644 | reset_workqueue = create_singlethread_workqueue("sfc_reset"); |
| 3645 | if (!reset_workqueue) { |
| 3646 | rc = -ENOMEM; |
| 3647 | goto err_reset; |
| 3648 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3649 | |
| 3650 | rc = pci_register_driver(&efx_pci_driver); |
| 3651 | if (rc < 0) |
| 3652 | goto err_pci; |
| 3653 | |
| 3654 | return 0; |
| 3655 | |
| 3656 | err_pci: |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 3657 | destroy_workqueue(reset_workqueue); |
| 3658 | err_reset: |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3659 | #ifdef CONFIG_SFC_SRIOV |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 3660 | efx_fini_sriov(); |
| 3661 | err_sriov: |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3662 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3663 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 3664 | err_notifier: |
| 3665 | return rc; |
| 3666 | } |
| 3667 | |
| 3668 | static void __exit efx_exit_module(void) |
| 3669 | { |
| 3670 | printk(KERN_INFO "Solarflare NET driver unloading\n"); |
| 3671 | |
| 3672 | pci_unregister_driver(&efx_pci_driver); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 3673 | destroy_workqueue(reset_workqueue); |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3674 | #ifdef CONFIG_SFC_SRIOV |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 3675 | efx_fini_sriov(); |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3676 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3677 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 3678 | |
| 3679 | } |
| 3680 | |
| 3681 | module_init(efx_init_module); |
| 3682 | module_exit(efx_exit_module); |
| 3683 | |
Ben Hutchings | 906bb26 | 2009-11-29 15:16:19 +0000 | [diff] [blame] | 3684 | MODULE_AUTHOR("Solarflare Communications and " |
| 3685 | "Michael Brown <mbrown@fensystems.co.uk>"); |
Ben Hutchings | 6a350fd | 2014-02-12 19:00:07 +0000 | [diff] [blame] | 3686 | MODULE_DESCRIPTION("Solarflare network driver"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3687 | MODULE_LICENSE("GPL"); |
| 3688 | MODULE_DEVICE_TABLE(pci, efx_pci_table); |
Edward Cree | 14077e9 | 2017-01-03 15:46:00 +0000 | [diff] [blame] | 3689 | MODULE_VERSION(EFX_DRIVER_VERSION); |