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