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