blob: f02591bb62f479c4fecdb9cc074bf3f646df0da2 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchings0a6f40c2011-02-25 00:01:34 +00004 * Copyright 2005-2011 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>
20#include <linux/crc32.h>
21#include <linux/ethtool.h>
Ben Hutchingsaa6ef272008-07-18 19:03:10 +010022#include <linux/topology.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/gfp.h>
Ben Hutchings64d8ad62011-01-05 00:50:41 +000024#include <linux/cpu_rmap.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[] = {
Ben Hutchingsc4593022009-11-23 16:08:17 +000074 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
75 [RESET_TYPE_ALL] = "ALL",
76 [RESET_TYPE_WORLD] = "WORLD",
77 [RESET_TYPE_DISABLE] = "DISABLE",
78 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
79 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
80 [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
81 [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH",
82 [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH",
83 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
Ben Hutchings8880f4e2009-11-29 15:15:41 +000084 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
Ben Hutchingsc4593022009-11-23 16:08:17 +000085};
86
Ben Hutchings8ceee662008-04-27 12:55:59 +010087#define EFX_MAX_MTU (9 * 1024)
88
Steve Hodgson1ab00622008-12-12 21:33:02 -080089/* Reset workqueue. If any NIC has a hardware failure then a reset will be
90 * queued onto this work queue. This is not a per-nic work queue, because
91 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
92 */
93static struct workqueue_struct *reset_workqueue;
94
Ben Hutchings8ceee662008-04-27 12:55:59 +010095/**************************************************************************
96 *
97 * Configurable values
98 *
99 *************************************************************************/
100
101/*
Ben Hutchings8ceee662008-04-27 12:55:59 +0100102 * Use separate channels for TX and RX events
103 *
Neil Turton28b581a2008-12-12 21:41:06 -0800104 * Set this to 1 to use separate channels for TX and RX. It allows us
105 * to control interrupt affinity separately for TX and RX.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100106 *
Neil Turton28b581a2008-12-12 21:41:06 -0800107 * This is only used in MSI-X interrupt mode
Ben Hutchings8ceee662008-04-27 12:55:59 +0100108 */
Neil Turton28b581a2008-12-12 21:41:06 -0800109static unsigned int separate_tx_channels;
Ben Hutchings8313aca2010-09-10 06:41:57 +0000110module_param(separate_tx_channels, uint, 0444);
Neil Turton28b581a2008-12-12 21:41:06 -0800111MODULE_PARM_DESC(separate_tx_channels,
112 "Use separate channels for TX and RX");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100113
114/* This is the weight assigned to each of the (per-channel) virtual
115 * NAPI devices.
116 */
117static int napi_weight = 64;
118
119/* This is the time (in jiffies) between invocations of the hardware
Ben Hutchingse254c272010-09-20 08:44:10 +0000120 * monitor. On Falcon-based NICs, this will:
121 * - Check the on-board hardware monitor;
122 * - Poll the link state and reconfigure the hardware as necessary.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100123 */
stephen hemmingerd2156972010-10-18 05:27:31 +0000124static unsigned int efx_monitor_interval = 1 * HZ;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100125
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126/* Initial interrupt moderation settings. They can be modified after
127 * module load with ethtool.
128 *
129 * The default for RX should strike a balance between increasing the
130 * round-trip latency and reducing overhead.
131 */
132static unsigned int rx_irq_mod_usec = 60;
133
134/* Initial interrupt moderation settings. They can be modified after
135 * module load with ethtool.
136 *
137 * This default is chosen to ensure that a 10G link does not go idle
138 * while a TX queue is stopped after it has become full. A queue is
139 * restarted when it drops below half full. The time this takes (assuming
140 * worst case 3 descriptors per packet and 1024 descriptors) is
141 * 512 / 3 * 1.2 = 205 usec.
142 */
143static unsigned int tx_irq_mod_usec = 150;
144
145/* This is the first interrupt mode to try out of:
146 * 0 => MSI-X
147 * 1 => MSI
148 * 2 => legacy
149 */
150static unsigned int interrupt_mode;
151
152/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
153 * i.e. the number of CPUs among which we may distribute simultaneous
154 * interrupt handling.
155 *
156 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
Ben Hutchingscdb08f82011-12-20 01:08:05 +0000157 * The default (0) means to assign an interrupt to each core.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100158 */
159static unsigned int rss_cpus;
160module_param(rss_cpus, uint, 0444);
161MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
162
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800163static int phy_flash_cfg;
164module_param(phy_flash_cfg, int, 0644);
165MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
166
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000167static unsigned irq_adapt_low_thresh = 8000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000168module_param(irq_adapt_low_thresh, uint, 0644);
169MODULE_PARM_DESC(irq_adapt_low_thresh,
170 "Threshold score for reducing IRQ moderation");
171
Ben Hutchingse7bed9c2012-02-28 18:44:13 +0000172static unsigned irq_adapt_high_thresh = 16000;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000173module_param(irq_adapt_high_thresh, uint, 0644);
174MODULE_PARM_DESC(irq_adapt_high_thresh,
175 "Threshold score for increasing IRQ moderation");
176
Ben Hutchings62776d02010-06-23 11:30:07 +0000177static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
178 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
179 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
180 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
181module_param(debug, uint, 0);
182MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
183
Ben Hutchings8ceee662008-04-27 12:55:59 +0100184/**************************************************************************
185 *
186 * Utility functions and prototypes
187 *
188 *************************************************************************/
Ben Hutchings46426102010-09-10 06:42:33 +0000189
Ben Hutchings7f967c02012-02-13 23:45:02 +0000190static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq);
191static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq);
192static void efx_remove_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000193static void efx_remove_channels(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000194static const struct efx_channel_type efx_default_channel_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100195static void efx_remove_port(struct efx_nic *efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000196static void efx_init_napi_channel(struct efx_channel *channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100197static void efx_fini_napi(struct efx_nic *efx);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000198static void efx_fini_napi_channel(struct efx_channel *channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000199static void efx_fini_struct(struct efx_nic *efx);
200static void efx_start_all(struct efx_nic *efx);
201static void efx_stop_all(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100202
203#define EFX_ASSERT_RESET_SERIALISED(efx) \
204 do { \
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100205 if ((efx->state == STATE_READY) || \
Ben Hutchings332c1ce2009-11-25 16:08:52 +0000206 (efx->state == STATE_DISABLED)) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100207 ASSERT_RTNL(); \
208 } while (0)
209
210/**************************************************************************
211 *
212 * Event queue processing
213 *
214 *************************************************************************/
215
216/* Process channel's event queue
217 *
218 * This function is responsible for processing the event queue of a
219 * single channel. The caller must guarantee that this function will
220 * never be concurrently called more than once on the same channel,
221 * though different channels may be being processed concurrently.
222 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000223static int efx_process_channel(struct efx_channel *channel, int budget)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100224{
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000225 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100226
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000227 if (unlikely(!channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100228 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100229
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000230 spent = efx_nic_process_eventq(channel, budget);
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000231 if (spent && efx_channel_has_rx_queue(channel)) {
232 struct efx_rx_queue *rx_queue =
233 efx_channel_get_rx_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100234
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000235 /* Deliver last RX packet. */
236 if (channel->rx_pkt) {
237 __efx_rx_packet(channel, channel->rx_pkt);
238 channel->rx_pkt = NULL;
239 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000240 if (rx_queue->enabled) {
241 efx_rx_strategy(channel);
242 efx_fast_push_rx_descriptors(rx_queue);
243 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100244 }
245
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000246 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100247}
248
249/* Mark channel as finished processing
250 *
251 * Note that since we will not receive further interrupts for this
252 * channel before we finish processing and call the eventq_read_ack()
253 * method, there is no need to use the interrupt hold-off timers.
254 */
255static inline void efx_channel_processed(struct efx_channel *channel)
256{
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100257 /* The interrupt handler for this channel may set work_pending
258 * as soon as we acknowledge the events we've seen. Make sure
259 * it's cleared before then. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100260 channel->work_pending = false;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100261 smp_wmb();
262
Ben Hutchings152b6a62009-11-29 03:43:56 +0000263 efx_nic_eventq_read_ack(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100264}
265
266/* NAPI poll handler
267 *
268 * NAPI guarantees serialisation of polls of the same device, which
269 * provides the guarantee required by efx_process_channel().
270 */
271static int efx_poll(struct napi_struct *napi, int budget)
272{
273 struct efx_channel *channel =
274 container_of(napi, struct efx_channel, napi_str);
Ben Hutchings62776d02010-06-23 11:30:07 +0000275 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000276 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100277
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 Hutchings8ceee662008-04-27 12:55:59 +0100310 * since efx_channel_processed() will have no effect if
311 * interrupts have already been disabled.
312 */
Ben Hutchings288379f2009-01-19 16:43:59 -0800313 napi_complete(napi);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100314 efx_channel_processed(channel);
315 }
316
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000317 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318}
319
320/* Process the eventq of the specified channel immediately on this CPU
321 *
322 * Disable hardware generated interrupts, wait for any existing
323 * processing to finish, then directly poll (and ack ) the eventq.
324 * Finally reenable NAPI and interrupts.
325 *
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100326 * This is for use only during a loopback self-test. It must not
327 * deliver any packets up the stack as this can result in deadlock.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100328 */
329void efx_process_channel_now(struct efx_channel *channel)
330{
331 struct efx_nic *efx = channel->efx;
332
Ben Hutchings8313aca2010-09-10 06:41:57 +0000333 BUG_ON(channel->channel >= efx->n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100334 BUG_ON(!channel->enabled);
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100335 BUG_ON(!efx->loopback_selftest);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100336
337 /* Disable interrupts and wait for ISRs to complete */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000338 efx_nic_disable_interrupts(efx);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000339 if (efx->legacy_irq) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100340 synchronize_irq(efx->legacy_irq);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000341 efx->legacy_irq_enabled = false;
342 }
Ben Hutchings64ee3122008-09-01 12:47:38 +0100343 if (channel->irq)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100344 synchronize_irq(channel->irq);
345
346 /* Wait for any NAPI processing to complete */
347 napi_disable(&channel->napi_str);
348
349 /* Poll the channel */
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000350 efx_process_channel(channel, channel->eventq_mask + 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100351
352 /* Ack the eventq. This may cause an interrupt to be generated
353 * when they are reenabled */
354 efx_channel_processed(channel);
355
356 napi_enable(&channel->napi_str);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000357 if (efx->legacy_irq)
358 efx->legacy_irq_enabled = true;
Ben Hutchings152b6a62009-11-29 03:43:56 +0000359 efx_nic_enable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100360}
361
362/* Create event queue
363 * Event queue memory allocations are done only once. If the channel
364 * is reset, the memory buffer will be reused; this guards against
365 * errors during channel reset and also simplifies interrupt handling.
366 */
367static int efx_probe_eventq(struct efx_channel *channel)
368{
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000369 struct efx_nic *efx = channel->efx;
370 unsigned long entries;
371
Ben Hutchings86ee5302012-01-09 19:51:22 +0000372 netif_dbg(efx, probe, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000373 "chan %d create event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100374
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000375 /* Build an event queue with room for one event per tx and rx buffer,
376 * plus some extra for link state events and MCDI completions. */
377 entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
378 EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
379 channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
380
Ben Hutchings152b6a62009-11-29 03:43:56 +0000381 return efx_nic_probe_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100382}
383
384/* Prepare channel's event queue */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100385static void efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100386{
Ben Hutchings62776d02010-06-23 11:30:07 +0000387 netif_dbg(channel->efx, drv, channel->efx->net_dev,
388 "chan %d init event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100389
390 channel->eventq_read_ptr = 0;
391
Ben Hutchings152b6a62009-11-29 03:43:56 +0000392 efx_nic_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100393}
394
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000395/* Enable event queue processing and NAPI */
396static void efx_start_eventq(struct efx_channel *channel)
397{
398 netif_dbg(channel->efx, ifup, channel->efx->net_dev,
399 "chan %d start event queue\n", channel->channel);
400
401 /* The interrupt handler for this channel may set work_pending
402 * as soon as we enable it. Make sure it's cleared before
403 * then. Similarly, make sure it sees the enabled flag set.
404 */
405 channel->work_pending = false;
406 channel->enabled = true;
407 smp_wmb();
408
409 napi_enable(&channel->napi_str);
410 efx_nic_eventq_read_ack(channel);
411}
412
413/* Disable event queue processing and NAPI */
414static void efx_stop_eventq(struct efx_channel *channel)
415{
416 if (!channel->enabled)
417 return;
418
419 napi_disable(&channel->napi_str);
420 channel->enabled = false;
421}
422
Ben Hutchings8ceee662008-04-27 12:55:59 +0100423static void efx_fini_eventq(struct efx_channel *channel)
424{
Ben Hutchings62776d02010-06-23 11:30:07 +0000425 netif_dbg(channel->efx, drv, channel->efx->net_dev,
426 "chan %d fini event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100427
Ben Hutchings152b6a62009-11-29 03:43:56 +0000428 efx_nic_fini_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100429}
430
431static void efx_remove_eventq(struct efx_channel *channel)
432{
Ben Hutchings62776d02010-06-23 11:30:07 +0000433 netif_dbg(channel->efx, drv, channel->efx->net_dev,
434 "chan %d remove event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100435
Ben Hutchings152b6a62009-11-29 03:43:56 +0000436 efx_nic_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437}
438
439/**************************************************************************
440 *
441 * Channel handling
442 *
443 *************************************************************************/
444
Ben Hutchings7f967c02012-02-13 23:45:02 +0000445/* Allocate and initialise a channel structure. */
Ben Hutchings46426102010-09-10 06:42:33 +0000446static struct efx_channel *
447efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
448{
449 struct efx_channel *channel;
450 struct efx_rx_queue *rx_queue;
451 struct efx_tx_queue *tx_queue;
452 int j;
453
Ben Hutchings7f967c02012-02-13 23:45:02 +0000454 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
455 if (!channel)
456 return NULL;
Ben Hutchings46426102010-09-10 06:42:33 +0000457
Ben Hutchings7f967c02012-02-13 23:45:02 +0000458 channel->efx = efx;
459 channel->channel = i;
460 channel->type = &efx_default_channel_type;
Ben Hutchings46426102010-09-10 06:42:33 +0000461
Ben Hutchings7f967c02012-02-13 23:45:02 +0000462 for (j = 0; j < EFX_TXQ_TYPES; j++) {
463 tx_queue = &channel->tx_queue[j];
464 tx_queue->efx = efx;
465 tx_queue->queue = i * EFX_TXQ_TYPES + j;
466 tx_queue->channel = channel;
Ben Hutchings46426102010-09-10 06:42:33 +0000467 }
468
Ben Hutchings46426102010-09-10 06:42:33 +0000469 rx_queue = &channel->rx_queue;
470 rx_queue->efx = efx;
471 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
472 (unsigned long)rx_queue);
473
474 return channel;
475}
476
Ben Hutchings7f967c02012-02-13 23:45:02 +0000477/* Allocate and initialise a channel structure, copying parameters
478 * (but not resources) from an old channel structure.
479 */
480static struct efx_channel *
481efx_copy_channel(const struct efx_channel *old_channel)
482{
483 struct efx_channel *channel;
484 struct efx_rx_queue *rx_queue;
485 struct efx_tx_queue *tx_queue;
486 int j;
487
488 channel = kmalloc(sizeof(*channel), GFP_KERNEL);
489 if (!channel)
490 return NULL;
491
492 *channel = *old_channel;
493
494 channel->napi_dev = NULL;
495 memset(&channel->eventq, 0, sizeof(channel->eventq));
496
497 for (j = 0; j < EFX_TXQ_TYPES; j++) {
498 tx_queue = &channel->tx_queue[j];
499 if (tx_queue->channel)
500 tx_queue->channel = channel;
501 tx_queue->buffer = NULL;
502 memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
503 }
504
505 rx_queue = &channel->rx_queue;
506 rx_queue->buffer = NULL;
507 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
508 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
509 (unsigned long)rx_queue);
510
511 return channel;
512}
513
Ben Hutchings8ceee662008-04-27 12:55:59 +0100514static int efx_probe_channel(struct efx_channel *channel)
515{
516 struct efx_tx_queue *tx_queue;
517 struct efx_rx_queue *rx_queue;
518 int rc;
519
Ben Hutchings62776d02010-06-23 11:30:07 +0000520 netif_dbg(channel->efx, probe, channel->efx->net_dev,
521 "creating channel %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100522
Ben Hutchings7f967c02012-02-13 23:45:02 +0000523 rc = channel->type->pre_probe(channel);
524 if (rc)
525 goto fail;
526
Ben Hutchings8ceee662008-04-27 12:55:59 +0100527 rc = efx_probe_eventq(channel);
528 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000529 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100530
531 efx_for_each_channel_tx_queue(tx_queue, channel) {
532 rc = efx_probe_tx_queue(tx_queue);
533 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000534 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535 }
536
537 efx_for_each_channel_rx_queue(rx_queue, channel) {
538 rc = efx_probe_rx_queue(rx_queue);
539 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000540 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100541 }
542
543 channel->n_rx_frm_trunc = 0;
544
545 return 0;
546
Ben Hutchings7f967c02012-02-13 23:45:02 +0000547fail:
548 efx_remove_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100549 return rc;
550}
551
Ben Hutchings7f967c02012-02-13 23:45:02 +0000552static void
553efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
554{
555 struct efx_nic *efx = channel->efx;
556 const char *type;
557 int number;
558
559 number = channel->channel;
560 if (efx->tx_channel_offset == 0) {
561 type = "";
562 } else if (channel->channel < efx->tx_channel_offset) {
563 type = "-rx";
564 } else {
565 type = "-tx";
566 number -= efx->tx_channel_offset;
567 }
568 snprintf(buf, len, "%s%s-%d", efx->name, type, number);
569}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100570
Ben Hutchings56536e92008-12-12 21:37:02 -0800571static void efx_set_channel_names(struct efx_nic *efx)
572{
573 struct efx_channel *channel;
Ben Hutchings56536e92008-12-12 21:37:02 -0800574
Ben Hutchings7f967c02012-02-13 23:45:02 +0000575 efx_for_each_channel(channel, efx)
576 channel->type->get_name(channel,
577 efx->channel_name[channel->channel],
578 sizeof(efx->channel_name[0]));
Ben Hutchings56536e92008-12-12 21:37:02 -0800579}
580
Ben Hutchings46426102010-09-10 06:42:33 +0000581static int efx_probe_channels(struct efx_nic *efx)
582{
583 struct efx_channel *channel;
584 int rc;
585
586 /* Restart special buffer allocation */
587 efx->next_buffer_table = 0;
588
Ben Hutchingsc92aaff2012-02-21 23:22:00 +0000589 /* Probe channels in reverse, so that any 'extra' channels
590 * use the start of the buffer table. This allows the traffic
591 * channels to be resized without moving them or wasting the
592 * entries before them.
593 */
594 efx_for_each_channel_rev(channel, efx) {
Ben Hutchings46426102010-09-10 06:42:33 +0000595 rc = efx_probe_channel(channel);
596 if (rc) {
597 netif_err(efx, probe, efx->net_dev,
598 "failed to create channel %d\n",
599 channel->channel);
600 goto fail;
601 }
602 }
603 efx_set_channel_names(efx);
604
605 return 0;
606
607fail:
608 efx_remove_channels(efx);
609 return rc;
610}
611
Ben Hutchings8ceee662008-04-27 12:55:59 +0100612/* Channels are shutdown and reinitialised whilst the NIC is running
613 * to propagate configuration changes (mtu, checksum offload), or
614 * to clear hardware error conditions
615 */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000616static void efx_start_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100617{
618 struct efx_tx_queue *tx_queue;
619 struct efx_rx_queue *rx_queue;
620 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100621
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100622 /* Calculate the rx buffer allocation parameters required to
623 * support the current MTU, including padding for header
624 * alignment and overruns.
625 */
626 efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
627 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
Ben Hutchings39c9cf02010-06-23 11:31:28 +0000628 efx->type->rx_buffer_hash_size +
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100629 efx->type->rx_buffer_padding);
Steve Hodgson62b330b2010-06-01 11:20:53 +0000630 efx->rx_buffer_order = get_order(efx->rx_buffer_len +
631 sizeof(struct efx_rx_page_state));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100632
Ben Hutchings14bf7182012-05-22 01:27:58 +0100633 /* We must keep at least one descriptor in a TX ring empty.
634 * We could avoid this when the queue size does not exactly
635 * match the hardware ring size, but it's not that important.
636 * Therefore we stop the queue when one more skb might fill
637 * the ring completely. We wake it when half way back to
638 * empty.
639 */
640 efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
641 efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
642
Ben Hutchings8ceee662008-04-27 12:55:59 +0100643 /* Initialise the channels */
644 efx_for_each_channel(channel, efx) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100645 efx_for_each_channel_tx_queue(tx_queue, channel)
646 efx_init_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100647
648 /* The rx buffer allocation strategy is MTU dependent */
649 efx_rx_strategy(channel);
650
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000651 efx_for_each_channel_rx_queue(rx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100652 efx_init_rx_queue(rx_queue);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000653 efx_nic_generate_fill_event(rx_queue);
654 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100655
656 WARN_ON(channel->rx_pkt != NULL);
657 efx_rx_strategy(channel);
658 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000659
660 if (netif_device_present(efx->net_dev))
661 netif_tx_wake_all_queues(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100662}
663
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000664static void efx_stop_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100665{
666 struct efx_channel *channel;
667 struct efx_tx_queue *tx_queue;
668 struct efx_rx_queue *rx_queue;
Stuart Hodgson3dca9d22012-03-30 13:04:51 +0100669 struct pci_dev *dev = efx->pci_dev;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100670 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100671
672 EFX_ASSERT_RESET_SERIALISED(efx);
673 BUG_ON(efx->port_enabled);
674
Stuart Hodgson3dca9d22012-03-30 13:04:51 +0100675 /* Only perform flush if dma is enabled */
676 if (dev->is_busmaster) {
677 rc = efx_nic_flush_queues(efx);
678
679 if (rc && EFX_WORKAROUND_7803(efx)) {
680 /* Schedule a reset to recover from the flush failure. The
681 * descriptor caches reference memory we're about to free,
682 * but falcon_reconfigure_mac_wrapper() won't reconnect
683 * the MACs because of the pending reset. */
684 netif_err(efx, drv, efx->net_dev,
685 "Resetting to recover from flush failure\n");
686 efx_schedule_reset(efx, RESET_TYPE_ALL);
687 } else if (rc) {
688 netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
689 } else {
690 netif_dbg(efx, drv, efx->net_dev,
691 "successfully flushed all queues\n");
692 }
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000693 }
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100694
Ben Hutchings8ceee662008-04-27 12:55:59 +0100695 efx_for_each_channel(channel, efx) {
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000696 /* RX packet processing is pipelined, so wait for the
697 * NAPI handler to complete. At least event queue 0
698 * might be kept active by non-data events, so don't
699 * use napi_synchronize() but actually disable NAPI
700 * temporarily.
701 */
702 if (efx_channel_has_rx_queue(channel)) {
703 efx_stop_eventq(channel);
704 efx_start_eventq(channel);
705 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100706
707 efx_for_each_channel_rx_queue(rx_queue, channel)
708 efx_fini_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000709 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100710 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100711 }
712}
713
714static void efx_remove_channel(struct efx_channel *channel)
715{
716 struct efx_tx_queue *tx_queue;
717 struct efx_rx_queue *rx_queue;
718
Ben Hutchings62776d02010-06-23 11:30:07 +0000719 netif_dbg(channel->efx, drv, channel->efx->net_dev,
720 "destroy chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100721
722 efx_for_each_channel_rx_queue(rx_queue, channel)
723 efx_remove_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000724 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100725 efx_remove_tx_queue(tx_queue);
726 efx_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100727}
728
Ben Hutchings46426102010-09-10 06:42:33 +0000729static void efx_remove_channels(struct efx_nic *efx)
730{
731 struct efx_channel *channel;
732
733 efx_for_each_channel(channel, efx)
734 efx_remove_channel(channel);
735}
736
737int
738efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
739{
740 struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
741 u32 old_rxq_entries, old_txq_entries;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000742 unsigned i, next_buffer_table = 0;
743 int rc = 0;
744
745 /* Not all channels should be reallocated. We must avoid
746 * reallocating their buffer table entries.
747 */
748 efx_for_each_channel(channel, efx) {
749 struct efx_rx_queue *rx_queue;
750 struct efx_tx_queue *tx_queue;
751
752 if (channel->type->copy)
753 continue;
754 next_buffer_table = max(next_buffer_table,
755 channel->eventq.index +
756 channel->eventq.entries);
757 efx_for_each_channel_rx_queue(rx_queue, channel)
758 next_buffer_table = max(next_buffer_table,
759 rx_queue->rxd.index +
760 rx_queue->rxd.entries);
761 efx_for_each_channel_tx_queue(tx_queue, channel)
762 next_buffer_table = max(next_buffer_table,
763 tx_queue->txd.index +
764 tx_queue->txd.entries);
765 }
Ben Hutchings46426102010-09-10 06:42:33 +0000766
767 efx_stop_all(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000768 efx_stop_interrupts(efx, true);
Ben Hutchings46426102010-09-10 06:42:33 +0000769
Ben Hutchings7f967c02012-02-13 23:45:02 +0000770 /* Clone channels (where possible) */
Ben Hutchings46426102010-09-10 06:42:33 +0000771 memset(other_channel, 0, sizeof(other_channel));
772 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000773 channel = efx->channel[i];
774 if (channel->type->copy)
775 channel = channel->type->copy(channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000776 if (!channel) {
777 rc = -ENOMEM;
778 goto out;
779 }
780 other_channel[i] = channel;
781 }
782
783 /* Swap entry counts and channel pointers */
784 old_rxq_entries = efx->rxq_entries;
785 old_txq_entries = efx->txq_entries;
786 efx->rxq_entries = rxq_entries;
787 efx->txq_entries = txq_entries;
788 for (i = 0; i < efx->n_channels; i++) {
789 channel = efx->channel[i];
790 efx->channel[i] = other_channel[i];
791 other_channel[i] = channel;
792 }
793
Ben Hutchings7f967c02012-02-13 23:45:02 +0000794 /* Restart buffer table allocation */
795 efx->next_buffer_table = next_buffer_table;
Ben Hutchings46426102010-09-10 06:42:33 +0000796
Ben Hutchingse8f14992010-12-07 19:47:34 +0000797 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000798 channel = efx->channel[i];
799 if (!channel->type->copy)
800 continue;
801 rc = efx_probe_channel(channel);
802 if (rc)
803 goto rollback;
804 efx_init_napi_channel(efx->channel[i]);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000805 }
Ben Hutchings46426102010-09-10 06:42:33 +0000806
Ben Hutchings7f967c02012-02-13 23:45:02 +0000807out:
808 /* Destroy unused channel structures */
809 for (i = 0; i < efx->n_channels; i++) {
810 channel = other_channel[i];
811 if (channel && channel->type->copy) {
812 efx_fini_napi_channel(channel);
813 efx_remove_channel(channel);
814 kfree(channel);
815 }
816 }
817
818 efx_start_interrupts(efx, true);
Ben Hutchings46426102010-09-10 06:42:33 +0000819 efx_start_all(efx);
820 return rc;
821
822rollback:
823 /* Swap back */
824 efx->rxq_entries = old_rxq_entries;
825 efx->txq_entries = old_txq_entries;
826 for (i = 0; i < efx->n_channels; i++) {
827 channel = efx->channel[i];
828 efx->channel[i] = other_channel[i];
829 other_channel[i] = channel;
830 }
831 goto out;
832}
833
Steve Hodgson90d683a2010-06-01 11:19:39 +0000834void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100835{
Steve Hodgson90d683a2010-06-01 11:19:39 +0000836 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100837}
838
Ben Hutchings7f967c02012-02-13 23:45:02 +0000839static const struct efx_channel_type efx_default_channel_type = {
840 .pre_probe = efx_channel_dummy_op_int,
841 .get_name = efx_get_channel_name,
842 .copy = efx_copy_channel,
843 .keep_eventq = false,
844};
845
846int efx_channel_dummy_op_int(struct efx_channel *channel)
847{
848 return 0;
849}
850
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851/**************************************************************************
852 *
853 * Port handling
854 *
855 **************************************************************************/
856
857/* This ensures that the kernel is kept informed (via
858 * netif_carrier_on/off) of the link status, and also maintains the
859 * link status's stop on the port's TX queue.
860 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000861void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100862{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000863 struct efx_link_state *link_state = &efx->link_state;
864
Ben Hutchings8ceee662008-04-27 12:55:59 +0100865 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
866 * that no events are triggered between unregister_netdev() and the
867 * driver unloading. A more general condition is that NETDEV_CHANGE
868 * can only be generated between NETDEV_UP and NETDEV_DOWN */
869 if (!netif_running(efx->net_dev))
870 return;
871
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000872 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100873 efx->n_link_state_changes++;
874
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000875 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100876 netif_carrier_on(efx->net_dev);
877 else
878 netif_carrier_off(efx->net_dev);
879 }
880
881 /* Status message for kernel log */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000882 if (link_state->up)
Ben Hutchings62776d02010-06-23 11:30:07 +0000883 netif_info(efx, link, efx->net_dev,
884 "link up at %uMbps %s-duplex (MTU %d)%s\n",
885 link_state->speed, link_state->fd ? "full" : "half",
886 efx->net_dev->mtu,
887 (efx->promiscuous ? " [PROMISC]" : ""));
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000888 else
Ben Hutchings62776d02010-06-23 11:30:07 +0000889 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100890}
891
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000892void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
893{
894 efx->link_advertising = advertising;
895 if (advertising) {
896 if (advertising & ADVERTISED_Pause)
897 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
898 else
899 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
900 if (advertising & ADVERTISED_Asym_Pause)
901 efx->wanted_fc ^= EFX_FC_TX;
902 }
903}
904
David S. Millerb56269462011-05-17 17:53:22 -0400905void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000906{
907 efx->wanted_fc = wanted_fc;
908 if (efx->link_advertising) {
909 if (wanted_fc & EFX_FC_RX)
910 efx->link_advertising |= (ADVERTISED_Pause |
911 ADVERTISED_Asym_Pause);
912 else
913 efx->link_advertising &= ~(ADVERTISED_Pause |
914 ADVERTISED_Asym_Pause);
915 if (wanted_fc & EFX_FC_TX)
916 efx->link_advertising ^= ADVERTISED_Asym_Pause;
917 }
918}
919
Ben Hutchings115122a2009-03-04 09:52:52 +0000920static void efx_fini_port(struct efx_nic *efx);
921
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000922/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
923 * the MAC appropriately. All other PHY configuration changes are pushed
924 * through phy_op->set_settings(), and pushed asynchronously to the MAC
925 * through efx_monitor().
926 *
927 * Callers must hold the mac_lock
928 */
929int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100930{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000931 enum efx_phy_mode phy_mode;
932 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100933
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000934 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100935
Ben Hutchings0fca8c92012-01-09 19:54:44 +0000936 /* Serialise the promiscuous flag with efx_set_rx_mode. */
Ben Hutchings73ba7b62012-01-09 19:47:08 +0000937 netif_addr_lock_bh(efx->net_dev);
938 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchingsa816f752008-09-01 12:49:12 +0100939
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000940 /* Disable PHY transmit in mac level loopbacks */
941 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800942 if (LOOPBACK_INTERNAL(efx))
943 efx->phy_mode |= PHY_MODE_TX_DISABLED;
944 else
945 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800946
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000947 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800948
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000949 if (rc)
950 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100951
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000952 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100953}
954
955/* Reinitialise the MAC to pick up new PHY settings, even if the port is
956 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000957int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100958{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000959 int rc;
960
Ben Hutchings8ceee662008-04-27 12:55:59 +0100961 EFX_ASSERT_RESET_SERIALISED(efx);
962
963 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000964 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100965 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000966
967 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100968}
969
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000970/* Asynchronous work item for changing MAC promiscuity and multicast
971 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
972 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800973static void efx_mac_work(struct work_struct *data)
974{
975 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
976
977 mutex_lock(&efx->mac_lock);
Ben Hutchings30b81cd2011-09-13 19:47:48 +0100978 if (efx->port_enabled)
Ben Hutchings710b2082011-09-03 00:15:00 +0100979 efx->type->reconfigure_mac(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800980 mutex_unlock(&efx->mac_lock);
981}
982
Ben Hutchings8ceee662008-04-27 12:55:59 +0100983static int efx_probe_port(struct efx_nic *efx)
984{
985 int rc;
986
Ben Hutchings62776d02010-06-23 11:30:07 +0000987 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100988
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000989 if (phy_flash_cfg)
990 efx->phy_mode = PHY_MODE_SPECIAL;
991
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000992 /* Connect up MAC/PHY operations table */
993 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100994 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +0000995 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100996
Ben Hutchingse332bcb2011-12-20 01:22:51 +0000997 /* Initialise MAC address to permanent address */
998 memcpy(efx->net_dev->dev_addr, efx->net_dev->perm_addr, ETH_ALEN);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100999
1000 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001001}
1002
1003static int efx_init_port(struct efx_nic *efx)
1004{
1005 int rc;
1006
Ben Hutchings62776d02010-06-23 11:30:07 +00001007 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001008
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001009 mutex_lock(&efx->mac_lock);
1010
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001011 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001012 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001013 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001014
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001015 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001016
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001017 /* Reconfigure the MAC before creating dma queues (required for
1018 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
Ben Hutchings710b2082011-09-03 00:15:00 +01001019 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001020
1021 /* Ensure the PHY advertises the correct flow control settings */
1022 rc = efx->phy_op->reconfigure(efx);
1023 if (rc)
1024 goto fail2;
1025
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001026 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001027 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001028
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001029fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001030 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001031fail1:
1032 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001033 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001034}
1035
Ben Hutchings8ceee662008-04-27 12:55:59 +01001036static void efx_start_port(struct efx_nic *efx)
1037{
Ben Hutchings62776d02010-06-23 11:30:07 +00001038 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001039 BUG_ON(efx->port_enabled);
1040
1041 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001042 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001043
1044 /* efx_mac_work() might have been scheduled after efx_stop_port(),
1045 * and then cancelled by efx_flush_all() */
Ben Hutchings710b2082011-09-03 00:15:00 +01001046 efx->type->reconfigure_mac(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001047
Ben Hutchings8ceee662008-04-27 12:55:59 +01001048 mutex_unlock(&efx->mac_lock);
1049}
1050
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00001051/* Prevent efx_mac_work() and efx_monitor() from working */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001052static void efx_stop_port(struct efx_nic *efx)
1053{
Ben Hutchings62776d02010-06-23 11:30:07 +00001054 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001055
1056 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001057 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001058 mutex_unlock(&efx->mac_lock);
1059
1060 /* Serialise against efx_set_multicast_list() */
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001061 netif_addr_lock_bh(efx->net_dev);
1062 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001063}
1064
1065static void efx_fini_port(struct efx_nic *efx)
1066{
Ben Hutchings62776d02010-06-23 11:30:07 +00001067 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001068
1069 if (!efx->port_initialized)
1070 return;
1071
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001072 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001073 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001074
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001075 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001076 efx_link_status_changed(efx);
1077}
1078
1079static void efx_remove_port(struct efx_nic *efx)
1080{
Ben Hutchings62776d02010-06-23 11:30:07 +00001081 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001082
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001083 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001084}
1085
1086/**************************************************************************
1087 *
1088 * NIC handling
1089 *
1090 **************************************************************************/
1091
1092/* This configures the PCI device to enable I/O and DMA. */
1093static int efx_init_io(struct efx_nic *efx)
1094{
1095 struct pci_dev *pci_dev = efx->pci_dev;
1096 dma_addr_t dma_mask = efx->type->max_dma_mask;
1097 int rc;
1098
Ben Hutchings62776d02010-06-23 11:30:07 +00001099 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001100
1101 rc = pci_enable_device(pci_dev);
1102 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001103 netif_err(efx, probe, efx->net_dev,
1104 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001105 goto fail1;
1106 }
1107
1108 pci_set_master(pci_dev);
1109
1110 /* Set the PCI DMA mask. Try all possibilities from our
1111 * genuine mask down to 32 bits, because some architectures
1112 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1113 * masks event though they reject 46 bit masks.
1114 */
1115 while (dma_mask > 0x7fffffffUL) {
Ben Hutchings0e33d872012-05-17 17:46:55 +01001116 if (dma_supported(&pci_dev->dev, dma_mask)) {
1117 rc = dma_set_mask(&pci_dev->dev, dma_mask);
Ben Hutchingse9e01842012-01-05 18:50:29 +00001118 if (rc == 0)
1119 break;
1120 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001121 dma_mask >>= 1;
1122 }
1123 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001124 netif_err(efx, probe, efx->net_dev,
1125 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001126 goto fail2;
1127 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001128 netif_dbg(efx, probe, efx->net_dev,
1129 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings0e33d872012-05-17 17:46:55 +01001130 rc = dma_set_coherent_mask(&pci_dev->dev, dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001131 if (rc) {
Ben Hutchings0e33d872012-05-17 17:46:55 +01001132 /* dma_set_coherent_mask() is not *allowed* to
1133 * fail with a mask that dma_set_mask() accepted,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001134 * but just in case...
1135 */
Ben Hutchings62776d02010-06-23 11:30:07 +00001136 netif_err(efx, probe, efx->net_dev,
1137 "failed to set consistent DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001138 goto fail2;
1139 }
1140
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001141 efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
1142 rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001143 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001144 netif_err(efx, probe, efx->net_dev,
1145 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001146 rc = -EIO;
1147 goto fail3;
1148 }
David S. Miller8decf862011-09-22 03:23:13 -04001149 efx->membase = ioremap_nocache(efx->membase_phys,
1150 efx->type->mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001151 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001152 netif_err(efx, probe, efx->net_dev,
1153 "could not map memory BAR at %llx+%x\n",
1154 (unsigned long long)efx->membase_phys,
1155 efx->type->mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001156 rc = -ENOMEM;
1157 goto fail4;
1158 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001159 netif_dbg(efx, probe, efx->net_dev,
1160 "memory BAR at %llx+%x (virtual %p)\n",
1161 (unsigned long long)efx->membase_phys,
1162 efx->type->mem_map_size, efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001163
1164 return 0;
1165
1166 fail4:
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001167 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001168 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001169 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001170 fail2:
1171 pci_disable_device(efx->pci_dev);
1172 fail1:
1173 return rc;
1174}
1175
1176static void efx_fini_io(struct efx_nic *efx)
1177{
Ben Hutchings62776d02010-06-23 11:30:07 +00001178 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001179
1180 if (efx->membase) {
1181 iounmap(efx->membase);
1182 efx->membase = NULL;
1183 }
1184
1185 if (efx->membase_phys) {
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001186 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001187 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001188 }
1189
1190 pci_disable_device(efx->pci_dev);
1191}
1192
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001193static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
Ben Hutchings46123d02008-09-01 12:47:33 +01001194{
Ben Hutchingscdb08f82011-12-20 01:08:05 +00001195 cpumask_var_t thread_mask;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001196 unsigned int count;
Ben Hutchings46123d02008-09-01 12:47:33 +01001197 int cpu;
1198
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001199 if (rss_cpus) {
1200 count = rss_cpus;
1201 } else {
1202 if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1203 netif_warn(efx, probe, efx->net_dev,
1204 "RSS disabled due to allocation failure\n");
1205 return 1;
Ben Hutchings46123d02008-09-01 12:47:33 +01001206 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001207
1208 count = 0;
1209 for_each_online_cpu(cpu) {
1210 if (!cpumask_test_cpu(cpu, thread_mask)) {
1211 ++count;
1212 cpumask_or(thread_mask, thread_mask,
1213 topology_thread_cpumask(cpu));
1214 }
1215 }
1216
1217 free_cpumask_var(thread_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001218 }
1219
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001220 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1221 * table entries that are inaccessible to VFs
1222 */
1223 if (efx_sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
1224 count > efx_vf_size(efx)) {
1225 netif_warn(efx, probe, efx->net_dev,
1226 "Reducing number of RSS channels from %u to %u for "
1227 "VF support. Increase vf-msix-limit to use more "
1228 "channels on the PF.\n",
1229 count, efx_vf_size(efx));
1230 count = efx_vf_size(efx);
1231 }
1232
Ben Hutchings46123d02008-09-01 12:47:33 +01001233 return count;
1234}
1235
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001236static int
1237efx_init_rx_cpu_rmap(struct efx_nic *efx, struct msix_entry *xentries)
1238{
1239#ifdef CONFIG_RFS_ACCEL
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001240 unsigned int i;
1241 int rc;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001242
1243 efx->net_dev->rx_cpu_rmap = alloc_irq_cpu_rmap(efx->n_rx_channels);
1244 if (!efx->net_dev->rx_cpu_rmap)
1245 return -ENOMEM;
1246 for (i = 0; i < efx->n_rx_channels; i++) {
1247 rc = irq_cpu_rmap_add(efx->net_dev->rx_cpu_rmap,
1248 xentries[i].vector);
1249 if (rc) {
1250 free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
1251 efx->net_dev->rx_cpu_rmap = NULL;
1252 return rc;
1253 }
1254 }
1255#endif
1256 return 0;
1257}
1258
Ben Hutchings46123d02008-09-01 12:47:33 +01001259/* Probe the number and type of interrupts we are able to obtain, and
1260 * the resulting numbers of channels and RX queues.
1261 */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001262static int efx_probe_interrupts(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001263{
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001264 unsigned int max_channels =
1265 min(efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001266 unsigned int extra_channels = 0;
1267 unsigned int i, j;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001268 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001269
Ben Hutchings7f967c02012-02-13 23:45:02 +00001270 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
1271 if (efx->extra_channel_type[i])
1272 ++extra_channels;
1273
Ben Hutchings8ceee662008-04-27 12:55:59 +01001274 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001275 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001276 unsigned int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001277
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001278 n_channels = efx_wanted_parallelism(efx);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001279 if (separate_tx_channels)
1280 n_channels *= 2;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001281 n_channels += extra_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001282 n_channels = min(n_channels, max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001283
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001284 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001285 xentries[i].entry = i;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001286 rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001287 if (rc > 0) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001288 netif_err(efx, drv, efx->net_dev,
1289 "WARNING: Insufficient MSI-X vectors"
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001290 " available (%d < %u).\n", rc, n_channels);
Ben Hutchings62776d02010-06-23 11:30:07 +00001291 netif_err(efx, drv, efx->net_dev,
1292 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001293 EFX_BUG_ON_PARANOID(rc >= n_channels);
1294 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001295 rc = pci_enable_msix(efx->pci_dev, xentries,
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001296 n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001297 }
1298
1299 if (rc == 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001300 efx->n_channels = n_channels;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001301 if (n_channels > extra_channels)
1302 n_channels -= extra_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001303 if (separate_tx_channels) {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001304 efx->n_tx_channels = max(n_channels / 2, 1U);
1305 efx->n_rx_channels = max(n_channels -
1306 efx->n_tx_channels,
1307 1U);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001308 } else {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001309 efx->n_tx_channels = n_channels;
1310 efx->n_rx_channels = n_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001311 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001312 rc = efx_init_rx_cpu_rmap(efx, xentries);
1313 if (rc) {
1314 pci_disable_msix(efx->pci_dev);
1315 return rc;
1316 }
Ben Hutchings7f967c02012-02-13 23:45:02 +00001317 for (i = 0; i < efx->n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001318 efx_get_channel(efx, i)->irq =
1319 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001320 } else {
1321 /* Fall back to single channel MSI */
1322 efx->interrupt_mode = EFX_INT_MODE_MSI;
Ben Hutchings62776d02010-06-23 11:30:07 +00001323 netif_err(efx, drv, efx->net_dev,
1324 "could not enable MSI-X\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001325 }
1326 }
1327
1328 /* Try single interrupt MSI */
1329 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001330 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001331 efx->n_rx_channels = 1;
1332 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001333 rc = pci_enable_msi(efx->pci_dev);
1334 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001335 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001336 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001337 netif_err(efx, drv, efx->net_dev,
1338 "could not enable MSI\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001339 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1340 }
1341 }
1342
1343 /* Assume legacy interrupts */
1344 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Neil Turton28b581a2008-12-12 21:41:06 -08001345 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001346 efx->n_rx_channels = 1;
1347 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001348 efx->legacy_irq = efx->pci_dev->irq;
1349 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001350
Ben Hutchings7f967c02012-02-13 23:45:02 +00001351 /* Assign extra channels if possible */
1352 j = efx->n_channels;
1353 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
1354 if (!efx->extra_channel_type[i])
1355 continue;
1356 if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
1357 efx->n_channels <= extra_channels) {
1358 efx->extra_channel_type[i]->handle_no_channel(efx);
1359 } else {
1360 --j;
1361 efx_get_channel(efx, j)->type =
1362 efx->extra_channel_type[i];
1363 }
1364 }
1365
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001366 /* RSS might be usable on VFs even if it is disabled on the PF */
Ben Hutchings3132d282012-05-05 02:31:23 +01001367 efx->rss_spread = ((efx->n_rx_channels > 1 || !efx_sriov_wanted(efx)) ?
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001368 efx->n_rx_channels : efx_vf_size(efx));
1369
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001370 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001371}
1372
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001373/* Enable interrupts, then probe and start the event queues */
Ben Hutchings7f967c02012-02-13 23:45:02 +00001374static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001375{
1376 struct efx_channel *channel;
1377
1378 if (efx->legacy_irq)
1379 efx->legacy_irq_enabled = true;
1380 efx_nic_enable_interrupts(efx);
1381
1382 efx_for_each_channel(channel, efx) {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001383 if (!channel->type->keep_eventq || !may_keep_eventq)
1384 efx_init_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001385 efx_start_eventq(channel);
1386 }
1387
1388 efx_mcdi_mode_event(efx);
1389}
1390
Ben Hutchings7f967c02012-02-13 23:45:02 +00001391static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001392{
1393 struct efx_channel *channel;
1394
1395 efx_mcdi_mode_poll(efx);
1396
1397 efx_nic_disable_interrupts(efx);
1398 if (efx->legacy_irq) {
1399 synchronize_irq(efx->legacy_irq);
1400 efx->legacy_irq_enabled = false;
1401 }
1402
1403 efx_for_each_channel(channel, efx) {
1404 if (channel->irq)
1405 synchronize_irq(channel->irq);
1406
1407 efx_stop_eventq(channel);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001408 if (!channel->type->keep_eventq || !may_keep_eventq)
1409 efx_fini_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001410 }
1411}
1412
Ben Hutchings8ceee662008-04-27 12:55:59 +01001413static void efx_remove_interrupts(struct efx_nic *efx)
1414{
1415 struct efx_channel *channel;
1416
1417 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001418 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001419 channel->irq = 0;
1420 pci_disable_msi(efx->pci_dev);
1421 pci_disable_msix(efx->pci_dev);
1422
1423 /* Remove legacy interrupt */
1424 efx->legacy_irq = 0;
1425}
1426
Ben Hutchings8831da72008-09-01 12:47:48 +01001427static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001428{
Ben Hutchings602a5322011-05-16 17:32:39 +01001429 struct efx_channel *channel;
1430 struct efx_tx_queue *tx_queue;
1431
Ben Hutchings97653432011-01-12 18:26:56 +00001432 efx->tx_channel_offset =
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001433 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings602a5322011-05-16 17:32:39 +01001434
1435 /* We need to adjust the TX queue numbers if we have separate
1436 * RX-only and TX-only channels.
1437 */
1438 efx_for_each_channel(channel, efx) {
1439 efx_for_each_channel_tx_queue(tx_queue, channel)
1440 tx_queue->queue -= (efx->tx_channel_offset *
1441 EFX_TXQ_TYPES);
1442 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001443}
1444
1445static int efx_probe_nic(struct efx_nic *efx)
1446{
Ben Hutchings765c9f42010-06-30 05:06:28 +00001447 size_t i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001448 int rc;
1449
Ben Hutchings62776d02010-06-23 11:30:07 +00001450 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001451
1452 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001453 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001454 if (rc)
1455 return rc;
1456
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001457 /* Determine the number of channels and queues by trying to hook
Ben Hutchings8ceee662008-04-27 12:55:59 +01001458 * in MSI-X interrupts. */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001459 rc = efx_probe_interrupts(efx);
1460 if (rc)
1461 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001462
Ben Hutchings28e47c42012-02-15 01:58:49 +00001463 efx->type->dimension_resources(efx);
1464
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001465 if (efx->n_channels > 1)
1466 get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001467 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
Ben Hutchings278bc422011-12-15 13:56:49 +00001468 efx->rx_indir_table[i] =
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001469 ethtool_rxfh_indir_default(i, efx->rss_spread);
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001470
Ben Hutchings8831da72008-09-01 12:47:48 +01001471 efx_set_channels(efx);
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001472 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1473 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001474
1475 /* Initialise the interrupt moderation settings */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001476 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1477 true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001478
1479 return 0;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001480
1481fail:
1482 efx->type->remove(efx);
1483 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001484}
1485
1486static void efx_remove_nic(struct efx_nic *efx)
1487{
Ben Hutchings62776d02010-06-23 11:30:07 +00001488 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001489
1490 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001491 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001492}
1493
1494/**************************************************************************
1495 *
1496 * NIC startup/shutdown
1497 *
1498 *************************************************************************/
1499
1500static int efx_probe_all(struct efx_nic *efx)
1501{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001502 int rc;
1503
Ben Hutchings8ceee662008-04-27 12:55:59 +01001504 rc = efx_probe_nic(efx);
1505 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001506 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001507 goto fail1;
1508 }
1509
Ben Hutchings8ceee662008-04-27 12:55:59 +01001510 rc = efx_probe_port(efx);
1511 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001512 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001513 goto fail2;
1514 }
1515
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00001516 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
1517 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
1518 rc = -EINVAL;
1519 goto fail3;
1520 }
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001521 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001522
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001523 rc = efx_probe_filters(efx);
1524 if (rc) {
1525 netif_err(efx, probe, efx->net_dev,
1526 "failed to create filter tables\n");
Ben Hutchings7f967c02012-02-13 23:45:02 +00001527 goto fail3;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001528 }
1529
Ben Hutchings7f967c02012-02-13 23:45:02 +00001530 rc = efx_probe_channels(efx);
1531 if (rc)
1532 goto fail4;
1533
Ben Hutchings8ceee662008-04-27 12:55:59 +01001534 return 0;
1535
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001536 fail4:
Ben Hutchings7f967c02012-02-13 23:45:02 +00001537 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001538 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001539 efx_remove_port(efx);
1540 fail2:
1541 efx_remove_nic(efx);
1542 fail1:
1543 return rc;
1544}
1545
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001546/* Called after previous invocation(s) of efx_stop_all, restarts the port,
1547 * kernel transmit queues and NAPI processing, and ensures that the port is
1548 * scheduled to be reconfigured. This function is safe to call multiple
1549 * times when the NIC is in any state.
1550 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001551static void efx_start_all(struct efx_nic *efx)
1552{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001553 EFX_ASSERT_RESET_SERIALISED(efx);
1554
1555 /* Check that it is appropriate to restart the interface. All
1556 * of these flags are safe to read under just the rtnl lock */
1557 if (efx->port_enabled)
1558 return;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01001559 if ((efx->state != STATE_READY) && (efx->state != STATE_UNINIT))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001560 return;
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001561 if (!netif_running(efx->net_dev))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001562 return;
1563
Ben Hutchings8ceee662008-04-27 12:55:59 +01001564 efx_start_port(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001565 efx_start_datapath(efx);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001566
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001567 /* Start the hardware monitor if there is one. Otherwise (we're link
1568 * event driven), we have to poll the PHY because after an event queue
1569 * flush, we could have a missed a link state change */
1570 if (efx->type->monitor != NULL) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001571 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1572 efx_monitor_interval);
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001573 } else {
1574 mutex_lock(&efx->mac_lock);
1575 if (efx->phy_op->poll(efx))
1576 efx_link_status_changed(efx);
1577 mutex_unlock(&efx->mac_lock);
1578 }
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001579
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001580 efx->type->start_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001581}
1582
1583/* Flush all delayed work. Should only be called when no more delayed work
1584 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1585 * since we're holding the rtnl_lock at this point. */
1586static void efx_flush_all(struct efx_nic *efx)
1587{
Ben Hutchingsdd407812012-02-28 23:40:21 +00001588 /* Make sure the hardware monitor and event self-test are stopped */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001589 cancel_delayed_work_sync(&efx->monitor_work);
Ben Hutchingsdd407812012-02-28 23:40:21 +00001590 efx_selftest_async_cancel(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001591 /* Stop scheduled port reconfigurations */
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001592 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001593}
1594
1595/* Quiesce hardware and software without bringing the link down.
1596 * Safe to call multiple times, when the nic and interface is in any
1597 * state. The caller is guaranteed to subsequently be in a position
1598 * to modify any hardware and software state they see fit without
1599 * taking locks. */
1600static void efx_stop_all(struct efx_nic *efx)
1601{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001602 EFX_ASSERT_RESET_SERIALISED(efx);
1603
1604 /* port_enabled can be read safely under the rtnl lock */
1605 if (!efx->port_enabled)
1606 return;
1607
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001608 efx->type->stop_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001609 efx_stop_port(efx);
1610
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00001611 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001612 efx_flush_all(efx);
1613
Ben Hutchings8ceee662008-04-27 12:55:59 +01001614 /* Stop the kernel transmit interface late, so the watchdog
1615 * timer isn't ticking over the flush */
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001616 netif_tx_disable(efx->net_dev);
1617
1618 efx_stop_datapath(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001619}
1620
1621static void efx_remove_all(struct efx_nic *efx)
1622{
Ben Hutchings46426102010-09-10 06:42:33 +00001623 efx_remove_channels(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001624 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001625 efx_remove_port(efx);
1626 efx_remove_nic(efx);
1627}
1628
Ben Hutchings8ceee662008-04-27 12:55:59 +01001629/**************************************************************************
1630 *
1631 * Interrupt moderation
1632 *
1633 **************************************************************************/
1634
Ben Hutchingscc180b62011-12-08 19:51:47 +00001635static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001636{
Ben Hutchingsb548f972011-09-05 07:41:44 +00001637 if (usecs == 0)
1638 return 0;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001639 if (usecs * 1000 < quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001640 return 1; /* never round down to 0 */
Ben Hutchingscc180b62011-12-08 19:51:47 +00001641 return usecs * 1000 / quantum_ns;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001642}
1643
Ben Hutchings8ceee662008-04-27 12:55:59 +01001644/* Set interrupt moderation parameters */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001645int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
1646 unsigned int rx_usecs, bool rx_adaptive,
1647 bool rx_may_override_tx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001648{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001649 struct efx_channel *channel;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001650 unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max *
1651 efx->timer_quantum_ns,
1652 1000);
1653 unsigned int tx_ticks;
1654 unsigned int rx_ticks;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001655
1656 EFX_ASSERT_RESET_SERIALISED(efx);
1657
Ben Hutchingscc180b62011-12-08 19:51:47 +00001658 if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max)
Ben Hutchings9e393b32011-09-05 07:43:04 +00001659 return -EINVAL;
1660
Ben Hutchingscc180b62011-12-08 19:51:47 +00001661 tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns);
1662 rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns);
1663
Ben Hutchings9e393b32011-09-05 07:43:04 +00001664 if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 &&
1665 !rx_may_override_tx) {
1666 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
1667 "RX and TX IRQ moderation must be equal\n");
1668 return -EINVAL;
1669 }
1670
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001671 efx->irq_rx_adaptive = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001672 efx->irq_rx_moderation = rx_ticks;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001673 efx_for_each_channel(channel, efx) {
Ben Hutchings525da902011-02-07 23:04:38 +00001674 if (efx_channel_has_rx_queue(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001675 channel->irq_moderation = rx_ticks;
Ben Hutchings525da902011-02-07 23:04:38 +00001676 else if (efx_channel_has_tx_queues(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001677 channel->irq_moderation = tx_ticks;
1678 }
Ben Hutchings9e393b32011-09-05 07:43:04 +00001679
1680 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001681}
1682
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001683void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
1684 unsigned int *rx_usecs, bool *rx_adaptive)
1685{
Ben Hutchingscc180b62011-12-08 19:51:47 +00001686 /* We must round up when converting ticks to microseconds
1687 * because we round down when converting the other way.
1688 */
1689
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001690 *rx_adaptive = efx->irq_rx_adaptive;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001691 *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation *
1692 efx->timer_quantum_ns,
1693 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001694
1695 /* If channels are shared between RX and TX, so is IRQ
1696 * moderation. Otherwise, IRQ moderation is the same for all
1697 * TX channels and is not adaptive.
1698 */
1699 if (efx->tx_channel_offset == 0)
1700 *tx_usecs = *rx_usecs;
1701 else
Ben Hutchingscc180b62011-12-08 19:51:47 +00001702 *tx_usecs = DIV_ROUND_UP(
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001703 efx->channel[efx->tx_channel_offset]->irq_moderation *
Ben Hutchingscc180b62011-12-08 19:51:47 +00001704 efx->timer_quantum_ns,
1705 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001706}
1707
Ben Hutchings8ceee662008-04-27 12:55:59 +01001708/**************************************************************************
1709 *
1710 * Hardware monitor
1711 *
1712 **************************************************************************/
1713
Ben Hutchingse254c272010-09-20 08:44:10 +00001714/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001715static void efx_monitor(struct work_struct *data)
1716{
1717 struct efx_nic *efx = container_of(data, struct efx_nic,
1718 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001719
Ben Hutchings62776d02010-06-23 11:30:07 +00001720 netif_vdbg(efx, timer, efx->net_dev,
1721 "hardware monitor executing on CPU %d\n",
1722 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001723 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001724
Ben Hutchings8ceee662008-04-27 12:55:59 +01001725 /* If the mac_lock is already held then it is likely a port
1726 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00001727 * most of the work of monitor() anyway. */
1728 if (mutex_trylock(&efx->mac_lock)) {
1729 if (efx->port_enabled)
1730 efx->type->monitor(efx);
1731 mutex_unlock(&efx->mac_lock);
1732 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001733
Ben Hutchings8ceee662008-04-27 12:55:59 +01001734 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1735 efx_monitor_interval);
1736}
1737
1738/**************************************************************************
1739 *
1740 * ioctls
1741 *
1742 *************************************************************************/
1743
1744/* Net device ioctl
1745 * Context: process, rtnl_lock() held.
1746 */
1747static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1748{
Ben Hutchings767e4682008-09-01 12:43:14 +01001749 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00001750 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001751
1752 EFX_ASSERT_RESET_SERIALISED(efx);
1753
Ben Hutchings68e7f452009-04-29 08:05:08 +00001754 /* Convert phy_id from older PRTAD/DEVAD format */
1755 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
1756 (data->phy_id & 0xfc00) == 0x0400)
1757 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
1758
1759 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001760}
1761
1762/**************************************************************************
1763 *
1764 * NAPI interface
1765 *
1766 **************************************************************************/
1767
Ben Hutchings7f967c02012-02-13 23:45:02 +00001768static void efx_init_napi_channel(struct efx_channel *channel)
1769{
1770 struct efx_nic *efx = channel->efx;
1771
1772 channel->napi_dev = efx->net_dev;
1773 netif_napi_add(channel->napi_dev, &channel->napi_str,
1774 efx_poll, napi_weight);
1775}
1776
Ben Hutchingse8f14992010-12-07 19:47:34 +00001777static void efx_init_napi(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001778{
1779 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001780
Ben Hutchings7f967c02012-02-13 23:45:02 +00001781 efx_for_each_channel(channel, efx)
1782 efx_init_napi_channel(channel);
Ben Hutchingse8f14992010-12-07 19:47:34 +00001783}
1784
1785static void efx_fini_napi_channel(struct efx_channel *channel)
1786{
1787 if (channel->napi_dev)
1788 netif_napi_del(&channel->napi_str);
1789 channel->napi_dev = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001790}
1791
1792static void efx_fini_napi(struct efx_nic *efx)
1793{
1794 struct efx_channel *channel;
1795
Ben Hutchingse8f14992010-12-07 19:47:34 +00001796 efx_for_each_channel(channel, efx)
1797 efx_fini_napi_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001798}
1799
1800/**************************************************************************
1801 *
1802 * Kernel netpoll interface
1803 *
1804 *************************************************************************/
1805
1806#ifdef CONFIG_NET_POLL_CONTROLLER
1807
1808/* Although in the common case interrupts will be disabled, this is not
1809 * guaranteed. However, all our work happens inside the NAPI callback,
1810 * so no locking is required.
1811 */
1812static void efx_netpoll(struct net_device *net_dev)
1813{
Ben Hutchings767e4682008-09-01 12:43:14 +01001814 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001815 struct efx_channel *channel;
1816
Ben Hutchings64ee3122008-09-01 12:47:38 +01001817 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001818 efx_schedule_channel(channel);
1819}
1820
1821#endif
1822
1823/**************************************************************************
1824 *
1825 * Kernel net device interface
1826 *
1827 *************************************************************************/
1828
1829/* Context: process, rtnl_lock() held. */
1830static int efx_net_open(struct net_device *net_dev)
1831{
Ben Hutchings767e4682008-09-01 12:43:14 +01001832 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001833 EFX_ASSERT_RESET_SERIALISED(efx);
1834
Ben Hutchings62776d02010-06-23 11:30:07 +00001835 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
1836 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001837
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08001838 if (efx->state == STATE_DISABLED)
1839 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001840 if (efx->phy_mode & PHY_MODE_SPECIAL)
1841 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001842 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
1843 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001844
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001845 /* Notify the kernel of the link state polled during driver load,
1846 * before the monitor starts running */
1847 efx_link_status_changed(efx);
1848
Ben Hutchings8ceee662008-04-27 12:55:59 +01001849 efx_start_all(efx);
Ben Hutchingsdd407812012-02-28 23:40:21 +00001850 efx_selftest_async_start(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001851 return 0;
1852}
1853
1854/* Context: process, rtnl_lock() held.
1855 * Note that the kernel will ignore our return code; this method
1856 * should really be a void.
1857 */
1858static int efx_net_stop(struct net_device *net_dev)
1859{
Ben Hutchings767e4682008-09-01 12:43:14 +01001860 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001861
Ben Hutchings62776d02010-06-23 11:30:07 +00001862 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
1863 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001864
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08001865 if (efx->state != STATE_DISABLED) {
1866 /* Stop the device and flush all the channels */
1867 efx_stop_all(efx);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08001868 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001869
1870 return 0;
1871}
1872
Ben Hutchings5b9e2072008-05-16 21:18:14 +01001873/* Context: process, dev_base_lock or RTNL held, non-blocking. */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +00001874static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev,
1875 struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001876{
Ben Hutchings767e4682008-09-01 12:43:14 +01001877 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001878 struct efx_mac_stats *mac_stats = &efx->mac_stats;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001879
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001880 spin_lock_bh(&efx->stats_lock);
Ben Hutchings1cb34522011-09-02 23:23:00 +01001881
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001882 efx->type->update_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001883
1884 stats->rx_packets = mac_stats->rx_packets;
1885 stats->tx_packets = mac_stats->tx_packets;
1886 stats->rx_bytes = mac_stats->rx_bytes;
1887 stats->tx_bytes = mac_stats->tx_bytes;
Ben Hutchings80485d32010-09-10 06:41:06 +00001888 stats->rx_dropped = efx->n_rx_nodesc_drop_cnt;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001889 stats->multicast = mac_stats->rx_multicast;
1890 stats->collisions = mac_stats->tx_collision;
1891 stats->rx_length_errors = (mac_stats->rx_gtjumbo +
1892 mac_stats->rx_length_error);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001893 stats->rx_crc_errors = mac_stats->rx_bad;
1894 stats->rx_frame_errors = mac_stats->rx_align_error;
1895 stats->rx_fifo_errors = mac_stats->rx_overflow;
1896 stats->rx_missed_errors = mac_stats->rx_missed;
1897 stats->tx_window_errors = mac_stats->tx_late_collision;
1898
1899 stats->rx_errors = (stats->rx_length_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001900 stats->rx_crc_errors +
1901 stats->rx_frame_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001902 mac_stats->rx_symbol_error);
1903 stats->tx_errors = (stats->tx_window_errors +
1904 mac_stats->tx_bad);
1905
Ben Hutchings1cb34522011-09-02 23:23:00 +01001906 spin_unlock_bh(&efx->stats_lock);
1907
Ben Hutchings8ceee662008-04-27 12:55:59 +01001908 return stats;
1909}
1910
1911/* Context: netif_tx_lock held, BHs disabled. */
1912static void efx_watchdog(struct net_device *net_dev)
1913{
Ben Hutchings767e4682008-09-01 12:43:14 +01001914 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001915
Ben Hutchings62776d02010-06-23 11:30:07 +00001916 netif_err(efx, tx_err, efx->net_dev,
1917 "TX stuck with port_enabled=%d: resetting channels\n",
1918 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001919
Ben Hutchings739bb23d2008-11-04 20:35:36 +00001920 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001921}
1922
1923
1924/* Context: process, rtnl_lock() held. */
1925static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1926{
Ben Hutchings767e4682008-09-01 12:43:14 +01001927 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001928
1929 EFX_ASSERT_RESET_SERIALISED(efx);
1930
1931 if (new_mtu > EFX_MAX_MTU)
1932 return -EINVAL;
1933
1934 efx_stop_all(efx);
1935
Ben Hutchings62776d02010-06-23 11:30:07 +00001936 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001937
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001938 mutex_lock(&efx->mac_lock);
1939 /* Reconfigure the MAC before enabling the dma queues so that
1940 * the RX buffers don't overflow */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001941 net_dev->mtu = new_mtu;
Ben Hutchings710b2082011-09-03 00:15:00 +01001942 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001943 mutex_unlock(&efx->mac_lock);
1944
Ben Hutchings8ceee662008-04-27 12:55:59 +01001945 efx_start_all(efx);
Ben Hutchings6c8eef42012-01-09 19:54:16 +00001946 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001947}
1948
1949static int efx_set_mac_address(struct net_device *net_dev, void *data)
1950{
Ben Hutchings767e4682008-09-01 12:43:14 +01001951 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001952 struct sockaddr *addr = data;
1953 char *new_addr = addr->sa_data;
1954
1955 EFX_ASSERT_RESET_SERIALISED(efx);
1956
1957 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001958 netif_err(efx, drv, efx->net_dev,
1959 "invalid ethernet MAC address requested: %pM\n",
1960 new_addr);
Danny Kukawka504f9b52012-02-21 02:07:49 +00001961 return -EADDRNOTAVAIL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001962 }
1963
1964 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001965 efx_sriov_mac_address_changed(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001966
1967 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001968 mutex_lock(&efx->mac_lock);
Ben Hutchings710b2082011-09-03 00:15:00 +01001969 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001970 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001971
1972 return 0;
1973}
1974
Ben Hutchingsa816f752008-09-01 12:49:12 +01001975/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings0fca8c92012-01-09 19:54:44 +00001976static void efx_set_rx_mode(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001977{
Ben Hutchings767e4682008-09-01 12:43:14 +01001978 struct efx_nic *efx = netdev_priv(net_dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001979 struct netdev_hw_addr *ha;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001980 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001981 u32 crc;
1982 int bit;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001983
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001984 efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001985
1986 /* Build multicast hash table */
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001987 if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001988 memset(mc_hash, 0xff, sizeof(*mc_hash));
1989 } else {
1990 memset(mc_hash, 0x00, sizeof(*mc_hash));
Jiri Pirko22bedad32010-04-01 21:22:57 +00001991 netdev_for_each_mc_addr(ha, net_dev) {
1992 crc = ether_crc_le(ETH_ALEN, ha->addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001993 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1994 set_bit_le(bit, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001995 }
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001996
1997 /* Broadcast packets go through the multicast hash filter.
1998 * ether_crc_le() of the broadcast address is 0xbe2612ff
1999 * so we always add bit 0xff to the mask.
2000 */
2001 set_bit_le(0xff, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002002 }
2003
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002004 if (efx->port_enabled)
2005 queue_work(efx->workqueue, &efx->mac_work);
2006 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002007}
2008
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002009static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002010{
2011 struct efx_nic *efx = netdev_priv(net_dev);
2012
2013 /* If disabling RX n-tuple filtering, clear existing filters */
2014 if (net_dev->features & ~data & NETIF_F_NTUPLE)
2015 efx_filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
2016
2017 return 0;
2018}
2019
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002020static const struct net_device_ops efx_netdev_ops = {
2021 .ndo_open = efx_net_open,
2022 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00002023 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002024 .ndo_tx_timeout = efx_watchdog,
2025 .ndo_start_xmit = efx_hard_start_xmit,
2026 .ndo_validate_addr = eth_validate_addr,
2027 .ndo_do_ioctl = efx_ioctl,
2028 .ndo_change_mtu = efx_change_mtu,
2029 .ndo_set_mac_address = efx_set_mac_address,
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002030 .ndo_set_rx_mode = efx_set_rx_mode,
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002031 .ndo_set_features = efx_set_features,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002032#ifdef CONFIG_SFC_SRIOV
2033 .ndo_set_vf_mac = efx_sriov_set_vf_mac,
2034 .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
2035 .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
2036 .ndo_get_vf_config = efx_sriov_get_vf_config,
2037#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002038#ifdef CONFIG_NET_POLL_CONTROLLER
2039 .ndo_poll_controller = efx_netpoll,
2040#endif
Ben Hutchings94b274b2011-01-10 21:18:20 +00002041 .ndo_setup_tc = efx_setup_tc,
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002042#ifdef CONFIG_RFS_ACCEL
2043 .ndo_rx_flow_steer = efx_filter_rfs,
2044#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002045};
2046
Ben Hutchings7dde5962008-12-12 22:09:38 -08002047static void efx_update_name(struct efx_nic *efx)
2048{
2049 strcpy(efx->name, efx->net_dev->name);
2050 efx_mtd_rename(efx);
2051 efx_set_channel_names(efx);
2052}
2053
Ben Hutchings8ceee662008-04-27 12:55:59 +01002054static int efx_netdev_event(struct notifier_block *this,
2055 unsigned long event, void *ptr)
2056{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01002057 struct net_device *net_dev = ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002058
Ben Hutchings7dde5962008-12-12 22:09:38 -08002059 if (net_dev->netdev_ops == &efx_netdev_ops &&
2060 event == NETDEV_CHANGENAME)
2061 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002062
2063 return NOTIFY_DONE;
2064}
2065
2066static struct notifier_block efx_netdev_notifier = {
2067 .notifier_call = efx_netdev_event,
2068};
2069
Ben Hutchings06d5e192008-12-12 21:47:23 -08002070static ssize_t
2071show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2072{
2073 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2074 return sprintf(buf, "%d\n", efx->phy_type);
2075}
2076static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL);
2077
Ben Hutchings8ceee662008-04-27 12:55:59 +01002078static int efx_register_netdev(struct efx_nic *efx)
2079{
2080 struct net_device *net_dev = efx->net_dev;
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002081 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002082 int rc;
2083
2084 net_dev->watchdog_timeo = 5 * HZ;
2085 net_dev->irq = efx->pci_dev->irq;
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002086 net_dev->netdev_ops = &efx_netdev_ops;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002087 SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00002088 net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002089
Ben Hutchings7dde5962008-12-12 22:09:38 -08002090 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00002091
2092 rc = dev_alloc_name(net_dev, net_dev->name);
2093 if (rc < 0)
2094 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002095 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002096
2097 rc = register_netdevice(net_dev);
2098 if (rc)
2099 goto fail_locked;
2100
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002101 efx_for_each_channel(channel, efx) {
2102 struct efx_tx_queue *tx_queue;
Ben Hutchings60031fc2011-01-12 18:39:40 +00002103 efx_for_each_channel_tx_queue(tx_queue, channel)
2104 efx_init_tx_queue_core_txq(tx_queue);
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002105 }
2106
Ben Hutchingsaed06282009-08-26 08:16:27 +00002107 /* Always start with carrier off; PHY events will detect the link */
Ben Hutchings86ee5302012-01-09 19:51:22 +00002108 netif_carrier_off(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002109
Ben Hutchings7dde5962008-12-12 22:09:38 -08002110 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002111
Ben Hutchings06d5e192008-12-12 21:47:23 -08002112 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2113 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002114 netif_err(efx, drv, efx->net_dev,
2115 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08002116 goto fail_registered;
2117 }
2118
Ben Hutchings8ceee662008-04-27 12:55:59 +01002119 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08002120
Ben Hutchingsaed06282009-08-26 08:16:27 +00002121fail_locked:
2122 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00002123 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00002124 return rc;
2125
Ben Hutchings06d5e192008-12-12 21:47:23 -08002126fail_registered:
2127 unregister_netdev(net_dev);
2128 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002129}
2130
2131static void efx_unregister_netdev(struct efx_nic *efx)
2132{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002133 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002134 struct efx_tx_queue *tx_queue;
2135
2136 if (!efx->net_dev)
2137 return;
2138
Ben Hutchings767e4682008-09-01 12:43:14 +01002139 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002140
2141 /* Free up any skbs still remaining. This has to happen before
2142 * we try to unregister the netdev as running their destructors
2143 * may be needed to get the device ref. count to 0. */
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002144 efx_for_each_channel(channel, efx) {
2145 efx_for_each_channel_tx_queue(tx_queue, channel)
2146 efx_release_tx_buffers(tx_queue);
2147 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002148
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002149 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2150 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2151 unregister_netdev(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002152}
2153
2154/**************************************************************************
2155 *
2156 * Device reset and suspend
2157 *
2158 **************************************************************************/
2159
Ben Hutchings2467ca42008-09-01 12:48:50 +01002160/* Tears down the entire software state and most of the hardware state
2161 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002162void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002163{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002164 EFX_ASSERT_RESET_SERIALISED(efx);
2165
Ben Hutchings2467ca42008-09-01 12:48:50 +01002166 efx_stop_all(efx);
2167 mutex_lock(&efx->mac_lock);
2168
Ben Hutchings7f967c02012-02-13 23:45:02 +00002169 efx_stop_interrupts(efx, false);
Steve Hodgson4b988282009-01-29 17:50:51 +00002170 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
2171 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002172 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002173}
2174
Ben Hutchings2467ca42008-09-01 12:48:50 +01002175/* This function will always ensure that the locks acquired in
2176 * efx_reset_down() are released. A failure return code indicates
2177 * that we were unable to reinitialise the hardware, and the
2178 * driver should be disabled. If ok is false, then the rx and tx
2179 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002180int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002181{
2182 int rc;
2183
Ben Hutchings2467ca42008-09-01 12:48:50 +01002184 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002185
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002186 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002187 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002188 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002189 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002190 }
2191
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002192 if (!ok)
2193 goto fail;
2194
Steve Hodgson4b988282009-01-29 17:50:51 +00002195 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002196 rc = efx->phy_op->init(efx);
2197 if (rc)
2198 goto fail;
2199 if (efx->phy_op->reconfigure(efx))
Ben Hutchings62776d02010-06-23 11:30:07 +00002200 netif_err(efx, drv, efx->net_dev,
2201 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002202 }
2203
Ben Hutchings710b2082011-09-03 00:15:00 +01002204 efx->type->reconfigure_mac(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002205
Ben Hutchings7f967c02012-02-13 23:45:02 +00002206 efx_start_interrupts(efx, false);
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002207 efx_restore_filters(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002208 efx_sriov_reset(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002209
2210 mutex_unlock(&efx->mac_lock);
2211
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002212 efx_start_all(efx);
2213
2214 return 0;
2215
2216fail:
2217 efx->port_initialized = false;
2218
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002219 mutex_unlock(&efx->mac_lock);
2220
Ben Hutchings8ceee662008-04-27 12:55:59 +01002221 return rc;
2222}
2223
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002224/* Reset the NIC using the specified method. Note that the reset may
2225 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002226 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002227 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002228 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002229int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002230{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002231 int rc, rc2;
2232 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002233
Ben Hutchings62776d02010-06-23 11:30:07 +00002234 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2235 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002236
Ben Hutchingse4abce82011-05-16 18:51:24 +01002237 netif_device_detach(efx->net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002238 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002239
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002240 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002241 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002242 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002243 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002244 }
2245
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002246 /* Clear flags for the scopes we covered. We assume the NIC and
2247 * driver are now quiescent so that there is no race here.
2248 */
2249 efx->reset_pending &= -(1 << (method + 1));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002250
2251 /* Reinitialise bus-mastering, which may have been turned off before
2252 * the reset was scheduled. This is still appropriate, even in the
2253 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2254 * can respond to requests. */
2255 pci_set_master(efx->pci_dev);
2256
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002257out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002258 /* Leave device stopped if necessary */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002259 disabled = rc || method == RESET_TYPE_DISABLE;
2260 rc2 = efx_reset_up(efx, method, !disabled);
2261 if (rc2) {
2262 disabled = true;
2263 if (!rc)
2264 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002265 }
2266
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002267 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002268 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002269 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002270 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002271 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002272 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Ben Hutchingse4abce82011-05-16 18:51:24 +01002273 netif_device_attach(efx->net_dev);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002274 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002275 return rc;
2276}
2277
2278/* The worker thread exists so that code that cannot sleep can
2279 * schedule a reset for later.
2280 */
2281static void efx_reset_work(struct work_struct *data)
2282{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002283 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002284 unsigned long pending = ACCESS_ONCE(efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002285
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002286 if (!pending)
Steve Hodgson319ba642010-06-01 11:17:24 +00002287 return;
2288
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002289 /* If we're not READY then don't reset. Leave the reset_pending
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002290 * flags set so that efx_pci_probe_main will be retried */
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002291 if (efx->state != STATE_READY) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002292 netif_info(efx, drv, efx->net_dev,
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002293 "scheduled reset quenched; NIC not ready\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002294 return;
2295 }
2296
2297 rtnl_lock();
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002298 (void)efx_reset(efx, fls(pending) - 1);
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002299 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002300}
2301
2302void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2303{
2304 enum reset_type method;
2305
Ben Hutchings8ceee662008-04-27 12:55:59 +01002306 switch (type) {
2307 case RESET_TYPE_INVISIBLE:
2308 case RESET_TYPE_ALL:
2309 case RESET_TYPE_WORLD:
2310 case RESET_TYPE_DISABLE:
2311 method = type;
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002312 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2313 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002314 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002315 default:
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002316 method = efx->type->map_reset_reason(type);
Ben Hutchings62776d02010-06-23 11:30:07 +00002317 netif_dbg(efx, drv, efx->net_dev,
2318 "scheduling %s reset for %s\n",
2319 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002320 break;
2321 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002322
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002323 set_bit(method, &efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002324
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002325 /* efx_process_channel() will no longer read events once a
2326 * reset is scheduled. So switch back to poll'd MCDI completions. */
2327 efx_mcdi_mode_poll(efx);
2328
Steve Hodgson1ab00622008-12-12 21:33:02 -08002329 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002330}
2331
2332/**************************************************************************
2333 *
2334 * List of NICs we support
2335 *
2336 **************************************************************************/
2337
2338/* PCI device ID table */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002339static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002340 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2341 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002342 .driver_data = (unsigned long) &falcon_a1_nic_type},
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002343 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2344 PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002345 .driver_data = (unsigned long) &falcon_b0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002346 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002347 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002348 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002349 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002350 {0} /* end of list */
2351};
2352
2353/**************************************************************************
2354 *
Ben Hutchings37594332009-11-23 16:05:45 +00002355 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002356 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002357 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002358 * Needed so all function pointers are valid and do not have to be tested
2359 * before use
2360 *
2361 **************************************************************************/
2362int efx_port_dummy_op_int(struct efx_nic *efx)
2363{
2364 return 0;
2365}
2366void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002367
2368static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002369{
2370 return false;
2371}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002372
stephen hemminger6c8c2512011-04-14 05:50:12 +00002373static const struct efx_phy_operations efx_dummy_phy_operations = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002374 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002375 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002376 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002377 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002378};
2379
Ben Hutchings8ceee662008-04-27 12:55:59 +01002380/**************************************************************************
2381 *
2382 * Data housekeeping
2383 *
2384 **************************************************************************/
2385
2386/* This zeroes out and then fills in the invariants in a struct
2387 * efx_nic (including all sub-structures).
2388 */
stephen hemminger6c8c2512011-04-14 05:50:12 +00002389static int efx_init_struct(struct efx_nic *efx, const struct efx_nic_type *type,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002390 struct pci_dev *pci_dev, struct net_device *net_dev)
2391{
Ben Hutchings46426102010-09-10 06:42:33 +00002392 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002393
2394 /* Initialise common structures */
2395 memset(efx, 0, sizeof(*efx));
2396 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002397#ifdef CONFIG_SFC_MTD
2398 INIT_LIST_HEAD(&efx->mtd_list);
2399#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002400 INIT_WORK(&efx->reset_work, efx_reset_work);
2401 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002402 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002403 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002404 efx->msg_enable = debug;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002405 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002406 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002407
2408 efx->net_dev = net_dev;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002409 spin_lock_init(&efx->stats_lock);
2410 mutex_init(&efx->mac_lock);
2411 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002412 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08002413 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00002414 init_waitqueue_head(&efx->flush_wq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002415
2416 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00002417 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
2418 if (!efx->channel[i])
2419 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002420 }
2421
2422 efx->type = type;
2423
Ben Hutchings8ceee662008-04-27 12:55:59 +01002424 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
2425
2426 /* Higher numbered interrupt modes are less capable! */
2427 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
2428 interrupt_mode);
2429
Ben Hutchings6977dc62008-12-26 13:44:39 -08002430 /* Would be good to use the net_dev name, but we're too early */
2431 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
2432 pci_name(pci_dev));
2433 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002434 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00002435 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01002436
Ben Hutchings8ceee662008-04-27 12:55:59 +01002437 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00002438
2439fail:
2440 efx_fini_struct(efx);
2441 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002442}
2443
2444static void efx_fini_struct(struct efx_nic *efx)
2445{
Ben Hutchings8313aca2010-09-10 06:41:57 +00002446 int i;
2447
2448 for (i = 0; i < EFX_MAX_CHANNELS; i++)
2449 kfree(efx->channel[i]);
2450
Ben Hutchings8ceee662008-04-27 12:55:59 +01002451 if (efx->workqueue) {
2452 destroy_workqueue(efx->workqueue);
2453 efx->workqueue = NULL;
2454 }
2455}
2456
2457/**************************************************************************
2458 *
2459 * PCI interface
2460 *
2461 **************************************************************************/
2462
2463/* Main body of final NIC shutdown code
2464 * This is called only at module unload (or hotplug removal).
2465 */
2466static void efx_pci_remove_main(struct efx_nic *efx)
2467{
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002468#ifdef CONFIG_RFS_ACCEL
2469 free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
2470 efx->net_dev->rx_cpu_rmap = NULL;
2471#endif
Ben Hutchings7f967c02012-02-13 23:45:02 +00002472 efx_stop_interrupts(efx, false);
Ben Hutchings152b6a62009-11-29 03:43:56 +00002473 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002474 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002475 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002476 efx_fini_napi(efx);
2477 efx_remove_all(efx);
2478}
2479
2480/* Final NIC shutdown
2481 * This is called only at module unload (or hotplug removal).
2482 */
2483static void efx_pci_remove(struct pci_dev *pci_dev)
2484{
2485 struct efx_nic *efx;
2486
2487 efx = pci_get_drvdata(pci_dev);
2488 if (!efx)
2489 return;
2490
2491 /* Mark the NIC as fini, then stop the interface */
2492 rtnl_lock();
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002493 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002494 dev_close(efx->net_dev);
2495
2496 /* Allow any queued efx_resets() to complete */
2497 rtnl_unlock();
2498
Ben Hutchings7f967c02012-02-13 23:45:02 +00002499 efx_stop_interrupts(efx, false);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002500 efx_sriov_fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002501 efx_unregister_netdev(efx);
2502
Ben Hutchings7dde5962008-12-12 22:09:38 -08002503 efx_mtd_remove(efx);
2504
Ben Hutchings8ceee662008-04-27 12:55:59 +01002505 /* Wait for any scheduled resets to complete. No more will be
2506 * scheduled from this point because efx_stop_all() has been
2507 * called, we are no longer registered with driverlink, and
2508 * the net_device's have been removed. */
Steve Hodgson1ab00622008-12-12 21:33:02 -08002509 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002510
2511 efx_pci_remove_main(efx);
2512
Ben Hutchings8ceee662008-04-27 12:55:59 +01002513 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002514 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002515
Ben Hutchings8ceee662008-04-27 12:55:59 +01002516 efx_fini_struct(efx);
Ben Hutchings3de4e302012-04-05 00:22:19 +01002517 pci_set_drvdata(pci_dev, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002518 free_netdev(efx->net_dev);
2519};
2520
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002521/* NIC VPD information
2522 * Called during probe to display the part number of the
2523 * installed NIC. VPD is potentially very large but this should
2524 * always appear within the first 512 bytes.
2525 */
2526#define SFC_VPD_LEN 512
2527static void efx_print_product_vpd(struct efx_nic *efx)
2528{
2529 struct pci_dev *dev = efx->pci_dev;
2530 char vpd_data[SFC_VPD_LEN];
2531 ssize_t vpd_size;
2532 int i, j;
2533
2534 /* Get the vpd data from the device */
2535 vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
2536 if (vpd_size <= 0) {
2537 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
2538 return;
2539 }
2540
2541 /* Get the Read only section */
2542 i = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
2543 if (i < 0) {
2544 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
2545 return;
2546 }
2547
2548 j = pci_vpd_lrdt_size(&vpd_data[i]);
2549 i += PCI_VPD_LRDT_TAG_SIZE;
2550 if (i + j > vpd_size)
2551 j = vpd_size - i;
2552
2553 /* Get the Part number */
2554 i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
2555 if (i < 0) {
2556 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
2557 return;
2558 }
2559
2560 j = pci_vpd_info_field_size(&vpd_data[i]);
2561 i += PCI_VPD_INFO_FLD_HDR_SIZE;
2562 if (i + j > vpd_size) {
2563 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
2564 return;
2565 }
2566
2567 netif_info(efx, drv, efx->net_dev,
2568 "Part Number : %.*s\n", j, &vpd_data[i]);
2569}
2570
2571
Ben Hutchings8ceee662008-04-27 12:55:59 +01002572/* Main body of NIC initialisation
2573 * This is called at module load (or hotplug insertion, theoretically).
2574 */
2575static int efx_pci_probe_main(struct efx_nic *efx)
2576{
2577 int rc;
2578
2579 /* Do start-of-day initialisation */
2580 rc = efx_probe_all(efx);
2581 if (rc)
2582 goto fail1;
2583
Ben Hutchingse8f14992010-12-07 19:47:34 +00002584 efx_init_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002585
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002586 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002587 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002588 netif_err(efx, probe, efx->net_dev,
2589 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002590 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002591 }
2592
2593 rc = efx_init_port(efx);
2594 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002595 netif_err(efx, probe, efx->net_dev,
2596 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002597 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002598 }
2599
Ben Hutchings152b6a62009-11-29 03:43:56 +00002600 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002601 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00002602 goto fail5;
Ben Hutchings7f967c02012-02-13 23:45:02 +00002603 efx_start_interrupts(efx, false);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002604
2605 return 0;
2606
Ben Hutchings278c0622009-11-23 16:05:12 +00002607 fail5:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002608 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002609 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002610 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002611 fail3:
2612 efx_fini_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002613 efx_remove_all(efx);
2614 fail1:
2615 return rc;
2616}
2617
2618/* NIC initialisation
2619 *
2620 * This is called at module load (or hotplug insertion,
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002621 * theoretically). It sets up PCI mappings, resets the NIC,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002622 * sets up and registers the network devices with the kernel and hooks
2623 * the interrupt service routine. It does not prepare the device for
2624 * transmission; this is left to the first time one of the network
2625 * interfaces is brought up (i.e. efx_net_open).
2626 */
2627static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2628 const struct pci_device_id *entry)
2629{
stephen hemminger6c8c2512011-04-14 05:50:12 +00002630 const struct efx_nic_type *type = (const struct efx_nic_type *) entry->driver_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002631 struct net_device *net_dev;
2632 struct efx_nic *efx;
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002633 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002634
2635 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchings94b274b2011-01-10 21:18:20 +00002636 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
2637 EFX_MAX_RX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002638 if (!net_dev)
2639 return -ENOMEM;
Ben Hutchingsc383b532009-11-29 15:11:02 +00002640 net_dev->features |= (type->offload_features | NETIF_F_SG |
Ben Hutchings97bc5412009-05-19 16:19:08 -07002641 NETIF_F_HIGHDMA | NETIF_F_TSO |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002642 NETIF_F_RXCSUM);
Ben Hutchings738a8f42009-11-29 15:16:05 +00002643 if (type->offload_features & NETIF_F_V6_CSUM)
2644 net_dev->features |= NETIF_F_TSO6;
Ben Hutchings285065632008-09-01 12:46:54 +01002645 /* Mask for features that also apply to VLAN devices */
2646 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002647 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
2648 NETIF_F_RXCSUM);
2649 /* All offloads can be toggled */
2650 net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA;
Ben Hutchings767e4682008-09-01 12:43:14 +01002651 efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002652 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002653 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002654 rc = efx_init_struct(efx, type, pci_dev, net_dev);
2655 if (rc)
2656 goto fail1;
2657
Ben Hutchings62776d02010-06-23 11:30:07 +00002658 netif_info(efx, probe, efx->net_dev,
Ben Hutchingsff79c8a2011-07-13 16:21:24 +01002659 "Solarflare NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002660
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002661 efx_print_product_vpd(efx);
2662
Ben Hutchings8ceee662008-04-27 12:55:59 +01002663 /* Set up basic I/O (BAR mappings etc) */
2664 rc = efx_init_io(efx);
2665 if (rc)
2666 goto fail2;
2667
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002668 rc = efx_pci_probe_main(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002669
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002670 /* Serialise against efx_reset(). No more resets will be
2671 * scheduled since efx_stop_all() has been called, and we have
2672 * not and never have been registered.
2673 */
2674 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002675
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002676 if (rc)
2677 goto fail3;
Steve Hodgsonfa402b22008-12-12 22:08:16 -08002678
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002679 /* If there was a scheduled reset during probe, the NIC is
2680 * probably hosed anyway.
2681 */
2682 if (efx->reset_pending) {
2683 rc = -EIO;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002684 goto fail4;
2685 }
2686
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002687 /* Switch to the READY state before we expose the device to the OS,
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002688 * so that dev_open()|efx_start_all() will actually start the device */
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002689 efx->state = STATE_READY;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002690
Ben Hutchings8ceee662008-04-27 12:55:59 +01002691 rc = efx_register_netdev(efx);
2692 if (rc)
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002693 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002694
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002695 rc = efx_sriov_init(efx);
2696 if (rc)
2697 netif_err(efx, probe, efx->net_dev,
2698 "SR-IOV can't be enabled rc %d\n", rc);
2699
Ben Hutchings62776d02010-06-23 11:30:07 +00002700 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002701
Ben Hutchings7c431612012-01-27 17:23:58 +00002702 /* Try to create MTDs, but allow this to fail */
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002703 rtnl_lock();
Ben Hutchings7c431612012-01-27 17:23:58 +00002704 rc = efx_mtd_probe(efx);
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002705 rtnl_unlock();
Ben Hutchings7c431612012-01-27 17:23:58 +00002706 if (rc)
2707 netif_warn(efx, probe, efx->net_dev,
2708 "failed to create MTDs (%d)\n", rc);
2709
Ben Hutchings8ceee662008-04-27 12:55:59 +01002710 return 0;
2711
Ben Hutchings8ceee662008-04-27 12:55:59 +01002712 fail4:
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002713 efx_pci_remove_main(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002714 fail3:
2715 efx_fini_io(efx);
2716 fail2:
2717 efx_fini_struct(efx);
2718 fail1:
Ben Hutchings3de4e302012-04-05 00:22:19 +01002719 pci_set_drvdata(pci_dev, NULL);
Steve Hodgson5e2a9112010-02-12 12:32:27 -08002720 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00002721 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002722 free_netdev(net_dev);
2723 return rc;
2724}
2725
Ben Hutchings89c758f2009-11-29 03:43:07 +00002726static int efx_pm_freeze(struct device *dev)
2727{
2728 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2729
Ben Hutchings61da0262012-07-27 19:35:39 +01002730 rtnl_lock();
2731
Ben Hutchings6032fb52012-07-27 19:35:47 +01002732 if (efx->state != STATE_DISABLED) {
2733 efx->state = STATE_UNINIT;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002734
Ben Hutchings6032fb52012-07-27 19:35:47 +01002735 netif_device_detach(efx->net_dev);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002736
Ben Hutchings6032fb52012-07-27 19:35:47 +01002737 efx_stop_all(efx);
2738 efx_stop_interrupts(efx, false);
2739 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00002740
Ben Hutchings61da0262012-07-27 19:35:39 +01002741 rtnl_unlock();
2742
Ben Hutchings89c758f2009-11-29 03:43:07 +00002743 return 0;
2744}
2745
2746static int efx_pm_thaw(struct device *dev)
2747{
2748 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2749
Ben Hutchings61da0262012-07-27 19:35:39 +01002750 rtnl_lock();
2751
Ben Hutchings6032fb52012-07-27 19:35:47 +01002752 if (efx->state != STATE_DISABLED) {
2753 efx_start_interrupts(efx, false);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002754
Ben Hutchings6032fb52012-07-27 19:35:47 +01002755 mutex_lock(&efx->mac_lock);
2756 efx->phy_op->reconfigure(efx);
2757 mutex_unlock(&efx->mac_lock);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002758
Ben Hutchings6032fb52012-07-27 19:35:47 +01002759 efx_start_all(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002760
Ben Hutchings6032fb52012-07-27 19:35:47 +01002761 netif_device_attach(efx->net_dev);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002762
Ben Hutchings6032fb52012-07-27 19:35:47 +01002763 efx->state = STATE_READY;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002764
Ben Hutchings6032fb52012-07-27 19:35:47 +01002765 efx->type->resume_wol(efx);
2766 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00002767
Ben Hutchings61da0262012-07-27 19:35:39 +01002768 rtnl_unlock();
2769
Steve Hodgson319ba642010-06-01 11:17:24 +00002770 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2771 queue_work(reset_workqueue, &efx->reset_work);
2772
Ben Hutchings89c758f2009-11-29 03:43:07 +00002773 return 0;
2774}
2775
2776static int efx_pm_poweroff(struct device *dev)
2777{
2778 struct pci_dev *pci_dev = to_pci_dev(dev);
2779 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2780
2781 efx->type->fini(efx);
2782
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002783 efx->reset_pending = 0;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002784
2785 pci_save_state(pci_dev);
2786 return pci_set_power_state(pci_dev, PCI_D3hot);
2787}
2788
2789/* Used for both resume and restore */
2790static int efx_pm_resume(struct device *dev)
2791{
2792 struct pci_dev *pci_dev = to_pci_dev(dev);
2793 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2794 int rc;
2795
2796 rc = pci_set_power_state(pci_dev, PCI_D0);
2797 if (rc)
2798 return rc;
2799 pci_restore_state(pci_dev);
2800 rc = pci_enable_device(pci_dev);
2801 if (rc)
2802 return rc;
2803 pci_set_master(efx->pci_dev);
2804 rc = efx->type->reset(efx, RESET_TYPE_ALL);
2805 if (rc)
2806 return rc;
2807 rc = efx->type->init(efx);
2808 if (rc)
2809 return rc;
2810 efx_pm_thaw(dev);
2811 return 0;
2812}
2813
2814static int efx_pm_suspend(struct device *dev)
2815{
2816 int rc;
2817
2818 efx_pm_freeze(dev);
2819 rc = efx_pm_poweroff(dev);
2820 if (rc)
2821 efx_pm_resume(dev);
2822 return rc;
2823}
2824
Ben Hutchings18e83e42012-01-05 19:05:20 +00002825static const struct dev_pm_ops efx_pm_ops = {
Ben Hutchings89c758f2009-11-29 03:43:07 +00002826 .suspend = efx_pm_suspend,
2827 .resume = efx_pm_resume,
2828 .freeze = efx_pm_freeze,
2829 .thaw = efx_pm_thaw,
2830 .poweroff = efx_pm_poweroff,
2831 .restore = efx_pm_resume,
2832};
2833
Ben Hutchings8ceee662008-04-27 12:55:59 +01002834static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00002835 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002836 .id_table = efx_pci_table,
2837 .probe = efx_pci_probe,
2838 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00002839 .driver.pm = &efx_pm_ops,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002840};
2841
2842/**************************************************************************
2843 *
2844 * Kernel module interface
2845 *
2846 *************************************************************************/
2847
2848module_param(interrupt_mode, uint, 0444);
2849MODULE_PARM_DESC(interrupt_mode,
2850 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
2851
2852static int __init efx_init_module(void)
2853{
2854 int rc;
2855
2856 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
2857
2858 rc = register_netdevice_notifier(&efx_netdev_notifier);
2859 if (rc)
2860 goto err_notifier;
2861
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002862 rc = efx_init_sriov();
2863 if (rc)
2864 goto err_sriov;
2865
Steve Hodgson1ab00622008-12-12 21:33:02 -08002866 reset_workqueue = create_singlethread_workqueue("sfc_reset");
2867 if (!reset_workqueue) {
2868 rc = -ENOMEM;
2869 goto err_reset;
2870 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002871
2872 rc = pci_register_driver(&efx_pci_driver);
2873 if (rc < 0)
2874 goto err_pci;
2875
2876 return 0;
2877
2878 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08002879 destroy_workqueue(reset_workqueue);
2880 err_reset:
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002881 efx_fini_sriov();
2882 err_sriov:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002883 unregister_netdevice_notifier(&efx_netdev_notifier);
2884 err_notifier:
2885 return rc;
2886}
2887
2888static void __exit efx_exit_module(void)
2889{
2890 printk(KERN_INFO "Solarflare NET driver unloading\n");
2891
2892 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002893 destroy_workqueue(reset_workqueue);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002894 efx_fini_sriov();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002895 unregister_netdevice_notifier(&efx_netdev_notifier);
2896
2897}
2898
2899module_init(efx_init_module);
2900module_exit(efx_exit_module);
2901
Ben Hutchings906bb262009-11-29 15:16:19 +00002902MODULE_AUTHOR("Solarflare Communications and "
2903 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002904MODULE_DESCRIPTION("Solarflare Communications network driver");
2905MODULE_LICENSE("GPL");
2906MODULE_DEVICE_TABLE(pci, efx_pci_table);