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