blob: f3e4043d70eee852a98d7fe7eddc8bef1e219a6f [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 Hutchings906bb262009-11-29 15:16:19 +00004 * Copyright 2005-2009 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 Hutchings8ceee662008-04-27 12:55:59 +010024#include "net_driver.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010025#include "efx.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000026#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010027
Ben Hutchings8880f4e2009-11-29 15:15:41 +000028#include "mcdi.h"
Steve Hodgsonfd371e32010-06-01 11:17:51 +000029#include "workarounds.h"
Ben Hutchings8880f4e2009-11-29 15:15:41 +000030
Ben Hutchingsc4593022009-11-23 16:08:17 +000031/**************************************************************************
32 *
33 * Type name strings
34 *
35 **************************************************************************
36 */
37
38/* Loopback mode names (see LOOPBACK_MODE()) */
39const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
40const char *efx_loopback_mode_names[] = {
41 [LOOPBACK_NONE] = "NONE",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000042 [LOOPBACK_DATA] = "DATAPATH",
Ben Hutchingsc4593022009-11-23 16:08:17 +000043 [LOOPBACK_GMAC] = "GMAC",
44 [LOOPBACK_XGMII] = "XGMII",
45 [LOOPBACK_XGXS] = "XGXS",
46 [LOOPBACK_XAUI] = "XAUI",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000047 [LOOPBACK_GMII] = "GMII",
48 [LOOPBACK_SGMII] = "SGMII",
49 [LOOPBACK_XGBR] = "XGBR",
50 [LOOPBACK_XFI] = "XFI",
51 [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
52 [LOOPBACK_GMII_FAR] = "GMII_FAR",
53 [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
54 [LOOPBACK_XFI_FAR] = "XFI_FAR",
Ben Hutchingsc4593022009-11-23 16:08:17 +000055 [LOOPBACK_GPHY] = "GPHY",
56 [LOOPBACK_PHYXS] = "PHYXS",
57 [LOOPBACK_PCS] = "PCS",
58 [LOOPBACK_PMAPMD] = "PMA/PMD",
Ben Hutchingse58f69f2009-11-29 15:08:41 +000059 [LOOPBACK_XPORT] = "XPORT",
60 [LOOPBACK_XGMII_WS] = "XGMII_WS",
61 [LOOPBACK_XAUI_WS] = "XAUI_WS",
62 [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
63 [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
64 [LOOPBACK_GMII_WS] = "GMII_WS",
65 [LOOPBACK_XFI_WS] = "XFI_WS",
66 [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
67 [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
Ben Hutchingsc4593022009-11-23 16:08:17 +000068};
69
Ben Hutchingsc4593022009-11-23 16:08:17 +000070const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
71const char *efx_reset_type_names[] = {
72 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
73 [RESET_TYPE_ALL] = "ALL",
74 [RESET_TYPE_WORLD] = "WORLD",
75 [RESET_TYPE_DISABLE] = "DISABLE",
76 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
77 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
78 [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
79 [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH",
80 [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH",
81 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
Ben Hutchings8880f4e2009-11-29 15:15:41 +000082 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
Ben Hutchingsc4593022009-11-23 16:08:17 +000083};
84
Ben Hutchings8ceee662008-04-27 12:55:59 +010085#define EFX_MAX_MTU (9 * 1024)
86
Steve Hodgson1ab00622008-12-12 21:33:02 -080087/* Reset workqueue. If any NIC has a hardware failure then a reset will be
88 * queued onto this work queue. This is not a per-nic work queue, because
89 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
90 */
91static struct workqueue_struct *reset_workqueue;
92
Ben Hutchings8ceee662008-04-27 12:55:59 +010093/**************************************************************************
94 *
95 * Configurable values
96 *
97 *************************************************************************/
98
99/*
Ben Hutchings8ceee662008-04-27 12:55:59 +0100100 * Use separate channels for TX and RX events
101 *
Neil Turton28b581a2008-12-12 21:41:06 -0800102 * Set this to 1 to use separate channels for TX and RX. It allows us
103 * to control interrupt affinity separately for TX and RX.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100104 *
Neil Turton28b581a2008-12-12 21:41:06 -0800105 * This is only used in MSI-X interrupt mode
Ben Hutchings8ceee662008-04-27 12:55:59 +0100106 */
Neil Turton28b581a2008-12-12 21:41:06 -0800107static unsigned int separate_tx_channels;
Ben Hutchings8313aca2010-09-10 06:41:57 +0000108module_param(separate_tx_channels, uint, 0444);
Neil Turton28b581a2008-12-12 21:41:06 -0800109MODULE_PARM_DESC(separate_tx_channels,
110 "Use separate channels for TX and RX");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100111
112/* This is the weight assigned to each of the (per-channel) virtual
113 * NAPI devices.
114 */
115static int napi_weight = 64;
116
117/* This is the time (in jiffies) between invocations of the hardware
Ben Hutchingse254c272010-09-20 08:44:10 +0000118 * monitor. On Falcon-based NICs, this will:
119 * - Check the on-board hardware monitor;
120 * - Poll the link state and reconfigure the hardware as necessary.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100121 */
stephen hemmingerd2156972010-10-18 05:27:31 +0000122static unsigned int efx_monitor_interval = 1 * HZ;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100123
Ben Hutchings8ceee662008-04-27 12:55:59 +0100124/* This controls whether or not the driver will initialise devices
125 * with invalid MAC addresses stored in the EEPROM or flash. If true,
126 * such devices will be initialised with a random locally-generated
127 * MAC address. This allows for loading the sfc_mtd driver to
128 * reprogram the flash, even if the flash contents (including the MAC
129 * address) have previously been erased.
130 */
131static unsigned int allow_bad_hwaddr;
132
133/* Initial interrupt moderation settings. They can be modified after
134 * module load with ethtool.
135 *
136 * The default for RX should strike a balance between increasing the
137 * round-trip latency and reducing overhead.
138 */
139static unsigned int rx_irq_mod_usec = 60;
140
141/* Initial interrupt moderation settings. They can be modified after
142 * module load with ethtool.
143 *
144 * This default is chosen to ensure that a 10G link does not go idle
145 * while a TX queue is stopped after it has become full. A queue is
146 * restarted when it drops below half full. The time this takes (assuming
147 * worst case 3 descriptors per packet and 1024 descriptors) is
148 * 512 / 3 * 1.2 = 205 usec.
149 */
150static unsigned int tx_irq_mod_usec = 150;
151
152/* This is the first interrupt mode to try out of:
153 * 0 => MSI-X
154 * 1 => MSI
155 * 2 => legacy
156 */
157static unsigned int interrupt_mode;
158
159/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
160 * i.e. the number of CPUs among which we may distribute simultaneous
161 * interrupt handling.
162 *
163 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
164 * The default (0) means to assign an interrupt to each package (level II cache)
165 */
166static unsigned int rss_cpus;
167module_param(rss_cpus, uint, 0444);
168MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
169
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800170static int phy_flash_cfg;
171module_param(phy_flash_cfg, int, 0644);
172MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
173
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000174static unsigned irq_adapt_low_thresh = 10000;
175module_param(irq_adapt_low_thresh, uint, 0644);
176MODULE_PARM_DESC(irq_adapt_low_thresh,
177 "Threshold score for reducing IRQ moderation");
178
179static unsigned irq_adapt_high_thresh = 20000;
180module_param(irq_adapt_high_thresh, uint, 0644);
181MODULE_PARM_DESC(irq_adapt_high_thresh,
182 "Threshold score for increasing IRQ moderation");
183
Ben Hutchings62776d02010-06-23 11:30:07 +0000184static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
185 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
186 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
187 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
188module_param(debug, uint, 0);
189MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
190
Ben Hutchings8ceee662008-04-27 12:55:59 +0100191/**************************************************************************
192 *
193 * Utility functions and prototypes
194 *
195 *************************************************************************/
Ben Hutchings46426102010-09-10 06:42:33 +0000196
197static void efx_remove_channels(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100198static void efx_remove_port(struct efx_nic *efx);
199static void efx_fini_napi(struct efx_nic *efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000200static void efx_fini_struct(struct efx_nic *efx);
201static void efx_start_all(struct efx_nic *efx);
202static void efx_stop_all(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100203
204#define EFX_ASSERT_RESET_SERIALISED(efx) \
205 do { \
Ben Hutchings332c1ce2009-11-25 16:08:52 +0000206 if ((efx->state == STATE_RUNNING) || \
207 (efx->state == STATE_DISABLED)) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100208 ASSERT_RTNL(); \
209 } while (0)
210
211/**************************************************************************
212 *
213 * Event queue processing
214 *
215 *************************************************************************/
216
217/* Process channel's event queue
218 *
219 * This function is responsible for processing the event queue of a
220 * single channel. The caller must guarantee that this function will
221 * never be concurrently called more than once on the same channel,
222 * though different channels may be being processed concurrently.
223 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000224static int efx_process_channel(struct efx_channel *channel, int budget)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100225{
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100226 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000227 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100228
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100229 if (unlikely(efx->reset_pending != RESET_TYPE_NONE ||
Ben Hutchings8ceee662008-04-27 12:55:59 +0100230 !channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100231 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100232
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000233 spent = efx_nic_process_eventq(channel, budget);
234 if (spent == 0)
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100235 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100236
237 /* Deliver last RX packet. */
238 if (channel->rx_pkt) {
239 __efx_rx_packet(channel, channel->rx_pkt,
240 channel->rx_pkt_csummed);
241 channel->rx_pkt = NULL;
242 }
243
Ben Hutchings8ceee662008-04-27 12:55:59 +0100244 efx_rx_strategy(channel);
245
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000246 efx_fast_push_rx_descriptors(efx_channel_get_rx_queue(channel));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100247
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000248 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100249}
250
251/* Mark channel as finished processing
252 *
253 * Note that since we will not receive further interrupts for this
254 * channel before we finish processing and call the eventq_read_ack()
255 * method, there is no need to use the interrupt hold-off timers.
256 */
257static inline void efx_channel_processed(struct efx_channel *channel)
258{
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100259 /* The interrupt handler for this channel may set work_pending
260 * as soon as we acknowledge the events we've seen. Make sure
261 * it's cleared before then. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100262 channel->work_pending = false;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100263 smp_wmb();
264
Ben Hutchings152b6a62009-11-29 03:43:56 +0000265 efx_nic_eventq_read_ack(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100266}
267
268/* NAPI poll handler
269 *
270 * NAPI guarantees serialisation of polls of the same device, which
271 * provides the guarantee required by efx_process_channel().
272 */
273static int efx_poll(struct napi_struct *napi, int budget)
274{
275 struct efx_channel *channel =
276 container_of(napi, struct efx_channel, napi_str);
Ben Hutchings62776d02010-06-23 11:30:07 +0000277 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000278 int spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100279
Ben Hutchings62776d02010-06-23 11:30:07 +0000280 netif_vdbg(efx, intr, efx->net_dev,
281 "channel %d NAPI poll executing on CPU %d\n",
282 channel->channel, raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +0100283
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000284 spent = efx_process_channel(channel, budget);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100285
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000286 if (spent < budget) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000287 if (channel->channel < efx->n_rx_channels &&
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000288 efx->irq_rx_adaptive &&
289 unlikely(++channel->irq_count == 1000)) {
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000290 if (unlikely(channel->irq_mod_score <
291 irq_adapt_low_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000292 if (channel->irq_moderation > 1) {
293 channel->irq_moderation -= 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000294 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000295 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000296 } else if (unlikely(channel->irq_mod_score >
297 irq_adapt_high_thresh)) {
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000298 if (channel->irq_moderation <
299 efx->irq_rx_moderation) {
300 channel->irq_moderation += 1;
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000301 efx->type->push_irq_moderation(channel);
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000302 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000303 }
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000304 channel->irq_count = 0;
305 channel->irq_mod_score = 0;
306 }
307
Ben Hutchings8ceee662008-04-27 12:55:59 +0100308 /* There is no race here; although napi_disable() will
Ben Hutchings288379f2009-01-19 16:43:59 -0800309 * only wait for napi_complete(), this isn't a problem
Ben Hutchings8ceee662008-04-27 12:55:59 +0100310 * since efx_channel_processed() will have no effect if
311 * interrupts have already been disabled.
312 */
Ben Hutchings288379f2009-01-19 16:43:59 -0800313 napi_complete(napi);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100314 efx_channel_processed(channel);
315 }
316
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000317 return spent;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318}
319
320/* Process the eventq of the specified channel immediately on this CPU
321 *
322 * Disable hardware generated interrupts, wait for any existing
323 * processing to finish, then directly poll (and ack ) the eventq.
324 * Finally reenable NAPI and interrupts.
325 *
326 * Since we are touching interrupts the caller should hold the suspend lock
327 */
328void efx_process_channel_now(struct efx_channel *channel)
329{
330 struct efx_nic *efx = channel->efx;
331
Ben Hutchings8313aca2010-09-10 06:41:57 +0000332 BUG_ON(channel->channel >= efx->n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100333 BUG_ON(!channel->enabled);
334
335 /* Disable interrupts and wait for ISRs to complete */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000336 efx_nic_disable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100337 if (efx->legacy_irq)
338 synchronize_irq(efx->legacy_irq);
Ben Hutchings64ee3122008-09-01 12:47:38 +0100339 if (channel->irq)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100340 synchronize_irq(channel->irq);
341
342 /* Wait for any NAPI processing to complete */
343 napi_disable(&channel->napi_str);
344
345 /* Poll the channel */
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000346 efx_process_channel(channel, channel->eventq_mask + 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100347
348 /* Ack the eventq. This may cause an interrupt to be generated
349 * when they are reenabled */
350 efx_channel_processed(channel);
351
352 napi_enable(&channel->napi_str);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000353 efx_nic_enable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100354}
355
356/* Create event queue
357 * Event queue memory allocations are done only once. If the channel
358 * is reset, the memory buffer will be reused; this guards against
359 * errors during channel reset and also simplifies interrupt handling.
360 */
361static int efx_probe_eventq(struct efx_channel *channel)
362{
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000363 struct efx_nic *efx = channel->efx;
364 unsigned long entries;
365
Ben Hutchings62776d02010-06-23 11:30:07 +0000366 netif_dbg(channel->efx, probe, channel->efx->net_dev,
367 "chan %d create event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100368
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000369 /* Build an event queue with room for one event per tx and rx buffer,
370 * plus some extra for link state events and MCDI completions. */
371 entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
372 EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
373 channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
374
Ben Hutchings152b6a62009-11-29 03:43:56 +0000375 return efx_nic_probe_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100376}
377
378/* Prepare channel's event queue */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100379static void efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100380{
Ben Hutchings62776d02010-06-23 11:30:07 +0000381 netif_dbg(channel->efx, drv, channel->efx->net_dev,
382 "chan %d init event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100383
384 channel->eventq_read_ptr = 0;
385
Ben Hutchings152b6a62009-11-29 03:43:56 +0000386 efx_nic_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100387}
388
389static void efx_fini_eventq(struct efx_channel *channel)
390{
Ben Hutchings62776d02010-06-23 11:30:07 +0000391 netif_dbg(channel->efx, drv, channel->efx->net_dev,
392 "chan %d fini event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100393
Ben Hutchings152b6a62009-11-29 03:43:56 +0000394 efx_nic_fini_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100395}
396
397static void efx_remove_eventq(struct efx_channel *channel)
398{
Ben Hutchings62776d02010-06-23 11:30:07 +0000399 netif_dbg(channel->efx, drv, channel->efx->net_dev,
400 "chan %d remove event queue\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100401
Ben Hutchings152b6a62009-11-29 03:43:56 +0000402 efx_nic_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100403}
404
405/**************************************************************************
406 *
407 * Channel handling
408 *
409 *************************************************************************/
410
Ben Hutchings46426102010-09-10 06:42:33 +0000411/* Allocate and initialise a channel structure, optionally copying
412 * parameters (but not resources) from an old channel structure. */
413static struct efx_channel *
414efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
415{
416 struct efx_channel *channel;
417 struct efx_rx_queue *rx_queue;
418 struct efx_tx_queue *tx_queue;
419 int j;
420
421 if (old_channel) {
422 channel = kmalloc(sizeof(*channel), GFP_KERNEL);
423 if (!channel)
424 return NULL;
425
426 *channel = *old_channel;
427
428 memset(&channel->eventq, 0, sizeof(channel->eventq));
429
430 rx_queue = &channel->rx_queue;
431 rx_queue->buffer = NULL;
432 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
433
434 for (j = 0; j < EFX_TXQ_TYPES; j++) {
435 tx_queue = &channel->tx_queue[j];
436 if (tx_queue->channel)
437 tx_queue->channel = channel;
438 tx_queue->buffer = NULL;
439 memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
440 }
441 } else {
442 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
443 if (!channel)
444 return NULL;
445
446 channel->efx = efx;
447 channel->channel = i;
448
449 for (j = 0; j < EFX_TXQ_TYPES; j++) {
450 tx_queue = &channel->tx_queue[j];
451 tx_queue->efx = efx;
452 tx_queue->queue = i * EFX_TXQ_TYPES + j;
453 tx_queue->channel = channel;
454 }
455 }
456
457 spin_lock_init(&channel->tx_stop_lock);
458 atomic_set(&channel->tx_stop_count, 1);
459
460 rx_queue = &channel->rx_queue;
461 rx_queue->efx = efx;
462 setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
463 (unsigned long)rx_queue);
464
465 return channel;
466}
467
Ben Hutchings8ceee662008-04-27 12:55:59 +0100468static int efx_probe_channel(struct efx_channel *channel)
469{
470 struct efx_tx_queue *tx_queue;
471 struct efx_rx_queue *rx_queue;
472 int rc;
473
Ben Hutchings62776d02010-06-23 11:30:07 +0000474 netif_dbg(channel->efx, probe, channel->efx->net_dev,
475 "creating channel %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476
477 rc = efx_probe_eventq(channel);
478 if (rc)
479 goto fail1;
480
481 efx_for_each_channel_tx_queue(tx_queue, channel) {
482 rc = efx_probe_tx_queue(tx_queue);
483 if (rc)
484 goto fail2;
485 }
486
487 efx_for_each_channel_rx_queue(rx_queue, channel) {
488 rc = efx_probe_rx_queue(rx_queue);
489 if (rc)
490 goto fail3;
491 }
492
493 channel->n_rx_frm_trunc = 0;
494
495 return 0;
496
497 fail3:
498 efx_for_each_channel_rx_queue(rx_queue, channel)
499 efx_remove_rx_queue(rx_queue);
500 fail2:
501 efx_for_each_channel_tx_queue(tx_queue, channel)
502 efx_remove_tx_queue(tx_queue);
503 fail1:
504 return rc;
505}
506
507
Ben Hutchings56536e92008-12-12 21:37:02 -0800508static void efx_set_channel_names(struct efx_nic *efx)
509{
510 struct efx_channel *channel;
511 const char *type = "";
512 int number;
513
514 efx_for_each_channel(channel, efx) {
515 number = channel->channel;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000516 if (efx->n_channels > efx->n_rx_channels) {
517 if (channel->channel < efx->n_rx_channels) {
Ben Hutchings56536e92008-12-12 21:37:02 -0800518 type = "-rx";
519 } else {
520 type = "-tx";
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000521 number -= efx->n_rx_channels;
Ben Hutchings56536e92008-12-12 21:37:02 -0800522 }
523 }
Ben Hutchings46426102010-09-10 06:42:33 +0000524 snprintf(efx->channel_name[channel->channel],
525 sizeof(efx->channel_name[0]),
Ben Hutchings56536e92008-12-12 21:37:02 -0800526 "%s%s-%d", efx->name, type, number);
527 }
528}
529
Ben Hutchings46426102010-09-10 06:42:33 +0000530static int efx_probe_channels(struct efx_nic *efx)
531{
532 struct efx_channel *channel;
533 int rc;
534
535 /* Restart special buffer allocation */
536 efx->next_buffer_table = 0;
537
538 efx_for_each_channel(channel, efx) {
539 rc = efx_probe_channel(channel);
540 if (rc) {
541 netif_err(efx, probe, efx->net_dev,
542 "failed to create channel %d\n",
543 channel->channel);
544 goto fail;
545 }
546 }
547 efx_set_channel_names(efx);
548
549 return 0;
550
551fail:
552 efx_remove_channels(efx);
553 return rc;
554}
555
Ben Hutchings8ceee662008-04-27 12:55:59 +0100556/* Channels are shutdown and reinitialised whilst the NIC is running
557 * to propagate configuration changes (mtu, checksum offload), or
558 * to clear hardware error conditions
559 */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100560static void efx_init_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100561{
562 struct efx_tx_queue *tx_queue;
563 struct efx_rx_queue *rx_queue;
564 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100565
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100566 /* Calculate the rx buffer allocation parameters required to
567 * support the current MTU, including padding for header
568 * alignment and overruns.
569 */
570 efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
571 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
Ben Hutchings39c9cf02010-06-23 11:31:28 +0000572 efx->type->rx_buffer_hash_size +
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100573 efx->type->rx_buffer_padding);
Steve Hodgson62b330b2010-06-01 11:20:53 +0000574 efx->rx_buffer_order = get_order(efx->rx_buffer_len +
575 sizeof(struct efx_rx_page_state));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100576
577 /* Initialise the channels */
578 efx_for_each_channel(channel, efx) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000579 netif_dbg(channel->efx, drv, channel->efx->net_dev,
580 "init chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100581
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100582 efx_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100583
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100584 efx_for_each_channel_tx_queue(tx_queue, channel)
585 efx_init_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100586
587 /* The rx buffer allocation strategy is MTU dependent */
588 efx_rx_strategy(channel);
589
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100590 efx_for_each_channel_rx_queue(rx_queue, channel)
591 efx_init_rx_queue(rx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100592
593 WARN_ON(channel->rx_pkt != NULL);
594 efx_rx_strategy(channel);
595 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100596}
597
598/* This enables event queue processing and packet transmission.
599 *
600 * Note that this function is not allowed to fail, since that would
601 * introduce too much complexity into the suspend/resume path.
602 */
603static void efx_start_channel(struct efx_channel *channel)
604{
605 struct efx_rx_queue *rx_queue;
606
Ben Hutchings62776d02010-06-23 11:30:07 +0000607 netif_dbg(channel->efx, ifup, channel->efx->net_dev,
608 "starting chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100609
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100610 /* The interrupt handler for this channel may set work_pending
611 * as soon as we enable it. Make sure it's cleared before
612 * then. Similarly, make sure it sees the enabled flag set. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100613 channel->work_pending = false;
614 channel->enabled = true;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100615 smp_wmb();
Ben Hutchings8ceee662008-04-27 12:55:59 +0100616
Steve Hodgson90d683a2010-06-01 11:19:39 +0000617 /* Fill the queues before enabling NAPI */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100618 efx_for_each_channel_rx_queue(rx_queue, channel)
619 efx_fast_push_rx_descriptors(rx_queue);
Steve Hodgson90d683a2010-06-01 11:19:39 +0000620
621 napi_enable(&channel->napi_str);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100622}
623
624/* This disables event queue processing and packet transmission.
625 * This function does not guarantee that all queue processing
626 * (e.g. RX refill) is complete.
627 */
628static void efx_stop_channel(struct efx_channel *channel)
629{
Ben Hutchings8ceee662008-04-27 12:55:59 +0100630 if (!channel->enabled)
631 return;
632
Ben Hutchings62776d02010-06-23 11:30:07 +0000633 netif_dbg(channel->efx, ifdown, channel->efx->net_dev,
634 "stop chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100635
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100636 channel->enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100637 napi_disable(&channel->napi_str);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100638}
639
640static void efx_fini_channels(struct efx_nic *efx)
641{
642 struct efx_channel *channel;
643 struct efx_tx_queue *tx_queue;
644 struct efx_rx_queue *rx_queue;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100645 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100646
647 EFX_ASSERT_RESET_SERIALISED(efx);
648 BUG_ON(efx->port_enabled);
649
Ben Hutchings152b6a62009-11-29 03:43:56 +0000650 rc = efx_nic_flush_queues(efx);
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000651 if (rc && EFX_WORKAROUND_7803(efx)) {
652 /* Schedule a reset to recover from the flush failure. The
653 * descriptor caches reference memory we're about to free,
654 * but falcon_reconfigure_mac_wrapper() won't reconnect
655 * the MACs because of the pending reset. */
Ben Hutchings62776d02010-06-23 11:30:07 +0000656 netif_err(efx, drv, efx->net_dev,
657 "Resetting to recover from flush failure\n");
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000658 efx_schedule_reset(efx, RESET_TYPE_ALL);
659 } else if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000660 netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000661 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000662 netif_dbg(efx, drv, efx->net_dev,
663 "successfully flushed all queues\n");
Steve Hodgsonfd371e32010-06-01 11:17:51 +0000664 }
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100665
Ben Hutchings8ceee662008-04-27 12:55:59 +0100666 efx_for_each_channel(channel, efx) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000667 netif_dbg(channel->efx, drv, channel->efx->net_dev,
668 "shut down chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100669
670 efx_for_each_channel_rx_queue(rx_queue, channel)
671 efx_fini_rx_queue(rx_queue);
672 efx_for_each_channel_tx_queue(tx_queue, channel)
673 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100674 efx_fini_eventq(channel);
675 }
676}
677
678static void efx_remove_channel(struct efx_channel *channel)
679{
680 struct efx_tx_queue *tx_queue;
681 struct efx_rx_queue *rx_queue;
682
Ben Hutchings62776d02010-06-23 11:30:07 +0000683 netif_dbg(channel->efx, drv, channel->efx->net_dev,
684 "destroy chan %d\n", channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100685
686 efx_for_each_channel_rx_queue(rx_queue, channel)
687 efx_remove_rx_queue(rx_queue);
688 efx_for_each_channel_tx_queue(tx_queue, channel)
689 efx_remove_tx_queue(tx_queue);
690 efx_remove_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100691}
692
Ben Hutchings46426102010-09-10 06:42:33 +0000693static void efx_remove_channels(struct efx_nic *efx)
694{
695 struct efx_channel *channel;
696
697 efx_for_each_channel(channel, efx)
698 efx_remove_channel(channel);
699}
700
701int
702efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
703{
704 struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
705 u32 old_rxq_entries, old_txq_entries;
706 unsigned i;
707 int rc;
708
709 efx_stop_all(efx);
710 efx_fini_channels(efx);
711
712 /* Clone channels */
713 memset(other_channel, 0, sizeof(other_channel));
714 for (i = 0; i < efx->n_channels; i++) {
715 channel = efx_alloc_channel(efx, i, efx->channel[i]);
716 if (!channel) {
717 rc = -ENOMEM;
718 goto out;
719 }
720 other_channel[i] = channel;
721 }
722
723 /* Swap entry counts and channel pointers */
724 old_rxq_entries = efx->rxq_entries;
725 old_txq_entries = efx->txq_entries;
726 efx->rxq_entries = rxq_entries;
727 efx->txq_entries = txq_entries;
728 for (i = 0; i < efx->n_channels; i++) {
729 channel = efx->channel[i];
730 efx->channel[i] = other_channel[i];
731 other_channel[i] = channel;
732 }
733
734 rc = efx_probe_channels(efx);
735 if (rc)
736 goto rollback;
737
738 /* Destroy old channels */
739 for (i = 0; i < efx->n_channels; i++)
740 efx_remove_channel(other_channel[i]);
741out:
742 /* Free unused channel structures */
743 for (i = 0; i < efx->n_channels; i++)
744 kfree(other_channel[i]);
745
746 efx_init_channels(efx);
747 efx_start_all(efx);
748 return rc;
749
750rollback:
751 /* Swap back */
752 efx->rxq_entries = old_rxq_entries;
753 efx->txq_entries = old_txq_entries;
754 for (i = 0; i < efx->n_channels; i++) {
755 channel = efx->channel[i];
756 efx->channel[i] = other_channel[i];
757 other_channel[i] = channel;
758 }
759 goto out;
760}
761
Steve Hodgson90d683a2010-06-01 11:19:39 +0000762void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100763{
Steve Hodgson90d683a2010-06-01 11:19:39 +0000764 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100765}
766
767/**************************************************************************
768 *
769 * Port handling
770 *
771 **************************************************************************/
772
773/* This ensures that the kernel is kept informed (via
774 * netif_carrier_on/off) of the link status, and also maintains the
775 * link status's stop on the port's TX queue.
776 */
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000777void efx_link_status_changed(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100778{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000779 struct efx_link_state *link_state = &efx->link_state;
780
Ben Hutchings8ceee662008-04-27 12:55:59 +0100781 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
782 * that no events are triggered between unregister_netdev() and the
783 * driver unloading. A more general condition is that NETDEV_CHANGE
784 * can only be generated between NETDEV_UP and NETDEV_DOWN */
785 if (!netif_running(efx->net_dev))
786 return;
787
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100788 if (efx->port_inhibited) {
789 netif_carrier_off(efx->net_dev);
790 return;
791 }
792
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000793 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100794 efx->n_link_state_changes++;
795
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000796 if (link_state->up)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100797 netif_carrier_on(efx->net_dev);
798 else
799 netif_carrier_off(efx->net_dev);
800 }
801
802 /* Status message for kernel log */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000803 if (link_state->up) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000804 netif_info(efx, link, efx->net_dev,
805 "link up at %uMbps %s-duplex (MTU %d)%s\n",
806 link_state->speed, link_state->fd ? "full" : "half",
807 efx->net_dev->mtu,
808 (efx->promiscuous ? " [PROMISC]" : ""));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100809 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000810 netif_info(efx, link, efx->net_dev, "link down\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100811 }
812
813}
814
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000815void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
816{
817 efx->link_advertising = advertising;
818 if (advertising) {
819 if (advertising & ADVERTISED_Pause)
820 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
821 else
822 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
823 if (advertising & ADVERTISED_Asym_Pause)
824 efx->wanted_fc ^= EFX_FC_TX;
825 }
826}
827
828void efx_link_set_wanted_fc(struct efx_nic *efx, enum efx_fc_type wanted_fc)
829{
830 efx->wanted_fc = wanted_fc;
831 if (efx->link_advertising) {
832 if (wanted_fc & EFX_FC_RX)
833 efx->link_advertising |= (ADVERTISED_Pause |
834 ADVERTISED_Asym_Pause);
835 else
836 efx->link_advertising &= ~(ADVERTISED_Pause |
837 ADVERTISED_Asym_Pause);
838 if (wanted_fc & EFX_FC_TX)
839 efx->link_advertising ^= ADVERTISED_Asym_Pause;
840 }
841}
842
Ben Hutchings115122a2009-03-04 09:52:52 +0000843static void efx_fini_port(struct efx_nic *efx);
844
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000845/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
846 * the MAC appropriately. All other PHY configuration changes are pushed
847 * through phy_op->set_settings(), and pushed asynchronously to the MAC
848 * through efx_monitor().
849 *
850 * Callers must hold the mac_lock
851 */
852int __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100853{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000854 enum efx_phy_mode phy_mode;
855 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100856
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000857 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100858
Ben Hutchingsa816f752008-09-01 12:49:12 +0100859 /* Serialise the promiscuous flag with efx_set_multicast_list. */
860 if (efx_dev_registered(efx)) {
861 netif_addr_lock_bh(efx->net_dev);
862 netif_addr_unlock_bh(efx->net_dev);
863 }
864
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000865 /* Disable PHY transmit in mac level loopbacks */
866 phy_mode = efx->phy_mode;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800867 if (LOOPBACK_INTERNAL(efx))
868 efx->phy_mode |= PHY_MODE_TX_DISABLED;
869 else
870 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800871
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000872 rc = efx->type->reconfigure_port(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800873
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000874 if (rc)
875 efx->phy_mode = phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100876
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000877 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100878}
879
880/* Reinitialise the MAC to pick up new PHY settings, even if the port is
881 * disabled. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000882int efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100883{
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000884 int rc;
885
Ben Hutchings8ceee662008-04-27 12:55:59 +0100886 EFX_ASSERT_RESET_SERIALISED(efx);
887
888 mutex_lock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000889 rc = __efx_reconfigure_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100890 mutex_unlock(&efx->mac_lock);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000891
892 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100893}
894
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000895/* Asynchronous work item for changing MAC promiscuity and multicast
896 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
897 * MAC directly. */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800898static void efx_mac_work(struct work_struct *data)
899{
900 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
901
902 mutex_lock(&efx->mac_lock);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000903 if (efx->port_enabled) {
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000904 efx->type->push_multicast_hash(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000905 efx->mac_op->reconfigure(efx);
906 }
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800907 mutex_unlock(&efx->mac_lock);
908}
909
Ben Hutchings8ceee662008-04-27 12:55:59 +0100910static int efx_probe_port(struct efx_nic *efx)
911{
Ben Hutchings7e300bc2010-12-02 13:48:28 +0000912 unsigned char *perm_addr;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100913 int rc;
914
Ben Hutchings62776d02010-06-23 11:30:07 +0000915 netif_dbg(efx, probe, efx->net_dev, "create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100916
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000917 if (phy_flash_cfg)
918 efx->phy_mode = PHY_MODE_SPECIAL;
919
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000920 /* Connect up MAC/PHY operations table */
921 rc = efx->type->probe_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100922 if (rc)
Ben Hutchingse42de262010-09-10 06:41:19 +0000923 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100924
925 /* Sanity check MAC address */
Ben Hutchings7e300bc2010-12-02 13:48:28 +0000926 perm_addr = efx->net_dev->perm_addr;
927 if (is_valid_ether_addr(perm_addr)) {
928 memcpy(efx->net_dev->dev_addr, perm_addr, ETH_ALEN);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100929 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000930 netif_err(efx, probe, efx->net_dev, "invalid MAC address %pM\n",
Ben Hutchings7e300bc2010-12-02 13:48:28 +0000931 perm_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100932 if (!allow_bad_hwaddr) {
933 rc = -EINVAL;
934 goto err;
935 }
936 random_ether_addr(efx->net_dev->dev_addr);
Ben Hutchings62776d02010-06-23 11:30:07 +0000937 netif_info(efx, probe, efx->net_dev,
938 "using locally-generated MAC %pM\n",
939 efx->net_dev->dev_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100940 }
941
942 return 0;
943
944 err:
Ben Hutchingse42de262010-09-10 06:41:19 +0000945 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100946 return rc;
947}
948
949static int efx_init_port(struct efx_nic *efx)
950{
951 int rc;
952
Ben Hutchings62776d02010-06-23 11:30:07 +0000953 netif_dbg(efx, drv, efx->net_dev, "init port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100954
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000955 mutex_lock(&efx->mac_lock);
956
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800957 rc = efx->phy_op->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100958 if (rc)
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000959 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100960
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100961 efx->port_initialized = true;
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000962
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000963 /* Reconfigure the MAC before creating dma queues (required for
964 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
965 efx->mac_op->reconfigure(efx);
966
967 /* Ensure the PHY advertises the correct flow control settings */
968 rc = efx->phy_op->reconfigure(efx);
969 if (rc)
970 goto fail2;
971
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000972 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100973 return 0;
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800974
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000975fail2:
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800976 efx->phy_op->fini(efx);
Ben Hutchings1dfc5ce2009-11-25 16:11:19 +0000977fail1:
978 mutex_unlock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800979 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100980}
981
Ben Hutchings8ceee662008-04-27 12:55:59 +0100982static void efx_start_port(struct efx_nic *efx)
983{
Ben Hutchings62776d02010-06-23 11:30:07 +0000984 netif_dbg(efx, ifup, efx->net_dev, "start port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100985 BUG_ON(efx->port_enabled);
986
987 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100988 efx->port_enabled = true;
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000989
990 /* efx_mac_work() might have been scheduled after efx_stop_port(),
991 * and then cancelled by efx_flush_all() */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000992 efx->type->push_multicast_hash(efx);
Ben Hutchings8be4f3e2009-11-25 16:12:16 +0000993 efx->mac_op->reconfigure(efx);
994
Ben Hutchings8ceee662008-04-27 12:55:59 +0100995 mutex_unlock(&efx->mac_lock);
996}
997
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000998/* Prevent efx_mac_work() and efx_monitor() from working */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100999static void efx_stop_port(struct efx_nic *efx)
1000{
Ben Hutchings62776d02010-06-23 11:30:07 +00001001 netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001002
1003 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001004 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001005 mutex_unlock(&efx->mac_lock);
1006
1007 /* Serialise against efx_set_multicast_list() */
Ben Hutchings55668612008-05-16 21:16:10 +01001008 if (efx_dev_registered(efx)) {
David S. Millerb9e40852008-07-15 00:15:08 -07001009 netif_addr_lock_bh(efx->net_dev);
1010 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001011 }
1012}
1013
1014static void efx_fini_port(struct efx_nic *efx)
1015{
Ben Hutchings62776d02010-06-23 11:30:07 +00001016 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001017
1018 if (!efx->port_initialized)
1019 return;
1020
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001021 efx->phy_op->fini(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001022 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001023
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001024 efx->link_state.up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001025 efx_link_status_changed(efx);
1026}
1027
1028static void efx_remove_port(struct efx_nic *efx)
1029{
Ben Hutchings62776d02010-06-23 11:30:07 +00001030 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001031
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001032 efx->type->remove_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001033}
1034
1035/**************************************************************************
1036 *
1037 * NIC handling
1038 *
1039 **************************************************************************/
1040
1041/* This configures the PCI device to enable I/O and DMA. */
1042static int efx_init_io(struct efx_nic *efx)
1043{
1044 struct pci_dev *pci_dev = efx->pci_dev;
1045 dma_addr_t dma_mask = efx->type->max_dma_mask;
1046 int rc;
1047
Ben Hutchings62776d02010-06-23 11:30:07 +00001048 netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001049
1050 rc = pci_enable_device(pci_dev);
1051 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001052 netif_err(efx, probe, efx->net_dev,
1053 "failed to enable PCI device\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001054 goto fail1;
1055 }
1056
1057 pci_set_master(pci_dev);
1058
1059 /* Set the PCI DMA mask. Try all possibilities from our
1060 * genuine mask down to 32 bits, because some architectures
1061 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1062 * masks event though they reject 46 bit masks.
1063 */
1064 while (dma_mask > 0x7fffffffUL) {
1065 if (pci_dma_supported(pci_dev, dma_mask) &&
1066 ((rc = pci_set_dma_mask(pci_dev, dma_mask)) == 0))
1067 break;
1068 dma_mask >>= 1;
1069 }
1070 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001071 netif_err(efx, probe, efx->net_dev,
1072 "could not find a suitable DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001073 goto fail2;
1074 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001075 netif_dbg(efx, probe, efx->net_dev,
1076 "using DMA mask %llx\n", (unsigned long long) dma_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001077 rc = pci_set_consistent_dma_mask(pci_dev, dma_mask);
1078 if (rc) {
1079 /* pci_set_consistent_dma_mask() is not *allowed* to
1080 * fail with a mask that pci_set_dma_mask() accepted,
1081 * but just in case...
1082 */
Ben Hutchings62776d02010-06-23 11:30:07 +00001083 netif_err(efx, probe, efx->net_dev,
1084 "failed to set consistent DMA mask\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001085 goto fail2;
1086 }
1087
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001088 efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
1089 rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001091 netif_err(efx, probe, efx->net_dev,
1092 "request for memory BAR failed\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001093 rc = -EIO;
1094 goto fail3;
1095 }
1096 efx->membase = ioremap_nocache(efx->membase_phys,
1097 efx->type->mem_map_size);
1098 if (!efx->membase) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001099 netif_err(efx, probe, efx->net_dev,
1100 "could not map memory BAR at %llx+%x\n",
1101 (unsigned long long)efx->membase_phys,
1102 efx->type->mem_map_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001103 rc = -ENOMEM;
1104 goto fail4;
1105 }
Ben Hutchings62776d02010-06-23 11:30:07 +00001106 netif_dbg(efx, probe, efx->net_dev,
1107 "memory BAR at %llx+%x (virtual %p)\n",
1108 (unsigned long long)efx->membase_phys,
1109 efx->type->mem_map_size, efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001110
1111 return 0;
1112
1113 fail4:
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001114 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001115 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +01001116 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001117 fail2:
1118 pci_disable_device(efx->pci_dev);
1119 fail1:
1120 return rc;
1121}
1122
1123static void efx_fini_io(struct efx_nic *efx)
1124{
Ben Hutchings62776d02010-06-23 11:30:07 +00001125 netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001126
1127 if (efx->membase) {
1128 iounmap(efx->membase);
1129 efx->membase = NULL;
1130 }
1131
1132 if (efx->membase_phys) {
Ben Hutchingsdc803df2009-10-23 08:32:33 +00001133 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
Ben Hutchings2c118e02008-05-16 21:15:29 +01001134 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001135 }
1136
1137 pci_disable_device(efx->pci_dev);
1138}
1139
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001140/* Get number of channels wanted. Each channel will have its own IRQ,
1141 * 1 RX queue and/or 2 TX queues. */
1142static int efx_wanted_channels(void)
Ben Hutchings46123d02008-09-01 12:47:33 +01001143{
Rusty Russell2f8975f2009-01-10 21:58:09 -08001144 cpumask_var_t core_mask;
Ben Hutchings46123d02008-09-01 12:47:33 +01001145 int count;
1146 int cpu;
1147
Li Zefan79f55992009-06-15 14:58:26 +08001148 if (unlikely(!zalloc_cpumask_var(&core_mask, GFP_KERNEL))) {
Rusty Russell2f8975f2009-01-10 21:58:09 -08001149 printk(KERN_WARNING
Mike Travis3977d032009-05-12 10:48:36 +00001150 "sfc: RSS disabled due to allocation failure\n");
Rusty Russell2f8975f2009-01-10 21:58:09 -08001151 return 1;
1152 }
1153
Ben Hutchings46123d02008-09-01 12:47:33 +01001154 count = 0;
1155 for_each_online_cpu(cpu) {
Rusty Russell2f8975f2009-01-10 21:58:09 -08001156 if (!cpumask_test_cpu(cpu, core_mask)) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001157 ++count;
Rusty Russell2f8975f2009-01-10 21:58:09 -08001158 cpumask_or(core_mask, core_mask,
Rusty Russellfbd59a82009-01-10 21:58:08 -08001159 topology_core_cpumask(cpu));
Ben Hutchings46123d02008-09-01 12:47:33 +01001160 }
1161 }
1162
Rusty Russell2f8975f2009-01-10 21:58:09 -08001163 free_cpumask_var(core_mask);
Ben Hutchings46123d02008-09-01 12:47:33 +01001164 return count;
1165}
1166
1167/* Probe the number and type of interrupts we are able to obtain, and
1168 * the resulting numbers of channels and RX queues.
1169 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001170static void efx_probe_interrupts(struct efx_nic *efx)
1171{
Ben Hutchings46123d02008-09-01 12:47:33 +01001172 int max_channels =
1173 min_t(int, efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001174 int rc, i;
1175
1176 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +01001177 struct msix_entry xentries[EFX_MAX_CHANNELS];
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001178 int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001179
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001180 n_channels = efx_wanted_channels();
1181 if (separate_tx_channels)
1182 n_channels *= 2;
1183 n_channels = min(n_channels, max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +01001184
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001185 for (i = 0; i < n_channels; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001186 xentries[i].entry = i;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001187 rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001188 if (rc > 0) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001189 netif_err(efx, drv, efx->net_dev,
1190 "WARNING: Insufficient MSI-X vectors"
1191 " available (%d < %d).\n", rc, n_channels);
1192 netif_err(efx, drv, efx->net_dev,
1193 "WARNING: Performance may be reduced.\n");
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001194 EFX_BUG_ON_PARANOID(rc >= n_channels);
1195 n_channels = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001196 rc = pci_enable_msix(efx->pci_dev, xentries,
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001197 n_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001198 }
1199
1200 if (rc == 0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001201 efx->n_channels = n_channels;
1202 if (separate_tx_channels) {
1203 efx->n_tx_channels =
1204 max(efx->n_channels / 2, 1U);
1205 efx->n_rx_channels =
1206 max(efx->n_channels -
1207 efx->n_tx_channels, 1U);
1208 } else {
1209 efx->n_tx_channels = efx->n_channels;
1210 efx->n_rx_channels = efx->n_channels;
1211 }
1212 for (i = 0; i < n_channels; i++)
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001213 efx_get_channel(efx, i)->irq =
1214 xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001215 } else {
1216 /* Fall back to single channel MSI */
1217 efx->interrupt_mode = EFX_INT_MODE_MSI;
Ben Hutchings62776d02010-06-23 11:30:07 +00001218 netif_err(efx, drv, efx->net_dev,
1219 "could not enable MSI-X\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001220 }
1221 }
1222
1223 /* Try single interrupt MSI */
1224 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Neil Turton28b581a2008-12-12 21:41:06 -08001225 efx->n_channels = 1;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001226 efx->n_rx_channels = 1;
1227 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001228 rc = pci_enable_msi(efx->pci_dev);
1229 if (rc == 0) {
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001230 efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001231 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00001232 netif_err(efx, drv, efx->net_dev,
1233 "could not enable MSI\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001234 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
1235 }
1236 }
1237
1238 /* Assume legacy interrupts */
1239 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Neil Turton28b581a2008-12-12 21:41:06 -08001240 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001241 efx->n_rx_channels = 1;
1242 efx->n_tx_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001243 efx->legacy_irq = efx->pci_dev->irq;
1244 }
1245}
1246
1247static void efx_remove_interrupts(struct efx_nic *efx)
1248{
1249 struct efx_channel *channel;
1250
1251 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001252 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001253 channel->irq = 0;
1254 pci_disable_msi(efx->pci_dev);
1255 pci_disable_msix(efx->pci_dev);
1256
1257 /* Remove legacy interrupt */
1258 efx->legacy_irq = 0;
1259}
1260
Ben Hutchings8313aca2010-09-10 06:41:57 +00001261struct efx_tx_queue *
1262efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
1263{
1264 unsigned tx_channel_offset =
1265 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
1266 EFX_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
1267 type >= EFX_TXQ_TYPES);
1268 return &efx->channel[tx_channel_offset + index]->tx_queue[type];
1269}
1270
Ben Hutchings8831da72008-09-01 12:47:48 +01001271static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001272{
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001273 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001274 struct efx_tx_queue *tx_queue;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001275 unsigned tx_channel_offset =
1276 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001277
Ben Hutchings8313aca2010-09-10 06:41:57 +00001278 /* Channel pointers were set in efx_init_struct() but we now
1279 * need to clear them for TX queues in any RX-only channels. */
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001280 efx_for_each_channel(channel, efx) {
Ben Hutchings8313aca2010-09-10 06:41:57 +00001281 if (channel->channel - tx_channel_offset >=
1282 efx->n_tx_channels) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001283 efx_for_each_channel_tx_queue(tx_queue, channel)
Ben Hutchings8313aca2010-09-10 06:41:57 +00001284 tx_queue->channel = NULL;
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001285 }
Ben Hutchings60ac1062008-09-01 12:44:59 +01001286 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001287}
1288
1289static int efx_probe_nic(struct efx_nic *efx)
1290{
Ben Hutchings765c9f42010-06-30 05:06:28 +00001291 size_t i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001292 int rc;
1293
Ben Hutchings62776d02010-06-23 11:30:07 +00001294 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001295
1296 /* Carry out hardware-type specific initialisation */
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001297 rc = efx->type->probe(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001298 if (rc)
1299 return rc;
1300
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001301 /* Determine the number of channels and queues by trying to hook
Ben Hutchings8ceee662008-04-27 12:55:59 +01001302 * in MSI-X interrupts. */
1303 efx_probe_interrupts(efx);
1304
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001305 if (efx->n_channels > 1)
1306 get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001307 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
1308 efx->rx_indir_table[i] = i % efx->n_rx_channels;
Ben Hutchings5d3a6fc2010-06-25 07:05:43 +00001309
Ben Hutchings8831da72008-09-01 12:47:48 +01001310 efx_set_channels(efx);
Ben Hutchingsc4f4adc2010-09-27 08:31:07 +00001311 netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1312 netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001313
1314 /* Initialise the interrupt moderation settings */
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001315 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001316
1317 return 0;
1318}
1319
1320static void efx_remove_nic(struct efx_nic *efx)
1321{
Ben Hutchings62776d02010-06-23 11:30:07 +00001322 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001323
1324 efx_remove_interrupts(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001325 efx->type->remove(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001326}
1327
1328/**************************************************************************
1329 *
1330 * NIC startup/shutdown
1331 *
1332 *************************************************************************/
1333
1334static int efx_probe_all(struct efx_nic *efx)
1335{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001336 int rc;
1337
Ben Hutchings8ceee662008-04-27 12:55:59 +01001338 rc = efx_probe_nic(efx);
1339 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001340 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001341 goto fail1;
1342 }
1343
Ben Hutchings8ceee662008-04-27 12:55:59 +01001344 rc = efx_probe_port(efx);
1345 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001346 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001347 goto fail2;
1348 }
1349
Steve Hodgsonecc910f2010-09-10 06:42:22 +00001350 efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
Ben Hutchings46426102010-09-10 06:42:33 +00001351 rc = efx_probe_channels(efx);
1352 if (rc)
1353 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001354
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001355 rc = efx_probe_filters(efx);
1356 if (rc) {
1357 netif_err(efx, probe, efx->net_dev,
1358 "failed to create filter tables\n");
1359 goto fail4;
1360 }
1361
Ben Hutchings8ceee662008-04-27 12:55:59 +01001362 return 0;
1363
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001364 fail4:
1365 efx_remove_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001366 fail3:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001367 efx_remove_port(efx);
1368 fail2:
1369 efx_remove_nic(efx);
1370 fail1:
1371 return rc;
1372}
1373
1374/* Called after previous invocation(s) of efx_stop_all, restarts the
1375 * port, kernel transmit queue, NAPI processing and hardware interrupts,
1376 * and ensures that the port is scheduled to be reconfigured.
1377 * This function is safe to call multiple times when the NIC is in any
1378 * state. */
1379static void efx_start_all(struct efx_nic *efx)
1380{
1381 struct efx_channel *channel;
1382
1383 EFX_ASSERT_RESET_SERIALISED(efx);
1384
1385 /* Check that it is appropriate to restart the interface. All
1386 * of these flags are safe to read under just the rtnl lock */
1387 if (efx->port_enabled)
1388 return;
1389 if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT))
1390 return;
Ben Hutchings55668612008-05-16 21:16:10 +01001391 if (efx_dev_registered(efx) && !netif_running(efx->net_dev))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001392 return;
1393
1394 /* Mark the port as enabled so port reconfigurations can start, then
1395 * restart the transmit interface early so the watchdog timer stops */
1396 efx_start_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001397
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001398 efx_for_each_channel(channel, efx) {
1399 if (efx_dev_registered(efx))
1400 efx_wake_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001401 efx_start_channel(channel);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001402 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001403
Ben Hutchings152b6a62009-11-29 03:43:56 +00001404 efx_nic_enable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001405
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001406 /* Switch to event based MCDI completions after enabling interrupts.
1407 * If a reset has been scheduled, then we need to stay in polled mode.
1408 * Rather than serialising efx_mcdi_mode_event() [which sleeps] and
1409 * reset_pending [modified from an atomic context], we instead guarantee
1410 * that efx_mcdi_mode_poll() isn't reverted erroneously */
1411 efx_mcdi_mode_event(efx);
1412 if (efx->reset_pending != RESET_TYPE_NONE)
1413 efx_mcdi_mode_poll(efx);
1414
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001415 /* Start the hardware monitor if there is one. Otherwise (we're link
1416 * event driven), we have to poll the PHY because after an event queue
1417 * flush, we could have a missed a link state change */
1418 if (efx->type->monitor != NULL) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001419 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1420 efx_monitor_interval);
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001421 } else {
1422 mutex_lock(&efx->mac_lock);
1423 if (efx->phy_op->poll(efx))
1424 efx_link_status_changed(efx);
1425 mutex_unlock(&efx->mac_lock);
1426 }
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001427
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001428 efx->type->start_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001429}
1430
1431/* Flush all delayed work. Should only be called when no more delayed work
1432 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1433 * since we're holding the rtnl_lock at this point. */
1434static void efx_flush_all(struct efx_nic *efx)
1435{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001436 /* Make sure the hardware monitor is stopped */
1437 cancel_delayed_work_sync(&efx->monitor_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001438 /* Stop scheduled port reconfigurations */
Ben Hutchings766ca0f2008-12-12 21:59:24 -08001439 cancel_work_sync(&efx->mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001440}
1441
1442/* Quiesce hardware and software without bringing the link down.
1443 * Safe to call multiple times, when the nic and interface is in any
1444 * state. The caller is guaranteed to subsequently be in a position
1445 * to modify any hardware and software state they see fit without
1446 * taking locks. */
1447static void efx_stop_all(struct efx_nic *efx)
1448{
1449 struct efx_channel *channel;
1450
1451 EFX_ASSERT_RESET_SERIALISED(efx);
1452
1453 /* port_enabled can be read safely under the rtnl lock */
1454 if (!efx->port_enabled)
1455 return;
1456
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001457 efx->type->stop_stats(efx);
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001458
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001459 /* Switch to MCDI polling on Siena before disabling interrupts */
1460 efx_mcdi_mode_poll(efx);
1461
Ben Hutchings8ceee662008-04-27 12:55:59 +01001462 /* Disable interrupts and wait for ISR to complete */
Ben Hutchings152b6a62009-11-29 03:43:56 +00001463 efx_nic_disable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001464 if (efx->legacy_irq)
1465 synchronize_irq(efx->legacy_irq);
Ben Hutchings64ee3122008-09-01 12:47:38 +01001466 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001467 if (channel->irq)
1468 synchronize_irq(channel->irq);
Ben Hutchingsb3475642008-05-16 21:15:49 +01001469 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001470
1471 /* Stop all NAPI processing and synchronous rx refills */
1472 efx_for_each_channel(channel, efx)
1473 efx_stop_channel(channel);
1474
1475 /* Stop all asynchronous port reconfigurations. Since all
1476 * event processing has already been stopped, there is no
1477 * window to loose phy events */
1478 efx_stop_port(efx);
1479
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00001480 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001481 efx_flush_all(efx);
1482
Ben Hutchings8ceee662008-04-27 12:55:59 +01001483 /* Stop the kernel transmit interface late, so the watchdog
1484 * timer isn't ticking over the flush */
Ben Hutchings55668612008-05-16 21:16:10 +01001485 if (efx_dev_registered(efx)) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001486 struct efx_channel *channel;
1487 efx_for_each_channel(channel, efx)
1488 efx_stop_queue(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001489 netif_tx_lock_bh(efx->net_dev);
1490 netif_tx_unlock_bh(efx->net_dev);
1491 }
1492}
1493
1494static void efx_remove_all(struct efx_nic *efx)
1495{
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001496 efx_remove_filters(efx);
Ben Hutchings46426102010-09-10 06:42:33 +00001497 efx_remove_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001498 efx_remove_port(efx);
1499 efx_remove_nic(efx);
1500}
1501
Ben Hutchings8ceee662008-04-27 12:55:59 +01001502/**************************************************************************
1503 *
1504 * Interrupt moderation
1505 *
1506 **************************************************************************/
1507
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001508static unsigned irq_mod_ticks(int usecs, int resolution)
1509{
1510 if (usecs <= 0)
1511 return 0; /* cannot receive interrupts ahead of time :-) */
1512 if (usecs < resolution)
1513 return 1; /* never round down to 0 */
1514 return usecs / resolution;
1515}
1516
Ben Hutchings8ceee662008-04-27 12:55:59 +01001517/* Set interrupt moderation parameters */
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001518void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs,
1519 bool rx_adaptive)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001520{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001521 struct efx_channel *channel;
Ben Hutchings152b6a62009-11-29 03:43:56 +00001522 unsigned tx_ticks = irq_mod_ticks(tx_usecs, EFX_IRQ_MOD_RESOLUTION);
1523 unsigned rx_ticks = irq_mod_ticks(rx_usecs, EFX_IRQ_MOD_RESOLUTION);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001524
1525 EFX_ASSERT_RESET_SERIALISED(efx);
1526
Ben Hutchings6fb70fd2009-03-20 13:30:37 +00001527 efx->irq_rx_adaptive = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001528 efx->irq_rx_moderation = rx_ticks;
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001529 efx_for_each_channel(channel, efx) {
1530 if (efx_channel_get_rx_queue(channel))
1531 channel->irq_moderation = rx_ticks;
1532 else if (efx_channel_get_tx_queue(channel, 0))
1533 channel->irq_moderation = tx_ticks;
1534 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001535}
1536
1537/**************************************************************************
1538 *
1539 * Hardware monitor
1540 *
1541 **************************************************************************/
1542
Ben Hutchingse254c272010-09-20 08:44:10 +00001543/* Run periodically off the general workqueue */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001544static void efx_monitor(struct work_struct *data)
1545{
1546 struct efx_nic *efx = container_of(data, struct efx_nic,
1547 monitor_work.work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001548
Ben Hutchings62776d02010-06-23 11:30:07 +00001549 netif_vdbg(efx, timer, efx->net_dev,
1550 "hardware monitor executing on CPU %d\n",
1551 raw_smp_processor_id());
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001552 BUG_ON(efx->type->monitor == NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001553
Ben Hutchings8ceee662008-04-27 12:55:59 +01001554 /* If the mac_lock is already held then it is likely a port
1555 * reconfiguration is already in place, which will likely do
Ben Hutchingse254c272010-09-20 08:44:10 +00001556 * most of the work of monitor() anyway. */
1557 if (mutex_trylock(&efx->mac_lock)) {
1558 if (efx->port_enabled)
1559 efx->type->monitor(efx);
1560 mutex_unlock(&efx->mac_lock);
1561 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001562
Ben Hutchings8ceee662008-04-27 12:55:59 +01001563 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1564 efx_monitor_interval);
1565}
1566
1567/**************************************************************************
1568 *
1569 * ioctls
1570 *
1571 *************************************************************************/
1572
1573/* Net device ioctl
1574 * Context: process, rtnl_lock() held.
1575 */
1576static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1577{
Ben Hutchings767e4682008-09-01 12:43:14 +01001578 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings68e7f452009-04-29 08:05:08 +00001579 struct mii_ioctl_data *data = if_mii(ifr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001580
1581 EFX_ASSERT_RESET_SERIALISED(efx);
1582
Ben Hutchings68e7f452009-04-29 08:05:08 +00001583 /* Convert phy_id from older PRTAD/DEVAD format */
1584 if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
1585 (data->phy_id & 0xfc00) == 0x0400)
1586 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
1587
1588 return mdio_mii_ioctl(&efx->mdio, data, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001589}
1590
1591/**************************************************************************
1592 *
1593 * NAPI interface
1594 *
1595 **************************************************************************/
1596
1597static int efx_init_napi(struct efx_nic *efx)
1598{
1599 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001600
1601 efx_for_each_channel(channel, efx) {
1602 channel->napi_dev = efx->net_dev;
Ben Hutchings718cff12009-04-14 19:47:46 -07001603 netif_napi_add(channel->napi_dev, &channel->napi_str,
1604 efx_poll, napi_weight);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001605 }
1606 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001607}
1608
1609static void efx_fini_napi(struct efx_nic *efx)
1610{
1611 struct efx_channel *channel;
1612
1613 efx_for_each_channel(channel, efx) {
Ben Hutchings718cff12009-04-14 19:47:46 -07001614 if (channel->napi_dev)
1615 netif_napi_del(&channel->napi_str);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001616 channel->napi_dev = NULL;
1617 }
1618}
1619
1620/**************************************************************************
1621 *
1622 * Kernel netpoll interface
1623 *
1624 *************************************************************************/
1625
1626#ifdef CONFIG_NET_POLL_CONTROLLER
1627
1628/* Although in the common case interrupts will be disabled, this is not
1629 * guaranteed. However, all our work happens inside the NAPI callback,
1630 * so no locking is required.
1631 */
1632static void efx_netpoll(struct net_device *net_dev)
1633{
Ben Hutchings767e4682008-09-01 12:43:14 +01001634 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001635 struct efx_channel *channel;
1636
Ben Hutchings64ee3122008-09-01 12:47:38 +01001637 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001638 efx_schedule_channel(channel);
1639}
1640
1641#endif
1642
1643/**************************************************************************
1644 *
1645 * Kernel net device interface
1646 *
1647 *************************************************************************/
1648
1649/* Context: process, rtnl_lock() held. */
1650static int efx_net_open(struct net_device *net_dev)
1651{
Ben Hutchings767e4682008-09-01 12:43:14 +01001652 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001653 EFX_ASSERT_RESET_SERIALISED(efx);
1654
Ben Hutchings62776d02010-06-23 11:30:07 +00001655 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
1656 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001657
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08001658 if (efx->state == STATE_DISABLED)
1659 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001660 if (efx->phy_mode & PHY_MODE_SPECIAL)
1661 return -EBUSY;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001662 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
1663 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001664
Steve Hodgson78c1f0a2009-11-29 03:43:00 +00001665 /* Notify the kernel of the link state polled during driver load,
1666 * before the monitor starts running */
1667 efx_link_status_changed(efx);
1668
Ben Hutchings8ceee662008-04-27 12:55:59 +01001669 efx_start_all(efx);
1670 return 0;
1671}
1672
1673/* Context: process, rtnl_lock() held.
1674 * Note that the kernel will ignore our return code; this method
1675 * should really be a void.
1676 */
1677static int efx_net_stop(struct net_device *net_dev)
1678{
Ben Hutchings767e4682008-09-01 12:43:14 +01001679 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001680
Ben Hutchings62776d02010-06-23 11:30:07 +00001681 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
1682 raw_smp_processor_id());
Ben Hutchings8ceee662008-04-27 12:55:59 +01001683
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08001684 if (efx->state != STATE_DISABLED) {
1685 /* Stop the device and flush all the channels */
1686 efx_stop_all(efx);
1687 efx_fini_channels(efx);
1688 efx_init_channels(efx);
1689 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001690
1691 return 0;
1692}
1693
Ben Hutchings5b9e2072008-05-16 21:18:14 +01001694/* Context: process, dev_base_lock or RTNL held, non-blocking. */
Eric Dumazet28172732010-07-07 14:58:56 -07001695static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev, struct rtnl_link_stats64 *stats)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001696{
Ben Hutchings767e4682008-09-01 12:43:14 +01001697 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001698 struct efx_mac_stats *mac_stats = &efx->mac_stats;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001699
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001700 spin_lock_bh(&efx->stats_lock);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001701 efx->type->update_stats(efx);
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001702 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001703
1704 stats->rx_packets = mac_stats->rx_packets;
1705 stats->tx_packets = mac_stats->tx_packets;
1706 stats->rx_bytes = mac_stats->rx_bytes;
1707 stats->tx_bytes = mac_stats->tx_bytes;
Ben Hutchings80485d32010-09-10 06:41:06 +00001708 stats->rx_dropped = efx->n_rx_nodesc_drop_cnt;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001709 stats->multicast = mac_stats->rx_multicast;
1710 stats->collisions = mac_stats->tx_collision;
1711 stats->rx_length_errors = (mac_stats->rx_gtjumbo +
1712 mac_stats->rx_length_error);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001713 stats->rx_crc_errors = mac_stats->rx_bad;
1714 stats->rx_frame_errors = mac_stats->rx_align_error;
1715 stats->rx_fifo_errors = mac_stats->rx_overflow;
1716 stats->rx_missed_errors = mac_stats->rx_missed;
1717 stats->tx_window_errors = mac_stats->tx_late_collision;
1718
1719 stats->rx_errors = (stats->rx_length_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001720 stats->rx_crc_errors +
1721 stats->rx_frame_errors +
Ben Hutchings8ceee662008-04-27 12:55:59 +01001722 mac_stats->rx_symbol_error);
1723 stats->tx_errors = (stats->tx_window_errors +
1724 mac_stats->tx_bad);
1725
1726 return stats;
1727}
1728
1729/* Context: netif_tx_lock held, BHs disabled. */
1730static void efx_watchdog(struct net_device *net_dev)
1731{
Ben Hutchings767e4682008-09-01 12:43:14 +01001732 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001733
Ben Hutchings62776d02010-06-23 11:30:07 +00001734 netif_err(efx, tx_err, efx->net_dev,
1735 "TX stuck with port_enabled=%d: resetting channels\n",
1736 efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001737
Ben Hutchings739bb23d2008-11-04 20:35:36 +00001738 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001739}
1740
1741
1742/* Context: process, rtnl_lock() held. */
1743static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1744{
Ben Hutchings767e4682008-09-01 12:43:14 +01001745 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001746 int rc = 0;
1747
1748 EFX_ASSERT_RESET_SERIALISED(efx);
1749
1750 if (new_mtu > EFX_MAX_MTU)
1751 return -EINVAL;
1752
1753 efx_stop_all(efx);
1754
Ben Hutchings62776d02010-06-23 11:30:07 +00001755 netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001756
1757 efx_fini_channels(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001758
1759 mutex_lock(&efx->mac_lock);
1760 /* Reconfigure the MAC before enabling the dma queues so that
1761 * the RX buffers don't overflow */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001762 net_dev->mtu = new_mtu;
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001763 efx->mac_op->reconfigure(efx);
1764 mutex_unlock(&efx->mac_lock);
1765
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001766 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001767
1768 efx_start_all(efx);
1769 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001770}
1771
1772static int efx_set_mac_address(struct net_device *net_dev, void *data)
1773{
Ben Hutchings767e4682008-09-01 12:43:14 +01001774 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001775 struct sockaddr *addr = data;
1776 char *new_addr = addr->sa_data;
1777
1778 EFX_ASSERT_RESET_SERIALISED(efx);
1779
1780 if (!is_valid_ether_addr(new_addr)) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001781 netif_err(efx, drv, efx->net_dev,
1782 "invalid ethernet MAC address requested: %pM\n",
1783 new_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001784 return -EINVAL;
1785 }
1786
1787 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
1788
1789 /* Reconfigure the MAC */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001790 mutex_lock(&efx->mac_lock);
1791 efx->mac_op->reconfigure(efx);
1792 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001793
1794 return 0;
1795}
1796
Ben Hutchingsa816f752008-09-01 12:49:12 +01001797/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001798static void efx_set_multicast_list(struct net_device *net_dev)
1799{
Ben Hutchings767e4682008-09-01 12:43:14 +01001800 struct efx_nic *efx = netdev_priv(net_dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001801 struct netdev_hw_addr *ha;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001802 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001803 u32 crc;
1804 int bit;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001805
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001806 efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001807
1808 /* Build multicast hash table */
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001809 if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001810 memset(mc_hash, 0xff, sizeof(*mc_hash));
1811 } else {
1812 memset(mc_hash, 0x00, sizeof(*mc_hash));
Jiri Pirko22bedad32010-04-01 21:22:57 +00001813 netdev_for_each_mc_addr(ha, net_dev) {
1814 crc = ether_crc_le(ETH_ALEN, ha->addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001815 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1816 set_bit_le(bit, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001817 }
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001818
1819 /* Broadcast packets go through the multicast hash filter.
1820 * ether_crc_le() of the broadcast address is 0xbe2612ff
1821 * so we always add bit 0xff to the mask.
1822 */
1823 set_bit_le(0xff, mc_hash->byte);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001824 }
1825
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001826 if (efx->port_enabled)
1827 queue_work(efx->workqueue, &efx->mac_work);
1828 /* Otherwise efx_start_port() will do this */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001829}
1830
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001831static const struct net_device_ops efx_netdev_ops = {
1832 .ndo_open = efx_net_open,
1833 .ndo_stop = efx_net_stop,
Ben Hutchings44727022010-06-08 07:21:12 +00001834 .ndo_get_stats64 = efx_net_stats,
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001835 .ndo_tx_timeout = efx_watchdog,
1836 .ndo_start_xmit = efx_hard_start_xmit,
1837 .ndo_validate_addr = eth_validate_addr,
1838 .ndo_do_ioctl = efx_ioctl,
1839 .ndo_change_mtu = efx_change_mtu,
1840 .ndo_set_mac_address = efx_set_mac_address,
1841 .ndo_set_multicast_list = efx_set_multicast_list,
1842#ifdef CONFIG_NET_POLL_CONTROLLER
1843 .ndo_poll_controller = efx_netpoll,
1844#endif
1845};
1846
Ben Hutchings7dde5962008-12-12 22:09:38 -08001847static void efx_update_name(struct efx_nic *efx)
1848{
1849 strcpy(efx->name, efx->net_dev->name);
1850 efx_mtd_rename(efx);
1851 efx_set_channel_names(efx);
1852}
1853
Ben Hutchings8ceee662008-04-27 12:55:59 +01001854static int efx_netdev_event(struct notifier_block *this,
1855 unsigned long event, void *ptr)
1856{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001857 struct net_device *net_dev = ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001858
Ben Hutchings7dde5962008-12-12 22:09:38 -08001859 if (net_dev->netdev_ops == &efx_netdev_ops &&
1860 event == NETDEV_CHANGENAME)
1861 efx_update_name(netdev_priv(net_dev));
Ben Hutchings8ceee662008-04-27 12:55:59 +01001862
1863 return NOTIFY_DONE;
1864}
1865
1866static struct notifier_block efx_netdev_notifier = {
1867 .notifier_call = efx_netdev_event,
1868};
1869
Ben Hutchings06d5e192008-12-12 21:47:23 -08001870static ssize_t
1871show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
1872{
1873 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
1874 return sprintf(buf, "%d\n", efx->phy_type);
1875}
1876static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL);
1877
Ben Hutchings8ceee662008-04-27 12:55:59 +01001878static int efx_register_netdev(struct efx_nic *efx)
1879{
1880 struct net_device *net_dev = efx->net_dev;
1881 int rc;
1882
1883 net_dev->watchdog_timeo = 5 * HZ;
1884 net_dev->irq = efx->pci_dev->irq;
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001885 net_dev->netdev_ops = &efx_netdev_ops;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001886 SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
1887
Ben Hutchings8ceee662008-04-27 12:55:59 +01001888 /* Clear MAC statistics */
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001889 efx->mac_op->update_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001890 memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
1891
Ben Hutchings7dde5962008-12-12 22:09:38 -08001892 rtnl_lock();
Ben Hutchingsaed06282009-08-26 08:16:27 +00001893
1894 rc = dev_alloc_name(net_dev, net_dev->name);
1895 if (rc < 0)
1896 goto fail_locked;
Ben Hutchings7dde5962008-12-12 22:09:38 -08001897 efx_update_name(efx);
Ben Hutchingsaed06282009-08-26 08:16:27 +00001898
1899 rc = register_netdevice(net_dev);
1900 if (rc)
1901 goto fail_locked;
1902
1903 /* Always start with carrier off; PHY events will detect the link */
1904 netif_carrier_off(efx->net_dev);
1905
Ben Hutchings7dde5962008-12-12 22:09:38 -08001906 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01001907
Ben Hutchings06d5e192008-12-12 21:47:23 -08001908 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
1909 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001910 netif_err(efx, drv, efx->net_dev,
1911 "failed to init net dev attributes\n");
Ben Hutchings06d5e192008-12-12 21:47:23 -08001912 goto fail_registered;
1913 }
1914
Ben Hutchings8ceee662008-04-27 12:55:59 +01001915 return 0;
Ben Hutchings06d5e192008-12-12 21:47:23 -08001916
Ben Hutchingsaed06282009-08-26 08:16:27 +00001917fail_locked:
1918 rtnl_unlock();
Ben Hutchings62776d02010-06-23 11:30:07 +00001919 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
Ben Hutchingsaed06282009-08-26 08:16:27 +00001920 return rc;
1921
Ben Hutchings06d5e192008-12-12 21:47:23 -08001922fail_registered:
1923 unregister_netdev(net_dev);
1924 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001925}
1926
1927static void efx_unregister_netdev(struct efx_nic *efx)
1928{
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001929 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001930 struct efx_tx_queue *tx_queue;
1931
1932 if (!efx->net_dev)
1933 return;
1934
Ben Hutchings767e4682008-09-01 12:43:14 +01001935 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001936
1937 /* Free up any skbs still remaining. This has to happen before
1938 * we try to unregister the netdev as running their destructors
1939 * may be needed to get the device ref. count to 0. */
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +00001940 efx_for_each_channel(channel, efx) {
1941 efx_for_each_channel_tx_queue(tx_queue, channel)
1942 efx_release_tx_buffers(tx_queue);
1943 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001944
Ben Hutchings55668612008-05-16 21:16:10 +01001945 if (efx_dev_registered(efx)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001946 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
Ben Hutchings06d5e192008-12-12 21:47:23 -08001947 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001948 unregister_netdev(efx->net_dev);
1949 }
1950}
1951
1952/**************************************************************************
1953 *
1954 * Device reset and suspend
1955 *
1956 **************************************************************************/
1957
Ben Hutchings2467ca42008-09-01 12:48:50 +01001958/* Tears down the entire software state and most of the hardware state
1959 * before reset. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001960void efx_reset_down(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001961{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001962 EFX_ASSERT_RESET_SERIALISED(efx);
1963
Ben Hutchings2467ca42008-09-01 12:48:50 +01001964 efx_stop_all(efx);
1965 mutex_lock(&efx->mac_lock);
1966
Ben Hutchings8ceee662008-04-27 12:55:59 +01001967 efx_fini_channels(efx);
Steve Hodgson4b988282009-01-29 17:50:51 +00001968 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
1969 efx->phy_op->fini(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001970 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001971}
1972
Ben Hutchings2467ca42008-09-01 12:48:50 +01001973/* This function will always ensure that the locks acquired in
1974 * efx_reset_down() are released. A failure return code indicates
1975 * that we were unable to reinitialise the hardware, and the
1976 * driver should be disabled. If ok is false, then the rx and tx
1977 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchingsd3245b22009-11-29 03:42:41 +00001978int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001979{
1980 int rc;
1981
Ben Hutchings2467ca42008-09-01 12:48:50 +01001982 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001983
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00001984 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001985 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00001986 netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001987 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001988 }
1989
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001990 if (!ok)
1991 goto fail;
1992
Steve Hodgson4b988282009-01-29 17:50:51 +00001993 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001994 rc = efx->phy_op->init(efx);
1995 if (rc)
1996 goto fail;
1997 if (efx->phy_op->reconfigure(efx))
Ben Hutchings62776d02010-06-23 11:30:07 +00001998 netif_err(efx, drv, efx->net_dev,
1999 "could not restore PHY settings\n");
Steve Hodgson4b988282009-01-29 17:50:51 +00002000 }
2001
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002002 efx->mac_op->reconfigure(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002003
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002004 efx_init_channels(efx);
Ben Hutchings64eebcf2010-09-20 08:43:07 +00002005 efx_restore_filters(efx);
Ben Hutchings2467ca42008-09-01 12:48:50 +01002006
2007 mutex_unlock(&efx->mac_lock);
2008
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002009 efx_start_all(efx);
2010
2011 return 0;
2012
2013fail:
2014 efx->port_initialized = false;
2015
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002016 mutex_unlock(&efx->mac_lock);
2017
Ben Hutchings8ceee662008-04-27 12:55:59 +01002018 return rc;
2019}
2020
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002021/* Reset the NIC using the specified method. Note that the reset may
2022 * fail, in which case the card will be left in an unusable state.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002023 *
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002024 * Caller must hold the rtnl_lock.
Ben Hutchings8ceee662008-04-27 12:55:59 +01002025 */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002026int efx_reset(struct efx_nic *efx, enum reset_type method)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002027{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002028 int rc, rc2;
2029 bool disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002030
Ben Hutchings62776d02010-06-23 11:30:07 +00002031 netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2032 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002033
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002034 efx_reset_down(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002035
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002036 rc = efx->type->reset(efx, method);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002037 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002038 netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002039 goto out;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002040 }
2041
2042 /* Allow resets to be rescheduled. */
2043 efx->reset_pending = RESET_TYPE_NONE;
2044
2045 /* Reinitialise bus-mastering, which may have been turned off before
2046 * the reset was scheduled. This is still appropriate, even in the
2047 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2048 * can respond to requests. */
2049 pci_set_master(efx->pci_dev);
2050
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002051out:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002052 /* Leave device stopped if necessary */
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002053 disabled = rc || method == RESET_TYPE_DISABLE;
2054 rc2 = efx_reset_up(efx, method, !disabled);
2055 if (rc2) {
2056 disabled = true;
2057 if (!rc)
2058 rc = rc2;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002059 }
2060
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002061 if (disabled) {
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002062 dev_close(efx->net_dev);
Ben Hutchings62776d02010-06-23 11:30:07 +00002063 netif_err(efx, drv, efx->net_dev, "has been disabled\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002064 efx->state = STATE_DISABLED;
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002065 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +00002066 netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
Ben Hutchingsf4bd9542008-12-26 13:48:51 -08002067 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002068 return rc;
2069}
2070
2071/* The worker thread exists so that code that cannot sleep can
2072 * schedule a reset for later.
2073 */
2074static void efx_reset_work(struct work_struct *data)
2075{
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002076 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002077
Steve Hodgson319ba642010-06-01 11:17:24 +00002078 if (efx->reset_pending == RESET_TYPE_NONE)
2079 return;
2080
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002081 /* If we're not RUNNING then don't reset. Leave the reset_pending
2082 * flag set so that efx_pci_probe_main will be retried */
2083 if (efx->state != STATE_RUNNING) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002084 netif_info(efx, drv, efx->net_dev,
2085 "scheduled reset quenched. NIC not RUNNING\n");
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002086 return;
2087 }
2088
2089 rtnl_lock();
Ben Hutchingsf49a4582010-04-28 09:01:33 +00002090 (void)efx_reset(efx, efx->reset_pending);
Ben Hutchingseb9f6742009-11-29 03:43:15 +00002091 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002092}
2093
2094void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2095{
2096 enum reset_type method;
2097
2098 if (efx->reset_pending != RESET_TYPE_NONE) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002099 netif_info(efx, drv, efx->net_dev,
2100 "quenching already scheduled reset\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002101 return;
2102 }
2103
2104 switch (type) {
2105 case RESET_TYPE_INVISIBLE:
2106 case RESET_TYPE_ALL:
2107 case RESET_TYPE_WORLD:
2108 case RESET_TYPE_DISABLE:
2109 method = type;
2110 break;
2111 case RESET_TYPE_RX_RECOVERY:
2112 case RESET_TYPE_RX_DESC_FETCH:
2113 case RESET_TYPE_TX_DESC_FETCH:
2114 case RESET_TYPE_TX_SKIP:
2115 method = RESET_TYPE_INVISIBLE;
2116 break;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002117 case RESET_TYPE_MC_FAILURE:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002118 default:
2119 method = RESET_TYPE_ALL;
2120 break;
2121 }
2122
2123 if (method != type)
Ben Hutchings62776d02010-06-23 11:30:07 +00002124 netif_dbg(efx, drv, efx->net_dev,
2125 "scheduling %s reset for %s\n",
2126 RESET_TYPE(method), RESET_TYPE(type));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002127 else
Ben Hutchings62776d02010-06-23 11:30:07 +00002128 netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2129 RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002130
2131 efx->reset_pending = method;
2132
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002133 /* efx_process_channel() will no longer read events once a
2134 * reset is scheduled. So switch back to poll'd MCDI completions. */
2135 efx_mcdi_mode_poll(efx);
2136
Steve Hodgson1ab00622008-12-12 21:33:02 -08002137 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002138}
2139
2140/**************************************************************************
2141 *
2142 * List of NICs we support
2143 *
2144 **************************************************************************/
2145
2146/* PCI device ID table */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002147static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002148 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002149 .driver_data = (unsigned long) &falcon_a1_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002150 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002151 .driver_data = (unsigned long) &falcon_b0_nic_type},
Ben Hutchings8880f4e2009-11-29 15:15:41 +00002152 {PCI_DEVICE(EFX_VENDID_SFC, BETHPAGE_A_P_DEVID),
2153 .driver_data = (unsigned long) &siena_a0_nic_type},
2154 {PCI_DEVICE(EFX_VENDID_SFC, SIENA_A_P_DEVID),
2155 .driver_data = (unsigned long) &siena_a0_nic_type},
Ben Hutchings8ceee662008-04-27 12:55:59 +01002156 {0} /* end of list */
2157};
2158
2159/**************************************************************************
2160 *
Ben Hutchings37594332009-11-23 16:05:45 +00002161 * Dummy PHY/MAC operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002162 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01002163 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01002164 * Needed so all function pointers are valid and do not have to be tested
2165 * before use
2166 *
2167 **************************************************************************/
2168int efx_port_dummy_op_int(struct efx_nic *efx)
2169{
2170 return 0;
2171}
2172void efx_port_dummy_op_void(struct efx_nic *efx) {}
stephen hemmingerd2156972010-10-18 05:27:31 +00002173
2174static bool efx_port_dummy_op_poll(struct efx_nic *efx)
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002175{
2176 return false;
2177}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002178
2179static struct efx_phy_operations efx_dummy_phy_operations = {
2180 .init = efx_port_dummy_op_int,
Ben Hutchingsd3245b22009-11-29 03:42:41 +00002181 .reconfigure = efx_port_dummy_op_int,
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002182 .poll = efx_port_dummy_op_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002183 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002184};
2185
Ben Hutchings8ceee662008-04-27 12:55:59 +01002186/**************************************************************************
2187 *
2188 * Data housekeeping
2189 *
2190 **************************************************************************/
2191
2192/* This zeroes out and then fills in the invariants in a struct
2193 * efx_nic (including all sub-structures).
2194 */
2195static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
2196 struct pci_dev *pci_dev, struct net_device *net_dev)
2197{
Ben Hutchings46426102010-09-10 06:42:33 +00002198 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002199
2200 /* Initialise common structures */
2201 memset(efx, 0, sizeof(*efx));
2202 spin_lock_init(&efx->biu_lock);
Ben Hutchings76884832009-11-29 15:10:44 +00002203#ifdef CONFIG_SFC_MTD
2204 INIT_LIST_HEAD(&efx->mtd_list);
2205#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +01002206 INIT_WORK(&efx->reset_work, efx_reset_work);
2207 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
2208 efx->pci_dev = pci_dev;
Ben Hutchings62776d02010-06-23 11:30:07 +00002209 efx->msg_enable = debug;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002210 efx->state = STATE_INIT;
2211 efx->reset_pending = RESET_TYPE_NONE;
2212 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002213
2214 efx->net_dev = net_dev;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01002215 efx->rx_checksum_enabled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002216 spin_lock_init(&efx->stats_lock);
2217 mutex_init(&efx->mac_lock);
Steve Hodgsonb895d732009-11-28 05:35:00 +00002218 efx->mac_op = type->default_mac_ops;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002219 efx->phy_op = &efx_dummy_phy_operations;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002220 efx->mdio.dev = net_dev;
Ben Hutchings766ca0f2008-12-12 21:59:24 -08002221 INIT_WORK(&efx->mac_work, efx_mac_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002222
2223 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
Ben Hutchings46426102010-09-10 06:42:33 +00002224 efx->channel[i] = efx_alloc_channel(efx, i, NULL);
2225 if (!efx->channel[i])
2226 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002227 }
2228
2229 efx->type = type;
2230
Ben Hutchings8ceee662008-04-27 12:55:59 +01002231 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
2232
2233 /* Higher numbered interrupt modes are less capable! */
2234 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
2235 interrupt_mode);
2236
Ben Hutchings6977dc62008-12-26 13:44:39 -08002237 /* Would be good to use the net_dev name, but we're too early */
2238 snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
2239 pci_name(pci_dev));
2240 efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002241 if (!efx->workqueue)
Ben Hutchings46426102010-09-10 06:42:33 +00002242 goto fail;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01002243
Ben Hutchings8ceee662008-04-27 12:55:59 +01002244 return 0;
Ben Hutchings46426102010-09-10 06:42:33 +00002245
2246fail:
2247 efx_fini_struct(efx);
2248 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002249}
2250
2251static void efx_fini_struct(struct efx_nic *efx)
2252{
Ben Hutchings8313aca2010-09-10 06:41:57 +00002253 int i;
2254
2255 for (i = 0; i < EFX_MAX_CHANNELS; i++)
2256 kfree(efx->channel[i]);
2257
Ben Hutchings8ceee662008-04-27 12:55:59 +01002258 if (efx->workqueue) {
2259 destroy_workqueue(efx->workqueue);
2260 efx->workqueue = NULL;
2261 }
2262}
2263
2264/**************************************************************************
2265 *
2266 * PCI interface
2267 *
2268 **************************************************************************/
2269
2270/* Main body of final NIC shutdown code
2271 * This is called only at module unload (or hotplug removal).
2272 */
2273static void efx_pci_remove_main(struct efx_nic *efx)
2274{
Ben Hutchings152b6a62009-11-29 03:43:56 +00002275 efx_nic_fini_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002276 efx_fini_channels(efx);
2277 efx_fini_port(efx);
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002278 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002279 efx_fini_napi(efx);
2280 efx_remove_all(efx);
2281}
2282
2283/* Final NIC shutdown
2284 * This is called only at module unload (or hotplug removal).
2285 */
2286static void efx_pci_remove(struct pci_dev *pci_dev)
2287{
2288 struct efx_nic *efx;
2289
2290 efx = pci_get_drvdata(pci_dev);
2291 if (!efx)
2292 return;
2293
2294 /* Mark the NIC as fini, then stop the interface */
2295 rtnl_lock();
2296 efx->state = STATE_FINI;
2297 dev_close(efx->net_dev);
2298
2299 /* Allow any queued efx_resets() to complete */
2300 rtnl_unlock();
2301
Ben Hutchings8ceee662008-04-27 12:55:59 +01002302 efx_unregister_netdev(efx);
2303
Ben Hutchings7dde5962008-12-12 22:09:38 -08002304 efx_mtd_remove(efx);
2305
Ben Hutchings8ceee662008-04-27 12:55:59 +01002306 /* Wait for any scheduled resets to complete. No more will be
2307 * scheduled from this point because efx_stop_all() has been
2308 * called, we are no longer registered with driverlink, and
2309 * the net_device's have been removed. */
Steve Hodgson1ab00622008-12-12 21:33:02 -08002310 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002311
2312 efx_pci_remove_main(efx);
2313
Ben Hutchings8ceee662008-04-27 12:55:59 +01002314 efx_fini_io(efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002315 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002316
2317 pci_set_drvdata(pci_dev, NULL);
2318 efx_fini_struct(efx);
2319 free_netdev(efx->net_dev);
2320};
2321
2322/* Main body of NIC initialisation
2323 * This is called at module load (or hotplug insertion, theoretically).
2324 */
2325static int efx_pci_probe_main(struct efx_nic *efx)
2326{
2327 int rc;
2328
2329 /* Do start-of-day initialisation */
2330 rc = efx_probe_all(efx);
2331 if (rc)
2332 goto fail1;
2333
2334 rc = efx_init_napi(efx);
2335 if (rc)
2336 goto fail2;
2337
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002338 rc = efx->type->init(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002339 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002340 netif_err(efx, probe, efx->net_dev,
2341 "failed to initialise NIC\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002342 goto fail3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002343 }
2344
2345 rc = efx_init_port(efx);
2346 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002347 netif_err(efx, probe, efx->net_dev,
2348 "failed to initialise port\n");
Ben Hutchings278c0622009-11-23 16:05:12 +00002349 goto fail4;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002350 }
2351
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01002352 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002353
Ben Hutchings152b6a62009-11-29 03:43:56 +00002354 rc = efx_nic_init_interrupt(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002355 if (rc)
Ben Hutchings278c0622009-11-23 16:05:12 +00002356 goto fail5;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002357
2358 return 0;
2359
Ben Hutchings278c0622009-11-23 16:05:12 +00002360 fail5:
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01002361 efx_fini_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002362 efx_fini_port(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002363 fail4:
Ben Hutchingsef2b90e2009-11-29 03:42:31 +00002364 efx->type->fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002365 fail3:
2366 efx_fini_napi(efx);
2367 fail2:
2368 efx_remove_all(efx);
2369 fail1:
2370 return rc;
2371}
2372
2373/* NIC initialisation
2374 *
2375 * This is called at module load (or hotplug insertion,
2376 * theoretically). It sets up PCI mappings, tests and resets the NIC,
2377 * sets up and registers the network devices with the kernel and hooks
2378 * the interrupt service routine. It does not prepare the device for
2379 * transmission; this is left to the first time one of the network
2380 * interfaces is brought up (i.e. efx_net_open).
2381 */
2382static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2383 const struct pci_device_id *entry)
2384{
2385 struct efx_nic_type *type = (struct efx_nic_type *) entry->driver_data;
2386 struct net_device *net_dev;
2387 struct efx_nic *efx;
2388 int i, rc;
2389
2390 /* Allocate and initialise a struct net_device and struct efx_nic */
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00002391 net_dev = alloc_etherdev_mq(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002392 if (!net_dev)
2393 return -ENOMEM;
Ben Hutchingsc383b532009-11-29 15:11:02 +00002394 net_dev->features |= (type->offload_features | NETIF_F_SG |
Ben Hutchings97bc5412009-05-19 16:19:08 -07002395 NETIF_F_HIGHDMA | NETIF_F_TSO |
2396 NETIF_F_GRO);
Ben Hutchings738a8f42009-11-29 15:16:05 +00002397 if (type->offload_features & NETIF_F_V6_CSUM)
2398 net_dev->features |= NETIF_F_TSO6;
Ben Hutchings285065632008-09-01 12:46:54 +01002399 /* Mask for features that also apply to VLAN devices */
2400 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
Ben Hutchings740847d2008-09-01 12:48:23 +01002401 NETIF_F_HIGHDMA | NETIF_F_TSO);
Ben Hutchings767e4682008-09-01 12:43:14 +01002402 efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002403 pci_set_drvdata(pci_dev, efx);
Ben Hutchings62776d02010-06-23 11:30:07 +00002404 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002405 rc = efx_init_struct(efx, type, pci_dev, net_dev);
2406 if (rc)
2407 goto fail1;
2408
Ben Hutchings62776d02010-06-23 11:30:07 +00002409 netif_info(efx, probe, efx->net_dev,
2410 "Solarflare Communications NIC detected\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002411
2412 /* Set up basic I/O (BAR mappings etc) */
2413 rc = efx_init_io(efx);
2414 if (rc)
2415 goto fail2;
2416
2417 /* No serialisation is required with the reset path because
2418 * we're in STATE_INIT. */
2419 for (i = 0; i < 5; i++) {
2420 rc = efx_pci_probe_main(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002421
2422 /* Serialise against efx_reset(). No more resets will be
2423 * scheduled since efx_stop_all() has been called, and we
2424 * have not and never have been registered with either
2425 * the rtnetlink or driverlink layers. */
Steve Hodgson1ab00622008-12-12 21:33:02 -08002426 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002427
Steve Hodgsonfa402b22008-12-12 22:08:16 -08002428 if (rc == 0) {
2429 if (efx->reset_pending != RESET_TYPE_NONE) {
2430 /* If there was a scheduled reset during
2431 * probe, the NIC is probably hosed anyway */
2432 efx_pci_remove_main(efx);
2433 rc = -EIO;
2434 } else {
2435 break;
2436 }
2437 }
2438
Ben Hutchings8ceee662008-04-27 12:55:59 +01002439 /* Retry if a recoverably reset event has been scheduled */
2440 if ((efx->reset_pending != RESET_TYPE_INVISIBLE) &&
2441 (efx->reset_pending != RESET_TYPE_ALL))
2442 goto fail3;
2443
2444 efx->reset_pending = RESET_TYPE_NONE;
2445 }
2446
2447 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +00002448 netif_err(efx, probe, efx->net_dev, "Could not reset NIC\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002449 goto fail4;
2450 }
2451
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002452 /* Switch to the running state before we expose the device to the OS,
2453 * so that dev_open()|efx_start_all() will actually start the device */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002454 efx->state = STATE_RUNNING;
Ben Hutchings7dde5962008-12-12 22:09:38 -08002455
Ben Hutchings8ceee662008-04-27 12:55:59 +01002456 rc = efx_register_netdev(efx);
2457 if (rc)
2458 goto fail5;
2459
Ben Hutchings62776d02010-06-23 11:30:07 +00002460 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
Ben Hutchingsa5211bb2009-10-23 08:33:09 +00002461
2462 rtnl_lock();
2463 efx_mtd_probe(efx); /* allowed to fail */
2464 rtnl_unlock();
Ben Hutchings8ceee662008-04-27 12:55:59 +01002465 return 0;
2466
2467 fail5:
2468 efx_pci_remove_main(efx);
2469 fail4:
2470 fail3:
2471 efx_fini_io(efx);
2472 fail2:
2473 efx_fini_struct(efx);
2474 fail1:
Steve Hodgson5e2a9112010-02-12 12:32:27 -08002475 WARN_ON(rc > 0);
Ben Hutchings62776d02010-06-23 11:30:07 +00002476 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002477 free_netdev(net_dev);
2478 return rc;
2479}
2480
Ben Hutchings89c758f2009-11-29 03:43:07 +00002481static int efx_pm_freeze(struct device *dev)
2482{
2483 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2484
2485 efx->state = STATE_FINI;
2486
2487 netif_device_detach(efx->net_dev);
2488
2489 efx_stop_all(efx);
2490 efx_fini_channels(efx);
2491
2492 return 0;
2493}
2494
2495static int efx_pm_thaw(struct device *dev)
2496{
2497 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2498
2499 efx->state = STATE_INIT;
2500
2501 efx_init_channels(efx);
2502
2503 mutex_lock(&efx->mac_lock);
2504 efx->phy_op->reconfigure(efx);
2505 mutex_unlock(&efx->mac_lock);
2506
2507 efx_start_all(efx);
2508
2509 netif_device_attach(efx->net_dev);
2510
2511 efx->state = STATE_RUNNING;
2512
2513 efx->type->resume_wol(efx);
2514
Steve Hodgson319ba642010-06-01 11:17:24 +00002515 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2516 queue_work(reset_workqueue, &efx->reset_work);
2517
Ben Hutchings89c758f2009-11-29 03:43:07 +00002518 return 0;
2519}
2520
2521static int efx_pm_poweroff(struct device *dev)
2522{
2523 struct pci_dev *pci_dev = to_pci_dev(dev);
2524 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2525
2526 efx->type->fini(efx);
2527
2528 efx->reset_pending = RESET_TYPE_NONE;
2529
2530 pci_save_state(pci_dev);
2531 return pci_set_power_state(pci_dev, PCI_D3hot);
2532}
2533
2534/* Used for both resume and restore */
2535static int efx_pm_resume(struct device *dev)
2536{
2537 struct pci_dev *pci_dev = to_pci_dev(dev);
2538 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2539 int rc;
2540
2541 rc = pci_set_power_state(pci_dev, PCI_D0);
2542 if (rc)
2543 return rc;
2544 pci_restore_state(pci_dev);
2545 rc = pci_enable_device(pci_dev);
2546 if (rc)
2547 return rc;
2548 pci_set_master(efx->pci_dev);
2549 rc = efx->type->reset(efx, RESET_TYPE_ALL);
2550 if (rc)
2551 return rc;
2552 rc = efx->type->init(efx);
2553 if (rc)
2554 return rc;
2555 efx_pm_thaw(dev);
2556 return 0;
2557}
2558
2559static int efx_pm_suspend(struct device *dev)
2560{
2561 int rc;
2562
2563 efx_pm_freeze(dev);
2564 rc = efx_pm_poweroff(dev);
2565 if (rc)
2566 efx_pm_resume(dev);
2567 return rc;
2568}
2569
2570static struct dev_pm_ops efx_pm_ops = {
2571 .suspend = efx_pm_suspend,
2572 .resume = efx_pm_resume,
2573 .freeze = efx_pm_freeze,
2574 .thaw = efx_pm_thaw,
2575 .poweroff = efx_pm_poweroff,
2576 .restore = efx_pm_resume,
2577};
2578
Ben Hutchings8ceee662008-04-27 12:55:59 +01002579static struct pci_driver efx_pci_driver = {
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +00002580 .name = KBUILD_MODNAME,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002581 .id_table = efx_pci_table,
2582 .probe = efx_pci_probe,
2583 .remove = efx_pci_remove,
Ben Hutchings89c758f2009-11-29 03:43:07 +00002584 .driver.pm = &efx_pm_ops,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002585};
2586
2587/**************************************************************************
2588 *
2589 * Kernel module interface
2590 *
2591 *************************************************************************/
2592
2593module_param(interrupt_mode, uint, 0444);
2594MODULE_PARM_DESC(interrupt_mode,
2595 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
2596
2597static int __init efx_init_module(void)
2598{
2599 int rc;
2600
2601 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
2602
2603 rc = register_netdevice_notifier(&efx_netdev_notifier);
2604 if (rc)
2605 goto err_notifier;
2606
Steve Hodgson1ab00622008-12-12 21:33:02 -08002607 reset_workqueue = create_singlethread_workqueue("sfc_reset");
2608 if (!reset_workqueue) {
2609 rc = -ENOMEM;
2610 goto err_reset;
2611 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002612
2613 rc = pci_register_driver(&efx_pci_driver);
2614 if (rc < 0)
2615 goto err_pci;
2616
2617 return 0;
2618
2619 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08002620 destroy_workqueue(reset_workqueue);
2621 err_reset:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002622 unregister_netdevice_notifier(&efx_netdev_notifier);
2623 err_notifier:
2624 return rc;
2625}
2626
2627static void __exit efx_exit_module(void)
2628{
2629 printk(KERN_INFO "Solarflare NET driver unloading\n");
2630
2631 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002632 destroy_workqueue(reset_workqueue);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002633 unregister_netdevice_notifier(&efx_netdev_notifier);
2634
2635}
2636
2637module_init(efx_init_module);
2638module_exit(efx_exit_module);
2639
Ben Hutchings906bb262009-11-29 15:16:19 +00002640MODULE_AUTHOR("Solarflare Communications and "
2641 "Michael Brown <mbrown@fensystems.co.uk>");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002642MODULE_DESCRIPTION("Solarflare Communications network driver");
2643MODULE_LICENSE("GPL");
2644MODULE_DEVICE_TABLE(pci, efx_pci_table);