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