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