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