blob: 4105a66647651ca615c82d2393609ff46cf452fa [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
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100210static int efx_check_disabled(struct efx_nic *efx)
211{
212 if (efx->state == STATE_DISABLED) {
213 netif_err(efx, drv, efx->net_dev,
214 "device is disabled due to earlier errors\n");
215 return -EIO;
216 }
217 return 0;
218}
219
Ben Hutchings8ceee662008-04-27 12:55:59 +0100220/**************************************************************************
221 *
222 * Event queue processing
223 *
224 *************************************************************************/
225
226/* Process channel's event queue
227 *
228 * This function is responsible for processing the event queue of a
229 * single channel. The caller must guarantee that this function will
230 * never be concurrently called more than once on the same channel,
231 * though different channels may be being processed concurrently.
232 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000233static int efx_process_channel(struct efx_channel *channel, int budget)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100234{
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000235 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100236
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000237 if (unlikely(!channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100238 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100239
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000240 spent = efx_nic_process_eventq(channel, budget);
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000241 if (spent && efx_channel_has_rx_queue(channel)) {
242 struct efx_rx_queue *rx_queue =
243 efx_channel_get_rx_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100244
Ben Hutchingsd9ab7002012-02-13 23:29:16 +0000245 /* Deliver last RX packet. */
246 if (channel->rx_pkt) {
247 __efx_rx_packet(channel, channel->rx_pkt);
248 channel->rx_pkt = NULL;
249 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000250 if (rx_queue->enabled) {
251 efx_rx_strategy(channel);
252 efx_fast_push_rx_descriptors(rx_queue);
253 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100254 }
255
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000256 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100257}
258
259/* Mark channel as finished processing
260 *
261 * Note that since we will not receive further interrupts for this
262 * channel before we finish processing and call the eventq_read_ack()
263 * method, there is no need to use the interrupt hold-off timers.
264 */
265static inline void efx_channel_processed(struct efx_channel *channel)
266{
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100267 /* The interrupt handler for this channel may set work_pending
268 * as soon as we acknowledge the events we've seen. Make sure
269 * it's cleared before then. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100270 channel->work_pending = false;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100271 smp_wmb();
272
Ben Hutchings152b6a62009-11-29 03:43:56 +0000273 efx_nic_eventq_read_ack(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100274}
275
276/* NAPI poll handler
277 *
278 * NAPI guarantees serialisation of polls of the same device, which
279 * provides the guarantee required by efx_process_channel().
280 */
281static int efx_poll(struct napi_struct *napi, int budget)
282{
283 struct efx_channel *channel =
284 container_of(napi, struct efx_channel, napi_str);
Ben Hutchings62776d02010-06-23 11:30:07 +0000285 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000286 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100287
Ben Hutchings62776d02010-06-23 11:30:07 +0000288 netif_vdbg(efx, intr, efx->net_dev,
289 "channel %d NAPI poll executing on CPU %d\n",
290 channel->channel, raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +0100291
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000292 spent = efx_process_channel(channel, budget);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100293
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000294 if (spent < budget) {
Ben Hutchings9d9a6972012-02-10 23:01:48 +0000295 if (efx_channel_has_rx_queue(channel) &&
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000296 efx->irq_rx_adaptive &&
297 unlikely(++channel->irq_count == 1000)) {
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000298 if (unlikely(channel->irq_mod_score <
299 irq_adapt_low_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000300 if (channel->irq_moderation > 1) {
301 channel->irq_moderation -= 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000302 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000303 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000304 } else if (unlikely(channel->irq_mod_score >
305 irq_adapt_high_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000306 if (channel->irq_moderation <
307 efx->irq_rx_moderation) {
308 channel->irq_moderation += 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000309 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000310 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000311 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000312 channel->irq_count = 0;
313 channel->irq_mod_score = 0;
314 }
315
Ben Hutchings64d8ad62011-01-05 00:50:41 +0000316 efx_filter_rfs_expire(channel);
317
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318 /* There is no race here; although napi_disable() will
Ben Hutchings288379f2009-01-19 16:43:59 -0800319 * only wait for napi_complete(), this isn't a problem
Ben Hutchings8ceee662008-04-27 12:55:59 +0100320 * since efx_channel_processed() will have no effect if
321 * interrupts have already been disabled.
322 */
Ben Hutchings288379f2009-01-19 16:43:59 -0800323 napi_complete(napi);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100324 efx_channel_processed(channel);
325 }
326
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000327 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100328}
329
330/* Process the eventq of the specified channel immediately on this CPU
331 *
332 * Disable hardware generated interrupts, wait for any existing
333 * processing to finish, then directly poll (and ack ) the eventq.
334 * Finally reenable NAPI and interrupts.
335 *
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100336 * This is for use only during a loopback self-test. It must not
337 * deliver any packets up the stack as this can result in deadlock.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100338 */
339void efx_process_channel_now(struct efx_channel *channel)
340{
341 struct efx_nic *efx = channel->efx;
342
Ben Hutchings8313aca2010-09-10 06:41:57 +0000343 BUG_ON(channel->channel >= efx->n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100344 BUG_ON(!channel->enabled);
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100345 BUG_ON(!efx->loopback_selftest);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100346
347 /* Disable interrupts and wait for ISRs to complete */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000348 efx_nic_disable_interrupts(efx);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000349 if (efx->legacy_irq) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100350 synchronize_irq(efx->legacy_irq);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000351 efx->legacy_irq_enabled = false;
352 }
Ben Hutchings64ee3122008-09-01 12:47:38 +0100353 if (channel->irq)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100354 synchronize_irq(channel->irq);
355
356 /* Wait for any NAPI processing to complete */
357 napi_disable(&channel->napi_str);
358
359 /* Poll the channel */
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000360 efx_process_channel(channel, channel->eventq_mask + 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100361
362 /* Ack the eventq. This may cause an interrupt to be generated
363 * when they are reenabled */
364 efx_channel_processed(channel);
365
366 napi_enable(&channel->napi_str);
Ben Hutchings94dec6a2010-12-07 19:24:45 +0000367 if (efx->legacy_irq)
368 efx->legacy_irq_enabled = true;
Ben Hutchings152b6a62009-11-29 03:43:56 +0000369 efx_nic_enable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100370}
371
372/* Create event queue
373 * Event queue memory allocations are done only once. If the channel
374 * is reset, the memory buffer will be reused; this guards against
375 * errors during channel reset and also simplifies interrupt handling.
376 */
377static int efx_probe_eventq(struct efx_channel *channel)
378{
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000379 struct efx_nic *efx = channel->efx;
380 unsigned long entries;
381
Ben Hutchings86ee5302012-01-09 19:51:22 +0000382 netif_dbg(efx, probe, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000383 "chan %d create event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100384
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000385 /* Build an event queue with room for one event per tx and rx buffer,
386 * plus some extra for link state events and MCDI completions. */
387 entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
388 EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
389 channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
390
Ben Hutchings152b6a62009-11-29 03:43:56 +0000391 return efx_nic_probe_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100392}
393
394/* Prepare channel's event queue */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100395static void efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100396{
Ben Hutchings62776d02010-06-23 11:30:07 +0000397 netif_dbg(channel->efx, drv, channel->efx->net_dev,
398 "chan %d init event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100399
400 channel->eventq_read_ptr = 0;
401
Ben Hutchings152b6a62009-11-29 03:43:56 +0000402 efx_nic_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100403}
404
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000405/* Enable event queue processing and NAPI */
406static void efx_start_eventq(struct efx_channel *channel)
407{
408 netif_dbg(channel->efx, ifup, channel->efx->net_dev,
409 "chan %d start event queue\n", channel->channel);
410
411 /* The interrupt handler for this channel may set work_pending
412 * as soon as we enable it. Make sure it's cleared before
413 * then. Similarly, make sure it sees the enabled flag set.
414 */
415 channel->work_pending = false;
416 channel->enabled = true;
417 smp_wmb();
418
419 napi_enable(&channel->napi_str);
420 efx_nic_eventq_read_ack(channel);
421}
422
423/* Disable event queue processing and NAPI */
424static void efx_stop_eventq(struct efx_channel *channel)
425{
426 if (!channel->enabled)
427 return;
428
429 napi_disable(&channel->napi_str);
430 channel->enabled = false;
431}
432
Ben Hutchings8ceee662008-04-27 12:55:59 +0100433static void efx_fini_eventq(struct efx_channel *channel)
434{
Ben Hutchings62776d02010-06-23 11:30:07 +0000435 netif_dbg(channel->efx, drv, channel->efx->net_dev,
436 "chan %d fini event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437
Ben Hutchings152b6a62009-11-29 03:43:56 +0000438 efx_nic_fini_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100439}
440
441static void efx_remove_eventq(struct efx_channel *channel)
442{
Ben Hutchings62776d02010-06-23 11:30:07 +0000443 netif_dbg(channel->efx, drv, channel->efx->net_dev,
444 "chan %d remove event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100445
Ben Hutchings152b6a62009-11-29 03:43:56 +0000446 efx_nic_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100447}
448
449/**************************************************************************
450 *
451 * Channel handling
452 *
453 *************************************************************************/
454
Ben Hutchings7f967c02012-02-13 23:45:02 +0000455/* Allocate and initialise a channel structure. */
Ben Hutchings46426102010-09-10 06:42:33 +0000456static struct efx_channel *
457efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
458{
459 struct efx_channel *channel;
460 struct efx_rx_queue *rx_queue;
461 struct efx_tx_queue *tx_queue;
462 int j;
463
Ben Hutchings7f967c02012-02-13 23:45:02 +0000464 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
465 if (!channel)
466 return NULL;
Ben Hutchings46426102010-09-10 06:42:33 +0000467
Ben Hutchings7f967c02012-02-13 23:45:02 +0000468 channel->efx = efx;
469 channel->channel = i;
470 channel->type = &efx_default_channel_type;
Ben Hutchings46426102010-09-10 06:42:33 +0000471
Ben Hutchings7f967c02012-02-13 23:45:02 +0000472 for (j = 0; j < EFX_TXQ_TYPES; j++) {
473 tx_queue = &channel->tx_queue[j];
474 tx_queue->efx = efx;
475 tx_queue->queue = i * EFX_TXQ_TYPES + j;
476 tx_queue->channel = channel;
Ben Hutchings46426102010-09-10 06:42:33 +0000477 }
478
Ben Hutchings46426102010-09-10 06:42:33 +0000479 rx_queue = &channel->rx_queue;
480 rx_queue->efx = efx;
481 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
482 (unsigned long)rx_queue);
483
484 return channel;
485}
486
Ben Hutchings7f967c02012-02-13 23:45:02 +0000487/* Allocate and initialise a channel structure, copying parameters
488 * (but not resources) from an old channel structure.
489 */
490static struct efx_channel *
491efx_copy_channel(const struct efx_channel *old_channel)
492{
493 struct efx_channel *channel;
494 struct efx_rx_queue *rx_queue;
495 struct efx_tx_queue *tx_queue;
496 int j;
497
498 channel = kmalloc(sizeof(*channel), GFP_KERNEL);
499 if (!channel)
500 return NULL;
501
502 *channel = *old_channel;
503
504 channel->napi_dev = NULL;
505 memset(&channel->eventq, 0, sizeof(channel->eventq));
506
507 for (j = 0; j < EFX_TXQ_TYPES; j++) {
508 tx_queue = &channel->tx_queue[j];
509 if (tx_queue->channel)
510 tx_queue->channel = channel;
511 tx_queue->buffer = NULL;
512 memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
513 }
514
515 rx_queue = &channel->rx_queue;
516 rx_queue->buffer = NULL;
517 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
518 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
519 (unsigned long)rx_queue);
520
521 return channel;
522}
523
Ben Hutchings8ceee662008-04-27 12:55:59 +0100524static int efx_probe_channel(struct efx_channel *channel)
525{
526 struct efx_tx_queue *tx_queue;
527 struct efx_rx_queue *rx_queue;
528 int rc;
529
Ben Hutchings62776d02010-06-23 11:30:07 +0000530 netif_dbg(channel->efx, probe, channel->efx->net_dev,
531 "creating channel %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100532
Ben Hutchings7f967c02012-02-13 23:45:02 +0000533 rc = channel->type->pre_probe(channel);
534 if (rc)
535 goto fail;
536
Ben Hutchings8ceee662008-04-27 12:55:59 +0100537 rc = efx_probe_eventq(channel);
538 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000539 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100540
541 efx_for_each_channel_tx_queue(tx_queue, channel) {
542 rc = efx_probe_tx_queue(tx_queue);
543 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000544 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100545 }
546
547 efx_for_each_channel_rx_queue(rx_queue, channel) {
548 rc = efx_probe_rx_queue(rx_queue);
549 if (rc)
Ben Hutchings7f967c02012-02-13 23:45:02 +0000550 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100551 }
552
553 channel->n_rx_frm_trunc = 0;
554
555 return 0;
556
Ben Hutchings7f967c02012-02-13 23:45:02 +0000557fail:
558 efx_remove_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100559 return rc;
560}
561
Ben Hutchings7f967c02012-02-13 23:45:02 +0000562static void
563efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
564{
565 struct efx_nic *efx = channel->efx;
566 const char *type;
567 int number;
568
569 number = channel->channel;
570 if (efx->tx_channel_offset == 0) {
571 type = "";
572 } else if (channel->channel < efx->tx_channel_offset) {
573 type = "-rx";
574 } else {
575 type = "-tx";
576 number -= efx->tx_channel_offset;
577 }
578 snprintf(buf, len, "%s%s-%d", efx->name, type, number);
579}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100580
Ben Hutchings56536e92008-12-12 21:37:02 -0800581static void efx_set_channel_names(struct efx_nic *efx)
582{
583 struct efx_channel *channel;
Ben Hutchings56536e92008-12-12 21:37:02 -0800584
Ben Hutchings7f967c02012-02-13 23:45:02 +0000585 efx_for_each_channel(channel, efx)
586 channel->type->get_name(channel,
587 efx->channel_name[channel->channel],
588 sizeof(efx->channel_name[0]));
Ben Hutchings56536e92008-12-12 21:37:02 -0800589}
590
Ben Hutchings46426102010-09-10 06:42:33 +0000591static int efx_probe_channels(struct efx_nic *efx)
592{
593 struct efx_channel *channel;
594 int rc;
595
596 /* Restart special buffer allocation */
597 efx->next_buffer_table = 0;
598
Ben Hutchingsc92aaff2012-02-21 23:22:00 +0000599 /* Probe channels in reverse, so that any 'extra' channels
600 * use the start of the buffer table. This allows the traffic
601 * channels to be resized without moving them or wasting the
602 * entries before them.
603 */
604 efx_for_each_channel_rev(channel, efx) {
Ben Hutchings46426102010-09-10 06:42:33 +0000605 rc = efx_probe_channel(channel);
606 if (rc) {
607 netif_err(efx, probe, efx->net_dev,
608 "failed to create channel %d\n",
609 channel->channel);
610 goto fail;
611 }
612 }
613 efx_set_channel_names(efx);
614
615 return 0;
616
617fail:
618 efx_remove_channels(efx);
619 return rc;
620}
621
Ben Hutchings8ceee662008-04-27 12:55:59 +0100622/* Channels are shutdown and reinitialised whilst the NIC is running
623 * to propagate configuration changes (mtu, checksum offload), or
624 * to clear hardware error conditions
625 */
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000626static void efx_start_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627{
628 struct efx_tx_queue *tx_queue;
629 struct efx_rx_queue *rx_queue;
630 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100631
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100632 /* Calculate the rx buffer allocation parameters required to
633 * support the current MTU, including padding for header
634 * alignment and overruns.
635 */
636 efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
637 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
Ben Hutchings39c9cf02010-06-23 11:31:28 +0000638 efx->type->rx_buffer_hash_size +
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100639 efx->type->rx_buffer_padding);
Steve Hodgson62b330b2010-06-01 11:20:53 +0000640 efx->rx_buffer_order = get_order(efx->rx_buffer_len +
641 sizeof(struct efx_rx_page_state));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100642
Ben Hutchings14bf7182012-05-22 01:27:58 +0100643 /* We must keep at least one descriptor in a TX ring empty.
644 * We could avoid this when the queue size does not exactly
645 * match the hardware ring size, but it's not that important.
646 * Therefore we stop the queue when one more skb might fill
647 * the ring completely. We wake it when half way back to
648 * empty.
649 */
650 efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
651 efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
652
Ben Hutchings8ceee662008-04-27 12:55:59 +0100653 /* Initialise the channels */
654 efx_for_each_channel(channel, efx) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100655 efx_for_each_channel_tx_queue(tx_queue, channel)
656 efx_init_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100657
658 /* The rx buffer allocation strategy is MTU dependent */
659 efx_rx_strategy(channel);
660
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000661 efx_for_each_channel_rx_queue(rx_queue, channel) {
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100662 efx_init_rx_queue(rx_queue);
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000663 efx_nic_generate_fill_event(rx_queue);
664 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100665
666 WARN_ON(channel->rx_pkt != NULL);
667 efx_rx_strategy(channel);
668 }
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000669
670 if (netif_device_present(efx->net_dev))
671 netif_tx_wake_all_queues(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100672}
673
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000674static void efx_stop_datapath(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100675{
676 struct efx_channel *channel;
677 struct efx_tx_queue *tx_queue;
678 struct efx_rx_queue *rx_queue;
Stuart Hodgson3dca9d22012-03-30 13:04:51 +0100679 struct pci_dev *dev = efx->pci_dev;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100680 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100681
682 EFX_ASSERT_RESET_SERIALISED(efx);
683 BUG_ON(efx->port_enabled);
684
Stuart Hodgson3dca9d22012-03-30 13:04:51 +0100685 /* Only perform flush if dma is enabled */
686 if (dev->is_busmaster) {
687 rc = efx_nic_flush_queues(efx);
688
689 if (rc && EFX_WORKAROUND_7803(efx)) {
690 /* Schedule a reset to recover from the flush failure. The
691 * descriptor caches reference memory we're about to free,
692 * but falcon_reconfigure_mac_wrapper() won't reconnect
693 * the MACs because of the pending reset. */
694 netif_err(efx, drv, efx->net_dev,
695 "Resetting to recover from flush failure\n");
696 efx_schedule_reset(efx, RESET_TYPE_ALL);
697 } else if (rc) {
698 netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
699 } else {
700 netif_dbg(efx, drv, efx->net_dev,
701 "successfully flushed all queues\n");
702 }
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000703 }
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100704
Ben Hutchings8ceee662008-04-27 12:55:59 +0100705 efx_for_each_channel(channel, efx) {
Ben Hutchings9f2cb712012-02-08 00:11:20 +0000706 /* RX packet processing is pipelined, so wait for the
707 * NAPI handler to complete. At least event queue 0
708 * might be kept active by non-data events, so don't
709 * use napi_synchronize() but actually disable NAPI
710 * temporarily.
711 */
712 if (efx_channel_has_rx_queue(channel)) {
713 efx_stop_eventq(channel);
714 efx_start_eventq(channel);
715 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100716
717 efx_for_each_channel_rx_queue(rx_queue, channel)
718 efx_fini_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000719 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100720 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100721 }
722}
723
724static void efx_remove_channel(struct efx_channel *channel)
725{
726 struct efx_tx_queue *tx_queue;
727 struct efx_rx_queue *rx_queue;
728
Ben Hutchings62776d02010-06-23 11:30:07 +0000729 netif_dbg(channel->efx, drv, channel->efx->net_dev,
730 "destroy chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100731
732 efx_for_each_channel_rx_queue(rx_queue, channel)
733 efx_remove_rx_queue(rx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000734 efx_for_each_possible_channel_tx_queue(tx_queue, channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100735 efx_remove_tx_queue(tx_queue);
736 efx_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100737}
738
Ben Hutchings46426102010-09-10 06:42:33 +0000739static void efx_remove_channels(struct efx_nic *efx)
740{
741 struct efx_channel *channel;
742
743 efx_for_each_channel(channel, efx)
744 efx_remove_channel(channel);
745}
746
747int
748efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
749{
750 struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
751 u32 old_rxq_entries, old_txq_entries;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000752 unsigned i, next_buffer_table = 0;
Ben Hutchings8b7325b2012-07-27 20:46:41 +0100753 int rc;
754
755 rc = efx_check_disabled(efx);
756 if (rc)
757 return rc;
Ben Hutchings7f967c02012-02-13 23:45:02 +0000758
759 /* Not all channels should be reallocated. We must avoid
760 * reallocating their buffer table entries.
761 */
762 efx_for_each_channel(channel, efx) {
763 struct efx_rx_queue *rx_queue;
764 struct efx_tx_queue *tx_queue;
765
766 if (channel->type->copy)
767 continue;
768 next_buffer_table = max(next_buffer_table,
769 channel->eventq.index +
770 channel->eventq.entries);
771 efx_for_each_channel_rx_queue(rx_queue, channel)
772 next_buffer_table = max(next_buffer_table,
773 rx_queue->rxd.index +
774 rx_queue->rxd.entries);
775 efx_for_each_channel_tx_queue(tx_queue, channel)
776 next_buffer_table = max(next_buffer_table,
777 tx_queue->txd.index +
778 tx_queue->txd.entries);
779 }
Ben Hutchings46426102010-09-10 06:42:33 +0000780
781 efx_stop_all(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +0000782 efx_stop_interrupts(efx, true);
Ben Hutchings46426102010-09-10 06:42:33 +0000783
Ben Hutchings7f967c02012-02-13 23:45:02 +0000784 /* Clone channels (where possible) */
Ben Hutchings46426102010-09-10 06:42:33 +0000785 memset(other_channel, 0, sizeof(other_channel));
786 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000787 channel = efx->channel[i];
788 if (channel->type->copy)
789 channel = channel->type->copy(channel);
Ben Hutchings46426102010-09-10 06:42:33 +0000790 if (!channel) {
791 rc = -ENOMEM;
792 goto out;
793 }
794 other_channel[i] = channel;
795 }
796
797 /* Swap entry counts and channel pointers */
798 old_rxq_entries = efx->rxq_entries;
799 old_txq_entries = efx->txq_entries;
800 efx->rxq_entries = rxq_entries;
801 efx->txq_entries = txq_entries;
802 for (i = 0; i < efx->n_channels; i++) {
803 channel = efx->channel[i];
804 efx->channel[i] = other_channel[i];
805 other_channel[i] = channel;
806 }
807
Ben Hutchings7f967c02012-02-13 23:45:02 +0000808 /* Restart buffer table allocation */
809 efx->next_buffer_table = next_buffer_table;
Ben Hutchings46426102010-09-10 06:42:33 +0000810
Ben Hutchingse8f14992010-12-07 19:47:34 +0000811 for (i = 0; i < efx->n_channels; i++) {
Ben Hutchings7f967c02012-02-13 23:45:02 +0000812 channel = efx->channel[i];
813 if (!channel->type->copy)
814 continue;
815 rc = efx_probe_channel(channel);
816 if (rc)
817 goto rollback;
818 efx_init_napi_channel(efx->channel[i]);
Ben Hutchingse8f14992010-12-07 19:47:34 +0000819 }
Ben Hutchings46426102010-09-10 06:42:33 +0000820
Ben Hutchings7f967c02012-02-13 23:45:02 +0000821out:
822 /* Destroy unused channel structures */
823 for (i = 0; i < efx->n_channels; i++) {
824 channel = other_channel[i];
825 if (channel && channel->type->copy) {
826 efx_fini_napi_channel(channel);
827 efx_remove_channel(channel);
828 kfree(channel);
829 }
830 }
831
832 efx_start_interrupts(efx, true);
Ben Hutchings46426102010-09-10 06:42:33 +0000833 efx_start_all(efx);
834 return rc;
835
836rollback:
837 /* Swap back */
838 efx->rxq_entries = old_rxq_entries;
839 efx->txq_entries = old_txq_entries;
840 for (i = 0; i < efx->n_channels; i++) {
841 channel = efx->channel[i];
842 efx->channel[i] = other_channel[i];
843 other_channel[i] = channel;
844 }
845 goto out;
846}
847
Steve Hodgson90d683a2010-06-01 11:19:39 +0000848void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100849{
Steve Hodgson90d683a2010-06-01 11:19:39 +0000850 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851}
852
Ben Hutchings7f967c02012-02-13 23:45:02 +0000853static const struct efx_channel_type efx_default_channel_type = {
854 .pre_probe = efx_channel_dummy_op_int,
855 .get_name = efx_get_channel_name,
856 .copy = efx_copy_channel,
857 .keep_eventq = false,
858};
859
860int efx_channel_dummy_op_int(struct efx_channel *channel)
861{
862 return 0;
863}
864
Ben Hutchings8ceee662008-04-27 12:55:59 +0100865/**************************************************************************
866 *
867 * Port handling
868 *
869 **************************************************************************/
870
871/* This ensures that the kernel is kept informed (via
872 * netif_carrier_on/off) of the link status, and also maintains the
873 * link status's stop on the port's TX queue.
874 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000875void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100876{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000877 struct efx_link_state *link_state = &efx->link_state;
878
Ben Hutchings8ceee662008-04-27 12:55:59 +0100879 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
880 * that no events are triggered between unregister_netdev() and the
881 * driver unloading. A more general condition is that NETDEV_CHANGE
882 * can only be generated between NETDEV_UP and NETDEV_DOWN */
883 if (!netif_running(efx->net_dev))
884 return;
885
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000886 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100887 efx->n_link_state_changes++;
888
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000889 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100890 netif_carrier_on(efx->net_dev);
891 else
892 netif_carrier_off(efx->net_dev);
893 }
894
895 /* Status message for kernel log */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000896 if (link_state->up)
Ben Hutchings62776d02010-06-23 11:30:07 +0000897 netif_info(efx, link, efx->net_dev,
898 "link up at %uMbps %s-duplex (MTU %d)%s\n",
899 link_state->speed, link_state->fd ? "full" : "half",
900 efx->net_dev->mtu,
901 (efx->promiscuous ? " [PROMISC]" : ""));
Ben Hutchings2aa9ef12012-01-09 19:53:41 +0000902 else
Ben Hutchings62776d02010-06-23 11:30:07 +0000903 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100904}
905
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000906void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
907{
908 efx->link_advertising = advertising;
909 if (advertising) {
910 if (advertising & ADVERTISED_Pause)
911 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
912 else
913 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
914 if (advertising & ADVERTISED_Asym_Pause)
915 efx->wanted_fc ^= EFX_FC_TX;
916 }
917}
918
David S. Millerb56269462011-05-17 17:53:22 -0400919void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000920{
921 efx->wanted_fc = wanted_fc;
922 if (efx->link_advertising) {
923 if (wanted_fc & EFX_FC_RX)
924 efx->link_advertising |= (ADVERTISED_Pause |
925 ADVERTISED_Asym_Pause);
926 else
927 efx->link_advertising &= ~(ADVERTISED_Pause |
928 ADVERTISED_Asym_Pause);
929 if (wanted_fc & EFX_FC_TX)
930 efx->link_advertising ^= ADVERTISED_Asym_Pause;
931 }
932}
933
Ben Hutchings115122a2009-03-04 09:52:52 +0000934static void efx_fini_port(struct efx_nic *efx);
935
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000936/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
937 * the MAC appropriately. All other PHY configuration changes are pushed
938 * through phy_op->set_settings(), and pushed asynchronously to the MAC
939 * through efx_monitor().
940 *
941 * Callers must hold the mac_lock
942 */
943int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100944{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000945 enum efx_phy_mode phy_mode;
946 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100947
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000948 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100949
Ben Hutchings0fca8c92012-01-09 19:54:44 +0000950 /* Serialise the promiscuous flag with efx_set_rx_mode. */
Ben Hutchings73ba7b62012-01-09 19:47:08 +0000951 netif_addr_lock_bh(efx->net_dev);
952 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchingsa816f752008-09-01 12:49:12 +0100953
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000954 /* Disable PHY transmit in mac level loopbacks */
955 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800956 if (LOOPBACK_INTERNAL(efx))
957 efx->phy_mode |= PHY_MODE_TX_DISABLED;
958 else
959 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800960
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000961 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800962
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000963 if (rc)
964 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100965
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000966 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100967}
968
969/* Reinitialise the MAC to pick up new PHY settings, even if the port is
970 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000971int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100972{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000973 int rc;
974
Ben Hutchings8ceee662008-04-27 12:55:59 +0100975 EFX_ASSERT_RESET_SERIALISED(efx);
976
977 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000978 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100979 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000980
981 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100982}
983
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000984/* Asynchronous work item for changing MAC promiscuity and multicast
985 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
986 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800987static void efx_mac_work(struct work_struct *data)
988{
989 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
990
991 mutex_lock(&efx->mac_lock);
Ben Hutchings30b81cd2011-09-13 19:47:48 +0100992 if (efx->port_enabled)
Ben Hutchings710b2082011-09-03 00:15:00 +0100993 efx->type->reconfigure_mac(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800994 mutex_unlock(&efx->mac_lock);
995}
996
Ben Hutchings8ceee662008-04-27 12:55:59 +0100997static int efx_probe_port(struct efx_nic *efx)
998{
999 int rc;
1000
Ben Hutchings62776d02010-06-23 11:30:07 +00001001 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001002
Steve Hodgsonff3b00a2009-12-23 13:46:36 +00001003 if (phy_flash_cfg)
1004 efx->phy_mode = PHY_MODE_SPECIAL;
1005
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001006 /* Connect up MAC/PHY operations table */
1007 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001008 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +00001009 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001010
Ben Hutchingse332bcb2011-12-20 01:22:51 +00001011 /* Initialise MAC address to permanent address */
1012 memcpy(efx->net_dev->dev_addr, efx->net_dev->perm_addr, ETH_ALEN);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001013
1014 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001015}
1016
1017static int efx_init_port(struct efx_nic *efx)
1018{
1019 int rc;
1020
Ben Hutchings62776d02010-06-23 11:30:07 +00001021 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001022
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001023 mutex_lock(&efx->mac_lock);
1024
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001025 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001026 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001027 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001028
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001029 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001030
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001031 /* Reconfigure the MAC before creating dma queues (required for
1032 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
Ben Hutchings710b2082011-09-03 00:15:00 +01001033 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001034
1035 /* Ensure the PHY advertises the correct flow control settings */
1036 rc = efx->phy_op->reconfigure(efx);
1037 if (rc)
1038 goto fail2;
1039
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001040 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001041 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001042
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001043fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001044 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +00001045fail1:
1046 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001047 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001048}
1049
Ben Hutchings8ceee662008-04-27 12:55:59 +01001050static void efx_start_port(struct efx_nic *efx)
1051{
Ben Hutchings62776d02010-06-23 11:30:07 +00001052 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001053 BUG_ON(efx->port_enabled);
1054
1055 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001056 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001057
1058 /* efx_mac_work() might have been scheduled after efx_stop_port(),
1059 * and then cancelled by efx_flush_all() */
Ben Hutchings710b2082011-09-03 00:15:00 +01001060 efx->type->reconfigure_mac(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001061
Ben Hutchings8ceee662008-04-27 12:55:59 +01001062 mutex_unlock(&efx->mac_lock);
1063}
1064
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00001065/* Prevent efx_mac_work() and efx_monitor() from working */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001066static void efx_stop_port(struct efx_nic *efx)
1067{
Ben Hutchings62776d02010-06-23 11:30:07 +00001068 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001069
1070 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001071 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001072 mutex_unlock(&efx->mac_lock);
1073
1074 /* Serialise against efx_set_multicast_list() */
Ben Hutchings73ba7b62012-01-09 19:47:08 +00001075 netif_addr_lock_bh(efx->net_dev);
1076 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001077}
1078
1079static void efx_fini_port(struct efx_nic *efx)
1080{
Ben Hutchings62776d02010-06-23 11:30:07 +00001081 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001082
1083 if (!efx->port_initialized)
1084 return;
1085
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001086 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001087 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001088
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001089 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090 efx_link_status_changed(efx);
1091}
1092
1093static void efx_remove_port(struct efx_nic *efx)
1094{
Ben Hutchings62776d02010-06-23 11:30:07 +00001095 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001096
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001097 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001098}
1099
1100/**************************************************************************
1101 *
1102 * NIC handling
1103 *
1104 **************************************************************************/
1105
1106/* This configures the PCI device to enable I/O and DMA. */
1107static int efx_init_io(struct efx_nic *efx)
1108{
1109 struct pci_dev *pci_dev = efx->pci_dev;
1110 dma_addr_t dma_mask = efx->type->max_dma_mask;
1111 int rc;
1112
Ben Hutchings62776d02010-06-23 11:30:07 +00001113 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001114
1115 rc = pci_enable_device(pci_dev);
1116 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001117 netif_err(efx, probe, efx->net_dev,
1118 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001119 goto fail1;
1120 }
1121
1122 pci_set_master(pci_dev);
1123
1124 /* Set the PCI DMA mask. Try all possibilities from our
1125 * genuine mask down to 32 bits, because some architectures
1126 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1127 * masks event though they reject 46 bit masks.
1128 */
1129 while (dma_mask > 0x7fffffffUL) {
Ben Hutchings0e33d872012-05-17 17:46:55 +01001130 if (dma_supported(&pci_dev->dev, dma_mask)) {
1131 rc = dma_set_mask(&pci_dev->dev, dma_mask);
Ben Hutchingse9e01842012-01-05 18:50:29 +00001132 if (rc == 0)
1133 break;
1134 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001135 dma_mask >>= 1;
1136 }
1137 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001138 netif_err(efx, probe, efx->net_dev,
1139 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001140 goto fail2;
1141 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001142 netif_dbg(efx, probe, efx->net_dev,
1143 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings0e33d872012-05-17 17:46:55 +01001144 rc = dma_set_coherent_mask(&pci_dev->dev, dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001145 if (rc) {
Ben Hutchings0e33d872012-05-17 17:46:55 +01001146 /* dma_set_coherent_mask() is not *allowed* to
1147 * fail with a mask that dma_set_mask() accepted,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001148 * but just in case...
1149 */
Ben Hutchings62776d02010-06-23 11:30:07 +00001150 netif_err(efx, probe, efx->net_dev,
1151 "failed to set consistent DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001152 goto fail2;
1153 }
1154
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001155 efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
1156 rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001157 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001158 netif_err(efx, probe, efx->net_dev,
1159 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001160 rc = -EIO;
1161 goto fail3;
1162 }
David S. Miller8decf862011-09-22 03:23:13 -04001163 efx->membase = ioremap_nocache(efx->membase_phys,
1164 efx->type->mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001165 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001166 netif_err(efx, probe, efx->net_dev,
1167 "could not map memory BAR at %llx+%x\n",
1168 (unsigned long long)efx->membase_phys,
1169 efx->type->mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001170 rc = -ENOMEM;
1171 goto fail4;
1172 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001173 netif_dbg(efx, probe, efx->net_dev,
1174 "memory BAR at %llx+%x (virtual %p)\n",
1175 (unsigned long long)efx->membase_phys,
1176 efx->type->mem_map_size, efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001177
1178 return 0;
1179
1180 fail4:
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001181 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001182 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001183 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001184 fail2:
1185 pci_disable_device(efx->pci_dev);
1186 fail1:
1187 return rc;
1188}
1189
1190static void efx_fini_io(struct efx_nic *efx)
1191{
Ben Hutchings62776d02010-06-23 11:30:07 +00001192 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001193
1194 if (efx->membase) {
1195 iounmap(efx->membase);
1196 efx->membase = NULL;
1197 }
1198
1199 if (efx->membase_phys) {
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001200 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001201 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001202 }
1203
1204 pci_disable_device(efx->pci_dev);
1205}
1206
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001207static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
Ben Hutchings46123d02008-09-01 12:47:33 +01001208{
Ben Hutchingscdb08f82011-12-20 01:08:05 +00001209 cpumask_var_t thread_mask;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001210 unsigned int count;
Ben Hutchings46123d02008-09-01 12:47:33 +01001211 int cpu;
1212
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001213 if (rss_cpus) {
1214 count = rss_cpus;
1215 } else {
1216 if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1217 netif_warn(efx, probe, efx->net_dev,
1218 "RSS disabled due to allocation failure\n");
1219 return 1;
Ben Hutchings46123d02008-09-01 12:47:33 +01001220 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001221
1222 count = 0;
1223 for_each_online_cpu(cpu) {
1224 if (!cpumask_test_cpu(cpu, thread_mask)) {
1225 ++count;
1226 cpumask_or(thread_mask, thread_mask,
1227 topology_thread_cpumask(cpu));
1228 }
1229 }
1230
1231 free_cpumask_var(thread_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001232 }
1233
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001234 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1235 * table entries that are inaccessible to VFs
1236 */
1237 if (efx_sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
1238 count > efx_vf_size(efx)) {
1239 netif_warn(efx, probe, efx->net_dev,
1240 "Reducing number of RSS channels from %u to %u for "
1241 "VF support. Increase vf-msix-limit to use more "
1242 "channels on the PF.\n",
1243 count, efx_vf_size(efx));
1244 count = efx_vf_size(efx);
1245 }
1246
Ben Hutchings46123d02008-09-01 12:47:33 +01001247 return count;
1248}
1249
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001250static int
1251efx_init_rx_cpu_rmap(struct efx_nic *efx, struct msix_entry *xentries)
1252{
1253#ifdef CONFIG_RFS_ACCEL
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001254 unsigned int i;
1255 int rc;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001256
1257 efx->net_dev->rx_cpu_rmap = alloc_irq_cpu_rmap(efx->n_rx_channels);
1258 if (!efx->net_dev->rx_cpu_rmap)
1259 return -ENOMEM;
1260 for (i = 0; i < efx->n_rx_channels; i++) {
1261 rc = irq_cpu_rmap_add(efx->net_dev->rx_cpu_rmap,
1262 xentries[i].vector);
1263 if (rc) {
1264 free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
1265 efx->net_dev->rx_cpu_rmap = NULL;
1266 return rc;
1267 }
1268 }
1269#endif
1270 return 0;
1271}
1272
Ben Hutchings46123d02008-09-01 12:47:33 +01001273/* Probe the number and type of interrupts we are able to obtain, and
1274 * the resulting numbers of channels and RX queues.
1275 */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001276static int efx_probe_interrupts(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001277{
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001278 unsigned int max_channels =
1279 min(efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001280 unsigned int extra_channels = 0;
1281 unsigned int i, j;
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001282 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001283
Ben Hutchings7f967c02012-02-13 23:45:02 +00001284 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
1285 if (efx->extra_channel_type[i])
1286 ++extra_channels;
1287
Ben Hutchings8ceee662008-04-27 12:55:59 +01001288 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001289 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001290 unsigned int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001291
Ben Hutchingsa9a525062012-02-14 20:15:57 +00001292 n_channels = efx_wanted_parallelism(efx);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001293 if (separate_tx_channels)
1294 n_channels *= 2;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001295 n_channels += extra_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001296 n_channels = min(n_channels, max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001297
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001298 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001299 xentries[i].entry = i;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001300 rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001301 if (rc > 0) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001302 netif_err(efx, drv, efx->net_dev,
1303 "WARNING: Insufficient MSI-X vectors"
Ben Hutchingsa16e5b22012-02-14 00:40:12 +00001304 " available (%d < %u).\n", rc, n_channels);
Ben Hutchings62776d02010-06-23 11:30:07 +00001305 netif_err(efx, drv, efx->net_dev,
1306 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001307 EFX_BUG_ON_PARANOID(rc >= n_channels);
1308 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001309 rc = pci_enable_msix(efx->pci_dev, xentries,
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001310 n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001311 }
1312
1313 if (rc == 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001314 efx->n_channels = n_channels;
Ben Hutchings7f967c02012-02-13 23:45:02 +00001315 if (n_channels > extra_channels)
1316 n_channels -= extra_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001317 if (separate_tx_channels) {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001318 efx->n_tx_channels = max(n_channels / 2, 1U);
1319 efx->n_rx_channels = max(n_channels -
1320 efx->n_tx_channels,
1321 1U);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001322 } else {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001323 efx->n_tx_channels = n_channels;
1324 efx->n_rx_channels = n_channels;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001325 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001326 rc = efx_init_rx_cpu_rmap(efx, xentries);
1327 if (rc) {
1328 pci_disable_msix(efx->pci_dev);
1329 return rc;
1330 }
Ben Hutchings7f967c02012-02-13 23:45:02 +00001331 for (i = 0; i < efx->n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001332 efx_get_channel(efx, i)->irq =
1333 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001334 } else {
1335 /* Fall back to single channel MSI */
1336 efx->interrupt_mode = EFX_INT_MODE_MSI;
Ben Hutchings62776d02010-06-23 11:30:07 +00001337 netif_err(efx, drv, efx->net_dev,
1338 "could not enable MSI-X\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001339 }
1340 }
1341
1342 /* Try single interrupt MSI */
1343 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001344 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001345 efx->n_rx_channels = 1;
1346 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001347 rc = pci_enable_msi(efx->pci_dev);
1348 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001349 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001350 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001351 netif_err(efx, drv, efx->net_dev,
1352 "could not enable MSI\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001353 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1354 }
1355 }
1356
1357 /* Assume legacy interrupts */
1358 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Neil Turton28b581a2008-12-12 21:41:06 -08001359 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001360 efx->n_rx_channels = 1;
1361 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001362 efx->legacy_irq = efx->pci_dev->irq;
1363 }
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001364
Ben Hutchings7f967c02012-02-13 23:45:02 +00001365 /* Assign extra channels if possible */
1366 j = efx->n_channels;
1367 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
1368 if (!efx->extra_channel_type[i])
1369 continue;
1370 if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
1371 efx->n_channels <= extra_channels) {
1372 efx->extra_channel_type[i]->handle_no_channel(efx);
1373 } else {
1374 --j;
1375 efx_get_channel(efx, j)->type =
1376 efx->extra_channel_type[i];
1377 }
1378 }
1379
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001380 /* RSS might be usable on VFs even if it is disabled on the PF */
Ben Hutchings3132d282012-05-05 02:31:23 +01001381 efx->rss_spread = ((efx->n_rx_channels > 1 || !efx_sriov_wanted(efx)) ?
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001382 efx->n_rx_channels : efx_vf_size(efx));
1383
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001384 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001385}
1386
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001387/* Enable interrupts, then probe and start the event queues */
Ben Hutchings7f967c02012-02-13 23:45:02 +00001388static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001389{
1390 struct efx_channel *channel;
1391
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001392 BUG_ON(efx->state == STATE_DISABLED);
1393
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001394 if (efx->legacy_irq)
1395 efx->legacy_irq_enabled = true;
1396 efx_nic_enable_interrupts(efx);
1397
1398 efx_for_each_channel(channel, efx) {
Ben Hutchings7f967c02012-02-13 23:45:02 +00001399 if (!channel->type->keep_eventq || !may_keep_eventq)
1400 efx_init_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001401 efx_start_eventq(channel);
1402 }
1403
1404 efx_mcdi_mode_event(efx);
1405}
1406
Ben Hutchings7f967c02012-02-13 23:45:02 +00001407static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq)
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001408{
1409 struct efx_channel *channel;
1410
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001411 if (efx->state == STATE_DISABLED)
1412 return;
1413
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001414 efx_mcdi_mode_poll(efx);
1415
1416 efx_nic_disable_interrupts(efx);
1417 if (efx->legacy_irq) {
1418 synchronize_irq(efx->legacy_irq);
1419 efx->legacy_irq_enabled = false;
1420 }
1421
1422 efx_for_each_channel(channel, efx) {
1423 if (channel->irq)
1424 synchronize_irq(channel->irq);
1425
1426 efx_stop_eventq(channel);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001427 if (!channel->type->keep_eventq || !may_keep_eventq)
1428 efx_fini_eventq(channel);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001429 }
1430}
1431
Ben Hutchings8ceee662008-04-27 12:55:59 +01001432static void efx_remove_interrupts(struct efx_nic *efx)
1433{
1434 struct efx_channel *channel;
1435
1436 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001437 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001438 channel->irq = 0;
1439 pci_disable_msi(efx->pci_dev);
1440 pci_disable_msix(efx->pci_dev);
1441
1442 /* Remove legacy interrupt */
1443 efx->legacy_irq = 0;
1444}
1445
Ben Hutchings8831da72008-09-01 12:47:48 +01001446static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001447{
Ben Hutchings602a5322011-05-16 17:32:39 +01001448 struct efx_channel *channel;
1449 struct efx_tx_queue *tx_queue;
1450
Ben Hutchings97653432011-01-12 18:26:56 +00001451 efx->tx_channel_offset =
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001452 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings602a5322011-05-16 17:32:39 +01001453
1454 /* We need to adjust the TX queue numbers if we have separate
1455 * RX-only and TX-only channels.
1456 */
1457 efx_for_each_channel(channel, efx) {
1458 efx_for_each_channel_tx_queue(tx_queue, channel)
1459 tx_queue->queue -= (efx->tx_channel_offset *
1460 EFX_TXQ_TYPES);
1461 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001462}
1463
1464static int efx_probe_nic(struct efx_nic *efx)
1465{
Ben Hutchings765c9f42010-06-30 05:06:28 +00001466 size_t i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001467 int rc;
1468
Ben Hutchings62776d02010-06-23 11:30:07 +00001469 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001470
1471 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001472 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001473 if (rc)
1474 return rc;
1475
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001476 /* Determine the number of channels and queues by trying to hook
Ben Hutchings8ceee662008-04-27 12:55:59 +01001477 * in MSI-X interrupts. */
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001478 rc = efx_probe_interrupts(efx);
1479 if (rc)
1480 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001481
Ben Hutchings28e47c42012-02-15 01:58:49 +00001482 efx->type->dimension_resources(efx);
1483
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001484 if (efx->n_channels > 1)
1485 get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001486 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
Ben Hutchings278bc422011-12-15 13:56:49 +00001487 efx->rx_indir_table[i] =
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001488 ethtool_rxfh_indir_default(i, efx->rss_spread);
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001489
Ben Hutchings8831da72008-09-01 12:47:48 +01001490 efx_set_channels(efx);
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001491 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1492 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001493
1494 /* Initialise the interrupt moderation settings */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001495 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1496 true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001497
1498 return 0;
Ben Hutchings64d8ad62011-01-05 00:50:41 +00001499
1500fail:
1501 efx->type->remove(efx);
1502 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001503}
1504
1505static void efx_remove_nic(struct efx_nic *efx)
1506{
Ben Hutchings62776d02010-06-23 11:30:07 +00001507 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001508
1509 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001510 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001511}
1512
1513/**************************************************************************
1514 *
1515 * NIC startup/shutdown
1516 *
1517 *************************************************************************/
1518
1519static int efx_probe_all(struct efx_nic *efx)
1520{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001521 int rc;
1522
Ben Hutchings8ceee662008-04-27 12:55:59 +01001523 rc = efx_probe_nic(efx);
1524 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001525 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001526 goto fail1;
1527 }
1528
Ben Hutchings8ceee662008-04-27 12:55:59 +01001529 rc = efx_probe_port(efx);
1530 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001531 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001532 goto fail2;
1533 }
1534
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00001535 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
1536 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
1537 rc = -EINVAL;
1538 goto fail3;
1539 }
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001540 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001541
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001542 rc = efx_probe_filters(efx);
1543 if (rc) {
1544 netif_err(efx, probe, efx->net_dev,
1545 "failed to create filter tables\n");
Ben Hutchings7f967c02012-02-13 23:45:02 +00001546 goto fail3;
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001547 }
1548
Ben Hutchings7f967c02012-02-13 23:45:02 +00001549 rc = efx_probe_channels(efx);
1550 if (rc)
1551 goto fail4;
1552
Ben Hutchings8ceee662008-04-27 12:55:59 +01001553 return 0;
1554
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001555 fail4:
Ben Hutchings7f967c02012-02-13 23:45:02 +00001556 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001557 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001558 efx_remove_port(efx);
1559 fail2:
1560 efx_remove_nic(efx);
1561 fail1:
1562 return rc;
1563}
1564
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001565/* If the interface is supposed to be running but is not, start
1566 * the hardware and software data path, regular activity for the port
1567 * (MAC statistics, link polling, etc.) and schedule the port to be
1568 * reconfigured. Interrupts must already be enabled. This function
1569 * is safe to call multiple times, so long as the NIC is not disabled.
1570 * Requires the RTNL lock.
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001571 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001572static void efx_start_all(struct efx_nic *efx)
1573{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001574 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001575 BUG_ON(efx->state == STATE_DISABLED);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001576
1577 /* Check that it is appropriate to restart the interface. All
1578 * of these flags are safe to read under just the rtnl lock */
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001579 if (efx->port_enabled || !netif_running(efx->net_dev))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001580 return;
1581
Ben Hutchings8ceee662008-04-27 12:55:59 +01001582 efx_start_port(efx);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001583 efx_start_datapath(efx);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001584
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001585 /* Start the hardware monitor if there is one. Otherwise (we're link
1586 * event driven), we have to poll the PHY because after an event queue
1587 * flush, we could have a missed a link state change */
1588 if (efx->type->monitor != NULL) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001589 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1590 efx_monitor_interval);
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001591 } else {
1592 mutex_lock(&efx->mac_lock);
1593 if (efx->phy_op->poll(efx))
1594 efx_link_status_changed(efx);
1595 mutex_unlock(&efx->mac_lock);
1596 }
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001597
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001598 efx->type->start_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001599}
1600
1601/* Flush all delayed work. Should only be called when no more delayed work
1602 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1603 * since we're holding the rtnl_lock at this point. */
1604static void efx_flush_all(struct efx_nic *efx)
1605{
Ben Hutchingsdd407812012-02-28 23:40:21 +00001606 /* Make sure the hardware monitor and event self-test are stopped */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001607 cancel_delayed_work_sync(&efx->monitor_work);
Ben Hutchingsdd407812012-02-28 23:40:21 +00001608 efx_selftest_async_cancel(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001609 /* Stop scheduled port reconfigurations */
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001610 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001611}
1612
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001613/* Quiesce the hardware and software data path, and regular activity
1614 * for the port without bringing the link down. Safe to call multiple
1615 * times with the NIC in almost any state, but interrupts should be
1616 * enabled. Requires the RTNL lock.
1617 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001618static void efx_stop_all(struct efx_nic *efx)
1619{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001620 EFX_ASSERT_RESET_SERIALISED(efx);
1621
1622 /* port_enabled can be read safely under the rtnl lock */
1623 if (!efx->port_enabled)
1624 return;
1625
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001626 efx->type->stop_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001627 efx_stop_port(efx);
1628
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00001629 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001630 efx_flush_all(efx);
1631
Ben Hutchings8ceee662008-04-27 12:55:59 +01001632 /* Stop the kernel transmit interface late, so the watchdog
1633 * timer isn't ticking over the flush */
Ben Hutchings9f2cb712012-02-08 00:11:20 +00001634 netif_tx_disable(efx->net_dev);
1635
1636 efx_stop_datapath(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001637}
1638
1639static void efx_remove_all(struct efx_nic *efx)
1640{
Ben Hutchings46426102010-09-10 06:42:33 +00001641 efx_remove_channels(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00001642 efx_remove_filters(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001643 efx_remove_port(efx);
1644 efx_remove_nic(efx);
1645}
1646
Ben Hutchings8ceee662008-04-27 12:55:59 +01001647/**************************************************************************
1648 *
1649 * Interrupt moderation
1650 *
1651 **************************************************************************/
1652
Ben Hutchingscc180b62011-12-08 19:51:47 +00001653static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001654{
Ben Hutchingsb548f972011-09-05 07:41:44 +00001655 if (usecs == 0)
1656 return 0;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001657 if (usecs * 1000 < quantum_ns)
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001658 return 1; /* never round down to 0 */
Ben Hutchingscc180b62011-12-08 19:51:47 +00001659 return usecs * 1000 / quantum_ns;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001660}
1661
Ben Hutchings8ceee662008-04-27 12:55:59 +01001662/* Set interrupt moderation parameters */
Ben Hutchings9e393b32011-09-05 07:43:04 +00001663int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
1664 unsigned int rx_usecs, bool rx_adaptive,
1665 bool rx_may_override_tx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001666{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001667 struct efx_channel *channel;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001668 unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max *
1669 efx->timer_quantum_ns,
1670 1000);
1671 unsigned int tx_ticks;
1672 unsigned int rx_ticks;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001673
1674 EFX_ASSERT_RESET_SERIALISED(efx);
1675
Ben Hutchingscc180b62011-12-08 19:51:47 +00001676 if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max)
Ben Hutchings9e393b32011-09-05 07:43:04 +00001677 return -EINVAL;
1678
Ben Hutchingscc180b62011-12-08 19:51:47 +00001679 tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns);
1680 rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns);
1681
Ben Hutchings9e393b32011-09-05 07:43:04 +00001682 if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 &&
1683 !rx_may_override_tx) {
1684 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
1685 "RX and TX IRQ moderation must be equal\n");
1686 return -EINVAL;
1687 }
1688
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001689 efx->irq_rx_adaptive = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001690 efx->irq_rx_moderation = rx_ticks;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001691 efx_for_each_channel(channel, efx) {
Ben Hutchings525da902011-02-07 23:04:38 +00001692 if (efx_channel_has_rx_queue(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001693 channel->irq_moderation = rx_ticks;
Ben Hutchings525da902011-02-07 23:04:38 +00001694 else if (efx_channel_has_tx_queues(channel))
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001695 channel->irq_moderation = tx_ticks;
1696 }
Ben Hutchings9e393b32011-09-05 07:43:04 +00001697
1698 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001699}
1700
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001701void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
1702 unsigned int *rx_usecs, bool *rx_adaptive)
1703{
Ben Hutchingscc180b62011-12-08 19:51:47 +00001704 /* We must round up when converting ticks to microseconds
1705 * because we round down when converting the other way.
1706 */
1707
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001708 *rx_adaptive = efx->irq_rx_adaptive;
Ben Hutchingscc180b62011-12-08 19:51:47 +00001709 *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation *
1710 efx->timer_quantum_ns,
1711 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001712
1713 /* If channels are shared between RX and TX, so is IRQ
1714 * moderation. Otherwise, IRQ moderation is the same for all
1715 * TX channels and is not adaptive.
1716 */
1717 if (efx->tx_channel_offset == 0)
1718 *tx_usecs = *rx_usecs;
1719 else
Ben Hutchingscc180b62011-12-08 19:51:47 +00001720 *tx_usecs = DIV_ROUND_UP(
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001721 efx->channel[efx->tx_channel_offset]->irq_moderation *
Ben Hutchingscc180b62011-12-08 19:51:47 +00001722 efx->timer_quantum_ns,
1723 1000);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +00001724}
1725
Ben Hutchings8ceee662008-04-27 12:55:59 +01001726/**************************************************************************
1727 *
1728 * Hardware monitor
1729 *
1730 **************************************************************************/
1731
Ben Hutchingse254c272010-09-20 08:44:10 +00001732/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001733static void efx_monitor(struct work_struct *data)
1734{
1735 struct efx_nic *efx = container_of(data, struct efx_nic,
1736 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001737
Ben Hutchings62776d02010-06-23 11:30:07 +00001738 netif_vdbg(efx, timer, efx->net_dev,
1739 "hardware monitor executing on CPU %d\n",
1740 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001741 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001742
Ben Hutchings8ceee662008-04-27 12:55:59 +01001743 /* If the mac_lock is already held then it is likely a port
1744 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00001745 * most of the work of monitor() anyway. */
1746 if (mutex_trylock(&efx->mac_lock)) {
1747 if (efx->port_enabled)
1748 efx->type->monitor(efx);
1749 mutex_unlock(&efx->mac_lock);
1750 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001751
Ben Hutchings8ceee662008-04-27 12:55:59 +01001752 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1753 efx_monitor_interval);
1754}
1755
1756/**************************************************************************
1757 *
1758 * ioctls
1759 *
1760 *************************************************************************/
1761
1762/* Net device ioctl
1763 * Context: process, rtnl_lock() held.
1764 */
1765static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1766{
Ben Hutchings767e4682008-09-01 12:43:14 +01001767 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00001768 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001769
Ben Hutchings68e7f452009-04-29 08:05:08 +00001770 /* Convert phy_id from older PRTAD/DEVAD format */
1771 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
1772 (data->phy_id & 0xfc00) == 0x0400)
1773 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
1774
1775 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001776}
1777
1778/**************************************************************************
1779 *
1780 * NAPI interface
1781 *
1782 **************************************************************************/
1783
Ben Hutchings7f967c02012-02-13 23:45:02 +00001784static void efx_init_napi_channel(struct efx_channel *channel)
1785{
1786 struct efx_nic *efx = channel->efx;
1787
1788 channel->napi_dev = efx->net_dev;
1789 netif_napi_add(channel->napi_dev, &channel->napi_str,
1790 efx_poll, napi_weight);
1791}
1792
Ben Hutchingse8f14992010-12-07 19:47:34 +00001793static void efx_init_napi(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001794{
1795 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001796
Ben Hutchings7f967c02012-02-13 23:45:02 +00001797 efx_for_each_channel(channel, efx)
1798 efx_init_napi_channel(channel);
Ben Hutchingse8f14992010-12-07 19:47:34 +00001799}
1800
1801static void efx_fini_napi_channel(struct efx_channel *channel)
1802{
1803 if (channel->napi_dev)
1804 netif_napi_del(&channel->napi_str);
1805 channel->napi_dev = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001806}
1807
1808static void efx_fini_napi(struct efx_nic *efx)
1809{
1810 struct efx_channel *channel;
1811
Ben Hutchingse8f14992010-12-07 19:47:34 +00001812 efx_for_each_channel(channel, efx)
1813 efx_fini_napi_channel(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001814}
1815
1816/**************************************************************************
1817 *
1818 * Kernel netpoll interface
1819 *
1820 *************************************************************************/
1821
1822#ifdef CONFIG_NET_POLL_CONTROLLER
1823
1824/* Although in the common case interrupts will be disabled, this is not
1825 * guaranteed. However, all our work happens inside the NAPI callback,
1826 * so no locking is required.
1827 */
1828static void efx_netpoll(struct net_device *net_dev)
1829{
Ben Hutchings767e4682008-09-01 12:43:14 +01001830 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001831 struct efx_channel *channel;
1832
Ben Hutchings64ee3122008-09-01 12:47:38 +01001833 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001834 efx_schedule_channel(channel);
1835}
1836
1837#endif
1838
1839/**************************************************************************
1840 *
1841 * Kernel net device interface
1842 *
1843 *************************************************************************/
1844
1845/* Context: process, rtnl_lock() held. */
1846static int efx_net_open(struct net_device *net_dev)
1847{
Ben Hutchings767e4682008-09-01 12:43:14 +01001848 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001849 int rc;
1850
Ben Hutchings62776d02010-06-23 11:30:07 +00001851 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
1852 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001853
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001854 rc = efx_check_disabled(efx);
1855 if (rc)
1856 return rc;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001857 if (efx->phy_mode & PHY_MODE_SPECIAL)
1858 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001859 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
1860 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001861
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001862 /* Notify the kernel of the link state polled during driver load,
1863 * before the monitor starts running */
1864 efx_link_status_changed(efx);
1865
Ben Hutchings8ceee662008-04-27 12:55:59 +01001866 efx_start_all(efx);
Ben Hutchingsdd407812012-02-28 23:40:21 +00001867 efx_selftest_async_start(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001868 return 0;
1869}
1870
1871/* Context: process, rtnl_lock() held.
1872 * Note that the kernel will ignore our return code; this method
1873 * should really be a void.
1874 */
1875static int efx_net_stop(struct net_device *net_dev)
1876{
Ben Hutchings767e4682008-09-01 12:43:14 +01001877 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001878
Ben Hutchings62776d02010-06-23 11:30:07 +00001879 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
1880 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001881
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001882 /* Stop the device and flush all the channels */
1883 efx_stop_all(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001884
1885 return 0;
1886}
1887
Ben Hutchings5b9e2072008-05-16 21:18:14 +01001888/* Context: process, dev_base_lock or RTNL held, non-blocking. */
Ben Hutchings2aa9ef12012-01-09 19:53:41 +00001889static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev,
1890 struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001891{
Ben Hutchings767e4682008-09-01 12:43:14 +01001892 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001893 struct efx_mac_stats *mac_stats = &efx->mac_stats;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001894
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001895 spin_lock_bh(&efx->stats_lock);
Ben Hutchings1cb34522011-09-02 23:23:00 +01001896
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001897 efx->type->update_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001898
1899 stats->rx_packets = mac_stats->rx_packets;
1900 stats->tx_packets = mac_stats->tx_packets;
1901 stats->rx_bytes = mac_stats->rx_bytes;
1902 stats->tx_bytes = mac_stats->tx_bytes;
Ben Hutchings80485d32010-09-10 06:41:06 +00001903 stats->rx_dropped = efx->n_rx_nodesc_drop_cnt;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001904 stats->multicast = mac_stats->rx_multicast;
1905 stats->collisions = mac_stats->tx_collision;
1906 stats->rx_length_errors = (mac_stats->rx_gtjumbo +
1907 mac_stats->rx_length_error);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001908 stats->rx_crc_errors = mac_stats->rx_bad;
1909 stats->rx_frame_errors = mac_stats->rx_align_error;
1910 stats->rx_fifo_errors = mac_stats->rx_overflow;
1911 stats->rx_missed_errors = mac_stats->rx_missed;
1912 stats->tx_window_errors = mac_stats->tx_late_collision;
1913
1914 stats->rx_errors = (stats->rx_length_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001915 stats->rx_crc_errors +
1916 stats->rx_frame_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001917 mac_stats->rx_symbol_error);
1918 stats->tx_errors = (stats->tx_window_errors +
1919 mac_stats->tx_bad);
1920
Ben Hutchings1cb34522011-09-02 23:23:00 +01001921 spin_unlock_bh(&efx->stats_lock);
1922
Ben Hutchings8ceee662008-04-27 12:55:59 +01001923 return stats;
1924}
1925
1926/* Context: netif_tx_lock held, BHs disabled. */
1927static void efx_watchdog(struct net_device *net_dev)
1928{
Ben Hutchings767e4682008-09-01 12:43:14 +01001929 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001930
Ben Hutchings62776d02010-06-23 11:30:07 +00001931 netif_err(efx, tx_err, efx->net_dev,
1932 "TX stuck with port_enabled=%d: resetting channels\n",
1933 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001934
Ben Hutchings739bb23d2008-11-04 20:35:36 +00001935 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001936}
1937
1938
1939/* Context: process, rtnl_lock() held. */
1940static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1941{
Ben Hutchings767e4682008-09-01 12:43:14 +01001942 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001943 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001944
Ben Hutchings8b7325b2012-07-27 20:46:41 +01001945 rc = efx_check_disabled(efx);
1946 if (rc)
1947 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001948 if (new_mtu > EFX_MAX_MTU)
1949 return -EINVAL;
1950
1951 efx_stop_all(efx);
1952
Ben Hutchings62776d02010-06-23 11:30:07 +00001953 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001954
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001955 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001956 net_dev->mtu = new_mtu;
Ben Hutchings710b2082011-09-03 00:15:00 +01001957 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001958 mutex_unlock(&efx->mac_lock);
1959
Ben Hutchings8ceee662008-04-27 12:55:59 +01001960 efx_start_all(efx);
Ben Hutchings6c8eef42012-01-09 19:54:16 +00001961 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001962}
1963
1964static int efx_set_mac_address(struct net_device *net_dev, void *data)
1965{
Ben Hutchings767e4682008-09-01 12:43:14 +01001966 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001967 struct sockaddr *addr = data;
1968 char *new_addr = addr->sa_data;
1969
Ben Hutchings8ceee662008-04-27 12:55:59 +01001970 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001971 netif_err(efx, drv, efx->net_dev,
1972 "invalid ethernet MAC address requested: %pM\n",
1973 new_addr);
Danny Kukawka504f9b52012-02-21 02:07:49 +00001974 return -EADDRNOTAVAIL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001975 }
1976
1977 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001978 efx_sriov_mac_address_changed(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001979
1980 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001981 mutex_lock(&efx->mac_lock);
Ben Hutchings710b2082011-09-03 00:15:00 +01001982 efx->type->reconfigure_mac(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001983 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001984
1985 return 0;
1986}
1987
Ben Hutchingsa816f752008-09-01 12:49:12 +01001988/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings0fca8c92012-01-09 19:54:44 +00001989static void efx_set_rx_mode(struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001990{
Ben Hutchings767e4682008-09-01 12:43:14 +01001991 struct efx_nic *efx = netdev_priv(net_dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001992 struct netdev_hw_addr *ha;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001993 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001994 u32 crc;
1995 int bit;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001996
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001997 efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001998
1999 /* Build multicast hash table */
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002000 if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002001 memset(mc_hash, 0xff, sizeof(*mc_hash));
2002 } else {
2003 memset(mc_hash, 0x00, sizeof(*mc_hash));
Jiri Pirko22bedad32010-04-01 21:22:57 +00002004 netdev_for_each_mc_addr(ha, net_dev) {
2005 crc = ether_crc_le(ETH_ALEN, ha->addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002006 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
2007 set_bit_le(bit, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002008 }
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002009
2010 /* Broadcast packets go through the multicast hash filter.
2011 * ether_crc_le() of the broadcast address is 0xbe2612ff
2012 * so we always add bit 0xff to the mask.
2013 */
2014 set_bit_le(0xff, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002015 }
2016
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002017 if (efx->port_enabled)
2018 queue_work(efx->workqueue, &efx->mac_work);
2019 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002020}
2021
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002022static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002023{
2024 struct efx_nic *efx = netdev_priv(net_dev);
2025
2026 /* If disabling RX n-tuple filtering, clear existing filters */
2027 if (net_dev->features & ~data & NETIF_F_NTUPLE)
2028 efx_filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
2029
2030 return 0;
2031}
2032
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002033static const struct net_device_ops efx_netdev_ops = {
2034 .ndo_open = efx_net_open,
2035 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00002036 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002037 .ndo_tx_timeout = efx_watchdog,
2038 .ndo_start_xmit = efx_hard_start_xmit,
2039 .ndo_validate_addr = eth_validate_addr,
2040 .ndo_do_ioctl = efx_ioctl,
2041 .ndo_change_mtu = efx_change_mtu,
2042 .ndo_set_mac_address = efx_set_mac_address,
Ben Hutchings0fca8c92012-01-09 19:54:44 +00002043 .ndo_set_rx_mode = efx_set_rx_mode,
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002044 .ndo_set_features = efx_set_features,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002045#ifdef CONFIG_SFC_SRIOV
2046 .ndo_set_vf_mac = efx_sriov_set_vf_mac,
2047 .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
2048 .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
2049 .ndo_get_vf_config = efx_sriov_get_vf_config,
2050#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002051#ifdef CONFIG_NET_POLL_CONTROLLER
2052 .ndo_poll_controller = efx_netpoll,
2053#endif
Ben Hutchings94b274b2011-01-10 21:18:20 +00002054 .ndo_setup_tc = efx_setup_tc,
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002055#ifdef CONFIG_RFS_ACCEL
2056 .ndo_rx_flow_steer = efx_filter_rfs,
2057#endif
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002058};
2059
Ben Hutchings7dde5962008-12-12 22:09:38 -08002060static void efx_update_name(struct efx_nic *efx)
2061{
2062 strcpy(efx->name, efx->net_dev->name);
2063 efx_mtd_rename(efx);
2064 efx_set_channel_names(efx);
2065}
2066
Ben Hutchings8ceee662008-04-27 12:55:59 +01002067static int efx_netdev_event(struct notifier_block *this,
2068 unsigned long event, void *ptr)
2069{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01002070 struct net_device *net_dev = ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002071
Ben Hutchings7dde5962008-12-12 22:09:38 -08002072 if (net_dev->netdev_ops == &efx_netdev_ops &&
2073 event == NETDEV_CHANGENAME)
2074 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002075
2076 return NOTIFY_DONE;
2077}
2078
2079static struct notifier_block efx_netdev_notifier = {
2080 .notifier_call = efx_netdev_event,
2081};
2082
Ben Hutchings06d5e192008-12-12 21:47:23 -08002083static ssize_t
2084show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2085{
2086 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2087 return sprintf(buf, "%d\n", efx->phy_type);
2088}
2089static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL);
2090
Ben Hutchings8ceee662008-04-27 12:55:59 +01002091static int efx_register_netdev(struct efx_nic *efx)
2092{
2093 struct net_device *net_dev = efx->net_dev;
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002094 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002095 int rc;
2096
2097 net_dev->watchdog_timeo = 5 * HZ;
2098 net_dev->irq = efx->pci_dev->irq;
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08002099 net_dev->netdev_ops = &efx_netdev_ops;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002100 SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +00002101 net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002102
Ben Hutchings7dde5962008-12-12 22:09:38 -08002103 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00002104
Ben Hutchings7153f622012-07-27 20:50:52 +01002105 /* Enable resets to be scheduled and check whether any were
2106 * already requested. If so, the NIC is probably hosed so we
2107 * abort.
2108 */
2109 efx->state = STATE_READY;
2110 smp_mb(); /* ensure we change state before checking reset_pending */
2111 if (efx->reset_pending) {
2112 netif_err(efx, probe, efx->net_dev,
2113 "aborting probe due to scheduled reset\n");
2114 rc = -EIO;
2115 goto fail_locked;
2116 }
2117
Ben Hutchingsaed06282009-08-26 08:16:27 +00002118 rc = dev_alloc_name(net_dev, net_dev->name);
2119 if (rc < 0)
2120 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002121 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002122
2123 rc = register_netdevice(net_dev);
2124 if (rc)
2125 goto fail_locked;
2126
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002127 efx_for_each_channel(channel, efx) {
2128 struct efx_tx_queue *tx_queue;
Ben Hutchings60031fc2011-01-12 18:39:40 +00002129 efx_for_each_channel_tx_queue(tx_queue, channel)
2130 efx_init_tx_queue_core_txq(tx_queue);
Ben Hutchingsc04bfc62010-12-10 01:24:16 +00002131 }
2132
Ben Hutchingsaed06282009-08-26 08:16:27 +00002133 /* Always start with carrier off; PHY events will detect the link */
Ben Hutchings86ee5302012-01-09 19:51:22 +00002134 netif_carrier_off(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002135
Ben Hutchings7dde5962008-12-12 22:09:38 -08002136 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002137
Ben Hutchings06d5e192008-12-12 21:47:23 -08002138 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2139 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002140 netif_err(efx, drv, efx->net_dev,
2141 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08002142 goto fail_registered;
2143 }
2144
Ben Hutchings8ceee662008-04-27 12:55:59 +01002145 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08002146
Ben Hutchings7153f622012-07-27 20:50:52 +01002147fail_registered:
2148 rtnl_lock();
2149 unregister_netdevice(net_dev);
Ben Hutchingsaed06282009-08-26 08:16:27 +00002150fail_locked:
Ben Hutchings7153f622012-07-27 20:50:52 +01002151 efx->state = STATE_UNINIT;
Ben Hutchingsaed06282009-08-26 08:16:27 +00002152 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00002153 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00002154 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002155}
2156
2157static void efx_unregister_netdev(struct efx_nic *efx)
2158{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002159 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002160 struct efx_tx_queue *tx_queue;
2161
2162 if (!efx->net_dev)
2163 return;
2164
Ben Hutchings767e4682008-09-01 12:43:14 +01002165 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002166
2167 /* Free up any skbs still remaining. This has to happen before
2168 * we try to unregister the netdev as running their destructors
2169 * may be needed to get the device ref. count to 0. */
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00002170 efx_for_each_channel(channel, efx) {
2171 efx_for_each_channel_tx_queue(tx_queue, channel)
2172 efx_release_tx_buffers(tx_queue);
2173 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002174
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002175 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2176 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
Ben Hutchings7153f622012-07-27 20:50:52 +01002177
2178 rtnl_lock();
2179 unregister_netdevice(efx->net_dev);
2180 efx->state = STATE_UNINIT;
2181 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002182}
2183
2184/**************************************************************************
2185 *
2186 * Device reset and suspend
2187 *
2188 **************************************************************************/
2189
Ben Hutchings2467ca42008-09-01 12:48:50 +01002190/* Tears down the entire software state and most of the hardware state
2191 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002192void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002193{
Ben Hutchings8ceee662008-04-27 12:55:59 +01002194 EFX_ASSERT_RESET_SERIALISED(efx);
2195
Ben Hutchings2467ca42008-09-01 12:48:50 +01002196 efx_stop_all(efx);
Ben Hutchings7f967c02012-02-13 23:45:02 +00002197 efx_stop_interrupts(efx, false);
Ben Hutchings5642cee2012-07-27 19:35:52 +01002198
2199 mutex_lock(&efx->mac_lock);
Steve Hodgson4b988282009-01-29 17:50:51 +00002200 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
2201 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002202 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002203}
2204
Ben Hutchings2467ca42008-09-01 12:48:50 +01002205/* This function will always ensure that the locks acquired in
2206 * efx_reset_down() are released. A failure return code indicates
2207 * that we were unable to reinitialise the hardware, and the
2208 * driver should be disabled. If ok is false, then the rx and tx
2209 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002210int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002211{
2212 int rc;
2213
Ben Hutchings2467ca42008-09-01 12:48:50 +01002214 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002215
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002216 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002217 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002218 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002219 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002220 }
2221
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002222 if (!ok)
2223 goto fail;
2224
Steve Hodgson4b988282009-01-29 17:50:51 +00002225 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002226 rc = efx->phy_op->init(efx);
2227 if (rc)
2228 goto fail;
2229 if (efx->phy_op->reconfigure(efx))
Ben Hutchings62776d02010-06-23 11:30:07 +00002230 netif_err(efx, drv, efx->net_dev,
2231 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002232 }
2233
Ben Hutchings710b2082011-09-03 00:15:00 +01002234 efx->type->reconfigure_mac(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002235
Ben Hutchings7f967c02012-02-13 23:45:02 +00002236 efx_start_interrupts(efx, false);
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002237 efx_restore_filters(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002238 efx_sriov_reset(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002239
2240 mutex_unlock(&efx->mac_lock);
2241
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002242 efx_start_all(efx);
2243
2244 return 0;
2245
2246fail:
2247 efx->port_initialized = false;
2248
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002249 mutex_unlock(&efx->mac_lock);
2250
Ben Hutchings8ceee662008-04-27 12:55:59 +01002251 return rc;
2252}
2253
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002254/* Reset the NIC using the specified method. Note that the reset may
2255 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002256 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002257 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002258 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002259int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002260{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002261 int rc, rc2;
2262 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002263
Ben Hutchings62776d02010-06-23 11:30:07 +00002264 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2265 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002266
Ben Hutchingse4abce82011-05-16 18:51:24 +01002267 netif_device_detach(efx->net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002268 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002269
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002270 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002271 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002272 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002273 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002274 }
2275
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002276 /* Clear flags for the scopes we covered. We assume the NIC and
2277 * driver are now quiescent so that there is no race here.
2278 */
2279 efx->reset_pending &= -(1 << (method + 1));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002280
2281 /* Reinitialise bus-mastering, which may have been turned off before
2282 * the reset was scheduled. This is still appropriate, even in the
2283 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2284 * can respond to requests. */
2285 pci_set_master(efx->pci_dev);
2286
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002287out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002288 /* Leave device stopped if necessary */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002289 disabled = rc || method == RESET_TYPE_DISABLE;
2290 rc2 = efx_reset_up(efx, method, !disabled);
2291 if (rc2) {
2292 disabled = true;
2293 if (!rc)
2294 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002295 }
2296
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002297 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002298 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002299 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002300 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002301 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002302 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Ben Hutchingse4abce82011-05-16 18:51:24 +01002303 netif_device_attach(efx->net_dev);
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002304 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002305 return rc;
2306}
2307
2308/* The worker thread exists so that code that cannot sleep can
2309 * schedule a reset for later.
2310 */
2311static void efx_reset_work(struct work_struct *data)
2312{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002313 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002314 unsigned long pending = ACCESS_ONCE(efx->reset_pending);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002315
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002316 if (!pending)
Steve Hodgson319ba642010-06-01 11:17:24 +00002317 return;
2318
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002319 rtnl_lock();
Ben Hutchings7153f622012-07-27 20:50:52 +01002320
2321 /* We checked the state in efx_schedule_reset() but it may
2322 * have changed by now. Now that we have the RTNL lock,
2323 * it cannot change again.
2324 */
2325 if (efx->state == STATE_READY)
2326 (void)efx_reset(efx, fls(pending) - 1);
2327
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002328 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002329}
2330
2331void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2332{
2333 enum reset_type method;
2334
Ben Hutchings8ceee662008-04-27 12:55:59 +01002335 switch (type) {
2336 case RESET_TYPE_INVISIBLE:
2337 case RESET_TYPE_ALL:
2338 case RESET_TYPE_WORLD:
2339 case RESET_TYPE_DISABLE:
2340 method = type;
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002341 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2342 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002343 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002344 default:
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002345 method = efx->type->map_reset_reason(type);
Ben Hutchings62776d02010-06-23 11:30:07 +00002346 netif_dbg(efx, drv, efx->net_dev,
2347 "scheduling %s reset for %s\n",
2348 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings0e2a9c72011-06-24 20:50:07 +01002349 break;
2350 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002351
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002352 set_bit(method, &efx->reset_pending);
Ben Hutchings7153f622012-07-27 20:50:52 +01002353 smp_mb(); /* ensure we change reset_pending before checking state */
2354
2355 /* If we're not READY then just leave the flags set as the cue
2356 * to abort probing or reschedule the reset later.
2357 */
2358 if (ACCESS_ONCE(efx->state) != STATE_READY)
2359 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002360
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002361 /* efx_process_channel() will no longer read events once a
2362 * reset is scheduled. So switch back to poll'd MCDI completions. */
2363 efx_mcdi_mode_poll(efx);
2364
Steve Hodgson1ab00622008-12-12 21:33:02 -08002365 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002366}
2367
2368/**************************************************************************
2369 *
2370 * List of NICs we support
2371 *
2372 **************************************************************************/
2373
2374/* PCI device ID table */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002375static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002376 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2377 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002378 .driver_data = (unsigned long) &falcon_a1_nic_type},
Linus Torvalds0e59e7e72011-10-28 14:20:44 -07002379 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2380 PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002381 .driver_data = (unsigned long) &falcon_b0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002382 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002383 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings547c4742011-12-02 18:23:56 +00002384 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002385 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002386 {0} /* end of list */
2387};
2388
2389/**************************************************************************
2390 *
Ben Hutchings37594332009-11-23 16:05:45 +00002391 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002392 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002393 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002394 * Needed so all function pointers are valid and do not have to be tested
2395 * before use
2396 *
2397 **************************************************************************/
2398int efx_port_dummy_op_int(struct efx_nic *efx)
2399{
2400 return 0;
2401}
2402void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002403
2404static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002405{
2406 return false;
2407}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002408
stephen hemminger6c8c2512011-04-14 05:50:12 +00002409static const struct efx_phy_operations efx_dummy_phy_operations = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002410 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002411 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002412 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002413 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002414};
2415
Ben Hutchings8ceee662008-04-27 12:55:59 +01002416/**************************************************************************
2417 *
2418 * Data housekeeping
2419 *
2420 **************************************************************************/
2421
2422/* This zeroes out and then fills in the invariants in a struct
2423 * efx_nic (including all sub-structures).
2424 */
stephen hemminger6c8c2512011-04-14 05:50:12 +00002425static int efx_init_struct(struct efx_nic *efx, const struct efx_nic_type *type,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002426 struct pci_dev *pci_dev, struct net_device *net_dev)
2427{
Ben Hutchings46426102010-09-10 06:42:33 +00002428 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002429
2430 /* Initialise common structures */
2431 memset(efx, 0, sizeof(*efx));
2432 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002433#ifdef CONFIG_SFC_MTD
2434 INIT_LIST_HEAD(&efx->mtd_list);
2435#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002436 INIT_WORK(&efx->reset_work, efx_reset_work);
2437 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
Ben Hutchingsdd407812012-02-28 23:40:21 +00002438 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002439 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002440 efx->msg_enable = debug;
Ben Hutchingsf16aeea2012-07-27 19:31:16 +01002441 efx->state = STATE_UNINIT;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002442 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002443
2444 efx->net_dev = net_dev;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002445 spin_lock_init(&efx->stats_lock);
2446 mutex_init(&efx->mac_lock);
2447 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002448 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08002449 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings9f2cb712012-02-08 00:11:20 +00002450 init_waitqueue_head(&efx->flush_wq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002451
2452 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00002453 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
2454 if (!efx->channel[i])
2455 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002456 }
2457
2458 efx->type = type;
2459
Ben Hutchings8ceee662008-04-27 12:55:59 +01002460 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
2461
2462 /* Higher numbered interrupt modes are less capable! */
2463 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
2464 interrupt_mode);
2465
Ben Hutchings6977dc62008-12-26 13:44:39 -08002466 /* Would be good to use the net_dev name, but we're too early */
2467 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
2468 pci_name(pci_dev));
2469 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002470 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00002471 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01002472
Ben Hutchings8ceee662008-04-27 12:55:59 +01002473 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00002474
2475fail:
2476 efx_fini_struct(efx);
2477 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002478}
2479
2480static void efx_fini_struct(struct efx_nic *efx)
2481{
Ben Hutchings8313aca2010-09-10 06:41:57 +00002482 int i;
2483
2484 for (i = 0; i < EFX_MAX_CHANNELS; i++)
2485 kfree(efx->channel[i]);
2486
Ben Hutchings8ceee662008-04-27 12:55:59 +01002487 if (efx->workqueue) {
2488 destroy_workqueue(efx->workqueue);
2489 efx->workqueue = NULL;
2490 }
2491}
2492
2493/**************************************************************************
2494 *
2495 * PCI interface
2496 *
2497 **************************************************************************/
2498
2499/* Main body of final NIC shutdown code
2500 * This is called only at module unload (or hotplug removal).
2501 */
2502static void efx_pci_remove_main(struct efx_nic *efx)
2503{
Ben Hutchings7153f622012-07-27 20:50:52 +01002504 /* Flush reset_work. It can no longer be scheduled since we
2505 * are not READY.
2506 */
2507 BUG_ON(efx->state == STATE_READY);
2508 cancel_work_sync(&efx->reset_work);
2509
Ben Hutchings64d8ad62011-01-05 00:50:41 +00002510#ifdef CONFIG_RFS_ACCEL
2511 free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
2512 efx->net_dev->rx_cpu_rmap = NULL;
2513#endif
Ben Hutchings7f967c02012-02-13 23:45:02 +00002514 efx_stop_interrupts(efx, false);
Ben Hutchings152b6a62009-11-29 03:43:56 +00002515 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002516 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002517 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002518 efx_fini_napi(efx);
2519 efx_remove_all(efx);
2520}
2521
2522/* Final NIC shutdown
2523 * This is called only at module unload (or hotplug removal).
2524 */
2525static void efx_pci_remove(struct pci_dev *pci_dev)
2526{
2527 struct efx_nic *efx;
2528
2529 efx = pci_get_drvdata(pci_dev);
2530 if (!efx)
2531 return;
2532
2533 /* Mark the NIC as fini, then stop the interface */
2534 rtnl_lock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002535 dev_close(efx->net_dev);
Ben Hutchings5642cee2012-07-27 19:35:52 +01002536 efx_stop_interrupts(efx, false);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002537 rtnl_unlock();
2538
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002539 efx_sriov_fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002540 efx_unregister_netdev(efx);
2541
Ben Hutchings7dde5962008-12-12 22:09:38 -08002542 efx_mtd_remove(efx);
2543
Ben Hutchings8ceee662008-04-27 12:55:59 +01002544 efx_pci_remove_main(efx);
2545
Ben Hutchings8ceee662008-04-27 12:55:59 +01002546 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002547 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002548
Ben Hutchings8ceee662008-04-27 12:55:59 +01002549 efx_fini_struct(efx);
Ben Hutchings3de4e302012-04-05 00:22:19 +01002550 pci_set_drvdata(pci_dev, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002551 free_netdev(efx->net_dev);
2552};
2553
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002554/* NIC VPD information
2555 * Called during probe to display the part number of the
2556 * installed NIC. VPD is potentially very large but this should
2557 * always appear within the first 512 bytes.
2558 */
2559#define SFC_VPD_LEN 512
2560static void efx_print_product_vpd(struct efx_nic *efx)
2561{
2562 struct pci_dev *dev = efx->pci_dev;
2563 char vpd_data[SFC_VPD_LEN];
2564 ssize_t vpd_size;
2565 int i, j;
2566
2567 /* Get the vpd data from the device */
2568 vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
2569 if (vpd_size <= 0) {
2570 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
2571 return;
2572 }
2573
2574 /* Get the Read only section */
2575 i = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
2576 if (i < 0) {
2577 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
2578 return;
2579 }
2580
2581 j = pci_vpd_lrdt_size(&vpd_data[i]);
2582 i += PCI_VPD_LRDT_TAG_SIZE;
2583 if (i + j > vpd_size)
2584 j = vpd_size - i;
2585
2586 /* Get the Part number */
2587 i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
2588 if (i < 0) {
2589 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
2590 return;
2591 }
2592
2593 j = pci_vpd_info_field_size(&vpd_data[i]);
2594 i += PCI_VPD_INFO_FLD_HDR_SIZE;
2595 if (i + j > vpd_size) {
2596 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
2597 return;
2598 }
2599
2600 netif_info(efx, drv, efx->net_dev,
2601 "Part Number : %.*s\n", j, &vpd_data[i]);
2602}
2603
2604
Ben Hutchings8ceee662008-04-27 12:55:59 +01002605/* Main body of NIC initialisation
2606 * This is called at module load (or hotplug insertion, theoretically).
2607 */
2608static int efx_pci_probe_main(struct efx_nic *efx)
2609{
2610 int rc;
2611
2612 /* Do start-of-day initialisation */
2613 rc = efx_probe_all(efx);
2614 if (rc)
2615 goto fail1;
2616
Ben Hutchingse8f14992010-12-07 19:47:34 +00002617 efx_init_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002618
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002619 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002620 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002621 netif_err(efx, probe, efx->net_dev,
2622 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002623 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002624 }
2625
2626 rc = efx_init_port(efx);
2627 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002628 netif_err(efx, probe, efx->net_dev,
2629 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002630 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002631 }
2632
Ben Hutchings152b6a62009-11-29 03:43:56 +00002633 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002634 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00002635 goto fail5;
Ben Hutchings7f967c02012-02-13 23:45:02 +00002636 efx_start_interrupts(efx, false);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002637
2638 return 0;
2639
Ben Hutchings278c0622009-11-23 16:05:12 +00002640 fail5:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002641 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002642 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002643 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002644 fail3:
2645 efx_fini_napi(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002646 efx_remove_all(efx);
2647 fail1:
2648 return rc;
2649}
2650
2651/* NIC initialisation
2652 *
2653 * This is called at module load (or hotplug insertion,
Ben Hutchings73ba7b62012-01-09 19:47:08 +00002654 * theoretically). It sets up PCI mappings, resets the NIC,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002655 * sets up and registers the network devices with the kernel and hooks
2656 * the interrupt service routine. It does not prepare the device for
2657 * transmission; this is left to the first time one of the network
2658 * interfaces is brought up (i.e. efx_net_open).
2659 */
2660static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2661 const struct pci_device_id *entry)
2662{
stephen hemminger6c8c2512011-04-14 05:50:12 +00002663 const struct efx_nic_type *type = (const struct efx_nic_type *) entry->driver_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002664 struct net_device *net_dev;
2665 struct efx_nic *efx;
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002666 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002667
2668 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchings94b274b2011-01-10 21:18:20 +00002669 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
2670 EFX_MAX_RX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002671 if (!net_dev)
2672 return -ENOMEM;
Ben Hutchingsc383b532009-11-29 15:11:02 +00002673 net_dev->features |= (type->offload_features | NETIF_F_SG |
Ben Hutchings97bc5412009-05-19 16:19:08 -07002674 NETIF_F_HIGHDMA | NETIF_F_TSO |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002675 NETIF_F_RXCSUM);
Ben Hutchings738a8f42009-11-29 15:16:05 +00002676 if (type->offload_features & NETIF_F_V6_CSUM)
2677 net_dev->features |= NETIF_F_TSO6;
Ben Hutchings285065632008-09-01 12:46:54 +01002678 /* Mask for features that also apply to VLAN devices */
2679 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
Ben Hutchingsabfe9032011-04-05 15:00:02 +01002680 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
2681 NETIF_F_RXCSUM);
2682 /* All offloads can be toggled */
2683 net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA;
Ben Hutchings767e4682008-09-01 12:43:14 +01002684 efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002685 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002686 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002687 rc = efx_init_struct(efx, type, pci_dev, net_dev);
2688 if (rc)
2689 goto fail1;
2690
Ben Hutchings62776d02010-06-23 11:30:07 +00002691 netif_info(efx, probe, efx->net_dev,
Ben Hutchingsff79c8a2011-07-13 16:21:24 +01002692 "Solarflare NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002693
Ben Hutchings460eeaa2012-03-05 15:35:39 +00002694 efx_print_product_vpd(efx);
2695
Ben Hutchings8ceee662008-04-27 12:55:59 +01002696 /* Set up basic I/O (BAR mappings etc) */
2697 rc = efx_init_io(efx);
2698 if (rc)
2699 goto fail2;
2700
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002701 rc = efx_pci_probe_main(efx);
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002702 if (rc)
2703 goto fail3;
Steve Hodgsonfa402b22008-12-12 22:08:16 -08002704
Ben Hutchings8ceee662008-04-27 12:55:59 +01002705 rc = efx_register_netdev(efx);
2706 if (rc)
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002707 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002708
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002709 rc = efx_sriov_init(efx);
2710 if (rc)
2711 netif_err(efx, probe, efx->net_dev,
2712 "SR-IOV can't be enabled rc %d\n", rc);
2713
Ben Hutchings62776d02010-06-23 11:30:07 +00002714 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002715
Ben Hutchings7c431612012-01-27 17:23:58 +00002716 /* Try to create MTDs, but allow this to fail */
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002717 rtnl_lock();
Ben Hutchings7c431612012-01-27 17:23:58 +00002718 rc = efx_mtd_probe(efx);
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002719 rtnl_unlock();
Ben Hutchings7c431612012-01-27 17:23:58 +00002720 if (rc)
2721 netif_warn(efx, probe, efx->net_dev,
2722 "failed to create MTDs (%d)\n", rc);
2723
Ben Hutchings8ceee662008-04-27 12:55:59 +01002724 return 0;
2725
Ben Hutchings8ceee662008-04-27 12:55:59 +01002726 fail4:
Ben Hutchingsfadac6a2011-11-19 00:35:47 +00002727 efx_pci_remove_main(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002728 fail3:
2729 efx_fini_io(efx);
2730 fail2:
2731 efx_fini_struct(efx);
2732 fail1:
Ben Hutchings3de4e302012-04-05 00:22:19 +01002733 pci_set_drvdata(pci_dev, NULL);
Steve Hodgson5e2a9112010-02-12 12:32:27 -08002734 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00002735 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002736 free_netdev(net_dev);
2737 return rc;
2738}
2739
Ben Hutchings89c758f2009-11-29 03:43:07 +00002740static int efx_pm_freeze(struct device *dev)
2741{
2742 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2743
Ben Hutchings61da0262012-07-27 19:35:39 +01002744 rtnl_lock();
2745
Ben Hutchings6032fb52012-07-27 19:35:47 +01002746 if (efx->state != STATE_DISABLED) {
2747 efx->state = STATE_UNINIT;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002748
Ben Hutchings6032fb52012-07-27 19:35:47 +01002749 netif_device_detach(efx->net_dev);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002750
Ben Hutchings6032fb52012-07-27 19:35:47 +01002751 efx_stop_all(efx);
2752 efx_stop_interrupts(efx, false);
2753 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00002754
Ben Hutchings61da0262012-07-27 19:35:39 +01002755 rtnl_unlock();
2756
Ben Hutchings89c758f2009-11-29 03:43:07 +00002757 return 0;
2758}
2759
2760static int efx_pm_thaw(struct device *dev)
2761{
2762 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2763
Ben Hutchings61da0262012-07-27 19:35:39 +01002764 rtnl_lock();
2765
Ben Hutchings6032fb52012-07-27 19:35:47 +01002766 if (efx->state != STATE_DISABLED) {
2767 efx_start_interrupts(efx, false);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002768
Ben Hutchings6032fb52012-07-27 19:35:47 +01002769 mutex_lock(&efx->mac_lock);
2770 efx->phy_op->reconfigure(efx);
2771 mutex_unlock(&efx->mac_lock);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002772
Ben Hutchings6032fb52012-07-27 19:35:47 +01002773 efx_start_all(efx);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002774
Ben Hutchings6032fb52012-07-27 19:35:47 +01002775 netif_device_attach(efx->net_dev);
Ben Hutchings89c758f2009-11-29 03:43:07 +00002776
Ben Hutchings6032fb52012-07-27 19:35:47 +01002777 efx->state = STATE_READY;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002778
Ben Hutchings6032fb52012-07-27 19:35:47 +01002779 efx->type->resume_wol(efx);
2780 }
Ben Hutchings89c758f2009-11-29 03:43:07 +00002781
Ben Hutchings61da0262012-07-27 19:35:39 +01002782 rtnl_unlock();
2783
Steve Hodgson319ba642010-06-01 11:17:24 +00002784 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2785 queue_work(reset_workqueue, &efx->reset_work);
2786
Ben Hutchings89c758f2009-11-29 03:43:07 +00002787 return 0;
2788}
2789
2790static int efx_pm_poweroff(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
2795 efx->type->fini(efx);
2796
Ben Hutchingsa7d529a2011-06-24 20:46:31 +01002797 efx->reset_pending = 0;
Ben Hutchings89c758f2009-11-29 03:43:07 +00002798
2799 pci_save_state(pci_dev);
2800 return pci_set_power_state(pci_dev, PCI_D3hot);
2801}
2802
2803/* Used for both resume and restore */
2804static int efx_pm_resume(struct device *dev)
2805{
2806 struct pci_dev *pci_dev = to_pci_dev(dev);
2807 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2808 int rc;
2809
2810 rc = pci_set_power_state(pci_dev, PCI_D0);
2811 if (rc)
2812 return rc;
2813 pci_restore_state(pci_dev);
2814 rc = pci_enable_device(pci_dev);
2815 if (rc)
2816 return rc;
2817 pci_set_master(efx->pci_dev);
2818 rc = efx->type->reset(efx, RESET_TYPE_ALL);
2819 if (rc)
2820 return rc;
2821 rc = efx->type->init(efx);
2822 if (rc)
2823 return rc;
2824 efx_pm_thaw(dev);
2825 return 0;
2826}
2827
2828static int efx_pm_suspend(struct device *dev)
2829{
2830 int rc;
2831
2832 efx_pm_freeze(dev);
2833 rc = efx_pm_poweroff(dev);
2834 if (rc)
2835 efx_pm_resume(dev);
2836 return rc;
2837}
2838
Ben Hutchings18e83e42012-01-05 19:05:20 +00002839static const struct dev_pm_ops efx_pm_ops = {
Ben Hutchings89c758f2009-11-29 03:43:07 +00002840 .suspend = efx_pm_suspend,
2841 .resume = efx_pm_resume,
2842 .freeze = efx_pm_freeze,
2843 .thaw = efx_pm_thaw,
2844 .poweroff = efx_pm_poweroff,
2845 .restore = efx_pm_resume,
2846};
2847
Ben Hutchings8ceee662008-04-27 12:55:59 +01002848static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00002849 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002850 .id_table = efx_pci_table,
2851 .probe = efx_pci_probe,
2852 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00002853 .driver.pm = &efx_pm_ops,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002854};
2855
2856/**************************************************************************
2857 *
2858 * Kernel module interface
2859 *
2860 *************************************************************************/
2861
2862module_param(interrupt_mode, uint, 0444);
2863MODULE_PARM_DESC(interrupt_mode,
2864 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
2865
2866static int __init efx_init_module(void)
2867{
2868 int rc;
2869
2870 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
2871
2872 rc = register_netdevice_notifier(&efx_netdev_notifier);
2873 if (rc)
2874 goto err_notifier;
2875
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002876 rc = efx_init_sriov();
2877 if (rc)
2878 goto err_sriov;
2879
Steve Hodgson1ab00622008-12-12 21:33:02 -08002880 reset_workqueue = create_singlethread_workqueue("sfc_reset");
2881 if (!reset_workqueue) {
2882 rc = -ENOMEM;
2883 goto err_reset;
2884 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002885
2886 rc = pci_register_driver(&efx_pci_driver);
2887 if (rc < 0)
2888 goto err_pci;
2889
2890 return 0;
2891
2892 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08002893 destroy_workqueue(reset_workqueue);
2894 err_reset:
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002895 efx_fini_sriov();
2896 err_sriov:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002897 unregister_netdevice_notifier(&efx_netdev_notifier);
2898 err_notifier:
2899 return rc;
2900}
2901
2902static void __exit efx_exit_module(void)
2903{
2904 printk(KERN_INFO "Solarflare NET driver unloading\n");
2905
2906 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002907 destroy_workqueue(reset_workqueue);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00002908 efx_fini_sriov();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002909 unregister_netdevice_notifier(&efx_netdev_notifier);
2910
2911}
2912
2913module_init(efx_init_module);
2914module_exit(efx_exit_module);
2915
Ben Hutchings906bb262009-11-29 15:16:19 +00002916MODULE_AUTHOR("Solarflare Communications and "
2917 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002918MODULE_DESCRIPTION("Solarflare Communications network driver");
2919MODULE_LICENSE("GPL");
2920MODULE_DEVICE_TABLE(pci, efx_pci_table);