blob: 16757cfc5b29258c8331d1f6238b064fabedc3a1 [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 Hutchings14bf718fb2012-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
kbuild test robote7345ba2018-01-26 17:00:39 +0000899static bool efx_default_channel_want_txqs(struct efx_channel *channel)
Edward Cree2935e3c2018-01-25 17:26:06 +0000900{
901 return channel->channel - channel->efx->tx_channel_offset <
902 channel->efx->n_tx_channels;
903}
904
Ben Hutchings7f967c02012-02-13 23:45:02 +0000905static const struct efx_channel_type efx_default_channel_type = {
906 .pre_probe = efx_channel_dummy_op_int,
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100907 .post_remove = efx_channel_dummy_op_void,
Ben Hutchings7f967c02012-02-13 23:45:02 +0000908 .get_name = efx_get_channel_name,
909 .copy = efx_copy_channel,
Edward Cree2935e3c2018-01-25 17:26:06 +0000910 .want_txqs = efx_default_channel_want_txqs,
Ben Hutchings7f967c02012-02-13 23:45:02 +0000911 .keep_eventq = false,
Edward Cree2935e3c2018-01-25 17:26:06 +0000912 .want_pio = true,
Ben Hutchings7f967c02012-02-13 23:45:02 +0000913};
914
915int efx_channel_dummy_op_int(struct efx_channel *channel)
916{
917 return 0;
918}
919
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100920void efx_channel_dummy_op_void(struct efx_channel *channel)
921{
922}
923
Ben Hutchings8ceee662008-04-27 12:55:59 +0100924/**************************************************************************
925 *
926 * Port handling
927 *
928 **************************************************************************/
929
930/* This ensures that the kernel is kept informed (via
931 * netif_carrier_on/off) of the link status, and also maintains the
932 * link status's stop on the port's TX queue.
933 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000934void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100935{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000936 struct efx_link_state *link_state = &efx->link_state;
937
Ben Hutchings8ceee662008-04-27 12:55:59 +0100938 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
939 * that no events are triggered between unregister_netdev() and the
940 * driver unloading. A more general condition is that NETDEV_CHANGE
941 * can only be generated between NETDEV_UP and NETDEV_DOWN */
942 if (!netif_running(efx->net_dev))
943 return;
944
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000945 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100946 efx->n_link_state_changes++;
947
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000948 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100949 netif_carrier_on(efx->net_dev);
950 else
951 netif_carrier_off(efx->net_dev);
952 }
953
954 /* Status message for kernel log */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000955 if (link_state->up)
Ben Hutchings62776d02010-06-23 11:30:07 +0000956 netif_info(efx, link, efx->net_dev,
Ben Hutchings964e6132012-11-19 23:08:22 +0000957 "link up at %uMbps %s-duplex (MTU %d)\n",
Ben Hutchings62776d02010-06-23 11:30:07 +0000958 link_state->speed, link_state->fd ? "full" : "half",
Ben Hutchings964e6132012-11-19 23:08:22 +0000959 efx->net_dev->mtu);
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000960 else
Ben Hutchings62776d02010-06-23 11:30:07 +0000961 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100962}
963
Edward Creec2ab85d2018-01-10 18:00:14 +0000964void efx_link_set_advertising(struct efx_nic *efx,
965 const unsigned long *advertising)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000966{
Edward Creec2ab85d2018-01-10 18:00:14 +0000967 memcpy(efx->link_advertising, advertising,
968 sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
969
970 efx->link_advertising[0] |= ADVERTISED_Autoneg;
971 if (advertising[0] & ADVERTISED_Pause)
972 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
973 else
974 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
975 if (advertising[0] & ADVERTISED_Asym_Pause)
976 efx->wanted_fc ^= EFX_FC_TX;
977}
978
979/* Equivalent to efx_link_set_advertising with all-zeroes, except does not
980 * force the Autoneg bit on.
981 */
982void efx_link_clear_advertising(struct efx_nic *efx)
983{
984 bitmap_zero(efx->link_advertising, __ETHTOOL_LINK_MODE_MASK_NBITS);
985 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000986}
987
David S. Millerb56269462011-05-17 17:53:22 -0400988void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000989{
990 efx->wanted_fc = wanted_fc;
Edward Creec2ab85d2018-01-10 18:00:14 +0000991 if (efx->link_advertising[0]) {
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000992 if (wanted_fc & EFX_FC_RX)
Edward Creec2ab85d2018-01-10 18:00:14 +0000993 efx->link_advertising[0] |= (ADVERTISED_Pause |
994 ADVERTISED_Asym_Pause);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000995 else
Edward Creec2ab85d2018-01-10 18:00:14 +0000996 efx->link_advertising[0] &= ~(ADVERTISED_Pause |
997 ADVERTISED_Asym_Pause);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000998 if (wanted_fc & EFX_FC_TX)
Edward Creec2ab85d2018-01-10 18:00:14 +0000999 efx->link_advertising[0] ^= ADVERTISED_Asym_Pause;
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001000 }
1001}
1002
Ben Hutchings115122a2009-03-04 09:52:52 +00001003static void efx_fini_port(struct efx_nic *efx);
1004
Edward Cree0d322412015-05-20 11:10:03 +01001005/* We assume that efx->type->reconfigure_mac will always try to sync RX
1006 * filters and therefore needs to read-lock the filter table against freeing
1007 */
1008void efx_mac_reconfigure(struct efx_nic *efx)
1009{
1010 down_read(&efx->filter_sem);
1011 efx->type->reconfigure_mac(efx);
1012 up_read(&efx->filter_sem);
1013}
1014
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001015/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
1016 * the MAC appropriately. All other PHY configuration changes are pushed
1017 * through phy_op->set_settings(), and pushed asynchronously to the MAC
1018 * through efx_monitor().
1019 *
1020 * Callers must hold the mac_lock
1021 */
1022int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001023{
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001024 enum efx_phy_mode phy_mode;
1025 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001026
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001027 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +01001028
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001029 /* Disable PHY transmit in mac level loopbacks */
1030 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001031 if (LOOPBACK_INTERNAL(efx))
1032 efx->phy_mode |= PHY_MODE_TX_DISABLED;
1033 else
1034 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001035
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001036 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001037
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001038 if (rc)
1039 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001040
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001041 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001042}
1043
1044/* Reinitialise the MAC to pick up new PHY settings, even if the port is
1045 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001046int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001047{
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001048 int rc;
1049
Ben Hutchings8ceee662008-04-27 12:55:59 +01001050 EFX_ASSERT_RESET_SERIALISED(efx);
1051
1052 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001053 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001054 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001055
1056 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001057}
1058
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001059/* Asynchronous work item for changing MAC promiscuity and multicast
1060 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
1061 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001062static void efx_mac_work(struct work_struct *data)
1063{
1064 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
1065
1066 mutex_lock(&efx->mac_lock);
Ben Hutchings30b81cd2011-09-13 19:47:48 +01001067 if (efx->port_enabled)
Edward Cree0d322412015-05-20 11:10:03 +01001068 efx_mac_reconfigure(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001069 mutex_unlock(&efx->mac_lock);
1070}
1071
Ben Hutchings8ceee662008-04-27 12:55:59 +01001072static int efx_probe_port(struct efx_nic *efx)
1073{
1074 int rc;
1075
Ben Hutchings62776d02010-06-23 11:30:07 +00001076 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001077
Steve Hodgsonff3b00a2009-12-23 13:46:36 +00001078 if (phy_flash_cfg)
1079 efx->phy_mode = PHY_MODE_SPECIAL;
1080
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001081 /* Connect up MAC/PHY operations table */
1082 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001083 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +00001084 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001085
Ben Hutchingse332bcb2011-12-20 01:22:51 +00001086 /* Initialise MAC address to permanent address */
Edward Creecd84ff42014-03-07 18:27:41 +00001087 ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001088
1089 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090}
1091
1092static int efx_init_port(struct efx_nic *efx)
1093{
1094 int rc;
1095
Ben Hutchings62776d02010-06-23 11:30:07 +00001096 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001097
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001098 mutex_lock(&efx->mac_lock);
1099
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001100 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001101 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001102 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001103
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001104 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001105
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001106 /* Reconfigure the MAC before creating dma queues (required for
1107 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
Edward Cree0d322412015-05-20 11:10:03 +01001108 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001109
1110 /* Ensure the PHY advertises the correct flow control settings */
1111 rc = efx->phy_op->reconfigure(efx);
Edward Cree267d9d72015-05-06 00:59:18 +01001112 if (rc && rc != -EPERM)
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001113 goto fail2;
1114
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001115 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001116 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001117
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001118fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001119 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001120fail1:
1121 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001122 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001123}
1124
Ben Hutchings8ceee662008-04-27 12:55:59 +01001125static void efx_start_port(struct efx_nic *efx)
1126{
Ben Hutchings62776d02010-06-23 11:30:07 +00001127 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001128 BUG_ON(efx->port_enabled);
1129
1130 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001131 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001132
Ben Hutchingsd615c032013-10-08 17:33:20 +01001133 /* Ensure MAC ingress/egress is enabled */
Edward Cree0d322412015-05-20 11:10:03 +01001134 efx_mac_reconfigure(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001135
Ben Hutchings8ceee662008-04-27 12:55:59 +01001136 mutex_unlock(&efx->mac_lock);
1137}
1138
Ben Hutchingsd615c032013-10-08 17:33:20 +01001139/* Cancel work for MAC reconfiguration, periodic hardware monitoring
1140 * and the async self-test, wait for them to finish and prevent them
1141 * being scheduled again. This doesn't cover online resets, which
1142 * should only be cancelled when removing the device.
1143 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001144static void efx_stop_port(struct efx_nic *efx)
1145{
Ben Hutchings62776d02010-06-23 11:30:07 +00001146 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001147
Ben Hutchingsd615c032013-10-08 17:33:20 +01001148 EFX_ASSERT_RESET_SERIALISED(efx);
1149
Ben Hutchings8ceee662008-04-27 12:55:59 +01001150 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001151 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001152 mutex_unlock(&efx->mac_lock);
1153
1154 /* Serialise against efx_set_multicast_list() */
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001155 netif_addr_lock_bh(efx->net_dev);
1156 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchingsd615c032013-10-08 17:33:20 +01001157
1158 cancel_delayed_work_sync(&efx->monitor_work);
1159 efx_selftest_async_cancel(efx);
1160 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001161}
1162
1163static void efx_fini_port(struct efx_nic *efx)
1164{
Ben Hutchings62776d02010-06-23 11:30:07 +00001165 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001166
1167 if (!efx->port_initialized)
1168 return;
1169
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001170 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001171 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001172
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001173 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001174 efx_link_status_changed(efx);
1175}
1176
1177static void efx_remove_port(struct efx_nic *efx)
1178{
Ben Hutchings62776d02010-06-23 11:30:07 +00001179 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001180
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001181 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001182}
1183
1184/**************************************************************************
1185 *
1186 * NIC handling
1187 *
1188 **************************************************************************/
1189
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01001190static LIST_HEAD(efx_primary_list);
1191static LIST_HEAD(efx_unassociated_list);
1192
1193static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
1194{
1195 return left->type == right->type &&
1196 left->vpd_sn && right->vpd_sn &&
1197 !strcmp(left->vpd_sn, right->vpd_sn);
1198}
1199
1200static void efx_associate(struct efx_nic *efx)
1201{
1202 struct efx_nic *other, *next;
1203
1204 if (efx->primary == efx) {
1205 /* Adding primary function; look for secondaries */
1206
1207 netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
1208 list_add_tail(&efx->node, &efx_primary_list);
1209
1210 list_for_each_entry_safe(other, next, &efx_unassociated_list,
1211 node) {
1212 if (efx_same_controller(efx, other)) {
1213 list_del(&other->node);
1214 netif_dbg(other, probe, other->net_dev,
1215 "moving to secondary list of %s %s\n",
1216 pci_name(efx->pci_dev),
1217 efx->net_dev->name);
1218 list_add_tail(&other->node,
1219 &efx->secondary_list);
1220 other->primary = efx;
1221 }
1222 }
1223 } else {
1224 /* Adding secondary function; look for primary */
1225
1226 list_for_each_entry(other, &efx_primary_list, node) {
1227 if (efx_same_controller(efx, other)) {
1228 netif_dbg(efx, probe, efx->net_dev,
1229 "adding to secondary list of %s %s\n",
1230 pci_name(other->pci_dev),
1231 other->net_dev->name);
1232 list_add_tail(&efx->node,
1233 &other->secondary_list);
1234 efx->primary = other;
1235 return;
1236 }
1237 }
1238
1239 netif_dbg(efx, probe, efx->net_dev,
1240 "adding to unassociated list\n");
1241 list_add_tail(&efx->node, &efx_unassociated_list);
1242 }
1243}
1244
1245static void efx_dissociate(struct efx_nic *efx)
1246{
1247 struct efx_nic *other, *next;
1248
1249 list_del(&efx->node);
1250 efx->primary = NULL;
1251
1252 list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
1253 list_del(&other->node);
1254 netif_dbg(other, probe, other->net_dev,
1255 "moving to unassociated list\n");
1256 list_add_tail(&other->node, &efx_unassociated_list);
1257 other->primary = NULL;
1258 }
1259}
1260
Ben Hutchings8ceee662008-04-27 12:55:59 +01001261/* This configures the PCI device to enable I/O and DMA. */
1262static int efx_init_io(struct efx_nic *efx)
1263{
1264 struct pci_dev *pci_dev = efx->pci_dev;
1265 dma_addr_t dma_mask = efx->type->max_dma_mask;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001266 unsigned int mem_map_size = efx->type->mem_map_size(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001267 int rc, bar;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001268
Ben Hutchings62776d02010-06-23 11:30:07 +00001269 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001270
Edward Cree03714bb2017-12-18 16:55:50 +00001271 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001272
Ben Hutchings8ceee662008-04-27 12:55:59 +01001273 rc = pci_enable_device(pci_dev);
1274 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001275 netif_err(efx, probe, efx->net_dev,
1276 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001277 goto fail1;
1278 }
1279
1280 pci_set_master(pci_dev);
1281
1282 /* Set the PCI DMA mask. Try all possibilities from our
1283 * genuine mask down to 32 bits, because some architectures
1284 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1285 * masks event though they reject 46 bit masks.
1286 */
1287 while (dma_mask > 0x7fffffffUL) {
Christoph Hellwig8722b8f2015-11-10 14:45:42 -08001288 rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
1289 if (rc == 0)
1290 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001291 dma_mask >>= 1;
1292 }
1293 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001294 netif_err(efx, probe, efx->net_dev,
1295 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001296 goto fail2;
1297 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001298 netif_dbg(efx, probe, efx->net_dev,
1299 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001300
Shradha Shah02246a72015-05-06 00:58:14 +01001301 efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
1302 rc = pci_request_region(pci_dev, bar, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001303 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001304 netif_err(efx, probe, efx->net_dev,
1305 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001306 rc = -EIO;
1307 goto fail3;
1308 }
Ben Hutchingsb1057982012-09-19 00:56:47 +01001309 efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001310 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001311 netif_err(efx, probe, efx->net_dev,
1312 "could not map memory BAR at %llx+%x\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001313 (unsigned long long)efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001314 rc = -ENOMEM;
1315 goto fail4;
1316 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001317 netif_dbg(efx, probe, efx->net_dev,
1318 "memory BAR at %llx+%x (virtual %p)\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001319 (unsigned long long)efx->membase_phys, mem_map_size,
1320 efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001321
1322 return 0;
1323
1324 fail4:
Shradha Shah02246a72015-05-06 00:58:14 +01001325 pci_release_region(efx->pci_dev, bar);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001326 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001327 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001328 fail2:
1329 pci_disable_device(efx->pci_dev);
1330 fail1:
1331 return rc;
1332}
1333
1334static void efx_fini_io(struct efx_nic *efx)
1335{
Shradha Shah02246a72015-05-06 00:58:14 +01001336 int bar;
1337
Ben Hutchings62776d02010-06-23 11:30:07 +00001338 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001339
1340 if (efx->membase) {
1341 iounmap(efx->membase);
1342 efx->membase = NULL;
1343 }
1344
1345 if (efx->membase_phys) {
Edward Cree03714bb2017-12-18 16:55:50 +00001346 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +01001347 pci_release_region(efx->pci_dev, bar);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001348 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001349 }
1350
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001351 /* Don't disable bus-mastering if VFs are assigned */
1352 if (!pci_vfs_assigned(efx->pci_dev))
1353 pci_disable_device(efx->pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001354}
1355
Jon Cooper267c0152015-05-06 00:59:38 +01001356void efx_set_default_rx_indir_table(struct efx_nic *efx)
1357{
1358 size_t i;
1359
1360 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
1361 efx->rx_indir_table[i] =
1362 ethtool_rxfh_indir_default(i, efx->rss_spread);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001363}
1364
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001365static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
Ben Hutchings46123d02008-09-01 12:47:33 +01001366{
Ben Hutchingscdb08f82011-12-20 01:08:05 +00001367 cpumask_var_t thread_mask;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001368 unsigned int count;
Ben Hutchings46123d02008-09-01 12:47:33 +01001369 int cpu;
1370
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001371 if (rss_cpus) {
1372 count = rss_cpus;
1373 } else {
1374 if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1375 netif_warn(efx, probe, efx->net_dev,
1376 "RSS disabled due to allocation failure\n");
1377 return 1;
Ben Hutchings46123d02008-09-01 12:47:33 +01001378 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001379
1380 count = 0;
1381 for_each_online_cpu(cpu) {
1382 if (!cpumask_test_cpu(cpu, thread_mask)) {
1383 ++count;
1384 cpumask_or(thread_mask, thread_mask,
Bartosz Golaszewski06931e62015-05-26 15:11:28 +02001385 topology_sibling_cpumask(cpu));
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001386 }
1387 }
1388
1389 free_cpumask_var(thread_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001390 }
1391
Bert Kenward271a8b42017-04-12 17:06:52 +01001392 if (count > EFX_MAX_RX_QUEUES) {
1393 netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1394 "Reducing number of rx queues from %u to %u.\n",
1395 count, EFX_MAX_RX_QUEUES);
1396 count = EFX_MAX_RX_QUEUES;
1397 }
1398
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001399 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1400 * table entries that are inaccessible to VFs
1401 */
Shradha Shah7fa8d542015-05-06 00:55:13 +01001402#ifdef CONFIG_SFC_SRIOV
1403 if (efx->type->sriov_wanted) {
1404 if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
1405 count > efx_vf_size(efx)) {
1406 netif_warn(efx, probe, efx->net_dev,
1407 "Reducing number of RSS channels from %u to %u for "
1408 "VF support. Increase vf-msix-limit to use more "
1409 "channels on the PF.\n",
1410 count, efx_vf_size(efx));
1411 count = efx_vf_size(efx);
1412 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001413 }
Shradha Shah7fa8d542015-05-06 00:55:13 +01001414#endif
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001415
Ben Hutchings46123d02008-09-01 12:47:33 +01001416 return count;
1417}
1418
1419/* Probe the number and type of interrupts we are able to obtain, and
1420 * the resulting numbers of channels and RX queues.
1421 */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001422static int efx_probe_interrupts(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001423{
Ben Hutchings7f967c02012-02-13 23:45:02 +00001424 unsigned int extra_channels = 0;
1425 unsigned int i, j;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001426 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001427
Ben Hutchings7f967c02012-02-13 23:45:02 +00001428 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
1429 if (efx->extra_channel_type[i])
1430 ++extra_channels;
1431
Ben Hutchings8ceee662008-04-27 12:55:59 +01001432 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001433 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001434 unsigned int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001435
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001436 n_channels = efx_wanted_parallelism(efx);
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001437 if (efx_separate_tx_channels)
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001438 n_channels *= 2;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001439 n_channels += extra_channels;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001440 n_channels = min(n_channels, efx->max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001441
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001442 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001443 xentries[i].entry = i;
Alexander Gordeev184603d2014-02-18 11:12:00 +01001444 rc = pci_enable_msix_range(efx->pci_dev,
1445 xentries, 1, n_channels);
1446 if (rc < 0) {
1447 /* Fall back to single channel MSI */
Alexander Gordeev184603d2014-02-18 11:12:00 +01001448 netif_err(efx, drv, efx->net_dev,
1449 "could not enable MSI-X\n");
Andrew Rybchenko62980cb2017-02-13 14:59:04 +00001450 if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
1451 efx->interrupt_mode = EFX_INT_MODE_MSI;
1452 else
1453 return rc;
Alexander Gordeev184603d2014-02-18 11:12:00 +01001454 } else if (rc < n_channels) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001455 netif_err(efx, drv, efx->net_dev,
1456 "WARNING: Insufficient MSI-X vectors"
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001457 " available (%d < %u).\n", rc, n_channels);
Ben Hutchings62776d02010-06-23 11:30:07 +00001458 netif_err(efx, drv, efx->net_dev,
1459 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001460 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001461 }
1462
Alexander Gordeev184603d2014-02-18 11:12:00 +01001463 if (rc > 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001464 efx->n_channels = n_channels;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001465 if (n_channels > extra_channels)
1466 n_channels -= extra_channels;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001467 if (efx_separate_tx_channels) {
1468 efx->n_tx_channels = min(max(n_channels / 2,
1469 1U),
1470 efx->max_tx_channels);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001471 efx->n_rx_channels = max(n_channels -
1472 efx->n_tx_channels,
1473 1U);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001474 } else {
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001475 efx->n_tx_channels = min(n_channels,
1476 efx->max_tx_channels);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001477 efx->n_rx_channels = n_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001478 }
Ben Hutchings7f967c02012-02-13 23:45:02 +00001479 for (i = 0; i < efx->n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001480 efx_get_channel(efx, i)->irq =
1481 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001482 }
1483 }
1484
1485 /* Try single interrupt MSI */
1486 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001487 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001488 efx->n_rx_channels = 1;
1489 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001490 rc = pci_enable_msi(efx->pci_dev);
1491 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001492 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001493 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001494 netif_err(efx, drv, efx->net_dev,
1495 "could not enable MSI\n");
Andrew Rybchenko62980cb2017-02-13 14:59:04 +00001496 if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
1497 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1498 else
1499 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001500 }
1501 }
1502
1503 /* Assume legacy interrupts */
1504 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001505 efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001506 efx->n_rx_channels = 1;
1507 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001508 efx->legacy_irq = efx->pci_dev->irq;
1509 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001510
Ben Hutchings7f967c02012-02-13 23:45:02 +00001511 /* Assign extra channels if possible */
Edward Cree2935e3c2018-01-25 17:26:06 +00001512 efx->n_extra_tx_channels = 0;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001513 j = efx->n_channels;
1514 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
1515 if (!efx->extra_channel_type[i])
1516 continue;
1517 if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
1518 efx->n_channels <= extra_channels) {
1519 efx->extra_channel_type[i]->handle_no_channel(efx);
1520 } else {
1521 --j;
1522 efx_get_channel(efx, j)->type =
1523 efx->extra_channel_type[i];
Edward Cree2935e3c2018-01-25 17:26:06 +00001524 if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
1525 efx->n_extra_tx_channels++;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001526 }
1527 }
1528
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001529 /* RSS might be usable on VFs even if it is disabled on the PF */
Shradha Shah7fa8d542015-05-06 00:55:13 +01001530#ifdef CONFIG_SFC_SRIOV
1531 if (efx->type->sriov_wanted) {
1532 efx->rss_spread = ((efx->n_rx_channels > 1 ||
1533 !efx->type->sriov_wanted(efx)) ?
1534 efx->n_rx_channels : efx_vf_size(efx));
1535 return 0;
1536 }
1537#endif
1538 efx->rss_spread = efx->n_rx_channels;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001539
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001540 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001541}
1542
Jon Cooper261e4d92013-04-15 18:51:54 +01001543static int efx_soft_enable_interrupts(struct efx_nic *efx)
Ben Hutchingsd8291182012-10-05 23:35:41 +01001544{
Jon Cooper261e4d92013-04-15 18:51:54 +01001545 struct efx_channel *channel, *end_channel;
1546 int rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001547
1548 BUG_ON(efx->state == STATE_DISABLED);
1549
1550 efx->irq_soft_enabled = true;
1551 smp_wmb();
1552
1553 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001554 if (!channel->type->keep_eventq) {
1555 rc = efx_init_eventq(channel);
1556 if (rc)
1557 goto fail;
1558 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001559 efx_start_eventq(channel);
1560 }
1561
1562 efx_mcdi_mode_event(efx);
Jon Cooper261e4d92013-04-15 18:51:54 +01001563
1564 return 0;
1565fail:
1566 end_channel = channel;
1567 efx_for_each_channel(channel, efx) {
1568 if (channel == end_channel)
1569 break;
1570 efx_stop_eventq(channel);
1571 if (!channel->type->keep_eventq)
1572 efx_fini_eventq(channel);
1573 }
1574
1575 return rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001576}
1577
1578static void efx_soft_disable_interrupts(struct efx_nic *efx)
1579{
1580 struct efx_channel *channel;
1581
1582 if (efx->state == STATE_DISABLED)
1583 return;
1584
1585 efx_mcdi_mode_poll(efx);
1586
1587 efx->irq_soft_enabled = false;
1588 smp_wmb();
1589
1590 if (efx->legacy_irq)
1591 synchronize_irq(efx->legacy_irq);
1592
1593 efx_for_each_channel(channel, efx) {
1594 if (channel->irq)
1595 synchronize_irq(channel->irq);
1596
1597 efx_stop_eventq(channel);
1598 if (!channel->type->keep_eventq)
1599 efx_fini_eventq(channel);
1600 }
Ben Hutchingscade7152013-08-27 23:12:31 +01001601
1602 /* Flush the asynchronous MCDI request queue */
1603 efx_mcdi_flush_async(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01001604}
1605
Jon Cooper261e4d92013-04-15 18:51:54 +01001606static int efx_enable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001607{
Jon Cooper261e4d92013-04-15 18:51:54 +01001608 struct efx_channel *channel, *end_channel;
1609 int rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001610
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001611 BUG_ON(efx->state == STATE_DISABLED);
1612
Alexandre Ramesb28405b2013-03-21 16:41:43 +00001613 if (efx->eeh_disabled_legacy_irq) {
1614 enable_irq(efx->legacy_irq);
1615 efx->eeh_disabled_legacy_irq = false;
1616 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001617
Ben Hutchings86094f72013-08-21 19:51:04 +01001618 efx->type->irq_enable_master(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001619
1620 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001621 if (channel->type->keep_eventq) {
1622 rc = efx_init_eventq(channel);
1623 if (rc)
1624 goto fail;
1625 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001626 }
1627
Jon Cooper261e4d92013-04-15 18:51:54 +01001628 rc = efx_soft_enable_interrupts(efx);
1629 if (rc)
1630 goto fail;
1631
1632 return 0;
1633
1634fail:
1635 end_channel = channel;
1636 efx_for_each_channel(channel, efx) {
1637 if (channel == end_channel)
1638 break;
1639 if (channel->type->keep_eventq)
1640 efx_fini_eventq(channel);
1641 }
1642
1643 efx->type->irq_disable_non_ev(efx);
1644
1645 return rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001646}
1647
Ben Hutchingsd8291182012-10-05 23:35:41 +01001648static void efx_disable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001649{
1650 struct efx_channel *channel;
1651
Ben Hutchingsd8291182012-10-05 23:35:41 +01001652 efx_soft_disable_interrupts(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001653
1654 efx_for_each_channel(channel, efx) {
Ben Hutchingsd8291182012-10-05 23:35:41 +01001655 if (channel->type->keep_eventq)
Ben Hutchings7f967c02012-02-13 23:45:02 +00001656 efx_fini_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001657 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001658
Ben Hutchings86094f72013-08-21 19:51:04 +01001659 efx->type->irq_disable_non_ev(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001660}
1661
Ben Hutchings8ceee662008-04-27 12:55:59 +01001662static void efx_remove_interrupts(struct efx_nic *efx)
1663{
1664 struct efx_channel *channel;
1665
1666 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001667 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001668 channel->irq = 0;
1669 pci_disable_msi(efx->pci_dev);
1670 pci_disable_msix(efx->pci_dev);
1671
1672 /* Remove legacy interrupt */
1673 efx->legacy_irq = 0;
1674}
1675
Ben Hutchings8831da72008-09-01 12:47:48 +01001676static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001677{
Ben Hutchings602a5322011-05-16 17:32:39 +01001678 struct efx_channel *channel;
1679 struct efx_tx_queue *tx_queue;
1680
Ben Hutchings97653432011-01-12 18:26:56 +00001681 efx->tx_channel_offset =
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001682 efx_separate_tx_channels ?
1683 efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings602a5322011-05-16 17:32:39 +01001684
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001685 /* We need to mark which channels really have RX and TX
1686 * queues, and adjust the TX queue numbers if we have separate
Ben Hutchings602a5322011-05-16 17:32:39 +01001687 * RX-only and TX-only channels.
1688 */
1689 efx_for_each_channel(channel, efx) {
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001690 if (channel->channel < efx->n_rx_channels)
1691 channel->rx_queue.core_index = channel->channel;
1692 else
1693 channel->rx_queue.core_index = -1;
1694
Ben Hutchings602a5322011-05-16 17:32:39 +01001695 efx_for_each_channel_tx_queue(tx_queue, channel)
1696 tx_queue->queue -= (efx->tx_channel_offset *
1697 EFX_TXQ_TYPES);
1698 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001699}
1700
1701static int efx_probe_nic(struct efx_nic *efx)
1702{
1703 int rc;
1704
Ben Hutchings62776d02010-06-23 11:30:07 +00001705 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001706
1707 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001708 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001709 if (rc)
1710 return rc;
1711
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001712 do {
1713 if (!efx->max_channels || !efx->max_tx_channels) {
1714 netif_err(efx, drv, efx->net_dev,
1715 "Insufficient resources to allocate"
1716 " any channels\n");
1717 rc = -ENOSPC;
1718 goto fail1;
1719 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001720
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001721 /* Determine the number of channels and queues by trying
1722 * to hook in MSI-X interrupts.
1723 */
1724 rc = efx_probe_interrupts(efx);
1725 if (rc)
1726 goto fail1;
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001727
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001728 efx_set_channels(efx);
1729
1730 /* dimension_resources can fail with EAGAIN */
1731 rc = efx->type->dimension_resources(efx);
1732 if (rc != 0 && rc != -EAGAIN)
1733 goto fail2;
1734
1735 if (rc == -EAGAIN)
1736 /* try again with new max_channels */
1737 efx_remove_interrupts(efx);
1738
1739 } while (rc == -EAGAIN);
Ben Hutchings28e47c42012-02-15 01:58:49 +00001740
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001741 if (efx->n_channels > 1)
Jon Cooper267c0152015-05-06 00:59:38 +01001742 netdev_rss_key_fill(&efx->rx_hash_key,
1743 sizeof(efx->rx_hash_key));
1744 efx_set_default_rx_indir_table(efx);
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001745
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001746 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1747 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001748
1749 /* Initialise the interrupt moderation settings */
Bert Kenward539de7c2016-08-11 13:02:09 +01001750 efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
Ben Hutchings9e393b32011-09-05 07:43:04 +00001751 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1752 true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001753
1754 return 0;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001755
Ben Hutchingsc15eed22013-08-29 00:45:48 +01001756fail2:
1757 efx_remove_interrupts(efx);
1758fail1:
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001759 efx->type->remove(efx);
1760 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001761}
1762
1763static void efx_remove_nic(struct efx_nic *efx)
1764{
Ben Hutchings62776d02010-06-23 11:30:07 +00001765 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001766
1767 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001768 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001769}
1770
Ben Hutchingsadd72472012-11-08 01:46:53 +00001771static int efx_probe_filters(struct efx_nic *efx)
1772{
1773 int rc;
1774
1775 spin_lock_init(&efx->filter_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001776 init_rwsem(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01001777 mutex_lock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001778 down_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001779 rc = efx->type->filter_table_probe(efx);
1780 if (rc)
Edward Cree0d322412015-05-20 11:10:03 +01001781 goto out_unlock;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001782
1783#ifdef CONFIG_RFS_ACCEL
1784 if (efx->type->offload_features & NETIF_F_NTUPLE) {
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001785 struct efx_channel *channel;
1786 int i, success = 1;
1787
1788 efx_for_each_channel(channel, efx) {
1789 channel->rps_flow_id =
1790 kcalloc(efx->type->max_rx_ip_filters,
1791 sizeof(*channel->rps_flow_id),
1792 GFP_KERNEL);
1793 if (!channel->rps_flow_id)
1794 success = 0;
1795 else
1796 for (i = 0;
1797 i < efx->type->max_rx_ip_filters;
1798 ++i)
1799 channel->rps_flow_id[i] =
1800 RPS_FLOW_ID_INVALID;
1801 }
1802
1803 if (!success) {
1804 efx_for_each_channel(channel, efx)
1805 kfree(channel->rps_flow_id);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001806 efx->type->filter_table_remove(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001807 rc = -ENOMEM;
1808 goto out_unlock;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001809 }
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001810
1811 efx->rps_expire_index = efx->rps_expire_channel = 0;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001812 }
1813#endif
Edward Cree0d322412015-05-20 11:10:03 +01001814out_unlock:
1815 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01001816 mutex_unlock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01001817 return rc;
Ben Hutchingsadd72472012-11-08 01:46:53 +00001818}
1819
1820static void efx_remove_filters(struct efx_nic *efx)
1821{
1822#ifdef CONFIG_RFS_ACCEL
Jon Cooperfaf8dcc2016-05-31 19:12:32 +01001823 struct efx_channel *channel;
1824
1825 efx_for_each_channel(channel, efx)
1826 kfree(channel->rps_flow_id);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001827#endif
Edward Cree0d322412015-05-20 11:10:03 +01001828 down_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001829 efx->type->filter_table_remove(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001830 up_write(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001831}
1832
1833static void efx_restore_filters(struct efx_nic *efx)
1834{
Edward Cree0d322412015-05-20 11:10:03 +01001835 down_read(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001836 efx->type->filter_table_restore(efx);
Edward Cree0d322412015-05-20 11:10:03 +01001837 up_read(&efx->filter_sem);
Ben Hutchingsadd72472012-11-08 01:46:53 +00001838}
1839
Ben Hutchings8ceee662008-04-27 12:55:59 +01001840/**************************************************************************
1841 *
1842 * NIC startup/shutdown
1843 *
1844 *************************************************************************/
1845
1846static int efx_probe_all(struct efx_nic *efx)
1847{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001848 int rc;
1849
Ben Hutchings8ceee662008-04-27 12:55:59 +01001850 rc = efx_probe_nic(efx);
1851 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001852 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001853 goto fail1;
1854 }
1855
Ben Hutchings8ceee662008-04-27 12:55:59 +01001856 rc = efx_probe_port(efx);
1857 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001858 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001859 goto fail2;
1860 }
1861
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00001862 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
1863 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
1864 rc = -EINVAL;
1865 goto fail3;
1866 }
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001867 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001868
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001869#ifdef CONFIG_SFC_SRIOV
1870 rc = efx->type->vswitching_probe(efx);
1871 if (rc) /* not fatal; the PF will still work fine */
1872 netif_warn(efx, probe, efx->net_dev,
1873 "failed to setup vswitching rc=%d;"
1874 " VFs may not function\n", rc);
1875#endif
1876
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001877 rc = efx_probe_filters(efx);
1878 if (rc) {
1879 netif_err(efx, probe, efx->net_dev,
1880 "failed to create filter tables\n");
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001881 goto fail4;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001882 }
1883
Ben Hutchings7f967c02012-02-13 23:45:02 +00001884 rc = efx_probe_channels(efx);
1885 if (rc)
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001886 goto fail5;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001887
Ben Hutchings8ceee662008-04-27 12:55:59 +01001888 return 0;
1889
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001890 fail5:
Ben Hutchings7f967c02012-02-13 23:45:02 +00001891 efx_remove_filters(efx);
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001892 fail4:
1893#ifdef CONFIG_SFC_SRIOV
1894 efx->type->vswitching_remove(efx);
1895#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01001896 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001897 efx_remove_port(efx);
1898 fail2:
1899 efx_remove_nic(efx);
1900 fail1:
1901 return rc;
1902}
1903
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001904/* If the interface is supposed to be running but is not, start
1905 * the hardware and software data path, regular activity for the port
1906 * (MAC statistics, link polling, etc.) and schedule the port to be
1907 * reconfigured. Interrupts must already be enabled. This function
1908 * is safe to call multiple times, so long as the NIC is not disabled.
1909 * Requires the RTNL lock.
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001910 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001911static void efx_start_all(struct efx_nic *efx)
1912{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001913 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001914 BUG_ON(efx->state == STATE_DISABLED);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001915
1916 /* Check that it is appropriate to restart the interface. All
1917 * of these flags are safe to read under just the rtnl lock */
Edward Creee2835462014-04-16 19:27:48 +01001918 if (efx->port_enabled || !netif_running(efx->net_dev) ||
1919 efx->reset_pending)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001920 return;
1921
Ben Hutchings8ceee662008-04-27 12:55:59 +01001922 efx_start_port(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001923 efx_start_datapath(efx);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001924
Alexandre Rames626950d2013-01-14 17:20:22 +00001925 /* Start the hardware monitor if there is one */
1926 if (efx->type->monitor != NULL)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001927 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1928 efx_monitor_interval);
Alexandre Rames626950d2013-01-14 17:20:22 +00001929
Edward Cree5a6681e2016-11-28 18:55:34 +00001930 /* Link state detection is normally event-driven; we have
Alexandre Rames626950d2013-01-14 17:20:22 +00001931 * to poll now because we could have missed a change
1932 */
Edward Cree5a6681e2016-11-28 18:55:34 +00001933 mutex_lock(&efx->mac_lock);
1934 if (efx->phy_op->poll(efx))
1935 efx_link_status_changed(efx);
1936 mutex_unlock(&efx->mac_lock);
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001937
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001938 efx->type->start_stats(efx);
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001939 efx->type->pull_stats(efx);
1940 spin_lock_bh(&efx->stats_lock);
1941 efx->type->update_stats(efx, NULL, NULL);
1942 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001943}
1944
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001945/* Quiesce the hardware and software data path, and regular activity
1946 * for the port without bringing the link down. Safe to call multiple
1947 * times with the NIC in almost any state, but interrupts should be
1948 * enabled. Requires the RTNL lock.
1949 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001950static void efx_stop_all(struct efx_nic *efx)
1951{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001952 EFX_ASSERT_RESET_SERIALISED(efx);
1953
1954 /* port_enabled can be read safely under the rtnl lock */
1955 if (!efx->port_enabled)
1956 return;
1957
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001958 /* update stats before we go down so we can accurately count
1959 * rx_nodesc_drops
1960 */
1961 efx->type->pull_stats(efx);
1962 spin_lock_bh(&efx->stats_lock);
1963 efx->type->update_stats(efx, NULL, NULL);
1964 spin_unlock_bh(&efx->stats_lock);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001965 efx->type->stop_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001966 efx_stop_port(efx);
1967
Ben Hutchings29c69a42013-01-28 19:01:06 +00001968 /* Stop the kernel transmit interface. This is only valid if
1969 * the device is stopped or detached; otherwise the watchdog
1970 * may fire immediately.
1971 */
1972 WARN_ON(netif_running(efx->net_dev) &&
1973 netif_device_present(efx->net_dev));
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001974 netif_tx_disable(efx->net_dev);
1975
1976 efx_stop_datapath(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001977}
1978
1979static void efx_remove_all(struct efx_nic *efx)
1980{
Ben Hutchings46426102010-09-10 06:42:33 +00001981 efx_remove_channels(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001982 efx_remove_filters(efx);
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001983#ifdef CONFIG_SFC_SRIOV
1984 efx->type->vswitching_remove(efx);
1985#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01001986 efx_remove_port(efx);
1987 efx_remove_nic(efx);
1988}
1989
Ben Hutchings8ceee662008-04-27 12:55:59 +01001990/**************************************************************************
1991 *
1992 * Interrupt moderation
1993 *
1994 **************************************************************************/
Bert Kenward539de7c2016-08-11 13:02:09 +01001995unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001996{
Ben Hutchingsb548f972011-09-05 07:41:44 +00001997 if (usecs == 0)
1998 return 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001999 if (usecs * 1000 < efx->timer_quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00002000 return 1; /* never round down to 0 */
Bert Kenward539de7c2016-08-11 13:02:09 +01002001 return usecs * 1000 / efx->timer_quantum_ns;
2002}
2003
2004unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
2005{
2006 /* We must round up when converting ticks to microseconds
2007 * because we round down when converting the other way.
2008 */
2009 return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00002010}
2011
Ben Hutchings8ceee662008-04-27 12:55:59 +01002012/* Set interrupt moderation parameters */
Ben Hutchings9e393b32011-09-05 07:43:04 +00002013int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
2014 unsigned int rx_usecs, bool rx_adaptive,
2015 bool rx_may_override_tx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002016{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002017 struct efx_channel *channel;
Bert Kenwardd95e3292016-08-11 13:02:36 +01002018 unsigned int timer_max_us;
2019
Ben Hutchings8ceee662008-04-27 12:55:59 +01002020 EFX_ASSERT_RESET_SERIALISED(efx);
2021
Bert Kenwardd95e3292016-08-11 13:02:36 +01002022 timer_max_us = efx->timer_max_ns / 1000;
2023
2024 if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
Ben Hutchings9e393b32011-09-05 07:43:04 +00002025 return -EINVAL;
2026
Bert Kenward539de7c2016-08-11 13:02:09 +01002027 if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
Ben Hutchings9e393b32011-09-05 07:43:04 +00002028 !rx_may_override_tx) {
2029 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
2030 "RX and TX IRQ moderation must be equal\n");
2031 return -EINVAL;
2032 }
2033
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00002034 efx->irq_rx_adaptive = rx_adaptive;
Bert Kenward539de7c2016-08-11 13:02:09 +01002035 efx->irq_rx_moderation_us = rx_usecs;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002036 efx_for_each_channel(channel, efx) {
Ben Hutchings525da902011-02-07 23:04:38 +00002037 if (efx_channel_has_rx_queue(channel))
Bert Kenward539de7c2016-08-11 13:02:09 +01002038 channel->irq_moderation_us = rx_usecs;
Ben Hutchings525da902011-02-07 23:04:38 +00002039 else if (efx_channel_has_tx_queues(channel))
Bert Kenward539de7c2016-08-11 13:02:09 +01002040 channel->irq_moderation_us = tx_usecs;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002041 }
Ben Hutchings9e393b32011-09-05 07:43:04 +00002042
2043 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002044}
2045
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002046void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
2047 unsigned int *rx_usecs, bool *rx_adaptive)
2048{
2049 *rx_adaptive = efx->irq_rx_adaptive;
Bert Kenward539de7c2016-08-11 13:02:09 +01002050 *rx_usecs = efx->irq_rx_moderation_us;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002051
2052 /* If channels are shared between RX and TX, so is IRQ
2053 * moderation. Otherwise, IRQ moderation is the same for all
2054 * TX channels and is not adaptive.
2055 */
Bert Kenward539de7c2016-08-11 13:02:09 +01002056 if (efx->tx_channel_offset == 0) {
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002057 *tx_usecs = *rx_usecs;
Bert Kenward539de7c2016-08-11 13:02:09 +01002058 } else {
2059 struct efx_channel *tx_channel;
2060
2061 tx_channel = efx->channel[efx->tx_channel_offset];
2062 *tx_usecs = tx_channel->irq_moderation_us;
2063 }
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00002064}
2065
Ben Hutchings8ceee662008-04-27 12:55:59 +01002066/**************************************************************************
2067 *
2068 * Hardware monitor
2069 *
2070 **************************************************************************/
2071
Ben Hutchingse254c272010-09-20 08:44:10 +00002072/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002073static void efx_monitor(struct work_struct *data)
2074{
2075 struct efx_nic *efx = container_of(data, struct efx_nic,
2076 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002077
Ben Hutchings62776d02010-06-23 11:30:07 +00002078 netif_vdbg(efx, timer, efx->net_dev,
2079 "hardware monitor executing on CPU %d\n",
2080 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002081 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002082
Ben Hutchings8ceee662008-04-27 12:55:59 +01002083 /* If the mac_lock is already held then it is likely a port
2084 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00002085 * most of the work of monitor() anyway. */
2086 if (mutex_trylock(&efx->mac_lock)) {
2087 if (efx->port_enabled)
2088 efx->type->monitor(efx);
2089 mutex_unlock(&efx->mac_lock);
2090 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002091
Ben Hutchings8ceee662008-04-27 12:55:59 +01002092 queue_delayed_work(efx->workqueue, &efx->monitor_work,
2093 efx_monitor_interval);
2094}
2095
2096/**************************************************************************
2097 *
2098 * ioctls
2099 *
2100 *************************************************************************/
2101
2102/* Net device ioctl
2103 * Context: process, rtnl_lock() held.
2104 */
2105static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
2106{
Ben Hutchings767e4682008-09-01 12:43:14 +01002107 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00002108 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002109
Stuart Hodgson7c236c42012-09-03 11:09:36 +01002110 if (cmd == SIOCSHWTSTAMP)
Ben Hutchings433dc9b2013-11-14 01:26:21 +00002111 return efx_ptp_set_ts_config(efx, ifr);
2112 if (cmd == SIOCGHWTSTAMP)
2113 return efx_ptp_get_ts_config(efx, ifr);
Stuart Hodgson7c236c42012-09-03 11:09:36 +01002114
Ben Hutchings68e7f452009-04-29 08:05:08 +00002115 /* Convert phy_id from older PRTAD/DEVAD format */
2116 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
2117 (data->phy_id & 0xfc00) == 0x0400)
2118 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
2119
2120 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002121}
2122
2123/**************************************************************************
2124 *
2125 * NAPI interface
2126 *
2127 **************************************************************************/
2128
Ben Hutchings7f967c02012-02-13 23:45:02 +00002129static void efx_init_napi_channel(struct efx_channel *channel)
2130{
2131 struct efx_nic *efx = channel->efx;
2132
2133 channel->napi_dev = efx->net_dev;
2134 netif_napi_add(channel->napi_dev, &channel->napi_str,
2135 efx_poll, napi_weight);
2136}
2137
Ben Hutchingse8f14992010-12-07 19:47:34 +00002138static void efx_init_napi(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002139{
2140 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002141
Ben Hutchings7f967c02012-02-13 23:45:02 +00002142 efx_for_each_channel(channel, efx)
2143 efx_init_napi_channel(channel);
Ben Hutchingse8f14992010-12-07 19:47:34 +00002144}
2145
2146static void efx_fini_napi_channel(struct efx_channel *channel)
2147{
Eric Dumazet973334a2016-11-16 06:01:47 -08002148 if (channel->napi_dev)
Ben Hutchingse8f14992010-12-07 19:47:34 +00002149 netif_napi_del(&channel->napi_str);
Eric Dumazet973334a2016-11-16 06:01:47 -08002150
Ben Hutchingse8f14992010-12-07 19:47:34 +00002151 channel->napi_dev = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002152}
2153
2154static void efx_fini_napi(struct efx_nic *efx)
2155{
2156 struct efx_channel *channel;
2157
Ben Hutchingse8f14992010-12-07 19:47:34 +00002158 efx_for_each_channel(channel, efx)
2159 efx_fini_napi_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002160}
2161
2162/**************************************************************************
2163 *
2164 * Kernel netpoll interface
2165 *
2166 *************************************************************************/
2167
2168#ifdef CONFIG_NET_POLL_CONTROLLER
2169
2170/* Although in the common case interrupts will be disabled, this is not
2171 * guaranteed. However, all our work happens inside the NAPI callback,
2172 * so no locking is required.
2173 */
2174static void efx_netpoll(struct net_device *net_dev)
2175{
Ben Hutchings767e4682008-09-01 12:43:14 +01002176 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002177 struct efx_channel *channel;
2178
Ben Hutchings64ee3122008-09-01 12:47:38 +01002179 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002180 efx_schedule_channel(channel);
2181}
2182
2183#endif
2184
2185/**************************************************************************
2186 *
2187 * Kernel net device interface
2188 *
2189 *************************************************************************/
2190
2191/* Context: process, rtnl_lock() held. */
Shradha Shahe340be92015-05-20 11:11:03 +01002192int efx_net_open(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002193{
Ben Hutchings767e4682008-09-01 12:43:14 +01002194 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002195 int rc;
2196
Ben Hutchings62776d02010-06-23 11:30:07 +00002197 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
2198 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002199
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002200 rc = efx_check_disabled(efx);
2201 if (rc)
2202 return rc;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002203 if (efx->phy_mode & PHY_MODE_SPECIAL)
2204 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002205 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
2206 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002207
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00002208 /* Notify the kernel of the link state polled during driver load,
2209 * before the monitor starts running */
2210 efx_link_status_changed(efx);
2211
Ben Hutchings8ceee662008-04-27 12:55:59 +01002212 efx_start_all(efx);
Peter Dunning9c568fd2017-02-17 15:50:43 +00002213 if (efx->state == STATE_DISABLED || efx->reset_pending)
2214 netif_device_detach(efx->net_dev);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002215 efx_selftest_async_start(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002216 return 0;
2217}
2218
2219/* Context: process, rtnl_lock() held.
2220 * Note that the kernel will ignore our return code; this method
2221 * should really be a void.
2222 */
Shradha Shahe340be92015-05-20 11:11:03 +01002223int efx_net_stop(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002224{
Ben Hutchings767e4682008-09-01 12:43:14 +01002225 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002226
Ben Hutchings62776d02010-06-23 11:30:07 +00002227 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
2228 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002229
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002230 /* Stop the device and flush all the channels */
2231 efx_stop_all(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002232
2233 return 0;
2234}
2235
Ben Hutchings5b9e2072008-05-16 21:18:14 +01002236/* Context: process, dev_base_lock or RTNL held, non-blocking. */
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002237static void efx_net_stats(struct net_device *net_dev,
2238 struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002239{
Ben Hutchings767e4682008-09-01 12:43:14 +01002240 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002241
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002242 spin_lock_bh(&efx->stats_lock);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +00002243 efx->type->update_stats(efx, NULL, stats);
Ben Hutchings1cb34522011-09-02 23:23:00 +01002244 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002245}
2246
2247/* Context: netif_tx_lock held, BHs disabled. */
2248static void efx_watchdog(struct net_device *net_dev)
2249{
Ben Hutchings767e4682008-09-01 12:43:14 +01002250 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002251
Ben Hutchings62776d02010-06-23 11:30:07 +00002252 netif_err(efx, tx_err, efx->net_dev,
2253 "TX stuck with port_enabled=%d: resetting channels\n",
2254 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002255
Ben Hutchings739bb23d2008-11-04 20:35:36 +00002256 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002257}
2258
2259
2260/* Context: process, rtnl_lock() held. */
2261static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
2262{
Ben Hutchings767e4682008-09-01 12:43:14 +01002263 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002264 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002265
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002266 rc = efx_check_disabled(efx);
2267 if (rc)
2268 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002269
Ben Hutchings62776d02010-06-23 11:30:07 +00002270 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002271
Ben Hutchings29c69a42013-01-28 19:01:06 +00002272 efx_device_detach_sync(efx);
2273 efx_stop_all(efx);
2274
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002275 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002276 net_dev->mtu = new_mtu;
Edward Cree0d322412015-05-20 11:10:03 +01002277 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002278 mutex_unlock(&efx->mac_lock);
2279
Ben Hutchings8ceee662008-04-27 12:55:59 +01002280 efx_start_all(efx);
Peter Dunning9c568fd2017-02-17 15:50:43 +00002281 efx_device_attach_if_not_resetting(efx);
Ben Hutchings6c8eef42012-01-09 19:54:16 +00002282 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002283}
2284
2285static int efx_set_mac_address(struct net_device *net_dev, void *data)
2286{
Ben Hutchings767e4682008-09-01 12:43:14 +01002287 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002288 struct sockaddr *addr = data;
Ben Hutchingse0b3ae32014-02-12 18:59:54 +00002289 u8 *new_addr = addr->sa_data;
Shradha Shahcfc77c22015-05-20 11:09:30 +01002290 u8 old_addr[6];
2291 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002292
Ben Hutchings8ceee662008-04-27 12:55:59 +01002293 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002294 netif_err(efx, drv, efx->net_dev,
2295 "invalid ethernet MAC address requested: %pM\n",
2296 new_addr);
Danny Kukawka504f9b52012-02-21 02:07:49 +00002297 return -EADDRNOTAVAIL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002298 }
2299
Shradha Shahcfc77c22015-05-20 11:09:30 +01002300 /* save old address */
2301 ether_addr_copy(old_addr, net_dev->dev_addr);
Edward Creecd84ff42014-03-07 18:27:41 +00002302 ether_addr_copy(net_dev->dev_addr, new_addr);
Shradha Shah910c8782015-05-20 11:12:48 +01002303 if (efx->type->set_mac_address) {
2304 rc = efx->type->set_mac_address(efx);
Shradha Shahcfc77c22015-05-20 11:09:30 +01002305 if (rc) {
2306 ether_addr_copy(net_dev->dev_addr, old_addr);
2307 return rc;
2308 }
2309 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002310
2311 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002312 mutex_lock(&efx->mac_lock);
Edward Cree0d322412015-05-20 11:10:03 +01002313 efx_mac_reconfigure(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002314 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002315
2316 return 0;
2317}
2318
Ben Hutchingsa816f752008-09-01 12:49:12 +01002319/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002320static void efx_set_rx_mode(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002321{
Ben Hutchings767e4682008-09-01 12:43:14 +01002322 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002323
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002324 if (efx->port_enabled)
2325 queue_work(efx->workqueue, &efx->mac_work);
2326 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002327}
2328
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002329static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002330{
2331 struct efx_nic *efx = netdev_priv(net_dev);
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002332 int rc;
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002333
2334 /* If disabling RX n-tuple filtering, clear existing filters */
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002335 if (net_dev->features & ~data & NETIF_F_NTUPLE) {
2336 rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
2337 if (rc)
2338 return rc;
2339 }
2340
Edward Cree69787292017-10-31 14:29:47 +00002341 /* If Rx VLAN filter is changed, update filters via mac_reconfigure.
2342 * If rx-fcs is changed, mac_reconfigure updates that too.
2343 */
2344 if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
2345 NETIF_F_RXFCS)) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002346 /* efx_set_rx_mode() will schedule MAC work to update filters
2347 * when a new features are finally set in net_dev.
2348 */
2349 efx_set_rx_mode(net_dev);
2350 }
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002351
2352 return 0;
2353}
2354
Wei Yongjunb40296f2017-01-11 16:16:12 +00002355static int efx_get_phys_port_id(struct net_device *net_dev,
2356 struct netdev_phys_item_id *ppid)
Bert Kenward08a7b29b2017-01-10 16:23:33 +00002357{
2358 struct efx_nic *efx = netdev_priv(net_dev);
2359
2360 if (efx->type->get_phys_port_id)
2361 return efx->type->get_phys_port_id(efx, ppid);
2362 else
2363 return -EOPNOTSUPP;
2364}
2365
Bert Kenwardac019f02017-01-10 16:23:56 +00002366static int efx_get_phys_port_name(struct net_device *net_dev,
2367 char *name, size_t len)
2368{
2369 struct efx_nic *efx = netdev_priv(net_dev);
2370
2371 if (snprintf(name, len, "p%u", efx->port_num) >= len)
2372 return -EINVAL;
2373 return 0;
2374}
2375
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002376static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
2377{
2378 struct efx_nic *efx = netdev_priv(net_dev);
2379
2380 if (efx->type->vlan_rx_add_vid)
2381 return efx->type->vlan_rx_add_vid(efx, proto, vid);
2382 else
2383 return -EOPNOTSUPP;
2384}
2385
2386static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
2387{
2388 struct efx_nic *efx = netdev_priv(net_dev);
2389
2390 if (efx->type->vlan_rx_kill_vid)
2391 return efx->type->vlan_rx_kill_vid(efx, proto, vid);
2392 else
2393 return -EOPNOTSUPP;
2394}
2395
Jon Coopere5fbd972017-02-08 16:52:10 +00002396static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
2397{
2398 switch (in) {
2399 case UDP_TUNNEL_TYPE_VXLAN:
2400 return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
2401 case UDP_TUNNEL_TYPE_GENEVE:
2402 return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
2403 default:
2404 return -1;
2405 }
2406}
2407
2408static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
2409{
2410 struct efx_nic *efx = netdev_priv(dev);
2411 struct efx_udp_tunnel tnl;
2412 int efx_tunnel_type;
2413
2414 efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2415 if (efx_tunnel_type < 0)
2416 return;
2417
2418 tnl.type = (u16)efx_tunnel_type;
2419 tnl.port = ti->port;
2420
2421 if (efx->type->udp_tnl_add_port)
2422 (void)efx->type->udp_tnl_add_port(efx, tnl);
2423}
2424
2425static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
2426{
2427 struct efx_nic *efx = netdev_priv(dev);
2428 struct efx_udp_tunnel tnl;
2429 int efx_tunnel_type;
2430
2431 efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2432 if (efx_tunnel_type < 0)
2433 return;
2434
2435 tnl.type = (u16)efx_tunnel_type;
2436 tnl.port = ti->port;
2437
Dan Carpenterc04ca612017-03-22 12:10:02 +03002438 if (efx->type->udp_tnl_del_port)
Jon Coopere5fbd972017-02-08 16:52:10 +00002439 (void)efx->type->udp_tnl_del_port(efx, tnl);
2440}
2441
Shradha Shah7fa8d542015-05-06 00:55:13 +01002442static const struct net_device_ops efx_netdev_ops = {
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002443 .ndo_open = efx_net_open,
2444 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00002445 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002446 .ndo_tx_timeout = efx_watchdog,
2447 .ndo_start_xmit = efx_hard_start_xmit,
2448 .ndo_validate_addr = eth_validate_addr,
2449 .ndo_do_ioctl = efx_ioctl,
2450 .ndo_change_mtu = efx_change_mtu,
2451 .ndo_set_mac_address = efx_set_mac_address,
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002452 .ndo_set_rx_mode = efx_set_rx_mode,
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002453 .ndo_set_features = efx_set_features,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01002454 .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
2455 .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002456#ifdef CONFIG_SFC_SRIOV
Shradha Shah7fa8d542015-05-06 00:55:13 +01002457 .ndo_set_vf_mac = efx_sriov_set_vf_mac,
2458 .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
2459 .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
2460 .ndo_get_vf_config = efx_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01002461 .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002462#endif
Bert Kenward08a7b29b2017-01-10 16:23:33 +00002463 .ndo_get_phys_port_id = efx_get_phys_port_id,
Bert Kenwardac019f02017-01-10 16:23:56 +00002464 .ndo_get_phys_port_name = efx_get_phys_port_name,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002465#ifdef CONFIG_NET_POLL_CONTROLLER
2466 .ndo_poll_controller = efx_netpoll,
2467#endif
Ben Hutchings94b274b2011-01-10 21:18:20 +00002468 .ndo_setup_tc = efx_setup_tc,
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002469#ifdef CONFIG_RFS_ACCEL
2470 .ndo_rx_flow_steer = efx_filter_rfs,
2471#endif
Jon Coopere5fbd972017-02-08 16:52:10 +00002472 .ndo_udp_tunnel_add = efx_udp_tunnel_add,
2473 .ndo_udp_tunnel_del = efx_udp_tunnel_del,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002474};
2475
Ben Hutchings7dde5962008-12-12 22:09:38 -08002476static void efx_update_name(struct efx_nic *efx)
2477{
2478 strcpy(efx->name, efx->net_dev->name);
2479 efx_mtd_rename(efx);
2480 efx_set_channel_names(efx);
2481}
2482
Ben Hutchings8ceee662008-04-27 12:55:59 +01002483static int efx_netdev_event(struct notifier_block *this,
2484 unsigned long event, void *ptr)
2485{
Jiri Pirko351638e2013-05-28 01:30:21 +00002486 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002487
Shradha Shah7fa8d542015-05-06 00:55:13 +01002488 if ((net_dev->netdev_ops == &efx_netdev_ops) &&
Ben Hutchings7dde5962008-12-12 22:09:38 -08002489 event == NETDEV_CHANGENAME)
2490 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002491
2492 return NOTIFY_DONE;
2493}
2494
2495static struct notifier_block efx_netdev_notifier = {
2496 .notifier_call = efx_netdev_event,
2497};
2498
Ben Hutchings06d5e192008-12-12 21:47:23 -08002499static ssize_t
2500show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2501{
2502 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2503 return sprintf(buf, "%d\n", efx->phy_type);
2504}
Ben Hutchings776fbcc2013-06-18 17:45:40 +01002505static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
Ben Hutchings06d5e192008-12-12 21:47:23 -08002506
Edward Creee7fef9b2015-05-27 13:14:01 +01002507#ifdef CONFIG_SFC_MCDI_LOGGING
2508static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
2509 char *buf)
2510{
2511 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2512 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2513
2514 return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
2515}
2516static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
2517 const char *buf, size_t count)
2518{
2519 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2520 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2521 bool enable = count > 0 && *buf != '0';
2522
2523 mcdi->logging_enabled = enable;
2524 return count;
2525}
2526static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
2527#endif
2528
Ben Hutchings8ceee662008-04-27 12:55:59 +01002529static int efx_register_netdev(struct efx_nic *efx)
2530{
2531 struct net_device *net_dev = efx->net_dev;
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002532 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002533 int rc;
2534
2535 net_dev->watchdog_timeo = 5 * HZ;
2536 net_dev->irq = efx->pci_dev->irq;
Shradha Shah7fa8d542015-05-06 00:55:13 +01002537 net_dev->netdev_ops = &efx_netdev_ops;
2538 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
Ben Hutchings8127d662013-08-29 19:19:29 +01002539 net_dev->priv_flags |= IFF_UNICAST_FLT;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002540 net_dev->ethtool_ops = &efx_ethtool_ops;
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00002541 net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
Bert Kenwardcd94e512016-10-18 17:47:45 +01002542 net_dev->min_mtu = EFX_MIN_MTU;
2543 net_dev->max_mtu = EFX_MAX_MTU;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002544
Ben Hutchings7dde5962008-12-12 22:09:38 -08002545 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00002546
Ben Hutchings7153f622012-07-27 20:50:52 +01002547 /* Enable resets to be scheduled and check whether any were
2548 * already requested. If so, the NIC is probably hosed so we
2549 * abort.
2550 */
2551 efx->state = STATE_READY;
2552 smp_mb(); /* ensure we change state before checking reset_pending */
2553 if (efx->reset_pending) {
2554 netif_err(efx, probe, efx->net_dev,
2555 "aborting probe due to scheduled reset\n");
2556 rc = -EIO;
2557 goto fail_locked;
2558 }
2559
Ben Hutchingsaed06282009-08-26 08:16:27 +00002560 rc = dev_alloc_name(net_dev, net_dev->name);
2561 if (rc < 0)
2562 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002563 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002564
Ben Hutchings8f8b3d52012-08-24 18:04:38 +01002565 /* Always start with carrier off; PHY events will detect the link */
2566 netif_carrier_off(net_dev);
2567
Ben Hutchingsaed06282009-08-26 08:16:27 +00002568 rc = register_netdevice(net_dev);
2569 if (rc)
2570 goto fail_locked;
2571
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002572 efx_for_each_channel(channel, efx) {
2573 struct efx_tx_queue *tx_queue;
Ben Hutchings60031fc2011-01-12 18:39:40 +00002574 efx_for_each_channel_tx_queue(tx_queue, channel)
2575 efx_init_tx_queue_core_txq(tx_queue);
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002576 }
2577
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002578 efx_associate(efx);
2579
Ben Hutchings7dde5962008-12-12 22:09:38 -08002580 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002581
Ben Hutchings06d5e192008-12-12 21:47:23 -08002582 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2583 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002584 netif_err(efx, drv, efx->net_dev,
2585 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08002586 goto fail_registered;
2587 }
Edward Creee7fef9b2015-05-27 13:14:01 +01002588#ifdef CONFIG_SFC_MCDI_LOGGING
2589 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2590 if (rc) {
2591 netif_err(efx, drv, efx->net_dev,
2592 "failed to init net dev attributes\n");
2593 goto fail_attr_mcdi_logging;
2594 }
2595#endif
Ben Hutchings06d5e192008-12-12 21:47:23 -08002596
Ben Hutchings8ceee662008-04-27 12:55:59 +01002597 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08002598
Edward Creee7fef9b2015-05-27 13:14:01 +01002599#ifdef CONFIG_SFC_MCDI_LOGGING
2600fail_attr_mcdi_logging:
2601 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2602#endif
Ben Hutchings7153f622012-07-27 20:50:52 +01002603fail_registered:
2604 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002605 efx_dissociate(efx);
Ben Hutchings7153f622012-07-27 20:50:52 +01002606 unregister_netdevice(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002607fail_locked:
Ben Hutchings7153f622012-07-27 20:50:52 +01002608 efx->state = STATE_UNINIT;
Ben Hutchingsaed06282009-08-26 08:16:27 +00002609 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00002610 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00002611 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002612}
2613
2614static void efx_unregister_netdev(struct efx_nic *efx)
2615{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002616 if (!efx->net_dev)
2617 return;
2618
Ben Hutchings767e4682008-09-01 12:43:14 +01002619 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002620
Edward Creee7fef9b2015-05-27 13:14:01 +01002621 if (efx_dev_registered(efx)) {
2622 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2623#ifdef CONFIG_SFC_MCDI_LOGGING
2624 device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2625#endif
2626 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2627 unregister_netdev(efx->net_dev);
2628 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002629}
2630
2631/**************************************************************************
2632 *
2633 * Device reset and suspend
2634 *
2635 **************************************************************************/
2636
Ben Hutchings2467ca42008-09-01 12:48:50 +01002637/* Tears down the entire software state and most of the hardware state
2638 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002639void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002640{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002641 EFX_ASSERT_RESET_SERIALISED(efx);
2642
Edward Creee2835462014-04-16 19:27:48 +01002643 if (method == RESET_TYPE_MCDI_TIMEOUT)
2644 efx->type->prepare_flr(efx);
2645
Ben Hutchings2467ca42008-09-01 12:48:50 +01002646 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01002647 efx_disable_interrupts(efx);
Ben Hutchings5642cee2012-07-27 19:35:52 +01002648
2649 mutex_lock(&efx->mac_lock);
Jon Cooper087e9022015-05-20 11:11:35 +01002650 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2651 method != RESET_TYPE_DATAPATH)
Steve Hodgson4b988282009-01-29 17:50:51 +00002652 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002653 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002654}
2655
Ben Hutchings2467ca42008-09-01 12:48:50 +01002656/* This function will always ensure that the locks acquired in
2657 * efx_reset_down() are released. A failure return code indicates
2658 * that we were unable to reinitialise the hardware, and the
2659 * driver should be disabled. If ok is false, then the rx and tx
2660 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002661int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002662{
2663 int rc;
2664
Ben Hutchings2467ca42008-09-01 12:48:50 +01002665 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002666
Edward Creee2835462014-04-16 19:27:48 +01002667 if (method == RESET_TYPE_MCDI_TIMEOUT)
2668 efx->type->finish_flr(efx);
2669
2670 /* Ensure that SRAM is initialised even if we're disabling the device */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002671 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002672 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002673 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002674 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002675 }
2676
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002677 if (!ok)
2678 goto fail;
2679
Jon Cooper087e9022015-05-20 11:11:35 +01002680 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2681 method != RESET_TYPE_DATAPATH) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002682 rc = efx->phy_op->init(efx);
2683 if (rc)
2684 goto fail;
Edward Cree267d9d72015-05-06 00:59:18 +01002685 rc = efx->phy_op->reconfigure(efx);
2686 if (rc && rc != -EPERM)
Ben Hutchings62776d02010-06-23 11:30:07 +00002687 netif_err(efx, drv, efx->net_dev,
2688 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002689 }
2690
Jon Cooper261e4d92013-04-15 18:51:54 +01002691 rc = efx_enable_interrupts(efx);
2692 if (rc)
2693 goto fail;
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01002694
2695#ifdef CONFIG_SFC_SRIOV
2696 rc = efx->type->vswitching_restore(efx);
2697 if (rc) /* not fatal; the PF will still work fine */
2698 netif_warn(efx, probe, efx->net_dev,
2699 "failed to restore vswitching rc=%d;"
2700 " VFs may not function\n", rc);
2701#endif
2702
Edward Cree0d322412015-05-20 11:10:03 +01002703 down_read(&efx->filter_sem);
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002704 efx_restore_filters(efx);
Edward Cree0d322412015-05-20 11:10:03 +01002705 up_read(&efx->filter_sem);
Shradha Shah7fa8d542015-05-06 00:55:13 +01002706 if (efx->type->sriov_reset)
2707 efx->type->sriov_reset(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002708
2709 mutex_unlock(&efx->mac_lock);
2710
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002711 efx_start_all(efx);
2712
Jon Coopere5fbd972017-02-08 16:52:10 +00002713 if (efx->type->udp_tnl_push_ports)
2714 efx->type->udp_tnl_push_ports(efx);
2715
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002716 return 0;
2717
2718fail:
2719 efx->port_initialized = false;
2720
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002721 mutex_unlock(&efx->mac_lock);
2722
Ben Hutchings8ceee662008-04-27 12:55:59 +01002723 return rc;
2724}
2725
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002726/* Reset the NIC using the specified method. Note that the reset may
2727 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002728 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002729 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002730 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002731int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002732{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002733 int rc, rc2;
2734 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002735
Ben Hutchings62776d02010-06-23 11:30:07 +00002736 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2737 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002738
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01002739 efx_device_detach_sync(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002740 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002741
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002742 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002743 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002744 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002745 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002746 }
2747
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002748 /* Clear flags for the scopes we covered. We assume the NIC and
2749 * driver are now quiescent so that there is no race here.
2750 */
Edward Creee2835462014-04-16 19:27:48 +01002751 if (method < RESET_TYPE_MAX_METHOD)
2752 efx->reset_pending &= -(1 << (method + 1));
2753 else /* it doesn't fit into the well-ordered scope hierarchy */
2754 __clear_bit(method, &efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002755
2756 /* Reinitialise bus-mastering, which may have been turned off before
2757 * the reset was scheduled. This is still appropriate, even in the
2758 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2759 * can respond to requests. */
2760 pci_set_master(efx->pci_dev);
2761
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002762out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002763 /* Leave device stopped if necessary */
Alexandre Rames626950d2013-01-14 17:20:22 +00002764 disabled = rc ||
2765 method == RESET_TYPE_DISABLE ||
2766 method == RESET_TYPE_RECOVER_OR_DISABLE;
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002767 rc2 = efx_reset_up(efx, method, !disabled);
2768 if (rc2) {
2769 disabled = true;
2770 if (!rc)
2771 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002772 }
2773
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002774 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002775 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002776 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002777 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002778 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002779 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Peter Dunning9c568fd2017-02-17 15:50:43 +00002780 efx_device_attach_if_not_resetting(efx);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002781 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002782 return rc;
2783}
2784
Alexandre Rames626950d2013-01-14 17:20:22 +00002785/* Try recovery mechanisms.
2786 * For now only EEH is supported.
2787 * Returns 0 if the recovery mechanisms are unsuccessful.
2788 * Returns a non-zero value otherwise.
2789 */
Alexandre Ramesb28405b2013-03-21 16:41:43 +00002790int efx_try_recovery(struct efx_nic *efx)
Alexandre Rames626950d2013-01-14 17:20:22 +00002791{
2792#ifdef CONFIG_EEH
2793 /* A PCI error can occur and not be seen by EEH because nothing
2794 * happens on the PCI bus. In this case the driver may fail and
2795 * schedule a 'recover or reset', leading to this recovery handler.
2796 * Manually call the eeh failure check function.
2797 */
Benjamin Herrenschmidt12a89db2015-03-23 14:00:47 +11002798 struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
Alexandre Rames626950d2013-01-14 17:20:22 +00002799 if (eeh_dev_check_failure(eehdev)) {
2800 /* The EEH mechanisms will handle the error and reset the
2801 * device if necessary.
2802 */
2803 return 1;
2804 }
2805#endif
2806 return 0;
2807}
2808
Jon Cooper74cd60a2013-09-16 14:18:51 +01002809static void efx_wait_for_bist_end(struct efx_nic *efx)
2810{
2811 int i;
2812
2813 for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
2814 if (efx_mcdi_poll_reboot(efx))
2815 goto out;
2816 msleep(BIST_WAIT_DELAY_MS);
2817 }
2818
2819 netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
2820out:
2821 /* Either way unset the BIST flag. If we found no reboot we probably
2822 * won't recover, but we should try.
2823 */
2824 efx->mc_bist_for_other_fn = false;
2825}
2826
Ben Hutchings8ceee662008-04-27 12:55:59 +01002827/* The worker thread exists so that code that cannot sleep can
2828 * schedule a reset for later.
2829 */
2830static void efx_reset_work(struct work_struct *data)
2831{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002832 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Alexandre Rames626950d2013-01-14 17:20:22 +00002833 unsigned long pending;
2834 enum reset_type method;
2835
Mark Rutland6aa7de02017-10-23 14:07:29 -07002836 pending = READ_ONCE(efx->reset_pending);
Alexandre Rames626950d2013-01-14 17:20:22 +00002837 method = fls(pending) - 1;
2838
Jon Cooper74cd60a2013-09-16 14:18:51 +01002839 if (method == RESET_TYPE_MC_BIST)
2840 efx_wait_for_bist_end(efx);
2841
Alexandre Rames626950d2013-01-14 17:20:22 +00002842 if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
2843 method == RESET_TYPE_RECOVER_OR_ALL) &&
2844 efx_try_recovery(efx))
2845 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002846
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002847 if (!pending)
Steve Hodgson319ba642010-06-01 11:17:24 +00002848 return;
2849
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002850 rtnl_lock();
Ben Hutchings7153f622012-07-27 20:50:52 +01002851
2852 /* We checked the state in efx_schedule_reset() but it may
2853 * have changed by now. Now that we have the RTNL lock,
2854 * it cannot change again.
2855 */
2856 if (efx->state == STATE_READY)
Alexandre Rames626950d2013-01-14 17:20:22 +00002857 (void)efx_reset(efx, method);
Ben Hutchings7153f622012-07-27 20:50:52 +01002858
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002859 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002860}
2861
2862void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2863{
2864 enum reset_type method;
2865
Alexandre Rames626950d2013-01-14 17:20:22 +00002866 if (efx->state == STATE_RECOVERY) {
2867 netif_dbg(efx, drv, efx->net_dev,
2868 "recovering: skip scheduling %s reset\n",
2869 RESET_TYPE(type));
2870 return;
2871 }
2872
Ben Hutchings8ceee662008-04-27 12:55:59 +01002873 switch (type) {
2874 case RESET_TYPE_INVISIBLE:
2875 case RESET_TYPE_ALL:
Alexandre Rames626950d2013-01-14 17:20:22 +00002876 case RESET_TYPE_RECOVER_OR_ALL:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002877 case RESET_TYPE_WORLD:
2878 case RESET_TYPE_DISABLE:
Alexandre Rames626950d2013-01-14 17:20:22 +00002879 case RESET_TYPE_RECOVER_OR_DISABLE:
Jon Cooper087e9022015-05-20 11:11:35 +01002880 case RESET_TYPE_DATAPATH:
Jon Cooper74cd60a2013-09-16 14:18:51 +01002881 case RESET_TYPE_MC_BIST:
Edward Creee2835462014-04-16 19:27:48 +01002882 case RESET_TYPE_MCDI_TIMEOUT:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002883 method = type;
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002884 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2885 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002886 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002887 default:
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002888 method = efx->type->map_reset_reason(type);
Ben Hutchings62776d02010-06-23 11:30:07 +00002889 netif_dbg(efx, drv, efx->net_dev,
2890 "scheduling %s reset for %s\n",
2891 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002892 break;
2893 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002894
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002895 set_bit(method, &efx->reset_pending);
Ben Hutchings7153f622012-07-27 20:50:52 +01002896 smp_mb(); /* ensure we change reset_pending before checking state */
2897
2898 /* If we're not READY then just leave the flags set as the cue
2899 * to abort probing or reschedule the reset later.
2900 */
Mark Rutland6aa7de02017-10-23 14:07:29 -07002901 if (READ_ONCE(efx->state) != STATE_READY)
Ben Hutchings7153f622012-07-27 20:50:52 +01002902 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002903
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002904 /* efx_process_channel() will no longer read events once a
2905 * reset is scheduled. So switch back to poll'd MCDI completions. */
2906 efx_mcdi_mode_poll(efx);
2907
Steve Hodgson1ab00622008-12-12 21:33:02 -08002908 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002909}
2910
2911/**************************************************************************
2912 *
2913 * List of NICs we support
2914 *
2915 **************************************************************************/
2916
2917/* PCI device ID table */
Benoit Taine9baa3c32014-08-08 15:56:03 +02002918static const struct pci_device_id efx_pci_table[] = {
Ben Hutchings547c4742011-12-02 18:23:56 +00002919 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002920 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002921 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002922 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8127d662013-08-29 19:19:29 +01002923 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
2924 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01002925 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
2926 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Mateusz Wrzesinski3b06a002014-07-14 08:38:49 +01002927 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
2928 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Bert Kenwarddd248f12015-11-30 09:05:47 +00002929 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
2930 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2931 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
2932 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2933 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
2934 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Edward Creeaae5a312017-12-18 16:56:34 +00002935 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */
2936 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2937 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */
2938 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002939 {0} /* end of list */
2940};
2941
2942/**************************************************************************
2943 *
Ben Hutchings37594332009-11-23 16:05:45 +00002944 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002945 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002946 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002947 * Needed so all function pointers are valid and do not have to be tested
2948 * before use
2949 *
2950 **************************************************************************/
2951int efx_port_dummy_op_int(struct efx_nic *efx)
2952{
2953 return 0;
2954}
2955void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002956
2957static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002958{
2959 return false;
2960}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002961
stephen hemminger6c8c2512011-04-14 05:50:12 +00002962static const struct efx_phy_operations efx_dummy_phy_operations = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002963 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002964 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002965 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002966 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002967};
2968
Ben Hutchings8ceee662008-04-27 12:55:59 +01002969/**************************************************************************
2970 *
2971 * Data housekeeping
2972 *
2973 **************************************************************************/
2974
2975/* This zeroes out and then fills in the invariants in a struct
2976 * efx_nic (including all sub-structures).
2977 */
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01002978static int efx_init_struct(struct efx_nic *efx,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002979 struct pci_dev *pci_dev, struct net_device *net_dev)
2980{
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00002981 int rc = -ENOMEM, i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002982
2983 /* Initialise common structures */
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002984 INIT_LIST_HEAD(&efx->node);
2985 INIT_LIST_HEAD(&efx->secondary_list);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002986 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002987#ifdef CONFIG_SFC_MTD
2988 INIT_LIST_HEAD(&efx->mtd_list);
2989#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002990 INIT_WORK(&efx->reset_work, efx_reset_work);
2991 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002992 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002993 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002994 efx->msg_enable = debug;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002995 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002996 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002997
2998 efx->net_dev = net_dev;
Jon Cooper43a37392012-10-18 15:49:54 +01002999 efx->rx_prefix_size = efx->type->rx_prefix_size;
Andrew Rybchenko2ec03012013-11-16 11:02:27 +04003000 efx->rx_ip_align =
3001 NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
Jon Cooper43a37392012-10-18 15:49:54 +01003002 efx->rx_packet_hash_offset =
3003 efx->type->rx_hash_offset - efx->type->rx_prefix_size;
Jon Cooperbd9a2652013-11-18 12:54:41 +00003004 efx->rx_packet_ts_offset =
3005 efx->type->rx_ts_offset - efx->type->rx_prefix_size;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003006 spin_lock_init(&efx->stats_lock);
Edward Cree71827442017-12-18 16:56:19 +00003007 efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
Edward Creec1be4822017-12-21 09:00:26 +00003008 efx->num_mac_stats = MC_CMD_MAC_NSTATS;
3009 BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003010 mutex_init(&efx->mac_lock);
3011 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00003012 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08003013 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00003014 init_waitqueue_head(&efx->flush_wq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003015
3016 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00003017 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
3018 if (!efx->channel[i])
3019 goto fail;
Ben Hutchingsd8291182012-10-05 23:35:41 +01003020 efx->msi_context[i].efx = efx;
3021 efx->msi_context[i].index = i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003022 }
3023
Ben Hutchings8ceee662008-04-27 12:55:59 +01003024 /* Higher numbered interrupt modes are less capable! */
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003025 if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
3026 efx->type->min_interrupt_mode)) {
3027 rc = -EIO;
3028 goto fail;
3029 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003030 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
3031 interrupt_mode);
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003032 efx->interrupt_mode = min(efx->type->min_interrupt_mode,
3033 interrupt_mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003034
Ben Hutchings6977dc62008-12-26 13:44:39 -08003035 /* Would be good to use the net_dev name, but we're too early */
3036 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
3037 pci_name(pci_dev));
3038 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08003039 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00003040 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01003041
Ben Hutchings8ceee662008-04-27 12:55:59 +01003042 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00003043
3044fail:
3045 efx_fini_struct(efx);
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00003046 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003047}
3048
3049static void efx_fini_struct(struct efx_nic *efx)
3050{
Ben Hutchings8313aca2010-09-10 06:41:57 +00003051 int i;
3052
3053 for (i = 0; i < EFX_MAX_CHANNELS; i++)
3054 kfree(efx->channel[i]);
3055
Ben Hutchingsef215e62013-12-05 20:13:22 +00003056 kfree(efx->vpd_sn);
3057
Ben Hutchings8ceee662008-04-27 12:55:59 +01003058 if (efx->workqueue) {
3059 destroy_workqueue(efx->workqueue);
3060 efx->workqueue = NULL;
3061 }
3062}
3063
Edward Creee4d112e2014-07-15 11:58:12 +01003064void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
3065{
3066 u64 n_rx_nodesc_trunc = 0;
3067 struct efx_channel *channel;
3068
3069 efx_for_each_channel(channel, efx)
3070 n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
3071 stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
3072 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
3073}
3074
Ben Hutchings8ceee662008-04-27 12:55:59 +01003075/**************************************************************************
3076 *
3077 * PCI interface
3078 *
3079 **************************************************************************/
3080
3081/* Main body of final NIC shutdown code
3082 * This is called only at module unload (or hotplug removal).
3083 */
3084static void efx_pci_remove_main(struct efx_nic *efx)
3085{
Ben Hutchings7153f622012-07-27 20:50:52 +01003086 /* Flush reset_work. It can no longer be scheduled since we
3087 * are not READY.
3088 */
3089 BUG_ON(efx->state == STATE_READY);
3090 cancel_work_sync(&efx->reset_work);
3091
Ben Hutchingsd8291182012-10-05 23:35:41 +01003092 efx_disable_interrupts(efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +00003093 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003094 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003095 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003096 efx_fini_napi(efx);
3097 efx_remove_all(efx);
3098}
3099
3100/* Final NIC shutdown
Daniel Pieczko2a3fc312015-06-02 11:40:46 +01003101 * This is called only at module unload (or hotplug removal). A PF can call
3102 * this on its VFs to ensure they are unbound first.
Ben Hutchings8ceee662008-04-27 12:55:59 +01003103 */
3104static void efx_pci_remove(struct pci_dev *pci_dev)
3105{
3106 struct efx_nic *efx;
3107
3108 efx = pci_get_drvdata(pci_dev);
3109 if (!efx)
3110 return;
3111
3112 /* Mark the NIC as fini, then stop the interface */
3113 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01003114 efx_dissociate(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003115 dev_close(efx->net_dev);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003116 efx_disable_interrupts(efx);
Edward Creeea6bb992015-06-15 18:27:54 +01003117 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003118 rtnl_unlock();
3119
Shradha Shah7fa8d542015-05-06 00:55:13 +01003120 if (efx->type->sriov_fini)
3121 efx->type->sriov_fini(efx);
3122
Ben Hutchings8ceee662008-04-27 12:55:59 +01003123 efx_unregister_netdev(efx);
3124
Ben Hutchings7dde5962008-12-12 22:09:38 -08003125 efx_mtd_remove(efx);
3126
Ben Hutchings8ceee662008-04-27 12:55:59 +01003127 efx_pci_remove_main(efx);
3128
Ben Hutchings8ceee662008-04-27 12:55:59 +01003129 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00003130 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003131
Ben Hutchings8ceee662008-04-27 12:55:59 +01003132 efx_fini_struct(efx);
3133 free_netdev(efx->net_dev);
Alexandre Rames626950d2013-01-14 17:20:22 +00003134
3135 pci_disable_pcie_error_reporting(pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003136};
3137
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003138/* NIC VPD information
3139 * Called during probe to display the part number of the
3140 * installed NIC. VPD is potentially very large but this should
3141 * always appear within the first 512 bytes.
3142 */
3143#define SFC_VPD_LEN 512
Ben Hutchingsef215e62013-12-05 20:13:22 +00003144static void efx_probe_vpd_strings(struct efx_nic *efx)
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003145{
3146 struct pci_dev *dev = efx->pci_dev;
3147 char vpd_data[SFC_VPD_LEN];
3148 ssize_t vpd_size;
Ben Hutchingsef215e62013-12-05 20:13:22 +00003149 int ro_start, ro_size, i, j;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003150
3151 /* Get the vpd data from the device */
3152 vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
3153 if (vpd_size <= 0) {
3154 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
3155 return;
3156 }
3157
3158 /* Get the Read only section */
Ben Hutchingsef215e62013-12-05 20:13:22 +00003159 ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
3160 if (ro_start < 0) {
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003161 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
3162 return;
3163 }
3164
Ben Hutchingsef215e62013-12-05 20:13:22 +00003165 ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
3166 j = ro_size;
3167 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003168 if (i + j > vpd_size)
3169 j = vpd_size - i;
3170
3171 /* Get the Part number */
3172 i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
3173 if (i < 0) {
3174 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
3175 return;
3176 }
3177
3178 j = pci_vpd_info_field_size(&vpd_data[i]);
3179 i += PCI_VPD_INFO_FLD_HDR_SIZE;
3180 if (i + j > vpd_size) {
3181 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
3182 return;
3183 }
3184
3185 netif_info(efx, drv, efx->net_dev,
3186 "Part Number : %.*s\n", j, &vpd_data[i]);
Ben Hutchingsef215e62013-12-05 20:13:22 +00003187
3188 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
3189 j = ro_size;
3190 i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
3191 if (i < 0) {
3192 netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
3193 return;
3194 }
3195
3196 j = pci_vpd_info_field_size(&vpd_data[i]);
3197 i += PCI_VPD_INFO_FLD_HDR_SIZE;
3198 if (i + j > vpd_size) {
3199 netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
3200 return;
3201 }
3202
3203 efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
3204 if (!efx->vpd_sn)
3205 return;
3206
3207 snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003208}
3209
3210
Ben Hutchings8ceee662008-04-27 12:55:59 +01003211/* Main body of NIC initialisation
3212 * This is called at module load (or hotplug insertion, theoretically).
3213 */
3214static int efx_pci_probe_main(struct efx_nic *efx)
3215{
3216 int rc;
3217
3218 /* Do start-of-day initialisation */
3219 rc = efx_probe_all(efx);
3220 if (rc)
3221 goto fail1;
3222
Ben Hutchingse8f14992010-12-07 19:47:34 +00003223 efx_init_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003224
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003225 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003226 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00003227 netif_err(efx, probe, efx->net_dev,
3228 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00003229 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003230 }
3231
3232 rc = efx_init_port(efx);
3233 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00003234 netif_err(efx, probe, efx->net_dev,
3235 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00003236 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003237 }
3238
Ben Hutchings152b6a62009-11-29 03:43:56 +00003239 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003240 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00003241 goto fail5;
Jon Cooper261e4d92013-04-15 18:51:54 +01003242 rc = efx_enable_interrupts(efx);
3243 if (rc)
3244 goto fail6;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003245
3246 return 0;
3247
Jon Cooper261e4d92013-04-15 18:51:54 +01003248 fail6:
3249 efx_nic_fini_interrupt(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +00003250 fail5:
Ben Hutchings8ceee662008-04-27 12:55:59 +01003251 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003252 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00003253 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003254 fail3:
3255 efx_fini_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003256 efx_remove_all(efx);
3257 fail1:
3258 return rc;
3259}
3260
Jon Cooper8a531402017-02-08 16:51:18 +00003261static int efx_pci_probe_post_io(struct efx_nic *efx)
3262{
3263 struct net_device *net_dev = efx->net_dev;
3264 int rc = efx_pci_probe_main(efx);
3265
3266 if (rc)
3267 return rc;
3268
3269 if (efx->type->sriov_init) {
3270 rc = efx->type->sriov_init(efx);
3271 if (rc)
3272 netif_err(efx, probe, efx->net_dev,
3273 "SR-IOV can't be enabled rc %d\n", rc);
3274 }
3275
3276 /* Determine netdevice features */
3277 net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
Edward Cree69787292017-10-31 14:29:47 +00003278 NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
Jon Cooper8a531402017-02-08 16:51:18 +00003279 if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
3280 net_dev->features |= NETIF_F_TSO6;
3281 /* Check whether device supports TSO */
3282 if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
3283 net_dev->features &= ~NETIF_F_ALL_TSO;
3284 /* Mask for features that also apply to VLAN devices */
3285 net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
3286 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
3287 NETIF_F_RXCSUM);
3288
Edward Cree69787292017-10-31 14:29:47 +00003289 net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
3290
3291 /* Disable receiving frames with bad FCS, by default. */
3292 net_dev->features &= ~NETIF_F_RXALL;
Jon Cooper8a531402017-02-08 16:51:18 +00003293
3294 /* Disable VLAN filtering by default. It may be enforced if
3295 * the feature is fixed (i.e. VLAN filters are required to
3296 * receive VLAN tagged packets due to vPort restrictions).
3297 */
3298 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
3299 net_dev->features |= efx->fixed_features;
3300
3301 rc = efx_register_netdev(efx);
3302 if (!rc)
3303 return 0;
3304
3305 efx_pci_remove_main(efx);
3306 return rc;
3307}
3308
Ben Hutchings8ceee662008-04-27 12:55:59 +01003309/* NIC initialisation
3310 *
3311 * This is called at module load (or hotplug insertion,
Ben Hutchings73ba7b62012-01-09 19:47:08 +00003312 * theoretically). It sets up PCI mappings, resets the NIC,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003313 * sets up and registers the network devices with the kernel and hooks
3314 * the interrupt service routine. It does not prepare the device for
3315 * transmission; this is left to the first time one of the network
3316 * interfaces is brought up (i.e. efx_net_open).
3317 */
Bill Pemberton87d1fc12012-12-03 09:23:32 -05003318static int efx_pci_probe(struct pci_dev *pci_dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003319 const struct pci_device_id *entry)
Ben Hutchings8ceee662008-04-27 12:55:59 +01003320{
Ben Hutchings8ceee662008-04-27 12:55:59 +01003321 struct net_device *net_dev;
3322 struct efx_nic *efx;
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003323 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003324
3325 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchings94b274b2011-01-10 21:18:20 +00003326 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
3327 EFX_MAX_RX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003328 if (!net_dev)
3329 return -ENOMEM;
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01003330 efx = netdev_priv(net_dev);
3331 efx->type = (const struct efx_nic_type *) entry->driver_data;
Andrew Rybchenkoebfcd0f2016-06-15 17:43:20 +01003332 efx->fixed_features |= NETIF_F_HIGHDMA;
Andrew Rybchenkoeb7cfd82016-06-15 17:51:36 +01003333
Ben Hutchings8ceee662008-04-27 12:55:59 +01003334 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00003335 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01003336 rc = efx_init_struct(efx, pci_dev, net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003337 if (rc)
3338 goto fail1;
3339
Ben Hutchings62776d02010-06-23 11:30:07 +00003340 netif_info(efx, probe, efx->net_dev,
Ben Hutchingsff79c8a2011-07-13 16:21:24 +01003341 "Solarflare NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003342
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01003343 if (!efx->type->is_vf)
3344 efx_probe_vpd_strings(efx);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003345
Ben Hutchings8ceee662008-04-27 12:55:59 +01003346 /* Set up basic I/O (BAR mappings etc) */
3347 rc = efx_init_io(efx);
3348 if (rc)
3349 goto fail2;
3350
Jon Cooper8a531402017-02-08 16:51:18 +00003351 rc = efx_pci_probe_post_io(efx);
3352 if (rc) {
3353 /* On failure, retry once immediately.
3354 * If we aborted probe due to a scheduled reset, dismiss it.
3355 */
3356 efx->reset_pending = 0;
3357 rc = efx_pci_probe_post_io(efx);
3358 if (rc) {
3359 /* On another failure, retry once more
3360 * after a 50-305ms delay.
3361 */
3362 unsigned char r;
3363
3364 get_random_bytes(&r, 1);
3365 msleep((unsigned int)r + 50);
3366 efx->reset_pending = 0;
3367 rc = efx_pci_probe_post_io(efx);
3368 }
3369 }
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003370 if (rc)
3371 goto fail3;
Steve Hodgsonfa402b22008-12-12 22:08:16 -08003372
Ben Hutchings62776d02010-06-23 11:30:07 +00003373 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003374
Ben Hutchings7c431612012-01-27 17:23:58 +00003375 /* Try to create MTDs, but allow this to fail */
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003376 rtnl_lock();
Ben Hutchings7c431612012-01-27 17:23:58 +00003377 rc = efx_mtd_probe(efx);
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003378 rtnl_unlock();
Bert Kenward09a04202015-12-23 08:58:15 +00003379 if (rc && rc != -EPERM)
Ben Hutchings7c431612012-01-27 17:23:58 +00003380 netif_warn(efx, probe, efx->net_dev,
3381 "failed to create MTDs (%d)\n", rc);
3382
Alexandre Rames626950d2013-01-14 17:20:22 +00003383 rc = pci_enable_pcie_error_reporting(pci_dev);
3384 if (rc && rc != -EINVAL)
Bert Kenward09a04202015-12-23 08:58:15 +00003385 netif_notice(efx, probe, efx->net_dev,
3386 "PCIE error reporting unavailable (%d).\n",
3387 rc);
Alexandre Rames626950d2013-01-14 17:20:22 +00003388
Jon Coopere5fbd972017-02-08 16:52:10 +00003389 if (efx->type->udp_tnl_push_ports)
3390 efx->type->udp_tnl_push_ports(efx);
3391
Ben Hutchings8ceee662008-04-27 12:55:59 +01003392 return 0;
3393
Ben Hutchings8ceee662008-04-27 12:55:59 +01003394 fail3:
3395 efx_fini_io(efx);
3396 fail2:
3397 efx_fini_struct(efx);
3398 fail1:
Steve Hodgson5e2a9112010-02-12 12:32:27 -08003399 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00003400 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003401 free_netdev(net_dev);
3402 return rc;
3403}
3404
Shradha Shah834e23d2015-05-06 00:55:58 +01003405/* efx_pci_sriov_configure returns the actual number of Virtual Functions
3406 * enabled on success
3407 */
3408#ifdef CONFIG_SFC_SRIOV
3409static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
3410{
3411 int rc;
3412 struct efx_nic *efx = pci_get_drvdata(dev);
3413
3414 if (efx->type->sriov_configure) {
3415 rc = efx->type->sriov_configure(efx, num_vfs);
3416 if (rc)
3417 return rc;
3418 else
3419 return num_vfs;
3420 } else
3421 return -EOPNOTSUPP;
3422}
3423#endif
3424
Ben Hutchings89c758f2009-11-29 03:43:07 +00003425static int efx_pm_freeze(struct device *dev)
3426{
3427 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3428
Ben Hutchings61da0262012-07-27 19:35:39 +01003429 rtnl_lock();
3430
Ben Hutchings6032fb52012-07-27 19:35:47 +01003431 if (efx->state != STATE_DISABLED) {
3432 efx->state = STATE_UNINIT;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003433
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01003434 efx_device_detach_sync(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003435
Ben Hutchings6032fb52012-07-27 19:35:47 +01003436 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003437 efx_disable_interrupts(efx);
Ben Hutchings6032fb52012-07-27 19:35:47 +01003438 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003439
Ben Hutchings61da0262012-07-27 19:35:39 +01003440 rtnl_unlock();
3441
Ben Hutchings89c758f2009-11-29 03:43:07 +00003442 return 0;
3443}
3444
3445static int efx_pm_thaw(struct device *dev)
3446{
Jon Cooper261e4d92013-04-15 18:51:54 +01003447 int rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003448 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3449
Ben Hutchings61da0262012-07-27 19:35:39 +01003450 rtnl_lock();
3451
Ben Hutchings6032fb52012-07-27 19:35:47 +01003452 if (efx->state != STATE_DISABLED) {
Jon Cooper261e4d92013-04-15 18:51:54 +01003453 rc = efx_enable_interrupts(efx);
3454 if (rc)
3455 goto fail;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003456
Ben Hutchings6032fb52012-07-27 19:35:47 +01003457 mutex_lock(&efx->mac_lock);
3458 efx->phy_op->reconfigure(efx);
3459 mutex_unlock(&efx->mac_lock);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003460
Ben Hutchings6032fb52012-07-27 19:35:47 +01003461 efx_start_all(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003462
Peter Dunning9c568fd2017-02-17 15:50:43 +00003463 efx_device_attach_if_not_resetting(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003464
Ben Hutchings6032fb52012-07-27 19:35:47 +01003465 efx->state = STATE_READY;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003466
Ben Hutchings6032fb52012-07-27 19:35:47 +01003467 efx->type->resume_wol(efx);
3468 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003469
Ben Hutchings61da0262012-07-27 19:35:39 +01003470 rtnl_unlock();
3471
Steve Hodgson319ba642010-06-01 11:17:24 +00003472 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
3473 queue_work(reset_workqueue, &efx->reset_work);
3474
Ben Hutchings89c758f2009-11-29 03:43:07 +00003475 return 0;
Jon Cooper261e4d92013-04-15 18:51:54 +01003476
3477fail:
3478 rtnl_unlock();
3479
3480 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003481}
3482
3483static int efx_pm_poweroff(struct device *dev)
3484{
3485 struct pci_dev *pci_dev = to_pci_dev(dev);
3486 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3487
3488 efx->type->fini(efx);
3489
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01003490 efx->reset_pending = 0;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003491
3492 pci_save_state(pci_dev);
3493 return pci_set_power_state(pci_dev, PCI_D3hot);
3494}
3495
3496/* Used for both resume and restore */
3497static int efx_pm_resume(struct device *dev)
3498{
3499 struct pci_dev *pci_dev = to_pci_dev(dev);
3500 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3501 int rc;
3502
3503 rc = pci_set_power_state(pci_dev, PCI_D0);
3504 if (rc)
3505 return rc;
3506 pci_restore_state(pci_dev);
3507 rc = pci_enable_device(pci_dev);
3508 if (rc)
3509 return rc;
3510 pci_set_master(efx->pci_dev);
3511 rc = efx->type->reset(efx, RESET_TYPE_ALL);
3512 if (rc)
3513 return rc;
3514 rc = efx->type->init(efx);
3515 if (rc)
3516 return rc;
Jon Cooper261e4d92013-04-15 18:51:54 +01003517 rc = efx_pm_thaw(dev);
3518 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003519}
3520
3521static int efx_pm_suspend(struct device *dev)
3522{
3523 int rc;
3524
3525 efx_pm_freeze(dev);
3526 rc = efx_pm_poweroff(dev);
3527 if (rc)
3528 efx_pm_resume(dev);
3529 return rc;
3530}
3531
Ben Hutchings18e83e42012-01-05 19:05:20 +00003532static const struct dev_pm_ops efx_pm_ops = {
Ben Hutchings89c758f2009-11-29 03:43:07 +00003533 .suspend = efx_pm_suspend,
3534 .resume = efx_pm_resume,
3535 .freeze = efx_pm_freeze,
3536 .thaw = efx_pm_thaw,
3537 .poweroff = efx_pm_poweroff,
3538 .restore = efx_pm_resume,
3539};
3540
Alexandre Rames626950d2013-01-14 17:20:22 +00003541/* A PCI error affecting this device was detected.
3542 * At this point MMIO and DMA may be disabled.
3543 * Stop the software path and request a slot reset.
3544 */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003545static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
3546 enum pci_channel_state state)
Alexandre Rames626950d2013-01-14 17:20:22 +00003547{
3548 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3549 struct efx_nic *efx = pci_get_drvdata(pdev);
3550
3551 if (state == pci_channel_io_perm_failure)
3552 return PCI_ERS_RESULT_DISCONNECT;
3553
3554 rtnl_lock();
3555
3556 if (efx->state != STATE_DISABLED) {
3557 efx->state = STATE_RECOVERY;
3558 efx->reset_pending = 0;
3559
3560 efx_device_detach_sync(efx);
3561
3562 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003563 efx_disable_interrupts(efx);
Alexandre Rames626950d2013-01-14 17:20:22 +00003564
3565 status = PCI_ERS_RESULT_NEED_RESET;
3566 } else {
3567 /* If the interface is disabled we don't want to do anything
3568 * with it.
3569 */
3570 status = PCI_ERS_RESULT_RECOVERED;
3571 }
3572
3573 rtnl_unlock();
3574
3575 pci_disable_device(pdev);
3576
3577 return status;
3578}
3579
Joe Perchesdbedd442015-03-06 20:49:12 -08003580/* Fake a successful reset, which will be performed later in efx_io_resume. */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003581static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
Alexandre Rames626950d2013-01-14 17:20:22 +00003582{
3583 struct efx_nic *efx = pci_get_drvdata(pdev);
3584 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3585 int rc;
3586
3587 if (pci_enable_device(pdev)) {
3588 netif_err(efx, hw, efx->net_dev,
3589 "Cannot re-enable PCI device after reset.\n");
3590 status = PCI_ERS_RESULT_DISCONNECT;
3591 }
3592
3593 rc = pci_cleanup_aer_uncorrect_error_status(pdev);
3594 if (rc) {
3595 netif_err(efx, hw, efx->net_dev,
3596 "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
3597 /* Non-fatal error. Continue. */
3598 }
3599
3600 return status;
3601}
3602
3603/* Perform the actual reset and resume I/O operations. */
3604static void efx_io_resume(struct pci_dev *pdev)
3605{
3606 struct efx_nic *efx = pci_get_drvdata(pdev);
3607 int rc;
3608
3609 rtnl_lock();
3610
3611 if (efx->state == STATE_DISABLED)
3612 goto out;
3613
3614 rc = efx_reset(efx, RESET_TYPE_ALL);
3615 if (rc) {
3616 netif_err(efx, hw, efx->net_dev,
3617 "efx_reset failed after PCI error (%d)\n", rc);
3618 } else {
3619 efx->state = STATE_READY;
3620 netif_dbg(efx, hw, efx->net_dev,
3621 "Done resetting and resuming IO after PCI error.\n");
3622 }
3623
3624out:
3625 rtnl_unlock();
3626}
3627
3628/* For simplicity and reliability, we always require a slot reset and try to
3629 * reset the hardware when a pci error affecting the device is detected.
3630 * We leave both the link_reset and mmio_enabled callback unimplemented:
3631 * with our request for slot reset the mmio_enabled callback will never be
3632 * called, and the link_reset callback is not used by AER or EEH mechanisms.
3633 */
Julia Lawallc300366b2015-11-14 11:06:57 +01003634static const struct pci_error_handlers efx_err_handlers = {
Alexandre Rames626950d2013-01-14 17:20:22 +00003635 .error_detected = efx_io_error_detected,
3636 .slot_reset = efx_io_slot_reset,
3637 .resume = efx_io_resume,
3638};
3639
Ben Hutchings8ceee662008-04-27 12:55:59 +01003640static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00003641 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003642 .id_table = efx_pci_table,
3643 .probe = efx_pci_probe,
3644 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00003645 .driver.pm = &efx_pm_ops,
Alexandre Rames626950d2013-01-14 17:20:22 +00003646 .err_handler = &efx_err_handlers,
Shradha Shah834e23d2015-05-06 00:55:58 +01003647#ifdef CONFIG_SFC_SRIOV
3648 .sriov_configure = efx_pci_sriov_configure,
3649#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003650};
3651
3652/**************************************************************************
3653 *
3654 * Kernel module interface
3655 *
3656 *************************************************************************/
3657
3658module_param(interrupt_mode, uint, 0444);
3659MODULE_PARM_DESC(interrupt_mode,
3660 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3661
3662static int __init efx_init_module(void)
3663{
3664 int rc;
3665
3666 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
3667
3668 rc = register_netdevice_notifier(&efx_netdev_notifier);
3669 if (rc)
3670 goto err_notifier;
3671
Shradha Shah7fa8d542015-05-06 00:55:13 +01003672#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003673 rc = efx_init_sriov();
3674 if (rc)
3675 goto err_sriov;
Shradha Shah7fa8d542015-05-06 00:55:13 +01003676#endif
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003677
Steve Hodgson1ab00622008-12-12 21:33:02 -08003678 reset_workqueue = create_singlethread_workqueue("sfc_reset");
3679 if (!reset_workqueue) {
3680 rc = -ENOMEM;
3681 goto err_reset;
3682 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003683
3684 rc = pci_register_driver(&efx_pci_driver);
3685 if (rc < 0)
3686 goto err_pci;
3687
3688 return 0;
3689
3690 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08003691 destroy_workqueue(reset_workqueue);
3692 err_reset:
Shradha Shah7fa8d542015-05-06 00:55:13 +01003693#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003694 efx_fini_sriov();
3695 err_sriov:
Shradha Shah7fa8d542015-05-06 00:55:13 +01003696#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003697 unregister_netdevice_notifier(&efx_netdev_notifier);
3698 err_notifier:
3699 return rc;
3700}
3701
3702static void __exit efx_exit_module(void)
3703{
3704 printk(KERN_INFO "Solarflare NET driver unloading\n");
3705
3706 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08003707 destroy_workqueue(reset_workqueue);
Shradha Shah7fa8d542015-05-06 00:55:13 +01003708#ifdef CONFIG_SFC_SRIOV
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003709 efx_fini_sriov();
Shradha Shah7fa8d542015-05-06 00:55:13 +01003710#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01003711 unregister_netdevice_notifier(&efx_netdev_notifier);
3712
3713}
3714
3715module_init(efx_init_module);
3716module_exit(efx_exit_module);
3717
Ben Hutchings906bb262009-11-29 15:16:19 +00003718MODULE_AUTHOR("Solarflare Communications and "
3719 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings6a350fd2014-02-12 19:00:07 +00003720MODULE_DESCRIPTION("Solarflare network driver");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003721MODULE_LICENSE("GPL");
3722MODULE_DEVICE_TABLE(pci, efx_pci_table);
Edward Cree14077e92017-01-03 15:46:00 +00003723MODULE_VERSION(EFX_DRIVER_VERSION);