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