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