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