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