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