Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare network controllers and boards |
| 3 | * Copyright 2012-2013 Solarflare Communications Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation, incorporated herein by reference. |
| 8 | */ |
| 9 | |
| 10 | #include "net_driver.h" |
| 11 | #include "ef10_regs.h" |
| 12 | #include "io.h" |
| 13 | #include "mcdi.h" |
| 14 | #include "mcdi_pcol.h" |
| 15 | #include "nic.h" |
| 16 | #include "workarounds.h" |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 17 | #include "selftest.h" |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 18 | #include "ef10_sriov.h" |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 19 | #include <linux/in.h> |
| 20 | #include <linux/jhash.h> |
| 21 | #include <linux/wait.h> |
| 22 | #include <linux/workqueue.h> |
| 23 | |
| 24 | /* Hardware control for EF10 architecture including 'Huntington'. */ |
| 25 | |
| 26 | #define EFX_EF10_DRVGEN_EV 7 |
| 27 | enum { |
| 28 | EFX_EF10_TEST = 1, |
| 29 | EFX_EF10_REFILL, |
| 30 | }; |
| 31 | |
| 32 | /* The reserved RSS context value */ |
| 33 | #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 34 | /* The maximum size of a shared RSS context */ |
| 35 | /* TODO: this should really be from the mcdi protocol export */ |
| 36 | #define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 37 | |
| 38 | /* The filter table(s) are managed by firmware and we have write-only |
| 39 | * access. When removing filters we must identify them to the |
| 40 | * firmware by a 64-bit handle, but this is too wide for Linux kernel |
| 41 | * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to |
| 42 | * be able to tell in advance whether a requested insertion will |
| 43 | * replace an existing filter. Therefore we maintain a software hash |
| 44 | * table, which should be at least as large as the hardware hash |
| 45 | * table. |
| 46 | * |
| 47 | * Huntington has a single 8K filter table shared between all filter |
| 48 | * types and both ports. |
| 49 | */ |
| 50 | #define HUNT_FILTER_TBL_ROWS 8192 |
| 51 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 52 | struct efx_ef10_dev_addr { |
| 53 | u8 addr[ETH_ALEN]; |
| 54 | u16 id; |
| 55 | }; |
| 56 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 57 | struct efx_ef10_filter_table { |
| 58 | /* The RX match field masks supported by this fw & hw, in order of priority */ |
| 59 | enum efx_filter_match_flags rx_match_flags[ |
| 60 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM]; |
| 61 | unsigned int rx_match_count; |
| 62 | |
| 63 | struct { |
| 64 | unsigned long spec; /* pointer to spec plus flag bits */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 65 | /* BUSY flag indicates that an update is in progress. AUTO_OLD is |
| 66 | * used to mark and sweep MAC filters for the device address lists. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 67 | */ |
| 68 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 69 | #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 70 | #define EFX_EF10_FILTER_FLAGS 3UL |
| 71 | u64 handle; /* firmware handle */ |
| 72 | } *entry; |
| 73 | wait_queue_head_t waitq; |
| 74 | /* Shadow of net_device address lists, guarded by mac_lock */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 75 | #define EFX_EF10_FILTER_DEV_UC_MAX 32 |
| 76 | #define EFX_EF10_FILTER_DEV_MC_MAX 256 |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 77 | struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX]; |
| 78 | struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 79 | int dev_uc_count; /* negative for PROMISC */ |
| 80 | int dev_mc_count; /* negative for PROMISC/ALLMULTI */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* An arbitrary search limit for the software hash table */ |
| 84 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 |
| 85 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 86 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); |
| 87 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); |
| 88 | |
| 89 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) |
| 90 | { |
| 91 | efx_dword_t reg; |
| 92 | |
| 93 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); |
| 94 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? |
| 95 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; |
| 96 | } |
| 97 | |
| 98 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) |
| 99 | { |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 100 | int bar; |
| 101 | |
| 102 | bar = efx->type->mem_bar; |
| 103 | return resource_size(&efx->pci_dev->resource[bar]); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 106 | static bool efx_ef10_is_vf(struct efx_nic *efx) |
| 107 | { |
| 108 | return efx->type->is_vf; |
| 109 | } |
| 110 | |
Daniel Pieczko | 1cd9ecb | 2015-05-06 00:57:53 +0100 | [diff] [blame] | 111 | static int efx_ef10_get_pf_index(struct efx_nic *efx) |
| 112 | { |
| 113 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); |
| 114 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 115 | size_t outlen; |
| 116 | int rc; |
| 117 | |
| 118 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, |
| 119 | sizeof(outbuf), &outlen); |
| 120 | if (rc) |
| 121 | return rc; |
| 122 | if (outlen < sizeof(outbuf)) |
| 123 | return -EIO; |
| 124 | |
| 125 | nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); |
| 126 | return 0; |
| 127 | } |
| 128 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 129 | #ifdef CONFIG_SFC_SRIOV |
| 130 | static int efx_ef10_get_vf_index(struct efx_nic *efx) |
| 131 | { |
| 132 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); |
| 133 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 134 | size_t outlen; |
| 135 | int rc; |
| 136 | |
| 137 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, |
| 138 | sizeof(outbuf), &outlen); |
| 139 | if (rc) |
| 140 | return rc; |
| 141 | if (outlen < sizeof(outbuf)) |
| 142 | return -EIO; |
| 143 | |
| 144 | nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF); |
| 145 | return 0; |
| 146 | } |
| 147 | #endif |
| 148 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 149 | static int efx_ef10_init_datapath_caps(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 150 | { |
| 151 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN); |
| 152 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 153 | size_t outlen; |
| 154 | int rc; |
| 155 | |
| 156 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); |
| 157 | |
| 158 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, |
| 159 | outbuf, sizeof(outbuf), &outlen); |
| 160 | if (rc) |
| 161 | return rc; |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 162 | if (outlen < sizeof(outbuf)) { |
| 163 | netif_err(efx, drv, efx->net_dev, |
| 164 | "unable to read datapath firmware capabilities\n"); |
| 165 | return -EIO; |
| 166 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 167 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 168 | nic_data->datapath_caps = |
| 169 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); |
| 170 | |
Daniel Pieczko | 8d9f9dd | 2015-05-06 00:56:55 +0100 | [diff] [blame] | 171 | /* record the DPCPU firmware IDs to determine VEB vswitching support. |
| 172 | */ |
| 173 | nic_data->rx_dpcpu_fw_id = |
| 174 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID); |
| 175 | nic_data->tx_dpcpu_fw_id = |
| 176 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID); |
| 177 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 178 | if (!(nic_data->datapath_caps & |
| 179 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) { |
| 180 | netif_err(efx, drv, efx->net_dev, |
| 181 | "current firmware does not support TSO\n"); |
| 182 | return -ENODEV; |
| 183 | } |
| 184 | |
| 185 | if (!(nic_data->datapath_caps & |
| 186 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { |
| 187 | netif_err(efx, probe, efx->net_dev, |
| 188 | "current firmware does not support an RX prefix\n"); |
| 189 | return -ENODEV; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) |
| 196 | { |
| 197 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); |
| 198 | int rc; |
| 199 | |
| 200 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, |
| 201 | outbuf, sizeof(outbuf), NULL); |
| 202 | if (rc) |
| 203 | return rc; |
| 204 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); |
| 205 | return rc > 0 ? rc : -ERANGE; |
| 206 | } |
| 207 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 208 | static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 209 | { |
| 210 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); |
| 211 | size_t outlen; |
| 212 | int rc; |
| 213 | |
| 214 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); |
| 215 | |
| 216 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, |
| 217 | outbuf, sizeof(outbuf), &outlen); |
| 218 | if (rc) |
| 219 | return rc; |
| 220 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) |
| 221 | return -EIO; |
| 222 | |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 223 | ether_addr_copy(mac_address, |
| 224 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 228 | static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address) |
| 229 | { |
| 230 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN); |
| 231 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX); |
| 232 | size_t outlen; |
| 233 | int num_addrs, rc; |
| 234 | |
| 235 | MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID, |
| 236 | EVB_PORT_ID_ASSIGNED); |
| 237 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf, |
| 238 | sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); |
| 239 | |
| 240 | if (rc) |
| 241 | return rc; |
| 242 | if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN) |
| 243 | return -EIO; |
| 244 | |
| 245 | num_addrs = MCDI_DWORD(outbuf, |
| 246 | VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT); |
| 247 | |
| 248 | WARN_ON(num_addrs != 1); |
| 249 | |
| 250 | ether_addr_copy(mac_address, |
| 251 | MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR)); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 256 | static ssize_t efx_ef10_show_link_control_flag(struct device *dev, |
| 257 | struct device_attribute *attr, |
| 258 | char *buf) |
| 259 | { |
| 260 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 261 | |
| 262 | return sprintf(buf, "%d\n", |
| 263 | ((efx->mcdi->fn_flags) & |
| 264 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) |
| 265 | ? 1 : 0); |
| 266 | } |
| 267 | |
| 268 | static ssize_t efx_ef10_show_primary_flag(struct device *dev, |
| 269 | struct device_attribute *attr, |
| 270 | char *buf) |
| 271 | { |
| 272 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 273 | |
| 274 | return sprintf(buf, "%d\n", |
| 275 | ((efx->mcdi->fn_flags) & |
| 276 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY)) |
| 277 | ? 1 : 0); |
| 278 | } |
| 279 | |
| 280 | static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag, |
| 281 | NULL); |
| 282 | static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL); |
| 283 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 284 | static int efx_ef10_probe(struct efx_nic *efx) |
| 285 | { |
| 286 | struct efx_ef10_nic_data *nic_data; |
Shradha Shah | 8be4132 | 2015-06-02 11:37:25 +0100 | [diff] [blame] | 287 | struct net_device *net_dev = efx->net_dev; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 288 | int i, rc; |
| 289 | |
Ben Hutchings | aa3930e | 2014-02-12 18:59:19 +0000 | [diff] [blame] | 290 | /* We can have one VI for each 8K region. However, until we |
| 291 | * use TX option descriptors we need two TX queues per channel. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 292 | */ |
| 293 | efx->max_channels = |
| 294 | min_t(unsigned int, |
| 295 | EFX_MAX_CHANNELS, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 296 | efx_ef10_mem_map_size(efx) / |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 297 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); |
Edward Cree | 9fd3d3a | 2014-11-03 14:14:35 +0000 | [diff] [blame] | 298 | if (WARN_ON(efx->max_channels == 0)) |
| 299 | return -EIO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 300 | |
| 301 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
| 302 | if (!nic_data) |
| 303 | return -ENOMEM; |
| 304 | efx->nic_data = nic_data; |
| 305 | |
Edward Cree | 75aba2a | 2015-05-27 13:13:54 +0100 | [diff] [blame] | 306 | /* we assume later that we can copy from this buffer in dwords */ |
| 307 | BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4); |
| 308 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 309 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, |
| 310 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); |
| 311 | if (rc) |
| 312 | goto fail1; |
| 313 | |
| 314 | /* Get the MC's warm boot count. In case it's rebooting right |
| 315 | * now, be prepared to retry. |
| 316 | */ |
| 317 | i = 0; |
| 318 | for (;;) { |
| 319 | rc = efx_ef10_get_warm_boot_count(efx); |
| 320 | if (rc >= 0) |
| 321 | break; |
| 322 | if (++i == 5) |
| 323 | goto fail2; |
| 324 | ssleep(1); |
| 325 | } |
| 326 | nic_data->warm_boot_count = rc; |
| 327 | |
| 328 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 329 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 330 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 331 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 332 | /* In case we're recovering from a crash (kexec), we want to |
| 333 | * cancel any outstanding request by the previous user of this |
| 334 | * function. We send a special message using the least |
| 335 | * significant bits of the 'high' (doorbell) register. |
| 336 | */ |
| 337 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); |
| 338 | |
| 339 | rc = efx_mcdi_init(efx); |
| 340 | if (rc) |
| 341 | goto fail2; |
| 342 | |
| 343 | /* Reset (most) configuration for this function */ |
| 344 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); |
| 345 | if (rc) |
| 346 | goto fail3; |
| 347 | |
| 348 | /* Enable event logging */ |
| 349 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); |
| 350 | if (rc) |
| 351 | goto fail3; |
| 352 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 353 | rc = device_create_file(&efx->pci_dev->dev, |
| 354 | &dev_attr_link_control_flag); |
Daniel Pieczko | 1cd9ecb | 2015-05-06 00:57:53 +0100 | [diff] [blame] | 355 | if (rc) |
| 356 | goto fail3; |
| 357 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 358 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 359 | if (rc) |
| 360 | goto fail4; |
| 361 | |
| 362 | rc = efx_ef10_get_pf_index(efx); |
| 363 | if (rc) |
| 364 | goto fail5; |
| 365 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 366 | rc = efx_ef10_init_datapath_caps(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 367 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 368 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 369 | |
| 370 | efx->rx_packet_len_offset = |
| 371 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; |
| 372 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 373 | rc = efx_mcdi_port_get_number(efx); |
| 374 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 375 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 376 | efx->port_num = rc; |
Shradha Shah | 8be4132 | 2015-06-02 11:37:25 +0100 | [diff] [blame] | 377 | net_dev->dev_port = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 378 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 379 | rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 380 | if (rc) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 381 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 382 | |
| 383 | rc = efx_ef10_get_sysclk_freq(efx); |
| 384 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 385 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 386 | efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */ |
| 387 | |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 388 | /* Check whether firmware supports bug 35388 workaround. |
| 389 | * First try to enable it, then if we get EPERM, just |
| 390 | * ask if it's already enabled |
| 391 | */ |
Daniel Pieczko | 34ccfe6 | 2015-07-21 15:09:43 +0100 | [diff] [blame] | 392 | rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true, NULL); |
Shradha Shah | c9012e0 | 2015-06-02 11:37:41 +0100 | [diff] [blame] | 393 | if (rc == 0) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 394 | nic_data->workaround_35388 = true; |
Shradha Shah | c9012e0 | 2015-06-02 11:37:41 +0100 | [diff] [blame] | 395 | } else if (rc == -EPERM) { |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 396 | unsigned int enabled; |
| 397 | |
| 398 | rc = efx_mcdi_get_workarounds(efx, NULL, &enabled); |
| 399 | if (rc) |
| 400 | goto fail3; |
| 401 | nic_data->workaround_35388 = enabled & |
| 402 | MC_CMD_GET_WORKAROUNDS_OUT_BUG35388; |
Shradha Shah | c9012e0 | 2015-06-02 11:37:41 +0100 | [diff] [blame] | 403 | } else if (rc != -ENOSYS && rc != -ENOENT) { |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 404 | goto fail5; |
Shradha Shah | c9012e0 | 2015-06-02 11:37:41 +0100 | [diff] [blame] | 405 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 406 | netif_dbg(efx, probe, efx->net_dev, |
| 407 | "workaround for bug 35388 is %sabled\n", |
| 408 | nic_data->workaround_35388 ? "en" : "dis"); |
| 409 | |
| 410 | rc = efx_mcdi_mon_probe(efx); |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 411 | if (rc && rc != -EPERM) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 412 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 413 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 414 | efx_ptp_probe(efx, NULL); |
| 415 | |
Shradha Shah | 1d051e0 | 2015-06-02 11:38:16 +0100 | [diff] [blame] | 416 | #ifdef CONFIG_SFC_SRIOV |
| 417 | if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) { |
| 418 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; |
| 419 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 420 | |
| 421 | efx_pf->type->get_mac_address(efx_pf, nic_data->port_id); |
| 422 | } else |
| 423 | #endif |
| 424 | ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr); |
| 425 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 426 | return 0; |
| 427 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 428 | fail5: |
| 429 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 430 | fail4: |
| 431 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 432 | fail3: |
| 433 | efx_mcdi_fini(efx); |
| 434 | fail2: |
| 435 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 436 | fail1: |
| 437 | kfree(nic_data); |
| 438 | efx->nic_data = NULL; |
| 439 | return rc; |
| 440 | } |
| 441 | |
| 442 | static int efx_ef10_free_vis(struct efx_nic *efx) |
| 443 | { |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 444 | MCDI_DECLARE_BUF_ERR(outbuf); |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 445 | size_t outlen; |
| 446 | int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0, |
| 447 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 448 | |
| 449 | /* -EALREADY means nothing to free, so ignore */ |
| 450 | if (rc == -EALREADY) |
| 451 | rc = 0; |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 452 | if (rc) |
| 453 | efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen, |
| 454 | rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 455 | return rc; |
| 456 | } |
| 457 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 458 | #ifdef EFX_USE_PIO |
| 459 | |
| 460 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 461 | { |
| 462 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 463 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN); |
| 464 | unsigned int i; |
| 465 | int rc; |
| 466 | |
| 467 | BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0); |
| 468 | |
| 469 | for (i = 0; i < nic_data->n_piobufs; i++) { |
| 470 | MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE, |
| 471 | nic_data->piobuf_handle[i]); |
| 472 | rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf), |
| 473 | NULL, 0, NULL); |
| 474 | WARN_ON(rc); |
| 475 | } |
| 476 | |
| 477 | nic_data->n_piobufs = 0; |
| 478 | } |
| 479 | |
| 480 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 481 | { |
| 482 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 483 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN); |
| 484 | unsigned int i; |
| 485 | size_t outlen; |
| 486 | int rc = 0; |
| 487 | |
| 488 | BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0); |
| 489 | |
| 490 | for (i = 0; i < n; i++) { |
| 491 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0, |
| 492 | outbuf, sizeof(outbuf), &outlen); |
| 493 | if (rc) |
| 494 | break; |
| 495 | if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) { |
| 496 | rc = -EIO; |
| 497 | break; |
| 498 | } |
| 499 | nic_data->piobuf_handle[i] = |
| 500 | MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE); |
| 501 | netif_dbg(efx, probe, efx->net_dev, |
| 502 | "allocated PIO buffer %u handle %x\n", i, |
| 503 | nic_data->piobuf_handle[i]); |
| 504 | } |
| 505 | |
| 506 | nic_data->n_piobufs = i; |
| 507 | if (rc) |
| 508 | efx_ef10_free_piobufs(efx); |
| 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 513 | { |
| 514 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 515 | _MCDI_DECLARE_BUF(inbuf, |
| 516 | max(MC_CMD_LINK_PIOBUF_IN_LEN, |
| 517 | MC_CMD_UNLINK_PIOBUF_IN_LEN)); |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 518 | struct efx_channel *channel; |
| 519 | struct efx_tx_queue *tx_queue; |
| 520 | unsigned int offset, index; |
| 521 | int rc; |
| 522 | |
| 523 | BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0); |
| 524 | BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0); |
| 525 | |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 526 | memset(inbuf, 0, sizeof(inbuf)); |
| 527 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 528 | /* Link a buffer to each VI in the write-combining mapping */ |
| 529 | for (index = 0; index < nic_data->n_piobufs; ++index) { |
| 530 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 531 | nic_data->piobuf_handle[index]); |
| 532 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 533 | nic_data->pio_write_vi_base + index); |
| 534 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 535 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 536 | NULL, 0, NULL); |
| 537 | if (rc) { |
| 538 | netif_err(efx, drv, efx->net_dev, |
| 539 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 540 | nic_data->pio_write_vi_base + index, index, |
| 541 | rc); |
| 542 | goto fail; |
| 543 | } |
| 544 | netif_dbg(efx, probe, efx->net_dev, |
| 545 | "linked VI %u to PIO buffer %u\n", |
| 546 | nic_data->pio_write_vi_base + index, index); |
| 547 | } |
| 548 | |
| 549 | /* Link a buffer to each TX queue */ |
| 550 | efx_for_each_channel(channel, efx) { |
| 551 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 552 | /* We assign the PIO buffers to queues in |
| 553 | * reverse order to allow for the following |
| 554 | * special case. |
| 555 | */ |
| 556 | offset = ((efx->tx_channel_offset + efx->n_tx_channels - |
| 557 | tx_queue->channel->channel - 1) * |
| 558 | efx_piobuf_size); |
| 559 | index = offset / ER_DZ_TX_PIOBUF_SIZE; |
| 560 | offset = offset % ER_DZ_TX_PIOBUF_SIZE; |
| 561 | |
| 562 | /* When the host page size is 4K, the first |
| 563 | * host page in the WC mapping may be within |
| 564 | * the same VI page as the last TX queue. We |
| 565 | * can only link one buffer to each VI. |
| 566 | */ |
| 567 | if (tx_queue->queue == nic_data->pio_write_vi_base) { |
| 568 | BUG_ON(index != 0); |
| 569 | rc = 0; |
| 570 | } else { |
| 571 | MCDI_SET_DWORD(inbuf, |
| 572 | LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 573 | nic_data->piobuf_handle[index]); |
| 574 | MCDI_SET_DWORD(inbuf, |
| 575 | LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 576 | tx_queue->queue); |
| 577 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 578 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 579 | NULL, 0, NULL); |
| 580 | } |
| 581 | |
| 582 | if (rc) { |
| 583 | /* This is non-fatal; the TX path just |
| 584 | * won't use PIO for this queue |
| 585 | */ |
| 586 | netif_err(efx, drv, efx->net_dev, |
| 587 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 588 | tx_queue->queue, index, rc); |
| 589 | tx_queue->piobuf = NULL; |
| 590 | } else { |
| 591 | tx_queue->piobuf = |
| 592 | nic_data->pio_write_base + |
| 593 | index * EFX_VI_PAGE_SIZE + offset; |
| 594 | tx_queue->piobuf_offset = offset; |
| 595 | netif_dbg(efx, probe, efx->net_dev, |
| 596 | "linked VI %u to PIO buffer %u offset %x addr %p\n", |
| 597 | tx_queue->queue, index, |
| 598 | tx_queue->piobuf_offset, |
| 599 | tx_queue->piobuf); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return 0; |
| 605 | |
| 606 | fail: |
| 607 | while (index--) { |
| 608 | MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE, |
| 609 | nic_data->pio_write_vi_base + index); |
| 610 | efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF, |
| 611 | inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN, |
| 612 | NULL, 0, NULL); |
| 613 | } |
| 614 | return rc; |
| 615 | } |
| 616 | |
| 617 | #else /* !EFX_USE_PIO */ |
| 618 | |
| 619 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 620 | { |
| 621 | return n == 0 ? 0 : -ENOBUFS; |
| 622 | } |
| 623 | |
| 624 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 625 | { |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 630 | { |
| 631 | } |
| 632 | |
| 633 | #endif /* EFX_USE_PIO */ |
| 634 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 635 | static void efx_ef10_remove(struct efx_nic *efx) |
| 636 | { |
| 637 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 638 | int rc; |
| 639 | |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 640 | #ifdef CONFIG_SFC_SRIOV |
| 641 | struct efx_ef10_nic_data *nic_data_pf; |
| 642 | struct pci_dev *pci_dev_pf; |
| 643 | struct efx_nic *efx_pf; |
| 644 | struct ef10_vf *vf; |
| 645 | |
| 646 | if (efx->pci_dev->is_virtfn) { |
| 647 | pci_dev_pf = efx->pci_dev->physfn; |
| 648 | if (pci_dev_pf) { |
| 649 | efx_pf = pci_get_drvdata(pci_dev_pf); |
| 650 | nic_data_pf = efx_pf->nic_data; |
| 651 | vf = nic_data_pf->vf + nic_data->vf_index; |
| 652 | vf->efx = NULL; |
| 653 | } else |
| 654 | netif_info(efx, drv, efx->net_dev, |
| 655 | "Could not get the PF id from VF\n"); |
| 656 | } |
| 657 | #endif |
| 658 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 659 | efx_ptp_remove(efx); |
| 660 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 661 | efx_mcdi_mon_remove(efx); |
| 662 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 663 | efx_ef10_rx_free_indir_table(efx); |
| 664 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 665 | if (nic_data->wc_membase) |
| 666 | iounmap(nic_data->wc_membase); |
| 667 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 668 | rc = efx_ef10_free_vis(efx); |
| 669 | WARN_ON(rc != 0); |
| 670 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 671 | if (!nic_data->must_restore_piobufs) |
| 672 | efx_ef10_free_piobufs(efx); |
| 673 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 674 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 675 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); |
| 676 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 677 | efx_mcdi_fini(efx); |
| 678 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 679 | kfree(nic_data); |
| 680 | } |
| 681 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 682 | static int efx_ef10_probe_pf(struct efx_nic *efx) |
| 683 | { |
| 684 | return efx_ef10_probe(efx); |
| 685 | } |
| 686 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 687 | int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id) |
| 688 | { |
| 689 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN); |
| 690 | |
| 691 | MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id); |
| 692 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf), |
| 693 | NULL, 0, NULL); |
| 694 | } |
| 695 | |
| 696 | int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id) |
| 697 | { |
| 698 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN); |
| 699 | |
| 700 | MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id); |
| 701 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf), |
| 702 | NULL, 0, NULL); |
| 703 | } |
| 704 | |
| 705 | int efx_ef10_vport_add_mac(struct efx_nic *efx, |
| 706 | unsigned int port_id, u8 *mac) |
| 707 | { |
| 708 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN); |
| 709 | |
| 710 | MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 711 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac); |
| 712 | |
| 713 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf, |
| 714 | sizeof(inbuf), NULL, 0, NULL); |
| 715 | } |
| 716 | |
| 717 | int efx_ef10_vport_del_mac(struct efx_nic *efx, |
| 718 | unsigned int port_id, u8 *mac) |
| 719 | { |
| 720 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN); |
| 721 | |
| 722 | MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 723 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac); |
| 724 | |
| 725 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf, |
| 726 | sizeof(inbuf), NULL, 0, NULL); |
| 727 | } |
| 728 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 729 | #ifdef CONFIG_SFC_SRIOV |
| 730 | static int efx_ef10_probe_vf(struct efx_nic *efx) |
| 731 | { |
| 732 | int rc; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 733 | struct pci_dev *pci_dev_pf; |
| 734 | |
| 735 | /* If the parent PF has no VF data structure, it doesn't know about this |
| 736 | * VF so fail probe. The VF needs to be re-created. This can happen |
| 737 | * if the PF driver is unloaded while the VF is assigned to a guest. |
| 738 | */ |
| 739 | pci_dev_pf = efx->pci_dev->physfn; |
| 740 | if (pci_dev_pf) { |
| 741 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 742 | struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data; |
| 743 | |
| 744 | if (!nic_data_pf->vf) { |
| 745 | netif_info(efx, drv, efx->net_dev, |
| 746 | "The VF cannot link to its parent PF; " |
| 747 | "please destroy and re-create the VF\n"); |
| 748 | return -EBUSY; |
| 749 | } |
| 750 | } |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 751 | |
| 752 | rc = efx_ef10_probe(efx); |
| 753 | if (rc) |
| 754 | return rc; |
| 755 | |
| 756 | rc = efx_ef10_get_vf_index(efx); |
| 757 | if (rc) |
| 758 | goto fail; |
| 759 | |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 760 | if (efx->pci_dev->is_virtfn) { |
| 761 | if (efx->pci_dev->physfn) { |
| 762 | struct efx_nic *efx_pf = |
| 763 | pci_get_drvdata(efx->pci_dev->physfn); |
| 764 | struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data; |
| 765 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 766 | |
| 767 | nic_data_p->vf[nic_data->vf_index].efx = efx; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 768 | nic_data_p->vf[nic_data->vf_index].pci_dev = |
| 769 | efx->pci_dev; |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 770 | } else |
| 771 | netif_info(efx, drv, efx->net_dev, |
| 772 | "Could not get the PF id from VF\n"); |
| 773 | } |
| 774 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 775 | return 0; |
| 776 | |
| 777 | fail: |
| 778 | efx_ef10_remove(efx); |
| 779 | return rc; |
| 780 | } |
| 781 | #else |
| 782 | static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused))) |
| 783 | { |
| 784 | return 0; |
| 785 | } |
| 786 | #endif |
| 787 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 788 | static int efx_ef10_alloc_vis(struct efx_nic *efx, |
| 789 | unsigned int min_vis, unsigned int max_vis) |
| 790 | { |
| 791 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); |
| 792 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); |
| 793 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 794 | size_t outlen; |
| 795 | int rc; |
| 796 | |
| 797 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); |
| 798 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); |
| 799 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), |
| 800 | outbuf, sizeof(outbuf), &outlen); |
| 801 | if (rc != 0) |
| 802 | return rc; |
| 803 | |
| 804 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) |
| 805 | return -EIO; |
| 806 | |
| 807 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", |
| 808 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); |
| 809 | |
| 810 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); |
| 811 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); |
| 812 | return 0; |
| 813 | } |
| 814 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 815 | /* Note that the failure path of this function does not free |
| 816 | * resources, as this will be done by efx_ef10_remove(). |
| 817 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 818 | static int efx_ef10_dimension_resources(struct efx_nic *efx) |
| 819 | { |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 820 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 821 | unsigned int uc_mem_map_size, wc_mem_map_size; |
| 822 | unsigned int min_vis, pio_write_vi_base, max_vis; |
| 823 | void __iomem *membase; |
| 824 | int rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 825 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 826 | min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); |
| 827 | |
| 828 | #ifdef EFX_USE_PIO |
| 829 | /* Try to allocate PIO buffers if wanted and if the full |
| 830 | * number of PIO buffers would be sufficient to allocate one |
| 831 | * copy-buffer per TX channel. Failure is non-fatal, as there |
| 832 | * are only a small number of PIO buffers shared between all |
| 833 | * functions of the controller. |
| 834 | */ |
| 835 | if (efx_piobuf_size != 0 && |
| 836 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >= |
| 837 | efx->n_tx_channels) { |
| 838 | unsigned int n_piobufs = |
| 839 | DIV_ROUND_UP(efx->n_tx_channels, |
| 840 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size); |
| 841 | |
| 842 | rc = efx_ef10_alloc_piobufs(efx, n_piobufs); |
| 843 | if (rc) |
| 844 | netif_err(efx, probe, efx->net_dev, |
| 845 | "failed to allocate PIO buffers (%d)\n", rc); |
| 846 | else |
| 847 | netif_dbg(efx, probe, efx->net_dev, |
| 848 | "allocated %u PIO buffers\n", n_piobufs); |
| 849 | } |
| 850 | #else |
| 851 | nic_data->n_piobufs = 0; |
| 852 | #endif |
| 853 | |
| 854 | /* PIO buffers should be mapped with write-combining enabled, |
| 855 | * and we want to make single UC and WC mappings rather than |
| 856 | * several of each (in fact that's the only option if host |
| 857 | * page size is >4K). So we may allocate some extra VIs just |
| 858 | * for writing PIO buffers through. |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 859 | * |
| 860 | * The UC mapping contains (min_vis - 1) complete VIs and the |
| 861 | * first half of the next VI. Then the WC mapping begins with |
| 862 | * the second half of this last VI. |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 863 | */ |
| 864 | uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE + |
| 865 | ER_DZ_TX_PIOBUF); |
| 866 | if (nic_data->n_piobufs) { |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 867 | /* pio_write_vi_base rounds down to give the number of complete |
| 868 | * VIs inside the UC mapping. |
| 869 | */ |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 870 | pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE; |
| 871 | wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base + |
| 872 | nic_data->n_piobufs) * |
| 873 | EFX_VI_PAGE_SIZE) - |
| 874 | uc_mem_map_size); |
| 875 | max_vis = pio_write_vi_base + nic_data->n_piobufs; |
| 876 | } else { |
| 877 | pio_write_vi_base = 0; |
| 878 | wc_mem_map_size = 0; |
| 879 | max_vis = min_vis; |
| 880 | } |
| 881 | |
| 882 | /* In case the last attached driver failed to free VIs, do it now */ |
| 883 | rc = efx_ef10_free_vis(efx); |
| 884 | if (rc != 0) |
| 885 | return rc; |
| 886 | |
| 887 | rc = efx_ef10_alloc_vis(efx, min_vis, max_vis); |
| 888 | if (rc != 0) |
| 889 | return rc; |
| 890 | |
| 891 | /* If we didn't get enough VIs to map all the PIO buffers, free the |
| 892 | * PIO buffers |
| 893 | */ |
| 894 | if (nic_data->n_piobufs && |
| 895 | nic_data->n_allocated_vis < |
| 896 | pio_write_vi_base + nic_data->n_piobufs) { |
| 897 | netif_dbg(efx, probe, efx->net_dev, |
| 898 | "%u VIs are not sufficient to map %u PIO buffers\n", |
| 899 | nic_data->n_allocated_vis, nic_data->n_piobufs); |
| 900 | efx_ef10_free_piobufs(efx); |
| 901 | } |
| 902 | |
| 903 | /* Shrink the original UC mapping of the memory BAR */ |
| 904 | membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size); |
| 905 | if (!membase) { |
| 906 | netif_err(efx, probe, efx->net_dev, |
| 907 | "could not shrink memory BAR to %x\n", |
| 908 | uc_mem_map_size); |
| 909 | return -ENOMEM; |
| 910 | } |
| 911 | iounmap(efx->membase); |
| 912 | efx->membase = membase; |
| 913 | |
| 914 | /* Set up the WC mapping if needed */ |
| 915 | if (wc_mem_map_size) { |
| 916 | nic_data->wc_membase = ioremap_wc(efx->membase_phys + |
| 917 | uc_mem_map_size, |
| 918 | wc_mem_map_size); |
| 919 | if (!nic_data->wc_membase) { |
| 920 | netif_err(efx, probe, efx->net_dev, |
| 921 | "could not allocate WC mapping of size %x\n", |
| 922 | wc_mem_map_size); |
| 923 | return -ENOMEM; |
| 924 | } |
| 925 | nic_data->pio_write_vi_base = pio_write_vi_base; |
| 926 | nic_data->pio_write_base = |
| 927 | nic_data->wc_membase + |
| 928 | (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF - |
| 929 | uc_mem_map_size); |
| 930 | |
| 931 | rc = efx_ef10_link_piobufs(efx); |
| 932 | if (rc) |
| 933 | efx_ef10_free_piobufs(efx); |
| 934 | } |
| 935 | |
| 936 | netif_dbg(efx, probe, efx->net_dev, |
| 937 | "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", |
| 938 | &efx->membase_phys, efx->membase, uc_mem_map_size, |
| 939 | nic_data->wc_membase, wc_mem_map_size); |
| 940 | |
| 941 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static int efx_ef10_init_nic(struct efx_nic *efx) |
| 945 | { |
| 946 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 947 | int rc; |
| 948 | |
Ben Hutchings | a915ccc | 2013-09-05 22:51:55 +0100 | [diff] [blame] | 949 | if (nic_data->must_check_datapath_caps) { |
| 950 | rc = efx_ef10_init_datapath_caps(efx); |
| 951 | if (rc) |
| 952 | return rc; |
| 953 | nic_data->must_check_datapath_caps = false; |
| 954 | } |
| 955 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 956 | if (nic_data->must_realloc_vis) { |
| 957 | /* We cannot let the number of VIs change now */ |
| 958 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, |
| 959 | nic_data->n_allocated_vis); |
| 960 | if (rc) |
| 961 | return rc; |
| 962 | nic_data->must_realloc_vis = false; |
| 963 | } |
| 964 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 965 | if (nic_data->must_restore_piobufs && nic_data->n_piobufs) { |
| 966 | rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs); |
| 967 | if (rc == 0) { |
| 968 | rc = efx_ef10_link_piobufs(efx); |
| 969 | if (rc) |
| 970 | efx_ef10_free_piobufs(efx); |
| 971 | } |
| 972 | |
| 973 | /* Log an error on failure, but this is non-fatal */ |
| 974 | if (rc) |
| 975 | netif_err(efx, drv, efx->net_dev, |
| 976 | "failed to restore PIO buffers (%d)\n", rc); |
| 977 | nic_data->must_restore_piobufs = false; |
| 978 | } |
| 979 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 980 | /* don't fail init if RSS setup doesn't work */ |
| 981 | efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table); |
| 982 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 983 | return 0; |
| 984 | } |
| 985 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 986 | static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) |
| 987 | { |
| 988 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 989 | |
| 990 | /* All our allocations have been reset */ |
| 991 | nic_data->must_realloc_vis = true; |
| 992 | nic_data->must_restore_filters = true; |
| 993 | nic_data->must_restore_piobufs = true; |
| 994 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 995 | } |
| 996 | |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 997 | static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason) |
| 998 | { |
| 999 | if (reason == RESET_TYPE_MC_FAILURE) |
| 1000 | return RESET_TYPE_DATAPATH; |
| 1001 | |
| 1002 | return efx_mcdi_map_reset_reason(reason); |
| 1003 | } |
| 1004 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1005 | static int efx_ef10_map_reset_flags(u32 *flags) |
| 1006 | { |
| 1007 | enum { |
| 1008 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << |
| 1009 | ETH_RESET_SHARED_SHIFT), |
| 1010 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | |
| 1011 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | |
| 1012 | ETH_RESET_PHY | ETH_RESET_MGMT) << |
| 1013 | ETH_RESET_SHARED_SHIFT) |
| 1014 | }; |
| 1015 | |
| 1016 | /* We assume for now that our PCI function is permitted to |
| 1017 | * reset everything. |
| 1018 | */ |
| 1019 | |
| 1020 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { |
| 1021 | *flags &= ~EF10_RESET_MC; |
| 1022 | return RESET_TYPE_WORLD; |
| 1023 | } |
| 1024 | |
| 1025 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { |
| 1026 | *flags &= ~EF10_RESET_PORT; |
| 1027 | return RESET_TYPE_ALL; |
| 1028 | } |
| 1029 | |
| 1030 | /* no invisible reset implemented */ |
| 1031 | |
| 1032 | return -EINVAL; |
| 1033 | } |
| 1034 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1035 | static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type) |
| 1036 | { |
| 1037 | int rc = efx_mcdi_reset(efx, reset_type); |
| 1038 | |
| 1039 | /* If it was a port reset, trigger reallocation of MC resources. |
| 1040 | * Note that on an MC reset nothing needs to be done now because we'll |
| 1041 | * detect the MC reset later and handle it then. |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 1042 | * For an FLR, we never get an MC reset event, but the MC has reset all |
| 1043 | * resources assigned to us, so we have to trigger reallocation now. |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1044 | */ |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 1045 | if ((reset_type == RESET_TYPE_ALL || |
| 1046 | reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc) |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1047 | efx_ef10_reset_mc_allocations(efx); |
| 1048 | return rc; |
| 1049 | } |
| 1050 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1051 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ |
| 1052 | [EF10_STAT_ ## ext_name] = \ |
| 1053 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 1054 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ |
| 1055 | [EF10_STAT_ ## int_name] = \ |
| 1056 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 1057 | #define EF10_OTHER_STAT(ext_name) \ |
| 1058 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1059 | #define GENERIC_SW_STAT(ext_name) \ |
| 1060 | [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1061 | |
| 1062 | static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = { |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1063 | EF10_DMA_STAT(port_tx_bytes, TX_BYTES), |
| 1064 | EF10_DMA_STAT(port_tx_packets, TX_PKTS), |
| 1065 | EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS), |
| 1066 | EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS), |
| 1067 | EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS), |
| 1068 | EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS), |
| 1069 | EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS), |
| 1070 | EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS), |
| 1071 | EF10_DMA_STAT(port_tx_64, TX_64_PKTS), |
| 1072 | EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS), |
| 1073 | EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS), |
| 1074 | EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS), |
| 1075 | EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS), |
| 1076 | EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), |
| 1077 | EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), |
| 1078 | EF10_DMA_STAT(port_rx_bytes, RX_BYTES), |
| 1079 | EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES), |
| 1080 | EF10_OTHER_STAT(port_rx_good_bytes), |
| 1081 | EF10_OTHER_STAT(port_rx_bad_bytes), |
| 1082 | EF10_DMA_STAT(port_rx_packets, RX_PKTS), |
| 1083 | EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS), |
| 1084 | EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS), |
| 1085 | EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS), |
| 1086 | EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS), |
| 1087 | EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS), |
| 1088 | EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS), |
| 1089 | EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS), |
| 1090 | EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS), |
| 1091 | EF10_DMA_STAT(port_rx_64, RX_64_PKTS), |
| 1092 | EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS), |
| 1093 | EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS), |
| 1094 | EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS), |
| 1095 | EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS), |
| 1096 | EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), |
| 1097 | EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), |
| 1098 | EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS), |
| 1099 | EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS), |
| 1100 | EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS), |
| 1101 | EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS), |
| 1102 | EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS), |
| 1103 | EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS), |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1104 | GENERIC_SW_STAT(rx_nodesc_trunc), |
| 1105 | GENERIC_SW_STAT(rx_noskb_drops), |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1106 | EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW), |
| 1107 | EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW), |
| 1108 | EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL), |
| 1109 | EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL), |
| 1110 | EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB), |
| 1111 | EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB), |
| 1112 | EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING), |
| 1113 | EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS), |
| 1114 | EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS), |
| 1115 | EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS), |
| 1116 | EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS), |
| 1117 | EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS), |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1118 | EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS), |
| 1119 | EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES), |
| 1120 | EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS), |
| 1121 | EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES), |
| 1122 | EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS), |
| 1123 | EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES), |
| 1124 | EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS), |
| 1125 | EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES), |
| 1126 | EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW), |
| 1127 | EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS), |
| 1128 | EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES), |
| 1129 | EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS), |
| 1130 | EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES), |
| 1131 | EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS), |
| 1132 | EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES), |
| 1133 | EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS), |
| 1134 | EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES), |
| 1135 | EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1136 | }; |
| 1137 | |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1138 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \ |
| 1139 | (1ULL << EF10_STAT_port_tx_packets) | \ |
| 1140 | (1ULL << EF10_STAT_port_tx_pause) | \ |
| 1141 | (1ULL << EF10_STAT_port_tx_unicast) | \ |
| 1142 | (1ULL << EF10_STAT_port_tx_multicast) | \ |
| 1143 | (1ULL << EF10_STAT_port_tx_broadcast) | \ |
| 1144 | (1ULL << EF10_STAT_port_rx_bytes) | \ |
| 1145 | (1ULL << \ |
| 1146 | EF10_STAT_port_rx_bytes_minus_good_bytes) | \ |
| 1147 | (1ULL << EF10_STAT_port_rx_good_bytes) | \ |
| 1148 | (1ULL << EF10_STAT_port_rx_bad_bytes) | \ |
| 1149 | (1ULL << EF10_STAT_port_rx_packets) | \ |
| 1150 | (1ULL << EF10_STAT_port_rx_good) | \ |
| 1151 | (1ULL << EF10_STAT_port_rx_bad) | \ |
| 1152 | (1ULL << EF10_STAT_port_rx_pause) | \ |
| 1153 | (1ULL << EF10_STAT_port_rx_control) | \ |
| 1154 | (1ULL << EF10_STAT_port_rx_unicast) | \ |
| 1155 | (1ULL << EF10_STAT_port_rx_multicast) | \ |
| 1156 | (1ULL << EF10_STAT_port_rx_broadcast) | \ |
| 1157 | (1ULL << EF10_STAT_port_rx_lt64) | \ |
| 1158 | (1ULL << EF10_STAT_port_rx_64) | \ |
| 1159 | (1ULL << EF10_STAT_port_rx_65_to_127) | \ |
| 1160 | (1ULL << EF10_STAT_port_rx_128_to_255) | \ |
| 1161 | (1ULL << EF10_STAT_port_rx_256_to_511) | \ |
| 1162 | (1ULL << EF10_STAT_port_rx_512_to_1023) |\ |
| 1163 | (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\ |
| 1164 | (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\ |
| 1165 | (1ULL << EF10_STAT_port_rx_gtjumbo) | \ |
| 1166 | (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\ |
| 1167 | (1ULL << EF10_STAT_port_rx_overflow) | \ |
| 1168 | (1ULL << EF10_STAT_port_rx_nodesc_drops) |\ |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1169 | (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \ |
| 1170 | (1ULL << GENERIC_STAT_rx_noskb_drops)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1171 | |
| 1172 | /* These statistics are only provided by the 10G MAC. For a 10G/40G |
| 1173 | * switchable port we do not expose these because they might not |
| 1174 | * include all the packets they should. |
| 1175 | */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1176 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \ |
| 1177 | (1ULL << EF10_STAT_port_tx_lt64) | \ |
| 1178 | (1ULL << EF10_STAT_port_tx_64) | \ |
| 1179 | (1ULL << EF10_STAT_port_tx_65_to_127) |\ |
| 1180 | (1ULL << EF10_STAT_port_tx_128_to_255) |\ |
| 1181 | (1ULL << EF10_STAT_port_tx_256_to_511) |\ |
| 1182 | (1ULL << EF10_STAT_port_tx_512_to_1023) |\ |
| 1183 | (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\ |
| 1184 | (1ULL << EF10_STAT_port_tx_15xx_to_jumbo)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1185 | |
| 1186 | /* These statistics are only provided by the 40G MAC. For a 10G/40G |
| 1187 | * switchable port we do expose these because the errors will otherwise |
| 1188 | * be silent. |
| 1189 | */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1190 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\ |
| 1191 | (1ULL << EF10_STAT_port_rx_length_error)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1192 | |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1193 | /* These statistics are only provided if the firmware supports the |
| 1194 | * capability PM_AND_RXDP_COUNTERS. |
| 1195 | */ |
| 1196 | #define HUNT_PM_AND_RXDP_STAT_MASK ( \ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1197 | (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \ |
| 1198 | (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \ |
| 1199 | (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \ |
| 1200 | (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \ |
| 1201 | (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \ |
| 1202 | (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \ |
| 1203 | (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \ |
| 1204 | (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \ |
| 1205 | (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \ |
| 1206 | (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \ |
| 1207 | (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \ |
| 1208 | (1ULL << EF10_STAT_port_rx_dp_hlb_wait)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1209 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1210 | static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1211 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1212 | u64 raw_mask = HUNT_COMMON_STAT_MASK; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1213 | u32 port_caps = efx_mcdi_phy_get_caps(efx); |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1214 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1215 | |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1216 | if (!(efx->mcdi->fn_flags & |
| 1217 | 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) |
| 1218 | return 0; |
| 1219 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1220 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1221 | raw_mask |= HUNT_40G_EXTRA_STAT_MASK; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1222 | else |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1223 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1224 | |
| 1225 | if (nic_data->datapath_caps & |
| 1226 | (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN)) |
| 1227 | raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK; |
| 1228 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1229 | return raw_mask; |
| 1230 | } |
| 1231 | |
| 1232 | static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask) |
| 1233 | { |
Daniel Pieczko | d94619c | 2015-06-02 11:40:05 +0100 | [diff] [blame] | 1234 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1235 | u64 raw_mask[2]; |
| 1236 | |
| 1237 | raw_mask[0] = efx_ef10_raw_stat_mask(efx); |
| 1238 | |
Daniel Pieczko | d94619c | 2015-06-02 11:40:05 +0100 | [diff] [blame] | 1239 | /* Only show vadaptor stats when EVB capability is present */ |
| 1240 | if (nic_data->datapath_caps & |
| 1241 | (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) { |
| 1242 | raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1); |
| 1243 | raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1; |
| 1244 | } else { |
| 1245 | raw_mask[1] = 0; |
| 1246 | } |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1247 | |
| 1248 | #if BITS_PER_LONG == 64 |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1249 | mask[0] = raw_mask[0]; |
| 1250 | mask[1] = raw_mask[1]; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1251 | #else |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1252 | mask[0] = raw_mask[0] & 0xffffffff; |
| 1253 | mask[1] = raw_mask[0] >> 32; |
| 1254 | mask[2] = raw_mask[1] & 0xffffffff; |
| 1255 | mask[3] = raw_mask[1] >> 32; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1256 | #endif |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) |
| 1260 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1261 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1262 | |
| 1263 | efx_ef10_get_stat_mask(efx, mask); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1264 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1265 | mask, names); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1268 | static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats, |
| 1269 | struct rtnl_link_stats64 *core_stats) |
| 1270 | { |
| 1271 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1272 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1273 | u64 *stats = nic_data->stats; |
| 1274 | size_t stats_count = 0, index; |
| 1275 | |
| 1276 | efx_ef10_get_stat_mask(efx, mask); |
| 1277 | |
| 1278 | if (full_stats) { |
| 1279 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { |
| 1280 | if (efx_ef10_stat_desc[index].name) { |
| 1281 | *full_stats++ = stats[index]; |
| 1282 | ++stats_count; |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | if (core_stats) { |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1288 | core_stats->rx_packets = stats[EF10_STAT_rx_unicast] + |
| 1289 | stats[EF10_STAT_rx_multicast] + |
| 1290 | stats[EF10_STAT_rx_broadcast]; |
| 1291 | core_stats->tx_packets = stats[EF10_STAT_tx_unicast] + |
| 1292 | stats[EF10_STAT_tx_multicast] + |
| 1293 | stats[EF10_STAT_tx_broadcast]; |
| 1294 | core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] + |
| 1295 | stats[EF10_STAT_rx_multicast_bytes] + |
| 1296 | stats[EF10_STAT_rx_broadcast_bytes]; |
| 1297 | core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] + |
| 1298 | stats[EF10_STAT_tx_multicast_bytes] + |
| 1299 | stats[EF10_STAT_tx_broadcast_bytes]; |
| 1300 | core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] + |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1301 | stats[GENERIC_STAT_rx_noskb_drops]; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1302 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
| 1303 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; |
| 1304 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; |
| 1305 | core_stats->rx_errors = core_stats->rx_crc_errors; |
| 1306 | core_stats->tx_errors = stats[EF10_STAT_tx_bad]; |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | return stats_count; |
| 1310 | } |
| 1311 | |
| 1312 | static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1313 | { |
| 1314 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1315 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1316 | __le64 generation_start, generation_end; |
| 1317 | u64 *stats = nic_data->stats; |
| 1318 | __le64 *dma_stats; |
| 1319 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1320 | efx_ef10_get_stat_mask(efx, mask); |
| 1321 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1322 | dma_stats = efx->stats_buffer.addr; |
| 1323 | nic_data = efx->nic_data; |
| 1324 | |
| 1325 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; |
| 1326 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) |
| 1327 | return 0; |
| 1328 | rmb(); |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1329 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1330 | stats, efx->stats_buffer.addr, false); |
Jon Cooper | d546a89 | 2013-09-27 18:26:30 +0100 | [diff] [blame] | 1331 | rmb(); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1332 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
| 1333 | if (generation_end != generation_start) |
| 1334 | return -EAGAIN; |
| 1335 | |
| 1336 | /* Update derived statistics */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1337 | efx_nic_fix_nodesc_drop_stat(efx, |
| 1338 | &stats[EF10_STAT_port_rx_nodesc_drops]); |
| 1339 | stats[EF10_STAT_port_rx_good_bytes] = |
| 1340 | stats[EF10_STAT_port_rx_bytes] - |
| 1341 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]; |
| 1342 | efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes], |
| 1343 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]); |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1344 | efx_update_sw_stats(efx, stats); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1349 | static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats, |
| 1350 | struct rtnl_link_stats64 *core_stats) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1351 | { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1352 | int retry; |
| 1353 | |
| 1354 | /* If we're unlucky enough to read statistics during the DMA, wait |
| 1355 | * up to 10ms for it to finish (typically takes <500us) |
| 1356 | */ |
| 1357 | for (retry = 0; retry < 100; ++retry) { |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1358 | if (efx_ef10_try_update_nic_stats_pf(efx) == 0) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1359 | break; |
| 1360 | udelay(100); |
| 1361 | } |
| 1362 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1363 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
| 1364 | } |
| 1365 | |
| 1366 | static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx) |
| 1367 | { |
| 1368 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN); |
| 1369 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1370 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1371 | __le64 generation_start, generation_end; |
| 1372 | u64 *stats = nic_data->stats; |
| 1373 | u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64); |
| 1374 | struct efx_buffer stats_buf; |
| 1375 | __le64 *dma_stats; |
| 1376 | int rc; |
| 1377 | |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1378 | spin_unlock_bh(&efx->stats_lock); |
| 1379 | |
| 1380 | if (in_interrupt()) { |
| 1381 | /* If in atomic context, cannot update stats. Just update the |
| 1382 | * software stats and return so the caller can continue. |
| 1383 | */ |
| 1384 | spin_lock_bh(&efx->stats_lock); |
| 1385 | efx_update_sw_stats(efx, stats); |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1389 | efx_ef10_get_stat_mask(efx, mask); |
| 1390 | |
| 1391 | rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC); |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1392 | if (rc) { |
| 1393 | spin_lock_bh(&efx->stats_lock); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1394 | return rc; |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1395 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1396 | |
| 1397 | dma_stats = stats_buf.addr; |
| 1398 | dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID; |
| 1399 | |
| 1400 | MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr); |
| 1401 | MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD, |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1402 | MAC_STATS_IN_DMA, 1); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1403 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
| 1404 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); |
| 1405 | |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1406 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), |
| 1407 | NULL, 0, NULL); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1408 | spin_lock_bh(&efx->stats_lock); |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1409 | if (rc) { |
| 1410 | /* Expect ENOENT if DMA queues have not been set up */ |
| 1411 | if (rc != -ENOENT || atomic_read(&efx->active_queues)) |
| 1412 | efx_mcdi_display_error(efx, MC_CMD_MAC_STATS, |
| 1413 | sizeof(inbuf), NULL, 0, rc); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1414 | goto out; |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1415 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1416 | |
| 1417 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1418 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) { |
| 1419 | WARN_ON_ONCE(1); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1420 | goto out; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1421 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1422 | rmb(); |
| 1423 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
| 1424 | stats, stats_buf.addr, false); |
| 1425 | rmb(); |
| 1426 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
| 1427 | if (generation_end != generation_start) { |
| 1428 | rc = -EAGAIN; |
| 1429 | goto out; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1432 | efx_update_sw_stats(efx, stats); |
| 1433 | out: |
| 1434 | efx_nic_free_buffer(efx, &stats_buf); |
| 1435 | return rc; |
| 1436 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1437 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1438 | static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats, |
| 1439 | struct rtnl_link_stats64 *core_stats) |
| 1440 | { |
| 1441 | if (efx_ef10_try_update_nic_stats_vf(efx)) |
| 1442 | return 0; |
| 1443 | |
| 1444 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) |
| 1448 | { |
| 1449 | struct efx_nic *efx = channel->efx; |
| 1450 | unsigned int mode, value; |
| 1451 | efx_dword_t timer_cmd; |
| 1452 | |
| 1453 | if (channel->irq_moderation) { |
| 1454 | mode = 3; |
| 1455 | value = channel->irq_moderation - 1; |
| 1456 | } else { |
| 1457 | mode = 0; |
| 1458 | value = 0; |
| 1459 | } |
| 1460 | |
| 1461 | if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 1462 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, |
| 1463 | EFE_DD_EVQ_IND_TIMER_FLAGS, |
| 1464 | ERF_DD_EVQ_IND_TIMER_MODE, mode, |
| 1465 | ERF_DD_EVQ_IND_TIMER_VAL, value); |
| 1466 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, |
| 1467 | channel->channel); |
| 1468 | } else { |
| 1469 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, |
| 1470 | ERF_DZ_TC_TIMER_VAL, value); |
| 1471 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, |
| 1472 | channel->channel); |
| 1473 | } |
| 1474 | } |
| 1475 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1476 | static void efx_ef10_get_wol_vf(struct efx_nic *efx, |
| 1477 | struct ethtool_wolinfo *wol) {} |
| 1478 | |
| 1479 | static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type) |
| 1480 | { |
| 1481 | return -EOPNOTSUPP; |
| 1482 | } |
| 1483 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1484 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 1485 | { |
| 1486 | wol->supported = 0; |
| 1487 | wol->wolopts = 0; |
| 1488 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 1489 | } |
| 1490 | |
| 1491 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) |
| 1492 | { |
| 1493 | if (type != 0) |
| 1494 | return -EINVAL; |
| 1495 | return 0; |
| 1496 | } |
| 1497 | |
| 1498 | static void efx_ef10_mcdi_request(struct efx_nic *efx, |
| 1499 | const efx_dword_t *hdr, size_t hdr_len, |
| 1500 | const efx_dword_t *sdu, size_t sdu_len) |
| 1501 | { |
| 1502 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1503 | u8 *pdu = nic_data->mcdi_buf.addr; |
| 1504 | |
| 1505 | memcpy(pdu, hdr, hdr_len); |
| 1506 | memcpy(pdu + hdr_len, sdu, sdu_len); |
| 1507 | wmb(); |
| 1508 | |
| 1509 | /* The hardware provides 'low' and 'high' (doorbell) registers |
| 1510 | * for passing the 64-bit address of an MCDI request to |
| 1511 | * firmware. However the dwords are swapped by firmware. The |
| 1512 | * least significant bits of the doorbell are then 0 for all |
| 1513 | * MCDI requests due to alignment. |
| 1514 | */ |
| 1515 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), |
| 1516 | ER_DZ_MC_DB_LWRD); |
| 1517 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), |
| 1518 | ER_DZ_MC_DB_HWRD); |
| 1519 | } |
| 1520 | |
| 1521 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) |
| 1522 | { |
| 1523 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1524 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; |
| 1525 | |
| 1526 | rmb(); |
| 1527 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); |
| 1528 | } |
| 1529 | |
| 1530 | static void |
| 1531 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, |
| 1532 | size_t offset, size_t outlen) |
| 1533 | { |
| 1534 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1535 | const u8 *pdu = nic_data->mcdi_buf.addr; |
| 1536 | |
| 1537 | memcpy(outbuf, pdu + offset, outlen); |
| 1538 | } |
| 1539 | |
| 1540 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) |
| 1541 | { |
| 1542 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1543 | int rc; |
| 1544 | |
| 1545 | rc = efx_ef10_get_warm_boot_count(efx); |
| 1546 | if (rc < 0) { |
| 1547 | /* The firmware is presumably in the process of |
| 1548 | * rebooting. However, we are supposed to report each |
| 1549 | * reboot just once, so we must only do that once we |
| 1550 | * can read and store the updated warm boot count. |
| 1551 | */ |
| 1552 | return 0; |
| 1553 | } |
| 1554 | |
| 1555 | if (rc == nic_data->warm_boot_count) |
| 1556 | return 0; |
| 1557 | |
| 1558 | nic_data->warm_boot_count = rc; |
| 1559 | |
| 1560 | /* All our allocations have been reset */ |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1561 | efx_ef10_reset_mc_allocations(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1562 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 1563 | /* Driver-created vswitches and vports must be re-created */ |
| 1564 | nic_data->must_probe_vswitching = true; |
| 1565 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 1566 | |
Ben Hutchings | a915ccc | 2013-09-05 22:51:55 +0100 | [diff] [blame] | 1567 | /* The datapath firmware might have been changed */ |
| 1568 | nic_data->must_check_datapath_caps = true; |
| 1569 | |
Ben Hutchings | 869070c | 2013-09-05 22:46:10 +0100 | [diff] [blame] | 1570 | /* MAC statistics have been cleared on the NIC; clear the local |
| 1571 | * statistic that we update with efx_update_diff_stat(). |
| 1572 | */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1573 | nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0; |
Ben Hutchings | 869070c | 2013-09-05 22:46:10 +0100 | [diff] [blame] | 1574 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1575 | return -EIO; |
| 1576 | } |
| 1577 | |
| 1578 | /* Handle an MSI interrupt |
| 1579 | * |
| 1580 | * Handle an MSI hardware interrupt. This routine schedules event |
| 1581 | * queue processing. No interrupt acknowledgement cycle is necessary. |
| 1582 | * Also, we never need to check that the interrupt is for us, since |
| 1583 | * MSI interrupts cannot be shared. |
| 1584 | */ |
| 1585 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) |
| 1586 | { |
| 1587 | struct efx_msi_context *context = dev_id; |
| 1588 | struct efx_nic *efx = context->efx; |
| 1589 | |
| 1590 | netif_vdbg(efx, intr, efx->net_dev, |
| 1591 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); |
| 1592 | |
| 1593 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { |
| 1594 | /* Note test interrupts */ |
| 1595 | if (context->index == efx->irq_level) |
| 1596 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 1597 | |
| 1598 | /* Schedule processing of the channel */ |
| 1599 | efx_schedule_channel_irq(efx->channel[context->index]); |
| 1600 | } |
| 1601 | |
| 1602 | return IRQ_HANDLED; |
| 1603 | } |
| 1604 | |
| 1605 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) |
| 1606 | { |
| 1607 | struct efx_nic *efx = dev_id; |
| 1608 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); |
| 1609 | struct efx_channel *channel; |
| 1610 | efx_dword_t reg; |
| 1611 | u32 queues; |
| 1612 | |
| 1613 | /* Read the ISR which also ACKs the interrupts */ |
| 1614 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); |
| 1615 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); |
| 1616 | |
| 1617 | if (queues == 0) |
| 1618 | return IRQ_NONE; |
| 1619 | |
| 1620 | if (likely(soft_enabled)) { |
| 1621 | /* Note test interrupts */ |
| 1622 | if (queues & (1U << efx->irq_level)) |
| 1623 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 1624 | |
| 1625 | efx_for_each_channel(channel, efx) { |
| 1626 | if (queues & 1) |
| 1627 | efx_schedule_channel_irq(channel); |
| 1628 | queues >>= 1; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | netif_vdbg(efx, intr, efx->net_dev, |
| 1633 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", |
| 1634 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); |
| 1635 | |
| 1636 | return IRQ_HANDLED; |
| 1637 | } |
| 1638 | |
| 1639 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) |
| 1640 | { |
| 1641 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); |
| 1642 | |
| 1643 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); |
| 1644 | |
| 1645 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); |
| 1646 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, |
| 1647 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 1648 | } |
| 1649 | |
| 1650 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) |
| 1651 | { |
| 1652 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, |
| 1653 | (tx_queue->ptr_mask + 1) * |
| 1654 | sizeof(efx_qword_t), |
| 1655 | GFP_KERNEL); |
| 1656 | } |
| 1657 | |
| 1658 | /* This writes to the TX_DESC_WPTR and also pushes data */ |
| 1659 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, |
| 1660 | const efx_qword_t *txd) |
| 1661 | { |
| 1662 | unsigned int write_ptr; |
| 1663 | efx_oword_t reg; |
| 1664 | |
| 1665 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1666 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); |
| 1667 | reg.qword[0] = *txd; |
| 1668 | efx_writeo_page(tx_queue->efx, ®, |
| 1669 | ER_DZ_TX_DESC_UPD, tx_queue->queue); |
| 1670 | } |
| 1671 | |
| 1672 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) |
| 1673 | { |
| 1674 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 1675 | EFX_BUF_SIZE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1676 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
| 1677 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; |
| 1678 | struct efx_channel *channel = tx_queue->channel; |
| 1679 | struct efx_nic *efx = tx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 1680 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 1681 | size_t inlen; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1682 | dma_addr_t dma_addr; |
| 1683 | efx_qword_t *txd; |
| 1684 | int rc; |
| 1685 | int i; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 1686 | BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1687 | |
| 1688 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); |
| 1689 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); |
| 1690 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); |
| 1691 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); |
| 1692 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, |
| 1693 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, |
| 1694 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); |
| 1695 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 1696 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1697 | |
| 1698 | dma_addr = tx_queue->txd.buf.dma_addr; |
| 1699 | |
| 1700 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", |
| 1701 | tx_queue->queue, entries, (u64)dma_addr); |
| 1702 | |
| 1703 | for (i = 0; i < entries; ++i) { |
| 1704 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); |
| 1705 | dma_addr += EFX_BUF_SIZE; |
| 1706 | } |
| 1707 | |
| 1708 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); |
| 1709 | |
| 1710 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 1711 | NULL, 0, NULL); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1712 | if (rc) |
| 1713 | goto fail; |
| 1714 | |
| 1715 | /* A previous user of this TX queue might have set us up the |
| 1716 | * bomb by writing a descriptor to the TX push collector but |
| 1717 | * not the doorbell. (Each collector belongs to a port, not a |
| 1718 | * queue or function, so cannot easily be reset.) We must |
| 1719 | * attempt to push a no-op descriptor in its place. |
| 1720 | */ |
| 1721 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; |
| 1722 | tx_queue->insert_count = 1; |
| 1723 | txd = efx_tx_desc(tx_queue, 0); |
| 1724 | EFX_POPULATE_QWORD_4(*txd, |
| 1725 | ESF_DZ_TX_DESC_IS_OPT, true, |
| 1726 | ESF_DZ_TX_OPTION_TYPE, |
| 1727 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, |
| 1728 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, |
| 1729 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); |
| 1730 | tx_queue->write_count = 1; |
| 1731 | wmb(); |
| 1732 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 1733 | |
| 1734 | return; |
| 1735 | |
| 1736 | fail: |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 1737 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
| 1738 | tx_queue->queue); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) |
| 1742 | { |
| 1743 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 1744 | MCDI_DECLARE_BUF_ERR(outbuf); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1745 | struct efx_nic *efx = tx_queue->efx; |
| 1746 | size_t outlen; |
| 1747 | int rc; |
| 1748 | |
| 1749 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, |
| 1750 | tx_queue->queue); |
| 1751 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1752 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1753 | outbuf, sizeof(outbuf), &outlen); |
| 1754 | |
| 1755 | if (rc && rc != -EALREADY) |
| 1756 | goto fail; |
| 1757 | |
| 1758 | return; |
| 1759 | |
| 1760 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1761 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
| 1762 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) |
| 1766 | { |
| 1767 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); |
| 1768 | } |
| 1769 | |
| 1770 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ |
| 1771 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) |
| 1772 | { |
| 1773 | unsigned int write_ptr; |
| 1774 | efx_dword_t reg; |
| 1775 | |
| 1776 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1777 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); |
| 1778 | efx_writed_page(tx_queue->efx, ®, |
| 1779 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); |
| 1780 | } |
| 1781 | |
| 1782 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) |
| 1783 | { |
| 1784 | unsigned int old_write_count = tx_queue->write_count; |
| 1785 | struct efx_tx_buffer *buffer; |
| 1786 | unsigned int write_ptr; |
| 1787 | efx_qword_t *txd; |
| 1788 | |
| 1789 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); |
| 1790 | |
| 1791 | do { |
| 1792 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1793 | buffer = &tx_queue->buffer[write_ptr]; |
| 1794 | txd = efx_tx_desc(tx_queue, write_ptr); |
| 1795 | ++tx_queue->write_count; |
| 1796 | |
| 1797 | /* Create TX descriptor ring entry */ |
| 1798 | if (buffer->flags & EFX_TX_BUF_OPTION) { |
| 1799 | *txd = buffer->option; |
| 1800 | } else { |
| 1801 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); |
| 1802 | EFX_POPULATE_QWORD_3( |
| 1803 | *txd, |
| 1804 | ESF_DZ_TX_KER_CONT, |
| 1805 | buffer->flags & EFX_TX_BUF_CONT, |
| 1806 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, |
| 1807 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); |
| 1808 | } |
| 1809 | } while (tx_queue->write_count != tx_queue->insert_count); |
| 1810 | |
| 1811 | wmb(); /* Ensure descriptors are written before they are fetched */ |
| 1812 | |
| 1813 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { |
| 1814 | txd = efx_tx_desc(tx_queue, |
| 1815 | old_write_count & tx_queue->ptr_mask); |
| 1816 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 1817 | ++tx_queue->pushes; |
| 1818 | } else { |
| 1819 | efx_ef10_notify_tx_desc(tx_queue); |
| 1820 | } |
| 1821 | } |
| 1822 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1823 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context, |
| 1824 | bool exclusive, unsigned *context_size) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1825 | { |
| 1826 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); |
| 1827 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 1828 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1829 | size_t outlen; |
| 1830 | int rc; |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1831 | u32 alloc_type = exclusive ? |
| 1832 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE : |
| 1833 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED; |
| 1834 | unsigned rss_spread = exclusive ? |
| 1835 | efx->rss_spread : |
| 1836 | min(rounddown_pow_of_two(efx->rss_spread), |
| 1837 | EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE); |
| 1838 | |
| 1839 | if (!exclusive && rss_spread == 1) { |
| 1840 | *context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 1841 | if (context_size) |
| 1842 | *context_size = 1; |
| 1843 | return 0; |
| 1844 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1845 | |
| 1846 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 1847 | nic_data->vport_id); |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1848 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type); |
| 1849 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1850 | |
| 1851 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), |
| 1852 | outbuf, sizeof(outbuf), &outlen); |
| 1853 | if (rc != 0) |
| 1854 | return rc; |
| 1855 | |
| 1856 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) |
| 1857 | return -EIO; |
| 1858 | |
| 1859 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); |
| 1860 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1861 | if (context_size) |
| 1862 | *context_size = rss_spread; |
| 1863 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1864 | return 0; |
| 1865 | } |
| 1866 | |
| 1867 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) |
| 1868 | { |
| 1869 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); |
| 1870 | int rc; |
| 1871 | |
| 1872 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, |
| 1873 | context); |
| 1874 | |
| 1875 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), |
| 1876 | NULL, 0, NULL); |
| 1877 | WARN_ON(rc != 0); |
| 1878 | } |
| 1879 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1880 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context, |
| 1881 | const u32 *rx_indir_table) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1882 | { |
| 1883 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); |
| 1884 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); |
| 1885 | int i, rc; |
| 1886 | |
| 1887 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, |
| 1888 | context); |
| 1889 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != |
| 1890 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); |
| 1891 | |
| 1892 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) |
| 1893 | MCDI_PTR(tablebuf, |
| 1894 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1895 | (u8) rx_indir_table[i]; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1896 | |
| 1897 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, |
| 1898 | sizeof(tablebuf), NULL, 0, NULL); |
| 1899 | if (rc != 0) |
| 1900 | return rc; |
| 1901 | |
| 1902 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, |
| 1903 | context); |
| 1904 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != |
| 1905 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); |
| 1906 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) |
| 1907 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = |
| 1908 | efx->rx_hash_key[i]; |
| 1909 | |
| 1910 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, |
| 1911 | sizeof(keybuf), NULL, 0, NULL); |
| 1912 | } |
| 1913 | |
| 1914 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) |
| 1915 | { |
| 1916 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1917 | |
| 1918 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) |
| 1919 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); |
| 1920 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 1921 | } |
| 1922 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1923 | static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx, |
| 1924 | unsigned *context_size) |
| 1925 | { |
| 1926 | u32 new_rx_rss_context; |
| 1927 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1928 | int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
| 1929 | false, context_size); |
| 1930 | |
| 1931 | if (rc != 0) |
| 1932 | return rc; |
| 1933 | |
| 1934 | nic_data->rx_rss_context = new_rx_rss_context; |
| 1935 | nic_data->rx_rss_context_exclusive = false; |
| 1936 | efx_set_default_rx_indir_table(efx); |
| 1937 | return 0; |
| 1938 | } |
| 1939 | |
| 1940 | static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx, |
| 1941 | const u32 *rx_indir_table) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1942 | { |
| 1943 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1944 | int rc; |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1945 | u32 new_rx_rss_context; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1946 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1947 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID || |
| 1948 | !nic_data->rx_rss_context_exclusive) { |
| 1949 | rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
| 1950 | true, NULL); |
| 1951 | if (rc == -EOPNOTSUPP) |
| 1952 | return rc; |
| 1953 | else if (rc != 0) |
| 1954 | goto fail1; |
| 1955 | } else { |
| 1956 | new_rx_rss_context = nic_data->rx_rss_context; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1959 | rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context, |
| 1960 | rx_indir_table); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1961 | if (rc != 0) |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1962 | goto fail2; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1963 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1964 | if (nic_data->rx_rss_context != new_rx_rss_context) |
| 1965 | efx_ef10_rx_free_indir_table(efx); |
| 1966 | nic_data->rx_rss_context = new_rx_rss_context; |
| 1967 | nic_data->rx_rss_context_exclusive = true; |
| 1968 | if (rx_indir_table != efx->rx_indir_table) |
| 1969 | memcpy(efx->rx_indir_table, rx_indir_table, |
| 1970 | sizeof(efx->rx_indir_table)); |
| 1971 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1972 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1973 | fail2: |
| 1974 | if (new_rx_rss_context != nic_data->rx_rss_context) |
| 1975 | efx_ef10_free_rss_context(efx, new_rx_rss_context); |
| 1976 | fail1: |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1977 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1978 | return rc; |
| 1979 | } |
| 1980 | |
| 1981 | static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user, |
| 1982 | const u32 *rx_indir_table) |
| 1983 | { |
| 1984 | int rc; |
| 1985 | |
| 1986 | if (efx->rss_spread == 1) |
| 1987 | return 0; |
| 1988 | |
| 1989 | rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table); |
| 1990 | |
| 1991 | if (rc == -ENOBUFS && !user) { |
| 1992 | unsigned context_size; |
| 1993 | bool mismatch = false; |
| 1994 | size_t i; |
| 1995 | |
| 1996 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch; |
| 1997 | i++) |
| 1998 | mismatch = rx_indir_table[i] != |
| 1999 | ethtool_rxfh_indir_default(i, efx->rss_spread); |
| 2000 | |
| 2001 | rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size); |
| 2002 | if (rc == 0) { |
| 2003 | if (context_size != efx->rss_spread) |
| 2004 | netif_warn(efx, probe, efx->net_dev, |
| 2005 | "Could not allocate an exclusive RSS" |
| 2006 | " context; allocated a shared one of" |
| 2007 | " different size." |
| 2008 | " Wanted %u, got %u.\n", |
| 2009 | efx->rss_spread, context_size); |
| 2010 | else if (mismatch) |
| 2011 | netif_warn(efx, probe, efx->net_dev, |
| 2012 | "Could not allocate an exclusive RSS" |
| 2013 | " context; allocated a shared one but" |
| 2014 | " could not apply custom" |
| 2015 | " indirection.\n"); |
| 2016 | else |
| 2017 | netif_info(efx, probe, efx->net_dev, |
| 2018 | "Could not allocate an exclusive RSS" |
| 2019 | " context; allocated a shared one.\n"); |
| 2020 | } |
| 2021 | } |
| 2022 | return rc; |
| 2023 | } |
| 2024 | |
| 2025 | static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user, |
| 2026 | const u32 *rx_indir_table |
| 2027 | __attribute__ ((unused))) |
| 2028 | { |
| 2029 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2030 | |
| 2031 | if (user) |
| 2032 | return -EOPNOTSUPP; |
| 2033 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) |
| 2034 | return 0; |
| 2035 | return efx_ef10_rx_push_shared_rss_config(efx, NULL); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) |
| 2039 | { |
| 2040 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, |
| 2041 | (rx_queue->ptr_mask + 1) * |
| 2042 | sizeof(efx_qword_t), |
| 2043 | GFP_KERNEL); |
| 2044 | } |
| 2045 | |
| 2046 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) |
| 2047 | { |
| 2048 | MCDI_DECLARE_BUF(inbuf, |
| 2049 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 2050 | EFX_BUF_SIZE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2051 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 2052 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; |
| 2053 | struct efx_nic *efx = rx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2054 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2055 | size_t inlen; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2056 | dma_addr_t dma_addr; |
| 2057 | int rc; |
| 2058 | int i; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2059 | BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2060 | |
| 2061 | rx_queue->scatter_n = 0; |
| 2062 | rx_queue->scatter_len = 0; |
| 2063 | |
| 2064 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); |
| 2065 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); |
| 2066 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); |
| 2067 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, |
| 2068 | efx_rx_queue_index(rx_queue)); |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 2069 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
| 2070 | INIT_RXQ_IN_FLAG_PREFIX, 1, |
| 2071 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2072 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2073 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2074 | |
| 2075 | dma_addr = rx_queue->rxd.buf.dma_addr; |
| 2076 | |
| 2077 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", |
| 2078 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); |
| 2079 | |
| 2080 | for (i = 0; i < entries; ++i) { |
| 2081 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); |
| 2082 | dma_addr += EFX_BUF_SIZE; |
| 2083 | } |
| 2084 | |
| 2085 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); |
| 2086 | |
| 2087 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2088 | NULL, 0, NULL); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 2089 | if (rc) |
| 2090 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", |
| 2091 | efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) |
| 2095 | { |
| 2096 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2097 | MCDI_DECLARE_BUF_ERR(outbuf); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2098 | struct efx_nic *efx = rx_queue->efx; |
| 2099 | size_t outlen; |
| 2100 | int rc; |
| 2101 | |
| 2102 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, |
| 2103 | efx_rx_queue_index(rx_queue)); |
| 2104 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2105 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2106 | outbuf, sizeof(outbuf), &outlen); |
| 2107 | |
| 2108 | if (rc && rc != -EALREADY) |
| 2109 | goto fail; |
| 2110 | |
| 2111 | return; |
| 2112 | |
| 2113 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2114 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
| 2115 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) |
| 2119 | { |
| 2120 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); |
| 2121 | } |
| 2122 | |
| 2123 | /* This creates an entry in the RX descriptor queue */ |
| 2124 | static inline void |
| 2125 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) |
| 2126 | { |
| 2127 | struct efx_rx_buffer *rx_buf; |
| 2128 | efx_qword_t *rxd; |
| 2129 | |
| 2130 | rxd = efx_rx_desc(rx_queue, index); |
| 2131 | rx_buf = efx_rx_buffer(rx_queue, index); |
| 2132 | EFX_POPULATE_QWORD_2(*rxd, |
| 2133 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, |
| 2134 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); |
| 2135 | } |
| 2136 | |
| 2137 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) |
| 2138 | { |
| 2139 | struct efx_nic *efx = rx_queue->efx; |
| 2140 | unsigned int write_count; |
| 2141 | efx_dword_t reg; |
| 2142 | |
| 2143 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ |
| 2144 | write_count = rx_queue->added_count & ~7; |
| 2145 | if (rx_queue->notified_count == write_count) |
| 2146 | return; |
| 2147 | |
| 2148 | do |
| 2149 | efx_ef10_build_rx_desc( |
| 2150 | rx_queue, |
| 2151 | rx_queue->notified_count & rx_queue->ptr_mask); |
| 2152 | while (++rx_queue->notified_count != write_count); |
| 2153 | |
| 2154 | wmb(); |
| 2155 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, |
| 2156 | write_count & rx_queue->ptr_mask); |
| 2157 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, |
| 2158 | efx_rx_queue_index(rx_queue)); |
| 2159 | } |
| 2160 | |
| 2161 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; |
| 2162 | |
| 2163 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) |
| 2164 | { |
| 2165 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 2166 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 2167 | efx_qword_t event; |
| 2168 | |
| 2169 | EFX_POPULATE_QWORD_2(event, |
| 2170 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 2171 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); |
| 2172 | |
| 2173 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 2174 | |
| 2175 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 2176 | * already swapped the data to little-endian order. |
| 2177 | */ |
| 2178 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 2179 | sizeof(efx_qword_t)); |
| 2180 | |
| 2181 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, |
| 2182 | inbuf, sizeof(inbuf), 0, |
| 2183 | efx_ef10_rx_defer_refill_complete, 0); |
| 2184 | } |
| 2185 | |
| 2186 | static void |
| 2187 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, |
| 2188 | int rc, efx_dword_t *outbuf, |
| 2189 | size_t outlen_actual) |
| 2190 | { |
| 2191 | /* nothing to do */ |
| 2192 | } |
| 2193 | |
| 2194 | static int efx_ef10_ev_probe(struct efx_channel *channel) |
| 2195 | { |
| 2196 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, |
| 2197 | (channel->eventq_mask + 1) * |
| 2198 | sizeof(efx_qword_t), |
| 2199 | GFP_KERNEL); |
| 2200 | } |
| 2201 | |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2202 | static void efx_ef10_ev_fini(struct efx_channel *channel) |
| 2203 | { |
| 2204 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); |
| 2205 | MCDI_DECLARE_BUF_ERR(outbuf); |
| 2206 | struct efx_nic *efx = channel->efx; |
| 2207 | size_t outlen; |
| 2208 | int rc; |
| 2209 | |
| 2210 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); |
| 2211 | |
| 2212 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
| 2213 | outbuf, sizeof(outbuf), &outlen); |
| 2214 | |
| 2215 | if (rc && rc != -EALREADY) |
| 2216 | goto fail; |
| 2217 | |
| 2218 | return; |
| 2219 | |
| 2220 | fail: |
| 2221 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
| 2222 | outbuf, outlen, rc); |
| 2223 | } |
| 2224 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2225 | static int efx_ef10_ev_init(struct efx_channel *channel) |
| 2226 | { |
| 2227 | MCDI_DECLARE_BUF(inbuf, |
| 2228 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / |
| 2229 | EFX_BUF_SIZE)); |
| 2230 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); |
| 2231 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; |
| 2232 | struct efx_nic *efx = channel->efx; |
| 2233 | struct efx_ef10_nic_data *nic_data; |
| 2234 | bool supports_rx_merge; |
| 2235 | size_t inlen, outlen; |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2236 | unsigned int enabled, implemented; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2237 | dma_addr_t dma_addr; |
| 2238 | int rc; |
| 2239 | int i; |
| 2240 | |
| 2241 | nic_data = efx->nic_data; |
| 2242 | supports_rx_merge = |
| 2243 | !!(nic_data->datapath_caps & |
| 2244 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); |
| 2245 | |
| 2246 | /* Fill event queue with all ones (i.e. empty events) */ |
| 2247 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); |
| 2248 | |
| 2249 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); |
| 2250 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); |
| 2251 | /* INIT_EVQ expects index in vector table, not absolute */ |
| 2252 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); |
| 2253 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, |
| 2254 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, |
| 2255 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, |
| 2256 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, |
| 2257 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); |
| 2258 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, |
| 2259 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); |
| 2260 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); |
| 2261 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); |
| 2262 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, |
| 2263 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); |
| 2264 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); |
| 2265 | |
| 2266 | dma_addr = channel->eventq.buf.dma_addr; |
| 2267 | for (i = 0; i < entries; ++i) { |
| 2268 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); |
| 2269 | dma_addr += EFX_BUF_SIZE; |
| 2270 | } |
| 2271 | |
| 2272 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); |
| 2273 | |
| 2274 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, |
| 2275 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2276 | /* IRQ return is ignored */ |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2277 | if (channel->channel || rc) |
| 2278 | return rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2279 | |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2280 | /* Successfully created event queue on channel 0 */ |
| 2281 | rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled); |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2282 | if (rc == -ENOSYS) { |
| 2283 | /* GET_WORKAROUNDS was implemented before the bug26807 |
| 2284 | * workaround, thus the latter must be unavailable in this fw |
| 2285 | */ |
| 2286 | nic_data->workaround_26807 = false; |
| 2287 | rc = 0; |
| 2288 | } else if (rc) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2289 | goto fail; |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2290 | } else { |
| 2291 | nic_data->workaround_26807 = |
| 2292 | !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2293 | |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2294 | if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 && |
| 2295 | !nic_data->workaround_26807) { |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 2296 | unsigned int flags; |
| 2297 | |
Daniel Pieczko | 34ccfe6 | 2015-07-21 15:09:43 +0100 | [diff] [blame] | 2298 | rc = efx_mcdi_set_workaround(efx, |
| 2299 | MC_CMD_WORKAROUND_BUG26807, |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 2300 | true, &flags); |
| 2301 | |
| 2302 | if (!rc) { |
| 2303 | if (flags & |
| 2304 | 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) { |
| 2305 | netif_info(efx, drv, efx->net_dev, |
| 2306 | "other functions on NIC have been reset\n"); |
| 2307 | /* MC's boot count has incremented */ |
| 2308 | ++nic_data->warm_boot_count; |
| 2309 | } |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2310 | nic_data->workaround_26807 = true; |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 2311 | } else if (rc == -EPERM) { |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2312 | rc = 0; |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 2313 | } |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 2314 | } |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | if (!rc) |
| 2318 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2319 | |
| 2320 | fail: |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2321 | efx_ef10_ev_fini(channel); |
| 2322 | return rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | static void efx_ef10_ev_remove(struct efx_channel *channel) |
| 2326 | { |
| 2327 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); |
| 2328 | } |
| 2329 | |
| 2330 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, |
| 2331 | unsigned int rx_queue_label) |
| 2332 | { |
| 2333 | struct efx_nic *efx = rx_queue->efx; |
| 2334 | |
| 2335 | netif_info(efx, hw, efx->net_dev, |
| 2336 | "rx event arrived on queue %d labeled as queue %u\n", |
| 2337 | efx_rx_queue_index(rx_queue), rx_queue_label); |
| 2338 | |
| 2339 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 2340 | } |
| 2341 | |
| 2342 | static void |
| 2343 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, |
| 2344 | unsigned int actual, unsigned int expected) |
| 2345 | { |
| 2346 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; |
| 2347 | struct efx_nic *efx = rx_queue->efx; |
| 2348 | |
| 2349 | netif_info(efx, hw, efx->net_dev, |
| 2350 | "dropped %d events (index=%d expected=%d)\n", |
| 2351 | dropped, actual, expected); |
| 2352 | |
| 2353 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 2354 | } |
| 2355 | |
| 2356 | /* partially received RX was aborted. clean up. */ |
| 2357 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) |
| 2358 | { |
| 2359 | unsigned int rx_desc_ptr; |
| 2360 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2361 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
| 2362 | "scattered RX aborted (dropping %u buffers)\n", |
| 2363 | rx_queue->scatter_n); |
| 2364 | |
| 2365 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; |
| 2366 | |
| 2367 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, |
| 2368 | 0, EFX_RX_PKT_DISCARD); |
| 2369 | |
| 2370 | rx_queue->removed_count += rx_queue->scatter_n; |
| 2371 | rx_queue->scatter_n = 0; |
| 2372 | rx_queue->scatter_len = 0; |
| 2373 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; |
| 2374 | } |
| 2375 | |
| 2376 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, |
| 2377 | const efx_qword_t *event) |
| 2378 | { |
| 2379 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; |
| 2380 | unsigned int n_descs, n_packets, i; |
| 2381 | struct efx_nic *efx = channel->efx; |
| 2382 | struct efx_rx_queue *rx_queue; |
| 2383 | bool rx_cont; |
| 2384 | u16 flags = 0; |
| 2385 | |
| 2386 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 2387 | return 0; |
| 2388 | |
| 2389 | /* Basic packet information */ |
| 2390 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); |
| 2391 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); |
| 2392 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); |
| 2393 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); |
| 2394 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); |
| 2395 | |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 2396 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
| 2397 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" |
| 2398 | EFX_QWORD_FMT "\n", |
| 2399 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2400 | |
| 2401 | rx_queue = efx_channel_get_rx_queue(channel); |
| 2402 | |
| 2403 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) |
| 2404 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); |
| 2405 | |
| 2406 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & |
| 2407 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 2408 | |
| 2409 | if (n_descs != rx_queue->scatter_n + 1) { |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 2410 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2411 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2412 | /* detect rx abort */ |
| 2413 | if (unlikely(n_descs == rx_queue->scatter_n)) { |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 2414 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
| 2415 | netdev_WARN(efx->net_dev, |
| 2416 | "invalid RX abort: scatter_n=%u event=" |
| 2417 | EFX_QWORD_FMT "\n", |
| 2418 | rx_queue->scatter_n, |
| 2419 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2420 | efx_ef10_handle_rx_abort(rx_queue); |
| 2421 | return 0; |
| 2422 | } |
| 2423 | |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 2424 | /* Check that RX completion merging is valid, i.e. |
| 2425 | * the current firmware supports it and this is a |
| 2426 | * non-scattered packet. |
| 2427 | */ |
| 2428 | if (!(nic_data->datapath_caps & |
| 2429 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || |
| 2430 | rx_queue->scatter_n != 0 || rx_cont) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2431 | efx_ef10_handle_rx_bad_lbits( |
| 2432 | rx_queue, next_ptr_lbits, |
| 2433 | (rx_queue->removed_count + |
| 2434 | rx_queue->scatter_n + 1) & |
| 2435 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 2436 | return 0; |
| 2437 | } |
| 2438 | |
| 2439 | /* Merged completion for multiple non-scattered packets */ |
| 2440 | rx_queue->scatter_n = 1; |
| 2441 | rx_queue->scatter_len = 0; |
| 2442 | n_packets = n_descs; |
| 2443 | ++channel->n_rx_merge_events; |
| 2444 | channel->n_rx_merge_packets += n_packets; |
| 2445 | flags |= EFX_RX_PKT_PREFIX_LEN; |
| 2446 | } else { |
| 2447 | ++rx_queue->scatter_n; |
| 2448 | rx_queue->scatter_len += rx_bytes; |
| 2449 | if (rx_cont) |
| 2450 | return 0; |
| 2451 | n_packets = 1; |
| 2452 | } |
| 2453 | |
| 2454 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) |
| 2455 | flags |= EFX_RX_PKT_DISCARD; |
| 2456 | |
| 2457 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { |
| 2458 | channel->n_rx_ip_hdr_chksum_err += n_packets; |
| 2459 | } else if (unlikely(EFX_QWORD_FIELD(*event, |
| 2460 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { |
| 2461 | channel->n_rx_tcp_udp_chksum_err += n_packets; |
| 2462 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || |
| 2463 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { |
| 2464 | flags |= EFX_RX_PKT_CSUMMED; |
| 2465 | } |
| 2466 | |
| 2467 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) |
| 2468 | flags |= EFX_RX_PKT_TCP; |
| 2469 | |
| 2470 | channel->irq_mod_score += 2 * n_packets; |
| 2471 | |
| 2472 | /* Handle received packet(s) */ |
| 2473 | for (i = 0; i < n_packets; i++) { |
| 2474 | efx_rx_packet(rx_queue, |
| 2475 | rx_queue->removed_count & rx_queue->ptr_mask, |
| 2476 | rx_queue->scatter_n, rx_queue->scatter_len, |
| 2477 | flags); |
| 2478 | rx_queue->removed_count += rx_queue->scatter_n; |
| 2479 | } |
| 2480 | |
| 2481 | rx_queue->scatter_n = 0; |
| 2482 | rx_queue->scatter_len = 0; |
| 2483 | |
| 2484 | return n_packets; |
| 2485 | } |
| 2486 | |
| 2487 | static int |
| 2488 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) |
| 2489 | { |
| 2490 | struct efx_nic *efx = channel->efx; |
| 2491 | struct efx_tx_queue *tx_queue; |
| 2492 | unsigned int tx_ev_desc_ptr; |
| 2493 | unsigned int tx_ev_q_label; |
| 2494 | int tx_descs = 0; |
| 2495 | |
| 2496 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 2497 | return 0; |
| 2498 | |
| 2499 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) |
| 2500 | return 0; |
| 2501 | |
| 2502 | /* Transmit completion */ |
| 2503 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); |
| 2504 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); |
| 2505 | tx_queue = efx_channel_get_tx_queue(channel, |
| 2506 | tx_ev_q_label % EFX_TXQ_TYPES); |
| 2507 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & |
| 2508 | tx_queue->ptr_mask); |
| 2509 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); |
| 2510 | |
| 2511 | return tx_descs; |
| 2512 | } |
| 2513 | |
| 2514 | static void |
| 2515 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) |
| 2516 | { |
| 2517 | struct efx_nic *efx = channel->efx; |
| 2518 | int subcode; |
| 2519 | |
| 2520 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); |
| 2521 | |
| 2522 | switch (subcode) { |
| 2523 | case ESE_DZ_DRV_TIMER_EV: |
| 2524 | case ESE_DZ_DRV_WAKE_UP_EV: |
| 2525 | break; |
| 2526 | case ESE_DZ_DRV_START_UP_EV: |
| 2527 | /* event queue init complete. ok. */ |
| 2528 | break; |
| 2529 | default: |
| 2530 | netif_err(efx, hw, efx->net_dev, |
| 2531 | "channel %d unknown driver event type %d" |
| 2532 | " (data " EFX_QWORD_FMT ")\n", |
| 2533 | channel->channel, subcode, |
| 2534 | EFX_QWORD_VAL(*event)); |
| 2535 | |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, |
| 2540 | efx_qword_t *event) |
| 2541 | { |
| 2542 | struct efx_nic *efx = channel->efx; |
| 2543 | u32 subcode; |
| 2544 | |
| 2545 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); |
| 2546 | |
| 2547 | switch (subcode) { |
| 2548 | case EFX_EF10_TEST: |
| 2549 | channel->event_test_cpu = raw_smp_processor_id(); |
| 2550 | break; |
| 2551 | case EFX_EF10_REFILL: |
| 2552 | /* The queue must be empty, so we won't receive any rx |
| 2553 | * events, so efx_process_channel() won't refill the |
| 2554 | * queue. Refill it here |
| 2555 | */ |
Jon Cooper | cce2879 | 2013-10-02 11:04:14 +0100 | [diff] [blame] | 2556 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2557 | break; |
| 2558 | default: |
| 2559 | netif_err(efx, hw, efx->net_dev, |
| 2560 | "channel %d unknown driver event type %u" |
| 2561 | " (data " EFX_QWORD_FMT ")\n", |
| 2562 | channel->channel, (unsigned) subcode, |
| 2563 | EFX_QWORD_VAL(*event)); |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) |
| 2568 | { |
| 2569 | struct efx_nic *efx = channel->efx; |
| 2570 | efx_qword_t event, *p_event; |
| 2571 | unsigned int read_ptr; |
| 2572 | int ev_code; |
| 2573 | int tx_descs = 0; |
| 2574 | int spent = 0; |
| 2575 | |
Eric W. Biederman | 75363a4 | 2014-03-14 18:11:22 -0700 | [diff] [blame] | 2576 | if (quota <= 0) |
| 2577 | return spent; |
| 2578 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2579 | read_ptr = channel->eventq_read_ptr; |
| 2580 | |
| 2581 | for (;;) { |
| 2582 | p_event = efx_event(channel, read_ptr); |
| 2583 | event = *p_event; |
| 2584 | |
| 2585 | if (!efx_event_present(&event)) |
| 2586 | break; |
| 2587 | |
| 2588 | EFX_SET_QWORD(*p_event); |
| 2589 | |
| 2590 | ++read_ptr; |
| 2591 | |
| 2592 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); |
| 2593 | |
| 2594 | netif_vdbg(efx, drv, efx->net_dev, |
| 2595 | "processing event on %d " EFX_QWORD_FMT "\n", |
| 2596 | channel->channel, EFX_QWORD_VAL(event)); |
| 2597 | |
| 2598 | switch (ev_code) { |
| 2599 | case ESE_DZ_EV_CODE_MCDI_EV: |
| 2600 | efx_mcdi_process_event(channel, &event); |
| 2601 | break; |
| 2602 | case ESE_DZ_EV_CODE_RX_EV: |
| 2603 | spent += efx_ef10_handle_rx_event(channel, &event); |
| 2604 | if (spent >= quota) { |
| 2605 | /* XXX can we split a merged event to |
| 2606 | * avoid going over-quota? |
| 2607 | */ |
| 2608 | spent = quota; |
| 2609 | goto out; |
| 2610 | } |
| 2611 | break; |
| 2612 | case ESE_DZ_EV_CODE_TX_EV: |
| 2613 | tx_descs += efx_ef10_handle_tx_event(channel, &event); |
| 2614 | if (tx_descs > efx->txq_entries) { |
| 2615 | spent = quota; |
| 2616 | goto out; |
| 2617 | } else if (++spent == quota) { |
| 2618 | goto out; |
| 2619 | } |
| 2620 | break; |
| 2621 | case ESE_DZ_EV_CODE_DRIVER_EV: |
| 2622 | efx_ef10_handle_driver_event(channel, &event); |
| 2623 | if (++spent == quota) |
| 2624 | goto out; |
| 2625 | break; |
| 2626 | case EFX_EF10_DRVGEN_EV: |
| 2627 | efx_ef10_handle_driver_generated_event(channel, &event); |
| 2628 | break; |
| 2629 | default: |
| 2630 | netif_err(efx, hw, efx->net_dev, |
| 2631 | "channel %d unknown event type %d" |
| 2632 | " (data " EFX_QWORD_FMT ")\n", |
| 2633 | channel->channel, ev_code, |
| 2634 | EFX_QWORD_VAL(event)); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | out: |
| 2639 | channel->eventq_read_ptr = read_ptr; |
| 2640 | return spent; |
| 2641 | } |
| 2642 | |
| 2643 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) |
| 2644 | { |
| 2645 | struct efx_nic *efx = channel->efx; |
| 2646 | efx_dword_t rptr; |
| 2647 | |
| 2648 | if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 2649 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < |
| 2650 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 2651 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > |
| 2652 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 2653 | |
| 2654 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 2655 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, |
| 2656 | ERF_DD_EVQ_IND_RPTR, |
| 2657 | (channel->eventq_read_ptr & |
| 2658 | channel->eventq_mask) >> |
| 2659 | ERF_DD_EVQ_IND_RPTR_WIDTH); |
| 2660 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 2661 | channel->channel); |
| 2662 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 2663 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, |
| 2664 | ERF_DD_EVQ_IND_RPTR, |
| 2665 | channel->eventq_read_ptr & |
| 2666 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); |
| 2667 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 2668 | channel->channel); |
| 2669 | } else { |
| 2670 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, |
| 2671 | channel->eventq_read_ptr & |
| 2672 | channel->eventq_mask); |
| 2673 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) |
| 2678 | { |
| 2679 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 2680 | struct efx_nic *efx = channel->efx; |
| 2681 | efx_qword_t event; |
| 2682 | int rc; |
| 2683 | |
| 2684 | EFX_POPULATE_QWORD_2(event, |
| 2685 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 2686 | ESF_DZ_EV_DATA, EFX_EF10_TEST); |
| 2687 | |
| 2688 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 2689 | |
| 2690 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 2691 | * already swapped the data to little-endian order. |
| 2692 | */ |
| 2693 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 2694 | sizeof(efx_qword_t)); |
| 2695 | |
| 2696 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), |
| 2697 | NULL, 0, NULL); |
| 2698 | if (rc != 0) |
| 2699 | goto fail; |
| 2700 | |
| 2701 | return; |
| 2702 | |
| 2703 | fail: |
| 2704 | WARN_ON(true); |
| 2705 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
| 2706 | } |
| 2707 | |
| 2708 | void efx_ef10_handle_drain_event(struct efx_nic *efx) |
| 2709 | { |
| 2710 | if (atomic_dec_and_test(&efx->active_queues)) |
| 2711 | wake_up(&efx->flush_wq); |
| 2712 | |
| 2713 | WARN_ON(atomic_read(&efx->active_queues) < 0); |
| 2714 | } |
| 2715 | |
| 2716 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) |
| 2717 | { |
| 2718 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2719 | struct efx_channel *channel; |
| 2720 | struct efx_tx_queue *tx_queue; |
| 2721 | struct efx_rx_queue *rx_queue; |
| 2722 | int pending; |
| 2723 | |
| 2724 | /* If the MC has just rebooted, the TX/RX queues will have already been |
| 2725 | * torn down, but efx->active_queues needs to be set to zero. |
| 2726 | */ |
| 2727 | if (nic_data->must_realloc_vis) { |
| 2728 | atomic_set(&efx->active_queues, 0); |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
| 2732 | /* Do not attempt to write to the NIC during EEH recovery */ |
| 2733 | if (efx->state != STATE_RECOVERY) { |
| 2734 | efx_for_each_channel(channel, efx) { |
| 2735 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 2736 | efx_ef10_rx_fini(rx_queue); |
| 2737 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 2738 | efx_ef10_tx_fini(tx_queue); |
| 2739 | } |
| 2740 | |
| 2741 | wait_event_timeout(efx->flush_wq, |
| 2742 | atomic_read(&efx->active_queues) == 0, |
| 2743 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); |
| 2744 | pending = atomic_read(&efx->active_queues); |
| 2745 | if (pending) { |
| 2746 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", |
| 2747 | pending); |
| 2748 | return -ETIMEDOUT; |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | return 0; |
| 2753 | } |
| 2754 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2755 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
| 2756 | { |
| 2757 | atomic_set(&efx->active_queues, 0); |
| 2758 | } |
| 2759 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2760 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
| 2761 | const struct efx_filter_spec *right) |
| 2762 | { |
| 2763 | if ((left->match_flags ^ right->match_flags) | |
| 2764 | ((left->flags ^ right->flags) & |
| 2765 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) |
| 2766 | return false; |
| 2767 | |
| 2768 | return memcmp(&left->outer_vid, &right->outer_vid, |
| 2769 | sizeof(struct efx_filter_spec) - |
| 2770 | offsetof(struct efx_filter_spec, outer_vid)) == 0; |
| 2771 | } |
| 2772 | |
| 2773 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) |
| 2774 | { |
| 2775 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); |
| 2776 | return jhash2((const u32 *)&spec->outer_vid, |
| 2777 | (sizeof(struct efx_filter_spec) - |
| 2778 | offsetof(struct efx_filter_spec, outer_vid)) / 4, |
| 2779 | 0); |
| 2780 | /* XXX should we randomise the initval? */ |
| 2781 | } |
| 2782 | |
| 2783 | /* Decide whether a filter should be exclusive or else should allow |
| 2784 | * delivery to additional recipients. Currently we decide that |
| 2785 | * filters for specific local unicast MAC and IP addresses are |
| 2786 | * exclusive. |
| 2787 | */ |
| 2788 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) |
| 2789 | { |
| 2790 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && |
| 2791 | !is_multicast_ether_addr(spec->loc_mac)) |
| 2792 | return true; |
| 2793 | |
| 2794 | if ((spec->match_flags & |
| 2795 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == |
| 2796 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { |
| 2797 | if (spec->ether_type == htons(ETH_P_IP) && |
| 2798 | !ipv4_is_multicast(spec->loc_host[0])) |
| 2799 | return true; |
| 2800 | if (spec->ether_type == htons(ETH_P_IPV6) && |
| 2801 | ((const u8 *)spec->loc_host)[0] != 0xff) |
| 2802 | return true; |
| 2803 | } |
| 2804 | |
| 2805 | return false; |
| 2806 | } |
| 2807 | |
| 2808 | static struct efx_filter_spec * |
| 2809 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, |
| 2810 | unsigned int filter_idx) |
| 2811 | { |
| 2812 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & |
| 2813 | ~EFX_EF10_FILTER_FLAGS); |
| 2814 | } |
| 2815 | |
| 2816 | static unsigned int |
| 2817 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, |
| 2818 | unsigned int filter_idx) |
| 2819 | { |
| 2820 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; |
| 2821 | } |
| 2822 | |
| 2823 | static void |
| 2824 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, |
| 2825 | unsigned int filter_idx, |
| 2826 | const struct efx_filter_spec *spec, |
| 2827 | unsigned int flags) |
| 2828 | { |
| 2829 | table->entry[filter_idx].spec = (unsigned long)spec | flags; |
| 2830 | } |
| 2831 | |
| 2832 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, |
| 2833 | const struct efx_filter_spec *spec, |
| 2834 | efx_dword_t *inbuf, u64 handle, |
| 2835 | bool replacing) |
| 2836 | { |
| 2837 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2838 | |
| 2839 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); |
| 2840 | |
| 2841 | if (replacing) { |
| 2842 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2843 | MC_CMD_FILTER_OP_IN_OP_REPLACE); |
| 2844 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); |
| 2845 | } else { |
| 2846 | u32 match_fields = 0; |
| 2847 | |
| 2848 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2849 | efx_ef10_filter_is_exclusive(spec) ? |
| 2850 | MC_CMD_FILTER_OP_IN_OP_INSERT : |
| 2851 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); |
| 2852 | |
| 2853 | /* Convert match flags and values. Unlike almost |
| 2854 | * everything else in MCDI, these fields are in |
| 2855 | * network byte order. |
| 2856 | */ |
| 2857 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) |
| 2858 | match_fields |= |
| 2859 | is_multicast_ether_addr(spec->loc_mac) ? |
| 2860 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : |
| 2861 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; |
| 2862 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ |
| 2863 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ |
| 2864 | match_fields |= \ |
| 2865 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ |
| 2866 | mcdi_field ## _LBN; \ |
| 2867 | BUILD_BUG_ON( \ |
| 2868 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ |
| 2869 | sizeof(spec->gen_field)); \ |
| 2870 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ |
| 2871 | &spec->gen_field, sizeof(spec->gen_field)); \ |
| 2872 | } |
| 2873 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); |
| 2874 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); |
| 2875 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); |
| 2876 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); |
| 2877 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); |
| 2878 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); |
| 2879 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); |
| 2880 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); |
| 2881 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); |
| 2882 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); |
| 2883 | #undef COPY_FIELD |
| 2884 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, |
| 2885 | match_fields); |
| 2886 | } |
| 2887 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2888 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2889 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
| 2890 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 2891 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : |
| 2892 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); |
Shradha Shah | e3d3629 | 2015-05-06 00:56:24 +0100 | [diff] [blame] | 2893 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2894 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
| 2895 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); |
Ben Hutchings | a0bc348 | 2013-12-16 18:56:24 +0000 | [diff] [blame] | 2896 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
| 2897 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 2898 | 0 : spec->dmaq_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2899 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
| 2900 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? |
| 2901 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : |
| 2902 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); |
| 2903 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) |
| 2904 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, |
| 2905 | spec->rss_context != |
| 2906 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? |
| 2907 | spec->rss_context : nic_data->rx_rss_context); |
| 2908 | } |
| 2909 | |
| 2910 | static int efx_ef10_filter_push(struct efx_nic *efx, |
| 2911 | const struct efx_filter_spec *spec, |
| 2912 | u64 *handle, bool replacing) |
| 2913 | { |
| 2914 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 2915 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); |
| 2916 | int rc; |
| 2917 | |
| 2918 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); |
| 2919 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 2920 | outbuf, sizeof(outbuf), NULL); |
| 2921 | if (rc == 0) |
| 2922 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
Ben Hutchings | 065e64c | 2013-10-09 14:17:27 +0100 | [diff] [blame] | 2923 | if (rc == -ENOSPC) |
| 2924 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2925 | return rc; |
| 2926 | } |
| 2927 | |
| 2928 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, |
| 2929 | enum efx_filter_match_flags match_flags) |
| 2930 | { |
| 2931 | unsigned int match_pri; |
| 2932 | |
| 2933 | for (match_pri = 0; |
| 2934 | match_pri < table->rx_match_count; |
| 2935 | match_pri++) |
| 2936 | if (table->rx_match_flags[match_pri] == match_flags) |
| 2937 | return match_pri; |
| 2938 | |
| 2939 | return -EPROTONOSUPPORT; |
| 2940 | } |
| 2941 | |
| 2942 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, |
| 2943 | struct efx_filter_spec *spec, |
| 2944 | bool replace_equal) |
| 2945 | { |
| 2946 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2947 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 2948 | struct efx_filter_spec *saved_spec; |
| 2949 | unsigned int match_pri, hash; |
| 2950 | unsigned int priv_flags; |
| 2951 | bool replacing = false; |
| 2952 | int ins_index = -1; |
| 2953 | DEFINE_WAIT(wait); |
| 2954 | bool is_mc_recip; |
| 2955 | s32 rc; |
| 2956 | |
| 2957 | /* For now, only support RX filters */ |
| 2958 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != |
| 2959 | EFX_FILTER_FLAG_RX) |
| 2960 | return -EINVAL; |
| 2961 | |
| 2962 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); |
| 2963 | if (rc < 0) |
| 2964 | return rc; |
| 2965 | match_pri = rc; |
| 2966 | |
| 2967 | hash = efx_ef10_filter_hash(spec); |
| 2968 | is_mc_recip = efx_filter_is_mc_recipient(spec); |
| 2969 | if (is_mc_recip) |
| 2970 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 2971 | |
| 2972 | /* Find any existing filters with the same match tuple or |
| 2973 | * else a free slot to insert at. If any of them are busy, |
| 2974 | * we have to wait and retry. |
| 2975 | */ |
| 2976 | for (;;) { |
| 2977 | unsigned int depth = 1; |
| 2978 | unsigned int i; |
| 2979 | |
| 2980 | spin_lock_bh(&efx->filter_lock); |
| 2981 | |
| 2982 | for (;;) { |
| 2983 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2984 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 2985 | |
| 2986 | if (!saved_spec) { |
| 2987 | if (ins_index < 0) |
| 2988 | ins_index = i; |
| 2989 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 2990 | if (table->entry[i].spec & |
| 2991 | EFX_EF10_FILTER_FLAG_BUSY) |
| 2992 | break; |
| 2993 | if (spec->priority < saved_spec->priority && |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2994 | spec->priority != EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2995 | rc = -EPERM; |
| 2996 | goto out_unlock; |
| 2997 | } |
| 2998 | if (!is_mc_recip) { |
| 2999 | /* This is the only one */ |
| 3000 | if (spec->priority == |
| 3001 | saved_spec->priority && |
| 3002 | !replace_equal) { |
| 3003 | rc = -EEXIST; |
| 3004 | goto out_unlock; |
| 3005 | } |
| 3006 | ins_index = i; |
| 3007 | goto found; |
| 3008 | } else if (spec->priority > |
| 3009 | saved_spec->priority || |
| 3010 | (spec->priority == |
| 3011 | saved_spec->priority && |
| 3012 | replace_equal)) { |
| 3013 | if (ins_index < 0) |
| 3014 | ins_index = i; |
| 3015 | else |
| 3016 | __set_bit(depth, mc_rem_map); |
| 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | /* Once we reach the maximum search depth, use |
| 3021 | * the first suitable slot or return -EBUSY if |
| 3022 | * there was none |
| 3023 | */ |
| 3024 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 3025 | if (ins_index < 0) { |
| 3026 | rc = -EBUSY; |
| 3027 | goto out_unlock; |
| 3028 | } |
| 3029 | goto found; |
| 3030 | } |
| 3031 | |
| 3032 | ++depth; |
| 3033 | } |
| 3034 | |
| 3035 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 3036 | spin_unlock_bh(&efx->filter_lock); |
| 3037 | schedule(); |
| 3038 | } |
| 3039 | |
| 3040 | found: |
| 3041 | /* Create a software table entry if necessary, and mark it |
| 3042 | * busy. We might yet fail to insert, but any attempt to |
| 3043 | * insert a conflicting filter while we're waiting for the |
| 3044 | * firmware must find the busy entry. |
| 3045 | */ |
| 3046 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 3047 | if (saved_spec) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3048 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
| 3049 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3050 | /* Just make sure it won't be removed */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3051 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
| 3052 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3053 | table->entry[ins_index].spec &= |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3054 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3055 | rc = ins_index; |
| 3056 | goto out_unlock; |
| 3057 | } |
| 3058 | replacing = true; |
| 3059 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); |
| 3060 | } else { |
| 3061 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 3062 | if (!saved_spec) { |
| 3063 | rc = -ENOMEM; |
| 3064 | goto out_unlock; |
| 3065 | } |
| 3066 | *saved_spec = *spec; |
| 3067 | priv_flags = 0; |
| 3068 | } |
| 3069 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 3070 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); |
| 3071 | |
| 3072 | /* Mark lower-priority multicast recipients busy prior to removal */ |
| 3073 | if (is_mc_recip) { |
| 3074 | unsigned int depth, i; |
| 3075 | |
| 3076 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 3077 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 3078 | if (test_bit(depth, mc_rem_map)) |
| 3079 | table->entry[i].spec |= |
| 3080 | EFX_EF10_FILTER_FLAG_BUSY; |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | spin_unlock_bh(&efx->filter_lock); |
| 3085 | |
| 3086 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, |
| 3087 | replacing); |
| 3088 | |
| 3089 | /* Finalise the software table entry */ |
| 3090 | spin_lock_bh(&efx->filter_lock); |
| 3091 | if (rc == 0) { |
| 3092 | if (replacing) { |
| 3093 | /* Update the fields that may differ */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3094 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
| 3095 | saved_spec->flags |= |
| 3096 | EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3097 | saved_spec->priority = spec->priority; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3098 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3099 | saved_spec->flags |= spec->flags; |
| 3100 | saved_spec->rss_context = spec->rss_context; |
| 3101 | saved_spec->dmaq_id = spec->dmaq_id; |
| 3102 | } |
| 3103 | } else if (!replacing) { |
| 3104 | kfree(saved_spec); |
| 3105 | saved_spec = NULL; |
| 3106 | } |
| 3107 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); |
| 3108 | |
| 3109 | /* Remove and finalise entries for lower-priority multicast |
| 3110 | * recipients |
| 3111 | */ |
| 3112 | if (is_mc_recip) { |
| 3113 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 3114 | unsigned int depth, i; |
| 3115 | |
| 3116 | memset(inbuf, 0, sizeof(inbuf)); |
| 3117 | |
| 3118 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 3119 | if (!test_bit(depth, mc_rem_map)) |
| 3120 | continue; |
| 3121 | |
| 3122 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 3123 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 3124 | priv_flags = efx_ef10_filter_entry_flags(table, i); |
| 3125 | |
| 3126 | if (rc == 0) { |
| 3127 | spin_unlock_bh(&efx->filter_lock); |
| 3128 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3129 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 3130 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 3131 | table->entry[i].handle); |
| 3132 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 3133 | inbuf, sizeof(inbuf), |
| 3134 | NULL, 0, NULL); |
| 3135 | spin_lock_bh(&efx->filter_lock); |
| 3136 | } |
| 3137 | |
| 3138 | if (rc == 0) { |
| 3139 | kfree(saved_spec); |
| 3140 | saved_spec = NULL; |
| 3141 | priv_flags = 0; |
| 3142 | } else { |
| 3143 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 3144 | } |
| 3145 | efx_ef10_filter_set_entry(table, i, saved_spec, |
| 3146 | priv_flags); |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | /* If successful, return the inserted filter ID */ |
| 3151 | if (rc == 0) |
| 3152 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; |
| 3153 | |
| 3154 | wake_up_all(&table->waitq); |
| 3155 | out_unlock: |
| 3156 | spin_unlock_bh(&efx->filter_lock); |
| 3157 | finish_wait(&table->waitq, &wait); |
| 3158 | return rc; |
| 3159 | } |
| 3160 | |
Fengguang Wu | 9fd8095d | 2013-08-31 06:54:05 +0800 | [diff] [blame] | 3161 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3162 | { |
| 3163 | /* no need to do anything here on EF10 */ |
| 3164 | } |
| 3165 | |
| 3166 | /* Remove a filter. |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3167 | * If !by_index, remove by ID |
| 3168 | * If by_index, remove by index |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3169 | * Filter ID may come from userland and must be range-checked. |
| 3170 | */ |
| 3171 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3172 | unsigned int priority_mask, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3173 | u32 filter_id, bool by_index) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3174 | { |
| 3175 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 3176 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3177 | MCDI_DECLARE_BUF(inbuf, |
| 3178 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 3179 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 3180 | struct efx_filter_spec *spec; |
| 3181 | DEFINE_WAIT(wait); |
| 3182 | int rc; |
| 3183 | |
| 3184 | /* Find the software table entry and mark it busy. Don't |
| 3185 | * remove it yet; any attempt to update while we're waiting |
| 3186 | * for the firmware must find the busy entry. |
| 3187 | */ |
| 3188 | for (;;) { |
| 3189 | spin_lock_bh(&efx->filter_lock); |
| 3190 | if (!(table->entry[filter_idx].spec & |
| 3191 | EFX_EF10_FILTER_FLAG_BUSY)) |
| 3192 | break; |
| 3193 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 3194 | spin_unlock_bh(&efx->filter_lock); |
| 3195 | schedule(); |
| 3196 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3197 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3198 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3199 | if (!spec || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3200 | (!by_index && |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3201 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != |
| 3202 | filter_id / HUNT_FILTER_TBL_ROWS)) { |
| 3203 | rc = -ENOENT; |
| 3204 | goto out_unlock; |
| 3205 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3206 | |
| 3207 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3208 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3209 | /* Just remove flags */ |
| 3210 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3211 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3212 | rc = 0; |
| 3213 | goto out_unlock; |
| 3214 | } |
| 3215 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3216 | if (!(priority_mask & (1U << spec->priority))) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3217 | rc = -ENOENT; |
| 3218 | goto out_unlock; |
| 3219 | } |
| 3220 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3221 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 3222 | spin_unlock_bh(&efx->filter_lock); |
| 3223 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3224 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3225 | /* Reset to an automatic filter */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3226 | |
| 3227 | struct efx_filter_spec new_spec = *spec; |
| 3228 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3229 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3230 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3231 | EFX_FILTER_FLAG_RX_RSS); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3232 | new_spec.dmaq_id = 0; |
| 3233 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; |
| 3234 | rc = efx_ef10_filter_push(efx, &new_spec, |
| 3235 | &table->entry[filter_idx].handle, |
| 3236 | true); |
| 3237 | |
| 3238 | spin_lock_bh(&efx->filter_lock); |
| 3239 | if (rc == 0) |
| 3240 | *spec = new_spec; |
| 3241 | } else { |
| 3242 | /* Really remove the filter */ |
| 3243 | |
| 3244 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3245 | efx_ef10_filter_is_exclusive(spec) ? |
| 3246 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 3247 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 3248 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 3249 | table->entry[filter_idx].handle); |
| 3250 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 3251 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 3252 | |
| 3253 | spin_lock_bh(&efx->filter_lock); |
| 3254 | if (rc == 0) { |
| 3255 | kfree(spec); |
| 3256 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 3257 | } |
| 3258 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3259 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3260 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 3261 | wake_up_all(&table->waitq); |
| 3262 | out_unlock: |
| 3263 | spin_unlock_bh(&efx->filter_lock); |
| 3264 | finish_wait(&table->waitq, &wait); |
| 3265 | return rc; |
| 3266 | } |
| 3267 | |
| 3268 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, |
| 3269 | enum efx_filter_priority priority, |
| 3270 | u32 filter_id) |
| 3271 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3272 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
| 3273 | filter_id, false); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, |
| 3277 | enum efx_filter_priority priority, |
| 3278 | u32 filter_id, struct efx_filter_spec *spec) |
| 3279 | { |
| 3280 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 3281 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3282 | const struct efx_filter_spec *saved_spec; |
| 3283 | int rc; |
| 3284 | |
| 3285 | spin_lock_bh(&efx->filter_lock); |
| 3286 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3287 | if (saved_spec && saved_spec->priority == priority && |
| 3288 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == |
| 3289 | filter_id / HUNT_FILTER_TBL_ROWS) { |
| 3290 | *spec = *saved_spec; |
| 3291 | rc = 0; |
| 3292 | } else { |
| 3293 | rc = -ENOENT; |
| 3294 | } |
| 3295 | spin_unlock_bh(&efx->filter_lock); |
| 3296 | return rc; |
| 3297 | } |
| 3298 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3299 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3300 | enum efx_filter_priority priority) |
| 3301 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3302 | unsigned int priority_mask; |
| 3303 | unsigned int i; |
| 3304 | int rc; |
| 3305 | |
| 3306 | priority_mask = (((1U << (priority + 1)) - 1) & |
| 3307 | ~(1U << EFX_FILTER_PRI_AUTO)); |
| 3308 | |
| 3309 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 3310 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, |
| 3311 | i, true); |
| 3312 | if (rc && rc != -ENOENT) |
| 3313 | return rc; |
| 3314 | } |
| 3315 | |
| 3316 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, |
| 3320 | enum efx_filter_priority priority) |
| 3321 | { |
| 3322 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3323 | unsigned int filter_idx; |
| 3324 | s32 count = 0; |
| 3325 | |
| 3326 | spin_lock_bh(&efx->filter_lock); |
| 3327 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3328 | if (table->entry[filter_idx].spec && |
| 3329 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == |
| 3330 | priority) |
| 3331 | ++count; |
| 3332 | } |
| 3333 | spin_unlock_bh(&efx->filter_lock); |
| 3334 | return count; |
| 3335 | } |
| 3336 | |
| 3337 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) |
| 3338 | { |
| 3339 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3340 | |
| 3341 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; |
| 3342 | } |
| 3343 | |
| 3344 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, |
| 3345 | enum efx_filter_priority priority, |
| 3346 | u32 *buf, u32 size) |
| 3347 | { |
| 3348 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3349 | struct efx_filter_spec *spec; |
| 3350 | unsigned int filter_idx; |
| 3351 | s32 count = 0; |
| 3352 | |
| 3353 | spin_lock_bh(&efx->filter_lock); |
| 3354 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3355 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3356 | if (spec && spec->priority == priority) { |
| 3357 | if (count == size) { |
| 3358 | count = -EMSGSIZE; |
| 3359 | break; |
| 3360 | } |
| 3361 | buf[count++] = (efx_ef10_filter_rx_match_pri( |
| 3362 | table, spec->match_flags) * |
| 3363 | HUNT_FILTER_TBL_ROWS + |
| 3364 | filter_idx); |
| 3365 | } |
| 3366 | } |
| 3367 | spin_unlock_bh(&efx->filter_lock); |
| 3368 | return count; |
| 3369 | } |
| 3370 | |
| 3371 | #ifdef CONFIG_RFS_ACCEL |
| 3372 | |
| 3373 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; |
| 3374 | |
| 3375 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, |
| 3376 | struct efx_filter_spec *spec) |
| 3377 | { |
| 3378 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3379 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 3380 | struct efx_filter_spec *saved_spec; |
| 3381 | unsigned int hash, i, depth = 1; |
| 3382 | bool replacing = false; |
| 3383 | int ins_index = -1; |
| 3384 | u64 cookie; |
| 3385 | s32 rc; |
| 3386 | |
| 3387 | /* Must be an RX filter without RSS and not for a multicast |
| 3388 | * destination address (RFS only works for connected sockets). |
| 3389 | * These restrictions allow us to pass only a tiny amount of |
| 3390 | * data through to the completion function. |
| 3391 | */ |
| 3392 | EFX_WARN_ON_PARANOID(spec->flags != |
| 3393 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); |
| 3394 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); |
| 3395 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); |
| 3396 | |
| 3397 | hash = efx_ef10_filter_hash(spec); |
| 3398 | |
| 3399 | spin_lock_bh(&efx->filter_lock); |
| 3400 | |
| 3401 | /* Find any existing filter with the same match tuple or else |
| 3402 | * a free slot to insert at. If an existing filter is busy, |
| 3403 | * we have to give up. |
| 3404 | */ |
| 3405 | for (;;) { |
| 3406 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 3407 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 3408 | |
| 3409 | if (!saved_spec) { |
| 3410 | if (ins_index < 0) |
| 3411 | ins_index = i; |
| 3412 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 3413 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { |
| 3414 | rc = -EBUSY; |
| 3415 | goto fail_unlock; |
| 3416 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3417 | if (spec->priority < saved_spec->priority) { |
| 3418 | rc = -EPERM; |
| 3419 | goto fail_unlock; |
| 3420 | } |
| 3421 | ins_index = i; |
| 3422 | break; |
| 3423 | } |
| 3424 | |
| 3425 | /* Once we reach the maximum search depth, use the |
| 3426 | * first suitable slot or return -EBUSY if there was |
| 3427 | * none |
| 3428 | */ |
| 3429 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 3430 | if (ins_index < 0) { |
| 3431 | rc = -EBUSY; |
| 3432 | goto fail_unlock; |
| 3433 | } |
| 3434 | break; |
| 3435 | } |
| 3436 | |
| 3437 | ++depth; |
| 3438 | } |
| 3439 | |
| 3440 | /* Create a software table entry if necessary, and mark it |
| 3441 | * busy. We might yet fail to insert, but any attempt to |
| 3442 | * insert a conflicting filter while we're waiting for the |
| 3443 | * firmware must find the busy entry. |
| 3444 | */ |
| 3445 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 3446 | if (saved_spec) { |
| 3447 | replacing = true; |
| 3448 | } else { |
| 3449 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 3450 | if (!saved_spec) { |
| 3451 | rc = -ENOMEM; |
| 3452 | goto fail_unlock; |
| 3453 | } |
| 3454 | *saved_spec = *spec; |
| 3455 | } |
| 3456 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 3457 | EFX_EF10_FILTER_FLAG_BUSY); |
| 3458 | |
| 3459 | spin_unlock_bh(&efx->filter_lock); |
| 3460 | |
| 3461 | /* Pack up the variables needed on completion */ |
| 3462 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; |
| 3463 | |
| 3464 | efx_ef10_filter_push_prep(efx, spec, inbuf, |
| 3465 | table->entry[ins_index].handle, replacing); |
| 3466 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 3467 | MC_CMD_FILTER_OP_OUT_LEN, |
| 3468 | efx_ef10_filter_rfs_insert_complete, cookie); |
| 3469 | |
| 3470 | return ins_index; |
| 3471 | |
| 3472 | fail_unlock: |
| 3473 | spin_unlock_bh(&efx->filter_lock); |
| 3474 | return rc; |
| 3475 | } |
| 3476 | |
| 3477 | static void |
| 3478 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, |
| 3479 | int rc, efx_dword_t *outbuf, |
| 3480 | size_t outlen_actual) |
| 3481 | { |
| 3482 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3483 | unsigned int ins_index, dmaq_id; |
| 3484 | struct efx_filter_spec *spec; |
| 3485 | bool replacing; |
| 3486 | |
| 3487 | /* Unpack the cookie */ |
| 3488 | replacing = cookie >> 31; |
| 3489 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); |
| 3490 | dmaq_id = cookie & 0xffff; |
| 3491 | |
| 3492 | spin_lock_bh(&efx->filter_lock); |
| 3493 | spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 3494 | if (rc == 0) { |
| 3495 | table->entry[ins_index].handle = |
| 3496 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
| 3497 | if (replacing) |
| 3498 | spec->dmaq_id = dmaq_id; |
| 3499 | } else if (!replacing) { |
| 3500 | kfree(spec); |
| 3501 | spec = NULL; |
| 3502 | } |
| 3503 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); |
| 3504 | spin_unlock_bh(&efx->filter_lock); |
| 3505 | |
| 3506 | wake_up_all(&table->waitq); |
| 3507 | } |
| 3508 | |
| 3509 | static void |
| 3510 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 3511 | unsigned long filter_idx, |
| 3512 | int rc, efx_dword_t *outbuf, |
| 3513 | size_t outlen_actual); |
| 3514 | |
| 3515 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, |
| 3516 | unsigned int filter_idx) |
| 3517 | { |
| 3518 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3519 | struct efx_filter_spec *spec = |
| 3520 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 3521 | MCDI_DECLARE_BUF(inbuf, |
| 3522 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 3523 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 3524 | |
| 3525 | if (!spec || |
| 3526 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || |
| 3527 | spec->priority != EFX_FILTER_PRI_HINT || |
| 3528 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, |
| 3529 | flow_id, filter_idx)) |
| 3530 | return false; |
| 3531 | |
| 3532 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3533 | MC_CMD_FILTER_OP_IN_OP_REMOVE); |
| 3534 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 3535 | table->entry[filter_idx].handle); |
| 3536 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, |
| 3537 | efx_ef10_filter_rfs_expire_complete, filter_idx)) |
| 3538 | return false; |
| 3539 | |
| 3540 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 3541 | return true; |
| 3542 | } |
| 3543 | |
| 3544 | static void |
| 3545 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 3546 | unsigned long filter_idx, |
| 3547 | int rc, efx_dword_t *outbuf, |
| 3548 | size_t outlen_actual) |
| 3549 | { |
| 3550 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3551 | struct efx_filter_spec *spec = |
| 3552 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 3553 | |
| 3554 | spin_lock_bh(&efx->filter_lock); |
| 3555 | if (rc == 0) { |
| 3556 | kfree(spec); |
| 3557 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 3558 | } |
| 3559 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 3560 | wake_up_all(&table->waitq); |
| 3561 | spin_unlock_bh(&efx->filter_lock); |
| 3562 | } |
| 3563 | |
| 3564 | #endif /* CONFIG_RFS_ACCEL */ |
| 3565 | |
| 3566 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) |
| 3567 | { |
| 3568 | int match_flags = 0; |
| 3569 | |
| 3570 | #define MAP_FLAG(gen_flag, mcdi_field) { \ |
| 3571 | u32 old_mcdi_flags = mcdi_flags; \ |
| 3572 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ |
| 3573 | mcdi_field ## _LBN); \ |
| 3574 | if (mcdi_flags != old_mcdi_flags) \ |
| 3575 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ |
| 3576 | } |
| 3577 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); |
| 3578 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); |
| 3579 | MAP_FLAG(REM_HOST, SRC_IP); |
| 3580 | MAP_FLAG(LOC_HOST, DST_IP); |
| 3581 | MAP_FLAG(REM_MAC, SRC_MAC); |
| 3582 | MAP_FLAG(REM_PORT, SRC_PORT); |
| 3583 | MAP_FLAG(LOC_MAC, DST_MAC); |
| 3584 | MAP_FLAG(LOC_PORT, DST_PORT); |
| 3585 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); |
| 3586 | MAP_FLAG(INNER_VID, INNER_VLAN); |
| 3587 | MAP_FLAG(OUTER_VID, OUTER_VLAN); |
| 3588 | MAP_FLAG(IP_PROTO, IP_PROTO); |
| 3589 | #undef MAP_FLAG |
| 3590 | |
| 3591 | /* Did we map them all? */ |
| 3592 | if (mcdi_flags) |
| 3593 | return -EINVAL; |
| 3594 | |
| 3595 | return match_flags; |
| 3596 | } |
| 3597 | |
| 3598 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) |
| 3599 | { |
| 3600 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); |
| 3601 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); |
| 3602 | unsigned int pd_match_pri, pd_match_count; |
| 3603 | struct efx_ef10_filter_table *table; |
| 3604 | size_t outlen; |
| 3605 | int rc; |
| 3606 | |
| 3607 | table = kzalloc(sizeof(*table), GFP_KERNEL); |
| 3608 | if (!table) |
| 3609 | return -ENOMEM; |
| 3610 | |
| 3611 | /* Find out which RX filter types are supported, and their priorities */ |
| 3612 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, |
| 3613 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); |
| 3614 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, |
| 3615 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), |
| 3616 | &outlen); |
| 3617 | if (rc) |
| 3618 | goto fail; |
| 3619 | pd_match_count = MCDI_VAR_ARRAY_LEN( |
| 3620 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); |
| 3621 | table->rx_match_count = 0; |
| 3622 | |
| 3623 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { |
| 3624 | u32 mcdi_flags = |
| 3625 | MCDI_ARRAY_DWORD( |
| 3626 | outbuf, |
| 3627 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, |
| 3628 | pd_match_pri); |
| 3629 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); |
| 3630 | if (rc < 0) { |
| 3631 | netif_dbg(efx, probe, efx->net_dev, |
| 3632 | "%s: fw flags %#x pri %u not supported in driver\n", |
| 3633 | __func__, mcdi_flags, pd_match_pri); |
| 3634 | } else { |
| 3635 | netif_dbg(efx, probe, efx->net_dev, |
| 3636 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", |
| 3637 | __func__, mcdi_flags, pd_match_pri, |
| 3638 | rc, table->rx_match_count); |
| 3639 | table->rx_match_flags[table->rx_match_count++] = rc; |
| 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); |
| 3644 | if (!table->entry) { |
| 3645 | rc = -ENOMEM; |
| 3646 | goto fail; |
| 3647 | } |
| 3648 | |
| 3649 | efx->filter_state = table; |
| 3650 | init_waitqueue_head(&table->waitq); |
| 3651 | return 0; |
| 3652 | |
| 3653 | fail: |
| 3654 | kfree(table); |
| 3655 | return rc; |
| 3656 | } |
| 3657 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3658 | /* Caller must hold efx->filter_sem for read if race against |
| 3659 | * efx_ef10_filter_table_remove() is possible |
| 3660 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3661 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) |
| 3662 | { |
| 3663 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3664 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 3665 | struct efx_filter_spec *spec; |
| 3666 | unsigned int filter_idx; |
| 3667 | bool failed = false; |
| 3668 | int rc; |
| 3669 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3670 | WARN_ON(!rwsem_is_locked(&efx->filter_sem)); |
| 3671 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3672 | if (!nic_data->must_restore_filters) |
| 3673 | return; |
| 3674 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3675 | if (!table) |
| 3676 | return; |
| 3677 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3678 | spin_lock_bh(&efx->filter_lock); |
| 3679 | |
| 3680 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3681 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3682 | if (!spec) |
| 3683 | continue; |
| 3684 | |
| 3685 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 3686 | spin_unlock_bh(&efx->filter_lock); |
| 3687 | |
| 3688 | rc = efx_ef10_filter_push(efx, spec, |
| 3689 | &table->entry[filter_idx].handle, |
| 3690 | false); |
| 3691 | if (rc) |
| 3692 | failed = true; |
| 3693 | |
| 3694 | spin_lock_bh(&efx->filter_lock); |
| 3695 | if (rc) { |
| 3696 | kfree(spec); |
| 3697 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 3698 | } else { |
| 3699 | table->entry[filter_idx].spec &= |
| 3700 | ~EFX_EF10_FILTER_FLAG_BUSY; |
| 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | spin_unlock_bh(&efx->filter_lock); |
| 3705 | |
| 3706 | if (failed) |
| 3707 | netif_err(efx, hw, efx->net_dev, |
| 3708 | "unable to restore all filters\n"); |
| 3709 | else |
| 3710 | nic_data->must_restore_filters = false; |
| 3711 | } |
| 3712 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3713 | /* Caller must hold efx->filter_sem for write */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3714 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) |
| 3715 | { |
| 3716 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3717 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 3718 | struct efx_filter_spec *spec; |
| 3719 | unsigned int filter_idx; |
| 3720 | int rc; |
| 3721 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3722 | efx->filter_state = NULL; |
| 3723 | if (!table) |
| 3724 | return; |
| 3725 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3726 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3727 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3728 | if (!spec) |
| 3729 | continue; |
| 3730 | |
| 3731 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3732 | efx_ef10_filter_is_exclusive(spec) ? |
| 3733 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 3734 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 3735 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 3736 | table->entry[filter_idx].handle); |
| 3737 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 3738 | NULL, 0, NULL); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 3739 | if (rc) |
| 3740 | netdev_WARN(efx->net_dev, |
| 3741 | "filter_idx=%#x handle=%#llx\n", |
| 3742 | filter_idx, |
| 3743 | table->entry[filter_idx].handle); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3744 | kfree(spec); |
| 3745 | } |
| 3746 | |
| 3747 | vfree(table->entry); |
| 3748 | kfree(table); |
| 3749 | } |
| 3750 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3751 | static void efx_ef10_filter_mark_old(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3752 | { |
| 3753 | struct efx_ef10_filter_table *table = efx->filter_state; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3754 | unsigned int filter_idx, i; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3755 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 3756 | if (!table) |
| 3757 | return; |
| 3758 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3759 | /* Mark old filters that may need to be removed */ |
| 3760 | spin_lock_bh(&efx->filter_lock); |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3761 | for (i = 0; i < table->dev_uc_count; i++) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3762 | filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS; |
| 3763 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3764 | } |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3765 | for (i = 0; i < table->dev_mc_count; i++) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3766 | filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS; |
| 3767 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3768 | } |
| 3769 | spin_unlock_bh(&efx->filter_lock); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3770 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3771 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3772 | static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx, bool *promisc) |
| 3773 | { |
| 3774 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3775 | struct net_device *net_dev = efx->net_dev; |
| 3776 | struct netdev_hw_addr *uc; |
| 3777 | unsigned int i; |
| 3778 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3779 | if (net_dev->flags & IFF_PROMISC || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3780 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) { |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3781 | *promisc = true; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3782 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3783 | table->dev_uc_count = 1 + netdev_uc_count(net_dev); |
| 3784 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
| 3785 | i = 1; |
| 3786 | netdev_for_each_uc_addr(uc, net_dev) { |
| 3787 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
| 3788 | i++; |
| 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx, bool *promisc) |
| 3793 | { |
| 3794 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3795 | struct net_device *net_dev = efx->net_dev; |
| 3796 | struct netdev_hw_addr *mc; |
| 3797 | unsigned int i; |
| 3798 | |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3799 | if (netdev_mc_count(net_dev) + 2 /* room for broadcast and promisc */ |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3800 | >= EFX_EF10_FILTER_DEV_MC_MAX) { |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3801 | table->dev_mc_count = 1; |
| 3802 | eth_broadcast_addr(table->dev_mc_list[0].addr); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3803 | *promisc = true; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3804 | } else { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3805 | table->dev_mc_count = 1 + netdev_mc_count(net_dev); |
| 3806 | eth_broadcast_addr(table->dev_mc_list[0].addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3807 | i = 1; |
| 3808 | netdev_for_each_mc_addr(mc, net_dev) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 3809 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3810 | i++; |
| 3811 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3812 | |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3813 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3814 | *promisc = true; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3815 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3816 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3817 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3818 | static void efx_ef10_filter_insert_addr_list(struct efx_nic *efx, |
| 3819 | bool multicast, bool *promisc) |
| 3820 | { |
| 3821 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3822 | struct efx_ef10_dev_addr *addr_list; |
| 3823 | struct efx_filter_spec spec; |
| 3824 | int *addr_count; |
| 3825 | unsigned int i; |
| 3826 | int rc; |
| 3827 | |
| 3828 | if (multicast) { |
| 3829 | addr_list = table->dev_mc_list; |
| 3830 | addr_count = &table->dev_mc_count; |
| 3831 | } else { |
| 3832 | addr_list = table->dev_uc_list; |
| 3833 | addr_count = &table->dev_uc_count; |
| 3834 | } |
| 3835 | |
| 3836 | /* Insert/renew filters */ |
| 3837 | for (i = 0; i < *addr_count; i++) { |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3838 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3839 | EFX_FILTER_FLAG_RX_RSS, |
| 3840 | 0); |
| 3841 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3842 | addr_list[i].addr); |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3843 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3844 | if (rc < 0) { |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3845 | /* Fall back to promiscuous, but leave the broadcast |
| 3846 | * filter for multicast |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3847 | */ |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3848 | while (i--) { |
| 3849 | if (multicast && i == 1) |
| 3850 | break; |
| 3851 | |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3852 | efx_ef10_filter_remove_safe( |
| 3853 | efx, EFX_FILTER_PRI_AUTO, |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3854 | addr_list[i].id); |
| 3855 | } |
| 3856 | *addr_count = i; |
| 3857 | *promisc = true; |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 3858 | break; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3859 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3860 | addr_list[i].id = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3861 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3862 | |
| 3863 | if (*promisc) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3864 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3865 | EFX_FILTER_FLAG_RX_RSS, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3866 | 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3867 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3868 | if (multicast) |
| 3869 | efx_filter_set_mc_def(&spec); |
| 3870 | else |
| 3871 | efx_filter_set_uc_def(&spec); |
| 3872 | |
| 3873 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3874 | if (rc < 0) |
| 3875 | netif_warn(efx, drv, efx->net_dev, |
| 3876 | "%scast mismatch filter insert failed.", |
| 3877 | multicast ? "Multi" : "Uni"); |
| 3878 | else |
| 3879 | addr_list[(*addr_count)++].id = rc; |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD |
| 3884 | * flag or removes these filters, we don't need to hold the filter_lock while |
| 3885 | * scanning for these filters. |
| 3886 | */ |
| 3887 | static void efx_ef10_filter_remove_old(struct efx_nic *efx) |
| 3888 | { |
| 3889 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3890 | bool remove_failed = false; |
| 3891 | int i; |
| 3892 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3893 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 3894 | if (ACCESS_ONCE(table->entry[i].spec) & |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3895 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3896 | if (efx_ef10_filter_remove_internal( |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3897 | efx, 1U << EFX_FILTER_PRI_AUTO, |
| 3898 | i, true) < 0) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3899 | remove_failed = true; |
| 3900 | } |
| 3901 | } |
| 3902 | WARN_ON(remove_failed); |
| 3903 | } |
| 3904 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 3905 | static int efx_ef10_vport_set_mac_address(struct efx_nic *efx) |
| 3906 | { |
| 3907 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 3908 | u8 mac_old[ETH_ALEN]; |
| 3909 | int rc, rc2; |
| 3910 | |
| 3911 | /* Only reconfigure a PF-created vport */ |
| 3912 | if (is_zero_ether_addr(nic_data->vport_mac)) |
| 3913 | return 0; |
| 3914 | |
| 3915 | efx_device_detach_sync(efx); |
| 3916 | efx_net_stop(efx->net_dev); |
| 3917 | down_write(&efx->filter_sem); |
| 3918 | efx_ef10_filter_table_remove(efx); |
| 3919 | up_write(&efx->filter_sem); |
| 3920 | |
| 3921 | rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id); |
| 3922 | if (rc) |
| 3923 | goto restore_filters; |
| 3924 | |
| 3925 | ether_addr_copy(mac_old, nic_data->vport_mac); |
| 3926 | rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id, |
| 3927 | nic_data->vport_mac); |
| 3928 | if (rc) |
| 3929 | goto restore_vadaptor; |
| 3930 | |
| 3931 | rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id, |
| 3932 | efx->net_dev->dev_addr); |
| 3933 | if (!rc) { |
| 3934 | ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr); |
| 3935 | } else { |
| 3936 | rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old); |
| 3937 | if (rc2) { |
| 3938 | /* Failed to add original MAC, so clear vport_mac */ |
| 3939 | eth_zero_addr(nic_data->vport_mac); |
| 3940 | goto reset_nic; |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | restore_vadaptor: |
| 3945 | rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 3946 | if (rc2) |
| 3947 | goto reset_nic; |
| 3948 | restore_filters: |
| 3949 | down_write(&efx->filter_sem); |
| 3950 | rc2 = efx_ef10_filter_table_probe(efx); |
| 3951 | up_write(&efx->filter_sem); |
| 3952 | if (rc2) |
| 3953 | goto reset_nic; |
| 3954 | |
| 3955 | rc2 = efx_net_open(efx->net_dev); |
| 3956 | if (rc2) |
| 3957 | goto reset_nic; |
| 3958 | |
| 3959 | netif_device_attach(efx->net_dev); |
| 3960 | |
| 3961 | return rc; |
| 3962 | |
| 3963 | reset_nic: |
| 3964 | netif_err(efx, drv, efx->net_dev, |
| 3965 | "Failed to restore when changing MAC address - scheduling reset\n"); |
| 3966 | efx_schedule_reset(efx, RESET_TYPE_DATAPATH); |
| 3967 | |
| 3968 | return rc ? rc : rc2; |
| 3969 | } |
| 3970 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame^] | 3971 | /* Caller must hold efx->filter_sem for read if race against |
| 3972 | * efx_ef10_filter_table_remove() is possible |
| 3973 | */ |
| 3974 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) |
| 3975 | { |
| 3976 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3977 | struct net_device *net_dev = efx->net_dev; |
| 3978 | bool uc_promisc = false, mc_promisc = false; |
| 3979 | |
| 3980 | if (!efx_dev_registered(efx)) |
| 3981 | return; |
| 3982 | |
| 3983 | if (!table) |
| 3984 | return; |
| 3985 | |
| 3986 | efx_ef10_filter_mark_old(efx); |
| 3987 | |
| 3988 | /* Copy/convert the address lists; add the primary station |
| 3989 | * address and broadcast address |
| 3990 | */ |
| 3991 | netif_addr_lock_bh(net_dev); |
| 3992 | efx_ef10_filter_uc_addr_list(efx, &uc_promisc); |
| 3993 | efx_ef10_filter_mc_addr_list(efx, &mc_promisc); |
| 3994 | netif_addr_unlock_bh(net_dev); |
| 3995 | |
| 3996 | /* Insert/renew filters */ |
| 3997 | efx_ef10_filter_insert_addr_list(efx, false, &uc_promisc); |
| 3998 | efx_ef10_filter_insert_addr_list(efx, true, &mc_promisc); |
| 3999 | |
| 4000 | efx_ef10_filter_remove_old(efx); |
| 4001 | } |
| 4002 | |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4003 | static int efx_ef10_set_mac_address(struct efx_nic *efx) |
| 4004 | { |
| 4005 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN); |
| 4006 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 4007 | bool was_enabled = efx->port_enabled; |
| 4008 | int rc; |
| 4009 | |
| 4010 | efx_device_detach_sync(efx); |
| 4011 | efx_net_stop(efx->net_dev); |
| 4012 | down_write(&efx->filter_sem); |
| 4013 | efx_ef10_filter_table_remove(efx); |
| 4014 | |
| 4015 | ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR), |
| 4016 | efx->net_dev->dev_addr); |
| 4017 | MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID, |
| 4018 | nic_data->vport_id); |
Daniel Pieczko | 535a617 | 2015-07-07 11:37:33 +0100 | [diff] [blame] | 4019 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf, |
| 4020 | sizeof(inbuf), NULL, 0, NULL); |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4021 | |
| 4022 | efx_ef10_filter_table_probe(efx); |
| 4023 | up_write(&efx->filter_sem); |
| 4024 | if (was_enabled) |
| 4025 | efx_net_open(efx->net_dev); |
| 4026 | netif_device_attach(efx->net_dev); |
| 4027 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4028 | #ifdef CONFIG_SFC_SRIOV |
| 4029 | if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) { |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4030 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; |
| 4031 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4032 | if (rc == -EPERM) { |
| 4033 | struct efx_nic *efx_pf; |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4034 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4035 | /* Switch to PF and change MAC address on vport */ |
| 4036 | efx_pf = pci_get_drvdata(pci_dev_pf); |
| 4037 | |
| 4038 | rc = efx_ef10_sriov_set_vf_mac(efx_pf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4039 | nic_data->vf_index, |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4040 | efx->net_dev->dev_addr); |
| 4041 | } else if (!rc) { |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4042 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 4043 | struct efx_ef10_nic_data *nic_data = efx_pf->nic_data; |
| 4044 | unsigned int i; |
| 4045 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4046 | /* MAC address successfully changed by VF (with MAC |
| 4047 | * spoofing) so update the parent PF if possible. |
| 4048 | */ |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4049 | for (i = 0; i < efx_pf->vf_count; ++i) { |
| 4050 | struct ef10_vf *vf = nic_data->vf + i; |
| 4051 | |
| 4052 | if (vf->efx == efx) { |
| 4053 | ether_addr_copy(vf->mac, |
| 4054 | efx->net_dev->dev_addr); |
| 4055 | return 0; |
| 4056 | } |
| 4057 | } |
| 4058 | } |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4059 | } else |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4060 | #endif |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4061 | if (rc == -EPERM) { |
| 4062 | netif_err(efx, drv, efx->net_dev, |
| 4063 | "Cannot change MAC address; use sfboot to enable" |
| 4064 | " mac-spoofing on this interface\n"); |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 4065 | } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) { |
| 4066 | /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC |
| 4067 | * fall-back to the method of changing the MAC address on the |
| 4068 | * vport. This only applies to PFs because such versions of |
| 4069 | * MCFW do not support VFs. |
| 4070 | */ |
| 4071 | rc = efx_ef10_vport_set_mac_address(efx); |
Daniel Pieczko | 535a617 | 2015-07-07 11:37:33 +0100 | [diff] [blame] | 4072 | } else { |
| 4073 | efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC, |
| 4074 | sizeof(inbuf), NULL, 0, rc); |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4077 | return rc; |
| 4078 | } |
| 4079 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4080 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) |
| 4081 | { |
| 4082 | efx_ef10_filter_sync_rx_mode(efx); |
| 4083 | |
| 4084 | return efx_mcdi_set_mac(efx); |
| 4085 | } |
| 4086 | |
Shradha Shah | 862f894 | 2015-05-20 11:08:56 +0100 | [diff] [blame] | 4087 | static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx) |
| 4088 | { |
| 4089 | efx_ef10_filter_sync_rx_mode(efx); |
| 4090 | |
| 4091 | return 0; |
| 4092 | } |
| 4093 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 4094 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
| 4095 | { |
| 4096 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); |
| 4097 | |
| 4098 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); |
| 4099 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), |
| 4100 | NULL, 0, NULL); |
| 4101 | } |
| 4102 | |
| 4103 | /* MC BISTs follow a different poll mechanism to phy BISTs. |
| 4104 | * The BIST is done in the poll handler on the MC, and the MCDI command |
| 4105 | * will block until the BIST is done. |
| 4106 | */ |
| 4107 | static int efx_ef10_poll_bist(struct efx_nic *efx) |
| 4108 | { |
| 4109 | int rc; |
| 4110 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); |
| 4111 | size_t outlen; |
| 4112 | u32 result; |
| 4113 | |
| 4114 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, |
| 4115 | outbuf, sizeof(outbuf), &outlen); |
| 4116 | if (rc != 0) |
| 4117 | return rc; |
| 4118 | |
| 4119 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) |
| 4120 | return -EIO; |
| 4121 | |
| 4122 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); |
| 4123 | switch (result) { |
| 4124 | case MC_CMD_POLL_BIST_PASSED: |
| 4125 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); |
| 4126 | return 0; |
| 4127 | case MC_CMD_POLL_BIST_TIMEOUT: |
| 4128 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); |
| 4129 | return -EIO; |
| 4130 | case MC_CMD_POLL_BIST_FAILED: |
| 4131 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); |
| 4132 | return -EIO; |
| 4133 | default: |
| 4134 | netif_err(efx, hw, efx->net_dev, |
| 4135 | "BIST returned unknown result %u", result); |
| 4136 | return -EIO; |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) |
| 4141 | { |
| 4142 | int rc; |
| 4143 | |
| 4144 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); |
| 4145 | |
| 4146 | rc = efx_ef10_start_bist(efx, bist_type); |
| 4147 | if (rc != 0) |
| 4148 | return rc; |
| 4149 | |
| 4150 | return efx_ef10_poll_bist(efx); |
| 4151 | } |
| 4152 | |
| 4153 | static int |
| 4154 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) |
| 4155 | { |
| 4156 | int rc, rc2; |
| 4157 | |
| 4158 | efx_reset_down(efx, RESET_TYPE_WORLD); |
| 4159 | |
| 4160 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, |
| 4161 | NULL, 0, NULL, 0, NULL); |
| 4162 | if (rc != 0) |
| 4163 | goto out; |
| 4164 | |
| 4165 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; |
| 4166 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; |
| 4167 | |
| 4168 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); |
| 4169 | |
| 4170 | out: |
| 4171 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); |
| 4172 | return rc ? rc : rc2; |
| 4173 | } |
| 4174 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4175 | #ifdef CONFIG_SFC_MTD |
| 4176 | |
| 4177 | struct efx_ef10_nvram_type_info { |
| 4178 | u16 type, type_mask; |
| 4179 | u8 port; |
| 4180 | const char *name; |
| 4181 | }; |
| 4182 | |
| 4183 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { |
| 4184 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, |
| 4185 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, |
| 4186 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, |
| 4187 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, |
| 4188 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, |
| 4189 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, |
| 4190 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, |
| 4191 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, |
| 4192 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, |
Ben Hutchings | a84f3bf9 | 2013-10-09 14:14:41 +0100 | [diff] [blame] | 4193 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4194 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
| 4195 | }; |
| 4196 | |
| 4197 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, |
| 4198 | struct efx_mcdi_mtd_partition *part, |
| 4199 | unsigned int type) |
| 4200 | { |
| 4201 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); |
| 4202 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); |
| 4203 | const struct efx_ef10_nvram_type_info *info; |
| 4204 | size_t size, erase_size, outlen; |
| 4205 | bool protected; |
| 4206 | int rc; |
| 4207 | |
| 4208 | for (info = efx_ef10_nvram_types; ; info++) { |
| 4209 | if (info == |
| 4210 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) |
| 4211 | return -ENODEV; |
| 4212 | if ((type & ~info->type_mask) == info->type) |
| 4213 | break; |
| 4214 | } |
| 4215 | if (info->port != efx_port_num(efx)) |
| 4216 | return -ENODEV; |
| 4217 | |
| 4218 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); |
| 4219 | if (rc) |
| 4220 | return rc; |
| 4221 | if (protected) |
| 4222 | return -ENODEV; /* hide it */ |
| 4223 | |
| 4224 | part->nvram_type = type; |
| 4225 | |
| 4226 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); |
| 4227 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), |
| 4228 | outbuf, sizeof(outbuf), &outlen); |
| 4229 | if (rc) |
| 4230 | return rc; |
| 4231 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) |
| 4232 | return -EIO; |
| 4233 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & |
| 4234 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) |
| 4235 | part->fw_subtype = MCDI_DWORD(outbuf, |
| 4236 | NVRAM_METADATA_OUT_SUBTYPE); |
| 4237 | |
| 4238 | part->common.dev_type_name = "EF10 NVRAM manager"; |
| 4239 | part->common.type_name = info->name; |
| 4240 | |
| 4241 | part->common.mtd.type = MTD_NORFLASH; |
| 4242 | part->common.mtd.flags = MTD_CAP_NORFLASH; |
| 4243 | part->common.mtd.size = size; |
| 4244 | part->common.mtd.erasesize = erase_size; |
| 4245 | |
| 4246 | return 0; |
| 4247 | } |
| 4248 | |
| 4249 | static int efx_ef10_mtd_probe(struct efx_nic *efx) |
| 4250 | { |
| 4251 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); |
| 4252 | struct efx_mcdi_mtd_partition *parts; |
| 4253 | size_t outlen, n_parts_total, i, n_parts; |
| 4254 | unsigned int type; |
| 4255 | int rc; |
| 4256 | |
| 4257 | ASSERT_RTNL(); |
| 4258 | |
| 4259 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); |
| 4260 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, |
| 4261 | outbuf, sizeof(outbuf), &outlen); |
| 4262 | if (rc) |
| 4263 | return rc; |
| 4264 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) |
| 4265 | return -EIO; |
| 4266 | |
| 4267 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); |
| 4268 | if (n_parts_total > |
| 4269 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) |
| 4270 | return -EIO; |
| 4271 | |
| 4272 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); |
| 4273 | if (!parts) |
| 4274 | return -ENOMEM; |
| 4275 | |
| 4276 | n_parts = 0; |
| 4277 | for (i = 0; i < n_parts_total; i++) { |
| 4278 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, |
| 4279 | i); |
| 4280 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); |
| 4281 | if (rc == 0) |
| 4282 | n_parts++; |
| 4283 | else if (rc != -ENODEV) |
| 4284 | goto fail; |
| 4285 | } |
| 4286 | |
| 4287 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); |
| 4288 | fail: |
| 4289 | if (rc) |
| 4290 | kfree(parts); |
| 4291 | return rc; |
| 4292 | } |
| 4293 | |
| 4294 | #endif /* CONFIG_SFC_MTD */ |
| 4295 | |
| 4296 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) |
| 4297 | { |
| 4298 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); |
| 4299 | } |
| 4300 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4301 | static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx, |
| 4302 | u32 host_time) {} |
| 4303 | |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 4304 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
| 4305 | bool temp) |
| 4306 | { |
| 4307 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); |
| 4308 | int rc; |
| 4309 | |
| 4310 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || |
| 4311 | channel->sync_events_state == SYNC_EVENTS_VALID || |
| 4312 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) |
| 4313 | return 0; |
| 4314 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; |
| 4315 | |
| 4316 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); |
| 4317 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 4318 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, |
| 4319 | channel->channel); |
| 4320 | |
| 4321 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 4322 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 4323 | |
| 4324 | if (rc != 0) |
| 4325 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 4326 | SYNC_EVENTS_DISABLED; |
| 4327 | |
| 4328 | return rc; |
| 4329 | } |
| 4330 | |
| 4331 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, |
| 4332 | bool temp) |
| 4333 | { |
| 4334 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); |
| 4335 | int rc; |
| 4336 | |
| 4337 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || |
| 4338 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) |
| 4339 | return 0; |
| 4340 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { |
| 4341 | channel->sync_events_state = SYNC_EVENTS_DISABLED; |
| 4342 | return 0; |
| 4343 | } |
| 4344 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 4345 | SYNC_EVENTS_DISABLED; |
| 4346 | |
| 4347 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); |
| 4348 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 4349 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, |
| 4350 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); |
| 4351 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, |
| 4352 | channel->channel); |
| 4353 | |
| 4354 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 4355 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 4356 | |
| 4357 | return rc; |
| 4358 | } |
| 4359 | |
| 4360 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, |
| 4361 | bool temp) |
| 4362 | { |
| 4363 | int (*set)(struct efx_channel *channel, bool temp); |
| 4364 | struct efx_channel *channel; |
| 4365 | |
| 4366 | set = en ? |
| 4367 | efx_ef10_rx_enable_timestamping : |
| 4368 | efx_ef10_rx_disable_timestamping; |
| 4369 | |
| 4370 | efx_for_each_channel(channel, efx) { |
| 4371 | int rc = set(channel, temp); |
| 4372 | if (en && rc != 0) { |
| 4373 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); |
| 4374 | return rc; |
| 4375 | } |
| 4376 | } |
| 4377 | |
| 4378 | return 0; |
| 4379 | } |
| 4380 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4381 | static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx, |
| 4382 | struct hwtstamp_config *init) |
| 4383 | { |
| 4384 | return -EOPNOTSUPP; |
| 4385 | } |
| 4386 | |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 4387 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
| 4388 | struct hwtstamp_config *init) |
| 4389 | { |
| 4390 | int rc; |
| 4391 | |
| 4392 | switch (init->rx_filter) { |
| 4393 | case HWTSTAMP_FILTER_NONE: |
| 4394 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); |
| 4395 | /* if TX timestamping is still requested then leave PTP on */ |
| 4396 | return efx_ptp_change_mode(efx, |
| 4397 | init->tx_type != HWTSTAMP_TX_OFF, 0); |
| 4398 | case HWTSTAMP_FILTER_ALL: |
| 4399 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 4400 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 4401 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 4402 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 4403 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 4404 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 4405 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 4406 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 4407 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 4408 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 4409 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 4410 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 4411 | init->rx_filter = HWTSTAMP_FILTER_ALL; |
| 4412 | rc = efx_ptp_change_mode(efx, true, 0); |
| 4413 | if (!rc) |
| 4414 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); |
| 4415 | if (rc) |
| 4416 | efx_ptp_change_mode(efx, false, 0); |
| 4417 | return rc; |
| 4418 | default: |
| 4419 | return -ERANGE; |
| 4420 | } |
| 4421 | } |
| 4422 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4423 | const struct efx_nic_type efx_hunt_a0_vf_nic_type = { |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 4424 | .is_vf = true, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4425 | .mem_bar = EFX_MEM_VF_BAR, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4426 | .mem_map_size = efx_ef10_mem_map_size, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4427 | .probe = efx_ef10_probe_vf, |
| 4428 | .remove = efx_ef10_remove, |
| 4429 | .dimension_resources = efx_ef10_dimension_resources, |
| 4430 | .init = efx_ef10_init_nic, |
| 4431 | .fini = efx_port_dummy_op_void, |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 4432 | .map_reset_reason = efx_ef10_map_reset_reason, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4433 | .map_reset_flags = efx_ef10_map_reset_flags, |
| 4434 | .reset = efx_ef10_reset, |
| 4435 | .probe_port = efx_mcdi_port_probe, |
| 4436 | .remove_port = efx_mcdi_port_remove, |
| 4437 | .fini_dmaq = efx_ef10_fini_dmaq, |
| 4438 | .prepare_flr = efx_ef10_prepare_flr, |
| 4439 | .finish_flr = efx_port_dummy_op_void, |
| 4440 | .describe_stats = efx_ef10_describe_stats, |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 4441 | .update_stats = efx_ef10_update_stats_vf, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4442 | .start_stats = efx_port_dummy_op_void, |
| 4443 | .pull_stats = efx_port_dummy_op_void, |
| 4444 | .stop_stats = efx_port_dummy_op_void, |
| 4445 | .set_id_led = efx_mcdi_set_id_led, |
| 4446 | .push_irq_moderation = efx_ef10_push_irq_moderation, |
Shradha Shah | 862f894 | 2015-05-20 11:08:56 +0100 | [diff] [blame] | 4447 | .reconfigure_mac = efx_ef10_mac_reconfigure_vf, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4448 | .check_mac_fault = efx_mcdi_mac_check_fault, |
| 4449 | .reconfigure_port = efx_mcdi_port_reconfigure, |
| 4450 | .get_wol = efx_ef10_get_wol_vf, |
| 4451 | .set_wol = efx_ef10_set_wol_vf, |
| 4452 | .resume_wol = efx_port_dummy_op_void, |
| 4453 | .mcdi_request = efx_ef10_mcdi_request, |
| 4454 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, |
| 4455 | .mcdi_read_response = efx_ef10_mcdi_read_response, |
| 4456 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, |
| 4457 | .irq_enable_master = efx_port_dummy_op_void, |
| 4458 | .irq_test_generate = efx_ef10_irq_test_generate, |
| 4459 | .irq_disable_non_ev = efx_port_dummy_op_void, |
| 4460 | .irq_handle_msi = efx_ef10_msi_interrupt, |
| 4461 | .irq_handle_legacy = efx_ef10_legacy_interrupt, |
| 4462 | .tx_probe = efx_ef10_tx_probe, |
| 4463 | .tx_init = efx_ef10_tx_init, |
| 4464 | .tx_remove = efx_ef10_tx_remove, |
| 4465 | .tx_write = efx_ef10_tx_write, |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 4466 | .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4467 | .rx_probe = efx_ef10_rx_probe, |
| 4468 | .rx_init = efx_ef10_rx_init, |
| 4469 | .rx_remove = efx_ef10_rx_remove, |
| 4470 | .rx_write = efx_ef10_rx_write, |
| 4471 | .rx_defer_refill = efx_ef10_rx_defer_refill, |
| 4472 | .ev_probe = efx_ef10_ev_probe, |
| 4473 | .ev_init = efx_ef10_ev_init, |
| 4474 | .ev_fini = efx_ef10_ev_fini, |
| 4475 | .ev_remove = efx_ef10_ev_remove, |
| 4476 | .ev_process = efx_ef10_ev_process, |
| 4477 | .ev_read_ack = efx_ef10_ev_read_ack, |
| 4478 | .ev_test_generate = efx_ef10_ev_test_generate, |
| 4479 | .filter_table_probe = efx_ef10_filter_table_probe, |
| 4480 | .filter_table_restore = efx_ef10_filter_table_restore, |
| 4481 | .filter_table_remove = efx_ef10_filter_table_remove, |
| 4482 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, |
| 4483 | .filter_insert = efx_ef10_filter_insert, |
| 4484 | .filter_remove_safe = efx_ef10_filter_remove_safe, |
| 4485 | .filter_get_safe = efx_ef10_filter_get_safe, |
| 4486 | .filter_clear_rx = efx_ef10_filter_clear_rx, |
| 4487 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, |
| 4488 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, |
| 4489 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, |
| 4490 | #ifdef CONFIG_RFS_ACCEL |
| 4491 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, |
| 4492 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, |
| 4493 | #endif |
| 4494 | #ifdef CONFIG_SFC_MTD |
| 4495 | .mtd_probe = efx_port_dummy_op_int, |
| 4496 | #endif |
| 4497 | .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf, |
| 4498 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf, |
| 4499 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 4500 | .vswitching_probe = efx_ef10_vswitching_probe_vf, |
| 4501 | .vswitching_restore = efx_ef10_vswitching_restore_vf, |
| 4502 | .vswitching_remove = efx_ef10_vswitching_remove_vf, |
Shradha Shah | 1d051e0 | 2015-06-02 11:38:16 +0100 | [diff] [blame] | 4503 | .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4504 | #endif |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 4505 | .get_mac_address = efx_ef10_get_mac_address_vf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4506 | .set_mac_address = efx_ef10_set_mac_address, |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 4507 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4508 | .revision = EFX_REV_HUNT_A0, |
| 4509 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), |
| 4510 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, |
| 4511 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, |
| 4512 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
| 4513 | .can_rx_scatter = true, |
| 4514 | .always_rx_scatter = true, |
| 4515 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 4516 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, |
| 4517 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4518 | NETIF_F_RXHASH | NETIF_F_NTUPLE), |
| 4519 | .mcdi_max_ver = 2, |
| 4520 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, |
| 4521 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
| 4522 | 1 << HWTSTAMP_FILTER_ALL, |
| 4523 | }; |
| 4524 | |
| 4525 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 4526 | .is_vf = false, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 4527 | .mem_bar = EFX_MEM_BAR, |
| 4528 | .mem_map_size = efx_ef10_mem_map_size, |
| 4529 | .probe = efx_ef10_probe_pf, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4530 | .remove = efx_ef10_remove, |
| 4531 | .dimension_resources = efx_ef10_dimension_resources, |
| 4532 | .init = efx_ef10_init_nic, |
| 4533 | .fini = efx_port_dummy_op_void, |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 4534 | .map_reset_reason = efx_ef10_map_reset_reason, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4535 | .map_reset_flags = efx_ef10_map_reset_flags, |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 4536 | .reset = efx_ef10_reset, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4537 | .probe_port = efx_mcdi_port_probe, |
| 4538 | .remove_port = efx_mcdi_port_remove, |
| 4539 | .fini_dmaq = efx_ef10_fini_dmaq, |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 4540 | .prepare_flr = efx_ef10_prepare_flr, |
| 4541 | .finish_flr = efx_port_dummy_op_void, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4542 | .describe_stats = efx_ef10_describe_stats, |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 4543 | .update_stats = efx_ef10_update_stats_pf, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4544 | .start_stats = efx_mcdi_mac_start_stats, |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 4545 | .pull_stats = efx_mcdi_mac_pull_stats, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4546 | .stop_stats = efx_mcdi_mac_stop_stats, |
| 4547 | .set_id_led = efx_mcdi_set_id_led, |
| 4548 | .push_irq_moderation = efx_ef10_push_irq_moderation, |
| 4549 | .reconfigure_mac = efx_ef10_mac_reconfigure, |
| 4550 | .check_mac_fault = efx_mcdi_mac_check_fault, |
| 4551 | .reconfigure_port = efx_mcdi_port_reconfigure, |
| 4552 | .get_wol = efx_ef10_get_wol, |
| 4553 | .set_wol = efx_ef10_set_wol, |
| 4554 | .resume_wol = efx_port_dummy_op_void, |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 4555 | .test_chip = efx_ef10_test_chip, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4556 | .test_nvram = efx_mcdi_nvram_test_all, |
| 4557 | .mcdi_request = efx_ef10_mcdi_request, |
| 4558 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, |
| 4559 | .mcdi_read_response = efx_ef10_mcdi_read_response, |
| 4560 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, |
| 4561 | .irq_enable_master = efx_port_dummy_op_void, |
| 4562 | .irq_test_generate = efx_ef10_irq_test_generate, |
| 4563 | .irq_disable_non_ev = efx_port_dummy_op_void, |
| 4564 | .irq_handle_msi = efx_ef10_msi_interrupt, |
| 4565 | .irq_handle_legacy = efx_ef10_legacy_interrupt, |
| 4566 | .tx_probe = efx_ef10_tx_probe, |
| 4567 | .tx_init = efx_ef10_tx_init, |
| 4568 | .tx_remove = efx_ef10_tx_remove, |
| 4569 | .tx_write = efx_ef10_tx_write, |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 4570 | .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4571 | .rx_probe = efx_ef10_rx_probe, |
| 4572 | .rx_init = efx_ef10_rx_init, |
| 4573 | .rx_remove = efx_ef10_rx_remove, |
| 4574 | .rx_write = efx_ef10_rx_write, |
| 4575 | .rx_defer_refill = efx_ef10_rx_defer_refill, |
| 4576 | .ev_probe = efx_ef10_ev_probe, |
| 4577 | .ev_init = efx_ef10_ev_init, |
| 4578 | .ev_fini = efx_ef10_ev_fini, |
| 4579 | .ev_remove = efx_ef10_ev_remove, |
| 4580 | .ev_process = efx_ef10_ev_process, |
| 4581 | .ev_read_ack = efx_ef10_ev_read_ack, |
| 4582 | .ev_test_generate = efx_ef10_ev_test_generate, |
| 4583 | .filter_table_probe = efx_ef10_filter_table_probe, |
| 4584 | .filter_table_restore = efx_ef10_filter_table_restore, |
| 4585 | .filter_table_remove = efx_ef10_filter_table_remove, |
| 4586 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, |
| 4587 | .filter_insert = efx_ef10_filter_insert, |
| 4588 | .filter_remove_safe = efx_ef10_filter_remove_safe, |
| 4589 | .filter_get_safe = efx_ef10_filter_get_safe, |
| 4590 | .filter_clear_rx = efx_ef10_filter_clear_rx, |
| 4591 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, |
| 4592 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, |
| 4593 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, |
| 4594 | #ifdef CONFIG_RFS_ACCEL |
| 4595 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, |
| 4596 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, |
| 4597 | #endif |
| 4598 | #ifdef CONFIG_SFC_MTD |
| 4599 | .mtd_probe = efx_ef10_mtd_probe, |
| 4600 | .mtd_rename = efx_mcdi_mtd_rename, |
| 4601 | .mtd_read = efx_mcdi_mtd_read, |
| 4602 | .mtd_erase = efx_mcdi_mtd_erase, |
| 4603 | .mtd_write = efx_mcdi_mtd_write, |
| 4604 | .mtd_sync = efx_mcdi_mtd_sync, |
| 4605 | #endif |
| 4606 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 4607 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
| 4608 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 4609 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 4610 | .sriov_configure = efx_ef10_sriov_configure, |
Shradha Shah | d98a4ff | 2014-11-05 12:16:46 +0000 | [diff] [blame] | 4611 | .sriov_init = efx_ef10_sriov_init, |
| 4612 | .sriov_fini = efx_ef10_sriov_fini, |
Shradha Shah | d98a4ff | 2014-11-05 12:16:46 +0000 | [diff] [blame] | 4613 | .sriov_wanted = efx_ef10_sriov_wanted, |
| 4614 | .sriov_reset = efx_ef10_sriov_reset, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 4615 | .sriov_flr = efx_ef10_sriov_flr, |
| 4616 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, |
| 4617 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, |
| 4618 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, |
| 4619 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 4620 | .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state, |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 4621 | .vswitching_probe = efx_ef10_vswitching_probe_pf, |
| 4622 | .vswitching_restore = efx_ef10_vswitching_restore_pf, |
| 4623 | .vswitching_remove = efx_ef10_vswitching_remove_pf, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 4624 | #endif |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 4625 | .get_mac_address = efx_ef10_get_mac_address_pf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 4626 | .set_mac_address = efx_ef10_set_mac_address, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4627 | |
| 4628 | .revision = EFX_REV_HUNT_A0, |
| 4629 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), |
| 4630 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, |
| 4631 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 4632 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4633 | .can_rx_scatter = true, |
| 4634 | .always_rx_scatter = true, |
| 4635 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 4636 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, |
| 4637 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4638 | NETIF_F_RXHASH | NETIF_F_NTUPLE), |
| 4639 | .mcdi_max_ver = 2, |
| 4640 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 4641 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
| 4642 | 1 << HWTSTAMP_FILTER_ALL, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4643 | }; |