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 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 52 | #define EFX_EF10_FILTER_ID_INVALID 0xffff |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 53 | |
| 54 | #define EFX_EF10_FILTER_DEV_UC_MAX 32 |
| 55 | #define EFX_EF10_FILTER_DEV_MC_MAX 256 |
| 56 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 57 | /* VLAN list entry */ |
| 58 | struct efx_ef10_vlan { |
| 59 | struct list_head list; |
| 60 | u16 vid; |
| 61 | }; |
| 62 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 63 | enum efx_ef10_default_filters { |
| 64 | EFX_EF10_BCAST, |
| 65 | EFX_EF10_UCDEF, |
| 66 | EFX_EF10_MCDEF, |
| 67 | EFX_EF10_VXLAN4_UCDEF, |
| 68 | EFX_EF10_VXLAN4_MCDEF, |
| 69 | EFX_EF10_VXLAN6_UCDEF, |
| 70 | EFX_EF10_VXLAN6_MCDEF, |
| 71 | EFX_EF10_NVGRE4_UCDEF, |
| 72 | EFX_EF10_NVGRE4_MCDEF, |
| 73 | EFX_EF10_NVGRE6_UCDEF, |
| 74 | EFX_EF10_NVGRE6_MCDEF, |
| 75 | EFX_EF10_GENEVE4_UCDEF, |
| 76 | EFX_EF10_GENEVE4_MCDEF, |
| 77 | EFX_EF10_GENEVE6_UCDEF, |
| 78 | EFX_EF10_GENEVE6_MCDEF, |
| 79 | |
| 80 | EFX_EF10_NUM_DEFAULT_FILTERS |
| 81 | }; |
| 82 | |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 83 | /* Per-VLAN filters information */ |
| 84 | struct efx_ef10_filter_vlan { |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 85 | struct list_head list; |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 86 | u16 vid; |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 87 | u16 uc[EFX_EF10_FILTER_DEV_UC_MAX]; |
| 88 | u16 mc[EFX_EF10_FILTER_DEV_MC_MAX]; |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 89 | u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS]; |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 92 | struct efx_ef10_dev_addr { |
| 93 | u8 addr[ETH_ALEN]; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 96 | struct efx_ef10_filter_table { |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 97 | /* The MCDI match masks supported by this fw & hw, in order of priority */ |
| 98 | u32 rx_match_mcdi_flags[ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 99 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2]; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 100 | unsigned int rx_match_count; |
| 101 | |
| 102 | struct { |
| 103 | unsigned long spec; /* pointer to spec plus flag bits */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 104 | /* BUSY flag indicates that an update is in progress. AUTO_OLD is |
| 105 | * used to mark and sweep MAC filters for the device address lists. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 106 | */ |
| 107 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 108 | #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 109 | #define EFX_EF10_FILTER_FLAGS 3UL |
| 110 | u64 handle; /* firmware handle */ |
| 111 | } *entry; |
| 112 | wait_queue_head_t waitq; |
| 113 | /* Shadow of net_device address lists, guarded by mac_lock */ |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 114 | struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX]; |
| 115 | struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 116 | int dev_uc_count; |
| 117 | int dev_mc_count; |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 118 | bool uc_promisc; |
| 119 | bool mc_promisc; |
Andrew Rybchenko | b071c3a | 2016-06-15 17:43:00 +0100 | [diff] [blame] | 120 | /* Whether in multicast promiscuous mode when last changed */ |
| 121 | bool mc_promisc_last; |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 122 | bool vlan_filter; |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 123 | struct list_head vlan_list; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /* An arbitrary search limit for the software hash table */ |
| 127 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 |
| 128 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 129 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); |
| 130 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 131 | static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid); |
| 132 | static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx, |
| 133 | struct efx_ef10_filter_vlan *vlan); |
| 134 | static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 135 | |
| 136 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) |
| 137 | { |
| 138 | efx_dword_t reg; |
| 139 | |
| 140 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); |
| 141 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? |
| 142 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; |
| 143 | } |
| 144 | |
| 145 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) |
| 146 | { |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 147 | int bar; |
| 148 | |
| 149 | bar = efx->type->mem_bar; |
| 150 | return resource_size(&efx->pci_dev->resource[bar]); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 153 | static bool efx_ef10_is_vf(struct efx_nic *efx) |
| 154 | { |
| 155 | return efx->type->is_vf; |
| 156 | } |
| 157 | |
Daniel Pieczko | 1cd9ecb | 2015-05-06 00:57:53 +0100 | [diff] [blame] | 158 | static int efx_ef10_get_pf_index(struct efx_nic *efx) |
| 159 | { |
| 160 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); |
| 161 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 162 | size_t outlen; |
| 163 | int rc; |
| 164 | |
| 165 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, |
| 166 | sizeof(outbuf), &outlen); |
| 167 | if (rc) |
| 168 | return rc; |
| 169 | if (outlen < sizeof(outbuf)) |
| 170 | return -EIO; |
| 171 | |
| 172 | nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); |
| 173 | return 0; |
| 174 | } |
| 175 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 176 | #ifdef CONFIG_SFC_SRIOV |
| 177 | static int efx_ef10_get_vf_index(struct efx_nic *efx) |
| 178 | { |
| 179 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); |
| 180 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 181 | size_t outlen; |
| 182 | int rc; |
| 183 | |
| 184 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, |
| 185 | sizeof(outbuf), &outlen); |
| 186 | if (rc) |
| 187 | return rc; |
| 188 | if (outlen < sizeof(outbuf)) |
| 189 | return -EIO; |
| 190 | |
| 191 | nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF); |
| 192 | return 0; |
| 193 | } |
| 194 | #endif |
| 195 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 196 | static int efx_ef10_init_datapath_caps(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 197 | { |
Bert Kenward | ca889a05 | 2016-08-11 13:01:35 +0100 | [diff] [blame] | 198 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V2_OUT_LEN); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 199 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 200 | size_t outlen; |
| 201 | int rc; |
| 202 | |
| 203 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); |
| 204 | |
| 205 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, |
| 206 | outbuf, sizeof(outbuf), &outlen); |
| 207 | if (rc) |
| 208 | return rc; |
Bert Kenward | ca889a05 | 2016-08-11 13:01:35 +0100 | [diff] [blame] | 209 | if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) { |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 210 | netif_err(efx, drv, efx->net_dev, |
| 211 | "unable to read datapath firmware capabilities\n"); |
| 212 | return -EIO; |
| 213 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 214 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 215 | nic_data->datapath_caps = |
| 216 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); |
| 217 | |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 218 | if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) { |
Bert Kenward | ca889a05 | 2016-08-11 13:01:35 +0100 | [diff] [blame] | 219 | nic_data->datapath_caps2 = MCDI_DWORD(outbuf, |
| 220 | GET_CAPABILITIES_V2_OUT_FLAGS2); |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 221 | nic_data->piobuf_size = MCDI_WORD(outbuf, |
| 222 | GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF); |
| 223 | } else { |
Bert Kenward | ca889a05 | 2016-08-11 13:01:35 +0100 | [diff] [blame] | 224 | nic_data->datapath_caps2 = 0; |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 225 | nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE; |
| 226 | } |
Bert Kenward | ca889a05 | 2016-08-11 13:01:35 +0100 | [diff] [blame] | 227 | |
Daniel Pieczko | 8d9f9dd | 2015-05-06 00:56:55 +0100 | [diff] [blame] | 228 | /* record the DPCPU firmware IDs to determine VEB vswitching support. |
| 229 | */ |
| 230 | nic_data->rx_dpcpu_fw_id = |
| 231 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID); |
| 232 | nic_data->tx_dpcpu_fw_id = |
| 233 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID); |
| 234 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 235 | if (!(nic_data->datapath_caps & |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 236 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { |
| 237 | netif_err(efx, probe, efx->net_dev, |
| 238 | "current firmware does not support an RX prefix\n"); |
| 239 | return -ENODEV; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) |
| 246 | { |
| 247 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); |
| 248 | int rc; |
| 249 | |
| 250 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, |
| 251 | outbuf, sizeof(outbuf), NULL); |
| 252 | if (rc) |
| 253 | return rc; |
| 254 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); |
| 255 | return rc > 0 ? rc : -ERANGE; |
| 256 | } |
| 257 | |
Bert Kenward | d95e329 | 2016-08-11 13:02:36 +0100 | [diff] [blame] | 258 | static int efx_ef10_get_timer_workarounds(struct efx_nic *efx) |
| 259 | { |
| 260 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 261 | unsigned int implemented; |
| 262 | unsigned int enabled; |
| 263 | int rc; |
| 264 | |
| 265 | nic_data->workaround_35388 = false; |
| 266 | nic_data->workaround_61265 = false; |
| 267 | |
| 268 | rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled); |
| 269 | |
| 270 | if (rc == -ENOSYS) { |
| 271 | /* Firmware without GET_WORKAROUNDS - not a problem. */ |
| 272 | rc = 0; |
| 273 | } else if (rc == 0) { |
| 274 | /* Bug61265 workaround is always enabled if implemented. */ |
| 275 | if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265) |
| 276 | nic_data->workaround_61265 = true; |
| 277 | |
| 278 | if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) { |
| 279 | nic_data->workaround_35388 = true; |
| 280 | } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) { |
| 281 | /* Workaround is implemented but not enabled. |
| 282 | * Try to enable it. |
| 283 | */ |
| 284 | rc = efx_mcdi_set_workaround(efx, |
| 285 | MC_CMD_WORKAROUND_BUG35388, |
| 286 | true, NULL); |
| 287 | if (rc == 0) |
| 288 | nic_data->workaround_35388 = true; |
| 289 | /* If we failed to set the workaround just carry on. */ |
| 290 | rc = 0; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | netif_dbg(efx, probe, efx->net_dev, |
| 295 | "workaround for bug 35388 is %sabled\n", |
| 296 | nic_data->workaround_35388 ? "en" : "dis"); |
| 297 | netif_dbg(efx, probe, efx->net_dev, |
| 298 | "workaround for bug 61265 is %sabled\n", |
| 299 | nic_data->workaround_61265 ? "en" : "dis"); |
| 300 | |
| 301 | return rc; |
| 302 | } |
| 303 | |
| 304 | static void efx_ef10_process_timer_config(struct efx_nic *efx, |
| 305 | const efx_dword_t *data) |
| 306 | { |
| 307 | unsigned int max_count; |
| 308 | |
| 309 | if (EFX_EF10_WORKAROUND_61265(efx)) { |
| 310 | efx->timer_quantum_ns = MCDI_DWORD(data, |
| 311 | GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS); |
| 312 | efx->timer_max_ns = MCDI_DWORD(data, |
| 313 | GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS); |
| 314 | } else if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 315 | efx->timer_quantum_ns = MCDI_DWORD(data, |
| 316 | GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT); |
| 317 | max_count = MCDI_DWORD(data, |
| 318 | GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT); |
| 319 | efx->timer_max_ns = max_count * efx->timer_quantum_ns; |
| 320 | } else { |
| 321 | efx->timer_quantum_ns = MCDI_DWORD(data, |
| 322 | GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT); |
| 323 | max_count = MCDI_DWORD(data, |
| 324 | GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT); |
| 325 | efx->timer_max_ns = max_count * efx->timer_quantum_ns; |
| 326 | } |
| 327 | |
| 328 | netif_dbg(efx, probe, efx->net_dev, |
| 329 | "got timer properties from MC: quantum %u ns; max %u ns\n", |
| 330 | efx->timer_quantum_ns, efx->timer_max_ns); |
| 331 | } |
| 332 | |
| 333 | static int efx_ef10_get_timer_config(struct efx_nic *efx) |
| 334 | { |
| 335 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN); |
| 336 | int rc; |
| 337 | |
| 338 | rc = efx_ef10_get_timer_workarounds(efx); |
| 339 | if (rc) |
| 340 | return rc; |
| 341 | |
| 342 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0, |
| 343 | outbuf, sizeof(outbuf), NULL); |
| 344 | |
| 345 | if (rc == 0) { |
| 346 | efx_ef10_process_timer_config(efx, outbuf); |
| 347 | } else if (rc == -ENOSYS || rc == -EPERM) { |
| 348 | /* Not available - fall back to Huntington defaults. */ |
| 349 | unsigned int quantum; |
| 350 | |
| 351 | rc = efx_ef10_get_sysclk_freq(efx); |
| 352 | if (rc < 0) |
| 353 | return rc; |
| 354 | |
| 355 | quantum = 1536000 / rc; /* 1536 cycles */ |
| 356 | efx->timer_quantum_ns = quantum; |
| 357 | efx->timer_max_ns = efx->type->timer_period_max * quantum; |
| 358 | rc = 0; |
| 359 | } else { |
| 360 | efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, |
| 361 | MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN, |
| 362 | NULL, 0, rc); |
| 363 | } |
| 364 | |
| 365 | return rc; |
| 366 | } |
| 367 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 368 | 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] | 369 | { |
| 370 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); |
| 371 | size_t outlen; |
| 372 | int rc; |
| 373 | |
| 374 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); |
| 375 | |
| 376 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, |
| 377 | outbuf, sizeof(outbuf), &outlen); |
| 378 | if (rc) |
| 379 | return rc; |
| 380 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) |
| 381 | return -EIO; |
| 382 | |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 383 | ether_addr_copy(mac_address, |
| 384 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 388 | static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address) |
| 389 | { |
| 390 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN); |
| 391 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX); |
| 392 | size_t outlen; |
| 393 | int num_addrs, rc; |
| 394 | |
| 395 | MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID, |
| 396 | EVB_PORT_ID_ASSIGNED); |
| 397 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf, |
| 398 | sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); |
| 399 | |
| 400 | if (rc) |
| 401 | return rc; |
| 402 | if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN) |
| 403 | return -EIO; |
| 404 | |
| 405 | num_addrs = MCDI_DWORD(outbuf, |
| 406 | VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT); |
| 407 | |
| 408 | WARN_ON(num_addrs != 1); |
| 409 | |
| 410 | ether_addr_copy(mac_address, |
| 411 | MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR)); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 416 | static ssize_t efx_ef10_show_link_control_flag(struct device *dev, |
| 417 | struct device_attribute *attr, |
| 418 | char *buf) |
| 419 | { |
| 420 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 421 | |
| 422 | return sprintf(buf, "%d\n", |
| 423 | ((efx->mcdi->fn_flags) & |
| 424 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) |
| 425 | ? 1 : 0); |
| 426 | } |
| 427 | |
| 428 | static ssize_t efx_ef10_show_primary_flag(struct device *dev, |
| 429 | struct device_attribute *attr, |
| 430 | char *buf) |
| 431 | { |
| 432 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 433 | |
| 434 | return sprintf(buf, "%d\n", |
| 435 | ((efx->mcdi->fn_flags) & |
| 436 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY)) |
| 437 | ? 1 : 0); |
| 438 | } |
| 439 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 440 | static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid) |
| 441 | { |
| 442 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 443 | struct efx_ef10_vlan *vlan; |
| 444 | |
| 445 | WARN_ON(!mutex_is_locked(&nic_data->vlan_lock)); |
| 446 | |
| 447 | list_for_each_entry(vlan, &nic_data->vlan_list, list) { |
| 448 | if (vlan->vid == vid) |
| 449 | return vlan; |
| 450 | } |
| 451 | |
| 452 | return NULL; |
| 453 | } |
| 454 | |
| 455 | static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid) |
| 456 | { |
| 457 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 458 | struct efx_ef10_vlan *vlan; |
| 459 | int rc; |
| 460 | |
| 461 | mutex_lock(&nic_data->vlan_lock); |
| 462 | |
| 463 | vlan = efx_ef10_find_vlan(efx, vid); |
| 464 | if (vlan) { |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 465 | /* We add VID 0 on init. 8021q adds it on module init |
| 466 | * for all interfaces with VLAN filtring feature. |
| 467 | */ |
| 468 | if (vid == 0) |
| 469 | goto done_unlock; |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 470 | netif_warn(efx, drv, efx->net_dev, |
| 471 | "VLAN %u already added\n", vid); |
| 472 | rc = -EALREADY; |
| 473 | goto fail_exist; |
| 474 | } |
| 475 | |
| 476 | rc = -ENOMEM; |
| 477 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 478 | if (!vlan) |
| 479 | goto fail_alloc; |
| 480 | |
| 481 | vlan->vid = vid; |
| 482 | |
| 483 | list_add_tail(&vlan->list, &nic_data->vlan_list); |
| 484 | |
| 485 | if (efx->filter_state) { |
| 486 | mutex_lock(&efx->mac_lock); |
| 487 | down_write(&efx->filter_sem); |
| 488 | rc = efx_ef10_filter_add_vlan(efx, vlan->vid); |
| 489 | up_write(&efx->filter_sem); |
| 490 | mutex_unlock(&efx->mac_lock); |
| 491 | if (rc) |
| 492 | goto fail_filter_add_vlan; |
| 493 | } |
| 494 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 495 | done_unlock: |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 496 | mutex_unlock(&nic_data->vlan_lock); |
| 497 | return 0; |
| 498 | |
| 499 | fail_filter_add_vlan: |
| 500 | list_del(&vlan->list); |
| 501 | kfree(vlan); |
| 502 | fail_alloc: |
| 503 | fail_exist: |
| 504 | mutex_unlock(&nic_data->vlan_lock); |
| 505 | return rc; |
| 506 | } |
| 507 | |
| 508 | static void efx_ef10_del_vlan_internal(struct efx_nic *efx, |
| 509 | struct efx_ef10_vlan *vlan) |
| 510 | { |
| 511 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 512 | |
| 513 | WARN_ON(!mutex_is_locked(&nic_data->vlan_lock)); |
| 514 | |
| 515 | if (efx->filter_state) { |
| 516 | down_write(&efx->filter_sem); |
| 517 | efx_ef10_filter_del_vlan(efx, vlan->vid); |
| 518 | up_write(&efx->filter_sem); |
| 519 | } |
| 520 | |
| 521 | list_del(&vlan->list); |
| 522 | kfree(vlan); |
| 523 | } |
| 524 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 525 | static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid) |
| 526 | { |
| 527 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 528 | struct efx_ef10_vlan *vlan; |
| 529 | int rc = 0; |
| 530 | |
| 531 | /* 8021q removes VID 0 on module unload for all interfaces |
| 532 | * with VLAN filtering feature. We need to keep it to receive |
| 533 | * untagged traffic. |
| 534 | */ |
| 535 | if (vid == 0) |
| 536 | return 0; |
| 537 | |
| 538 | mutex_lock(&nic_data->vlan_lock); |
| 539 | |
| 540 | vlan = efx_ef10_find_vlan(efx, vid); |
| 541 | if (!vlan) { |
| 542 | netif_err(efx, drv, efx->net_dev, |
| 543 | "VLAN %u to be deleted not found\n", vid); |
| 544 | rc = -ENOENT; |
| 545 | } else { |
| 546 | efx_ef10_del_vlan_internal(efx, vlan); |
| 547 | } |
| 548 | |
| 549 | mutex_unlock(&nic_data->vlan_lock); |
| 550 | |
| 551 | return rc; |
| 552 | } |
| 553 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 554 | static void efx_ef10_cleanup_vlans(struct efx_nic *efx) |
| 555 | { |
| 556 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 557 | struct efx_ef10_vlan *vlan, *next_vlan; |
| 558 | |
| 559 | mutex_lock(&nic_data->vlan_lock); |
| 560 | list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list) |
| 561 | efx_ef10_del_vlan_internal(efx, vlan); |
| 562 | mutex_unlock(&nic_data->vlan_lock); |
| 563 | } |
| 564 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 565 | static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag, |
| 566 | NULL); |
| 567 | static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL); |
| 568 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 569 | static int efx_ef10_probe(struct efx_nic *efx) |
| 570 | { |
| 571 | struct efx_ef10_nic_data *nic_data; |
| 572 | int i, rc; |
| 573 | |
Ben Hutchings | aa3930e | 2014-02-12 18:59:19 +0000 | [diff] [blame] | 574 | /* We can have one VI for each 8K region. However, until we |
| 575 | * use TX option descriptors we need two TX queues per channel. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 576 | */ |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 577 | efx->max_channels = min_t(unsigned int, |
| 578 | EFX_MAX_CHANNELS, |
| 579 | efx_ef10_mem_map_size(efx) / |
| 580 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); |
| 581 | efx->max_tx_channels = efx->max_channels; |
Edward Cree | 9fd3d3a | 2014-11-03 14:14:35 +0000 | [diff] [blame] | 582 | if (WARN_ON(efx->max_channels == 0)) |
| 583 | return -EIO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 584 | |
| 585 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
| 586 | if (!nic_data) |
| 587 | return -ENOMEM; |
| 588 | efx->nic_data = nic_data; |
| 589 | |
Edward Cree | 75aba2a | 2015-05-27 13:13:54 +0100 | [diff] [blame] | 590 | /* we assume later that we can copy from this buffer in dwords */ |
| 591 | BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4); |
| 592 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 593 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, |
| 594 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); |
| 595 | if (rc) |
| 596 | goto fail1; |
| 597 | |
| 598 | /* Get the MC's warm boot count. In case it's rebooting right |
| 599 | * now, be prepared to retry. |
| 600 | */ |
| 601 | i = 0; |
| 602 | for (;;) { |
| 603 | rc = efx_ef10_get_warm_boot_count(efx); |
| 604 | if (rc >= 0) |
| 605 | break; |
| 606 | if (++i == 5) |
| 607 | goto fail2; |
| 608 | ssleep(1); |
| 609 | } |
| 610 | nic_data->warm_boot_count = rc; |
| 611 | |
| 612 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 613 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 614 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 615 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 616 | /* In case we're recovering from a crash (kexec), we want to |
| 617 | * cancel any outstanding request by the previous user of this |
| 618 | * function. We send a special message using the least |
| 619 | * significant bits of the 'high' (doorbell) register. |
| 620 | */ |
| 621 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); |
| 622 | |
| 623 | rc = efx_mcdi_init(efx); |
| 624 | if (rc) |
| 625 | goto fail2; |
| 626 | |
| 627 | /* Reset (most) configuration for this function */ |
| 628 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); |
| 629 | if (rc) |
| 630 | goto fail3; |
| 631 | |
| 632 | /* Enable event logging */ |
| 633 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); |
| 634 | if (rc) |
| 635 | goto fail3; |
| 636 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 637 | rc = device_create_file(&efx->pci_dev->dev, |
| 638 | &dev_attr_link_control_flag); |
Daniel Pieczko | 1cd9ecb | 2015-05-06 00:57:53 +0100 | [diff] [blame] | 639 | if (rc) |
| 640 | goto fail3; |
| 641 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 642 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 643 | if (rc) |
| 644 | goto fail4; |
| 645 | |
| 646 | rc = efx_ef10_get_pf_index(efx); |
| 647 | if (rc) |
| 648 | goto fail5; |
| 649 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 650 | rc = efx_ef10_init_datapath_caps(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 651 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 652 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 653 | |
| 654 | efx->rx_packet_len_offset = |
| 655 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; |
| 656 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 657 | rc = efx_mcdi_port_get_number(efx); |
| 658 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 659 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 660 | efx->port_num = rc; |
| 661 | |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 662 | rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 663 | if (rc) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 664 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 665 | |
Bert Kenward | d95e329 | 2016-08-11 13:02:36 +0100 | [diff] [blame] | 666 | rc = efx_ef10_get_timer_config(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 667 | if (rc < 0) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 668 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 669 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 670 | rc = efx_mcdi_mon_probe(efx); |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 671 | if (rc && rc != -EPERM) |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 672 | goto fail5; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 673 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 674 | efx_ptp_probe(efx, NULL); |
| 675 | |
Shradha Shah | 1d051e0 | 2015-06-02 11:38:16 +0100 | [diff] [blame] | 676 | #ifdef CONFIG_SFC_SRIOV |
| 677 | if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) { |
| 678 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; |
| 679 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 680 | |
| 681 | efx_pf->type->get_mac_address(efx_pf, nic_data->port_id); |
| 682 | } else |
| 683 | #endif |
| 684 | ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr); |
| 685 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 686 | INIT_LIST_HEAD(&nic_data->vlan_list); |
| 687 | mutex_init(&nic_data->vlan_lock); |
| 688 | |
| 689 | /* Add unspecified VID to support VLAN filtering being disabled */ |
| 690 | rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC); |
| 691 | if (rc) |
| 692 | goto fail_add_vid_unspec; |
| 693 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 694 | /* If VLAN filtering is enabled, we need VID 0 to get untagged |
| 695 | * traffic. It is added automatically if 8021q module is loaded, |
| 696 | * but we can't rely on it since module may be not loaded. |
| 697 | */ |
| 698 | rc = efx_ef10_add_vlan(efx, 0); |
| 699 | if (rc) |
| 700 | goto fail_add_vid_0; |
| 701 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 702 | return 0; |
| 703 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 704 | fail_add_vid_0: |
| 705 | efx_ef10_cleanup_vlans(efx); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 706 | fail_add_vid_unspec: |
| 707 | mutex_destroy(&nic_data->vlan_lock); |
| 708 | efx_ptp_remove(efx); |
| 709 | efx_mcdi_mon_remove(efx); |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 710 | fail5: |
| 711 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 712 | fail4: |
| 713 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 714 | fail3: |
| 715 | efx_mcdi_fini(efx); |
| 716 | fail2: |
| 717 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 718 | fail1: |
| 719 | kfree(nic_data); |
| 720 | efx->nic_data = NULL; |
| 721 | return rc; |
| 722 | } |
| 723 | |
| 724 | static int efx_ef10_free_vis(struct efx_nic *efx) |
| 725 | { |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 726 | MCDI_DECLARE_BUF_ERR(outbuf); |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 727 | size_t outlen; |
| 728 | int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0, |
| 729 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 730 | |
| 731 | /* -EALREADY means nothing to free, so ignore */ |
| 732 | if (rc == -EALREADY) |
| 733 | rc = 0; |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 734 | if (rc) |
| 735 | efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen, |
| 736 | rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 737 | return rc; |
| 738 | } |
| 739 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 740 | #ifdef EFX_USE_PIO |
| 741 | |
| 742 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 743 | { |
| 744 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 745 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN); |
| 746 | unsigned int i; |
| 747 | int rc; |
| 748 | |
| 749 | BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0); |
| 750 | |
| 751 | for (i = 0; i < nic_data->n_piobufs; i++) { |
| 752 | MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE, |
| 753 | nic_data->piobuf_handle[i]); |
| 754 | rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf), |
| 755 | NULL, 0, NULL); |
| 756 | WARN_ON(rc); |
| 757 | } |
| 758 | |
| 759 | nic_data->n_piobufs = 0; |
| 760 | } |
| 761 | |
| 762 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 763 | { |
| 764 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 765 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN); |
| 766 | unsigned int i; |
| 767 | size_t outlen; |
| 768 | int rc = 0; |
| 769 | |
| 770 | BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0); |
| 771 | |
| 772 | for (i = 0; i < n; i++) { |
Bert Kenward | 09a0420 | 2015-12-23 08:58:15 +0000 | [diff] [blame] | 773 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0, |
| 774 | outbuf, sizeof(outbuf), &outlen); |
| 775 | if (rc) { |
| 776 | /* Don't display the MC error if we didn't have space |
| 777 | * for a VF. |
| 778 | */ |
| 779 | if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC)) |
| 780 | efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF, |
| 781 | 0, outbuf, outlen, rc); |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 782 | break; |
Bert Kenward | 09a0420 | 2015-12-23 08:58:15 +0000 | [diff] [blame] | 783 | } |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 784 | if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) { |
| 785 | rc = -EIO; |
| 786 | break; |
| 787 | } |
| 788 | nic_data->piobuf_handle[i] = |
| 789 | MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE); |
| 790 | netif_dbg(efx, probe, efx->net_dev, |
| 791 | "allocated PIO buffer %u handle %x\n", i, |
| 792 | nic_data->piobuf_handle[i]); |
| 793 | } |
| 794 | |
| 795 | nic_data->n_piobufs = i; |
| 796 | if (rc) |
| 797 | efx_ef10_free_piobufs(efx); |
| 798 | return rc; |
| 799 | } |
| 800 | |
| 801 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 802 | { |
| 803 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 804 | _MCDI_DECLARE_BUF(inbuf, |
| 805 | max(MC_CMD_LINK_PIOBUF_IN_LEN, |
| 806 | MC_CMD_UNLINK_PIOBUF_IN_LEN)); |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 807 | struct efx_channel *channel; |
| 808 | struct efx_tx_queue *tx_queue; |
| 809 | unsigned int offset, index; |
| 810 | int rc; |
| 811 | |
| 812 | BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0); |
| 813 | BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0); |
| 814 | |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 815 | memset(inbuf, 0, sizeof(inbuf)); |
| 816 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 817 | /* Link a buffer to each VI in the write-combining mapping */ |
| 818 | for (index = 0; index < nic_data->n_piobufs; ++index) { |
| 819 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 820 | nic_data->piobuf_handle[index]); |
| 821 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 822 | nic_data->pio_write_vi_base + index); |
| 823 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 824 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 825 | NULL, 0, NULL); |
| 826 | if (rc) { |
| 827 | netif_err(efx, drv, efx->net_dev, |
| 828 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 829 | nic_data->pio_write_vi_base + index, index, |
| 830 | rc); |
| 831 | goto fail; |
| 832 | } |
| 833 | netif_dbg(efx, probe, efx->net_dev, |
| 834 | "linked VI %u to PIO buffer %u\n", |
| 835 | nic_data->pio_write_vi_base + index, index); |
| 836 | } |
| 837 | |
| 838 | /* Link a buffer to each TX queue */ |
| 839 | efx_for_each_channel(channel, efx) { |
| 840 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 841 | /* We assign the PIO buffers to queues in |
| 842 | * reverse order to allow for the following |
| 843 | * special case. |
| 844 | */ |
| 845 | offset = ((efx->tx_channel_offset + efx->n_tx_channels - |
| 846 | tx_queue->channel->channel - 1) * |
| 847 | efx_piobuf_size); |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 848 | index = offset / nic_data->piobuf_size; |
| 849 | offset = offset % nic_data->piobuf_size; |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 850 | |
| 851 | /* When the host page size is 4K, the first |
| 852 | * host page in the WC mapping may be within |
| 853 | * the same VI page as the last TX queue. We |
| 854 | * can only link one buffer to each VI. |
| 855 | */ |
| 856 | if (tx_queue->queue == nic_data->pio_write_vi_base) { |
| 857 | BUG_ON(index != 0); |
| 858 | rc = 0; |
| 859 | } else { |
| 860 | MCDI_SET_DWORD(inbuf, |
| 861 | LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 862 | nic_data->piobuf_handle[index]); |
| 863 | MCDI_SET_DWORD(inbuf, |
| 864 | LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 865 | tx_queue->queue); |
| 866 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 867 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 868 | NULL, 0, NULL); |
| 869 | } |
| 870 | |
| 871 | if (rc) { |
| 872 | /* This is non-fatal; the TX path just |
| 873 | * won't use PIO for this queue |
| 874 | */ |
| 875 | netif_err(efx, drv, efx->net_dev, |
| 876 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 877 | tx_queue->queue, index, rc); |
| 878 | tx_queue->piobuf = NULL; |
| 879 | } else { |
| 880 | tx_queue->piobuf = |
| 881 | nic_data->pio_write_base + |
| 882 | index * EFX_VI_PAGE_SIZE + offset; |
| 883 | tx_queue->piobuf_offset = offset; |
| 884 | netif_dbg(efx, probe, efx->net_dev, |
| 885 | "linked VI %u to PIO buffer %u offset %x addr %p\n", |
| 886 | tx_queue->queue, index, |
| 887 | tx_queue->piobuf_offset, |
| 888 | tx_queue->piobuf); |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | |
| 895 | fail: |
| 896 | while (index--) { |
| 897 | MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE, |
| 898 | nic_data->pio_write_vi_base + index); |
| 899 | efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF, |
| 900 | inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN, |
| 901 | NULL, 0, NULL); |
| 902 | } |
| 903 | return rc; |
| 904 | } |
| 905 | |
Edward Cree | c0795bf | 2016-05-24 18:53:36 +0100 | [diff] [blame] | 906 | static void efx_ef10_forget_old_piobufs(struct efx_nic *efx) |
| 907 | { |
| 908 | struct efx_channel *channel; |
| 909 | struct efx_tx_queue *tx_queue; |
| 910 | |
| 911 | /* All our existing PIO buffers went away */ |
| 912 | efx_for_each_channel(channel, efx) |
| 913 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 914 | tx_queue->piobuf = NULL; |
| 915 | } |
| 916 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 917 | #else /* !EFX_USE_PIO */ |
| 918 | |
| 919 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 920 | { |
| 921 | return n == 0 ? 0 : -ENOBUFS; |
| 922 | } |
| 923 | |
| 924 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 925 | { |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 930 | { |
| 931 | } |
| 932 | |
Edward Cree | c0795bf | 2016-05-24 18:53:36 +0100 | [diff] [blame] | 933 | static void efx_ef10_forget_old_piobufs(struct efx_nic *efx) |
| 934 | { |
| 935 | } |
| 936 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 937 | #endif /* EFX_USE_PIO */ |
| 938 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 939 | static void efx_ef10_remove(struct efx_nic *efx) |
| 940 | { |
| 941 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 942 | int rc; |
| 943 | |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 944 | #ifdef CONFIG_SFC_SRIOV |
| 945 | struct efx_ef10_nic_data *nic_data_pf; |
| 946 | struct pci_dev *pci_dev_pf; |
| 947 | struct efx_nic *efx_pf; |
| 948 | struct ef10_vf *vf; |
| 949 | |
| 950 | if (efx->pci_dev->is_virtfn) { |
| 951 | pci_dev_pf = efx->pci_dev->physfn; |
| 952 | if (pci_dev_pf) { |
| 953 | efx_pf = pci_get_drvdata(pci_dev_pf); |
| 954 | nic_data_pf = efx_pf->nic_data; |
| 955 | vf = nic_data_pf->vf + nic_data->vf_index; |
| 956 | vf->efx = NULL; |
| 957 | } else |
| 958 | netif_info(efx, drv, efx->net_dev, |
| 959 | "Could not get the PF id from VF\n"); |
| 960 | } |
| 961 | #endif |
| 962 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 963 | efx_ef10_cleanup_vlans(efx); |
| 964 | mutex_destroy(&nic_data->vlan_lock); |
| 965 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 966 | efx_ptp_remove(efx); |
| 967 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 968 | efx_mcdi_mon_remove(efx); |
| 969 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 970 | efx_ef10_rx_free_indir_table(efx); |
| 971 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 972 | if (nic_data->wc_membase) |
| 973 | iounmap(nic_data->wc_membase); |
| 974 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 975 | rc = efx_ef10_free_vis(efx); |
| 976 | WARN_ON(rc != 0); |
| 977 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 978 | if (!nic_data->must_restore_piobufs) |
| 979 | efx_ef10_free_piobufs(efx); |
| 980 | |
Shradha Shah | 0f5c084 | 2015-06-02 11:37:58 +0100 | [diff] [blame] | 981 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
| 982 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); |
| 983 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 984 | efx_mcdi_fini(efx); |
| 985 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 986 | kfree(nic_data); |
| 987 | } |
| 988 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 989 | static int efx_ef10_probe_pf(struct efx_nic *efx) |
| 990 | { |
| 991 | return efx_ef10_probe(efx); |
| 992 | } |
| 993 | |
Andrew Rybchenko | 38d27f3 | 2016-06-15 17:52:08 +0100 | [diff] [blame] | 994 | int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id, |
| 995 | u32 *port_flags, u32 *vadaptor_flags, |
| 996 | unsigned int *vlan_tags) |
| 997 | { |
| 998 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 999 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN); |
| 1000 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN); |
| 1001 | size_t outlen; |
| 1002 | int rc; |
| 1003 | |
| 1004 | if (nic_data->datapath_caps & |
| 1005 | (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) { |
| 1006 | MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID, |
| 1007 | port_id); |
| 1008 | |
| 1009 | rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf), |
| 1010 | outbuf, sizeof(outbuf), &outlen); |
| 1011 | if (rc) |
| 1012 | return rc; |
| 1013 | |
| 1014 | if (outlen < sizeof(outbuf)) { |
| 1015 | rc = -EIO; |
| 1016 | return rc; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if (port_flags) |
| 1021 | *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS); |
| 1022 | if (vadaptor_flags) |
| 1023 | *vadaptor_flags = |
| 1024 | MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS); |
| 1025 | if (vlan_tags) |
| 1026 | *vlan_tags = |
| 1027 | MCDI_DWORD(outbuf, |
| 1028 | VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS); |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 1033 | int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id) |
| 1034 | { |
| 1035 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN); |
| 1036 | |
| 1037 | MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id); |
| 1038 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf), |
| 1039 | NULL, 0, NULL); |
| 1040 | } |
| 1041 | |
| 1042 | int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id) |
| 1043 | { |
| 1044 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN); |
| 1045 | |
| 1046 | MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id); |
| 1047 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf), |
| 1048 | NULL, 0, NULL); |
| 1049 | } |
| 1050 | |
| 1051 | int efx_ef10_vport_add_mac(struct efx_nic *efx, |
| 1052 | unsigned int port_id, u8 *mac) |
| 1053 | { |
| 1054 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN); |
| 1055 | |
| 1056 | MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 1057 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac); |
| 1058 | |
| 1059 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf, |
| 1060 | sizeof(inbuf), NULL, 0, NULL); |
| 1061 | } |
| 1062 | |
| 1063 | int efx_ef10_vport_del_mac(struct efx_nic *efx, |
| 1064 | unsigned int port_id, u8 *mac) |
| 1065 | { |
| 1066 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN); |
| 1067 | |
| 1068 | MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 1069 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac); |
| 1070 | |
| 1071 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf, |
| 1072 | sizeof(inbuf), NULL, 0, NULL); |
| 1073 | } |
| 1074 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 1075 | #ifdef CONFIG_SFC_SRIOV |
| 1076 | static int efx_ef10_probe_vf(struct efx_nic *efx) |
| 1077 | { |
| 1078 | int rc; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 1079 | struct pci_dev *pci_dev_pf; |
| 1080 | |
| 1081 | /* If the parent PF has no VF data structure, it doesn't know about this |
| 1082 | * VF so fail probe. The VF needs to be re-created. This can happen |
| 1083 | * if the PF driver is unloaded while the VF is assigned to a guest. |
| 1084 | */ |
| 1085 | pci_dev_pf = efx->pci_dev->physfn; |
| 1086 | if (pci_dev_pf) { |
| 1087 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 1088 | struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data; |
| 1089 | |
| 1090 | if (!nic_data_pf->vf) { |
| 1091 | netif_info(efx, drv, efx->net_dev, |
| 1092 | "The VF cannot link to its parent PF; " |
| 1093 | "please destroy and re-create the VF\n"); |
| 1094 | return -EBUSY; |
| 1095 | } |
| 1096 | } |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 1097 | |
| 1098 | rc = efx_ef10_probe(efx); |
| 1099 | if (rc) |
| 1100 | return rc; |
| 1101 | |
| 1102 | rc = efx_ef10_get_vf_index(efx); |
| 1103 | if (rc) |
| 1104 | goto fail; |
| 1105 | |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 1106 | if (efx->pci_dev->is_virtfn) { |
| 1107 | if (efx->pci_dev->physfn) { |
| 1108 | struct efx_nic *efx_pf = |
| 1109 | pci_get_drvdata(efx->pci_dev->physfn); |
| 1110 | struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data; |
| 1111 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1112 | |
| 1113 | nic_data_p->vf[nic_data->vf_index].efx = efx; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 1114 | nic_data_p->vf[nic_data->vf_index].pci_dev = |
| 1115 | efx->pci_dev; |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 1116 | } else |
| 1117 | netif_info(efx, drv, efx->net_dev, |
| 1118 | "Could not get the PF id from VF\n"); |
| 1119 | } |
| 1120 | |
Shradha Shah | 88a37de | 2015-05-20 11:09:15 +0100 | [diff] [blame] | 1121 | return 0; |
| 1122 | |
| 1123 | fail: |
| 1124 | efx_ef10_remove(efx); |
| 1125 | return rc; |
| 1126 | } |
| 1127 | #else |
| 1128 | static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused))) |
| 1129 | { |
| 1130 | return 0; |
| 1131 | } |
| 1132 | #endif |
| 1133 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1134 | static int efx_ef10_alloc_vis(struct efx_nic *efx, |
| 1135 | unsigned int min_vis, unsigned int max_vis) |
| 1136 | { |
| 1137 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); |
| 1138 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); |
| 1139 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1140 | size_t outlen; |
| 1141 | int rc; |
| 1142 | |
| 1143 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); |
| 1144 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); |
| 1145 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), |
| 1146 | outbuf, sizeof(outbuf), &outlen); |
| 1147 | if (rc != 0) |
| 1148 | return rc; |
| 1149 | |
| 1150 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) |
| 1151 | return -EIO; |
| 1152 | |
| 1153 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", |
| 1154 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); |
| 1155 | |
| 1156 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); |
| 1157 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1161 | /* Note that the failure path of this function does not free |
| 1162 | * resources, as this will be done by efx_ef10_remove(). |
| 1163 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1164 | static int efx_ef10_dimension_resources(struct efx_nic *efx) |
| 1165 | { |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1166 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1167 | unsigned int uc_mem_map_size, wc_mem_map_size; |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1168 | unsigned int min_vis = max(EFX_TXQ_TYPES, |
| 1169 | efx_separate_tx_channels ? 2 : 1); |
| 1170 | unsigned int channel_vis, pio_write_vi_base, max_vis; |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1171 | void __iomem *membase; |
| 1172 | int rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1173 | |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1174 | channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1175 | |
| 1176 | #ifdef EFX_USE_PIO |
| 1177 | /* Try to allocate PIO buffers if wanted and if the full |
| 1178 | * number of PIO buffers would be sufficient to allocate one |
| 1179 | * copy-buffer per TX channel. Failure is non-fatal, as there |
| 1180 | * are only a small number of PIO buffers shared between all |
| 1181 | * functions of the controller. |
| 1182 | */ |
| 1183 | if (efx_piobuf_size != 0 && |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 1184 | nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >= |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1185 | efx->n_tx_channels) { |
| 1186 | unsigned int n_piobufs = |
| 1187 | DIV_ROUND_UP(efx->n_tx_channels, |
Edward Cree | c634700 | 2017-01-13 21:20:29 +0000 | [diff] [blame] | 1188 | nic_data->piobuf_size / efx_piobuf_size); |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1189 | |
| 1190 | rc = efx_ef10_alloc_piobufs(efx, n_piobufs); |
Tomáš Pilař | 6eacfb5 | 2017-01-25 13:48:17 +0000 | [diff] [blame] | 1191 | if (rc == -ENOSPC) |
| 1192 | netif_dbg(efx, probe, efx->net_dev, |
| 1193 | "out of PIO buffers; cannot allocate more\n"); |
| 1194 | else if (rc == -EPERM) |
| 1195 | netif_dbg(efx, probe, efx->net_dev, |
| 1196 | "not permitted to allocate PIO buffers\n"); |
| 1197 | else if (rc) |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1198 | netif_err(efx, probe, efx->net_dev, |
| 1199 | "failed to allocate PIO buffers (%d)\n", rc); |
| 1200 | else |
| 1201 | netif_dbg(efx, probe, efx->net_dev, |
| 1202 | "allocated %u PIO buffers\n", n_piobufs); |
| 1203 | } |
| 1204 | #else |
| 1205 | nic_data->n_piobufs = 0; |
| 1206 | #endif |
| 1207 | |
| 1208 | /* PIO buffers should be mapped with write-combining enabled, |
| 1209 | * and we want to make single UC and WC mappings rather than |
| 1210 | * several of each (in fact that's the only option if host |
| 1211 | * page size is >4K). So we may allocate some extra VIs just |
| 1212 | * for writing PIO buffers through. |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 1213 | * |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1214 | * The UC mapping contains (channel_vis - 1) complete VIs and the |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 1215 | * first half of the next VI. Then the WC mapping begins with |
| 1216 | * the second half of this last VI. |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1217 | */ |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1218 | uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE + |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1219 | ER_DZ_TX_PIOBUF); |
| 1220 | if (nic_data->n_piobufs) { |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 1221 | /* pio_write_vi_base rounds down to give the number of complete |
| 1222 | * VIs inside the UC mapping. |
| 1223 | */ |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1224 | pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE; |
| 1225 | wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base + |
| 1226 | nic_data->n_piobufs) * |
| 1227 | EFX_VI_PAGE_SIZE) - |
| 1228 | uc_mem_map_size); |
| 1229 | max_vis = pio_write_vi_base + nic_data->n_piobufs; |
| 1230 | } else { |
| 1231 | pio_write_vi_base = 0; |
| 1232 | wc_mem_map_size = 0; |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1233 | max_vis = channel_vis; |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /* In case the last attached driver failed to free VIs, do it now */ |
| 1237 | rc = efx_ef10_free_vis(efx); |
| 1238 | if (rc != 0) |
| 1239 | return rc; |
| 1240 | |
| 1241 | rc = efx_ef10_alloc_vis(efx, min_vis, max_vis); |
| 1242 | if (rc != 0) |
| 1243 | return rc; |
| 1244 | |
Shradha Shah | b0fbdae | 2015-08-28 10:55:42 +0100 | [diff] [blame] | 1245 | if (nic_data->n_allocated_vis < channel_vis) { |
| 1246 | netif_info(efx, drv, efx->net_dev, |
| 1247 | "Could not allocate enough VIs to satisfy RSS" |
| 1248 | " requirements. Performance may not be optimal.\n"); |
| 1249 | /* We didn't get the VIs to populate our channels. |
| 1250 | * We could keep what we got but then we'd have more |
| 1251 | * interrupts than we need. |
| 1252 | * Instead calculate new max_channels and restart |
| 1253 | */ |
| 1254 | efx->max_channels = nic_data->n_allocated_vis; |
| 1255 | efx->max_tx_channels = |
| 1256 | nic_data->n_allocated_vis / EFX_TXQ_TYPES; |
| 1257 | |
| 1258 | efx_ef10_free_vis(efx); |
| 1259 | return -EAGAIN; |
| 1260 | } |
| 1261 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1262 | /* If we didn't get enough VIs to map all the PIO buffers, free the |
| 1263 | * PIO buffers |
| 1264 | */ |
| 1265 | if (nic_data->n_piobufs && |
| 1266 | nic_data->n_allocated_vis < |
| 1267 | pio_write_vi_base + nic_data->n_piobufs) { |
| 1268 | netif_dbg(efx, probe, efx->net_dev, |
| 1269 | "%u VIs are not sufficient to map %u PIO buffers\n", |
| 1270 | nic_data->n_allocated_vis, nic_data->n_piobufs); |
| 1271 | efx_ef10_free_piobufs(efx); |
| 1272 | } |
| 1273 | |
| 1274 | /* Shrink the original UC mapping of the memory BAR */ |
| 1275 | membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size); |
| 1276 | if (!membase) { |
| 1277 | netif_err(efx, probe, efx->net_dev, |
| 1278 | "could not shrink memory BAR to %x\n", |
| 1279 | uc_mem_map_size); |
| 1280 | return -ENOMEM; |
| 1281 | } |
| 1282 | iounmap(efx->membase); |
| 1283 | efx->membase = membase; |
| 1284 | |
| 1285 | /* Set up the WC mapping if needed */ |
| 1286 | if (wc_mem_map_size) { |
| 1287 | nic_data->wc_membase = ioremap_wc(efx->membase_phys + |
| 1288 | uc_mem_map_size, |
| 1289 | wc_mem_map_size); |
| 1290 | if (!nic_data->wc_membase) { |
| 1291 | netif_err(efx, probe, efx->net_dev, |
| 1292 | "could not allocate WC mapping of size %x\n", |
| 1293 | wc_mem_map_size); |
| 1294 | return -ENOMEM; |
| 1295 | } |
| 1296 | nic_data->pio_write_vi_base = pio_write_vi_base; |
| 1297 | nic_data->pio_write_base = |
| 1298 | nic_data->wc_membase + |
| 1299 | (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF - |
| 1300 | uc_mem_map_size); |
| 1301 | |
| 1302 | rc = efx_ef10_link_piobufs(efx); |
| 1303 | if (rc) |
| 1304 | efx_ef10_free_piobufs(efx); |
| 1305 | } |
| 1306 | |
| 1307 | netif_dbg(efx, probe, efx->net_dev, |
| 1308 | "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", |
| 1309 | &efx->membase_phys, efx->membase, uc_mem_map_size, |
| 1310 | nic_data->wc_membase, wc_mem_map_size); |
| 1311 | |
| 1312 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int efx_ef10_init_nic(struct efx_nic *efx) |
| 1316 | { |
| 1317 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1318 | int rc; |
| 1319 | |
Ben Hutchings | a915ccc | 2013-09-05 22:51:55 +0100 | [diff] [blame] | 1320 | if (nic_data->must_check_datapath_caps) { |
| 1321 | rc = efx_ef10_init_datapath_caps(efx); |
| 1322 | if (rc) |
| 1323 | return rc; |
| 1324 | nic_data->must_check_datapath_caps = false; |
| 1325 | } |
| 1326 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1327 | if (nic_data->must_realloc_vis) { |
| 1328 | /* We cannot let the number of VIs change now */ |
| 1329 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, |
| 1330 | nic_data->n_allocated_vis); |
| 1331 | if (rc) |
| 1332 | return rc; |
| 1333 | nic_data->must_realloc_vis = false; |
| 1334 | } |
| 1335 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1336 | if (nic_data->must_restore_piobufs && nic_data->n_piobufs) { |
| 1337 | rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs); |
| 1338 | if (rc == 0) { |
| 1339 | rc = efx_ef10_link_piobufs(efx); |
| 1340 | if (rc) |
| 1341 | efx_ef10_free_piobufs(efx); |
| 1342 | } |
| 1343 | |
Tomáš Pilař | 6eacfb5 | 2017-01-25 13:48:17 +0000 | [diff] [blame] | 1344 | /* Log an error on failure, but this is non-fatal. |
| 1345 | * Permission errors are less important - we've presumably |
| 1346 | * had the PIO buffer licence removed. |
| 1347 | */ |
| 1348 | if (rc == -EPERM) |
| 1349 | netif_dbg(efx, drv, efx->net_dev, |
| 1350 | "not permitted to restore PIO buffers\n"); |
| 1351 | else if (rc) |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 1352 | netif_err(efx, drv, efx->net_dev, |
| 1353 | "failed to restore PIO buffers (%d)\n", rc); |
| 1354 | nic_data->must_restore_piobufs = false; |
| 1355 | } |
| 1356 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1357 | /* don't fail init if RSS setup doesn't work */ |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 1358 | rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL); |
Edward Cree | 4fdda95 | 2017-01-04 15:10:56 +0000 | [diff] [blame] | 1359 | efx->rss_active = (rc == 0); |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1360 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1361 | return 0; |
| 1362 | } |
| 1363 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1364 | static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) |
| 1365 | { |
| 1366 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Daniel Pieczko | 774ad03 | 2015-07-31 11:15:22 +0100 | [diff] [blame] | 1367 | #ifdef CONFIG_SFC_SRIOV |
| 1368 | unsigned int i; |
| 1369 | #endif |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1370 | |
| 1371 | /* All our allocations have been reset */ |
| 1372 | nic_data->must_realloc_vis = true; |
| 1373 | nic_data->must_restore_filters = true; |
| 1374 | nic_data->must_restore_piobufs = true; |
Edward Cree | c0795bf | 2016-05-24 18:53:36 +0100 | [diff] [blame] | 1375 | efx_ef10_forget_old_piobufs(efx); |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1376 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
Daniel Pieczko | 774ad03 | 2015-07-31 11:15:22 +0100 | [diff] [blame] | 1377 | |
| 1378 | /* Driver-created vswitches and vports must be re-created */ |
| 1379 | nic_data->must_probe_vswitching = true; |
| 1380 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 1381 | #ifdef CONFIG_SFC_SRIOV |
| 1382 | if (nic_data->vf) |
| 1383 | for (i = 0; i < efx->vf_count; i++) |
| 1384 | nic_data->vf[i].vport_id = 0; |
| 1385 | #endif |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 1388 | static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason) |
| 1389 | { |
| 1390 | if (reason == RESET_TYPE_MC_FAILURE) |
| 1391 | return RESET_TYPE_DATAPATH; |
| 1392 | |
| 1393 | return efx_mcdi_map_reset_reason(reason); |
| 1394 | } |
| 1395 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1396 | static int efx_ef10_map_reset_flags(u32 *flags) |
| 1397 | { |
| 1398 | enum { |
| 1399 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << |
| 1400 | ETH_RESET_SHARED_SHIFT), |
| 1401 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | |
| 1402 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | |
| 1403 | ETH_RESET_PHY | ETH_RESET_MGMT) << |
| 1404 | ETH_RESET_SHARED_SHIFT) |
| 1405 | }; |
| 1406 | |
| 1407 | /* We assume for now that our PCI function is permitted to |
| 1408 | * reset everything. |
| 1409 | */ |
| 1410 | |
| 1411 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { |
| 1412 | *flags &= ~EF10_RESET_MC; |
| 1413 | return RESET_TYPE_WORLD; |
| 1414 | } |
| 1415 | |
| 1416 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { |
| 1417 | *flags &= ~EF10_RESET_PORT; |
| 1418 | return RESET_TYPE_ALL; |
| 1419 | } |
| 1420 | |
| 1421 | /* no invisible reset implemented */ |
| 1422 | |
| 1423 | return -EINVAL; |
| 1424 | } |
| 1425 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1426 | static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type) |
| 1427 | { |
| 1428 | int rc = efx_mcdi_reset(efx, reset_type); |
| 1429 | |
Daniel Pieczko | 2732482 | 2015-07-31 11:14:54 +0100 | [diff] [blame] | 1430 | /* Unprivileged functions return -EPERM, but need to return success |
| 1431 | * here so that the datapath is brought back up. |
| 1432 | */ |
| 1433 | if (reset_type == RESET_TYPE_WORLD && rc == -EPERM) |
| 1434 | rc = 0; |
| 1435 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1436 | /* If it was a port reset, trigger reallocation of MC resources. |
| 1437 | * Note that on an MC reset nothing needs to be done now because we'll |
| 1438 | * detect the MC reset later and handle it then. |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 1439 | * For an FLR, we never get an MC reset event, but the MC has reset all |
| 1440 | * resources assigned to us, so we have to trigger reallocation now. |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1441 | */ |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 1442 | if ((reset_type == RESET_TYPE_ALL || |
| 1443 | reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc) |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1444 | efx_ef10_reset_mc_allocations(efx); |
| 1445 | return rc; |
| 1446 | } |
| 1447 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1448 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ |
| 1449 | [EF10_STAT_ ## ext_name] = \ |
| 1450 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 1451 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ |
| 1452 | [EF10_STAT_ ## int_name] = \ |
| 1453 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 1454 | #define EF10_OTHER_STAT(ext_name) \ |
| 1455 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1456 | #define GENERIC_SW_STAT(ext_name) \ |
| 1457 | [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1458 | |
| 1459 | 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] | 1460 | EF10_DMA_STAT(port_tx_bytes, TX_BYTES), |
| 1461 | EF10_DMA_STAT(port_tx_packets, TX_PKTS), |
| 1462 | EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS), |
| 1463 | EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS), |
| 1464 | EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS), |
| 1465 | EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS), |
| 1466 | EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS), |
| 1467 | EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS), |
| 1468 | EF10_DMA_STAT(port_tx_64, TX_64_PKTS), |
| 1469 | EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS), |
| 1470 | EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS), |
| 1471 | EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS), |
| 1472 | EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS), |
| 1473 | EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), |
| 1474 | EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), |
| 1475 | EF10_DMA_STAT(port_rx_bytes, RX_BYTES), |
| 1476 | EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES), |
| 1477 | EF10_OTHER_STAT(port_rx_good_bytes), |
| 1478 | EF10_OTHER_STAT(port_rx_bad_bytes), |
| 1479 | EF10_DMA_STAT(port_rx_packets, RX_PKTS), |
| 1480 | EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS), |
| 1481 | EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS), |
| 1482 | EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS), |
| 1483 | EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS), |
| 1484 | EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS), |
| 1485 | EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS), |
| 1486 | EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS), |
| 1487 | EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS), |
| 1488 | EF10_DMA_STAT(port_rx_64, RX_64_PKTS), |
| 1489 | EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS), |
| 1490 | EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS), |
| 1491 | EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS), |
| 1492 | EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS), |
| 1493 | EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), |
| 1494 | EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), |
| 1495 | EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS), |
| 1496 | EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS), |
| 1497 | EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS), |
| 1498 | EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS), |
| 1499 | EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS), |
| 1500 | EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS), |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1501 | GENERIC_SW_STAT(rx_nodesc_trunc), |
| 1502 | GENERIC_SW_STAT(rx_noskb_drops), |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1503 | EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW), |
| 1504 | EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW), |
| 1505 | EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL), |
| 1506 | EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL), |
| 1507 | EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB), |
| 1508 | EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB), |
| 1509 | EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING), |
| 1510 | EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS), |
| 1511 | EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS), |
| 1512 | EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS), |
| 1513 | EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS), |
| 1514 | EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS), |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1515 | EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS), |
| 1516 | EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES), |
| 1517 | EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS), |
| 1518 | EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES), |
| 1519 | EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS), |
| 1520 | EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES), |
| 1521 | EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS), |
| 1522 | EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES), |
| 1523 | EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW), |
| 1524 | EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS), |
| 1525 | EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES), |
| 1526 | EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS), |
| 1527 | EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES), |
| 1528 | EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS), |
| 1529 | EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES), |
| 1530 | EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS), |
| 1531 | EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES), |
| 1532 | EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1533 | }; |
| 1534 | |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1535 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \ |
| 1536 | (1ULL << EF10_STAT_port_tx_packets) | \ |
| 1537 | (1ULL << EF10_STAT_port_tx_pause) | \ |
| 1538 | (1ULL << EF10_STAT_port_tx_unicast) | \ |
| 1539 | (1ULL << EF10_STAT_port_tx_multicast) | \ |
| 1540 | (1ULL << EF10_STAT_port_tx_broadcast) | \ |
| 1541 | (1ULL << EF10_STAT_port_rx_bytes) | \ |
| 1542 | (1ULL << \ |
| 1543 | EF10_STAT_port_rx_bytes_minus_good_bytes) | \ |
| 1544 | (1ULL << EF10_STAT_port_rx_good_bytes) | \ |
| 1545 | (1ULL << EF10_STAT_port_rx_bad_bytes) | \ |
| 1546 | (1ULL << EF10_STAT_port_rx_packets) | \ |
| 1547 | (1ULL << EF10_STAT_port_rx_good) | \ |
| 1548 | (1ULL << EF10_STAT_port_rx_bad) | \ |
| 1549 | (1ULL << EF10_STAT_port_rx_pause) | \ |
| 1550 | (1ULL << EF10_STAT_port_rx_control) | \ |
| 1551 | (1ULL << EF10_STAT_port_rx_unicast) | \ |
| 1552 | (1ULL << EF10_STAT_port_rx_multicast) | \ |
| 1553 | (1ULL << EF10_STAT_port_rx_broadcast) | \ |
| 1554 | (1ULL << EF10_STAT_port_rx_lt64) | \ |
| 1555 | (1ULL << EF10_STAT_port_rx_64) | \ |
| 1556 | (1ULL << EF10_STAT_port_rx_65_to_127) | \ |
| 1557 | (1ULL << EF10_STAT_port_rx_128_to_255) | \ |
| 1558 | (1ULL << EF10_STAT_port_rx_256_to_511) | \ |
| 1559 | (1ULL << EF10_STAT_port_rx_512_to_1023) |\ |
| 1560 | (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\ |
| 1561 | (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\ |
| 1562 | (1ULL << EF10_STAT_port_rx_gtjumbo) | \ |
| 1563 | (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\ |
| 1564 | (1ULL << EF10_STAT_port_rx_overflow) | \ |
| 1565 | (1ULL << EF10_STAT_port_rx_nodesc_drops) |\ |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1566 | (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \ |
| 1567 | (1ULL << GENERIC_STAT_rx_noskb_drops)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1568 | |
Edward Cree | 69b365c | 2016-08-26 15:12:41 +0100 | [diff] [blame] | 1569 | /* On 7000 series NICs, these statistics are only provided by the 10G MAC. |
| 1570 | * For a 10G/40G switchable port we do not expose these because they might |
| 1571 | * not include all the packets they should. |
| 1572 | * On 8000 series NICs these statistics are always provided. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1573 | */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1574 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \ |
| 1575 | (1ULL << EF10_STAT_port_tx_lt64) | \ |
| 1576 | (1ULL << EF10_STAT_port_tx_64) | \ |
| 1577 | (1ULL << EF10_STAT_port_tx_65_to_127) |\ |
| 1578 | (1ULL << EF10_STAT_port_tx_128_to_255) |\ |
| 1579 | (1ULL << EF10_STAT_port_tx_256_to_511) |\ |
| 1580 | (1ULL << EF10_STAT_port_tx_512_to_1023) |\ |
| 1581 | (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\ |
| 1582 | (1ULL << EF10_STAT_port_tx_15xx_to_jumbo)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1583 | |
| 1584 | /* These statistics are only provided by the 40G MAC. For a 10G/40G |
| 1585 | * switchable port we do expose these because the errors will otherwise |
| 1586 | * be silent. |
| 1587 | */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1588 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\ |
| 1589 | (1ULL << EF10_STAT_port_rx_length_error)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1590 | |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1591 | /* These statistics are only provided if the firmware supports the |
| 1592 | * capability PM_AND_RXDP_COUNTERS. |
| 1593 | */ |
| 1594 | #define HUNT_PM_AND_RXDP_STAT_MASK ( \ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1595 | (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \ |
| 1596 | (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \ |
| 1597 | (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \ |
| 1598 | (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \ |
| 1599 | (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \ |
| 1600 | (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \ |
| 1601 | (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \ |
| 1602 | (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \ |
| 1603 | (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \ |
| 1604 | (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \ |
| 1605 | (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \ |
| 1606 | (1ULL << EF10_STAT_port_rx_dp_hlb_wait)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1607 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1608 | static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1609 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1610 | u64 raw_mask = HUNT_COMMON_STAT_MASK; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1611 | u32 port_caps = efx_mcdi_phy_get_caps(efx); |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1612 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1613 | |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1614 | if (!(efx->mcdi->fn_flags & |
| 1615 | 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) |
| 1616 | return 0; |
| 1617 | |
Edward Cree | 69b365c | 2016-08-26 15:12:41 +0100 | [diff] [blame] | 1618 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1619 | raw_mask |= HUNT_40G_EXTRA_STAT_MASK; |
Edward Cree | 69b365c | 2016-08-26 15:12:41 +0100 | [diff] [blame] | 1620 | /* 8000 series have everything even at 40G */ |
| 1621 | if (nic_data->datapath_caps2 & |
| 1622 | (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN)) |
| 1623 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
| 1624 | } else { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1625 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
Edward Cree | 69b365c | 2016-08-26 15:12:41 +0100 | [diff] [blame] | 1626 | } |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 1627 | |
| 1628 | if (nic_data->datapath_caps & |
| 1629 | (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN)) |
| 1630 | raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK; |
| 1631 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1632 | return raw_mask; |
| 1633 | } |
| 1634 | |
| 1635 | static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask) |
| 1636 | { |
Daniel Pieczko | d94619c | 2015-06-02 11:40:05 +0100 | [diff] [blame] | 1637 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1638 | u64 raw_mask[2]; |
| 1639 | |
| 1640 | raw_mask[0] = efx_ef10_raw_stat_mask(efx); |
| 1641 | |
Daniel Pieczko | d94619c | 2015-06-02 11:40:05 +0100 | [diff] [blame] | 1642 | /* Only show vadaptor stats when EVB capability is present */ |
| 1643 | if (nic_data->datapath_caps & |
| 1644 | (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) { |
| 1645 | raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1); |
| 1646 | raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1; |
| 1647 | } else { |
| 1648 | raw_mask[1] = 0; |
| 1649 | } |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1650 | |
| 1651 | #if BITS_PER_LONG == 64 |
Andrew Rybchenko | e70c70c3 | 2016-08-26 11:19:34 +0100 | [diff] [blame] | 1652 | BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2); |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1653 | mask[0] = raw_mask[0]; |
| 1654 | mask[1] = raw_mask[1]; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1655 | #else |
Andrew Rybchenko | e70c70c3 | 2016-08-26 11:19:34 +0100 | [diff] [blame] | 1656 | BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3); |
Daniel Pieczko | 3c36a2a | 2015-06-02 11:39:06 +0100 | [diff] [blame] | 1657 | mask[0] = raw_mask[0] & 0xffffffff; |
| 1658 | mask[1] = raw_mask[0] >> 32; |
| 1659 | mask[2] = raw_mask[1] & 0xffffffff; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1660 | #endif |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) |
| 1664 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1665 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1666 | |
| 1667 | efx_ef10_get_stat_mask(efx, mask); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1668 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1669 | mask, names); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1672 | static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats, |
| 1673 | struct rtnl_link_stats64 *core_stats) |
| 1674 | { |
| 1675 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1676 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1677 | u64 *stats = nic_data->stats; |
| 1678 | size_t stats_count = 0, index; |
| 1679 | |
| 1680 | efx_ef10_get_stat_mask(efx, mask); |
| 1681 | |
| 1682 | if (full_stats) { |
| 1683 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { |
| 1684 | if (efx_ef10_stat_desc[index].name) { |
| 1685 | *full_stats++ = stats[index]; |
| 1686 | ++stats_count; |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | |
Bert Kenward | fbe4307 | 2015-08-26 16:39:03 +0100 | [diff] [blame] | 1691 | if (!core_stats) |
| 1692 | return stats_count; |
| 1693 | |
| 1694 | if (nic_data->datapath_caps & |
| 1695 | 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) { |
| 1696 | /* Use vadaptor stats. */ |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1697 | core_stats->rx_packets = stats[EF10_STAT_rx_unicast] + |
| 1698 | stats[EF10_STAT_rx_multicast] + |
| 1699 | stats[EF10_STAT_rx_broadcast]; |
| 1700 | core_stats->tx_packets = stats[EF10_STAT_tx_unicast] + |
| 1701 | stats[EF10_STAT_tx_multicast] + |
| 1702 | stats[EF10_STAT_tx_broadcast]; |
| 1703 | core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] + |
| 1704 | stats[EF10_STAT_rx_multicast_bytes] + |
| 1705 | stats[EF10_STAT_rx_broadcast_bytes]; |
| 1706 | core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] + |
| 1707 | stats[EF10_STAT_tx_multicast_bytes] + |
| 1708 | stats[EF10_STAT_tx_broadcast_bytes]; |
| 1709 | core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] + |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1710 | stats[GENERIC_STAT_rx_noskb_drops]; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1711 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
| 1712 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; |
| 1713 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; |
| 1714 | core_stats->rx_errors = core_stats->rx_crc_errors; |
| 1715 | core_stats->tx_errors = stats[EF10_STAT_tx_bad]; |
Bert Kenward | fbe4307 | 2015-08-26 16:39:03 +0100 | [diff] [blame] | 1716 | } else { |
| 1717 | /* Use port stats. */ |
| 1718 | core_stats->rx_packets = stats[EF10_STAT_port_rx_packets]; |
| 1719 | core_stats->tx_packets = stats[EF10_STAT_port_tx_packets]; |
| 1720 | core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes]; |
| 1721 | core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes]; |
| 1722 | core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] + |
| 1723 | stats[GENERIC_STAT_rx_nodesc_trunc] + |
| 1724 | stats[GENERIC_STAT_rx_noskb_drops]; |
| 1725 | core_stats->multicast = stats[EF10_STAT_port_rx_multicast]; |
| 1726 | core_stats->rx_length_errors = |
| 1727 | stats[EF10_STAT_port_rx_gtjumbo] + |
| 1728 | stats[EF10_STAT_port_rx_length_error]; |
| 1729 | core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad]; |
| 1730 | core_stats->rx_frame_errors = |
| 1731 | stats[EF10_STAT_port_rx_align_error]; |
| 1732 | core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow]; |
| 1733 | core_stats->rx_errors = (core_stats->rx_length_errors + |
| 1734 | core_stats->rx_crc_errors + |
| 1735 | core_stats->rx_frame_errors); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | return stats_count; |
| 1739 | } |
| 1740 | |
| 1741 | 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] | 1742 | { |
| 1743 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1744 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1745 | __le64 generation_start, generation_end; |
| 1746 | u64 *stats = nic_data->stats; |
| 1747 | __le64 *dma_stats; |
| 1748 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1749 | efx_ef10_get_stat_mask(efx, mask); |
| 1750 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1751 | dma_stats = efx->stats_buffer.addr; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1752 | |
| 1753 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; |
| 1754 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) |
| 1755 | return 0; |
| 1756 | rmb(); |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 1757 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1758 | stats, efx->stats_buffer.addr, false); |
Jon Cooper | d546a89 | 2013-09-27 18:26:30 +0100 | [diff] [blame] | 1759 | rmb(); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1760 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
| 1761 | if (generation_end != generation_start) |
| 1762 | return -EAGAIN; |
| 1763 | |
| 1764 | /* Update derived statistics */ |
Daniel Pieczko | e80ca013 | 2015-06-02 11:38:34 +0100 | [diff] [blame] | 1765 | efx_nic_fix_nodesc_drop_stat(efx, |
| 1766 | &stats[EF10_STAT_port_rx_nodesc_drops]); |
| 1767 | stats[EF10_STAT_port_rx_good_bytes] = |
| 1768 | stats[EF10_STAT_port_rx_bytes] - |
| 1769 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]; |
| 1770 | efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes], |
| 1771 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]); |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1772 | efx_update_sw_stats(efx, stats); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1773 | return 0; |
| 1774 | } |
| 1775 | |
| 1776 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1777 | static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats, |
| 1778 | struct rtnl_link_stats64 *core_stats) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1779 | { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1780 | int retry; |
| 1781 | |
| 1782 | /* If we're unlucky enough to read statistics during the DMA, wait |
| 1783 | * up to 10ms for it to finish (typically takes <500us) |
| 1784 | */ |
| 1785 | for (retry = 0; retry < 100; ++retry) { |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1786 | if (efx_ef10_try_update_nic_stats_pf(efx) == 0) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1787 | break; |
| 1788 | udelay(100); |
| 1789 | } |
| 1790 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1791 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
| 1792 | } |
| 1793 | |
| 1794 | static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx) |
| 1795 | { |
| 1796 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN); |
| 1797 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1798 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 1799 | __le64 generation_start, generation_end; |
| 1800 | u64 *stats = nic_data->stats; |
| 1801 | u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64); |
| 1802 | struct efx_buffer stats_buf; |
| 1803 | __le64 *dma_stats; |
| 1804 | int rc; |
| 1805 | |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1806 | spin_unlock_bh(&efx->stats_lock); |
| 1807 | |
| 1808 | if (in_interrupt()) { |
| 1809 | /* If in atomic context, cannot update stats. Just update the |
| 1810 | * software stats and return so the caller can continue. |
| 1811 | */ |
| 1812 | spin_lock_bh(&efx->stats_lock); |
| 1813 | efx_update_sw_stats(efx, stats); |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1817 | efx_ef10_get_stat_mask(efx, mask); |
| 1818 | |
| 1819 | rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC); |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1820 | if (rc) { |
| 1821 | spin_lock_bh(&efx->stats_lock); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1822 | return rc; |
Daniel Pieczko | f00bf23 | 2015-06-02 11:40:18 +0100 | [diff] [blame] | 1823 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1824 | |
| 1825 | dma_stats = stats_buf.addr; |
| 1826 | dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID; |
| 1827 | |
| 1828 | MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr); |
| 1829 | MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD, |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1830 | MAC_STATS_IN_DMA, 1); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1831 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
| 1832 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); |
| 1833 | |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1834 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), |
| 1835 | NULL, 0, NULL); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1836 | spin_lock_bh(&efx->stats_lock); |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1837 | if (rc) { |
| 1838 | /* Expect ENOENT if DMA queues have not been set up */ |
| 1839 | if (rc != -ENOENT || atomic_read(&efx->active_queues)) |
| 1840 | efx_mcdi_display_error(efx, MC_CMD_MAC_STATS, |
| 1841 | sizeof(inbuf), NULL, 0, rc); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1842 | goto out; |
Daniel Pieczko | 6dd4859 | 2015-06-02 11:39:49 +0100 | [diff] [blame] | 1843 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1844 | |
| 1845 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1846 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) { |
| 1847 | WARN_ON_ONCE(1); |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1848 | goto out; |
Daniel Pieczko | 0fc95fc | 2015-06-02 11:39:33 +0100 | [diff] [blame] | 1849 | } |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1850 | rmb(); |
| 1851 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
| 1852 | stats, stats_buf.addr, false); |
| 1853 | rmb(); |
| 1854 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
| 1855 | if (generation_end != generation_start) { |
| 1856 | rc = -EAGAIN; |
| 1857 | goto out; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1858 | } |
| 1859 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1860 | efx_update_sw_stats(efx, stats); |
| 1861 | out: |
| 1862 | efx_nic_free_buffer(efx, &stats_buf); |
| 1863 | return rc; |
| 1864 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1865 | |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 1866 | static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats, |
| 1867 | struct rtnl_link_stats64 *core_stats) |
| 1868 | { |
| 1869 | if (efx_ef10_try_update_nic_stats_vf(efx)) |
| 1870 | return 0; |
| 1871 | |
| 1872 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) |
| 1876 | { |
| 1877 | struct efx_nic *efx = channel->efx; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1878 | unsigned int mode, usecs; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1879 | efx_dword_t timer_cmd; |
| 1880 | |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1881 | if (channel->irq_moderation_us) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1882 | mode = 3; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1883 | usecs = channel->irq_moderation_us; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1884 | } else { |
| 1885 | mode = 0; |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1886 | usecs = 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1889 | if (EFX_EF10_WORKAROUND_61265(efx)) { |
| 1890 | MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN); |
| 1891 | unsigned int ns = usecs * 1000; |
| 1892 | |
| 1893 | MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE, |
| 1894 | channel->channel); |
| 1895 | MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns); |
| 1896 | MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns); |
| 1897 | MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode); |
| 1898 | |
| 1899 | efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR, |
| 1900 | inbuf, sizeof(inbuf), 0, NULL, 0); |
| 1901 | } else if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 1902 | unsigned int ticks = efx_usecs_to_ticks(efx, usecs); |
| 1903 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1904 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, |
| 1905 | EFE_DD_EVQ_IND_TIMER_FLAGS, |
| 1906 | ERF_DD_EVQ_IND_TIMER_MODE, mode, |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1907 | ERF_DD_EVQ_IND_TIMER_VAL, ticks); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1908 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, |
| 1909 | channel->channel); |
| 1910 | } else { |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1911 | unsigned int ticks = efx_usecs_to_ticks(efx, usecs); |
| 1912 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1913 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, |
Bert Kenward | 539de7c | 2016-08-11 13:02:09 +0100 | [diff] [blame] | 1914 | ERF_DZ_TC_TIMER_VAL, ticks); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1915 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, |
| 1916 | channel->channel); |
| 1917 | } |
| 1918 | } |
| 1919 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 1920 | static void efx_ef10_get_wol_vf(struct efx_nic *efx, |
| 1921 | struct ethtool_wolinfo *wol) {} |
| 1922 | |
| 1923 | static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type) |
| 1924 | { |
| 1925 | return -EOPNOTSUPP; |
| 1926 | } |
| 1927 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1928 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 1929 | { |
| 1930 | wol->supported = 0; |
| 1931 | wol->wolopts = 0; |
| 1932 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 1933 | } |
| 1934 | |
| 1935 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) |
| 1936 | { |
| 1937 | if (type != 0) |
| 1938 | return -EINVAL; |
| 1939 | return 0; |
| 1940 | } |
| 1941 | |
| 1942 | static void efx_ef10_mcdi_request(struct efx_nic *efx, |
| 1943 | const efx_dword_t *hdr, size_t hdr_len, |
| 1944 | const efx_dword_t *sdu, size_t sdu_len) |
| 1945 | { |
| 1946 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1947 | u8 *pdu = nic_data->mcdi_buf.addr; |
| 1948 | |
| 1949 | memcpy(pdu, hdr, hdr_len); |
| 1950 | memcpy(pdu + hdr_len, sdu, sdu_len); |
| 1951 | wmb(); |
| 1952 | |
| 1953 | /* The hardware provides 'low' and 'high' (doorbell) registers |
| 1954 | * for passing the 64-bit address of an MCDI request to |
| 1955 | * firmware. However the dwords are swapped by firmware. The |
| 1956 | * least significant bits of the doorbell are then 0 for all |
| 1957 | * MCDI requests due to alignment. |
| 1958 | */ |
| 1959 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), |
| 1960 | ER_DZ_MC_DB_LWRD); |
| 1961 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), |
| 1962 | ER_DZ_MC_DB_HWRD); |
| 1963 | } |
| 1964 | |
| 1965 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) |
| 1966 | { |
| 1967 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1968 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; |
| 1969 | |
| 1970 | rmb(); |
| 1971 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); |
| 1972 | } |
| 1973 | |
| 1974 | static void |
| 1975 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, |
| 1976 | size_t offset, size_t outlen) |
| 1977 | { |
| 1978 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1979 | const u8 *pdu = nic_data->mcdi_buf.addr; |
| 1980 | |
| 1981 | memcpy(outbuf, pdu + offset, outlen); |
| 1982 | } |
| 1983 | |
Daniel Pieczko | c577e59 | 2015-10-09 10:40:35 +0100 | [diff] [blame] | 1984 | static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx) |
| 1985 | { |
| 1986 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1987 | |
| 1988 | /* All our allocations have been reset */ |
| 1989 | efx_ef10_reset_mc_allocations(efx); |
| 1990 | |
| 1991 | /* The datapath firmware might have been changed */ |
| 1992 | nic_data->must_check_datapath_caps = true; |
| 1993 | |
| 1994 | /* MAC statistics have been cleared on the NIC; clear the local |
| 1995 | * statistic that we update with efx_update_diff_stat(). |
| 1996 | */ |
| 1997 | nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0; |
| 1998 | } |
| 1999 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2000 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) |
| 2001 | { |
| 2002 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2003 | int rc; |
| 2004 | |
| 2005 | rc = efx_ef10_get_warm_boot_count(efx); |
| 2006 | if (rc < 0) { |
| 2007 | /* The firmware is presumably in the process of |
| 2008 | * rebooting. However, we are supposed to report each |
| 2009 | * reboot just once, so we must only do that once we |
| 2010 | * can read and store the updated warm boot count. |
| 2011 | */ |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | if (rc == nic_data->warm_boot_count) |
| 2016 | return 0; |
| 2017 | |
| 2018 | nic_data->warm_boot_count = rc; |
Daniel Pieczko | c577e59 | 2015-10-09 10:40:35 +0100 | [diff] [blame] | 2019 | efx_ef10_mcdi_reboot_detected(efx); |
Ben Hutchings | 869070c | 2013-09-05 22:46:10 +0100 | [diff] [blame] | 2020 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2021 | return -EIO; |
| 2022 | } |
| 2023 | |
| 2024 | /* Handle an MSI interrupt |
| 2025 | * |
| 2026 | * Handle an MSI hardware interrupt. This routine schedules event |
| 2027 | * queue processing. No interrupt acknowledgement cycle is necessary. |
| 2028 | * Also, we never need to check that the interrupt is for us, since |
| 2029 | * MSI interrupts cannot be shared. |
| 2030 | */ |
| 2031 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) |
| 2032 | { |
| 2033 | struct efx_msi_context *context = dev_id; |
| 2034 | struct efx_nic *efx = context->efx; |
| 2035 | |
| 2036 | netif_vdbg(efx, intr, efx->net_dev, |
| 2037 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); |
| 2038 | |
| 2039 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { |
| 2040 | /* Note test interrupts */ |
| 2041 | if (context->index == efx->irq_level) |
| 2042 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 2043 | |
| 2044 | /* Schedule processing of the channel */ |
| 2045 | efx_schedule_channel_irq(efx->channel[context->index]); |
| 2046 | } |
| 2047 | |
| 2048 | return IRQ_HANDLED; |
| 2049 | } |
| 2050 | |
| 2051 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) |
| 2052 | { |
| 2053 | struct efx_nic *efx = dev_id; |
| 2054 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); |
| 2055 | struct efx_channel *channel; |
| 2056 | efx_dword_t reg; |
| 2057 | u32 queues; |
| 2058 | |
| 2059 | /* Read the ISR which also ACKs the interrupts */ |
| 2060 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); |
| 2061 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); |
| 2062 | |
| 2063 | if (queues == 0) |
| 2064 | return IRQ_NONE; |
| 2065 | |
| 2066 | if (likely(soft_enabled)) { |
| 2067 | /* Note test interrupts */ |
| 2068 | if (queues & (1U << efx->irq_level)) |
| 2069 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 2070 | |
| 2071 | efx_for_each_channel(channel, efx) { |
| 2072 | if (queues & 1) |
| 2073 | efx_schedule_channel_irq(channel); |
| 2074 | queues >>= 1; |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | netif_vdbg(efx, intr, efx->net_dev, |
| 2079 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", |
| 2080 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); |
| 2081 | |
| 2082 | return IRQ_HANDLED; |
| 2083 | } |
| 2084 | |
Jon Cooper | 942e298 | 2016-08-26 15:13:30 +0100 | [diff] [blame] | 2085 | static int efx_ef10_irq_test_generate(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2086 | { |
| 2087 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); |
| 2088 | |
Jon Cooper | 942e298 | 2016-08-26 15:13:30 +0100 | [diff] [blame] | 2089 | if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true, |
| 2090 | NULL) == 0) |
| 2091 | return -ENOTSUPP; |
| 2092 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2093 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); |
| 2094 | |
| 2095 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); |
Jon Cooper | 942e298 | 2016-08-26 15:13:30 +0100 | [diff] [blame] | 2096 | return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2097 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 2098 | } |
| 2099 | |
| 2100 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) |
| 2101 | { |
| 2102 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, |
| 2103 | (tx_queue->ptr_mask + 1) * |
| 2104 | sizeof(efx_qword_t), |
| 2105 | GFP_KERNEL); |
| 2106 | } |
| 2107 | |
| 2108 | /* This writes to the TX_DESC_WPTR and also pushes data */ |
| 2109 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, |
| 2110 | const efx_qword_t *txd) |
| 2111 | { |
| 2112 | unsigned int write_ptr; |
| 2113 | efx_oword_t reg; |
| 2114 | |
| 2115 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 2116 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); |
| 2117 | reg.qword[0] = *txd; |
| 2118 | efx_writeo_page(tx_queue->efx, ®, |
| 2119 | ER_DZ_TX_DESC_UPD, tx_queue->queue); |
| 2120 | } |
| 2121 | |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2122 | /* Add Firmware-Assisted TSO v2 option descriptors to a queue. |
| 2123 | */ |
| 2124 | static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue, |
| 2125 | struct sk_buff *skb, |
| 2126 | bool *data_mapped) |
| 2127 | { |
| 2128 | struct efx_tx_buffer *buffer; |
| 2129 | struct tcphdr *tcp; |
| 2130 | struct iphdr *ip; |
| 2131 | |
| 2132 | u16 ipv4_id; |
| 2133 | u32 seqnum; |
| 2134 | u32 mss; |
| 2135 | |
Edward Cree | e01b16a | 2016-12-02 15:51:33 +0000 | [diff] [blame] | 2136 | EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2); |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2137 | |
| 2138 | mss = skb_shinfo(skb)->gso_size; |
| 2139 | |
| 2140 | if (unlikely(mss < 4)) { |
| 2141 | WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss); |
| 2142 | return -EINVAL; |
| 2143 | } |
| 2144 | |
| 2145 | ip = ip_hdr(skb); |
| 2146 | if (ip->version == 4) { |
| 2147 | /* Modify IPv4 header if needed. */ |
| 2148 | ip->tot_len = 0; |
| 2149 | ip->check = 0; |
| 2150 | ipv4_id = ip->id; |
| 2151 | } else { |
| 2152 | /* Modify IPv6 header if needed. */ |
| 2153 | struct ipv6hdr *ipv6 = ipv6_hdr(skb); |
| 2154 | |
| 2155 | ipv6->payload_len = 0; |
| 2156 | ipv4_id = 0; |
| 2157 | } |
| 2158 | |
| 2159 | tcp = tcp_hdr(skb); |
| 2160 | seqnum = ntohl(tcp->seq); |
| 2161 | |
| 2162 | buffer = efx_tx_queue_get_insert_buffer(tx_queue); |
| 2163 | |
| 2164 | buffer->flags = EFX_TX_BUF_OPTION; |
| 2165 | buffer->len = 0; |
| 2166 | buffer->unmap_len = 0; |
| 2167 | EFX_POPULATE_QWORD_5(buffer->option, |
| 2168 | ESF_DZ_TX_DESC_IS_OPT, 1, |
| 2169 | ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO, |
| 2170 | ESF_DZ_TX_TSO_OPTION_TYPE, |
| 2171 | ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A, |
| 2172 | ESF_DZ_TX_TSO_IP_ID, ipv4_id, |
| 2173 | ESF_DZ_TX_TSO_TCP_SEQNO, seqnum |
| 2174 | ); |
| 2175 | ++tx_queue->insert_count; |
| 2176 | |
| 2177 | buffer = efx_tx_queue_get_insert_buffer(tx_queue); |
| 2178 | |
| 2179 | buffer->flags = EFX_TX_BUF_OPTION; |
| 2180 | buffer->len = 0; |
| 2181 | buffer->unmap_len = 0; |
| 2182 | EFX_POPULATE_QWORD_4(buffer->option, |
| 2183 | ESF_DZ_TX_DESC_IS_OPT, 1, |
| 2184 | ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO, |
| 2185 | ESF_DZ_TX_TSO_OPTION_TYPE, |
| 2186 | ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B, |
| 2187 | ESF_DZ_TX_TSO_TCP_MSS, mss |
| 2188 | ); |
| 2189 | ++tx_queue->insert_count; |
| 2190 | |
| 2191 | return 0; |
| 2192 | } |
| 2193 | |
Edward Cree | 46d1efd | 2016-11-17 10:52:36 +0000 | [diff] [blame] | 2194 | static u32 efx_ef10_tso_versions(struct efx_nic *efx) |
| 2195 | { |
| 2196 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2197 | u32 tso_versions = 0; |
| 2198 | |
| 2199 | if (nic_data->datapath_caps & |
| 2200 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) |
| 2201 | tso_versions |= BIT(1); |
| 2202 | if (nic_data->datapath_caps2 & |
| 2203 | (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) |
| 2204 | tso_versions |= BIT(2); |
| 2205 | return tso_versions; |
| 2206 | } |
| 2207 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2208 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) |
| 2209 | { |
| 2210 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 2211 | EFX_BUF_SIZE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2212 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
| 2213 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; |
| 2214 | struct efx_channel *channel = tx_queue->channel; |
| 2215 | struct efx_nic *efx = tx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2216 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2217 | bool tso_v2 = false; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2218 | size_t inlen; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2219 | dma_addr_t dma_addr; |
| 2220 | efx_qword_t *txd; |
| 2221 | int rc; |
| 2222 | int i; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2223 | BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2224 | |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2225 | /* TSOv2 is a limited resource that can only be configured on a limited |
| 2226 | * number of queues. TSO without checksum offload is not really a thing, |
| 2227 | * so we only enable it for those queues. |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2228 | */ |
| 2229 | if (csum_offload && (nic_data->datapath_caps2 & |
| 2230 | (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) { |
| 2231 | tso_v2 = true; |
| 2232 | netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n", |
| 2233 | channel->channel); |
| 2234 | } |
| 2235 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2236 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); |
| 2237 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); |
| 2238 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); |
| 2239 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2240 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2241 | 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] | 2242 | |
| 2243 | dma_addr = tx_queue->txd.buf.dma_addr; |
| 2244 | |
| 2245 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", |
| 2246 | tx_queue->queue, entries, (u64)dma_addr); |
| 2247 | |
| 2248 | for (i = 0; i < entries; ++i) { |
| 2249 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); |
| 2250 | dma_addr += EFX_BUF_SIZE; |
| 2251 | } |
| 2252 | |
| 2253 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); |
| 2254 | |
Edward Cree | e638ee1 | 2016-11-17 10:52:07 +0000 | [diff] [blame] | 2255 | do { |
| 2256 | MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS, |
| 2257 | /* This flag was removed from mcdi_pcol.h for |
| 2258 | * the non-_EXT version of INIT_TXQ. However, |
| 2259 | * firmware still honours it. |
| 2260 | */ |
| 2261 | INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2, |
| 2262 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, |
| 2263 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); |
| 2264 | |
| 2265 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen, |
| 2266 | NULL, 0, NULL); |
| 2267 | if (rc == -ENOSPC && tso_v2) { |
| 2268 | /* Retry without TSOv2 if we're short on contexts. */ |
| 2269 | tso_v2 = false; |
| 2270 | netif_warn(efx, probe, efx->net_dev, |
| 2271 | "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n"); |
| 2272 | } else if (rc) { |
| 2273 | efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ, |
| 2274 | MC_CMD_INIT_TXQ_EXT_IN_LEN, |
| 2275 | NULL, 0, rc); |
| 2276 | goto fail; |
| 2277 | } |
| 2278 | } while (rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2279 | |
| 2280 | /* A previous user of this TX queue might have set us up the |
| 2281 | * bomb by writing a descriptor to the TX push collector but |
| 2282 | * not the doorbell. (Each collector belongs to a port, not a |
| 2283 | * queue or function, so cannot easily be reset.) We must |
| 2284 | * attempt to push a no-op descriptor in its place. |
| 2285 | */ |
| 2286 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; |
| 2287 | tx_queue->insert_count = 1; |
| 2288 | txd = efx_tx_desc(tx_queue, 0); |
| 2289 | EFX_POPULATE_QWORD_4(*txd, |
| 2290 | ESF_DZ_TX_DESC_IS_OPT, true, |
| 2291 | ESF_DZ_TX_OPTION_TYPE, |
| 2292 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, |
| 2293 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, |
| 2294 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); |
| 2295 | tx_queue->write_count = 1; |
Bert Kenward | 93171b1 | 2015-11-30 09:05:35 +0000 | [diff] [blame] | 2296 | |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2297 | if (tso_v2) { |
| 2298 | tx_queue->handle_tso = efx_ef10_tx_tso_desc; |
| 2299 | tx_queue->tso_version = 2; |
| 2300 | } else if (nic_data->datapath_caps & |
| 2301 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) { |
Bert Kenward | 93171b1 | 2015-11-30 09:05:35 +0000 | [diff] [blame] | 2302 | tx_queue->tso_version = 1; |
| 2303 | } |
| 2304 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2305 | wmb(); |
| 2306 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 2307 | |
| 2308 | return; |
| 2309 | |
| 2310 | fail: |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 2311 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
| 2312 | tx_queue->queue); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) |
| 2316 | { |
| 2317 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2318 | MCDI_DECLARE_BUF_ERR(outbuf); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2319 | struct efx_nic *efx = tx_queue->efx; |
| 2320 | size_t outlen; |
| 2321 | int rc; |
| 2322 | |
| 2323 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, |
| 2324 | tx_queue->queue); |
| 2325 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2326 | 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] | 2327 | outbuf, sizeof(outbuf), &outlen); |
| 2328 | |
| 2329 | if (rc && rc != -EALREADY) |
| 2330 | goto fail; |
| 2331 | |
| 2332 | return; |
| 2333 | |
| 2334 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2335 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
| 2336 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) |
| 2340 | { |
| 2341 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); |
| 2342 | } |
| 2343 | |
| 2344 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ |
| 2345 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) |
| 2346 | { |
| 2347 | unsigned int write_ptr; |
| 2348 | efx_dword_t reg; |
| 2349 | |
| 2350 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 2351 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); |
| 2352 | efx_writed_page(tx_queue->efx, ®, |
| 2353 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); |
| 2354 | } |
| 2355 | |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 2356 | #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff |
| 2357 | |
| 2358 | static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue, |
| 2359 | dma_addr_t dma_addr, unsigned int len) |
| 2360 | { |
| 2361 | if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) { |
| 2362 | /* If we need to break across multiple descriptors we should |
| 2363 | * stop at a page boundary. This assumes the length limit is |
| 2364 | * greater than the page size. |
| 2365 | */ |
| 2366 | dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN; |
| 2367 | |
| 2368 | BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE); |
| 2369 | len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr; |
| 2370 | } |
| 2371 | |
| 2372 | return len; |
| 2373 | } |
| 2374 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2375 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) |
| 2376 | { |
| 2377 | unsigned int old_write_count = tx_queue->write_count; |
| 2378 | struct efx_tx_buffer *buffer; |
| 2379 | unsigned int write_ptr; |
| 2380 | efx_qword_t *txd; |
| 2381 | |
Martin Habets | b2663a4 | 2015-11-02 12:51:31 +0000 | [diff] [blame] | 2382 | tx_queue->xmit_more_available = false; |
| 2383 | if (unlikely(tx_queue->write_count == tx_queue->insert_count)) |
| 2384 | return; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2385 | |
| 2386 | do { |
| 2387 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 2388 | buffer = &tx_queue->buffer[write_ptr]; |
| 2389 | txd = efx_tx_desc(tx_queue, write_ptr); |
| 2390 | ++tx_queue->write_count; |
| 2391 | |
| 2392 | /* Create TX descriptor ring entry */ |
| 2393 | if (buffer->flags & EFX_TX_BUF_OPTION) { |
| 2394 | *txd = buffer->option; |
Edward Cree | de1deff | 2017-01-13 21:20:14 +0000 | [diff] [blame] | 2395 | if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1) |
| 2396 | /* PIO descriptor */ |
| 2397 | tx_queue->packet_write_count = tx_queue->write_count; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2398 | } else { |
Edward Cree | de1deff | 2017-01-13 21:20:14 +0000 | [diff] [blame] | 2399 | tx_queue->packet_write_count = tx_queue->write_count; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2400 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); |
| 2401 | EFX_POPULATE_QWORD_3( |
| 2402 | *txd, |
| 2403 | ESF_DZ_TX_KER_CONT, |
| 2404 | buffer->flags & EFX_TX_BUF_CONT, |
| 2405 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, |
| 2406 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); |
| 2407 | } |
| 2408 | } while (tx_queue->write_count != tx_queue->insert_count); |
| 2409 | |
| 2410 | wmb(); /* Ensure descriptors are written before they are fetched */ |
| 2411 | |
| 2412 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { |
| 2413 | txd = efx_tx_desc(tx_queue, |
| 2414 | old_write_count & tx_queue->ptr_mask); |
| 2415 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 2416 | ++tx_queue->pushes; |
| 2417 | } else { |
| 2418 | efx_ef10_notify_tx_desc(tx_queue); |
| 2419 | } |
| 2420 | } |
| 2421 | |
Edward Cree | a33a4c7 | 2016-11-03 22:12:27 +0000 | [diff] [blame] | 2422 | #define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\ |
| 2423 | 1 << RSS_MODE_HASH_DST_ADDR_LBN) |
| 2424 | #define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\ |
| 2425 | 1 << RSS_MODE_HASH_DST_PORT_LBN) |
| 2426 | #define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\ |
| 2427 | 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\ |
| 2428 | 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\ |
| 2429 | 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\ |
| 2430 | (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\ |
| 2431 | RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\ |
| 2432 | RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\ |
| 2433 | (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\ |
| 2434 | RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\ |
| 2435 | RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN) |
| 2436 | |
| 2437 | static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags) |
| 2438 | { |
| 2439 | /* Firmware had a bug (sfc bug 61952) where it would not actually |
| 2440 | * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS. |
| 2441 | * This meant that it would always contain whatever was previously |
| 2442 | * in the MCDI buffer. Fortunately, all firmware versions with |
| 2443 | * this bug have the same default flags value for a newly-allocated |
| 2444 | * RSS context, and the only time we want to get the flags is just |
| 2445 | * after allocating. Moreover, the response has a 32-bit hole |
| 2446 | * where the context ID would be in the request, so we can use an |
| 2447 | * overlength buffer in the request and pre-fill the flags field |
| 2448 | * with what we believe the default to be. Thus if the firmware |
| 2449 | * has the bug, it will leave our pre-filled value in the flags |
| 2450 | * field of the response, and we will get the right answer. |
| 2451 | * |
| 2452 | * However, this does mean that this function should NOT be used if |
| 2453 | * the RSS context flags might not be their defaults - it is ONLY |
| 2454 | * reliably correct for a newly-allocated RSS context. |
| 2455 | */ |
| 2456 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN); |
| 2457 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN); |
| 2458 | size_t outlen; |
| 2459 | int rc; |
| 2460 | |
| 2461 | /* Check we have a hole for the context ID */ |
| 2462 | BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST); |
| 2463 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context); |
| 2464 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS, |
| 2465 | RSS_CONTEXT_FLAGS_DEFAULT); |
| 2466 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf, |
| 2467 | sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); |
| 2468 | if (rc == 0) { |
| 2469 | if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN) |
| 2470 | rc = -EIO; |
| 2471 | else |
| 2472 | *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS); |
| 2473 | } |
| 2474 | return rc; |
| 2475 | } |
| 2476 | |
| 2477 | /* Attempt to enable 4-tuple UDP hashing on the specified RSS context. |
| 2478 | * If we fail, we just leave the RSS context at its default hash settings, |
| 2479 | * which is safe but may slightly reduce performance. |
| 2480 | * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we |
| 2481 | * just need to set the UDP ports flags (for both IP versions). |
| 2482 | */ |
| 2483 | static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context) |
| 2484 | { |
| 2485 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN); |
| 2486 | u32 flags; |
| 2487 | |
| 2488 | BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0); |
| 2489 | |
| 2490 | if (efx_ef10_get_rss_flags(efx, context, &flags) != 0) |
| 2491 | return; |
| 2492 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context); |
| 2493 | flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN; |
| 2494 | flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN; |
| 2495 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags); |
Edward Cree | b718c88 | 2016-11-03 22:12:58 +0000 | [diff] [blame] | 2496 | if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf), |
| 2497 | NULL, 0, NULL)) |
| 2498 | /* Succeeded, so UDP 4-tuple is now enabled */ |
| 2499 | efx->rx_hash_udp_4tuple = true; |
Edward Cree | a33a4c7 | 2016-11-03 22:12:27 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2502 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context, |
| 2503 | bool exclusive, unsigned *context_size) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2504 | { |
| 2505 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); |
| 2506 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2507 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2508 | size_t outlen; |
| 2509 | int rc; |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2510 | u32 alloc_type = exclusive ? |
| 2511 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE : |
| 2512 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED; |
| 2513 | unsigned rss_spread = exclusive ? |
| 2514 | efx->rss_spread : |
| 2515 | min(rounddown_pow_of_two(efx->rss_spread), |
| 2516 | EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE); |
| 2517 | |
| 2518 | if (!exclusive && rss_spread == 1) { |
| 2519 | *context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 2520 | if (context_size) |
| 2521 | *context_size = 1; |
| 2522 | return 0; |
| 2523 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2524 | |
Jon Cooper | dcb4123 | 2016-04-25 16:51:00 +0100 | [diff] [blame] | 2525 | if (nic_data->datapath_caps & |
| 2526 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN) |
| 2527 | return -EOPNOTSUPP; |
| 2528 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2529 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2530 | nic_data->vport_id); |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2531 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type); |
| 2532 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2533 | |
| 2534 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), |
| 2535 | outbuf, sizeof(outbuf), &outlen); |
| 2536 | if (rc != 0) |
| 2537 | return rc; |
| 2538 | |
| 2539 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) |
| 2540 | return -EIO; |
| 2541 | |
| 2542 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); |
| 2543 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2544 | if (context_size) |
| 2545 | *context_size = rss_spread; |
| 2546 | |
Edward Cree | a33a4c7 | 2016-11-03 22:12:27 +0000 | [diff] [blame] | 2547 | if (nic_data->datapath_caps & |
| 2548 | 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN) |
| 2549 | efx_ef10_set_rss_flags(efx, *context); |
| 2550 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2551 | return 0; |
| 2552 | } |
| 2553 | |
| 2554 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) |
| 2555 | { |
| 2556 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); |
| 2557 | int rc; |
| 2558 | |
| 2559 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, |
| 2560 | context); |
| 2561 | |
| 2562 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), |
| 2563 | NULL, 0, NULL); |
| 2564 | WARN_ON(rc != 0); |
| 2565 | } |
| 2566 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2567 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2568 | const u32 *rx_indir_table, const u8 *key) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2569 | { |
| 2570 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); |
| 2571 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); |
| 2572 | int i, rc; |
| 2573 | |
| 2574 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, |
| 2575 | context); |
| 2576 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != |
| 2577 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); |
| 2578 | |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2579 | /* This iterates over the length of efx->rx_indir_table, but copies |
| 2580 | * bytes from rx_indir_table. That's because the latter is a pointer |
| 2581 | * rather than an array, but should have the same length. |
| 2582 | * The efx->rx_hash_key loop below is similar. |
| 2583 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2584 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) |
| 2585 | MCDI_PTR(tablebuf, |
| 2586 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2587 | (u8) rx_indir_table[i]; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2588 | |
| 2589 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, |
| 2590 | sizeof(tablebuf), NULL, 0, NULL); |
| 2591 | if (rc != 0) |
| 2592 | return rc; |
| 2593 | |
| 2594 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, |
| 2595 | context); |
| 2596 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != |
| 2597 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); |
| 2598 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2599 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i]; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2600 | |
| 2601 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, |
| 2602 | sizeof(keybuf), NULL, 0, NULL); |
| 2603 | } |
| 2604 | |
| 2605 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) |
| 2606 | { |
| 2607 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2608 | |
| 2609 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) |
| 2610 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); |
| 2611 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 2612 | } |
| 2613 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2614 | static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx, |
| 2615 | unsigned *context_size) |
| 2616 | { |
| 2617 | u32 new_rx_rss_context; |
| 2618 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2619 | int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
| 2620 | false, context_size); |
| 2621 | |
| 2622 | if (rc != 0) |
| 2623 | return rc; |
| 2624 | |
| 2625 | nic_data->rx_rss_context = new_rx_rss_context; |
| 2626 | nic_data->rx_rss_context_exclusive = false; |
| 2627 | efx_set_default_rx_indir_table(efx); |
| 2628 | return 0; |
| 2629 | } |
| 2630 | |
| 2631 | static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2632 | const u32 *rx_indir_table, |
| 2633 | const u8 *key) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2634 | { |
| 2635 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2636 | int rc; |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2637 | u32 new_rx_rss_context; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2638 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2639 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID || |
| 2640 | !nic_data->rx_rss_context_exclusive) { |
| 2641 | rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
| 2642 | true, NULL); |
| 2643 | if (rc == -EOPNOTSUPP) |
| 2644 | return rc; |
| 2645 | else if (rc != 0) |
| 2646 | goto fail1; |
| 2647 | } else { |
| 2648 | new_rx_rss_context = nic_data->rx_rss_context; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2649 | } |
| 2650 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2651 | rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2652 | rx_indir_table, key); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2653 | if (rc != 0) |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2654 | goto fail2; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2655 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2656 | if (nic_data->rx_rss_context != new_rx_rss_context) |
| 2657 | efx_ef10_rx_free_indir_table(efx); |
| 2658 | nic_data->rx_rss_context = new_rx_rss_context; |
| 2659 | nic_data->rx_rss_context_exclusive = true; |
| 2660 | if (rx_indir_table != efx->rx_indir_table) |
| 2661 | memcpy(efx->rx_indir_table, rx_indir_table, |
| 2662 | sizeof(efx->rx_indir_table)); |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2663 | if (key != efx->rx_hash_key) |
| 2664 | memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size); |
| 2665 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2666 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2667 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2668 | fail2: |
| 2669 | if (new_rx_rss_context != nic_data->rx_rss_context) |
| 2670 | efx_ef10_free_rss_context(efx, new_rx_rss_context); |
| 2671 | fail1: |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2672 | 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] | 2673 | return rc; |
| 2674 | } |
| 2675 | |
Edward Cree | a707d18 | 2017-01-17 12:02:12 +0000 | [diff] [blame] | 2676 | static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx) |
| 2677 | { |
| 2678 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2679 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN); |
| 2680 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN); |
| 2681 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN); |
| 2682 | size_t outlen; |
| 2683 | int rc, i; |
| 2684 | |
| 2685 | BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN != |
| 2686 | MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN); |
| 2687 | |
| 2688 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID) |
| 2689 | return -ENOENT; |
| 2690 | |
| 2691 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID, |
| 2692 | nic_data->rx_rss_context); |
| 2693 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != |
| 2694 | MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN); |
| 2695 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf), |
| 2696 | tablebuf, sizeof(tablebuf), &outlen); |
| 2697 | if (rc != 0) |
| 2698 | return rc; |
| 2699 | |
| 2700 | if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN)) |
| 2701 | return -EIO; |
| 2702 | |
| 2703 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) |
| 2704 | efx->rx_indir_table[i] = MCDI_PTR(tablebuf, |
| 2705 | RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i]; |
| 2706 | |
| 2707 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID, |
| 2708 | nic_data->rx_rss_context); |
| 2709 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != |
| 2710 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); |
| 2711 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf), |
| 2712 | keybuf, sizeof(keybuf), &outlen); |
| 2713 | if (rc != 0) |
| 2714 | return rc; |
| 2715 | |
| 2716 | if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN)) |
| 2717 | return -EIO; |
| 2718 | |
| 2719 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) |
| 2720 | efx->rx_hash_key[i] = MCDI_PTR( |
| 2721 | keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i]; |
| 2722 | |
| 2723 | return 0; |
| 2724 | } |
| 2725 | |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2726 | static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2727 | const u32 *rx_indir_table, |
| 2728 | const u8 *key) |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2729 | { |
| 2730 | int rc; |
| 2731 | |
| 2732 | if (efx->rss_spread == 1) |
| 2733 | return 0; |
| 2734 | |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2735 | if (!key) |
| 2736 | key = efx->rx_hash_key; |
| 2737 | |
| 2738 | rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key); |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2739 | |
| 2740 | if (rc == -ENOBUFS && !user) { |
| 2741 | unsigned context_size; |
| 2742 | bool mismatch = false; |
| 2743 | size_t i; |
| 2744 | |
| 2745 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch; |
| 2746 | i++) |
| 2747 | mismatch = rx_indir_table[i] != |
| 2748 | ethtool_rxfh_indir_default(i, efx->rss_spread); |
| 2749 | |
| 2750 | rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size); |
| 2751 | if (rc == 0) { |
| 2752 | if (context_size != efx->rss_spread) |
| 2753 | netif_warn(efx, probe, efx->net_dev, |
| 2754 | "Could not allocate an exclusive RSS" |
| 2755 | " context; allocated a shared one of" |
| 2756 | " different size." |
| 2757 | " Wanted %u, got %u.\n", |
| 2758 | efx->rss_spread, context_size); |
| 2759 | else if (mismatch) |
| 2760 | netif_warn(efx, probe, efx->net_dev, |
| 2761 | "Could not allocate an exclusive RSS" |
| 2762 | " context; allocated a shared one but" |
| 2763 | " could not apply custom" |
| 2764 | " indirection.\n"); |
| 2765 | else |
| 2766 | netif_info(efx, probe, efx->net_dev, |
| 2767 | "Could not allocate an exclusive RSS" |
| 2768 | " context; allocated a shared one.\n"); |
| 2769 | } |
| 2770 | } |
| 2771 | return rc; |
| 2772 | } |
| 2773 | |
| 2774 | static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user, |
| 2775 | const u32 *rx_indir_table |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 2776 | __attribute__ ((unused)), |
| 2777 | const u8 *key |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 2778 | __attribute__ ((unused))) |
| 2779 | { |
| 2780 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2781 | |
| 2782 | if (user) |
| 2783 | return -EOPNOTSUPP; |
| 2784 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) |
| 2785 | return 0; |
| 2786 | return efx_ef10_rx_push_shared_rss_config(efx, NULL); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) |
| 2790 | { |
| 2791 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, |
| 2792 | (rx_queue->ptr_mask + 1) * |
| 2793 | sizeof(efx_qword_t), |
| 2794 | GFP_KERNEL); |
| 2795 | } |
| 2796 | |
| 2797 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) |
| 2798 | { |
| 2799 | MCDI_DECLARE_BUF(inbuf, |
| 2800 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 2801 | EFX_BUF_SIZE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2802 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 2803 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; |
| 2804 | struct efx_nic *efx = rx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2805 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2806 | size_t inlen; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2807 | dma_addr_t dma_addr; |
| 2808 | int rc; |
| 2809 | int i; |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2810 | BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2811 | |
| 2812 | rx_queue->scatter_n = 0; |
| 2813 | rx_queue->scatter_len = 0; |
| 2814 | |
| 2815 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); |
| 2816 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); |
| 2817 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); |
| 2818 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, |
| 2819 | efx_rx_queue_index(rx_queue)); |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 2820 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
| 2821 | INIT_RXQ_IN_FLAG_PREFIX, 1, |
| 2822 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2823 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 2824 | 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] | 2825 | |
| 2826 | dma_addr = rx_queue->rxd.buf.dma_addr; |
| 2827 | |
| 2828 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", |
| 2829 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); |
| 2830 | |
| 2831 | for (i = 0; i < entries; ++i) { |
| 2832 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); |
| 2833 | dma_addr += EFX_BUF_SIZE; |
| 2834 | } |
| 2835 | |
| 2836 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); |
| 2837 | |
| 2838 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2839 | NULL, 0, NULL); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 2840 | if (rc) |
| 2841 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", |
| 2842 | efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) |
| 2846 | { |
| 2847 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 2848 | MCDI_DECLARE_BUF_ERR(outbuf); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2849 | struct efx_nic *efx = rx_queue->efx; |
| 2850 | size_t outlen; |
| 2851 | int rc; |
| 2852 | |
| 2853 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, |
| 2854 | efx_rx_queue_index(rx_queue)); |
| 2855 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2856 | 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] | 2857 | outbuf, sizeof(outbuf), &outlen); |
| 2858 | |
| 2859 | if (rc && rc != -EALREADY) |
| 2860 | goto fail; |
| 2861 | |
| 2862 | return; |
| 2863 | |
| 2864 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 2865 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
| 2866 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) |
| 2870 | { |
| 2871 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); |
| 2872 | } |
| 2873 | |
| 2874 | /* This creates an entry in the RX descriptor queue */ |
| 2875 | static inline void |
| 2876 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) |
| 2877 | { |
| 2878 | struct efx_rx_buffer *rx_buf; |
| 2879 | efx_qword_t *rxd; |
| 2880 | |
| 2881 | rxd = efx_rx_desc(rx_queue, index); |
| 2882 | rx_buf = efx_rx_buffer(rx_queue, index); |
| 2883 | EFX_POPULATE_QWORD_2(*rxd, |
| 2884 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, |
| 2885 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); |
| 2886 | } |
| 2887 | |
| 2888 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) |
| 2889 | { |
| 2890 | struct efx_nic *efx = rx_queue->efx; |
| 2891 | unsigned int write_count; |
| 2892 | efx_dword_t reg; |
| 2893 | |
| 2894 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ |
| 2895 | write_count = rx_queue->added_count & ~7; |
| 2896 | if (rx_queue->notified_count == write_count) |
| 2897 | return; |
| 2898 | |
| 2899 | do |
| 2900 | efx_ef10_build_rx_desc( |
| 2901 | rx_queue, |
| 2902 | rx_queue->notified_count & rx_queue->ptr_mask); |
| 2903 | while (++rx_queue->notified_count != write_count); |
| 2904 | |
| 2905 | wmb(); |
| 2906 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, |
| 2907 | write_count & rx_queue->ptr_mask); |
| 2908 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, |
| 2909 | efx_rx_queue_index(rx_queue)); |
| 2910 | } |
| 2911 | |
| 2912 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; |
| 2913 | |
| 2914 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) |
| 2915 | { |
| 2916 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 2917 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 2918 | efx_qword_t event; |
| 2919 | |
| 2920 | EFX_POPULATE_QWORD_2(event, |
| 2921 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 2922 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); |
| 2923 | |
| 2924 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 2925 | |
| 2926 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 2927 | * already swapped the data to little-endian order. |
| 2928 | */ |
| 2929 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 2930 | sizeof(efx_qword_t)); |
| 2931 | |
| 2932 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, |
| 2933 | inbuf, sizeof(inbuf), 0, |
| 2934 | efx_ef10_rx_defer_refill_complete, 0); |
| 2935 | } |
| 2936 | |
| 2937 | static void |
| 2938 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, |
| 2939 | int rc, efx_dword_t *outbuf, |
| 2940 | size_t outlen_actual) |
| 2941 | { |
| 2942 | /* nothing to do */ |
| 2943 | } |
| 2944 | |
| 2945 | static int efx_ef10_ev_probe(struct efx_channel *channel) |
| 2946 | { |
| 2947 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, |
| 2948 | (channel->eventq_mask + 1) * |
| 2949 | sizeof(efx_qword_t), |
| 2950 | GFP_KERNEL); |
| 2951 | } |
| 2952 | |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2953 | static void efx_ef10_ev_fini(struct efx_channel *channel) |
| 2954 | { |
| 2955 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); |
| 2956 | MCDI_DECLARE_BUF_ERR(outbuf); |
| 2957 | struct efx_nic *efx = channel->efx; |
| 2958 | size_t outlen; |
| 2959 | int rc; |
| 2960 | |
| 2961 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); |
| 2962 | |
| 2963 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
| 2964 | outbuf, sizeof(outbuf), &outlen); |
| 2965 | |
| 2966 | if (rc && rc != -EALREADY) |
| 2967 | goto fail; |
| 2968 | |
| 2969 | return; |
| 2970 | |
| 2971 | fail: |
| 2972 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
| 2973 | outbuf, outlen, rc); |
| 2974 | } |
| 2975 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2976 | static int efx_ef10_ev_init(struct efx_channel *channel) |
| 2977 | { |
| 2978 | MCDI_DECLARE_BUF(inbuf, |
Bert Kenward | a995560 | 2016-08-11 13:01:54 +0100 | [diff] [blame] | 2979 | MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / |
| 2980 | EFX_BUF_SIZE)); |
| 2981 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2982 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; |
| 2983 | struct efx_nic *efx = channel->efx; |
| 2984 | struct efx_ef10_nic_data *nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2985 | size_t inlen, outlen; |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 2986 | unsigned int enabled, implemented; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2987 | dma_addr_t dma_addr; |
| 2988 | int rc; |
| 2989 | int i; |
| 2990 | |
| 2991 | nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2992 | |
| 2993 | /* Fill event queue with all ones (i.e. empty events) */ |
| 2994 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); |
| 2995 | |
| 2996 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); |
| 2997 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); |
| 2998 | /* INIT_EVQ expects index in vector table, not absolute */ |
| 2999 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3000 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, |
| 3001 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); |
| 3002 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); |
| 3003 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); |
| 3004 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, |
| 3005 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); |
| 3006 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); |
| 3007 | |
Bert Kenward | a995560 | 2016-08-11 13:01:54 +0100 | [diff] [blame] | 3008 | if (nic_data->datapath_caps2 & |
| 3009 | 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) { |
| 3010 | /* Use the new generic approach to specifying event queue |
| 3011 | * configuration, requesting lower latency or higher throughput. |
| 3012 | * The options that actually get used appear in the output. |
| 3013 | */ |
| 3014 | MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS, |
| 3015 | INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1, |
| 3016 | INIT_EVQ_V2_IN_FLAG_TYPE, |
| 3017 | MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO); |
| 3018 | } else { |
| 3019 | bool cut_thru = !(nic_data->datapath_caps & |
| 3020 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); |
| 3021 | |
| 3022 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, |
| 3023 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, |
| 3024 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, |
| 3025 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, |
| 3026 | INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru); |
| 3027 | } |
| 3028 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3029 | dma_addr = channel->eventq.buf.dma_addr; |
| 3030 | for (i = 0; i < entries; ++i) { |
| 3031 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); |
| 3032 | dma_addr += EFX_BUF_SIZE; |
| 3033 | } |
| 3034 | |
| 3035 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); |
| 3036 | |
| 3037 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, |
| 3038 | outbuf, sizeof(outbuf), &outlen); |
Bert Kenward | a995560 | 2016-08-11 13:01:54 +0100 | [diff] [blame] | 3039 | |
| 3040 | if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN) |
| 3041 | netif_dbg(efx, drv, efx->net_dev, |
| 3042 | "Channel %d using event queue flags %08x\n", |
| 3043 | channel->channel, |
| 3044 | MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS)); |
| 3045 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3046 | /* IRQ return is ignored */ |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 3047 | if (channel->channel || rc) |
| 3048 | return rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3049 | |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 3050 | /* Successfully created event queue on channel 0 */ |
| 3051 | rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled); |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3052 | if (rc == -ENOSYS) { |
Bert Kenward | d95e329 | 2016-08-11 13:02:36 +0100 | [diff] [blame] | 3053 | /* GET_WORKAROUNDS was implemented before this workaround, |
| 3054 | * thus it must be unavailable in this firmware. |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3055 | */ |
| 3056 | nic_data->workaround_26807 = false; |
| 3057 | rc = 0; |
| 3058 | } else if (rc) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3059 | goto fail; |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3060 | } else { |
| 3061 | nic_data->workaround_26807 = |
| 3062 | !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3063 | |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3064 | if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 && |
| 3065 | !nic_data->workaround_26807) { |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 3066 | unsigned int flags; |
| 3067 | |
Daniel Pieczko | 34ccfe6 | 2015-07-21 15:09:43 +0100 | [diff] [blame] | 3068 | rc = efx_mcdi_set_workaround(efx, |
| 3069 | MC_CMD_WORKAROUND_BUG26807, |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 3070 | true, &flags); |
| 3071 | |
| 3072 | if (!rc) { |
| 3073 | if (flags & |
| 3074 | 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) { |
| 3075 | netif_info(efx, drv, efx->net_dev, |
| 3076 | "other functions on NIC have been reset\n"); |
Daniel Pieczko | abd86a5 | 2015-12-04 08:48:39 +0000 | [diff] [blame] | 3077 | |
| 3078 | /* With MCFW v4.6.x and earlier, the |
| 3079 | * boot count will have incremented, |
| 3080 | * so re-read the warm_boot_count |
| 3081 | * value now to ensure this function |
| 3082 | * doesn't think it has changed next |
| 3083 | * time it checks. |
| 3084 | */ |
| 3085 | rc = efx_ef10_get_warm_boot_count(efx); |
| 3086 | if (rc >= 0) { |
| 3087 | nic_data->warm_boot_count = rc; |
| 3088 | rc = 0; |
| 3089 | } |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 3090 | } |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3091 | nic_data->workaround_26807 = true; |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 3092 | } else if (rc == -EPERM) { |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3093 | rc = 0; |
Daniel Pieczko | 5a55a72 | 2015-07-21 15:10:02 +0100 | [diff] [blame] | 3094 | } |
Edward Cree | 832dc9e | 2015-07-21 15:09:31 +0100 | [diff] [blame] | 3095 | } |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | if (!rc) |
| 3099 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3100 | |
| 3101 | fail: |
Daniel Pieczko | 46e612b | 2015-07-21 15:09:18 +0100 | [diff] [blame] | 3102 | efx_ef10_ev_fini(channel); |
| 3103 | return rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | static void efx_ef10_ev_remove(struct efx_channel *channel) |
| 3107 | { |
| 3108 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); |
| 3109 | } |
| 3110 | |
| 3111 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, |
| 3112 | unsigned int rx_queue_label) |
| 3113 | { |
| 3114 | struct efx_nic *efx = rx_queue->efx; |
| 3115 | |
| 3116 | netif_info(efx, hw, efx->net_dev, |
| 3117 | "rx event arrived on queue %d labeled as queue %u\n", |
| 3118 | efx_rx_queue_index(rx_queue), rx_queue_label); |
| 3119 | |
| 3120 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 3121 | } |
| 3122 | |
| 3123 | static void |
| 3124 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, |
| 3125 | unsigned int actual, unsigned int expected) |
| 3126 | { |
| 3127 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; |
| 3128 | struct efx_nic *efx = rx_queue->efx; |
| 3129 | |
| 3130 | netif_info(efx, hw, efx->net_dev, |
| 3131 | "dropped %d events (index=%d expected=%d)\n", |
| 3132 | dropped, actual, expected); |
| 3133 | |
| 3134 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 3135 | } |
| 3136 | |
| 3137 | /* partially received RX was aborted. clean up. */ |
| 3138 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) |
| 3139 | { |
| 3140 | unsigned int rx_desc_ptr; |
| 3141 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3142 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
| 3143 | "scattered RX aborted (dropping %u buffers)\n", |
| 3144 | rx_queue->scatter_n); |
| 3145 | |
| 3146 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; |
| 3147 | |
| 3148 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, |
| 3149 | 0, EFX_RX_PKT_DISCARD); |
| 3150 | |
| 3151 | rx_queue->removed_count += rx_queue->scatter_n; |
| 3152 | rx_queue->scatter_n = 0; |
| 3153 | rx_queue->scatter_len = 0; |
| 3154 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; |
| 3155 | } |
| 3156 | |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3157 | static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel, |
| 3158 | unsigned int n_packets, |
| 3159 | unsigned int rx_encap_hdr, |
| 3160 | unsigned int rx_l3_class, |
| 3161 | unsigned int rx_l4_class, |
| 3162 | const efx_qword_t *event) |
| 3163 | { |
| 3164 | struct efx_nic *efx = channel->efx; |
| 3165 | |
| 3166 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) { |
| 3167 | if (!efx->loopback_selftest) |
| 3168 | channel->n_rx_eth_crc_err += n_packets; |
| 3169 | return EFX_RX_PKT_DISCARD; |
| 3170 | } |
| 3171 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) { |
| 3172 | if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN && |
| 3173 | rx_l3_class != ESE_DZ_L3_CLASS_IP4 && |
| 3174 | rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG && |
| 3175 | rx_l3_class != ESE_DZ_L3_CLASS_IP6 && |
| 3176 | rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG)) |
| 3177 | netdev_WARN(efx->net_dev, |
| 3178 | "invalid class for RX_IPCKSUM_ERR: event=" |
| 3179 | EFX_QWORD_FMT "\n", |
| 3180 | EFX_QWORD_VAL(*event)); |
| 3181 | if (!efx->loopback_selftest) |
| 3182 | *(rx_encap_hdr ? |
| 3183 | &channel->n_rx_outer_ip_hdr_chksum_err : |
| 3184 | &channel->n_rx_ip_hdr_chksum_err) += n_packets; |
| 3185 | return 0; |
| 3186 | } |
| 3187 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) { |
| 3188 | if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN && |
| 3189 | ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 && |
| 3190 | rx_l3_class != ESE_DZ_L3_CLASS_IP6) || |
| 3191 | (rx_l4_class != ESE_DZ_L4_CLASS_TCP && |
| 3192 | rx_l4_class != ESE_DZ_L4_CLASS_UDP)))) |
| 3193 | netdev_WARN(efx->net_dev, |
| 3194 | "invalid class for RX_TCPUDP_CKSUM_ERR: event=" |
| 3195 | EFX_QWORD_FMT "\n", |
| 3196 | EFX_QWORD_VAL(*event)); |
| 3197 | if (!efx->loopback_selftest) |
| 3198 | *(rx_encap_hdr ? |
| 3199 | &channel->n_rx_outer_tcp_udp_chksum_err : |
| 3200 | &channel->n_rx_tcp_udp_chksum_err) += n_packets; |
| 3201 | return 0; |
| 3202 | } |
| 3203 | if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) { |
| 3204 | if (unlikely(!rx_encap_hdr)) |
| 3205 | netdev_WARN(efx->net_dev, |
| 3206 | "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event=" |
| 3207 | EFX_QWORD_FMT "\n", |
| 3208 | EFX_QWORD_VAL(*event)); |
| 3209 | else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 && |
| 3210 | rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG && |
| 3211 | rx_l3_class != ESE_DZ_L3_CLASS_IP6 && |
| 3212 | rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG)) |
| 3213 | netdev_WARN(efx->net_dev, |
| 3214 | "invalid class for RX_IP_INNER_CHKSUM_ERR: event=" |
| 3215 | EFX_QWORD_FMT "\n", |
| 3216 | EFX_QWORD_VAL(*event)); |
| 3217 | if (!efx->loopback_selftest) |
| 3218 | channel->n_rx_inner_ip_hdr_chksum_err += n_packets; |
| 3219 | return 0; |
| 3220 | } |
| 3221 | if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) { |
| 3222 | if (unlikely(!rx_encap_hdr)) |
| 3223 | netdev_WARN(efx->net_dev, |
| 3224 | "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event=" |
| 3225 | EFX_QWORD_FMT "\n", |
| 3226 | EFX_QWORD_VAL(*event)); |
| 3227 | else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 && |
| 3228 | rx_l3_class != ESE_DZ_L3_CLASS_IP6) || |
| 3229 | (rx_l4_class != ESE_DZ_L4_CLASS_TCP && |
| 3230 | rx_l4_class != ESE_DZ_L4_CLASS_UDP))) |
| 3231 | netdev_WARN(efx->net_dev, |
| 3232 | "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event=" |
| 3233 | EFX_QWORD_FMT "\n", |
| 3234 | EFX_QWORD_VAL(*event)); |
| 3235 | if (!efx->loopback_selftest) |
| 3236 | channel->n_rx_inner_tcp_udp_chksum_err += n_packets; |
| 3237 | return 0; |
| 3238 | } |
| 3239 | |
| 3240 | WARN_ON(1); /* No error bits were recognised */ |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3244 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, |
| 3245 | const efx_qword_t *event) |
| 3246 | { |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3247 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label; |
| 3248 | unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3249 | unsigned int n_descs, n_packets, i; |
| 3250 | struct efx_nic *efx = channel->efx; |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3251 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3252 | struct efx_rx_queue *rx_queue; |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3253 | efx_qword_t errors; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3254 | bool rx_cont; |
| 3255 | u16 flags = 0; |
| 3256 | |
| 3257 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 3258 | return 0; |
| 3259 | |
| 3260 | /* Basic packet information */ |
| 3261 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); |
| 3262 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); |
| 3263 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3264 | rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3265 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); |
| 3266 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3267 | rx_encap_hdr = |
| 3268 | nic_data->datapath_caps & |
| 3269 | (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ? |
| 3270 | EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) : |
| 3271 | ESE_EZ_ENCAP_HDR_NONE; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3272 | |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 3273 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
| 3274 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" |
| 3275 | EFX_QWORD_FMT "\n", |
| 3276 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3277 | |
| 3278 | rx_queue = efx_channel_get_rx_queue(channel); |
| 3279 | |
| 3280 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) |
| 3281 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); |
| 3282 | |
| 3283 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & |
| 3284 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 3285 | |
| 3286 | if (n_descs != rx_queue->scatter_n + 1) { |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 3287 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 3288 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3289 | /* detect rx abort */ |
| 3290 | if (unlikely(n_descs == rx_queue->scatter_n)) { |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 3291 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
| 3292 | netdev_WARN(efx->net_dev, |
| 3293 | "invalid RX abort: scatter_n=%u event=" |
| 3294 | EFX_QWORD_FMT "\n", |
| 3295 | rx_queue->scatter_n, |
| 3296 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3297 | efx_ef10_handle_rx_abort(rx_queue); |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 3301 | /* Check that RX completion merging is valid, i.e. |
| 3302 | * the current firmware supports it and this is a |
| 3303 | * non-scattered packet. |
| 3304 | */ |
| 3305 | if (!(nic_data->datapath_caps & |
| 3306 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || |
| 3307 | rx_queue->scatter_n != 0 || rx_cont) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3308 | efx_ef10_handle_rx_bad_lbits( |
| 3309 | rx_queue, next_ptr_lbits, |
| 3310 | (rx_queue->removed_count + |
| 3311 | rx_queue->scatter_n + 1) & |
| 3312 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | /* Merged completion for multiple non-scattered packets */ |
| 3317 | rx_queue->scatter_n = 1; |
| 3318 | rx_queue->scatter_len = 0; |
| 3319 | n_packets = n_descs; |
| 3320 | ++channel->n_rx_merge_events; |
| 3321 | channel->n_rx_merge_packets += n_packets; |
| 3322 | flags |= EFX_RX_PKT_PREFIX_LEN; |
| 3323 | } else { |
| 3324 | ++rx_queue->scatter_n; |
| 3325 | rx_queue->scatter_len += rx_bytes; |
| 3326 | if (rx_cont) |
| 3327 | return 0; |
| 3328 | n_packets = 1; |
| 3329 | } |
| 3330 | |
Jon Cooper | a0ee354 | 2017-02-08 16:50:40 +0000 | [diff] [blame] | 3331 | EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1, |
| 3332 | ESF_DZ_RX_IPCKSUM_ERR, 1, |
| 3333 | ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1, |
| 3334 | ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1, |
| 3335 | ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1); |
| 3336 | EFX_AND_QWORD(errors, *event, errors); |
| 3337 | if (unlikely(!EFX_QWORD_IS_ZERO(errors))) { |
| 3338 | flags |= efx_ef10_handle_rx_event_errors(channel, n_packets, |
| 3339 | rx_l3_class, rx_l4_class, |
| 3340 | rx_encap_hdr, event); |
| 3341 | } else { |
Jon Cooper | da50ae2 | 2017-02-08 16:51:02 +0000 | [diff] [blame] | 3342 | bool tcpudp = rx_l4_class == ESE_DZ_L4_CLASS_TCP || |
| 3343 | rx_l4_class == ESE_DZ_L4_CLASS_UDP; |
| 3344 | |
| 3345 | switch (rx_encap_hdr) { |
| 3346 | case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */ |
| 3347 | flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */ |
| 3348 | if (tcpudp) |
| 3349 | flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */ |
| 3350 | break; |
| 3351 | case ESE_EZ_ENCAP_HDR_GRE: |
| 3352 | case ESE_EZ_ENCAP_HDR_NONE: |
| 3353 | if (tcpudp) |
| 3354 | flags |= EFX_RX_PKT_CSUMMED; |
| 3355 | break; |
| 3356 | default: |
| 3357 | netdev_WARN(efx->net_dev, |
| 3358 | "unknown encapsulation type: event=" |
| 3359 | EFX_QWORD_FMT "\n", |
| 3360 | EFX_QWORD_VAL(*event)); |
| 3361 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) |
| 3365 | flags |= EFX_RX_PKT_TCP; |
| 3366 | |
| 3367 | channel->irq_mod_score += 2 * n_packets; |
| 3368 | |
| 3369 | /* Handle received packet(s) */ |
| 3370 | for (i = 0; i < n_packets; i++) { |
| 3371 | efx_rx_packet(rx_queue, |
| 3372 | rx_queue->removed_count & rx_queue->ptr_mask, |
| 3373 | rx_queue->scatter_n, rx_queue->scatter_len, |
| 3374 | flags); |
| 3375 | rx_queue->removed_count += rx_queue->scatter_n; |
| 3376 | } |
| 3377 | |
| 3378 | rx_queue->scatter_n = 0; |
| 3379 | rx_queue->scatter_len = 0; |
| 3380 | |
| 3381 | return n_packets; |
| 3382 | } |
| 3383 | |
| 3384 | static int |
| 3385 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) |
| 3386 | { |
| 3387 | struct efx_nic *efx = channel->efx; |
| 3388 | struct efx_tx_queue *tx_queue; |
| 3389 | unsigned int tx_ev_desc_ptr; |
| 3390 | unsigned int tx_ev_q_label; |
| 3391 | int tx_descs = 0; |
| 3392 | |
| 3393 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 3394 | return 0; |
| 3395 | |
| 3396 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) |
| 3397 | return 0; |
| 3398 | |
| 3399 | /* Transmit completion */ |
| 3400 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); |
| 3401 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); |
| 3402 | tx_queue = efx_channel_get_tx_queue(channel, |
| 3403 | tx_ev_q_label % EFX_TXQ_TYPES); |
| 3404 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & |
| 3405 | tx_queue->ptr_mask); |
| 3406 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); |
| 3407 | |
| 3408 | return tx_descs; |
| 3409 | } |
| 3410 | |
| 3411 | static void |
| 3412 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) |
| 3413 | { |
| 3414 | struct efx_nic *efx = channel->efx; |
| 3415 | int subcode; |
| 3416 | |
| 3417 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); |
| 3418 | |
| 3419 | switch (subcode) { |
| 3420 | case ESE_DZ_DRV_TIMER_EV: |
| 3421 | case ESE_DZ_DRV_WAKE_UP_EV: |
| 3422 | break; |
| 3423 | case ESE_DZ_DRV_START_UP_EV: |
| 3424 | /* event queue init complete. ok. */ |
| 3425 | break; |
| 3426 | default: |
| 3427 | netif_err(efx, hw, efx->net_dev, |
| 3428 | "channel %d unknown driver event type %d" |
| 3429 | " (data " EFX_QWORD_FMT ")\n", |
| 3430 | channel->channel, subcode, |
| 3431 | EFX_QWORD_VAL(*event)); |
| 3432 | |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, |
| 3437 | efx_qword_t *event) |
| 3438 | { |
| 3439 | struct efx_nic *efx = channel->efx; |
| 3440 | u32 subcode; |
| 3441 | |
| 3442 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); |
| 3443 | |
| 3444 | switch (subcode) { |
| 3445 | case EFX_EF10_TEST: |
| 3446 | channel->event_test_cpu = raw_smp_processor_id(); |
| 3447 | break; |
| 3448 | case EFX_EF10_REFILL: |
| 3449 | /* The queue must be empty, so we won't receive any rx |
| 3450 | * events, so efx_process_channel() won't refill the |
| 3451 | * queue. Refill it here |
| 3452 | */ |
Jon Cooper | cce2879 | 2013-10-02 11:04:14 +0100 | [diff] [blame] | 3453 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3454 | break; |
| 3455 | default: |
| 3456 | netif_err(efx, hw, efx->net_dev, |
| 3457 | "channel %d unknown driver event type %u" |
| 3458 | " (data " EFX_QWORD_FMT ")\n", |
| 3459 | channel->channel, (unsigned) subcode, |
| 3460 | EFX_QWORD_VAL(*event)); |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) |
| 3465 | { |
| 3466 | struct efx_nic *efx = channel->efx; |
| 3467 | efx_qword_t event, *p_event; |
| 3468 | unsigned int read_ptr; |
| 3469 | int ev_code; |
| 3470 | int tx_descs = 0; |
| 3471 | int spent = 0; |
| 3472 | |
Eric W. Biederman | 75363a4 | 2014-03-14 18:11:22 -0700 | [diff] [blame] | 3473 | if (quota <= 0) |
| 3474 | return spent; |
| 3475 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3476 | read_ptr = channel->eventq_read_ptr; |
| 3477 | |
| 3478 | for (;;) { |
| 3479 | p_event = efx_event(channel, read_ptr); |
| 3480 | event = *p_event; |
| 3481 | |
| 3482 | if (!efx_event_present(&event)) |
| 3483 | break; |
| 3484 | |
| 3485 | EFX_SET_QWORD(*p_event); |
| 3486 | |
| 3487 | ++read_ptr; |
| 3488 | |
| 3489 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); |
| 3490 | |
| 3491 | netif_vdbg(efx, drv, efx->net_dev, |
| 3492 | "processing event on %d " EFX_QWORD_FMT "\n", |
| 3493 | channel->channel, EFX_QWORD_VAL(event)); |
| 3494 | |
| 3495 | switch (ev_code) { |
| 3496 | case ESE_DZ_EV_CODE_MCDI_EV: |
| 3497 | efx_mcdi_process_event(channel, &event); |
| 3498 | break; |
| 3499 | case ESE_DZ_EV_CODE_RX_EV: |
| 3500 | spent += efx_ef10_handle_rx_event(channel, &event); |
| 3501 | if (spent >= quota) { |
| 3502 | /* XXX can we split a merged event to |
| 3503 | * avoid going over-quota? |
| 3504 | */ |
| 3505 | spent = quota; |
| 3506 | goto out; |
| 3507 | } |
| 3508 | break; |
| 3509 | case ESE_DZ_EV_CODE_TX_EV: |
| 3510 | tx_descs += efx_ef10_handle_tx_event(channel, &event); |
| 3511 | if (tx_descs > efx->txq_entries) { |
| 3512 | spent = quota; |
| 3513 | goto out; |
| 3514 | } else if (++spent == quota) { |
| 3515 | goto out; |
| 3516 | } |
| 3517 | break; |
| 3518 | case ESE_DZ_EV_CODE_DRIVER_EV: |
| 3519 | efx_ef10_handle_driver_event(channel, &event); |
| 3520 | if (++spent == quota) |
| 3521 | goto out; |
| 3522 | break; |
| 3523 | case EFX_EF10_DRVGEN_EV: |
| 3524 | efx_ef10_handle_driver_generated_event(channel, &event); |
| 3525 | break; |
| 3526 | default: |
| 3527 | netif_err(efx, hw, efx->net_dev, |
| 3528 | "channel %d unknown event type %d" |
| 3529 | " (data " EFX_QWORD_FMT ")\n", |
| 3530 | channel->channel, ev_code, |
| 3531 | EFX_QWORD_VAL(event)); |
| 3532 | } |
| 3533 | } |
| 3534 | |
| 3535 | out: |
| 3536 | channel->eventq_read_ptr = read_ptr; |
| 3537 | return spent; |
| 3538 | } |
| 3539 | |
| 3540 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) |
| 3541 | { |
| 3542 | struct efx_nic *efx = channel->efx; |
| 3543 | efx_dword_t rptr; |
| 3544 | |
| 3545 | if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 3546 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < |
| 3547 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 3548 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > |
| 3549 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 3550 | |
| 3551 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 3552 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, |
| 3553 | ERF_DD_EVQ_IND_RPTR, |
| 3554 | (channel->eventq_read_ptr & |
| 3555 | channel->eventq_mask) >> |
| 3556 | ERF_DD_EVQ_IND_RPTR_WIDTH); |
| 3557 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 3558 | channel->channel); |
| 3559 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 3560 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, |
| 3561 | ERF_DD_EVQ_IND_RPTR, |
| 3562 | channel->eventq_read_ptr & |
| 3563 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); |
| 3564 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 3565 | channel->channel); |
| 3566 | } else { |
| 3567 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, |
| 3568 | channel->eventq_read_ptr & |
| 3569 | channel->eventq_mask); |
| 3570 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) |
| 3575 | { |
| 3576 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 3577 | struct efx_nic *efx = channel->efx; |
| 3578 | efx_qword_t event; |
| 3579 | int rc; |
| 3580 | |
| 3581 | EFX_POPULATE_QWORD_2(event, |
| 3582 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 3583 | ESF_DZ_EV_DATA, EFX_EF10_TEST); |
| 3584 | |
| 3585 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 3586 | |
| 3587 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 3588 | * already swapped the data to little-endian order. |
| 3589 | */ |
| 3590 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 3591 | sizeof(efx_qword_t)); |
| 3592 | |
| 3593 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), |
| 3594 | NULL, 0, NULL); |
| 3595 | if (rc != 0) |
| 3596 | goto fail; |
| 3597 | |
| 3598 | return; |
| 3599 | |
| 3600 | fail: |
| 3601 | WARN_ON(true); |
| 3602 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
| 3603 | } |
| 3604 | |
| 3605 | void efx_ef10_handle_drain_event(struct efx_nic *efx) |
| 3606 | { |
| 3607 | if (atomic_dec_and_test(&efx->active_queues)) |
| 3608 | wake_up(&efx->flush_wq); |
| 3609 | |
| 3610 | WARN_ON(atomic_read(&efx->active_queues) < 0); |
| 3611 | } |
| 3612 | |
| 3613 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) |
| 3614 | { |
| 3615 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 3616 | struct efx_channel *channel; |
| 3617 | struct efx_tx_queue *tx_queue; |
| 3618 | struct efx_rx_queue *rx_queue; |
| 3619 | int pending; |
| 3620 | |
| 3621 | /* If the MC has just rebooted, the TX/RX queues will have already been |
| 3622 | * torn down, but efx->active_queues needs to be set to zero. |
| 3623 | */ |
| 3624 | if (nic_data->must_realloc_vis) { |
| 3625 | atomic_set(&efx->active_queues, 0); |
| 3626 | return 0; |
| 3627 | } |
| 3628 | |
| 3629 | /* Do not attempt to write to the NIC during EEH recovery */ |
| 3630 | if (efx->state != STATE_RECOVERY) { |
| 3631 | efx_for_each_channel(channel, efx) { |
| 3632 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 3633 | efx_ef10_rx_fini(rx_queue); |
| 3634 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 3635 | efx_ef10_tx_fini(tx_queue); |
| 3636 | } |
| 3637 | |
| 3638 | wait_event_timeout(efx->flush_wq, |
| 3639 | atomic_read(&efx->active_queues) == 0, |
| 3640 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); |
| 3641 | pending = atomic_read(&efx->active_queues); |
| 3642 | if (pending) { |
| 3643 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", |
| 3644 | pending); |
| 3645 | return -ETIMEDOUT; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 3652 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
| 3653 | { |
| 3654 | atomic_set(&efx->active_queues, 0); |
| 3655 | } |
| 3656 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3657 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
| 3658 | const struct efx_filter_spec *right) |
| 3659 | { |
| 3660 | if ((left->match_flags ^ right->match_flags) | |
| 3661 | ((left->flags ^ right->flags) & |
| 3662 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) |
| 3663 | return false; |
| 3664 | |
| 3665 | return memcmp(&left->outer_vid, &right->outer_vid, |
| 3666 | sizeof(struct efx_filter_spec) - |
| 3667 | offsetof(struct efx_filter_spec, outer_vid)) == 0; |
| 3668 | } |
| 3669 | |
| 3670 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) |
| 3671 | { |
| 3672 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); |
| 3673 | return jhash2((const u32 *)&spec->outer_vid, |
| 3674 | (sizeof(struct efx_filter_spec) - |
| 3675 | offsetof(struct efx_filter_spec, outer_vid)) / 4, |
| 3676 | 0); |
| 3677 | /* XXX should we randomise the initval? */ |
| 3678 | } |
| 3679 | |
| 3680 | /* Decide whether a filter should be exclusive or else should allow |
| 3681 | * delivery to additional recipients. Currently we decide that |
| 3682 | * filters for specific local unicast MAC and IP addresses are |
| 3683 | * exclusive. |
| 3684 | */ |
| 3685 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) |
| 3686 | { |
| 3687 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && |
| 3688 | !is_multicast_ether_addr(spec->loc_mac)) |
| 3689 | return true; |
| 3690 | |
| 3691 | if ((spec->match_flags & |
| 3692 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == |
| 3693 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { |
| 3694 | if (spec->ether_type == htons(ETH_P_IP) && |
| 3695 | !ipv4_is_multicast(spec->loc_host[0])) |
| 3696 | return true; |
| 3697 | if (spec->ether_type == htons(ETH_P_IPV6) && |
| 3698 | ((const u8 *)spec->loc_host)[0] != 0xff) |
| 3699 | return true; |
| 3700 | } |
| 3701 | |
| 3702 | return false; |
| 3703 | } |
| 3704 | |
| 3705 | static struct efx_filter_spec * |
| 3706 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, |
| 3707 | unsigned int filter_idx) |
| 3708 | { |
| 3709 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & |
| 3710 | ~EFX_EF10_FILTER_FLAGS); |
| 3711 | } |
| 3712 | |
| 3713 | static unsigned int |
| 3714 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, |
| 3715 | unsigned int filter_idx) |
| 3716 | { |
| 3717 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; |
| 3718 | } |
| 3719 | |
| 3720 | static void |
| 3721 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, |
| 3722 | unsigned int filter_idx, |
| 3723 | const struct efx_filter_spec *spec, |
| 3724 | unsigned int flags) |
| 3725 | { |
| 3726 | table->entry[filter_idx].spec = (unsigned long)spec | flags; |
| 3727 | } |
| 3728 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3729 | static void |
| 3730 | efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx, |
| 3731 | const struct efx_filter_spec *spec, |
| 3732 | efx_dword_t *inbuf) |
| 3733 | { |
| 3734 | enum efx_encap_type encap_type = efx_filter_get_encap_type(spec); |
| 3735 | u32 match_fields = 0, uc_match, mc_match; |
| 3736 | |
| 3737 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3738 | efx_ef10_filter_is_exclusive(spec) ? |
| 3739 | MC_CMD_FILTER_OP_IN_OP_INSERT : |
| 3740 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); |
| 3741 | |
| 3742 | /* Convert match flags and values. Unlike almost |
| 3743 | * everything else in MCDI, these fields are in |
| 3744 | * network byte order. |
| 3745 | */ |
| 3746 | #define COPY_VALUE(value, mcdi_field) \ |
| 3747 | do { \ |
| 3748 | match_fields |= \ |
| 3749 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ |
| 3750 | mcdi_field ## _LBN; \ |
| 3751 | BUILD_BUG_ON( \ |
| 3752 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ |
| 3753 | sizeof(value)); \ |
| 3754 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ |
| 3755 | &value, sizeof(value)); \ |
| 3756 | } while (0) |
| 3757 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ |
| 3758 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ |
| 3759 | COPY_VALUE(spec->gen_field, mcdi_field); \ |
| 3760 | } |
| 3761 | /* Handle encap filters first. They will always be mismatch |
| 3762 | * (unknown UC or MC) filters |
| 3763 | */ |
| 3764 | if (encap_type) { |
| 3765 | /* ether_type and outer_ip_proto need to be variables |
| 3766 | * because COPY_VALUE wants to memcpy them |
| 3767 | */ |
| 3768 | __be16 ether_type = |
| 3769 | htons(encap_type & EFX_ENCAP_FLAG_IPV6 ? |
| 3770 | ETH_P_IPV6 : ETH_P_IP); |
| 3771 | u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE; |
| 3772 | u8 outer_ip_proto; |
| 3773 | |
| 3774 | switch (encap_type & EFX_ENCAP_TYPES_MASK) { |
| 3775 | case EFX_ENCAP_TYPE_VXLAN: |
| 3776 | vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN; |
| 3777 | /* fallthrough */ |
| 3778 | case EFX_ENCAP_TYPE_GENEVE: |
| 3779 | COPY_VALUE(ether_type, ETHER_TYPE); |
| 3780 | outer_ip_proto = IPPROTO_UDP; |
| 3781 | COPY_VALUE(outer_ip_proto, IP_PROTO); |
| 3782 | /* We always need to set the type field, even |
| 3783 | * though we're not matching on the TNI. |
| 3784 | */ |
| 3785 | MCDI_POPULATE_DWORD_1(inbuf, |
| 3786 | FILTER_OP_EXT_IN_VNI_OR_VSID, |
| 3787 | FILTER_OP_EXT_IN_VNI_TYPE, |
| 3788 | vni_type); |
| 3789 | break; |
| 3790 | case EFX_ENCAP_TYPE_NVGRE: |
| 3791 | COPY_VALUE(ether_type, ETHER_TYPE); |
| 3792 | outer_ip_proto = IPPROTO_GRE; |
| 3793 | COPY_VALUE(outer_ip_proto, IP_PROTO); |
| 3794 | break; |
| 3795 | default: |
| 3796 | WARN_ON(1); |
| 3797 | } |
| 3798 | |
| 3799 | uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN; |
| 3800 | mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN; |
| 3801 | } else { |
| 3802 | uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN; |
| 3803 | mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN; |
| 3804 | } |
| 3805 | |
| 3806 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) |
| 3807 | match_fields |= |
| 3808 | is_multicast_ether_addr(spec->loc_mac) ? |
| 3809 | 1 << mc_match : |
| 3810 | 1 << uc_match; |
| 3811 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); |
| 3812 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); |
| 3813 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); |
| 3814 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); |
| 3815 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); |
| 3816 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); |
| 3817 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); |
| 3818 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); |
| 3819 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); |
| 3820 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); |
| 3821 | #undef COPY_FIELD |
| 3822 | #undef COPY_VALUE |
| 3823 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, |
| 3824 | match_fields); |
| 3825 | } |
| 3826 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3827 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, |
| 3828 | const struct efx_filter_spec *spec, |
| 3829 | efx_dword_t *inbuf, u64 handle, |
| 3830 | bool replacing) |
| 3831 | { |
| 3832 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | dcb4123 | 2016-04-25 16:51:00 +0100 | [diff] [blame] | 3833 | u32 flags = spec->flags; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3834 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3835 | memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3836 | |
Jon Cooper | dcb4123 | 2016-04-25 16:51:00 +0100 | [diff] [blame] | 3837 | /* Remove RSS flag if we don't have an RSS context. */ |
| 3838 | if (flags & EFX_FILTER_FLAG_RX_RSS && |
| 3839 | spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT && |
| 3840 | nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID) |
| 3841 | flags &= ~EFX_FILTER_FLAG_RX_RSS; |
| 3842 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3843 | if (replacing) { |
| 3844 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3845 | MC_CMD_FILTER_OP_IN_OP_REPLACE); |
| 3846 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); |
| 3847 | } else { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3848 | efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3849 | } |
| 3850 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame] | 3851 | 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] | 3852 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
| 3853 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 3854 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : |
| 3855 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); |
Shradha Shah | e3d3629 | 2015-05-06 00:56:24 +0100 | [diff] [blame] | 3856 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3857 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
| 3858 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); |
Ben Hutchings | a0bc348 | 2013-12-16 18:56:24 +0000 | [diff] [blame] | 3859 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
| 3860 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 3861 | 0 : spec->dmaq_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3862 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
Jon Cooper | dcb4123 | 2016-04-25 16:51:00 +0100 | [diff] [blame] | 3863 | (flags & EFX_FILTER_FLAG_RX_RSS) ? |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3864 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : |
| 3865 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); |
Jon Cooper | dcb4123 | 2016-04-25 16:51:00 +0100 | [diff] [blame] | 3866 | if (flags & EFX_FILTER_FLAG_RX_RSS) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3867 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, |
| 3868 | spec->rss_context != |
| 3869 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? |
| 3870 | spec->rss_context : nic_data->rx_rss_context); |
| 3871 | } |
| 3872 | |
| 3873 | static int efx_ef10_filter_push(struct efx_nic *efx, |
| 3874 | const struct efx_filter_spec *spec, |
| 3875 | u64 *handle, bool replacing) |
| 3876 | { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3877 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN); |
| 3878 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3879 | int rc; |
| 3880 | |
| 3881 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); |
| 3882 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 3883 | outbuf, sizeof(outbuf), NULL); |
| 3884 | if (rc == 0) |
| 3885 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
Ben Hutchings | 065e64c | 2013-10-09 14:17:27 +0100 | [diff] [blame] | 3886 | if (rc == -ENOSPC) |
| 3887 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3888 | return rc; |
| 3889 | } |
| 3890 | |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3891 | static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3892 | { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3893 | enum efx_encap_type encap_type = efx_filter_get_encap_type(spec); |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3894 | unsigned int match_flags = spec->match_flags; |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3895 | unsigned int uc_match, mc_match; |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3896 | u32 mcdi_flags = 0; |
| 3897 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3898 | #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \ |
| 3899 | unsigned int old_match_flags = match_flags; \ |
| 3900 | match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \ |
| 3901 | if (match_flags != old_match_flags) \ |
| 3902 | mcdi_flags |= \ |
| 3903 | (1 << ((encap) ? \ |
| 3904 | MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \ |
| 3905 | mcdi_field ## _LBN : \ |
| 3906 | MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\ |
| 3907 | mcdi_field ## _LBN)); \ |
| 3908 | } |
| 3909 | /* inner or outer based on encap type */ |
| 3910 | MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type); |
| 3911 | MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type); |
| 3912 | MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type); |
| 3913 | MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type); |
| 3914 | MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type); |
| 3915 | MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type); |
| 3916 | MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type); |
| 3917 | MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type); |
| 3918 | /* always outer */ |
| 3919 | MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false); |
| 3920 | MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false); |
| 3921 | #undef MAP_FILTER_TO_MCDI_FLAG |
| 3922 | |
| 3923 | /* special handling for encap type, and mismatch */ |
| 3924 | if (encap_type) { |
| 3925 | match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE; |
| 3926 | mcdi_flags |= |
| 3927 | (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN); |
| 3928 | mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN); |
| 3929 | |
| 3930 | uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN; |
| 3931 | mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN; |
| 3932 | } else { |
| 3933 | uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN; |
| 3934 | mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN; |
| 3935 | } |
| 3936 | |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3937 | if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) { |
| 3938 | match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG; |
| 3939 | mcdi_flags |= |
| 3940 | is_multicast_ether_addr(spec->loc_mac) ? |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 3941 | 1 << mc_match : |
| 3942 | 1 << uc_match; |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3943 | } |
| 3944 | |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3945 | /* Did we map them all? */ |
| 3946 | WARN_ON_ONCE(match_flags); |
| 3947 | |
| 3948 | return mcdi_flags; |
| 3949 | } |
| 3950 | |
| 3951 | static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table, |
| 3952 | const struct efx_filter_spec *spec) |
| 3953 | { |
| 3954 | u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3955 | unsigned int match_pri; |
| 3956 | |
| 3957 | for (match_pri = 0; |
| 3958 | match_pri < table->rx_match_count; |
| 3959 | match_pri++) |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3960 | if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3961 | return match_pri; |
| 3962 | |
| 3963 | return -EPROTONOSUPPORT; |
| 3964 | } |
| 3965 | |
| 3966 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, |
| 3967 | struct efx_filter_spec *spec, |
| 3968 | bool replace_equal) |
| 3969 | { |
| 3970 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3971 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 3972 | struct efx_filter_spec *saved_spec; |
| 3973 | unsigned int match_pri, hash; |
| 3974 | unsigned int priv_flags; |
| 3975 | bool replacing = false; |
| 3976 | int ins_index = -1; |
| 3977 | DEFINE_WAIT(wait); |
| 3978 | bool is_mc_recip; |
| 3979 | s32 rc; |
| 3980 | |
| 3981 | /* For now, only support RX filters */ |
| 3982 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != |
| 3983 | EFX_FILTER_FLAG_RX) |
| 3984 | return -EINVAL; |
| 3985 | |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 3986 | rc = efx_ef10_filter_pri(table, spec); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3987 | if (rc < 0) |
| 3988 | return rc; |
| 3989 | match_pri = rc; |
| 3990 | |
| 3991 | hash = efx_ef10_filter_hash(spec); |
| 3992 | is_mc_recip = efx_filter_is_mc_recipient(spec); |
| 3993 | if (is_mc_recip) |
| 3994 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 3995 | |
| 3996 | /* Find any existing filters with the same match tuple or |
| 3997 | * else a free slot to insert at. If any of them are busy, |
| 3998 | * we have to wait and retry. |
| 3999 | */ |
| 4000 | for (;;) { |
| 4001 | unsigned int depth = 1; |
| 4002 | unsigned int i; |
| 4003 | |
| 4004 | spin_lock_bh(&efx->filter_lock); |
| 4005 | |
| 4006 | for (;;) { |
| 4007 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 4008 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 4009 | |
| 4010 | if (!saved_spec) { |
| 4011 | if (ins_index < 0) |
| 4012 | ins_index = i; |
| 4013 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 4014 | if (table->entry[i].spec & |
| 4015 | EFX_EF10_FILTER_FLAG_BUSY) |
| 4016 | break; |
| 4017 | if (spec->priority < saved_spec->priority && |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4018 | spec->priority != EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4019 | rc = -EPERM; |
| 4020 | goto out_unlock; |
| 4021 | } |
| 4022 | if (!is_mc_recip) { |
| 4023 | /* This is the only one */ |
| 4024 | if (spec->priority == |
| 4025 | saved_spec->priority && |
| 4026 | !replace_equal) { |
| 4027 | rc = -EEXIST; |
| 4028 | goto out_unlock; |
| 4029 | } |
| 4030 | ins_index = i; |
| 4031 | goto found; |
| 4032 | } else if (spec->priority > |
| 4033 | saved_spec->priority || |
| 4034 | (spec->priority == |
| 4035 | saved_spec->priority && |
| 4036 | replace_equal)) { |
| 4037 | if (ins_index < 0) |
| 4038 | ins_index = i; |
| 4039 | else |
| 4040 | __set_bit(depth, mc_rem_map); |
| 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | /* Once we reach the maximum search depth, use |
| 4045 | * the first suitable slot or return -EBUSY if |
| 4046 | * there was none |
| 4047 | */ |
| 4048 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 4049 | if (ins_index < 0) { |
| 4050 | rc = -EBUSY; |
| 4051 | goto out_unlock; |
| 4052 | } |
| 4053 | goto found; |
| 4054 | } |
| 4055 | |
| 4056 | ++depth; |
| 4057 | } |
| 4058 | |
| 4059 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 4060 | spin_unlock_bh(&efx->filter_lock); |
| 4061 | schedule(); |
| 4062 | } |
| 4063 | |
| 4064 | found: |
| 4065 | /* Create a software table entry if necessary, and mark it |
| 4066 | * busy. We might yet fail to insert, but any attempt to |
| 4067 | * insert a conflicting filter while we're waiting for the |
| 4068 | * firmware must find the busy entry. |
| 4069 | */ |
| 4070 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 4071 | if (saved_spec) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4072 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
| 4073 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4074 | /* Just make sure it won't be removed */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4075 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
| 4076 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4077 | table->entry[ins_index].spec &= |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4078 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4079 | rc = ins_index; |
| 4080 | goto out_unlock; |
| 4081 | } |
| 4082 | replacing = true; |
| 4083 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); |
| 4084 | } else { |
| 4085 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 4086 | if (!saved_spec) { |
| 4087 | rc = -ENOMEM; |
| 4088 | goto out_unlock; |
| 4089 | } |
| 4090 | *saved_spec = *spec; |
| 4091 | priv_flags = 0; |
| 4092 | } |
| 4093 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 4094 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); |
| 4095 | |
| 4096 | /* Mark lower-priority multicast recipients busy prior to removal */ |
| 4097 | if (is_mc_recip) { |
| 4098 | unsigned int depth, i; |
| 4099 | |
| 4100 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 4101 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 4102 | if (test_bit(depth, mc_rem_map)) |
| 4103 | table->entry[i].spec |= |
| 4104 | EFX_EF10_FILTER_FLAG_BUSY; |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | spin_unlock_bh(&efx->filter_lock); |
| 4109 | |
| 4110 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, |
| 4111 | replacing); |
| 4112 | |
| 4113 | /* Finalise the software table entry */ |
| 4114 | spin_lock_bh(&efx->filter_lock); |
| 4115 | if (rc == 0) { |
| 4116 | if (replacing) { |
| 4117 | /* Update the fields that may differ */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4118 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
| 4119 | saved_spec->flags |= |
| 4120 | EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4121 | saved_spec->priority = spec->priority; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4122 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4123 | saved_spec->flags |= spec->flags; |
| 4124 | saved_spec->rss_context = spec->rss_context; |
| 4125 | saved_spec->dmaq_id = spec->dmaq_id; |
| 4126 | } |
| 4127 | } else if (!replacing) { |
| 4128 | kfree(saved_spec); |
| 4129 | saved_spec = NULL; |
| 4130 | } |
| 4131 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); |
| 4132 | |
| 4133 | /* Remove and finalise entries for lower-priority multicast |
| 4134 | * recipients |
| 4135 | */ |
| 4136 | if (is_mc_recip) { |
| 4137 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 4138 | unsigned int depth, i; |
| 4139 | |
| 4140 | memset(inbuf, 0, sizeof(inbuf)); |
| 4141 | |
| 4142 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 4143 | if (!test_bit(depth, mc_rem_map)) |
| 4144 | continue; |
| 4145 | |
| 4146 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 4147 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 4148 | priv_flags = efx_ef10_filter_entry_flags(table, i); |
| 4149 | |
| 4150 | if (rc == 0) { |
| 4151 | spin_unlock_bh(&efx->filter_lock); |
| 4152 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 4153 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 4154 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 4155 | table->entry[i].handle); |
| 4156 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 4157 | inbuf, sizeof(inbuf), |
| 4158 | NULL, 0, NULL); |
| 4159 | spin_lock_bh(&efx->filter_lock); |
| 4160 | } |
| 4161 | |
| 4162 | if (rc == 0) { |
| 4163 | kfree(saved_spec); |
| 4164 | saved_spec = NULL; |
| 4165 | priv_flags = 0; |
| 4166 | } else { |
| 4167 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 4168 | } |
| 4169 | efx_ef10_filter_set_entry(table, i, saved_spec, |
| 4170 | priv_flags); |
| 4171 | } |
| 4172 | } |
| 4173 | |
| 4174 | /* If successful, return the inserted filter ID */ |
| 4175 | if (rc == 0) |
| 4176 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; |
| 4177 | |
| 4178 | wake_up_all(&table->waitq); |
| 4179 | out_unlock: |
| 4180 | spin_unlock_bh(&efx->filter_lock); |
| 4181 | finish_wait(&table->waitq, &wait); |
| 4182 | return rc; |
| 4183 | } |
| 4184 | |
Fengguang Wu | 9fd8095d | 2013-08-31 06:54:05 +0800 | [diff] [blame] | 4185 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4186 | { |
| 4187 | /* no need to do anything here on EF10 */ |
| 4188 | } |
| 4189 | |
| 4190 | /* Remove a filter. |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4191 | * If !by_index, remove by ID |
| 4192 | * If by_index, remove by index |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4193 | * Filter ID may come from userland and must be range-checked. |
| 4194 | */ |
| 4195 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4196 | unsigned int priority_mask, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4197 | u32 filter_id, bool by_index) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4198 | { |
| 4199 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 4200 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4201 | MCDI_DECLARE_BUF(inbuf, |
| 4202 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 4203 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 4204 | struct efx_filter_spec *spec; |
| 4205 | DEFINE_WAIT(wait); |
| 4206 | int rc; |
| 4207 | |
| 4208 | /* Find the software table entry and mark it busy. Don't |
| 4209 | * remove it yet; any attempt to update while we're waiting |
| 4210 | * for the firmware must find the busy entry. |
| 4211 | */ |
| 4212 | for (;;) { |
| 4213 | spin_lock_bh(&efx->filter_lock); |
| 4214 | if (!(table->entry[filter_idx].spec & |
| 4215 | EFX_EF10_FILTER_FLAG_BUSY)) |
| 4216 | break; |
| 4217 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 4218 | spin_unlock_bh(&efx->filter_lock); |
| 4219 | schedule(); |
| 4220 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4221 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4222 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4223 | if (!spec || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4224 | (!by_index && |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4225 | efx_ef10_filter_pri(table, spec) != |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4226 | filter_id / HUNT_FILTER_TBL_ROWS)) { |
| 4227 | rc = -ENOENT; |
| 4228 | goto out_unlock; |
| 4229 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4230 | |
| 4231 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4232 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4233 | /* Just remove flags */ |
| 4234 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4235 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4236 | rc = 0; |
| 4237 | goto out_unlock; |
| 4238 | } |
| 4239 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4240 | if (!(priority_mask & (1U << spec->priority))) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4241 | rc = -ENOENT; |
| 4242 | goto out_unlock; |
| 4243 | } |
| 4244 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4245 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 4246 | spin_unlock_bh(&efx->filter_lock); |
| 4247 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4248 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 4249 | /* Reset to an automatic filter */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4250 | |
| 4251 | struct efx_filter_spec new_spec = *spec; |
| 4252 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4253 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4254 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 4255 | (efx_rss_enabled(efx) ? |
| 4256 | EFX_FILTER_FLAG_RX_RSS : 0)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4257 | new_spec.dmaq_id = 0; |
| 4258 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; |
| 4259 | rc = efx_ef10_filter_push(efx, &new_spec, |
| 4260 | &table->entry[filter_idx].handle, |
| 4261 | true); |
| 4262 | |
| 4263 | spin_lock_bh(&efx->filter_lock); |
| 4264 | if (rc == 0) |
| 4265 | *spec = new_spec; |
| 4266 | } else { |
| 4267 | /* Really remove the filter */ |
| 4268 | |
| 4269 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 4270 | efx_ef10_filter_is_exclusive(spec) ? |
| 4271 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 4272 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 4273 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 4274 | table->entry[filter_idx].handle); |
| 4275 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 4276 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 4277 | |
| 4278 | spin_lock_bh(&efx->filter_lock); |
| 4279 | if (rc == 0) { |
| 4280 | kfree(spec); |
| 4281 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 4282 | } |
| 4283 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 4284 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4285 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 4286 | wake_up_all(&table->waitq); |
| 4287 | out_unlock: |
| 4288 | spin_unlock_bh(&efx->filter_lock); |
| 4289 | finish_wait(&table->waitq, &wait); |
| 4290 | return rc; |
| 4291 | } |
| 4292 | |
| 4293 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, |
| 4294 | enum efx_filter_priority priority, |
| 4295 | u32 filter_id) |
| 4296 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4297 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
| 4298 | filter_id, false); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4299 | } |
| 4300 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4301 | static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id) |
| 4302 | { |
| 4303 | return filter_id % HUNT_FILTER_TBL_ROWS; |
| 4304 | } |
| 4305 | |
Edward Cree | 8c91562 | 2016-06-15 17:49:05 +0100 | [diff] [blame] | 4306 | static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx, |
| 4307 | enum efx_filter_priority priority, |
| 4308 | u32 filter_id) |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4309 | { |
Edward Cree | 8c91562 | 2016-06-15 17:49:05 +0100 | [diff] [blame] | 4310 | if (filter_id == EFX_EF10_FILTER_ID_INVALID) |
| 4311 | return; |
| 4312 | efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4313 | } |
| 4314 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4315 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, |
| 4316 | enum efx_filter_priority priority, |
| 4317 | u32 filter_id, struct efx_filter_spec *spec) |
| 4318 | { |
| 4319 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 4320 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4321 | const struct efx_filter_spec *saved_spec; |
| 4322 | int rc; |
| 4323 | |
| 4324 | spin_lock_bh(&efx->filter_lock); |
| 4325 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 4326 | if (saved_spec && saved_spec->priority == priority && |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4327 | efx_ef10_filter_pri(table, saved_spec) == |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4328 | filter_id / HUNT_FILTER_TBL_ROWS) { |
| 4329 | *spec = *saved_spec; |
| 4330 | rc = 0; |
| 4331 | } else { |
| 4332 | rc = -ENOENT; |
| 4333 | } |
| 4334 | spin_unlock_bh(&efx->filter_lock); |
| 4335 | return rc; |
| 4336 | } |
| 4337 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4338 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4339 | enum efx_filter_priority priority) |
| 4340 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 4341 | unsigned int priority_mask; |
| 4342 | unsigned int i; |
| 4343 | int rc; |
| 4344 | |
| 4345 | priority_mask = (((1U << (priority + 1)) - 1) & |
| 4346 | ~(1U << EFX_FILTER_PRI_AUTO)); |
| 4347 | |
| 4348 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 4349 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, |
| 4350 | i, true); |
| 4351 | if (rc && rc != -ENOENT) |
| 4352 | return rc; |
| 4353 | } |
| 4354 | |
| 4355 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, |
| 4359 | enum efx_filter_priority priority) |
| 4360 | { |
| 4361 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4362 | unsigned int filter_idx; |
| 4363 | s32 count = 0; |
| 4364 | |
| 4365 | spin_lock_bh(&efx->filter_lock); |
| 4366 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 4367 | if (table->entry[filter_idx].spec && |
| 4368 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == |
| 4369 | priority) |
| 4370 | ++count; |
| 4371 | } |
| 4372 | spin_unlock_bh(&efx->filter_lock); |
| 4373 | return count; |
| 4374 | } |
| 4375 | |
| 4376 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) |
| 4377 | { |
| 4378 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4379 | |
| 4380 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; |
| 4381 | } |
| 4382 | |
| 4383 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, |
| 4384 | enum efx_filter_priority priority, |
| 4385 | u32 *buf, u32 size) |
| 4386 | { |
| 4387 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4388 | struct efx_filter_spec *spec; |
| 4389 | unsigned int filter_idx; |
| 4390 | s32 count = 0; |
| 4391 | |
| 4392 | spin_lock_bh(&efx->filter_lock); |
| 4393 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 4394 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 4395 | if (spec && spec->priority == priority) { |
| 4396 | if (count == size) { |
| 4397 | count = -EMSGSIZE; |
| 4398 | break; |
| 4399 | } |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4400 | buf[count++] = (efx_ef10_filter_pri(table, spec) * |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4401 | HUNT_FILTER_TBL_ROWS + |
| 4402 | filter_idx); |
| 4403 | } |
| 4404 | } |
| 4405 | spin_unlock_bh(&efx->filter_lock); |
| 4406 | return count; |
| 4407 | } |
| 4408 | |
| 4409 | #ifdef CONFIG_RFS_ACCEL |
| 4410 | |
| 4411 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; |
| 4412 | |
| 4413 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, |
| 4414 | struct efx_filter_spec *spec) |
| 4415 | { |
| 4416 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4417 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 4418 | struct efx_filter_spec *saved_spec; |
| 4419 | unsigned int hash, i, depth = 1; |
| 4420 | bool replacing = false; |
| 4421 | int ins_index = -1; |
| 4422 | u64 cookie; |
| 4423 | s32 rc; |
| 4424 | |
| 4425 | /* Must be an RX filter without RSS and not for a multicast |
| 4426 | * destination address (RFS only works for connected sockets). |
| 4427 | * These restrictions allow us to pass only a tiny amount of |
| 4428 | * data through to the completion function. |
| 4429 | */ |
| 4430 | EFX_WARN_ON_PARANOID(spec->flags != |
| 4431 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); |
| 4432 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); |
| 4433 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); |
| 4434 | |
| 4435 | hash = efx_ef10_filter_hash(spec); |
| 4436 | |
| 4437 | spin_lock_bh(&efx->filter_lock); |
| 4438 | |
| 4439 | /* Find any existing filter with the same match tuple or else |
| 4440 | * a free slot to insert at. If an existing filter is busy, |
| 4441 | * we have to give up. |
| 4442 | */ |
| 4443 | for (;;) { |
| 4444 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 4445 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 4446 | |
| 4447 | if (!saved_spec) { |
| 4448 | if (ins_index < 0) |
| 4449 | ins_index = i; |
| 4450 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 4451 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { |
| 4452 | rc = -EBUSY; |
| 4453 | goto fail_unlock; |
| 4454 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4455 | if (spec->priority < saved_spec->priority) { |
| 4456 | rc = -EPERM; |
| 4457 | goto fail_unlock; |
| 4458 | } |
| 4459 | ins_index = i; |
| 4460 | break; |
| 4461 | } |
| 4462 | |
| 4463 | /* Once we reach the maximum search depth, use the |
| 4464 | * first suitable slot or return -EBUSY if there was |
| 4465 | * none |
| 4466 | */ |
| 4467 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 4468 | if (ins_index < 0) { |
| 4469 | rc = -EBUSY; |
| 4470 | goto fail_unlock; |
| 4471 | } |
| 4472 | break; |
| 4473 | } |
| 4474 | |
| 4475 | ++depth; |
| 4476 | } |
| 4477 | |
| 4478 | /* Create a software table entry if necessary, and mark it |
| 4479 | * busy. We might yet fail to insert, but any attempt to |
| 4480 | * insert a conflicting filter while we're waiting for the |
| 4481 | * firmware must find the busy entry. |
| 4482 | */ |
| 4483 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 4484 | if (saved_spec) { |
| 4485 | replacing = true; |
| 4486 | } else { |
| 4487 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 4488 | if (!saved_spec) { |
| 4489 | rc = -ENOMEM; |
| 4490 | goto fail_unlock; |
| 4491 | } |
| 4492 | *saved_spec = *spec; |
| 4493 | } |
| 4494 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 4495 | EFX_EF10_FILTER_FLAG_BUSY); |
| 4496 | |
| 4497 | spin_unlock_bh(&efx->filter_lock); |
| 4498 | |
| 4499 | /* Pack up the variables needed on completion */ |
| 4500 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; |
| 4501 | |
| 4502 | efx_ef10_filter_push_prep(efx, spec, inbuf, |
| 4503 | table->entry[ins_index].handle, replacing); |
| 4504 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 4505 | MC_CMD_FILTER_OP_OUT_LEN, |
| 4506 | efx_ef10_filter_rfs_insert_complete, cookie); |
| 4507 | |
| 4508 | return ins_index; |
| 4509 | |
| 4510 | fail_unlock: |
| 4511 | spin_unlock_bh(&efx->filter_lock); |
| 4512 | return rc; |
| 4513 | } |
| 4514 | |
| 4515 | static void |
| 4516 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, |
| 4517 | int rc, efx_dword_t *outbuf, |
| 4518 | size_t outlen_actual) |
| 4519 | { |
| 4520 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4521 | unsigned int ins_index, dmaq_id; |
| 4522 | struct efx_filter_spec *spec; |
| 4523 | bool replacing; |
| 4524 | |
| 4525 | /* Unpack the cookie */ |
| 4526 | replacing = cookie >> 31; |
| 4527 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); |
| 4528 | dmaq_id = cookie & 0xffff; |
| 4529 | |
| 4530 | spin_lock_bh(&efx->filter_lock); |
| 4531 | spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 4532 | if (rc == 0) { |
| 4533 | table->entry[ins_index].handle = |
| 4534 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
| 4535 | if (replacing) |
| 4536 | spec->dmaq_id = dmaq_id; |
| 4537 | } else if (!replacing) { |
| 4538 | kfree(spec); |
| 4539 | spec = NULL; |
| 4540 | } |
| 4541 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); |
| 4542 | spin_unlock_bh(&efx->filter_lock); |
| 4543 | |
| 4544 | wake_up_all(&table->waitq); |
| 4545 | } |
| 4546 | |
| 4547 | static void |
| 4548 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 4549 | unsigned long filter_idx, |
| 4550 | int rc, efx_dword_t *outbuf, |
| 4551 | size_t outlen_actual); |
| 4552 | |
| 4553 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, |
| 4554 | unsigned int filter_idx) |
| 4555 | { |
| 4556 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4557 | struct efx_filter_spec *spec = |
| 4558 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 4559 | MCDI_DECLARE_BUF(inbuf, |
| 4560 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 4561 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 4562 | |
| 4563 | if (!spec || |
| 4564 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || |
| 4565 | spec->priority != EFX_FILTER_PRI_HINT || |
| 4566 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, |
| 4567 | flow_id, filter_idx)) |
| 4568 | return false; |
| 4569 | |
| 4570 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 4571 | MC_CMD_FILTER_OP_IN_OP_REMOVE); |
| 4572 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 4573 | table->entry[filter_idx].handle); |
| 4574 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, |
| 4575 | efx_ef10_filter_rfs_expire_complete, filter_idx)) |
| 4576 | return false; |
| 4577 | |
| 4578 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 4579 | return true; |
| 4580 | } |
| 4581 | |
| 4582 | static void |
| 4583 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 4584 | unsigned long filter_idx, |
| 4585 | int rc, efx_dword_t *outbuf, |
| 4586 | size_t outlen_actual) |
| 4587 | { |
| 4588 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4589 | struct efx_filter_spec *spec = |
| 4590 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 4591 | |
| 4592 | spin_lock_bh(&efx->filter_lock); |
| 4593 | if (rc == 0) { |
| 4594 | kfree(spec); |
| 4595 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 4596 | } |
| 4597 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 4598 | wake_up_all(&table->waitq); |
| 4599 | spin_unlock_bh(&efx->filter_lock); |
| 4600 | } |
| 4601 | |
| 4602 | #endif /* CONFIG_RFS_ACCEL */ |
| 4603 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4604 | static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4605 | { |
| 4606 | int match_flags = 0; |
| 4607 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4608 | #define MAP_FLAG(gen_flag, mcdi_field) do { \ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4609 | u32 old_mcdi_flags = mcdi_flags; \ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4610 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \ |
| 4611 | mcdi_field ## _LBN); \ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4612 | if (mcdi_flags != old_mcdi_flags) \ |
| 4613 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4614 | } while (0) |
| 4615 | |
| 4616 | if (encap) { |
| 4617 | /* encap filters must specify encap type */ |
| 4618 | match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE; |
| 4619 | /* and imply ethertype and ip proto */ |
| 4620 | mcdi_flags &= |
| 4621 | ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN); |
| 4622 | mcdi_flags &= |
| 4623 | ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN); |
| 4624 | /* VLAN tags refer to the outer packet */ |
| 4625 | MAP_FLAG(INNER_VID, INNER_VLAN); |
| 4626 | MAP_FLAG(OUTER_VID, OUTER_VLAN); |
| 4627 | /* everything else refers to the inner packet */ |
| 4628 | MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST); |
| 4629 | MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST); |
| 4630 | MAP_FLAG(REM_HOST, IFRM_SRC_IP); |
| 4631 | MAP_FLAG(LOC_HOST, IFRM_DST_IP); |
| 4632 | MAP_FLAG(REM_MAC, IFRM_SRC_MAC); |
| 4633 | MAP_FLAG(REM_PORT, IFRM_SRC_PORT); |
| 4634 | MAP_FLAG(LOC_MAC, IFRM_DST_MAC); |
| 4635 | MAP_FLAG(LOC_PORT, IFRM_DST_PORT); |
| 4636 | MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE); |
| 4637 | MAP_FLAG(IP_PROTO, IFRM_IP_PROTO); |
| 4638 | } else { |
| 4639 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); |
| 4640 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); |
| 4641 | MAP_FLAG(REM_HOST, SRC_IP); |
| 4642 | MAP_FLAG(LOC_HOST, DST_IP); |
| 4643 | MAP_FLAG(REM_MAC, SRC_MAC); |
| 4644 | MAP_FLAG(REM_PORT, SRC_PORT); |
| 4645 | MAP_FLAG(LOC_MAC, DST_MAC); |
| 4646 | MAP_FLAG(LOC_PORT, DST_PORT); |
| 4647 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); |
| 4648 | MAP_FLAG(INNER_VID, INNER_VLAN); |
| 4649 | MAP_FLAG(OUTER_VID, OUTER_VLAN); |
| 4650 | MAP_FLAG(IP_PROTO, IP_PROTO); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4651 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4652 | #undef MAP_FLAG |
| 4653 | |
| 4654 | /* Did we map them all? */ |
| 4655 | if (mcdi_flags) |
| 4656 | return -EINVAL; |
| 4657 | |
| 4658 | return match_flags; |
| 4659 | } |
| 4660 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4661 | static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx) |
| 4662 | { |
| 4663 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4664 | struct efx_ef10_filter_vlan *vlan, *next_vlan; |
| 4665 | |
| 4666 | /* See comment in efx_ef10_filter_table_remove() */ |
| 4667 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 4668 | return; |
| 4669 | |
| 4670 | if (!table) |
| 4671 | return; |
| 4672 | |
| 4673 | list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list) |
| 4674 | efx_ef10_filter_del_vlan_internal(efx, vlan); |
| 4675 | } |
| 4676 | |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4677 | static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table, |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4678 | bool encap, |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4679 | enum efx_filter_match_flags match_flags) |
| 4680 | { |
| 4681 | unsigned int match_pri; |
| 4682 | int mf; |
| 4683 | |
| 4684 | for (match_pri = 0; |
| 4685 | match_pri < table->rx_match_count; |
| 4686 | match_pri++) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4687 | mf = efx_ef10_filter_match_flags_from_mcdi(encap, |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4688 | table->rx_match_mcdi_flags[match_pri]); |
| 4689 | if (mf == match_flags) |
| 4690 | return true; |
| 4691 | } |
| 4692 | |
| 4693 | return false; |
| 4694 | } |
| 4695 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4696 | static int |
| 4697 | efx_ef10_filter_table_probe_matches(struct efx_nic *efx, |
| 4698 | struct efx_ef10_filter_table *table, |
| 4699 | bool encap) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4700 | { |
| 4701 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); |
| 4702 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); |
| 4703 | unsigned int pd_match_pri, pd_match_count; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4704 | size_t outlen; |
| 4705 | int rc; |
| 4706 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4707 | /* Find out which RX filter types are supported, and their priorities */ |
| 4708 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4709 | encap ? |
| 4710 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES : |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4711 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); |
| 4712 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, |
| 4713 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), |
| 4714 | &outlen); |
| 4715 | if (rc) |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4716 | return rc; |
| 4717 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4718 | pd_match_count = MCDI_VAR_ARRAY_LEN( |
| 4719 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4720 | |
| 4721 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { |
| 4722 | u32 mcdi_flags = |
| 4723 | MCDI_ARRAY_DWORD( |
| 4724 | outbuf, |
| 4725 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, |
| 4726 | pd_match_pri); |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4727 | rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4728 | if (rc < 0) { |
| 4729 | netif_dbg(efx, probe, efx->net_dev, |
| 4730 | "%s: fw flags %#x pri %u not supported in driver\n", |
| 4731 | __func__, mcdi_flags, pd_match_pri); |
| 4732 | } else { |
| 4733 | netif_dbg(efx, probe, efx->net_dev, |
| 4734 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", |
| 4735 | __func__, mcdi_flags, pd_match_pri, |
| 4736 | rc, table->rx_match_count); |
Andrew Rybchenko | 7ac0dd9 | 2016-06-15 17:49:30 +0100 | [diff] [blame] | 4737 | table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags; |
| 4738 | table->rx_match_count++; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4739 | } |
| 4740 | } |
| 4741 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4742 | return 0; |
| 4743 | } |
| 4744 | |
| 4745 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) |
| 4746 | { |
| 4747 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 4748 | struct net_device *net_dev = efx->net_dev; |
| 4749 | struct efx_ef10_filter_table *table; |
| 4750 | struct efx_ef10_vlan *vlan; |
| 4751 | int rc; |
| 4752 | |
| 4753 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 4754 | return -EINVAL; |
| 4755 | |
| 4756 | if (efx->filter_state) /* already probed */ |
| 4757 | return 0; |
| 4758 | |
| 4759 | table = kzalloc(sizeof(*table), GFP_KERNEL); |
| 4760 | if (!table) |
| 4761 | return -ENOMEM; |
| 4762 | |
| 4763 | table->rx_match_count = 0; |
| 4764 | rc = efx_ef10_filter_table_probe_matches(efx, table, false); |
| 4765 | if (rc) |
| 4766 | goto fail; |
| 4767 | if (nic_data->datapath_caps & |
| 4768 | (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)) |
| 4769 | rc = efx_ef10_filter_table_probe_matches(efx, table, true); |
| 4770 | if (rc) |
| 4771 | goto fail; |
Martin Habets | e4478ad | 2016-06-15 17:51:07 +0100 | [diff] [blame] | 4772 | if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) && |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4773 | !(efx_ef10_filter_match_supported(table, false, |
Martin Habets | e4478ad | 2016-06-15 17:51:07 +0100 | [diff] [blame] | 4774 | (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) && |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4775 | efx_ef10_filter_match_supported(table, false, |
Martin Habets | e4478ad | 2016-06-15 17:51:07 +0100 | [diff] [blame] | 4776 | (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) { |
| 4777 | netif_info(efx, probe, net_dev, |
| 4778 | "VLAN filters are not supported in this firmware variant\n"); |
| 4779 | net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 4780 | efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 4781 | net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 4782 | } |
| 4783 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4784 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); |
| 4785 | if (!table->entry) { |
| 4786 | rc = -ENOMEM; |
| 4787 | goto fail; |
| 4788 | } |
| 4789 | |
Andrew Rybchenko | b071c3a | 2016-06-15 17:43:00 +0100 | [diff] [blame] | 4790 | table->mc_promisc_last = false; |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 4791 | table->vlan_filter = |
| 4792 | !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4793 | INIT_LIST_HEAD(&table->vlan_list); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4794 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4795 | efx->filter_state = table; |
| 4796 | init_waitqueue_head(&table->waitq); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4797 | |
| 4798 | list_for_each_entry(vlan, &nic_data->vlan_list, list) { |
| 4799 | rc = efx_ef10_filter_add_vlan(efx, vlan->vid); |
| 4800 | if (rc) |
| 4801 | goto fail_add_vlan; |
| 4802 | } |
| 4803 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4804 | return 0; |
| 4805 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4806 | fail_add_vlan: |
| 4807 | efx_ef10_filter_cleanup_vlans(efx); |
| 4808 | efx->filter_state = NULL; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4809 | fail: |
| 4810 | kfree(table); |
| 4811 | return rc; |
| 4812 | } |
| 4813 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 4814 | /* Caller must hold efx->filter_sem for read if race against |
| 4815 | * efx_ef10_filter_table_remove() is possible |
| 4816 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4817 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) |
| 4818 | { |
| 4819 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4820 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4821 | unsigned int invalid_filters = 0, failed = 0; |
| 4822 | struct efx_ef10_filter_vlan *vlan; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4823 | struct efx_filter_spec *spec; |
| 4824 | unsigned int filter_idx; |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4825 | u32 mcdi_flags; |
| 4826 | int match_pri; |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4827 | int rc, i; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4828 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 4829 | WARN_ON(!rwsem_is_locked(&efx->filter_sem)); |
| 4830 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4831 | if (!nic_data->must_restore_filters) |
| 4832 | return; |
| 4833 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 4834 | if (!table) |
| 4835 | return; |
| 4836 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4837 | spin_lock_bh(&efx->filter_lock); |
| 4838 | |
| 4839 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 4840 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 4841 | if (!spec) |
| 4842 | continue; |
| 4843 | |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4844 | mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec); |
| 4845 | match_pri = 0; |
| 4846 | while (match_pri < table->rx_match_count && |
| 4847 | table->rx_match_mcdi_flags[match_pri] != mcdi_flags) |
| 4848 | ++match_pri; |
| 4849 | if (match_pri >= table->rx_match_count) { |
| 4850 | invalid_filters++; |
| 4851 | goto not_restored; |
| 4852 | } |
| 4853 | if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT && |
| 4854 | spec->rss_context != nic_data->rx_rss_context) |
| 4855 | netif_warn(efx, drv, efx->net_dev, |
| 4856 | "Warning: unable to restore a filter with specific RSS context.\n"); |
| 4857 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4858 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 4859 | spin_unlock_bh(&efx->filter_lock); |
| 4860 | |
| 4861 | rc = efx_ef10_filter_push(efx, spec, |
| 4862 | &table->entry[filter_idx].handle, |
| 4863 | false); |
| 4864 | if (rc) |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4865 | failed++; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4866 | spin_lock_bh(&efx->filter_lock); |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4867 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4868 | if (rc) { |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4869 | not_restored: |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4870 | list_for_each_entry(vlan, &table->vlan_list, list) |
| 4871 | for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i) |
| 4872 | if (vlan->default_filters[i] == filter_idx) |
| 4873 | vlan->default_filters[i] = |
| 4874 | EFX_EF10_FILTER_ID_INVALID; |
| 4875 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4876 | kfree(spec); |
| 4877 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 4878 | } else { |
| 4879 | table->entry[filter_idx].spec &= |
| 4880 | ~EFX_EF10_FILTER_FLAG_BUSY; |
| 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | spin_unlock_bh(&efx->filter_lock); |
| 4885 | |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4886 | /* This can happen validly if the MC's capabilities have changed, so |
| 4887 | * is not an error. |
| 4888 | */ |
| 4889 | if (invalid_filters) |
| 4890 | netif_dbg(efx, drv, efx->net_dev, |
| 4891 | "Did not restore %u filters that are now unsupported.\n", |
| 4892 | invalid_filters); |
| 4893 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4894 | if (failed) |
| 4895 | netif_err(efx, hw, efx->net_dev, |
Jon Cooper | 2d3d4ec | 2017-01-27 15:02:11 +0000 | [diff] [blame] | 4896 | "unable to restore %u filters\n", failed); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4897 | else |
| 4898 | nic_data->must_restore_filters = false; |
| 4899 | } |
| 4900 | |
| 4901 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) |
| 4902 | { |
| 4903 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4904 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 4905 | struct efx_filter_spec *spec; |
| 4906 | unsigned int filter_idx; |
| 4907 | int rc; |
| 4908 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4909 | efx_ef10_filter_cleanup_vlans(efx); |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 4910 | efx->filter_state = NULL; |
Edward Cree | dd98708 | 2016-06-15 17:43:43 +0100 | [diff] [blame] | 4911 | /* If we were called without locking, then it's not safe to free |
| 4912 | * the table as others might be using it. So we just WARN, leak |
| 4913 | * the memory, and potentially get an inconsistent filter table |
| 4914 | * state. |
| 4915 | * This should never actually happen. |
| 4916 | */ |
| 4917 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 4918 | return; |
| 4919 | |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 4920 | if (!table) |
| 4921 | return; |
| 4922 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4923 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 4924 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 4925 | if (!spec) |
| 4926 | continue; |
| 4927 | |
| 4928 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 4929 | efx_ef10_filter_is_exclusive(spec) ? |
| 4930 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 4931 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 4932 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 4933 | table->entry[filter_idx].handle); |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 4934 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf, |
| 4935 | sizeof(inbuf), NULL, 0, NULL); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 4936 | if (rc) |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 4937 | netif_info(efx, drv, efx->net_dev, |
| 4938 | "%s: filter %04x remove failed\n", |
| 4939 | __func__, filter_idx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4940 | kfree(spec); |
| 4941 | } |
| 4942 | |
| 4943 | vfree(table->entry); |
| 4944 | kfree(table); |
| 4945 | } |
| 4946 | |
Andrew Rybchenko | 6a37958 | 2016-06-15 17:44:20 +0100 | [diff] [blame] | 4947 | static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id) |
| 4948 | { |
| 4949 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4950 | unsigned int filter_idx; |
| 4951 | |
| 4952 | if (*id != EFX_EF10_FILTER_ID_INVALID) { |
| 4953 | filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id); |
| 4954 | if (!table->entry[filter_idx].spec) |
| 4955 | netif_dbg(efx, drv, efx->net_dev, |
| 4956 | "marked null spec old %04x:%04x\n", *id, |
| 4957 | filter_idx); |
| 4958 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; |
| 4959 | *id = EFX_EF10_FILTER_ID_INVALID; |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 4960 | } |
Andrew Rybchenko | 6a37958 | 2016-06-15 17:44:20 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 4963 | /* Mark old per-VLAN filters that may need to be removed */ |
| 4964 | static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx, |
| 4965 | struct efx_ef10_filter_vlan *vlan) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4966 | { |
| 4967 | struct efx_ef10_filter_table *table = efx->filter_state; |
Andrew Rybchenko | 6a37958 | 2016-06-15 17:44:20 +0100 | [diff] [blame] | 4968 | unsigned int i; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4969 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4970 | for (i = 0; i < table->dev_uc_count; i++) |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 4971 | efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4972 | for (i = 0; i < table->dev_mc_count; i++) |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 4973 | efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]); |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 4974 | for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++) |
| 4975 | efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 4976 | } |
| 4977 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4978 | /* Mark old filters that may need to be removed. |
| 4979 | * Caller must hold efx->filter_sem for read if race against |
| 4980 | * efx_ef10_filter_table_remove() is possible |
| 4981 | */ |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 4982 | static void efx_ef10_filter_mark_old(struct efx_nic *efx) |
| 4983 | { |
| 4984 | struct efx_ef10_filter_table *table = efx->filter_state; |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4985 | struct efx_ef10_filter_vlan *vlan; |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 4986 | |
| 4987 | spin_lock_bh(&efx->filter_lock); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 4988 | list_for_each_entry(vlan, &table->vlan_list, list) |
| 4989 | _efx_ef10_filter_vlan_mark_old(efx, vlan); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4990 | spin_unlock_bh(&efx->filter_lock); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 4991 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 4992 | |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 4993 | static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx) |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 4994 | { |
| 4995 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 4996 | struct net_device *net_dev = efx->net_dev; |
| 4997 | struct netdev_hw_addr *uc; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 4998 | int addr_count; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 4999 | unsigned int i; |
| 5000 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5001 | addr_count = netdev_uc_count(net_dev); |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5002 | table->uc_promisc = !!(net_dev->flags & IFF_PROMISC); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5003 | table->dev_uc_count = 1 + addr_count; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5004 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
| 5005 | i = 1; |
| 5006 | netdev_for_each_uc_addr(uc, net_dev) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5007 | if (i >= EFX_EF10_FILTER_DEV_UC_MAX) { |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5008 | table->uc_promisc = true; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5009 | break; |
| 5010 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5011 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
| 5012 | i++; |
| 5013 | } |
| 5014 | } |
| 5015 | |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5016 | static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx) |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5017 | { |
| 5018 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 5019 | struct net_device *net_dev = efx->net_dev; |
| 5020 | struct netdev_hw_addr *mc; |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5021 | unsigned int i, addr_count; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5022 | |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5023 | table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI)); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5024 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5025 | addr_count = netdev_mc_count(net_dev); |
| 5026 | i = 0; |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5027 | netdev_for_each_mc_addr(mc, net_dev) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5028 | if (i >= EFX_EF10_FILTER_DEV_MC_MAX) { |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5029 | table->mc_promisc = true; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5030 | break; |
| 5031 | } |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5032 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
| 5033 | i++; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5034 | } |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5035 | |
| 5036 | table->dev_mc_count = i; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5037 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5038 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5039 | static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx, |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5040 | struct efx_ef10_filter_vlan *vlan, |
| 5041 | bool multicast, bool rollback) |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5042 | { |
| 5043 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 5044 | struct efx_ef10_dev_addr *addr_list; |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5045 | enum efx_filter_flags filter_flags; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5046 | struct efx_filter_spec spec; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5047 | u8 baddr[ETH_ALEN]; |
| 5048 | unsigned int i, j; |
| 5049 | int addr_count; |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5050 | u16 *ids; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5051 | int rc; |
| 5052 | |
| 5053 | if (multicast) { |
| 5054 | addr_list = table->dev_mc_list; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5055 | addr_count = table->dev_mc_count; |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5056 | ids = vlan->mc; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5057 | } else { |
| 5058 | addr_list = table->dev_uc_list; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5059 | addr_count = table->dev_uc_count; |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5060 | ids = vlan->uc; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5061 | } |
| 5062 | |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5063 | filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0; |
| 5064 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5065 | /* Insert/renew filters */ |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5066 | for (i = 0; i < addr_count; i++) { |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5067 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5068 | efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr); |
Jon Cooper | b6f568e | 2015-07-21 15:10:15 +0100 | [diff] [blame] | 5069 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 5070 | if (rc < 0) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5071 | if (rollback) { |
| 5072 | netif_info(efx, drv, efx->net_dev, |
| 5073 | "efx_ef10_filter_insert failed rc=%d\n", |
| 5074 | rc); |
| 5075 | /* Fall back to promiscuous */ |
| 5076 | for (j = 0; j < i; j++) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5077 | efx_ef10_filter_remove_unsafe( |
| 5078 | efx, EFX_FILTER_PRI_AUTO, |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5079 | ids[j]); |
| 5080 | ids[j] = EFX_EF10_FILTER_ID_INVALID; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5081 | } |
| 5082 | return rc; |
| 5083 | } else { |
| 5084 | /* mark as not inserted, and carry on */ |
| 5085 | rc = EFX_EF10_FILTER_ID_INVALID; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5086 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5087 | } |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5088 | ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5089 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5090 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5091 | if (multicast && rollback) { |
| 5092 | /* Also need an Ethernet broadcast filter */ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5093 | EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] != |
| 5094 | EFX_EF10_FILTER_ID_INVALID); |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5095 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5096 | eth_broadcast_addr(baddr); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5097 | efx_filter_set_eth_local(&spec, vlan->vid, baddr); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5098 | rc = efx_ef10_filter_insert(efx, &spec, true); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5099 | if (rc < 0) { |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5100 | netif_warn(efx, drv, efx->net_dev, |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5101 | "Broadcast filter insert failed rc=%d\n", rc); |
| 5102 | /* Fall back to promiscuous */ |
| 5103 | for (j = 0; j < i; j++) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5104 | efx_ef10_filter_remove_unsafe( |
| 5105 | efx, EFX_FILTER_PRI_AUTO, |
Andrew Rybchenko | dc3273e | 2016-06-15 17:45:36 +0100 | [diff] [blame] | 5106 | ids[j]); |
| 5107 | ids[j] = EFX_EF10_FILTER_ID_INVALID; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5108 | } |
| 5109 | return rc; |
| 5110 | } else { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5111 | vlan->default_filters[EFX_EF10_BCAST] = |
| 5112 | efx_ef10_filter_get_unsafe_id(efx, rc); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5113 | } |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5114 | } |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5115 | |
| 5116 | return 0; |
| 5117 | } |
| 5118 | |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5119 | static int efx_ef10_filter_insert_def(struct efx_nic *efx, |
| 5120 | struct efx_ef10_filter_vlan *vlan, |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5121 | enum efx_encap_type encap_type, |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5122 | bool multicast, bool rollback) |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5123 | { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5124 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5125 | enum efx_filter_flags filter_flags; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5126 | struct efx_filter_spec spec; |
| 5127 | u8 baddr[ETH_ALEN]; |
| 5128 | int rc; |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5129 | u16 *id; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5130 | |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5131 | filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0; |
| 5132 | |
| 5133 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5134 | |
| 5135 | if (multicast) |
| 5136 | efx_filter_set_mc_def(&spec); |
| 5137 | else |
| 5138 | efx_filter_set_uc_def(&spec); |
| 5139 | |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5140 | if (encap_type) { |
| 5141 | if (nic_data->datapath_caps & |
| 5142 | (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)) |
| 5143 | efx_filter_set_encap_type(&spec, encap_type); |
| 5144 | else |
| 5145 | /* don't insert encap filters on non-supporting |
| 5146 | * platforms. ID will be left as INVALID. |
| 5147 | */ |
| 5148 | return 0; |
| 5149 | } |
| 5150 | |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5151 | if (vlan->vid != EFX_FILTER_VID_UNSPEC) |
| 5152 | efx_filter_set_eth_local(&spec, vlan->vid, NULL); |
| 5153 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5154 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 5155 | if (rc < 0) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5156 | const char *um = multicast ? "Multicast" : "Unicast"; |
| 5157 | const char *encap_name = ""; |
| 5158 | const char *encap_ipv = ""; |
| 5159 | |
| 5160 | if ((encap_type & EFX_ENCAP_TYPES_MASK) == |
| 5161 | EFX_ENCAP_TYPE_VXLAN) |
| 5162 | encap_name = "VXLAN "; |
| 5163 | else if ((encap_type & EFX_ENCAP_TYPES_MASK) == |
| 5164 | EFX_ENCAP_TYPE_NVGRE) |
| 5165 | encap_name = "NVGRE "; |
| 5166 | else if ((encap_type & EFX_ENCAP_TYPES_MASK) == |
| 5167 | EFX_ENCAP_TYPE_GENEVE) |
| 5168 | encap_name = "GENEVE "; |
| 5169 | if (encap_type & EFX_ENCAP_FLAG_IPV6) |
| 5170 | encap_ipv = "IPv6 "; |
| 5171 | else if (encap_type) |
| 5172 | encap_ipv = "IPv4 "; |
| 5173 | |
| 5174 | /* unprivileged functions can't insert mismatch filters |
| 5175 | * for encapsulated or unicast traffic, so downgrade |
| 5176 | * those warnings to debug. |
| 5177 | */ |
Jon Cooper | 34e7aef | 2017-01-27 15:02:39 +0000 | [diff] [blame] | 5178 | netif_cond_dbg(efx, drv, efx->net_dev, |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5179 | rc == -EPERM && (encap_type || !multicast), warn, |
| 5180 | "%s%s%s mismatch filter insert failed rc=%d\n", |
| 5181 | encap_name, encap_ipv, um, rc); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5182 | } else if (multicast) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5183 | /* mapping from encap types to default filter IDs (multicast) */ |
| 5184 | static enum efx_ef10_default_filters map[] = { |
| 5185 | [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF, |
| 5186 | [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF, |
| 5187 | [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF, |
| 5188 | [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF, |
| 5189 | [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] = |
| 5190 | EFX_EF10_VXLAN6_MCDEF, |
| 5191 | [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] = |
| 5192 | EFX_EF10_NVGRE6_MCDEF, |
| 5193 | [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] = |
| 5194 | EFX_EF10_GENEVE6_MCDEF, |
| 5195 | }; |
| 5196 | |
| 5197 | /* quick bounds check (BCAST result impossible) */ |
| 5198 | BUILD_BUG_ON(EFX_EF10_BCAST != 0); |
Colin Ian King | e990499 | 2017-01-31 16:30:02 +0000 | [diff] [blame] | 5199 | if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5200 | WARN_ON(1); |
| 5201 | return -EINVAL; |
| 5202 | } |
| 5203 | /* then follow map */ |
| 5204 | id = &vlan->default_filters[map[encap_type]]; |
| 5205 | |
| 5206 | EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID); |
| 5207 | *id = efx_ef10_filter_get_unsafe_id(efx, rc); |
| 5208 | if (!nic_data->workaround_26807 && !encap_type) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5209 | /* Also need an Ethernet broadcast filter */ |
| 5210 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
Bert Kenward | f1c2ef4 | 2015-12-11 09:39:32 +0000 | [diff] [blame] | 5211 | filter_flags, 0); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5212 | eth_broadcast_addr(baddr); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5213 | efx_filter_set_eth_local(&spec, vlan->vid, baddr); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5214 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 5215 | if (rc < 0) { |
| 5216 | netif_warn(efx, drv, efx->net_dev, |
| 5217 | "Broadcast filter insert failed rc=%d\n", |
| 5218 | rc); |
| 5219 | if (rollback) { |
| 5220 | /* Roll back the mc_def filter */ |
| 5221 | efx_ef10_filter_remove_unsafe( |
| 5222 | efx, EFX_FILTER_PRI_AUTO, |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5223 | *id); |
| 5224 | *id = EFX_EF10_FILTER_ID_INVALID; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5225 | return rc; |
| 5226 | } |
| 5227 | } else { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5228 | EFX_WARN_ON_PARANOID( |
| 5229 | vlan->default_filters[EFX_EF10_BCAST] != |
| 5230 | EFX_EF10_FILTER_ID_INVALID); |
| 5231 | vlan->default_filters[EFX_EF10_BCAST] = |
| 5232 | efx_ef10_filter_get_unsafe_id(efx, rc); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5233 | } |
| 5234 | } |
| 5235 | rc = 0; |
| 5236 | } else { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5237 | /* mapping from encap types to default filter IDs (unicast) */ |
| 5238 | static enum efx_ef10_default_filters map[] = { |
| 5239 | [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF, |
| 5240 | [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF, |
| 5241 | [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF, |
| 5242 | [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF, |
| 5243 | [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] = |
| 5244 | EFX_EF10_VXLAN6_UCDEF, |
| 5245 | [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] = |
| 5246 | EFX_EF10_NVGRE6_UCDEF, |
| 5247 | [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] = |
| 5248 | EFX_EF10_GENEVE6_UCDEF, |
| 5249 | }; |
| 5250 | |
| 5251 | /* quick bounds check (BCAST result impossible) */ |
| 5252 | BUILD_BUG_ON(EFX_EF10_BCAST != 0); |
Dan Carpenter | ee467fb | 2017-02-07 10:44:31 +0300 | [diff] [blame] | 5253 | if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5254 | WARN_ON(1); |
| 5255 | return -EINVAL; |
| 5256 | } |
| 5257 | /* then follow map */ |
| 5258 | id = &vlan->default_filters[map[encap_type]]; |
| 5259 | EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID); |
| 5260 | *id = rc; |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5261 | rc = 0; |
| 5262 | } |
| 5263 | return rc; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD |
| 5267 | * flag or removes these filters, we don't need to hold the filter_lock while |
| 5268 | * scanning for these filters. |
| 5269 | */ |
| 5270 | static void efx_ef10_filter_remove_old(struct efx_nic *efx) |
| 5271 | { |
| 5272 | struct efx_ef10_filter_table *table = efx->filter_state; |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 5273 | int remove_failed = 0; |
| 5274 | int remove_noent = 0; |
| 5275 | int rc; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5276 | int i; |
| 5277 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5278 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 5279 | if (ACCESS_ONCE(table->entry[i].spec) & |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 5280 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 5281 | rc = efx_ef10_filter_remove_internal(efx, |
| 5282 | 1U << EFX_FILTER_PRI_AUTO, i, true); |
| 5283 | if (rc == -ENOENT) |
| 5284 | remove_noent++; |
| 5285 | else if (rc) |
| 5286 | remove_failed++; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5287 | } |
| 5288 | } |
Bert Kenward | e65a510 | 2015-12-23 08:57:36 +0000 | [diff] [blame] | 5289 | |
| 5290 | if (remove_failed) |
| 5291 | netif_info(efx, drv, efx->net_dev, |
| 5292 | "%s: failed to remove %d filters\n", |
| 5293 | __func__, remove_failed); |
| 5294 | if (remove_noent) |
| 5295 | netif_info(efx, drv, efx->net_dev, |
| 5296 | "%s: failed to remove %d non-existent filters\n", |
| 5297 | __func__, remove_noent); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5298 | } |
| 5299 | |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 5300 | static int efx_ef10_vport_set_mac_address(struct efx_nic *efx) |
| 5301 | { |
| 5302 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 5303 | u8 mac_old[ETH_ALEN]; |
| 5304 | int rc, rc2; |
| 5305 | |
| 5306 | /* Only reconfigure a PF-created vport */ |
| 5307 | if (is_zero_ether_addr(nic_data->vport_mac)) |
| 5308 | return 0; |
| 5309 | |
| 5310 | efx_device_detach_sync(efx); |
| 5311 | efx_net_stop(efx->net_dev); |
| 5312 | down_write(&efx->filter_sem); |
| 5313 | efx_ef10_filter_table_remove(efx); |
| 5314 | up_write(&efx->filter_sem); |
| 5315 | |
| 5316 | rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id); |
| 5317 | if (rc) |
| 5318 | goto restore_filters; |
| 5319 | |
| 5320 | ether_addr_copy(mac_old, nic_data->vport_mac); |
| 5321 | rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id, |
| 5322 | nic_data->vport_mac); |
| 5323 | if (rc) |
| 5324 | goto restore_vadaptor; |
| 5325 | |
| 5326 | rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id, |
| 5327 | efx->net_dev->dev_addr); |
| 5328 | if (!rc) { |
| 5329 | ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr); |
| 5330 | } else { |
| 5331 | rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old); |
| 5332 | if (rc2) { |
| 5333 | /* Failed to add original MAC, so clear vport_mac */ |
| 5334 | eth_zero_addr(nic_data->vport_mac); |
| 5335 | goto reset_nic; |
| 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | restore_vadaptor: |
| 5340 | rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 5341 | if (rc2) |
| 5342 | goto reset_nic; |
| 5343 | restore_filters: |
| 5344 | down_write(&efx->filter_sem); |
| 5345 | rc2 = efx_ef10_filter_table_probe(efx); |
| 5346 | up_write(&efx->filter_sem); |
| 5347 | if (rc2) |
| 5348 | goto reset_nic; |
| 5349 | |
| 5350 | rc2 = efx_net_open(efx->net_dev); |
| 5351 | if (rc2) |
| 5352 | goto reset_nic; |
| 5353 | |
| 5354 | netif_device_attach(efx->net_dev); |
| 5355 | |
| 5356 | return rc; |
| 5357 | |
| 5358 | reset_nic: |
| 5359 | netif_err(efx, drv, efx->net_dev, |
| 5360 | "Failed to restore when changing MAC address - scheduling reset\n"); |
| 5361 | efx_schedule_reset(efx, RESET_TYPE_DATAPATH); |
| 5362 | |
| 5363 | return rc ? rc : rc2; |
| 5364 | } |
| 5365 | |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5366 | /* Caller must hold efx->filter_sem for read if race against |
| 5367 | * efx_ef10_filter_table_remove() is possible |
| 5368 | */ |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5369 | static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx, |
| 5370 | struct efx_ef10_filter_vlan *vlan) |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5371 | { |
| 5372 | struct efx_ef10_filter_table *table = efx->filter_state; |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5373 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5374 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 5375 | /* Do not install unspecified VID if VLAN filtering is enabled. |
| 5376 | * Do not install all specified VIDs if VLAN filtering is disabled. |
| 5377 | */ |
| 5378 | if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter) |
| 5379 | return; |
| 5380 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5381 | /* Insert/renew unicast filters */ |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5382 | if (table->uc_promisc) { |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5383 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE, |
| 5384 | false, false); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5385 | efx_ef10_filter_insert_addr_list(efx, vlan, false, false); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5386 | } else { |
| 5387 | /* If any of the filters failed to insert, fall back to |
| 5388 | * promiscuous mode - add in the uc_def filter. But keep |
| 5389 | * our individual unicast filters. |
| 5390 | */ |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5391 | if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false)) |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5392 | efx_ef10_filter_insert_def(efx, vlan, |
| 5393 | EFX_ENCAP_TYPE_NONE, |
| 5394 | false, false); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5395 | } |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5396 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN, |
| 5397 | false, false); |
| 5398 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN | |
| 5399 | EFX_ENCAP_FLAG_IPV6, |
| 5400 | false, false); |
| 5401 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE, |
| 5402 | false, false); |
| 5403 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE | |
| 5404 | EFX_ENCAP_FLAG_IPV6, |
| 5405 | false, false); |
| 5406 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE, |
| 5407 | false, false); |
| 5408 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE | |
| 5409 | EFX_ENCAP_FLAG_IPV6, |
| 5410 | false, false); |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5411 | |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5412 | /* Insert/renew multicast filters */ |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5413 | /* If changing promiscuous state with cascaded multicast filters, remove |
| 5414 | * old filters first, so that packets are dropped rather than duplicated |
| 5415 | */ |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5416 | if (nic_data->workaround_26807 && |
| 5417 | table->mc_promisc_last != table->mc_promisc) |
Daniel Pieczko | ab8b1f7c | 2015-07-21 15:10:44 +0100 | [diff] [blame] | 5418 | efx_ef10_filter_remove_old(efx); |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5419 | if (table->mc_promisc) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5420 | if (nic_data->workaround_26807) { |
| 5421 | /* If we failed to insert promiscuous filters, rollback |
| 5422 | * and fall back to individual multicast filters |
| 5423 | */ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5424 | if (efx_ef10_filter_insert_def(efx, vlan, |
| 5425 | EFX_ENCAP_TYPE_NONE, |
| 5426 | true, true)) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5427 | /* Changing promisc state, so remove old filters */ |
| 5428 | efx_ef10_filter_remove_old(efx); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5429 | efx_ef10_filter_insert_addr_list(efx, vlan, |
| 5430 | true, false); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5431 | } |
| 5432 | } else { |
| 5433 | /* If we failed to insert promiscuous filters, don't |
| 5434 | * rollback. Regardless, also insert the mc_list |
| 5435 | */ |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5436 | efx_ef10_filter_insert_def(efx, vlan, |
| 5437 | EFX_ENCAP_TYPE_NONE, |
| 5438 | true, false); |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5439 | efx_ef10_filter_insert_addr_list(efx, vlan, true, false); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5440 | } |
| 5441 | } else { |
| 5442 | /* If any filters failed to insert, rollback and fall back to |
| 5443 | * promiscuous mode - mc_def filter and maybe broadcast. If |
| 5444 | * that fails, roll back again and insert as many of our |
| 5445 | * individual multicast filters as we can. |
| 5446 | */ |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5447 | if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) { |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5448 | /* Changing promisc state, so remove old filters */ |
| 5449 | if (nic_data->workaround_26807) |
| 5450 | efx_ef10_filter_remove_old(efx); |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5451 | if (efx_ef10_filter_insert_def(efx, vlan, |
| 5452 | EFX_ENCAP_TYPE_NONE, |
| 5453 | true, true)) |
Andrew Rybchenko | b3a3c03 | 2016-06-15 17:47:36 +0100 | [diff] [blame] | 5454 | efx_ef10_filter_insert_addr_list(efx, vlan, |
| 5455 | true, false); |
Edward Cree | 12fb0da | 2015-07-21 15:11:00 +0100 | [diff] [blame] | 5456 | } |
| 5457 | } |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5458 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN, |
| 5459 | true, false); |
| 5460 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN | |
| 5461 | EFX_ENCAP_FLAG_IPV6, |
| 5462 | true, false); |
| 5463 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE, |
| 5464 | true, false); |
| 5465 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE | |
| 5466 | EFX_ENCAP_FLAG_IPV6, |
| 5467 | true, false); |
| 5468 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE, |
| 5469 | true, false); |
| 5470 | efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE | |
| 5471 | EFX_ENCAP_FLAG_IPV6, |
| 5472 | true, false); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | /* Caller must hold efx->filter_sem for read if race against |
| 5476 | * efx_ef10_filter_table_remove() is possible |
| 5477 | */ |
| 5478 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) |
| 5479 | { |
| 5480 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 5481 | struct net_device *net_dev = efx->net_dev; |
| 5482 | struct efx_ef10_filter_vlan *vlan; |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 5483 | bool vlan_filter; |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5484 | |
| 5485 | if (!efx_dev_registered(efx)) |
| 5486 | return; |
| 5487 | |
| 5488 | if (!table) |
| 5489 | return; |
| 5490 | |
| 5491 | efx_ef10_filter_mark_old(efx); |
| 5492 | |
| 5493 | /* Copy/convert the address lists; add the primary station |
| 5494 | * address and broadcast address |
| 5495 | */ |
| 5496 | netif_addr_lock_bh(net_dev); |
| 5497 | efx_ef10_filter_uc_addr_list(efx); |
| 5498 | efx_ef10_filter_mc_addr_list(efx); |
| 5499 | netif_addr_unlock_bh(net_dev); |
| 5500 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 5501 | /* If VLAN filtering changes, all old filters are finally removed. |
| 5502 | * Do it in advance to avoid conflicts for unicast untagged and |
| 5503 | * VLAN 0 tagged filters. |
| 5504 | */ |
| 5505 | vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER); |
| 5506 | if (table->vlan_filter != vlan_filter) { |
| 5507 | table->vlan_filter = vlan_filter; |
| 5508 | efx_ef10_filter_remove_old(efx); |
| 5509 | } |
| 5510 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5511 | list_for_each_entry(vlan, &table->vlan_list, list) |
| 5512 | efx_ef10_filter_vlan_sync_rx_mode(efx, vlan); |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5513 | |
| 5514 | efx_ef10_filter_remove_old(efx); |
Andrew Rybchenko | afa4ce1 | 2016-06-15 17:45:56 +0100 | [diff] [blame] | 5515 | table->mc_promisc_last = table->mc_promisc; |
Daniel Pieczko | 822b96f | 2015-07-21 15:10:27 +0100 | [diff] [blame] | 5516 | } |
| 5517 | |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5518 | static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid) |
| 5519 | { |
| 5520 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 5521 | struct efx_ef10_filter_vlan *vlan; |
| 5522 | |
| 5523 | WARN_ON(!rwsem_is_locked(&efx->filter_sem)); |
| 5524 | |
| 5525 | list_for_each_entry(vlan, &table->vlan_list, list) { |
| 5526 | if (vlan->vid == vid) |
| 5527 | return vlan; |
| 5528 | } |
| 5529 | |
| 5530 | return NULL; |
| 5531 | } |
| 5532 | |
| 5533 | static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid) |
| 5534 | { |
| 5535 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 5536 | struct efx_ef10_filter_vlan *vlan; |
| 5537 | unsigned int i; |
| 5538 | |
| 5539 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 5540 | return -EINVAL; |
| 5541 | |
| 5542 | vlan = efx_ef10_filter_find_vlan(efx, vid); |
| 5543 | if (WARN_ON(vlan)) { |
| 5544 | netif_err(efx, drv, efx->net_dev, |
| 5545 | "VLAN %u already added\n", vid); |
| 5546 | return -EALREADY; |
| 5547 | } |
| 5548 | |
| 5549 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 5550 | if (!vlan) |
| 5551 | return -ENOMEM; |
| 5552 | |
| 5553 | vlan->vid = vid; |
| 5554 | |
| 5555 | for (i = 0; i < ARRAY_SIZE(vlan->uc); i++) |
| 5556 | vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID; |
| 5557 | for (i = 0; i < ARRAY_SIZE(vlan->mc); i++) |
| 5558 | vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID; |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5559 | for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++) |
| 5560 | vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID; |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5561 | |
| 5562 | list_add_tail(&vlan->list, &table->vlan_list); |
| 5563 | |
| 5564 | if (efx_dev_registered(efx)) |
| 5565 | efx_ef10_filter_vlan_sync_rx_mode(efx, vlan); |
| 5566 | |
| 5567 | return 0; |
| 5568 | } |
| 5569 | |
| 5570 | static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx, |
| 5571 | struct efx_ef10_filter_vlan *vlan) |
| 5572 | { |
| 5573 | unsigned int i; |
| 5574 | |
| 5575 | /* See comment in efx_ef10_filter_table_remove() */ |
| 5576 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 5577 | return; |
| 5578 | |
| 5579 | list_del(&vlan->list); |
| 5580 | |
Edward Cree | 8c91562 | 2016-06-15 17:49:05 +0100 | [diff] [blame] | 5581 | for (i = 0; i < ARRAY_SIZE(vlan->uc); i++) |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5582 | efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, |
Edward Cree | 8c91562 | 2016-06-15 17:49:05 +0100 | [diff] [blame] | 5583 | vlan->uc[i]); |
| 5584 | for (i = 0; i < ARRAY_SIZE(vlan->mc); i++) |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5585 | efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, |
Edward Cree | 8c91562 | 2016-06-15 17:49:05 +0100 | [diff] [blame] | 5586 | vlan->mc[i]); |
Edward Cree | 9b41080 | 2017-01-27 15:02:52 +0000 | [diff] [blame] | 5587 | for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++) |
| 5588 | if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID) |
| 5589 | efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, |
| 5590 | vlan->default_filters[i]); |
Andrew Rybchenko | 34813fe | 2016-06-15 17:48:14 +0100 | [diff] [blame] | 5591 | |
| 5592 | kfree(vlan); |
| 5593 | } |
| 5594 | |
| 5595 | static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid) |
| 5596 | { |
| 5597 | struct efx_ef10_filter_vlan *vlan; |
| 5598 | |
| 5599 | /* See comment in efx_ef10_filter_table_remove() */ |
| 5600 | if (!efx_rwsem_assert_write_locked(&efx->filter_sem)) |
| 5601 | return; |
| 5602 | |
| 5603 | vlan = efx_ef10_filter_find_vlan(efx, vid); |
| 5604 | if (!vlan) { |
| 5605 | netif_err(efx, drv, efx->net_dev, |
| 5606 | "VLAN %u not found in filter state\n", vid); |
| 5607 | return; |
| 5608 | } |
| 5609 | |
| 5610 | efx_ef10_filter_del_vlan_internal(efx, vlan); |
| 5611 | } |
| 5612 | |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5613 | static int efx_ef10_set_mac_address(struct efx_nic *efx) |
| 5614 | { |
| 5615 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN); |
| 5616 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 5617 | bool was_enabled = efx->port_enabled; |
| 5618 | int rc; |
| 5619 | |
| 5620 | efx_device_detach_sync(efx); |
| 5621 | efx_net_stop(efx->net_dev); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 5622 | |
| 5623 | mutex_lock(&efx->mac_lock); |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5624 | down_write(&efx->filter_sem); |
| 5625 | efx_ef10_filter_table_remove(efx); |
| 5626 | |
| 5627 | ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR), |
| 5628 | efx->net_dev->dev_addr); |
| 5629 | MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID, |
| 5630 | nic_data->vport_id); |
Daniel Pieczko | 535a617 | 2015-07-07 11:37:33 +0100 | [diff] [blame] | 5631 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf, |
| 5632 | sizeof(inbuf), NULL, 0, NULL); |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5633 | |
| 5634 | efx_ef10_filter_table_probe(efx); |
| 5635 | up_write(&efx->filter_sem); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 5636 | mutex_unlock(&efx->mac_lock); |
| 5637 | |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5638 | if (was_enabled) |
| 5639 | efx_net_open(efx->net_dev); |
| 5640 | netif_device_attach(efx->net_dev); |
| 5641 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5642 | #ifdef CONFIG_SFC_SRIOV |
| 5643 | if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) { |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5644 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; |
| 5645 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5646 | if (rc == -EPERM) { |
| 5647 | struct efx_nic *efx_pf; |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5648 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5649 | /* Switch to PF and change MAC address on vport */ |
| 5650 | efx_pf = pci_get_drvdata(pci_dev_pf); |
| 5651 | |
| 5652 | rc = efx_ef10_sriov_set_vf_mac(efx_pf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5653 | nic_data->vf_index, |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5654 | efx->net_dev->dev_addr); |
| 5655 | } else if (!rc) { |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5656 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); |
| 5657 | struct efx_ef10_nic_data *nic_data = efx_pf->nic_data; |
| 5658 | unsigned int i; |
| 5659 | |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5660 | /* MAC address successfully changed by VF (with MAC |
| 5661 | * spoofing) so update the parent PF if possible. |
| 5662 | */ |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5663 | for (i = 0; i < efx_pf->vf_count; ++i) { |
| 5664 | struct ef10_vf *vf = nic_data->vf + i; |
| 5665 | |
| 5666 | if (vf->efx == efx) { |
| 5667 | ether_addr_copy(vf->mac, |
| 5668 | efx->net_dev->dev_addr); |
| 5669 | return 0; |
| 5670 | } |
| 5671 | } |
| 5672 | } |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5673 | } else |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5674 | #endif |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5675 | if (rc == -EPERM) { |
| 5676 | netif_err(efx, drv, efx->net_dev, |
| 5677 | "Cannot change MAC address; use sfboot to enable" |
| 5678 | " mac-spoofing on this interface\n"); |
Daniel Pieczko | 7a186f4 | 2015-07-07 11:37:19 +0100 | [diff] [blame] | 5679 | } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) { |
| 5680 | /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC |
| 5681 | * fall-back to the method of changing the MAC address on the |
| 5682 | * vport. This only applies to PFs because such versions of |
| 5683 | * MCFW do not support VFs. |
| 5684 | */ |
| 5685 | rc = efx_ef10_vport_set_mac_address(efx); |
Daniel Pieczko | 535a617 | 2015-07-07 11:37:33 +0100 | [diff] [blame] | 5686 | } else { |
| 5687 | efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC, |
| 5688 | sizeof(inbuf), NULL, 0, rc); |
Daniel Pieczko | 9e9f665 | 2015-07-07 11:37:00 +0100 | [diff] [blame] | 5689 | } |
| 5690 | |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 5691 | return rc; |
| 5692 | } |
| 5693 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5694 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) |
| 5695 | { |
| 5696 | efx_ef10_filter_sync_rx_mode(efx); |
| 5697 | |
| 5698 | return efx_mcdi_set_mac(efx); |
| 5699 | } |
| 5700 | |
Shradha Shah | 862f894 | 2015-05-20 11:08:56 +0100 | [diff] [blame] | 5701 | static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx) |
| 5702 | { |
| 5703 | efx_ef10_filter_sync_rx_mode(efx); |
| 5704 | |
| 5705 | return 0; |
| 5706 | } |
| 5707 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 5708 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
| 5709 | { |
| 5710 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); |
| 5711 | |
| 5712 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); |
| 5713 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), |
| 5714 | NULL, 0, NULL); |
| 5715 | } |
| 5716 | |
| 5717 | /* MC BISTs follow a different poll mechanism to phy BISTs. |
| 5718 | * The BIST is done in the poll handler on the MC, and the MCDI command |
| 5719 | * will block until the BIST is done. |
| 5720 | */ |
| 5721 | static int efx_ef10_poll_bist(struct efx_nic *efx) |
| 5722 | { |
| 5723 | int rc; |
| 5724 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); |
| 5725 | size_t outlen; |
| 5726 | u32 result; |
| 5727 | |
| 5728 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, |
| 5729 | outbuf, sizeof(outbuf), &outlen); |
| 5730 | if (rc != 0) |
| 5731 | return rc; |
| 5732 | |
| 5733 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) |
| 5734 | return -EIO; |
| 5735 | |
| 5736 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); |
| 5737 | switch (result) { |
| 5738 | case MC_CMD_POLL_BIST_PASSED: |
| 5739 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); |
| 5740 | return 0; |
| 5741 | case MC_CMD_POLL_BIST_TIMEOUT: |
| 5742 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); |
| 5743 | return -EIO; |
| 5744 | case MC_CMD_POLL_BIST_FAILED: |
| 5745 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); |
| 5746 | return -EIO; |
| 5747 | default: |
| 5748 | netif_err(efx, hw, efx->net_dev, |
| 5749 | "BIST returned unknown result %u", result); |
| 5750 | return -EIO; |
| 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) |
| 5755 | { |
| 5756 | int rc; |
| 5757 | |
| 5758 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); |
| 5759 | |
| 5760 | rc = efx_ef10_start_bist(efx, bist_type); |
| 5761 | if (rc != 0) |
| 5762 | return rc; |
| 5763 | |
| 5764 | return efx_ef10_poll_bist(efx); |
| 5765 | } |
| 5766 | |
| 5767 | static int |
| 5768 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) |
| 5769 | { |
| 5770 | int rc, rc2; |
| 5771 | |
| 5772 | efx_reset_down(efx, RESET_TYPE_WORLD); |
| 5773 | |
| 5774 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, |
| 5775 | NULL, 0, NULL, 0, NULL); |
| 5776 | if (rc != 0) |
| 5777 | goto out; |
| 5778 | |
| 5779 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; |
| 5780 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; |
| 5781 | |
| 5782 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); |
| 5783 | |
| 5784 | out: |
Daniel Pieczko | 2732482 | 2015-07-31 11:14:54 +0100 | [diff] [blame] | 5785 | if (rc == -EPERM) |
| 5786 | rc = 0; |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 5787 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); |
| 5788 | return rc ? rc : rc2; |
| 5789 | } |
| 5790 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5791 | #ifdef CONFIG_SFC_MTD |
| 5792 | |
| 5793 | struct efx_ef10_nvram_type_info { |
| 5794 | u16 type, type_mask; |
| 5795 | u8 port; |
| 5796 | const char *name; |
| 5797 | }; |
| 5798 | |
| 5799 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { |
| 5800 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, |
| 5801 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, |
| 5802 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, |
| 5803 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, |
| 5804 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, |
| 5805 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, |
| 5806 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, |
| 5807 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, |
| 5808 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, |
Ben Hutchings | a84f3bf9 | 2013-10-09 14:14:41 +0100 | [diff] [blame] | 5809 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 5810 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
| 5811 | }; |
| 5812 | |
| 5813 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, |
| 5814 | struct efx_mcdi_mtd_partition *part, |
| 5815 | unsigned int type) |
| 5816 | { |
| 5817 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); |
| 5818 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); |
| 5819 | const struct efx_ef10_nvram_type_info *info; |
| 5820 | size_t size, erase_size, outlen; |
| 5821 | bool protected; |
| 5822 | int rc; |
| 5823 | |
| 5824 | for (info = efx_ef10_nvram_types; ; info++) { |
| 5825 | if (info == |
| 5826 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) |
| 5827 | return -ENODEV; |
| 5828 | if ((type & ~info->type_mask) == info->type) |
| 5829 | break; |
| 5830 | } |
| 5831 | if (info->port != efx_port_num(efx)) |
| 5832 | return -ENODEV; |
| 5833 | |
| 5834 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); |
| 5835 | if (rc) |
| 5836 | return rc; |
| 5837 | if (protected) |
| 5838 | return -ENODEV; /* hide it */ |
| 5839 | |
| 5840 | part->nvram_type = type; |
| 5841 | |
| 5842 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); |
| 5843 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), |
| 5844 | outbuf, sizeof(outbuf), &outlen); |
| 5845 | if (rc) |
| 5846 | return rc; |
| 5847 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) |
| 5848 | return -EIO; |
| 5849 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & |
| 5850 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) |
| 5851 | part->fw_subtype = MCDI_DWORD(outbuf, |
| 5852 | NVRAM_METADATA_OUT_SUBTYPE); |
| 5853 | |
| 5854 | part->common.dev_type_name = "EF10 NVRAM manager"; |
| 5855 | part->common.type_name = info->name; |
| 5856 | |
| 5857 | part->common.mtd.type = MTD_NORFLASH; |
| 5858 | part->common.mtd.flags = MTD_CAP_NORFLASH; |
| 5859 | part->common.mtd.size = size; |
| 5860 | part->common.mtd.erasesize = erase_size; |
| 5861 | |
| 5862 | return 0; |
| 5863 | } |
| 5864 | |
| 5865 | static int efx_ef10_mtd_probe(struct efx_nic *efx) |
| 5866 | { |
| 5867 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); |
| 5868 | struct efx_mcdi_mtd_partition *parts; |
| 5869 | size_t outlen, n_parts_total, i, n_parts; |
| 5870 | unsigned int type; |
| 5871 | int rc; |
| 5872 | |
| 5873 | ASSERT_RTNL(); |
| 5874 | |
| 5875 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); |
| 5876 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, |
| 5877 | outbuf, sizeof(outbuf), &outlen); |
| 5878 | if (rc) |
| 5879 | return rc; |
| 5880 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) |
| 5881 | return -EIO; |
| 5882 | |
| 5883 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); |
| 5884 | if (n_parts_total > |
| 5885 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) |
| 5886 | return -EIO; |
| 5887 | |
| 5888 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); |
| 5889 | if (!parts) |
| 5890 | return -ENOMEM; |
| 5891 | |
| 5892 | n_parts = 0; |
| 5893 | for (i = 0; i < n_parts_total; i++) { |
| 5894 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, |
| 5895 | i); |
| 5896 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); |
| 5897 | if (rc == 0) |
| 5898 | n_parts++; |
| 5899 | else if (rc != -ENODEV) |
| 5900 | goto fail; |
| 5901 | } |
| 5902 | |
| 5903 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); |
| 5904 | fail: |
| 5905 | if (rc) |
| 5906 | kfree(parts); |
| 5907 | return rc; |
| 5908 | } |
| 5909 | |
| 5910 | #endif /* CONFIG_SFC_MTD */ |
| 5911 | |
| 5912 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) |
| 5913 | { |
| 5914 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); |
| 5915 | } |
| 5916 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 5917 | static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx, |
| 5918 | u32 host_time) {} |
| 5919 | |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 5920 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
| 5921 | bool temp) |
| 5922 | { |
| 5923 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); |
| 5924 | int rc; |
| 5925 | |
| 5926 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || |
| 5927 | channel->sync_events_state == SYNC_EVENTS_VALID || |
| 5928 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) |
| 5929 | return 0; |
| 5930 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; |
| 5931 | |
| 5932 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); |
| 5933 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 5934 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, |
| 5935 | channel->channel); |
| 5936 | |
| 5937 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 5938 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 5939 | |
| 5940 | if (rc != 0) |
| 5941 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 5942 | SYNC_EVENTS_DISABLED; |
| 5943 | |
| 5944 | return rc; |
| 5945 | } |
| 5946 | |
| 5947 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, |
| 5948 | bool temp) |
| 5949 | { |
| 5950 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); |
| 5951 | int rc; |
| 5952 | |
| 5953 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || |
| 5954 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) |
| 5955 | return 0; |
| 5956 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { |
| 5957 | channel->sync_events_state = SYNC_EVENTS_DISABLED; |
| 5958 | return 0; |
| 5959 | } |
| 5960 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 5961 | SYNC_EVENTS_DISABLED; |
| 5962 | |
| 5963 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); |
| 5964 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 5965 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, |
| 5966 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); |
| 5967 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, |
| 5968 | channel->channel); |
| 5969 | |
| 5970 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 5971 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 5972 | |
| 5973 | return rc; |
| 5974 | } |
| 5975 | |
| 5976 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, |
| 5977 | bool temp) |
| 5978 | { |
| 5979 | int (*set)(struct efx_channel *channel, bool temp); |
| 5980 | struct efx_channel *channel; |
| 5981 | |
| 5982 | set = en ? |
| 5983 | efx_ef10_rx_enable_timestamping : |
| 5984 | efx_ef10_rx_disable_timestamping; |
| 5985 | |
| 5986 | efx_for_each_channel(channel, efx) { |
| 5987 | int rc = set(channel, temp); |
| 5988 | if (en && rc != 0) { |
| 5989 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); |
| 5990 | return rc; |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | return 0; |
| 5995 | } |
| 5996 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 5997 | static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx, |
| 5998 | struct hwtstamp_config *init) |
| 5999 | { |
| 6000 | return -EOPNOTSUPP; |
| 6001 | } |
| 6002 | |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 6003 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
| 6004 | struct hwtstamp_config *init) |
| 6005 | { |
| 6006 | int rc; |
| 6007 | |
| 6008 | switch (init->rx_filter) { |
| 6009 | case HWTSTAMP_FILTER_NONE: |
| 6010 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); |
| 6011 | /* if TX timestamping is still requested then leave PTP on */ |
| 6012 | return efx_ptp_change_mode(efx, |
| 6013 | init->tx_type != HWTSTAMP_TX_OFF, 0); |
| 6014 | case HWTSTAMP_FILTER_ALL: |
| 6015 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 6016 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 6017 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 6018 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 6019 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 6020 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 6021 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 6022 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 6023 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 6024 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 6025 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 6026 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 6027 | init->rx_filter = HWTSTAMP_FILTER_ALL; |
| 6028 | rc = efx_ptp_change_mode(efx, true, 0); |
| 6029 | if (!rc) |
| 6030 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); |
| 6031 | if (rc) |
| 6032 | efx_ptp_change_mode(efx, false, 0); |
| 6033 | return rc; |
| 6034 | default: |
| 6035 | return -ERANGE; |
| 6036 | } |
| 6037 | } |
| 6038 | |
Bert Kenward | 08a7b29b | 2017-01-10 16:23:33 +0000 | [diff] [blame] | 6039 | static int efx_ef10_get_phys_port_id(struct efx_nic *efx, |
| 6040 | struct netdev_phys_item_id *ppid) |
| 6041 | { |
| 6042 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 6043 | |
| 6044 | if (!is_valid_ether_addr(nic_data->port_id)) |
| 6045 | return -EOPNOTSUPP; |
| 6046 | |
| 6047 | ppid->id_len = ETH_ALEN; |
| 6048 | memcpy(ppid->id, nic_data->port_id, ppid->id_len); |
| 6049 | |
| 6050 | return 0; |
| 6051 | } |
| 6052 | |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 6053 | static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid) |
| 6054 | { |
| 6055 | if (proto != htons(ETH_P_8021Q)) |
| 6056 | return -EINVAL; |
| 6057 | |
| 6058 | return efx_ef10_add_vlan(efx, vid); |
| 6059 | } |
| 6060 | |
| 6061 | static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid) |
| 6062 | { |
| 6063 | if (proto != htons(ETH_P_8021Q)) |
| 6064 | return -EINVAL; |
| 6065 | |
| 6066 | return efx_ef10_del_vlan(efx, vid); |
| 6067 | } |
| 6068 | |
Andrew Rybchenko | 100a9db | 2016-06-15 17:42:26 +0100 | [diff] [blame] | 6069 | #define EF10_OFFLOAD_FEATURES \ |
| 6070 | (NETIF_F_IP_CSUM | \ |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 6071 | NETIF_F_HW_VLAN_CTAG_FILTER | \ |
Andrew Rybchenko | 100a9db | 2016-06-15 17:42:26 +0100 | [diff] [blame] | 6072 | NETIF_F_IPV6_CSUM | \ |
| 6073 | NETIF_F_RXHASH | \ |
| 6074 | NETIF_F_NTUPLE) |
| 6075 | |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6076 | const struct efx_nic_type efx_hunt_a0_vf_nic_type = { |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 6077 | .is_vf = true, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6078 | .mem_bar = EFX_MEM_VF_BAR, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6079 | .mem_map_size = efx_ef10_mem_map_size, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6080 | .probe = efx_ef10_probe_vf, |
| 6081 | .remove = efx_ef10_remove, |
| 6082 | .dimension_resources = efx_ef10_dimension_resources, |
| 6083 | .init = efx_ef10_init_nic, |
| 6084 | .fini = efx_port_dummy_op_void, |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 6085 | .map_reset_reason = efx_ef10_map_reset_reason, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6086 | .map_reset_flags = efx_ef10_map_reset_flags, |
| 6087 | .reset = efx_ef10_reset, |
| 6088 | .probe_port = efx_mcdi_port_probe, |
| 6089 | .remove_port = efx_mcdi_port_remove, |
| 6090 | .fini_dmaq = efx_ef10_fini_dmaq, |
| 6091 | .prepare_flr = efx_ef10_prepare_flr, |
| 6092 | .finish_flr = efx_port_dummy_op_void, |
| 6093 | .describe_stats = efx_ef10_describe_stats, |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 6094 | .update_stats = efx_ef10_update_stats_vf, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6095 | .start_stats = efx_port_dummy_op_void, |
| 6096 | .pull_stats = efx_port_dummy_op_void, |
| 6097 | .stop_stats = efx_port_dummy_op_void, |
| 6098 | .set_id_led = efx_mcdi_set_id_led, |
| 6099 | .push_irq_moderation = efx_ef10_push_irq_moderation, |
Shradha Shah | 862f894 | 2015-05-20 11:08:56 +0100 | [diff] [blame] | 6100 | .reconfigure_mac = efx_ef10_mac_reconfigure_vf, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6101 | .check_mac_fault = efx_mcdi_mac_check_fault, |
| 6102 | .reconfigure_port = efx_mcdi_port_reconfigure, |
| 6103 | .get_wol = efx_ef10_get_wol_vf, |
| 6104 | .set_wol = efx_ef10_set_wol_vf, |
| 6105 | .resume_wol = efx_port_dummy_op_void, |
| 6106 | .mcdi_request = efx_ef10_mcdi_request, |
| 6107 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, |
| 6108 | .mcdi_read_response = efx_ef10_mcdi_read_response, |
| 6109 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, |
Daniel Pieczko | c577e59 | 2015-10-09 10:40:35 +0100 | [diff] [blame] | 6110 | .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6111 | .irq_enable_master = efx_port_dummy_op_void, |
| 6112 | .irq_test_generate = efx_ef10_irq_test_generate, |
| 6113 | .irq_disable_non_ev = efx_port_dummy_op_void, |
| 6114 | .irq_handle_msi = efx_ef10_msi_interrupt, |
| 6115 | .irq_handle_legacy = efx_ef10_legacy_interrupt, |
| 6116 | .tx_probe = efx_ef10_tx_probe, |
| 6117 | .tx_init = efx_ef10_tx_init, |
| 6118 | .tx_remove = efx_ef10_tx_remove, |
| 6119 | .tx_write = efx_ef10_tx_write, |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 6120 | .tx_limit_len = efx_ef10_tx_limit_len, |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 6121 | .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config, |
Edward Cree | a707d18 | 2017-01-17 12:02:12 +0000 | [diff] [blame] | 6122 | .rx_pull_rss_config = efx_ef10_rx_pull_rss_config, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6123 | .rx_probe = efx_ef10_rx_probe, |
| 6124 | .rx_init = efx_ef10_rx_init, |
| 6125 | .rx_remove = efx_ef10_rx_remove, |
| 6126 | .rx_write = efx_ef10_rx_write, |
| 6127 | .rx_defer_refill = efx_ef10_rx_defer_refill, |
| 6128 | .ev_probe = efx_ef10_ev_probe, |
| 6129 | .ev_init = efx_ef10_ev_init, |
| 6130 | .ev_fini = efx_ef10_ev_fini, |
| 6131 | .ev_remove = efx_ef10_ev_remove, |
| 6132 | .ev_process = efx_ef10_ev_process, |
| 6133 | .ev_read_ack = efx_ef10_ev_read_ack, |
| 6134 | .ev_test_generate = efx_ef10_ev_test_generate, |
| 6135 | .filter_table_probe = efx_ef10_filter_table_probe, |
| 6136 | .filter_table_restore = efx_ef10_filter_table_restore, |
| 6137 | .filter_table_remove = efx_ef10_filter_table_remove, |
| 6138 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, |
| 6139 | .filter_insert = efx_ef10_filter_insert, |
| 6140 | .filter_remove_safe = efx_ef10_filter_remove_safe, |
| 6141 | .filter_get_safe = efx_ef10_filter_get_safe, |
| 6142 | .filter_clear_rx = efx_ef10_filter_clear_rx, |
| 6143 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, |
| 6144 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, |
| 6145 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, |
| 6146 | #ifdef CONFIG_RFS_ACCEL |
| 6147 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, |
| 6148 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, |
| 6149 | #endif |
| 6150 | #ifdef CONFIG_SFC_MTD |
| 6151 | .mtd_probe = efx_port_dummy_op_int, |
| 6152 | #endif |
| 6153 | .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf, |
| 6154 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf, |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 6155 | .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid, |
| 6156 | .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6157 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 6158 | .vswitching_probe = efx_ef10_vswitching_probe_vf, |
| 6159 | .vswitching_restore = efx_ef10_vswitching_restore_vf, |
| 6160 | .vswitching_remove = efx_ef10_vswitching_remove_vf, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6161 | #endif |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 6162 | .get_mac_address = efx_ef10_get_mac_address_vf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 6163 | .set_mac_address = efx_ef10_set_mac_address, |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 6164 | |
Bert Kenward | 08a7b29b | 2017-01-10 16:23:33 +0000 | [diff] [blame] | 6165 | .get_phys_port_id = efx_ef10_get_phys_port_id, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6166 | .revision = EFX_REV_HUNT_A0, |
| 6167 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), |
| 6168 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, |
| 6169 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, |
| 6170 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
| 6171 | .can_rx_scatter = true, |
| 6172 | .always_rx_scatter = true, |
| 6173 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 6174 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, |
Andrew Rybchenko | 100a9db | 2016-06-15 17:42:26 +0100 | [diff] [blame] | 6175 | .offload_features = EF10_OFFLOAD_FEATURES, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6176 | .mcdi_max_ver = 2, |
| 6177 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, |
| 6178 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
| 6179 | 1 << HWTSTAMP_FILTER_ALL, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 6180 | .rx_hash_key_size = 40, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6181 | }; |
| 6182 | |
| 6183 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
Shradha Shah | 6f7f8aa | 2015-05-06 01:00:07 +0100 | [diff] [blame] | 6184 | .is_vf = false, |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 6185 | .mem_bar = EFX_MEM_BAR, |
| 6186 | .mem_map_size = efx_ef10_mem_map_size, |
| 6187 | .probe = efx_ef10_probe_pf, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6188 | .remove = efx_ef10_remove, |
| 6189 | .dimension_resources = efx_ef10_dimension_resources, |
| 6190 | .init = efx_ef10_init_nic, |
| 6191 | .fini = efx_port_dummy_op_void, |
Jon Cooper | 087e902 | 2015-05-20 11:11:35 +0100 | [diff] [blame] | 6192 | .map_reset_reason = efx_ef10_map_reset_reason, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6193 | .map_reset_flags = efx_ef10_map_reset_flags, |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 6194 | .reset = efx_ef10_reset, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6195 | .probe_port = efx_mcdi_port_probe, |
| 6196 | .remove_port = efx_mcdi_port_remove, |
| 6197 | .fini_dmaq = efx_ef10_fini_dmaq, |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 6198 | .prepare_flr = efx_ef10_prepare_flr, |
| 6199 | .finish_flr = efx_port_dummy_op_void, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6200 | .describe_stats = efx_ef10_describe_stats, |
Daniel Pieczko | d778819 | 2015-06-02 11:39:20 +0100 | [diff] [blame] | 6201 | .update_stats = efx_ef10_update_stats_pf, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6202 | .start_stats = efx_mcdi_mac_start_stats, |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 6203 | .pull_stats = efx_mcdi_mac_pull_stats, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6204 | .stop_stats = efx_mcdi_mac_stop_stats, |
| 6205 | .set_id_led = efx_mcdi_set_id_led, |
| 6206 | .push_irq_moderation = efx_ef10_push_irq_moderation, |
| 6207 | .reconfigure_mac = efx_ef10_mac_reconfigure, |
| 6208 | .check_mac_fault = efx_mcdi_mac_check_fault, |
| 6209 | .reconfigure_port = efx_mcdi_port_reconfigure, |
| 6210 | .get_wol = efx_ef10_get_wol, |
| 6211 | .set_wol = efx_ef10_set_wol, |
| 6212 | .resume_wol = efx_port_dummy_op_void, |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 6213 | .test_chip = efx_ef10_test_chip, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6214 | .test_nvram = efx_mcdi_nvram_test_all, |
| 6215 | .mcdi_request = efx_ef10_mcdi_request, |
| 6216 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, |
| 6217 | .mcdi_read_response = efx_ef10_mcdi_read_response, |
| 6218 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, |
Daniel Pieczko | c577e59 | 2015-10-09 10:40:35 +0100 | [diff] [blame] | 6219 | .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6220 | .irq_enable_master = efx_port_dummy_op_void, |
| 6221 | .irq_test_generate = efx_ef10_irq_test_generate, |
| 6222 | .irq_disable_non_ev = efx_port_dummy_op_void, |
| 6223 | .irq_handle_msi = efx_ef10_msi_interrupt, |
| 6224 | .irq_handle_legacy = efx_ef10_legacy_interrupt, |
| 6225 | .tx_probe = efx_ef10_tx_probe, |
| 6226 | .tx_init = efx_ef10_tx_init, |
| 6227 | .tx_remove = efx_ef10_tx_remove, |
| 6228 | .tx_write = efx_ef10_tx_write, |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 6229 | .tx_limit_len = efx_ef10_tx_limit_len, |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 6230 | .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config, |
Edward Cree | a707d18 | 2017-01-17 12:02:12 +0000 | [diff] [blame] | 6231 | .rx_pull_rss_config = efx_ef10_rx_pull_rss_config, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6232 | .rx_probe = efx_ef10_rx_probe, |
| 6233 | .rx_init = efx_ef10_rx_init, |
| 6234 | .rx_remove = efx_ef10_rx_remove, |
| 6235 | .rx_write = efx_ef10_rx_write, |
| 6236 | .rx_defer_refill = efx_ef10_rx_defer_refill, |
| 6237 | .ev_probe = efx_ef10_ev_probe, |
| 6238 | .ev_init = efx_ef10_ev_init, |
| 6239 | .ev_fini = efx_ef10_ev_fini, |
| 6240 | .ev_remove = efx_ef10_ev_remove, |
| 6241 | .ev_process = efx_ef10_ev_process, |
| 6242 | .ev_read_ack = efx_ef10_ev_read_ack, |
| 6243 | .ev_test_generate = efx_ef10_ev_test_generate, |
| 6244 | .filter_table_probe = efx_ef10_filter_table_probe, |
| 6245 | .filter_table_restore = efx_ef10_filter_table_restore, |
| 6246 | .filter_table_remove = efx_ef10_filter_table_remove, |
| 6247 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, |
| 6248 | .filter_insert = efx_ef10_filter_insert, |
| 6249 | .filter_remove_safe = efx_ef10_filter_remove_safe, |
| 6250 | .filter_get_safe = efx_ef10_filter_get_safe, |
| 6251 | .filter_clear_rx = efx_ef10_filter_clear_rx, |
| 6252 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, |
| 6253 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, |
| 6254 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, |
| 6255 | #ifdef CONFIG_RFS_ACCEL |
| 6256 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, |
| 6257 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, |
| 6258 | #endif |
| 6259 | #ifdef CONFIG_SFC_MTD |
| 6260 | .mtd_probe = efx_ef10_mtd_probe, |
| 6261 | .mtd_rename = efx_mcdi_mtd_rename, |
| 6262 | .mtd_read = efx_mcdi_mtd_read, |
| 6263 | .mtd_erase = efx_mcdi_mtd_erase, |
| 6264 | .mtd_write = efx_mcdi_mtd_write, |
| 6265 | .mtd_sync = efx_mcdi_mtd_sync, |
| 6266 | #endif |
| 6267 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 6268 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
| 6269 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, |
Andrew Rybchenko | 4a53ea8 | 2016-06-15 17:48:32 +0100 | [diff] [blame] | 6270 | .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid, |
| 6271 | .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 6272 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 6273 | .sriov_configure = efx_ef10_sriov_configure, |
Shradha Shah | d98a4ff | 2014-11-05 12:16:46 +0000 | [diff] [blame] | 6274 | .sriov_init = efx_ef10_sriov_init, |
| 6275 | .sriov_fini = efx_ef10_sriov_fini, |
Shradha Shah | d98a4ff | 2014-11-05 12:16:46 +0000 | [diff] [blame] | 6276 | .sriov_wanted = efx_ef10_sriov_wanted, |
| 6277 | .sriov_reset = efx_ef10_sriov_reset, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 6278 | .sriov_flr = efx_ef10_sriov_flr, |
| 6279 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, |
| 6280 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, |
| 6281 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, |
| 6282 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 6283 | .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state, |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 6284 | .vswitching_probe = efx_ef10_vswitching_probe_pf, |
| 6285 | .vswitching_restore = efx_ef10_vswitching_restore_pf, |
| 6286 | .vswitching_remove = efx_ef10_vswitching_remove_pf, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 6287 | #endif |
Daniel Pieczko | 0d5e0fb | 2015-05-20 11:10:20 +0100 | [diff] [blame] | 6288 | .get_mac_address = efx_ef10_get_mac_address_pf, |
Shradha Shah | 910c878 | 2015-05-20 11:12:48 +0100 | [diff] [blame] | 6289 | .set_mac_address = efx_ef10_set_mac_address, |
Edward Cree | 46d1efd | 2016-11-17 10:52:36 +0000 | [diff] [blame] | 6290 | .tso_versions = efx_ef10_tso_versions, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6291 | |
Bert Kenward | 08a7b29b | 2017-01-10 16:23:33 +0000 | [diff] [blame] | 6292 | .get_phys_port_id = efx_ef10_get_phys_port_id, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6293 | .revision = EFX_REV_HUNT_A0, |
| 6294 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), |
| 6295 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, |
| 6296 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 6297 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6298 | .can_rx_scatter = true, |
| 6299 | .always_rx_scatter = true, |
Edward Cree | de1deff | 2017-01-13 21:20:14 +0000 | [diff] [blame] | 6300 | .option_descriptors = true, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6301 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 6302 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, |
Andrew Rybchenko | 100a9db | 2016-06-15 17:42:26 +0100 | [diff] [blame] | 6303 | .offload_features = EF10_OFFLOAD_FEATURES, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6304 | .mcdi_max_ver = 2, |
| 6305 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 6306 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
| 6307 | 1 << HWTSTAMP_FILTER_ALL, |
Edward Cree | f74d199 | 2017-01-17 12:01:53 +0000 | [diff] [blame] | 6308 | .rx_hash_key_size = 40, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 6309 | }; |