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