blob: 12f0abc30cb1284e6f0c04847d71a923ab65a342 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01002 * Driver for Solarflare network controllers and boards
Ben Hutchings8ceee662008-04-27 12:55:59 +01003 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01004 * Copyright 2005-2013 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01005 *
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 Hutchings8ceee662008-04-27 12:55:59 +010020#include <linux/ethtool.h>
Ben Hutchingsaa6ef272008-07-18 19:03:10 +010021#include <linux/topology.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
Alexandre Rames626950d2013-01-14 17:20:22 +000023#include <linux/aer.h>
Alexandre Ramesb28405b2013-03-21 16:41:43 +000024#include <linux/interrupt.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010025#include "net_driver.h"
Jon Coopere5fbd972017-02-08 16:52:10 +000026#include <net/gre.h>
27#include <net/udp_tunnel.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010028#include "efx.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000029#include "nic.h"
Edward Cree71827442017-12-18 16:56:19 +000030#include "io.h"
Ben Hutchingsdd407812012-02-28 23:40:21 +000031#include "selftest.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010032#include "sriov.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010033
Ben Hutchings8880f4e2009-11-29 15:15:41 +000034#include "mcdi.h"
Jon Coopere5fbd972017-02-08 16:52:10 +000035#include "mcdi_pcol.h"
Steve Hodgsonfd371e32010-06-01 11:17:51 +000036#include "workarounds.h"
Ben Hutchings8880f4e2009-11-29 15:15:41 +000037
Ben Hutchingsc4593022009-11-23 16:08:17 +000038/**************************************************************************
39 *
40 * Type name strings
41 *
42 **************************************************************************
43 */
44
45/* Loopback mode names (see LOOPBACK_MODE()) */
46const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
Ben Hutchings18e83e42012-01-05 19:05:20 +000047const char *const efx_loopback_mode_names[] = {
Ben Hutchingsc4593022009-11-23 16:08:17 +000048 [LOOPBACK_NONE] = "NONE",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000049 [LOOPBACK_DATA] = "DATAPATH",
Ben Hutchingsc4593022009-11-23 16:08:17 +000050 [LOOPBACK_GMAC] = "GMAC",
51 [LOOPBACK_XGMII] = "XGMII",
52 [LOOPBACK_XGXS] = "XGXS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000053 [LOOPBACK_XAUI] = "XAUI",
54 [LOOPBACK_GMII] = "GMII",
55 [LOOPBACK_SGMII] = "SGMII",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000056 [LOOPBACK_XGBR] = "XGBR",
57 [LOOPBACK_XFI] = "XFI",
58 [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
59 [LOOPBACK_GMII_FAR] = "GMII_FAR",
60 [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
61 [LOOPBACK_XFI_FAR] = "XFI_FAR",
Ben Hutchingsc4593022009-11-23 16:08:17 +000062 [LOOPBACK_GPHY] = "GPHY",
63 [LOOPBACK_PHYXS] = "PHYXS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000064 [LOOPBACK_PCS] = "PCS",
65 [LOOPBACK_PMAPMD] = "PMA/PMD",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000066 [LOOPBACK_XPORT] = "XPORT",
67 [LOOPBACK_XGMII_WS] = "XGMII_WS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000068 [LOOPBACK_XAUI_WS] = "XAUI_WS",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000069 [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
70 [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000071 [LOOPBACK_GMII_WS] = "GMII_WS",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000072 [LOOPBACK_XFI_WS] = "XFI_WS",
73 [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000074 [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
Ben Hutchingsc4593022009-11-23 16:08:17 +000075};
76
Ben Hutchingsc4593022009-11-23 16:08:17 +000077const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
Ben Hutchings18e83e42012-01-05 19:05:20 +000078const char *const efx_reset_type_names[] = {
Alexandre Rames626950d2013-01-14 17:20:22 +000079 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
80 [RESET_TYPE_ALL] = "ALL",
81 [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
82 [RESET_TYPE_WORLD] = "WORLD",
83 [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
Jon Cooper087e9022015-05-20 11:11:35 +010084 [RESET_TYPE_DATAPATH] = "DATAPATH",
Edward Creee2835462014-04-16 19:27:48 +010085 [RESET_TYPE_MC_BIST] = "MC_BIST",
Alexandre Rames626950d2013-01-14 17:20:22 +000086 [RESET_TYPE_DISABLE] = "DISABLE",
87 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
88 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
Alexandre Rames3de82b92013-06-13 11:36:15 +010089 [RESET_TYPE_DMA_ERROR] = "DMA_ERROR",
Alexandre Rames626950d2013-01-14 17:20:22 +000090 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
91 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
Edward Creee2835462014-04-16 19:27:48 +010092 [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)",
Ben Hutchingsc4593022009-11-23 16:08:17 +000093};
94
Jon Coopere5fbd972017-02-08 16:52:10 +000095/* UDP tunnel type names */
96static const char *const efx_udp_tunnel_type_names[] = {
97 [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
98 [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
99};
100
101void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
102{
103 if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
104 efx_udp_tunnel_type_names[type] != NULL)
105 snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
106 else
107 snprintf(buf, buflen, "type %d", type);
108}
109
Steve Hodgson1ab00622008-12-12 21:33:02 -0800110/* Reset workqueue. If any NIC has a hardware failure then a reset will be
111 * queued onto this work queue. This is not a per-nic work queue, because
112 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
113 */
114static struct workqueue_struct *reset_workqueue;
115
Jon Cooper74cd60a2013-09-16 14:18:51 +0100116/* How often and how many times to poll for a reset while waiting for a
117 * BIST that another function started to complete.
118 */
119#define BIST_WAIT_DELAY_MS 100
120#define BIST_WAIT_DELAY_COUNT 100
121
Ben Hutchings8ceee662008-04-27 12:55:59 +0100122/**************************************************************************
123 *
124 * Configurable values
125 *
126 *************************************************************************/
127
128/*
Ben Hutchings8ceee662008-04-27 12:55:59 +0100129 * Use separate channels for TX and RX events
130 *
Neil Turton28b581a2008-12-12 21:41:06 -0800131 * Set this to 1 to use separate channels for TX and RX. It allows us
132 * to control interrupt affinity separately for TX and RX.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133 *
Neil Turton28b581a2008-12-12 21:41:06 -0800134 * This is only used in MSI-X interrupt mode
Ben Hutchings8ceee662008-04-27 12:55:59 +0100135 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100136bool efx_separate_tx_channels;
137module_param(efx_separate_tx_channels, bool, 0444);
138MODULE_PARM_DESC(efx_separate_tx_channels,
Neil Turton28b581a2008-12-12 21:41:06 -0800139 "Use separate channels for TX and RX");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100140
141/* This is the weight assigned to each of the (per-channel) virtual
142 * NAPI devices.
143 */
144static int napi_weight = 64;
145
146/* This is the time (in jiffies) between invocations of the hardware
Alexandre Rames626950d2013-01-14 17:20:22 +0000147 * monitor.
148 * On Falcon-based NICs, this will:
Ben Hutchingse254c272010-09-20 08:44:10 +0000149 * - Check the on-board hardware monitor;
150 * - Poll the link state and reconfigure the hardware as necessary.
Alexandre Rames626950d2013-01-14 17:20:22 +0000151 * On Siena-based NICs for power systems with EEH support, this will give EEH a
152 * chance to start.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100153 */
stephen hemmingerd2156972010-10-18 05:27:31 +0000154static unsigned int efx_monitor_interval = 1 * HZ;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100155
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156/* Initial interrupt moderation settings. They can be modified after
157 * module load with ethtool.
158 *
159 * The default for RX should strike a balance between increasing the
160 * round-trip latency and reducing overhead.
161 */
162static unsigned int rx_irq_mod_usec = 60;
163
164/* Initial interrupt moderation settings. They can be modified after
165 * module load with ethtool.
166 *
167 * This default is chosen to ensure that a 10G link does not go idle
168 * while a TX queue is stopped after it has become full. A queue is
169 * restarted when it drops below half full. The time this takes (assuming
170 * worst case 3 descriptors per packet and 1024 descriptors) is
171 * 512 / 3 * 1.2 = 205 usec.
172 */
173static unsigned int tx_irq_mod_usec = 150;
174
175/* This is the first interrupt mode to try out of:
176 * 0 => MSI-X
177 * 1 => MSI
178 * 2 => legacy
179 */
180static unsigned int interrupt_mode;
181
182/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
183 * i.e. the number of CPUs among which we may distribute simultaneous
184 * interrupt handling.
185 *
186 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
Ben Hutchingscdb08f82011-12-20 01:08:05 +0000187 * The default (0) means to assign an interrupt to each core.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188 */
189static unsigned int rss_cpus;
190module_param(rss_cpus, uint, 0444);
191MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
192
Ben Hutchingsb9cc9772012-11-28 04:12:41 +0000193static bool phy_flash_cfg;
194module_param(phy_flash_cfg, bool, 0644);
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800195MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
196
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000197static unsigned irq_adapt_low_thresh = 8000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000198module_param(irq_adapt_low_thresh, uint, 0644);
199MODULE_PARM_DESC(irq_adapt_low_thresh,
200 "Threshold score for reducing IRQ moderation");
201
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000202static unsigned irq_adapt_high_thresh = 16000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000203module_param(irq_adapt_high_thresh, uint, 0644);
204MODULE_PARM_DESC(irq_adapt_high_thresh,
205 "Threshold score for increasing IRQ moderation");
206
Ben Hutchings62776d02010-06-23 11:30:07 +0000207static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
208 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
209 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
210 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
211module_param(debug, uint, 0);
212MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
213
Ben Hutchings8ceee662008-04-27 12:55:59 +0100214/**************************************************************************
215 *
216 * Utility functions and prototypes
217 *
218 *************************************************************************/
Ben Hutchings46426102010-09-10 06:42:33 +0000219
Jon Cooper261e4d92013-04-15 18:51:54 +0100220static int efx_soft_enable_interrupts(struct efx_nic *efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +0100221static void efx_soft_disable_interrupts(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000222static void efx_remove_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000223static void efx_remove_channels(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000224static const struct efx_channel_type efx_default_channel_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100225static void efx_remove_port(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000226static void efx_init_napi_channel(struct efx_channel *channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100227static void efx_fini_napi(struct efx_nic *efx);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000228static void efx_fini_napi_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000229static void efx_fini_struct(struct efx_nic *efx);
230static void efx_start_all(struct efx_nic *efx);
231static void efx_stop_all(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100232
233#define EFX_ASSERT_RESET_SERIALISED(efx) \
234 do { \
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100235 if ((efx->state == STATE_READY) || \
Alexandre Rames626950d2013-01-14 17:20:22 +0000236 (efx->state == STATE_RECOVERY) || \
Ben Hutchings332c1ce2009-11-25 16:08:52 +0000237 (efx->state == STATE_DISABLED)) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100238 ASSERT_RTNL(); \
239 } while (0)
240
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100241static int efx_check_disabled(struct efx_nic *efx)
242{
Alexandre Rames626950d2013-01-14 17:20:22 +0000243 if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100244 netif_err(efx, drv, efx->net_dev,
245 "device is disabled due to earlier errors\n");
246 return -EIO;
247 }
248 return 0;
249}
250
Ben Hutchings8ceee662008-04-27 12:55:59 +0100251/**************************************************************************
252 *
253 * Event queue processing
254 *
255 *************************************************************************/
256
257/* Process channel's event queue
258 *
259 * This function is responsible for processing the event queue of a
260 * single channel. The caller must guarantee that this function will
261 * never be concurrently called more than once on the same channel,
262 * though different channels may be being processed concurrently.
263 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000264static int efx_process_channel(struct efx_channel *channel, int budget)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100265{
Peter Dunningc9368352015-07-08 10:05:10 +0100266 struct efx_tx_queue *tx_queue;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000267 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100268
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000269 if (unlikely(!channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100270 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100271
Peter Dunningc9368352015-07-08 10:05:10 +0100272 efx_for_each_channel_tx_queue(tx_queue, channel) {
273 tx_queue->pkts_compl = 0;
274 tx_queue->bytes_compl = 0;
275 }
276
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000277 spent = efx_nic_process_eventq(channel, budget);
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000278 if (spent && efx_channel_has_rx_queue(channel)) {
279 struct efx_rx_queue *rx_queue =
280 efx_channel_get_rx_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100281
Ben Hutchingsff734ef2013-01-29 23:33:14 +0000282 efx_rx_flush_packet(channel);
Jon Coopercce28792013-10-02 11:04:14 +0100283 efx_fast_push_rx_descriptors(rx_queue, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100284 }
285
Peter Dunningc9368352015-07-08 10:05:10 +0100286 /* Update BQL */
287 efx_for_each_channel_tx_queue(tx_queue, channel) {
288 if (tx_queue->bytes_compl) {
289 netdev_tx_completed_queue(tx_queue->core_txq,
290 tx_queue->pkts_compl, tx_queue->bytes_compl);
291 }
292 }
293
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000294 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100295}
296
Ben Hutchings8ceee662008-04-27 12:55:59 +0100297/* NAPI poll handler
298 *
299 * NAPI guarantees serialisation of polls of the same device, which
300 * provides the guarantee required by efx_process_channel().
301 */
Bert Kenward539de7c2016-08-11 13:02:09 +0100302static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
303{
304 int step = efx->irq_mod_step_us;
305
306 if (channel->irq_mod_score < irq_adapt_low_thresh) {
307 if (channel->irq_moderation_us > step) {
308 channel->irq_moderation_us -= step;
309 efx->type->push_irq_moderation(channel);
310 }
311 } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
312 if (channel->irq_moderation_us <
313 efx->irq_rx_moderation_us) {
314 channel->irq_moderation_us += step;
315 efx->type->push_irq_moderation(channel);
316 }
317 }
318
319 channel->irq_count = 0;
320 channel->irq_mod_score = 0;
321}
322
Ben Hutchings8ceee662008-04-27 12:55:59 +0100323static int efx_poll(struct napi_struct *napi, int budget)
324{
325 struct efx_channel *channel =
326 container_of(napi, struct efx_channel, napi_str);
Ben Hutchings62776d02010-06-23 11:30:07 +0000327 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000328 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100329
Ben Hutchings62776d02010-06-23 11:30:07 +0000330 netif_vdbg(efx, intr, efx->net_dev,
331 "channel %d NAPI poll executing on CPU %d\n",
332 channel->channel, raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +0100333
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000334 spent = efx_process_channel(channel, budget);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100335
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000336 if (spent < budget) {
Ben Hutchings9d9a6972012-02-10 23:01:48 +0000337 if (efx_channel_has_rx_queue(channel) &&
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000338 efx->irq_rx_adaptive &&
339 unlikely(++channel->irq_count == 1000)) {
Bert Kenward539de7c2016-08-11 13:02:09 +0100340 efx_update_irq_mod(efx, channel);
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000341 }
342
Ben Hutchings64d8ad62011-01-05 00:50:41 +0000343 efx_filter_rfs_expire(channel);
344
Ben Hutchings8ceee662008-04-27 12:55:59 +0100345 /* There is no race here; although napi_disable() will
Ben Hutchings288379f2009-01-19 16:43:59 -0800346 * only wait for napi_complete(), this isn't a problem
Ben Hutchings514bedb2012-10-05 19:30:16 +0100347 * since efx_nic_eventq_read_ack() will have no effect if
Ben Hutchings8ceee662008-04-27 12:55:59 +0100348 * interrupts have already been disabled.
349 */
Bert Kenwardf820c0a2017-02-06 16:50:55 +0000350 if (napi_complete_done(napi, spent))
351 efx_nic_eventq_read_ack(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100352 }
353
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000354 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100355}
356
Ben Hutchings8ceee662008-04-27 12:55:59 +0100357/* Create event queue
358 * Event queue memory allocations are done only once. If the channel
359 * is reset, the memory buffer will be reused; this guards against
360 * errors during channel reset and also simplifies interrupt handling.
361 */
362static int efx_probe_eventq(struct efx_channel *channel)
363{
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000364 struct efx_nic *efx = channel->efx;
365 unsigned long entries;
366
Ben Hutchings86ee5302012-01-09 19:51:22 +0000367 netif_dbg(efx, probe, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000368 "chan %d create event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100369
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000370 /* Build an event queue with room for one event per tx and rx buffer,
371 * plus some extra for link state events and MCDI completions. */
372 entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
Edward Creee01b16a2016-12-02 15:51:33 +0000373 EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000374 channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
375
Ben Hutchings152b6a62009-11-29 03:43:56 +0000376 return efx_nic_probe_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100377}
378
379/* Prepare channel's event queue */
Jon Cooper261e4d92013-04-15 18:51:54 +0100380static int efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100381{
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100382 struct efx_nic *efx = channel->efx;
Jon Cooper261e4d92013-04-15 18:51:54 +0100383 int rc;
384
385 EFX_WARN_ON_PARANOID(channel->eventq_init);
386
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100387 netif_dbg(efx, drv, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000388 "chan %d init event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100389
Jon Cooper261e4d92013-04-15 18:51:54 +0100390 rc = efx_nic_init_eventq(channel);
391 if (rc == 0) {
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100392 efx->type->push_irq_moderation(channel);
Jon Cooper261e4d92013-04-15 18:51:54 +0100393 channel->eventq_read_ptr = 0;
394 channel->eventq_init = true;
395 }
396 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397}
398
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000399/* Enable event queue processing and NAPI */
Alexandre Rames36763262014-07-22 14:03:25 +0100400void efx_start_eventq(struct efx_channel *channel)
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000401{
402 netif_dbg(channel->efx, ifup, channel->efx->net_dev,
403 "chan %d start event queue\n", channel->channel);
404
Ben Hutchings514bedb2012-10-05 19:30:16 +0100405 /* Make sure the NAPI handler sees the enabled flag set */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000406 channel->enabled = true;
407 smp_wmb();
408
409 napi_enable(&channel->napi_str);
410 efx_nic_eventq_read_ack(channel);
411}
412
413/* Disable event queue processing and NAPI */
Alexandre Rames36763262014-07-22 14:03:25 +0100414void efx_stop_eventq(struct efx_channel *channel)
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000415{
416 if (!channel->enabled)
417 return;
418
419 napi_disable(&channel->napi_str);
420 channel->enabled = false;
421}
422
Ben Hutchings8ceee662008-04-27 12:55:59 +0100423static void efx_fini_eventq(struct efx_channel *channel)
424{
Ben Hutchingsbe3fc092012-10-08 18:21:51 +0100425 if (!channel->eventq_init)
426 return;
427
Ben Hutchings62776d02010-06-23 11:30:07 +0000428 netif_dbg(channel->efx, drv, channel->efx->net_dev,
429 "chan %d fini event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100430
Ben Hutchings152b6a62009-11-29 03:43:56 +0000431 efx_nic_fini_eventq(channel);
Ben Hutchingsbe3fc092012-10-08 18:21:51 +0100432 channel->eventq_init = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100433}
434
435static void efx_remove_eventq(struct efx_channel *channel)
436{
Ben Hutchings62776d02010-06-23 11:30:07 +0000437 netif_dbg(channel->efx, drv, channel->efx->net_dev,
438 "chan %d remove event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100439
Ben Hutchings152b6a62009-11-29 03:43:56 +0000440 efx_nic_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100441}
442
443/**************************************************************************
444 *
445 * Channel handling
446 *
447 *************************************************************************/
448
Ben Hutchings7f967c02012-02-13 23:45:02 +0000449/* Allocate and initialise a channel structure. */
Ben Hutchings46426102010-09-10 06:42:33 +0000450static struct efx_channel *
451efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
452{
453 struct efx_channel *channel;
454 struct efx_rx_queue *rx_queue;
455 struct efx_tx_queue *tx_queue;
456 int j;
457
Ben Hutchings7f967c02012-02-13 23:45:02 +0000458 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
459 if (!channel)
460 return NULL;
Ben Hutchings46426102010-09-10 06:42:33 +0000461
Ben Hutchings7f967c02012-02-13 23:45:02 +0000462 channel->efx = efx;
463 channel->channel = i;
464 channel->type = &efx_default_channel_type;
Ben Hutchings46426102010-09-10 06:42:33 +0000465
Ben Hutchings7f967c02012-02-13 23:45:02 +0000466 for (j = 0; j < EFX_TXQ_TYPES; j++) {
467 tx_queue = &channel->tx_queue[j];
468 tx_queue->efx = efx;
469 tx_queue->queue = i * EFX_TXQ_TYPES + j;
470 tx_queue->channel = channel;
Ben Hutchings46426102010-09-10 06:42:33 +0000471 }
472
Ben Hutchings46426102010-09-10 06:42:33 +0000473 rx_queue = &channel->rx_queue;
474 rx_queue->efx = efx;
Kees Cook7aa14022017-10-24 01:45:59 -0700475 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
Ben Hutchings46426102010-09-10 06:42:33 +0000476
477 return channel;
478}
479
Ben Hutchings7f967c02012-02-13 23:45:02 +0000480/* Allocate and initialise a channel structure, copying parameters
481 * (but not resources) from an old channel structure.
482 */
483static struct efx_channel *
484efx_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 Kenward46d054f2016-11-11 15:56:51 +0000498 INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
499 channel->napi_str.napi_id = 0;
500 channel->napi_str.state = 0;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000501 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));
Kees Cook7aa14022017-10-24 01:45:59 -0700514 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000515
516 return channel;
517}
518
Ben Hutchings8ceee662008-04-27 12:55:59 +0100519static int efx_probe_channel(struct efx_channel *channel)
520{
521 struct efx_tx_queue *tx_queue;
522 struct efx_rx_queue *rx_queue;
523 int rc;
524
Ben Hutchings62776d02010-06-23 11:30:07 +0000525 netif_dbg(channel->efx, probe, channel->efx->net_dev,
526 "creating channel %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100527
Ben Hutchings7f967c02012-02-13 23:45:02 +0000528 rc = channel->type->pre_probe(channel);
529 if (rc)
530 goto fail;
531
Ben Hutchings8ceee662008-04-27 12:55:59 +0100532 rc = efx_probe_eventq(channel);
533 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000534 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535
536 efx_for_each_channel_tx_queue(tx_queue, channel) {
537 rc = efx_probe_tx_queue(tx_queue);
538 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000539 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100540 }
541
542 efx_for_each_channel_rx_queue(rx_queue, channel) {
543 rc = efx_probe_rx_queue(rx_queue);
544 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000545 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100546 }
547
Ben Hutchings8ceee662008-04-27 12:55:59 +0100548 return 0;
549
Ben Hutchings7f967c02012-02-13 23:45:02 +0000550fail:
551 efx_remove_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100552 return rc;
553}
554
Ben Hutchings7f967c02012-02-13 23:45:02 +0000555static void
556efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
557{
558 struct efx_nic *efx = channel->efx;
559 const char *type;
560 int number;
561
562 number = channel->channel;
563 if (efx->tx_channel_offset == 0) {
564 type = "";
565 } else if (channel->channel < efx->tx_channel_offset) {
566 type = "-rx";
567 } else {
568 type = "-tx";
569 number -= efx->tx_channel_offset;
570 }
571 snprintf(buf, len, "%s%s-%d", efx->name, type, number);
572}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100573
Ben Hutchings56536e92008-12-12 21:37:02 -0800574static void efx_set_channel_names(struct efx_nic *efx)
575{
576 struct efx_channel *channel;
Ben Hutchings56536e92008-12-12 21:37:02 -0800577
Ben Hutchings7f967c02012-02-13 23:45:02 +0000578 efx_for_each_channel(channel, efx)
579 channel->type->get_name(channel,
Ben Hutchingsd8291182012-10-05 23:35:41 +0100580 efx->msi_context[channel->channel].name,
581 sizeof(efx->msi_context[0].name));
Ben Hutchings56536e92008-12-12 21:37:02 -0800582}
583
Ben Hutchings46426102010-09-10 06:42:33 +0000584static int efx_probe_channels(struct efx_nic *efx)
585{
586 struct efx_channel *channel;
587 int rc;
588
589 /* Restart special buffer allocation */
590 efx->next_buffer_table = 0;
591
Ben Hutchingsc92aaff2012-02-21 23:22:00 +0000592 /* Probe channels in reverse, so that any 'extra' channels
593 * use the start of the buffer table. This allows the traffic
594 * channels to be resized without moving them or wasting the
595 * entries before them.
596 */
597 efx_for_each_channel_rev(channel, efx) {
Ben Hutchings46426102010-09-10 06:42:33 +0000598 rc = efx_probe_channel(channel);
599 if (rc) {
600 netif_err(efx, probe, efx->net_dev,
601 "failed to create channel %d\n",
602 channel->channel);
603 goto fail;
604 }
605 }
606 efx_set_channel_names(efx);
607
608 return 0;
609
610fail:
611 efx_remove_channels(efx);
612 return rc;
613}
614
Ben Hutchings8ceee662008-04-27 12:55:59 +0100615/* Channels are shutdown and reinitialised whilst the NIC is running
616 * to propagate configuration changes (mtu, checksum offload), or
617 * to clear hardware error conditions
618 */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000619static void efx_start_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620{
Andrew Rybchenkoebfcd0f2016-06-15 17:43:20 +0100621 netdev_features_t old_features = efx->net_dev->features;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000622 bool old_rx_scatter = efx->rx_scatter;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100623 struct efx_tx_queue *tx_queue;
624 struct efx_rx_queue *rx_queue;
625 struct efx_channel *channel;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000626 size_t rx_buf_len;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100628 /* Calculate the rx buffer allocation parameters required to
629 * support the current MTU, including padding for header
630 * alignment and overruns.
631 */
Jon Cooper43a37392012-10-18 15:49:54 +0100632 efx->rx_dma_len = (efx->rx_prefix_size +
Ben Hutchings272baee2013-01-29 23:33:14 +0000633 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
634 efx->type->rx_buffer_padding);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000635 rx_buf_len = (sizeof(struct efx_rx_page_state) +
Andrew Rybchenko2ec03012013-11-16 11:02:27 +0400636 efx->rx_ip_align + efx->rx_dma_len);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000637 if (rx_buf_len <= PAGE_SIZE) {
Jon Coopere8c68c02013-03-08 10:18:28 +0000638 efx->rx_scatter = efx->type->always_rx_scatter;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000639 efx->rx_buffer_order = 0;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000640 } else if (efx->type->can_rx_scatter) {
Ben Hutchings950c54d2013-05-13 12:01:22 +0000641 BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000642 BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
Ben Hutchings950c54d2013-05-13 12:01:22 +0000643 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
644 EFX_RX_BUF_ALIGNMENT) >
645 PAGE_SIZE);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000646 efx->rx_scatter = true;
647 efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
648 efx->rx_buffer_order = 0;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000649 } else {
650 efx->rx_scatter = false;
651 efx->rx_buffer_order = get_order(rx_buf_len);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000652 }
653
Daniel Pieczko1648a232013-02-13 10:54:41 +0000654 efx_rx_config_page_split(efx);
655 if (efx->rx_buffer_order)
656 netif_dbg(efx, drv, efx->net_dev,
657 "RX buf len=%u; page order=%u batch=%u\n",
658 efx->rx_dma_len, efx->rx_buffer_order,
659 efx->rx_pages_per_batch);
660 else
661 netif_dbg(efx, drv, efx->net_dev,
662 "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
663 efx->rx_dma_len, efx->rx_page_buf_step,
664 efx->rx_bufs_per_page, efx->rx_pages_per_batch);
Daniel Pieczko27689352013-02-13 10:54:41 +0000665
Andrew Rybchenkoebfcd0f2016-06-15 17:43:20 +0100666 /* Restore previously fixed features in hw_features and remove
667 * features which are fixed now
668 */
669 efx->net_dev->hw_features |= efx->net_dev->features;
670 efx->net_dev->hw_features &= ~efx->fixed_features;
671 efx->net_dev->features |= efx->fixed_features;
672 if (efx->net_dev->features != old_features)
673 netdev_features_change(efx->net_dev);
674
Jon Coopere8c68c02013-03-08 10:18:28 +0000675 /* RX filters may also have scatter-enabled flags */
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000676 if (efx->rx_scatter != old_rx_scatter)
Ben Hutchingsadd72472012-11-08 01:46:53 +0000677 efx->type->filter_update_rx_scatter(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100678
Ben Hutchings14bf7182012-05-22 01:27:58 +0100679 /* We must keep at least one descriptor in a TX ring empty.
680 * We could avoid this when the queue size does not exactly
681 * match the hardware ring size, but it's not that important.
682 * Therefore we stop the queue when one more skb might fill
683 * the ring completely. We wake it when half way back to
684 * empty.
685 */
686 efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
687 efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
688
Ben Hutchings8ceee662008-04-27 12:55:59 +0100689 /* Initialise the channels */
690 efx_for_each_channel(channel, efx) {
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100691 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100692 efx_init_tx_queue(tx_queue);
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100693 atomic_inc(&efx->active_queues);
694 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100695
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000696 efx_for_each_channel_rx_queue(rx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100697 efx_init_rx_queue(rx_queue);
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100698 atomic_inc(&efx->active_queues);
Jon Coopercce28792013-10-02 11:04:14 +0100699 efx_stop_eventq(channel);
700 efx_fast_push_rx_descriptors(rx_queue, false);
701 efx_start_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000702 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100703
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000704 WARN_ON(channel->rx_pkt_n_frags);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100705 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000706
Alexandre Rames2ea4dc22013-11-08 10:20:31 +0000707 efx_ptp_start_datapath(efx);
708
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000709 if (netif_device_present(efx->net_dev))
710 netif_tx_wake_all_queues(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100711}
712
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000713static void efx_stop_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100714{
715 struct efx_channel *channel;
716 struct efx_tx_queue *tx_queue;
717 struct efx_rx_queue *rx_queue;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100718 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100719
720 EFX_ASSERT_RESET_SERIALISED(efx);
721 BUG_ON(efx->port_enabled);
722
Alexandre Rames2ea4dc22013-11-08 10:20:31 +0000723 efx_ptp_stop_datapath(efx);
724
Ben Hutchingsd8aec742013-05-27 16:52:54 +0100725 /* Stop RX refill */
726 efx_for_each_channel(channel, efx) {
727 efx_for_each_channel_rx_queue(rx_queue, channel)
728 rx_queue->refill_enabled = false;
729 }
730
Ben Hutchings8ceee662008-04-27 12:55:59 +0100731 efx_for_each_channel(channel, efx) {
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000732 /* RX packet processing is pipelined, so wait for the
733 * NAPI handler to complete. At least event queue 0
734 * might be kept active by non-data events, so don't
735 * use napi_synchronize() but actually disable NAPI
736 * temporarily.
737 */
738 if (efx_channel_has_rx_queue(channel)) {
739 efx_stop_eventq(channel);
740 efx_start_eventq(channel);
741 }
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100742 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100743
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100744 rc = efx->type->fini_dmaq(efx);
Edward Cree5a6681e2016-11-28 18:55:34 +0000745 if (rc) {
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100746 netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
747 } else {
748 netif_dbg(efx, drv, efx->net_dev,
749 "successfully flushed all queues\n");
750 }
751
752 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100753 efx_for_each_channel_rx_queue(rx_queue, channel)
754 efx_fini_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000755 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100756 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100757 }
758}
759
760static void efx_remove_channel(struct efx_channel *channel)
761{
762 struct efx_tx_queue *tx_queue;
763 struct efx_rx_queue *rx_queue;
764
Ben Hutchings62776d02010-06-23 11:30:07 +0000765 netif_dbg(channel->efx, drv, channel->efx->net_dev,
766 "destroy chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100767
768 efx_for_each_channel_rx_queue(rx_queue, channel)
769 efx_remove_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000770 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100771 efx_remove_tx_queue(tx_queue);
772 efx_remove_eventq(channel);
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100773 channel->type->post_remove(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100774}
775
Ben Hutchings46426102010-09-10 06:42:33 +0000776static void efx_remove_channels(struct efx_nic *efx)
777{
778 struct efx_channel *channel;
779
780 efx_for_each_channel(channel, efx)
781 efx_remove_channel(channel);
782}
783
784int
785efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
786{
787 struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
788 u32 old_rxq_entries, old_txq_entries;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000789 unsigned i, next_buffer_table = 0;
Jon Cooper261e4d92013-04-15 18:51:54 +0100790 int rc, rc2;
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100791
792 rc = efx_check_disabled(efx);
793 if (rc)
794 return rc;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000795
796 /* Not all channels should be reallocated. We must avoid
797 * reallocating their buffer table entries.
798 */
799 efx_for_each_channel(channel, efx) {
800 struct efx_rx_queue *rx_queue;
801 struct efx_tx_queue *tx_queue;
802
803 if (channel->type->copy)
804 continue;
805 next_buffer_table = max(next_buffer_table,
806 channel->eventq.index +
807 channel->eventq.entries);
808 efx_for_each_channel_rx_queue(rx_queue, channel)
809 next_buffer_table = max(next_buffer_table,
810 rx_queue->rxd.index +
811 rx_queue->rxd.entries);
812 efx_for_each_channel_tx_queue(tx_queue, channel)
813 next_buffer_table = max(next_buffer_table,
814 tx_queue->txd.index +
815 tx_queue->txd.entries);
816 }
Ben Hutchings46426102010-09-10 06:42:33 +0000817
Ben Hutchings29c69a42013-01-28 19:01:06 +0000818 efx_device_detach_sync(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000819 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +0100820 efx_soft_disable_interrupts(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000821
Ben Hutchings7f967c02012-02-13 23:45:02 +0000822 /* Clone channels (where possible) */
Ben Hutchings46426102010-09-10 06:42:33 +0000823 memset(other_channel, 0, sizeof(other_channel));
824 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000825 channel = efx->channel[i];
826 if (channel->type->copy)
827 channel = channel->type->copy(channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000828 if (!channel) {
829 rc = -ENOMEM;
830 goto out;
831 }
832 other_channel[i] = channel;
833 }
834
835 /* Swap entry counts and channel pointers */
836 old_rxq_entries = efx->rxq_entries;
837 old_txq_entries = efx->txq_entries;
838 efx->rxq_entries = rxq_entries;
839 efx->txq_entries = txq_entries;
840 for (i = 0; i < efx->n_channels; i++) {
841 channel = efx->channel[i];
842 efx->channel[i] = other_channel[i];
843 other_channel[i] = channel;
844 }
845
Ben Hutchings7f967c02012-02-13 23:45:02 +0000846 /* Restart buffer table allocation */
847 efx->next_buffer_table = next_buffer_table;
Ben Hutchings46426102010-09-10 06:42:33 +0000848
Ben Hutchingse8f14992010-12-07 19:47:34 +0000849 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000850 channel = efx->channel[i];
851 if (!channel->type->copy)
852 continue;
853 rc = efx_probe_channel(channel);
854 if (rc)
855 goto rollback;
856 efx_init_napi_channel(efx->channel[i]);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000857 }
Ben Hutchings46426102010-09-10 06:42:33 +0000858
Ben Hutchings7f967c02012-02-13 23:45:02 +0000859out:
860 /* Destroy unused channel structures */
861 for (i = 0; i < efx->n_channels; i++) {
862 channel = other_channel[i];
863 if (channel && channel->type->copy) {
864 efx_fini_napi_channel(channel);
865 efx_remove_channel(channel);
866 kfree(channel);
867 }
868 }
869
Jon Cooper261e4d92013-04-15 18:51:54 +0100870 rc2 = efx_soft_enable_interrupts(efx);
871 if (rc2) {
872 rc = rc ? rc : rc2;
873 netif_err(efx, drv, efx->net_dev,
874 "unable to restart interrupts on channel reallocation\n");
875 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
876 } else {
877 efx_start_all(efx);
Peter Dunning9c568fd2017-02-17 15:50:43 +0000878 efx_device_attach_if_not_resetting(efx);
Jon Cooper261e4d92013-04-15 18:51:54 +0100879 }
Ben Hutchings46426102010-09-10 06:42:33 +0000880 return rc;
881
882rollback:
883 /* Swap back */
884 efx->rxq_entries = old_rxq_entries;
885 efx->txq_entries = old_txq_entries;
886 for (i = 0; i < efx->n_channels; i++) {
887 channel = efx->channel[i];
888 efx->channel[i] = other_channel[i];
889 other_channel[i] = channel;
890 }
891 goto out;
892}
893
Steve Hodgson90d683a2010-06-01 11:19:39 +0000894void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100895{
Steve Hodgson90d683a2010-06-01 11:19:39 +0000896 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100897}
898
Ben Hutchings7f967c02012-02-13 23:45:02 +0000899static const struct efx_channel_type efx_default_channel_type = {
900 .pre_probe = efx_channel_dummy_op_int,
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100901 .post_remove = efx_channel_dummy_op_void,
Ben Hutchings7f967c02012-02-13 23:45:02 +0000902 .get_name = efx_get_channel_name,
903 .copy = efx_copy_channel,
904 .keep_eventq = false,
905};
906
907int efx_channel_dummy_op_int(struct efx_channel *channel)
908{
909 return 0;
910}
911
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100912void efx_channel_dummy_op_void(struct efx_channel *channel)
913{
914}
915
Ben Hutchings8ceee662008-04-27 12:55:59 +0100916/**************************************************************************
917 *
918 * Port handling
919 *
920 **************************************************************************/
921
922/* This ensures that the kernel is kept informed (via
923 * netif_carrier_on/off) of the link status, and also maintains the
924 * link status's stop on the port's TX queue.
925 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000926void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100927{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000928 struct efx_link_state *link_state = &efx->link_state;
929
Ben Hutchings8ceee662008-04-27 12:55:59 +0100930 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
931 * that no events are triggered between unregister_netdev() and the
932 * driver unloading. A more general condition is that NETDEV_CHANGE
933 * can only be generated between NETDEV_UP and NETDEV_DOWN */
934 if (!netif_running(efx->net_dev))
935 return;
936
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000937 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100938 efx->n_link_state_changes++;
939
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000940 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100941 netif_carrier_on(efx->net_dev);
942 else
943 netif_carrier_off(efx->net_dev);
944 }
945
946 /* Status message for kernel log */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000947 if (link_state->up)
Ben Hutchings62776d02010-06-23 11:30:07 +0000948 netif_info(efx, link, efx->net_dev,
Ben Hutchings964e6132012-11-19 23:08:22 +0000949 "link up at %uMbps %s-duplex (MTU %d)\n",
Ben Hutchings62776d02010-06-23 11:30:07 +0000950 link_state->speed, link_state->fd ? "full" : "half",
Ben Hutchings964e6132012-11-19 23:08:22 +0000951 efx->net_dev->mtu);
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000952 else
Ben Hutchings62776d02010-06-23 11:30:07 +0000953 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100954}
955
Edward Creec2ab85d2018-01-10 18:00:14 +0000956void efx_link_set_advertising(struct efx_nic *efx,
957 const unsigned long *advertising)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000958{
Edward Creec2ab85d2018-01-10 18:00:14 +0000959 memcpy(efx->link_advertising, advertising,
960 sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
961
962 efx->link_advertising[0] |= ADVERTISED_Autoneg;
963 if (advertising[0] & ADVERTISED_Pause)
964 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
965 else
966 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
967 if (advertising[0] & ADVERTISED_Asym_Pause)
968 efx->wanted_fc ^= EFX_FC_TX;
969}
970
971/* Equivalent to efx_link_set_advertising with all-zeroes, except does not
972 * force the Autoneg bit on.
973 */
974void efx_link_clear_advertising(struct efx_nic *efx)
975{
976 bitmap_zero(efx->link_advertising, __ETHTOOL_LINK_MODE_MASK_NBITS);
977 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000978}
979
David S. Millerb56269462011-05-17 17:53:22 -0400980void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000981{
982 efx->wanted_fc = wanted_fc;
Edward Creec2ab85d2018-01-10 18:00:14 +0000983 if (efx->link_advertising[0]) {
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000984 if (wanted_fc & EFX_FC_RX)
Edward Creec2ab85d2018-01-10 18:00:14 +0000985 efx->link_advertising[0] |= (ADVERTISED_Pause |
986 ADVERTISED_Asym_Pause);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000987 else
Edward Creec2ab85d2018-01-10 18:00:14 +0000988 efx->link_advertising[0] &= ~(ADVERTISED_Pause |
989 ADVERTISED_Asym_Pause);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000990 if (wanted_fc & EFX_FC_TX)
Edward Creec2ab85d2018-01-10 18:00:14 +0000991 efx->link_advertising[0] ^= ADVERTISED_Asym_Pause;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000992 }
993}
994
Ben Hutchings115122a2009-03-04 09:52:52 +0000995static void efx_fini_port(struct efx_nic *efx);
996
Edward Cree0d322412015-05-20 11:10:03 +0100997/* We assume that efx->type->reconfigure_mac will always try to sync RX
998 * filters and therefore needs to read-lock the filter table against freeing
999 */
1000void efx_mac_reconfigure(struct efx_nic *efx)
1001{
1002 down_read(&efx->filter_sem);
1003 efx->type->reconfigure_mac(efx);
1004 up_read(&efx->filter_sem);
1005}
1006
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001007/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
1008 * the MAC appropriately. All other PHY configuration changes are pushed
1009 * through phy_op->set_settings(), and pushed asynchronously to the MAC
1010 * through efx_monitor().
1011 *
1012 * Callers must hold the mac_lock
1013 */
1014int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001015{
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001016 enum efx_phy_mode phy_mode;
1017 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001018
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001019 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +01001020
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001021 /* Disable PHY transmit in mac level loopbacks */
1022 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001023 if (LOOPBACK_INTERNAL(efx))
1024 efx->phy_mode |= PHY_MODE_TX_DISABLED;
1025 else
1026 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001027
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001028 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001029
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001030 if (rc)
1031 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001032
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001033 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001034}
1035
1036/* Reinitialise the MAC to pick up new PHY settings, even if the port is
1037 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001038int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001039{
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001040 int rc;
1041
Ben Hutchings8ceee662008-04-27 12:55:59 +01001042 EFX_ASSERT_RESET_SERIALISED(efx);
1043
1044 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001045 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001046 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001047
1048 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001049}
1050
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001051/* Asynchronous work item for changing MAC promiscuity and multicast
1052 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
1053 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001054static void efx_mac_work(struct work_struct *data)
1055{
1056 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
1057
1058 mutex_lock(&efx->mac_lock);
Ben Hutchings30b81cd2011-09-13 19:47:48 +01001059 if (efx->port_enabled)
Edward Cree0d322412015-05-20 11:10:03 +01001060 efx_mac_reconfigure(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001061 mutex_unlock(&efx->mac_lock);
1062}
1063
Ben Hutchings8ceee662008-04-27 12:55:59 +01001064static int efx_probe_port(struct efx_nic *efx)
1065{
1066 int rc;
1067
Ben Hutchings62776d02010-06-23 11:30:07 +00001068 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001069
Steve Hodgsonff3b00a2009-12-23 13:46:36 +00001070 if (phy_flash_cfg)
1071 efx->phy_mode = PHY_MODE_SPECIAL;
1072
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001073 /* Connect up MAC/PHY operations table */
1074 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001075 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +00001076 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001077
Ben Hutchingse332bcb2011-12-20 01:22:51 +00001078 /* Initialise MAC address to permanent address */
Edward Creecd84ff42014-03-07 18:27:41 +00001079 ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001080
1081 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001082}
1083
1084static int efx_init_port(struct efx_nic *efx)
1085{
1086 int rc;
1087
Ben Hutchings62776d02010-06-23 11:30:07 +00001088 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001089
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001090 mutex_lock(&efx->mac_lock);
1091
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001092 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001093 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001094 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001095
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001096 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001097
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001098 /* Reconfigure the MAC before creating dma queues (required for
1099 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
Edward Cree0d322412015-05-20 11:10:03 +01001100 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001101
1102 /* Ensure the PHY advertises the correct flow control settings */
1103 rc = efx->phy_op->reconfigure(efx);
Edward Cree267d9d72015-05-06 00:59:18 +01001104 if (rc && rc != -EPERM)
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001105 goto fail2;
1106
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001107 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001108 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001109
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001110fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001111 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001112fail1:
1113 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001114 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001115}
1116
Ben Hutchings8ceee662008-04-27 12:55:59 +01001117static void efx_start_port(struct efx_nic *efx)
1118{
Ben Hutchings62776d02010-06-23 11:30:07 +00001119 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001120 BUG_ON(efx->port_enabled);
1121
1122 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001123 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001124
Ben Hutchingsd615c032013-10-08 17:33:20 +01001125 /* Ensure MAC ingress/egress is enabled */
Edward Cree0d322412015-05-20 11:10:03 +01001126 efx_mac_reconfigure(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001127
Ben Hutchings8ceee662008-04-27 12:55:59 +01001128 mutex_unlock(&efx->mac_lock);
1129}
1130
Ben Hutchingsd615c032013-10-08 17:33:20 +01001131/* Cancel work for MAC reconfiguration, periodic hardware monitoring
1132 * and the async self-test, wait for them to finish and prevent them
1133 * being scheduled again. This doesn't cover online resets, which
1134 * should only be cancelled when removing the device.
1135 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001136static void efx_stop_port(struct efx_nic *efx)
1137{
Ben Hutchings62776d02010-06-23 11:30:07 +00001138 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001139
Ben Hutchingsd615c032013-10-08 17:33:20 +01001140 EFX_ASSERT_RESET_SERIALISED(efx);
1141
Ben Hutchings8ceee662008-04-27 12:55:59 +01001142 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001143 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001144 mutex_unlock(&efx->mac_lock);
1145
1146 /* Serialise against efx_set_multicast_list() */
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001147 netif_addr_lock_bh(efx->net_dev);
1148 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchingsd615c032013-10-08 17:33:20 +01001149
1150 cancel_delayed_work_sync(&efx->monitor_work);
1151 efx_selftest_async_cancel(efx);
1152 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001153}
1154
1155static void efx_fini_port(struct efx_nic *efx)
1156{
Ben Hutchings62776d02010-06-23 11:30:07 +00001157 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001158
1159 if (!efx->port_initialized)
1160 return;
1161
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001162 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001163 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001164
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001165 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001166 efx_link_status_changed(efx);
1167}
1168
1169static void efx_remove_port(struct efx_nic *efx)
1170{
Ben Hutchings62776d02010-06-23 11:30:07 +00001171 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001172
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001173 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001174}
1175
1176/**************************************************************************
1177 *
1178 * NIC handling
1179 *
1180 **************************************************************************/
1181
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01001182static LIST_HEAD(efx_primary_list);
1183static LIST_HEAD(efx_unassociated_list);
1184
1185static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
1186{
1187 return left->type == right->type &&
1188 left->vpd_sn && right->vpd_sn &&
1189 !strcmp(left->vpd_sn, right->vpd_sn);
1190}
1191
1192static void efx_associate(struct efx_nic *efx)
1193{
1194 struct efx_nic *other, *next;
1195
1196 if (efx->primary == efx) {
1197 /* Adding primary function; look for secondaries */
1198
1199 netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
1200 list_add_tail(&efx->node, &efx_primary_list);
1201
1202 list_for_each_entry_safe(other, next, &efx_unassociated_list,
1203 node) {
1204 if (efx_same_controller(efx, other)) {
1205 list_del(&other->node);
1206 netif_dbg(other, probe, other->net_dev,
1207 "moving to secondary list of %s %s\n",
1208 pci_name(efx->pci_dev),
1209 efx->net_dev->name);
1210 list_add_tail(&other->node,
1211 &efx->secondary_list);
1212 other->primary = efx;
1213 }
1214 }
1215 } else {
1216 /* Adding secondary function; look for primary */
1217
1218 list_for_each_entry(other, &efx_primary_list, node) {
1219 if (efx_same_controller(efx, other)) {
1220 netif_dbg(efx, probe, efx->net_dev,
1221 "adding to secondary list of %s %s\n",
1222 pci_name(other->pci_dev),
1223 other->net_dev->name);
1224 list_add_tail(&efx->node,
1225 &other->secondary_list);
1226 efx->primary = other;
1227 return;
1228 }
1229 }
1230
1231 netif_dbg(efx, probe, efx->net_dev,
1232 "adding to unassociated list\n");
1233 list_add_tail(&efx->node, &efx_unassociated_list);
1234 }
1235}
1236
1237static void efx_dissociate(struct efx_nic *efx)
1238{
1239 struct efx_nic *other, *next;
1240
1241 list_del(&efx->node);
1242 efx->primary = NULL;
1243
1244 list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
1245 list_del(&other->node);
1246 netif_dbg(other, probe, other->net_dev,
1247 "moving to unassociated list\n");
1248 list_add_tail(&other->node, &efx_unassociated_list);
1249 other->primary = NULL;
1250 }
1251}
1252
Ben Hutchings8ceee662008-04-27 12:55:59 +01001253/* This configures the PCI device to enable I/O and DMA. */
1254static int efx_init_io(struct efx_nic *efx)
1255{
1256 struct pci_dev *pci_dev = efx->pci_dev;
1257 dma_addr_t dma_mask = efx->type->max_dma_mask;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001258 unsigned int mem_map_size = efx->type->mem_map_size(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001259 int rc, bar;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001260
Ben Hutchings62776d02010-06-23 11:30:07 +00001261 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001262
Edward Cree03714bb2017-12-18 16:55:50 +00001263 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001264
Ben Hutchings8ceee662008-04-27 12:55:59 +01001265 rc = pci_enable_device(pci_dev);
1266 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001267 netif_err(efx, probe, efx->net_dev,
1268 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001269 goto fail1;
1270 }
1271
1272 pci_set_master(pci_dev);
1273
1274 /* Set the PCI DMA mask. Try all possibilities from our
1275 * genuine mask down to 32 bits, because some architectures
1276 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1277 * masks event though they reject 46 bit masks.
1278 */
1279 while (dma_mask > 0x7fffffffUL) {
Christoph Hellwig8722b8f2015-11-10 14:45:42 -08001280 rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
1281 if (rc == 0)
1282 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001283 dma_mask >>= 1;
1284 }
1285 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001286 netif_err(efx, probe, efx->net_dev,
1287 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001288 goto fail2;
1289 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001290 netif_dbg(efx, probe, efx->net_dev,
1291 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001292
Shradha Shah02246a72015-05-06 00:58:14 +01001293 efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
1294 rc = pci_request_region(pci_dev, bar, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001295 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001296 netif_err(efx, probe, efx->net_dev,
1297 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001298 rc = -EIO;
1299 goto fail3;
1300 }
Ben Hutchingsb1057982012-09-19 00:56:47 +01001301 efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001302 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001303 netif_err(efx, probe, efx->net_dev,
1304 "could not map memory BAR at %llx+%x\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001305 (unsigned long long)efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001306 rc = -ENOMEM;
1307 goto fail4;
1308 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001309 netif_dbg(efx, probe, efx->net_dev,
1310 "memory BAR at %llx+%x (virtual %p)\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001311 (unsigned long long)efx->membase_phys, mem_map_size,
1312 efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001313
1314 return 0;
1315
1316 fail4:
Shradha Shah02246a72015-05-06 00:58:14 +01001317 pci_release_region(efx->pci_dev, bar);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001318 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001319 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001320 fail2:
1321 pci_disable_device(efx->pci_dev);
1322 fail1:
1323 return rc;
1324}
1325
1326static void efx_fini_io(struct efx_nic *efx)
1327{
Shradha Shah02246a72015-05-06 00:58:14 +01001328 int bar;
1329
Ben Hutchings62776d02010-06-23 11:30:07 +00001330 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001331
1332 if (efx->membase) {
1333 iounmap(efx->membase);
1334 efx->membase = NULL;
1335 }
1336
1337 if (efx->membase_phys) {
Edward Cree03714bb2017-12-18 16:55:50 +00001338 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001339 pci_release_region(efx->pci_dev, bar);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001340 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001341 }
1342
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001343 /* Don't disable bus-mastering if VFs are assigned */
1344 if (!pci_vfs_assigned(efx->pci_dev))
1345 pci_disable_device(efx->pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001346}
1347
Jon Cooper267c0152015-05-06 00:59:38 +01001348void efx_set_default_rx_indir_table(struct efx_nic *efx)
1349{
1350 size_t i;
1351
1352 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
1353 efx->rx_indir_table[i] =
1354 ethtool_rxfh_indir_default(i, efx->rss_spread);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001355}
1356
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001357static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
Ben Hutchings46123d02008-09-01 12:47:33 +01001358{
Ben Hutchingscdb08f82011-12-20 01:08:05 +00001359 cpumask_var_t thread_mask;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001360 unsigned int count;
Ben Hutchings46123d02008-09-01 12:47:33 +01001361 int cpu;
1362
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001363 if (rss_cpus) {
1364 count = rss_cpus;
1365 } else {
1366 if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1367 netif_warn(efx, probe, efx->net_dev,
1368 "RSS disabled due to allocation failure\n");
1369 return 1;
Ben Hutchings46123d02008-09-01 12:47:33 +01001370 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001371
1372 count = 0;
1373 for_each_online_cpu(cpu) {
1374 if (!cpumask_test_cpu(cpu, thread_mask)) {
1375 ++count;
1376 cpumask_or(thread_mask, thread_mask,
Bartosz Golaszewski06931e62015-05-26 15:11:28 +02001377 topology_sibling_cpumask(cpu));
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001378 }
1379 }
1380
1381 free_cpumask_var(thread_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001382 }
1383
Bert Kenward271a8b42017-04-12 17:06:52 +01001384 if (count > EFX_MAX_RX_QUEUES) {
1385 netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1386 "Reducing number of rx queues from %u to %u.\n",
1387 count, EFX_MAX_RX_QUEUES);
1388 count = EFX_MAX_RX_QUEUES;
1389 }
1390
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001391 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1392 * table entries that are inaccessible to VFs
1393 */
Shradha Shah7fa8d542015-05-06 00:55:13 +01001394#ifdef CONFIG_SFC_SRIOV
1395 if (efx->type->sriov_wanted) {
1396 if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
1397 count > efx_vf_size(efx)) {
1398 netif_warn(efx, probe, efx->net_dev,
1399 "Reducing number of RSS channels from %u to %u for "
1400 "VF support. Increase vf-msix-limit to use more "
1401 "channels on the PF.\n",
1402 count, efx_vf_size(efx));
1403 count = efx_vf_size(efx);
1404 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001405 }
Shradha Shah7fa8d542015-05-06 00:55:13 +01001406#endif
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001407
Ben Hutchings46123d02008-09-01 12:47:33 +01001408 return count;
1409}
1410
1411/* Probe the number and type of interrupts we are able to obtain, and
1412 * the resulting numbers of channels and RX queues.
1413 */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001414static int efx_probe_interrupts(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001415{
Ben Hutchings7f967c02012-02-13 23:45:02 +00001416 unsigned int extra_channels = 0;
1417 unsigned int i, j;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001418 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001419
Ben Hutchings7f967c02012-02-13 23:45:02 +00001420 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
1421 if (efx->extra_channel_type[i])
1422 ++extra_channels;
1423
Ben Hutchings8ceee662008-04-27 12:55:59 +01001424 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001425 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001426 unsigned int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001427
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001428 n_channels = efx_wanted_parallelism(efx);
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001429 if (efx_separate_tx_channels)
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001430 n_channels *= 2;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001431 n_channels += extra_channels;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001432 n_channels = min(n_channels, efx->max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001433
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001434 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001435 xentries[i].entry = i;
Alexander Gordeev184603d2014-02-18 11:12:00 +01001436 rc = pci_enable_msix_range(efx->pci_dev,
1437 xentries, 1, n_channels);
1438 if (rc < 0) {
1439 /* Fall back to single channel MSI */
Alexander Gordeev184603d2014-02-18 11:12:00 +01001440 netif_err(efx, drv, efx->net_dev,
1441 "could not enable MSI-X\n");
Andrew Rybchenko62980cb2017-02-13 14:59:04 +00001442 if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
1443 efx->interrupt_mode = EFX_INT_MODE_MSI;
1444 else
1445 return rc;
Alexander Gordeev184603d2014-02-18 11:12:00 +01001446 } else if (rc < n_channels) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001447 netif_err(efx, drv, efx->net_dev,
1448 "WARNING: Insufficient MSI-X vectors"
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001449 " available (%d < %u).\n", rc, n_channels);
Ben Hutchings62776d02010-06-23 11:30:07 +00001450 netif_err(efx, drv, efx->net_dev,
1451 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001452 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001453 }
1454
Alexander Gordeev184603d2014-02-18 11:12:00 +01001455 if (rc > 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001456 efx->n_channels = n_channels;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001457 if (n_channels > extra_channels)
1458 n_channels -= extra_channels;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001459 if (efx_separate_tx_channels) {
1460 efx->n_tx_channels = min(max(n_channels / 2,
1461 1U),
1462 efx->max_tx_channels);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001463 efx->n_rx_channels = max(n_channels -
1464 efx->n_tx_channels,
1465 1U);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001466 } else {
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001467 efx->n_tx_channels = min(n_channels,
1468 efx->max_tx_channels);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001469 efx->n_rx_channels = n_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001470 }
Ben Hutchings7f967c02012-02-13 23:45:02 +00001471 for (i = 0; i < efx->n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001472 efx_get_channel(efx, i)->irq =
1473 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001474 }
1475 }
1476
1477 /* Try single interrupt MSI */
1478 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001479 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001480 efx->n_rx_channels = 1;
1481 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001482 rc = pci_enable_msi(efx->pci_dev);
1483 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001484 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001485 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001486 netif_err(efx, drv, efx->net_dev,
1487 "could not enable MSI\n");
Andrew Rybchenko62980cb2017-02-13 14:59:04 +00001488 if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
1489 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1490 else
1491 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001492 }
1493 }
1494
1495 /* Assume legacy interrupts */
1496 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001497 efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001498 efx->n_rx_channels = 1;
1499 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001500 efx->legacy_irq = efx->pci_dev->irq;
1501 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001502
Ben Hutchings7f967c02012-02-13 23:45:02 +00001503 /* Assign extra channels if possible */
1504 j = efx->n_channels;
1505 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
1506 if (!efx->extra_channel_type[i])
1507 continue;
1508 if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
1509 efx->n_channels <= extra_channels) {
1510 efx->extra_channel_type[i]->handle_no_channel(efx);
1511 } else {
1512 --j;
1513 efx_get_channel(efx, j)->type =
1514 efx->extra_channel_type[i];
1515 }
1516 }
1517
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001518 /* RSS might be usable on VFs even if it is disabled on the PF */
Shradha Shah7fa8d542015-05-06 00:55:13 +01001519#ifdef CONFIG_SFC_SRIOV
1520 if (efx->type->sriov_wanted) {
1521 efx->rss_spread = ((efx->n_rx_channels > 1 ||
1522 !efx->type->sriov_wanted(efx)) ?
1523 efx->n_rx_channels : efx_vf_size(efx));
1524 return 0;
1525 }
1526#endif
1527 efx->rss_spread = efx->n_rx_channels;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001528
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001529 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001530}
1531
Jon Cooper261e4d92013-04-15 18:51:54 +01001532static int efx_soft_enable_interrupts(struct efx_nic *efx)
Ben Hutchingsd8291182012-10-05 23:35:41 +01001533{
Jon Cooper261e4d92013-04-15 18:51:54 +01001534 struct efx_channel *channel, *end_channel;
1535 int rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001536
1537 BUG_ON(efx->state == STATE_DISABLED);
1538
1539 efx->irq_soft_enabled = true;
1540 smp_wmb();
1541
1542 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001543 if (!channel->type->keep_eventq) {
1544 rc = efx_init_eventq(channel);
1545 if (rc)
1546 goto fail;
1547 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001548 efx_start_eventq(channel);
1549 }
1550
1551 efx_mcdi_mode_event(efx);
Jon Cooper261e4d92013-04-15 18:51:54 +01001552
1553 return 0;
1554fail:
1555 end_channel = channel;
1556 efx_for_each_channel(channel, efx) {
1557 if (channel == end_channel)
1558 break;
1559 efx_stop_eventq(channel);
1560 if (!channel->type->keep_eventq)
1561 efx_fini_eventq(channel);
1562 }
1563
1564 return rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001565}
1566
1567static void efx_soft_disable_interrupts(struct efx_nic *efx)
1568{
1569 struct efx_channel *channel;
1570
1571 if (efx->state == STATE_DISABLED)
1572 return;
1573
1574 efx_mcdi_mode_poll(efx);
1575
1576 efx->irq_soft_enabled = false;
1577 smp_wmb();
1578
1579 if (efx->legacy_irq)
1580 synchronize_irq(efx->legacy_irq);
1581
1582 efx_for_each_channel(channel, efx) {
1583 if (channel->irq)
1584 synchronize_irq(channel->irq);
1585
1586 efx_stop_eventq(channel);
1587 if (!channel->type->keep_eventq)
1588 efx_fini_eventq(channel);
1589 }
Ben Hutchingscade7152013-08-27 23:12:31 +01001590
1591 /* Flush the asynchronous MCDI request queue */
1592 efx_mcdi_flush_async(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01001593}
1594
Jon Cooper261e4d92013-04-15 18:51:54 +01001595static int efx_enable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001596{
Jon Cooper261e4d92013-04-15 18:51:54 +01001597 struct efx_channel *channel, *end_channel;
1598 int rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001599
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001600 BUG_ON(efx->state == STATE_DISABLED);
1601
Alexandre Ramesb28405b2013-03-21 16:41:43 +00001602 if (efx->eeh_disabled_legacy_irq) {
1603 enable_irq(efx->legacy_irq);
1604 efx->eeh_disabled_legacy_irq = false;
1605 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001606
Ben Hutchings86094f72013-08-21 19:51:04 +01001607 efx->type->irq_enable_master(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001608
1609 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001610 if (channel->type->keep_eventq) {
1611 rc = efx_init_eventq(channel);
1612 if (rc)
1613 goto fail;
1614 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001615 }
1616
Jon Cooper261e4d92013-04-15 18:51:54 +01001617 rc = efx_soft_enable_interrupts(efx);
1618 if (rc)
1619 goto fail;
1620
1621 return 0;
1622
1623fail:
1624 end_channel = channel;
1625 efx_for_each_channel(channel, efx) {
1626 if (channel == end_channel)
1627 break;
1628 if (channel->type->keep_eventq)
1629 efx_fini_eventq(channel);
1630 }
1631
1632 efx->type->irq_disable_non_ev(efx);
1633
1634 return rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001635}
1636
Ben Hutchingsd8291182012-10-05 23:35:41 +01001637static void efx_disable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001638{
1639 struct efx_channel *channel;
1640
Ben Hutchingsd8291182012-10-05 23:35:41 +01001641 efx_soft_disable_interrupts(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001642
1643 efx_for_each_channel(channel, efx) {
Ben Hutchingsd8291182012-10-05 23:35:41 +01001644 if (channel->type->keep_eventq)
Ben Hutchings7f967c02012-02-13 23:45:02 +00001645 efx_fini_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001646 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001647
Ben Hutchings86094f72013-08-21 19:51:04 +01001648 efx->type->irq_disable_non_ev(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001649}
1650
Ben Hutchings8ceee662008-04-27 12:55:59 +01001651static void efx_remove_interrupts(struct efx_nic *efx)
1652{
1653 struct efx_channel *channel;
1654
1655 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001656 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001657 channel->irq = 0;
1658 pci_disable_msi(efx->pci_dev);
1659 pci_disable_msix(efx->pci_dev);
1660
1661 /* Remove legacy interrupt */
1662 efx->legacy_irq = 0;
1663}
1664
Ben Hutchings8831da72008-09-01 12:47:48 +01001665static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001666{
Ben Hutchings602a5322011-05-16 17:32:39 +01001667 struct efx_channel *channel;
1668 struct efx_tx_queue *tx_queue;
1669
Ben Hutchings97653432011-01-12 18:26:56 +00001670 efx->tx_channel_offset =
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001671 efx_separate_tx_channels ?
1672 efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings602a5322011-05-16 17:32:39 +01001673
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001674 /* We need to mark which channels really have RX and TX
1675 * queues, and adjust the TX queue numbers if we have separate
Ben Hutchings602a5322011-05-16 17:32:39 +01001676 * RX-only and TX-only channels.
1677 */
1678 efx_for_each_channel(channel, efx) {
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001679 if (channel->channel < efx->n_rx_channels)
1680 channel->rx_queue.core_index = channel->channel;
1681 else
1682 channel->rx_queue.core_index = -1;
1683
Ben Hutchings602a5322011-05-16 17:32:39 +01001684 efx_for_each_channel_tx_queue(tx_queue, channel)
1685 tx_queue->queue -= (efx->tx_channel_offset *
1686 EFX_TXQ_TYPES);
1687 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001688}
1689
1690static int efx_probe_nic(struct efx_nic *efx)
1691{
1692 int rc;
1693
Ben Hutchings62776d02010-06-23 11:30:07 +00001694 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001695
1696 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001697 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001698 if (rc)
1699 return rc;
1700
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001701 do {
1702 if (!efx->max_channels || !efx->max_tx_channels) {
1703 netif_err(efx, drv, efx->net_dev,
1704 "Insufficient resources to allocate"
1705 " any channels\n");
1706 rc = -ENOSPC;
1707 goto fail1;
1708 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001709
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001710 /* Determine the number of channels and queues by trying
1711 * to hook in MSI-X interrupts.
1712 */
1713 rc = efx_probe_interrupts(efx);
1714 if (rc)
1715 goto fail1;
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001716
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001717 efx_set_channels(efx);
1718
1719 /* dimension_resources can fail with EAGAIN */
1720 rc = efx->type->dimension_resources(efx);
1721 if (rc != 0 && rc != -EAGAIN)
1722 goto fail2;
1723
1724 if (rc == -EAGAIN)
1725 /* try again with new max_channels */
1726 efx_remove_interrupts(efx);
1727
1728 } while (rc == -EAGAIN);
Ben Hutchings28e47c42012-02-15 01:58:49 +00001729
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001730 if (efx->n_channels > 1)
Jon Cooper267c0152015-05-06 00:59:38 +01001731 netdev_rss_key_fill(&efx->rx_hash_key,
1732 sizeof(efx->rx_hash_key));
1733 efx_set_default_rx_indir_table(efx);
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001734
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001735 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1736 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001737
1738 /* Initialise the interrupt moderation settings */
Bert Kenward539de7c2016-08-11 13:02:09 +01001739 efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
Ben Hutchings9e393b32011-09-05 07:43:04 +00001740 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1741 true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001742
1743 return 0;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001744
Ben Hutchingsc15eed22013-08-29 00:45:48 +01001745fail2:
1746 efx_remove_interrupts(efx);
1747fail1:
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001748 efx->type->remove(efx);
1749 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001750}
1751
1752static void efx_remove_nic(struct efx_nic *efx)
1753{
Ben Hutchings62776d02010-06-23 11:30:07 +00001754 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001755
1756 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001757 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001758}
1759
Ben Hutchingsadd72472012-11-08 01:46:53 +00001760static int efx_probe_filters(struct efx_nic *efx)
1761{
1762 int rc;
1763
1764 spin_lock_init(&efx->filter_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001765 init_rwsem(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01001766 mutex_lock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001767 down_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001768 rc = efx->type->filter_table_probe(efx);
1769 if (rc)
Edward Cree0d322412015-05-20 11:10:03 +01001770 goto out_unlock;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001771
1772#ifdef CONFIG_RFS_ACCEL
1773 if (efx->type->offload_features & NETIF_F_NTUPLE) {
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001774 struct efx_channel *channel;
1775 int i, success = 1;
1776
1777 efx_for_each_channel(channel, efx) {
1778 channel->rps_flow_id =
1779 kcalloc(efx->type->max_rx_ip_filters,
1780 sizeof(*channel->rps_flow_id),
1781 GFP_KERNEL);
1782 if (!channel->rps_flow_id)
1783 success = 0;
1784 else
1785 for (i = 0;
1786 i < efx->type->max_rx_ip_filters;
1787 ++i)
1788 channel->rps_flow_id[i] =
1789 RPS_FLOW_ID_INVALID;
1790 }
1791
1792 if (!success) {
1793 efx_for_each_channel(channel, efx)
1794 kfree(channel->rps_flow_id);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001795 efx->type->filter_table_remove(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001796 rc = -ENOMEM;
1797 goto out_unlock;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001798 }
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001799
1800 efx->rps_expire_index = efx->rps_expire_channel = 0;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001801 }
1802#endif
Edward Cree0d322412015-05-20 11:10:03 +01001803out_unlock:
1804 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01001805 mutex_unlock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001806 return rc;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001807}
1808
1809static void efx_remove_filters(struct efx_nic *efx)
1810{
1811#ifdef CONFIG_RFS_ACCEL
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001812 struct efx_channel *channel;
1813
1814 efx_for_each_channel(channel, efx)
1815 kfree(channel->rps_flow_id);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001816#endif
Edward Cree0d322412015-05-20 11:10:03 +01001817 down_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001818 efx->type->filter_table_remove(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001819 up_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001820}
1821
1822static void efx_restore_filters(struct efx_nic *efx)
1823{
Edward Cree0d322412015-05-20 11:10:03 +01001824 down_read(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001825 efx->type->filter_table_restore(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001826 up_read(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001827}
1828
Ben Hutchings8ceee662008-04-27 12:55:59 +01001829/**************************************************************************
1830 *
1831 * NIC startup/shutdown
1832 *
1833 *************************************************************************/
1834
1835static int efx_probe_all(struct efx_nic *efx)
1836{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001837 int rc;
1838
Ben Hutchings8ceee662008-04-27 12:55:59 +01001839 rc = efx_probe_nic(efx);
1840 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001841 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001842 goto fail1;
1843 }
1844
Ben Hutchings8ceee662008-04-27 12:55:59 +01001845 rc = efx_probe_port(efx);
1846 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001847 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001848 goto fail2;
1849 }
1850
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00001851 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
1852 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
1853 rc = -EINVAL;
1854 goto fail3;
1855 }
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001856 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001857
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001858#ifdef CONFIG_SFC_SRIOV
1859 rc = efx->type->vswitching_probe(efx);
1860 if (rc) /* not fatal; the PF will still work fine */
1861 netif_warn(efx, probe, efx->net_dev,
1862 "failed to setup vswitching rc=%d;"
1863 " VFs may not function\n", rc);
1864#endif
1865
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001866 rc = efx_probe_filters(efx);
1867 if (rc) {
1868 netif_err(efx, probe, efx->net_dev,
1869 "failed to create filter tables\n");
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001870 goto fail4;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001871 }
1872
Ben Hutchings7f967c02012-02-13 23:45:02 +00001873 rc = efx_probe_channels(efx);
1874 if (rc)
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001875 goto fail5;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001876
Ben Hutchings8ceee662008-04-27 12:55:59 +01001877 return 0;
1878
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001879 fail5:
Ben Hutchings7f967c02012-02-13 23:45:02 +00001880 efx_remove_filters(efx);
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001881 fail4:
1882#ifdef CONFIG_SFC_SRIOV
1883 efx->type->vswitching_remove(efx);
1884#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01001885 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001886 efx_remove_port(efx);
1887 fail2:
1888 efx_remove_nic(efx);
1889 fail1:
1890 return rc;
1891}
1892
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001893/* If the interface is supposed to be running but is not, start
1894 * the hardware and software data path, regular activity for the port
1895 * (MAC statistics, link polling, etc.) and schedule the port to be
1896 * reconfigured. Interrupts must already be enabled. This function
1897 * is safe to call multiple times, so long as the NIC is not disabled.
1898 * Requires the RTNL lock.
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001899 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001900static void efx_start_all(struct efx_nic *efx)
1901{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001902 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001903 BUG_ON(efx->state == STATE_DISABLED);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001904
1905 /* Check that it is appropriate to restart the interface. All
1906 * of these flags are safe to read under just the rtnl lock */
Edward Creee2835462014-04-16 19:27:48 +01001907 if (efx->port_enabled || !netif_running(efx->net_dev) ||
1908 efx->reset_pending)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001909 return;
1910
Ben Hutchings8ceee662008-04-27 12:55:59 +01001911 efx_start_port(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001912 efx_start_datapath(efx);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001913
Alexandre Rames626950d2013-01-14 17:20:22 +00001914 /* Start the hardware monitor if there is one */
1915 if (efx->type->monitor != NULL)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001916 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1917 efx_monitor_interval);
Alexandre Rames626950d2013-01-14 17:20:22 +00001918
Edward Cree5a6681e2016-11-28 18:55:34 +00001919 /* Link state detection is normally event-driven; we have
Alexandre Rames626950d2013-01-14 17:20:22 +00001920 * to poll now because we could have missed a change
1921 */
Edward Cree5a6681e2016-11-28 18:55:34 +00001922 mutex_lock(&efx->mac_lock);
1923 if (efx->phy_op->poll(efx))
1924 efx_link_status_changed(efx);
1925 mutex_unlock(&efx->mac_lock);
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001926
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001927 efx->type->start_stats(efx);
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001928 efx->type->pull_stats(efx);
1929 spin_lock_bh(&efx->stats_lock);
1930 efx->type->update_stats(efx, NULL, NULL);
1931 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001932}
1933
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001934/* Quiesce the hardware and software data path, and regular activity
1935 * for the port without bringing the link down. Safe to call multiple
1936 * times with the NIC in almost any state, but interrupts should be
1937 * enabled. Requires the RTNL lock.
1938 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001939static void efx_stop_all(struct efx_nic *efx)
1940{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001941 EFX_ASSERT_RESET_SERIALISED(efx);
1942
1943 /* port_enabled can be read safely under the rtnl lock */
1944 if (!efx->port_enabled)
1945 return;
1946
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001947 /* update stats before we go down so we can accurately count
1948 * rx_nodesc_drops
1949 */
1950 efx->type->pull_stats(efx);
1951 spin_lock_bh(&efx->stats_lock);
1952 efx->type->update_stats(efx, NULL, NULL);
1953 spin_unlock_bh(&efx->stats_lock);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001954 efx->type->stop_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001955 efx_stop_port(efx);
1956
Ben Hutchings29c69a42013-01-28 19:01:06 +00001957 /* Stop the kernel transmit interface. This is only valid if
1958 * the device is stopped or detached; otherwise the watchdog
1959 * may fire immediately.
1960 */
1961 WARN_ON(netif_running(efx->net_dev) &&
1962 netif_device_present(efx->net_dev));
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001963 netif_tx_disable(efx->net_dev);
1964
1965 efx_stop_datapath(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001966}
1967
1968static void efx_remove_all(struct efx_nic *efx)
1969{
Ben Hutchings46426102010-09-10 06:42:33 +00001970 efx_remove_channels(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001971 efx_remove_filters(efx);
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001972#ifdef CONFIG_SFC_SRIOV
1973 efx->type->vswitching_remove(efx);
1974#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01001975 efx_remove_port(efx);
1976 efx_remove_nic(efx);
1977}
1978
Ben Hutchings8ceee662008-04-27 12:55:59 +01001979/**************************************************************************
1980 *
1981 * Interrupt moderation
1982 *
1983 **************************************************************************/
Bert Kenward539de7c2016-08-11 13:02:09 +01001984unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001985{
Ben Hutchingsb548f972011-09-05 07:41:44 +00001986 if (usecs == 0)
1987 return 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001988 if (usecs * 1000 < efx->timer_quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001989 return 1; /* never round down to 0 */
Bert Kenward539de7c2016-08-11 13:02:09 +01001990 return usecs * 1000 / efx->timer_quantum_ns;
1991}
1992
1993unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
1994{
1995 /* We must round up when converting ticks to microseconds
1996 * because we round down when converting the other way.
1997 */
1998 return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001999}
2000
Ben Hutchings8ceee662008-04-27 12:55:59 +01002001/* Set interrupt moderation parameters */
Ben Hutchings9e393b32011-09-05 07:43:04 +00002002int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
2003 unsigned int rx_usecs, bool rx_adaptive,
2004 bool rx_may_override_tx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002005{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002006 struct efx_channel *channel;
Bert Kenwardd95e3292016-08-11 13:02:36 +01002007 unsigned int timer_max_us;
2008
Ben Hutchings8ceee662008-04-27 12:55:59 +01002009 EFX_ASSERT_RESET_SERIALISED(efx);
2010
Bert Kenwardd95e3292016-08-11 13:02:36 +01002011 timer_max_us = efx->timer_max_ns / 1000;
2012
2013 if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
Ben Hutchings9e393b32011-09-05 07:43:04 +00002014 return -EINVAL;
2015
Bert Kenward539de7c2016-08-11 13:02:09 +01002016 if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
Ben Hutchings9e393b32011-09-05 07:43:04 +00002017 !rx_may_override_tx) {
2018 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
2019 "RX and TX IRQ moderation must be equal\n");
2020 return -EINVAL;
2021 }
2022
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00002023 efx->irq_rx_adaptive = rx_adaptive;
Bert Kenward539de7c2016-08-11 13:02:09 +01002024 efx->irq_rx_moderation_us = rx_usecs;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002025 efx_for_each_channel(channel, efx) {
Ben Hutchings525da902011-02-07 23:04:38 +00002026 if (efx_channel_has_rx_queue(channel))
Bert Kenward539de7c2016-08-11 13:02:09 +01002027 channel->irq_moderation_us = rx_usecs;
Ben Hutchings525da902011-02-07 23:04:38 +00002028 else if (efx_channel_has_tx_queues(channel))
Bert Kenward539de7c2016-08-11 13:02:09 +01002029 channel->irq_moderation_us = tx_usecs;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002030 }
Ben Hutchings9e393b32011-09-05 07:43:04 +00002031
2032 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002033}
2034
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002035void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
2036 unsigned int *rx_usecs, bool *rx_adaptive)
2037{
2038 *rx_adaptive = efx->irq_rx_adaptive;
Bert Kenward539de7c2016-08-11 13:02:09 +01002039 *rx_usecs = efx->irq_rx_moderation_us;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002040
2041 /* If channels are shared between RX and TX, so is IRQ
2042 * moderation. Otherwise, IRQ moderation is the same for all
2043 * TX channels and is not adaptive.
2044 */
Bert Kenward539de7c2016-08-11 13:02:09 +01002045 if (efx->tx_channel_offset == 0) {
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002046 *tx_usecs = *rx_usecs;
Bert Kenward539de7c2016-08-11 13:02:09 +01002047 } else {
2048 struct efx_channel *tx_channel;
2049
2050 tx_channel = efx->channel[efx->tx_channel_offset];
2051 *tx_usecs = tx_channel->irq_moderation_us;
2052 }
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002053}
2054
Ben Hutchings8ceee662008-04-27 12:55:59 +01002055/**************************************************************************
2056 *
2057 * Hardware monitor
2058 *
2059 **************************************************************************/
2060
Ben Hutchingse254c272010-09-20 08:44:10 +00002061/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002062static void efx_monitor(struct work_struct *data)
2063{
2064 struct efx_nic *efx = container_of(data, struct efx_nic,
2065 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002066
Ben Hutchings62776d02010-06-23 11:30:07 +00002067 netif_vdbg(efx, timer, efx->net_dev,
2068 "hardware monitor executing on CPU %d\n",
2069 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002070 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002071
Ben Hutchings8ceee662008-04-27 12:55:59 +01002072 /* If the mac_lock is already held then it is likely a port
2073 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00002074 * most of the work of monitor() anyway. */
2075 if (mutex_trylock(&efx->mac_lock)) {
2076 if (efx->port_enabled)
2077 efx->type->monitor(efx);
2078 mutex_unlock(&efx->mac_lock);
2079 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002080
Ben Hutchings8ceee662008-04-27 12:55:59 +01002081 queue_delayed_work(efx->workqueue, &efx->monitor_work,
2082 efx_monitor_interval);
2083}
2084
2085/**************************************************************************
2086 *
2087 * ioctls
2088 *
2089 *************************************************************************/
2090
2091/* Net device ioctl
2092 * Context: process, rtnl_lock() held.
2093 */
2094static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
2095{
Ben Hutchings767e4682008-09-01 12:43:14 +01002096 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00002097 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002098
Stuart Hodgson7c236c42012-09-03 11:09:36 +01002099 if (cmd == SIOCSHWTSTAMP)
Ben Hutchings433dc9b2013-11-14 01:26:21 +00002100 return efx_ptp_set_ts_config(efx, ifr);
2101 if (cmd == SIOCGHWTSTAMP)
2102 return efx_ptp_get_ts_config(efx, ifr);
Stuart Hodgson7c236c42012-09-03 11:09:36 +01002103
Ben Hutchings68e7f452009-04-29 08:05:08 +00002104 /* Convert phy_id from older PRTAD/DEVAD format */
2105 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
2106 (data->phy_id & 0xfc00) == 0x0400)
2107 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
2108
2109 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002110}
2111
2112/**************************************************************************
2113 *
2114 * NAPI interface
2115 *
2116 **************************************************************************/
2117
Ben Hutchings7f967c02012-02-13 23:45:02 +00002118static void efx_init_napi_channel(struct efx_channel *channel)
2119{
2120 struct efx_nic *efx = channel->efx;
2121
2122 channel->napi_dev = efx->net_dev;
2123 netif_napi_add(channel->napi_dev, &channel->napi_str,
2124 efx_poll, napi_weight);
2125}
2126
Ben Hutchingse8f14992010-12-07 19:47:34 +00002127static void efx_init_napi(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002128{
2129 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002130
Ben Hutchings7f967c02012-02-13 23:45:02 +00002131 efx_for_each_channel(channel, efx)
2132 efx_init_napi_channel(channel);
Ben Hutchingse8f14992010-12-07 19:47:34 +00002133}
2134
2135static void efx_fini_napi_channel(struct efx_channel *channel)
2136{
Eric Dumazet973334a2016-11-16 06:01:47 -08002137 if (channel->napi_dev)
Ben Hutchingse8f14992010-12-07 19:47:34 +00002138 netif_napi_del(&channel->napi_str);
Eric Dumazet973334a2016-11-16 06:01:47 -08002139
Ben Hutchingse8f14992010-12-07 19:47:34 +00002140 channel->napi_dev = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002141}
2142
2143static void efx_fini_napi(struct efx_nic *efx)
2144{
2145 struct efx_channel *channel;
2146
Ben Hutchingse8f14992010-12-07 19:47:34 +00002147 efx_for_each_channel(channel, efx)
2148 efx_fini_napi_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002149}
2150
2151/**************************************************************************
2152 *
2153 * Kernel netpoll interface
2154 *
2155 *************************************************************************/
2156
2157#ifdef CONFIG_NET_POLL_CONTROLLER
2158
2159/* Although in the common case interrupts will be disabled, this is not
2160 * guaranteed. However, all our work happens inside the NAPI callback,
2161 * so no locking is required.
2162 */
2163static void efx_netpoll(struct net_device *net_dev)
2164{
Ben Hutchings767e4682008-09-01 12:43:14 +01002165 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002166 struct efx_channel *channel;
2167
Ben Hutchings64ee3122008-09-01 12:47:38 +01002168 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002169 efx_schedule_channel(channel);
2170}
2171
2172#endif
2173
2174/**************************************************************************
2175 *
2176 * Kernel net device interface
2177 *
2178 *************************************************************************/
2179
2180/* Context: process, rtnl_lock() held. */
Shradha Shahe340be92015-05-20 11:11:03 +01002181int efx_net_open(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002182{
Ben Hutchings767e4682008-09-01 12:43:14 +01002183 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002184 int rc;
2185
Ben Hutchings62776d02010-06-23 11:30:07 +00002186 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
2187 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002188
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002189 rc = efx_check_disabled(efx);
2190 if (rc)
2191 return rc;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002192 if (efx->phy_mode & PHY_MODE_SPECIAL)
2193 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002194 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
2195 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002196
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00002197 /* Notify the kernel of the link state polled during driver load,
2198 * before the monitor starts running */
2199 efx_link_status_changed(efx);
2200
Ben Hutchings8ceee662008-04-27 12:55:59 +01002201 efx_start_all(efx);
Peter Dunning9c568fd2017-02-17 15:50:43 +00002202 if (efx->state == STATE_DISABLED || efx->reset_pending)
2203 netif_device_detach(efx->net_dev);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002204 efx_selftest_async_start(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002205 return 0;
2206}
2207
2208/* Context: process, rtnl_lock() held.
2209 * Note that the kernel will ignore our return code; this method
2210 * should really be a void.
2211 */
Shradha Shahe340be92015-05-20 11:11:03 +01002212int efx_net_stop(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002213{
Ben Hutchings767e4682008-09-01 12:43:14 +01002214 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002215
Ben Hutchings62776d02010-06-23 11:30:07 +00002216 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
2217 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002218
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002219 /* Stop the device and flush all the channels */
2220 efx_stop_all(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002221
2222 return 0;
2223}
2224
Ben Hutchings5b9e2072008-05-16 21:18:14 +01002225/* Context: process, dev_base_lock or RTNL held, non-blocking. */
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002226static void efx_net_stats(struct net_device *net_dev,
2227 struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002228{
Ben Hutchings767e4682008-09-01 12:43:14 +01002229 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002230
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002231 spin_lock_bh(&efx->stats_lock);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +00002232 efx->type->update_stats(efx, NULL, stats);
Ben Hutchings1cb34522011-09-02 23:23:00 +01002233 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002234}
2235
2236/* Context: netif_tx_lock held, BHs disabled. */
2237static void efx_watchdog(struct net_device *net_dev)
2238{
Ben Hutchings767e4682008-09-01 12:43:14 +01002239 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002240
Ben Hutchings62776d02010-06-23 11:30:07 +00002241 netif_err(efx, tx_err, efx->net_dev,
2242 "TX stuck with port_enabled=%d: resetting channels\n",
2243 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002244
Ben Hutchings739bb23d2008-11-04 20:35:36 +00002245 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002246}
2247
2248
2249/* Context: process, rtnl_lock() held. */
2250static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
2251{
Ben Hutchings767e4682008-09-01 12:43:14 +01002252 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002253 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002254
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002255 rc = efx_check_disabled(efx);
2256 if (rc)
2257 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002258
Ben Hutchings62776d02010-06-23 11:30:07 +00002259 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002260
Ben Hutchings29c69a42013-01-28 19:01:06 +00002261 efx_device_detach_sync(efx);
2262 efx_stop_all(efx);
2263
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002264 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002265 net_dev->mtu = new_mtu;
Edward Cree0d322412015-05-20 11:10:03 +01002266 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002267 mutex_unlock(&efx->mac_lock);
2268
Ben Hutchings8ceee662008-04-27 12:55:59 +01002269 efx_start_all(efx);
Peter Dunning9c568fd2017-02-17 15:50:43 +00002270 efx_device_attach_if_not_resetting(efx);
Ben Hutchings6c8eef42012-01-09 19:54:16 +00002271 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002272}
2273
2274static int efx_set_mac_address(struct net_device *net_dev, void *data)
2275{
Ben Hutchings767e4682008-09-01 12:43:14 +01002276 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002277 struct sockaddr *addr = data;
Ben Hutchingse0b3ae32014-02-12 18:59:54 +00002278 u8 *new_addr = addr->sa_data;
Shradha Shahcfc77c22015-05-20 11:09:30 +01002279 u8 old_addr[6];
2280 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002281
Ben Hutchings8ceee662008-04-27 12:55:59 +01002282 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002283 netif_err(efx, drv, efx->net_dev,
2284 "invalid ethernet MAC address requested: %pM\n",
2285 new_addr);
Danny Kukawka504f9b52012-02-21 02:07:49 +00002286 return -EADDRNOTAVAIL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002287 }
2288
Shradha Shahcfc77c22015-05-20 11:09:30 +01002289 /* save old address */
2290 ether_addr_copy(old_addr, net_dev->dev_addr);
Edward Creecd84ff42014-03-07 18:27:41 +00002291 ether_addr_copy(net_dev->dev_addr, new_addr);
Shradha Shah910c8782015-05-20 11:12:48 +01002292 if (efx->type->set_mac_address) {
2293 rc = efx->type->set_mac_address(efx);
Shradha Shahcfc77c22015-05-20 11:09:30 +01002294 if (rc) {
2295 ether_addr_copy(net_dev->dev_addr, old_addr);
2296 return rc;
2297 }
2298 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002299
2300 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002301 mutex_lock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01002302 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002303 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002304
2305 return 0;
2306}
2307
Ben Hutchingsa816f752008-09-01 12:49:12 +01002308/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002309static void efx_set_rx_mode(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002310{
Ben Hutchings767e4682008-09-01 12:43:14 +01002311 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002312
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002313 if (efx->port_enabled)
2314 queue_work(efx->workqueue, &efx->mac_work);
2315 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002316}
2317
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002318static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002319{
2320 struct efx_nic *efx = netdev_priv(net_dev);
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002321 int rc;
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002322
2323 /* If disabling RX n-tuple filtering, clear existing filters */
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002324 if (net_dev->features & ~data & NETIF_F_NTUPLE) {
2325 rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
2326 if (rc)
2327 return rc;
2328 }
2329
Edward Cree69787292017-10-31 14:29:47 +00002330 /* If Rx VLAN filter is changed, update filters via mac_reconfigure.
2331 * If rx-fcs is changed, mac_reconfigure updates that too.
2332 */
2333 if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
2334 NETIF_F_RXFCS)) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002335 /* efx_set_rx_mode() will schedule MAC work to update filters
2336 * when a new features are finally set in net_dev.
2337 */
2338 efx_set_rx_mode(net_dev);
2339 }
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002340
2341 return 0;
2342}
2343
Wei Yongjunb40296f2017-01-11 16:16:12 +00002344static int efx_get_phys_port_id(struct net_device *net_dev,
2345 struct netdev_phys_item_id *ppid)
Bert Kenward08a7b29b2017-01-10 16:23:33 +00002346{
2347 struct efx_nic *efx = netdev_priv(net_dev);
2348
2349 if (efx->type->get_phys_port_id)
2350 return efx->type->get_phys_port_id(efx, ppid);
2351 else
2352 return -EOPNOTSUPP;
2353}
2354
Bert Kenwardac019f02017-01-10 16:23:56 +00002355static int efx_get_phys_port_name(struct net_device *net_dev,
2356 char *name, size_t len)
2357{
2358 struct efx_nic *efx = netdev_priv(net_dev);
2359
2360 if (snprintf(name, len, "p%u", efx->port_num) >= len)
2361 return -EINVAL;
2362 return 0;
2363}
2364
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002365static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
2366{
2367 struct efx_nic *efx = netdev_priv(net_dev);
2368
2369 if (efx->type->vlan_rx_add_vid)
2370 return efx->type->vlan_rx_add_vid(efx, proto, vid);
2371 else
2372 return -EOPNOTSUPP;
2373}
2374
2375static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
2376{
2377 struct efx_nic *efx = netdev_priv(net_dev);
2378
2379 if (efx->type->vlan_rx_kill_vid)
2380 return efx->type->vlan_rx_kill_vid(efx, proto, vid);
2381 else
2382 return -EOPNOTSUPP;
2383}
2384
Jon Coopere5fbd972017-02-08 16:52:10 +00002385static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
2386{
2387 switch (in) {
2388 case UDP_TUNNEL_TYPE_VXLAN:
2389 return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
2390 case UDP_TUNNEL_TYPE_GENEVE:
2391 return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
2392 default:
2393 return -1;
2394 }
2395}
2396
2397static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
2398{
2399 struct efx_nic *efx = netdev_priv(dev);
2400 struct efx_udp_tunnel tnl;
2401 int efx_tunnel_type;
2402
2403 efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2404 if (efx_tunnel_type < 0)
2405 return;
2406
2407 tnl.type = (u16)efx_tunnel_type;
2408 tnl.port = ti->port;
2409
2410 if (efx->type->udp_tnl_add_port)
2411 (void)efx->type->udp_tnl_add_port(efx, tnl);
2412}
2413
2414static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
2415{
2416 struct efx_nic *efx = netdev_priv(dev);
2417 struct efx_udp_tunnel tnl;
2418 int efx_tunnel_type;
2419
2420 efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2421 if (efx_tunnel_type < 0)
2422 return;
2423
2424 tnl.type = (u16)efx_tunnel_type;
2425 tnl.port = ti->port;
2426
Dan Carpenterc04ca612017-03-22 12:10:02 +03002427 if (efx->type->udp_tnl_del_port)
Jon Coopere5fbd972017-02-08 16:52:10 +00002428 (void)efx->type->udp_tnl_del_port(efx, tnl);
2429}
2430
Shradha Shah7fa8d542015-05-06 00:55:13 +01002431static const struct net_device_ops efx_netdev_ops = {
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002432 .ndo_open = efx_net_open,
2433 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00002434 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002435 .ndo_tx_timeout = efx_watchdog,
2436 .ndo_start_xmit = efx_hard_start_xmit,
2437 .ndo_validate_addr = eth_validate_addr,
2438 .ndo_do_ioctl = efx_ioctl,
2439 .ndo_change_mtu = efx_change_mtu,
2440 .ndo_set_mac_address = efx_set_mac_address,
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002441 .ndo_set_rx_mode = efx_set_rx_mode,
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002442 .ndo_set_features = efx_set_features,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002443 .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
2444 .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002445#ifdef CONFIG_SFC_SRIOV
Shradha Shah7fa8d542015-05-06 00:55:13 +01002446 .ndo_set_vf_mac = efx_sriov_set_vf_mac,
2447 .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
2448 .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
2449 .ndo_get_vf_config = efx_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01002450 .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002451#endif
Bert Kenward08a7b29b2017-01-10 16:23:33 +00002452 .ndo_get_phys_port_id = efx_get_phys_port_id,
Bert Kenwardac019f02017-01-10 16:23:56 +00002453 .ndo_get_phys_port_name = efx_get_phys_port_name,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002454#ifdef CONFIG_NET_POLL_CONTROLLER
2455 .ndo_poll_controller = efx_netpoll,
2456#endif
Ben Hutchings94b274b2011-01-10 21:18:20 +00002457 .ndo_setup_tc = efx_setup_tc,
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002458#ifdef CONFIG_RFS_ACCEL
2459 .ndo_rx_flow_steer = efx_filter_rfs,
2460#endif
Jon Coopere5fbd972017-02-08 16:52:10 +00002461 .ndo_udp_tunnel_add = efx_udp_tunnel_add,
2462 .ndo_udp_tunnel_del = efx_udp_tunnel_del,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002463};
2464
Ben Hutchings7dde5962008-12-12 22:09:38 -08002465static void efx_update_name(struct efx_nic *efx)
2466{
2467 strcpy(efx->name, efx->net_dev->name);
2468 efx_mtd_rename(efx);
2469 efx_set_channel_names(efx);
2470}
2471
Ben Hutchings8ceee662008-04-27 12:55:59 +01002472static int efx_netdev_event(struct notifier_block *this,
2473 unsigned long event, void *ptr)
2474{
Jiri Pirko351638e2013-05-28 01:30:21 +00002475 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002476
Shradha Shah7fa8d542015-05-06 00:55:13 +01002477 if ((net_dev->netdev_ops == &efx_netdev_ops) &&
Ben Hutchings7dde5962008-12-12 22:09:38 -08002478 event == NETDEV_CHANGENAME)
2479 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002480
2481 return NOTIFY_DONE;
2482}
2483
2484static struct notifier_block efx_netdev_notifier = {
2485 .notifier_call = efx_netdev_event,
2486};
2487
Ben Hutchings06d5e192008-12-12 21:47:23 -08002488static ssize_t
2489show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2490{
2491 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2492 return sprintf(buf, "%d\n", efx->phy_type);
2493}
Ben Hutchings776fbcc2013-06-18 17:45:40 +01002494static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
Ben Hutchings06d5e192008-12-12 21:47:23 -08002495
Edward Creee7fef9b2015-05-27 13:14:01 +01002496#ifdef CONFIG_SFC_MCDI_LOGGING
2497static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
2498 char *buf)
2499{
2500 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2501 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2502
2503 return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
2504}
2505static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
2506 const char *buf, size_t count)
2507{
2508 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2509 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2510 bool enable = count > 0 && *buf != '0';
2511
2512 mcdi->logging_enabled = enable;
2513 return count;
2514}
2515static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
2516#endif
2517
Ben Hutchings8ceee662008-04-27 12:55:59 +01002518static int efx_register_netdev(struct efx_nic *efx)
2519{
2520 struct net_device *net_dev = efx->net_dev;
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002521 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002522 int rc;
2523
2524 net_dev->watchdog_timeo = 5 * HZ;
2525 net_dev->irq = efx->pci_dev->irq;
Shradha Shah7fa8d542015-05-06 00:55:13 +01002526 net_dev->netdev_ops = &efx_netdev_ops;
2527 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
Ben Hutchings8127d662013-08-29 19:19:29 +01002528 net_dev->priv_flags |= IFF_UNICAST_FLT;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002529 net_dev->ethtool_ops = &efx_ethtool_ops;
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00002530 net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
Bert Kenwardcd94e512016-10-18 17:47:45 +01002531 net_dev->min_mtu = EFX_MIN_MTU;
2532 net_dev->max_mtu = EFX_MAX_MTU;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002533
Ben Hutchings7dde5962008-12-12 22:09:38 -08002534 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00002535
Ben Hutchings7153f622012-07-27 20:50:52 +01002536 /* Enable resets to be scheduled and check whether any were
2537 * already requested. If so, the NIC is probably hosed so we
2538 * abort.
2539 */
2540 efx->state = STATE_READY;
2541 smp_mb(); /* ensure we change state before checking reset_pending */
2542 if (efx->reset_pending) {
2543 netif_err(efx, probe, efx->net_dev,
2544 "aborting probe due to scheduled reset\n");
2545 rc = -EIO;
2546 goto fail_locked;
2547 }
2548
Ben Hutchingsaed06282009-08-26 08:16:27 +00002549 rc = dev_alloc_name(net_dev, net_dev->name);
2550 if (rc < 0)
2551 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002552 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002553
Ben Hutchings8f8b3d52012-08-24 18:04:38 +01002554 /* Always start with carrier off; PHY events will detect the link */
2555 netif_carrier_off(net_dev);
2556
Ben Hutchingsaed06282009-08-26 08:16:27 +00002557 rc = register_netdevice(net_dev);
2558 if (rc)
2559 goto fail_locked;
2560
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002561 efx_for_each_channel(channel, efx) {
2562 struct efx_tx_queue *tx_queue;
Ben Hutchings60031fc2011-01-12 18:39:40 +00002563 efx_for_each_channel_tx_queue(tx_queue, channel)
2564 efx_init_tx_queue_core_txq(tx_queue);
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002565 }
2566
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002567 efx_associate(efx);
2568
Ben Hutchings7dde5962008-12-12 22:09:38 -08002569 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002570
Ben Hutchings06d5e192008-12-12 21:47:23 -08002571 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2572 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002573 netif_err(efx, drv, efx->net_dev,
2574 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08002575 goto fail_registered;
2576 }
Edward Creee7fef9b2015-05-27 13:14:01 +01002577#ifdef CONFIG_SFC_MCDI_LOGGING
2578 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2579 if (rc) {
2580 netif_err(efx, drv, efx->net_dev,
2581 "failed to init net dev attributes\n");
2582 goto fail_attr_mcdi_logging;
2583 }
2584#endif
Ben Hutchings06d5e192008-12-12 21:47:23 -08002585
Ben Hutchings8ceee662008-04-27 12:55:59 +01002586 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08002587
Edward Creee7fef9b2015-05-27 13:14:01 +01002588#ifdef CONFIG_SFC_MCDI_LOGGING
2589fail_attr_mcdi_logging:
2590 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2591#endif
Ben Hutchings7153f622012-07-27 20:50:52 +01002592fail_registered:
2593 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002594 efx_dissociate(efx);
Ben Hutchings7153f622012-07-27 20:50:52 +01002595 unregister_netdevice(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002596fail_locked:
Ben Hutchings7153f622012-07-27 20:50:52 +01002597 efx->state = STATE_UNINIT;
Ben Hutchingsaed06282009-08-26 08:16:27 +00002598 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00002599 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00002600 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002601}
2602
2603static void efx_unregister_netdev(struct efx_nic *efx)
2604{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002605 if (!efx->net_dev)
2606 return;
2607
Ben Hutchings767e4682008-09-01 12:43:14 +01002608 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002609
Edward Creee7fef9b2015-05-27 13:14:01 +01002610 if (efx_dev_registered(efx)) {
2611 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2612#ifdef CONFIG_SFC_MCDI_LOGGING
2613 device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2614#endif
2615 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2616 unregister_netdev(efx->net_dev);
2617 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002618}
2619
2620/**************************************************************************
2621 *
2622 * Device reset and suspend
2623 *
2624 **************************************************************************/
2625
Ben Hutchings2467ca42008-09-01 12:48:50 +01002626/* Tears down the entire software state and most of the hardware state
2627 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002628void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002629{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002630 EFX_ASSERT_RESET_SERIALISED(efx);
2631
Edward Creee2835462014-04-16 19:27:48 +01002632 if (method == RESET_TYPE_MCDI_TIMEOUT)
2633 efx->type->prepare_flr(efx);
2634
Ben Hutchings2467ca42008-09-01 12:48:50 +01002635 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01002636 efx_disable_interrupts(efx);
Ben Hutchings5642cee2012-07-27 19:35:52 +01002637
2638 mutex_lock(&efx->mac_lock);
Jon Cooper087e9022015-05-20 11:11:35 +01002639 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2640 method != RESET_TYPE_DATAPATH)
Steve Hodgson4b988282009-01-29 17:50:51 +00002641 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002642 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002643}
2644
Ben Hutchings2467ca42008-09-01 12:48:50 +01002645/* This function will always ensure that the locks acquired in
2646 * efx_reset_down() are released. A failure return code indicates
2647 * that we were unable to reinitialise the hardware, and the
2648 * driver should be disabled. If ok is false, then the rx and tx
2649 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002650int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002651{
2652 int rc;
2653
Ben Hutchings2467ca42008-09-01 12:48:50 +01002654 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002655
Edward Creee2835462014-04-16 19:27:48 +01002656 if (method == RESET_TYPE_MCDI_TIMEOUT)
2657 efx->type->finish_flr(efx);
2658
2659 /* Ensure that SRAM is initialised even if we're disabling the device */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002660 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002661 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002662 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002663 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002664 }
2665
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002666 if (!ok)
2667 goto fail;
2668
Jon Cooper087e9022015-05-20 11:11:35 +01002669 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2670 method != RESET_TYPE_DATAPATH) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002671 rc = efx->phy_op->init(efx);
2672 if (rc)
2673 goto fail;
Edward Cree267d9d72015-05-06 00:59:18 +01002674 rc = efx->phy_op->reconfigure(efx);
2675 if (rc && rc != -EPERM)
Ben Hutchings62776d02010-06-23 11:30:07 +00002676 netif_err(efx, drv, efx->net_dev,
2677 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002678 }
2679
Jon Cooper261e4d92013-04-15 18:51:54 +01002680 rc = efx_enable_interrupts(efx);
2681 if (rc)
2682 goto fail;
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01002683
2684#ifdef CONFIG_SFC_SRIOV
2685 rc = efx->type->vswitching_restore(efx);
2686 if (rc) /* not fatal; the PF will still work fine */
2687 netif_warn(efx, probe, efx->net_dev,
2688 "failed to restore vswitching rc=%d;"
2689 " VFs may not function\n", rc);
2690#endif
2691
Edward Cree0d322412015-05-20 11:10:03 +01002692 down_read(&efx->filter_sem);
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002693 efx_restore_filters(efx);
Edward Cree0d322412015-05-20 11:10:03 +01002694 up_read(&efx->filter_sem);
Shradha Shah7fa8d542015-05-06 00:55:13 +01002695 if (efx->type->sriov_reset)
2696 efx->type->sriov_reset(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002697
2698 mutex_unlock(&efx->mac_lock);
2699
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002700 efx_start_all(efx);
2701
Jon Coopere5fbd972017-02-08 16:52:10 +00002702 if (efx->type->udp_tnl_push_ports)
2703 efx->type->udp_tnl_push_ports(efx);
2704
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002705 return 0;
2706
2707fail:
2708 efx->port_initialized = false;
2709
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002710 mutex_unlock(&efx->mac_lock);
2711
Ben Hutchings8ceee662008-04-27 12:55:59 +01002712 return rc;
2713}
2714
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002715/* Reset the NIC using the specified method. Note that the reset may
2716 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002717 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002718 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002719 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002720int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002721{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002722 int rc, rc2;
2723 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002724
Ben Hutchings62776d02010-06-23 11:30:07 +00002725 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2726 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002727
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01002728 efx_device_detach_sync(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002729 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002730
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002731 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002732 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002733 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002734 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002735 }
2736
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002737 /* Clear flags for the scopes we covered. We assume the NIC and
2738 * driver are now quiescent so that there is no race here.
2739 */
Edward Creee2835462014-04-16 19:27:48 +01002740 if (method < RESET_TYPE_MAX_METHOD)
2741 efx->reset_pending &= -(1 << (method + 1));
2742 else /* it doesn't fit into the well-ordered scope hierarchy */
2743 __clear_bit(method, &efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002744
2745 /* Reinitialise bus-mastering, which may have been turned off before
2746 * the reset was scheduled. This is still appropriate, even in the
2747 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2748 * can respond to requests. */
2749 pci_set_master(efx->pci_dev);
2750
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002751out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002752 /* Leave device stopped if necessary */
Alexandre Rames626950d2013-01-14 17:20:22 +00002753 disabled = rc ||
2754 method == RESET_TYPE_DISABLE ||
2755 method == RESET_TYPE_RECOVER_OR_DISABLE;
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002756 rc2 = efx_reset_up(efx, method, !disabled);
2757 if (rc2) {
2758 disabled = true;
2759 if (!rc)
2760 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002761 }
2762
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002763 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002764 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002765 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002766 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002767 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002768 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Peter Dunning9c568fd2017-02-17 15:50:43 +00002769 efx_device_attach_if_not_resetting(efx);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002770 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002771 return rc;
2772}
2773
Alexandre Rames626950d2013-01-14 17:20:22 +00002774/* Try recovery mechanisms.
2775 * For now only EEH is supported.
2776 * Returns 0 if the recovery mechanisms are unsuccessful.
2777 * Returns a non-zero value otherwise.
2778 */
Alexandre Ramesb28405b2013-03-21 16:41:43 +00002779int efx_try_recovery(struct efx_nic *efx)
Alexandre Rames626950d2013-01-14 17:20:22 +00002780{
2781#ifdef CONFIG_EEH
2782 /* A PCI error can occur and not be seen by EEH because nothing
2783 * happens on the PCI bus. In this case the driver may fail and
2784 * schedule a 'recover or reset', leading to this recovery handler.
2785 * Manually call the eeh failure check function.
2786 */
Benjamin Herrenschmidt12a89db2015-03-23 14:00:47 +11002787 struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
Alexandre Rames626950d2013-01-14 17:20:22 +00002788 if (eeh_dev_check_failure(eehdev)) {
2789 /* The EEH mechanisms will handle the error and reset the
2790 * device if necessary.
2791 */
2792 return 1;
2793 }
2794#endif
2795 return 0;
2796}
2797
Jon Cooper74cd60a2013-09-16 14:18:51 +01002798static void efx_wait_for_bist_end(struct efx_nic *efx)
2799{
2800 int i;
2801
2802 for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
2803 if (efx_mcdi_poll_reboot(efx))
2804 goto out;
2805 msleep(BIST_WAIT_DELAY_MS);
2806 }
2807
2808 netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
2809out:
2810 /* Either way unset the BIST flag. If we found no reboot we probably
2811 * won't recover, but we should try.
2812 */
2813 efx->mc_bist_for_other_fn = false;
2814}
2815
Ben Hutchings8ceee662008-04-27 12:55:59 +01002816/* The worker thread exists so that code that cannot sleep can
2817 * schedule a reset for later.
2818 */
2819static void efx_reset_work(struct work_struct *data)
2820{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002821 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Alexandre Rames626950d2013-01-14 17:20:22 +00002822 unsigned long pending;
2823 enum reset_type method;
2824
Mark Rutland6aa7de02017-10-23 14:07:29 -07002825 pending = READ_ONCE(efx->reset_pending);
Alexandre Rames626950d2013-01-14 17:20:22 +00002826 method = fls(pending) - 1;
2827
Jon Cooper74cd60a2013-09-16 14:18:51 +01002828 if (method == RESET_TYPE_MC_BIST)
2829 efx_wait_for_bist_end(efx);
2830
Alexandre Rames626950d2013-01-14 17:20:22 +00002831 if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
2832 method == RESET_TYPE_RECOVER_OR_ALL) &&
2833 efx_try_recovery(efx))
2834 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002835
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002836 if (!pending)
Steve Hodgson319ba642010-06-01 11:17:24 +00002837 return;
2838
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002839 rtnl_lock();
Ben Hutchings7153f622012-07-27 20:50:52 +01002840
2841 /* We checked the state in efx_schedule_reset() but it may
2842 * have changed by now. Now that we have the RTNL lock,
2843 * it cannot change again.
2844 */
2845 if (efx->state == STATE_READY)
Alexandre Rames626950d2013-01-14 17:20:22 +00002846 (void)efx_reset(efx, method);
Ben Hutchings7153f622012-07-27 20:50:52 +01002847
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002848 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002849}
2850
2851void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2852{
2853 enum reset_type method;
2854
Alexandre Rames626950d2013-01-14 17:20:22 +00002855 if (efx->state == STATE_RECOVERY) {
2856 netif_dbg(efx, drv, efx->net_dev,
2857 "recovering: skip scheduling %s reset\n",
2858 RESET_TYPE(type));
2859 return;
2860 }
2861
Ben Hutchings8ceee662008-04-27 12:55:59 +01002862 switch (type) {
2863 case RESET_TYPE_INVISIBLE:
2864 case RESET_TYPE_ALL:
Alexandre Rames626950d2013-01-14 17:20:22 +00002865 case RESET_TYPE_RECOVER_OR_ALL:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002866 case RESET_TYPE_WORLD:
2867 case RESET_TYPE_DISABLE:
Alexandre Rames626950d2013-01-14 17:20:22 +00002868 case RESET_TYPE_RECOVER_OR_DISABLE:
Jon Cooper087e9022015-05-20 11:11:35 +01002869 case RESET_TYPE_DATAPATH:
Jon Cooper74cd60a2013-09-16 14:18:51 +01002870 case RESET_TYPE_MC_BIST:
Edward Creee2835462014-04-16 19:27:48 +01002871 case RESET_TYPE_MCDI_TIMEOUT:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002872 method = type;
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002873 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2874 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002875 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002876 default:
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002877 method = efx->type->map_reset_reason(type);
Ben Hutchings62776d02010-06-23 11:30:07 +00002878 netif_dbg(efx, drv, efx->net_dev,
2879 "scheduling %s reset for %s\n",
2880 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002881 break;
2882 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002883
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002884 set_bit(method, &efx->reset_pending);
Ben Hutchings7153f622012-07-27 20:50:52 +01002885 smp_mb(); /* ensure we change reset_pending before checking state */
2886
2887 /* If we're not READY then just leave the flags set as the cue
2888 * to abort probing or reschedule the reset later.
2889 */
Mark Rutland6aa7de02017-10-23 14:07:29 -07002890 if (READ_ONCE(efx->state) != STATE_READY)
Ben Hutchings7153f622012-07-27 20:50:52 +01002891 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002892
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002893 /* efx_process_channel() will no longer read events once a
2894 * reset is scheduled. So switch back to poll'd MCDI completions. */
2895 efx_mcdi_mode_poll(efx);
2896
Steve Hodgson1ab00622008-12-12 21:33:02 -08002897 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002898}
2899
2900/**************************************************************************
2901 *
2902 * List of NICs we support
2903 *
2904 **************************************************************************/
2905
2906/* PCI device ID table */
Benoit Taine9baa3c32014-08-08 15:56:03 +02002907static const struct pci_device_id efx_pci_table[] = {
Ben Hutchings547c4742011-12-02 18:23:56 +00002908 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002909 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002910 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002911 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8127d662013-08-29 19:19:29 +01002912 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
2913 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01002914 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
2915 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Mateusz Wrzesinski3b06a002014-07-14 08:38:49 +01002916 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
2917 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Bert Kenwarddd248f12015-11-30 09:05:47 +00002918 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
2919 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2920 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
2921 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2922 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
2923 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Edward Creeaae5a312017-12-18 16:56:34 +00002924 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */
2925 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2926 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */
2927 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002928 {0} /* end of list */
2929};
2930
2931/**************************************************************************
2932 *
Ben Hutchings37594332009-11-23 16:05:45 +00002933 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002934 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002935 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002936 * Needed so all function pointers are valid and do not have to be tested
2937 * before use
2938 *
2939 **************************************************************************/
2940int efx_port_dummy_op_int(struct efx_nic *efx)
2941{
2942 return 0;
2943}
2944void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002945
2946static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002947{
2948 return false;
2949}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002950
stephen hemminger6c8c2512011-04-14 05:50:12 +00002951static const struct efx_phy_operations efx_dummy_phy_operations = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002952 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002953 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002954 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002955 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002956};
2957
Ben Hutchings8ceee662008-04-27 12:55:59 +01002958/**************************************************************************
2959 *
2960 * Data housekeeping
2961 *
2962 **************************************************************************/
2963
2964/* This zeroes out and then fills in the invariants in a struct
2965 * efx_nic (including all sub-structures).
2966 */
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01002967static int efx_init_struct(struct efx_nic *efx,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002968 struct pci_dev *pci_dev, struct net_device *net_dev)
2969{
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00002970 int rc = -ENOMEM, i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002971
2972 /* Initialise common structures */
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002973 INIT_LIST_HEAD(&efx->node);
2974 INIT_LIST_HEAD(&efx->secondary_list);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002975 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002976#ifdef CONFIG_SFC_MTD
2977 INIT_LIST_HEAD(&efx->mtd_list);
2978#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002979 INIT_WORK(&efx->reset_work, efx_reset_work);
2980 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002981 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002982 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002983 efx->msg_enable = debug;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002984 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002985 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002986
2987 efx->net_dev = net_dev;
Jon Cooper43a37392012-10-18 15:49:54 +01002988 efx->rx_prefix_size = efx->type->rx_prefix_size;
Andrew Rybchenko2ec03012013-11-16 11:02:27 +04002989 efx->rx_ip_align =
2990 NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
Jon Cooper43a37392012-10-18 15:49:54 +01002991 efx->rx_packet_hash_offset =
2992 efx->type->rx_hash_offset - efx->type->rx_prefix_size;
Jon Cooperbd9a2652013-11-18 12:54:41 +00002993 efx->rx_packet_ts_offset =
2994 efx->type->rx_ts_offset - efx->type->rx_prefix_size;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002995 spin_lock_init(&efx->stats_lock);
Edward Cree71827442017-12-18 16:56:19 +00002996 efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
Edward Creec1be4822017-12-21 09:00:26 +00002997 efx->num_mac_stats = MC_CMD_MAC_NSTATS;
2998 BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002999 mutex_init(&efx->mac_lock);
3000 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00003001 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08003002 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00003003 init_waitqueue_head(&efx->flush_wq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003004
3005 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00003006 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
3007 if (!efx->channel[i])
3008 goto fail;
Ben Hutchingsd8291182012-10-05 23:35:41 +01003009 efx->msi_context[i].efx = efx;
3010 efx->msi_context[i].index = i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003011 }
3012
Ben Hutchings8ceee662008-04-27 12:55:59 +01003013 /* Higher numbered interrupt modes are less capable! */
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003014 if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
3015 efx->type->min_interrupt_mode)) {
3016 rc = -EIO;
3017 goto fail;
3018 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003019 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
3020 interrupt_mode);
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003021 efx->interrupt_mode = min(efx->type->min_interrupt_mode,
3022 interrupt_mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003023
Ben Hutchings6977dc62008-12-26 13:44:39 -08003024 /* Would be good to use the net_dev name, but we're too early */
3025 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
3026 pci_name(pci_dev));
3027 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08003028 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00003029 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01003030
Ben Hutchings8ceee662008-04-27 12:55:59 +01003031 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00003032
3033fail:
3034 efx_fini_struct(efx);
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003035 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003036}
3037
3038static void efx_fini_struct(struct efx_nic *efx)
3039{
Ben Hutchings8313aca2010-09-10 06:41:57 +00003040 int i;
3041
3042 for (i = 0; i < EFX_MAX_CHANNELS; i++)
3043 kfree(efx->channel[i]);
3044
Ben Hutchingsef215e62013-12-05 20:13:22 +00003045 kfree(efx->vpd_sn);
3046
Ben Hutchings8ceee662008-04-27 12:55:59 +01003047 if (efx->workqueue) {
3048 destroy_workqueue(efx->workqueue);
3049 efx->workqueue = NULL;
3050 }
3051}
3052
Edward Creee4d112e2014-07-15 11:58:12 +01003053void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
3054{
3055 u64 n_rx_nodesc_trunc = 0;
3056 struct efx_channel *channel;
3057
3058 efx_for_each_channel(channel, efx)
3059 n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
3060 stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
3061 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
3062}
3063
Ben Hutchings8ceee662008-04-27 12:55:59 +01003064/**************************************************************************
3065 *
3066 * PCI interface
3067 *
3068 **************************************************************************/
3069
3070/* Main body of final NIC shutdown code
3071 * This is called only at module unload (or hotplug removal).
3072 */
3073static void efx_pci_remove_main(struct efx_nic *efx)
3074{
Ben Hutchings7153f622012-07-27 20:50:52 +01003075 /* Flush reset_work. It can no longer be scheduled since we
3076 * are not READY.
3077 */
3078 BUG_ON(efx->state == STATE_READY);
3079 cancel_work_sync(&efx->reset_work);
3080
Ben Hutchingsd8291182012-10-05 23:35:41 +01003081 efx_disable_interrupts(efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +00003082 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003083 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003084 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003085 efx_fini_napi(efx);
3086 efx_remove_all(efx);
3087}
3088
3089/* Final NIC shutdown
Daniel Pieczko2a3fc312015-06-02 11:40:46 +01003090 * This is called only at module unload (or hotplug removal). A PF can call
3091 * this on its VFs to ensure they are unbound first.
Ben Hutchings8ceee662008-04-27 12:55:59 +01003092 */
3093static void efx_pci_remove(struct pci_dev *pci_dev)
3094{
3095 struct efx_nic *efx;
3096
3097 efx = pci_get_drvdata(pci_dev);
3098 if (!efx)
3099 return;
3100
3101 /* Mark the NIC as fini, then stop the interface */
3102 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01003103 efx_dissociate(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003104 dev_close(efx->net_dev);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003105 efx_disable_interrupts(efx);
Edward Creeea6bb992015-06-15 18:27:54 +01003106 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003107 rtnl_unlock();
3108
Shradha Shah7fa8d542015-05-06 00:55:13 +01003109 if (efx->type->sriov_fini)
3110 efx->type->sriov_fini(efx);
3111
Ben Hutchings8ceee662008-04-27 12:55:59 +01003112 efx_unregister_netdev(efx);
3113
Ben Hutchings7dde5962008-12-12 22:09:38 -08003114 efx_mtd_remove(efx);
3115
Ben Hutchings8ceee662008-04-27 12:55:59 +01003116 efx_pci_remove_main(efx);
3117
Ben Hutchings8ceee662008-04-27 12:55:59 +01003118 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00003119 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003120
Ben Hutchings8ceee662008-04-27 12:55:59 +01003121 efx_fini_struct(efx);
3122 free_netdev(efx->net_dev);
Alexandre Rames626950d2013-01-14 17:20:22 +00003123
3124 pci_disable_pcie_error_reporting(pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003125};
3126
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003127/* NIC VPD information
3128 * Called during probe to display the part number of the
3129 * installed NIC. VPD is potentially very large but this should
3130 * always appear within the first 512 bytes.
3131 */
3132#define SFC_VPD_LEN 512
Ben Hutchingsef215e62013-12-05 20:13:22 +00003133static void efx_probe_vpd_strings(struct efx_nic *efx)
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003134{
3135 struct pci_dev *dev = efx->pci_dev;
3136 char vpd_data[SFC_VPD_LEN];
3137 ssize_t vpd_size;
Ben Hutchingsef215e62013-12-05 20:13:22 +00003138 int ro_start, ro_size, i, j;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003139
3140 /* Get the vpd data from the device */
3141 vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
3142 if (vpd_size <= 0) {
3143 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
3144 return;
3145 }
3146
3147 /* Get the Read only section */
Ben Hutchingsef215e62013-12-05 20:13:22 +00003148 ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
3149 if (ro_start < 0) {
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003150 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
3151 return;
3152 }
3153
Ben Hutchingsef215e62013-12-05 20:13:22 +00003154 ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
3155 j = ro_size;
3156 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003157 if (i + j > vpd_size)
3158 j = vpd_size - i;
3159
3160 /* Get the Part number */
3161 i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
3162 if (i < 0) {
3163 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
3164 return;
3165 }
3166
3167 j = pci_vpd_info_field_size(&vpd_data[i]);
3168 i += PCI_VPD_INFO_FLD_HDR_SIZE;
3169 if (i + j > vpd_size) {
3170 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
3171 return;
3172 }
3173
3174 netif_info(efx, drv, efx->net_dev,
3175 "Part Number : %.*s\n", j, &vpd_data[i]);
Ben Hutchingsef215e62013-12-05 20:13:22 +00003176
3177 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
3178 j = ro_size;
3179 i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
3180 if (i < 0) {
3181 netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
3182 return;
3183 }
3184
3185 j = pci_vpd_info_field_size(&vpd_data[i]);
3186 i += PCI_VPD_INFO_FLD_HDR_SIZE;
3187 if (i + j > vpd_size) {
3188 netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
3189 return;
3190 }
3191
3192 efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
3193 if (!efx->vpd_sn)
3194 return;
3195
3196 snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003197}
3198
3199
Ben Hutchings8ceee662008-04-27 12:55:59 +01003200/* Main body of NIC initialisation
3201 * This is called at module load (or hotplug insertion, theoretically).
3202 */
3203static int efx_pci_probe_main(struct efx_nic *efx)
3204{
3205 int rc;
3206
3207 /* Do start-of-day initialisation */
3208 rc = efx_probe_all(efx);
3209 if (rc)
3210 goto fail1;
3211
Ben Hutchingse8f14992010-12-07 19:47:34 +00003212 efx_init_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003213
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003214 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003215 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00003216 netif_err(efx, probe, efx->net_dev,
3217 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00003218 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003219 }
3220
3221 rc = efx_init_port(efx);
3222 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00003223 netif_err(efx, probe, efx->net_dev,
3224 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00003225 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003226 }
3227
Ben Hutchings152b6a62009-11-29 03:43:56 +00003228 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003229 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00003230 goto fail5;
Jon Cooper261e4d92013-04-15 18:51:54 +01003231 rc = efx_enable_interrupts(efx);
3232 if (rc)
3233 goto fail6;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003234
3235 return 0;
3236
Jon Cooper261e4d92013-04-15 18:51:54 +01003237 fail6:
3238 efx_nic_fini_interrupt(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +00003239 fail5:
Ben Hutchings8ceee662008-04-27 12:55:59 +01003240 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003241 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003242 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003243 fail3:
3244 efx_fini_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003245 efx_remove_all(efx);
3246 fail1:
3247 return rc;
3248}
3249
Jon Cooper8a531402017-02-08 16:51:18 +00003250static int efx_pci_probe_post_io(struct efx_nic *efx)
3251{
3252 struct net_device *net_dev = efx->net_dev;
3253 int rc = efx_pci_probe_main(efx);
3254
3255 if (rc)
3256 return rc;
3257
3258 if (efx->type->sriov_init) {
3259 rc = efx->type->sriov_init(efx);
3260 if (rc)
3261 netif_err(efx, probe, efx->net_dev,
3262 "SR-IOV can't be enabled rc %d\n", rc);
3263 }
3264
3265 /* Determine netdevice features */
3266 net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
Edward Cree69787292017-10-31 14:29:47 +00003267 NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
Jon Cooper8a531402017-02-08 16:51:18 +00003268 if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
3269 net_dev->features |= NETIF_F_TSO6;
3270 /* Check whether device supports TSO */
3271 if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
3272 net_dev->features &= ~NETIF_F_ALL_TSO;
3273 /* Mask for features that also apply to VLAN devices */
3274 net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
3275 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
3276 NETIF_F_RXCSUM);
3277
Edward Cree69787292017-10-31 14:29:47 +00003278 net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
3279
3280 /* Disable receiving frames with bad FCS, by default. */
3281 net_dev->features &= ~NETIF_F_RXALL;
Jon Cooper8a531402017-02-08 16:51:18 +00003282
3283 /* Disable VLAN filtering by default. It may be enforced if
3284 * the feature is fixed (i.e. VLAN filters are required to
3285 * receive VLAN tagged packets due to vPort restrictions).
3286 */
3287 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
3288 net_dev->features |= efx->fixed_features;
3289
3290 rc = efx_register_netdev(efx);
3291 if (!rc)
3292 return 0;
3293
3294 efx_pci_remove_main(efx);
3295 return rc;
3296}
3297
Ben Hutchings8ceee662008-04-27 12:55:59 +01003298/* NIC initialisation
3299 *
3300 * This is called at module load (or hotplug insertion,
Ben Hutchings73ba7b62012-01-09 19:47:08 +00003301 * theoretically). It sets up PCI mappings, resets the NIC,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003302 * sets up and registers the network devices with the kernel and hooks
3303 * the interrupt service routine. It does not prepare the device for
3304 * transmission; this is left to the first time one of the network
3305 * interfaces is brought up (i.e. efx_net_open).
3306 */
Bill Pemberton87d1fc12012-12-03 09:23:32 -05003307static int efx_pci_probe(struct pci_dev *pci_dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003308 const struct pci_device_id *entry)
Ben Hutchings8ceee662008-04-27 12:55:59 +01003309{
Ben Hutchings8ceee662008-04-27 12:55:59 +01003310 struct net_device *net_dev;
3311 struct efx_nic *efx;
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003312 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003313
3314 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchings94b274b2011-01-10 21:18:20 +00003315 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
3316 EFX_MAX_RX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003317 if (!net_dev)
3318 return -ENOMEM;
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01003319 efx = netdev_priv(net_dev);
3320 efx->type = (const struct efx_nic_type *) entry->driver_data;
Andrew Rybchenkoebfcd0f2016-06-15 17:43:20 +01003321 efx->fixed_features |= NETIF_F_HIGHDMA;
Andrew Rybchenkoeb7cfd82016-06-15 17:51:36 +01003322
Ben Hutchings8ceee662008-04-27 12:55:59 +01003323 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00003324 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01003325 rc = efx_init_struct(efx, pci_dev, net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003326 if (rc)
3327 goto fail1;
3328
Ben Hutchings62776d02010-06-23 11:30:07 +00003329 netif_info(efx, probe, efx->net_dev,
Ben Hutchingsff79c8a2011-07-13 16:21:24 +01003330 "Solarflare NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003331
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01003332 if (!efx->type->is_vf)
3333 efx_probe_vpd_strings(efx);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003334
Ben Hutchings8ceee662008-04-27 12:55:59 +01003335 /* Set up basic I/O (BAR mappings etc) */
3336 rc = efx_init_io(efx);
3337 if (rc)
3338 goto fail2;
3339
Jon Cooper8a531402017-02-08 16:51:18 +00003340 rc = efx_pci_probe_post_io(efx);
3341 if (rc) {
3342 /* On failure, retry once immediately.
3343 * If we aborted probe due to a scheduled reset, dismiss it.
3344 */
3345 efx->reset_pending = 0;
3346 rc = efx_pci_probe_post_io(efx);
3347 if (rc) {
3348 /* On another failure, retry once more
3349 * after a 50-305ms delay.
3350 */
3351 unsigned char r;
3352
3353 get_random_bytes(&r, 1);
3354 msleep((unsigned int)r + 50);
3355 efx->reset_pending = 0;
3356 rc = efx_pci_probe_post_io(efx);
3357 }
3358 }
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003359 if (rc)
3360 goto fail3;
Steve Hodgsonfa402b22008-12-12 22:08:16 -08003361
Ben Hutchings62776d02010-06-23 11:30:07 +00003362 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003363
Ben Hutchings7c431612012-01-27 17:23:58 +00003364 /* Try to create MTDs, but allow this to fail */
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003365 rtnl_lock();
Ben Hutchings7c431612012-01-27 17:23:58 +00003366 rc = efx_mtd_probe(efx);
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003367 rtnl_unlock();
Bert Kenward09a04202015-12-23 08:58:15 +00003368 if (rc && rc != -EPERM)
Ben Hutchings7c431612012-01-27 17:23:58 +00003369 netif_warn(efx, probe, efx->net_dev,
3370 "failed to create MTDs (%d)\n", rc);
3371
Alexandre Rames626950d2013-01-14 17:20:22 +00003372 rc = pci_enable_pcie_error_reporting(pci_dev);
3373 if (rc && rc != -EINVAL)
Bert Kenward09a04202015-12-23 08:58:15 +00003374 netif_notice(efx, probe, efx->net_dev,
3375 "PCIE error reporting unavailable (%d).\n",
3376 rc);
Alexandre Rames626950d2013-01-14 17:20:22 +00003377
Jon Coopere5fbd972017-02-08 16:52:10 +00003378 if (efx->type->udp_tnl_push_ports)
3379 efx->type->udp_tnl_push_ports(efx);
3380
Ben Hutchings8ceee662008-04-27 12:55:59 +01003381 return 0;
3382
Ben Hutchings8ceee662008-04-27 12:55:59 +01003383 fail3:
3384 efx_fini_io(efx);
3385 fail2:
3386 efx_fini_struct(efx);
3387 fail1:
Steve Hodgson5e2a9112010-02-12 12:32:27 -08003388 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00003389 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003390 free_netdev(net_dev);
3391 return rc;
3392}
3393
Shradha Shah834e23d2015-05-06 00:55:58 +01003394/* efx_pci_sriov_configure returns the actual number of Virtual Functions
3395 * enabled on success
3396 */
3397#ifdef CONFIG_SFC_SRIOV
3398static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
3399{
3400 int rc;
3401 struct efx_nic *efx = pci_get_drvdata(dev);
3402
3403 if (efx->type->sriov_configure) {
3404 rc = efx->type->sriov_configure(efx, num_vfs);
3405 if (rc)
3406 return rc;
3407 else
3408 return num_vfs;
3409 } else
3410 return -EOPNOTSUPP;
3411}
3412#endif
3413
Ben Hutchings89c758f2009-11-29 03:43:07 +00003414static int efx_pm_freeze(struct device *dev)
3415{
3416 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3417
Ben Hutchings61da0262012-07-27 19:35:39 +01003418 rtnl_lock();
3419
Ben Hutchings6032fb52012-07-27 19:35:47 +01003420 if (efx->state != STATE_DISABLED) {
3421 efx->state = STATE_UNINIT;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003422
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01003423 efx_device_detach_sync(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003424
Ben Hutchings6032fb52012-07-27 19:35:47 +01003425 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003426 efx_disable_interrupts(efx);
Ben Hutchings6032fb52012-07-27 19:35:47 +01003427 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003428
Ben Hutchings61da0262012-07-27 19:35:39 +01003429 rtnl_unlock();
3430
Ben Hutchings89c758f2009-11-29 03:43:07 +00003431 return 0;
3432}
3433
3434static int efx_pm_thaw(struct device *dev)
3435{
Jon Cooper261e4d92013-04-15 18:51:54 +01003436 int rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003437 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3438
Ben Hutchings61da0262012-07-27 19:35:39 +01003439 rtnl_lock();
3440
Ben Hutchings6032fb52012-07-27 19:35:47 +01003441 if (efx->state != STATE_DISABLED) {
Jon Cooper261e4d92013-04-15 18:51:54 +01003442 rc = efx_enable_interrupts(efx);
3443 if (rc)
3444 goto fail;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003445
Ben Hutchings6032fb52012-07-27 19:35:47 +01003446 mutex_lock(&efx->mac_lock);
3447 efx->phy_op->reconfigure(efx);
3448 mutex_unlock(&efx->mac_lock);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003449
Ben Hutchings6032fb52012-07-27 19:35:47 +01003450 efx_start_all(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003451
Peter Dunning9c568fd2017-02-17 15:50:43 +00003452 efx_device_attach_if_not_resetting(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003453
Ben Hutchings6032fb52012-07-27 19:35:47 +01003454 efx->state = STATE_READY;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003455
Ben Hutchings6032fb52012-07-27 19:35:47 +01003456 efx->type->resume_wol(efx);
3457 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003458
Ben Hutchings61da0262012-07-27 19:35:39 +01003459 rtnl_unlock();
3460
Steve Hodgson319ba642010-06-01 11:17:24 +00003461 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
3462 queue_work(reset_workqueue, &efx->reset_work);
3463
Ben Hutchings89c758f2009-11-29 03:43:07 +00003464 return 0;
Jon Cooper261e4d92013-04-15 18:51:54 +01003465
3466fail:
3467 rtnl_unlock();
3468
3469 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003470}
3471
3472static int efx_pm_poweroff(struct device *dev)
3473{
3474 struct pci_dev *pci_dev = to_pci_dev(dev);
3475 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3476
3477 efx->type->fini(efx);
3478
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01003479 efx->reset_pending = 0;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003480
3481 pci_save_state(pci_dev);
3482 return pci_set_power_state(pci_dev, PCI_D3hot);
3483}
3484
3485/* Used for both resume and restore */
3486static int efx_pm_resume(struct device *dev)
3487{
3488 struct pci_dev *pci_dev = to_pci_dev(dev);
3489 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3490 int rc;
3491
3492 rc = pci_set_power_state(pci_dev, PCI_D0);
3493 if (rc)
3494 return rc;
3495 pci_restore_state(pci_dev);
3496 rc = pci_enable_device(pci_dev);
3497 if (rc)
3498 return rc;
3499 pci_set_master(efx->pci_dev);
3500 rc = efx->type->reset(efx, RESET_TYPE_ALL);
3501 if (rc)
3502 return rc;
3503 rc = efx->type->init(efx);
3504 if (rc)
3505 return rc;
Jon Cooper261e4d92013-04-15 18:51:54 +01003506 rc = efx_pm_thaw(dev);
3507 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003508}
3509
3510static int efx_pm_suspend(struct device *dev)
3511{
3512 int rc;
3513
3514 efx_pm_freeze(dev);
3515 rc = efx_pm_poweroff(dev);
3516 if (rc)
3517 efx_pm_resume(dev);
3518 return rc;
3519}
3520
Ben Hutchings18e83e42012-01-05 19:05:20 +00003521static const struct dev_pm_ops efx_pm_ops = {
Ben Hutchings89c758f2009-11-29 03:43:07 +00003522 .suspend = efx_pm_suspend,
3523 .resume = efx_pm_resume,
3524 .freeze = efx_pm_freeze,
3525 .thaw = efx_pm_thaw,
3526 .poweroff = efx_pm_poweroff,
3527 .restore = efx_pm_resume,
3528};
3529
Alexandre Rames626950d2013-01-14 17:20:22 +00003530/* A PCI error affecting this device was detected.
3531 * At this point MMIO and DMA may be disabled.
3532 * Stop the software path and request a slot reset.
3533 */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003534static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
3535 enum pci_channel_state state)
Alexandre Rames626950d2013-01-14 17:20:22 +00003536{
3537 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3538 struct efx_nic *efx = pci_get_drvdata(pdev);
3539
3540 if (state == pci_channel_io_perm_failure)
3541 return PCI_ERS_RESULT_DISCONNECT;
3542
3543 rtnl_lock();
3544
3545 if (efx->state != STATE_DISABLED) {
3546 efx->state = STATE_RECOVERY;
3547 efx->reset_pending = 0;
3548
3549 efx_device_detach_sync(efx);
3550
3551 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003552 efx_disable_interrupts(efx);
Alexandre Rames626950d2013-01-14 17:20:22 +00003553
3554 status = PCI_ERS_RESULT_NEED_RESET;
3555 } else {
3556 /* If the interface is disabled we don't want to do anything
3557 * with it.
3558 */
3559 status = PCI_ERS_RESULT_RECOVERED;
3560 }
3561
3562 rtnl_unlock();
3563
3564 pci_disable_device(pdev);
3565
3566 return status;
3567}
3568
Joe Perchesdbedd442015-03-06 20:49:12 -08003569/* Fake a successful reset, which will be performed later in efx_io_resume. */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003570static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
Alexandre Rames626950d2013-01-14 17:20:22 +00003571{
3572 struct efx_nic *efx = pci_get_drvdata(pdev);
3573 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3574 int rc;
3575
3576 if (pci_enable_device(pdev)) {
3577 netif_err(efx, hw, efx->net_dev,
3578 "Cannot re-enable PCI device after reset.\n");
3579 status = PCI_ERS_RESULT_DISCONNECT;
3580 }
3581
3582 rc = pci_cleanup_aer_uncorrect_error_status(pdev);
3583 if (rc) {
3584 netif_err(efx, hw, efx->net_dev,
3585 "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
3586 /* Non-fatal error. Continue. */
3587 }
3588
3589 return status;
3590}
3591
3592/* Perform the actual reset and resume I/O operations. */
3593static void efx_io_resume(struct pci_dev *pdev)
3594{
3595 struct efx_nic *efx = pci_get_drvdata(pdev);
3596 int rc;
3597
3598 rtnl_lock();
3599
3600 if (efx->state == STATE_DISABLED)
3601 goto out;
3602
3603 rc = efx_reset(efx, RESET_TYPE_ALL);
3604 if (rc) {
3605 netif_err(efx, hw, efx->net_dev,
3606 "efx_reset failed after PCI error (%d)\n", rc);
3607 } else {
3608 efx->state = STATE_READY;
3609 netif_dbg(efx, hw, efx->net_dev,
3610 "Done resetting and resuming IO after PCI error.\n");
3611 }
3612
3613out:
3614 rtnl_unlock();
3615}
3616
3617/* For simplicity and reliability, we always require a slot reset and try to
3618 * reset the hardware when a pci error affecting the device is detected.
3619 * We leave both the link_reset and mmio_enabled callback unimplemented:
3620 * with our request for slot reset the mmio_enabled callback will never be
3621 * called, and the link_reset callback is not used by AER or EEH mechanisms.
3622 */
Julia Lawallc300366b2015-11-14 11:06:57 +01003623static const struct pci_error_handlers efx_err_handlers = {
Alexandre Rames626950d2013-01-14 17:20:22 +00003624 .error_detected = efx_io_error_detected,
3625 .slot_reset = efx_io_slot_reset,
3626 .resume = efx_io_resume,
3627};
3628
Ben Hutchings8ceee662008-04-27 12:55:59 +01003629static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00003630 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003631 .id_table = efx_pci_table,
3632 .probe = efx_pci_probe,
3633 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00003634 .driver.pm = &efx_pm_ops,
Alexandre Rames626950d2013-01-14 17:20:22 +00003635 .err_handler = &efx_err_handlers,
Shradha Shah834e23d2015-05-06 00:55:58 +01003636#ifdef CONFIG_SFC_SRIOV
3637 .sriov_configure = efx_pci_sriov_configure,
3638#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003639};
3640
3641/**************************************************************************
3642 *
3643 * Kernel module interface
3644 *
3645 *************************************************************************/
3646
3647module_param(interrupt_mode, uint, 0444);
3648MODULE_PARM_DESC(interrupt_mode,
3649 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3650
3651static int __init efx_init_module(void)
3652{
3653 int rc;
3654
3655 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
3656
3657 rc = register_netdevice_notifier(&efx_netdev_notifier);
3658 if (rc)
3659 goto err_notifier;
3660
Shradha Shah7fa8d542015-05-06 00:55:13 +01003661#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003662 rc = efx_init_sriov();
3663 if (rc)
3664 goto err_sriov;
Shradha Shah7fa8d542015-05-06 00:55:13 +01003665#endif
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003666
Steve Hodgson1ab00622008-12-12 21:33:02 -08003667 reset_workqueue = create_singlethread_workqueue("sfc_reset");
3668 if (!reset_workqueue) {
3669 rc = -ENOMEM;
3670 goto err_reset;
3671 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003672
3673 rc = pci_register_driver(&efx_pci_driver);
3674 if (rc < 0)
3675 goto err_pci;
3676
3677 return 0;
3678
3679 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08003680 destroy_workqueue(reset_workqueue);
3681 err_reset:
Shradha Shah7fa8d542015-05-06 00:55:13 +01003682#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003683 efx_fini_sriov();
3684 err_sriov:
Shradha Shah7fa8d542015-05-06 00:55:13 +01003685#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003686 unregister_netdevice_notifier(&efx_netdev_notifier);
3687 err_notifier:
3688 return rc;
3689}
3690
3691static void __exit efx_exit_module(void)
3692{
3693 printk(KERN_INFO "Solarflare NET driver unloading\n");
3694
3695 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08003696 destroy_workqueue(reset_workqueue);
Shradha Shah7fa8d542015-05-06 00:55:13 +01003697#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003698 efx_fini_sriov();
Shradha Shah7fa8d542015-05-06 00:55:13 +01003699#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003700 unregister_netdevice_notifier(&efx_netdev_notifier);
3701
3702}
3703
3704module_init(efx_init_module);
3705module_exit(efx_exit_module);
3706
Ben Hutchings906bb262009-11-29 15:16:19 +00003707MODULE_AUTHOR("Solarflare Communications and "
3708 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings6a350fd2014-02-12 19:00:07 +00003709MODULE_DESCRIPTION("Solarflare network driver");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003710MODULE_LICENSE("GPL");
3711MODULE_DEVICE_TABLE(pci, efx_pci_table);
Edward Cree14077e92017-01-03 15:46:00 +00003712MODULE_VERSION(EFX_DRIVER_VERSION);