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 |
| 34 | |
| 35 | /* The filter table(s) are managed by firmware and we have write-only |
| 36 | * access. When removing filters we must identify them to the |
| 37 | * firmware by a 64-bit handle, but this is too wide for Linux kernel |
| 38 | * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to |
| 39 | * be able to tell in advance whether a requested insertion will |
| 40 | * replace an existing filter. Therefore we maintain a software hash |
| 41 | * table, which should be at least as large as the hardware hash |
| 42 | * table. |
| 43 | * |
| 44 | * Huntington has a single 8K filter table shared between all filter |
| 45 | * types and both ports. |
| 46 | */ |
| 47 | #define HUNT_FILTER_TBL_ROWS 8192 |
| 48 | |
| 49 | struct efx_ef10_filter_table { |
| 50 | /* The RX match field masks supported by this fw & hw, in order of priority */ |
| 51 | enum efx_filter_match_flags rx_match_flags[ |
| 52 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM]; |
| 53 | unsigned int rx_match_count; |
| 54 | |
| 55 | struct { |
| 56 | unsigned long spec; /* pointer to spec plus flag bits */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 57 | /* BUSY flag indicates that an update is in progress. AUTO_OLD is |
| 58 | * used to mark and sweep MAC filters for the device address lists. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 59 | */ |
| 60 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 61 | #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 62 | #define EFX_EF10_FILTER_FLAGS 3UL |
| 63 | u64 handle; /* firmware handle */ |
| 64 | } *entry; |
| 65 | wait_queue_head_t waitq; |
| 66 | /* Shadow of net_device address lists, guarded by mac_lock */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 67 | #define EFX_EF10_FILTER_DEV_UC_MAX 32 |
| 68 | #define EFX_EF10_FILTER_DEV_MC_MAX 256 |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 69 | struct { |
| 70 | u8 addr[ETH_ALEN]; |
| 71 | u16 id; |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 72 | } dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX], |
| 73 | dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; |
| 74 | int dev_uc_count; /* negative for PROMISC */ |
| 75 | int dev_mc_count; /* negative for PROMISC/ALLMULTI */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* An arbitrary search limit for the software hash table */ |
| 79 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 |
| 80 | |
Andrew Rybchenko | d43050c | 2013-11-14 09:00:27 +0400 | [diff] [blame] | 81 | static void efx_ef10_rx_push_rss_config(struct efx_nic *efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 82 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); |
| 83 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); |
| 84 | |
| 85 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) |
| 86 | { |
| 87 | efx_dword_t reg; |
| 88 | |
| 89 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); |
| 90 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? |
| 91 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; |
| 92 | } |
| 93 | |
| 94 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) |
| 95 | { |
| 96 | return resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]); |
| 97 | } |
| 98 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 99 | static int efx_ef10_init_datapath_caps(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 100 | { |
| 101 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN); |
| 102 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 103 | size_t outlen; |
| 104 | int rc; |
| 105 | |
| 106 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); |
| 107 | |
| 108 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, |
| 109 | outbuf, sizeof(outbuf), &outlen); |
| 110 | if (rc) |
| 111 | return rc; |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 112 | if (outlen < sizeof(outbuf)) { |
| 113 | netif_err(efx, drv, efx->net_dev, |
| 114 | "unable to read datapath firmware capabilities\n"); |
| 115 | return -EIO; |
| 116 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 117 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 118 | nic_data->datapath_caps = |
| 119 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); |
| 120 | |
Daniel Pieczko | 8d9f9dd | 2015-05-06 00:56:55 +0100 | [diff] [blame] | 121 | /* record the DPCPU firmware IDs to determine VEB vswitching support. |
| 122 | */ |
| 123 | nic_data->rx_dpcpu_fw_id = |
| 124 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID); |
| 125 | nic_data->tx_dpcpu_fw_id = |
| 126 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID); |
| 127 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 128 | if (!(nic_data->datapath_caps & |
| 129 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) { |
| 130 | netif_err(efx, drv, efx->net_dev, |
| 131 | "current firmware does not support TSO\n"); |
| 132 | return -ENODEV; |
| 133 | } |
| 134 | |
| 135 | if (!(nic_data->datapath_caps & |
| 136 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { |
| 137 | netif_err(efx, probe, efx->net_dev, |
| 138 | "current firmware does not support an RX prefix\n"); |
| 139 | return -ENODEV; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) |
| 146 | { |
| 147 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); |
| 148 | int rc; |
| 149 | |
| 150 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, |
| 151 | outbuf, sizeof(outbuf), NULL); |
| 152 | if (rc) |
| 153 | return rc; |
| 154 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); |
| 155 | return rc > 0 ? rc : -ERANGE; |
| 156 | } |
| 157 | |
| 158 | static int efx_ef10_get_mac_address(struct efx_nic *efx, u8 *mac_address) |
| 159 | { |
| 160 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); |
| 161 | size_t outlen; |
| 162 | int rc; |
| 163 | |
| 164 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); |
| 165 | |
| 166 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, |
| 167 | outbuf, sizeof(outbuf), &outlen); |
| 168 | if (rc) |
| 169 | return rc; |
| 170 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) |
| 171 | return -EIO; |
| 172 | |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 173 | ether_addr_copy(mac_address, |
| 174 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int efx_ef10_probe(struct efx_nic *efx) |
| 179 | { |
| 180 | struct efx_ef10_nic_data *nic_data; |
| 181 | int i, rc; |
| 182 | |
Ben Hutchings | aa3930e | 2014-02-12 18:59:19 +0000 | [diff] [blame] | 183 | /* We can have one VI for each 8K region. However, until we |
| 184 | * use TX option descriptors we need two TX queues per channel. |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 185 | */ |
| 186 | efx->max_channels = |
| 187 | min_t(unsigned int, |
| 188 | EFX_MAX_CHANNELS, |
| 189 | resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]) / |
| 190 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); |
Edward Cree | 9fd3d3a | 2014-11-03 14:14:35 +0000 | [diff] [blame] | 191 | if (WARN_ON(efx->max_channels == 0)) |
| 192 | return -EIO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 193 | |
| 194 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
| 195 | if (!nic_data) |
| 196 | return -ENOMEM; |
| 197 | efx->nic_data = nic_data; |
| 198 | |
| 199 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, |
| 200 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); |
| 201 | if (rc) |
| 202 | goto fail1; |
| 203 | |
| 204 | /* Get the MC's warm boot count. In case it's rebooting right |
| 205 | * now, be prepared to retry. |
| 206 | */ |
| 207 | i = 0; |
| 208 | for (;;) { |
| 209 | rc = efx_ef10_get_warm_boot_count(efx); |
| 210 | if (rc >= 0) |
| 211 | break; |
| 212 | if (++i == 5) |
| 213 | goto fail2; |
| 214 | ssleep(1); |
| 215 | } |
| 216 | nic_data->warm_boot_count = rc; |
| 217 | |
| 218 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 219 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 220 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 221 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 222 | /* In case we're recovering from a crash (kexec), we want to |
| 223 | * cancel any outstanding request by the previous user of this |
| 224 | * function. We send a special message using the least |
| 225 | * significant bits of the 'high' (doorbell) register. |
| 226 | */ |
| 227 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); |
| 228 | |
| 229 | rc = efx_mcdi_init(efx); |
| 230 | if (rc) |
| 231 | goto fail2; |
| 232 | |
| 233 | /* Reset (most) configuration for this function */ |
| 234 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); |
| 235 | if (rc) |
| 236 | goto fail3; |
| 237 | |
| 238 | /* Enable event logging */ |
| 239 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); |
| 240 | if (rc) |
| 241 | goto fail3; |
| 242 | |
Ben Hutchings | e5a2538 | 2013-09-05 22:50:59 +0100 | [diff] [blame] | 243 | rc = efx_ef10_init_datapath_caps(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 244 | if (rc < 0) |
| 245 | goto fail3; |
| 246 | |
| 247 | efx->rx_packet_len_offset = |
| 248 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; |
| 249 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 250 | rc = efx_mcdi_port_get_number(efx); |
| 251 | if (rc < 0) |
| 252 | goto fail3; |
| 253 | efx->port_num = rc; |
| 254 | |
| 255 | rc = efx_ef10_get_mac_address(efx, efx->net_dev->perm_addr); |
| 256 | if (rc) |
| 257 | goto fail3; |
| 258 | |
| 259 | rc = efx_ef10_get_sysclk_freq(efx); |
| 260 | if (rc < 0) |
| 261 | goto fail3; |
| 262 | efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */ |
| 263 | |
| 264 | /* Check whether firmware supports bug 35388 workaround */ |
| 265 | rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true); |
| 266 | if (rc == 0) |
| 267 | nic_data->workaround_35388 = true; |
| 268 | else if (rc != -ENOSYS && rc != -ENOENT) |
| 269 | goto fail3; |
| 270 | netif_dbg(efx, probe, efx->net_dev, |
| 271 | "workaround for bug 35388 is %sabled\n", |
| 272 | nic_data->workaround_35388 ? "en" : "dis"); |
| 273 | |
| 274 | rc = efx_mcdi_mon_probe(efx); |
| 275 | if (rc) |
| 276 | goto fail3; |
| 277 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 278 | efx_ptp_probe(efx, NULL); |
| 279 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 280 | return 0; |
| 281 | |
| 282 | fail3: |
| 283 | efx_mcdi_fini(efx); |
| 284 | fail2: |
| 285 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 286 | fail1: |
| 287 | kfree(nic_data); |
| 288 | efx->nic_data = NULL; |
| 289 | return rc; |
| 290 | } |
| 291 | |
| 292 | static int efx_ef10_free_vis(struct efx_nic *efx) |
| 293 | { |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 294 | MCDI_DECLARE_BUF_OUT_OR_ERR(outbuf, 0); |
| 295 | size_t outlen; |
| 296 | int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0, |
| 297 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 298 | |
| 299 | /* -EALREADY means nothing to free, so ignore */ |
| 300 | if (rc == -EALREADY) |
| 301 | rc = 0; |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 302 | if (rc) |
| 303 | efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen, |
| 304 | rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 305 | return rc; |
| 306 | } |
| 307 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 308 | #ifdef EFX_USE_PIO |
| 309 | |
| 310 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 311 | { |
| 312 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 313 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN); |
| 314 | unsigned int i; |
| 315 | int rc; |
| 316 | |
| 317 | BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0); |
| 318 | |
| 319 | for (i = 0; i < nic_data->n_piobufs; i++) { |
| 320 | MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE, |
| 321 | nic_data->piobuf_handle[i]); |
| 322 | rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf), |
| 323 | NULL, 0, NULL); |
| 324 | WARN_ON(rc); |
| 325 | } |
| 326 | |
| 327 | nic_data->n_piobufs = 0; |
| 328 | } |
| 329 | |
| 330 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 331 | { |
| 332 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 333 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN); |
| 334 | unsigned int i; |
| 335 | size_t outlen; |
| 336 | int rc = 0; |
| 337 | |
| 338 | BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0); |
| 339 | |
| 340 | for (i = 0; i < n; i++) { |
| 341 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0, |
| 342 | outbuf, sizeof(outbuf), &outlen); |
| 343 | if (rc) |
| 344 | break; |
| 345 | if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) { |
| 346 | rc = -EIO; |
| 347 | break; |
| 348 | } |
| 349 | nic_data->piobuf_handle[i] = |
| 350 | MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE); |
| 351 | netif_dbg(efx, probe, efx->net_dev, |
| 352 | "allocated PIO buffer %u handle %x\n", i, |
| 353 | nic_data->piobuf_handle[i]); |
| 354 | } |
| 355 | |
| 356 | nic_data->n_piobufs = i; |
| 357 | if (rc) |
| 358 | efx_ef10_free_piobufs(efx); |
| 359 | return rc; |
| 360 | } |
| 361 | |
| 362 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 363 | { |
| 364 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 365 | MCDI_DECLARE_BUF(inbuf, |
| 366 | max(MC_CMD_LINK_PIOBUF_IN_LEN, |
| 367 | MC_CMD_UNLINK_PIOBUF_IN_LEN)); |
| 368 | struct efx_channel *channel; |
| 369 | struct efx_tx_queue *tx_queue; |
| 370 | unsigned int offset, index; |
| 371 | int rc; |
| 372 | |
| 373 | BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0); |
| 374 | BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0); |
| 375 | |
| 376 | /* Link a buffer to each VI in the write-combining mapping */ |
| 377 | for (index = 0; index < nic_data->n_piobufs; ++index) { |
| 378 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 379 | nic_data->piobuf_handle[index]); |
| 380 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 381 | nic_data->pio_write_vi_base + index); |
| 382 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 383 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 384 | NULL, 0, NULL); |
| 385 | if (rc) { |
| 386 | netif_err(efx, drv, efx->net_dev, |
| 387 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 388 | nic_data->pio_write_vi_base + index, index, |
| 389 | rc); |
| 390 | goto fail; |
| 391 | } |
| 392 | netif_dbg(efx, probe, efx->net_dev, |
| 393 | "linked VI %u to PIO buffer %u\n", |
| 394 | nic_data->pio_write_vi_base + index, index); |
| 395 | } |
| 396 | |
| 397 | /* Link a buffer to each TX queue */ |
| 398 | efx_for_each_channel(channel, efx) { |
| 399 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 400 | /* We assign the PIO buffers to queues in |
| 401 | * reverse order to allow for the following |
| 402 | * special case. |
| 403 | */ |
| 404 | offset = ((efx->tx_channel_offset + efx->n_tx_channels - |
| 405 | tx_queue->channel->channel - 1) * |
| 406 | efx_piobuf_size); |
| 407 | index = offset / ER_DZ_TX_PIOBUF_SIZE; |
| 408 | offset = offset % ER_DZ_TX_PIOBUF_SIZE; |
| 409 | |
| 410 | /* When the host page size is 4K, the first |
| 411 | * host page in the WC mapping may be within |
| 412 | * the same VI page as the last TX queue. We |
| 413 | * can only link one buffer to each VI. |
| 414 | */ |
| 415 | if (tx_queue->queue == nic_data->pio_write_vi_base) { |
| 416 | BUG_ON(index != 0); |
| 417 | rc = 0; |
| 418 | } else { |
| 419 | MCDI_SET_DWORD(inbuf, |
| 420 | LINK_PIOBUF_IN_PIOBUF_HANDLE, |
| 421 | nic_data->piobuf_handle[index]); |
| 422 | MCDI_SET_DWORD(inbuf, |
| 423 | LINK_PIOBUF_IN_TXQ_INSTANCE, |
| 424 | tx_queue->queue); |
| 425 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, |
| 426 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, |
| 427 | NULL, 0, NULL); |
| 428 | } |
| 429 | |
| 430 | if (rc) { |
| 431 | /* This is non-fatal; the TX path just |
| 432 | * won't use PIO for this queue |
| 433 | */ |
| 434 | netif_err(efx, drv, efx->net_dev, |
| 435 | "failed to link VI %u to PIO buffer %u (%d)\n", |
| 436 | tx_queue->queue, index, rc); |
| 437 | tx_queue->piobuf = NULL; |
| 438 | } else { |
| 439 | tx_queue->piobuf = |
| 440 | nic_data->pio_write_base + |
| 441 | index * EFX_VI_PAGE_SIZE + offset; |
| 442 | tx_queue->piobuf_offset = offset; |
| 443 | netif_dbg(efx, probe, efx->net_dev, |
| 444 | "linked VI %u to PIO buffer %u offset %x addr %p\n", |
| 445 | tx_queue->queue, index, |
| 446 | tx_queue->piobuf_offset, |
| 447 | tx_queue->piobuf); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | |
| 454 | fail: |
| 455 | while (index--) { |
| 456 | MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE, |
| 457 | nic_data->pio_write_vi_base + index); |
| 458 | efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF, |
| 459 | inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN, |
| 460 | NULL, 0, NULL); |
| 461 | } |
| 462 | return rc; |
| 463 | } |
| 464 | |
| 465 | #else /* !EFX_USE_PIO */ |
| 466 | |
| 467 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) |
| 468 | { |
| 469 | return n == 0 ? 0 : -ENOBUFS; |
| 470 | } |
| 471 | |
| 472 | static int efx_ef10_link_piobufs(struct efx_nic *efx) |
| 473 | { |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | static void efx_ef10_free_piobufs(struct efx_nic *efx) |
| 478 | { |
| 479 | } |
| 480 | |
| 481 | #endif /* EFX_USE_PIO */ |
| 482 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 483 | static void efx_ef10_remove(struct efx_nic *efx) |
| 484 | { |
| 485 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 486 | int rc; |
| 487 | |
Ben Hutchings | 9aecda9 | 2013-12-05 21:28:42 +0000 | [diff] [blame] | 488 | efx_ptp_remove(efx); |
| 489 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 490 | efx_mcdi_mon_remove(efx); |
| 491 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 492 | efx_ef10_rx_free_indir_table(efx); |
| 493 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 494 | if (nic_data->wc_membase) |
| 495 | iounmap(nic_data->wc_membase); |
| 496 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 497 | rc = efx_ef10_free_vis(efx); |
| 498 | WARN_ON(rc != 0); |
| 499 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 500 | if (!nic_data->must_restore_piobufs) |
| 501 | efx_ef10_free_piobufs(efx); |
| 502 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 503 | efx_mcdi_fini(efx); |
| 504 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); |
| 505 | kfree(nic_data); |
| 506 | } |
| 507 | |
| 508 | static int efx_ef10_alloc_vis(struct efx_nic *efx, |
| 509 | unsigned int min_vis, unsigned int max_vis) |
| 510 | { |
| 511 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); |
| 512 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); |
| 513 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 514 | size_t outlen; |
| 515 | int rc; |
| 516 | |
| 517 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); |
| 518 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); |
| 519 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), |
| 520 | outbuf, sizeof(outbuf), &outlen); |
| 521 | if (rc != 0) |
| 522 | return rc; |
| 523 | |
| 524 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) |
| 525 | return -EIO; |
| 526 | |
| 527 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", |
| 528 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); |
| 529 | |
| 530 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); |
| 531 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); |
| 532 | return 0; |
| 533 | } |
| 534 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 535 | /* Note that the failure path of this function does not free |
| 536 | * resources, as this will be done by efx_ef10_remove(). |
| 537 | */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 538 | static int efx_ef10_dimension_resources(struct efx_nic *efx) |
| 539 | { |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 540 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 541 | unsigned int uc_mem_map_size, wc_mem_map_size; |
| 542 | unsigned int min_vis, pio_write_vi_base, max_vis; |
| 543 | void __iomem *membase; |
| 544 | int rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 545 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 546 | min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); |
| 547 | |
| 548 | #ifdef EFX_USE_PIO |
| 549 | /* Try to allocate PIO buffers if wanted and if the full |
| 550 | * number of PIO buffers would be sufficient to allocate one |
| 551 | * copy-buffer per TX channel. Failure is non-fatal, as there |
| 552 | * are only a small number of PIO buffers shared between all |
| 553 | * functions of the controller. |
| 554 | */ |
| 555 | if (efx_piobuf_size != 0 && |
| 556 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >= |
| 557 | efx->n_tx_channels) { |
| 558 | unsigned int n_piobufs = |
| 559 | DIV_ROUND_UP(efx->n_tx_channels, |
| 560 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size); |
| 561 | |
| 562 | rc = efx_ef10_alloc_piobufs(efx, n_piobufs); |
| 563 | if (rc) |
| 564 | netif_err(efx, probe, efx->net_dev, |
| 565 | "failed to allocate PIO buffers (%d)\n", rc); |
| 566 | else |
| 567 | netif_dbg(efx, probe, efx->net_dev, |
| 568 | "allocated %u PIO buffers\n", n_piobufs); |
| 569 | } |
| 570 | #else |
| 571 | nic_data->n_piobufs = 0; |
| 572 | #endif |
| 573 | |
| 574 | /* PIO buffers should be mapped with write-combining enabled, |
| 575 | * and we want to make single UC and WC mappings rather than |
| 576 | * several of each (in fact that's the only option if host |
| 577 | * page size is >4K). So we may allocate some extra VIs just |
| 578 | * for writing PIO buffers through. |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 579 | * |
| 580 | * The UC mapping contains (min_vis - 1) complete VIs and the |
| 581 | * first half of the next VI. Then the WC mapping begins with |
| 582 | * the second half of this last VI. |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 583 | */ |
| 584 | uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE + |
| 585 | ER_DZ_TX_PIOBUF); |
| 586 | if (nic_data->n_piobufs) { |
Daniel Pieczko | 52ad762 | 2014-04-01 13:10:34 +0100 | [diff] [blame] | 587 | /* pio_write_vi_base rounds down to give the number of complete |
| 588 | * VIs inside the UC mapping. |
| 589 | */ |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 590 | pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE; |
| 591 | wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base + |
| 592 | nic_data->n_piobufs) * |
| 593 | EFX_VI_PAGE_SIZE) - |
| 594 | uc_mem_map_size); |
| 595 | max_vis = pio_write_vi_base + nic_data->n_piobufs; |
| 596 | } else { |
| 597 | pio_write_vi_base = 0; |
| 598 | wc_mem_map_size = 0; |
| 599 | max_vis = min_vis; |
| 600 | } |
| 601 | |
| 602 | /* In case the last attached driver failed to free VIs, do it now */ |
| 603 | rc = efx_ef10_free_vis(efx); |
| 604 | if (rc != 0) |
| 605 | return rc; |
| 606 | |
| 607 | rc = efx_ef10_alloc_vis(efx, min_vis, max_vis); |
| 608 | if (rc != 0) |
| 609 | return rc; |
| 610 | |
| 611 | /* If we didn't get enough VIs to map all the PIO buffers, free the |
| 612 | * PIO buffers |
| 613 | */ |
| 614 | if (nic_data->n_piobufs && |
| 615 | nic_data->n_allocated_vis < |
| 616 | pio_write_vi_base + nic_data->n_piobufs) { |
| 617 | netif_dbg(efx, probe, efx->net_dev, |
| 618 | "%u VIs are not sufficient to map %u PIO buffers\n", |
| 619 | nic_data->n_allocated_vis, nic_data->n_piobufs); |
| 620 | efx_ef10_free_piobufs(efx); |
| 621 | } |
| 622 | |
| 623 | /* Shrink the original UC mapping of the memory BAR */ |
| 624 | membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size); |
| 625 | if (!membase) { |
| 626 | netif_err(efx, probe, efx->net_dev, |
| 627 | "could not shrink memory BAR to %x\n", |
| 628 | uc_mem_map_size); |
| 629 | return -ENOMEM; |
| 630 | } |
| 631 | iounmap(efx->membase); |
| 632 | efx->membase = membase; |
| 633 | |
| 634 | /* Set up the WC mapping if needed */ |
| 635 | if (wc_mem_map_size) { |
| 636 | nic_data->wc_membase = ioremap_wc(efx->membase_phys + |
| 637 | uc_mem_map_size, |
| 638 | wc_mem_map_size); |
| 639 | if (!nic_data->wc_membase) { |
| 640 | netif_err(efx, probe, efx->net_dev, |
| 641 | "could not allocate WC mapping of size %x\n", |
| 642 | wc_mem_map_size); |
| 643 | return -ENOMEM; |
| 644 | } |
| 645 | nic_data->pio_write_vi_base = pio_write_vi_base; |
| 646 | nic_data->pio_write_base = |
| 647 | nic_data->wc_membase + |
| 648 | (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF - |
| 649 | uc_mem_map_size); |
| 650 | |
| 651 | rc = efx_ef10_link_piobufs(efx); |
| 652 | if (rc) |
| 653 | efx_ef10_free_piobufs(efx); |
| 654 | } |
| 655 | |
| 656 | netif_dbg(efx, probe, efx->net_dev, |
| 657 | "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", |
| 658 | &efx->membase_phys, efx->membase, uc_mem_map_size, |
| 659 | nic_data->wc_membase, wc_mem_map_size); |
| 660 | |
| 661 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static int efx_ef10_init_nic(struct efx_nic *efx) |
| 665 | { |
| 666 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 667 | int rc; |
| 668 | |
Ben Hutchings | a915ccc | 2013-09-05 22:51:55 +0100 | [diff] [blame] | 669 | if (nic_data->must_check_datapath_caps) { |
| 670 | rc = efx_ef10_init_datapath_caps(efx); |
| 671 | if (rc) |
| 672 | return rc; |
| 673 | nic_data->must_check_datapath_caps = false; |
| 674 | } |
| 675 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 676 | if (nic_data->must_realloc_vis) { |
| 677 | /* We cannot let the number of VIs change now */ |
| 678 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, |
| 679 | nic_data->n_allocated_vis); |
| 680 | if (rc) |
| 681 | return rc; |
| 682 | nic_data->must_realloc_vis = false; |
| 683 | } |
| 684 | |
Ben Hutchings | 183233b | 2013-06-28 21:47:12 +0100 | [diff] [blame] | 685 | if (nic_data->must_restore_piobufs && nic_data->n_piobufs) { |
| 686 | rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs); |
| 687 | if (rc == 0) { |
| 688 | rc = efx_ef10_link_piobufs(efx); |
| 689 | if (rc) |
| 690 | efx_ef10_free_piobufs(efx); |
| 691 | } |
| 692 | |
| 693 | /* Log an error on failure, but this is non-fatal */ |
| 694 | if (rc) |
| 695 | netif_err(efx, drv, efx->net_dev, |
| 696 | "failed to restore PIO buffers (%d)\n", rc); |
| 697 | nic_data->must_restore_piobufs = false; |
| 698 | } |
| 699 | |
Andrew Rybchenko | d43050c | 2013-11-14 09:00:27 +0400 | [diff] [blame] | 700 | efx_ef10_rx_push_rss_config(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 704 | static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) |
| 705 | { |
| 706 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 707 | |
| 708 | /* All our allocations have been reset */ |
| 709 | nic_data->must_realloc_vis = true; |
| 710 | nic_data->must_restore_filters = true; |
| 711 | nic_data->must_restore_piobufs = true; |
| 712 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 713 | } |
| 714 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 715 | static int efx_ef10_map_reset_flags(u32 *flags) |
| 716 | { |
| 717 | enum { |
| 718 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << |
| 719 | ETH_RESET_SHARED_SHIFT), |
| 720 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | |
| 721 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | |
| 722 | ETH_RESET_PHY | ETH_RESET_MGMT) << |
| 723 | ETH_RESET_SHARED_SHIFT) |
| 724 | }; |
| 725 | |
| 726 | /* We assume for now that our PCI function is permitted to |
| 727 | * reset everything. |
| 728 | */ |
| 729 | |
| 730 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { |
| 731 | *flags &= ~EF10_RESET_MC; |
| 732 | return RESET_TYPE_WORLD; |
| 733 | } |
| 734 | |
| 735 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { |
| 736 | *flags &= ~EF10_RESET_PORT; |
| 737 | return RESET_TYPE_ALL; |
| 738 | } |
| 739 | |
| 740 | /* no invisible reset implemented */ |
| 741 | |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 745 | static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type) |
| 746 | { |
| 747 | int rc = efx_mcdi_reset(efx, reset_type); |
| 748 | |
| 749 | /* If it was a port reset, trigger reallocation of MC resources. |
| 750 | * Note that on an MC reset nothing needs to be done now because we'll |
| 751 | * detect the MC reset later and handle it then. |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 752 | * For an FLR, we never get an MC reset event, but the MC has reset all |
| 753 | * resources assigned to us, so we have to trigger reallocation now. |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 754 | */ |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 755 | if ((reset_type == RESET_TYPE_ALL || |
| 756 | reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc) |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 757 | efx_ef10_reset_mc_allocations(efx); |
| 758 | return rc; |
| 759 | } |
| 760 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 761 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ |
| 762 | [EF10_STAT_ ## ext_name] = \ |
| 763 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 764 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ |
| 765 | [EF10_STAT_ ## int_name] = \ |
| 766 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } |
| 767 | #define EF10_OTHER_STAT(ext_name) \ |
| 768 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 769 | #define GENERIC_SW_STAT(ext_name) \ |
| 770 | [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 771 | |
| 772 | static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = { |
| 773 | EF10_DMA_STAT(tx_bytes, TX_BYTES), |
| 774 | EF10_DMA_STAT(tx_packets, TX_PKTS), |
| 775 | EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS), |
| 776 | EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS), |
| 777 | EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS), |
| 778 | EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS), |
| 779 | EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS), |
| 780 | EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS), |
| 781 | EF10_DMA_STAT(tx_64, TX_64_PKTS), |
| 782 | EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS), |
| 783 | EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS), |
| 784 | EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS), |
| 785 | EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS), |
| 786 | EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), |
| 787 | EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), |
| 788 | EF10_DMA_STAT(rx_bytes, RX_BYTES), |
| 789 | EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES), |
| 790 | EF10_OTHER_STAT(rx_good_bytes), |
| 791 | EF10_OTHER_STAT(rx_bad_bytes), |
| 792 | EF10_DMA_STAT(rx_packets, RX_PKTS), |
| 793 | EF10_DMA_STAT(rx_good, RX_GOOD_PKTS), |
| 794 | EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS), |
| 795 | EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS), |
| 796 | EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS), |
| 797 | EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS), |
| 798 | EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS), |
| 799 | EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS), |
| 800 | EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS), |
| 801 | EF10_DMA_STAT(rx_64, RX_64_PKTS), |
| 802 | EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS), |
| 803 | EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS), |
| 804 | EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS), |
| 805 | EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS), |
| 806 | EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), |
| 807 | EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), |
| 808 | EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS), |
| 809 | EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS), |
| 810 | EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS), |
| 811 | EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS), |
| 812 | EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS), |
| 813 | EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS), |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 814 | GENERIC_SW_STAT(rx_nodesc_trunc), |
| 815 | GENERIC_SW_STAT(rx_noskb_drops), |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 816 | EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW), |
| 817 | EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW), |
| 818 | EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL), |
| 819 | EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL), |
| 820 | EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB), |
| 821 | EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB), |
| 822 | EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING), |
| 823 | EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS), |
| 824 | EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS), |
| 825 | EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS), |
Shradha Shah | 79ac47a | 2013-11-28 18:48:49 +0000 | [diff] [blame] | 826 | EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS), |
| 827 | EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 828 | }; |
| 829 | |
| 830 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \ |
| 831 | (1ULL << EF10_STAT_tx_packets) | \ |
| 832 | (1ULL << EF10_STAT_tx_pause) | \ |
| 833 | (1ULL << EF10_STAT_tx_unicast) | \ |
| 834 | (1ULL << EF10_STAT_tx_multicast) | \ |
| 835 | (1ULL << EF10_STAT_tx_broadcast) | \ |
| 836 | (1ULL << EF10_STAT_rx_bytes) | \ |
| 837 | (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \ |
| 838 | (1ULL << EF10_STAT_rx_good_bytes) | \ |
| 839 | (1ULL << EF10_STAT_rx_bad_bytes) | \ |
| 840 | (1ULL << EF10_STAT_rx_packets) | \ |
| 841 | (1ULL << EF10_STAT_rx_good) | \ |
| 842 | (1ULL << EF10_STAT_rx_bad) | \ |
| 843 | (1ULL << EF10_STAT_rx_pause) | \ |
| 844 | (1ULL << EF10_STAT_rx_control) | \ |
| 845 | (1ULL << EF10_STAT_rx_unicast) | \ |
| 846 | (1ULL << EF10_STAT_rx_multicast) | \ |
| 847 | (1ULL << EF10_STAT_rx_broadcast) | \ |
| 848 | (1ULL << EF10_STAT_rx_lt64) | \ |
| 849 | (1ULL << EF10_STAT_rx_64) | \ |
| 850 | (1ULL << EF10_STAT_rx_65_to_127) | \ |
| 851 | (1ULL << EF10_STAT_rx_128_to_255) | \ |
| 852 | (1ULL << EF10_STAT_rx_256_to_511) | \ |
| 853 | (1ULL << EF10_STAT_rx_512_to_1023) | \ |
| 854 | (1ULL << EF10_STAT_rx_1024_to_15xx) | \ |
| 855 | (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \ |
| 856 | (1ULL << EF10_STAT_rx_gtjumbo) | \ |
| 857 | (1ULL << EF10_STAT_rx_bad_gtjumbo) | \ |
| 858 | (1ULL << EF10_STAT_rx_overflow) | \ |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 859 | (1ULL << EF10_STAT_rx_nodesc_drops) | \ |
| 860 | (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \ |
| 861 | (1ULL << GENERIC_STAT_rx_noskb_drops)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 862 | |
| 863 | /* These statistics are only provided by the 10G MAC. For a 10G/40G |
| 864 | * switchable port we do not expose these because they might not |
| 865 | * include all the packets they should. |
| 866 | */ |
| 867 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \ |
| 868 | (1ULL << EF10_STAT_tx_lt64) | \ |
| 869 | (1ULL << EF10_STAT_tx_64) | \ |
| 870 | (1ULL << EF10_STAT_tx_65_to_127) | \ |
| 871 | (1ULL << EF10_STAT_tx_128_to_255) | \ |
| 872 | (1ULL << EF10_STAT_tx_256_to_511) | \ |
| 873 | (1ULL << EF10_STAT_tx_512_to_1023) | \ |
| 874 | (1ULL << EF10_STAT_tx_1024_to_15xx) | \ |
| 875 | (1ULL << EF10_STAT_tx_15xx_to_jumbo)) |
| 876 | |
| 877 | /* These statistics are only provided by the 40G MAC. For a 10G/40G |
| 878 | * switchable port we do expose these because the errors will otherwise |
| 879 | * be silent. |
| 880 | */ |
| 881 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \ |
| 882 | (1ULL << EF10_STAT_rx_length_error)) |
| 883 | |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 884 | /* These statistics are only provided if the firmware supports the |
| 885 | * capability PM_AND_RXDP_COUNTERS. |
| 886 | */ |
| 887 | #define HUNT_PM_AND_RXDP_STAT_MASK ( \ |
| 888 | (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \ |
| 889 | (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \ |
| 890 | (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \ |
| 891 | (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \ |
| 892 | (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \ |
| 893 | (1ULL << EF10_STAT_rx_pm_discard_qbb) | \ |
| 894 | (1ULL << EF10_STAT_rx_pm_discard_mapping) | \ |
| 895 | (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \ |
| 896 | (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \ |
| 897 | (1ULL << EF10_STAT_rx_dp_streaming_packets) | \ |
Shradha Shah | 79ac47a | 2013-11-28 18:48:49 +0000 | [diff] [blame] | 898 | (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \ |
| 899 | (1ULL << EF10_STAT_rx_dp_hlb_wait)) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 900 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 901 | static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 902 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 903 | u64 raw_mask = HUNT_COMMON_STAT_MASK; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 904 | u32 port_caps = efx_mcdi_phy_get_caps(efx); |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 905 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 906 | |
| 907 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 908 | raw_mask |= HUNT_40G_EXTRA_STAT_MASK; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 909 | else |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 910 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
Edward Cree | 568d7a0 | 2013-09-25 17:32:09 +0100 | [diff] [blame] | 911 | |
| 912 | if (nic_data->datapath_caps & |
| 913 | (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN)) |
| 914 | raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK; |
| 915 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 916 | return raw_mask; |
| 917 | } |
| 918 | |
| 919 | static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask) |
| 920 | { |
| 921 | u64 raw_mask = efx_ef10_raw_stat_mask(efx); |
| 922 | |
| 923 | #if BITS_PER_LONG == 64 |
| 924 | mask[0] = raw_mask; |
| 925 | #else |
| 926 | mask[0] = raw_mask & 0xffffffff; |
| 927 | mask[1] = raw_mask >> 32; |
| 928 | #endif |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) |
| 932 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 933 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
| 934 | |
| 935 | efx_ef10_get_stat_mask(efx, mask); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 936 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 937 | mask, names); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | static int efx_ef10_try_update_nic_stats(struct efx_nic *efx) |
| 941 | { |
| 942 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 943 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 944 | __le64 generation_start, generation_end; |
| 945 | u64 *stats = nic_data->stats; |
| 946 | __le64 *dma_stats; |
| 947 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 948 | efx_ef10_get_stat_mask(efx, mask); |
| 949 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 950 | dma_stats = efx->stats_buffer.addr; |
| 951 | nic_data = efx->nic_data; |
| 952 | |
| 953 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; |
| 954 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) |
| 955 | return 0; |
| 956 | rmb(); |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 957 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 958 | stats, efx->stats_buffer.addr, false); |
Jon Cooper | d546a89 | 2013-09-27 18:26:30 +0100 | [diff] [blame] | 959 | rmb(); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 960 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
| 961 | if (generation_end != generation_start) |
| 962 | return -EAGAIN; |
| 963 | |
| 964 | /* Update derived statistics */ |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 965 | efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 966 | stats[EF10_STAT_rx_good_bytes] = |
| 967 | stats[EF10_STAT_rx_bytes] - |
| 968 | stats[EF10_STAT_rx_bytes_minus_good_bytes]; |
| 969 | efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes], |
| 970 | stats[EF10_STAT_rx_bytes_minus_good_bytes]); |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 971 | efx_update_sw_stats(efx, stats); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | |
| 976 | static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats, |
| 977 | struct rtnl_link_stats64 *core_stats) |
| 978 | { |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 979 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 980 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 981 | u64 *stats = nic_data->stats; |
| 982 | size_t stats_count = 0, index; |
| 983 | int retry; |
| 984 | |
Edward Cree | 4bae913 | 2013-09-27 18:52:49 +0100 | [diff] [blame] | 985 | efx_ef10_get_stat_mask(efx, mask); |
| 986 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 987 | /* If we're unlucky enough to read statistics during the DMA, wait |
| 988 | * up to 10ms for it to finish (typically takes <500us) |
| 989 | */ |
| 990 | for (retry = 0; retry < 100; ++retry) { |
| 991 | if (efx_ef10_try_update_nic_stats(efx) == 0) |
| 992 | break; |
| 993 | udelay(100); |
| 994 | } |
| 995 | |
| 996 | if (full_stats) { |
| 997 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { |
| 998 | if (efx_ef10_stat_desc[index].name) { |
| 999 | *full_stats++ = stats[index]; |
| 1000 | ++stats_count; |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | if (core_stats) { |
| 1006 | core_stats->rx_packets = stats[EF10_STAT_rx_packets]; |
| 1007 | core_stats->tx_packets = stats[EF10_STAT_tx_packets]; |
| 1008 | core_stats->rx_bytes = stats[EF10_STAT_rx_bytes]; |
| 1009 | core_stats->tx_bytes = stats[EF10_STAT_tx_bytes]; |
Edward Cree | e4d112e | 2014-07-15 11:58:12 +0100 | [diff] [blame] | 1010 | core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] + |
| 1011 | stats[GENERIC_STAT_rx_nodesc_trunc] + |
| 1012 | stats[GENERIC_STAT_rx_noskb_drops]; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1013 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
| 1014 | core_stats->rx_length_errors = |
| 1015 | stats[EF10_STAT_rx_gtjumbo] + |
| 1016 | stats[EF10_STAT_rx_length_error]; |
| 1017 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; |
| 1018 | core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error]; |
| 1019 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; |
| 1020 | core_stats->rx_errors = (core_stats->rx_length_errors + |
| 1021 | core_stats->rx_crc_errors + |
| 1022 | core_stats->rx_frame_errors); |
| 1023 | } |
| 1024 | |
| 1025 | return stats_count; |
| 1026 | } |
| 1027 | |
| 1028 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) |
| 1029 | { |
| 1030 | struct efx_nic *efx = channel->efx; |
| 1031 | unsigned int mode, value; |
| 1032 | efx_dword_t timer_cmd; |
| 1033 | |
| 1034 | if (channel->irq_moderation) { |
| 1035 | mode = 3; |
| 1036 | value = channel->irq_moderation - 1; |
| 1037 | } else { |
| 1038 | mode = 0; |
| 1039 | value = 0; |
| 1040 | } |
| 1041 | |
| 1042 | if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 1043 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, |
| 1044 | EFE_DD_EVQ_IND_TIMER_FLAGS, |
| 1045 | ERF_DD_EVQ_IND_TIMER_MODE, mode, |
| 1046 | ERF_DD_EVQ_IND_TIMER_VAL, value); |
| 1047 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, |
| 1048 | channel->channel); |
| 1049 | } else { |
| 1050 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, |
| 1051 | ERF_DZ_TC_TIMER_VAL, value); |
| 1052 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, |
| 1053 | channel->channel); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 1058 | { |
| 1059 | wol->supported = 0; |
| 1060 | wol->wolopts = 0; |
| 1061 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 1062 | } |
| 1063 | |
| 1064 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) |
| 1065 | { |
| 1066 | if (type != 0) |
| 1067 | return -EINVAL; |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static void efx_ef10_mcdi_request(struct efx_nic *efx, |
| 1072 | const efx_dword_t *hdr, size_t hdr_len, |
| 1073 | const efx_dword_t *sdu, size_t sdu_len) |
| 1074 | { |
| 1075 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1076 | u8 *pdu = nic_data->mcdi_buf.addr; |
| 1077 | |
| 1078 | memcpy(pdu, hdr, hdr_len); |
| 1079 | memcpy(pdu + hdr_len, sdu, sdu_len); |
| 1080 | wmb(); |
| 1081 | |
| 1082 | /* The hardware provides 'low' and 'high' (doorbell) registers |
| 1083 | * for passing the 64-bit address of an MCDI request to |
| 1084 | * firmware. However the dwords are swapped by firmware. The |
| 1085 | * least significant bits of the doorbell are then 0 for all |
| 1086 | * MCDI requests due to alignment. |
| 1087 | */ |
| 1088 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), |
| 1089 | ER_DZ_MC_DB_LWRD); |
| 1090 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), |
| 1091 | ER_DZ_MC_DB_HWRD); |
| 1092 | } |
| 1093 | |
| 1094 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) |
| 1095 | { |
| 1096 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1097 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; |
| 1098 | |
| 1099 | rmb(); |
| 1100 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); |
| 1101 | } |
| 1102 | |
| 1103 | static void |
| 1104 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, |
| 1105 | size_t offset, size_t outlen) |
| 1106 | { |
| 1107 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1108 | const u8 *pdu = nic_data->mcdi_buf.addr; |
| 1109 | |
| 1110 | memcpy(outbuf, pdu + offset, outlen); |
| 1111 | } |
| 1112 | |
| 1113 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) |
| 1114 | { |
| 1115 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1116 | int rc; |
| 1117 | |
| 1118 | rc = efx_ef10_get_warm_boot_count(efx); |
| 1119 | if (rc < 0) { |
| 1120 | /* The firmware is presumably in the process of |
| 1121 | * rebooting. However, we are supposed to report each |
| 1122 | * reboot just once, so we must only do that once we |
| 1123 | * can read and store the updated warm boot count. |
| 1124 | */ |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | if (rc == nic_data->warm_boot_count) |
| 1129 | return 0; |
| 1130 | |
| 1131 | nic_data->warm_boot_count = rc; |
| 1132 | |
| 1133 | /* All our allocations have been reset */ |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 1134 | efx_ef10_reset_mc_allocations(efx); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1135 | |
Ben Hutchings | a915ccc | 2013-09-05 22:51:55 +0100 | [diff] [blame] | 1136 | /* The datapath firmware might have been changed */ |
| 1137 | nic_data->must_check_datapath_caps = true; |
| 1138 | |
Ben Hutchings | 869070c | 2013-09-05 22:46:10 +0100 | [diff] [blame] | 1139 | /* MAC statistics have been cleared on the NIC; clear the local |
| 1140 | * statistic that we update with efx_update_diff_stat(). |
| 1141 | */ |
| 1142 | nic_data->stats[EF10_STAT_rx_bad_bytes] = 0; |
| 1143 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1144 | return -EIO; |
| 1145 | } |
| 1146 | |
| 1147 | /* Handle an MSI interrupt |
| 1148 | * |
| 1149 | * Handle an MSI hardware interrupt. This routine schedules event |
| 1150 | * queue processing. No interrupt acknowledgement cycle is necessary. |
| 1151 | * Also, we never need to check that the interrupt is for us, since |
| 1152 | * MSI interrupts cannot be shared. |
| 1153 | */ |
| 1154 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) |
| 1155 | { |
| 1156 | struct efx_msi_context *context = dev_id; |
| 1157 | struct efx_nic *efx = context->efx; |
| 1158 | |
| 1159 | netif_vdbg(efx, intr, efx->net_dev, |
| 1160 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); |
| 1161 | |
| 1162 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { |
| 1163 | /* Note test interrupts */ |
| 1164 | if (context->index == efx->irq_level) |
| 1165 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 1166 | |
| 1167 | /* Schedule processing of the channel */ |
| 1168 | efx_schedule_channel_irq(efx->channel[context->index]); |
| 1169 | } |
| 1170 | |
| 1171 | return IRQ_HANDLED; |
| 1172 | } |
| 1173 | |
| 1174 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) |
| 1175 | { |
| 1176 | struct efx_nic *efx = dev_id; |
| 1177 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); |
| 1178 | struct efx_channel *channel; |
| 1179 | efx_dword_t reg; |
| 1180 | u32 queues; |
| 1181 | |
| 1182 | /* Read the ISR which also ACKs the interrupts */ |
| 1183 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); |
| 1184 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); |
| 1185 | |
| 1186 | if (queues == 0) |
| 1187 | return IRQ_NONE; |
| 1188 | |
| 1189 | if (likely(soft_enabled)) { |
| 1190 | /* Note test interrupts */ |
| 1191 | if (queues & (1U << efx->irq_level)) |
| 1192 | efx->last_irq_cpu = raw_smp_processor_id(); |
| 1193 | |
| 1194 | efx_for_each_channel(channel, efx) { |
| 1195 | if (queues & 1) |
| 1196 | efx_schedule_channel_irq(channel); |
| 1197 | queues >>= 1; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | netif_vdbg(efx, intr, efx->net_dev, |
| 1202 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", |
| 1203 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); |
| 1204 | |
| 1205 | return IRQ_HANDLED; |
| 1206 | } |
| 1207 | |
| 1208 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) |
| 1209 | { |
| 1210 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); |
| 1211 | |
| 1212 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); |
| 1213 | |
| 1214 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); |
| 1215 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, |
| 1216 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 1217 | } |
| 1218 | |
| 1219 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) |
| 1220 | { |
| 1221 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, |
| 1222 | (tx_queue->ptr_mask + 1) * |
| 1223 | sizeof(efx_qword_t), |
| 1224 | GFP_KERNEL); |
| 1225 | } |
| 1226 | |
| 1227 | /* This writes to the TX_DESC_WPTR and also pushes data */ |
| 1228 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, |
| 1229 | const efx_qword_t *txd) |
| 1230 | { |
| 1231 | unsigned int write_ptr; |
| 1232 | efx_oword_t reg; |
| 1233 | |
| 1234 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1235 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); |
| 1236 | reg.qword[0] = *txd; |
| 1237 | efx_writeo_page(tx_queue->efx, ®, |
| 1238 | ER_DZ_TX_DESC_UPD, tx_queue->queue); |
| 1239 | } |
| 1240 | |
| 1241 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) |
| 1242 | { |
| 1243 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 1244 | EFX_BUF_SIZE)); |
| 1245 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_TXQ_OUT_LEN); |
| 1246 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
| 1247 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; |
| 1248 | struct efx_channel *channel = tx_queue->channel; |
| 1249 | struct efx_nic *efx = tx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1250 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1251 | size_t inlen, outlen; |
| 1252 | dma_addr_t dma_addr; |
| 1253 | efx_qword_t *txd; |
| 1254 | int rc; |
| 1255 | int i; |
| 1256 | |
| 1257 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); |
| 1258 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); |
| 1259 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); |
| 1260 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); |
| 1261 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, |
| 1262 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, |
| 1263 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); |
| 1264 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1265 | 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] | 1266 | |
| 1267 | dma_addr = tx_queue->txd.buf.dma_addr; |
| 1268 | |
| 1269 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", |
| 1270 | tx_queue->queue, entries, (u64)dma_addr); |
| 1271 | |
| 1272 | for (i = 0; i < entries; ++i) { |
| 1273 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); |
| 1274 | dma_addr += EFX_BUF_SIZE; |
| 1275 | } |
| 1276 | |
| 1277 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); |
| 1278 | |
| 1279 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, |
| 1280 | outbuf, sizeof(outbuf), &outlen); |
| 1281 | if (rc) |
| 1282 | goto fail; |
| 1283 | |
| 1284 | /* A previous user of this TX queue might have set us up the |
| 1285 | * bomb by writing a descriptor to the TX push collector but |
| 1286 | * not the doorbell. (Each collector belongs to a port, not a |
| 1287 | * queue or function, so cannot easily be reset.) We must |
| 1288 | * attempt to push a no-op descriptor in its place. |
| 1289 | */ |
| 1290 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; |
| 1291 | tx_queue->insert_count = 1; |
| 1292 | txd = efx_tx_desc(tx_queue, 0); |
| 1293 | EFX_POPULATE_QWORD_4(*txd, |
| 1294 | ESF_DZ_TX_DESC_IS_OPT, true, |
| 1295 | ESF_DZ_TX_OPTION_TYPE, |
| 1296 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, |
| 1297 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, |
| 1298 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); |
| 1299 | tx_queue->write_count = 1; |
| 1300 | wmb(); |
| 1301 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 1302 | |
| 1303 | return; |
| 1304 | |
| 1305 | fail: |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 1306 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
| 1307 | tx_queue->queue); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) |
| 1311 | { |
| 1312 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); |
| 1313 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_TXQ_OUT_LEN); |
| 1314 | struct efx_nic *efx = tx_queue->efx; |
| 1315 | size_t outlen; |
| 1316 | int rc; |
| 1317 | |
| 1318 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, |
| 1319 | tx_queue->queue); |
| 1320 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1321 | 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] | 1322 | outbuf, sizeof(outbuf), &outlen); |
| 1323 | |
| 1324 | if (rc && rc != -EALREADY) |
| 1325 | goto fail; |
| 1326 | |
| 1327 | return; |
| 1328 | |
| 1329 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1330 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
| 1331 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) |
| 1335 | { |
| 1336 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); |
| 1337 | } |
| 1338 | |
| 1339 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ |
| 1340 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) |
| 1341 | { |
| 1342 | unsigned int write_ptr; |
| 1343 | efx_dword_t reg; |
| 1344 | |
| 1345 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1346 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); |
| 1347 | efx_writed_page(tx_queue->efx, ®, |
| 1348 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); |
| 1349 | } |
| 1350 | |
| 1351 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) |
| 1352 | { |
| 1353 | unsigned int old_write_count = tx_queue->write_count; |
| 1354 | struct efx_tx_buffer *buffer; |
| 1355 | unsigned int write_ptr; |
| 1356 | efx_qword_t *txd; |
| 1357 | |
| 1358 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); |
| 1359 | |
| 1360 | do { |
| 1361 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
| 1362 | buffer = &tx_queue->buffer[write_ptr]; |
| 1363 | txd = efx_tx_desc(tx_queue, write_ptr); |
| 1364 | ++tx_queue->write_count; |
| 1365 | |
| 1366 | /* Create TX descriptor ring entry */ |
| 1367 | if (buffer->flags & EFX_TX_BUF_OPTION) { |
| 1368 | *txd = buffer->option; |
| 1369 | } else { |
| 1370 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); |
| 1371 | EFX_POPULATE_QWORD_3( |
| 1372 | *txd, |
| 1373 | ESF_DZ_TX_KER_CONT, |
| 1374 | buffer->flags & EFX_TX_BUF_CONT, |
| 1375 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, |
| 1376 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); |
| 1377 | } |
| 1378 | } while (tx_queue->write_count != tx_queue->insert_count); |
| 1379 | |
| 1380 | wmb(); /* Ensure descriptors are written before they are fetched */ |
| 1381 | |
| 1382 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { |
| 1383 | txd = efx_tx_desc(tx_queue, |
| 1384 | old_write_count & tx_queue->ptr_mask); |
| 1385 | efx_ef10_push_tx_desc(tx_queue, txd); |
| 1386 | ++tx_queue->pushes; |
| 1387 | } else { |
| 1388 | efx_ef10_notify_tx_desc(tx_queue); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context) |
| 1393 | { |
| 1394 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); |
| 1395 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1396 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1397 | size_t outlen; |
| 1398 | int rc; |
| 1399 | |
| 1400 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1401 | nic_data->vport_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1402 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, |
| 1403 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE); |
| 1404 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, |
| 1405 | EFX_MAX_CHANNELS); |
| 1406 | |
| 1407 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), |
| 1408 | outbuf, sizeof(outbuf), &outlen); |
| 1409 | if (rc != 0) |
| 1410 | return rc; |
| 1411 | |
| 1412 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) |
| 1413 | return -EIO; |
| 1414 | |
| 1415 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) |
| 1421 | { |
| 1422 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); |
| 1423 | int rc; |
| 1424 | |
| 1425 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, |
| 1426 | context); |
| 1427 | |
| 1428 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), |
| 1429 | NULL, 0, NULL); |
| 1430 | WARN_ON(rc != 0); |
| 1431 | } |
| 1432 | |
| 1433 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context) |
| 1434 | { |
| 1435 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); |
| 1436 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); |
| 1437 | int i, rc; |
| 1438 | |
| 1439 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, |
| 1440 | context); |
| 1441 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != |
| 1442 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); |
| 1443 | |
| 1444 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) |
| 1445 | MCDI_PTR(tablebuf, |
| 1446 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = |
| 1447 | (u8) efx->rx_indir_table[i]; |
| 1448 | |
| 1449 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, |
| 1450 | sizeof(tablebuf), NULL, 0, NULL); |
| 1451 | if (rc != 0) |
| 1452 | return rc; |
| 1453 | |
| 1454 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, |
| 1455 | context); |
| 1456 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != |
| 1457 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); |
| 1458 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) |
| 1459 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = |
| 1460 | efx->rx_hash_key[i]; |
| 1461 | |
| 1462 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, |
| 1463 | sizeof(keybuf), NULL, 0, NULL); |
| 1464 | } |
| 1465 | |
| 1466 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) |
| 1467 | { |
| 1468 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1469 | |
| 1470 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) |
| 1471 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); |
| 1472 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; |
| 1473 | } |
| 1474 | |
Andrew Rybchenko | d43050c | 2013-11-14 09:00:27 +0400 | [diff] [blame] | 1475 | static void efx_ef10_rx_push_rss_config(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1476 | { |
| 1477 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1478 | int rc; |
| 1479 | |
Andrew Rybchenko | d43050c | 2013-11-14 09:00:27 +0400 | [diff] [blame] | 1480 | netif_dbg(efx, drv, efx->net_dev, "pushing RSS config\n"); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1481 | |
| 1482 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID) { |
| 1483 | rc = efx_ef10_alloc_rss_context(efx, &nic_data->rx_rss_context); |
| 1484 | if (rc != 0) |
| 1485 | goto fail; |
| 1486 | } |
| 1487 | |
| 1488 | rc = efx_ef10_populate_rss_table(efx, nic_data->rx_rss_context); |
| 1489 | if (rc != 0) |
| 1490 | goto fail; |
| 1491 | |
| 1492 | return; |
| 1493 | |
| 1494 | fail: |
| 1495 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
| 1496 | } |
| 1497 | |
| 1498 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) |
| 1499 | { |
| 1500 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, |
| 1501 | (rx_queue->ptr_mask + 1) * |
| 1502 | sizeof(efx_qword_t), |
| 1503 | GFP_KERNEL); |
| 1504 | } |
| 1505 | |
| 1506 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) |
| 1507 | { |
| 1508 | MCDI_DECLARE_BUF(inbuf, |
| 1509 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / |
| 1510 | EFX_BUF_SIZE)); |
| 1511 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_RXQ_OUT_LEN); |
| 1512 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 1513 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; |
| 1514 | struct efx_nic *efx = rx_queue->efx; |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1515 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1516 | size_t inlen, outlen; |
| 1517 | dma_addr_t dma_addr; |
| 1518 | int rc; |
| 1519 | int i; |
| 1520 | |
| 1521 | rx_queue->scatter_n = 0; |
| 1522 | rx_queue->scatter_len = 0; |
| 1523 | |
| 1524 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); |
| 1525 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); |
| 1526 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); |
| 1527 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, |
| 1528 | efx_rx_queue_index(rx_queue)); |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 1529 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
| 1530 | INIT_RXQ_IN_FLAG_PREFIX, 1, |
| 1531 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1532 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 1533 | 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] | 1534 | |
| 1535 | dma_addr = rx_queue->rxd.buf.dma_addr; |
| 1536 | |
| 1537 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", |
| 1538 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); |
| 1539 | |
| 1540 | for (i = 0; i < entries; ++i) { |
| 1541 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); |
| 1542 | dma_addr += EFX_BUF_SIZE; |
| 1543 | } |
| 1544 | |
| 1545 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); |
| 1546 | |
| 1547 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, |
| 1548 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 1549 | if (rc) |
| 1550 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", |
| 1551 | efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) |
| 1555 | { |
| 1556 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); |
| 1557 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_RXQ_OUT_LEN); |
| 1558 | struct efx_nic *efx = rx_queue->efx; |
| 1559 | size_t outlen; |
| 1560 | int rc; |
| 1561 | |
| 1562 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, |
| 1563 | efx_rx_queue_index(rx_queue)); |
| 1564 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1565 | 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] | 1566 | outbuf, sizeof(outbuf), &outlen); |
| 1567 | |
| 1568 | if (rc && rc != -EALREADY) |
| 1569 | goto fail; |
| 1570 | |
| 1571 | return; |
| 1572 | |
| 1573 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1574 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
| 1575 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) |
| 1579 | { |
| 1580 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); |
| 1581 | } |
| 1582 | |
| 1583 | /* This creates an entry in the RX descriptor queue */ |
| 1584 | static inline void |
| 1585 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) |
| 1586 | { |
| 1587 | struct efx_rx_buffer *rx_buf; |
| 1588 | efx_qword_t *rxd; |
| 1589 | |
| 1590 | rxd = efx_rx_desc(rx_queue, index); |
| 1591 | rx_buf = efx_rx_buffer(rx_queue, index); |
| 1592 | EFX_POPULATE_QWORD_2(*rxd, |
| 1593 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, |
| 1594 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); |
| 1595 | } |
| 1596 | |
| 1597 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) |
| 1598 | { |
| 1599 | struct efx_nic *efx = rx_queue->efx; |
| 1600 | unsigned int write_count; |
| 1601 | efx_dword_t reg; |
| 1602 | |
| 1603 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ |
| 1604 | write_count = rx_queue->added_count & ~7; |
| 1605 | if (rx_queue->notified_count == write_count) |
| 1606 | return; |
| 1607 | |
| 1608 | do |
| 1609 | efx_ef10_build_rx_desc( |
| 1610 | rx_queue, |
| 1611 | rx_queue->notified_count & rx_queue->ptr_mask); |
| 1612 | while (++rx_queue->notified_count != write_count); |
| 1613 | |
| 1614 | wmb(); |
| 1615 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, |
| 1616 | write_count & rx_queue->ptr_mask); |
| 1617 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, |
| 1618 | efx_rx_queue_index(rx_queue)); |
| 1619 | } |
| 1620 | |
| 1621 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; |
| 1622 | |
| 1623 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) |
| 1624 | { |
| 1625 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
| 1626 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 1627 | efx_qword_t event; |
| 1628 | |
| 1629 | EFX_POPULATE_QWORD_2(event, |
| 1630 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 1631 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); |
| 1632 | |
| 1633 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 1634 | |
| 1635 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 1636 | * already swapped the data to little-endian order. |
| 1637 | */ |
| 1638 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 1639 | sizeof(efx_qword_t)); |
| 1640 | |
| 1641 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, |
| 1642 | inbuf, sizeof(inbuf), 0, |
| 1643 | efx_ef10_rx_defer_refill_complete, 0); |
| 1644 | } |
| 1645 | |
| 1646 | static void |
| 1647 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, |
| 1648 | int rc, efx_dword_t *outbuf, |
| 1649 | size_t outlen_actual) |
| 1650 | { |
| 1651 | /* nothing to do */ |
| 1652 | } |
| 1653 | |
| 1654 | static int efx_ef10_ev_probe(struct efx_channel *channel) |
| 1655 | { |
| 1656 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, |
| 1657 | (channel->eventq_mask + 1) * |
| 1658 | sizeof(efx_qword_t), |
| 1659 | GFP_KERNEL); |
| 1660 | } |
| 1661 | |
| 1662 | static int efx_ef10_ev_init(struct efx_channel *channel) |
| 1663 | { |
| 1664 | MCDI_DECLARE_BUF(inbuf, |
| 1665 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / |
| 1666 | EFX_BUF_SIZE)); |
| 1667 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); |
| 1668 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; |
| 1669 | struct efx_nic *efx = channel->efx; |
| 1670 | struct efx_ef10_nic_data *nic_data; |
| 1671 | bool supports_rx_merge; |
| 1672 | size_t inlen, outlen; |
| 1673 | dma_addr_t dma_addr; |
| 1674 | int rc; |
| 1675 | int i; |
| 1676 | |
| 1677 | nic_data = efx->nic_data; |
| 1678 | supports_rx_merge = |
| 1679 | !!(nic_data->datapath_caps & |
| 1680 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); |
| 1681 | |
| 1682 | /* Fill event queue with all ones (i.e. empty events) */ |
| 1683 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); |
| 1684 | |
| 1685 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); |
| 1686 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); |
| 1687 | /* INIT_EVQ expects index in vector table, not absolute */ |
| 1688 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); |
| 1689 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, |
| 1690 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, |
| 1691 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, |
| 1692 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, |
| 1693 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); |
| 1694 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, |
| 1695 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); |
| 1696 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); |
| 1697 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); |
| 1698 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, |
| 1699 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); |
| 1700 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); |
| 1701 | |
| 1702 | dma_addr = channel->eventq.buf.dma_addr; |
| 1703 | for (i = 0; i < entries; ++i) { |
| 1704 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); |
| 1705 | dma_addr += EFX_BUF_SIZE; |
| 1706 | } |
| 1707 | |
| 1708 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); |
| 1709 | |
| 1710 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, |
| 1711 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1712 | /* IRQ return is ignored */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1713 | return rc; |
| 1714 | } |
| 1715 | |
| 1716 | static void efx_ef10_ev_fini(struct efx_channel *channel) |
| 1717 | { |
| 1718 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); |
| 1719 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_EVQ_OUT_LEN); |
| 1720 | struct efx_nic *efx = channel->efx; |
| 1721 | size_t outlen; |
| 1722 | int rc; |
| 1723 | |
| 1724 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); |
| 1725 | |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1726 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1727 | outbuf, sizeof(outbuf), &outlen); |
| 1728 | |
| 1729 | if (rc && rc != -EALREADY) |
| 1730 | goto fail; |
| 1731 | |
| 1732 | return; |
| 1733 | |
| 1734 | fail: |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 1735 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
| 1736 | outbuf, outlen, rc); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | static void efx_ef10_ev_remove(struct efx_channel *channel) |
| 1740 | { |
| 1741 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); |
| 1742 | } |
| 1743 | |
| 1744 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, |
| 1745 | unsigned int rx_queue_label) |
| 1746 | { |
| 1747 | struct efx_nic *efx = rx_queue->efx; |
| 1748 | |
| 1749 | netif_info(efx, hw, efx->net_dev, |
| 1750 | "rx event arrived on queue %d labeled as queue %u\n", |
| 1751 | efx_rx_queue_index(rx_queue), rx_queue_label); |
| 1752 | |
| 1753 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 1754 | } |
| 1755 | |
| 1756 | static void |
| 1757 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, |
| 1758 | unsigned int actual, unsigned int expected) |
| 1759 | { |
| 1760 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; |
| 1761 | struct efx_nic *efx = rx_queue->efx; |
| 1762 | |
| 1763 | netif_info(efx, hw, efx->net_dev, |
| 1764 | "dropped %d events (index=%d expected=%d)\n", |
| 1765 | dropped, actual, expected); |
| 1766 | |
| 1767 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
| 1768 | } |
| 1769 | |
| 1770 | /* partially received RX was aborted. clean up. */ |
| 1771 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) |
| 1772 | { |
| 1773 | unsigned int rx_desc_ptr; |
| 1774 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1775 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
| 1776 | "scattered RX aborted (dropping %u buffers)\n", |
| 1777 | rx_queue->scatter_n); |
| 1778 | |
| 1779 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; |
| 1780 | |
| 1781 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, |
| 1782 | 0, EFX_RX_PKT_DISCARD); |
| 1783 | |
| 1784 | rx_queue->removed_count += rx_queue->scatter_n; |
| 1785 | rx_queue->scatter_n = 0; |
| 1786 | rx_queue->scatter_len = 0; |
| 1787 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; |
| 1788 | } |
| 1789 | |
| 1790 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, |
| 1791 | const efx_qword_t *event) |
| 1792 | { |
| 1793 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; |
| 1794 | unsigned int n_descs, n_packets, i; |
| 1795 | struct efx_nic *efx = channel->efx; |
| 1796 | struct efx_rx_queue *rx_queue; |
| 1797 | bool rx_cont; |
| 1798 | u16 flags = 0; |
| 1799 | |
| 1800 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 1801 | return 0; |
| 1802 | |
| 1803 | /* Basic packet information */ |
| 1804 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); |
| 1805 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); |
| 1806 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); |
| 1807 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); |
| 1808 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); |
| 1809 | |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 1810 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
| 1811 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" |
| 1812 | EFX_QWORD_FMT "\n", |
| 1813 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1814 | |
| 1815 | rx_queue = efx_channel_get_rx_queue(channel); |
| 1816 | |
| 1817 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) |
| 1818 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); |
| 1819 | |
| 1820 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & |
| 1821 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 1822 | |
| 1823 | if (n_descs != rx_queue->scatter_n + 1) { |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 1824 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 1825 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1826 | /* detect rx abort */ |
| 1827 | if (unlikely(n_descs == rx_queue->scatter_n)) { |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 1828 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
| 1829 | netdev_WARN(efx->net_dev, |
| 1830 | "invalid RX abort: scatter_n=%u event=" |
| 1831 | EFX_QWORD_FMT "\n", |
| 1832 | rx_queue->scatter_n, |
| 1833 | EFX_QWORD_VAL(*event)); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1834 | efx_ef10_handle_rx_abort(rx_queue); |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
Ben Hutchings | 92a0416 | 2013-09-24 23:21:57 +0100 | [diff] [blame] | 1838 | /* Check that RX completion merging is valid, i.e. |
| 1839 | * the current firmware supports it and this is a |
| 1840 | * non-scattered packet. |
| 1841 | */ |
| 1842 | if (!(nic_data->datapath_caps & |
| 1843 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || |
| 1844 | rx_queue->scatter_n != 0 || rx_cont) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1845 | efx_ef10_handle_rx_bad_lbits( |
| 1846 | rx_queue, next_ptr_lbits, |
| 1847 | (rx_queue->removed_count + |
| 1848 | rx_queue->scatter_n + 1) & |
| 1849 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | /* Merged completion for multiple non-scattered packets */ |
| 1854 | rx_queue->scatter_n = 1; |
| 1855 | rx_queue->scatter_len = 0; |
| 1856 | n_packets = n_descs; |
| 1857 | ++channel->n_rx_merge_events; |
| 1858 | channel->n_rx_merge_packets += n_packets; |
| 1859 | flags |= EFX_RX_PKT_PREFIX_LEN; |
| 1860 | } else { |
| 1861 | ++rx_queue->scatter_n; |
| 1862 | rx_queue->scatter_len += rx_bytes; |
| 1863 | if (rx_cont) |
| 1864 | return 0; |
| 1865 | n_packets = 1; |
| 1866 | } |
| 1867 | |
| 1868 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) |
| 1869 | flags |= EFX_RX_PKT_DISCARD; |
| 1870 | |
| 1871 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { |
| 1872 | channel->n_rx_ip_hdr_chksum_err += n_packets; |
| 1873 | } else if (unlikely(EFX_QWORD_FIELD(*event, |
| 1874 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { |
| 1875 | channel->n_rx_tcp_udp_chksum_err += n_packets; |
| 1876 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || |
| 1877 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { |
| 1878 | flags |= EFX_RX_PKT_CSUMMED; |
| 1879 | } |
| 1880 | |
| 1881 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) |
| 1882 | flags |= EFX_RX_PKT_TCP; |
| 1883 | |
| 1884 | channel->irq_mod_score += 2 * n_packets; |
| 1885 | |
| 1886 | /* Handle received packet(s) */ |
| 1887 | for (i = 0; i < n_packets; i++) { |
| 1888 | efx_rx_packet(rx_queue, |
| 1889 | rx_queue->removed_count & rx_queue->ptr_mask, |
| 1890 | rx_queue->scatter_n, rx_queue->scatter_len, |
| 1891 | flags); |
| 1892 | rx_queue->removed_count += rx_queue->scatter_n; |
| 1893 | } |
| 1894 | |
| 1895 | rx_queue->scatter_n = 0; |
| 1896 | rx_queue->scatter_len = 0; |
| 1897 | |
| 1898 | return n_packets; |
| 1899 | } |
| 1900 | |
| 1901 | static int |
| 1902 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) |
| 1903 | { |
| 1904 | struct efx_nic *efx = channel->efx; |
| 1905 | struct efx_tx_queue *tx_queue; |
| 1906 | unsigned int tx_ev_desc_ptr; |
| 1907 | unsigned int tx_ev_q_label; |
| 1908 | int tx_descs = 0; |
| 1909 | |
| 1910 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) |
| 1911 | return 0; |
| 1912 | |
| 1913 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) |
| 1914 | return 0; |
| 1915 | |
| 1916 | /* Transmit completion */ |
| 1917 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); |
| 1918 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); |
| 1919 | tx_queue = efx_channel_get_tx_queue(channel, |
| 1920 | tx_ev_q_label % EFX_TXQ_TYPES); |
| 1921 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & |
| 1922 | tx_queue->ptr_mask); |
| 1923 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); |
| 1924 | |
| 1925 | return tx_descs; |
| 1926 | } |
| 1927 | |
| 1928 | static void |
| 1929 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) |
| 1930 | { |
| 1931 | struct efx_nic *efx = channel->efx; |
| 1932 | int subcode; |
| 1933 | |
| 1934 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); |
| 1935 | |
| 1936 | switch (subcode) { |
| 1937 | case ESE_DZ_DRV_TIMER_EV: |
| 1938 | case ESE_DZ_DRV_WAKE_UP_EV: |
| 1939 | break; |
| 1940 | case ESE_DZ_DRV_START_UP_EV: |
| 1941 | /* event queue init complete. ok. */ |
| 1942 | break; |
| 1943 | default: |
| 1944 | netif_err(efx, hw, efx->net_dev, |
| 1945 | "channel %d unknown driver event type %d" |
| 1946 | " (data " EFX_QWORD_FMT ")\n", |
| 1947 | channel->channel, subcode, |
| 1948 | EFX_QWORD_VAL(*event)); |
| 1949 | |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, |
| 1954 | efx_qword_t *event) |
| 1955 | { |
| 1956 | struct efx_nic *efx = channel->efx; |
| 1957 | u32 subcode; |
| 1958 | |
| 1959 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); |
| 1960 | |
| 1961 | switch (subcode) { |
| 1962 | case EFX_EF10_TEST: |
| 1963 | channel->event_test_cpu = raw_smp_processor_id(); |
| 1964 | break; |
| 1965 | case EFX_EF10_REFILL: |
| 1966 | /* The queue must be empty, so we won't receive any rx |
| 1967 | * events, so efx_process_channel() won't refill the |
| 1968 | * queue. Refill it here |
| 1969 | */ |
Jon Cooper | cce2879 | 2013-10-02 11:04:14 +0100 | [diff] [blame] | 1970 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1971 | break; |
| 1972 | default: |
| 1973 | netif_err(efx, hw, efx->net_dev, |
| 1974 | "channel %d unknown driver event type %u" |
| 1975 | " (data " EFX_QWORD_FMT ")\n", |
| 1976 | channel->channel, (unsigned) subcode, |
| 1977 | EFX_QWORD_VAL(*event)); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) |
| 1982 | { |
| 1983 | struct efx_nic *efx = channel->efx; |
| 1984 | efx_qword_t event, *p_event; |
| 1985 | unsigned int read_ptr; |
| 1986 | int ev_code; |
| 1987 | int tx_descs = 0; |
| 1988 | int spent = 0; |
| 1989 | |
Eric W. Biederman | 75363a4 | 2014-03-14 18:11:22 -0700 | [diff] [blame] | 1990 | if (quota <= 0) |
| 1991 | return spent; |
| 1992 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1993 | read_ptr = channel->eventq_read_ptr; |
| 1994 | |
| 1995 | for (;;) { |
| 1996 | p_event = efx_event(channel, read_ptr); |
| 1997 | event = *p_event; |
| 1998 | |
| 1999 | if (!efx_event_present(&event)) |
| 2000 | break; |
| 2001 | |
| 2002 | EFX_SET_QWORD(*p_event); |
| 2003 | |
| 2004 | ++read_ptr; |
| 2005 | |
| 2006 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); |
| 2007 | |
| 2008 | netif_vdbg(efx, drv, efx->net_dev, |
| 2009 | "processing event on %d " EFX_QWORD_FMT "\n", |
| 2010 | channel->channel, EFX_QWORD_VAL(event)); |
| 2011 | |
| 2012 | switch (ev_code) { |
| 2013 | case ESE_DZ_EV_CODE_MCDI_EV: |
| 2014 | efx_mcdi_process_event(channel, &event); |
| 2015 | break; |
| 2016 | case ESE_DZ_EV_CODE_RX_EV: |
| 2017 | spent += efx_ef10_handle_rx_event(channel, &event); |
| 2018 | if (spent >= quota) { |
| 2019 | /* XXX can we split a merged event to |
| 2020 | * avoid going over-quota? |
| 2021 | */ |
| 2022 | spent = quota; |
| 2023 | goto out; |
| 2024 | } |
| 2025 | break; |
| 2026 | case ESE_DZ_EV_CODE_TX_EV: |
| 2027 | tx_descs += efx_ef10_handle_tx_event(channel, &event); |
| 2028 | if (tx_descs > efx->txq_entries) { |
| 2029 | spent = quota; |
| 2030 | goto out; |
| 2031 | } else if (++spent == quota) { |
| 2032 | goto out; |
| 2033 | } |
| 2034 | break; |
| 2035 | case ESE_DZ_EV_CODE_DRIVER_EV: |
| 2036 | efx_ef10_handle_driver_event(channel, &event); |
| 2037 | if (++spent == quota) |
| 2038 | goto out; |
| 2039 | break; |
| 2040 | case EFX_EF10_DRVGEN_EV: |
| 2041 | efx_ef10_handle_driver_generated_event(channel, &event); |
| 2042 | break; |
| 2043 | default: |
| 2044 | netif_err(efx, hw, efx->net_dev, |
| 2045 | "channel %d unknown event type %d" |
| 2046 | " (data " EFX_QWORD_FMT ")\n", |
| 2047 | channel->channel, ev_code, |
| 2048 | EFX_QWORD_VAL(event)); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | out: |
| 2053 | channel->eventq_read_ptr = read_ptr; |
| 2054 | return spent; |
| 2055 | } |
| 2056 | |
| 2057 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) |
| 2058 | { |
| 2059 | struct efx_nic *efx = channel->efx; |
| 2060 | efx_dword_t rptr; |
| 2061 | |
| 2062 | if (EFX_EF10_WORKAROUND_35388(efx)) { |
| 2063 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < |
| 2064 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 2065 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > |
| 2066 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); |
| 2067 | |
| 2068 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 2069 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, |
| 2070 | ERF_DD_EVQ_IND_RPTR, |
| 2071 | (channel->eventq_read_ptr & |
| 2072 | channel->eventq_mask) >> |
| 2073 | ERF_DD_EVQ_IND_RPTR_WIDTH); |
| 2074 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 2075 | channel->channel); |
| 2076 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, |
| 2077 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, |
| 2078 | ERF_DD_EVQ_IND_RPTR, |
| 2079 | channel->eventq_read_ptr & |
| 2080 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); |
| 2081 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, |
| 2082 | channel->channel); |
| 2083 | } else { |
| 2084 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, |
| 2085 | channel->eventq_read_ptr & |
| 2086 | channel->eventq_mask); |
| 2087 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) |
| 2092 | { |
| 2093 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); |
| 2094 | struct efx_nic *efx = channel->efx; |
| 2095 | efx_qword_t event; |
| 2096 | int rc; |
| 2097 | |
| 2098 | EFX_POPULATE_QWORD_2(event, |
| 2099 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, |
| 2100 | ESF_DZ_EV_DATA, EFX_EF10_TEST); |
| 2101 | |
| 2102 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); |
| 2103 | |
| 2104 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has |
| 2105 | * already swapped the data to little-endian order. |
| 2106 | */ |
| 2107 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], |
| 2108 | sizeof(efx_qword_t)); |
| 2109 | |
| 2110 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), |
| 2111 | NULL, 0, NULL); |
| 2112 | if (rc != 0) |
| 2113 | goto fail; |
| 2114 | |
| 2115 | return; |
| 2116 | |
| 2117 | fail: |
| 2118 | WARN_ON(true); |
| 2119 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
| 2120 | } |
| 2121 | |
| 2122 | void efx_ef10_handle_drain_event(struct efx_nic *efx) |
| 2123 | { |
| 2124 | if (atomic_dec_and_test(&efx->active_queues)) |
| 2125 | wake_up(&efx->flush_wq); |
| 2126 | |
| 2127 | WARN_ON(atomic_read(&efx->active_queues) < 0); |
| 2128 | } |
| 2129 | |
| 2130 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) |
| 2131 | { |
| 2132 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2133 | struct efx_channel *channel; |
| 2134 | struct efx_tx_queue *tx_queue; |
| 2135 | struct efx_rx_queue *rx_queue; |
| 2136 | int pending; |
| 2137 | |
| 2138 | /* If the MC has just rebooted, the TX/RX queues will have already been |
| 2139 | * torn down, but efx->active_queues needs to be set to zero. |
| 2140 | */ |
| 2141 | if (nic_data->must_realloc_vis) { |
| 2142 | atomic_set(&efx->active_queues, 0); |
| 2143 | return 0; |
| 2144 | } |
| 2145 | |
| 2146 | /* Do not attempt to write to the NIC during EEH recovery */ |
| 2147 | if (efx->state != STATE_RECOVERY) { |
| 2148 | efx_for_each_channel(channel, efx) { |
| 2149 | efx_for_each_channel_rx_queue(rx_queue, channel) |
| 2150 | efx_ef10_rx_fini(rx_queue); |
| 2151 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 2152 | efx_ef10_tx_fini(tx_queue); |
| 2153 | } |
| 2154 | |
| 2155 | wait_event_timeout(efx->flush_wq, |
| 2156 | atomic_read(&efx->active_queues) == 0, |
| 2157 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); |
| 2158 | pending = atomic_read(&efx->active_queues); |
| 2159 | if (pending) { |
| 2160 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", |
| 2161 | pending); |
| 2162 | return -ETIMEDOUT; |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | return 0; |
| 2167 | } |
| 2168 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 2169 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
| 2170 | { |
| 2171 | atomic_set(&efx->active_queues, 0); |
| 2172 | } |
| 2173 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2174 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
| 2175 | const struct efx_filter_spec *right) |
| 2176 | { |
| 2177 | if ((left->match_flags ^ right->match_flags) | |
| 2178 | ((left->flags ^ right->flags) & |
| 2179 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) |
| 2180 | return false; |
| 2181 | |
| 2182 | return memcmp(&left->outer_vid, &right->outer_vid, |
| 2183 | sizeof(struct efx_filter_spec) - |
| 2184 | offsetof(struct efx_filter_spec, outer_vid)) == 0; |
| 2185 | } |
| 2186 | |
| 2187 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) |
| 2188 | { |
| 2189 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); |
| 2190 | return jhash2((const u32 *)&spec->outer_vid, |
| 2191 | (sizeof(struct efx_filter_spec) - |
| 2192 | offsetof(struct efx_filter_spec, outer_vid)) / 4, |
| 2193 | 0); |
| 2194 | /* XXX should we randomise the initval? */ |
| 2195 | } |
| 2196 | |
| 2197 | /* Decide whether a filter should be exclusive or else should allow |
| 2198 | * delivery to additional recipients. Currently we decide that |
| 2199 | * filters for specific local unicast MAC and IP addresses are |
| 2200 | * exclusive. |
| 2201 | */ |
| 2202 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) |
| 2203 | { |
| 2204 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && |
| 2205 | !is_multicast_ether_addr(spec->loc_mac)) |
| 2206 | return true; |
| 2207 | |
| 2208 | if ((spec->match_flags & |
| 2209 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == |
| 2210 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { |
| 2211 | if (spec->ether_type == htons(ETH_P_IP) && |
| 2212 | !ipv4_is_multicast(spec->loc_host[0])) |
| 2213 | return true; |
| 2214 | if (spec->ether_type == htons(ETH_P_IPV6) && |
| 2215 | ((const u8 *)spec->loc_host)[0] != 0xff) |
| 2216 | return true; |
| 2217 | } |
| 2218 | |
| 2219 | return false; |
| 2220 | } |
| 2221 | |
| 2222 | static struct efx_filter_spec * |
| 2223 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, |
| 2224 | unsigned int filter_idx) |
| 2225 | { |
| 2226 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & |
| 2227 | ~EFX_EF10_FILTER_FLAGS); |
| 2228 | } |
| 2229 | |
| 2230 | static unsigned int |
| 2231 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, |
| 2232 | unsigned int filter_idx) |
| 2233 | { |
| 2234 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; |
| 2235 | } |
| 2236 | |
| 2237 | static void |
| 2238 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, |
| 2239 | unsigned int filter_idx, |
| 2240 | const struct efx_filter_spec *spec, |
| 2241 | unsigned int flags) |
| 2242 | { |
| 2243 | table->entry[filter_idx].spec = (unsigned long)spec | flags; |
| 2244 | } |
| 2245 | |
| 2246 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, |
| 2247 | const struct efx_filter_spec *spec, |
| 2248 | efx_dword_t *inbuf, u64 handle, |
| 2249 | bool replacing) |
| 2250 | { |
| 2251 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 2252 | |
| 2253 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); |
| 2254 | |
| 2255 | if (replacing) { |
| 2256 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2257 | MC_CMD_FILTER_OP_IN_OP_REPLACE); |
| 2258 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); |
| 2259 | } else { |
| 2260 | u32 match_fields = 0; |
| 2261 | |
| 2262 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2263 | efx_ef10_filter_is_exclusive(spec) ? |
| 2264 | MC_CMD_FILTER_OP_IN_OP_INSERT : |
| 2265 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); |
| 2266 | |
| 2267 | /* Convert match flags and values. Unlike almost |
| 2268 | * everything else in MCDI, these fields are in |
| 2269 | * network byte order. |
| 2270 | */ |
| 2271 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) |
| 2272 | match_fields |= |
| 2273 | is_multicast_ether_addr(spec->loc_mac) ? |
| 2274 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : |
| 2275 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; |
| 2276 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ |
| 2277 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ |
| 2278 | match_fields |= \ |
| 2279 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ |
| 2280 | mcdi_field ## _LBN; \ |
| 2281 | BUILD_BUG_ON( \ |
| 2282 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ |
| 2283 | sizeof(spec->gen_field)); \ |
| 2284 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ |
| 2285 | &spec->gen_field, sizeof(spec->gen_field)); \ |
| 2286 | } |
| 2287 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); |
| 2288 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); |
| 2289 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); |
| 2290 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); |
| 2291 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); |
| 2292 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); |
| 2293 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); |
| 2294 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); |
| 2295 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); |
| 2296 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); |
| 2297 | #undef COPY_FIELD |
| 2298 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, |
| 2299 | match_fields); |
| 2300 | } |
| 2301 | |
Daniel Pieczko | 45b2449 | 2015-05-06 00:57:14 +0100 | [diff] [blame^] | 2302 | 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] | 2303 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
| 2304 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 2305 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : |
| 2306 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); |
Shradha Shah | e3d3629 | 2015-05-06 00:56:24 +0100 | [diff] [blame] | 2307 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2308 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
| 2309 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); |
Ben Hutchings | a0bc348 | 2013-12-16 18:56:24 +0000 | [diff] [blame] | 2310 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
| 2311 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? |
| 2312 | 0 : spec->dmaq_id); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2313 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
| 2314 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? |
| 2315 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : |
| 2316 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); |
| 2317 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) |
| 2318 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, |
| 2319 | spec->rss_context != |
| 2320 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? |
| 2321 | spec->rss_context : nic_data->rx_rss_context); |
| 2322 | } |
| 2323 | |
| 2324 | static int efx_ef10_filter_push(struct efx_nic *efx, |
| 2325 | const struct efx_filter_spec *spec, |
| 2326 | u64 *handle, bool replacing) |
| 2327 | { |
| 2328 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 2329 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); |
| 2330 | int rc; |
| 2331 | |
| 2332 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); |
| 2333 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 2334 | outbuf, sizeof(outbuf), NULL); |
| 2335 | if (rc == 0) |
| 2336 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
Ben Hutchings | 065e64c | 2013-10-09 14:17:27 +0100 | [diff] [blame] | 2337 | if (rc == -ENOSPC) |
| 2338 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2339 | return rc; |
| 2340 | } |
| 2341 | |
| 2342 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, |
| 2343 | enum efx_filter_match_flags match_flags) |
| 2344 | { |
| 2345 | unsigned int match_pri; |
| 2346 | |
| 2347 | for (match_pri = 0; |
| 2348 | match_pri < table->rx_match_count; |
| 2349 | match_pri++) |
| 2350 | if (table->rx_match_flags[match_pri] == match_flags) |
| 2351 | return match_pri; |
| 2352 | |
| 2353 | return -EPROTONOSUPPORT; |
| 2354 | } |
| 2355 | |
| 2356 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, |
| 2357 | struct efx_filter_spec *spec, |
| 2358 | bool replace_equal) |
| 2359 | { |
| 2360 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2361 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 2362 | struct efx_filter_spec *saved_spec; |
| 2363 | unsigned int match_pri, hash; |
| 2364 | unsigned int priv_flags; |
| 2365 | bool replacing = false; |
| 2366 | int ins_index = -1; |
| 2367 | DEFINE_WAIT(wait); |
| 2368 | bool is_mc_recip; |
| 2369 | s32 rc; |
| 2370 | |
| 2371 | /* For now, only support RX filters */ |
| 2372 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != |
| 2373 | EFX_FILTER_FLAG_RX) |
| 2374 | return -EINVAL; |
| 2375 | |
| 2376 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); |
| 2377 | if (rc < 0) |
| 2378 | return rc; |
| 2379 | match_pri = rc; |
| 2380 | |
| 2381 | hash = efx_ef10_filter_hash(spec); |
| 2382 | is_mc_recip = efx_filter_is_mc_recipient(spec); |
| 2383 | if (is_mc_recip) |
| 2384 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); |
| 2385 | |
| 2386 | /* Find any existing filters with the same match tuple or |
| 2387 | * else a free slot to insert at. If any of them are busy, |
| 2388 | * we have to wait and retry. |
| 2389 | */ |
| 2390 | for (;;) { |
| 2391 | unsigned int depth = 1; |
| 2392 | unsigned int i; |
| 2393 | |
| 2394 | spin_lock_bh(&efx->filter_lock); |
| 2395 | |
| 2396 | for (;;) { |
| 2397 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2398 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 2399 | |
| 2400 | if (!saved_spec) { |
| 2401 | if (ins_index < 0) |
| 2402 | ins_index = i; |
| 2403 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 2404 | if (table->entry[i].spec & |
| 2405 | EFX_EF10_FILTER_FLAG_BUSY) |
| 2406 | break; |
| 2407 | if (spec->priority < saved_spec->priority && |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2408 | spec->priority != EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2409 | rc = -EPERM; |
| 2410 | goto out_unlock; |
| 2411 | } |
| 2412 | if (!is_mc_recip) { |
| 2413 | /* This is the only one */ |
| 2414 | if (spec->priority == |
| 2415 | saved_spec->priority && |
| 2416 | !replace_equal) { |
| 2417 | rc = -EEXIST; |
| 2418 | goto out_unlock; |
| 2419 | } |
| 2420 | ins_index = i; |
| 2421 | goto found; |
| 2422 | } else if (spec->priority > |
| 2423 | saved_spec->priority || |
| 2424 | (spec->priority == |
| 2425 | saved_spec->priority && |
| 2426 | replace_equal)) { |
| 2427 | if (ins_index < 0) |
| 2428 | ins_index = i; |
| 2429 | else |
| 2430 | __set_bit(depth, mc_rem_map); |
| 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | /* Once we reach the maximum search depth, use |
| 2435 | * the first suitable slot or return -EBUSY if |
| 2436 | * there was none |
| 2437 | */ |
| 2438 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 2439 | if (ins_index < 0) { |
| 2440 | rc = -EBUSY; |
| 2441 | goto out_unlock; |
| 2442 | } |
| 2443 | goto found; |
| 2444 | } |
| 2445 | |
| 2446 | ++depth; |
| 2447 | } |
| 2448 | |
| 2449 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 2450 | spin_unlock_bh(&efx->filter_lock); |
| 2451 | schedule(); |
| 2452 | } |
| 2453 | |
| 2454 | found: |
| 2455 | /* Create a software table entry if necessary, and mark it |
| 2456 | * busy. We might yet fail to insert, but any attempt to |
| 2457 | * insert a conflicting filter while we're waiting for the |
| 2458 | * firmware must find the busy entry. |
| 2459 | */ |
| 2460 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 2461 | if (saved_spec) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2462 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
| 2463 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2464 | /* Just make sure it won't be removed */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2465 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
| 2466 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2467 | table->entry[ins_index].spec &= |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2468 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2469 | rc = ins_index; |
| 2470 | goto out_unlock; |
| 2471 | } |
| 2472 | replacing = true; |
| 2473 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); |
| 2474 | } else { |
| 2475 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 2476 | if (!saved_spec) { |
| 2477 | rc = -ENOMEM; |
| 2478 | goto out_unlock; |
| 2479 | } |
| 2480 | *saved_spec = *spec; |
| 2481 | priv_flags = 0; |
| 2482 | } |
| 2483 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 2484 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); |
| 2485 | |
| 2486 | /* Mark lower-priority multicast recipients busy prior to removal */ |
| 2487 | if (is_mc_recip) { |
| 2488 | unsigned int depth, i; |
| 2489 | |
| 2490 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 2491 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2492 | if (test_bit(depth, mc_rem_map)) |
| 2493 | table->entry[i].spec |= |
| 2494 | EFX_EF10_FILTER_FLAG_BUSY; |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | spin_unlock_bh(&efx->filter_lock); |
| 2499 | |
| 2500 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, |
| 2501 | replacing); |
| 2502 | |
| 2503 | /* Finalise the software table entry */ |
| 2504 | spin_lock_bh(&efx->filter_lock); |
| 2505 | if (rc == 0) { |
| 2506 | if (replacing) { |
| 2507 | /* Update the fields that may differ */ |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2508 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
| 2509 | saved_spec->flags |= |
| 2510 | EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2511 | saved_spec->priority = spec->priority; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2512 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2513 | saved_spec->flags |= spec->flags; |
| 2514 | saved_spec->rss_context = spec->rss_context; |
| 2515 | saved_spec->dmaq_id = spec->dmaq_id; |
| 2516 | } |
| 2517 | } else if (!replacing) { |
| 2518 | kfree(saved_spec); |
| 2519 | saved_spec = NULL; |
| 2520 | } |
| 2521 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); |
| 2522 | |
| 2523 | /* Remove and finalise entries for lower-priority multicast |
| 2524 | * recipients |
| 2525 | */ |
| 2526 | if (is_mc_recip) { |
| 2527 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 2528 | unsigned int depth, i; |
| 2529 | |
| 2530 | memset(inbuf, 0, sizeof(inbuf)); |
| 2531 | |
| 2532 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { |
| 2533 | if (!test_bit(depth, mc_rem_map)) |
| 2534 | continue; |
| 2535 | |
| 2536 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2537 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 2538 | priv_flags = efx_ef10_filter_entry_flags(table, i); |
| 2539 | |
| 2540 | if (rc == 0) { |
| 2541 | spin_unlock_bh(&efx->filter_lock); |
| 2542 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2543 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 2544 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 2545 | table->entry[i].handle); |
| 2546 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 2547 | inbuf, sizeof(inbuf), |
| 2548 | NULL, 0, NULL); |
| 2549 | spin_lock_bh(&efx->filter_lock); |
| 2550 | } |
| 2551 | |
| 2552 | if (rc == 0) { |
| 2553 | kfree(saved_spec); |
| 2554 | saved_spec = NULL; |
| 2555 | priv_flags = 0; |
| 2556 | } else { |
| 2557 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 2558 | } |
| 2559 | efx_ef10_filter_set_entry(table, i, saved_spec, |
| 2560 | priv_flags); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | /* If successful, return the inserted filter ID */ |
| 2565 | if (rc == 0) |
| 2566 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; |
| 2567 | |
| 2568 | wake_up_all(&table->waitq); |
| 2569 | out_unlock: |
| 2570 | spin_unlock_bh(&efx->filter_lock); |
| 2571 | finish_wait(&table->waitq, &wait); |
| 2572 | return rc; |
| 2573 | } |
| 2574 | |
Fengguang Wu | 9fd8095d | 2013-08-31 06:54:05 +0800 | [diff] [blame] | 2575 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2576 | { |
| 2577 | /* no need to do anything here on EF10 */ |
| 2578 | } |
| 2579 | |
| 2580 | /* Remove a filter. |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2581 | * If !by_index, remove by ID |
| 2582 | * If by_index, remove by index |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2583 | * Filter ID may come from userland and must be range-checked. |
| 2584 | */ |
| 2585 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2586 | unsigned int priority_mask, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2587 | u32 filter_id, bool by_index) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2588 | { |
| 2589 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 2590 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2591 | MCDI_DECLARE_BUF(inbuf, |
| 2592 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 2593 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 2594 | struct efx_filter_spec *spec; |
| 2595 | DEFINE_WAIT(wait); |
| 2596 | int rc; |
| 2597 | |
| 2598 | /* Find the software table entry and mark it busy. Don't |
| 2599 | * remove it yet; any attempt to update while we're waiting |
| 2600 | * for the firmware must find the busy entry. |
| 2601 | */ |
| 2602 | for (;;) { |
| 2603 | spin_lock_bh(&efx->filter_lock); |
| 2604 | if (!(table->entry[filter_idx].spec & |
| 2605 | EFX_EF10_FILTER_FLAG_BUSY)) |
| 2606 | break; |
| 2607 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); |
| 2608 | spin_unlock_bh(&efx->filter_lock); |
| 2609 | schedule(); |
| 2610 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2611 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2612 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2613 | if (!spec || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2614 | (!by_index && |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2615 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != |
| 2616 | filter_id / HUNT_FILTER_TBL_ROWS)) { |
| 2617 | rc = -ENOENT; |
| 2618 | goto out_unlock; |
| 2619 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2620 | |
| 2621 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2622 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2623 | /* Just remove flags */ |
| 2624 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2625 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2626 | rc = 0; |
| 2627 | goto out_unlock; |
| 2628 | } |
| 2629 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2630 | if (!(priority_mask & (1U << spec->priority))) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2631 | rc = -ENOENT; |
| 2632 | goto out_unlock; |
| 2633 | } |
| 2634 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2635 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 2636 | spin_unlock_bh(&efx->filter_lock); |
| 2637 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2638 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 2639 | /* Reset to an automatic filter */ |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2640 | |
| 2641 | struct efx_filter_spec new_spec = *spec; |
| 2642 | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2643 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2644 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2645 | EFX_FILTER_FLAG_RX_RSS); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2646 | new_spec.dmaq_id = 0; |
| 2647 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; |
| 2648 | rc = efx_ef10_filter_push(efx, &new_spec, |
| 2649 | &table->entry[filter_idx].handle, |
| 2650 | true); |
| 2651 | |
| 2652 | spin_lock_bh(&efx->filter_lock); |
| 2653 | if (rc == 0) |
| 2654 | *spec = new_spec; |
| 2655 | } else { |
| 2656 | /* Really remove the filter */ |
| 2657 | |
| 2658 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2659 | efx_ef10_filter_is_exclusive(spec) ? |
| 2660 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 2661 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 2662 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 2663 | table->entry[filter_idx].handle); |
| 2664 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, |
| 2665 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 2666 | |
| 2667 | spin_lock_bh(&efx->filter_lock); |
| 2668 | if (rc == 0) { |
| 2669 | kfree(spec); |
| 2670 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 2671 | } |
| 2672 | } |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 2673 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2674 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 2675 | wake_up_all(&table->waitq); |
| 2676 | out_unlock: |
| 2677 | spin_unlock_bh(&efx->filter_lock); |
| 2678 | finish_wait(&table->waitq, &wait); |
| 2679 | return rc; |
| 2680 | } |
| 2681 | |
| 2682 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, |
| 2683 | enum efx_filter_priority priority, |
| 2684 | u32 filter_id) |
| 2685 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2686 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
| 2687 | filter_id, false); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, |
| 2691 | enum efx_filter_priority priority, |
| 2692 | u32 filter_id, struct efx_filter_spec *spec) |
| 2693 | { |
| 2694 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; |
| 2695 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2696 | const struct efx_filter_spec *saved_spec; |
| 2697 | int rc; |
| 2698 | |
| 2699 | spin_lock_bh(&efx->filter_lock); |
| 2700 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 2701 | if (saved_spec && saved_spec->priority == priority && |
| 2702 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == |
| 2703 | filter_id / HUNT_FILTER_TBL_ROWS) { |
| 2704 | *spec = *saved_spec; |
| 2705 | rc = 0; |
| 2706 | } else { |
| 2707 | rc = -ENOENT; |
| 2708 | } |
| 2709 | spin_unlock_bh(&efx->filter_lock); |
| 2710 | return rc; |
| 2711 | } |
| 2712 | |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2713 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2714 | enum efx_filter_priority priority) |
| 2715 | { |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 2716 | unsigned int priority_mask; |
| 2717 | unsigned int i; |
| 2718 | int rc; |
| 2719 | |
| 2720 | priority_mask = (((1U << (priority + 1)) - 1) & |
| 2721 | ~(1U << EFX_FILTER_PRI_AUTO)); |
| 2722 | |
| 2723 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 2724 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, |
| 2725 | i, true); |
| 2726 | if (rc && rc != -ENOENT) |
| 2727 | return rc; |
| 2728 | } |
| 2729 | |
| 2730 | return 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, |
| 2734 | enum efx_filter_priority priority) |
| 2735 | { |
| 2736 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2737 | unsigned int filter_idx; |
| 2738 | s32 count = 0; |
| 2739 | |
| 2740 | spin_lock_bh(&efx->filter_lock); |
| 2741 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 2742 | if (table->entry[filter_idx].spec && |
| 2743 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == |
| 2744 | priority) |
| 2745 | ++count; |
| 2746 | } |
| 2747 | spin_unlock_bh(&efx->filter_lock); |
| 2748 | return count; |
| 2749 | } |
| 2750 | |
| 2751 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) |
| 2752 | { |
| 2753 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2754 | |
| 2755 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; |
| 2756 | } |
| 2757 | |
| 2758 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, |
| 2759 | enum efx_filter_priority priority, |
| 2760 | u32 *buf, u32 size) |
| 2761 | { |
| 2762 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2763 | struct efx_filter_spec *spec; |
| 2764 | unsigned int filter_idx; |
| 2765 | s32 count = 0; |
| 2766 | |
| 2767 | spin_lock_bh(&efx->filter_lock); |
| 2768 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 2769 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 2770 | if (spec && spec->priority == priority) { |
| 2771 | if (count == size) { |
| 2772 | count = -EMSGSIZE; |
| 2773 | break; |
| 2774 | } |
| 2775 | buf[count++] = (efx_ef10_filter_rx_match_pri( |
| 2776 | table, spec->match_flags) * |
| 2777 | HUNT_FILTER_TBL_ROWS + |
| 2778 | filter_idx); |
| 2779 | } |
| 2780 | } |
| 2781 | spin_unlock_bh(&efx->filter_lock); |
| 2782 | return count; |
| 2783 | } |
| 2784 | |
| 2785 | #ifdef CONFIG_RFS_ACCEL |
| 2786 | |
| 2787 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; |
| 2788 | |
| 2789 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, |
| 2790 | struct efx_filter_spec *spec) |
| 2791 | { |
| 2792 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2793 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 2794 | struct efx_filter_spec *saved_spec; |
| 2795 | unsigned int hash, i, depth = 1; |
| 2796 | bool replacing = false; |
| 2797 | int ins_index = -1; |
| 2798 | u64 cookie; |
| 2799 | s32 rc; |
| 2800 | |
| 2801 | /* Must be an RX filter without RSS and not for a multicast |
| 2802 | * destination address (RFS only works for connected sockets). |
| 2803 | * These restrictions allow us to pass only a tiny amount of |
| 2804 | * data through to the completion function. |
| 2805 | */ |
| 2806 | EFX_WARN_ON_PARANOID(spec->flags != |
| 2807 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); |
| 2808 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); |
| 2809 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); |
| 2810 | |
| 2811 | hash = efx_ef10_filter_hash(spec); |
| 2812 | |
| 2813 | spin_lock_bh(&efx->filter_lock); |
| 2814 | |
| 2815 | /* Find any existing filter with the same match tuple or else |
| 2816 | * a free slot to insert at. If an existing filter is busy, |
| 2817 | * we have to give up. |
| 2818 | */ |
| 2819 | for (;;) { |
| 2820 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2821 | saved_spec = efx_ef10_filter_entry_spec(table, i); |
| 2822 | |
| 2823 | if (!saved_spec) { |
| 2824 | if (ins_index < 0) |
| 2825 | ins_index = i; |
| 2826 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { |
| 2827 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { |
| 2828 | rc = -EBUSY; |
| 2829 | goto fail_unlock; |
| 2830 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 2831 | if (spec->priority < saved_spec->priority) { |
| 2832 | rc = -EPERM; |
| 2833 | goto fail_unlock; |
| 2834 | } |
| 2835 | ins_index = i; |
| 2836 | break; |
| 2837 | } |
| 2838 | |
| 2839 | /* Once we reach the maximum search depth, use the |
| 2840 | * first suitable slot or return -EBUSY if there was |
| 2841 | * none |
| 2842 | */ |
| 2843 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { |
| 2844 | if (ins_index < 0) { |
| 2845 | rc = -EBUSY; |
| 2846 | goto fail_unlock; |
| 2847 | } |
| 2848 | break; |
| 2849 | } |
| 2850 | |
| 2851 | ++depth; |
| 2852 | } |
| 2853 | |
| 2854 | /* Create a software table entry if necessary, and mark it |
| 2855 | * busy. We might yet fail to insert, but any attempt to |
| 2856 | * insert a conflicting filter while we're waiting for the |
| 2857 | * firmware must find the busy entry. |
| 2858 | */ |
| 2859 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 2860 | if (saved_spec) { |
| 2861 | replacing = true; |
| 2862 | } else { |
| 2863 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); |
| 2864 | if (!saved_spec) { |
| 2865 | rc = -ENOMEM; |
| 2866 | goto fail_unlock; |
| 2867 | } |
| 2868 | *saved_spec = *spec; |
| 2869 | } |
| 2870 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, |
| 2871 | EFX_EF10_FILTER_FLAG_BUSY); |
| 2872 | |
| 2873 | spin_unlock_bh(&efx->filter_lock); |
| 2874 | |
| 2875 | /* Pack up the variables needed on completion */ |
| 2876 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; |
| 2877 | |
| 2878 | efx_ef10_filter_push_prep(efx, spec, inbuf, |
| 2879 | table->entry[ins_index].handle, replacing); |
| 2880 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 2881 | MC_CMD_FILTER_OP_OUT_LEN, |
| 2882 | efx_ef10_filter_rfs_insert_complete, cookie); |
| 2883 | |
| 2884 | return ins_index; |
| 2885 | |
| 2886 | fail_unlock: |
| 2887 | spin_unlock_bh(&efx->filter_lock); |
| 2888 | return rc; |
| 2889 | } |
| 2890 | |
| 2891 | static void |
| 2892 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, |
| 2893 | int rc, efx_dword_t *outbuf, |
| 2894 | size_t outlen_actual) |
| 2895 | { |
| 2896 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2897 | unsigned int ins_index, dmaq_id; |
| 2898 | struct efx_filter_spec *spec; |
| 2899 | bool replacing; |
| 2900 | |
| 2901 | /* Unpack the cookie */ |
| 2902 | replacing = cookie >> 31; |
| 2903 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); |
| 2904 | dmaq_id = cookie & 0xffff; |
| 2905 | |
| 2906 | spin_lock_bh(&efx->filter_lock); |
| 2907 | spec = efx_ef10_filter_entry_spec(table, ins_index); |
| 2908 | if (rc == 0) { |
| 2909 | table->entry[ins_index].handle = |
| 2910 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); |
| 2911 | if (replacing) |
| 2912 | spec->dmaq_id = dmaq_id; |
| 2913 | } else if (!replacing) { |
| 2914 | kfree(spec); |
| 2915 | spec = NULL; |
| 2916 | } |
| 2917 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); |
| 2918 | spin_unlock_bh(&efx->filter_lock); |
| 2919 | |
| 2920 | wake_up_all(&table->waitq); |
| 2921 | } |
| 2922 | |
| 2923 | static void |
| 2924 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 2925 | unsigned long filter_idx, |
| 2926 | int rc, efx_dword_t *outbuf, |
| 2927 | size_t outlen_actual); |
| 2928 | |
| 2929 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, |
| 2930 | unsigned int filter_idx) |
| 2931 | { |
| 2932 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2933 | struct efx_filter_spec *spec = |
| 2934 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 2935 | MCDI_DECLARE_BUF(inbuf, |
| 2936 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + |
| 2937 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); |
| 2938 | |
| 2939 | if (!spec || |
| 2940 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || |
| 2941 | spec->priority != EFX_FILTER_PRI_HINT || |
| 2942 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, |
| 2943 | flow_id, filter_idx)) |
| 2944 | return false; |
| 2945 | |
| 2946 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 2947 | MC_CMD_FILTER_OP_IN_OP_REMOVE); |
| 2948 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 2949 | table->entry[filter_idx].handle); |
| 2950 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, |
| 2951 | efx_ef10_filter_rfs_expire_complete, filter_idx)) |
| 2952 | return false; |
| 2953 | |
| 2954 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 2955 | return true; |
| 2956 | } |
| 2957 | |
| 2958 | static void |
| 2959 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, |
| 2960 | unsigned long filter_idx, |
| 2961 | int rc, efx_dword_t *outbuf, |
| 2962 | size_t outlen_actual) |
| 2963 | { |
| 2964 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 2965 | struct efx_filter_spec *spec = |
| 2966 | efx_ef10_filter_entry_spec(table, filter_idx); |
| 2967 | |
| 2968 | spin_lock_bh(&efx->filter_lock); |
| 2969 | if (rc == 0) { |
| 2970 | kfree(spec); |
| 2971 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 2972 | } |
| 2973 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
| 2974 | wake_up_all(&table->waitq); |
| 2975 | spin_unlock_bh(&efx->filter_lock); |
| 2976 | } |
| 2977 | |
| 2978 | #endif /* CONFIG_RFS_ACCEL */ |
| 2979 | |
| 2980 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) |
| 2981 | { |
| 2982 | int match_flags = 0; |
| 2983 | |
| 2984 | #define MAP_FLAG(gen_flag, mcdi_field) { \ |
| 2985 | u32 old_mcdi_flags = mcdi_flags; \ |
| 2986 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ |
| 2987 | mcdi_field ## _LBN); \ |
| 2988 | if (mcdi_flags != old_mcdi_flags) \ |
| 2989 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ |
| 2990 | } |
| 2991 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); |
| 2992 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); |
| 2993 | MAP_FLAG(REM_HOST, SRC_IP); |
| 2994 | MAP_FLAG(LOC_HOST, DST_IP); |
| 2995 | MAP_FLAG(REM_MAC, SRC_MAC); |
| 2996 | MAP_FLAG(REM_PORT, SRC_PORT); |
| 2997 | MAP_FLAG(LOC_MAC, DST_MAC); |
| 2998 | MAP_FLAG(LOC_PORT, DST_PORT); |
| 2999 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); |
| 3000 | MAP_FLAG(INNER_VID, INNER_VLAN); |
| 3001 | MAP_FLAG(OUTER_VID, OUTER_VLAN); |
| 3002 | MAP_FLAG(IP_PROTO, IP_PROTO); |
| 3003 | #undef MAP_FLAG |
| 3004 | |
| 3005 | /* Did we map them all? */ |
| 3006 | if (mcdi_flags) |
| 3007 | return -EINVAL; |
| 3008 | |
| 3009 | return match_flags; |
| 3010 | } |
| 3011 | |
| 3012 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) |
| 3013 | { |
| 3014 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); |
| 3015 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); |
| 3016 | unsigned int pd_match_pri, pd_match_count; |
| 3017 | struct efx_ef10_filter_table *table; |
| 3018 | size_t outlen; |
| 3019 | int rc; |
| 3020 | |
| 3021 | table = kzalloc(sizeof(*table), GFP_KERNEL); |
| 3022 | if (!table) |
| 3023 | return -ENOMEM; |
| 3024 | |
| 3025 | /* Find out which RX filter types are supported, and their priorities */ |
| 3026 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, |
| 3027 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); |
| 3028 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, |
| 3029 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), |
| 3030 | &outlen); |
| 3031 | if (rc) |
| 3032 | goto fail; |
| 3033 | pd_match_count = MCDI_VAR_ARRAY_LEN( |
| 3034 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); |
| 3035 | table->rx_match_count = 0; |
| 3036 | |
| 3037 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { |
| 3038 | u32 mcdi_flags = |
| 3039 | MCDI_ARRAY_DWORD( |
| 3040 | outbuf, |
| 3041 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, |
| 3042 | pd_match_pri); |
| 3043 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); |
| 3044 | if (rc < 0) { |
| 3045 | netif_dbg(efx, probe, efx->net_dev, |
| 3046 | "%s: fw flags %#x pri %u not supported in driver\n", |
| 3047 | __func__, mcdi_flags, pd_match_pri); |
| 3048 | } else { |
| 3049 | netif_dbg(efx, probe, efx->net_dev, |
| 3050 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", |
| 3051 | __func__, mcdi_flags, pd_match_pri, |
| 3052 | rc, table->rx_match_count); |
| 3053 | table->rx_match_flags[table->rx_match_count++] = rc; |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); |
| 3058 | if (!table->entry) { |
| 3059 | rc = -ENOMEM; |
| 3060 | goto fail; |
| 3061 | } |
| 3062 | |
| 3063 | efx->filter_state = table; |
| 3064 | init_waitqueue_head(&table->waitq); |
| 3065 | return 0; |
| 3066 | |
| 3067 | fail: |
| 3068 | kfree(table); |
| 3069 | return rc; |
| 3070 | } |
| 3071 | |
| 3072 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) |
| 3073 | { |
| 3074 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3075 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 3076 | struct efx_filter_spec *spec; |
| 3077 | unsigned int filter_idx; |
| 3078 | bool failed = false; |
| 3079 | int rc; |
| 3080 | |
| 3081 | if (!nic_data->must_restore_filters) |
| 3082 | return; |
| 3083 | |
| 3084 | spin_lock_bh(&efx->filter_lock); |
| 3085 | |
| 3086 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3087 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3088 | if (!spec) |
| 3089 | continue; |
| 3090 | |
| 3091 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
| 3092 | spin_unlock_bh(&efx->filter_lock); |
| 3093 | |
| 3094 | rc = efx_ef10_filter_push(efx, spec, |
| 3095 | &table->entry[filter_idx].handle, |
| 3096 | false); |
| 3097 | if (rc) |
| 3098 | failed = true; |
| 3099 | |
| 3100 | spin_lock_bh(&efx->filter_lock); |
| 3101 | if (rc) { |
| 3102 | kfree(spec); |
| 3103 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); |
| 3104 | } else { |
| 3105 | table->entry[filter_idx].spec &= |
| 3106 | ~EFX_EF10_FILTER_FLAG_BUSY; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | spin_unlock_bh(&efx->filter_lock); |
| 3111 | |
| 3112 | if (failed) |
| 3113 | netif_err(efx, hw, efx->net_dev, |
| 3114 | "unable to restore all filters\n"); |
| 3115 | else |
| 3116 | nic_data->must_restore_filters = false; |
| 3117 | } |
| 3118 | |
| 3119 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) |
| 3120 | { |
| 3121 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3122 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); |
| 3123 | struct efx_filter_spec *spec; |
| 3124 | unsigned int filter_idx; |
| 3125 | int rc; |
| 3126 | |
| 3127 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
| 3128 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
| 3129 | if (!spec) |
| 3130 | continue; |
| 3131 | |
| 3132 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, |
| 3133 | efx_ef10_filter_is_exclusive(spec) ? |
| 3134 | MC_CMD_FILTER_OP_IN_OP_REMOVE : |
| 3135 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); |
| 3136 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, |
| 3137 | table->entry[filter_idx].handle); |
| 3138 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), |
| 3139 | NULL, 0, NULL); |
Ben Hutchings | 48ce563 | 2013-11-01 16:42:44 +0000 | [diff] [blame] | 3140 | if (rc) |
| 3141 | netdev_WARN(efx->net_dev, |
| 3142 | "filter_idx=%#x handle=%#llx\n", |
| 3143 | filter_idx, |
| 3144 | table->entry[filter_idx].handle); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3145 | kfree(spec); |
| 3146 | } |
| 3147 | |
| 3148 | vfree(table->entry); |
| 3149 | kfree(table); |
| 3150 | } |
| 3151 | |
| 3152 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) |
| 3153 | { |
| 3154 | struct efx_ef10_filter_table *table = efx->filter_state; |
| 3155 | struct net_device *net_dev = efx->net_dev; |
| 3156 | struct efx_filter_spec spec; |
| 3157 | bool remove_failed = false; |
| 3158 | struct netdev_hw_addr *uc; |
| 3159 | struct netdev_hw_addr *mc; |
| 3160 | unsigned int filter_idx; |
| 3161 | int i, n, rc; |
| 3162 | |
| 3163 | if (!efx_dev_registered(efx)) |
| 3164 | return; |
| 3165 | |
| 3166 | /* Mark old filters that may need to be removed */ |
| 3167 | spin_lock_bh(&efx->filter_lock); |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3168 | n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3169 | for (i = 0; i < n; i++) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3170 | filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS; |
| 3171 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3172 | } |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3173 | n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3174 | for (i = 0; i < n; i++) { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3175 | filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS; |
| 3176 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3177 | } |
| 3178 | spin_unlock_bh(&efx->filter_lock); |
| 3179 | |
| 3180 | /* Copy/convert the address lists; add the primary station |
| 3181 | * address and broadcast address |
| 3182 | */ |
| 3183 | netif_addr_lock_bh(net_dev); |
| 3184 | if (net_dev->flags & IFF_PROMISC || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3185 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) { |
| 3186 | table->dev_uc_count = -1; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3187 | } else { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3188 | table->dev_uc_count = 1 + netdev_uc_count(net_dev); |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 3189 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3190 | i = 1; |
| 3191 | netdev_for_each_uc_addr(uc, net_dev) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 3192 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3193 | i++; |
| 3194 | } |
| 3195 | } |
| 3196 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) || |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3197 | netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) { |
| 3198 | table->dev_mc_count = -1; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3199 | } else { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3200 | table->dev_mc_count = 1 + netdev_mc_count(net_dev); |
| 3201 | eth_broadcast_addr(table->dev_mc_list[0].addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3202 | i = 1; |
| 3203 | netdev_for_each_mc_addr(mc, net_dev) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 3204 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3205 | i++; |
| 3206 | } |
| 3207 | } |
| 3208 | netif_addr_unlock_bh(net_dev); |
| 3209 | |
| 3210 | /* Insert/renew unicast filters */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3211 | if (table->dev_uc_count >= 0) { |
| 3212 | for (i = 0; i < table->dev_uc_count; i++) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3213 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3214 | EFX_FILTER_FLAG_RX_RSS, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3215 | 0); |
| 3216 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3217 | table->dev_uc_list[i].addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3218 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3219 | if (rc < 0) { |
| 3220 | /* Fall back to unicast-promisc */ |
| 3221 | while (i--) |
| 3222 | efx_ef10_filter_remove_safe( |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3223 | efx, EFX_FILTER_PRI_AUTO, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3224 | table->dev_uc_list[i].id); |
| 3225 | table->dev_uc_count = -1; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3226 | break; |
| 3227 | } |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3228 | table->dev_uc_list[i].id = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3229 | } |
| 3230 | } |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3231 | if (table->dev_uc_count < 0) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3232 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3233 | EFX_FILTER_FLAG_RX_RSS, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3234 | 0); |
| 3235 | efx_filter_set_uc_def(&spec); |
| 3236 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3237 | if (rc < 0) { |
| 3238 | WARN_ON(1); |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3239 | table->dev_uc_count = 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3240 | } else { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3241 | table->dev_uc_list[0].id = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | /* Insert/renew multicast filters */ |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3246 | if (table->dev_mc_count >= 0) { |
| 3247 | for (i = 0; i < table->dev_mc_count; i++) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3248 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3249 | EFX_FILTER_FLAG_RX_RSS, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3250 | 0); |
| 3251 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3252 | table->dev_mc_list[i].addr); |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3253 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3254 | if (rc < 0) { |
| 3255 | /* Fall back to multicast-promisc */ |
| 3256 | while (i--) |
| 3257 | efx_ef10_filter_remove_safe( |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3258 | efx, EFX_FILTER_PRI_AUTO, |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3259 | table->dev_mc_list[i].id); |
| 3260 | table->dev_mc_count = -1; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3261 | break; |
| 3262 | } |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3263 | table->dev_mc_list[i].id = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3264 | } |
| 3265 | } |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3266 | if (table->dev_mc_count < 0) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3267 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
| 3268 | EFX_FILTER_FLAG_RX_RSS, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3269 | 0); |
| 3270 | efx_filter_set_mc_def(&spec); |
| 3271 | rc = efx_ef10_filter_insert(efx, &spec, true); |
| 3272 | if (rc < 0) { |
| 3273 | WARN_ON(1); |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3274 | table->dev_mc_count = 0; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3275 | } else { |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3276 | table->dev_mc_list[0].id = rc; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | /* Remove filters that weren't renewed. Since nothing else |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3281 | * changes the AUTO_OLD flag or removes these filters, we |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3282 | * don't need to hold the filter_lock while scanning for |
| 3283 | * these filters. |
| 3284 | */ |
| 3285 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { |
| 3286 | if (ACCESS_ONCE(table->entry[i].spec) & |
Ben Hutchings | b59e6ef | 2013-11-21 19:02:22 +0000 | [diff] [blame] | 3287 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
Ben Hutchings | 7665d1a | 2013-11-21 19:02:18 +0000 | [diff] [blame] | 3288 | if (efx_ef10_filter_remove_internal( |
Ben Hutchings | fbd7912 | 2013-11-21 19:15:03 +0000 | [diff] [blame] | 3289 | efx, 1U << EFX_FILTER_PRI_AUTO, |
| 3290 | i, true) < 0) |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3291 | remove_failed = true; |
| 3292 | } |
| 3293 | } |
| 3294 | WARN_ON(remove_failed); |
| 3295 | } |
| 3296 | |
| 3297 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) |
| 3298 | { |
| 3299 | efx_ef10_filter_sync_rx_mode(efx); |
| 3300 | |
| 3301 | return efx_mcdi_set_mac(efx); |
| 3302 | } |
| 3303 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 3304 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
| 3305 | { |
| 3306 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); |
| 3307 | |
| 3308 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); |
| 3309 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), |
| 3310 | NULL, 0, NULL); |
| 3311 | } |
| 3312 | |
| 3313 | /* MC BISTs follow a different poll mechanism to phy BISTs. |
| 3314 | * The BIST is done in the poll handler on the MC, and the MCDI command |
| 3315 | * will block until the BIST is done. |
| 3316 | */ |
| 3317 | static int efx_ef10_poll_bist(struct efx_nic *efx) |
| 3318 | { |
| 3319 | int rc; |
| 3320 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); |
| 3321 | size_t outlen; |
| 3322 | u32 result; |
| 3323 | |
| 3324 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, |
| 3325 | outbuf, sizeof(outbuf), &outlen); |
| 3326 | if (rc != 0) |
| 3327 | return rc; |
| 3328 | |
| 3329 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) |
| 3330 | return -EIO; |
| 3331 | |
| 3332 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); |
| 3333 | switch (result) { |
| 3334 | case MC_CMD_POLL_BIST_PASSED: |
| 3335 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); |
| 3336 | return 0; |
| 3337 | case MC_CMD_POLL_BIST_TIMEOUT: |
| 3338 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); |
| 3339 | return -EIO; |
| 3340 | case MC_CMD_POLL_BIST_FAILED: |
| 3341 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); |
| 3342 | return -EIO; |
| 3343 | default: |
| 3344 | netif_err(efx, hw, efx->net_dev, |
| 3345 | "BIST returned unknown result %u", result); |
| 3346 | return -EIO; |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) |
| 3351 | { |
| 3352 | int rc; |
| 3353 | |
| 3354 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); |
| 3355 | |
| 3356 | rc = efx_ef10_start_bist(efx, bist_type); |
| 3357 | if (rc != 0) |
| 3358 | return rc; |
| 3359 | |
| 3360 | return efx_ef10_poll_bist(efx); |
| 3361 | } |
| 3362 | |
| 3363 | static int |
| 3364 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) |
| 3365 | { |
| 3366 | int rc, rc2; |
| 3367 | |
| 3368 | efx_reset_down(efx, RESET_TYPE_WORLD); |
| 3369 | |
| 3370 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, |
| 3371 | NULL, 0, NULL, 0, NULL); |
| 3372 | if (rc != 0) |
| 3373 | goto out; |
| 3374 | |
| 3375 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; |
| 3376 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; |
| 3377 | |
| 3378 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); |
| 3379 | |
| 3380 | out: |
| 3381 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); |
| 3382 | return rc ? rc : rc2; |
| 3383 | } |
| 3384 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3385 | #ifdef CONFIG_SFC_MTD |
| 3386 | |
| 3387 | struct efx_ef10_nvram_type_info { |
| 3388 | u16 type, type_mask; |
| 3389 | u8 port; |
| 3390 | const char *name; |
| 3391 | }; |
| 3392 | |
| 3393 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { |
| 3394 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, |
| 3395 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, |
| 3396 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, |
| 3397 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, |
| 3398 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, |
| 3399 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, |
| 3400 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, |
| 3401 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, |
| 3402 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, |
Ben Hutchings | a84f3bf9 | 2013-10-09 14:14:41 +0100 | [diff] [blame] | 3403 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3404 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
| 3405 | }; |
| 3406 | |
| 3407 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, |
| 3408 | struct efx_mcdi_mtd_partition *part, |
| 3409 | unsigned int type) |
| 3410 | { |
| 3411 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); |
| 3412 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); |
| 3413 | const struct efx_ef10_nvram_type_info *info; |
| 3414 | size_t size, erase_size, outlen; |
| 3415 | bool protected; |
| 3416 | int rc; |
| 3417 | |
| 3418 | for (info = efx_ef10_nvram_types; ; info++) { |
| 3419 | if (info == |
| 3420 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) |
| 3421 | return -ENODEV; |
| 3422 | if ((type & ~info->type_mask) == info->type) |
| 3423 | break; |
| 3424 | } |
| 3425 | if (info->port != efx_port_num(efx)) |
| 3426 | return -ENODEV; |
| 3427 | |
| 3428 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); |
| 3429 | if (rc) |
| 3430 | return rc; |
| 3431 | if (protected) |
| 3432 | return -ENODEV; /* hide it */ |
| 3433 | |
| 3434 | part->nvram_type = type; |
| 3435 | |
| 3436 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); |
| 3437 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), |
| 3438 | outbuf, sizeof(outbuf), &outlen); |
| 3439 | if (rc) |
| 3440 | return rc; |
| 3441 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) |
| 3442 | return -EIO; |
| 3443 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & |
| 3444 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) |
| 3445 | part->fw_subtype = MCDI_DWORD(outbuf, |
| 3446 | NVRAM_METADATA_OUT_SUBTYPE); |
| 3447 | |
| 3448 | part->common.dev_type_name = "EF10 NVRAM manager"; |
| 3449 | part->common.type_name = info->name; |
| 3450 | |
| 3451 | part->common.mtd.type = MTD_NORFLASH; |
| 3452 | part->common.mtd.flags = MTD_CAP_NORFLASH; |
| 3453 | part->common.mtd.size = size; |
| 3454 | part->common.mtd.erasesize = erase_size; |
| 3455 | |
| 3456 | return 0; |
| 3457 | } |
| 3458 | |
| 3459 | static int efx_ef10_mtd_probe(struct efx_nic *efx) |
| 3460 | { |
| 3461 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); |
| 3462 | struct efx_mcdi_mtd_partition *parts; |
| 3463 | size_t outlen, n_parts_total, i, n_parts; |
| 3464 | unsigned int type; |
| 3465 | int rc; |
| 3466 | |
| 3467 | ASSERT_RTNL(); |
| 3468 | |
| 3469 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); |
| 3470 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, |
| 3471 | outbuf, sizeof(outbuf), &outlen); |
| 3472 | if (rc) |
| 3473 | return rc; |
| 3474 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) |
| 3475 | return -EIO; |
| 3476 | |
| 3477 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); |
| 3478 | if (n_parts_total > |
| 3479 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) |
| 3480 | return -EIO; |
| 3481 | |
| 3482 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); |
| 3483 | if (!parts) |
| 3484 | return -ENOMEM; |
| 3485 | |
| 3486 | n_parts = 0; |
| 3487 | for (i = 0; i < n_parts_total; i++) { |
| 3488 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, |
| 3489 | i); |
| 3490 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); |
| 3491 | if (rc == 0) |
| 3492 | n_parts++; |
| 3493 | else if (rc != -ENODEV) |
| 3494 | goto fail; |
| 3495 | } |
| 3496 | |
| 3497 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); |
| 3498 | fail: |
| 3499 | if (rc) |
| 3500 | kfree(parts); |
| 3501 | return rc; |
| 3502 | } |
| 3503 | |
| 3504 | #endif /* CONFIG_SFC_MTD */ |
| 3505 | |
| 3506 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) |
| 3507 | { |
| 3508 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); |
| 3509 | } |
| 3510 | |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 3511 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
| 3512 | bool temp) |
| 3513 | { |
| 3514 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); |
| 3515 | int rc; |
| 3516 | |
| 3517 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || |
| 3518 | channel->sync_events_state == SYNC_EVENTS_VALID || |
| 3519 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) |
| 3520 | return 0; |
| 3521 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; |
| 3522 | |
| 3523 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); |
| 3524 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 3525 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, |
| 3526 | channel->channel); |
| 3527 | |
| 3528 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 3529 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 3530 | |
| 3531 | if (rc != 0) |
| 3532 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 3533 | SYNC_EVENTS_DISABLED; |
| 3534 | |
| 3535 | return rc; |
| 3536 | } |
| 3537 | |
| 3538 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, |
| 3539 | bool temp) |
| 3540 | { |
| 3541 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); |
| 3542 | int rc; |
| 3543 | |
| 3544 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || |
| 3545 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) |
| 3546 | return 0; |
| 3547 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { |
| 3548 | channel->sync_events_state = SYNC_EVENTS_DISABLED; |
| 3549 | return 0; |
| 3550 | } |
| 3551 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : |
| 3552 | SYNC_EVENTS_DISABLED; |
| 3553 | |
| 3554 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); |
| 3555 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); |
| 3556 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, |
| 3557 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); |
| 3558 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, |
| 3559 | channel->channel); |
| 3560 | |
| 3561 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, |
| 3562 | inbuf, sizeof(inbuf), NULL, 0, NULL); |
| 3563 | |
| 3564 | return rc; |
| 3565 | } |
| 3566 | |
| 3567 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, |
| 3568 | bool temp) |
| 3569 | { |
| 3570 | int (*set)(struct efx_channel *channel, bool temp); |
| 3571 | struct efx_channel *channel; |
| 3572 | |
| 3573 | set = en ? |
| 3574 | efx_ef10_rx_enable_timestamping : |
| 3575 | efx_ef10_rx_disable_timestamping; |
| 3576 | |
| 3577 | efx_for_each_channel(channel, efx) { |
| 3578 | int rc = set(channel, temp); |
| 3579 | if (en && rc != 0) { |
| 3580 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); |
| 3581 | return rc; |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | return 0; |
| 3586 | } |
| 3587 | |
| 3588 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
| 3589 | struct hwtstamp_config *init) |
| 3590 | { |
| 3591 | int rc; |
| 3592 | |
| 3593 | switch (init->rx_filter) { |
| 3594 | case HWTSTAMP_FILTER_NONE: |
| 3595 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); |
| 3596 | /* if TX timestamping is still requested then leave PTP on */ |
| 3597 | return efx_ptp_change_mode(efx, |
| 3598 | init->tx_type != HWTSTAMP_TX_OFF, 0); |
| 3599 | case HWTSTAMP_FILTER_ALL: |
| 3600 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 3601 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 3602 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 3603 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 3604 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 3605 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 3606 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 3607 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 3608 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 3609 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 3610 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 3611 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 3612 | init->rx_filter = HWTSTAMP_FILTER_ALL; |
| 3613 | rc = efx_ptp_change_mode(efx, true, 0); |
| 3614 | if (!rc) |
| 3615 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); |
| 3616 | if (rc) |
| 3617 | efx_ptp_change_mode(efx, false, 0); |
| 3618 | return rc; |
| 3619 | default: |
| 3620 | return -ERANGE; |
| 3621 | } |
| 3622 | } |
| 3623 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3624 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
| 3625 | .mem_map_size = efx_ef10_mem_map_size, |
| 3626 | .probe = efx_ef10_probe, |
| 3627 | .remove = efx_ef10_remove, |
| 3628 | .dimension_resources = efx_ef10_dimension_resources, |
| 3629 | .init = efx_ef10_init_nic, |
| 3630 | .fini = efx_port_dummy_op_void, |
| 3631 | .map_reset_reason = efx_mcdi_map_reset_reason, |
| 3632 | .map_reset_flags = efx_ef10_map_reset_flags, |
Jon Cooper | 3e33626 | 2014-01-17 19:48:06 +0000 | [diff] [blame] | 3633 | .reset = efx_ef10_reset, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3634 | .probe_port = efx_mcdi_port_probe, |
| 3635 | .remove_port = efx_mcdi_port_remove, |
| 3636 | .fini_dmaq = efx_ef10_fini_dmaq, |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 3637 | .prepare_flr = efx_ef10_prepare_flr, |
| 3638 | .finish_flr = efx_port_dummy_op_void, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3639 | .describe_stats = efx_ef10_describe_stats, |
| 3640 | .update_stats = efx_ef10_update_stats, |
| 3641 | .start_stats = efx_mcdi_mac_start_stats, |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 3642 | .pull_stats = efx_mcdi_mac_pull_stats, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3643 | .stop_stats = efx_mcdi_mac_stop_stats, |
| 3644 | .set_id_led = efx_mcdi_set_id_led, |
| 3645 | .push_irq_moderation = efx_ef10_push_irq_moderation, |
| 3646 | .reconfigure_mac = efx_ef10_mac_reconfigure, |
| 3647 | .check_mac_fault = efx_mcdi_mac_check_fault, |
| 3648 | .reconfigure_port = efx_mcdi_port_reconfigure, |
| 3649 | .get_wol = efx_ef10_get_wol, |
| 3650 | .set_wol = efx_ef10_set_wol, |
| 3651 | .resume_wol = efx_port_dummy_op_void, |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 3652 | .test_chip = efx_ef10_test_chip, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3653 | .test_nvram = efx_mcdi_nvram_test_all, |
| 3654 | .mcdi_request = efx_ef10_mcdi_request, |
| 3655 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, |
| 3656 | .mcdi_read_response = efx_ef10_mcdi_read_response, |
| 3657 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, |
| 3658 | .irq_enable_master = efx_port_dummy_op_void, |
| 3659 | .irq_test_generate = efx_ef10_irq_test_generate, |
| 3660 | .irq_disable_non_ev = efx_port_dummy_op_void, |
| 3661 | .irq_handle_msi = efx_ef10_msi_interrupt, |
| 3662 | .irq_handle_legacy = efx_ef10_legacy_interrupt, |
| 3663 | .tx_probe = efx_ef10_tx_probe, |
| 3664 | .tx_init = efx_ef10_tx_init, |
| 3665 | .tx_remove = efx_ef10_tx_remove, |
| 3666 | .tx_write = efx_ef10_tx_write, |
Andrew Rybchenko | d43050c | 2013-11-14 09:00:27 +0400 | [diff] [blame] | 3667 | .rx_push_rss_config = efx_ef10_rx_push_rss_config, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3668 | .rx_probe = efx_ef10_rx_probe, |
| 3669 | .rx_init = efx_ef10_rx_init, |
| 3670 | .rx_remove = efx_ef10_rx_remove, |
| 3671 | .rx_write = efx_ef10_rx_write, |
| 3672 | .rx_defer_refill = efx_ef10_rx_defer_refill, |
| 3673 | .ev_probe = efx_ef10_ev_probe, |
| 3674 | .ev_init = efx_ef10_ev_init, |
| 3675 | .ev_fini = efx_ef10_ev_fini, |
| 3676 | .ev_remove = efx_ef10_ev_remove, |
| 3677 | .ev_process = efx_ef10_ev_process, |
| 3678 | .ev_read_ack = efx_ef10_ev_read_ack, |
| 3679 | .ev_test_generate = efx_ef10_ev_test_generate, |
| 3680 | .filter_table_probe = efx_ef10_filter_table_probe, |
| 3681 | .filter_table_restore = efx_ef10_filter_table_restore, |
| 3682 | .filter_table_remove = efx_ef10_filter_table_remove, |
| 3683 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, |
| 3684 | .filter_insert = efx_ef10_filter_insert, |
| 3685 | .filter_remove_safe = efx_ef10_filter_remove_safe, |
| 3686 | .filter_get_safe = efx_ef10_filter_get_safe, |
| 3687 | .filter_clear_rx = efx_ef10_filter_clear_rx, |
| 3688 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, |
| 3689 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, |
| 3690 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, |
| 3691 | #ifdef CONFIG_RFS_ACCEL |
| 3692 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, |
| 3693 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, |
| 3694 | #endif |
| 3695 | #ifdef CONFIG_SFC_MTD |
| 3696 | .mtd_probe = efx_ef10_mtd_probe, |
| 3697 | .mtd_rename = efx_mcdi_mtd_rename, |
| 3698 | .mtd_read = efx_mcdi_mtd_read, |
| 3699 | .mtd_erase = efx_mcdi_mtd_erase, |
| 3700 | .mtd_write = efx_mcdi_mtd_write, |
| 3701 | .mtd_sync = efx_mcdi_mtd_sync, |
| 3702 | #endif |
| 3703 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 3704 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
| 3705 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3706 | #ifdef CONFIG_SFC_SRIOV |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 3707 | .sriov_configure = efx_ef10_sriov_configure, |
Shradha Shah | d98a4ff | 2014-11-05 12:16:46 +0000 | [diff] [blame] | 3708 | .sriov_init = efx_ef10_sriov_init, |
| 3709 | .sriov_fini = efx_ef10_sriov_fini, |
| 3710 | .sriov_mac_address_changed = efx_ef10_sriov_mac_address_changed, |
| 3711 | .sriov_wanted = efx_ef10_sriov_wanted, |
| 3712 | .sriov_reset = efx_ef10_sriov_reset, |
Shradha Shah | 7fa8d54 | 2015-05-06 00:55:13 +0100 | [diff] [blame] | 3713 | .sriov_flr = efx_ef10_sriov_flr, |
| 3714 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, |
| 3715 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, |
| 3716 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, |
| 3717 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, |
| 3718 | #endif |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3719 | |
| 3720 | .revision = EFX_REV_HUNT_A0, |
| 3721 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), |
| 3722 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, |
| 3723 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 3724 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3725 | .can_rx_scatter = true, |
| 3726 | .always_rx_scatter = true, |
| 3727 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 3728 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, |
| 3729 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 3730 | NETIF_F_RXHASH | NETIF_F_NTUPLE), |
| 3731 | .mcdi_max_ver = 2, |
| 3732 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, |
Jon Cooper | bd9a265 | 2013-11-18 12:54:41 +0000 | [diff] [blame] | 3733 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
| 3734 | 1 << HWTSTAMP_FILTER_ALL, |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 3735 | }; |