Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 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 Hutchings | aa6ef27 | 2008-07-18 19:03:10 +0100 | [diff] [blame] | 22 | #include <linux/topology.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 23 | #include "net_driver.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 24 | #include "ethtool.h" |
| 25 | #include "tx.h" |
| 26 | #include "rx.h" |
| 27 | #include "efx.h" |
| 28 | #include "mdio_10g.h" |
| 29 | #include "falcon.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | |
| 31 | #define EFX_MAX_MTU (9 * 1024) |
| 32 | |
| 33 | /* RX slow fill workqueue. If memory allocation fails in the fast path, |
| 34 | * a work item is pushed onto this work queue to retry the allocation later, |
| 35 | * to avoid the NIC being starved of RX buffers. Since this is a per cpu |
| 36 | * workqueue, there is nothing to be gained in making it per NIC |
| 37 | */ |
| 38 | static struct workqueue_struct *refill_workqueue; |
| 39 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 40 | /* Reset workqueue. If any NIC has a hardware failure then a reset will be |
| 41 | * queued onto this work queue. This is not a per-nic work queue, because |
| 42 | * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised. |
| 43 | */ |
| 44 | static struct workqueue_struct *reset_workqueue; |
| 45 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 46 | /************************************************************************** |
| 47 | * |
| 48 | * Configurable values |
| 49 | * |
| 50 | *************************************************************************/ |
| 51 | |
| 52 | /* |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 53 | * Use separate channels for TX and RX events |
| 54 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 55 | * Set this to 1 to use separate channels for TX and RX. It allows us |
| 56 | * to control interrupt affinity separately for TX and RX. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 57 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 58 | * This is only used in MSI-X interrupt mode |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 59 | */ |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 60 | static unsigned int separate_tx_channels; |
| 61 | module_param(separate_tx_channels, uint, 0644); |
| 62 | MODULE_PARM_DESC(separate_tx_channels, |
| 63 | "Use separate channels for TX and RX"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 64 | |
| 65 | /* This is the weight assigned to each of the (per-channel) virtual |
| 66 | * NAPI devices. |
| 67 | */ |
| 68 | static int napi_weight = 64; |
| 69 | |
| 70 | /* This is the time (in jiffies) between invocations of the hardware |
| 71 | * monitor, which checks for known hardware bugs and resets the |
| 72 | * hardware and driver as necessary. |
| 73 | */ |
| 74 | unsigned int efx_monitor_interval = 1 * HZ; |
| 75 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 76 | /* This controls whether or not the driver will initialise devices |
| 77 | * with invalid MAC addresses stored in the EEPROM or flash. If true, |
| 78 | * such devices will be initialised with a random locally-generated |
| 79 | * MAC address. This allows for loading the sfc_mtd driver to |
| 80 | * reprogram the flash, even if the flash contents (including the MAC |
| 81 | * address) have previously been erased. |
| 82 | */ |
| 83 | static unsigned int allow_bad_hwaddr; |
| 84 | |
| 85 | /* Initial interrupt moderation settings. They can be modified after |
| 86 | * module load with ethtool. |
| 87 | * |
| 88 | * The default for RX should strike a balance between increasing the |
| 89 | * round-trip latency and reducing overhead. |
| 90 | */ |
| 91 | static unsigned int rx_irq_mod_usec = 60; |
| 92 | |
| 93 | /* Initial interrupt moderation settings. They can be modified after |
| 94 | * module load with ethtool. |
| 95 | * |
| 96 | * This default is chosen to ensure that a 10G link does not go idle |
| 97 | * while a TX queue is stopped after it has become full. A queue is |
| 98 | * restarted when it drops below half full. The time this takes (assuming |
| 99 | * worst case 3 descriptors per packet and 1024 descriptors) is |
| 100 | * 512 / 3 * 1.2 = 205 usec. |
| 101 | */ |
| 102 | static unsigned int tx_irq_mod_usec = 150; |
| 103 | |
| 104 | /* This is the first interrupt mode to try out of: |
| 105 | * 0 => MSI-X |
| 106 | * 1 => MSI |
| 107 | * 2 => legacy |
| 108 | */ |
| 109 | static unsigned int interrupt_mode; |
| 110 | |
| 111 | /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), |
| 112 | * i.e. the number of CPUs among which we may distribute simultaneous |
| 113 | * interrupt handling. |
| 114 | * |
| 115 | * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. |
| 116 | * The default (0) means to assign an interrupt to each package (level II cache) |
| 117 | */ |
| 118 | static unsigned int rss_cpus; |
| 119 | module_param(rss_cpus, uint, 0444); |
| 120 | MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); |
| 121 | |
Ben Hutchings | 84ae48f | 2008-12-12 21:34:54 -0800 | [diff] [blame] | 122 | static int phy_flash_cfg; |
| 123 | module_param(phy_flash_cfg, int, 0644); |
| 124 | MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); |
| 125 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 126 | static unsigned irq_adapt_low_thresh = 10000; |
| 127 | module_param(irq_adapt_low_thresh, uint, 0644); |
| 128 | MODULE_PARM_DESC(irq_adapt_low_thresh, |
| 129 | "Threshold score for reducing IRQ moderation"); |
| 130 | |
| 131 | static unsigned irq_adapt_high_thresh = 20000; |
| 132 | module_param(irq_adapt_high_thresh, uint, 0644); |
| 133 | MODULE_PARM_DESC(irq_adapt_high_thresh, |
| 134 | "Threshold score for increasing IRQ moderation"); |
| 135 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 136 | /************************************************************************** |
| 137 | * |
| 138 | * Utility functions and prototypes |
| 139 | * |
| 140 | *************************************************************************/ |
| 141 | static void efx_remove_channel(struct efx_channel *channel); |
| 142 | static void efx_remove_port(struct efx_nic *efx); |
| 143 | static void efx_fini_napi(struct efx_nic *efx); |
| 144 | static void efx_fini_channels(struct efx_nic *efx); |
| 145 | |
| 146 | #define EFX_ASSERT_RESET_SERIALISED(efx) \ |
| 147 | do { \ |
Ben Hutchings | 3c78708 | 2008-09-01 12:49:08 +0100 | [diff] [blame] | 148 | if (efx->state == STATE_RUNNING) \ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 149 | ASSERT_RTNL(); \ |
| 150 | } while (0) |
| 151 | |
| 152 | /************************************************************************** |
| 153 | * |
| 154 | * Event queue processing |
| 155 | * |
| 156 | *************************************************************************/ |
| 157 | |
| 158 | /* Process channel's event queue |
| 159 | * |
| 160 | * This function is responsible for processing the event queue of a |
| 161 | * single channel. The caller must guarantee that this function will |
| 162 | * never be concurrently called more than once on the same channel, |
| 163 | * though different channels may be being processed concurrently. |
| 164 | */ |
Ben Hutchings | 4d56606 | 2008-09-01 12:47:12 +0100 | [diff] [blame] | 165 | static int efx_process_channel(struct efx_channel *channel, int rx_quota) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 166 | { |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 167 | struct efx_nic *efx = channel->efx; |
| 168 | int rx_packets; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 169 | |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 170 | if (unlikely(efx->reset_pending != RESET_TYPE_NONE || |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 171 | !channel->enabled)) |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 172 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 173 | |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 174 | rx_packets = falcon_process_eventq(channel, rx_quota); |
| 175 | if (rx_packets == 0) |
| 176 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 177 | |
| 178 | /* Deliver last RX packet. */ |
| 179 | if (channel->rx_pkt) { |
| 180 | __efx_rx_packet(channel, channel->rx_pkt, |
| 181 | channel->rx_pkt_csummed); |
| 182 | channel->rx_pkt = NULL; |
| 183 | } |
| 184 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 185 | efx_rx_strategy(channel); |
| 186 | |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 187 | efx_fast_push_rx_descriptors(&efx->rx_queue[channel->channel]); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 188 | |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 189 | return rx_packets; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* Mark channel as finished processing |
| 193 | * |
| 194 | * Note that since we will not receive further interrupts for this |
| 195 | * channel before we finish processing and call the eventq_read_ack() |
| 196 | * method, there is no need to use the interrupt hold-off timers. |
| 197 | */ |
| 198 | static inline void efx_channel_processed(struct efx_channel *channel) |
| 199 | { |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 200 | /* The interrupt handler for this channel may set work_pending |
| 201 | * as soon as we acknowledge the events we've seen. Make sure |
| 202 | * it's cleared before then. */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 203 | channel->work_pending = false; |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 204 | smp_wmb(); |
| 205 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 206 | falcon_eventq_read_ack(channel); |
| 207 | } |
| 208 | |
| 209 | /* NAPI poll handler |
| 210 | * |
| 211 | * NAPI guarantees serialisation of polls of the same device, which |
| 212 | * provides the guarantee required by efx_process_channel(). |
| 213 | */ |
| 214 | static int efx_poll(struct napi_struct *napi, int budget) |
| 215 | { |
| 216 | struct efx_channel *channel = |
| 217 | container_of(napi, struct efx_channel, napi_str); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 218 | int rx_packets; |
| 219 | |
| 220 | EFX_TRACE(channel->efx, "channel %d NAPI poll executing on CPU %d\n", |
| 221 | channel->channel, raw_smp_processor_id()); |
| 222 | |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 223 | rx_packets = efx_process_channel(channel, budget); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 224 | |
| 225 | if (rx_packets < budget) { |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 226 | struct efx_nic *efx = channel->efx; |
| 227 | |
| 228 | if (channel->used_flags & EFX_USED_BY_RX && |
| 229 | efx->irq_rx_adaptive && |
| 230 | unlikely(++channel->irq_count == 1000)) { |
| 231 | unsigned old_irq_moderation = channel->irq_moderation; |
| 232 | |
| 233 | if (unlikely(channel->irq_mod_score < |
| 234 | irq_adapt_low_thresh)) { |
| 235 | channel->irq_moderation = |
| 236 | max_t(int, |
| 237 | channel->irq_moderation - |
| 238 | FALCON_IRQ_MOD_RESOLUTION, |
| 239 | FALCON_IRQ_MOD_RESOLUTION); |
| 240 | } else if (unlikely(channel->irq_mod_score > |
| 241 | irq_adapt_high_thresh)) { |
| 242 | channel->irq_moderation = |
| 243 | min(channel->irq_moderation + |
| 244 | FALCON_IRQ_MOD_RESOLUTION, |
| 245 | efx->irq_rx_moderation); |
| 246 | } |
| 247 | |
| 248 | if (channel->irq_moderation != old_irq_moderation) |
| 249 | falcon_set_int_moderation(channel); |
| 250 | |
| 251 | channel->irq_count = 0; |
| 252 | channel->irq_mod_score = 0; |
| 253 | } |
| 254 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 255 | /* There is no race here; although napi_disable() will |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 256 | * only wait for napi_complete(), this isn't a problem |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 257 | * since efx_channel_processed() will have no effect if |
| 258 | * interrupts have already been disabled. |
| 259 | */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 260 | napi_complete(napi); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 261 | efx_channel_processed(channel); |
| 262 | } |
| 263 | |
| 264 | return rx_packets; |
| 265 | } |
| 266 | |
| 267 | /* Process the eventq of the specified channel immediately on this CPU |
| 268 | * |
| 269 | * Disable hardware generated interrupts, wait for any existing |
| 270 | * processing to finish, then directly poll (and ack ) the eventq. |
| 271 | * Finally reenable NAPI and interrupts. |
| 272 | * |
| 273 | * Since we are touching interrupts the caller should hold the suspend lock |
| 274 | */ |
| 275 | void efx_process_channel_now(struct efx_channel *channel) |
| 276 | { |
| 277 | struct efx_nic *efx = channel->efx; |
| 278 | |
| 279 | BUG_ON(!channel->used_flags); |
| 280 | BUG_ON(!channel->enabled); |
| 281 | |
| 282 | /* Disable interrupts and wait for ISRs to complete */ |
| 283 | falcon_disable_interrupts(efx); |
| 284 | if (efx->legacy_irq) |
| 285 | synchronize_irq(efx->legacy_irq); |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 286 | if (channel->irq) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 287 | synchronize_irq(channel->irq); |
| 288 | |
| 289 | /* Wait for any NAPI processing to complete */ |
| 290 | napi_disable(&channel->napi_str); |
| 291 | |
| 292 | /* Poll the channel */ |
Ben Hutchings | 91ad757 | 2008-05-16 21:14:27 +0100 | [diff] [blame] | 293 | efx_process_channel(channel, efx->type->evq_size); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 294 | |
| 295 | /* Ack the eventq. This may cause an interrupt to be generated |
| 296 | * when they are reenabled */ |
| 297 | efx_channel_processed(channel); |
| 298 | |
| 299 | napi_enable(&channel->napi_str); |
| 300 | falcon_enable_interrupts(efx); |
| 301 | } |
| 302 | |
| 303 | /* Create event queue |
| 304 | * Event queue memory allocations are done only once. If the channel |
| 305 | * is reset, the memory buffer will be reused; this guards against |
| 306 | * errors during channel reset and also simplifies interrupt handling. |
| 307 | */ |
| 308 | static int efx_probe_eventq(struct efx_channel *channel) |
| 309 | { |
| 310 | EFX_LOG(channel->efx, "chan %d create event queue\n", channel->channel); |
| 311 | |
| 312 | return falcon_probe_eventq(channel); |
| 313 | } |
| 314 | |
| 315 | /* Prepare channel's event queue */ |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 316 | static void efx_init_eventq(struct efx_channel *channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 317 | { |
| 318 | EFX_LOG(channel->efx, "chan %d init event queue\n", channel->channel); |
| 319 | |
| 320 | channel->eventq_read_ptr = 0; |
| 321 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 322 | falcon_init_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static void efx_fini_eventq(struct efx_channel *channel) |
| 326 | { |
| 327 | EFX_LOG(channel->efx, "chan %d fini event queue\n", channel->channel); |
| 328 | |
| 329 | falcon_fini_eventq(channel); |
| 330 | } |
| 331 | |
| 332 | static void efx_remove_eventq(struct efx_channel *channel) |
| 333 | { |
| 334 | EFX_LOG(channel->efx, "chan %d remove event queue\n", channel->channel); |
| 335 | |
| 336 | falcon_remove_eventq(channel); |
| 337 | } |
| 338 | |
| 339 | /************************************************************************** |
| 340 | * |
| 341 | * Channel handling |
| 342 | * |
| 343 | *************************************************************************/ |
| 344 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 345 | static int efx_probe_channel(struct efx_channel *channel) |
| 346 | { |
| 347 | struct efx_tx_queue *tx_queue; |
| 348 | struct efx_rx_queue *rx_queue; |
| 349 | int rc; |
| 350 | |
| 351 | EFX_LOG(channel->efx, "creating channel %d\n", channel->channel); |
| 352 | |
| 353 | rc = efx_probe_eventq(channel); |
| 354 | if (rc) |
| 355 | goto fail1; |
| 356 | |
| 357 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 358 | rc = efx_probe_tx_queue(tx_queue); |
| 359 | if (rc) |
| 360 | goto fail2; |
| 361 | } |
| 362 | |
| 363 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 364 | rc = efx_probe_rx_queue(rx_queue); |
| 365 | if (rc) |
| 366 | goto fail3; |
| 367 | } |
| 368 | |
| 369 | channel->n_rx_frm_trunc = 0; |
| 370 | |
| 371 | return 0; |
| 372 | |
| 373 | fail3: |
| 374 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 375 | efx_remove_rx_queue(rx_queue); |
| 376 | fail2: |
| 377 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 378 | efx_remove_tx_queue(tx_queue); |
| 379 | fail1: |
| 380 | return rc; |
| 381 | } |
| 382 | |
| 383 | |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 384 | static void efx_set_channel_names(struct efx_nic *efx) |
| 385 | { |
| 386 | struct efx_channel *channel; |
| 387 | const char *type = ""; |
| 388 | int number; |
| 389 | |
| 390 | efx_for_each_channel(channel, efx) { |
| 391 | number = channel->channel; |
| 392 | if (efx->n_channels > efx->n_rx_queues) { |
| 393 | if (channel->channel < efx->n_rx_queues) { |
| 394 | type = "-rx"; |
| 395 | } else { |
| 396 | type = "-tx"; |
| 397 | number -= efx->n_rx_queues; |
| 398 | } |
| 399 | } |
| 400 | snprintf(channel->name, sizeof(channel->name), |
| 401 | "%s%s-%d", efx->name, type, number); |
| 402 | } |
| 403 | } |
| 404 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 405 | /* Channels are shutdown and reinitialised whilst the NIC is running |
| 406 | * to propagate configuration changes (mtu, checksum offload), or |
| 407 | * to clear hardware error conditions |
| 408 | */ |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 409 | static void efx_init_channels(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 410 | { |
| 411 | struct efx_tx_queue *tx_queue; |
| 412 | struct efx_rx_queue *rx_queue; |
| 413 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 414 | |
Ben Hutchings | f7f13b0 | 2008-05-16 21:15:06 +0100 | [diff] [blame] | 415 | /* Calculate the rx buffer allocation parameters required to |
| 416 | * support the current MTU, including padding for header |
| 417 | * alignment and overruns. |
| 418 | */ |
| 419 | efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) + |
| 420 | EFX_MAX_FRAME_LEN(efx->net_dev->mtu) + |
| 421 | efx->type->rx_buffer_padding); |
| 422 | efx->rx_buffer_order = get_order(efx->rx_buffer_len); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 423 | |
| 424 | /* Initialise the channels */ |
| 425 | efx_for_each_channel(channel, efx) { |
| 426 | EFX_LOG(channel->efx, "init chan %d\n", channel->channel); |
| 427 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 428 | efx_init_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 429 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 430 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 431 | efx_init_tx_queue(tx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 432 | |
| 433 | /* The rx buffer allocation strategy is MTU dependent */ |
| 434 | efx_rx_strategy(channel); |
| 435 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 436 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 437 | efx_init_rx_queue(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 438 | |
| 439 | WARN_ON(channel->rx_pkt != NULL); |
| 440 | efx_rx_strategy(channel); |
| 441 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /* This enables event queue processing and packet transmission. |
| 445 | * |
| 446 | * Note that this function is not allowed to fail, since that would |
| 447 | * introduce too much complexity into the suspend/resume path. |
| 448 | */ |
| 449 | static void efx_start_channel(struct efx_channel *channel) |
| 450 | { |
| 451 | struct efx_rx_queue *rx_queue; |
| 452 | |
| 453 | EFX_LOG(channel->efx, "starting chan %d\n", channel->channel); |
| 454 | |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 455 | /* The interrupt handler for this channel may set work_pending |
| 456 | * as soon as we enable it. Make sure it's cleared before |
| 457 | * then. Similarly, make sure it sees the enabled flag set. */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 458 | channel->work_pending = false; |
| 459 | channel->enabled = true; |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 460 | smp_wmb(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 461 | |
| 462 | napi_enable(&channel->napi_str); |
| 463 | |
| 464 | /* Load up RX descriptors */ |
| 465 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 466 | efx_fast_push_rx_descriptors(rx_queue); |
| 467 | } |
| 468 | |
| 469 | /* This disables event queue processing and packet transmission. |
| 470 | * This function does not guarantee that all queue processing |
| 471 | * (e.g. RX refill) is complete. |
| 472 | */ |
| 473 | static void efx_stop_channel(struct efx_channel *channel) |
| 474 | { |
| 475 | struct efx_rx_queue *rx_queue; |
| 476 | |
| 477 | if (!channel->enabled) |
| 478 | return; |
| 479 | |
| 480 | EFX_LOG(channel->efx, "stop chan %d\n", channel->channel); |
| 481 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 482 | channel->enabled = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 483 | napi_disable(&channel->napi_str); |
| 484 | |
| 485 | /* Ensure that any worker threads have exited or will be no-ops */ |
| 486 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 487 | spin_lock_bh(&rx_queue->add_lock); |
| 488 | spin_unlock_bh(&rx_queue->add_lock); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | static void efx_fini_channels(struct efx_nic *efx) |
| 493 | { |
| 494 | struct efx_channel *channel; |
| 495 | struct efx_tx_queue *tx_queue; |
| 496 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 497 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 498 | |
| 499 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 500 | BUG_ON(efx->port_enabled); |
| 501 | |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 502 | rc = falcon_flush_queues(efx); |
| 503 | if (rc) |
| 504 | EFX_ERR(efx, "failed to flush queues\n"); |
| 505 | else |
| 506 | EFX_LOG(efx, "successfully flushed all queues\n"); |
| 507 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 508 | efx_for_each_channel(channel, efx) { |
| 509 | EFX_LOG(channel->efx, "shut down chan %d\n", channel->channel); |
| 510 | |
| 511 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 512 | efx_fini_rx_queue(rx_queue); |
| 513 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 514 | efx_fini_tx_queue(tx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 515 | efx_fini_eventq(channel); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | static void efx_remove_channel(struct efx_channel *channel) |
| 520 | { |
| 521 | struct efx_tx_queue *tx_queue; |
| 522 | struct efx_rx_queue *rx_queue; |
| 523 | |
| 524 | EFX_LOG(channel->efx, "destroy chan %d\n", channel->channel); |
| 525 | |
| 526 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 527 | efx_remove_rx_queue(rx_queue); |
| 528 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 529 | efx_remove_tx_queue(tx_queue); |
| 530 | efx_remove_eventq(channel); |
| 531 | |
| 532 | channel->used_flags = 0; |
| 533 | } |
| 534 | |
| 535 | void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay) |
| 536 | { |
| 537 | queue_delayed_work(refill_workqueue, &rx_queue->work, delay); |
| 538 | } |
| 539 | |
| 540 | /************************************************************************** |
| 541 | * |
| 542 | * Port handling |
| 543 | * |
| 544 | **************************************************************************/ |
| 545 | |
| 546 | /* This ensures that the kernel is kept informed (via |
| 547 | * netif_carrier_on/off) of the link status, and also maintains the |
| 548 | * link status's stop on the port's TX queue. |
| 549 | */ |
| 550 | static void efx_link_status_changed(struct efx_nic *efx) |
| 551 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 552 | /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure |
| 553 | * that no events are triggered between unregister_netdev() and the |
| 554 | * driver unloading. A more general condition is that NETDEV_CHANGE |
| 555 | * can only be generated between NETDEV_UP and NETDEV_DOWN */ |
| 556 | if (!netif_running(efx->net_dev)) |
| 557 | return; |
| 558 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 559 | if (efx->port_inhibited) { |
| 560 | netif_carrier_off(efx->net_dev); |
| 561 | return; |
| 562 | } |
| 563 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 564 | if (efx->link_up != netif_carrier_ok(efx->net_dev)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 565 | efx->n_link_state_changes++; |
| 566 | |
| 567 | if (efx->link_up) |
| 568 | netif_carrier_on(efx->net_dev); |
| 569 | else |
| 570 | netif_carrier_off(efx->net_dev); |
| 571 | } |
| 572 | |
| 573 | /* Status message for kernel log */ |
| 574 | if (efx->link_up) { |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 575 | EFX_INFO(efx, "link up at %uMbps %s-duplex (MTU %d)%s\n", |
| 576 | efx->link_speed, efx->link_fd ? "full" : "half", |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 577 | efx->net_dev->mtu, |
| 578 | (efx->promiscuous ? " [PROMISC]" : "")); |
| 579 | } else { |
| 580 | EFX_INFO(efx, "link down\n"); |
| 581 | } |
| 582 | |
| 583 | } |
| 584 | |
Ben Hutchings | 115122a | 2009-03-04 09:52:52 +0000 | [diff] [blame] | 585 | static void efx_fini_port(struct efx_nic *efx); |
| 586 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 587 | /* This call reinitialises the MAC to pick up new PHY settings. The |
| 588 | * caller must hold the mac_lock */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 589 | void __efx_reconfigure_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 590 | { |
| 591 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 592 | |
| 593 | EFX_LOG(efx, "reconfiguring MAC from PHY settings on CPU %d\n", |
| 594 | raw_smp_processor_id()); |
| 595 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 596 | /* Serialise the promiscuous flag with efx_set_multicast_list. */ |
| 597 | if (efx_dev_registered(efx)) { |
| 598 | netif_addr_lock_bh(efx->net_dev); |
| 599 | netif_addr_unlock_bh(efx->net_dev); |
| 600 | } |
| 601 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 602 | falcon_deconfigure_mac_wrapper(efx); |
| 603 | |
| 604 | /* Reconfigure the PHY, disabling transmit in mac level loopback. */ |
| 605 | if (LOOPBACK_INTERNAL(efx)) |
| 606 | efx->phy_mode |= PHY_MODE_TX_DISABLED; |
| 607 | else |
| 608 | efx->phy_mode &= ~PHY_MODE_TX_DISABLED; |
| 609 | efx->phy_op->reconfigure(efx); |
| 610 | |
| 611 | if (falcon_switch_mac(efx)) |
| 612 | goto fail; |
| 613 | |
| 614 | efx->mac_op->reconfigure(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 615 | |
| 616 | /* Inform kernel of loss/gain of carrier */ |
| 617 | efx_link_status_changed(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 618 | return; |
| 619 | |
| 620 | fail: |
| 621 | EFX_ERR(efx, "failed to reconfigure MAC\n"); |
Ben Hutchings | 115122a | 2009-03-04 09:52:52 +0000 | [diff] [blame] | 622 | efx->port_enabled = false; |
| 623 | efx_fini_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* Reinitialise the MAC to pick up new PHY settings, even if the port is |
| 627 | * disabled. */ |
| 628 | void efx_reconfigure_port(struct efx_nic *efx) |
| 629 | { |
| 630 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 631 | |
| 632 | mutex_lock(&efx->mac_lock); |
| 633 | __efx_reconfigure_port(efx); |
| 634 | mutex_unlock(&efx->mac_lock); |
| 635 | } |
| 636 | |
| 637 | /* Asynchronous efx_reconfigure_port work item. To speed up efx_flush_all() |
| 638 | * we don't efx_reconfigure_port() if the port is disabled. Care is taken |
| 639 | * in efx_stop_all() and efx_start_port() to prevent PHY events being lost */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 640 | static void efx_phy_work(struct work_struct *data) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 641 | { |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 642 | struct efx_nic *efx = container_of(data, struct efx_nic, phy_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 643 | |
| 644 | mutex_lock(&efx->mac_lock); |
| 645 | if (efx->port_enabled) |
| 646 | __efx_reconfigure_port(efx); |
| 647 | mutex_unlock(&efx->mac_lock); |
| 648 | } |
| 649 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 650 | static void efx_mac_work(struct work_struct *data) |
| 651 | { |
| 652 | struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); |
| 653 | |
| 654 | mutex_lock(&efx->mac_lock); |
| 655 | if (efx->port_enabled) |
| 656 | efx->mac_op->irq(efx); |
| 657 | mutex_unlock(&efx->mac_lock); |
| 658 | } |
| 659 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 660 | static int efx_probe_port(struct efx_nic *efx) |
| 661 | { |
| 662 | int rc; |
| 663 | |
| 664 | EFX_LOG(efx, "create port\n"); |
| 665 | |
| 666 | /* Connect up MAC/PHY operations table and read MAC address */ |
| 667 | rc = falcon_probe_port(efx); |
| 668 | if (rc) |
| 669 | goto err; |
| 670 | |
Ben Hutchings | 84ae48f | 2008-12-12 21:34:54 -0800 | [diff] [blame] | 671 | if (phy_flash_cfg) |
| 672 | efx->phy_mode = PHY_MODE_SPECIAL; |
| 673 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 674 | /* Sanity check MAC address */ |
| 675 | if (is_valid_ether_addr(efx->mac_address)) { |
| 676 | memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN); |
| 677 | } else { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 678 | EFX_ERR(efx, "invalid MAC address %pM\n", |
| 679 | efx->mac_address); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 680 | if (!allow_bad_hwaddr) { |
| 681 | rc = -EINVAL; |
| 682 | goto err; |
| 683 | } |
| 684 | random_ether_addr(efx->net_dev->dev_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 685 | EFX_INFO(efx, "using locally-generated MAC %pM\n", |
| 686 | efx->net_dev->dev_addr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | return 0; |
| 690 | |
| 691 | err: |
| 692 | efx_remove_port(efx); |
| 693 | return rc; |
| 694 | } |
| 695 | |
| 696 | static int efx_init_port(struct efx_nic *efx) |
| 697 | { |
| 698 | int rc; |
| 699 | |
| 700 | EFX_LOG(efx, "init port\n"); |
| 701 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 702 | rc = efx->phy_op->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 703 | if (rc) |
| 704 | return rc; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 705 | mutex_lock(&efx->mac_lock); |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 706 | efx->phy_op->reconfigure(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 707 | rc = falcon_switch_mac(efx); |
| 708 | mutex_unlock(&efx->mac_lock); |
| 709 | if (rc) |
| 710 | goto fail; |
| 711 | efx->mac_op->reconfigure(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 712 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 713 | efx->port_initialized = true; |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 714 | efx_stats_enable(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 715 | return 0; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 716 | |
| 717 | fail: |
| 718 | efx->phy_op->fini(efx); |
| 719 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* Allow efx_reconfigure_port() to be scheduled, and close the window |
| 723 | * between efx_stop_port and efx_flush_all whereby a previously scheduled |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 724 | * efx_phy_work()/efx_mac_work() may have been cancelled */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 725 | static void efx_start_port(struct efx_nic *efx) |
| 726 | { |
| 727 | EFX_LOG(efx, "start port\n"); |
| 728 | BUG_ON(efx->port_enabled); |
| 729 | |
| 730 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 731 | efx->port_enabled = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 732 | __efx_reconfigure_port(efx); |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 733 | efx->mac_op->irq(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 734 | mutex_unlock(&efx->mac_lock); |
| 735 | } |
| 736 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 737 | /* Prevent efx_phy_work, efx_mac_work, and efx_monitor() from executing, |
| 738 | * and efx_set_multicast_list() from scheduling efx_phy_work. efx_phy_work |
| 739 | * and efx_mac_work may still be scheduled via NAPI processing until |
| 740 | * efx_flush_all() is called */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 741 | static void efx_stop_port(struct efx_nic *efx) |
| 742 | { |
| 743 | EFX_LOG(efx, "stop port\n"); |
| 744 | |
| 745 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 746 | efx->port_enabled = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 747 | mutex_unlock(&efx->mac_lock); |
| 748 | |
| 749 | /* Serialise against efx_set_multicast_list() */ |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 750 | if (efx_dev_registered(efx)) { |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 751 | netif_addr_lock_bh(efx->net_dev); |
| 752 | netif_addr_unlock_bh(efx->net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
| 756 | static void efx_fini_port(struct efx_nic *efx) |
| 757 | { |
| 758 | EFX_LOG(efx, "shut down port\n"); |
| 759 | |
| 760 | if (!efx->port_initialized) |
| 761 | return; |
| 762 | |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 763 | efx_stats_disable(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 764 | efx->phy_op->fini(efx); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 765 | efx->port_initialized = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 766 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 767 | efx->link_up = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 768 | efx_link_status_changed(efx); |
| 769 | } |
| 770 | |
| 771 | static void efx_remove_port(struct efx_nic *efx) |
| 772 | { |
| 773 | EFX_LOG(efx, "destroying port\n"); |
| 774 | |
| 775 | falcon_remove_port(efx); |
| 776 | } |
| 777 | |
| 778 | /************************************************************************** |
| 779 | * |
| 780 | * NIC handling |
| 781 | * |
| 782 | **************************************************************************/ |
| 783 | |
| 784 | /* This configures the PCI device to enable I/O and DMA. */ |
| 785 | static int efx_init_io(struct efx_nic *efx) |
| 786 | { |
| 787 | struct pci_dev *pci_dev = efx->pci_dev; |
| 788 | dma_addr_t dma_mask = efx->type->max_dma_mask; |
| 789 | int rc; |
| 790 | |
| 791 | EFX_LOG(efx, "initialising I/O\n"); |
| 792 | |
| 793 | rc = pci_enable_device(pci_dev); |
| 794 | if (rc) { |
| 795 | EFX_ERR(efx, "failed to enable PCI device\n"); |
| 796 | goto fail1; |
| 797 | } |
| 798 | |
| 799 | pci_set_master(pci_dev); |
| 800 | |
| 801 | /* Set the PCI DMA mask. Try all possibilities from our |
| 802 | * genuine mask down to 32 bits, because some architectures |
| 803 | * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit |
| 804 | * masks event though they reject 46 bit masks. |
| 805 | */ |
| 806 | while (dma_mask > 0x7fffffffUL) { |
| 807 | if (pci_dma_supported(pci_dev, dma_mask) && |
| 808 | ((rc = pci_set_dma_mask(pci_dev, dma_mask)) == 0)) |
| 809 | break; |
| 810 | dma_mask >>= 1; |
| 811 | } |
| 812 | if (rc) { |
| 813 | EFX_ERR(efx, "could not find a suitable DMA mask\n"); |
| 814 | goto fail2; |
| 815 | } |
| 816 | EFX_LOG(efx, "using DMA mask %llx\n", (unsigned long long) dma_mask); |
| 817 | rc = pci_set_consistent_dma_mask(pci_dev, dma_mask); |
| 818 | if (rc) { |
| 819 | /* pci_set_consistent_dma_mask() is not *allowed* to |
| 820 | * fail with a mask that pci_set_dma_mask() accepted, |
| 821 | * but just in case... |
| 822 | */ |
| 823 | EFX_ERR(efx, "failed to set consistent DMA mask\n"); |
| 824 | goto fail2; |
| 825 | } |
| 826 | |
| 827 | efx->membase_phys = pci_resource_start(efx->pci_dev, |
| 828 | efx->type->mem_bar); |
| 829 | rc = pci_request_region(pci_dev, efx->type->mem_bar, "sfc"); |
| 830 | if (rc) { |
| 831 | EFX_ERR(efx, "request for memory BAR failed\n"); |
| 832 | rc = -EIO; |
| 833 | goto fail3; |
| 834 | } |
| 835 | efx->membase = ioremap_nocache(efx->membase_phys, |
| 836 | efx->type->mem_map_size); |
| 837 | if (!efx->membase) { |
Ben Hutchings | 086ea35 | 2008-05-16 21:17:06 +0100 | [diff] [blame] | 838 | EFX_ERR(efx, "could not map memory BAR %d at %llx+%x\n", |
| 839 | efx->type->mem_bar, |
| 840 | (unsigned long long)efx->membase_phys, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 841 | efx->type->mem_map_size); |
| 842 | rc = -ENOMEM; |
| 843 | goto fail4; |
| 844 | } |
Ben Hutchings | 086ea35 | 2008-05-16 21:17:06 +0100 | [diff] [blame] | 845 | EFX_LOG(efx, "memory BAR %u at %llx+%x (virtual %p)\n", |
| 846 | efx->type->mem_bar, (unsigned long long)efx->membase_phys, |
| 847 | efx->type->mem_map_size, efx->membase); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 848 | |
| 849 | return 0; |
| 850 | |
| 851 | fail4: |
Ben Hutchings | e1074a0 | 2008-09-01 12:49:15 +0100 | [diff] [blame] | 852 | pci_release_region(efx->pci_dev, efx->type->mem_bar); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 853 | fail3: |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 854 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 855 | fail2: |
| 856 | pci_disable_device(efx->pci_dev); |
| 857 | fail1: |
| 858 | return rc; |
| 859 | } |
| 860 | |
| 861 | static void efx_fini_io(struct efx_nic *efx) |
| 862 | { |
| 863 | EFX_LOG(efx, "shutting down I/O\n"); |
| 864 | |
| 865 | if (efx->membase) { |
| 866 | iounmap(efx->membase); |
| 867 | efx->membase = NULL; |
| 868 | } |
| 869 | |
| 870 | if (efx->membase_phys) { |
| 871 | pci_release_region(efx->pci_dev, efx->type->mem_bar); |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 872 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | pci_disable_device(efx->pci_dev); |
| 876 | } |
| 877 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 878 | /* Get number of RX queues wanted. Return number of online CPU |
| 879 | * packages in the expectation that an IRQ balancer will spread |
| 880 | * interrupts across them. */ |
| 881 | static int efx_wanted_rx_queues(void) |
| 882 | { |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 883 | cpumask_var_t core_mask; |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 884 | int count; |
| 885 | int cpu; |
| 886 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 887 | if (unlikely(!zalloc_cpumask_var(&core_mask, GFP_KERNEL))) { |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 888 | printk(KERN_WARNING |
Mike Travis | 3977d03 | 2009-05-12 10:48:36 +0000 | [diff] [blame] | 889 | "sfc: RSS disabled due to allocation failure\n"); |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 890 | return 1; |
| 891 | } |
| 892 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 893 | count = 0; |
| 894 | for_each_online_cpu(cpu) { |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 895 | if (!cpumask_test_cpu(cpu, core_mask)) { |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 896 | ++count; |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 897 | cpumask_or(core_mask, core_mask, |
Rusty Russell | fbd59a8 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 898 | topology_core_cpumask(cpu)); |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
Rusty Russell | 2f8975f | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 902 | free_cpumask_var(core_mask); |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 903 | return count; |
| 904 | } |
| 905 | |
| 906 | /* Probe the number and type of interrupts we are able to obtain, and |
| 907 | * the resulting numbers of channels and RX queues. |
| 908 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 909 | static void efx_probe_interrupts(struct efx_nic *efx) |
| 910 | { |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 911 | int max_channels = |
| 912 | min_t(int, efx->type->phys_addr_channels, EFX_MAX_CHANNELS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 913 | int rc, i; |
| 914 | |
| 915 | if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 916 | struct msix_entry xentries[EFX_MAX_CHANNELS]; |
| 917 | int wanted_ints; |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 918 | int rx_queues; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 919 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 920 | /* We want one RX queue and interrupt per CPU package |
| 921 | * (or as specified by the rss_cpus module parameter). |
| 922 | * We will need one channel per interrupt. |
| 923 | */ |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 924 | rx_queues = rss_cpus ? rss_cpus : efx_wanted_rx_queues(); |
| 925 | wanted_ints = rx_queues + (separate_tx_channels ? 1 : 0); |
| 926 | wanted_ints = min(wanted_ints, max_channels); |
Ben Hutchings | aa6ef27 | 2008-07-18 19:03:10 +0100 | [diff] [blame] | 927 | |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 928 | for (i = 0; i < wanted_ints; i++) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 929 | xentries[i].entry = i; |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 930 | rc = pci_enable_msix(efx->pci_dev, xentries, wanted_ints); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 931 | if (rc > 0) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 932 | EFX_ERR(efx, "WARNING: Insufficient MSI-X vectors" |
| 933 | " available (%d < %d).\n", rc, wanted_ints); |
| 934 | EFX_ERR(efx, "WARNING: Performance may be reduced.\n"); |
| 935 | EFX_BUG_ON_PARANOID(rc >= wanted_ints); |
| 936 | wanted_ints = rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 937 | rc = pci_enable_msix(efx->pci_dev, xentries, |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 938 | wanted_ints); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | if (rc == 0) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 942 | efx->n_rx_queues = min(rx_queues, wanted_ints); |
| 943 | efx->n_channels = wanted_ints; |
| 944 | for (i = 0; i < wanted_ints; i++) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 945 | efx->channel[i].irq = xentries[i].vector; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 946 | } else { |
| 947 | /* Fall back to single channel MSI */ |
| 948 | efx->interrupt_mode = EFX_INT_MODE_MSI; |
| 949 | EFX_ERR(efx, "could not enable MSI-X\n"); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | /* Try single interrupt MSI */ |
| 954 | if (efx->interrupt_mode == EFX_INT_MODE_MSI) { |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 955 | efx->n_rx_queues = 1; |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 956 | efx->n_channels = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 957 | rc = pci_enable_msi(efx->pci_dev); |
| 958 | if (rc == 0) { |
| 959 | efx->channel[0].irq = efx->pci_dev->irq; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 960 | } else { |
| 961 | EFX_ERR(efx, "could not enable MSI\n"); |
| 962 | efx->interrupt_mode = EFX_INT_MODE_LEGACY; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /* Assume legacy interrupts */ |
| 967 | if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 968 | efx->n_rx_queues = 1; |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 969 | efx->n_channels = 1 + (separate_tx_channels ? 1 : 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 970 | efx->legacy_irq = efx->pci_dev->irq; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | static void efx_remove_interrupts(struct efx_nic *efx) |
| 975 | { |
| 976 | struct efx_channel *channel; |
| 977 | |
| 978 | /* Remove MSI/MSI-X interrupts */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 979 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 980 | channel->irq = 0; |
| 981 | pci_disable_msi(efx->pci_dev); |
| 982 | pci_disable_msix(efx->pci_dev); |
| 983 | |
| 984 | /* Remove legacy interrupt */ |
| 985 | efx->legacy_irq = 0; |
| 986 | } |
| 987 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 988 | static void efx_set_channels(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 989 | { |
| 990 | struct efx_tx_queue *tx_queue; |
| 991 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 992 | |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 993 | efx_for_each_tx_queue(tx_queue, efx) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 994 | if (separate_tx_channels) |
| 995 | tx_queue->channel = &efx->channel[efx->n_channels-1]; |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 996 | else |
| 997 | tx_queue->channel = &efx->channel[0]; |
| 998 | tx_queue->channel->used_flags |= EFX_USED_BY_TX; |
| 999 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1000 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 1001 | efx_for_each_rx_queue(rx_queue, efx) { |
| 1002 | rx_queue->channel = &efx->channel[rx_queue->queue]; |
| 1003 | rx_queue->channel->used_flags |= EFX_USED_BY_RX; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | static int efx_probe_nic(struct efx_nic *efx) |
| 1008 | { |
| 1009 | int rc; |
| 1010 | |
| 1011 | EFX_LOG(efx, "creating NIC\n"); |
| 1012 | |
| 1013 | /* Carry out hardware-type specific initialisation */ |
| 1014 | rc = falcon_probe_nic(efx); |
| 1015 | if (rc) |
| 1016 | return rc; |
| 1017 | |
| 1018 | /* Determine the number of channels and RX queues by trying to hook |
| 1019 | * in MSI-X interrupts. */ |
| 1020 | efx_probe_interrupts(efx); |
| 1021 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 1022 | efx_set_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1023 | |
| 1024 | /* Initialise the interrupt moderation settings */ |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 1025 | efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | static void efx_remove_nic(struct efx_nic *efx) |
| 1031 | { |
| 1032 | EFX_LOG(efx, "destroying NIC\n"); |
| 1033 | |
| 1034 | efx_remove_interrupts(efx); |
| 1035 | falcon_remove_nic(efx); |
| 1036 | } |
| 1037 | |
| 1038 | /************************************************************************** |
| 1039 | * |
| 1040 | * NIC startup/shutdown |
| 1041 | * |
| 1042 | *************************************************************************/ |
| 1043 | |
| 1044 | static int efx_probe_all(struct efx_nic *efx) |
| 1045 | { |
| 1046 | struct efx_channel *channel; |
| 1047 | int rc; |
| 1048 | |
| 1049 | /* Create NIC */ |
| 1050 | rc = efx_probe_nic(efx); |
| 1051 | if (rc) { |
| 1052 | EFX_ERR(efx, "failed to create NIC\n"); |
| 1053 | goto fail1; |
| 1054 | } |
| 1055 | |
| 1056 | /* Create port */ |
| 1057 | rc = efx_probe_port(efx); |
| 1058 | if (rc) { |
| 1059 | EFX_ERR(efx, "failed to create port\n"); |
| 1060 | goto fail2; |
| 1061 | } |
| 1062 | |
| 1063 | /* Create channels */ |
| 1064 | efx_for_each_channel(channel, efx) { |
| 1065 | rc = efx_probe_channel(channel); |
| 1066 | if (rc) { |
| 1067 | EFX_ERR(efx, "failed to create channel %d\n", |
| 1068 | channel->channel); |
| 1069 | goto fail3; |
| 1070 | } |
| 1071 | } |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 1072 | efx_set_channel_names(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1073 | |
| 1074 | return 0; |
| 1075 | |
| 1076 | fail3: |
| 1077 | efx_for_each_channel(channel, efx) |
| 1078 | efx_remove_channel(channel); |
| 1079 | efx_remove_port(efx); |
| 1080 | fail2: |
| 1081 | efx_remove_nic(efx); |
| 1082 | fail1: |
| 1083 | return rc; |
| 1084 | } |
| 1085 | |
| 1086 | /* Called after previous invocation(s) of efx_stop_all, restarts the |
| 1087 | * port, kernel transmit queue, NAPI processing and hardware interrupts, |
| 1088 | * and ensures that the port is scheduled to be reconfigured. |
| 1089 | * This function is safe to call multiple times when the NIC is in any |
| 1090 | * state. */ |
| 1091 | static void efx_start_all(struct efx_nic *efx) |
| 1092 | { |
| 1093 | struct efx_channel *channel; |
| 1094 | |
| 1095 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1096 | |
| 1097 | /* Check that it is appropriate to restart the interface. All |
| 1098 | * of these flags are safe to read under just the rtnl lock */ |
| 1099 | if (efx->port_enabled) |
| 1100 | return; |
| 1101 | if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT)) |
| 1102 | return; |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 1103 | if (efx_dev_registered(efx) && !netif_running(efx->net_dev)) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1104 | return; |
| 1105 | |
| 1106 | /* Mark the port as enabled so port reconfigurations can start, then |
| 1107 | * restart the transmit interface early so the watchdog timer stops */ |
| 1108 | efx_start_port(efx); |
Steve Hodgson | dacccc7 | 2008-09-01 12:48:20 +0100 | [diff] [blame] | 1109 | if (efx_dev_registered(efx)) |
| 1110 | efx_wake_queue(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1111 | |
| 1112 | efx_for_each_channel(channel, efx) |
| 1113 | efx_start_channel(channel); |
| 1114 | |
| 1115 | falcon_enable_interrupts(efx); |
| 1116 | |
| 1117 | /* Start hardware monitor if we're in RUNNING */ |
| 1118 | if (efx->state == STATE_RUNNING) |
| 1119 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 1120 | efx_monitor_interval); |
| 1121 | } |
| 1122 | |
| 1123 | /* Flush all delayed work. Should only be called when no more delayed work |
| 1124 | * will be scheduled. This doesn't flush pending online resets (efx_reset), |
| 1125 | * since we're holding the rtnl_lock at this point. */ |
| 1126 | static void efx_flush_all(struct efx_nic *efx) |
| 1127 | { |
| 1128 | struct efx_rx_queue *rx_queue; |
| 1129 | |
| 1130 | /* Make sure the hardware monitor is stopped */ |
| 1131 | cancel_delayed_work_sync(&efx->monitor_work); |
| 1132 | |
| 1133 | /* Ensure that all RX slow refills are complete. */ |
Ben Hutchings | b347564 | 2008-05-16 21:15:49 +0100 | [diff] [blame] | 1134 | efx_for_each_rx_queue(rx_queue, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1135 | cancel_delayed_work_sync(&rx_queue->work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1136 | |
| 1137 | /* Stop scheduled port reconfigurations */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1138 | cancel_work_sync(&efx->mac_work); |
| 1139 | cancel_work_sync(&efx->phy_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1140 | |
| 1141 | } |
| 1142 | |
| 1143 | /* Quiesce hardware and software without bringing the link down. |
| 1144 | * Safe to call multiple times, when the nic and interface is in any |
| 1145 | * state. The caller is guaranteed to subsequently be in a position |
| 1146 | * to modify any hardware and software state they see fit without |
| 1147 | * taking locks. */ |
| 1148 | static void efx_stop_all(struct efx_nic *efx) |
| 1149 | { |
| 1150 | struct efx_channel *channel; |
| 1151 | |
| 1152 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1153 | |
| 1154 | /* port_enabled can be read safely under the rtnl lock */ |
| 1155 | if (!efx->port_enabled) |
| 1156 | return; |
| 1157 | |
| 1158 | /* Disable interrupts and wait for ISR to complete */ |
| 1159 | falcon_disable_interrupts(efx); |
| 1160 | if (efx->legacy_irq) |
| 1161 | synchronize_irq(efx->legacy_irq); |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 1162 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1163 | if (channel->irq) |
| 1164 | synchronize_irq(channel->irq); |
Ben Hutchings | b347564 | 2008-05-16 21:15:49 +0100 | [diff] [blame] | 1165 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1166 | |
| 1167 | /* Stop all NAPI processing and synchronous rx refills */ |
| 1168 | efx_for_each_channel(channel, efx) |
| 1169 | efx_stop_channel(channel); |
| 1170 | |
| 1171 | /* Stop all asynchronous port reconfigurations. Since all |
| 1172 | * event processing has already been stopped, there is no |
| 1173 | * window to loose phy events */ |
| 1174 | efx_stop_port(efx); |
| 1175 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1176 | /* Flush efx_phy_work, efx_mac_work, refill_workqueue, monitor_work */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1177 | efx_flush_all(efx); |
| 1178 | |
| 1179 | /* Isolate the MAC from the TX and RX engines, so that queue |
| 1180 | * flushes will complete in a timely fashion. */ |
Ben Hutchings | 5c8af3b | 2009-08-26 08:18:13 +0000 | [diff] [blame] | 1181 | falcon_deconfigure_mac_wrapper(efx); |
| 1182 | msleep(10); /* Let the Rx FIFO drain */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1183 | falcon_drain_tx_fifo(efx); |
| 1184 | |
| 1185 | /* Stop the kernel transmit interface late, so the watchdog |
| 1186 | * timer isn't ticking over the flush */ |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 1187 | if (efx_dev_registered(efx)) { |
Steve Hodgson | dacccc7 | 2008-09-01 12:48:20 +0100 | [diff] [blame] | 1188 | efx_stop_queue(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1189 | netif_tx_lock_bh(efx->net_dev); |
| 1190 | netif_tx_unlock_bh(efx->net_dev); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | static void efx_remove_all(struct efx_nic *efx) |
| 1195 | { |
| 1196 | struct efx_channel *channel; |
| 1197 | |
| 1198 | efx_for_each_channel(channel, efx) |
| 1199 | efx_remove_channel(channel); |
| 1200 | efx_remove_port(efx); |
| 1201 | efx_remove_nic(efx); |
| 1202 | } |
| 1203 | |
| 1204 | /* A convinience function to safely flush all the queues */ |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 1205 | void efx_flush_queues(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1206 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1207 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1208 | |
| 1209 | efx_stop_all(efx); |
| 1210 | |
| 1211 | efx_fini_channels(efx); |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 1212 | efx_init_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1213 | |
| 1214 | efx_start_all(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /************************************************************************** |
| 1218 | * |
| 1219 | * Interrupt moderation |
| 1220 | * |
| 1221 | **************************************************************************/ |
| 1222 | |
| 1223 | /* Set interrupt moderation parameters */ |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 1224 | void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs, |
| 1225 | bool rx_adaptive) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1226 | { |
| 1227 | struct efx_tx_queue *tx_queue; |
| 1228 | struct efx_rx_queue *rx_queue; |
| 1229 | |
| 1230 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1231 | |
| 1232 | efx_for_each_tx_queue(tx_queue, efx) |
| 1233 | tx_queue->channel->irq_moderation = tx_usecs; |
| 1234 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 1235 | efx->irq_rx_adaptive = rx_adaptive; |
| 1236 | efx->irq_rx_moderation = rx_usecs; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1237 | efx_for_each_rx_queue(rx_queue, efx) |
| 1238 | rx_queue->channel->irq_moderation = rx_usecs; |
| 1239 | } |
| 1240 | |
| 1241 | /************************************************************************** |
| 1242 | * |
| 1243 | * Hardware monitor |
| 1244 | * |
| 1245 | **************************************************************************/ |
| 1246 | |
| 1247 | /* Run periodically off the general workqueue. Serialised against |
| 1248 | * efx_reconfigure_port via the mac_lock */ |
| 1249 | static void efx_monitor(struct work_struct *data) |
| 1250 | { |
| 1251 | struct efx_nic *efx = container_of(data, struct efx_nic, |
| 1252 | monitor_work.work); |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1253 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1254 | |
| 1255 | EFX_TRACE(efx, "hardware monitor executing on CPU %d\n", |
| 1256 | raw_smp_processor_id()); |
| 1257 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1258 | /* If the mac_lock is already held then it is likely a port |
| 1259 | * reconfiguration is already in place, which will likely do |
| 1260 | * most of the work of check_hw() anyway. */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1261 | if (!mutex_trylock(&efx->mac_lock)) |
| 1262 | goto out_requeue; |
| 1263 | if (!efx->port_enabled) |
| 1264 | goto out_unlock; |
| 1265 | rc = efx->board_info.monitor(efx); |
| 1266 | if (rc) { |
| 1267 | EFX_ERR(efx, "Board sensor %s; shutting down PHY\n", |
| 1268 | (rc == -ERANGE) ? "reported fault" : "failed"); |
| 1269 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
| 1270 | falcon_sim_phy_event(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1271 | } |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1272 | efx->phy_op->poll(efx); |
| 1273 | efx->mac_op->poll(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1274 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1275 | out_unlock: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1276 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1277 | out_requeue: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1278 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 1279 | efx_monitor_interval); |
| 1280 | } |
| 1281 | |
| 1282 | /************************************************************************** |
| 1283 | * |
| 1284 | * ioctls |
| 1285 | * |
| 1286 | *************************************************************************/ |
| 1287 | |
| 1288 | /* Net device ioctl |
| 1289 | * Context: process, rtnl_lock() held. |
| 1290 | */ |
| 1291 | static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) |
| 1292 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1293 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1294 | struct mii_ioctl_data *data = if_mii(ifr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1295 | |
| 1296 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1297 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1298 | /* Convert phy_id from older PRTAD/DEVAD format */ |
| 1299 | if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && |
| 1300 | (data->phy_id & 0xfc00) == 0x0400) |
| 1301 | data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; |
| 1302 | |
| 1303 | return mdio_mii_ioctl(&efx->mdio, data, cmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /************************************************************************** |
| 1307 | * |
| 1308 | * NAPI interface |
| 1309 | * |
| 1310 | **************************************************************************/ |
| 1311 | |
| 1312 | static int efx_init_napi(struct efx_nic *efx) |
| 1313 | { |
| 1314 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1315 | |
| 1316 | efx_for_each_channel(channel, efx) { |
| 1317 | channel->napi_dev = efx->net_dev; |
Ben Hutchings | 718cff1 | 2009-04-14 19:47:46 -0700 | [diff] [blame] | 1318 | netif_napi_add(channel->napi_dev, &channel->napi_str, |
| 1319 | efx_poll, napi_weight); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1320 | } |
| 1321 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static void efx_fini_napi(struct efx_nic *efx) |
| 1325 | { |
| 1326 | struct efx_channel *channel; |
| 1327 | |
| 1328 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 718cff1 | 2009-04-14 19:47:46 -0700 | [diff] [blame] | 1329 | if (channel->napi_dev) |
| 1330 | netif_napi_del(&channel->napi_str); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1331 | channel->napi_dev = NULL; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | /************************************************************************** |
| 1336 | * |
| 1337 | * Kernel netpoll interface |
| 1338 | * |
| 1339 | *************************************************************************/ |
| 1340 | |
| 1341 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1342 | |
| 1343 | /* Although in the common case interrupts will be disabled, this is not |
| 1344 | * guaranteed. However, all our work happens inside the NAPI callback, |
| 1345 | * so no locking is required. |
| 1346 | */ |
| 1347 | static void efx_netpoll(struct net_device *net_dev) |
| 1348 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1349 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1350 | struct efx_channel *channel; |
| 1351 | |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 1352 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1353 | efx_schedule_channel(channel); |
| 1354 | } |
| 1355 | |
| 1356 | #endif |
| 1357 | |
| 1358 | /************************************************************************** |
| 1359 | * |
| 1360 | * Kernel net device interface |
| 1361 | * |
| 1362 | *************************************************************************/ |
| 1363 | |
| 1364 | /* Context: process, rtnl_lock() held. */ |
| 1365 | static int efx_net_open(struct net_device *net_dev) |
| 1366 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1367 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1368 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1369 | |
| 1370 | EFX_LOG(efx, "opening device %s on CPU %d\n", net_dev->name, |
| 1371 | raw_smp_processor_id()); |
| 1372 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1373 | if (efx->state == STATE_DISABLED) |
| 1374 | return -EIO; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 1375 | if (efx->phy_mode & PHY_MODE_SPECIAL) |
| 1376 | return -EBUSY; |
| 1377 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1378 | efx_start_all(efx); |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
| 1382 | /* Context: process, rtnl_lock() held. |
| 1383 | * Note that the kernel will ignore our return code; this method |
| 1384 | * should really be a void. |
| 1385 | */ |
| 1386 | static int efx_net_stop(struct net_device *net_dev) |
| 1387 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1388 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1389 | |
| 1390 | EFX_LOG(efx, "closing %s on CPU %d\n", net_dev->name, |
| 1391 | raw_smp_processor_id()); |
| 1392 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1393 | if (efx->state != STATE_DISABLED) { |
| 1394 | /* Stop the device and flush all the channels */ |
| 1395 | efx_stop_all(efx); |
| 1396 | efx_fini_channels(efx); |
| 1397 | efx_init_channels(efx); |
| 1398 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1403 | void efx_stats_disable(struct efx_nic *efx) |
| 1404 | { |
| 1405 | spin_lock(&efx->stats_lock); |
| 1406 | ++efx->stats_disable_count; |
| 1407 | spin_unlock(&efx->stats_lock); |
| 1408 | } |
| 1409 | |
| 1410 | void efx_stats_enable(struct efx_nic *efx) |
| 1411 | { |
| 1412 | spin_lock(&efx->stats_lock); |
| 1413 | --efx->stats_disable_count; |
| 1414 | spin_unlock(&efx->stats_lock); |
| 1415 | } |
| 1416 | |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 1417 | /* Context: process, dev_base_lock or RTNL held, non-blocking. */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1418 | static struct net_device_stats *efx_net_stats(struct net_device *net_dev) |
| 1419 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1420 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1421 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
| 1422 | struct net_device_stats *stats = &net_dev->stats; |
| 1423 | |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 1424 | /* Update stats if possible, but do not wait if another thread |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1425 | * is updating them or if MAC stats fetches are temporarily |
| 1426 | * disabled; slightly stale stats are acceptable. |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 1427 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1428 | if (!spin_trylock(&efx->stats_lock)) |
| 1429 | return stats; |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1430 | if (!efx->stats_disable_count) { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1431 | efx->mac_op->update_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1432 | falcon_update_nic_stats(efx); |
| 1433 | } |
| 1434 | spin_unlock(&efx->stats_lock); |
| 1435 | |
| 1436 | stats->rx_packets = mac_stats->rx_packets; |
| 1437 | stats->tx_packets = mac_stats->tx_packets; |
| 1438 | stats->rx_bytes = mac_stats->rx_bytes; |
| 1439 | stats->tx_bytes = mac_stats->tx_bytes; |
| 1440 | stats->multicast = mac_stats->rx_multicast; |
| 1441 | stats->collisions = mac_stats->tx_collision; |
| 1442 | stats->rx_length_errors = (mac_stats->rx_gtjumbo + |
| 1443 | mac_stats->rx_length_error); |
| 1444 | stats->rx_over_errors = efx->n_rx_nodesc_drop_cnt; |
| 1445 | stats->rx_crc_errors = mac_stats->rx_bad; |
| 1446 | stats->rx_frame_errors = mac_stats->rx_align_error; |
| 1447 | stats->rx_fifo_errors = mac_stats->rx_overflow; |
| 1448 | stats->rx_missed_errors = mac_stats->rx_missed; |
| 1449 | stats->tx_window_errors = mac_stats->tx_late_collision; |
| 1450 | |
| 1451 | stats->rx_errors = (stats->rx_length_errors + |
| 1452 | stats->rx_over_errors + |
| 1453 | stats->rx_crc_errors + |
| 1454 | stats->rx_frame_errors + |
| 1455 | stats->rx_fifo_errors + |
| 1456 | stats->rx_missed_errors + |
| 1457 | mac_stats->rx_symbol_error); |
| 1458 | stats->tx_errors = (stats->tx_window_errors + |
| 1459 | mac_stats->tx_bad); |
| 1460 | |
| 1461 | return stats; |
| 1462 | } |
| 1463 | |
| 1464 | /* Context: netif_tx_lock held, BHs disabled. */ |
| 1465 | static void efx_watchdog(struct net_device *net_dev) |
| 1466 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1467 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1468 | |
Ben Hutchings | 739bb23 | 2008-11-04 20:35:36 +0000 | [diff] [blame] | 1469 | EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d:" |
| 1470 | " resetting channels\n", |
| 1471 | atomic_read(&efx->netif_stop_count), efx->port_enabled); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1472 | |
Ben Hutchings | 739bb23 | 2008-11-04 20:35:36 +0000 | [diff] [blame] | 1473 | efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | /* Context: process, rtnl_lock() held. */ |
| 1478 | static int efx_change_mtu(struct net_device *net_dev, int new_mtu) |
| 1479 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1480 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1481 | int rc = 0; |
| 1482 | |
| 1483 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1484 | |
| 1485 | if (new_mtu > EFX_MAX_MTU) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | efx_stop_all(efx); |
| 1489 | |
| 1490 | EFX_LOG(efx, "changing MTU to %d\n", new_mtu); |
| 1491 | |
| 1492 | efx_fini_channels(efx); |
| 1493 | net_dev->mtu = new_mtu; |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 1494 | efx_init_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1495 | |
| 1496 | efx_start_all(efx); |
| 1497 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static int efx_set_mac_address(struct net_device *net_dev, void *data) |
| 1501 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1502 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1503 | struct sockaddr *addr = data; |
| 1504 | char *new_addr = addr->sa_data; |
| 1505 | |
| 1506 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1507 | |
| 1508 | if (!is_valid_ether_addr(new_addr)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1509 | EFX_ERR(efx, "invalid ethernet MAC address requested: %pM\n", |
| 1510 | new_addr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | |
| 1514 | memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len); |
| 1515 | |
| 1516 | /* Reconfigure the MAC */ |
| 1517 | efx_reconfigure_port(efx); |
| 1518 | |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1522 | /* Context: netif_addr_lock held, BHs disabled. */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1523 | static void efx_set_multicast_list(struct net_device *net_dev) |
| 1524 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1525 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1526 | struct dev_mc_list *mc_list = net_dev->mc_list; |
| 1527 | union efx_multicast_hash *mc_hash = &efx->multicast_hash; |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1528 | bool promiscuous = !!(net_dev->flags & IFF_PROMISC); |
| 1529 | bool changed = (efx->promiscuous != promiscuous); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1530 | u32 crc; |
| 1531 | int bit; |
| 1532 | int i; |
| 1533 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1534 | efx->promiscuous = promiscuous; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1535 | |
| 1536 | /* Build multicast hash table */ |
| 1537 | if (promiscuous || (net_dev->flags & IFF_ALLMULTI)) { |
| 1538 | memset(mc_hash, 0xff, sizeof(*mc_hash)); |
| 1539 | } else { |
| 1540 | memset(mc_hash, 0x00, sizeof(*mc_hash)); |
| 1541 | for (i = 0; i < net_dev->mc_count; i++) { |
| 1542 | crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr); |
| 1543 | bit = crc & (EFX_MCAST_HASH_ENTRIES - 1); |
| 1544 | set_bit_le(bit, mc_hash->byte); |
| 1545 | mc_list = mc_list->next; |
| 1546 | } |
| 1547 | } |
| 1548 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1549 | if (!efx->port_enabled) |
| 1550 | /* Delay pushing settings until efx_start_port() */ |
| 1551 | return; |
| 1552 | |
| 1553 | if (changed) |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1554 | queue_work(efx->workqueue, &efx->phy_work); |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1555 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1556 | /* Create and activate new global multicast hash table */ |
| 1557 | falcon_set_multicast_hash(efx); |
| 1558 | } |
| 1559 | |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 1560 | static const struct net_device_ops efx_netdev_ops = { |
| 1561 | .ndo_open = efx_net_open, |
| 1562 | .ndo_stop = efx_net_stop, |
| 1563 | .ndo_get_stats = efx_net_stats, |
| 1564 | .ndo_tx_timeout = efx_watchdog, |
| 1565 | .ndo_start_xmit = efx_hard_start_xmit, |
| 1566 | .ndo_validate_addr = eth_validate_addr, |
| 1567 | .ndo_do_ioctl = efx_ioctl, |
| 1568 | .ndo_change_mtu = efx_change_mtu, |
| 1569 | .ndo_set_mac_address = efx_set_mac_address, |
| 1570 | .ndo_set_multicast_list = efx_set_multicast_list, |
| 1571 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1572 | .ndo_poll_controller = efx_netpoll, |
| 1573 | #endif |
| 1574 | }; |
| 1575 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 1576 | static void efx_update_name(struct efx_nic *efx) |
| 1577 | { |
| 1578 | strcpy(efx->name, efx->net_dev->name); |
| 1579 | efx_mtd_rename(efx); |
| 1580 | efx_set_channel_names(efx); |
| 1581 | } |
| 1582 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1583 | static int efx_netdev_event(struct notifier_block *this, |
| 1584 | unsigned long event, void *ptr) |
| 1585 | { |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 1586 | struct net_device *net_dev = ptr; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1587 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 1588 | if (net_dev->netdev_ops == &efx_netdev_ops && |
| 1589 | event == NETDEV_CHANGENAME) |
| 1590 | efx_update_name(netdev_priv(net_dev)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1591 | |
| 1592 | return NOTIFY_DONE; |
| 1593 | } |
| 1594 | |
| 1595 | static struct notifier_block efx_netdev_notifier = { |
| 1596 | .notifier_call = efx_netdev_event, |
| 1597 | }; |
| 1598 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 1599 | static ssize_t |
| 1600 | show_phy_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 1601 | { |
| 1602 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 1603 | return sprintf(buf, "%d\n", efx->phy_type); |
| 1604 | } |
| 1605 | static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL); |
| 1606 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1607 | static int efx_register_netdev(struct efx_nic *efx) |
| 1608 | { |
| 1609 | struct net_device *net_dev = efx->net_dev; |
| 1610 | int rc; |
| 1611 | |
| 1612 | net_dev->watchdog_timeo = 5 * HZ; |
| 1613 | net_dev->irq = efx->pci_dev->irq; |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 1614 | net_dev->netdev_ops = &efx_netdev_ops; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1615 | SET_NETDEV_DEV(net_dev, &efx->pci_dev->dev); |
| 1616 | SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops); |
| 1617 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1618 | /* Clear MAC statistics */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1619 | efx->mac_op->update_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1620 | memset(&efx->mac_stats, 0, sizeof(efx->mac_stats)); |
| 1621 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 1622 | rtnl_lock(); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 1623 | |
| 1624 | rc = dev_alloc_name(net_dev, net_dev->name); |
| 1625 | if (rc < 0) |
| 1626 | goto fail_locked; |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 1627 | efx_update_name(efx); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 1628 | |
| 1629 | rc = register_netdevice(net_dev); |
| 1630 | if (rc) |
| 1631 | goto fail_locked; |
| 1632 | |
| 1633 | /* Always start with carrier off; PHY events will detect the link */ |
| 1634 | netif_carrier_off(efx->net_dev); |
| 1635 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 1636 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1637 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 1638 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 1639 | if (rc) { |
| 1640 | EFX_ERR(efx, "failed to init net dev attributes\n"); |
| 1641 | goto fail_registered; |
| 1642 | } |
| 1643 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1644 | return 0; |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 1645 | |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 1646 | fail_locked: |
| 1647 | rtnl_unlock(); |
| 1648 | EFX_ERR(efx, "could not register net dev\n"); |
| 1649 | return rc; |
| 1650 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 1651 | fail_registered: |
| 1652 | unregister_netdev(net_dev); |
| 1653 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | static void efx_unregister_netdev(struct efx_nic *efx) |
| 1657 | { |
| 1658 | struct efx_tx_queue *tx_queue; |
| 1659 | |
| 1660 | if (!efx->net_dev) |
| 1661 | return; |
| 1662 | |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1663 | BUG_ON(netdev_priv(efx->net_dev) != efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1664 | |
| 1665 | /* Free up any skbs still remaining. This has to happen before |
| 1666 | * we try to unregister the netdev as running their destructors |
| 1667 | * may be needed to get the device ref. count to 0. */ |
| 1668 | efx_for_each_tx_queue(tx_queue, efx) |
| 1669 | efx_release_tx_buffers(tx_queue); |
| 1670 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 1671 | if (efx_dev_registered(efx)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1672 | strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 1673 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1674 | unregister_netdev(efx->net_dev); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | /************************************************************************** |
| 1679 | * |
| 1680 | * Device reset and suspend |
| 1681 | * |
| 1682 | **************************************************************************/ |
| 1683 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1684 | /* Tears down the entire software state and most of the hardware state |
| 1685 | * before reset. */ |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1686 | void efx_reset_down(struct efx_nic *efx, enum reset_type method, |
| 1687 | struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1688 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1689 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1690 | |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1691 | efx_stats_disable(efx); |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1692 | efx_stop_all(efx); |
| 1693 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1694 | mutex_lock(&efx->spi_lock); |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1695 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1696 | efx->phy_op->get_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1697 | |
| 1698 | efx_fini_channels(efx); |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1699 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) |
| 1700 | efx->phy_op->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1703 | /* This function will always ensure that the locks acquired in |
| 1704 | * efx_reset_down() are released. A failure return code indicates |
| 1705 | * that we were unable to reinitialise the hardware, and the |
| 1706 | * driver should be disabled. If ok is false, then the rx and tx |
| 1707 | * engines are not restarted, pending a RESET_DISABLE. */ |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1708 | int efx_reset_up(struct efx_nic *efx, enum reset_type method, |
| 1709 | struct ethtool_cmd *ecmd, bool ok) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1710 | { |
| 1711 | int rc; |
| 1712 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1713 | EFX_ASSERT_RESET_SERIALISED(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1714 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1715 | rc = falcon_init_nic(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1716 | if (rc) { |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1717 | EFX_ERR(efx, "failed to initialise NIC\n"); |
| 1718 | ok = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1721 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) { |
| 1722 | if (ok) { |
| 1723 | rc = efx->phy_op->init(efx); |
| 1724 | if (rc) |
| 1725 | ok = false; |
Ben Hutchings | 115122a | 2009-03-04 09:52:52 +0000 | [diff] [blame] | 1726 | } |
| 1727 | if (!ok) |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1728 | efx->port_initialized = false; |
| 1729 | } |
| 1730 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1731 | if (ok) { |
| 1732 | efx_init_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1733 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1734 | if (efx->phy_op->set_settings(efx, ecmd)) |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1735 | EFX_ERR(efx, "could not restore PHY settings\n"); |
| 1736 | } |
| 1737 | |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1738 | mutex_unlock(&efx->spi_lock); |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1739 | mutex_unlock(&efx->mac_lock); |
| 1740 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1741 | if (ok) { |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 1742 | efx_start_all(efx); |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1743 | efx_stats_enable(efx); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1744 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1745 | return rc; |
| 1746 | } |
| 1747 | |
| 1748 | /* Reset the NIC as transparently as possible. Do not reset the PHY |
| 1749 | * Note that the reset may fail, in which case the card will be left |
| 1750 | * in a most-probably-unusable state. |
| 1751 | * |
| 1752 | * This function will sleep. You cannot reset from within an atomic |
| 1753 | * state; use efx_schedule_reset() instead. |
| 1754 | * |
| 1755 | * Grabs the rtnl_lock. |
| 1756 | */ |
| 1757 | static int efx_reset(struct efx_nic *efx) |
| 1758 | { |
| 1759 | struct ethtool_cmd ecmd; |
| 1760 | enum reset_type method = efx->reset_pending; |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1761 | int rc = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1762 | |
| 1763 | /* Serialise with kernel interfaces */ |
| 1764 | rtnl_lock(); |
| 1765 | |
| 1766 | /* If we're not RUNNING then don't reset. Leave the reset_pending |
| 1767 | * flag set so that efx_pci_probe_main will be retried */ |
| 1768 | if (efx->state != STATE_RUNNING) { |
| 1769 | EFX_INFO(efx, "scheduled reset quenched. NIC not RUNNING\n"); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1770 | goto out_unlock; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1773 | EFX_INFO(efx, "resetting (%d)\n", method); |
| 1774 | |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1775 | efx_reset_down(efx, method, &ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1776 | |
| 1777 | rc = falcon_reset_hw(efx, method); |
| 1778 | if (rc) { |
| 1779 | EFX_ERR(efx, "failed to reset hardware\n"); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1780 | goto out_disable; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | /* Allow resets to be rescheduled. */ |
| 1784 | efx->reset_pending = RESET_TYPE_NONE; |
| 1785 | |
| 1786 | /* Reinitialise bus-mastering, which may have been turned off before |
| 1787 | * the reset was scheduled. This is still appropriate, even in the |
| 1788 | * RESET_TYPE_DISABLE since this driver generally assumes the hardware |
| 1789 | * can respond to requests. */ |
| 1790 | pci_set_master(efx->pci_dev); |
| 1791 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1792 | /* Leave device stopped if necessary */ |
| 1793 | if (method == RESET_TYPE_DISABLE) { |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1794 | efx_reset_up(efx, method, &ecmd, false); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1795 | rc = -EIO; |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1796 | } else { |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 1797 | rc = efx_reset_up(efx, method, &ecmd, true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1798 | } |
| 1799 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1800 | out_disable: |
| 1801 | if (rc) { |
| 1802 | EFX_ERR(efx, "has been disabled\n"); |
| 1803 | efx->state = STATE_DISABLED; |
| 1804 | dev_close(efx->net_dev); |
| 1805 | } else { |
| 1806 | EFX_LOG(efx, "reset complete\n"); |
| 1807 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1808 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1809 | out_unlock: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1810 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1811 | return rc; |
| 1812 | } |
| 1813 | |
| 1814 | /* The worker thread exists so that code that cannot sleep can |
| 1815 | * schedule a reset for later. |
| 1816 | */ |
| 1817 | static void efx_reset_work(struct work_struct *data) |
| 1818 | { |
| 1819 | struct efx_nic *nic = container_of(data, struct efx_nic, reset_work); |
| 1820 | |
| 1821 | efx_reset(nic); |
| 1822 | } |
| 1823 | |
| 1824 | void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) |
| 1825 | { |
| 1826 | enum reset_type method; |
| 1827 | |
| 1828 | if (efx->reset_pending != RESET_TYPE_NONE) { |
| 1829 | EFX_INFO(efx, "quenching already scheduled reset\n"); |
| 1830 | return; |
| 1831 | } |
| 1832 | |
| 1833 | switch (type) { |
| 1834 | case RESET_TYPE_INVISIBLE: |
| 1835 | case RESET_TYPE_ALL: |
| 1836 | case RESET_TYPE_WORLD: |
| 1837 | case RESET_TYPE_DISABLE: |
| 1838 | method = type; |
| 1839 | break; |
| 1840 | case RESET_TYPE_RX_RECOVERY: |
| 1841 | case RESET_TYPE_RX_DESC_FETCH: |
| 1842 | case RESET_TYPE_TX_DESC_FETCH: |
| 1843 | case RESET_TYPE_TX_SKIP: |
| 1844 | method = RESET_TYPE_INVISIBLE; |
| 1845 | break; |
| 1846 | default: |
| 1847 | method = RESET_TYPE_ALL; |
| 1848 | break; |
| 1849 | } |
| 1850 | |
| 1851 | if (method != type) |
| 1852 | EFX_LOG(efx, "scheduling reset (%d:%d)\n", type, method); |
| 1853 | else |
| 1854 | EFX_LOG(efx, "scheduling reset (%d)\n", method); |
| 1855 | |
| 1856 | efx->reset_pending = method; |
| 1857 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 1858 | queue_work(reset_workqueue, &efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /************************************************************************** |
| 1862 | * |
| 1863 | * List of NICs we support |
| 1864 | * |
| 1865 | **************************************************************************/ |
| 1866 | |
| 1867 | /* PCI device ID table */ |
| 1868 | static struct pci_device_id efx_pci_table[] __devinitdata = { |
| 1869 | {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID), |
| 1870 | .driver_data = (unsigned long) &falcon_a_nic_type}, |
| 1871 | {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID), |
| 1872 | .driver_data = (unsigned long) &falcon_b_nic_type}, |
| 1873 | {0} /* end of list */ |
| 1874 | }; |
| 1875 | |
| 1876 | /************************************************************************** |
| 1877 | * |
| 1878 | * Dummy PHY/MAC/Board operations |
| 1879 | * |
Ben Hutchings | 01aad7b | 2008-09-01 12:48:36 +0100 | [diff] [blame] | 1880 | * Can be used for some unimplemented operations |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1881 | * Needed so all function pointers are valid and do not have to be tested |
| 1882 | * before use |
| 1883 | * |
| 1884 | **************************************************************************/ |
| 1885 | int efx_port_dummy_op_int(struct efx_nic *efx) |
| 1886 | { |
| 1887 | return 0; |
| 1888 | } |
| 1889 | void efx_port_dummy_op_void(struct efx_nic *efx) {} |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1890 | void efx_port_dummy_op_blink(struct efx_nic *efx, bool blink) {} |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1891 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1892 | static struct efx_mac_operations efx_dummy_mac_operations = { |
| 1893 | .reconfigure = efx_port_dummy_op_void, |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1894 | .poll = efx_port_dummy_op_void, |
| 1895 | .irq = efx_port_dummy_op_void, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1896 | }; |
| 1897 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1898 | static struct efx_phy_operations efx_dummy_phy_operations = { |
| 1899 | .init = efx_port_dummy_op_int, |
| 1900 | .reconfigure = efx_port_dummy_op_void, |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1901 | .poll = efx_port_dummy_op_void, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1902 | .fini = efx_port_dummy_op_void, |
| 1903 | .clear_interrupt = efx_port_dummy_op_void, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1904 | }; |
| 1905 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1906 | static struct efx_board efx_dummy_board_info = { |
Ben Hutchings | 01aad7b | 2008-09-01 12:48:36 +0100 | [diff] [blame] | 1907 | .init = efx_port_dummy_op_int, |
Ben Hutchings | 8129d21 | 2009-02-27 13:08:03 +0000 | [diff] [blame] | 1908 | .init_leds = efx_port_dummy_op_void, |
| 1909 | .set_id_led = efx_port_dummy_op_blink, |
Ben Hutchings | a17102b | 2008-12-12 21:28:20 -0800 | [diff] [blame] | 1910 | .monitor = efx_port_dummy_op_int, |
Ben Hutchings | 01aad7b | 2008-09-01 12:48:36 +0100 | [diff] [blame] | 1911 | .blink = efx_port_dummy_op_blink, |
| 1912 | .fini = efx_port_dummy_op_void, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1913 | }; |
| 1914 | |
| 1915 | /************************************************************************** |
| 1916 | * |
| 1917 | * Data housekeeping |
| 1918 | * |
| 1919 | **************************************************************************/ |
| 1920 | |
| 1921 | /* This zeroes out and then fills in the invariants in a struct |
| 1922 | * efx_nic (including all sub-structures). |
| 1923 | */ |
| 1924 | static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type, |
| 1925 | struct pci_dev *pci_dev, struct net_device *net_dev) |
| 1926 | { |
| 1927 | struct efx_channel *channel; |
| 1928 | struct efx_tx_queue *tx_queue; |
| 1929 | struct efx_rx_queue *rx_queue; |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 1930 | int i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1931 | |
| 1932 | /* Initialise common structures */ |
| 1933 | memset(efx, 0, sizeof(*efx)); |
| 1934 | spin_lock_init(&efx->biu_lock); |
| 1935 | spin_lock_init(&efx->phy_lock); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1936 | mutex_init(&efx->spi_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1937 | INIT_WORK(&efx->reset_work, efx_reset_work); |
| 1938 | INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); |
| 1939 | efx->pci_dev = pci_dev; |
| 1940 | efx->state = STATE_INIT; |
| 1941 | efx->reset_pending = RESET_TYPE_NONE; |
| 1942 | strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); |
| 1943 | efx->board_info = efx_dummy_board_info; |
| 1944 | |
| 1945 | efx->net_dev = net_dev; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1946 | efx->rx_checksum_enabled = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1947 | spin_lock_init(&efx->netif_stop_lock); |
| 1948 | spin_lock_init(&efx->stats_lock); |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 1949 | efx->stats_disable_count = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1950 | mutex_init(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1951 | efx->mac_op = &efx_dummy_mac_operations; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1952 | efx->phy_op = &efx_dummy_phy_operations; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1953 | efx->mdio.dev = net_dev; |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1954 | INIT_WORK(&efx->phy_work, efx_phy_work); |
| 1955 | INIT_WORK(&efx->mac_work, efx_mac_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1956 | atomic_set(&efx->netif_stop_count, 1); |
| 1957 | |
| 1958 | for (i = 0; i < EFX_MAX_CHANNELS; i++) { |
| 1959 | channel = &efx->channel[i]; |
| 1960 | channel->efx = efx; |
| 1961 | channel->channel = i; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1962 | channel->work_pending = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1963 | } |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 1964 | for (i = 0; i < EFX_TX_QUEUE_COUNT; i++) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1965 | tx_queue = &efx->tx_queue[i]; |
| 1966 | tx_queue->efx = efx; |
| 1967 | tx_queue->queue = i; |
| 1968 | tx_queue->buffer = NULL; |
| 1969 | tx_queue->channel = &efx->channel[0]; /* for safety */ |
Ben Hutchings | b9b39b6 | 2008-05-07 12:51:12 +0100 | [diff] [blame] | 1970 | tx_queue->tso_headers_free = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1971 | } |
| 1972 | for (i = 0; i < EFX_MAX_RX_QUEUES; i++) { |
| 1973 | rx_queue = &efx->rx_queue[i]; |
| 1974 | rx_queue->efx = efx; |
| 1975 | rx_queue->queue = i; |
| 1976 | rx_queue->channel = &efx->channel[0]; /* for safety */ |
| 1977 | rx_queue->buffer = NULL; |
| 1978 | spin_lock_init(&rx_queue->add_lock); |
| 1979 | INIT_DELAYED_WORK(&rx_queue->work, efx_rx_work); |
| 1980 | } |
| 1981 | |
| 1982 | efx->type = type; |
| 1983 | |
| 1984 | /* Sanity-check NIC type */ |
| 1985 | EFX_BUG_ON_PARANOID(efx->type->txd_ring_mask & |
| 1986 | (efx->type->txd_ring_mask + 1)); |
| 1987 | EFX_BUG_ON_PARANOID(efx->type->rxd_ring_mask & |
| 1988 | (efx->type->rxd_ring_mask + 1)); |
| 1989 | EFX_BUG_ON_PARANOID(efx->type->evq_size & |
| 1990 | (efx->type->evq_size - 1)); |
| 1991 | /* As close as we can get to guaranteeing that we don't overflow */ |
| 1992 | EFX_BUG_ON_PARANOID(efx->type->evq_size < |
| 1993 | (efx->type->txd_ring_mask + 1 + |
| 1994 | efx->type->rxd_ring_mask + 1)); |
| 1995 | EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS); |
| 1996 | |
| 1997 | /* Higher numbered interrupt modes are less capable! */ |
| 1998 | efx->interrupt_mode = max(efx->type->max_interrupt_mode, |
| 1999 | interrupt_mode); |
| 2000 | |
Ben Hutchings | 6977dc6 | 2008-12-26 13:44:39 -0800 | [diff] [blame] | 2001 | /* Would be good to use the net_dev name, but we're too early */ |
| 2002 | snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s", |
| 2003 | pci_name(pci_dev)); |
| 2004 | efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2005 | if (!efx->workqueue) |
| 2006 | return -ENOMEM; |
Ben Hutchings | 8d9853d | 2008-07-18 19:01:20 +0100 | [diff] [blame] | 2007 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2008 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | static void efx_fini_struct(struct efx_nic *efx) |
| 2012 | { |
| 2013 | if (efx->workqueue) { |
| 2014 | destroy_workqueue(efx->workqueue); |
| 2015 | efx->workqueue = NULL; |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | /************************************************************************** |
| 2020 | * |
| 2021 | * PCI interface |
| 2022 | * |
| 2023 | **************************************************************************/ |
| 2024 | |
| 2025 | /* Main body of final NIC shutdown code |
| 2026 | * This is called only at module unload (or hotplug removal). |
| 2027 | */ |
| 2028 | static void efx_pci_remove_main(struct efx_nic *efx) |
| 2029 | { |
| 2030 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 2031 | |
| 2032 | /* Skip everything if we never obtained a valid membase */ |
| 2033 | if (!efx->membase) |
| 2034 | return; |
| 2035 | |
| 2036 | efx_fini_channels(efx); |
| 2037 | efx_fini_port(efx); |
| 2038 | |
| 2039 | /* Shutdown the board, then the NIC and board state */ |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2040 | efx->board_info.fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2041 | falcon_fini_interrupt(efx); |
| 2042 | |
| 2043 | efx_fini_napi(efx); |
| 2044 | efx_remove_all(efx); |
| 2045 | } |
| 2046 | |
| 2047 | /* Final NIC shutdown |
| 2048 | * This is called only at module unload (or hotplug removal). |
| 2049 | */ |
| 2050 | static void efx_pci_remove(struct pci_dev *pci_dev) |
| 2051 | { |
| 2052 | struct efx_nic *efx; |
| 2053 | |
| 2054 | efx = pci_get_drvdata(pci_dev); |
| 2055 | if (!efx) |
| 2056 | return; |
| 2057 | |
| 2058 | /* Mark the NIC as fini, then stop the interface */ |
| 2059 | rtnl_lock(); |
| 2060 | efx->state = STATE_FINI; |
| 2061 | dev_close(efx->net_dev); |
| 2062 | |
| 2063 | /* Allow any queued efx_resets() to complete */ |
| 2064 | rtnl_unlock(); |
| 2065 | |
| 2066 | if (efx->membase == NULL) |
| 2067 | goto out; |
| 2068 | |
| 2069 | efx_unregister_netdev(efx); |
| 2070 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2071 | efx_mtd_remove(efx); |
| 2072 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2073 | /* Wait for any scheduled resets to complete. No more will be |
| 2074 | * scheduled from this point because efx_stop_all() has been |
| 2075 | * called, we are no longer registered with driverlink, and |
| 2076 | * the net_device's have been removed. */ |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2077 | cancel_work_sync(&efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2078 | |
| 2079 | efx_pci_remove_main(efx); |
| 2080 | |
| 2081 | out: |
| 2082 | efx_fini_io(efx); |
| 2083 | EFX_LOG(efx, "shutdown successful\n"); |
| 2084 | |
| 2085 | pci_set_drvdata(pci_dev, NULL); |
| 2086 | efx_fini_struct(efx); |
| 2087 | free_netdev(efx->net_dev); |
| 2088 | }; |
| 2089 | |
| 2090 | /* Main body of NIC initialisation |
| 2091 | * This is called at module load (or hotplug insertion, theoretically). |
| 2092 | */ |
| 2093 | static int efx_pci_probe_main(struct efx_nic *efx) |
| 2094 | { |
| 2095 | int rc; |
| 2096 | |
| 2097 | /* Do start-of-day initialisation */ |
| 2098 | rc = efx_probe_all(efx); |
| 2099 | if (rc) |
| 2100 | goto fail1; |
| 2101 | |
| 2102 | rc = efx_init_napi(efx); |
| 2103 | if (rc) |
| 2104 | goto fail2; |
| 2105 | |
| 2106 | /* Initialise the board */ |
| 2107 | rc = efx->board_info.init(efx); |
| 2108 | if (rc) { |
| 2109 | EFX_ERR(efx, "failed to initialise board\n"); |
| 2110 | goto fail3; |
| 2111 | } |
| 2112 | |
| 2113 | rc = falcon_init_nic(efx); |
| 2114 | if (rc) { |
| 2115 | EFX_ERR(efx, "failed to initialise NIC\n"); |
| 2116 | goto fail4; |
| 2117 | } |
| 2118 | |
| 2119 | rc = efx_init_port(efx); |
| 2120 | if (rc) { |
| 2121 | EFX_ERR(efx, "failed to initialise port\n"); |
| 2122 | goto fail5; |
| 2123 | } |
| 2124 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 2125 | efx_init_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2126 | |
| 2127 | rc = falcon_init_interrupt(efx); |
| 2128 | if (rc) |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 2129 | goto fail6; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2130 | |
| 2131 | return 0; |
| 2132 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2133 | fail6: |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 2134 | efx_fini_channels(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2135 | efx_fini_port(efx); |
| 2136 | fail5: |
| 2137 | fail4: |
Ben Hutchings | a17102b | 2008-12-12 21:28:20 -0800 | [diff] [blame] | 2138 | efx->board_info.fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2139 | fail3: |
| 2140 | efx_fini_napi(efx); |
| 2141 | fail2: |
| 2142 | efx_remove_all(efx); |
| 2143 | fail1: |
| 2144 | return rc; |
| 2145 | } |
| 2146 | |
| 2147 | /* NIC initialisation |
| 2148 | * |
| 2149 | * This is called at module load (or hotplug insertion, |
| 2150 | * theoretically). It sets up PCI mappings, tests and resets the NIC, |
| 2151 | * sets up and registers the network devices with the kernel and hooks |
| 2152 | * the interrupt service routine. It does not prepare the device for |
| 2153 | * transmission; this is left to the first time one of the network |
| 2154 | * interfaces is brought up (i.e. efx_net_open). |
| 2155 | */ |
| 2156 | static int __devinit efx_pci_probe(struct pci_dev *pci_dev, |
| 2157 | const struct pci_device_id *entry) |
| 2158 | { |
| 2159 | struct efx_nic_type *type = (struct efx_nic_type *) entry->driver_data; |
| 2160 | struct net_device *net_dev; |
| 2161 | struct efx_nic *efx; |
| 2162 | int i, rc; |
| 2163 | |
| 2164 | /* Allocate and initialise a struct net_device and struct efx_nic */ |
| 2165 | net_dev = alloc_etherdev(sizeof(*efx)); |
| 2166 | if (!net_dev) |
| 2167 | return -ENOMEM; |
Ben Hutchings | b9b39b6 | 2008-05-07 12:51:12 +0100 | [diff] [blame] | 2168 | net_dev->features |= (NETIF_F_IP_CSUM | NETIF_F_SG | |
Ben Hutchings | 97bc541 | 2009-05-19 16:19:08 -0700 | [diff] [blame] | 2169 | NETIF_F_HIGHDMA | NETIF_F_TSO | |
| 2170 | NETIF_F_GRO); |
Ben Hutchings | 2850656 | 2008-09-01 12:46:54 +0100 | [diff] [blame] | 2171 | /* Mask for features that also apply to VLAN devices */ |
| 2172 | net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG | |
Ben Hutchings | 740847d | 2008-09-01 12:48:23 +0100 | [diff] [blame] | 2173 | NETIF_F_HIGHDMA | NETIF_F_TSO); |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2174 | efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2175 | pci_set_drvdata(pci_dev, efx); |
| 2176 | rc = efx_init_struct(efx, type, pci_dev, net_dev); |
| 2177 | if (rc) |
| 2178 | goto fail1; |
| 2179 | |
| 2180 | EFX_INFO(efx, "Solarflare Communications NIC detected\n"); |
| 2181 | |
| 2182 | /* Set up basic I/O (BAR mappings etc) */ |
| 2183 | rc = efx_init_io(efx); |
| 2184 | if (rc) |
| 2185 | goto fail2; |
| 2186 | |
| 2187 | /* No serialisation is required with the reset path because |
| 2188 | * we're in STATE_INIT. */ |
| 2189 | for (i = 0; i < 5; i++) { |
| 2190 | rc = efx_pci_probe_main(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2191 | |
| 2192 | /* Serialise against efx_reset(). No more resets will be |
| 2193 | * scheduled since efx_stop_all() has been called, and we |
| 2194 | * have not and never have been registered with either |
| 2195 | * the rtnetlink or driverlink layers. */ |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2196 | cancel_work_sync(&efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2197 | |
Steve Hodgson | fa402b2 | 2008-12-12 22:08:16 -0800 | [diff] [blame] | 2198 | if (rc == 0) { |
| 2199 | if (efx->reset_pending != RESET_TYPE_NONE) { |
| 2200 | /* If there was a scheduled reset during |
| 2201 | * probe, the NIC is probably hosed anyway */ |
| 2202 | efx_pci_remove_main(efx); |
| 2203 | rc = -EIO; |
| 2204 | } else { |
| 2205 | break; |
| 2206 | } |
| 2207 | } |
| 2208 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2209 | /* Retry if a recoverably reset event has been scheduled */ |
| 2210 | if ((efx->reset_pending != RESET_TYPE_INVISIBLE) && |
| 2211 | (efx->reset_pending != RESET_TYPE_ALL)) |
| 2212 | goto fail3; |
| 2213 | |
| 2214 | efx->reset_pending = RESET_TYPE_NONE; |
| 2215 | } |
| 2216 | |
| 2217 | if (rc) { |
| 2218 | EFX_ERR(efx, "Could not reset NIC\n"); |
| 2219 | goto fail4; |
| 2220 | } |
| 2221 | |
| 2222 | /* Switch to the running state before we expose the device to |
| 2223 | * the OS. This is to ensure that the initial gathering of |
| 2224 | * MAC stats succeeds. */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2225 | efx->state = STATE_RUNNING; |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2226 | |
| 2227 | efx_mtd_probe(efx); /* allowed to fail */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2228 | |
| 2229 | rc = efx_register_netdev(efx); |
| 2230 | if (rc) |
| 2231 | goto fail5; |
| 2232 | |
| 2233 | EFX_LOG(efx, "initialisation successful\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2234 | return 0; |
| 2235 | |
| 2236 | fail5: |
| 2237 | efx_pci_remove_main(efx); |
| 2238 | fail4: |
| 2239 | fail3: |
| 2240 | efx_fini_io(efx); |
| 2241 | fail2: |
| 2242 | efx_fini_struct(efx); |
| 2243 | fail1: |
| 2244 | EFX_LOG(efx, "initialisation failed. rc=%d\n", rc); |
| 2245 | free_netdev(net_dev); |
| 2246 | return rc; |
| 2247 | } |
| 2248 | |
| 2249 | static struct pci_driver efx_pci_driver = { |
| 2250 | .name = EFX_DRIVER_NAME, |
| 2251 | .id_table = efx_pci_table, |
| 2252 | .probe = efx_pci_probe, |
| 2253 | .remove = efx_pci_remove, |
| 2254 | }; |
| 2255 | |
| 2256 | /************************************************************************** |
| 2257 | * |
| 2258 | * Kernel module interface |
| 2259 | * |
| 2260 | *************************************************************************/ |
| 2261 | |
| 2262 | module_param(interrupt_mode, uint, 0444); |
| 2263 | MODULE_PARM_DESC(interrupt_mode, |
| 2264 | "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); |
| 2265 | |
| 2266 | static int __init efx_init_module(void) |
| 2267 | { |
| 2268 | int rc; |
| 2269 | |
| 2270 | printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n"); |
| 2271 | |
| 2272 | rc = register_netdevice_notifier(&efx_netdev_notifier); |
| 2273 | if (rc) |
| 2274 | goto err_notifier; |
| 2275 | |
| 2276 | refill_workqueue = create_workqueue("sfc_refill"); |
| 2277 | if (!refill_workqueue) { |
| 2278 | rc = -ENOMEM; |
| 2279 | goto err_refill; |
| 2280 | } |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2281 | reset_workqueue = create_singlethread_workqueue("sfc_reset"); |
| 2282 | if (!reset_workqueue) { |
| 2283 | rc = -ENOMEM; |
| 2284 | goto err_reset; |
| 2285 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2286 | |
| 2287 | rc = pci_register_driver(&efx_pci_driver); |
| 2288 | if (rc < 0) |
| 2289 | goto err_pci; |
| 2290 | |
| 2291 | return 0; |
| 2292 | |
| 2293 | err_pci: |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2294 | destroy_workqueue(reset_workqueue); |
| 2295 | err_reset: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2296 | destroy_workqueue(refill_workqueue); |
| 2297 | err_refill: |
| 2298 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 2299 | err_notifier: |
| 2300 | return rc; |
| 2301 | } |
| 2302 | |
| 2303 | static void __exit efx_exit_module(void) |
| 2304 | { |
| 2305 | printk(KERN_INFO "Solarflare NET driver unloading\n"); |
| 2306 | |
| 2307 | pci_unregister_driver(&efx_pci_driver); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2308 | destroy_workqueue(reset_workqueue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2309 | destroy_workqueue(refill_workqueue); |
| 2310 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 2311 | |
| 2312 | } |
| 2313 | |
| 2314 | module_init(efx_init_module); |
| 2315 | module_exit(efx_exit_module); |
| 2316 | |
| 2317 | MODULE_AUTHOR("Michael Brown <mbrown@fensystems.co.uk> and " |
| 2318 | "Solarflare Communications"); |
| 2319 | MODULE_DESCRIPTION("Solarflare Communications network driver"); |
| 2320 | MODULE_LICENSE("GPL"); |
| 2321 | MODULE_DEVICE_TABLE(pci, efx_pci_table); |