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