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. |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2005-2011 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/gfp.h> |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 24 | #include <linux/cpu_rmap.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 25 | #include "net_driver.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 26 | #include "efx.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 27 | #include "nic.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 28 | |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 29 | #include "mcdi.h" |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 30 | #include "workarounds.h" |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 31 | |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 32 | /************************************************************************** |
| 33 | * |
| 34 | * Type name strings |
| 35 | * |
| 36 | ************************************************************************** |
| 37 | */ |
| 38 | |
| 39 | /* Loopback mode names (see LOOPBACK_MODE()) */ |
| 40 | const unsigned int efx_loopback_mode_max = LOOPBACK_MAX; |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 41 | const char *const efx_loopback_mode_names[] = { |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 42 | [LOOPBACK_NONE] = "NONE", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 43 | [LOOPBACK_DATA] = "DATAPATH", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 44 | [LOOPBACK_GMAC] = "GMAC", |
| 45 | [LOOPBACK_XGMII] = "XGMII", |
| 46 | [LOOPBACK_XGXS] = "XGXS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 47 | [LOOPBACK_XAUI] = "XAUI", |
| 48 | [LOOPBACK_GMII] = "GMII", |
| 49 | [LOOPBACK_SGMII] = "SGMII", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 50 | [LOOPBACK_XGBR] = "XGBR", |
| 51 | [LOOPBACK_XFI] = "XFI", |
| 52 | [LOOPBACK_XAUI_FAR] = "XAUI_FAR", |
| 53 | [LOOPBACK_GMII_FAR] = "GMII_FAR", |
| 54 | [LOOPBACK_SGMII_FAR] = "SGMII_FAR", |
| 55 | [LOOPBACK_XFI_FAR] = "XFI_FAR", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 56 | [LOOPBACK_GPHY] = "GPHY", |
| 57 | [LOOPBACK_PHYXS] = "PHYXS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 58 | [LOOPBACK_PCS] = "PCS", |
| 59 | [LOOPBACK_PMAPMD] = "PMA/PMD", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 60 | [LOOPBACK_XPORT] = "XPORT", |
| 61 | [LOOPBACK_XGMII_WS] = "XGMII_WS", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 62 | [LOOPBACK_XAUI_WS] = "XAUI_WS", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 63 | [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR", |
| 64 | [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 65 | [LOOPBACK_GMII_WS] = "GMII_WS", |
Ben Hutchings | e58f69f | 2009-11-29 15:08:41 +0000 | [diff] [blame] | 66 | [LOOPBACK_XFI_WS] = "XFI_WS", |
| 67 | [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR", |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 68 | [LOOPBACK_PHYXS_WS] = "PHYXS_WS", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 71 | const unsigned int efx_reset_type_max = RESET_TYPE_MAX; |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 72 | const char *const efx_reset_type_names[] = { |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 73 | [RESET_TYPE_INVISIBLE] = "INVISIBLE", |
| 74 | [RESET_TYPE_ALL] = "ALL", |
| 75 | [RESET_TYPE_WORLD] = "WORLD", |
| 76 | [RESET_TYPE_DISABLE] = "DISABLE", |
| 77 | [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG", |
| 78 | [RESET_TYPE_INT_ERROR] = "INT_ERROR", |
| 79 | [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY", |
| 80 | [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH", |
| 81 | [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH", |
| 82 | [RESET_TYPE_TX_SKIP] = "TX_SKIP", |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 83 | [RESET_TYPE_MC_FAILURE] = "MC_FAILURE", |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 86 | #define EFX_MAX_MTU (9 * 1024) |
| 87 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 88 | /* Reset workqueue. If any NIC has a hardware failure then a reset will be |
| 89 | * queued onto this work queue. This is not a per-nic work queue, because |
| 90 | * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised. |
| 91 | */ |
| 92 | static struct workqueue_struct *reset_workqueue; |
| 93 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 94 | /************************************************************************** |
| 95 | * |
| 96 | * Configurable values |
| 97 | * |
| 98 | *************************************************************************/ |
| 99 | |
| 100 | /* |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 101 | * Use separate channels for TX and RX events |
| 102 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 103 | * Set this to 1 to use separate channels for TX and RX. It allows us |
| 104 | * to control interrupt affinity separately for TX and RX. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 105 | * |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 106 | * This is only used in MSI-X interrupt mode |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 107 | */ |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 108 | static unsigned int separate_tx_channels; |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 109 | module_param(separate_tx_channels, uint, 0444); |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 110 | MODULE_PARM_DESC(separate_tx_channels, |
| 111 | "Use separate channels for TX and RX"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 112 | |
| 113 | /* This is the weight assigned to each of the (per-channel) virtual |
| 114 | * NAPI devices. |
| 115 | */ |
| 116 | static int napi_weight = 64; |
| 117 | |
| 118 | /* This is the time (in jiffies) between invocations of the hardware |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 119 | * monitor. On Falcon-based NICs, this will: |
| 120 | * - Check the on-board hardware monitor; |
| 121 | * - Poll the link state and reconfigure the hardware as necessary. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 122 | */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 123 | static unsigned int efx_monitor_interval = 1 * HZ; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 124 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 125 | /* Initial interrupt moderation settings. They can be modified after |
| 126 | * module load with ethtool. |
| 127 | * |
| 128 | * The default for RX should strike a balance between increasing the |
| 129 | * round-trip latency and reducing overhead. |
| 130 | */ |
| 131 | static unsigned int rx_irq_mod_usec = 60; |
| 132 | |
| 133 | /* Initial interrupt moderation settings. They can be modified after |
| 134 | * module load with ethtool. |
| 135 | * |
| 136 | * This default is chosen to ensure that a 10G link does not go idle |
| 137 | * while a TX queue is stopped after it has become full. A queue is |
| 138 | * restarted when it drops below half full. The time this takes (assuming |
| 139 | * worst case 3 descriptors per packet and 1024 descriptors) is |
| 140 | * 512 / 3 * 1.2 = 205 usec. |
| 141 | */ |
| 142 | static unsigned int tx_irq_mod_usec = 150; |
| 143 | |
| 144 | /* This is the first interrupt mode to try out of: |
| 145 | * 0 => MSI-X |
| 146 | * 1 => MSI |
| 147 | * 2 => legacy |
| 148 | */ |
| 149 | static unsigned int interrupt_mode; |
| 150 | |
| 151 | /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), |
| 152 | * i.e. the number of CPUs among which we may distribute simultaneous |
| 153 | * interrupt handling. |
| 154 | * |
| 155 | * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. |
Ben Hutchings | cdb08f8 | 2011-12-20 01:08:05 +0000 | [diff] [blame] | 156 | * The default (0) means to assign an interrupt to each core. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 157 | */ |
| 158 | static unsigned int rss_cpus; |
| 159 | module_param(rss_cpus, uint, 0444); |
| 160 | MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); |
| 161 | |
Ben Hutchings | 84ae48f | 2008-12-12 21:34:54 -0800 | [diff] [blame] | 162 | static int phy_flash_cfg; |
| 163 | module_param(phy_flash_cfg, int, 0644); |
| 164 | MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); |
| 165 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 166 | static unsigned irq_adapt_low_thresh = 10000; |
| 167 | module_param(irq_adapt_low_thresh, uint, 0644); |
| 168 | MODULE_PARM_DESC(irq_adapt_low_thresh, |
| 169 | "Threshold score for reducing IRQ moderation"); |
| 170 | |
| 171 | static unsigned irq_adapt_high_thresh = 20000; |
| 172 | module_param(irq_adapt_high_thresh, uint, 0644); |
| 173 | MODULE_PARM_DESC(irq_adapt_high_thresh, |
| 174 | "Threshold score for increasing IRQ moderation"); |
| 175 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 176 | static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 177 | NETIF_MSG_LINK | NETIF_MSG_IFDOWN | |
| 178 | NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | |
| 179 | NETIF_MSG_TX_ERR | NETIF_MSG_HW); |
| 180 | module_param(debug, uint, 0); |
| 181 | MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); |
| 182 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 183 | /************************************************************************** |
| 184 | * |
| 185 | * Utility functions and prototypes |
| 186 | * |
| 187 | *************************************************************************/ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 188 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 189 | static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq); |
| 190 | static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq); |
| 191 | static void efx_remove_channel(struct efx_channel *channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 192 | static void efx_remove_channels(struct efx_nic *efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 193 | static const struct efx_channel_type efx_default_channel_type; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 194 | static void efx_remove_port(struct efx_nic *efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 195 | static void efx_init_napi_channel(struct efx_channel *channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 196 | static void efx_fini_napi(struct efx_nic *efx); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 197 | static void efx_fini_napi_channel(struct efx_channel *channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 198 | static void efx_fini_struct(struct efx_nic *efx); |
| 199 | static void efx_start_all(struct efx_nic *efx); |
| 200 | static void efx_stop_all(struct efx_nic *efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 201 | |
| 202 | #define EFX_ASSERT_RESET_SERIALISED(efx) \ |
| 203 | do { \ |
Ben Hutchings | 332c1ce | 2009-11-25 16:08:52 +0000 | [diff] [blame] | 204 | if ((efx->state == STATE_RUNNING) || \ |
| 205 | (efx->state == STATE_DISABLED)) \ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 206 | ASSERT_RTNL(); \ |
| 207 | } while (0) |
| 208 | |
| 209 | /************************************************************************** |
| 210 | * |
| 211 | * Event queue processing |
| 212 | * |
| 213 | *************************************************************************/ |
| 214 | |
| 215 | /* Process channel's event queue |
| 216 | * |
| 217 | * This function is responsible for processing the event queue of a |
| 218 | * single channel. The caller must guarantee that this function will |
| 219 | * never be concurrently called more than once on the same channel, |
| 220 | * though different channels may be being processed concurrently. |
| 221 | */ |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 222 | static int efx_process_channel(struct efx_channel *channel, int budget) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 223 | { |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 224 | int spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 225 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 226 | if (unlikely(!channel->enabled)) |
Ben Hutchings | 42cbe2d | 2008-09-01 12:48:08 +0100 | [diff] [blame] | 227 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 228 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 229 | spent = efx_nic_process_eventq(channel, budget); |
Ben Hutchings | d9ab700 | 2012-02-13 23:29:16 +0000 | [diff] [blame] | 230 | if (spent && efx_channel_has_rx_queue(channel)) { |
| 231 | struct efx_rx_queue *rx_queue = |
| 232 | efx_channel_get_rx_queue(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 233 | |
Ben Hutchings | d9ab700 | 2012-02-13 23:29:16 +0000 | [diff] [blame] | 234 | /* Deliver last RX packet. */ |
| 235 | if (channel->rx_pkt) { |
| 236 | __efx_rx_packet(channel, channel->rx_pkt); |
| 237 | channel->rx_pkt = NULL; |
| 238 | } |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 239 | if (rx_queue->enabled) { |
| 240 | efx_rx_strategy(channel); |
| 241 | efx_fast_push_rx_descriptors(rx_queue); |
| 242 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 245 | return spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Mark channel as finished processing |
| 249 | * |
| 250 | * Note that since we will not receive further interrupts for this |
| 251 | * channel before we finish processing and call the eventq_read_ack() |
| 252 | * method, there is no need to use the interrupt hold-off timers. |
| 253 | */ |
| 254 | static inline void efx_channel_processed(struct efx_channel *channel) |
| 255 | { |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 256 | /* The interrupt handler for this channel may set work_pending |
| 257 | * as soon as we acknowledge the events we've seen. Make sure |
| 258 | * it's cleared before then. */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 259 | channel->work_pending = false; |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 260 | smp_wmb(); |
| 261 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 262 | efx_nic_eventq_read_ack(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* NAPI poll handler |
| 266 | * |
| 267 | * NAPI guarantees serialisation of polls of the same device, which |
| 268 | * provides the guarantee required by efx_process_channel(). |
| 269 | */ |
| 270 | static int efx_poll(struct napi_struct *napi, int budget) |
| 271 | { |
| 272 | struct efx_channel *channel = |
| 273 | container_of(napi, struct efx_channel, napi_str); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 274 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 275 | int spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 276 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 277 | netif_vdbg(efx, intr, efx->net_dev, |
| 278 | "channel %d NAPI poll executing on CPU %d\n", |
| 279 | channel->channel, raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 280 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 281 | spent = efx_process_channel(channel, budget); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 282 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 283 | if (spent < budget) { |
Ben Hutchings | 9d9a697 | 2012-02-10 23:01:48 +0000 | [diff] [blame] | 284 | if (efx_channel_has_rx_queue(channel) && |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 285 | efx->irq_rx_adaptive && |
| 286 | unlikely(++channel->irq_count == 1000)) { |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 287 | if (unlikely(channel->irq_mod_score < |
| 288 | irq_adapt_low_thresh)) { |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 289 | if (channel->irq_moderation > 1) { |
| 290 | channel->irq_moderation -= 1; |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 291 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 292 | } |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 293 | } else if (unlikely(channel->irq_mod_score > |
| 294 | irq_adapt_high_thresh)) { |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 295 | if (channel->irq_moderation < |
| 296 | efx->irq_rx_moderation) { |
| 297 | channel->irq_moderation += 1; |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 298 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 299 | } |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 300 | } |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 301 | channel->irq_count = 0; |
| 302 | channel->irq_mod_score = 0; |
| 303 | } |
| 304 | |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 305 | efx_filter_rfs_expire(channel); |
| 306 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 307 | /* There is no race here; although napi_disable() will |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 308 | * only wait for napi_complete(), this isn't a problem |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 309 | * since efx_channel_processed() will have no effect if |
| 310 | * interrupts have already been disabled. |
| 311 | */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 312 | napi_complete(napi); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 313 | efx_channel_processed(channel); |
| 314 | } |
| 315 | |
Ben Hutchings | fa236e1 | 2010-04-28 09:29:42 +0000 | [diff] [blame] | 316 | return spent; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /* Process the eventq of the specified channel immediately on this CPU |
| 320 | * |
| 321 | * Disable hardware generated interrupts, wait for any existing |
| 322 | * processing to finish, then directly poll (and ack ) the eventq. |
| 323 | * Finally reenable NAPI and interrupts. |
| 324 | * |
Ben Hutchings | d4fabcc | 2011-04-04 14:22:11 +0100 | [diff] [blame] | 325 | * This is for use only during a loopback self-test. It must not |
| 326 | * deliver any packets up the stack as this can result in deadlock. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 327 | */ |
| 328 | void efx_process_channel_now(struct efx_channel *channel) |
| 329 | { |
| 330 | struct efx_nic *efx = channel->efx; |
| 331 | |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 332 | BUG_ON(channel->channel >= efx->n_channels); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 333 | BUG_ON(!channel->enabled); |
Ben Hutchings | d4fabcc | 2011-04-04 14:22:11 +0100 | [diff] [blame] | 334 | BUG_ON(!efx->loopback_selftest); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 335 | |
| 336 | /* Disable interrupts and wait for ISRs to complete */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 337 | efx_nic_disable_interrupts(efx); |
Ben Hutchings | 94dec6a | 2010-12-07 19:24:45 +0000 | [diff] [blame] | 338 | if (efx->legacy_irq) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 339 | synchronize_irq(efx->legacy_irq); |
Ben Hutchings | 94dec6a | 2010-12-07 19:24:45 +0000 | [diff] [blame] | 340 | efx->legacy_irq_enabled = false; |
| 341 | } |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 342 | if (channel->irq) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 343 | synchronize_irq(channel->irq); |
| 344 | |
| 345 | /* Wait for any NAPI processing to complete */ |
| 346 | napi_disable(&channel->napi_str); |
| 347 | |
| 348 | /* Poll the channel */ |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 349 | efx_process_channel(channel, channel->eventq_mask + 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 350 | |
| 351 | /* Ack the eventq. This may cause an interrupt to be generated |
| 352 | * when they are reenabled */ |
| 353 | efx_channel_processed(channel); |
| 354 | |
| 355 | napi_enable(&channel->napi_str); |
Ben Hutchings | 94dec6a | 2010-12-07 19:24:45 +0000 | [diff] [blame] | 356 | if (efx->legacy_irq) |
| 357 | efx->legacy_irq_enabled = true; |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 358 | efx_nic_enable_interrupts(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /* Create event queue |
| 362 | * Event queue memory allocations are done only once. If the channel |
| 363 | * is reset, the memory buffer will be reused; this guards against |
| 364 | * errors during channel reset and also simplifies interrupt handling. |
| 365 | */ |
| 366 | static int efx_probe_eventq(struct efx_channel *channel) |
| 367 | { |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 368 | struct efx_nic *efx = channel->efx; |
| 369 | unsigned long entries; |
| 370 | |
Ben Hutchings | 86ee530 | 2012-01-09 19:51:22 +0000 | [diff] [blame] | 371 | netif_dbg(efx, probe, efx->net_dev, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 372 | "chan %d create event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 373 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 374 | /* Build an event queue with room for one event per tx and rx buffer, |
| 375 | * plus some extra for link state events and MCDI completions. */ |
| 376 | entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128); |
| 377 | EFX_BUG_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE); |
| 378 | channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1; |
| 379 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 380 | return efx_nic_probe_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Prepare channel's event queue */ |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 384 | static void efx_init_eventq(struct efx_channel *channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 385 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 386 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 387 | "chan %d init event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 388 | |
| 389 | channel->eventq_read_ptr = 0; |
| 390 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 391 | efx_nic_init_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 394 | /* Enable event queue processing and NAPI */ |
| 395 | static void efx_start_eventq(struct efx_channel *channel) |
| 396 | { |
| 397 | netif_dbg(channel->efx, ifup, channel->efx->net_dev, |
| 398 | "chan %d start event queue\n", channel->channel); |
| 399 | |
| 400 | /* The interrupt handler for this channel may set work_pending |
| 401 | * as soon as we enable it. Make sure it's cleared before |
| 402 | * then. Similarly, make sure it sees the enabled flag set. |
| 403 | */ |
| 404 | channel->work_pending = false; |
| 405 | channel->enabled = true; |
| 406 | smp_wmb(); |
| 407 | |
| 408 | napi_enable(&channel->napi_str); |
| 409 | efx_nic_eventq_read_ack(channel); |
| 410 | } |
| 411 | |
| 412 | /* Disable event queue processing and NAPI */ |
| 413 | static void efx_stop_eventq(struct efx_channel *channel) |
| 414 | { |
| 415 | if (!channel->enabled) |
| 416 | return; |
| 417 | |
| 418 | napi_disable(&channel->napi_str); |
| 419 | channel->enabled = false; |
| 420 | } |
| 421 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 422 | static void efx_fini_eventq(struct efx_channel *channel) |
| 423 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 424 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 425 | "chan %d fini event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 426 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 427 | efx_nic_fini_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void efx_remove_eventq(struct efx_channel *channel) |
| 431 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 432 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 433 | "chan %d remove event queue\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 434 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 435 | efx_nic_remove_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /************************************************************************** |
| 439 | * |
| 440 | * Channel handling |
| 441 | * |
| 442 | *************************************************************************/ |
| 443 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 444 | /* Allocate and initialise a channel structure. */ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 445 | static struct efx_channel * |
| 446 | efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) |
| 447 | { |
| 448 | struct efx_channel *channel; |
| 449 | struct efx_rx_queue *rx_queue; |
| 450 | struct efx_tx_queue *tx_queue; |
| 451 | int j; |
| 452 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 453 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); |
| 454 | if (!channel) |
| 455 | return NULL; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 456 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 457 | channel->efx = efx; |
| 458 | channel->channel = i; |
| 459 | channel->type = &efx_default_channel_type; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 460 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 461 | for (j = 0; j < EFX_TXQ_TYPES; j++) { |
| 462 | tx_queue = &channel->tx_queue[j]; |
| 463 | tx_queue->efx = efx; |
| 464 | tx_queue->queue = i * EFX_TXQ_TYPES + j; |
| 465 | tx_queue->channel = channel; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 468 | rx_queue = &channel->rx_queue; |
| 469 | rx_queue->efx = efx; |
| 470 | setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, |
| 471 | (unsigned long)rx_queue); |
| 472 | |
| 473 | return channel; |
| 474 | } |
| 475 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 476 | /* Allocate and initialise a channel structure, copying parameters |
| 477 | * (but not resources) from an old channel structure. |
| 478 | */ |
| 479 | static struct efx_channel * |
| 480 | efx_copy_channel(const struct efx_channel *old_channel) |
| 481 | { |
| 482 | struct efx_channel *channel; |
| 483 | struct efx_rx_queue *rx_queue; |
| 484 | struct efx_tx_queue *tx_queue; |
| 485 | int j; |
| 486 | |
| 487 | channel = kmalloc(sizeof(*channel), GFP_KERNEL); |
| 488 | if (!channel) |
| 489 | return NULL; |
| 490 | |
| 491 | *channel = *old_channel; |
| 492 | |
| 493 | channel->napi_dev = NULL; |
| 494 | memset(&channel->eventq, 0, sizeof(channel->eventq)); |
| 495 | |
| 496 | for (j = 0; j < EFX_TXQ_TYPES; j++) { |
| 497 | tx_queue = &channel->tx_queue[j]; |
| 498 | if (tx_queue->channel) |
| 499 | tx_queue->channel = channel; |
| 500 | tx_queue->buffer = NULL; |
| 501 | memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); |
| 502 | } |
| 503 | |
| 504 | rx_queue = &channel->rx_queue; |
| 505 | rx_queue->buffer = NULL; |
| 506 | memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); |
| 507 | setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill, |
| 508 | (unsigned long)rx_queue); |
| 509 | |
| 510 | return channel; |
| 511 | } |
| 512 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 513 | static int efx_probe_channel(struct efx_channel *channel) |
| 514 | { |
| 515 | struct efx_tx_queue *tx_queue; |
| 516 | struct efx_rx_queue *rx_queue; |
| 517 | int rc; |
| 518 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 519 | netif_dbg(channel->efx, probe, channel->efx->net_dev, |
| 520 | "creating channel %d\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 521 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 522 | rc = channel->type->pre_probe(channel); |
| 523 | if (rc) |
| 524 | goto fail; |
| 525 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 526 | rc = efx_probe_eventq(channel); |
| 527 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 528 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 529 | |
| 530 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 531 | rc = efx_probe_tx_queue(tx_queue); |
| 532 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 533 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 537 | rc = efx_probe_rx_queue(rx_queue); |
| 538 | if (rc) |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 539 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | channel->n_rx_frm_trunc = 0; |
| 543 | |
| 544 | return 0; |
| 545 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 546 | fail: |
| 547 | efx_remove_channel(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 548 | return rc; |
| 549 | } |
| 550 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 551 | static void |
| 552 | efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) |
| 553 | { |
| 554 | struct efx_nic *efx = channel->efx; |
| 555 | const char *type; |
| 556 | int number; |
| 557 | |
| 558 | number = channel->channel; |
| 559 | if (efx->tx_channel_offset == 0) { |
| 560 | type = ""; |
| 561 | } else if (channel->channel < efx->tx_channel_offset) { |
| 562 | type = "-rx"; |
| 563 | } else { |
| 564 | type = "-tx"; |
| 565 | number -= efx->tx_channel_offset; |
| 566 | } |
| 567 | snprintf(buf, len, "%s%s-%d", efx->name, type, number); |
| 568 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 569 | |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 570 | static void efx_set_channel_names(struct efx_nic *efx) |
| 571 | { |
| 572 | struct efx_channel *channel; |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 573 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 574 | efx_for_each_channel(channel, efx) |
| 575 | channel->type->get_name(channel, |
| 576 | efx->channel_name[channel->channel], |
| 577 | sizeof(efx->channel_name[0])); |
Ben Hutchings | 56536e9 | 2008-12-12 21:37:02 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 580 | static int efx_probe_channels(struct efx_nic *efx) |
| 581 | { |
| 582 | struct efx_channel *channel; |
| 583 | int rc; |
| 584 | |
| 585 | /* Restart special buffer allocation */ |
| 586 | efx->next_buffer_table = 0; |
| 587 | |
| 588 | efx_for_each_channel(channel, efx) { |
| 589 | rc = efx_probe_channel(channel); |
| 590 | if (rc) { |
| 591 | netif_err(efx, probe, efx->net_dev, |
| 592 | "failed to create channel %d\n", |
| 593 | channel->channel); |
| 594 | goto fail; |
| 595 | } |
| 596 | } |
| 597 | efx_set_channel_names(efx); |
| 598 | |
| 599 | return 0; |
| 600 | |
| 601 | fail: |
| 602 | efx_remove_channels(efx); |
| 603 | return rc; |
| 604 | } |
| 605 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 606 | /* Channels are shutdown and reinitialised whilst the NIC is running |
| 607 | * to propagate configuration changes (mtu, checksum offload), or |
| 608 | * to clear hardware error conditions |
| 609 | */ |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 610 | static void efx_start_datapath(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 611 | { |
| 612 | struct efx_tx_queue *tx_queue; |
| 613 | struct efx_rx_queue *rx_queue; |
| 614 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 615 | |
Ben Hutchings | f7f13b0 | 2008-05-16 21:15:06 +0100 | [diff] [blame] | 616 | /* Calculate the rx buffer allocation parameters required to |
| 617 | * support the current MTU, including padding for header |
| 618 | * alignment and overruns. |
| 619 | */ |
| 620 | efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) + |
| 621 | EFX_MAX_FRAME_LEN(efx->net_dev->mtu) + |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 622 | efx->type->rx_buffer_hash_size + |
Ben Hutchings | f7f13b0 | 2008-05-16 21:15:06 +0100 | [diff] [blame] | 623 | efx->type->rx_buffer_padding); |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 624 | efx->rx_buffer_order = get_order(efx->rx_buffer_len + |
| 625 | sizeof(struct efx_rx_page_state)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 626 | |
| 627 | /* Initialise the channels */ |
| 628 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 629 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 630 | efx_init_tx_queue(tx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 631 | |
| 632 | /* The rx buffer allocation strategy is MTU dependent */ |
| 633 | efx_rx_strategy(channel); |
| 634 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 635 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 636 | efx_init_rx_queue(rx_queue); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 637 | efx_nic_generate_fill_event(rx_queue); |
| 638 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 639 | |
| 640 | WARN_ON(channel->rx_pkt != NULL); |
| 641 | efx_rx_strategy(channel); |
| 642 | } |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 643 | |
| 644 | if (netif_device_present(efx->net_dev)) |
| 645 | netif_tx_wake_all_queues(efx->net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 648 | static void efx_stop_datapath(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 649 | { |
| 650 | struct efx_channel *channel; |
| 651 | struct efx_tx_queue *tx_queue; |
| 652 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 653 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 654 | |
| 655 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 656 | BUG_ON(efx->port_enabled); |
| 657 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 658 | rc = efx_nic_flush_queues(efx); |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 659 | if (rc && EFX_WORKAROUND_7803(efx)) { |
| 660 | /* Schedule a reset to recover from the flush failure. The |
| 661 | * descriptor caches reference memory we're about to free, |
| 662 | * but falcon_reconfigure_mac_wrapper() won't reconnect |
| 663 | * the MACs because of the pending reset. */ |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 664 | netif_err(efx, drv, efx->net_dev, |
| 665 | "Resetting to recover from flush failure\n"); |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 666 | efx_schedule_reset(efx, RESET_TYPE_ALL); |
| 667 | } else if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 668 | netif_err(efx, drv, efx->net_dev, "failed to flush queues\n"); |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 669 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 670 | netif_dbg(efx, drv, efx->net_dev, |
| 671 | "successfully flushed all queues\n"); |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 672 | } |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 673 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 674 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 675 | /* RX packet processing is pipelined, so wait for the |
| 676 | * NAPI handler to complete. At least event queue 0 |
| 677 | * might be kept active by non-data events, so don't |
| 678 | * use napi_synchronize() but actually disable NAPI |
| 679 | * temporarily. |
| 680 | */ |
| 681 | if (efx_channel_has_rx_queue(channel)) { |
| 682 | efx_stop_eventq(channel); |
| 683 | efx_start_eventq(channel); |
| 684 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 685 | |
| 686 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 687 | efx_fini_rx_queue(rx_queue); |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 688 | efx_for_each_possible_channel_tx_queue(tx_queue, channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 689 | efx_fini_tx_queue(tx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | static void efx_remove_channel(struct efx_channel *channel) |
| 694 | { |
| 695 | struct efx_tx_queue *tx_queue; |
| 696 | struct efx_rx_queue *rx_queue; |
| 697 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 698 | netif_dbg(channel->efx, drv, channel->efx->net_dev, |
| 699 | "destroy chan %d\n", channel->channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 700 | |
| 701 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 702 | efx_remove_rx_queue(rx_queue); |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 703 | efx_for_each_possible_channel_tx_queue(tx_queue, channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 704 | efx_remove_tx_queue(tx_queue); |
| 705 | efx_remove_eventq(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 708 | static void efx_remove_channels(struct efx_nic *efx) |
| 709 | { |
| 710 | struct efx_channel *channel; |
| 711 | |
| 712 | efx_for_each_channel(channel, efx) |
| 713 | efx_remove_channel(channel); |
| 714 | } |
| 715 | |
| 716 | int |
| 717 | efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) |
| 718 | { |
| 719 | struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; |
| 720 | u32 old_rxq_entries, old_txq_entries; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 721 | unsigned i, next_buffer_table = 0; |
| 722 | int rc = 0; |
| 723 | |
| 724 | /* Not all channels should be reallocated. We must avoid |
| 725 | * reallocating their buffer table entries. |
| 726 | */ |
| 727 | efx_for_each_channel(channel, efx) { |
| 728 | struct efx_rx_queue *rx_queue; |
| 729 | struct efx_tx_queue *tx_queue; |
| 730 | |
| 731 | if (channel->type->copy) |
| 732 | continue; |
| 733 | next_buffer_table = max(next_buffer_table, |
| 734 | channel->eventq.index + |
| 735 | channel->eventq.entries); |
| 736 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 737 | next_buffer_table = max(next_buffer_table, |
| 738 | rx_queue->rxd.index + |
| 739 | rx_queue->rxd.entries); |
| 740 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 741 | next_buffer_table = max(next_buffer_table, |
| 742 | tx_queue->txd.index + |
| 743 | tx_queue->txd.entries); |
| 744 | } |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 745 | |
| 746 | efx_stop_all(efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 747 | efx_stop_interrupts(efx, true); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 748 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 749 | /* Clone channels (where possible) */ |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 750 | memset(other_channel, 0, sizeof(other_channel)); |
| 751 | for (i = 0; i < efx->n_channels; i++) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 752 | channel = efx->channel[i]; |
| 753 | if (channel->type->copy) |
| 754 | channel = channel->type->copy(channel); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 755 | if (!channel) { |
| 756 | rc = -ENOMEM; |
| 757 | goto out; |
| 758 | } |
| 759 | other_channel[i] = channel; |
| 760 | } |
| 761 | |
| 762 | /* Swap entry counts and channel pointers */ |
| 763 | old_rxq_entries = efx->rxq_entries; |
| 764 | old_txq_entries = efx->txq_entries; |
| 765 | efx->rxq_entries = rxq_entries; |
| 766 | efx->txq_entries = txq_entries; |
| 767 | for (i = 0; i < efx->n_channels; i++) { |
| 768 | channel = efx->channel[i]; |
| 769 | efx->channel[i] = other_channel[i]; |
| 770 | other_channel[i] = channel; |
| 771 | } |
| 772 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 773 | /* Restart buffer table allocation */ |
| 774 | efx->next_buffer_table = next_buffer_table; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 775 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 776 | for (i = 0; i < efx->n_channels; i++) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 777 | channel = efx->channel[i]; |
| 778 | if (!channel->type->copy) |
| 779 | continue; |
| 780 | rc = efx_probe_channel(channel); |
| 781 | if (rc) |
| 782 | goto rollback; |
| 783 | efx_init_napi_channel(efx->channel[i]); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 784 | } |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 785 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 786 | out: |
| 787 | /* Destroy unused channel structures */ |
| 788 | for (i = 0; i < efx->n_channels; i++) { |
| 789 | channel = other_channel[i]; |
| 790 | if (channel && channel->type->copy) { |
| 791 | efx_fini_napi_channel(channel); |
| 792 | efx_remove_channel(channel); |
| 793 | kfree(channel); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | efx_start_interrupts(efx, true); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 798 | efx_start_all(efx); |
| 799 | return rc; |
| 800 | |
| 801 | rollback: |
| 802 | /* Swap back */ |
| 803 | efx->rxq_entries = old_rxq_entries; |
| 804 | efx->txq_entries = old_txq_entries; |
| 805 | for (i = 0; i < efx->n_channels; i++) { |
| 806 | channel = efx->channel[i]; |
| 807 | efx->channel[i] = other_channel[i]; |
| 808 | other_channel[i] = channel; |
| 809 | } |
| 810 | goto out; |
| 811 | } |
| 812 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 813 | void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 814 | { |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 815 | mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 818 | static const struct efx_channel_type efx_default_channel_type = { |
| 819 | .pre_probe = efx_channel_dummy_op_int, |
| 820 | .get_name = efx_get_channel_name, |
| 821 | .copy = efx_copy_channel, |
| 822 | .keep_eventq = false, |
| 823 | }; |
| 824 | |
| 825 | int efx_channel_dummy_op_int(struct efx_channel *channel) |
| 826 | { |
| 827 | return 0; |
| 828 | } |
| 829 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 830 | /************************************************************************** |
| 831 | * |
| 832 | * Port handling |
| 833 | * |
| 834 | **************************************************************************/ |
| 835 | |
| 836 | /* This ensures that the kernel is kept informed (via |
| 837 | * netif_carrier_on/off) of the link status, and also maintains the |
| 838 | * link status's stop on the port's TX queue. |
| 839 | */ |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 840 | void efx_link_status_changed(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 841 | { |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 842 | struct efx_link_state *link_state = &efx->link_state; |
| 843 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 844 | /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure |
| 845 | * that no events are triggered between unregister_netdev() and the |
| 846 | * driver unloading. A more general condition is that NETDEV_CHANGE |
| 847 | * can only be generated between NETDEV_UP and NETDEV_DOWN */ |
| 848 | if (!netif_running(efx->net_dev)) |
| 849 | return; |
| 850 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 851 | if (link_state->up != netif_carrier_ok(efx->net_dev)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 852 | efx->n_link_state_changes++; |
| 853 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 854 | if (link_state->up) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 855 | netif_carrier_on(efx->net_dev); |
| 856 | else |
| 857 | netif_carrier_off(efx->net_dev); |
| 858 | } |
| 859 | |
| 860 | /* Status message for kernel log */ |
Ben Hutchings | 2aa9ef1 | 2012-01-09 19:53:41 +0000 | [diff] [blame] | 861 | if (link_state->up) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 862 | netif_info(efx, link, efx->net_dev, |
| 863 | "link up at %uMbps %s-duplex (MTU %d)%s\n", |
| 864 | link_state->speed, link_state->fd ? "full" : "half", |
| 865 | efx->net_dev->mtu, |
| 866 | (efx->promiscuous ? " [PROMISC]" : "")); |
Ben Hutchings | 2aa9ef1 | 2012-01-09 19:53:41 +0000 | [diff] [blame] | 867 | else |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 868 | netif_info(efx, link, efx->net_dev, "link down\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 871 | void efx_link_set_advertising(struct efx_nic *efx, u32 advertising) |
| 872 | { |
| 873 | efx->link_advertising = advertising; |
| 874 | if (advertising) { |
| 875 | if (advertising & ADVERTISED_Pause) |
| 876 | efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX); |
| 877 | else |
| 878 | efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX); |
| 879 | if (advertising & ADVERTISED_Asym_Pause) |
| 880 | efx->wanted_fc ^= EFX_FC_TX; |
| 881 | } |
| 882 | } |
| 883 | |
David S. Miller | b5626946 | 2011-05-17 17:53:22 -0400 | [diff] [blame] | 884 | void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc) |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 885 | { |
| 886 | efx->wanted_fc = wanted_fc; |
| 887 | if (efx->link_advertising) { |
| 888 | if (wanted_fc & EFX_FC_RX) |
| 889 | efx->link_advertising |= (ADVERTISED_Pause | |
| 890 | ADVERTISED_Asym_Pause); |
| 891 | else |
| 892 | efx->link_advertising &= ~(ADVERTISED_Pause | |
| 893 | ADVERTISED_Asym_Pause); |
| 894 | if (wanted_fc & EFX_FC_TX) |
| 895 | efx->link_advertising ^= ADVERTISED_Asym_Pause; |
| 896 | } |
| 897 | } |
| 898 | |
Ben Hutchings | 115122a | 2009-03-04 09:52:52 +0000 | [diff] [blame] | 899 | static void efx_fini_port(struct efx_nic *efx); |
| 900 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 901 | /* Push loopback/power/transmit disable settings to the PHY, and reconfigure |
| 902 | * the MAC appropriately. All other PHY configuration changes are pushed |
| 903 | * through phy_op->set_settings(), and pushed asynchronously to the MAC |
| 904 | * through efx_monitor(). |
| 905 | * |
| 906 | * Callers must hold the mac_lock |
| 907 | */ |
| 908 | int __efx_reconfigure_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 909 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 910 | enum efx_phy_mode phy_mode; |
| 911 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 912 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 913 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 914 | |
Ben Hutchings | 0fca8c9 | 2012-01-09 19:54:44 +0000 | [diff] [blame] | 915 | /* Serialise the promiscuous flag with efx_set_rx_mode. */ |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 916 | netif_addr_lock_bh(efx->net_dev); |
| 917 | netif_addr_unlock_bh(efx->net_dev); |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 918 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 919 | /* Disable PHY transmit in mac level loopbacks */ |
| 920 | phy_mode = efx->phy_mode; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 921 | if (LOOPBACK_INTERNAL(efx)) |
| 922 | efx->phy_mode |= PHY_MODE_TX_DISABLED; |
| 923 | else |
| 924 | efx->phy_mode &= ~PHY_MODE_TX_DISABLED; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 925 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 926 | rc = efx->type->reconfigure_port(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 927 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 928 | if (rc) |
| 929 | efx->phy_mode = phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 930 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 931 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | /* Reinitialise the MAC to pick up new PHY settings, even if the port is |
| 935 | * disabled. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 936 | int efx_reconfigure_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 937 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 938 | int rc; |
| 939 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 940 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 941 | |
| 942 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 943 | rc = __efx_reconfigure_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 944 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 945 | |
| 946 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 949 | /* Asynchronous work item for changing MAC promiscuity and multicast |
| 950 | * hash. Avoid a drain/rx_ingress enable by reconfiguring the current |
| 951 | * MAC directly. */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 952 | static void efx_mac_work(struct work_struct *data) |
| 953 | { |
| 954 | struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); |
| 955 | |
| 956 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 30b81cd | 2011-09-13 19:47:48 +0100 | [diff] [blame] | 957 | if (efx->port_enabled) |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 958 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 959 | mutex_unlock(&efx->mac_lock); |
| 960 | } |
| 961 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 962 | static int efx_probe_port(struct efx_nic *efx) |
| 963 | { |
| 964 | int rc; |
| 965 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 966 | netif_dbg(efx, probe, efx->net_dev, "create port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 967 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 968 | if (phy_flash_cfg) |
| 969 | efx->phy_mode = PHY_MODE_SPECIAL; |
| 970 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 971 | /* Connect up MAC/PHY operations table */ |
| 972 | rc = efx->type->probe_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 973 | if (rc) |
Ben Hutchings | e42de26 | 2010-09-10 06:41:19 +0000 | [diff] [blame] | 974 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 975 | |
Ben Hutchings | e332bcb | 2011-12-20 01:22:51 +0000 | [diff] [blame] | 976 | /* Initialise MAC address to permanent address */ |
| 977 | memcpy(efx->net_dev->dev_addr, efx->net_dev->perm_addr, ETH_ALEN); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 978 | |
| 979 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static int efx_init_port(struct efx_nic *efx) |
| 983 | { |
| 984 | int rc; |
| 985 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 986 | netif_dbg(efx, drv, efx->net_dev, "init port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 987 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 988 | mutex_lock(&efx->mac_lock); |
| 989 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 990 | rc = efx->phy_op->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 991 | if (rc) |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 992 | goto fail1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 993 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 994 | efx->port_initialized = true; |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 995 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 996 | /* Reconfigure the MAC before creating dma queues (required for |
| 997 | * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 998 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 999 | |
| 1000 | /* Ensure the PHY advertises the correct flow control settings */ |
| 1001 | rc = efx->phy_op->reconfigure(efx); |
| 1002 | if (rc) |
| 1003 | goto fail2; |
| 1004 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1005 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1006 | return 0; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1007 | |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1008 | fail2: |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1009 | efx->phy_op->fini(efx); |
Ben Hutchings | 1dfc5ce | 2009-11-25 16:11:19 +0000 | [diff] [blame] | 1010 | fail1: |
| 1011 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1012 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1015 | static void efx_start_port(struct efx_nic *efx) |
| 1016 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1017 | netif_dbg(efx, ifup, efx->net_dev, "start port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1018 | BUG_ON(efx->port_enabled); |
| 1019 | |
| 1020 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1021 | efx->port_enabled = true; |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1022 | |
| 1023 | /* efx_mac_work() might have been scheduled after efx_stop_port(), |
| 1024 | * and then cancelled by efx_flush_all() */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1025 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1026 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1027 | mutex_unlock(&efx->mac_lock); |
| 1028 | } |
| 1029 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1030 | /* Prevent efx_mac_work() and efx_monitor() from working */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1031 | static void efx_stop_port(struct efx_nic *efx) |
| 1032 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1033 | netif_dbg(efx, ifdown, efx->net_dev, "stop port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1034 | |
| 1035 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1036 | efx->port_enabled = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1037 | mutex_unlock(&efx->mac_lock); |
| 1038 | |
| 1039 | /* Serialise against efx_set_multicast_list() */ |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 1040 | netif_addr_lock_bh(efx->net_dev); |
| 1041 | netif_addr_unlock_bh(efx->net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static void efx_fini_port(struct efx_nic *efx) |
| 1045 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1046 | netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1047 | |
| 1048 | if (!efx->port_initialized) |
| 1049 | return; |
| 1050 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1051 | efx->phy_op->fini(efx); |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 1052 | efx->port_initialized = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1053 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1054 | efx->link_state.up = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1055 | efx_link_status_changed(efx); |
| 1056 | } |
| 1057 | |
| 1058 | static void efx_remove_port(struct efx_nic *efx) |
| 1059 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1060 | netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1061 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1062 | efx->type->remove_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /************************************************************************** |
| 1066 | * |
| 1067 | * NIC handling |
| 1068 | * |
| 1069 | **************************************************************************/ |
| 1070 | |
| 1071 | /* This configures the PCI device to enable I/O and DMA. */ |
| 1072 | static int efx_init_io(struct efx_nic *efx) |
| 1073 | { |
| 1074 | struct pci_dev *pci_dev = efx->pci_dev; |
| 1075 | dma_addr_t dma_mask = efx->type->max_dma_mask; |
| 1076 | int rc; |
| 1077 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1078 | netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1079 | |
| 1080 | rc = pci_enable_device(pci_dev); |
| 1081 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1082 | netif_err(efx, probe, efx->net_dev, |
| 1083 | "failed to enable PCI device\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1084 | goto fail1; |
| 1085 | } |
| 1086 | |
| 1087 | pci_set_master(pci_dev); |
| 1088 | |
| 1089 | /* Set the PCI DMA mask. Try all possibilities from our |
| 1090 | * genuine mask down to 32 bits, because some architectures |
| 1091 | * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit |
| 1092 | * masks event though they reject 46 bit masks. |
| 1093 | */ |
| 1094 | while (dma_mask > 0x7fffffffUL) { |
Ben Hutchings | e9e0184 | 2012-01-05 18:50:29 +0000 | [diff] [blame] | 1095 | if (pci_dma_supported(pci_dev, dma_mask)) { |
| 1096 | rc = pci_set_dma_mask(pci_dev, dma_mask); |
| 1097 | if (rc == 0) |
| 1098 | break; |
| 1099 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1100 | dma_mask >>= 1; |
| 1101 | } |
| 1102 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1103 | netif_err(efx, probe, efx->net_dev, |
| 1104 | "could not find a suitable DMA mask\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1105 | goto fail2; |
| 1106 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1107 | netif_dbg(efx, probe, efx->net_dev, |
| 1108 | "using DMA mask %llx\n", (unsigned long long) dma_mask); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1109 | rc = pci_set_consistent_dma_mask(pci_dev, dma_mask); |
| 1110 | if (rc) { |
| 1111 | /* pci_set_consistent_dma_mask() is not *allowed* to |
| 1112 | * fail with a mask that pci_set_dma_mask() accepted, |
| 1113 | * but just in case... |
| 1114 | */ |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1115 | netif_err(efx, probe, efx->net_dev, |
| 1116 | "failed to set consistent DMA mask\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1117 | goto fail2; |
| 1118 | } |
| 1119 | |
Ben Hutchings | dc803df | 2009-10-23 08:32:33 +0000 | [diff] [blame] | 1120 | efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR); |
| 1121 | rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1122 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1123 | netif_err(efx, probe, efx->net_dev, |
| 1124 | "request for memory BAR failed\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1125 | rc = -EIO; |
| 1126 | goto fail3; |
| 1127 | } |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 1128 | efx->membase = ioremap_nocache(efx->membase_phys, |
| 1129 | efx->type->mem_map_size); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1130 | if (!efx->membase) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1131 | netif_err(efx, probe, efx->net_dev, |
| 1132 | "could not map memory BAR at %llx+%x\n", |
| 1133 | (unsigned long long)efx->membase_phys, |
| 1134 | efx->type->mem_map_size); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1135 | rc = -ENOMEM; |
| 1136 | goto fail4; |
| 1137 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1138 | netif_dbg(efx, probe, efx->net_dev, |
| 1139 | "memory BAR at %llx+%x (virtual %p)\n", |
| 1140 | (unsigned long long)efx->membase_phys, |
| 1141 | efx->type->mem_map_size, efx->membase); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1142 | |
| 1143 | return 0; |
| 1144 | |
| 1145 | fail4: |
Ben Hutchings | dc803df | 2009-10-23 08:32:33 +0000 | [diff] [blame] | 1146 | pci_release_region(efx->pci_dev, EFX_MEM_BAR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1147 | fail3: |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 1148 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1149 | fail2: |
| 1150 | pci_disable_device(efx->pci_dev); |
| 1151 | fail1: |
| 1152 | return rc; |
| 1153 | } |
| 1154 | |
| 1155 | static void efx_fini_io(struct efx_nic *efx) |
| 1156 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1157 | netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1158 | |
| 1159 | if (efx->membase) { |
| 1160 | iounmap(efx->membase); |
| 1161 | efx->membase = NULL; |
| 1162 | } |
| 1163 | |
| 1164 | if (efx->membase_phys) { |
Ben Hutchings | dc803df | 2009-10-23 08:32:33 +0000 | [diff] [blame] | 1165 | pci_release_region(efx->pci_dev, EFX_MEM_BAR); |
Ben Hutchings | 2c118e0 | 2008-05-16 21:15:29 +0100 | [diff] [blame] | 1166 | efx->membase_phys = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | pci_disable_device(efx->pci_dev); |
| 1170 | } |
| 1171 | |
Ben Hutchings | a9a52506 | 2012-02-14 20:15:57 +0000 | [diff] [blame] | 1172 | static unsigned int efx_wanted_parallelism(struct efx_nic *efx) |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1173 | { |
Ben Hutchings | cdb08f8 | 2011-12-20 01:08:05 +0000 | [diff] [blame] | 1174 | cpumask_var_t thread_mask; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1175 | unsigned int count; |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1176 | int cpu; |
| 1177 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1178 | if (rss_cpus) { |
| 1179 | count = rss_cpus; |
| 1180 | } else { |
| 1181 | if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) { |
| 1182 | netif_warn(efx, probe, efx->net_dev, |
| 1183 | "RSS disabled due to allocation failure\n"); |
| 1184 | return 1; |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1185 | } |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1186 | |
| 1187 | count = 0; |
| 1188 | for_each_online_cpu(cpu) { |
| 1189 | if (!cpumask_test_cpu(cpu, thread_mask)) { |
| 1190 | ++count; |
| 1191 | cpumask_or(thread_mask, thread_mask, |
| 1192 | topology_thread_cpumask(cpu)); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | free_cpumask_var(thread_mask); |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1199 | /* If RSS is requested for the PF *and* VFs then we can't write RSS |
| 1200 | * table entries that are inaccessible to VFs |
| 1201 | */ |
| 1202 | if (efx_sriov_wanted(efx) && efx_vf_size(efx) > 1 && |
| 1203 | count > efx_vf_size(efx)) { |
| 1204 | netif_warn(efx, probe, efx->net_dev, |
| 1205 | "Reducing number of RSS channels from %u to %u for " |
| 1206 | "VF support. Increase vf-msix-limit to use more " |
| 1207 | "channels on the PF.\n", |
| 1208 | count, efx_vf_size(efx)); |
| 1209 | count = efx_vf_size(efx); |
| 1210 | } |
| 1211 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1212 | return count; |
| 1213 | } |
| 1214 | |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1215 | static int |
| 1216 | efx_init_rx_cpu_rmap(struct efx_nic *efx, struct msix_entry *xentries) |
| 1217 | { |
| 1218 | #ifdef CONFIG_RFS_ACCEL |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1219 | unsigned int i; |
| 1220 | int rc; |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1221 | |
| 1222 | efx->net_dev->rx_cpu_rmap = alloc_irq_cpu_rmap(efx->n_rx_channels); |
| 1223 | if (!efx->net_dev->rx_cpu_rmap) |
| 1224 | return -ENOMEM; |
| 1225 | for (i = 0; i < efx->n_rx_channels; i++) { |
| 1226 | rc = irq_cpu_rmap_add(efx->net_dev->rx_cpu_rmap, |
| 1227 | xentries[i].vector); |
| 1228 | if (rc) { |
| 1229 | free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap); |
| 1230 | efx->net_dev->rx_cpu_rmap = NULL; |
| 1231 | return rc; |
| 1232 | } |
| 1233 | } |
| 1234 | #endif |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1238 | /* Probe the number and type of interrupts we are able to obtain, and |
| 1239 | * the resulting numbers of channels and RX queues. |
| 1240 | */ |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1241 | static int efx_probe_interrupts(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1242 | { |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1243 | unsigned int max_channels = |
| 1244 | min(efx->type->phys_addr_channels, EFX_MAX_CHANNELS); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1245 | unsigned int extra_channels = 0; |
| 1246 | unsigned int i, j; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1247 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1248 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1249 | for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) |
| 1250 | if (efx->extra_channel_type[i]) |
| 1251 | ++extra_channels; |
| 1252 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1253 | if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { |
Ben Hutchings | 46123d0 | 2008-09-01 12:47:33 +0100 | [diff] [blame] | 1254 | struct msix_entry xentries[EFX_MAX_CHANNELS]; |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1255 | unsigned int n_channels; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1256 | |
Ben Hutchings | a9a52506 | 2012-02-14 20:15:57 +0000 | [diff] [blame] | 1257 | n_channels = efx_wanted_parallelism(efx); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1258 | if (separate_tx_channels) |
| 1259 | n_channels *= 2; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1260 | n_channels += extra_channels; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1261 | n_channels = min(n_channels, max_channels); |
Ben Hutchings | aa6ef27 | 2008-07-18 19:03:10 +0100 | [diff] [blame] | 1262 | |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1263 | for (i = 0; i < n_channels; i++) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1264 | xentries[i].entry = i; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1265 | rc = pci_enable_msix(efx->pci_dev, xentries, n_channels); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1266 | if (rc > 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1267 | netif_err(efx, drv, efx->net_dev, |
| 1268 | "WARNING: Insufficient MSI-X vectors" |
Ben Hutchings | a16e5b2 | 2012-02-14 00:40:12 +0000 | [diff] [blame] | 1269 | " available (%d < %u).\n", rc, n_channels); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1270 | netif_err(efx, drv, efx->net_dev, |
| 1271 | "WARNING: Performance may be reduced.\n"); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1272 | EFX_BUG_ON_PARANOID(rc >= n_channels); |
| 1273 | n_channels = rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1274 | rc = pci_enable_msix(efx->pci_dev, xentries, |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1275 | n_channels); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | if (rc == 0) { |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1279 | efx->n_channels = n_channels; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1280 | if (n_channels > extra_channels) |
| 1281 | n_channels -= extra_channels; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1282 | if (separate_tx_channels) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1283 | efx->n_tx_channels = max(n_channels / 2, 1U); |
| 1284 | efx->n_rx_channels = max(n_channels - |
| 1285 | efx->n_tx_channels, |
| 1286 | 1U); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1287 | } else { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1288 | efx->n_tx_channels = n_channels; |
| 1289 | efx->n_rx_channels = n_channels; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1290 | } |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1291 | rc = efx_init_rx_cpu_rmap(efx, xentries); |
| 1292 | if (rc) { |
| 1293 | pci_disable_msix(efx->pci_dev); |
| 1294 | return rc; |
| 1295 | } |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1296 | for (i = 0; i < efx->n_channels; i++) |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1297 | efx_get_channel(efx, i)->irq = |
| 1298 | xentries[i].vector; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1299 | } else { |
| 1300 | /* Fall back to single channel MSI */ |
| 1301 | efx->interrupt_mode = EFX_INT_MODE_MSI; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1302 | netif_err(efx, drv, efx->net_dev, |
| 1303 | "could not enable MSI-X\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | /* Try single interrupt MSI */ |
| 1308 | if (efx->interrupt_mode == EFX_INT_MODE_MSI) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 1309 | efx->n_channels = 1; |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1310 | efx->n_rx_channels = 1; |
| 1311 | efx->n_tx_channels = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1312 | rc = pci_enable_msi(efx->pci_dev); |
| 1313 | if (rc == 0) { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1314 | efx_get_channel(efx, 0)->irq = efx->pci_dev->irq; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1315 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1316 | netif_err(efx, drv, efx->net_dev, |
| 1317 | "could not enable MSI\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1318 | efx->interrupt_mode = EFX_INT_MODE_LEGACY; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | /* Assume legacy interrupts */ |
| 1323 | if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { |
Neil Turton | 28b581a | 2008-12-12 21:41:06 -0800 | [diff] [blame] | 1324 | efx->n_channels = 1 + (separate_tx_channels ? 1 : 0); |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1325 | efx->n_rx_channels = 1; |
| 1326 | efx->n_tx_channels = 1; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1327 | efx->legacy_irq = efx->pci_dev->irq; |
| 1328 | } |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1329 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1330 | /* Assign extra channels if possible */ |
| 1331 | j = efx->n_channels; |
| 1332 | for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { |
| 1333 | if (!efx->extra_channel_type[i]) |
| 1334 | continue; |
| 1335 | if (efx->interrupt_mode != EFX_INT_MODE_MSIX || |
| 1336 | efx->n_channels <= extra_channels) { |
| 1337 | efx->extra_channel_type[i]->handle_no_channel(efx); |
| 1338 | } else { |
| 1339 | --j; |
| 1340 | efx_get_channel(efx, j)->type = |
| 1341 | efx->extra_channel_type[i]; |
| 1342 | } |
| 1343 | } |
| 1344 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1345 | /* RSS might be usable on VFs even if it is disabled on the PF */ |
| 1346 | efx->rss_spread = (efx->n_rx_channels > 1 ? |
| 1347 | efx->n_rx_channels : efx_vf_size(efx)); |
| 1348 | |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1349 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1352 | /* Enable interrupts, then probe and start the event queues */ |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1353 | static void efx_start_interrupts(struct efx_nic *efx, bool may_keep_eventq) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1354 | { |
| 1355 | struct efx_channel *channel; |
| 1356 | |
| 1357 | if (efx->legacy_irq) |
| 1358 | efx->legacy_irq_enabled = true; |
| 1359 | efx_nic_enable_interrupts(efx); |
| 1360 | |
| 1361 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1362 | if (!channel->type->keep_eventq || !may_keep_eventq) |
| 1363 | efx_init_eventq(channel); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1364 | efx_start_eventq(channel); |
| 1365 | } |
| 1366 | |
| 1367 | efx_mcdi_mode_event(efx); |
| 1368 | } |
| 1369 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1370 | static void efx_stop_interrupts(struct efx_nic *efx, bool may_keep_eventq) |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1371 | { |
| 1372 | struct efx_channel *channel; |
| 1373 | |
| 1374 | efx_mcdi_mode_poll(efx); |
| 1375 | |
| 1376 | efx_nic_disable_interrupts(efx); |
| 1377 | if (efx->legacy_irq) { |
| 1378 | synchronize_irq(efx->legacy_irq); |
| 1379 | efx->legacy_irq_enabled = false; |
| 1380 | } |
| 1381 | |
| 1382 | efx_for_each_channel(channel, efx) { |
| 1383 | if (channel->irq) |
| 1384 | synchronize_irq(channel->irq); |
| 1385 | |
| 1386 | efx_stop_eventq(channel); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1387 | if (!channel->type->keep_eventq || !may_keep_eventq) |
| 1388 | efx_fini_eventq(channel); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1392 | static void efx_remove_interrupts(struct efx_nic *efx) |
| 1393 | { |
| 1394 | struct efx_channel *channel; |
| 1395 | |
| 1396 | /* Remove MSI/MSI-X interrupts */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 1397 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1398 | channel->irq = 0; |
| 1399 | pci_disable_msi(efx->pci_dev); |
| 1400 | pci_disable_msix(efx->pci_dev); |
| 1401 | |
| 1402 | /* Remove legacy interrupt */ |
| 1403 | efx->legacy_irq = 0; |
| 1404 | } |
| 1405 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 1406 | static void efx_set_channels(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1407 | { |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1408 | struct efx_channel *channel; |
| 1409 | struct efx_tx_queue *tx_queue; |
| 1410 | |
Ben Hutchings | 9765343 | 2011-01-12 18:26:56 +0000 | [diff] [blame] | 1411 | efx->tx_channel_offset = |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1412 | separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0; |
Ben Hutchings | 602a532 | 2011-05-16 17:32:39 +0100 | [diff] [blame] | 1413 | |
| 1414 | /* We need to adjust the TX queue numbers if we have separate |
| 1415 | * RX-only and TX-only channels. |
| 1416 | */ |
| 1417 | efx_for_each_channel(channel, efx) { |
| 1418 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 1419 | tx_queue->queue -= (efx->tx_channel_offset * |
| 1420 | EFX_TXQ_TYPES); |
| 1421 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | static int efx_probe_nic(struct efx_nic *efx) |
| 1425 | { |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1426 | size_t i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1427 | int rc; |
| 1428 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1429 | netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1430 | |
| 1431 | /* Carry out hardware-type specific initialisation */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1432 | rc = efx->type->probe(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1433 | if (rc) |
| 1434 | return rc; |
| 1435 | |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 1436 | /* Determine the number of channels and queues by trying to hook |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1437 | * in MSI-X interrupts. */ |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1438 | rc = efx_probe_interrupts(efx); |
| 1439 | if (rc) |
| 1440 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1441 | |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 1442 | efx->type->dimension_resources(efx); |
| 1443 | |
Ben Hutchings | 5d3a6fc | 2010-06-25 07:05:43 +0000 | [diff] [blame] | 1444 | if (efx->n_channels > 1) |
| 1445 | get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key)); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1446 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 1447 | efx->rx_indir_table[i] = |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1448 | ethtool_rxfh_indir_default(i, efx->rss_spread); |
Ben Hutchings | 5d3a6fc | 2010-06-25 07:05:43 +0000 | [diff] [blame] | 1449 | |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 1450 | efx_set_channels(efx); |
Ben Hutchings | c4f4adc | 2010-09-27 08:31:07 +0000 | [diff] [blame] | 1451 | netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels); |
| 1452 | netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1453 | |
| 1454 | /* Initialise the interrupt moderation settings */ |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1455 | efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, |
| 1456 | true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1457 | |
| 1458 | return 0; |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 1459 | |
| 1460 | fail: |
| 1461 | efx->type->remove(efx); |
| 1462 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | static void efx_remove_nic(struct efx_nic *efx) |
| 1466 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1467 | netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1468 | |
| 1469 | efx_remove_interrupts(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1470 | efx->type->remove(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /************************************************************************** |
| 1474 | * |
| 1475 | * NIC startup/shutdown |
| 1476 | * |
| 1477 | *************************************************************************/ |
| 1478 | |
| 1479 | static int efx_probe_all(struct efx_nic *efx) |
| 1480 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1481 | int rc; |
| 1482 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1483 | rc = efx_probe_nic(efx); |
| 1484 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1485 | netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1486 | goto fail1; |
| 1487 | } |
| 1488 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1489 | rc = efx_probe_port(efx); |
| 1490 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1491 | netif_err(efx, probe, efx->net_dev, "failed to create port\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1492 | goto fail2; |
| 1493 | } |
| 1494 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 1495 | efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1496 | |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1497 | rc = efx_probe_filters(efx); |
| 1498 | if (rc) { |
| 1499 | netif_err(efx, probe, efx->net_dev, |
| 1500 | "failed to create filter tables\n"); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1501 | goto fail3; |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1504 | rc = efx_probe_channels(efx); |
| 1505 | if (rc) |
| 1506 | goto fail4; |
| 1507 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1508 | return 0; |
| 1509 | |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1510 | fail4: |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1511 | efx_remove_filters(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1512 | fail3: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1513 | efx_remove_port(efx); |
| 1514 | fail2: |
| 1515 | efx_remove_nic(efx); |
| 1516 | fail1: |
| 1517 | return rc; |
| 1518 | } |
| 1519 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1520 | /* Called after previous invocation(s) of efx_stop_all, restarts the port, |
| 1521 | * kernel transmit queues and NAPI processing, and ensures that the port is |
| 1522 | * scheduled to be reconfigured. This function is safe to call multiple |
| 1523 | * times when the NIC is in any state. |
| 1524 | */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1525 | static void efx_start_all(struct efx_nic *efx) |
| 1526 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1527 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1528 | |
| 1529 | /* Check that it is appropriate to restart the interface. All |
| 1530 | * of these flags are safe to read under just the rtnl lock */ |
| 1531 | if (efx->port_enabled) |
| 1532 | return; |
| 1533 | if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT)) |
| 1534 | return; |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 1535 | if (!netif_running(efx->net_dev)) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1536 | return; |
| 1537 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1538 | efx_start_port(efx); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1539 | efx_start_datapath(efx); |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 1540 | |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 1541 | /* Start the hardware monitor if there is one. Otherwise (we're link |
| 1542 | * event driven), we have to poll the PHY because after an event queue |
| 1543 | * flush, we could have a missed a link state change */ |
| 1544 | if (efx->type->monitor != NULL) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1545 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 1546 | efx_monitor_interval); |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 1547 | } else { |
| 1548 | mutex_lock(&efx->mac_lock); |
| 1549 | if (efx->phy_op->poll(efx)) |
| 1550 | efx_link_status_changed(efx); |
| 1551 | mutex_unlock(&efx->mac_lock); |
| 1552 | } |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1553 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1554 | efx->type->start_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | /* Flush all delayed work. Should only be called when no more delayed work |
| 1558 | * will be scheduled. This doesn't flush pending online resets (efx_reset), |
| 1559 | * since we're holding the rtnl_lock at this point. */ |
| 1560 | static void efx_flush_all(struct efx_nic *efx) |
| 1561 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1562 | /* Make sure the hardware monitor is stopped */ |
| 1563 | cancel_delayed_work_sync(&efx->monitor_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1564 | /* Stop scheduled port reconfigurations */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 1565 | cancel_work_sync(&efx->mac_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /* Quiesce hardware and software without bringing the link down. |
| 1569 | * Safe to call multiple times, when the nic and interface is in any |
| 1570 | * state. The caller is guaranteed to subsequently be in a position |
| 1571 | * to modify any hardware and software state they see fit without |
| 1572 | * taking locks. */ |
| 1573 | static void efx_stop_all(struct efx_nic *efx) |
| 1574 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1575 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1576 | |
| 1577 | /* port_enabled can be read safely under the rtnl lock */ |
| 1578 | if (!efx->port_enabled) |
| 1579 | return; |
| 1580 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1581 | efx->type->stop_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1582 | efx_stop_port(efx); |
| 1583 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1584 | /* Flush efx_mac_work(), refill_workqueue, monitor_work */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1585 | efx_flush_all(efx); |
| 1586 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1587 | /* Stop the kernel transmit interface late, so the watchdog |
| 1588 | * timer isn't ticking over the flush */ |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 1589 | netif_tx_disable(efx->net_dev); |
| 1590 | |
| 1591 | efx_stop_datapath(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static void efx_remove_all(struct efx_nic *efx) |
| 1595 | { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 1596 | efx_remove_channels(efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1597 | efx_remove_filters(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1598 | efx_remove_port(efx); |
| 1599 | efx_remove_nic(efx); |
| 1600 | } |
| 1601 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1602 | /************************************************************************** |
| 1603 | * |
| 1604 | * Interrupt moderation |
| 1605 | * |
| 1606 | **************************************************************************/ |
| 1607 | |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1608 | static unsigned int irq_mod_ticks(unsigned int usecs, unsigned int quantum_ns) |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1609 | { |
Ben Hutchings | b548f97 | 2011-09-05 07:41:44 +0000 | [diff] [blame] | 1610 | if (usecs == 0) |
| 1611 | return 0; |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1612 | if (usecs * 1000 < quantum_ns) |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1613 | return 1; /* never round down to 0 */ |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1614 | return usecs * 1000 / quantum_ns; |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1617 | /* Set interrupt moderation parameters */ |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1618 | int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, |
| 1619 | unsigned int rx_usecs, bool rx_adaptive, |
| 1620 | bool rx_may_override_tx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1621 | { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1622 | struct efx_channel *channel; |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1623 | unsigned int irq_mod_max = DIV_ROUND_UP(efx->type->timer_period_max * |
| 1624 | efx->timer_quantum_ns, |
| 1625 | 1000); |
| 1626 | unsigned int tx_ticks; |
| 1627 | unsigned int rx_ticks; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1628 | |
| 1629 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1630 | |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1631 | if (tx_usecs > irq_mod_max || rx_usecs > irq_mod_max) |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1632 | return -EINVAL; |
| 1633 | |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1634 | tx_ticks = irq_mod_ticks(tx_usecs, efx->timer_quantum_ns); |
| 1635 | rx_ticks = irq_mod_ticks(rx_usecs, efx->timer_quantum_ns); |
| 1636 | |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1637 | if (tx_ticks != rx_ticks && efx->tx_channel_offset == 0 && |
| 1638 | !rx_may_override_tx) { |
| 1639 | netif_err(efx, drv, efx->net_dev, "Channels are shared. " |
| 1640 | "RX and TX IRQ moderation must be equal\n"); |
| 1641 | return -EINVAL; |
| 1642 | } |
| 1643 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 1644 | efx->irq_rx_adaptive = rx_adaptive; |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 1645 | efx->irq_rx_moderation = rx_ticks; |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1646 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 525da90 | 2011-02-07 23:04:38 +0000 | [diff] [blame] | 1647 | if (efx_channel_has_rx_queue(channel)) |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1648 | channel->irq_moderation = rx_ticks; |
Ben Hutchings | 525da90 | 2011-02-07 23:04:38 +0000 | [diff] [blame] | 1649 | else if (efx_channel_has_tx_queues(channel)) |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 1650 | channel->irq_moderation = tx_ticks; |
| 1651 | } |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 1652 | |
| 1653 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1654 | } |
| 1655 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 1656 | void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, |
| 1657 | unsigned int *rx_usecs, bool *rx_adaptive) |
| 1658 | { |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1659 | /* We must round up when converting ticks to microseconds |
| 1660 | * because we round down when converting the other way. |
| 1661 | */ |
| 1662 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 1663 | *rx_adaptive = efx->irq_rx_adaptive; |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1664 | *rx_usecs = DIV_ROUND_UP(efx->irq_rx_moderation * |
| 1665 | efx->timer_quantum_ns, |
| 1666 | 1000); |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 1667 | |
| 1668 | /* If channels are shared between RX and TX, so is IRQ |
| 1669 | * moderation. Otherwise, IRQ moderation is the same for all |
| 1670 | * TX channels and is not adaptive. |
| 1671 | */ |
| 1672 | if (efx->tx_channel_offset == 0) |
| 1673 | *tx_usecs = *rx_usecs; |
| 1674 | else |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1675 | *tx_usecs = DIV_ROUND_UP( |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 1676 | efx->channel[efx->tx_channel_offset]->irq_moderation * |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 1677 | efx->timer_quantum_ns, |
| 1678 | 1000); |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1681 | /************************************************************************** |
| 1682 | * |
| 1683 | * Hardware monitor |
| 1684 | * |
| 1685 | **************************************************************************/ |
| 1686 | |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 1687 | /* Run periodically off the general workqueue */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1688 | static void efx_monitor(struct work_struct *data) |
| 1689 | { |
| 1690 | struct efx_nic *efx = container_of(data, struct efx_nic, |
| 1691 | monitor_work.work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1692 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1693 | netif_vdbg(efx, timer, efx->net_dev, |
| 1694 | "hardware monitor executing on CPU %d\n", |
| 1695 | raw_smp_processor_id()); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1696 | BUG_ON(efx->type->monitor == NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1697 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1698 | /* If the mac_lock is already held then it is likely a port |
| 1699 | * reconfiguration is already in place, which will likely do |
Ben Hutchings | e254c27 | 2010-09-20 08:44:10 +0000 | [diff] [blame] | 1700 | * most of the work of monitor() anyway. */ |
| 1701 | if (mutex_trylock(&efx->mac_lock)) { |
| 1702 | if (efx->port_enabled) |
| 1703 | efx->type->monitor(efx); |
| 1704 | mutex_unlock(&efx->mac_lock); |
| 1705 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1706 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1707 | queue_delayed_work(efx->workqueue, &efx->monitor_work, |
| 1708 | efx_monitor_interval); |
| 1709 | } |
| 1710 | |
| 1711 | /************************************************************************** |
| 1712 | * |
| 1713 | * ioctls |
| 1714 | * |
| 1715 | *************************************************************************/ |
| 1716 | |
| 1717 | /* Net device ioctl |
| 1718 | * Context: process, rtnl_lock() held. |
| 1719 | */ |
| 1720 | static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) |
| 1721 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1722 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1723 | struct mii_ioctl_data *data = if_mii(ifr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1724 | |
| 1725 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1726 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1727 | /* Convert phy_id from older PRTAD/DEVAD format */ |
| 1728 | if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && |
| 1729 | (data->phy_id & 0xfc00) == 0x0400) |
| 1730 | data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; |
| 1731 | |
| 1732 | return mdio_mii_ioctl(&efx->mdio, data, cmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /************************************************************************** |
| 1736 | * |
| 1737 | * NAPI interface |
| 1738 | * |
| 1739 | **************************************************************************/ |
| 1740 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1741 | static void efx_init_napi_channel(struct efx_channel *channel) |
| 1742 | { |
| 1743 | struct efx_nic *efx = channel->efx; |
| 1744 | |
| 1745 | channel->napi_dev = efx->net_dev; |
| 1746 | netif_napi_add(channel->napi_dev, &channel->napi_str, |
| 1747 | efx_poll, napi_weight); |
| 1748 | } |
| 1749 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 1750 | static void efx_init_napi(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1751 | { |
| 1752 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1753 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 1754 | efx_for_each_channel(channel, efx) |
| 1755 | efx_init_napi_channel(channel); |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | static void efx_fini_napi_channel(struct efx_channel *channel) |
| 1759 | { |
| 1760 | if (channel->napi_dev) |
| 1761 | netif_napi_del(&channel->napi_str); |
| 1762 | channel->napi_dev = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | static void efx_fini_napi(struct efx_nic *efx) |
| 1766 | { |
| 1767 | struct efx_channel *channel; |
| 1768 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 1769 | efx_for_each_channel(channel, efx) |
| 1770 | efx_fini_napi_channel(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | /************************************************************************** |
| 1774 | * |
| 1775 | * Kernel netpoll interface |
| 1776 | * |
| 1777 | *************************************************************************/ |
| 1778 | |
| 1779 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1780 | |
| 1781 | /* Although in the common case interrupts will be disabled, this is not |
| 1782 | * guaranteed. However, all our work happens inside the NAPI callback, |
| 1783 | * so no locking is required. |
| 1784 | */ |
| 1785 | static void efx_netpoll(struct net_device *net_dev) |
| 1786 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1787 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1788 | struct efx_channel *channel; |
| 1789 | |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 1790 | efx_for_each_channel(channel, efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1791 | efx_schedule_channel(channel); |
| 1792 | } |
| 1793 | |
| 1794 | #endif |
| 1795 | |
| 1796 | /************************************************************************** |
| 1797 | * |
| 1798 | * Kernel net device interface |
| 1799 | * |
| 1800 | *************************************************************************/ |
| 1801 | |
| 1802 | /* Context: process, rtnl_lock() held. */ |
| 1803 | static int efx_net_open(struct net_device *net_dev) |
| 1804 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1805 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1806 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1807 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1808 | netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", |
| 1809 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1810 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1811 | if (efx->state == STATE_DISABLED) |
| 1812 | return -EIO; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 1813 | if (efx->phy_mode & PHY_MODE_SPECIAL) |
| 1814 | return -EBUSY; |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 1815 | if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) |
| 1816 | return -EIO; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 1817 | |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 1818 | /* Notify the kernel of the link state polled during driver load, |
| 1819 | * before the monitor starts running */ |
| 1820 | efx_link_status_changed(efx); |
| 1821 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1822 | efx_start_all(efx); |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
| 1826 | /* Context: process, rtnl_lock() held. |
| 1827 | * Note that the kernel will ignore our return code; this method |
| 1828 | * should really be a void. |
| 1829 | */ |
| 1830 | static int efx_net_stop(struct net_device *net_dev) |
| 1831 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1832 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1833 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1834 | netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", |
| 1835 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1836 | |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1837 | if (efx->state != STATE_DISABLED) { |
| 1838 | /* Stop the device and flush all the channels */ |
| 1839 | efx_stop_all(efx); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 1840 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1841 | |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
Ben Hutchings | 5b9e207 | 2008-05-16 21:18:14 +0100 | [diff] [blame] | 1845 | /* Context: process, dev_base_lock or RTNL held, non-blocking. */ |
Ben Hutchings | 2aa9ef1 | 2012-01-09 19:53:41 +0000 | [diff] [blame] | 1846 | static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev, |
| 1847 | struct rtnl_link_stats64 *stats) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1848 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1849 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1850 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1851 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1852 | spin_lock_bh(&efx->stats_lock); |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 1853 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1854 | efx->type->update_stats(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1855 | |
| 1856 | stats->rx_packets = mac_stats->rx_packets; |
| 1857 | stats->tx_packets = mac_stats->tx_packets; |
| 1858 | stats->rx_bytes = mac_stats->rx_bytes; |
| 1859 | stats->tx_bytes = mac_stats->tx_bytes; |
Ben Hutchings | 80485d3 | 2010-09-10 06:41:06 +0000 | [diff] [blame] | 1860 | stats->rx_dropped = efx->n_rx_nodesc_drop_cnt; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1861 | stats->multicast = mac_stats->rx_multicast; |
| 1862 | stats->collisions = mac_stats->tx_collision; |
| 1863 | stats->rx_length_errors = (mac_stats->rx_gtjumbo + |
| 1864 | mac_stats->rx_length_error); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1865 | stats->rx_crc_errors = mac_stats->rx_bad; |
| 1866 | stats->rx_frame_errors = mac_stats->rx_align_error; |
| 1867 | stats->rx_fifo_errors = mac_stats->rx_overflow; |
| 1868 | stats->rx_missed_errors = mac_stats->rx_missed; |
| 1869 | stats->tx_window_errors = mac_stats->tx_late_collision; |
| 1870 | |
| 1871 | stats->rx_errors = (stats->rx_length_errors + |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1872 | stats->rx_crc_errors + |
| 1873 | stats->rx_frame_errors + |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1874 | mac_stats->rx_symbol_error); |
| 1875 | stats->tx_errors = (stats->tx_window_errors + |
| 1876 | mac_stats->tx_bad); |
| 1877 | |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 1878 | spin_unlock_bh(&efx->stats_lock); |
| 1879 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1880 | return stats; |
| 1881 | } |
| 1882 | |
| 1883 | /* Context: netif_tx_lock held, BHs disabled. */ |
| 1884 | static void efx_watchdog(struct net_device *net_dev) |
| 1885 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1886 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1887 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1888 | netif_err(efx, tx_err, efx->net_dev, |
| 1889 | "TX stuck with port_enabled=%d: resetting channels\n", |
| 1890 | efx->port_enabled); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1891 | |
Ben Hutchings | 739bb23d | 2008-11-04 20:35:36 +0000 | [diff] [blame] | 1892 | efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | |
| 1896 | /* Context: process, rtnl_lock() held. */ |
| 1897 | static int efx_change_mtu(struct net_device *net_dev, int new_mtu) |
| 1898 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1899 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1900 | |
| 1901 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1902 | |
| 1903 | if (new_mtu > EFX_MAX_MTU) |
| 1904 | return -EINVAL; |
| 1905 | |
| 1906 | efx_stop_all(efx); |
| 1907 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1908 | netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1909 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1910 | mutex_lock(&efx->mac_lock); |
| 1911 | /* Reconfigure the MAC before enabling the dma queues so that |
| 1912 | * the RX buffers don't overflow */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1913 | net_dev->mtu = new_mtu; |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1914 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1915 | mutex_unlock(&efx->mac_lock); |
| 1916 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1917 | efx_start_all(efx); |
Ben Hutchings | 6c8eef4 | 2012-01-09 19:54:16 +0000 | [diff] [blame] | 1918 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | static int efx_set_mac_address(struct net_device *net_dev, void *data) |
| 1922 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1923 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1924 | struct sockaddr *addr = data; |
| 1925 | char *new_addr = addr->sa_data; |
| 1926 | |
| 1927 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 1928 | |
| 1929 | if (!is_valid_ether_addr(new_addr)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1930 | netif_err(efx, drv, efx->net_dev, |
| 1931 | "invalid ethernet MAC address requested: %pM\n", |
| 1932 | new_addr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1933 | return -EINVAL; |
| 1934 | } |
| 1935 | |
| 1936 | memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1937 | efx_sriov_mac_address_changed(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1938 | |
| 1939 | /* Reconfigure the MAC */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1940 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1941 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1942 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1943 | |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
Ben Hutchings | a816f75 | 2008-09-01 12:49:12 +0100 | [diff] [blame] | 1947 | /* Context: netif_addr_lock held, BHs disabled. */ |
Ben Hutchings | 0fca8c9 | 2012-01-09 19:54:44 +0000 | [diff] [blame] | 1948 | static void efx_set_rx_mode(struct net_device *net_dev) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1949 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1950 | struct efx_nic *efx = netdev_priv(net_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1951 | struct netdev_hw_addr *ha; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1952 | union efx_multicast_hash *mc_hash = &efx->multicast_hash; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1953 | u32 crc; |
| 1954 | int bit; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1955 | |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1956 | efx->promiscuous = !!(net_dev->flags & IFF_PROMISC); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1957 | |
| 1958 | /* Build multicast hash table */ |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1959 | if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1960 | memset(mc_hash, 0xff, sizeof(*mc_hash)); |
| 1961 | } else { |
| 1962 | memset(mc_hash, 0x00, sizeof(*mc_hash)); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1963 | netdev_for_each_mc_addr(ha, net_dev) { |
| 1964 | crc = ether_crc_le(ETH_ALEN, ha->addr); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1965 | bit = crc & (EFX_MCAST_HASH_ENTRIES - 1); |
| 1966 | set_bit_le(bit, mc_hash->byte); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1967 | } |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1968 | |
| 1969 | /* Broadcast packets go through the multicast hash filter. |
| 1970 | * ether_crc_le() of the broadcast address is 0xbe2612ff |
| 1971 | * so we always add bit 0xff to the mask. |
| 1972 | */ |
| 1973 | set_bit_le(0xff, mc_hash->byte); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1974 | } |
| 1975 | |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1976 | if (efx->port_enabled) |
| 1977 | queue_work(efx->workqueue, &efx->mac_work); |
| 1978 | /* Otherwise efx_start_port() will do this */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1979 | } |
| 1980 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1981 | static int efx_set_features(struct net_device *net_dev, netdev_features_t data) |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 1982 | { |
| 1983 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1984 | |
| 1985 | /* If disabling RX n-tuple filtering, clear existing filters */ |
| 1986 | if (net_dev->features & ~data & NETIF_F_NTUPLE) |
| 1987 | efx_filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); |
| 1988 | |
| 1989 | return 0; |
| 1990 | } |
| 1991 | |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 1992 | static const struct net_device_ops efx_netdev_ops = { |
| 1993 | .ndo_open = efx_net_open, |
| 1994 | .ndo_stop = efx_net_stop, |
Ben Hutchings | 4472702 | 2010-06-08 07:21:12 +0000 | [diff] [blame] | 1995 | .ndo_get_stats64 = efx_net_stats, |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 1996 | .ndo_tx_timeout = efx_watchdog, |
| 1997 | .ndo_start_xmit = efx_hard_start_xmit, |
| 1998 | .ndo_validate_addr = eth_validate_addr, |
| 1999 | .ndo_do_ioctl = efx_ioctl, |
| 2000 | .ndo_change_mtu = efx_change_mtu, |
| 2001 | .ndo_set_mac_address = efx_set_mac_address, |
Ben Hutchings | 0fca8c9 | 2012-01-09 19:54:44 +0000 | [diff] [blame] | 2002 | .ndo_set_rx_mode = efx_set_rx_mode, |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2003 | .ndo_set_features = efx_set_features, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2004 | #ifdef CONFIG_SFC_SRIOV |
| 2005 | .ndo_set_vf_mac = efx_sriov_set_vf_mac, |
| 2006 | .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, |
| 2007 | .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, |
| 2008 | .ndo_get_vf_config = efx_sriov_get_vf_config, |
| 2009 | #endif |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2010 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2011 | .ndo_poll_controller = efx_netpoll, |
| 2012 | #endif |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 2013 | .ndo_setup_tc = efx_setup_tc, |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 2014 | #ifdef CONFIG_RFS_ACCEL |
| 2015 | .ndo_rx_flow_steer = efx_filter_rfs, |
| 2016 | #endif |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2017 | }; |
| 2018 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2019 | static void efx_update_name(struct efx_nic *efx) |
| 2020 | { |
| 2021 | strcpy(efx->name, efx->net_dev->name); |
| 2022 | efx_mtd_rename(efx); |
| 2023 | efx_set_channel_names(efx); |
| 2024 | } |
| 2025 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2026 | static int efx_netdev_event(struct notifier_block *this, |
| 2027 | unsigned long event, void *ptr) |
| 2028 | { |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 2029 | struct net_device *net_dev = ptr; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2030 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2031 | if (net_dev->netdev_ops == &efx_netdev_ops && |
| 2032 | event == NETDEV_CHANGENAME) |
| 2033 | efx_update_name(netdev_priv(net_dev)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2034 | |
| 2035 | return NOTIFY_DONE; |
| 2036 | } |
| 2037 | |
| 2038 | static struct notifier_block efx_netdev_notifier = { |
| 2039 | .notifier_call = efx_netdev_event, |
| 2040 | }; |
| 2041 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2042 | static ssize_t |
| 2043 | show_phy_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 2044 | { |
| 2045 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2046 | return sprintf(buf, "%d\n", efx->phy_type); |
| 2047 | } |
| 2048 | static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL); |
| 2049 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2050 | static int efx_register_netdev(struct efx_nic *efx) |
| 2051 | { |
| 2052 | struct net_device *net_dev = efx->net_dev; |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2053 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2054 | int rc; |
| 2055 | |
| 2056 | net_dev->watchdog_timeo = 5 * HZ; |
| 2057 | net_dev->irq = efx->pci_dev->irq; |
Stephen Hemminger | c3ecb9f | 2008-11-21 17:32:54 -0800 | [diff] [blame] | 2058 | net_dev->netdev_ops = &efx_netdev_ops; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2059 | SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops); |
| 2060 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2061 | rtnl_lock(); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2062 | |
| 2063 | rc = dev_alloc_name(net_dev, net_dev->name); |
| 2064 | if (rc < 0) |
| 2065 | goto fail_locked; |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2066 | efx_update_name(efx); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2067 | |
| 2068 | rc = register_netdevice(net_dev); |
| 2069 | if (rc) |
| 2070 | goto fail_locked; |
| 2071 | |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2072 | efx_for_each_channel(channel, efx) { |
| 2073 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | 60031fc | 2011-01-12 18:39:40 +0000 | [diff] [blame] | 2074 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 2075 | efx_init_tx_queue_core_txq(tx_queue); |
Ben Hutchings | c04bfc6 | 2010-12-10 01:24:16 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2078 | /* Always start with carrier off; PHY events will detect the link */ |
Ben Hutchings | 86ee530 | 2012-01-09 19:51:22 +0000 | [diff] [blame] | 2079 | netif_carrier_off(net_dev); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2080 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2081 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2082 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2083 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 2084 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2085 | netif_err(efx, drv, efx->net_dev, |
| 2086 | "failed to init net dev attributes\n"); |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2087 | goto fail_registered; |
| 2088 | } |
| 2089 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2090 | return 0; |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2091 | |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2092 | fail_locked: |
| 2093 | rtnl_unlock(); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2094 | netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); |
Ben Hutchings | aed0628 | 2009-08-26 08:16:27 +0000 | [diff] [blame] | 2095 | return rc; |
| 2096 | |
Ben Hutchings | 06d5e19 | 2008-12-12 21:47:23 -0800 | [diff] [blame] | 2097 | fail_registered: |
| 2098 | unregister_netdev(net_dev); |
| 2099 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | static void efx_unregister_netdev(struct efx_nic *efx) |
| 2103 | { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 2104 | struct efx_channel *channel; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2105 | struct efx_tx_queue *tx_queue; |
| 2106 | |
| 2107 | if (!efx->net_dev) |
| 2108 | return; |
| 2109 | |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2110 | BUG_ON(netdev_priv(efx->net_dev) != efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2111 | |
| 2112 | /* Free up any skbs still remaining. This has to happen before |
| 2113 | * we try to unregister the netdev as running their destructors |
| 2114 | * may be needed to get the device ref. count to 0. */ |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 2115 | efx_for_each_channel(channel, efx) { |
| 2116 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 2117 | efx_release_tx_buffers(tx_queue); |
| 2118 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2119 | |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 2120 | strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); |
| 2121 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
| 2122 | unregister_netdev(efx->net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /************************************************************************** |
| 2126 | * |
| 2127 | * Device reset and suspend |
| 2128 | * |
| 2129 | **************************************************************************/ |
| 2130 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2131 | /* Tears down the entire software state and most of the hardware state |
| 2132 | * before reset. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2133 | void efx_reset_down(struct efx_nic *efx, enum reset_type method) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2134 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2135 | EFX_ASSERT_RESET_SERIALISED(efx); |
| 2136 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2137 | efx_stop_all(efx); |
| 2138 | mutex_lock(&efx->mac_lock); |
| 2139 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2140 | efx_stop_interrupts(efx, false); |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 2141 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) |
| 2142 | efx->phy_op->fini(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2143 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2144 | } |
| 2145 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2146 | /* This function will always ensure that the locks acquired in |
| 2147 | * efx_reset_down() are released. A failure return code indicates |
| 2148 | * that we were unable to reinitialise the hardware, and the |
| 2149 | * driver should be disabled. If ok is false, then the rx and tx |
| 2150 | * engines are not restarted, pending a RESET_DISABLE. */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2151 | int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2152 | { |
| 2153 | int rc; |
| 2154 | |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2155 | EFX_ASSERT_RESET_SERIALISED(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2156 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2157 | rc = efx->type->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2158 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2159 | netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n"); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2160 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2161 | } |
| 2162 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2163 | if (!ok) |
| 2164 | goto fail; |
| 2165 | |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 2166 | if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2167 | rc = efx->phy_op->init(efx); |
| 2168 | if (rc) |
| 2169 | goto fail; |
| 2170 | if (efx->phy_op->reconfigure(efx)) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2171 | netif_err(efx, drv, efx->net_dev, |
| 2172 | "could not restore PHY settings\n"); |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2175 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2176 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2177 | efx_start_interrupts(efx, false); |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 2178 | efx_restore_filters(efx); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2179 | efx_sriov_reset(efx); |
Ben Hutchings | 2467ca4 | 2008-09-01 12:48:50 +0100 | [diff] [blame] | 2180 | |
| 2181 | mutex_unlock(&efx->mac_lock); |
| 2182 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2183 | efx_start_all(efx); |
| 2184 | |
| 2185 | return 0; |
| 2186 | |
| 2187 | fail: |
| 2188 | efx->port_initialized = false; |
| 2189 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2190 | mutex_unlock(&efx->mac_lock); |
| 2191 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2192 | return rc; |
| 2193 | } |
| 2194 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2195 | /* Reset the NIC using the specified method. Note that the reset may |
| 2196 | * fail, in which case the card will be left in an unusable state. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2197 | * |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2198 | * Caller must hold the rtnl_lock. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2199 | */ |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2200 | int efx_reset(struct efx_nic *efx, enum reset_type method) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2201 | { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2202 | int rc, rc2; |
| 2203 | bool disabled; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2204 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2205 | netif_info(efx, drv, efx->net_dev, "resetting (%s)\n", |
| 2206 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2207 | |
Ben Hutchings | e4abce8 | 2011-05-16 18:51:24 +0100 | [diff] [blame] | 2208 | netif_device_detach(efx->net_dev); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2209 | efx_reset_down(efx, method); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2210 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2211 | rc = efx->type->reset(efx, method); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2212 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2213 | netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n"); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2214 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2215 | } |
| 2216 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2217 | /* Clear flags for the scopes we covered. We assume the NIC and |
| 2218 | * driver are now quiescent so that there is no race here. |
| 2219 | */ |
| 2220 | efx->reset_pending &= -(1 << (method + 1)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2221 | |
| 2222 | /* Reinitialise bus-mastering, which may have been turned off before |
| 2223 | * the reset was scheduled. This is still appropriate, even in the |
| 2224 | * RESET_TYPE_DISABLE since this driver generally assumes the hardware |
| 2225 | * can respond to requests. */ |
| 2226 | pci_set_master(efx->pci_dev); |
| 2227 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2228 | out: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2229 | /* Leave device stopped if necessary */ |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2230 | disabled = rc || method == RESET_TYPE_DISABLE; |
| 2231 | rc2 = efx_reset_up(efx, method, !disabled); |
| 2232 | if (rc2) { |
| 2233 | disabled = true; |
| 2234 | if (!rc) |
| 2235 | rc = rc2; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2238 | if (disabled) { |
Ben Hutchings | f49a458 | 2010-04-28 09:01:33 +0000 | [diff] [blame] | 2239 | dev_close(efx->net_dev); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2240 | netif_err(efx, drv, efx->net_dev, "has been disabled\n"); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2241 | efx->state = STATE_DISABLED; |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2242 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2243 | netif_dbg(efx, drv, efx->net_dev, "reset complete\n"); |
Ben Hutchings | e4abce8 | 2011-05-16 18:51:24 +0100 | [diff] [blame] | 2244 | netif_device_attach(efx->net_dev); |
Ben Hutchings | f4bd954 | 2008-12-26 13:48:51 -0800 | [diff] [blame] | 2245 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2246 | return rc; |
| 2247 | } |
| 2248 | |
| 2249 | /* The worker thread exists so that code that cannot sleep can |
| 2250 | * schedule a reset for later. |
| 2251 | */ |
| 2252 | static void efx_reset_work(struct work_struct *data) |
| 2253 | { |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2254 | struct efx_nic *efx = container_of(data, struct efx_nic, reset_work); |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2255 | unsigned long pending = ACCESS_ONCE(efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2256 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2257 | if (!pending) |
Steve Hodgson | 319ba64 | 2010-06-01 11:17:24 +0000 | [diff] [blame] | 2258 | return; |
| 2259 | |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2260 | /* If we're not RUNNING then don't reset. Leave the reset_pending |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2261 | * flags set so that efx_pci_probe_main will be retried */ |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2262 | if (efx->state != STATE_RUNNING) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2263 | netif_info(efx, drv, efx->net_dev, |
| 2264 | "scheduled reset quenched. NIC not RUNNING\n"); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2265 | return; |
| 2266 | } |
| 2267 | |
| 2268 | rtnl_lock(); |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2269 | (void)efx_reset(efx, fls(pending) - 1); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 2270 | rtnl_unlock(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) |
| 2274 | { |
| 2275 | enum reset_type method; |
| 2276 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2277 | switch (type) { |
| 2278 | case RESET_TYPE_INVISIBLE: |
| 2279 | case RESET_TYPE_ALL: |
| 2280 | case RESET_TYPE_WORLD: |
| 2281 | case RESET_TYPE_DISABLE: |
| 2282 | method = type; |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2283 | netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n", |
| 2284 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2285 | break; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2286 | default: |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2287 | method = efx->type->map_reset_reason(type); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2288 | netif_dbg(efx, drv, efx->net_dev, |
| 2289 | "scheduling %s reset for %s\n", |
| 2290 | RESET_TYPE(method), RESET_TYPE(type)); |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2291 | break; |
| 2292 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2293 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2294 | set_bit(method, &efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2295 | |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2296 | /* efx_process_channel() will no longer read events once a |
| 2297 | * reset is scheduled. So switch back to poll'd MCDI completions. */ |
| 2298 | efx_mcdi_mode_poll(efx); |
| 2299 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2300 | queue_work(reset_workqueue, &efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /************************************************************************** |
| 2304 | * |
| 2305 | * List of NICs we support |
| 2306 | * |
| 2307 | **************************************************************************/ |
| 2308 | |
| 2309 | /* PCI device ID table */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 2310 | static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = { |
Linus Torvalds | 0e59e7e7 | 2011-10-28 14:20:44 -0700 | [diff] [blame] | 2311 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, |
| 2312 | PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0), |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2313 | .driver_data = (unsigned long) &falcon_a1_nic_type}, |
Linus Torvalds | 0e59e7e7 | 2011-10-28 14:20:44 -0700 | [diff] [blame] | 2314 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, |
| 2315 | PCI_DEVICE_ID_SOLARFLARE_SFC4000B), |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2316 | .driver_data = (unsigned long) &falcon_b0_nic_type}, |
Ben Hutchings | 547c474 | 2011-12-02 18:23:56 +0000 | [diff] [blame] | 2317 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */ |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2318 | .driver_data = (unsigned long) &siena_a0_nic_type}, |
Ben Hutchings | 547c474 | 2011-12-02 18:23:56 +0000 | [diff] [blame] | 2319 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */ |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 2320 | .driver_data = (unsigned long) &siena_a0_nic_type}, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2321 | {0} /* end of list */ |
| 2322 | }; |
| 2323 | |
| 2324 | /************************************************************************** |
| 2325 | * |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 2326 | * Dummy PHY/MAC operations |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2327 | * |
Ben Hutchings | 01aad7b | 2008-09-01 12:48:36 +0100 | [diff] [blame] | 2328 | * Can be used for some unimplemented operations |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2329 | * Needed so all function pointers are valid and do not have to be tested |
| 2330 | * before use |
| 2331 | * |
| 2332 | **************************************************************************/ |
| 2333 | int efx_port_dummy_op_int(struct efx_nic *efx) |
| 2334 | { |
| 2335 | return 0; |
| 2336 | } |
| 2337 | void efx_port_dummy_op_void(struct efx_nic *efx) {} |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 2338 | |
| 2339 | static bool efx_port_dummy_op_poll(struct efx_nic *efx) |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 2340 | { |
| 2341 | return false; |
| 2342 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2343 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2344 | static const struct efx_phy_operations efx_dummy_phy_operations = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2345 | .init = efx_port_dummy_op_int, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2346 | .reconfigure = efx_port_dummy_op_int, |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 2347 | .poll = efx_port_dummy_op_poll, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2348 | .fini = efx_port_dummy_op_void, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2349 | }; |
| 2350 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2351 | /************************************************************************** |
| 2352 | * |
| 2353 | * Data housekeeping |
| 2354 | * |
| 2355 | **************************************************************************/ |
| 2356 | |
| 2357 | /* This zeroes out and then fills in the invariants in a struct |
| 2358 | * efx_nic (including all sub-structures). |
| 2359 | */ |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2360 | static int efx_init_struct(struct efx_nic *efx, const struct efx_nic_type *type, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2361 | struct pci_dev *pci_dev, struct net_device *net_dev) |
| 2362 | { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 2363 | int i; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2364 | |
| 2365 | /* Initialise common structures */ |
| 2366 | memset(efx, 0, sizeof(*efx)); |
| 2367 | spin_lock_init(&efx->biu_lock); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 2368 | #ifdef CONFIG_SFC_MTD |
| 2369 | INIT_LIST_HEAD(&efx->mtd_list); |
| 2370 | #endif |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2371 | INIT_WORK(&efx->reset_work, efx_reset_work); |
| 2372 | INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); |
| 2373 | efx->pci_dev = pci_dev; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2374 | efx->msg_enable = debug; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2375 | efx->state = STATE_INIT; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2376 | strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2377 | |
| 2378 | efx->net_dev = net_dev; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2379 | spin_lock_init(&efx->stats_lock); |
| 2380 | mutex_init(&efx->mac_lock); |
| 2381 | efx->phy_op = &efx_dummy_phy_operations; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 2382 | efx->mdio.dev = net_dev; |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 2383 | INIT_WORK(&efx->mac_work, efx_mac_work); |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 2384 | init_waitqueue_head(&efx->flush_wq); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2385 | |
| 2386 | for (i = 0; i < EFX_MAX_CHANNELS; i++) { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 2387 | efx->channel[i] = efx_alloc_channel(efx, i, NULL); |
| 2388 | if (!efx->channel[i]) |
| 2389 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | efx->type = type; |
| 2393 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2394 | EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS); |
| 2395 | |
| 2396 | /* Higher numbered interrupt modes are less capable! */ |
| 2397 | efx->interrupt_mode = max(efx->type->max_interrupt_mode, |
| 2398 | interrupt_mode); |
| 2399 | |
Ben Hutchings | 6977dc6 | 2008-12-26 13:44:39 -0800 | [diff] [blame] | 2400 | /* Would be good to use the net_dev name, but we're too early */ |
| 2401 | snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s", |
| 2402 | pci_name(pci_dev)); |
| 2403 | efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2404 | if (!efx->workqueue) |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 2405 | goto fail; |
Ben Hutchings | 8d9853d | 2008-07-18 19:01:20 +0100 | [diff] [blame] | 2406 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2407 | return 0; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 2408 | |
| 2409 | fail: |
| 2410 | efx_fini_struct(efx); |
| 2411 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | static void efx_fini_struct(struct efx_nic *efx) |
| 2415 | { |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 2416 | int i; |
| 2417 | |
| 2418 | for (i = 0; i < EFX_MAX_CHANNELS; i++) |
| 2419 | kfree(efx->channel[i]); |
| 2420 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2421 | if (efx->workqueue) { |
| 2422 | destroy_workqueue(efx->workqueue); |
| 2423 | efx->workqueue = NULL; |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | /************************************************************************** |
| 2428 | * |
| 2429 | * PCI interface |
| 2430 | * |
| 2431 | **************************************************************************/ |
| 2432 | |
| 2433 | /* Main body of final NIC shutdown code |
| 2434 | * This is called only at module unload (or hotplug removal). |
| 2435 | */ |
| 2436 | static void efx_pci_remove_main(struct efx_nic *efx) |
| 2437 | { |
Ben Hutchings | 64d8ad6 | 2011-01-05 00:50:41 +0000 | [diff] [blame] | 2438 | #ifdef CONFIG_RFS_ACCEL |
| 2439 | free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap); |
| 2440 | efx->net_dev->rx_cpu_rmap = NULL; |
| 2441 | #endif |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2442 | efx_stop_interrupts(efx, false); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2443 | efx_nic_fini_interrupt(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2444 | efx_fini_port(efx); |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2445 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2446 | efx_fini_napi(efx); |
| 2447 | efx_remove_all(efx); |
| 2448 | } |
| 2449 | |
| 2450 | /* Final NIC shutdown |
| 2451 | * This is called only at module unload (or hotplug removal). |
| 2452 | */ |
| 2453 | static void efx_pci_remove(struct pci_dev *pci_dev) |
| 2454 | { |
| 2455 | struct efx_nic *efx; |
| 2456 | |
| 2457 | efx = pci_get_drvdata(pci_dev); |
| 2458 | if (!efx) |
| 2459 | return; |
| 2460 | |
| 2461 | /* Mark the NIC as fini, then stop the interface */ |
| 2462 | rtnl_lock(); |
| 2463 | efx->state = STATE_FINI; |
| 2464 | dev_close(efx->net_dev); |
| 2465 | |
| 2466 | /* Allow any queued efx_resets() to complete */ |
| 2467 | rtnl_unlock(); |
| 2468 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2469 | efx_stop_interrupts(efx, false); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2470 | efx_sriov_fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2471 | efx_unregister_netdev(efx); |
| 2472 | |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2473 | efx_mtd_remove(efx); |
| 2474 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2475 | /* Wait for any scheduled resets to complete. No more will be |
| 2476 | * scheduled from this point because efx_stop_all() has been |
| 2477 | * called, we are no longer registered with driverlink, and |
| 2478 | * the net_device's have been removed. */ |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2479 | cancel_work_sync(&efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2480 | |
| 2481 | efx_pci_remove_main(efx); |
| 2482 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2483 | efx_fini_io(efx); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2484 | netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2485 | |
| 2486 | pci_set_drvdata(pci_dev, NULL); |
| 2487 | efx_fini_struct(efx); |
| 2488 | free_netdev(efx->net_dev); |
| 2489 | }; |
| 2490 | |
| 2491 | /* Main body of NIC initialisation |
| 2492 | * This is called at module load (or hotplug insertion, theoretically). |
| 2493 | */ |
| 2494 | static int efx_pci_probe_main(struct efx_nic *efx) |
| 2495 | { |
| 2496 | int rc; |
| 2497 | |
| 2498 | /* Do start-of-day initialisation */ |
| 2499 | rc = efx_probe_all(efx); |
| 2500 | if (rc) |
| 2501 | goto fail1; |
| 2502 | |
Ben Hutchings | e8f1499 | 2010-12-07 19:47:34 +0000 | [diff] [blame] | 2503 | efx_init_napi(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2504 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2505 | rc = efx->type->init(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2506 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2507 | netif_err(efx, probe, efx->net_dev, |
| 2508 | "failed to initialise NIC\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2509 | goto fail3; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | rc = efx_init_port(efx); |
| 2513 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2514 | netif_err(efx, probe, efx->net_dev, |
| 2515 | "failed to initialise port\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2516 | goto fail4; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2517 | } |
| 2518 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2519 | rc = efx_nic_init_interrupt(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2520 | if (rc) |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2521 | goto fail5; |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2522 | efx_start_interrupts(efx, false); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2523 | |
| 2524 | return 0; |
| 2525 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2526 | fail5: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2527 | efx_fini_port(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2528 | fail4: |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2529 | efx->type->fini(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2530 | fail3: |
| 2531 | efx_fini_napi(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2532 | efx_remove_all(efx); |
| 2533 | fail1: |
| 2534 | return rc; |
| 2535 | } |
| 2536 | |
| 2537 | /* NIC initialisation |
| 2538 | * |
| 2539 | * This is called at module load (or hotplug insertion, |
Ben Hutchings | 73ba7b6 | 2012-01-09 19:47:08 +0000 | [diff] [blame] | 2540 | * theoretically). It sets up PCI mappings, resets the NIC, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2541 | * sets up and registers the network devices with the kernel and hooks |
| 2542 | * the interrupt service routine. It does not prepare the device for |
| 2543 | * transmission; this is left to the first time one of the network |
| 2544 | * interfaces is brought up (i.e. efx_net_open). |
| 2545 | */ |
| 2546 | static int __devinit efx_pci_probe(struct pci_dev *pci_dev, |
| 2547 | const struct pci_device_id *entry) |
| 2548 | { |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2549 | const struct efx_nic_type *type = (const struct efx_nic_type *) entry->driver_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2550 | struct net_device *net_dev; |
| 2551 | struct efx_nic *efx; |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2552 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2553 | |
| 2554 | /* Allocate and initialise a struct net_device and struct efx_nic */ |
Ben Hutchings | 94b274b | 2011-01-10 21:18:20 +0000 | [diff] [blame] | 2555 | net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES, |
| 2556 | EFX_MAX_RX_QUEUES); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2557 | if (!net_dev) |
| 2558 | return -ENOMEM; |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 2559 | net_dev->features |= (type->offload_features | NETIF_F_SG | |
Ben Hutchings | 97bc541 | 2009-05-19 16:19:08 -0700 | [diff] [blame] | 2560 | NETIF_F_HIGHDMA | NETIF_F_TSO | |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2561 | NETIF_F_RXCSUM); |
Ben Hutchings | 738a8f4 | 2009-11-29 15:16:05 +0000 | [diff] [blame] | 2562 | if (type->offload_features & NETIF_F_V6_CSUM) |
| 2563 | net_dev->features |= NETIF_F_TSO6; |
Ben Hutchings | 28506563 | 2008-09-01 12:46:54 +0100 | [diff] [blame] | 2564 | /* Mask for features that also apply to VLAN devices */ |
| 2565 | net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG | |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 2566 | NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | |
| 2567 | NETIF_F_RXCSUM); |
| 2568 | /* All offloads can be toggled */ |
| 2569 | net_dev->hw_features = net_dev->features & ~NETIF_F_HIGHDMA; |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 2570 | efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2571 | pci_set_drvdata(pci_dev, efx); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2572 | SET_NETDEV_DEV(net_dev, &pci_dev->dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2573 | rc = efx_init_struct(efx, type, pci_dev, net_dev); |
| 2574 | if (rc) |
| 2575 | goto fail1; |
| 2576 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2577 | netif_info(efx, probe, efx->net_dev, |
Ben Hutchings | ff79c8a | 2011-07-13 16:21:24 +0100 | [diff] [blame] | 2578 | "Solarflare NIC detected\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2579 | |
| 2580 | /* Set up basic I/O (BAR mappings etc) */ |
| 2581 | rc = efx_init_io(efx); |
| 2582 | if (rc) |
| 2583 | goto fail2; |
| 2584 | |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2585 | rc = efx_pci_probe_main(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2586 | |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2587 | /* Serialise against efx_reset(). No more resets will be |
| 2588 | * scheduled since efx_stop_all() has been called, and we have |
| 2589 | * not and never have been registered. |
| 2590 | */ |
| 2591 | cancel_work_sync(&efx->reset_work); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2592 | |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2593 | if (rc) |
| 2594 | goto fail3; |
Steve Hodgson | fa402b2 | 2008-12-12 22:08:16 -0800 | [diff] [blame] | 2595 | |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2596 | /* If there was a scheduled reset during probe, the NIC is |
| 2597 | * probably hosed anyway. |
| 2598 | */ |
| 2599 | if (efx->reset_pending) { |
| 2600 | rc = -EIO; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2601 | goto fail4; |
| 2602 | } |
| 2603 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2604 | /* Switch to the running state before we expose the device to the OS, |
| 2605 | * so that dev_open()|efx_start_all() will actually start the device */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2606 | efx->state = STATE_RUNNING; |
Ben Hutchings | 7dde596 | 2008-12-12 22:09:38 -0800 | [diff] [blame] | 2607 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2608 | rc = efx_register_netdev(efx); |
| 2609 | if (rc) |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2610 | goto fail4; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2611 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2612 | rc = efx_sriov_init(efx); |
| 2613 | if (rc) |
| 2614 | netif_err(efx, probe, efx->net_dev, |
| 2615 | "SR-IOV can't be enabled rc %d\n", rc); |
| 2616 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2617 | netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 2618 | |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 2619 | /* Try to create MTDs, but allow this to fail */ |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 2620 | rtnl_lock(); |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 2621 | rc = efx_mtd_probe(efx); |
Ben Hutchings | a5211bb | 2009-10-23 08:33:09 +0000 | [diff] [blame] | 2622 | rtnl_unlock(); |
Ben Hutchings | 7c43161 | 2012-01-27 17:23:58 +0000 | [diff] [blame] | 2623 | if (rc) |
| 2624 | netif_warn(efx, probe, efx->net_dev, |
| 2625 | "failed to create MTDs (%d)\n", rc); |
| 2626 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2627 | return 0; |
| 2628 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2629 | fail4: |
Ben Hutchings | fadac6a | 2011-11-19 00:35:47 +0000 | [diff] [blame] | 2630 | efx_pci_remove_main(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2631 | fail3: |
| 2632 | efx_fini_io(efx); |
| 2633 | fail2: |
| 2634 | efx_fini_struct(efx); |
| 2635 | fail1: |
Steve Hodgson | 5e2a911 | 2010-02-12 12:32:27 -0800 | [diff] [blame] | 2636 | WARN_ON(rc > 0); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2637 | netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2638 | free_netdev(net_dev); |
| 2639 | return rc; |
| 2640 | } |
| 2641 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2642 | static int efx_pm_freeze(struct device *dev) |
| 2643 | { |
| 2644 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2645 | |
| 2646 | efx->state = STATE_FINI; |
| 2647 | |
| 2648 | netif_device_detach(efx->net_dev); |
| 2649 | |
| 2650 | efx_stop_all(efx); |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2651 | efx_stop_interrupts(efx, false); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2652 | |
| 2653 | return 0; |
| 2654 | } |
| 2655 | |
| 2656 | static int efx_pm_thaw(struct device *dev) |
| 2657 | { |
| 2658 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 2659 | |
| 2660 | efx->state = STATE_INIT; |
| 2661 | |
Ben Hutchings | 7f967c0 | 2012-02-13 23:45:02 +0000 | [diff] [blame] | 2662 | efx_start_interrupts(efx, false); |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2663 | |
| 2664 | mutex_lock(&efx->mac_lock); |
| 2665 | efx->phy_op->reconfigure(efx); |
| 2666 | mutex_unlock(&efx->mac_lock); |
| 2667 | |
| 2668 | efx_start_all(efx); |
| 2669 | |
| 2670 | netif_device_attach(efx->net_dev); |
| 2671 | |
| 2672 | efx->state = STATE_RUNNING; |
| 2673 | |
| 2674 | efx->type->resume_wol(efx); |
| 2675 | |
Steve Hodgson | 319ba64 | 2010-06-01 11:17:24 +0000 | [diff] [blame] | 2676 | /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ |
| 2677 | queue_work(reset_workqueue, &efx->reset_work); |
| 2678 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2679 | return 0; |
| 2680 | } |
| 2681 | |
| 2682 | static int efx_pm_poweroff(struct device *dev) |
| 2683 | { |
| 2684 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 2685 | struct efx_nic *efx = pci_get_drvdata(pci_dev); |
| 2686 | |
| 2687 | efx->type->fini(efx); |
| 2688 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 2689 | efx->reset_pending = 0; |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2690 | |
| 2691 | pci_save_state(pci_dev); |
| 2692 | return pci_set_power_state(pci_dev, PCI_D3hot); |
| 2693 | } |
| 2694 | |
| 2695 | /* Used for both resume and restore */ |
| 2696 | static int efx_pm_resume(struct device *dev) |
| 2697 | { |
| 2698 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 2699 | struct efx_nic *efx = pci_get_drvdata(pci_dev); |
| 2700 | int rc; |
| 2701 | |
| 2702 | rc = pci_set_power_state(pci_dev, PCI_D0); |
| 2703 | if (rc) |
| 2704 | return rc; |
| 2705 | pci_restore_state(pci_dev); |
| 2706 | rc = pci_enable_device(pci_dev); |
| 2707 | if (rc) |
| 2708 | return rc; |
| 2709 | pci_set_master(efx->pci_dev); |
| 2710 | rc = efx->type->reset(efx, RESET_TYPE_ALL); |
| 2711 | if (rc) |
| 2712 | return rc; |
| 2713 | rc = efx->type->init(efx); |
| 2714 | if (rc) |
| 2715 | return rc; |
| 2716 | efx_pm_thaw(dev); |
| 2717 | return 0; |
| 2718 | } |
| 2719 | |
| 2720 | static int efx_pm_suspend(struct device *dev) |
| 2721 | { |
| 2722 | int rc; |
| 2723 | |
| 2724 | efx_pm_freeze(dev); |
| 2725 | rc = efx_pm_poweroff(dev); |
| 2726 | if (rc) |
| 2727 | efx_pm_resume(dev); |
| 2728 | return rc; |
| 2729 | } |
| 2730 | |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 2731 | static const struct dev_pm_ops efx_pm_ops = { |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2732 | .suspend = efx_pm_suspend, |
| 2733 | .resume = efx_pm_resume, |
| 2734 | .freeze = efx_pm_freeze, |
| 2735 | .thaw = efx_pm_thaw, |
| 2736 | .poweroff = efx_pm_poweroff, |
| 2737 | .restore = efx_pm_resume, |
| 2738 | }; |
| 2739 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2740 | static struct pci_driver efx_pci_driver = { |
Ben Hutchings | c5d5f5f | 2010-06-23 11:30:26 +0000 | [diff] [blame] | 2741 | .name = KBUILD_MODNAME, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2742 | .id_table = efx_pci_table, |
| 2743 | .probe = efx_pci_probe, |
| 2744 | .remove = efx_pci_remove, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2745 | .driver.pm = &efx_pm_ops, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2746 | }; |
| 2747 | |
| 2748 | /************************************************************************** |
| 2749 | * |
| 2750 | * Kernel module interface |
| 2751 | * |
| 2752 | *************************************************************************/ |
| 2753 | |
| 2754 | module_param(interrupt_mode, uint, 0444); |
| 2755 | MODULE_PARM_DESC(interrupt_mode, |
| 2756 | "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); |
| 2757 | |
| 2758 | static int __init efx_init_module(void) |
| 2759 | { |
| 2760 | int rc; |
| 2761 | |
| 2762 | printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n"); |
| 2763 | |
| 2764 | rc = register_netdevice_notifier(&efx_netdev_notifier); |
| 2765 | if (rc) |
| 2766 | goto err_notifier; |
| 2767 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2768 | rc = efx_init_sriov(); |
| 2769 | if (rc) |
| 2770 | goto err_sriov; |
| 2771 | |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2772 | reset_workqueue = create_singlethread_workqueue("sfc_reset"); |
| 2773 | if (!reset_workqueue) { |
| 2774 | rc = -ENOMEM; |
| 2775 | goto err_reset; |
| 2776 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2777 | |
| 2778 | rc = pci_register_driver(&efx_pci_driver); |
| 2779 | if (rc < 0) |
| 2780 | goto err_pci; |
| 2781 | |
| 2782 | return 0; |
| 2783 | |
| 2784 | err_pci: |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2785 | destroy_workqueue(reset_workqueue); |
| 2786 | err_reset: |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2787 | efx_fini_sriov(); |
| 2788 | err_sriov: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2789 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 2790 | err_notifier: |
| 2791 | return rc; |
| 2792 | } |
| 2793 | |
| 2794 | static void __exit efx_exit_module(void) |
| 2795 | { |
| 2796 | printk(KERN_INFO "Solarflare NET driver unloading\n"); |
| 2797 | |
| 2798 | pci_unregister_driver(&efx_pci_driver); |
Steve Hodgson | 1ab0062 | 2008-12-12 21:33:02 -0800 | [diff] [blame] | 2799 | destroy_workqueue(reset_workqueue); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 2800 | efx_fini_sriov(); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2801 | unregister_netdevice_notifier(&efx_netdev_notifier); |
| 2802 | |
| 2803 | } |
| 2804 | |
| 2805 | module_init(efx_init_module); |
| 2806 | module_exit(efx_exit_module); |
| 2807 | |
Ben Hutchings | 906bb26 | 2009-11-29 15:16:19 +0000 | [diff] [blame] | 2808 | MODULE_AUTHOR("Solarflare Communications and " |
| 2809 | "Michael Brown <mbrown@fensystems.co.uk>"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2810 | MODULE_DESCRIPTION("Solarflare Communications network driver"); |
| 2811 | MODULE_LICENSE("GPL"); |
| 2812 | MODULE_DEVICE_TABLE(pci, efx_pci_table); |