blob: bba11490ef416cee60885d182ee6057e80fbcbd3 [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.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
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>
Ben Hutchings8ceee662008-04-27 12:55:59 +010023#include "net_driver.h"
24#include "gmii.h"
25#include "ethtool.h"
26#include "tx.h"
27#include "rx.h"
28#include "efx.h"
29#include "mdio_10g.h"
30#include "falcon.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010031#include "mac.h"
32
33#define EFX_MAX_MTU (9 * 1024)
34
35/* RX slow fill workqueue. If memory allocation fails in the fast path,
36 * a work item is pushed onto this work queue to retry the allocation later,
37 * to avoid the NIC being starved of RX buffers. Since this is a per cpu
38 * workqueue, there is nothing to be gained in making it per NIC
39 */
40static struct workqueue_struct *refill_workqueue;
41
Steve Hodgson1ab00622008-12-12 21:33:02 -080042/* Reset workqueue. If any NIC has a hardware failure then a reset will be
43 * queued onto this work queue. This is not a per-nic work queue, because
44 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
45 */
46static struct workqueue_struct *reset_workqueue;
47
Ben Hutchings8ceee662008-04-27 12:55:59 +010048/**************************************************************************
49 *
50 * Configurable values
51 *
52 *************************************************************************/
53
54/*
55 * Enable large receive offload (LRO) aka soft segment reassembly (SSR)
56 *
57 * This sets the default for new devices. It can be controlled later
58 * using ethtool.
59 */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +010060static int lro = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +010061module_param(lro, int, 0644);
62MODULE_PARM_DESC(lro, "Large receive offload acceleration");
63
64/*
65 * Use separate channels for TX and RX events
66 *
Neil Turton28b581a2008-12-12 21:41:06 -080067 * Set this to 1 to use separate channels for TX and RX. It allows us
68 * to control interrupt affinity separately for TX and RX.
Ben Hutchings8ceee662008-04-27 12:55:59 +010069 *
Neil Turton28b581a2008-12-12 21:41:06 -080070 * This is only used in MSI-X interrupt mode
Ben Hutchings8ceee662008-04-27 12:55:59 +010071 */
Neil Turton28b581a2008-12-12 21:41:06 -080072static unsigned int separate_tx_channels;
73module_param(separate_tx_channels, uint, 0644);
74MODULE_PARM_DESC(separate_tx_channels,
75 "Use separate channels for TX and RX");
Ben Hutchings8ceee662008-04-27 12:55:59 +010076
77/* This is the weight assigned to each of the (per-channel) virtual
78 * NAPI devices.
79 */
80static int napi_weight = 64;
81
82/* This is the time (in jiffies) between invocations of the hardware
83 * monitor, which checks for known hardware bugs and resets the
84 * hardware and driver as necessary.
85 */
86unsigned int efx_monitor_interval = 1 * HZ;
87
Ben Hutchings8ceee662008-04-27 12:55:59 +010088/* This controls whether or not the driver will initialise devices
89 * with invalid MAC addresses stored in the EEPROM or flash. If true,
90 * such devices will be initialised with a random locally-generated
91 * MAC address. This allows for loading the sfc_mtd driver to
92 * reprogram the flash, even if the flash contents (including the MAC
93 * address) have previously been erased.
94 */
95static unsigned int allow_bad_hwaddr;
96
97/* Initial interrupt moderation settings. They can be modified after
98 * module load with ethtool.
99 *
100 * The default for RX should strike a balance between increasing the
101 * round-trip latency and reducing overhead.
102 */
103static unsigned int rx_irq_mod_usec = 60;
104
105/* Initial interrupt moderation settings. They can be modified after
106 * module load with ethtool.
107 *
108 * This default is chosen to ensure that a 10G link does not go idle
109 * while a TX queue is stopped after it has become full. A queue is
110 * restarted when it drops below half full. The time this takes (assuming
111 * worst case 3 descriptors per packet and 1024 descriptors) is
112 * 512 / 3 * 1.2 = 205 usec.
113 */
114static unsigned int tx_irq_mod_usec = 150;
115
116/* This is the first interrupt mode to try out of:
117 * 0 => MSI-X
118 * 1 => MSI
119 * 2 => legacy
120 */
121static unsigned int interrupt_mode;
122
123/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
124 * i.e. the number of CPUs among which we may distribute simultaneous
125 * interrupt handling.
126 *
127 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
128 * The default (0) means to assign an interrupt to each package (level II cache)
129 */
130static unsigned int rss_cpus;
131module_param(rss_cpus, uint, 0444);
132MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
133
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800134static int phy_flash_cfg;
135module_param(phy_flash_cfg, int, 0644);
136MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
137
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138/**************************************************************************
139 *
140 * Utility functions and prototypes
141 *
142 *************************************************************************/
143static void efx_remove_channel(struct efx_channel *channel);
144static void efx_remove_port(struct efx_nic *efx);
145static void efx_fini_napi(struct efx_nic *efx);
146static void efx_fini_channels(struct efx_nic *efx);
147
148#define EFX_ASSERT_RESET_SERIALISED(efx) \
149 do { \
Ben Hutchings3c787082008-09-01 12:49:08 +0100150 if (efx->state == STATE_RUNNING) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100151 ASSERT_RTNL(); \
152 } while (0)
153
154/**************************************************************************
155 *
156 * Event queue processing
157 *
158 *************************************************************************/
159
160/* Process channel's event queue
161 *
162 * This function is responsible for processing the event queue of a
163 * single channel. The caller must guarantee that this function will
164 * never be concurrently called more than once on the same channel,
165 * though different channels may be being processed concurrently.
166 */
Ben Hutchings4d566062008-09-01 12:47:12 +0100167static int efx_process_channel(struct efx_channel *channel, int rx_quota)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100168{
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100169 struct efx_nic *efx = channel->efx;
170 int rx_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100172 if (unlikely(efx->reset_pending != RESET_TYPE_NONE ||
Ben Hutchings8ceee662008-04-27 12:55:59 +0100173 !channel->enabled))
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100174 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100175
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100176 rx_packets = falcon_process_eventq(channel, rx_quota);
177 if (rx_packets == 0)
178 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100179
180 /* Deliver last RX packet. */
181 if (channel->rx_pkt) {
182 __efx_rx_packet(channel, channel->rx_pkt,
183 channel->rx_pkt_csummed);
184 channel->rx_pkt = NULL;
185 }
186
187 efx_flush_lro(channel);
188 efx_rx_strategy(channel);
189
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100190 efx_fast_push_rx_descriptors(&efx->rx_queue[channel->channel]);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100191
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100192 return rx_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100193}
194
195/* Mark channel as finished processing
196 *
197 * Note that since we will not receive further interrupts for this
198 * channel before we finish processing and call the eventq_read_ack()
199 * method, there is no need to use the interrupt hold-off timers.
200 */
201static inline void efx_channel_processed(struct efx_channel *channel)
202{
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100203 /* The interrupt handler for this channel may set work_pending
204 * as soon as we acknowledge the events we've seen. Make sure
205 * it's cleared before then. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100206 channel->work_pending = false;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100207 smp_wmb();
208
Ben Hutchings8ceee662008-04-27 12:55:59 +0100209 falcon_eventq_read_ack(channel);
210}
211
212/* NAPI poll handler
213 *
214 * NAPI guarantees serialisation of polls of the same device, which
215 * provides the guarantee required by efx_process_channel().
216 */
217static int efx_poll(struct napi_struct *napi, int budget)
218{
219 struct efx_channel *channel =
220 container_of(napi, struct efx_channel, napi_str);
221 struct net_device *napi_dev = channel->napi_dev;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100222 int rx_packets;
223
224 EFX_TRACE(channel->efx, "channel %d NAPI poll executing on CPU %d\n",
225 channel->channel, raw_smp_processor_id());
226
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100227 rx_packets = efx_process_channel(channel, budget);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100228
229 if (rx_packets < budget) {
230 /* There is no race here; although napi_disable() will
231 * only wait for netif_rx_complete(), this isn't a problem
232 * since efx_channel_processed() will have no effect if
233 * interrupts have already been disabled.
234 */
235 netif_rx_complete(napi_dev, napi);
236 efx_channel_processed(channel);
237 }
238
239 return rx_packets;
240}
241
242/* Process the eventq of the specified channel immediately on this CPU
243 *
244 * Disable hardware generated interrupts, wait for any existing
245 * processing to finish, then directly poll (and ack ) the eventq.
246 * Finally reenable NAPI and interrupts.
247 *
248 * Since we are touching interrupts the caller should hold the suspend lock
249 */
250void efx_process_channel_now(struct efx_channel *channel)
251{
252 struct efx_nic *efx = channel->efx;
253
254 BUG_ON(!channel->used_flags);
255 BUG_ON(!channel->enabled);
256
257 /* Disable interrupts and wait for ISRs to complete */
258 falcon_disable_interrupts(efx);
259 if (efx->legacy_irq)
260 synchronize_irq(efx->legacy_irq);
Ben Hutchings64ee3122008-09-01 12:47:38 +0100261 if (channel->irq)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100262 synchronize_irq(channel->irq);
263
264 /* Wait for any NAPI processing to complete */
265 napi_disable(&channel->napi_str);
266
267 /* Poll the channel */
Ben Hutchings91ad7572008-05-16 21:14:27 +0100268 efx_process_channel(channel, efx->type->evq_size);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100269
270 /* Ack the eventq. This may cause an interrupt to be generated
271 * when they are reenabled */
272 efx_channel_processed(channel);
273
274 napi_enable(&channel->napi_str);
275 falcon_enable_interrupts(efx);
276}
277
278/* Create event queue
279 * Event queue memory allocations are done only once. If the channel
280 * is reset, the memory buffer will be reused; this guards against
281 * errors during channel reset and also simplifies interrupt handling.
282 */
283static int efx_probe_eventq(struct efx_channel *channel)
284{
285 EFX_LOG(channel->efx, "chan %d create event queue\n", channel->channel);
286
287 return falcon_probe_eventq(channel);
288}
289
290/* Prepare channel's event queue */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100291static void efx_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100292{
293 EFX_LOG(channel->efx, "chan %d init event queue\n", channel->channel);
294
295 channel->eventq_read_ptr = 0;
296
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100297 falcon_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100298}
299
300static void efx_fini_eventq(struct efx_channel *channel)
301{
302 EFX_LOG(channel->efx, "chan %d fini event queue\n", channel->channel);
303
304 falcon_fini_eventq(channel);
305}
306
307static void efx_remove_eventq(struct efx_channel *channel)
308{
309 EFX_LOG(channel->efx, "chan %d remove event queue\n", channel->channel);
310
311 falcon_remove_eventq(channel);
312}
313
314/**************************************************************************
315 *
316 * Channel handling
317 *
318 *************************************************************************/
319
Ben Hutchings8ceee662008-04-27 12:55:59 +0100320static int efx_probe_channel(struct efx_channel *channel)
321{
322 struct efx_tx_queue *tx_queue;
323 struct efx_rx_queue *rx_queue;
324 int rc;
325
326 EFX_LOG(channel->efx, "creating channel %d\n", channel->channel);
327
328 rc = efx_probe_eventq(channel);
329 if (rc)
330 goto fail1;
331
332 efx_for_each_channel_tx_queue(tx_queue, channel) {
333 rc = efx_probe_tx_queue(tx_queue);
334 if (rc)
335 goto fail2;
336 }
337
338 efx_for_each_channel_rx_queue(rx_queue, channel) {
339 rc = efx_probe_rx_queue(rx_queue);
340 if (rc)
341 goto fail3;
342 }
343
344 channel->n_rx_frm_trunc = 0;
345
346 return 0;
347
348 fail3:
349 efx_for_each_channel_rx_queue(rx_queue, channel)
350 efx_remove_rx_queue(rx_queue);
351 fail2:
352 efx_for_each_channel_tx_queue(tx_queue, channel)
353 efx_remove_tx_queue(tx_queue);
354 fail1:
355 return rc;
356}
357
358
Ben Hutchings56536e92008-12-12 21:37:02 -0800359static void efx_set_channel_names(struct efx_nic *efx)
360{
361 struct efx_channel *channel;
362 const char *type = "";
363 int number;
364
365 efx_for_each_channel(channel, efx) {
366 number = channel->channel;
367 if (efx->n_channels > efx->n_rx_queues) {
368 if (channel->channel < efx->n_rx_queues) {
369 type = "-rx";
370 } else {
371 type = "-tx";
372 number -= efx->n_rx_queues;
373 }
374 }
375 snprintf(channel->name, sizeof(channel->name),
376 "%s%s-%d", efx->name, type, number);
377 }
378}
379
Ben Hutchings8ceee662008-04-27 12:55:59 +0100380/* Channels are shutdown and reinitialised whilst the NIC is running
381 * to propagate configuration changes (mtu, checksum offload), or
382 * to clear hardware error conditions
383 */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100384static void efx_init_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100385{
386 struct efx_tx_queue *tx_queue;
387 struct efx_rx_queue *rx_queue;
388 struct efx_channel *channel;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100389
Ben Hutchingsf7f13b02008-05-16 21:15:06 +0100390 /* Calculate the rx buffer allocation parameters required to
391 * support the current MTU, including padding for header
392 * alignment and overruns.
393 */
394 efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
395 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
396 efx->type->rx_buffer_padding);
397 efx->rx_buffer_order = get_order(efx->rx_buffer_len);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100398
399 /* Initialise the channels */
400 efx_for_each_channel(channel, efx) {
401 EFX_LOG(channel->efx, "init chan %d\n", channel->channel);
402
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100403 efx_init_eventq(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100404
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100405 efx_for_each_channel_tx_queue(tx_queue, channel)
406 efx_init_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100407
408 /* The rx buffer allocation strategy is MTU dependent */
409 efx_rx_strategy(channel);
410
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100411 efx_for_each_channel_rx_queue(rx_queue, channel)
412 efx_init_rx_queue(rx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100413
414 WARN_ON(channel->rx_pkt != NULL);
415 efx_rx_strategy(channel);
416 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100417}
418
419/* This enables event queue processing and packet transmission.
420 *
421 * Note that this function is not allowed to fail, since that would
422 * introduce too much complexity into the suspend/resume path.
423 */
424static void efx_start_channel(struct efx_channel *channel)
425{
426 struct efx_rx_queue *rx_queue;
427
428 EFX_LOG(channel->efx, "starting chan %d\n", channel->channel);
429
430 if (!(channel->efx->net_dev->flags & IFF_UP))
431 netif_napi_add(channel->napi_dev, &channel->napi_str,
432 efx_poll, napi_weight);
433
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100434 /* The interrupt handler for this channel may set work_pending
435 * as soon as we enable it. Make sure it's cleared before
436 * then. Similarly, make sure it sees the enabled flag set. */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100437 channel->work_pending = false;
438 channel->enabled = true;
Ben Hutchings5b9e2072008-05-16 21:18:14 +0100439 smp_wmb();
Ben Hutchings8ceee662008-04-27 12:55:59 +0100440
441 napi_enable(&channel->napi_str);
442
443 /* Load up RX descriptors */
444 efx_for_each_channel_rx_queue(rx_queue, channel)
445 efx_fast_push_rx_descriptors(rx_queue);
446}
447
448/* This disables event queue processing and packet transmission.
449 * This function does not guarantee that all queue processing
450 * (e.g. RX refill) is complete.
451 */
452static void efx_stop_channel(struct efx_channel *channel)
453{
454 struct efx_rx_queue *rx_queue;
455
456 if (!channel->enabled)
457 return;
458
459 EFX_LOG(channel->efx, "stop chan %d\n", channel->channel);
460
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100461 channel->enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100462 napi_disable(&channel->napi_str);
463
464 /* Ensure that any worker threads have exited or will be no-ops */
465 efx_for_each_channel_rx_queue(rx_queue, channel) {
466 spin_lock_bh(&rx_queue->add_lock);
467 spin_unlock_bh(&rx_queue->add_lock);
468 }
469}
470
471static void efx_fini_channels(struct efx_nic *efx)
472{
473 struct efx_channel *channel;
474 struct efx_tx_queue *tx_queue;
475 struct efx_rx_queue *rx_queue;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100476 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100477
478 EFX_ASSERT_RESET_SERIALISED(efx);
479 BUG_ON(efx->port_enabled);
480
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100481 rc = falcon_flush_queues(efx);
482 if (rc)
483 EFX_ERR(efx, "failed to flush queues\n");
484 else
485 EFX_LOG(efx, "successfully flushed all queues\n");
486
Ben Hutchings8ceee662008-04-27 12:55:59 +0100487 efx_for_each_channel(channel, efx) {
488 EFX_LOG(channel->efx, "shut down chan %d\n", channel->channel);
489
490 efx_for_each_channel_rx_queue(rx_queue, channel)
491 efx_fini_rx_queue(rx_queue);
492 efx_for_each_channel_tx_queue(tx_queue, channel)
493 efx_fini_tx_queue(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100494 efx_fini_eventq(channel);
495 }
496}
497
498static void efx_remove_channel(struct efx_channel *channel)
499{
500 struct efx_tx_queue *tx_queue;
501 struct efx_rx_queue *rx_queue;
502
503 EFX_LOG(channel->efx, "destroy chan %d\n", channel->channel);
504
505 efx_for_each_channel_rx_queue(rx_queue, channel)
506 efx_remove_rx_queue(rx_queue);
507 efx_for_each_channel_tx_queue(tx_queue, channel)
508 efx_remove_tx_queue(tx_queue);
509 efx_remove_eventq(channel);
510
511 channel->used_flags = 0;
512}
513
514void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay)
515{
516 queue_delayed_work(refill_workqueue, &rx_queue->work, delay);
517}
518
519/**************************************************************************
520 *
521 * Port handling
522 *
523 **************************************************************************/
524
525/* This ensures that the kernel is kept informed (via
526 * netif_carrier_on/off) of the link status, and also maintains the
527 * link status's stop on the port's TX queue.
528 */
529static void efx_link_status_changed(struct efx_nic *efx)
530{
Ben Hutchings8ceee662008-04-27 12:55:59 +0100531 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
532 * that no events are triggered between unregister_netdev() and the
533 * driver unloading. A more general condition is that NETDEV_CHANGE
534 * can only be generated between NETDEV_UP and NETDEV_DOWN */
535 if (!netif_running(efx->net_dev))
536 return;
537
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100538 if (efx->port_inhibited) {
539 netif_carrier_off(efx->net_dev);
540 return;
541 }
542
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100543 if (efx->link_up != netif_carrier_ok(efx->net_dev)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100544 efx->n_link_state_changes++;
545
546 if (efx->link_up)
547 netif_carrier_on(efx->net_dev);
548 else
549 netif_carrier_off(efx->net_dev);
550 }
551
552 /* Status message for kernel log */
553 if (efx->link_up) {
554 struct mii_if_info *gmii = &efx->mii;
555 unsigned adv, lpa;
556 /* NONE here means direct XAUI from the controller, with no
557 * MDIO-attached device we can query. */
558 if (efx->phy_type != PHY_TYPE_NONE) {
559 adv = gmii_advertised(gmii);
560 lpa = gmii_lpa(gmii);
561 } else {
562 lpa = GM_LPA_10000 | LPA_DUPLEX;
563 adv = lpa;
564 }
565 EFX_INFO(efx, "link up at %dMbps %s-duplex "
566 "(adv %04x lpa %04x) (MTU %d)%s\n",
567 (efx->link_options & GM_LPA_10000 ? 10000 :
568 (efx->link_options & GM_LPA_1000 ? 1000 :
569 (efx->link_options & GM_LPA_100 ? 100 :
570 10))),
571 (efx->link_options & GM_LPA_DUPLEX ?
572 "full" : "half"),
573 adv, lpa,
574 efx->net_dev->mtu,
575 (efx->promiscuous ? " [PROMISC]" : ""));
576 } else {
577 EFX_INFO(efx, "link down\n");
578 }
579
580}
581
582/* This call reinitialises the MAC to pick up new PHY settings. The
583 * caller must hold the mac_lock */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100584void __efx_reconfigure_port(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100585{
586 WARN_ON(!mutex_is_locked(&efx->mac_lock));
587
588 EFX_LOG(efx, "reconfiguring MAC from PHY settings on CPU %d\n",
589 raw_smp_processor_id());
590
Ben Hutchingsa816f752008-09-01 12:49:12 +0100591 /* Serialise the promiscuous flag with efx_set_multicast_list. */
592 if (efx_dev_registered(efx)) {
593 netif_addr_lock_bh(efx->net_dev);
594 netif_addr_unlock_bh(efx->net_dev);
595 }
596
Ben Hutchings8ceee662008-04-27 12:55:59 +0100597 falcon_reconfigure_xmac(efx);
598
599 /* Inform kernel of loss/gain of carrier */
600 efx_link_status_changed(efx);
601}
602
603/* Reinitialise the MAC to pick up new PHY settings, even if the port is
604 * disabled. */
605void efx_reconfigure_port(struct efx_nic *efx)
606{
607 EFX_ASSERT_RESET_SERIALISED(efx);
608
609 mutex_lock(&efx->mac_lock);
610 __efx_reconfigure_port(efx);
611 mutex_unlock(&efx->mac_lock);
612}
613
614/* Asynchronous efx_reconfigure_port work item. To speed up efx_flush_all()
615 * we don't efx_reconfigure_port() if the port is disabled. Care is taken
616 * in efx_stop_all() and efx_start_port() to prevent PHY events being lost */
617static void efx_reconfigure_work(struct work_struct *data)
618{
619 struct efx_nic *efx = container_of(data, struct efx_nic,
620 reconfigure_work);
621
622 mutex_lock(&efx->mac_lock);
623 if (efx->port_enabled)
624 __efx_reconfigure_port(efx);
625 mutex_unlock(&efx->mac_lock);
626}
627
628static int efx_probe_port(struct efx_nic *efx)
629{
630 int rc;
631
632 EFX_LOG(efx, "create port\n");
633
634 /* Connect up MAC/PHY operations table and read MAC address */
635 rc = falcon_probe_port(efx);
636 if (rc)
637 goto err;
638
Ben Hutchings84ae48f2008-12-12 21:34:54 -0800639 if (phy_flash_cfg)
640 efx->phy_mode = PHY_MODE_SPECIAL;
641
Ben Hutchings8ceee662008-04-27 12:55:59 +0100642 /* Sanity check MAC address */
643 if (is_valid_ether_addr(efx->mac_address)) {
644 memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN);
645 } else {
Johannes Berge1749612008-10-27 15:59:26 -0700646 EFX_ERR(efx, "invalid MAC address %pM\n",
647 efx->mac_address);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100648 if (!allow_bad_hwaddr) {
649 rc = -EINVAL;
650 goto err;
651 }
652 random_ether_addr(efx->net_dev->dev_addr);
Johannes Berge1749612008-10-27 15:59:26 -0700653 EFX_INFO(efx, "using locally-generated MAC %pM\n",
654 efx->net_dev->dev_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100655 }
656
657 return 0;
658
659 err:
660 efx_remove_port(efx);
661 return rc;
662}
663
664static int efx_init_port(struct efx_nic *efx)
665{
666 int rc;
667
668 EFX_LOG(efx, "init port\n");
669
670 /* Initialise the MAC and PHY */
671 rc = falcon_init_xmac(efx);
672 if (rc)
673 return rc;
674
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100675 efx->port_initialized = true;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100676 efx->stats_enabled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100677
678 /* Reconfigure port to program MAC registers */
679 falcon_reconfigure_xmac(efx);
680
681 return 0;
682}
683
684/* Allow efx_reconfigure_port() to be scheduled, and close the window
685 * between efx_stop_port and efx_flush_all whereby a previously scheduled
686 * efx_reconfigure_port() may have been cancelled */
687static void efx_start_port(struct efx_nic *efx)
688{
689 EFX_LOG(efx, "start port\n");
690 BUG_ON(efx->port_enabled);
691
692 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100693 efx->port_enabled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100694 __efx_reconfigure_port(efx);
695 mutex_unlock(&efx->mac_lock);
696}
697
698/* Prevent efx_reconfigure_work and efx_monitor() from executing, and
699 * efx_set_multicast_list() from scheduling efx_reconfigure_work.
700 * efx_reconfigure_work can still be scheduled via NAPI processing
701 * until efx_flush_all() is called */
702static void efx_stop_port(struct efx_nic *efx)
703{
704 EFX_LOG(efx, "stop port\n");
705
706 mutex_lock(&efx->mac_lock);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100707 efx->port_enabled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100708 mutex_unlock(&efx->mac_lock);
709
710 /* Serialise against efx_set_multicast_list() */
Ben Hutchings55668612008-05-16 21:16:10 +0100711 if (efx_dev_registered(efx)) {
David S. Millerb9e40852008-07-15 00:15:08 -0700712 netif_addr_lock_bh(efx->net_dev);
713 netif_addr_unlock_bh(efx->net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100714 }
715}
716
717static void efx_fini_port(struct efx_nic *efx)
718{
719 EFX_LOG(efx, "shut down port\n");
720
721 if (!efx->port_initialized)
722 return;
723
724 falcon_fini_xmac(efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100725 efx->port_initialized = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100726
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100727 efx->link_up = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100728 efx_link_status_changed(efx);
729}
730
731static void efx_remove_port(struct efx_nic *efx)
732{
733 EFX_LOG(efx, "destroying port\n");
734
735 falcon_remove_port(efx);
736}
737
738/**************************************************************************
739 *
740 * NIC handling
741 *
742 **************************************************************************/
743
744/* This configures the PCI device to enable I/O and DMA. */
745static int efx_init_io(struct efx_nic *efx)
746{
747 struct pci_dev *pci_dev = efx->pci_dev;
748 dma_addr_t dma_mask = efx->type->max_dma_mask;
749 int rc;
750
751 EFX_LOG(efx, "initialising I/O\n");
752
753 rc = pci_enable_device(pci_dev);
754 if (rc) {
755 EFX_ERR(efx, "failed to enable PCI device\n");
756 goto fail1;
757 }
758
759 pci_set_master(pci_dev);
760
761 /* Set the PCI DMA mask. Try all possibilities from our
762 * genuine mask down to 32 bits, because some architectures
763 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
764 * masks event though they reject 46 bit masks.
765 */
766 while (dma_mask > 0x7fffffffUL) {
767 if (pci_dma_supported(pci_dev, dma_mask) &&
768 ((rc = pci_set_dma_mask(pci_dev, dma_mask)) == 0))
769 break;
770 dma_mask >>= 1;
771 }
772 if (rc) {
773 EFX_ERR(efx, "could not find a suitable DMA mask\n");
774 goto fail2;
775 }
776 EFX_LOG(efx, "using DMA mask %llx\n", (unsigned long long) dma_mask);
777 rc = pci_set_consistent_dma_mask(pci_dev, dma_mask);
778 if (rc) {
779 /* pci_set_consistent_dma_mask() is not *allowed* to
780 * fail with a mask that pci_set_dma_mask() accepted,
781 * but just in case...
782 */
783 EFX_ERR(efx, "failed to set consistent DMA mask\n");
784 goto fail2;
785 }
786
787 efx->membase_phys = pci_resource_start(efx->pci_dev,
788 efx->type->mem_bar);
789 rc = pci_request_region(pci_dev, efx->type->mem_bar, "sfc");
790 if (rc) {
791 EFX_ERR(efx, "request for memory BAR failed\n");
792 rc = -EIO;
793 goto fail3;
794 }
795 efx->membase = ioremap_nocache(efx->membase_phys,
796 efx->type->mem_map_size);
797 if (!efx->membase) {
Ben Hutchings086ea352008-05-16 21:17:06 +0100798 EFX_ERR(efx, "could not map memory BAR %d at %llx+%x\n",
799 efx->type->mem_bar,
800 (unsigned long long)efx->membase_phys,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100801 efx->type->mem_map_size);
802 rc = -ENOMEM;
803 goto fail4;
804 }
Ben Hutchings086ea352008-05-16 21:17:06 +0100805 EFX_LOG(efx, "memory BAR %u at %llx+%x (virtual %p)\n",
806 efx->type->mem_bar, (unsigned long long)efx->membase_phys,
807 efx->type->mem_map_size, efx->membase);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100808
809 return 0;
810
811 fail4:
Ben Hutchingse1074a02008-09-01 12:49:15 +0100812 pci_release_region(efx->pci_dev, efx->type->mem_bar);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100813 fail3:
Ben Hutchings2c118e02008-05-16 21:15:29 +0100814 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100815 fail2:
816 pci_disable_device(efx->pci_dev);
817 fail1:
818 return rc;
819}
820
821static void efx_fini_io(struct efx_nic *efx)
822{
823 EFX_LOG(efx, "shutting down I/O\n");
824
825 if (efx->membase) {
826 iounmap(efx->membase);
827 efx->membase = NULL;
828 }
829
830 if (efx->membase_phys) {
831 pci_release_region(efx->pci_dev, efx->type->mem_bar);
Ben Hutchings2c118e02008-05-16 21:15:29 +0100832 efx->membase_phys = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100833 }
834
835 pci_disable_device(efx->pci_dev);
836}
837
Ben Hutchings46123d02008-09-01 12:47:33 +0100838/* Get number of RX queues wanted. Return number of online CPU
839 * packages in the expectation that an IRQ balancer will spread
840 * interrupts across them. */
841static int efx_wanted_rx_queues(void)
842{
843 cpumask_t core_mask;
844 int count;
845 int cpu;
846
847 cpus_clear(core_mask);
848 count = 0;
849 for_each_online_cpu(cpu) {
850 if (!cpu_isset(cpu, core_mask)) {
851 ++count;
852 cpus_or(core_mask, core_mask,
853 topology_core_siblings(cpu));
854 }
855 }
856
857 return count;
858}
859
860/* Probe the number and type of interrupts we are able to obtain, and
861 * the resulting numbers of channels and RX queues.
862 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100863static void efx_probe_interrupts(struct efx_nic *efx)
864{
Ben Hutchings46123d02008-09-01 12:47:33 +0100865 int max_channels =
866 min_t(int, efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100867 int rc, i;
868
869 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
Ben Hutchings46123d02008-09-01 12:47:33 +0100870 struct msix_entry xentries[EFX_MAX_CHANNELS];
871 int wanted_ints;
Neil Turton28b581a2008-12-12 21:41:06 -0800872 int rx_queues;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100873
Ben Hutchings46123d02008-09-01 12:47:33 +0100874 /* We want one RX queue and interrupt per CPU package
875 * (or as specified by the rss_cpus module parameter).
876 * We will need one channel per interrupt.
877 */
Neil Turton28b581a2008-12-12 21:41:06 -0800878 rx_queues = rss_cpus ? rss_cpus : efx_wanted_rx_queues();
879 wanted_ints = rx_queues + (separate_tx_channels ? 1 : 0);
880 wanted_ints = min(wanted_ints, max_channels);
Ben Hutchingsaa6ef272008-07-18 19:03:10 +0100881
Neil Turton28b581a2008-12-12 21:41:06 -0800882 for (i = 0; i < wanted_ints; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100883 xentries[i].entry = i;
Neil Turton28b581a2008-12-12 21:41:06 -0800884 rc = pci_enable_msix(efx->pci_dev, xentries, wanted_ints);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100885 if (rc > 0) {
Neil Turton28b581a2008-12-12 21:41:06 -0800886 EFX_ERR(efx, "WARNING: Insufficient MSI-X vectors"
887 " available (%d < %d).\n", rc, wanted_ints);
888 EFX_ERR(efx, "WARNING: Performance may be reduced.\n");
889 EFX_BUG_ON_PARANOID(rc >= wanted_ints);
890 wanted_ints = rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100891 rc = pci_enable_msix(efx->pci_dev, xentries,
Neil Turton28b581a2008-12-12 21:41:06 -0800892 wanted_ints);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100893 }
894
895 if (rc == 0) {
Neil Turton28b581a2008-12-12 21:41:06 -0800896 efx->n_rx_queues = min(rx_queues, wanted_ints);
897 efx->n_channels = wanted_ints;
898 for (i = 0; i < wanted_ints; i++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100899 efx->channel[i].irq = xentries[i].vector;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100900 } else {
901 /* Fall back to single channel MSI */
902 efx->interrupt_mode = EFX_INT_MODE_MSI;
903 EFX_ERR(efx, "could not enable MSI-X\n");
904 }
905 }
906
907 /* Try single interrupt MSI */
908 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
Ben Hutchings8831da72008-09-01 12:47:48 +0100909 efx->n_rx_queues = 1;
Neil Turton28b581a2008-12-12 21:41:06 -0800910 efx->n_channels = 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100911 rc = pci_enable_msi(efx->pci_dev);
912 if (rc == 0) {
913 efx->channel[0].irq = efx->pci_dev->irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100914 } else {
915 EFX_ERR(efx, "could not enable MSI\n");
916 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
917 }
918 }
919
920 /* Assume legacy interrupts */
921 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
Ben Hutchings8831da72008-09-01 12:47:48 +0100922 efx->n_rx_queues = 1;
Neil Turton28b581a2008-12-12 21:41:06 -0800923 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100924 efx->legacy_irq = efx->pci_dev->irq;
925 }
926}
927
928static void efx_remove_interrupts(struct efx_nic *efx)
929{
930 struct efx_channel *channel;
931
932 /* Remove MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +0100933 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100934 channel->irq = 0;
935 pci_disable_msi(efx->pci_dev);
936 pci_disable_msix(efx->pci_dev);
937
938 /* Remove legacy interrupt */
939 efx->legacy_irq = 0;
940}
941
Ben Hutchings8831da72008-09-01 12:47:48 +0100942static void efx_set_channels(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100943{
944 struct efx_tx_queue *tx_queue;
945 struct efx_rx_queue *rx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100946
Ben Hutchings60ac1062008-09-01 12:44:59 +0100947 efx_for_each_tx_queue(tx_queue, efx) {
Neil Turton28b581a2008-12-12 21:41:06 -0800948 if (separate_tx_channels)
949 tx_queue->channel = &efx->channel[efx->n_channels-1];
Ben Hutchings60ac1062008-09-01 12:44:59 +0100950 else
951 tx_queue->channel = &efx->channel[0];
952 tx_queue->channel->used_flags |= EFX_USED_BY_TX;
953 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100954
Ben Hutchings8831da72008-09-01 12:47:48 +0100955 efx_for_each_rx_queue(rx_queue, efx) {
956 rx_queue->channel = &efx->channel[rx_queue->queue];
957 rx_queue->channel->used_flags |= EFX_USED_BY_RX;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100958 }
959}
960
961static int efx_probe_nic(struct efx_nic *efx)
962{
963 int rc;
964
965 EFX_LOG(efx, "creating NIC\n");
966
967 /* Carry out hardware-type specific initialisation */
968 rc = falcon_probe_nic(efx);
969 if (rc)
970 return rc;
971
972 /* Determine the number of channels and RX queues by trying to hook
973 * in MSI-X interrupts. */
974 efx_probe_interrupts(efx);
975
Ben Hutchings8831da72008-09-01 12:47:48 +0100976 efx_set_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100977
978 /* Initialise the interrupt moderation settings */
979 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec);
980
981 return 0;
982}
983
984static void efx_remove_nic(struct efx_nic *efx)
985{
986 EFX_LOG(efx, "destroying NIC\n");
987
988 efx_remove_interrupts(efx);
989 falcon_remove_nic(efx);
990}
991
992/**************************************************************************
993 *
994 * NIC startup/shutdown
995 *
996 *************************************************************************/
997
998static int efx_probe_all(struct efx_nic *efx)
999{
1000 struct efx_channel *channel;
1001 int rc;
1002
1003 /* Create NIC */
1004 rc = efx_probe_nic(efx);
1005 if (rc) {
1006 EFX_ERR(efx, "failed to create NIC\n");
1007 goto fail1;
1008 }
1009
1010 /* Create port */
1011 rc = efx_probe_port(efx);
1012 if (rc) {
1013 EFX_ERR(efx, "failed to create port\n");
1014 goto fail2;
1015 }
1016
1017 /* Create channels */
1018 efx_for_each_channel(channel, efx) {
1019 rc = efx_probe_channel(channel);
1020 if (rc) {
1021 EFX_ERR(efx, "failed to create channel %d\n",
1022 channel->channel);
1023 goto fail3;
1024 }
1025 }
Ben Hutchings56536e92008-12-12 21:37:02 -08001026 efx_set_channel_names(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001027
1028 return 0;
1029
1030 fail3:
1031 efx_for_each_channel(channel, efx)
1032 efx_remove_channel(channel);
1033 efx_remove_port(efx);
1034 fail2:
1035 efx_remove_nic(efx);
1036 fail1:
1037 return rc;
1038}
1039
1040/* Called after previous invocation(s) of efx_stop_all, restarts the
1041 * port, kernel transmit queue, NAPI processing and hardware interrupts,
1042 * and ensures that the port is scheduled to be reconfigured.
1043 * This function is safe to call multiple times when the NIC is in any
1044 * state. */
1045static void efx_start_all(struct efx_nic *efx)
1046{
1047 struct efx_channel *channel;
1048
1049 EFX_ASSERT_RESET_SERIALISED(efx);
1050
1051 /* Check that it is appropriate to restart the interface. All
1052 * of these flags are safe to read under just the rtnl lock */
1053 if (efx->port_enabled)
1054 return;
1055 if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT))
1056 return;
Ben Hutchings55668612008-05-16 21:16:10 +01001057 if (efx_dev_registered(efx) && !netif_running(efx->net_dev))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001058 return;
1059
1060 /* Mark the port as enabled so port reconfigurations can start, then
1061 * restart the transmit interface early so the watchdog timer stops */
1062 efx_start_port(efx);
Steve Hodgsondacccc72008-09-01 12:48:20 +01001063 if (efx_dev_registered(efx))
1064 efx_wake_queue(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001065
1066 efx_for_each_channel(channel, efx)
1067 efx_start_channel(channel);
1068
1069 falcon_enable_interrupts(efx);
1070
1071 /* Start hardware monitor if we're in RUNNING */
1072 if (efx->state == STATE_RUNNING)
1073 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1074 efx_monitor_interval);
1075}
1076
1077/* Flush all delayed work. Should only be called when no more delayed work
1078 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1079 * since we're holding the rtnl_lock at this point. */
1080static void efx_flush_all(struct efx_nic *efx)
1081{
1082 struct efx_rx_queue *rx_queue;
1083
1084 /* Make sure the hardware monitor is stopped */
1085 cancel_delayed_work_sync(&efx->monitor_work);
1086
1087 /* Ensure that all RX slow refills are complete. */
Ben Hutchingsb3475642008-05-16 21:15:49 +01001088 efx_for_each_rx_queue(rx_queue, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001089 cancel_delayed_work_sync(&rx_queue->work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090
1091 /* Stop scheduled port reconfigurations */
1092 cancel_work_sync(&efx->reconfigure_work);
1093
1094}
1095
1096/* Quiesce hardware and software without bringing the link down.
1097 * Safe to call multiple times, when the nic and interface is in any
1098 * state. The caller is guaranteed to subsequently be in a position
1099 * to modify any hardware and software state they see fit without
1100 * taking locks. */
1101static void efx_stop_all(struct efx_nic *efx)
1102{
1103 struct efx_channel *channel;
1104
1105 EFX_ASSERT_RESET_SERIALISED(efx);
1106
1107 /* port_enabled can be read safely under the rtnl lock */
1108 if (!efx->port_enabled)
1109 return;
1110
1111 /* Disable interrupts and wait for ISR to complete */
1112 falcon_disable_interrupts(efx);
1113 if (efx->legacy_irq)
1114 synchronize_irq(efx->legacy_irq);
Ben Hutchings64ee3122008-09-01 12:47:38 +01001115 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001116 if (channel->irq)
1117 synchronize_irq(channel->irq);
Ben Hutchingsb3475642008-05-16 21:15:49 +01001118 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001119
1120 /* Stop all NAPI processing and synchronous rx refills */
1121 efx_for_each_channel(channel, efx)
1122 efx_stop_channel(channel);
1123
1124 /* Stop all asynchronous port reconfigurations. Since all
1125 * event processing has already been stopped, there is no
1126 * window to loose phy events */
1127 efx_stop_port(efx);
1128
1129 /* Flush reconfigure_work, refill_workqueue, monitor_work */
1130 efx_flush_all(efx);
1131
1132 /* Isolate the MAC from the TX and RX engines, so that queue
1133 * flushes will complete in a timely fashion. */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001134 falcon_drain_tx_fifo(efx);
1135
1136 /* Stop the kernel transmit interface late, so the watchdog
1137 * timer isn't ticking over the flush */
Ben Hutchings55668612008-05-16 21:16:10 +01001138 if (efx_dev_registered(efx)) {
Steve Hodgsondacccc72008-09-01 12:48:20 +01001139 efx_stop_queue(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001140 netif_tx_lock_bh(efx->net_dev);
1141 netif_tx_unlock_bh(efx->net_dev);
1142 }
1143}
1144
1145static void efx_remove_all(struct efx_nic *efx)
1146{
1147 struct efx_channel *channel;
1148
1149 efx_for_each_channel(channel, efx)
1150 efx_remove_channel(channel);
1151 efx_remove_port(efx);
1152 efx_remove_nic(efx);
1153}
1154
1155/* A convinience function to safely flush all the queues */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001156void efx_flush_queues(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001157{
Ben Hutchings8ceee662008-04-27 12:55:59 +01001158 EFX_ASSERT_RESET_SERIALISED(efx);
1159
1160 efx_stop_all(efx);
1161
1162 efx_fini_channels(efx);
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001163 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001164
1165 efx_start_all(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001166}
1167
1168/**************************************************************************
1169 *
1170 * Interrupt moderation
1171 *
1172 **************************************************************************/
1173
1174/* Set interrupt moderation parameters */
1175void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs)
1176{
1177 struct efx_tx_queue *tx_queue;
1178 struct efx_rx_queue *rx_queue;
1179
1180 EFX_ASSERT_RESET_SERIALISED(efx);
1181
1182 efx_for_each_tx_queue(tx_queue, efx)
1183 tx_queue->channel->irq_moderation = tx_usecs;
1184
1185 efx_for_each_rx_queue(rx_queue, efx)
1186 rx_queue->channel->irq_moderation = rx_usecs;
1187}
1188
1189/**************************************************************************
1190 *
1191 * Hardware monitor
1192 *
1193 **************************************************************************/
1194
1195/* Run periodically off the general workqueue. Serialised against
1196 * efx_reconfigure_port via the mac_lock */
1197static void efx_monitor(struct work_struct *data)
1198{
1199 struct efx_nic *efx = container_of(data, struct efx_nic,
1200 monitor_work.work);
1201 int rc = 0;
1202
1203 EFX_TRACE(efx, "hardware monitor executing on CPU %d\n",
1204 raw_smp_processor_id());
1205
1206
1207 /* If the mac_lock is already held then it is likely a port
1208 * reconfiguration is already in place, which will likely do
1209 * most of the work of check_hw() anyway. */
1210 if (!mutex_trylock(&efx->mac_lock)) {
1211 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1212 efx_monitor_interval);
1213 return;
1214 }
1215
1216 if (efx->port_enabled)
1217 rc = falcon_check_xmac(efx);
1218 mutex_unlock(&efx->mac_lock);
1219
Ben Hutchings8ceee662008-04-27 12:55:59 +01001220 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1221 efx_monitor_interval);
1222}
1223
1224/**************************************************************************
1225 *
1226 * ioctls
1227 *
1228 *************************************************************************/
1229
1230/* Net device ioctl
1231 * Context: process, rtnl_lock() held.
1232 */
1233static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1234{
Ben Hutchings767e4682008-09-01 12:43:14 +01001235 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001236
1237 EFX_ASSERT_RESET_SERIALISED(efx);
1238
1239 return generic_mii_ioctl(&efx->mii, if_mii(ifr), cmd, NULL);
1240}
1241
1242/**************************************************************************
1243 *
1244 * NAPI interface
1245 *
1246 **************************************************************************/
1247
1248static int efx_init_napi(struct efx_nic *efx)
1249{
1250 struct efx_channel *channel;
1251 int rc;
1252
1253 efx_for_each_channel(channel, efx) {
1254 channel->napi_dev = efx->net_dev;
1255 rc = efx_lro_init(&channel->lro_mgr, efx);
1256 if (rc)
1257 goto err;
1258 }
1259 return 0;
1260 err:
1261 efx_fini_napi(efx);
1262 return rc;
1263}
1264
1265static void efx_fini_napi(struct efx_nic *efx)
1266{
1267 struct efx_channel *channel;
1268
1269 efx_for_each_channel(channel, efx) {
1270 efx_lro_fini(&channel->lro_mgr);
1271 channel->napi_dev = NULL;
1272 }
1273}
1274
1275/**************************************************************************
1276 *
1277 * Kernel netpoll interface
1278 *
1279 *************************************************************************/
1280
1281#ifdef CONFIG_NET_POLL_CONTROLLER
1282
1283/* Although in the common case interrupts will be disabled, this is not
1284 * guaranteed. However, all our work happens inside the NAPI callback,
1285 * so no locking is required.
1286 */
1287static void efx_netpoll(struct net_device *net_dev)
1288{
Ben Hutchings767e4682008-09-01 12:43:14 +01001289 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001290 struct efx_channel *channel;
1291
Ben Hutchings64ee3122008-09-01 12:47:38 +01001292 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001293 efx_schedule_channel(channel);
1294}
1295
1296#endif
1297
1298/**************************************************************************
1299 *
1300 * Kernel net device interface
1301 *
1302 *************************************************************************/
1303
1304/* Context: process, rtnl_lock() held. */
1305static int efx_net_open(struct net_device *net_dev)
1306{
Ben Hutchings767e4682008-09-01 12:43:14 +01001307 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001308 EFX_ASSERT_RESET_SERIALISED(efx);
1309
1310 EFX_LOG(efx, "opening device %s on CPU %d\n", net_dev->name,
1311 raw_smp_processor_id());
1312
Ben Hutchingsf8b87c12008-09-01 12:48:17 +01001313 if (efx->phy_mode & PHY_MODE_SPECIAL)
1314 return -EBUSY;
1315
Ben Hutchings8ceee662008-04-27 12:55:59 +01001316 efx_start_all(efx);
1317 return 0;
1318}
1319
1320/* Context: process, rtnl_lock() held.
1321 * Note that the kernel will ignore our return code; this method
1322 * should really be a void.
1323 */
1324static int efx_net_stop(struct net_device *net_dev)
1325{
Ben Hutchings767e4682008-09-01 12:43:14 +01001326 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001327
1328 EFX_LOG(efx, "closing %s on CPU %d\n", net_dev->name,
1329 raw_smp_processor_id());
1330
1331 /* Stop the device and flush all the channels */
1332 efx_stop_all(efx);
1333 efx_fini_channels(efx);
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001334 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001335
1336 return 0;
1337}
1338
Ben Hutchings5b9e2072008-05-16 21:18:14 +01001339/* Context: process, dev_base_lock or RTNL held, non-blocking. */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001340static struct net_device_stats *efx_net_stats(struct net_device *net_dev)
1341{
Ben Hutchings767e4682008-09-01 12:43:14 +01001342 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001343 struct efx_mac_stats *mac_stats = &efx->mac_stats;
1344 struct net_device_stats *stats = &net_dev->stats;
1345
Ben Hutchings5b9e2072008-05-16 21:18:14 +01001346 /* Update stats if possible, but do not wait if another thread
1347 * is updating them (or resetting the NIC); slightly stale
1348 * stats are acceptable.
1349 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001350 if (!spin_trylock(&efx->stats_lock))
1351 return stats;
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001352 if (efx->stats_enabled) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001353 falcon_update_stats_xmac(efx);
1354 falcon_update_nic_stats(efx);
1355 }
1356 spin_unlock(&efx->stats_lock);
1357
1358 stats->rx_packets = mac_stats->rx_packets;
1359 stats->tx_packets = mac_stats->tx_packets;
1360 stats->rx_bytes = mac_stats->rx_bytes;
1361 stats->tx_bytes = mac_stats->tx_bytes;
1362 stats->multicast = mac_stats->rx_multicast;
1363 stats->collisions = mac_stats->tx_collision;
1364 stats->rx_length_errors = (mac_stats->rx_gtjumbo +
1365 mac_stats->rx_length_error);
1366 stats->rx_over_errors = efx->n_rx_nodesc_drop_cnt;
1367 stats->rx_crc_errors = mac_stats->rx_bad;
1368 stats->rx_frame_errors = mac_stats->rx_align_error;
1369 stats->rx_fifo_errors = mac_stats->rx_overflow;
1370 stats->rx_missed_errors = mac_stats->rx_missed;
1371 stats->tx_window_errors = mac_stats->tx_late_collision;
1372
1373 stats->rx_errors = (stats->rx_length_errors +
1374 stats->rx_over_errors +
1375 stats->rx_crc_errors +
1376 stats->rx_frame_errors +
1377 stats->rx_fifo_errors +
1378 stats->rx_missed_errors +
1379 mac_stats->rx_symbol_error);
1380 stats->tx_errors = (stats->tx_window_errors +
1381 mac_stats->tx_bad);
1382
1383 return stats;
1384}
1385
1386/* Context: netif_tx_lock held, BHs disabled. */
1387static void efx_watchdog(struct net_device *net_dev)
1388{
Ben Hutchings767e4682008-09-01 12:43:14 +01001389 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001390
Ben Hutchings739bb23d2008-11-04 20:35:36 +00001391 EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d:"
1392 " resetting channels\n",
1393 atomic_read(&efx->netif_stop_count), efx->port_enabled);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001394
Ben Hutchings739bb23d2008-11-04 20:35:36 +00001395 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001396}
1397
1398
1399/* Context: process, rtnl_lock() held. */
1400static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1401{
Ben Hutchings767e4682008-09-01 12:43:14 +01001402 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001403 int rc = 0;
1404
1405 EFX_ASSERT_RESET_SERIALISED(efx);
1406
1407 if (new_mtu > EFX_MAX_MTU)
1408 return -EINVAL;
1409
1410 efx_stop_all(efx);
1411
1412 EFX_LOG(efx, "changing MTU to %d\n", new_mtu);
1413
1414 efx_fini_channels(efx);
1415 net_dev->mtu = new_mtu;
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001416 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001417
1418 efx_start_all(efx);
1419 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001420}
1421
1422static int efx_set_mac_address(struct net_device *net_dev, void *data)
1423{
Ben Hutchings767e4682008-09-01 12:43:14 +01001424 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001425 struct sockaddr *addr = data;
1426 char *new_addr = addr->sa_data;
1427
1428 EFX_ASSERT_RESET_SERIALISED(efx);
1429
1430 if (!is_valid_ether_addr(new_addr)) {
Johannes Berge1749612008-10-27 15:59:26 -07001431 EFX_ERR(efx, "invalid ethernet MAC address requested: %pM\n",
1432 new_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001433 return -EINVAL;
1434 }
1435
1436 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
1437
1438 /* Reconfigure the MAC */
1439 efx_reconfigure_port(efx);
1440
1441 return 0;
1442}
1443
Ben Hutchingsa816f752008-09-01 12:49:12 +01001444/* Context: netif_addr_lock held, BHs disabled. */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001445static void efx_set_multicast_list(struct net_device *net_dev)
1446{
Ben Hutchings767e4682008-09-01 12:43:14 +01001447 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001448 struct dev_mc_list *mc_list = net_dev->mc_list;
1449 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
Ben Hutchingsa816f752008-09-01 12:49:12 +01001450 bool promiscuous = !!(net_dev->flags & IFF_PROMISC);
1451 bool changed = (efx->promiscuous != promiscuous);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001452 u32 crc;
1453 int bit;
1454 int i;
1455
Ben Hutchingsa816f752008-09-01 12:49:12 +01001456 efx->promiscuous = promiscuous;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001457
1458 /* Build multicast hash table */
1459 if (promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
1460 memset(mc_hash, 0xff, sizeof(*mc_hash));
1461 } else {
1462 memset(mc_hash, 0x00, sizeof(*mc_hash));
1463 for (i = 0; i < net_dev->mc_count; i++) {
1464 crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr);
1465 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1466 set_bit_le(bit, mc_hash->byte);
1467 mc_list = mc_list->next;
1468 }
1469 }
1470
Ben Hutchingsa816f752008-09-01 12:49:12 +01001471 if (!efx->port_enabled)
1472 /* Delay pushing settings until efx_start_port() */
1473 return;
1474
1475 if (changed)
1476 queue_work(efx->workqueue, &efx->reconfigure_work);
1477
Ben Hutchings8ceee662008-04-27 12:55:59 +01001478 /* Create and activate new global multicast hash table */
1479 falcon_set_multicast_hash(efx);
1480}
1481
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001482static const struct net_device_ops efx_netdev_ops = {
1483 .ndo_open = efx_net_open,
1484 .ndo_stop = efx_net_stop,
1485 .ndo_get_stats = efx_net_stats,
1486 .ndo_tx_timeout = efx_watchdog,
1487 .ndo_start_xmit = efx_hard_start_xmit,
1488 .ndo_validate_addr = eth_validate_addr,
1489 .ndo_do_ioctl = efx_ioctl,
1490 .ndo_change_mtu = efx_change_mtu,
1491 .ndo_set_mac_address = efx_set_mac_address,
1492 .ndo_set_multicast_list = efx_set_multicast_list,
1493#ifdef CONFIG_NET_POLL_CONTROLLER
1494 .ndo_poll_controller = efx_netpoll,
1495#endif
1496};
1497
Ben Hutchings8ceee662008-04-27 12:55:59 +01001498static int efx_netdev_event(struct notifier_block *this,
1499 unsigned long event, void *ptr)
1500{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001501 struct net_device *net_dev = ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001502
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001503 if (net_dev->netdev_ops == &efx_netdev_ops && event == NETDEV_CHANGENAME) {
Ben Hutchings767e4682008-09-01 12:43:14 +01001504 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001505
1506 strcpy(efx->name, net_dev->name);
Ben Hutchingsf4150722008-11-04 20:34:28 +00001507 efx_mtd_rename(efx);
Ben Hutchings56536e92008-12-12 21:37:02 -08001508 efx_set_channel_names(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001509 }
1510
1511 return NOTIFY_DONE;
1512}
1513
1514static struct notifier_block efx_netdev_notifier = {
1515 .notifier_call = efx_netdev_event,
1516};
1517
1518static int efx_register_netdev(struct efx_nic *efx)
1519{
1520 struct net_device *net_dev = efx->net_dev;
1521 int rc;
1522
1523 net_dev->watchdog_timeo = 5 * HZ;
1524 net_dev->irq = efx->pci_dev->irq;
Stephen Hemmingerc3ecb9f2008-11-21 17:32:54 -08001525 net_dev->netdev_ops = &efx_netdev_ops;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001526 SET_NETDEV_DEV(net_dev, &efx->pci_dev->dev);
1527 SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
1528
1529 /* Always start with carrier off; PHY events will detect the link */
1530 netif_carrier_off(efx->net_dev);
1531
1532 /* Clear MAC statistics */
1533 falcon_update_stats_xmac(efx);
1534 memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
1535
1536 rc = register_netdev(net_dev);
1537 if (rc) {
1538 EFX_ERR(efx, "could not register net dev\n");
1539 return rc;
1540 }
1541 strcpy(efx->name, net_dev->name);
Ben Hutchings56536e92008-12-12 21:37:02 -08001542 efx_set_channel_names(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001543
1544 return 0;
1545}
1546
1547static void efx_unregister_netdev(struct efx_nic *efx)
1548{
1549 struct efx_tx_queue *tx_queue;
1550
1551 if (!efx->net_dev)
1552 return;
1553
Ben Hutchings767e4682008-09-01 12:43:14 +01001554 BUG_ON(netdev_priv(efx->net_dev) != efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001555
1556 /* Free up any skbs still remaining. This has to happen before
1557 * we try to unregister the netdev as running their destructors
1558 * may be needed to get the device ref. count to 0. */
1559 efx_for_each_tx_queue(tx_queue, efx)
1560 efx_release_tx_buffers(tx_queue);
1561
Ben Hutchings55668612008-05-16 21:16:10 +01001562 if (efx_dev_registered(efx)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001563 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
1564 unregister_netdev(efx->net_dev);
1565 }
1566}
1567
1568/**************************************************************************
1569 *
1570 * Device reset and suspend
1571 *
1572 **************************************************************************/
1573
Ben Hutchings2467ca42008-09-01 12:48:50 +01001574/* Tears down the entire software state and most of the hardware state
1575 * before reset. */
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001576void efx_reset_down(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001577{
1578 int rc;
1579
1580 EFX_ASSERT_RESET_SERIALISED(efx);
1581
Ben Hutchings2467ca42008-09-01 12:48:50 +01001582 /* The net_dev->get_stats handler is quite slow, and will fail
1583 * if a fetch is pending over reset. Serialise against it. */
1584 spin_lock(&efx->stats_lock);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001585 efx->stats_enabled = false;
Ben Hutchings2467ca42008-09-01 12:48:50 +01001586 spin_unlock(&efx->stats_lock);
1587
1588 efx_stop_all(efx);
1589 mutex_lock(&efx->mac_lock);
Ben Hutchingsf4150722008-11-04 20:34:28 +00001590 mutex_lock(&efx->spi_lock);
Ben Hutchings2467ca42008-09-01 12:48:50 +01001591
Ben Hutchings8ceee662008-04-27 12:55:59 +01001592 rc = falcon_xmac_get_settings(efx, ecmd);
Ben Hutchings2467ca42008-09-01 12:48:50 +01001593 if (rc)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001594 EFX_ERR(efx, "could not back up PHY settings\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001595
1596 efx_fini_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001597}
1598
Ben Hutchings2467ca42008-09-01 12:48:50 +01001599/* This function will always ensure that the locks acquired in
1600 * efx_reset_down() are released. A failure return code indicates
1601 * that we were unable to reinitialise the hardware, and the
1602 * driver should be disabled. If ok is false, then the rx and tx
1603 * engines are not restarted, pending a RESET_DISABLE. */
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001604int efx_reset_up(struct efx_nic *efx, struct ethtool_cmd *ecmd, bool ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001605{
1606 int rc;
1607
Ben Hutchings2467ca42008-09-01 12:48:50 +01001608 EFX_ASSERT_RESET_SERIALISED(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001609
Ben Hutchings2467ca42008-09-01 12:48:50 +01001610 rc = falcon_init_nic(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001611 if (rc) {
Ben Hutchings2467ca42008-09-01 12:48:50 +01001612 EFX_ERR(efx, "failed to initialise NIC\n");
1613 ok = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001614 }
1615
Ben Hutchings2467ca42008-09-01 12:48:50 +01001616 if (ok) {
1617 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001618
Ben Hutchings2467ca42008-09-01 12:48:50 +01001619 if (falcon_xmac_set_settings(efx, ecmd))
1620 EFX_ERR(efx, "could not restore PHY settings\n");
1621 }
1622
Ben Hutchingsf4150722008-11-04 20:34:28 +00001623 mutex_unlock(&efx->spi_lock);
Ben Hutchings2467ca42008-09-01 12:48:50 +01001624 mutex_unlock(&efx->mac_lock);
1625
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001626 if (ok) {
Ben Hutchings2467ca42008-09-01 12:48:50 +01001627 efx_start_all(efx);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01001628 efx->stats_enabled = true;
1629 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001630 return rc;
1631}
1632
1633/* Reset the NIC as transparently as possible. Do not reset the PHY
1634 * Note that the reset may fail, in which case the card will be left
1635 * in a most-probably-unusable state.
1636 *
1637 * This function will sleep. You cannot reset from within an atomic
1638 * state; use efx_schedule_reset() instead.
1639 *
1640 * Grabs the rtnl_lock.
1641 */
1642static int efx_reset(struct efx_nic *efx)
1643{
1644 struct ethtool_cmd ecmd;
1645 enum reset_type method = efx->reset_pending;
1646 int rc;
1647
1648 /* Serialise with kernel interfaces */
1649 rtnl_lock();
1650
1651 /* If we're not RUNNING then don't reset. Leave the reset_pending
1652 * flag set so that efx_pci_probe_main will be retried */
1653 if (efx->state != STATE_RUNNING) {
1654 EFX_INFO(efx, "scheduled reset quenched. NIC not RUNNING\n");
1655 goto unlock_rtnl;
1656 }
1657
Ben Hutchings8ceee662008-04-27 12:55:59 +01001658 EFX_INFO(efx, "resetting (%d)\n", method);
1659
Ben Hutchings2467ca42008-09-01 12:48:50 +01001660 efx_reset_down(efx, &ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001661
1662 rc = falcon_reset_hw(efx, method);
1663 if (rc) {
1664 EFX_ERR(efx, "failed to reset hardware\n");
Ben Hutchings2467ca42008-09-01 12:48:50 +01001665 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001666 }
1667
1668 /* Allow resets to be rescheduled. */
1669 efx->reset_pending = RESET_TYPE_NONE;
1670
1671 /* Reinitialise bus-mastering, which may have been turned off before
1672 * the reset was scheduled. This is still appropriate, even in the
1673 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
1674 * can respond to requests. */
1675 pci_set_master(efx->pci_dev);
1676
Ben Hutchings8ceee662008-04-27 12:55:59 +01001677 /* Leave device stopped if necessary */
1678 if (method == RESET_TYPE_DISABLE) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001679 rc = -EIO;
Ben Hutchings2467ca42008-09-01 12:48:50 +01001680 goto fail;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001681 }
1682
Ben Hutchings2467ca42008-09-01 12:48:50 +01001683 rc = efx_reset_up(efx, &ecmd, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001684 if (rc)
Ben Hutchings2467ca42008-09-01 12:48:50 +01001685 goto disable;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001686
Ben Hutchings8ceee662008-04-27 12:55:59 +01001687 EFX_LOG(efx, "reset complete\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01001688 unlock_rtnl:
1689 rtnl_unlock();
1690 return 0;
1691
Ben Hutchings2467ca42008-09-01 12:48:50 +01001692 fail:
1693 efx_reset_up(efx, &ecmd, false);
1694 disable:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001695 EFX_ERR(efx, "has been disabled\n");
1696 efx->state = STATE_DISABLED;
1697
Ben Hutchings8ceee662008-04-27 12:55:59 +01001698 rtnl_unlock();
1699 efx_unregister_netdev(efx);
1700 efx_fini_port(efx);
1701 return rc;
1702}
1703
1704/* The worker thread exists so that code that cannot sleep can
1705 * schedule a reset for later.
1706 */
1707static void efx_reset_work(struct work_struct *data)
1708{
1709 struct efx_nic *nic = container_of(data, struct efx_nic, reset_work);
1710
1711 efx_reset(nic);
1712}
1713
1714void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
1715{
1716 enum reset_type method;
1717
1718 if (efx->reset_pending != RESET_TYPE_NONE) {
1719 EFX_INFO(efx, "quenching already scheduled reset\n");
1720 return;
1721 }
1722
1723 switch (type) {
1724 case RESET_TYPE_INVISIBLE:
1725 case RESET_TYPE_ALL:
1726 case RESET_TYPE_WORLD:
1727 case RESET_TYPE_DISABLE:
1728 method = type;
1729 break;
1730 case RESET_TYPE_RX_RECOVERY:
1731 case RESET_TYPE_RX_DESC_FETCH:
1732 case RESET_TYPE_TX_DESC_FETCH:
1733 case RESET_TYPE_TX_SKIP:
1734 method = RESET_TYPE_INVISIBLE;
1735 break;
1736 default:
1737 method = RESET_TYPE_ALL;
1738 break;
1739 }
1740
1741 if (method != type)
1742 EFX_LOG(efx, "scheduling reset (%d:%d)\n", type, method);
1743 else
1744 EFX_LOG(efx, "scheduling reset (%d)\n", method);
1745
1746 efx->reset_pending = method;
1747
Steve Hodgson1ab00622008-12-12 21:33:02 -08001748 queue_work(reset_workqueue, &efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001749}
1750
1751/**************************************************************************
1752 *
1753 * List of NICs we support
1754 *
1755 **************************************************************************/
1756
1757/* PCI device ID table */
1758static struct pci_device_id efx_pci_table[] __devinitdata = {
1759 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
1760 .driver_data = (unsigned long) &falcon_a_nic_type},
1761 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
1762 .driver_data = (unsigned long) &falcon_b_nic_type},
1763 {0} /* end of list */
1764};
1765
1766/**************************************************************************
1767 *
1768 * Dummy PHY/MAC/Board operations
1769 *
Ben Hutchings01aad7b2008-09-01 12:48:36 +01001770 * Can be used for some unimplemented operations
Ben Hutchings8ceee662008-04-27 12:55:59 +01001771 * Needed so all function pointers are valid and do not have to be tested
1772 * before use
1773 *
1774 **************************************************************************/
1775int efx_port_dummy_op_int(struct efx_nic *efx)
1776{
1777 return 0;
1778}
1779void efx_port_dummy_op_void(struct efx_nic *efx) {}
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001780void efx_port_dummy_op_blink(struct efx_nic *efx, bool blink) {}
Ben Hutchings8ceee662008-04-27 12:55:59 +01001781
1782static struct efx_phy_operations efx_dummy_phy_operations = {
1783 .init = efx_port_dummy_op_int,
1784 .reconfigure = efx_port_dummy_op_void,
1785 .check_hw = efx_port_dummy_op_int,
1786 .fini = efx_port_dummy_op_void,
1787 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001788};
1789
Ben Hutchings8ceee662008-04-27 12:55:59 +01001790static struct efx_board efx_dummy_board_info = {
Ben Hutchings01aad7b2008-09-01 12:48:36 +01001791 .init = efx_port_dummy_op_int,
1792 .init_leds = efx_port_dummy_op_int,
1793 .set_fault_led = efx_port_dummy_op_blink,
Ben Hutchingsa17102b2008-12-12 21:28:20 -08001794 .monitor = efx_port_dummy_op_int,
Ben Hutchings01aad7b2008-09-01 12:48:36 +01001795 .blink = efx_port_dummy_op_blink,
1796 .fini = efx_port_dummy_op_void,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001797};
1798
1799/**************************************************************************
1800 *
1801 * Data housekeeping
1802 *
1803 **************************************************************************/
1804
1805/* This zeroes out and then fills in the invariants in a struct
1806 * efx_nic (including all sub-structures).
1807 */
1808static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
1809 struct pci_dev *pci_dev, struct net_device *net_dev)
1810{
1811 struct efx_channel *channel;
1812 struct efx_tx_queue *tx_queue;
1813 struct efx_rx_queue *rx_queue;
Steve Hodgson1ab00622008-12-12 21:33:02 -08001814 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001815
1816 /* Initialise common structures */
1817 memset(efx, 0, sizeof(*efx));
1818 spin_lock_init(&efx->biu_lock);
1819 spin_lock_init(&efx->phy_lock);
Ben Hutchingsf4150722008-11-04 20:34:28 +00001820 mutex_init(&efx->spi_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001821 INIT_WORK(&efx->reset_work, efx_reset_work);
1822 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
1823 efx->pci_dev = pci_dev;
1824 efx->state = STATE_INIT;
1825 efx->reset_pending = RESET_TYPE_NONE;
1826 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
1827 efx->board_info = efx_dummy_board_info;
1828
1829 efx->net_dev = net_dev;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001830 efx->rx_checksum_enabled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001831 spin_lock_init(&efx->netif_stop_lock);
1832 spin_lock_init(&efx->stats_lock);
1833 mutex_init(&efx->mac_lock);
1834 efx->phy_op = &efx_dummy_phy_operations;
1835 efx->mii.dev = net_dev;
1836 INIT_WORK(&efx->reconfigure_work, efx_reconfigure_work);
1837 atomic_set(&efx->netif_stop_count, 1);
1838
1839 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
1840 channel = &efx->channel[i];
1841 channel->efx = efx;
1842 channel->channel = i;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001843 channel->work_pending = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001844 }
Ben Hutchings60ac1062008-09-01 12:44:59 +01001845 for (i = 0; i < EFX_TX_QUEUE_COUNT; i++) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001846 tx_queue = &efx->tx_queue[i];
1847 tx_queue->efx = efx;
1848 tx_queue->queue = i;
1849 tx_queue->buffer = NULL;
1850 tx_queue->channel = &efx->channel[0]; /* for safety */
Ben Hutchingsb9b39b62008-05-07 12:51:12 +01001851 tx_queue->tso_headers_free = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001852 }
1853 for (i = 0; i < EFX_MAX_RX_QUEUES; i++) {
1854 rx_queue = &efx->rx_queue[i];
1855 rx_queue->efx = efx;
1856 rx_queue->queue = i;
1857 rx_queue->channel = &efx->channel[0]; /* for safety */
1858 rx_queue->buffer = NULL;
1859 spin_lock_init(&rx_queue->add_lock);
1860 INIT_DELAYED_WORK(&rx_queue->work, efx_rx_work);
1861 }
1862
1863 efx->type = type;
1864
1865 /* Sanity-check NIC type */
1866 EFX_BUG_ON_PARANOID(efx->type->txd_ring_mask &
1867 (efx->type->txd_ring_mask + 1));
1868 EFX_BUG_ON_PARANOID(efx->type->rxd_ring_mask &
1869 (efx->type->rxd_ring_mask + 1));
1870 EFX_BUG_ON_PARANOID(efx->type->evq_size &
1871 (efx->type->evq_size - 1));
1872 /* As close as we can get to guaranteeing that we don't overflow */
1873 EFX_BUG_ON_PARANOID(efx->type->evq_size <
1874 (efx->type->txd_ring_mask + 1 +
1875 efx->type->rxd_ring_mask + 1));
1876 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
1877
1878 /* Higher numbered interrupt modes are less capable! */
1879 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
1880 interrupt_mode);
1881
1882 efx->workqueue = create_singlethread_workqueue("sfc_work");
Steve Hodgson1ab00622008-12-12 21:33:02 -08001883 if (!efx->workqueue)
1884 return -ENOMEM;
Ben Hutchings8d9853d2008-07-18 19:01:20 +01001885
Ben Hutchings8ceee662008-04-27 12:55:59 +01001886 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001887}
1888
1889static void efx_fini_struct(struct efx_nic *efx)
1890{
1891 if (efx->workqueue) {
1892 destroy_workqueue(efx->workqueue);
1893 efx->workqueue = NULL;
1894 }
1895}
1896
1897/**************************************************************************
1898 *
1899 * PCI interface
1900 *
1901 **************************************************************************/
1902
1903/* Main body of final NIC shutdown code
1904 * This is called only at module unload (or hotplug removal).
1905 */
1906static void efx_pci_remove_main(struct efx_nic *efx)
1907{
1908 EFX_ASSERT_RESET_SERIALISED(efx);
1909
1910 /* Skip everything if we never obtained a valid membase */
1911 if (!efx->membase)
1912 return;
1913
1914 efx_fini_channels(efx);
1915 efx_fini_port(efx);
1916
1917 /* Shutdown the board, then the NIC and board state */
Ben Hutchings37b5a602008-05-30 22:27:04 +01001918 efx->board_info.fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001919 falcon_fini_interrupt(efx);
1920
1921 efx_fini_napi(efx);
1922 efx_remove_all(efx);
1923}
1924
1925/* Final NIC shutdown
1926 * This is called only at module unload (or hotplug removal).
1927 */
1928static void efx_pci_remove(struct pci_dev *pci_dev)
1929{
1930 struct efx_nic *efx;
1931
1932 efx = pci_get_drvdata(pci_dev);
1933 if (!efx)
1934 return;
1935
Ben Hutchingsf4150722008-11-04 20:34:28 +00001936 efx_mtd_remove(efx);
1937
Ben Hutchings8ceee662008-04-27 12:55:59 +01001938 /* Mark the NIC as fini, then stop the interface */
1939 rtnl_lock();
1940 efx->state = STATE_FINI;
1941 dev_close(efx->net_dev);
1942
1943 /* Allow any queued efx_resets() to complete */
1944 rtnl_unlock();
1945
1946 if (efx->membase == NULL)
1947 goto out;
1948
1949 efx_unregister_netdev(efx);
1950
1951 /* Wait for any scheduled resets to complete. No more will be
1952 * scheduled from this point because efx_stop_all() has been
1953 * called, we are no longer registered with driverlink, and
1954 * the net_device's have been removed. */
Steve Hodgson1ab00622008-12-12 21:33:02 -08001955 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001956
1957 efx_pci_remove_main(efx);
1958
1959out:
1960 efx_fini_io(efx);
1961 EFX_LOG(efx, "shutdown successful\n");
1962
1963 pci_set_drvdata(pci_dev, NULL);
1964 efx_fini_struct(efx);
1965 free_netdev(efx->net_dev);
1966};
1967
1968/* Main body of NIC initialisation
1969 * This is called at module load (or hotplug insertion, theoretically).
1970 */
1971static int efx_pci_probe_main(struct efx_nic *efx)
1972{
1973 int rc;
1974
1975 /* Do start-of-day initialisation */
1976 rc = efx_probe_all(efx);
1977 if (rc)
1978 goto fail1;
1979
1980 rc = efx_init_napi(efx);
1981 if (rc)
1982 goto fail2;
1983
1984 /* Initialise the board */
1985 rc = efx->board_info.init(efx);
1986 if (rc) {
1987 EFX_ERR(efx, "failed to initialise board\n");
1988 goto fail3;
1989 }
1990
1991 rc = falcon_init_nic(efx);
1992 if (rc) {
1993 EFX_ERR(efx, "failed to initialise NIC\n");
1994 goto fail4;
1995 }
1996
1997 rc = efx_init_port(efx);
1998 if (rc) {
1999 EFX_ERR(efx, "failed to initialise port\n");
2000 goto fail5;
2001 }
2002
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01002003 efx_init_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002004
2005 rc = falcon_init_interrupt(efx);
2006 if (rc)
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01002007 goto fail6;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002008
2009 return 0;
2010
Ben Hutchings8ceee662008-04-27 12:55:59 +01002011 fail6:
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01002012 efx_fini_channels(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002013 efx_fini_port(efx);
2014 fail5:
2015 fail4:
Ben Hutchingsa17102b2008-12-12 21:28:20 -08002016 efx->board_info.fini(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002017 fail3:
2018 efx_fini_napi(efx);
2019 fail2:
2020 efx_remove_all(efx);
2021 fail1:
2022 return rc;
2023}
2024
2025/* NIC initialisation
2026 *
2027 * This is called at module load (or hotplug insertion,
2028 * theoretically). It sets up PCI mappings, tests and resets the NIC,
2029 * sets up and registers the network devices with the kernel and hooks
2030 * the interrupt service routine. It does not prepare the device for
2031 * transmission; this is left to the first time one of the network
2032 * interfaces is brought up (i.e. efx_net_open).
2033 */
2034static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2035 const struct pci_device_id *entry)
2036{
2037 struct efx_nic_type *type = (struct efx_nic_type *) entry->driver_data;
2038 struct net_device *net_dev;
2039 struct efx_nic *efx;
2040 int i, rc;
2041
2042 /* Allocate and initialise a struct net_device and struct efx_nic */
2043 net_dev = alloc_etherdev(sizeof(*efx));
2044 if (!net_dev)
2045 return -ENOMEM;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +01002046 net_dev->features |= (NETIF_F_IP_CSUM | NETIF_F_SG |
2047 NETIF_F_HIGHDMA | NETIF_F_TSO);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002048 if (lro)
2049 net_dev->features |= NETIF_F_LRO;
Ben Hutchings285065632008-09-01 12:46:54 +01002050 /* Mask for features that also apply to VLAN devices */
2051 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
Ben Hutchings740847d2008-09-01 12:48:23 +01002052 NETIF_F_HIGHDMA | NETIF_F_TSO);
Ben Hutchings767e4682008-09-01 12:43:14 +01002053 efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002054 pci_set_drvdata(pci_dev, efx);
2055 rc = efx_init_struct(efx, type, pci_dev, net_dev);
2056 if (rc)
2057 goto fail1;
2058
2059 EFX_INFO(efx, "Solarflare Communications NIC detected\n");
2060
2061 /* Set up basic I/O (BAR mappings etc) */
2062 rc = efx_init_io(efx);
2063 if (rc)
2064 goto fail2;
2065
2066 /* No serialisation is required with the reset path because
2067 * we're in STATE_INIT. */
2068 for (i = 0; i < 5; i++) {
2069 rc = efx_pci_probe_main(efx);
2070 if (rc == 0)
2071 break;
2072
2073 /* Serialise against efx_reset(). No more resets will be
2074 * scheduled since efx_stop_all() has been called, and we
2075 * have not and never have been registered with either
2076 * the rtnetlink or driverlink layers. */
Steve Hodgson1ab00622008-12-12 21:33:02 -08002077 cancel_work_sync(&efx->reset_work);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002078
2079 /* Retry if a recoverably reset event has been scheduled */
2080 if ((efx->reset_pending != RESET_TYPE_INVISIBLE) &&
2081 (efx->reset_pending != RESET_TYPE_ALL))
2082 goto fail3;
2083
2084 efx->reset_pending = RESET_TYPE_NONE;
2085 }
2086
2087 if (rc) {
2088 EFX_ERR(efx, "Could not reset NIC\n");
2089 goto fail4;
2090 }
2091
2092 /* Switch to the running state before we expose the device to
2093 * the OS. This is to ensure that the initial gathering of
2094 * MAC stats succeeds. */
2095 rtnl_lock();
2096 efx->state = STATE_RUNNING;
2097 rtnl_unlock();
2098
2099 rc = efx_register_netdev(efx);
2100 if (rc)
2101 goto fail5;
2102
2103 EFX_LOG(efx, "initialisation successful\n");
2104
Ben Hutchingsf4150722008-11-04 20:34:28 +00002105 efx_mtd_probe(efx); /* allowed to fail */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002106 return 0;
2107
2108 fail5:
2109 efx_pci_remove_main(efx);
2110 fail4:
2111 fail3:
2112 efx_fini_io(efx);
2113 fail2:
2114 efx_fini_struct(efx);
2115 fail1:
2116 EFX_LOG(efx, "initialisation failed. rc=%d\n", rc);
2117 free_netdev(net_dev);
2118 return rc;
2119}
2120
2121static struct pci_driver efx_pci_driver = {
2122 .name = EFX_DRIVER_NAME,
2123 .id_table = efx_pci_table,
2124 .probe = efx_pci_probe,
2125 .remove = efx_pci_remove,
2126};
2127
2128/**************************************************************************
2129 *
2130 * Kernel module interface
2131 *
2132 *************************************************************************/
2133
2134module_param(interrupt_mode, uint, 0444);
2135MODULE_PARM_DESC(interrupt_mode,
2136 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
2137
2138static int __init efx_init_module(void)
2139{
2140 int rc;
2141
2142 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
2143
2144 rc = register_netdevice_notifier(&efx_netdev_notifier);
2145 if (rc)
2146 goto err_notifier;
2147
2148 refill_workqueue = create_workqueue("sfc_refill");
2149 if (!refill_workqueue) {
2150 rc = -ENOMEM;
2151 goto err_refill;
2152 }
Steve Hodgson1ab00622008-12-12 21:33:02 -08002153 reset_workqueue = create_singlethread_workqueue("sfc_reset");
2154 if (!reset_workqueue) {
2155 rc = -ENOMEM;
2156 goto err_reset;
2157 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002158
2159 rc = pci_register_driver(&efx_pci_driver);
2160 if (rc < 0)
2161 goto err_pci;
2162
2163 return 0;
2164
2165 err_pci:
Steve Hodgson1ab00622008-12-12 21:33:02 -08002166 destroy_workqueue(reset_workqueue);
2167 err_reset:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002168 destroy_workqueue(refill_workqueue);
2169 err_refill:
2170 unregister_netdevice_notifier(&efx_netdev_notifier);
2171 err_notifier:
2172 return rc;
2173}
2174
2175static void __exit efx_exit_module(void)
2176{
2177 printk(KERN_INFO "Solarflare NET driver unloading\n");
2178
2179 pci_unregister_driver(&efx_pci_driver);
Steve Hodgson1ab00622008-12-12 21:33:02 -08002180 destroy_workqueue(reset_workqueue);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002181 destroy_workqueue(refill_workqueue);
2182 unregister_netdevice_notifier(&efx_netdev_notifier);
2183
2184}
2185
2186module_init(efx_init_module);
2187module_exit(efx_exit_module);
2188
2189MODULE_AUTHOR("Michael Brown <mbrown@fensystems.co.uk> and "
2190 "Solarflare Communications");
2191MODULE_DESCRIPTION("Solarflare Communications network driver");
2192MODULE_LICENSE("GPL");
2193MODULE_DEVICE_TABLE(pci, efx_pci_table);