blob: 2236ffc6de32250402a8f2db0b60684c5734b049 [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"
Ben Hutchings8ceee662008-04-27 12:55:59 +010026#include "efx.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000027#include "nic.h"
Ben Hutchingsdd407812012-02-28 23:40:21 +000028#include "selftest.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010029
Ben Hutchings8880f4e2009-11-29 15:15:41 +000030#include "mcdi.h"
Steve Hodgsonfd371e32010-06-01 11:17:51 +000031#include "workarounds.h"
Ben Hutchings8880f4e2009-11-29 15:15:41 +000032
Ben Hutchingsc4593022009-11-23 16:08:17 +000033/**************************************************************************
34 *
35 * Type name strings
36 *
37 **************************************************************************
38 */
39
40/* Loopback mode names (see LOOPBACK_MODE()) */
41const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
Ben Hutchings18e83e42012-01-05 19:05:20 +000042const char *const efx_loopback_mode_names[] = {
Ben Hutchingsc4593022009-11-23 16:08:17 +000043 [LOOPBACK_NONE] = "NONE",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000044 [LOOPBACK_DATA] = "DATAPATH",
Ben Hutchingsc4593022009-11-23 16:08:17 +000045 [LOOPBACK_GMAC] = "GMAC",
46 [LOOPBACK_XGMII] = "XGMII",
47 [LOOPBACK_XGXS] = "XGXS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000048 [LOOPBACK_XAUI] = "XAUI",
49 [LOOPBACK_GMII] = "GMII",
50 [LOOPBACK_SGMII] = "SGMII",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000051 [LOOPBACK_XGBR] = "XGBR",
52 [LOOPBACK_XFI] = "XFI",
53 [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
54 [LOOPBACK_GMII_FAR] = "GMII_FAR",
55 [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
56 [LOOPBACK_XFI_FAR] = "XFI_FAR",
Ben Hutchingsc4593022009-11-23 16:08:17 +000057 [LOOPBACK_GPHY] = "GPHY",
58 [LOOPBACK_PHYXS] = "PHYXS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000059 [LOOPBACK_PCS] = "PCS",
60 [LOOPBACK_PMAPMD] = "PMA/PMD",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000061 [LOOPBACK_XPORT] = "XPORT",
62 [LOOPBACK_XGMII_WS] = "XGMII_WS",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000063 [LOOPBACK_XAUI_WS] = "XAUI_WS",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000064 [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
65 [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000066 [LOOPBACK_GMII_WS] = "GMII_WS",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000067 [LOOPBACK_XFI_WS] = "XFI_WS",
68 [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
Ben Hutchings9c636ba2012-01-05 17:19:45 +000069 [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
Ben Hutchingsc4593022009-11-23 16:08:17 +000070};
71
Ben Hutchingsc4593022009-11-23 16:08:17 +000072const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
Ben Hutchings18e83e42012-01-05 19:05:20 +000073const char *const efx_reset_type_names[] = {
Alexandre Rames626950d2013-01-14 17:20:22 +000074 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
75 [RESET_TYPE_ALL] = "ALL",
76 [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
77 [RESET_TYPE_WORLD] = "WORLD",
78 [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
Edward Creee2835462014-04-16 19:27:48 +010079 [RESET_TYPE_MC_BIST] = "MC_BIST",
Alexandre Rames626950d2013-01-14 17:20:22 +000080 [RESET_TYPE_DISABLE] = "DISABLE",
81 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
82 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
83 [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
Alexandre Rames3de82b92013-06-13 11:36:15 +010084 [RESET_TYPE_DMA_ERROR] = "DMA_ERROR",
Alexandre Rames626950d2013-01-14 17:20:22 +000085 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
86 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
Edward Creee2835462014-04-16 19:27:48 +010087 [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)",
Ben Hutchingsc4593022009-11-23 16:08:17 +000088};
89
Steve Hodgson1ab00622008-12-12 21:33:02 -080090/* Reset workqueue. If any NIC has a hardware failure then a reset will be
91 * queued onto this work queue. This is not a per-nic work queue, because
92 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
93 */
94static struct workqueue_struct *reset_workqueue;
95
Jon Cooper74cd60a2013-09-16 14:18:51 +010096/* How often and how many times to poll for a reset while waiting for a
97 * BIST that another function started to complete.
98 */
99#define BIST_WAIT_DELAY_MS 100
100#define BIST_WAIT_DELAY_COUNT 100
101
Ben Hutchings8ceee662008-04-27 12:55:59 +0100102/**************************************************************************
103 *
104 * Configurable values
105 *
106 *************************************************************************/
107
108/*
Ben Hutchings8ceee662008-04-27 12:55:59 +0100109 * Use separate channels for TX and RX events
110 *
Neil Turton28b581a2008-12-12 21:41:06 -0800111 * Set this to 1 to use separate channels for TX and RX. It allows us
112 * to control interrupt affinity separately for TX and RX.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100113 *
Neil Turton28b581a2008-12-12 21:41:06 -0800114 * This is only used in MSI-X interrupt mode
Ben Hutchings8ceee662008-04-27 12:55:59 +0100115 */
Ben Hutchingsb9cc9772012-11-28 04:12:41 +0000116static bool separate_tx_channels;
117module_param(separate_tx_channels, bool, 0444);
Neil Turton28b581a2008-12-12 21:41:06 -0800118MODULE_PARM_DESC(separate_tx_channels,
119 "Use separate channels for TX and RX");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100120
121/* This is the weight assigned to each of the (per-channel) virtual
122 * NAPI devices.
123 */
124static int napi_weight = 64;
125
126/* This is the time (in jiffies) between invocations of the hardware
Alexandre Rames626950d2013-01-14 17:20:22 +0000127 * monitor.
128 * On Falcon-based NICs, this will:
Ben Hutchingse254c272010-09-20 08:44:10 +0000129 * - Check the on-board hardware monitor;
130 * - Poll the link state and reconfigure the hardware as necessary.
Alexandre Rames626950d2013-01-14 17:20:22 +0000131 * On Siena-based NICs for power systems with EEH support, this will give EEH a
132 * chance to start.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133 */
stephen hemmingerd2156972010-10-18 05:27:31 +0000134static unsigned int efx_monitor_interval = 1 * HZ;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100135
Ben Hutchings8ceee662008-04-27 12:55:59 +0100136/* Initial interrupt moderation settings. They can be modified after
137 * module load with ethtool.
138 *
139 * The default for RX should strike a balance between increasing the
140 * round-trip latency and reducing overhead.
141 */
142static unsigned int rx_irq_mod_usec = 60;
143
144/* Initial interrupt moderation settings. They can be modified after
145 * module load with ethtool.
146 *
147 * This default is chosen to ensure that a 10G link does not go idle
148 * while a TX queue is stopped after it has become full. A queue is
149 * restarted when it drops below half full. The time this takes (assuming
150 * worst case 3 descriptors per packet and 1024 descriptors) is
151 * 512 / 3 * 1.2 = 205 usec.
152 */
153static unsigned int tx_irq_mod_usec = 150;
154
155/* This is the first interrupt mode to try out of:
156 * 0 => MSI-X
157 * 1 => MSI
158 * 2 => legacy
159 */
160static unsigned int interrupt_mode;
161
162/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
163 * i.e. the number of CPUs among which we may distribute simultaneous
164 * interrupt handling.
165 *
166 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
Ben Hutchingscdb08f82011-12-20 01:08:05 +0000167 * The default (0) means to assign an interrupt to each core.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100168 */
169static unsigned int rss_cpus;
170module_param(rss_cpus, uint, 0444);
171MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
172
Ben Hutchingsb9cc9772012-11-28 04:12:41 +0000173static bool phy_flash_cfg;
174module_param(phy_flash_cfg, bool, 0644);
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800175MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
176
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000177static unsigned irq_adapt_low_thresh = 8000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000178module_param(irq_adapt_low_thresh, uint, 0644);
179MODULE_PARM_DESC(irq_adapt_low_thresh,
180 "Threshold score for reducing IRQ moderation");
181
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000182static unsigned irq_adapt_high_thresh = 16000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000183module_param(irq_adapt_high_thresh, uint, 0644);
184MODULE_PARM_DESC(irq_adapt_high_thresh,
185 "Threshold score for increasing IRQ moderation");
186
Ben Hutchings62776d02010-06-23 11:30:07 +0000187static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
188 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
189 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
190 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
191module_param(debug, uint, 0);
192MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
193
Ben Hutchings8ceee662008-04-27 12:55:59 +0100194/**************************************************************************
195 *
196 * Utility functions and prototypes
197 *
198 *************************************************************************/
Ben Hutchings46426102010-09-10 06:42:33 +0000199
Jon Cooper261e4d92013-04-15 18:51:54 +0100200static int efx_soft_enable_interrupts(struct efx_nic *efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +0100201static void efx_soft_disable_interrupts(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000202static void efx_remove_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000203static void efx_remove_channels(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000204static const struct efx_channel_type efx_default_channel_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100205static void efx_remove_port(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000206static void efx_init_napi_channel(struct efx_channel *channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100207static void efx_fini_napi(struct efx_nic *efx);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000208static void efx_fini_napi_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000209static void efx_fini_struct(struct efx_nic *efx);
210static void efx_start_all(struct efx_nic *efx);
211static void efx_stop_all(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100212
213#define EFX_ASSERT_RESET_SERIALISED(efx) \
214 do { \
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100215 if ((efx->state == STATE_READY) || \
Alexandre Rames626950d2013-01-14 17:20:22 +0000216 (efx->state == STATE_RECOVERY) || \
Ben Hutchings332c1ce2009-11-25 16:08:52 +0000217 (efx->state == STATE_DISABLED)) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100218 ASSERT_RTNL(); \
219 } while (0)
220
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100221static int efx_check_disabled(struct efx_nic *efx)
222{
Alexandre Rames626950d2013-01-14 17:20:22 +0000223 if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100224 netif_err(efx, drv, efx->net_dev,
225 "device is disabled due to earlier errors\n");
226 return -EIO;
227 }
228 return 0;
229}
230
Ben Hutchings8ceee662008-04-27 12:55:59 +0100231/**************************************************************************
232 *
233 * Event queue processing
234 *
235 *************************************************************************/
236
237/* Process channel's event queue
238 *
239 * This function is responsible for processing the event queue of a
240 * single channel. The caller must guarantee that this function will
241 * never be concurrently called more than once on the same channel,
242 * though different channels may be being processed concurrently.
243 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000244static int efx_process_channel(struct efx_channel *channel, int budget)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100245{
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000246 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100247
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000248 if (unlikely(!channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100249 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100250
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000251 spent = efx_nic_process_eventq(channel, budget);
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000252 if (spent && efx_channel_has_rx_queue(channel)) {
253 struct efx_rx_queue *rx_queue =
254 efx_channel_get_rx_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100255
Ben Hutchingsff734ef2013-01-29 23:33:14 +0000256 efx_rx_flush_packet(channel);
Jon Coopercce28792013-10-02 11:04:14 +0100257 efx_fast_push_rx_descriptors(rx_queue, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100258 }
259
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000260 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100261}
262
Ben Hutchings8ceee662008-04-27 12:55:59 +0100263/* NAPI poll handler
264 *
265 * NAPI guarantees serialisation of polls of the same device, which
266 * provides the guarantee required by efx_process_channel().
267 */
268static int efx_poll(struct napi_struct *napi, int budget)
269{
270 struct efx_channel *channel =
271 container_of(napi, struct efx_channel, napi_str);
Ben Hutchings62776d02010-06-23 11:30:07 +0000272 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000273 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100274
Alexandre Rames36763262014-07-22 14:03:25 +0100275 if (!efx_channel_lock_napi(channel))
276 return budget;
277
Ben Hutchings62776d02010-06-23 11:30:07 +0000278 netif_vdbg(efx, intr, efx->net_dev,
279 "channel %d NAPI poll executing on CPU %d\n",
280 channel->channel, raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +0100281
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000282 spent = efx_process_channel(channel, budget);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100283
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000284 if (spent < budget) {
Ben Hutchings9d9a6972012-02-10 23:01:48 +0000285 if (efx_channel_has_rx_queue(channel) &&
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000286 efx->irq_rx_adaptive &&
287 unlikely(++channel->irq_count == 1000)) {
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000288 if (unlikely(channel->irq_mod_score <
289 irq_adapt_low_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000290 if (channel->irq_moderation > 1) {
291 channel->irq_moderation -= 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000292 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000293 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000294 } else if (unlikely(channel->irq_mod_score >
295 irq_adapt_high_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000296 if (channel->irq_moderation <
297 efx->irq_rx_moderation) {
298 channel->irq_moderation += 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000299 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000300 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000301 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000302 channel->irq_count = 0;
303 channel->irq_mod_score = 0;
304 }
305
Ben Hutchings64d8ad62011-01-05 00:50:41 +0000306 efx_filter_rfs_expire(channel);
307
Ben Hutchings8ceee662008-04-27 12:55:59 +0100308 /* There is no race here; although napi_disable() will
Ben Hutchings288379f2009-01-19 16:43:59 -0800309 * only wait for napi_complete(), this isn't a problem
Ben Hutchings514bedb2012-10-05 19:30:16 +0100310 * since efx_nic_eventq_read_ack() will have no effect if
Ben Hutchings8ceee662008-04-27 12:55:59 +0100311 * interrupts have already been disabled.
312 */
Ben Hutchings288379f2009-01-19 16:43:59 -0800313 napi_complete(napi);
Ben Hutchings514bedb2012-10-05 19:30:16 +0100314 efx_nic_eventq_read_ack(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100315 }
316
Alexandre Rames36763262014-07-22 14:03:25 +0100317 efx_channel_unlock_napi(channel);
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000318 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100319}
320
Ben Hutchings8ceee662008-04-27 12:55:59 +0100321/* Create event queue
322 * Event queue memory allocations are done only once. If the channel
323 * is reset, the memory buffer will be reused; this guards against
324 * errors during channel reset and also simplifies interrupt handling.
325 */
326static int efx_probe_eventq(struct efx_channel *channel)
327{
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000328 struct efx_nic *efx = channel->efx;
329 unsigned long entries;
330
Ben Hutchings86ee5302012-01-09 19:51:22 +0000331 netif_dbg(efx, probe, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000332 "chan %d create event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100333
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000334 /* Build an event queue with room for one event per tx and rx buffer,
335 * plus some extra for link state events and MCDI completions. */
336 entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
337 EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
338 channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
339
Ben Hutchings152b6a62009-11-29 03:43:56 +0000340 return efx_nic_probe_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100341}
342
343/* Prepare channel's event queue */
Jon Cooper261e4d92013-04-15 18:51:54 +0100344static int efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100345{
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100346 struct efx_nic *efx = channel->efx;
Jon Cooper261e4d92013-04-15 18:51:54 +0100347 int rc;
348
349 EFX_WARN_ON_PARANOID(channel->eventq_init);
350
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100351 netif_dbg(efx, drv, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000352 "chan %d init event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100353
Jon Cooper261e4d92013-04-15 18:51:54 +0100354 rc = efx_nic_init_eventq(channel);
355 if (rc == 0) {
Ben Hutchings15acb1c2013-05-01 16:30:17 +0100356 efx->type->push_irq_moderation(channel);
Jon Cooper261e4d92013-04-15 18:51:54 +0100357 channel->eventq_read_ptr = 0;
358 channel->eventq_init = true;
359 }
360 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100361}
362
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000363/* Enable event queue processing and NAPI */
Alexandre Rames36763262014-07-22 14:03:25 +0100364void efx_start_eventq(struct efx_channel *channel)
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000365{
366 netif_dbg(channel->efx, ifup, channel->efx->net_dev,
367 "chan %d start event queue\n", channel->channel);
368
Ben Hutchings514bedb2012-10-05 19:30:16 +0100369 /* Make sure the NAPI handler sees the enabled flag set */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000370 channel->enabled = true;
371 smp_wmb();
372
Alexandre Rames36763262014-07-22 14:03:25 +0100373 efx_channel_enable(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000374 napi_enable(&channel->napi_str);
375 efx_nic_eventq_read_ack(channel);
376}
377
378/* Disable event queue processing and NAPI */
Alexandre Rames36763262014-07-22 14:03:25 +0100379void efx_stop_eventq(struct efx_channel *channel)
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000380{
381 if (!channel->enabled)
382 return;
383
384 napi_disable(&channel->napi_str);
Alexandre Rames36763262014-07-22 14:03:25 +0100385 while (!efx_channel_disable(channel))
386 usleep_range(1000, 20000);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000387 channel->enabled = false;
388}
389
Ben Hutchings8ceee662008-04-27 12:55:59 +0100390static void efx_fini_eventq(struct efx_channel *channel)
391{
Ben Hutchingsbe3fc092012-10-08 18:21:51 +0100392 if (!channel->eventq_init)
393 return;
394
Ben Hutchings62776d02010-06-23 11:30:07 +0000395 netif_dbg(channel->efx, drv, channel->efx->net_dev,
396 "chan %d fini event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397
Ben Hutchings152b6a62009-11-29 03:43:56 +0000398 efx_nic_fini_eventq(channel);
Ben Hutchingsbe3fc092012-10-08 18:21:51 +0100399 channel->eventq_init = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100400}
401
402static void efx_remove_eventq(struct efx_channel *channel)
403{
Ben Hutchings62776d02010-06-23 11:30:07 +0000404 netif_dbg(channel->efx, drv, channel->efx->net_dev,
405 "chan %d remove event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406
Ben Hutchings152b6a62009-11-29 03:43:56 +0000407 efx_nic_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100408}
409
410/**************************************************************************
411 *
412 * Channel handling
413 *
414 *************************************************************************/
415
Ben Hutchings7f967c02012-02-13 23:45:02 +0000416/* Allocate and initialise a channel structure. */
Ben Hutchings46426102010-09-10 06:42:33 +0000417static struct efx_channel *
418efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
419{
420 struct efx_channel *channel;
421 struct efx_rx_queue *rx_queue;
422 struct efx_tx_queue *tx_queue;
423 int j;
424
Ben Hutchings7f967c02012-02-13 23:45:02 +0000425 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
426 if (!channel)
427 return NULL;
Ben Hutchings46426102010-09-10 06:42:33 +0000428
Ben Hutchings7f967c02012-02-13 23:45:02 +0000429 channel->efx = efx;
430 channel->channel = i;
431 channel->type = &efx_default_channel_type;
Ben Hutchings46426102010-09-10 06:42:33 +0000432
Ben Hutchings7f967c02012-02-13 23:45:02 +0000433 for (j = 0; j < EFX_TXQ_TYPES; j++) {
434 tx_queue = &channel->tx_queue[j];
435 tx_queue->efx = efx;
436 tx_queue->queue = i * EFX_TXQ_TYPES + j;
437 tx_queue->channel = channel;
Ben Hutchings46426102010-09-10 06:42:33 +0000438 }
439
Ben Hutchings46426102010-09-10 06:42:33 +0000440 rx_queue = &channel->rx_queue;
441 rx_queue->efx = efx;
442 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
443 (unsigned long)rx_queue);
444
445 return channel;
446}
447
Ben Hutchings7f967c02012-02-13 23:45:02 +0000448/* Allocate and initialise a channel structure, copying parameters
449 * (but not resources) from an old channel structure.
450 */
451static struct efx_channel *
452efx_copy_channel(const struct efx_channel *old_channel)
453{
454 struct efx_channel *channel;
455 struct efx_rx_queue *rx_queue;
456 struct efx_tx_queue *tx_queue;
457 int j;
458
459 channel = kmalloc(sizeof(*channel), GFP_KERNEL);
460 if (!channel)
461 return NULL;
462
463 *channel = *old_channel;
464
465 channel->napi_dev = NULL;
466 memset(&channel->eventq, 0, sizeof(channel->eventq));
467
468 for (j = 0; j < EFX_TXQ_TYPES; j++) {
469 tx_queue = &channel->tx_queue[j];
470 if (tx_queue->channel)
471 tx_queue->channel = channel;
472 tx_queue->buffer = NULL;
473 memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
474 }
475
476 rx_queue = &channel->rx_queue;
477 rx_queue->buffer = NULL;
478 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
479 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
480 (unsigned long)rx_queue);
481
482 return channel;
483}
484
Ben Hutchings8ceee662008-04-27 12:55:59 +0100485static int efx_probe_channel(struct efx_channel *channel)
486{
487 struct efx_tx_queue *tx_queue;
488 struct efx_rx_queue *rx_queue;
489 int rc;
490
Ben Hutchings62776d02010-06-23 11:30:07 +0000491 netif_dbg(channel->efx, probe, channel->efx->net_dev,
492 "creating channel %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100493
Ben Hutchings7f967c02012-02-13 23:45:02 +0000494 rc = channel->type->pre_probe(channel);
495 if (rc)
496 goto fail;
497
Ben Hutchings8ceee662008-04-27 12:55:59 +0100498 rc = efx_probe_eventq(channel);
499 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000500 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100501
502 efx_for_each_channel_tx_queue(tx_queue, channel) {
503 rc = efx_probe_tx_queue(tx_queue);
504 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000505 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100506 }
507
508 efx_for_each_channel_rx_queue(rx_queue, channel) {
509 rc = efx_probe_rx_queue(rx_queue);
510 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000511 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100512 }
513
Ben Hutchings8ceee662008-04-27 12:55:59 +0100514 return 0;
515
Ben Hutchings7f967c02012-02-13 23:45:02 +0000516fail:
517 efx_remove_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100518 return rc;
519}
520
Ben Hutchings7f967c02012-02-13 23:45:02 +0000521static void
522efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
523{
524 struct efx_nic *efx = channel->efx;
525 const char *type;
526 int number;
527
528 number = channel->channel;
529 if (efx->tx_channel_offset == 0) {
530 type = "";
531 } else if (channel->channel < efx->tx_channel_offset) {
532 type = "-rx";
533 } else {
534 type = "-tx";
535 number -= efx->tx_channel_offset;
536 }
537 snprintf(buf, len, "%s%s-%d", efx->name, type, number);
538}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100539
Ben Hutchings56536e92008-12-12 21:37:02 -0800540static void efx_set_channel_names(struct efx_nic *efx)
541{
542 struct efx_channel *channel;
Ben Hutchings56536e92008-12-12 21:37:02 -0800543
Ben Hutchings7f967c02012-02-13 23:45:02 +0000544 efx_for_each_channel(channel, efx)
545 channel->type->get_name(channel,
Ben Hutchingsd8291182012-10-05 23:35:41 +0100546 efx->msi_context[channel->channel].name,
547 sizeof(efx->msi_context[0].name));
Ben Hutchings56536e92008-12-12 21:37:02 -0800548}
549
Ben Hutchings46426102010-09-10 06:42:33 +0000550static int efx_probe_channels(struct efx_nic *efx)
551{
552 struct efx_channel *channel;
553 int rc;
554
555 /* Restart special buffer allocation */
556 efx->next_buffer_table = 0;
557
Ben Hutchingsc92aaff2012-02-21 23:22:00 +0000558 /* Probe channels in reverse, so that any 'extra' channels
559 * use the start of the buffer table. This allows the traffic
560 * channels to be resized without moving them or wasting the
561 * entries before them.
562 */
563 efx_for_each_channel_rev(channel, efx) {
Ben Hutchings46426102010-09-10 06:42:33 +0000564 rc = efx_probe_channel(channel);
565 if (rc) {
566 netif_err(efx, probe, efx->net_dev,
567 "failed to create channel %d\n",
568 channel->channel);
569 goto fail;
570 }
571 }
572 efx_set_channel_names(efx);
573
574 return 0;
575
576fail:
577 efx_remove_channels(efx);
578 return rc;
579}
580
Ben Hutchings8ceee662008-04-27 12:55:59 +0100581/* Channels are shutdown and reinitialised whilst the NIC is running
582 * to propagate configuration changes (mtu, checksum offload), or
583 * to clear hardware error conditions
584 */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000585static void efx_start_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100586{
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000587 bool old_rx_scatter = efx->rx_scatter;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100588 struct efx_tx_queue *tx_queue;
589 struct efx_rx_queue *rx_queue;
590 struct efx_channel *channel;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000591 size_t rx_buf_len;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100592
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100593 /* Calculate the rx buffer allocation parameters required to
594 * support the current MTU, including padding for header
595 * alignment and overruns.
596 */
Jon Cooper43a37392012-10-18 15:49:54 +0100597 efx->rx_dma_len = (efx->rx_prefix_size +
Ben Hutchings272baee2013-01-29 23:33:14 +0000598 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
599 efx->type->rx_buffer_padding);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000600 rx_buf_len = (sizeof(struct efx_rx_page_state) +
Andrew Rybchenko2ec03012013-11-16 11:02:27 +0400601 efx->rx_ip_align + efx->rx_dma_len);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000602 if (rx_buf_len <= PAGE_SIZE) {
Jon Coopere8c68c02013-03-08 10:18:28 +0000603 efx->rx_scatter = efx->type->always_rx_scatter;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000604 efx->rx_buffer_order = 0;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000605 } else if (efx->type->can_rx_scatter) {
Ben Hutchings950c54d2013-05-13 12:01:22 +0000606 BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000607 BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
Ben Hutchings950c54d2013-05-13 12:01:22 +0000608 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
609 EFX_RX_BUF_ALIGNMENT) >
610 PAGE_SIZE);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000611 efx->rx_scatter = true;
612 efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
613 efx->rx_buffer_order = 0;
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000614 } else {
615 efx->rx_scatter = false;
616 efx->rx_buffer_order = get_order(rx_buf_len);
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000617 }
618
Daniel Pieczko1648a232013-02-13 10:54:41 +0000619 efx_rx_config_page_split(efx);
620 if (efx->rx_buffer_order)
621 netif_dbg(efx, drv, efx->net_dev,
622 "RX buf len=%u; page order=%u batch=%u\n",
623 efx->rx_dma_len, efx->rx_buffer_order,
624 efx->rx_pages_per_batch);
625 else
626 netif_dbg(efx, drv, efx->net_dev,
627 "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
628 efx->rx_dma_len, efx->rx_page_buf_step,
629 efx->rx_bufs_per_page, efx->rx_pages_per_batch);
Daniel Pieczko27689352013-02-13 10:54:41 +0000630
Jon Coopere8c68c02013-03-08 10:18:28 +0000631 /* RX filters may also have scatter-enabled flags */
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000632 if (efx->rx_scatter != old_rx_scatter)
Ben Hutchingsadd72472012-11-08 01:46:53 +0000633 efx->type->filter_update_rx_scatter(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100634
Ben Hutchings14bf7182012-05-22 01:27:58 +0100635 /* We must keep at least one descriptor in a TX ring empty.
636 * We could avoid this when the queue size does not exactly
637 * match the hardware ring size, but it's not that important.
638 * Therefore we stop the queue when one more skb might fill
639 * the ring completely. We wake it when half way back to
640 * empty.
641 */
642 efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
643 efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
644
Ben Hutchings8ceee662008-04-27 12:55:59 +0100645 /* Initialise the channels */
646 efx_for_each_channel(channel, efx) {
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100647 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100648 efx_init_tx_queue(tx_queue);
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100649 atomic_inc(&efx->active_queues);
650 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100651
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000652 efx_for_each_channel_rx_queue(rx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100653 efx_init_rx_queue(rx_queue);
Alexandre Rames3881d8a2013-06-10 11:03:21 +0100654 atomic_inc(&efx->active_queues);
Jon Coopercce28792013-10-02 11:04:14 +0100655 efx_stop_eventq(channel);
656 efx_fast_push_rx_descriptors(rx_queue, false);
657 efx_start_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000658 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100659
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000660 WARN_ON(channel->rx_pkt_n_frags);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100661 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000662
Alexandre Rames2ea4dc22013-11-08 10:20:31 +0000663 efx_ptp_start_datapath(efx);
664
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000665 if (netif_device_present(efx->net_dev))
666 netif_tx_wake_all_queues(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100667}
668
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000669static void efx_stop_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100670{
671 struct efx_channel *channel;
672 struct efx_tx_queue *tx_queue;
673 struct efx_rx_queue *rx_queue;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100674 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100675
676 EFX_ASSERT_RESET_SERIALISED(efx);
677 BUG_ON(efx->port_enabled);
678
Alexandre Rames2ea4dc22013-11-08 10:20:31 +0000679 efx_ptp_stop_datapath(efx);
680
Ben Hutchingsd8aec742013-05-27 16:52:54 +0100681 /* Stop RX refill */
682 efx_for_each_channel(channel, efx) {
683 efx_for_each_channel_rx_queue(rx_queue, channel)
684 rx_queue->refill_enabled = false;
685 }
686
Ben Hutchings8ceee662008-04-27 12:55:59 +0100687 efx_for_each_channel(channel, efx) {
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000688 /* RX packet processing is pipelined, so wait for the
689 * NAPI handler to complete. At least event queue 0
690 * might be kept active by non-data events, so don't
691 * use napi_synchronize() but actually disable NAPI
692 * temporarily.
693 */
694 if (efx_channel_has_rx_queue(channel)) {
695 efx_stop_eventq(channel);
696 efx_start_eventq(channel);
697 }
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100698 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100699
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100700 rc = efx->type->fini_dmaq(efx);
701 if (rc && EFX_WORKAROUND_7803(efx)) {
702 /* Schedule a reset to recover from the flush failure. The
703 * descriptor caches reference memory we're about to free,
704 * but falcon_reconfigure_mac_wrapper() won't reconnect
705 * the MACs because of the pending reset.
706 */
707 netif_err(efx, drv, efx->net_dev,
708 "Resetting to recover from flush failure\n");
709 efx_schedule_reset(efx, RESET_TYPE_ALL);
710 } else if (rc) {
711 netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
712 } else {
713 netif_dbg(efx, drv, efx->net_dev,
714 "successfully flushed all queues\n");
715 }
716
717 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100718 efx_for_each_channel_rx_queue(rx_queue, channel)
719 efx_fini_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000720 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100721 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100722 }
723}
724
725static void efx_remove_channel(struct efx_channel *channel)
726{
727 struct efx_tx_queue *tx_queue;
728 struct efx_rx_queue *rx_queue;
729
Ben Hutchings62776d02010-06-23 11:30:07 +0000730 netif_dbg(channel->efx, drv, channel->efx->net_dev,
731 "destroy chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100732
733 efx_for_each_channel_rx_queue(rx_queue, channel)
734 efx_remove_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000735 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100736 efx_remove_tx_queue(tx_queue);
737 efx_remove_eventq(channel);
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100738 channel->type->post_remove(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739}
740
Ben Hutchings46426102010-09-10 06:42:33 +0000741static void efx_remove_channels(struct efx_nic *efx)
742{
743 struct efx_channel *channel;
744
745 efx_for_each_channel(channel, efx)
746 efx_remove_channel(channel);
747}
748
749int
750efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
751{
752 struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
753 u32 old_rxq_entries, old_txq_entries;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000754 unsigned i, next_buffer_table = 0;
Jon Cooper261e4d92013-04-15 18:51:54 +0100755 int rc, rc2;
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100756
757 rc = efx_check_disabled(efx);
758 if (rc)
759 return rc;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000760
761 /* Not all channels should be reallocated. We must avoid
762 * reallocating their buffer table entries.
763 */
764 efx_for_each_channel(channel, efx) {
765 struct efx_rx_queue *rx_queue;
766 struct efx_tx_queue *tx_queue;
767
768 if (channel->type->copy)
769 continue;
770 next_buffer_table = max(next_buffer_table,
771 channel->eventq.index +
772 channel->eventq.entries);
773 efx_for_each_channel_rx_queue(rx_queue, channel)
774 next_buffer_table = max(next_buffer_table,
775 rx_queue->rxd.index +
776 rx_queue->rxd.entries);
777 efx_for_each_channel_tx_queue(tx_queue, channel)
778 next_buffer_table = max(next_buffer_table,
779 tx_queue->txd.index +
780 tx_queue->txd.entries);
781 }
Ben Hutchings46426102010-09-10 06:42:33 +0000782
Ben Hutchings29c69a42013-01-28 19:01:06 +0000783 efx_device_detach_sync(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000784 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +0100785 efx_soft_disable_interrupts(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000786
Ben Hutchings7f967c02012-02-13 23:45:02 +0000787 /* Clone channels (where possible) */
Ben Hutchings46426102010-09-10 06:42:33 +0000788 memset(other_channel, 0, sizeof(other_channel));
789 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000790 channel = efx->channel[i];
791 if (channel->type->copy)
792 channel = channel->type->copy(channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000793 if (!channel) {
794 rc = -ENOMEM;
795 goto out;
796 }
797 other_channel[i] = channel;
798 }
799
800 /* Swap entry counts and channel pointers */
801 old_rxq_entries = efx->rxq_entries;
802 old_txq_entries = efx->txq_entries;
803 efx->rxq_entries = rxq_entries;
804 efx->txq_entries = txq_entries;
805 for (i = 0; i < efx->n_channels; i++) {
806 channel = efx->channel[i];
807 efx->channel[i] = other_channel[i];
808 other_channel[i] = channel;
809 }
810
Ben Hutchings7f967c02012-02-13 23:45:02 +0000811 /* Restart buffer table allocation */
812 efx->next_buffer_table = next_buffer_table;
Ben Hutchings46426102010-09-10 06:42:33 +0000813
Ben Hutchingse8f14992010-12-07 19:47:34 +0000814 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000815 channel = efx->channel[i];
816 if (!channel->type->copy)
817 continue;
818 rc = efx_probe_channel(channel);
819 if (rc)
820 goto rollback;
821 efx_init_napi_channel(efx->channel[i]);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000822 }
Ben Hutchings46426102010-09-10 06:42:33 +0000823
Ben Hutchings7f967c02012-02-13 23:45:02 +0000824out:
825 /* Destroy unused channel structures */
826 for (i = 0; i < efx->n_channels; i++) {
827 channel = other_channel[i];
828 if (channel && channel->type->copy) {
829 efx_fini_napi_channel(channel);
830 efx_remove_channel(channel);
831 kfree(channel);
832 }
833 }
834
Jon Cooper261e4d92013-04-15 18:51:54 +0100835 rc2 = efx_soft_enable_interrupts(efx);
836 if (rc2) {
837 rc = rc ? rc : rc2;
838 netif_err(efx, drv, efx->net_dev,
839 "unable to restart interrupts on channel reallocation\n");
840 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
841 } else {
842 efx_start_all(efx);
843 netif_device_attach(efx->net_dev);
844 }
Ben Hutchings46426102010-09-10 06:42:33 +0000845 return rc;
846
847rollback:
848 /* Swap back */
849 efx->rxq_entries = old_rxq_entries;
850 efx->txq_entries = old_txq_entries;
851 for (i = 0; i < efx->n_channels; i++) {
852 channel = efx->channel[i];
853 efx->channel[i] = other_channel[i];
854 other_channel[i] = channel;
855 }
856 goto out;
857}
858
Steve Hodgson90d683a2010-06-01 11:19:39 +0000859void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100860{
Steve Hodgson90d683a2010-06-01 11:19:39 +0000861 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100862}
863
Ben Hutchings7f967c02012-02-13 23:45:02 +0000864static const struct efx_channel_type efx_default_channel_type = {
865 .pre_probe = efx_channel_dummy_op_int,
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100866 .post_remove = efx_channel_dummy_op_void,
Ben Hutchings7f967c02012-02-13 23:45:02 +0000867 .get_name = efx_get_channel_name,
868 .copy = efx_copy_channel,
869 .keep_eventq = false,
870};
871
872int efx_channel_dummy_op_int(struct efx_channel *channel)
873{
874 return 0;
875}
876
Stuart Hodgsonc31e5f92012-07-18 09:52:11 +0100877void efx_channel_dummy_op_void(struct efx_channel *channel)
878{
879}
880
Ben Hutchings8ceee662008-04-27 12:55:59 +0100881/**************************************************************************
882 *
883 * Port handling
884 *
885 **************************************************************************/
886
887/* This ensures that the kernel is kept informed (via
888 * netif_carrier_on/off) of the link status, and also maintains the
889 * link status's stop on the port's TX queue.
890 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000891void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100892{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000893 struct efx_link_state *link_state = &efx->link_state;
894
Ben Hutchings8ceee662008-04-27 12:55:59 +0100895 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
896 * that no events are triggered between unregister_netdev() and the
897 * driver unloading. A more general condition is that NETDEV_CHANGE
898 * can only be generated between NETDEV_UP and NETDEV_DOWN */
899 if (!netif_running(efx->net_dev))
900 return;
901
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000902 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100903 efx->n_link_state_changes++;
904
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000905 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100906 netif_carrier_on(efx->net_dev);
907 else
908 netif_carrier_off(efx->net_dev);
909 }
910
911 /* Status message for kernel log */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000912 if (link_state->up)
Ben Hutchings62776d02010-06-23 11:30:07 +0000913 netif_info(efx, link, efx->net_dev,
Ben Hutchings964e6132012-11-19 23:08:22 +0000914 "link up at %uMbps %s-duplex (MTU %d)\n",
Ben Hutchings62776d02010-06-23 11:30:07 +0000915 link_state->speed, link_state->fd ? "full" : "half",
Ben Hutchings964e6132012-11-19 23:08:22 +0000916 efx->net_dev->mtu);
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000917 else
Ben Hutchings62776d02010-06-23 11:30:07 +0000918 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100919}
920
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000921void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
922{
923 efx->link_advertising = advertising;
924 if (advertising) {
925 if (advertising & ADVERTISED_Pause)
926 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
927 else
928 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
929 if (advertising & ADVERTISED_Asym_Pause)
930 efx->wanted_fc ^= EFX_FC_TX;
931 }
932}
933
David S. Millerb56269462011-05-17 17:53:22 -0400934void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000935{
936 efx->wanted_fc = wanted_fc;
937 if (efx->link_advertising) {
938 if (wanted_fc & EFX_FC_RX)
939 efx->link_advertising |= (ADVERTISED_Pause |
940 ADVERTISED_Asym_Pause);
941 else
942 efx->link_advertising &= ~(ADVERTISED_Pause |
943 ADVERTISED_Asym_Pause);
944 if (wanted_fc & EFX_FC_TX)
945 efx->link_advertising ^= ADVERTISED_Asym_Pause;
946 }
947}
948
Ben Hutchings115122a2009-03-04 09:52:52 +0000949static void efx_fini_port(struct efx_nic *efx);
950
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000951/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
952 * the MAC appropriately. All other PHY configuration changes are pushed
953 * through phy_op->set_settings(), and pushed asynchronously to the MAC
954 * through efx_monitor().
955 *
956 * Callers must hold the mac_lock
957 */
958int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100959{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000960 enum efx_phy_mode phy_mode;
961 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100962
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000963 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100964
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000965 /* Disable PHY transmit in mac level loopbacks */
966 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800967 if (LOOPBACK_INTERNAL(efx))
968 efx->phy_mode |= PHY_MODE_TX_DISABLED;
969 else
970 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800971
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000972 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800973
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000974 if (rc)
975 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100976
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000977 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100978}
979
980/* Reinitialise the MAC to pick up new PHY settings, even if the port is
981 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000982int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100983{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000984 int rc;
985
Ben Hutchings8ceee662008-04-27 12:55:59 +0100986 EFX_ASSERT_RESET_SERIALISED(efx);
987
988 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000989 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100990 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000991
992 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100993}
994
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000995/* Asynchronous work item for changing MAC promiscuity and multicast
996 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
997 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800998static void efx_mac_work(struct work_struct *data)
999{
1000 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
1001
1002 mutex_lock(&efx->mac_lock);
Ben Hutchings30b81cd2011-09-13 19:47:48 +01001003 if (efx->port_enabled)
Ben Hutchings710b2082011-09-03 00:15:00 +01001004 efx->type->reconfigure_mac(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001005 mutex_unlock(&efx->mac_lock);
1006}
1007
Ben Hutchings8ceee662008-04-27 12:55:59 +01001008static int efx_probe_port(struct efx_nic *efx)
1009{
1010 int rc;
1011
Ben Hutchings62776d02010-06-23 11:30:07 +00001012 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001013
Steve Hodgsonff3b00a2009-12-23 13:46:36 +00001014 if (phy_flash_cfg)
1015 efx->phy_mode = PHY_MODE_SPECIAL;
1016
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001017 /* Connect up MAC/PHY operations table */
1018 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001019 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +00001020 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001021
Ben Hutchingse332bcb2011-12-20 01:22:51 +00001022 /* Initialise MAC address to permanent address */
Edward Creecd84ff42014-03-07 18:27:41 +00001023 ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001024
1025 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001026}
1027
1028static int efx_init_port(struct efx_nic *efx)
1029{
1030 int rc;
1031
Ben Hutchings62776d02010-06-23 11:30:07 +00001032 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001033
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001034 mutex_lock(&efx->mac_lock);
1035
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001036 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001037 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001038 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001039
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001040 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001041
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001042 /* Reconfigure the MAC before creating dma queues (required for
1043 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
Ben Hutchings710b2082011-09-03 00:15:00 +01001044 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001045
1046 /* Ensure the PHY advertises the correct flow control settings */
1047 rc = efx->phy_op->reconfigure(efx);
1048 if (rc)
1049 goto fail2;
1050
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001051 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001052 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001053
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001054fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001055 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001056fail1:
1057 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001058 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001059}
1060
Ben Hutchings8ceee662008-04-27 12:55:59 +01001061static void efx_start_port(struct efx_nic *efx)
1062{
Ben Hutchings62776d02010-06-23 11:30:07 +00001063 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001064 BUG_ON(efx->port_enabled);
1065
1066 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001067 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001068
Ben Hutchingsd615c032013-10-08 17:33:20 +01001069 /* Ensure MAC ingress/egress is enabled */
Ben Hutchings710b2082011-09-03 00:15:00 +01001070 efx->type->reconfigure_mac(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001071
Ben Hutchings8ceee662008-04-27 12:55:59 +01001072 mutex_unlock(&efx->mac_lock);
1073}
1074
Ben Hutchingsd615c032013-10-08 17:33:20 +01001075/* Cancel work for MAC reconfiguration, periodic hardware monitoring
1076 * and the async self-test, wait for them to finish and prevent them
1077 * being scheduled again. This doesn't cover online resets, which
1078 * should only be cancelled when removing the device.
1079 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001080static void efx_stop_port(struct efx_nic *efx)
1081{
Ben Hutchings62776d02010-06-23 11:30:07 +00001082 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001083
Ben Hutchingsd615c032013-10-08 17:33:20 +01001084 EFX_ASSERT_RESET_SERIALISED(efx);
1085
Ben Hutchings8ceee662008-04-27 12:55:59 +01001086 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001087 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001088 mutex_unlock(&efx->mac_lock);
1089
1090 /* Serialise against efx_set_multicast_list() */
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001091 netif_addr_lock_bh(efx->net_dev);
1092 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchingsd615c032013-10-08 17:33:20 +01001093
1094 cancel_delayed_work_sync(&efx->monitor_work);
1095 efx_selftest_async_cancel(efx);
1096 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001097}
1098
1099static void efx_fini_port(struct efx_nic *efx)
1100{
Ben Hutchings62776d02010-06-23 11:30:07 +00001101 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001102
1103 if (!efx->port_initialized)
1104 return;
1105
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001106 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001107 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001108
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001109 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001110 efx_link_status_changed(efx);
1111}
1112
1113static void efx_remove_port(struct efx_nic *efx)
1114{
Ben Hutchings62776d02010-06-23 11:30:07 +00001115 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001116
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001117 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001118}
1119
1120/**************************************************************************
1121 *
1122 * NIC handling
1123 *
1124 **************************************************************************/
1125
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01001126static LIST_HEAD(efx_primary_list);
1127static LIST_HEAD(efx_unassociated_list);
1128
1129static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
1130{
1131 return left->type == right->type &&
1132 left->vpd_sn && right->vpd_sn &&
1133 !strcmp(left->vpd_sn, right->vpd_sn);
1134}
1135
1136static void efx_associate(struct efx_nic *efx)
1137{
1138 struct efx_nic *other, *next;
1139
1140 if (efx->primary == efx) {
1141 /* Adding primary function; look for secondaries */
1142
1143 netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
1144 list_add_tail(&efx->node, &efx_primary_list);
1145
1146 list_for_each_entry_safe(other, next, &efx_unassociated_list,
1147 node) {
1148 if (efx_same_controller(efx, other)) {
1149 list_del(&other->node);
1150 netif_dbg(other, probe, other->net_dev,
1151 "moving to secondary list of %s %s\n",
1152 pci_name(efx->pci_dev),
1153 efx->net_dev->name);
1154 list_add_tail(&other->node,
1155 &efx->secondary_list);
1156 other->primary = efx;
1157 }
1158 }
1159 } else {
1160 /* Adding secondary function; look for primary */
1161
1162 list_for_each_entry(other, &efx_primary_list, node) {
1163 if (efx_same_controller(efx, other)) {
1164 netif_dbg(efx, probe, efx->net_dev,
1165 "adding to secondary list of %s %s\n",
1166 pci_name(other->pci_dev),
1167 other->net_dev->name);
1168 list_add_tail(&efx->node,
1169 &other->secondary_list);
1170 efx->primary = other;
1171 return;
1172 }
1173 }
1174
1175 netif_dbg(efx, probe, efx->net_dev,
1176 "adding to unassociated list\n");
1177 list_add_tail(&efx->node, &efx_unassociated_list);
1178 }
1179}
1180
1181static void efx_dissociate(struct efx_nic *efx)
1182{
1183 struct efx_nic *other, *next;
1184
1185 list_del(&efx->node);
1186 efx->primary = NULL;
1187
1188 list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
1189 list_del(&other->node);
1190 netif_dbg(other, probe, other->net_dev,
1191 "moving to unassociated list\n");
1192 list_add_tail(&other->node, &efx_unassociated_list);
1193 other->primary = NULL;
1194 }
1195}
1196
Ben Hutchings8ceee662008-04-27 12:55:59 +01001197/* This configures the PCI device to enable I/O and DMA. */
1198static int efx_init_io(struct efx_nic *efx)
1199{
1200 struct pci_dev *pci_dev = efx->pci_dev;
1201 dma_addr_t dma_mask = efx->type->max_dma_mask;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001202 unsigned int mem_map_size = efx->type->mem_map_size(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001203 int rc;
1204
Ben Hutchings62776d02010-06-23 11:30:07 +00001205 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001206
1207 rc = pci_enable_device(pci_dev);
1208 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001209 netif_err(efx, probe, efx->net_dev,
1210 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001211 goto fail1;
1212 }
1213
1214 pci_set_master(pci_dev);
1215
1216 /* Set the PCI DMA mask. Try all possibilities from our
1217 * genuine mask down to 32 bits, because some architectures
1218 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1219 * masks event though they reject 46 bit masks.
1220 */
1221 while (dma_mask > 0x7fffffffUL) {
Ben Hutchings0e33d872012-05-17 17:46:55 +01001222 if (dma_supported(&pci_dev->dev, dma_mask)) {
Russell King9663ded2013-06-26 23:49:11 +01001223 rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
Ben Hutchingse9e01842012-01-05 18:50:29 +00001224 if (rc == 0)
1225 break;
1226 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001227 dma_mask >>= 1;
1228 }
1229 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001230 netif_err(efx, probe, efx->net_dev,
1231 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001232 goto fail2;
1233 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001234 netif_dbg(efx, probe, efx->net_dev,
1235 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001236
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001237 efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
1238 rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001239 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001240 netif_err(efx, probe, efx->net_dev,
1241 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001242 rc = -EIO;
1243 goto fail3;
1244 }
Ben Hutchingsb1057982012-09-19 00:56:47 +01001245 efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001246 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001247 netif_err(efx, probe, efx->net_dev,
1248 "could not map memory BAR at %llx+%x\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001249 (unsigned long long)efx->membase_phys, mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001250 rc = -ENOMEM;
1251 goto fail4;
1252 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001253 netif_dbg(efx, probe, efx->net_dev,
1254 "memory BAR at %llx+%x (virtual %p)\n",
Ben Hutchingsb1057982012-09-19 00:56:47 +01001255 (unsigned long long)efx->membase_phys, mem_map_size,
1256 efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001257
1258 return 0;
1259
1260 fail4:
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001261 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001262 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001263 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001264 fail2:
1265 pci_disable_device(efx->pci_dev);
1266 fail1:
1267 return rc;
1268}
1269
1270static void efx_fini_io(struct efx_nic *efx)
1271{
Ben Hutchings62776d02010-06-23 11:30:07 +00001272 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001273
1274 if (efx->membase) {
1275 iounmap(efx->membase);
1276 efx->membase = NULL;
1277 }
1278
1279 if (efx->membase_phys) {
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001280 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001281 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001282 }
1283
1284 pci_disable_device(efx->pci_dev);
1285}
1286
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001287static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
Ben Hutchings46123d02008-09-01 12:47:33 +01001288{
Ben Hutchingscdb08f82011-12-20 01:08:05 +00001289 cpumask_var_t thread_mask;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001290 unsigned int count;
Ben Hutchings46123d02008-09-01 12:47:33 +01001291 int cpu;
1292
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001293 if (rss_cpus) {
1294 count = rss_cpus;
1295 } else {
1296 if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1297 netif_warn(efx, probe, efx->net_dev,
1298 "RSS disabled due to allocation failure\n");
1299 return 1;
Ben Hutchings46123d02008-09-01 12:47:33 +01001300 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001301
1302 count = 0;
1303 for_each_online_cpu(cpu) {
1304 if (!cpumask_test_cpu(cpu, thread_mask)) {
1305 ++count;
1306 cpumask_or(thread_mask, thread_mask,
1307 topology_thread_cpumask(cpu));
1308 }
1309 }
1310
1311 free_cpumask_var(thread_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001312 }
1313
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001314 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1315 * table entries that are inaccessible to VFs
1316 */
Shradha Shah327c6852014-11-05 12:16:32 +00001317 if (efx_siena_sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001318 count > efx_vf_size(efx)) {
1319 netif_warn(efx, probe, efx->net_dev,
1320 "Reducing number of RSS channels from %u to %u for "
1321 "VF support. Increase vf-msix-limit to use more "
1322 "channels on the PF.\n",
1323 count, efx_vf_size(efx));
1324 count = efx_vf_size(efx);
1325 }
1326
Ben Hutchings46123d02008-09-01 12:47:33 +01001327 return count;
1328}
1329
1330/* Probe the number and type of interrupts we are able to obtain, and
1331 * the resulting numbers of channels and RX queues.
1332 */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001333static int efx_probe_interrupts(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001334{
Ben Hutchings7f967c02012-02-13 23:45:02 +00001335 unsigned int extra_channels = 0;
1336 unsigned int i, j;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001337 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001338
Ben Hutchings7f967c02012-02-13 23:45:02 +00001339 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
1340 if (efx->extra_channel_type[i])
1341 ++extra_channels;
1342
Ben Hutchings8ceee662008-04-27 12:55:59 +01001343 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001344 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001345 unsigned int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001346
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001347 n_channels = efx_wanted_parallelism(efx);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001348 if (separate_tx_channels)
1349 n_channels *= 2;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001350 n_channels += extra_channels;
Ben Hutchingsb1057982012-09-19 00:56:47 +01001351 n_channels = min(n_channels, efx->max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001352
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001353 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001354 xentries[i].entry = i;
Alexander Gordeev184603d2014-02-18 11:12:00 +01001355 rc = pci_enable_msix_range(efx->pci_dev,
1356 xentries, 1, n_channels);
1357 if (rc < 0) {
1358 /* Fall back to single channel MSI */
1359 efx->interrupt_mode = EFX_INT_MODE_MSI;
1360 netif_err(efx, drv, efx->net_dev,
1361 "could not enable MSI-X\n");
1362 } else if (rc < n_channels) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001363 netif_err(efx, drv, efx->net_dev,
1364 "WARNING: Insufficient MSI-X vectors"
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001365 " available (%d < %u).\n", rc, n_channels);
Ben Hutchings62776d02010-06-23 11:30:07 +00001366 netif_err(efx, drv, efx->net_dev,
1367 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001368 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001369 }
1370
Alexander Gordeev184603d2014-02-18 11:12:00 +01001371 if (rc > 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001372 efx->n_channels = n_channels;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001373 if (n_channels > extra_channels)
1374 n_channels -= extra_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001375 if (separate_tx_channels) {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001376 efx->n_tx_channels = max(n_channels / 2, 1U);
1377 efx->n_rx_channels = max(n_channels -
1378 efx->n_tx_channels,
1379 1U);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001380 } else {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001381 efx->n_tx_channels = n_channels;
1382 efx->n_rx_channels = n_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001383 }
Ben Hutchings7f967c02012-02-13 23:45:02 +00001384 for (i = 0; i < efx->n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001385 efx_get_channel(efx, i)->irq =
1386 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001387 }
1388 }
1389
1390 /* Try single interrupt MSI */
1391 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001392 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001393 efx->n_rx_channels = 1;
1394 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001395 rc = pci_enable_msi(efx->pci_dev);
1396 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001397 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001398 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001399 netif_err(efx, drv, efx->net_dev,
1400 "could not enable MSI\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001401 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1402 }
1403 }
1404
1405 /* Assume legacy interrupts */
1406 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Neil Turton28b581a2008-12-12 21:41:06 -08001407 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001408 efx->n_rx_channels = 1;
1409 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001410 efx->legacy_irq = efx->pci_dev->irq;
1411 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001412
Ben Hutchings7f967c02012-02-13 23:45:02 +00001413 /* Assign extra channels if possible */
1414 j = efx->n_channels;
1415 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
1416 if (!efx->extra_channel_type[i])
1417 continue;
1418 if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
1419 efx->n_channels <= extra_channels) {
1420 efx->extra_channel_type[i]->handle_no_channel(efx);
1421 } else {
1422 --j;
1423 efx_get_channel(efx, j)->type =
1424 efx->extra_channel_type[i];
1425 }
1426 }
1427
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001428 /* RSS might be usable on VFs even if it is disabled on the PF */
Shradha Shah327c6852014-11-05 12:16:32 +00001429 efx->rss_spread = ((efx->n_rx_channels > 1 ||
1430 !efx_siena_sriov_wanted(efx)) ?
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001431 efx->n_rx_channels : efx_vf_size(efx));
1432
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001433 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001434}
1435
Jon Cooper261e4d92013-04-15 18:51:54 +01001436static int efx_soft_enable_interrupts(struct efx_nic *efx)
Ben Hutchingsd8291182012-10-05 23:35:41 +01001437{
Jon Cooper261e4d92013-04-15 18:51:54 +01001438 struct efx_channel *channel, *end_channel;
1439 int rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001440
1441 BUG_ON(efx->state == STATE_DISABLED);
1442
1443 efx->irq_soft_enabled = true;
1444 smp_wmb();
1445
1446 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001447 if (!channel->type->keep_eventq) {
1448 rc = efx_init_eventq(channel);
1449 if (rc)
1450 goto fail;
1451 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001452 efx_start_eventq(channel);
1453 }
1454
1455 efx_mcdi_mode_event(efx);
Jon Cooper261e4d92013-04-15 18:51:54 +01001456
1457 return 0;
1458fail:
1459 end_channel = channel;
1460 efx_for_each_channel(channel, efx) {
1461 if (channel == end_channel)
1462 break;
1463 efx_stop_eventq(channel);
1464 if (!channel->type->keep_eventq)
1465 efx_fini_eventq(channel);
1466 }
1467
1468 return rc;
Ben Hutchingsd8291182012-10-05 23:35:41 +01001469}
1470
1471static void efx_soft_disable_interrupts(struct efx_nic *efx)
1472{
1473 struct efx_channel *channel;
1474
1475 if (efx->state == STATE_DISABLED)
1476 return;
1477
1478 efx_mcdi_mode_poll(efx);
1479
1480 efx->irq_soft_enabled = false;
1481 smp_wmb();
1482
1483 if (efx->legacy_irq)
1484 synchronize_irq(efx->legacy_irq);
1485
1486 efx_for_each_channel(channel, efx) {
1487 if (channel->irq)
1488 synchronize_irq(channel->irq);
1489
1490 efx_stop_eventq(channel);
1491 if (!channel->type->keep_eventq)
1492 efx_fini_eventq(channel);
1493 }
Ben Hutchingscade7152013-08-27 23:12:31 +01001494
1495 /* Flush the asynchronous MCDI request queue */
1496 efx_mcdi_flush_async(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01001497}
1498
Jon Cooper261e4d92013-04-15 18:51:54 +01001499static int efx_enable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001500{
Jon Cooper261e4d92013-04-15 18:51:54 +01001501 struct efx_channel *channel, *end_channel;
1502 int rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001503
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001504 BUG_ON(efx->state == STATE_DISABLED);
1505
Alexandre Ramesb28405b2013-03-21 16:41:43 +00001506 if (efx->eeh_disabled_legacy_irq) {
1507 enable_irq(efx->legacy_irq);
1508 efx->eeh_disabled_legacy_irq = false;
1509 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001510
Ben Hutchings86094f72013-08-21 19:51:04 +01001511 efx->type->irq_enable_master(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001512
1513 efx_for_each_channel(channel, efx) {
Jon Cooper261e4d92013-04-15 18:51:54 +01001514 if (channel->type->keep_eventq) {
1515 rc = efx_init_eventq(channel);
1516 if (rc)
1517 goto fail;
1518 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001519 }
1520
Jon Cooper261e4d92013-04-15 18:51:54 +01001521 rc = efx_soft_enable_interrupts(efx);
1522 if (rc)
1523 goto fail;
1524
1525 return 0;
1526
1527fail:
1528 end_channel = channel;
1529 efx_for_each_channel(channel, efx) {
1530 if (channel == end_channel)
1531 break;
1532 if (channel->type->keep_eventq)
1533 efx_fini_eventq(channel);
1534 }
1535
1536 efx->type->irq_disable_non_ev(efx);
1537
1538 return rc;
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001539}
1540
Ben Hutchingsd8291182012-10-05 23:35:41 +01001541static void efx_disable_interrupts(struct efx_nic *efx)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001542{
1543 struct efx_channel *channel;
1544
Ben Hutchingsd8291182012-10-05 23:35:41 +01001545 efx_soft_disable_interrupts(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001546
1547 efx_for_each_channel(channel, efx) {
Ben Hutchingsd8291182012-10-05 23:35:41 +01001548 if (channel->type->keep_eventq)
Ben Hutchings7f967c02012-02-13 23:45:02 +00001549 efx_fini_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001550 }
Ben Hutchingsd8291182012-10-05 23:35:41 +01001551
Ben Hutchings86094f72013-08-21 19:51:04 +01001552 efx->type->irq_disable_non_ev(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001553}
1554
Ben Hutchings8ceee662008-04-27 12:55:59 +01001555static void efx_remove_interrupts(struct efx_nic *efx)
1556{
1557 struct efx_channel *channel;
1558
1559 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001560 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001561 channel->irq = 0;
1562 pci_disable_msi(efx->pci_dev);
1563 pci_disable_msix(efx->pci_dev);
1564
1565 /* Remove legacy interrupt */
1566 efx->legacy_irq = 0;
1567}
1568
Ben Hutchings8831da72008-09-01 12:47:48 +01001569static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001570{
Ben Hutchings602a5322011-05-16 17:32:39 +01001571 struct efx_channel *channel;
1572 struct efx_tx_queue *tx_queue;
1573
Ben Hutchings97653432011-01-12 18:26:56 +00001574 efx->tx_channel_offset =
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001575 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings602a5322011-05-16 17:32:39 +01001576
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001577 /* We need to mark which channels really have RX and TX
1578 * queues, and adjust the TX queue numbers if we have separate
Ben Hutchings602a5322011-05-16 17:32:39 +01001579 * RX-only and TX-only channels.
1580 */
1581 efx_for_each_channel(channel, efx) {
Stuart Hodgson79d68b32012-07-16 17:08:33 +01001582 if (channel->channel < efx->n_rx_channels)
1583 channel->rx_queue.core_index = channel->channel;
1584 else
1585 channel->rx_queue.core_index = -1;
1586
Ben Hutchings602a5322011-05-16 17:32:39 +01001587 efx_for_each_channel_tx_queue(tx_queue, channel)
1588 tx_queue->queue -= (efx->tx_channel_offset *
1589 EFX_TXQ_TYPES);
1590 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001591}
1592
1593static int efx_probe_nic(struct efx_nic *efx)
1594{
Ben Hutchings765c9f42010-06-30 05:06:28 +00001595 size_t i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001596 int rc;
1597
Ben Hutchings62776d02010-06-23 11:30:07 +00001598 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001599
1600 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001601 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001602 if (rc)
1603 return rc;
1604
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001605 /* Determine the number of channels and queues by trying to hook
Ben Hutchings8ceee662008-04-27 12:55:59 +01001606 * in MSI-X interrupts. */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001607 rc = efx_probe_interrupts(efx);
1608 if (rc)
Ben Hutchingsc15eed22013-08-29 00:45:48 +01001609 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001610
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001611 efx_set_channels(efx);
1612
Ben Hutchingsc15eed22013-08-29 00:45:48 +01001613 rc = efx->type->dimension_resources(efx);
1614 if (rc)
1615 goto fail2;
Ben Hutchings28e47c42012-02-15 01:58:49 +00001616
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001617 if (efx->n_channels > 1)
1618 get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001619 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
Ben Hutchings278bc422011-12-15 13:56:49 +00001620 efx->rx_indir_table[i] =
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001621 ethtool_rxfh_indir_default(i, efx->rss_spread);
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001622
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001623 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1624 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001625
1626 /* Initialise the interrupt moderation settings */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001627 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1628 true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001629
1630 return 0;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001631
Ben Hutchingsc15eed22013-08-29 00:45:48 +01001632fail2:
1633 efx_remove_interrupts(efx);
1634fail1:
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001635 efx->type->remove(efx);
1636 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001637}
1638
1639static void efx_remove_nic(struct efx_nic *efx)
1640{
Ben Hutchings62776d02010-06-23 11:30:07 +00001641 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001642
1643 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001644 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001645}
1646
Ben Hutchingsadd72472012-11-08 01:46:53 +00001647static int efx_probe_filters(struct efx_nic *efx)
1648{
1649 int rc;
1650
1651 spin_lock_init(&efx->filter_lock);
1652
1653 rc = efx->type->filter_table_probe(efx);
1654 if (rc)
1655 return rc;
1656
1657#ifdef CONFIG_RFS_ACCEL
1658 if (efx->type->offload_features & NETIF_F_NTUPLE) {
1659 efx->rps_flow_id = kcalloc(efx->type->max_rx_ip_filters,
1660 sizeof(*efx->rps_flow_id),
1661 GFP_KERNEL);
1662 if (!efx->rps_flow_id) {
1663 efx->type->filter_table_remove(efx);
1664 return -ENOMEM;
1665 }
1666 }
1667#endif
1668
1669 return 0;
1670}
1671
1672static void efx_remove_filters(struct efx_nic *efx)
1673{
1674#ifdef CONFIG_RFS_ACCEL
1675 kfree(efx->rps_flow_id);
1676#endif
1677 efx->type->filter_table_remove(efx);
1678}
1679
1680static void efx_restore_filters(struct efx_nic *efx)
1681{
1682 efx->type->filter_table_restore(efx);
1683}
1684
Ben Hutchings8ceee662008-04-27 12:55:59 +01001685/**************************************************************************
1686 *
1687 * NIC startup/shutdown
1688 *
1689 *************************************************************************/
1690
1691static int efx_probe_all(struct efx_nic *efx)
1692{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001693 int rc;
1694
Ben Hutchings8ceee662008-04-27 12:55:59 +01001695 rc = efx_probe_nic(efx);
1696 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001697 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001698 goto fail1;
1699 }
1700
Ben Hutchings8ceee662008-04-27 12:55:59 +01001701 rc = efx_probe_port(efx);
1702 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001703 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001704 goto fail2;
1705 }
1706
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00001707 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
1708 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
1709 rc = -EINVAL;
1710 goto fail3;
1711 }
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001712 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001713
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001714 rc = efx_probe_filters(efx);
1715 if (rc) {
1716 netif_err(efx, probe, efx->net_dev,
1717 "failed to create filter tables\n");
Ben Hutchings7f967c02012-02-13 23:45:02 +00001718 goto fail3;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001719 }
1720
Ben Hutchings7f967c02012-02-13 23:45:02 +00001721 rc = efx_probe_channels(efx);
1722 if (rc)
1723 goto fail4;
1724
Ben Hutchings8ceee662008-04-27 12:55:59 +01001725 return 0;
1726
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001727 fail4:
Ben Hutchings7f967c02012-02-13 23:45:02 +00001728 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001729 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001730 efx_remove_port(efx);
1731 fail2:
1732 efx_remove_nic(efx);
1733 fail1:
1734 return rc;
1735}
1736
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001737/* If the interface is supposed to be running but is not, start
1738 * the hardware and software data path, regular activity for the port
1739 * (MAC statistics, link polling, etc.) and schedule the port to be
1740 * reconfigured. Interrupts must already be enabled. This function
1741 * is safe to call multiple times, so long as the NIC is not disabled.
1742 * Requires the RTNL lock.
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001743 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001744static void efx_start_all(struct efx_nic *efx)
1745{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001746 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001747 BUG_ON(efx->state == STATE_DISABLED);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001748
1749 /* Check that it is appropriate to restart the interface. All
1750 * of these flags are safe to read under just the rtnl lock */
Edward Creee2835462014-04-16 19:27:48 +01001751 if (efx->port_enabled || !netif_running(efx->net_dev) ||
1752 efx->reset_pending)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001753 return;
1754
Ben Hutchings8ceee662008-04-27 12:55:59 +01001755 efx_start_port(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001756 efx_start_datapath(efx);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001757
Alexandre Rames626950d2013-01-14 17:20:22 +00001758 /* Start the hardware monitor if there is one */
1759 if (efx->type->monitor != NULL)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001760 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1761 efx_monitor_interval);
Alexandre Rames626950d2013-01-14 17:20:22 +00001762
1763 /* If link state detection is normally event-driven, we have
1764 * to poll now because we could have missed a change
1765 */
1766 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001767 mutex_lock(&efx->mac_lock);
1768 if (efx->phy_op->poll(efx))
1769 efx_link_status_changed(efx);
1770 mutex_unlock(&efx->mac_lock);
1771 }
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001772
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001773 efx->type->start_stats(efx);
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001774 efx->type->pull_stats(efx);
1775 spin_lock_bh(&efx->stats_lock);
1776 efx->type->update_stats(efx, NULL, NULL);
1777 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001778}
1779
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001780/* Quiesce the hardware and software data path, and regular activity
1781 * for the port without bringing the link down. Safe to call multiple
1782 * times with the NIC in almost any state, but interrupts should be
1783 * enabled. Requires the RTNL lock.
1784 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001785static void efx_stop_all(struct efx_nic *efx)
1786{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001787 EFX_ASSERT_RESET_SERIALISED(efx);
1788
1789 /* port_enabled can be read safely under the rtnl lock */
1790 if (!efx->port_enabled)
1791 return;
1792
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001793 /* update stats before we go down so we can accurately count
1794 * rx_nodesc_drops
1795 */
1796 efx->type->pull_stats(efx);
1797 spin_lock_bh(&efx->stats_lock);
1798 efx->type->update_stats(efx, NULL, NULL);
1799 spin_unlock_bh(&efx->stats_lock);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001800 efx->type->stop_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001801 efx_stop_port(efx);
1802
Ben Hutchings29c69a42013-01-28 19:01:06 +00001803 /* Stop the kernel transmit interface. This is only valid if
1804 * the device is stopped or detached; otherwise the watchdog
1805 * may fire immediately.
1806 */
1807 WARN_ON(netif_running(efx->net_dev) &&
1808 netif_device_present(efx->net_dev));
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001809 netif_tx_disable(efx->net_dev);
1810
1811 efx_stop_datapath(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001812}
1813
1814static void efx_remove_all(struct efx_nic *efx)
1815{
Ben Hutchings46426102010-09-10 06:42:33 +00001816 efx_remove_channels(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001817 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001818 efx_remove_port(efx);
1819 efx_remove_nic(efx);
1820}
1821
Ben Hutchings8ceee662008-04-27 12:55:59 +01001822/**************************************************************************
1823 *
1824 * Interrupt moderation
1825 *
1826 **************************************************************************/
1827
Ben Hutchingscc180b62011-12-08 19:51:47 +00001828static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001829{
Ben Hutchingsb548f972011-09-05 07:41:44 +00001830 if (usecs == 0)
1831 return 0;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001832 if (usecs * 1000 < quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001833 return 1; /* never round down to 0 */
Ben Hutchingscc180b62011-12-08 19:51:47 +00001834 return usecs * 1000 / quantum_ns;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001835}
1836
Ben Hutchings8ceee662008-04-27 12:55:59 +01001837/* Set interrupt moderation parameters */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001838int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
1839 unsigned int rx_usecs, bool rx_adaptive,
1840 bool rx_may_override_tx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001841{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001842 struct efx_channel *channel;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001843 unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max *
1844 efx->timer_quantum_ns,
1845 1000);
1846 unsigned int tx_ticks;
1847 unsigned int rx_ticks;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001848
1849 EFX_ASSERT_RESET_SERIALISED(efx);
1850
Ben Hutchingscc180b62011-12-08 19:51:47 +00001851 if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max)
Ben Hutchings9e393b32011-09-05 07:43:04 +00001852 return -EINVAL;
1853
Ben Hutchingscc180b62011-12-08 19:51:47 +00001854 tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns);
1855 rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns);
1856
Ben Hutchings9e393b32011-09-05 07:43:04 +00001857 if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 &&
1858 !rx_may_override_tx) {
1859 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
1860 "RX and TX IRQ moderation must be equal\n");
1861 return -EINVAL;
1862 }
1863
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001864 efx->irq_rx_adaptive = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001865 efx->irq_rx_moderation = rx_ticks;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001866 efx_for_each_channel(channel, efx) {
Ben Hutchings525da902011-02-07 23:04:38 +00001867 if (efx_channel_has_rx_queue(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001868 channel->irq_moderation = rx_ticks;
Ben Hutchings525da902011-02-07 23:04:38 +00001869 else if (efx_channel_has_tx_queues(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001870 channel->irq_moderation = tx_ticks;
1871 }
Ben Hutchings9e393b32011-09-05 07:43:04 +00001872
1873 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001874}
1875
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001876void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
1877 unsigned int *rx_usecs, bool *rx_adaptive)
1878{
Ben Hutchingscc180b62011-12-08 19:51:47 +00001879 /* We must round up when converting ticks to microseconds
1880 * because we round down when converting the other way.
1881 */
1882
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001883 *rx_adaptive = efx->irq_rx_adaptive;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001884 *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation *
1885 efx->timer_quantum_ns,
1886 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001887
1888 /* If channels are shared between RX and TX, so is IRQ
1889 * moderation. Otherwise, IRQ moderation is the same for all
1890 * TX channels and is not adaptive.
1891 */
1892 if (efx->tx_channel_offset == 0)
1893 *tx_usecs = *rx_usecs;
1894 else
Ben Hutchingscc180b62011-12-08 19:51:47 +00001895 *tx_usecs = DIV_ROUND_UP(
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001896 efx->channel[efx->tx_channel_offset]->irq_moderation *
Ben Hutchingscc180b62011-12-08 19:51:47 +00001897 efx->timer_quantum_ns,
1898 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001899}
1900
Ben Hutchings8ceee662008-04-27 12:55:59 +01001901/**************************************************************************
1902 *
1903 * Hardware monitor
1904 *
1905 **************************************************************************/
1906
Ben Hutchingse254c272010-09-20 08:44:10 +00001907/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001908static void efx_monitor(struct work_struct *data)
1909{
1910 struct efx_nic *efx = container_of(data, struct efx_nic,
1911 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001912
Ben Hutchings62776d02010-06-23 11:30:07 +00001913 netif_vdbg(efx, timer, efx->net_dev,
1914 "hardware monitor executing on CPU %d\n",
1915 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001916 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001917
Ben Hutchings8ceee662008-04-27 12:55:59 +01001918 /* If the mac_lock is already held then it is likely a port
1919 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00001920 * most of the work of monitor() anyway. */
1921 if (mutex_trylock(&efx->mac_lock)) {
1922 if (efx->port_enabled)
1923 efx->type->monitor(efx);
1924 mutex_unlock(&efx->mac_lock);
1925 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001926
Ben Hutchings8ceee662008-04-27 12:55:59 +01001927 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1928 efx_monitor_interval);
1929}
1930
1931/**************************************************************************
1932 *
1933 * ioctls
1934 *
1935 *************************************************************************/
1936
1937/* Net device ioctl
1938 * Context: process, rtnl_lock() held.
1939 */
1940static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1941{
Ben Hutchings767e4682008-09-01 12:43:14 +01001942 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00001943 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001944
Stuart Hodgson7c236c42012-09-03 11:09:36 +01001945 if (cmd == SIOCSHWTSTAMP)
Ben Hutchings433dc9b2013-11-14 01:26:21 +00001946 return efx_ptp_set_ts_config(efx, ifr);
1947 if (cmd == SIOCGHWTSTAMP)
1948 return efx_ptp_get_ts_config(efx, ifr);
Stuart Hodgson7c236c42012-09-03 11:09:36 +01001949
Ben Hutchings68e7f452009-04-29 08:05:08 +00001950 /* Convert phy_id from older PRTAD/DEVAD format */
1951 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
1952 (data->phy_id & 0xfc00) == 0x0400)
1953 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
1954
1955 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001956}
1957
1958/**************************************************************************
1959 *
1960 * NAPI interface
1961 *
1962 **************************************************************************/
1963
Ben Hutchings7f967c02012-02-13 23:45:02 +00001964static void efx_init_napi_channel(struct efx_channel *channel)
1965{
1966 struct efx_nic *efx = channel->efx;
1967
1968 channel->napi_dev = efx->net_dev;
1969 netif_napi_add(channel->napi_dev, &channel->napi_str,
1970 efx_poll, napi_weight);
Alexandre Rames36763262014-07-22 14:03:25 +01001971 napi_hash_add(&channel->napi_str);
1972 efx_channel_init_lock(channel);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001973}
1974
Ben Hutchingse8f14992010-12-07 19:47:34 +00001975static void efx_init_napi(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001976{
1977 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001978
Ben Hutchings7f967c02012-02-13 23:45:02 +00001979 efx_for_each_channel(channel, efx)
1980 efx_init_napi_channel(channel);
Ben Hutchingse8f14992010-12-07 19:47:34 +00001981}
1982
1983static void efx_fini_napi_channel(struct efx_channel *channel)
1984{
Alexandre Rames36763262014-07-22 14:03:25 +01001985 if (channel->napi_dev) {
Ben Hutchingse8f14992010-12-07 19:47:34 +00001986 netif_napi_del(&channel->napi_str);
Alexandre Rames36763262014-07-22 14:03:25 +01001987 napi_hash_del(&channel->napi_str);
1988 }
Ben Hutchingse8f14992010-12-07 19:47:34 +00001989 channel->napi_dev = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001990}
1991
1992static void efx_fini_napi(struct efx_nic *efx)
1993{
1994 struct efx_channel *channel;
1995
Ben Hutchingse8f14992010-12-07 19:47:34 +00001996 efx_for_each_channel(channel, efx)
1997 efx_fini_napi_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001998}
1999
2000/**************************************************************************
2001 *
2002 * Kernel netpoll interface
2003 *
2004 *************************************************************************/
2005
2006#ifdef CONFIG_NET_POLL_CONTROLLER
2007
2008/* Although in the common case interrupts will be disabled, this is not
2009 * guaranteed. However, all our work happens inside the NAPI callback,
2010 * so no locking is required.
2011 */
2012static void efx_netpoll(struct net_device *net_dev)
2013{
Ben Hutchings767e4682008-09-01 12:43:14 +01002014 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002015 struct efx_channel *channel;
2016
Ben Hutchings64ee3122008-09-01 12:47:38 +01002017 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002018 efx_schedule_channel(channel);
2019}
2020
2021#endif
2022
Alexandre Rames36763262014-07-22 14:03:25 +01002023#ifdef CONFIG_NET_RX_BUSY_POLL
2024static int efx_busy_poll(struct napi_struct *napi)
2025{
2026 struct efx_channel *channel =
2027 container_of(napi, struct efx_channel, napi_str);
2028 struct efx_nic *efx = channel->efx;
2029 int budget = 4;
2030 int old_rx_packets, rx_packets;
2031
2032 if (!netif_running(efx->net_dev))
2033 return LL_FLUSH_FAILED;
2034
2035 if (!efx_channel_lock_poll(channel))
2036 return LL_FLUSH_BUSY;
2037
2038 old_rx_packets = channel->rx_queue.rx_packets;
2039 efx_process_channel(channel, budget);
2040
2041 rx_packets = channel->rx_queue.rx_packets - old_rx_packets;
2042
2043 /* There is no race condition with NAPI here.
2044 * NAPI will automatically be rescheduled if it yielded during busy
2045 * polling, because it was not able to take the lock and thus returned
2046 * the full budget.
2047 */
2048 efx_channel_unlock_poll(channel);
2049
2050 return rx_packets;
2051}
2052#endif
2053
Ben Hutchings8ceee662008-04-27 12:55:59 +01002054/**************************************************************************
2055 *
2056 * Kernel net device interface
2057 *
2058 *************************************************************************/
2059
2060/* Context: process, rtnl_lock() held. */
2061static int efx_net_open(struct net_device *net_dev)
2062{
Ben Hutchings767e4682008-09-01 12:43:14 +01002063 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002064 int rc;
2065
Ben Hutchings62776d02010-06-23 11:30:07 +00002066 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
2067 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002068
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002069 rc = efx_check_disabled(efx);
2070 if (rc)
2071 return rc;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002072 if (efx->phy_mode & PHY_MODE_SPECIAL)
2073 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002074 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
2075 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01002076
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00002077 /* Notify the kernel of the link state polled during driver load,
2078 * before the monitor starts running */
2079 efx_link_status_changed(efx);
2080
Ben Hutchings8ceee662008-04-27 12:55:59 +01002081 efx_start_all(efx);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002082 efx_selftest_async_start(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002083 return 0;
2084}
2085
2086/* Context: process, rtnl_lock() held.
2087 * Note that the kernel will ignore our return code; this method
2088 * should really be a void.
2089 */
2090static int efx_net_stop(struct net_device *net_dev)
2091{
Ben Hutchings767e4682008-09-01 12:43:14 +01002092 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002093
Ben Hutchings62776d02010-06-23 11:30:07 +00002094 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
2095 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01002096
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002097 /* Stop the device and flush all the channels */
2098 efx_stop_all(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002099
2100 return 0;
2101}
2102
Ben Hutchings5b9e2072008-05-16 21:18:14 +01002103/* Context: process, dev_base_lock or RTNL held, non-blocking. */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +00002104static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev,
2105 struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002106{
Ben Hutchings767e4682008-09-01 12:43:14 +01002107 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002108
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002109 spin_lock_bh(&efx->stats_lock);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +00002110 efx->type->update_stats(efx, NULL, stats);
Ben Hutchings1cb34522011-09-02 23:23:00 +01002111 spin_unlock_bh(&efx->stats_lock);
2112
Ben Hutchings8ceee662008-04-27 12:55:59 +01002113 return stats;
2114}
2115
2116/* Context: netif_tx_lock held, BHs disabled. */
2117static void efx_watchdog(struct net_device *net_dev)
2118{
Ben Hutchings767e4682008-09-01 12:43:14 +01002119 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002120
Ben Hutchings62776d02010-06-23 11:30:07 +00002121 netif_err(efx, tx_err, efx->net_dev,
2122 "TX stuck with port_enabled=%d: resetting channels\n",
2123 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002124
Ben Hutchings739bb23d2008-11-04 20:35:36 +00002125 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002126}
2127
2128
2129/* Context: process, rtnl_lock() held. */
2130static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
2131{
Ben Hutchings767e4682008-09-01 12:43:14 +01002132 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002133 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002134
Ben Hutchings8b7325b2012-07-27 20:46:41 +01002135 rc = efx_check_disabled(efx);
2136 if (rc)
2137 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002138 if (new_mtu > EFX_MAX_MTU)
2139 return -EINVAL;
2140
Ben Hutchings62776d02010-06-23 11:30:07 +00002141 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002142
Ben Hutchings29c69a42013-01-28 19:01:06 +00002143 efx_device_detach_sync(efx);
2144 efx_stop_all(efx);
2145
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002146 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002147 net_dev->mtu = new_mtu;
Ben Hutchings710b2082011-09-03 00:15:00 +01002148 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002149 mutex_unlock(&efx->mac_lock);
2150
Ben Hutchings8ceee662008-04-27 12:55:59 +01002151 efx_start_all(efx);
Ben Hutchings29c69a42013-01-28 19:01:06 +00002152 netif_device_attach(efx->net_dev);
Ben Hutchings6c8eef42012-01-09 19:54:16 +00002153 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002154}
2155
2156static int efx_set_mac_address(struct net_device *net_dev, void *data)
2157{
Ben Hutchings767e4682008-09-01 12:43:14 +01002158 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002159 struct sockaddr *addr = data;
Ben Hutchingse0b3ae32014-02-12 18:59:54 +00002160 u8 *new_addr = addr->sa_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002161
Ben Hutchings8ceee662008-04-27 12:55:59 +01002162 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002163 netif_err(efx, drv, efx->net_dev,
2164 "invalid ethernet MAC address requested: %pM\n",
2165 new_addr);
Danny Kukawka504f9b52012-02-21 02:07:49 +00002166 return -EADDRNOTAVAIL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002167 }
2168
Edward Creecd84ff42014-03-07 18:27:41 +00002169 ether_addr_copy(net_dev->dev_addr, new_addr);
Shradha Shah327c6852014-11-05 12:16:32 +00002170 efx_siena_sriov_mac_address_changed(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002171
2172 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002173 mutex_lock(&efx->mac_lock);
Ben Hutchings710b2082011-09-03 00:15:00 +01002174 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002175 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002176
2177 return 0;
2178}
2179
Ben Hutchingsa816f752008-09-01 12:49:12 +01002180/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002181static void efx_set_rx_mode(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002182{
Ben Hutchings767e4682008-09-01 12:43:14 +01002183 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002184
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002185 if (efx->port_enabled)
2186 queue_work(efx->workqueue, &efx->mac_work);
2187 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002188}
2189
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002190static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002191{
2192 struct efx_nic *efx = netdev_priv(net_dev);
2193
2194 /* If disabling RX n-tuple filtering, clear existing filters */
2195 if (net_dev->features & ~data & NETIF_F_NTUPLE)
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002196 return efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002197
2198 return 0;
2199}
2200
Ben Hutchings8127d662013-08-29 19:19:29 +01002201static const struct net_device_ops efx_farch_netdev_ops = {
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002202 .ndo_open = efx_net_open,
2203 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00002204 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002205 .ndo_tx_timeout = efx_watchdog,
2206 .ndo_start_xmit = efx_hard_start_xmit,
2207 .ndo_validate_addr = eth_validate_addr,
2208 .ndo_do_ioctl = efx_ioctl,
2209 .ndo_change_mtu = efx_change_mtu,
2210 .ndo_set_mac_address = efx_set_mac_address,
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002211 .ndo_set_rx_mode = efx_set_rx_mode,
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002212 .ndo_set_features = efx_set_features,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002213#ifdef CONFIG_SFC_SRIOV
Shradha Shah327c6852014-11-05 12:16:32 +00002214 .ndo_set_vf_mac = efx_siena_sriov_set_vf_mac,
2215 .ndo_set_vf_vlan = efx_siena_sriov_set_vf_vlan,
2216 .ndo_set_vf_spoofchk = efx_siena_sriov_set_vf_spoofchk,
2217 .ndo_get_vf_config = efx_siena_sriov_get_vf_config,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002218#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002219#ifdef CONFIG_NET_POLL_CONTROLLER
2220 .ndo_poll_controller = efx_netpoll,
2221#endif
Ben Hutchings94b274b2011-01-10 21:18:20 +00002222 .ndo_setup_tc = efx_setup_tc,
Alexandre Rames36763262014-07-22 14:03:25 +01002223#ifdef CONFIG_NET_RX_BUSY_POLL
2224 .ndo_busy_poll = efx_busy_poll,
2225#endif
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002226#ifdef CONFIG_RFS_ACCEL
2227 .ndo_rx_flow_steer = efx_filter_rfs,
2228#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002229};
2230
Ben Hutchings8127d662013-08-29 19:19:29 +01002231static const struct net_device_ops efx_ef10_netdev_ops = {
2232 .ndo_open = efx_net_open,
2233 .ndo_stop = efx_net_stop,
2234 .ndo_get_stats64 = efx_net_stats,
2235 .ndo_tx_timeout = efx_watchdog,
2236 .ndo_start_xmit = efx_hard_start_xmit,
2237 .ndo_validate_addr = eth_validate_addr,
2238 .ndo_do_ioctl = efx_ioctl,
2239 .ndo_change_mtu = efx_change_mtu,
2240 .ndo_set_mac_address = efx_set_mac_address,
2241 .ndo_set_rx_mode = efx_set_rx_mode,
2242 .ndo_set_features = efx_set_features,
2243#ifdef CONFIG_NET_POLL_CONTROLLER
2244 .ndo_poll_controller = efx_netpoll,
2245#endif
Alexandre Rames36763262014-07-22 14:03:25 +01002246#ifdef CONFIG_NET_RX_BUSY_POLL
2247 .ndo_busy_poll = efx_busy_poll,
2248#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01002249#ifdef CONFIG_RFS_ACCEL
2250 .ndo_rx_flow_steer = efx_filter_rfs,
2251#endif
2252};
2253
Ben Hutchings7dde5962008-12-12 22:09:38 -08002254static void efx_update_name(struct efx_nic *efx)
2255{
2256 strcpy(efx->name, efx->net_dev->name);
2257 efx_mtd_rename(efx);
2258 efx_set_channel_names(efx);
2259}
2260
Ben Hutchings8ceee662008-04-27 12:55:59 +01002261static int efx_netdev_event(struct notifier_block *this,
2262 unsigned long event, void *ptr)
2263{
Jiri Pirko351638e2013-05-28 01:30:21 +00002264 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002265
Ben Hutchings8127d662013-08-29 19:19:29 +01002266 if ((net_dev->netdev_ops == &efx_farch_netdev_ops ||
2267 net_dev->netdev_ops == &efx_ef10_netdev_ops) &&
Ben Hutchings7dde5962008-12-12 22:09:38 -08002268 event == NETDEV_CHANGENAME)
2269 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002270
2271 return NOTIFY_DONE;
2272}
2273
2274static struct notifier_block efx_netdev_notifier = {
2275 .notifier_call = efx_netdev_event,
2276};
2277
Ben Hutchings06d5e192008-12-12 21:47:23 -08002278static ssize_t
2279show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2280{
2281 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2282 return sprintf(buf, "%d\n", efx->phy_type);
2283}
Ben Hutchings776fbcc2013-06-18 17:45:40 +01002284static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
Ben Hutchings06d5e192008-12-12 21:47:23 -08002285
Ben Hutchings8ceee662008-04-27 12:55:59 +01002286static int efx_register_netdev(struct efx_nic *efx)
2287{
2288 struct net_device *net_dev = efx->net_dev;
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002289 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002290 int rc;
2291
2292 net_dev->watchdog_timeo = 5 * HZ;
2293 net_dev->irq = efx->pci_dev->irq;
Ben Hutchings8127d662013-08-29 19:19:29 +01002294 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) {
2295 net_dev->netdev_ops = &efx_ef10_netdev_ops;
2296 net_dev->priv_flags |= IFF_UNICAST_FLT;
2297 } else {
2298 net_dev->netdev_ops = &efx_farch_netdev_ops;
2299 }
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002300 net_dev->ethtool_ops = &efx_ethtool_ops;
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00002301 net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002302
Ben Hutchings7dde5962008-12-12 22:09:38 -08002303 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00002304
Ben Hutchings7153f622012-07-27 20:50:52 +01002305 /* Enable resets to be scheduled and check whether any were
2306 * already requested. If so, the NIC is probably hosed so we
2307 * abort.
2308 */
2309 efx->state = STATE_READY;
2310 smp_mb(); /* ensure we change state before checking reset_pending */
2311 if (efx->reset_pending) {
2312 netif_err(efx, probe, efx->net_dev,
2313 "aborting probe due to scheduled reset\n");
2314 rc = -EIO;
2315 goto fail_locked;
2316 }
2317
Ben Hutchingsaed06282009-08-26 08:16:27 +00002318 rc = dev_alloc_name(net_dev, net_dev->name);
2319 if (rc < 0)
2320 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002321 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002322
Ben Hutchings8f8b3d52012-08-24 18:04:38 +01002323 /* Always start with carrier off; PHY events will detect the link */
2324 netif_carrier_off(net_dev);
2325
Ben Hutchingsaed06282009-08-26 08:16:27 +00002326 rc = register_netdevice(net_dev);
2327 if (rc)
2328 goto fail_locked;
2329
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002330 efx_for_each_channel(channel, efx) {
2331 struct efx_tx_queue *tx_queue;
Ben Hutchings60031fc2011-01-12 18:39:40 +00002332 efx_for_each_channel_tx_queue(tx_queue, channel)
2333 efx_init_tx_queue_core_txq(tx_queue);
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002334 }
2335
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002336 efx_associate(efx);
2337
Ben Hutchings7dde5962008-12-12 22:09:38 -08002338 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002339
Ben Hutchings06d5e192008-12-12 21:47:23 -08002340 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2341 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002342 netif_err(efx, drv, efx->net_dev,
2343 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08002344 goto fail_registered;
2345 }
2346
Ben Hutchings8ceee662008-04-27 12:55:59 +01002347 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08002348
Ben Hutchings7153f622012-07-27 20:50:52 +01002349fail_registered:
2350 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002351 efx_dissociate(efx);
Ben Hutchings7153f622012-07-27 20:50:52 +01002352 unregister_netdevice(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002353fail_locked:
Ben Hutchings7153f622012-07-27 20:50:52 +01002354 efx->state = STATE_UNINIT;
Ben Hutchingsaed06282009-08-26 08:16:27 +00002355 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00002356 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00002357 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002358}
2359
2360static void efx_unregister_netdev(struct efx_nic *efx)
2361{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002362 if (!efx->net_dev)
2363 return;
2364
Ben Hutchings767e4682008-09-01 12:43:14 +01002365 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002366
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002367 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2368 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
Ben Hutchings7153f622012-07-27 20:50:52 +01002369
2370 rtnl_lock();
2371 unregister_netdevice(efx->net_dev);
2372 efx->state = STATE_UNINIT;
2373 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002374}
2375
2376/**************************************************************************
2377 *
2378 * Device reset and suspend
2379 *
2380 **************************************************************************/
2381
Ben Hutchings2467ca42008-09-01 12:48:50 +01002382/* Tears down the entire software state and most of the hardware state
2383 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002384void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002385{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002386 EFX_ASSERT_RESET_SERIALISED(efx);
2387
Edward Creee2835462014-04-16 19:27:48 +01002388 if (method == RESET_TYPE_MCDI_TIMEOUT)
2389 efx->type->prepare_flr(efx);
2390
Ben Hutchings2467ca42008-09-01 12:48:50 +01002391 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01002392 efx_disable_interrupts(efx);
Ben Hutchings5642cee2012-07-27 19:35:52 +01002393
2394 mutex_lock(&efx->mac_lock);
Steve Hodgson4b988282009-01-29 17:50:51 +00002395 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
2396 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002397 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002398}
2399
Ben Hutchings2467ca42008-09-01 12:48:50 +01002400/* This function will always ensure that the locks acquired in
2401 * efx_reset_down() are released. A failure return code indicates
2402 * that we were unable to reinitialise the hardware, and the
2403 * driver should be disabled. If ok is false, then the rx and tx
2404 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002405int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002406{
2407 int rc;
2408
Ben Hutchings2467ca42008-09-01 12:48:50 +01002409 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002410
Edward Creee2835462014-04-16 19:27:48 +01002411 if (method == RESET_TYPE_MCDI_TIMEOUT)
2412 efx->type->finish_flr(efx);
2413
2414 /* Ensure that SRAM is initialised even if we're disabling the device */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002415 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002416 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002417 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002418 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002419 }
2420
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002421 if (!ok)
2422 goto fail;
2423
Steve Hodgson4b988282009-01-29 17:50:51 +00002424 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002425 rc = efx->phy_op->init(efx);
2426 if (rc)
2427 goto fail;
2428 if (efx->phy_op->reconfigure(efx))
Ben Hutchings62776d02010-06-23 11:30:07 +00002429 netif_err(efx, drv, efx->net_dev,
2430 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002431 }
2432
Jon Cooper261e4d92013-04-15 18:51:54 +01002433 rc = efx_enable_interrupts(efx);
2434 if (rc)
2435 goto fail;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002436 efx_restore_filters(efx);
Shradha Shah327c6852014-11-05 12:16:32 +00002437 efx_siena_sriov_reset(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002438
2439 mutex_unlock(&efx->mac_lock);
2440
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002441 efx_start_all(efx);
2442
2443 return 0;
2444
2445fail:
2446 efx->port_initialized = false;
2447
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002448 mutex_unlock(&efx->mac_lock);
2449
Ben Hutchings8ceee662008-04-27 12:55:59 +01002450 return rc;
2451}
2452
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002453/* Reset the NIC using the specified method. Note that the reset may
2454 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002455 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002456 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002457 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002458int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002459{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002460 int rc, rc2;
2461 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002462
Ben Hutchings62776d02010-06-23 11:30:07 +00002463 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2464 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002465
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01002466 efx_device_detach_sync(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002467 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002468
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002469 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002470 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002471 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002472 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002473 }
2474
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002475 /* Clear flags for the scopes we covered. We assume the NIC and
2476 * driver are now quiescent so that there is no race here.
2477 */
Edward Creee2835462014-04-16 19:27:48 +01002478 if (method < RESET_TYPE_MAX_METHOD)
2479 efx->reset_pending &= -(1 << (method + 1));
2480 else /* it doesn't fit into the well-ordered scope hierarchy */
2481 __clear_bit(method, &efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002482
2483 /* Reinitialise bus-mastering, which may have been turned off before
2484 * the reset was scheduled. This is still appropriate, even in the
2485 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2486 * can respond to requests. */
2487 pci_set_master(efx->pci_dev);
2488
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002489out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002490 /* Leave device stopped if necessary */
Alexandre Rames626950d2013-01-14 17:20:22 +00002491 disabled = rc ||
2492 method == RESET_TYPE_DISABLE ||
2493 method == RESET_TYPE_RECOVER_OR_DISABLE;
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002494 rc2 = efx_reset_up(efx, method, !disabled);
2495 if (rc2) {
2496 disabled = true;
2497 if (!rc)
2498 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002499 }
2500
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002501 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002502 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002503 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002504 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002505 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002506 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Ben Hutchingse4abce82011-05-16 18:51:24 +01002507 netif_device_attach(efx->net_dev);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002508 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002509 return rc;
2510}
2511
Alexandre Rames626950d2013-01-14 17:20:22 +00002512/* Try recovery mechanisms.
2513 * For now only EEH is supported.
2514 * Returns 0 if the recovery mechanisms are unsuccessful.
2515 * Returns a non-zero value otherwise.
2516 */
Alexandre Ramesb28405b2013-03-21 16:41:43 +00002517int efx_try_recovery(struct efx_nic *efx)
Alexandre Rames626950d2013-01-14 17:20:22 +00002518{
2519#ifdef CONFIG_EEH
2520 /* A PCI error can occur and not be seen by EEH because nothing
2521 * happens on the PCI bus. In this case the driver may fail and
2522 * schedule a 'recover or reset', leading to this recovery handler.
2523 * Manually call the eeh failure check function.
2524 */
2525 struct eeh_dev *eehdev =
2526 of_node_to_eeh_dev(pci_device_to_OF_node(efx->pci_dev));
2527
2528 if (eeh_dev_check_failure(eehdev)) {
2529 /* The EEH mechanisms will handle the error and reset the
2530 * device if necessary.
2531 */
2532 return 1;
2533 }
2534#endif
2535 return 0;
2536}
2537
Jon Cooper74cd60a2013-09-16 14:18:51 +01002538static void efx_wait_for_bist_end(struct efx_nic *efx)
2539{
2540 int i;
2541
2542 for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
2543 if (efx_mcdi_poll_reboot(efx))
2544 goto out;
2545 msleep(BIST_WAIT_DELAY_MS);
2546 }
2547
2548 netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
2549out:
2550 /* Either way unset the BIST flag. If we found no reboot we probably
2551 * won't recover, but we should try.
2552 */
2553 efx->mc_bist_for_other_fn = false;
2554}
2555
Ben Hutchings8ceee662008-04-27 12:55:59 +01002556/* The worker thread exists so that code that cannot sleep can
2557 * schedule a reset for later.
2558 */
2559static void efx_reset_work(struct work_struct *data)
2560{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002561 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Alexandre Rames626950d2013-01-14 17:20:22 +00002562 unsigned long pending;
2563 enum reset_type method;
2564
2565 pending = ACCESS_ONCE(efx->reset_pending);
2566 method = fls(pending) - 1;
2567
Jon Cooper74cd60a2013-09-16 14:18:51 +01002568 if (method == RESET_TYPE_MC_BIST)
2569 efx_wait_for_bist_end(efx);
2570
Alexandre Rames626950d2013-01-14 17:20:22 +00002571 if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
2572 method == RESET_TYPE_RECOVER_OR_ALL) &&
2573 efx_try_recovery(efx))
2574 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002575
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002576 if (!pending)
Steve Hodgson319ba642010-06-01 11:17:24 +00002577 return;
2578
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002579 rtnl_lock();
Ben Hutchings7153f622012-07-27 20:50:52 +01002580
2581 /* We checked the state in efx_schedule_reset() but it may
2582 * have changed by now. Now that we have the RTNL lock,
2583 * it cannot change again.
2584 */
2585 if (efx->state == STATE_READY)
Alexandre Rames626950d2013-01-14 17:20:22 +00002586 (void)efx_reset(efx, method);
Ben Hutchings7153f622012-07-27 20:50:52 +01002587
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002588 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002589}
2590
2591void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2592{
2593 enum reset_type method;
2594
Alexandre Rames626950d2013-01-14 17:20:22 +00002595 if (efx->state == STATE_RECOVERY) {
2596 netif_dbg(efx, drv, efx->net_dev,
2597 "recovering: skip scheduling %s reset\n",
2598 RESET_TYPE(type));
2599 return;
2600 }
2601
Ben Hutchings8ceee662008-04-27 12:55:59 +01002602 switch (type) {
2603 case RESET_TYPE_INVISIBLE:
2604 case RESET_TYPE_ALL:
Alexandre Rames626950d2013-01-14 17:20:22 +00002605 case RESET_TYPE_RECOVER_OR_ALL:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002606 case RESET_TYPE_WORLD:
2607 case RESET_TYPE_DISABLE:
Alexandre Rames626950d2013-01-14 17:20:22 +00002608 case RESET_TYPE_RECOVER_OR_DISABLE:
Jon Cooper74cd60a2013-09-16 14:18:51 +01002609 case RESET_TYPE_MC_BIST:
Edward Creee2835462014-04-16 19:27:48 +01002610 case RESET_TYPE_MCDI_TIMEOUT:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002611 method = type;
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002612 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2613 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002614 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002615 default:
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002616 method = efx->type->map_reset_reason(type);
Ben Hutchings62776d02010-06-23 11:30:07 +00002617 netif_dbg(efx, drv, efx->net_dev,
2618 "scheduling %s reset for %s\n",
2619 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002620 break;
2621 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002622
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002623 set_bit(method, &efx->reset_pending);
Ben Hutchings7153f622012-07-27 20:50:52 +01002624 smp_mb(); /* ensure we change reset_pending before checking state */
2625
2626 /* If we're not READY then just leave the flags set as the cue
2627 * to abort probing or reschedule the reset later.
2628 */
2629 if (ACCESS_ONCE(efx->state) != STATE_READY)
2630 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002631
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002632 /* efx_process_channel() will no longer read events once a
2633 * reset is scheduled. So switch back to poll'd MCDI completions. */
2634 efx_mcdi_mode_poll(efx);
2635
Steve Hodgson1ab00622008-12-12 21:33:02 -08002636 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002637}
2638
2639/**************************************************************************
2640 *
2641 * List of NICs we support
2642 *
2643 **************************************************************************/
2644
2645/* PCI device ID table */
Benoit Taine9baa3c32014-08-08 15:56:03 +02002646static const struct pci_device_id efx_pci_table[] = {
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002647 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2648 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002649 .driver_data = (unsigned long) &falcon_a1_nic_type},
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002650 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2651 PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002652 .driver_data = (unsigned long) &falcon_b0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002653 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002654 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002655 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002656 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8127d662013-08-29 19:19:29 +01002657 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
2658 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Mateusz Wrzesinski3b06a002014-07-14 08:38:49 +01002659 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
2660 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002661 {0} /* end of list */
2662};
2663
2664/**************************************************************************
2665 *
Ben Hutchings37594332009-11-23 16:05:45 +00002666 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002667 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002668 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002669 * Needed so all function pointers are valid and do not have to be tested
2670 * before use
2671 *
2672 **************************************************************************/
2673int efx_port_dummy_op_int(struct efx_nic *efx)
2674{
2675 return 0;
2676}
2677void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002678
2679static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002680{
2681 return false;
2682}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002683
stephen hemminger6c8c2512011-04-14 05:50:12 +00002684static const struct efx_phy_operations efx_dummy_phy_operations = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002685 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002686 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002687 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002688 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002689};
2690
Ben Hutchings8ceee662008-04-27 12:55:59 +01002691/**************************************************************************
2692 *
2693 * Data housekeeping
2694 *
2695 **************************************************************************/
2696
2697/* This zeroes out and then fills in the invariants in a struct
2698 * efx_nic (including all sub-structures).
2699 */
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01002700static int efx_init_struct(struct efx_nic *efx,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002701 struct pci_dev *pci_dev, struct net_device *net_dev)
2702{
Ben Hutchings46426102010-09-10 06:42:33 +00002703 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002704
2705 /* Initialise common structures */
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002706 INIT_LIST_HEAD(&efx->node);
2707 INIT_LIST_HEAD(&efx->secondary_list);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002708 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002709#ifdef CONFIG_SFC_MTD
2710 INIT_LIST_HEAD(&efx->mtd_list);
2711#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002712 INIT_WORK(&efx->reset_work, efx_reset_work);
2713 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002714 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002715 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002716 efx->msg_enable = debug;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002717 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002718 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002719
2720 efx->net_dev = net_dev;
Jon Cooper43a37392012-10-18 15:49:54 +01002721 efx->rx_prefix_size = efx->type->rx_prefix_size;
Andrew Rybchenko2ec03012013-11-16 11:02:27 +04002722 efx->rx_ip_align =
2723 NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
Jon Cooper43a37392012-10-18 15:49:54 +01002724 efx->rx_packet_hash_offset =
2725 efx->type->rx_hash_offset - efx->type->rx_prefix_size;
Jon Cooperbd9a2652013-11-18 12:54:41 +00002726 efx->rx_packet_ts_offset =
2727 efx->type->rx_ts_offset - efx->type->rx_prefix_size;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002728 spin_lock_init(&efx->stats_lock);
2729 mutex_init(&efx->mac_lock);
2730 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002731 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08002732 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00002733 init_waitqueue_head(&efx->flush_wq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002734
2735 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00002736 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
2737 if (!efx->channel[i])
2738 goto fail;
Ben Hutchingsd8291182012-10-05 23:35:41 +01002739 efx->msi_context[i].efx = efx;
2740 efx->msi_context[i].index = i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002741 }
2742
Ben Hutchings8ceee662008-04-27 12:55:59 +01002743 /* Higher numbered interrupt modes are less capable! */
2744 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
2745 interrupt_mode);
2746
Ben Hutchings6977dc62008-12-26 13:44:39 -08002747 /* Would be good to use the net_dev name, but we're too early */
2748 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
2749 pci_name(pci_dev));
2750 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002751 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00002752 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01002753
Ben Hutchings8ceee662008-04-27 12:55:59 +01002754 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00002755
2756fail:
2757 efx_fini_struct(efx);
2758 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002759}
2760
2761static void efx_fini_struct(struct efx_nic *efx)
2762{
Ben Hutchings8313aca2010-09-10 06:41:57 +00002763 int i;
2764
2765 for (i = 0; i < EFX_MAX_CHANNELS; i++)
2766 kfree(efx->channel[i]);
2767
Ben Hutchingsef215e62013-12-05 20:13:22 +00002768 kfree(efx->vpd_sn);
2769
Ben Hutchings8ceee662008-04-27 12:55:59 +01002770 if (efx->workqueue) {
2771 destroy_workqueue(efx->workqueue);
2772 efx->workqueue = NULL;
2773 }
2774}
2775
Edward Creee4d112e2014-07-15 11:58:12 +01002776void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
2777{
2778 u64 n_rx_nodesc_trunc = 0;
2779 struct efx_channel *channel;
2780
2781 efx_for_each_channel(channel, efx)
2782 n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
2783 stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
2784 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
2785}
2786
Ben Hutchings8ceee662008-04-27 12:55:59 +01002787/**************************************************************************
2788 *
2789 * PCI interface
2790 *
2791 **************************************************************************/
2792
2793/* Main body of final NIC shutdown code
2794 * This is called only at module unload (or hotplug removal).
2795 */
2796static void efx_pci_remove_main(struct efx_nic *efx)
2797{
Ben Hutchings7153f622012-07-27 20:50:52 +01002798 /* Flush reset_work. It can no longer be scheduled since we
2799 * are not READY.
2800 */
2801 BUG_ON(efx->state == STATE_READY);
2802 cancel_work_sync(&efx->reset_work);
2803
Ben Hutchingsd8291182012-10-05 23:35:41 +01002804 efx_disable_interrupts(efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +00002805 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002806 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002807 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002808 efx_fini_napi(efx);
2809 efx_remove_all(efx);
2810}
2811
2812/* Final NIC shutdown
2813 * This is called only at module unload (or hotplug removal).
2814 */
2815static void efx_pci_remove(struct pci_dev *pci_dev)
2816{
2817 struct efx_nic *efx;
2818
2819 efx = pci_get_drvdata(pci_dev);
2820 if (!efx)
2821 return;
2822
2823 /* Mark the NIC as fini, then stop the interface */
2824 rtnl_lock();
Ben Hutchings0bcf4a62013-10-18 19:21:45 +01002825 efx_dissociate(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002826 dev_close(efx->net_dev);
Ben Hutchingsd8291182012-10-05 23:35:41 +01002827 efx_disable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002828 rtnl_unlock();
2829
Shradha Shah327c6852014-11-05 12:16:32 +00002830 efx_siena_sriov_fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002831 efx_unregister_netdev(efx);
2832
Ben Hutchings7dde5962008-12-12 22:09:38 -08002833 efx_mtd_remove(efx);
2834
Ben Hutchings8ceee662008-04-27 12:55:59 +01002835 efx_pci_remove_main(efx);
2836
Ben Hutchings8ceee662008-04-27 12:55:59 +01002837 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002838 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002839
Ben Hutchings8ceee662008-04-27 12:55:59 +01002840 efx_fini_struct(efx);
2841 free_netdev(efx->net_dev);
Alexandre Rames626950d2013-01-14 17:20:22 +00002842
2843 pci_disable_pcie_error_reporting(pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002844};
2845
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002846/* NIC VPD information
2847 * Called during probe to display the part number of the
2848 * installed NIC. VPD is potentially very large but this should
2849 * always appear within the first 512 bytes.
2850 */
2851#define SFC_VPD_LEN 512
Ben Hutchingsef215e62013-12-05 20:13:22 +00002852static void efx_probe_vpd_strings(struct efx_nic *efx)
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002853{
2854 struct pci_dev *dev = efx->pci_dev;
2855 char vpd_data[SFC_VPD_LEN];
2856 ssize_t vpd_size;
Ben Hutchingsef215e62013-12-05 20:13:22 +00002857 int ro_start, ro_size, i, j;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002858
2859 /* Get the vpd data from the device */
2860 vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
2861 if (vpd_size <= 0) {
2862 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
2863 return;
2864 }
2865
2866 /* Get the Read only section */
Ben Hutchingsef215e62013-12-05 20:13:22 +00002867 ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
2868 if (ro_start < 0) {
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002869 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
2870 return;
2871 }
2872
Ben Hutchingsef215e62013-12-05 20:13:22 +00002873 ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
2874 j = ro_size;
2875 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002876 if (i + j > vpd_size)
2877 j = vpd_size - i;
2878
2879 /* Get the Part number */
2880 i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
2881 if (i < 0) {
2882 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
2883 return;
2884 }
2885
2886 j = pci_vpd_info_field_size(&vpd_data[i]);
2887 i += PCI_VPD_INFO_FLD_HDR_SIZE;
2888 if (i + j > vpd_size) {
2889 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
2890 return;
2891 }
2892
2893 netif_info(efx, drv, efx->net_dev,
2894 "Part Number : %.*s\n", j, &vpd_data[i]);
Ben Hutchingsef215e62013-12-05 20:13:22 +00002895
2896 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
2897 j = ro_size;
2898 i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
2899 if (i < 0) {
2900 netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
2901 return;
2902 }
2903
2904 j = pci_vpd_info_field_size(&vpd_data[i]);
2905 i += PCI_VPD_INFO_FLD_HDR_SIZE;
2906 if (i + j > vpd_size) {
2907 netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
2908 return;
2909 }
2910
2911 efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
2912 if (!efx->vpd_sn)
2913 return;
2914
2915 snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002916}
2917
2918
Ben Hutchings8ceee662008-04-27 12:55:59 +01002919/* Main body of NIC initialisation
2920 * This is called at module load (or hotplug insertion, theoretically).
2921 */
2922static int efx_pci_probe_main(struct efx_nic *efx)
2923{
2924 int rc;
2925
2926 /* Do start-of-day initialisation */
2927 rc = efx_probe_all(efx);
2928 if (rc)
2929 goto fail1;
2930
Ben Hutchingse8f14992010-12-07 19:47:34 +00002931 efx_init_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002932
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002933 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002934 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002935 netif_err(efx, probe, efx->net_dev,
2936 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002937 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002938 }
2939
2940 rc = efx_init_port(efx);
2941 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002942 netif_err(efx, probe, efx->net_dev,
2943 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002944 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002945 }
2946
Ben Hutchings152b6a62009-11-29 03:43:56 +00002947 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002948 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00002949 goto fail5;
Jon Cooper261e4d92013-04-15 18:51:54 +01002950 rc = efx_enable_interrupts(efx);
2951 if (rc)
2952 goto fail6;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002953
2954 return 0;
2955
Jon Cooper261e4d92013-04-15 18:51:54 +01002956 fail6:
2957 efx_nic_fini_interrupt(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +00002958 fail5:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002959 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002960 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002961 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002962 fail3:
2963 efx_fini_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002964 efx_remove_all(efx);
2965 fail1:
2966 return rc;
2967}
2968
2969/* NIC initialisation
2970 *
2971 * This is called at module load (or hotplug insertion,
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002972 * theoretically). It sets up PCI mappings, resets the NIC,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002973 * sets up and registers the network devices with the kernel and hooks
2974 * the interrupt service routine. It does not prepare the device for
2975 * transmission; this is left to the first time one of the network
2976 * interfaces is brought up (i.e. efx_net_open).
2977 */
Bill Pemberton87d1fc12012-12-03 09:23:32 -05002978static int efx_pci_probe(struct pci_dev *pci_dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00002979 const struct pci_device_id *entry)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002980{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002981 struct net_device *net_dev;
2982 struct efx_nic *efx;
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002983 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002984
2985 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchings94b274b2011-01-10 21:18:20 +00002986 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
2987 EFX_MAX_RX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002988 if (!net_dev)
2989 return -ENOMEM;
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01002990 efx = netdev_priv(net_dev);
2991 efx->type = (const struct efx_nic_type *) entry->driver_data;
2992 net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
Ben Hutchings97bc5412009-05-19 16:19:08 -07002993 NETIF_F_HIGHDMA | NETIF_F_TSO |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002994 NETIF_F_RXCSUM);
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01002995 if (efx->type->offload_features & NETIF_F_V6_CSUM)
Ben Hutchings738a8f42009-11-29 15:16:05 +00002996 net_dev->features |= NETIF_F_TSO6;
Ben Hutchings285065632008-09-01 12:46:54 +01002997 /* Mask for features that also apply to VLAN devices */
2998 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002999 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
3000 NETIF_F_RXCSUM);
3001 /* All offloads can be toggled */
3002 net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003003 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00003004 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchingsadeb15a2012-08-02 01:39:38 +01003005 rc = efx_init_struct(efx, pci_dev, net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003006 if (rc)
3007 goto fail1;
3008
Ben Hutchings62776d02010-06-23 11:30:07 +00003009 netif_info(efx, probe, efx->net_dev,
Ben Hutchingsff79c8a2011-07-13 16:21:24 +01003010 "Solarflare NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003011
Ben Hutchingsef215e62013-12-05 20:13:22 +00003012 efx_probe_vpd_strings(efx);
Ben Hutchings460eeaa2012-03-05 15:35:39 +00003013
Ben Hutchings8ceee662008-04-27 12:55:59 +01003014 /* Set up basic I/O (BAR mappings etc) */
3015 rc = efx_init_io(efx);
3016 if (rc)
3017 goto fail2;
3018
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003019 rc = efx_pci_probe_main(efx);
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003020 if (rc)
3021 goto fail3;
Steve Hodgsonfa402b22008-12-12 22:08:16 -08003022
Ben Hutchings8ceee662008-04-27 12:55:59 +01003023 rc = efx_register_netdev(efx);
3024 if (rc)
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003025 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003026
Shradha Shah327c6852014-11-05 12:16:32 +00003027 rc = efx_siena_sriov_init(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003028 if (rc)
3029 netif_err(efx, probe, efx->net_dev,
3030 "SR-IOV can't be enabled rc %d\n", rc);
3031
Ben Hutchings62776d02010-06-23 11:30:07 +00003032 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003033
Ben Hutchings7c431612012-01-27 17:23:58 +00003034 /* Try to create MTDs, but allow this to fail */
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003035 rtnl_lock();
Ben Hutchings7c431612012-01-27 17:23:58 +00003036 rc = efx_mtd_probe(efx);
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00003037 rtnl_unlock();
Ben Hutchings7c431612012-01-27 17:23:58 +00003038 if (rc)
3039 netif_warn(efx, probe, efx->net_dev,
3040 "failed to create MTDs (%d)\n", rc);
3041
Alexandre Rames626950d2013-01-14 17:20:22 +00003042 rc = pci_enable_pcie_error_reporting(pci_dev);
3043 if (rc && rc != -EINVAL)
3044 netif_warn(efx, probe, efx->net_dev,
3045 "pci_enable_pcie_error_reporting failed (%d)\n", rc);
3046
Ben Hutchings8ceee662008-04-27 12:55:59 +01003047 return 0;
3048
Ben Hutchings8ceee662008-04-27 12:55:59 +01003049 fail4:
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00003050 efx_pci_remove_main(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003051 fail3:
3052 efx_fini_io(efx);
3053 fail2:
3054 efx_fini_struct(efx);
3055 fail1:
Steve Hodgson5e2a9112010-02-12 12:32:27 -08003056 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00003057 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003058 free_netdev(net_dev);
3059 return rc;
3060}
3061
Ben Hutchings89c758f2009-11-29 03:43:07 +00003062static int efx_pm_freeze(struct device *dev)
3063{
3064 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3065
Ben Hutchings61da0262012-07-27 19:35:39 +01003066 rtnl_lock();
3067
Ben Hutchings6032fb52012-07-27 19:35:47 +01003068 if (efx->state != STATE_DISABLED) {
3069 efx->state = STATE_UNINIT;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003070
Daniel Pieczkoc2f3b8e2012-10-17 13:21:23 +01003071 efx_device_detach_sync(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003072
Ben Hutchings6032fb52012-07-27 19:35:47 +01003073 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003074 efx_disable_interrupts(efx);
Ben Hutchings6032fb52012-07-27 19:35:47 +01003075 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003076
Ben Hutchings61da0262012-07-27 19:35:39 +01003077 rtnl_unlock();
3078
Ben Hutchings89c758f2009-11-29 03:43:07 +00003079 return 0;
3080}
3081
3082static int efx_pm_thaw(struct device *dev)
3083{
Jon Cooper261e4d92013-04-15 18:51:54 +01003084 int rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003085 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3086
Ben Hutchings61da0262012-07-27 19:35:39 +01003087 rtnl_lock();
3088
Ben Hutchings6032fb52012-07-27 19:35:47 +01003089 if (efx->state != STATE_DISABLED) {
Jon Cooper261e4d92013-04-15 18:51:54 +01003090 rc = efx_enable_interrupts(efx);
3091 if (rc)
3092 goto fail;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003093
Ben Hutchings6032fb52012-07-27 19:35:47 +01003094 mutex_lock(&efx->mac_lock);
3095 efx->phy_op->reconfigure(efx);
3096 mutex_unlock(&efx->mac_lock);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003097
Ben Hutchings6032fb52012-07-27 19:35:47 +01003098 efx_start_all(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003099
Ben Hutchings6032fb52012-07-27 19:35:47 +01003100 netif_device_attach(efx->net_dev);
Ben Hutchings89c758f2009-11-29 03:43:07 +00003101
Ben Hutchings6032fb52012-07-27 19:35:47 +01003102 efx->state = STATE_READY;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003103
Ben Hutchings6032fb52012-07-27 19:35:47 +01003104 efx->type->resume_wol(efx);
3105 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00003106
Ben Hutchings61da0262012-07-27 19:35:39 +01003107 rtnl_unlock();
3108
Steve Hodgson319ba642010-06-01 11:17:24 +00003109 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
3110 queue_work(reset_workqueue, &efx->reset_work);
3111
Ben Hutchings89c758f2009-11-29 03:43:07 +00003112 return 0;
Jon Cooper261e4d92013-04-15 18:51:54 +01003113
3114fail:
3115 rtnl_unlock();
3116
3117 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003118}
3119
3120static int efx_pm_poweroff(struct device *dev)
3121{
3122 struct pci_dev *pci_dev = to_pci_dev(dev);
3123 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3124
3125 efx->type->fini(efx);
3126
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01003127 efx->reset_pending = 0;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003128
3129 pci_save_state(pci_dev);
3130 return pci_set_power_state(pci_dev, PCI_D3hot);
3131}
3132
3133/* Used for both resume and restore */
3134static int efx_pm_resume(struct device *dev)
3135{
3136 struct pci_dev *pci_dev = to_pci_dev(dev);
3137 struct efx_nic *efx = pci_get_drvdata(pci_dev);
3138 int rc;
3139
3140 rc = pci_set_power_state(pci_dev, PCI_D0);
3141 if (rc)
3142 return rc;
3143 pci_restore_state(pci_dev);
3144 rc = pci_enable_device(pci_dev);
3145 if (rc)
3146 return rc;
3147 pci_set_master(efx->pci_dev);
3148 rc = efx->type->reset(efx, RESET_TYPE_ALL);
3149 if (rc)
3150 return rc;
3151 rc = efx->type->init(efx);
3152 if (rc)
3153 return rc;
Jon Cooper261e4d92013-04-15 18:51:54 +01003154 rc = efx_pm_thaw(dev);
3155 return rc;
Ben Hutchings89c758f2009-11-29 03:43:07 +00003156}
3157
3158static int efx_pm_suspend(struct device *dev)
3159{
3160 int rc;
3161
3162 efx_pm_freeze(dev);
3163 rc = efx_pm_poweroff(dev);
3164 if (rc)
3165 efx_pm_resume(dev);
3166 return rc;
3167}
3168
Ben Hutchings18e83e42012-01-05 19:05:20 +00003169static const struct dev_pm_ops efx_pm_ops = {
Ben Hutchings89c758f2009-11-29 03:43:07 +00003170 .suspend = efx_pm_suspend,
3171 .resume = efx_pm_resume,
3172 .freeze = efx_pm_freeze,
3173 .thaw = efx_pm_thaw,
3174 .poweroff = efx_pm_poweroff,
3175 .restore = efx_pm_resume,
3176};
3177
Alexandre Rames626950d2013-01-14 17:20:22 +00003178/* A PCI error affecting this device was detected.
3179 * At this point MMIO and DMA may be disabled.
3180 * Stop the software path and request a slot reset.
3181 */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003182static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
3183 enum pci_channel_state state)
Alexandre Rames626950d2013-01-14 17:20:22 +00003184{
3185 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3186 struct efx_nic *efx = pci_get_drvdata(pdev);
3187
3188 if (state == pci_channel_io_perm_failure)
3189 return PCI_ERS_RESULT_DISCONNECT;
3190
3191 rtnl_lock();
3192
3193 if (efx->state != STATE_DISABLED) {
3194 efx->state = STATE_RECOVERY;
3195 efx->reset_pending = 0;
3196
3197 efx_device_detach_sync(efx);
3198
3199 efx_stop_all(efx);
Ben Hutchingsd8291182012-10-05 23:35:41 +01003200 efx_disable_interrupts(efx);
Alexandre Rames626950d2013-01-14 17:20:22 +00003201
3202 status = PCI_ERS_RESULT_NEED_RESET;
3203 } else {
3204 /* If the interface is disabled we don't want to do anything
3205 * with it.
3206 */
3207 status = PCI_ERS_RESULT_RECOVERED;
3208 }
3209
3210 rtnl_unlock();
3211
3212 pci_disable_device(pdev);
3213
3214 return status;
3215}
3216
3217/* Fake a successfull reset, which will be performed later in efx_io_resume. */
stephen hemmingerdebd0032013-03-16 06:57:51 +00003218static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
Alexandre Rames626950d2013-01-14 17:20:22 +00003219{
3220 struct efx_nic *efx = pci_get_drvdata(pdev);
3221 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3222 int rc;
3223
3224 if (pci_enable_device(pdev)) {
3225 netif_err(efx, hw, efx->net_dev,
3226 "Cannot re-enable PCI device after reset.\n");
3227 status = PCI_ERS_RESULT_DISCONNECT;
3228 }
3229
3230 rc = pci_cleanup_aer_uncorrect_error_status(pdev);
3231 if (rc) {
3232 netif_err(efx, hw, efx->net_dev,
3233 "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
3234 /* Non-fatal error. Continue. */
3235 }
3236
3237 return status;
3238}
3239
3240/* Perform the actual reset and resume I/O operations. */
3241static void efx_io_resume(struct pci_dev *pdev)
3242{
3243 struct efx_nic *efx = pci_get_drvdata(pdev);
3244 int rc;
3245
3246 rtnl_lock();
3247
3248 if (efx->state == STATE_DISABLED)
3249 goto out;
3250
3251 rc = efx_reset(efx, RESET_TYPE_ALL);
3252 if (rc) {
3253 netif_err(efx, hw, efx->net_dev,
3254 "efx_reset failed after PCI error (%d)\n", rc);
3255 } else {
3256 efx->state = STATE_READY;
3257 netif_dbg(efx, hw, efx->net_dev,
3258 "Done resetting and resuming IO after PCI error.\n");
3259 }
3260
3261out:
3262 rtnl_unlock();
3263}
3264
3265/* For simplicity and reliability, we always require a slot reset and try to
3266 * reset the hardware when a pci error affecting the device is detected.
3267 * We leave both the link_reset and mmio_enabled callback unimplemented:
3268 * with our request for slot reset the mmio_enabled callback will never be
3269 * called, and the link_reset callback is not used by AER or EEH mechanisms.
3270 */
3271static struct pci_error_handlers efx_err_handlers = {
3272 .error_detected = efx_io_error_detected,
3273 .slot_reset = efx_io_slot_reset,
3274 .resume = efx_io_resume,
3275};
3276
Ben Hutchings8ceee662008-04-27 12:55:59 +01003277static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00003278 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003279 .id_table = efx_pci_table,
3280 .probe = efx_pci_probe,
3281 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00003282 .driver.pm = &efx_pm_ops,
Alexandre Rames626950d2013-01-14 17:20:22 +00003283 .err_handler = &efx_err_handlers,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003284};
3285
3286/**************************************************************************
3287 *
3288 * Kernel module interface
3289 *
3290 *************************************************************************/
3291
3292module_param(interrupt_mode, uint, 0444);
3293MODULE_PARM_DESC(interrupt_mode,
3294 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3295
3296static int __init efx_init_module(void)
3297{
3298 int rc;
3299
3300 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
3301
3302 rc = register_netdevice_notifier(&efx_netdev_notifier);
3303 if (rc)
3304 goto err_notifier;
3305
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003306 rc = efx_init_sriov();
3307 if (rc)
3308 goto err_sriov;
3309
Steve Hodgson1ab00622008-12-12 21:33:02 -08003310 reset_workqueue = create_singlethread_workqueue("sfc_reset");
3311 if (!reset_workqueue) {
3312 rc = -ENOMEM;
3313 goto err_reset;
3314 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003315
3316 rc = pci_register_driver(&efx_pci_driver);
3317 if (rc < 0)
3318 goto err_pci;
3319
3320 return 0;
3321
3322 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08003323 destroy_workqueue(reset_workqueue);
3324 err_reset:
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003325 efx_fini_sriov();
3326 err_sriov:
Ben Hutchings8ceee662008-04-27 12:55:59 +01003327 unregister_netdevice_notifier(&efx_netdev_notifier);
3328 err_notifier:
3329 return rc;
3330}
3331
3332static void __exit efx_exit_module(void)
3333{
3334 printk(KERN_INFO "Solarflare NET driver unloading\n");
3335
3336 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08003337 destroy_workqueue(reset_workqueue);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00003338 efx_fini_sriov();
Ben Hutchings8ceee662008-04-27 12:55:59 +01003339 unregister_netdevice_notifier(&efx_netdev_notifier);
3340
3341}
3342
3343module_init(efx_init_module);
3344module_exit(efx_exit_module);
3345
Ben Hutchings906bb262009-11-29 15:16:19 +00003346MODULE_AUTHOR("Solarflare Communications and "
3347 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings6a350fd2014-02-12 19:00:07 +00003348MODULE_DESCRIPTION("Solarflare network driver");
Ben Hutchings8ceee662008-04-27 12:55:59 +01003349MODULE_LICENSE("GPL");
3350MODULE_DEVICE_TABLE(pci, efx_pci_table);