aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-03-27 13:33:21 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-27 13:33:21 -0400
commit5d22d47b9ed96eddb35821dc2cc4f629f45827f7 (patch)
treea5e601f614c88f93b9b7919153cdbd70d66ab8c5
parentc709002c23f91d90eb6ee2d4efbb548a8fe3cc80 (diff)
parenta8e8fbebde5ded18e94c36220397521021d941ce (diff)
Merge branch 'sfc-filter-locking'
Edward Cree says: ==================== sfc: rework locking around filter management The use of a spinlock to protect filter state combined with the need for a sleeping operation (MCDI) to apply that state to the NIC (on EF10) led to unfixable race conditions, around the handling of filter restoration after an MC reboot. So, this patch series removes the requirement to be able to modify the SW filter table from atomic context, by using a workqueue to request asynchronous filter operations (which are needed for ARFS). Then, the filter table locks are changed to mutexes, replacing the dance of spinlocks and 'busy' flags. Also, a mutex is added to protect the RSS context state, since otherwise a similar race is possible around restoring that after an MC reboot. While we're at it, fix a couple of other related bugs. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/sfc/ef10.c545
-rw-r--r--drivers/net/ethernet/sfc/efx.c30
-rw-r--r--drivers/net/ethernet/sfc/efx.h11
-rw-r--r--drivers/net/ethernet/sfc/ethtool.c77
-rw-r--r--drivers/net/ethernet/sfc/farch.c80
-rw-r--r--drivers/net/ethernet/sfc/net_driver.h16
-rw-r--r--drivers/net/ethernet/sfc/nic.h5
-rw-r--r--drivers/net/ethernet/sfc/rx.c119
-rw-r--r--drivers/net/ethernet/sfc/siena.c1
9 files changed, 400 insertions, 484 deletions
diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c
index e100273b623d..c4c45c94da77 100644
--- a/drivers/net/ethernet/sfc/ef10.c
+++ b/drivers/net/ethernet/sfc/ef10.c
@@ -96,17 +96,15 @@ struct efx_ef10_filter_table {
96 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2]; 96 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
97 unsigned int rx_match_count; 97 unsigned int rx_match_count;
98 98
99 struct rw_semaphore lock; /* Protects entries */
99 struct { 100 struct {
100 unsigned long spec; /* pointer to spec plus flag bits */ 101 unsigned long spec; /* pointer to spec plus flag bits */
101/* BUSY flag indicates that an update is in progress. AUTO_OLD is 102/* AUTO_OLD is used to mark and sweep MAC filters for the device address lists. */
102 * used to mark and sweep MAC filters for the device address lists. 103/* unused flag 1UL */
103 */
104#define EFX_EF10_FILTER_FLAG_BUSY 1UL
105#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL 104#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
106#define EFX_EF10_FILTER_FLAGS 3UL 105#define EFX_EF10_FILTER_FLAGS 3UL
107 u64 handle; /* firmware handle */ 106 u64 handle; /* firmware handle */
108 } *entry; 107 } *entry;
109 wait_queue_head_t waitq;
110/* Shadow of net_device address lists, guarded by mac_lock */ 108/* Shadow of net_device address lists, guarded by mac_lock */
111 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX]; 109 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
112 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; 110 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
@@ -1501,6 +1499,7 @@ static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1501 1499
1502 /* All our allocations have been reset */ 1500 /* All our allocations have been reset */
1503 nic_data->must_realloc_vis = true; 1501 nic_data->must_realloc_vis = true;
1502 nic_data->must_restore_rss_contexts = true;
1504 nic_data->must_restore_filters = true; 1503 nic_data->must_restore_filters = true;
1505 nic_data->must_restore_piobufs = true; 1504 nic_data->must_restore_piobufs = true;
1506 efx_ef10_forget_old_piobufs(efx); 1505 efx_ef10_forget_old_piobufs(efx);
@@ -2901,6 +2900,8 @@ static int efx_ef10_rx_push_rss_context_config(struct efx_nic *efx,
2901{ 2900{
2902 int rc; 2901 int rc;
2903 2902
2903 WARN_ON(!mutex_is_locked(&efx->rss_lock));
2904
2904 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) { 2905 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
2905 rc = efx_ef10_alloc_rss_context(efx, true, ctx, NULL); 2906 rc = efx_ef10_alloc_rss_context(efx, true, ctx, NULL);
2906 if (rc) 2907 if (rc)
@@ -2931,6 +2932,8 @@ static int efx_ef10_rx_pull_rss_context_config(struct efx_nic *efx,
2931 size_t outlen; 2932 size_t outlen;
2932 int rc, i; 2933 int rc, i;
2933 2934
2935 WARN_ON(!mutex_is_locked(&efx->rss_lock));
2936
2934 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN != 2937 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2935 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN); 2938 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2936 2939
@@ -2974,14 +2977,25 @@ static int efx_ef10_rx_pull_rss_context_config(struct efx_nic *efx,
2974 2977
2975static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx) 2978static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2976{ 2979{
2977 return efx_ef10_rx_pull_rss_context_config(efx, &efx->rss_context); 2980 int rc;
2981
2982 mutex_lock(&efx->rss_lock);
2983 rc = efx_ef10_rx_pull_rss_context_config(efx, &efx->rss_context);
2984 mutex_unlock(&efx->rss_lock);
2985 return rc;
2978} 2986}
2979 2987
2980static void efx_ef10_rx_restore_rss_contexts(struct efx_nic *efx) 2988static void efx_ef10_rx_restore_rss_contexts(struct efx_nic *efx)
2981{ 2989{
2990 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2982 struct efx_rss_context *ctx; 2991 struct efx_rss_context *ctx;
2983 int rc; 2992 int rc;
2984 2993
2994 WARN_ON(!mutex_is_locked(&efx->rss_lock));
2995
2996 if (!nic_data->must_restore_rss_contexts)
2997 return;
2998
2985 list_for_each_entry(ctx, &efx->rss_context.list, list) { 2999 list_for_each_entry(ctx, &efx->rss_context.list, list) {
2986 /* previous NIC RSS context is gone */ 3000 /* previous NIC RSS context is gone */
2987 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID; 3001 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
@@ -2995,6 +3009,7 @@ static void efx_ef10_rx_restore_rss_contexts(struct efx_nic *efx)
2995 "; RSS filters may fail to be applied\n", 3009 "; RSS filters may fail to be applied\n",
2996 ctx->user_id, rc); 3010 ctx->user_id, rc);
2997 } 3011 }
3012 nic_data->must_restore_rss_contexts = false;
2998} 3013}
2999 3014
3000static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user, 3015static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
@@ -4302,26 +4317,35 @@ static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4302 struct efx_filter_spec *spec, 4317 struct efx_filter_spec *spec,
4303 bool replace_equal) 4318 bool replace_equal)
4304{ 4319{
4305 struct efx_ef10_filter_table *table = efx->filter_state;
4306 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); 4320 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4321 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4322 struct efx_ef10_filter_table *table;
4307 struct efx_filter_spec *saved_spec; 4323 struct efx_filter_spec *saved_spec;
4308 struct efx_rss_context *ctx = NULL; 4324 struct efx_rss_context *ctx = NULL;
4309 unsigned int match_pri, hash; 4325 unsigned int match_pri, hash;
4310 unsigned int priv_flags; 4326 unsigned int priv_flags;
4327 bool rss_locked = false;
4311 bool replacing = false; 4328 bool replacing = false;
4329 unsigned int depth, i;
4312 int ins_index = -1; 4330 int ins_index = -1;
4313 DEFINE_WAIT(wait); 4331 DEFINE_WAIT(wait);
4314 bool is_mc_recip; 4332 bool is_mc_recip;
4315 s32 rc; 4333 s32 rc;
4316 4334
4335 down_read(&efx->filter_sem);
4336 table = efx->filter_state;
4337 down_write(&table->lock);
4338
4317 /* For now, only support RX filters */ 4339 /* For now, only support RX filters */
4318 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != 4340 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4319 EFX_FILTER_FLAG_RX) 4341 EFX_FILTER_FLAG_RX) {
4320 return -EINVAL; 4342 rc = -EINVAL;
4343 goto out_unlock;
4344 }
4321 4345
4322 rc = efx_ef10_filter_pri(table, spec); 4346 rc = efx_ef10_filter_pri(table, spec);
4323 if (rc < 0) 4347 if (rc < 0)
4324 return rc; 4348 goto out_unlock;
4325 match_pri = rc; 4349 match_pri = rc;
4326 4350
4327 hash = efx_ef10_filter_hash(spec); 4351 hash = efx_ef10_filter_hash(spec);
@@ -4330,91 +4354,70 @@ static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4330 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); 4354 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4331 4355
4332 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) { 4356 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
4357 mutex_lock(&efx->rss_lock);
4358 rss_locked = true;
4333 if (spec->rss_context) 4359 if (spec->rss_context)
4334 ctx = efx_find_rss_context_entry(spec->rss_context, 4360 ctx = efx_find_rss_context_entry(efx, spec->rss_context);
4335 &efx->rss_context.list);
4336 else 4361 else
4337 ctx = &efx->rss_context; 4362 ctx = &efx->rss_context;
4338 if (!ctx) 4363 if (!ctx) {
4339 return -ENOENT; 4364 rc = -ENOENT;
4340 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) 4365 goto out_unlock;
4341 return -EOPNOTSUPP; 4366 }
4367 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
4368 rc = -EOPNOTSUPP;
4369 goto out_unlock;
4370 }
4342 } 4371 }
4343 4372
4344 /* Find any existing filters with the same match tuple or 4373 /* Find any existing filters with the same match tuple or
4345 * else a free slot to insert at. If any of them are busy, 4374 * else a free slot to insert at.
4346 * we have to wait and retry.
4347 */ 4375 */
4348 for (;;) { 4376 for (depth = 1; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4349 unsigned int depth = 1; 4377 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4350 unsigned int i; 4378 saved_spec = efx_ef10_filter_entry_spec(table, i);
4351
4352 spin_lock_bh(&efx->filter_lock);
4353
4354 for (;;) {
4355 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4356 saved_spec = efx_ef10_filter_entry_spec(table, i);
4357 4379
4358 if (!saved_spec) { 4380 if (!saved_spec) {
4359 if (ins_index < 0) 4381 if (ins_index < 0)
4360 ins_index = i; 4382 ins_index = i;
4361 } else if (efx_ef10_filter_equal(spec, saved_spec)) { 4383 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4362 if (table->entry[i].spec & 4384 if (spec->priority < saved_spec->priority &&
4363 EFX_EF10_FILTER_FLAG_BUSY) 4385 spec->priority != EFX_FILTER_PRI_AUTO) {
4364 break; 4386 rc = -EPERM;
4365 if (spec->priority < saved_spec->priority && 4387 goto out_unlock;
4366 spec->priority != EFX_FILTER_PRI_AUTO) {
4367 rc = -EPERM;
4368 goto out_unlock;
4369 }
4370 if (!is_mc_recip) {
4371 /* This is the only one */
4372 if (spec->priority ==
4373 saved_spec->priority &&
4374 !replace_equal) {
4375 rc = -EEXIST;
4376 goto out_unlock;
4377 }
4378 ins_index = i;
4379 goto found;
4380 } else if (spec->priority >
4381 saved_spec->priority ||
4382 (spec->priority ==
4383 saved_spec->priority &&
4384 replace_equal)) {
4385 if (ins_index < 0)
4386 ins_index = i;
4387 else
4388 __set_bit(depth, mc_rem_map);
4389 }
4390 } 4388 }
4391 4389 if (!is_mc_recip) {
4392 /* Once we reach the maximum search depth, use 4390 /* This is the only one */
4393 * the first suitable slot or return -EBUSY if 4391 if (spec->priority ==
4394 * there was none 4392 saved_spec->priority &&
4395 */ 4393 !replace_equal) {
4396 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { 4394 rc = -EEXIST;
4397 if (ins_index < 0) {
4398 rc = -EBUSY;
4399 goto out_unlock; 4395 goto out_unlock;
4400 } 4396 }
4401 goto found; 4397 ins_index = i;
4398 break;
4399 } else if (spec->priority >
4400 saved_spec->priority ||
4401 (spec->priority ==
4402 saved_spec->priority &&
4403 replace_equal)) {
4404 if (ins_index < 0)
4405 ins_index = i;
4406 else
4407 __set_bit(depth, mc_rem_map);
4402 } 4408 }
4403
4404 ++depth;
4405 } 4409 }
4406
4407 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4408 spin_unlock_bh(&efx->filter_lock);
4409 schedule();
4410 } 4410 }
4411 4411
4412found: 4412 /* Once we reach the maximum search depth, use the first suitable
4413 /* Create a software table entry if necessary, and mark it 4413 * slot, or return -EBUSY if there was none
4414 * busy. We might yet fail to insert, but any attempt to
4415 * insert a conflicting filter while we're waiting for the
4416 * firmware must find the busy entry.
4417 */ 4414 */
4415 if (ins_index < 0) {
4416 rc = -EBUSY;
4417 goto out_unlock;
4418 }
4419
4420 /* Create a software table entry if necessary. */
4418 saved_spec = efx_ef10_filter_entry_spec(table, ins_index); 4421 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4419 if (saved_spec) { 4422 if (saved_spec) {
4420 if (spec->priority == EFX_FILTER_PRI_AUTO && 4423 if (spec->priority == EFX_FILTER_PRI_AUTO &&
@@ -4438,28 +4441,19 @@ found:
4438 *saved_spec = *spec; 4441 *saved_spec = *spec;
4439 priv_flags = 0; 4442 priv_flags = 0;
4440 } 4443 }
4441 efx_ef10_filter_set_entry(table, ins_index, saved_spec, 4444 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4442 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4443
4444 /* Mark lower-priority multicast recipients busy prior to removal */
4445 if (is_mc_recip) {
4446 unsigned int depth, i;
4447
4448 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4449 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4450 if (test_bit(depth, mc_rem_map))
4451 table->entry[i].spec |=
4452 EFX_EF10_FILTER_FLAG_BUSY;
4453 }
4454 }
4455
4456 spin_unlock_bh(&efx->filter_lock);
4457 4445
4446 /* Actually insert the filter on the HW */
4458 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, 4447 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4459 ctx, replacing); 4448 ctx, replacing);
4460 4449
4450 if (rc == -EINVAL && nic_data->must_realloc_vis)
4451 /* The MC rebooted under us, causing it to reject our filter
4452 * insertion as pointing to an invalid VI (spec->dmaq_id).
4453 */
4454 rc = -EAGAIN;
4455
4461 /* Finalise the software table entry */ 4456 /* Finalise the software table entry */
4462 spin_lock_bh(&efx->filter_lock);
4463 if (rc == 0) { 4457 if (rc == 0) {
4464 if (replacing) { 4458 if (replacing) {
4465 /* Update the fields that may differ */ 4459 /* Update the fields that may differ */
@@ -4475,6 +4469,12 @@ found:
4475 } else if (!replacing) { 4469 } else if (!replacing) {
4476 kfree(saved_spec); 4470 kfree(saved_spec);
4477 saved_spec = NULL; 4471 saved_spec = NULL;
4472 } else {
4473 /* We failed to replace, so the old filter is still present.
4474 * Roll back the software table to reflect this. In fact the
4475 * efx_ef10_filter_set_entry() call below will do the right
4476 * thing, so nothing extra is needed here.
4477 */
4478 } 4478 }
4479 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); 4479 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4480 4480
@@ -4496,7 +4496,6 @@ found:
4496 priv_flags = efx_ef10_filter_entry_flags(table, i); 4496 priv_flags = efx_ef10_filter_entry_flags(table, i);
4497 4497
4498 if (rc == 0) { 4498 if (rc == 0) {
4499 spin_unlock_bh(&efx->filter_lock);
4500 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, 4499 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4501 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); 4500 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4502 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, 4501 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
@@ -4504,15 +4503,12 @@ found:
4504 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, 4503 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4505 inbuf, sizeof(inbuf), 4504 inbuf, sizeof(inbuf),
4506 NULL, 0, NULL); 4505 NULL, 0, NULL);
4507 spin_lock_bh(&efx->filter_lock);
4508 } 4506 }
4509 4507
4510 if (rc == 0) { 4508 if (rc == 0) {
4511 kfree(saved_spec); 4509 kfree(saved_spec);
4512 saved_spec = NULL; 4510 saved_spec = NULL;
4513 priv_flags = 0; 4511 priv_flags = 0;
4514 } else {
4515 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4516 } 4512 }
4517 efx_ef10_filter_set_entry(table, i, saved_spec, 4513 efx_ef10_filter_set_entry(table, i, saved_spec,
4518 priv_flags); 4514 priv_flags);
@@ -4523,10 +4519,11 @@ found:
4523 if (rc == 0) 4519 if (rc == 0)
4524 rc = efx_ef10_make_filter_id(match_pri, ins_index); 4520 rc = efx_ef10_make_filter_id(match_pri, ins_index);
4525 4521
4526 wake_up_all(&table->waitq);
4527out_unlock: 4522out_unlock:
4528 spin_unlock_bh(&efx->filter_lock); 4523 if (rss_locked)
4529 finish_wait(&table->waitq, &wait); 4524 mutex_unlock(&efx->rss_lock);
4525 up_write(&table->lock);
4526 up_read(&efx->filter_sem);
4530 return rc; 4527 return rc;
4531} 4528}
4532 4529
@@ -4539,6 +4536,8 @@ static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
4539 * If !by_index, remove by ID 4536 * If !by_index, remove by ID
4540 * If by_index, remove by index 4537 * If by_index, remove by index
4541 * Filter ID may come from userland and must be range-checked. 4538 * Filter ID may come from userland and must be range-checked.
4539 * Caller must hold efx->filter_sem for read, and efx->filter_state->lock
4540 * for write.
4542 */ 4541 */
4543static int efx_ef10_filter_remove_internal(struct efx_nic *efx, 4542static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4544 unsigned int priority_mask, 4543 unsigned int priority_mask,
@@ -4553,45 +4552,23 @@ static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4553 DEFINE_WAIT(wait); 4552 DEFINE_WAIT(wait);
4554 int rc; 4553 int rc;
4555 4554
4556 /* Find the software table entry and mark it busy. Don't
4557 * remove it yet; any attempt to update while we're waiting
4558 * for the firmware must find the busy entry.
4559 */
4560 for (;;) {
4561 spin_lock_bh(&efx->filter_lock);
4562 if (!(table->entry[filter_idx].spec &
4563 EFX_EF10_FILTER_FLAG_BUSY))
4564 break;
4565 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4566 spin_unlock_bh(&efx->filter_lock);
4567 schedule();
4568 }
4569
4570 spec = efx_ef10_filter_entry_spec(table, filter_idx); 4555 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4571 if (!spec || 4556 if (!spec ||
4572 (!by_index && 4557 (!by_index &&
4573 efx_ef10_filter_pri(table, spec) != 4558 efx_ef10_filter_pri(table, spec) !=
4574 efx_ef10_filter_get_unsafe_pri(filter_id))) { 4559 efx_ef10_filter_get_unsafe_pri(filter_id)))
4575 rc = -ENOENT; 4560 return -ENOENT;
4576 goto out_unlock;
4577 }
4578 4561
4579 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && 4562 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
4580 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { 4563 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
4581 /* Just remove flags */ 4564 /* Just remove flags */
4582 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; 4565 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
4583 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; 4566 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
4584 rc = 0; 4567 return 0;
4585 goto out_unlock;
4586 }
4587
4588 if (!(priority_mask & (1U << spec->priority))) {
4589 rc = -ENOENT;
4590 goto out_unlock;
4591 } 4568 }
4592 4569
4593 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; 4570 if (!(priority_mask & (1U << spec->priority)))
4594 spin_unlock_bh(&efx->filter_lock); 4571 return -ENOENT;
4595 4572
4596 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { 4573 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
4597 /* Reset to an automatic filter */ 4574 /* Reset to an automatic filter */
@@ -4609,7 +4586,6 @@ static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4609 &efx->rss_context, 4586 &efx->rss_context,
4610 true); 4587 true);
4611 4588
4612 spin_lock_bh(&efx->filter_lock);
4613 if (rc == 0) 4589 if (rc == 0)
4614 *spec = new_spec; 4590 *spec = new_spec;
4615 } else { 4591 } else {
@@ -4624,7 +4600,6 @@ static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4624 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, 4600 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4625 inbuf, sizeof(inbuf), NULL, 0, NULL); 4601 inbuf, sizeof(inbuf), NULL, 0, NULL);
4626 4602
4627 spin_lock_bh(&efx->filter_lock);
4628 if ((rc == 0) || (rc == -ENOENT)) { 4603 if ((rc == 0) || (rc == -ENOENT)) {
4629 /* Filter removed OK or didn't actually exist */ 4604 /* Filter removed OK or didn't actually exist */
4630 kfree(spec); 4605 kfree(spec);
@@ -4636,11 +4611,6 @@ static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4636 } 4611 }
4637 } 4612 }
4638 4613
4639 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4640 wake_up_all(&table->waitq);
4641out_unlock:
4642 spin_unlock_bh(&efx->filter_lock);
4643 finish_wait(&table->waitq, &wait);
4644 return rc; 4614 return rc;
4645} 4615}
4646 4616
@@ -4648,17 +4618,33 @@ static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4648 enum efx_filter_priority priority, 4618 enum efx_filter_priority priority,
4649 u32 filter_id) 4619 u32 filter_id)
4650{ 4620{
4651 return efx_ef10_filter_remove_internal(efx, 1U << priority, 4621 struct efx_ef10_filter_table *table;
4652 filter_id, false); 4622 int rc;
4623
4624 down_read(&efx->filter_sem);
4625 table = efx->filter_state;
4626 down_write(&table->lock);
4627 rc = efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id,
4628 false);
4629 up_write(&table->lock);
4630 up_read(&efx->filter_sem);
4631 return rc;
4653} 4632}
4654 4633
4634/* Caller must hold efx->filter_sem for read */
4655static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx, 4635static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4656 enum efx_filter_priority priority, 4636 enum efx_filter_priority priority,
4657 u32 filter_id) 4637 u32 filter_id)
4658{ 4638{
4639 struct efx_ef10_filter_table *table = efx->filter_state;
4640
4659 if (filter_id == EFX_EF10_FILTER_ID_INVALID) 4641 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4660 return; 4642 return;
4661 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true); 4643
4644 down_write(&table->lock);
4645 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id,
4646 true);
4647 up_write(&table->lock);
4662} 4648}
4663 4649
4664static int efx_ef10_filter_get_safe(struct efx_nic *efx, 4650static int efx_ef10_filter_get_safe(struct efx_nic *efx,
@@ -4666,11 +4652,13 @@ static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4666 u32 filter_id, struct efx_filter_spec *spec) 4652 u32 filter_id, struct efx_filter_spec *spec)
4667{ 4653{
4668 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id); 4654 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
4669 struct efx_ef10_filter_table *table = efx->filter_state;
4670 const struct efx_filter_spec *saved_spec; 4655 const struct efx_filter_spec *saved_spec;
4656 struct efx_ef10_filter_table *table;
4671 int rc; 4657 int rc;
4672 4658
4673 spin_lock_bh(&efx->filter_lock); 4659 down_read(&efx->filter_sem);
4660 table = efx->filter_state;
4661 down_read(&table->lock);
4674 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); 4662 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4675 if (saved_spec && saved_spec->priority == priority && 4663 if (saved_spec && saved_spec->priority == priority &&
4676 efx_ef10_filter_pri(table, saved_spec) == 4664 efx_ef10_filter_pri(table, saved_spec) ==
@@ -4680,13 +4668,15 @@ static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4680 } else { 4668 } else {
4681 rc = -ENOENT; 4669 rc = -ENOENT;
4682 } 4670 }
4683 spin_unlock_bh(&efx->filter_lock); 4671 up_read(&table->lock);
4672 up_read(&efx->filter_sem);
4684 return rc; 4673 return rc;
4685} 4674}
4686 4675
4687static int efx_ef10_filter_clear_rx(struct efx_nic *efx, 4676static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
4688 enum efx_filter_priority priority) 4677 enum efx_filter_priority priority)
4689{ 4678{
4679 struct efx_ef10_filter_table *table;
4690 unsigned int priority_mask; 4680 unsigned int priority_mask;
4691 unsigned int i; 4681 unsigned int i;
4692 int rc; 4682 int rc;
@@ -4694,31 +4684,40 @@ static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
4694 priority_mask = (((1U << (priority + 1)) - 1) & 4684 priority_mask = (((1U << (priority + 1)) - 1) &
4695 ~(1U << EFX_FILTER_PRI_AUTO)); 4685 ~(1U << EFX_FILTER_PRI_AUTO));
4696 4686
4687 down_read(&efx->filter_sem);
4688 table = efx->filter_state;
4689 down_write(&table->lock);
4697 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { 4690 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4698 rc = efx_ef10_filter_remove_internal(efx, priority_mask, 4691 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4699 i, true); 4692 i, true);
4700 if (rc && rc != -ENOENT) 4693 if (rc && rc != -ENOENT)
4701 return rc; 4694 break;
4695 rc = 0;
4702 } 4696 }
4703 4697
4704 return 0; 4698 up_write(&table->lock);
4699 up_read(&efx->filter_sem);
4700 return rc;
4705} 4701}
4706 4702
4707static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, 4703static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4708 enum efx_filter_priority priority) 4704 enum efx_filter_priority priority)
4709{ 4705{
4710 struct efx_ef10_filter_table *table = efx->filter_state; 4706 struct efx_ef10_filter_table *table;
4711 unsigned int filter_idx; 4707 unsigned int filter_idx;
4712 s32 count = 0; 4708 s32 count = 0;
4713 4709
4714 spin_lock_bh(&efx->filter_lock); 4710 down_read(&efx->filter_sem);
4711 table = efx->filter_state;
4712 down_read(&table->lock);
4715 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { 4713 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4716 if (table->entry[filter_idx].spec && 4714 if (table->entry[filter_idx].spec &&
4717 efx_ef10_filter_entry_spec(table, filter_idx)->priority == 4715 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4718 priority) 4716 priority)
4719 ++count; 4717 ++count;
4720 } 4718 }
4721 spin_unlock_bh(&efx->filter_lock); 4719 up_read(&table->lock);
4720 up_read(&efx->filter_sem);
4722 return count; 4721 return count;
4723} 4722}
4724 4723
@@ -4733,12 +4732,15 @@ static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4733 enum efx_filter_priority priority, 4732 enum efx_filter_priority priority,
4734 u32 *buf, u32 size) 4733 u32 *buf, u32 size)
4735{ 4734{
4736 struct efx_ef10_filter_table *table = efx->filter_state; 4735 struct efx_ef10_filter_table *table;
4737 struct efx_filter_spec *spec; 4736 struct efx_filter_spec *spec;
4738 unsigned int filter_idx; 4737 unsigned int filter_idx;
4739 s32 count = 0; 4738 s32 count = 0;
4740 4739
4741 spin_lock_bh(&efx->filter_lock); 4740 down_read(&efx->filter_sem);
4741 table = efx->filter_state;
4742 down_read(&table->lock);
4743
4742 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { 4744 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4743 spec = efx_ef10_filter_entry_spec(table, filter_idx); 4745 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4744 if (spec && spec->priority == priority) { 4746 if (spec && spec->priority == priority) {
@@ -4752,202 +4754,42 @@ static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4752 filter_idx); 4754 filter_idx);
4753 } 4755 }
4754 } 4756 }
4755 spin_unlock_bh(&efx->filter_lock); 4757 up_read(&table->lock);
4758 up_read(&efx->filter_sem);
4756 return count; 4759 return count;
4757} 4760}
4758 4761
4759#ifdef CONFIG_RFS_ACCEL 4762#ifdef CONFIG_RFS_ACCEL
4760 4763
4761static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4762
4763static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4764 struct efx_filter_spec *spec)
4765{
4766 struct efx_ef10_filter_table *table = efx->filter_state;
4767 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4768 struct efx_filter_spec *saved_spec;
4769 unsigned int hash, i, depth = 1;
4770 bool replacing = false;
4771 int ins_index = -1;
4772 u64 cookie;
4773 s32 rc;
4774
4775 /* Must be an RX filter without RSS and not for a multicast
4776 * destination address (RFS only works for connected sockets).
4777 * These restrictions allow us to pass only a tiny amount of
4778 * data through to the completion function.
4779 */
4780 EFX_WARN_ON_PARANOID(spec->flags !=
4781 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4782 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4783 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4784
4785 hash = efx_ef10_filter_hash(spec);
4786
4787 spin_lock_bh(&efx->filter_lock);
4788
4789 /* Find any existing filter with the same match tuple or else
4790 * a free slot to insert at. If an existing filter is busy,
4791 * we have to give up.
4792 */
4793 for (;;) {
4794 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4795 saved_spec = efx_ef10_filter_entry_spec(table, i);
4796
4797 if (!saved_spec) {
4798 if (ins_index < 0)
4799 ins_index = i;
4800 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4801 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4802 rc = -EBUSY;
4803 goto fail_unlock;
4804 }
4805 if (spec->priority < saved_spec->priority) {
4806 rc = -EPERM;
4807 goto fail_unlock;
4808 }
4809 ins_index = i;
4810 break;
4811 }
4812
4813 /* Once we reach the maximum search depth, use the
4814 * first suitable slot or return -EBUSY if there was
4815 * none
4816 */
4817 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4818 if (ins_index < 0) {
4819 rc = -EBUSY;
4820 goto fail_unlock;
4821 }
4822 break;
4823 }
4824
4825 ++depth;
4826 }
4827
4828 /* Create a software table entry if necessary, and mark it
4829 * busy. We might yet fail to insert, but any attempt to
4830 * insert a conflicting filter while we're waiting for the
4831 * firmware must find the busy entry.
4832 */
4833 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4834 if (saved_spec) {
4835 replacing = true;
4836 } else {
4837 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4838 if (!saved_spec) {
4839 rc = -ENOMEM;
4840 goto fail_unlock;
4841 }
4842 *saved_spec = *spec;
4843 }
4844 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4845 EFX_EF10_FILTER_FLAG_BUSY);
4846
4847 spin_unlock_bh(&efx->filter_lock);
4848
4849 /* Pack up the variables needed on completion */
4850 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4851
4852 efx_ef10_filter_push_prep(efx, spec, inbuf,
4853 table->entry[ins_index].handle, NULL,
4854 replacing);
4855 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4856 MC_CMD_FILTER_OP_OUT_LEN,
4857 efx_ef10_filter_rfs_insert_complete, cookie);
4858
4859 return ins_index;
4860
4861fail_unlock:
4862 spin_unlock_bh(&efx->filter_lock);
4863 return rc;
4864}
4865
4866static void
4867efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4868 int rc, efx_dword_t *outbuf,
4869 size_t outlen_actual)
4870{
4871 struct efx_ef10_filter_table *table = efx->filter_state;
4872 unsigned int ins_index, dmaq_id;
4873 struct efx_filter_spec *spec;
4874 bool replacing;
4875
4876 /* Unpack the cookie */
4877 replacing = cookie >> 31;
4878 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4879 dmaq_id = cookie & 0xffff;
4880
4881 spin_lock_bh(&efx->filter_lock);
4882 spec = efx_ef10_filter_entry_spec(table, ins_index);
4883 if (rc == 0) {
4884 table->entry[ins_index].handle =
4885 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4886 if (replacing)
4887 spec->dmaq_id = dmaq_id;
4888 } else if (!replacing) {
4889 kfree(spec);
4890 spec = NULL;
4891 }
4892 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4893 spin_unlock_bh(&efx->filter_lock);
4894
4895 wake_up_all(&table->waitq);
4896}
4897
4898static void
4899efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4900 unsigned long filter_idx,
4901 int rc, efx_dword_t *outbuf,
4902 size_t outlen_actual);
4903
4904static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 4764static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4905 unsigned int filter_idx) 4765 unsigned int filter_idx)
4906{ 4766{
4907 struct efx_ef10_filter_table *table = efx->filter_state; 4767 struct efx_ef10_filter_table *table;
4908 struct efx_filter_spec *spec = 4768 struct efx_filter_spec *spec;
4909 efx_ef10_filter_entry_spec(table, filter_idx); 4769 bool ret;
4910 MCDI_DECLARE_BUF(inbuf,
4911 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4912 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4913
4914 if (!spec ||
4915 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4916 spec->priority != EFX_FILTER_PRI_HINT ||
4917 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4918 flow_id, filter_idx))
4919 return false;
4920
4921 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4922 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4923 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4924 table->entry[filter_idx].handle);
4925 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4926 efx_ef10_filter_rfs_expire_complete, filter_idx))
4927 return false;
4928 4770
4929 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; 4771 down_read(&efx->filter_sem);
4930 return true; 4772 table = efx->filter_state;
4931} 4773 down_write(&table->lock);
4774 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4932 4775
4933static void 4776 if (!spec || spec->priority != EFX_FILTER_PRI_HINT) {
4934efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, 4777 ret = true;
4935 unsigned long filter_idx, 4778 goto out_unlock;
4936 int rc, efx_dword_t *outbuf, 4779 }
4937 size_t outlen_actual)
4938{
4939 struct efx_ef10_filter_table *table = efx->filter_state;
4940 struct efx_filter_spec *spec =
4941 efx_ef10_filter_entry_spec(table, filter_idx);
4942 4780
4943 spin_lock_bh(&efx->filter_lock); 4781 if (!rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4944 if (rc == 0) { 4782 flow_id, filter_idx)) {
4945 kfree(spec); 4783 ret = false;
4946 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); 4784 goto out_unlock;
4947 } 4785 }
4948 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; 4786
4949 wake_up_all(&table->waitq); 4787 ret = efx_ef10_filter_remove_internal(efx, 1U << spec->priority,
4950 spin_unlock_bh(&efx->filter_lock); 4788 filter_idx, true) == 0;
4789out_unlock:
4790 up_write(&table->lock);
4791 up_read(&efx->filter_sem);
4792 return ret;
4951} 4793}
4952 4794
4953#endif /* CONFIG_RFS_ACCEL */ 4795#endif /* CONFIG_RFS_ACCEL */
@@ -5142,9 +4984,9 @@ static int efx_ef10_filter_table_probe(struct efx_nic *efx)
5142 table->vlan_filter = 4984 table->vlan_filter =
5143 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER); 4985 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5144 INIT_LIST_HEAD(&table->vlan_list); 4986 INIT_LIST_HEAD(&table->vlan_list);
4987 init_rwsem(&table->lock);
5145 4988
5146 efx->filter_state = table; 4989 efx->filter_state = table;
5147 init_waitqueue_head(&table->waitq);
5148 4990
5149 list_for_each_entry(vlan, &nic_data->vlan_list, list) { 4991 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
5150 rc = efx_ef10_filter_add_vlan(efx, vlan->vid); 4992 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
@@ -5186,7 +5028,8 @@ static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5186 if (!table) 5028 if (!table)
5187 return; 5029 return;
5188 5030
5189 spin_lock_bh(&efx->filter_lock); 5031 down_write(&table->lock);
5032 mutex_lock(&efx->rss_lock);
5190 5033
5191 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { 5034 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5192 spec = efx_ef10_filter_entry_spec(table, filter_idx); 5035 spec = efx_ef10_filter_entry_spec(table, filter_idx);
@@ -5203,8 +5046,7 @@ static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5203 goto not_restored; 5046 goto not_restored;
5204 } 5047 }
5205 if (spec->rss_context) 5048 if (spec->rss_context)
5206 ctx = efx_find_rss_context_entry(spec->rss_context, 5049 ctx = efx_find_rss_context_entry(efx, spec->rss_context);
5207 &efx->rss_context.list);
5208 else 5050 else
5209 ctx = &efx->rss_context; 5051 ctx = &efx->rss_context;
5210 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) { 5052 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
@@ -5224,15 +5066,11 @@ static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5224 } 5066 }
5225 } 5067 }
5226 5068
5227 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
5228 spin_unlock_bh(&efx->filter_lock);
5229
5230 rc = efx_ef10_filter_push(efx, spec, 5069 rc = efx_ef10_filter_push(efx, spec,
5231 &table->entry[filter_idx].handle, 5070 &table->entry[filter_idx].handle,
5232 ctx, false); 5071 ctx, false);
5233 if (rc) 5072 if (rc)
5234 failed++; 5073 failed++;
5235 spin_lock_bh(&efx->filter_lock);
5236 5074
5237 if (rc) { 5075 if (rc) {
5238not_restored: 5076not_restored:
@@ -5244,13 +5082,11 @@ not_restored:
5244 5082
5245 kfree(spec); 5083 kfree(spec);
5246 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); 5084 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
5247 } else {
5248 table->entry[filter_idx].spec &=
5249 ~EFX_EF10_FILTER_FLAG_BUSY;
5250 } 5085 }
5251 } 5086 }
5252 5087
5253 spin_unlock_bh(&efx->filter_lock); 5088 mutex_unlock(&efx->rss_lock);
5089 up_write(&table->lock);
5254 5090
5255 /* This can happen validly if the MC's capabilities have changed, so 5091 /* This can happen validly if the MC's capabilities have changed, so
5256 * is not an error. 5092 * is not an error.
@@ -5318,6 +5154,8 @@ static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5318 struct efx_ef10_filter_table *table = efx->filter_state; 5154 struct efx_ef10_filter_table *table = efx->filter_state;
5319 unsigned int filter_idx; 5155 unsigned int filter_idx;
5320 5156
5157 efx_rwsem_assert_write_locked(&table->lock);
5158
5321 if (*id != EFX_EF10_FILTER_ID_INVALID) { 5159 if (*id != EFX_EF10_FILTER_ID_INVALID) {
5322 filter_idx = efx_ef10_filter_get_unsafe_id(*id); 5160 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
5323 if (!table->entry[filter_idx].spec) 5161 if (!table->entry[filter_idx].spec)
@@ -5353,10 +5191,10 @@ static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5353 struct efx_ef10_filter_table *table = efx->filter_state; 5191 struct efx_ef10_filter_table *table = efx->filter_state;
5354 struct efx_ef10_filter_vlan *vlan; 5192 struct efx_ef10_filter_vlan *vlan;
5355 5193
5356 spin_lock_bh(&efx->filter_lock); 5194 down_write(&table->lock);
5357 list_for_each_entry(vlan, &table->vlan_list, list) 5195 list_for_each_entry(vlan, &table->vlan_list, list)
5358 _efx_ef10_filter_vlan_mark_old(efx, vlan); 5196 _efx_ef10_filter_vlan_mark_old(efx, vlan);
5359 spin_unlock_bh(&efx->filter_lock); 5197 up_write(&table->lock);
5360} 5198}
5361 5199
5362static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx) 5200static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
@@ -5633,10 +5471,7 @@ static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5633 return rc; 5471 return rc;
5634} 5472}
5635 5473
5636/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD 5474/* Remove filters that weren't renewed. */
5637 * flag or removes these filters, we don't need to hold the filter_lock while
5638 * scanning for these filters.
5639 */
5640static void efx_ef10_filter_remove_old(struct efx_nic *efx) 5475static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5641{ 5476{
5642 struct efx_ef10_filter_table *table = efx->filter_state; 5477 struct efx_ef10_filter_table *table = efx->filter_state;
@@ -5645,6 +5480,7 @@ static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5645 int rc; 5480 int rc;
5646 int i; 5481 int i;
5647 5482
5483 down_write(&table->lock);
5648 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { 5484 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
5649 if (READ_ONCE(table->entry[i].spec) & 5485 if (READ_ONCE(table->entry[i].spec) &
5650 EFX_EF10_FILTER_FLAG_AUTO_OLD) { 5486 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
@@ -5656,6 +5492,7 @@ static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5656 remove_failed++; 5492 remove_failed++;
5657 } 5493 }
5658 } 5494 }
5495 up_write(&table->lock);
5659 5496
5660 if (remove_failed) 5497 if (remove_failed)
5661 netif_info(efx, drv, efx->net_dev, 5498 netif_info(efx, drv, efx->net_dev,
@@ -6784,7 +6621,6 @@ const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
6784 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, 6621 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6785 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, 6622 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6786#ifdef CONFIG_RFS_ACCEL 6623#ifdef CONFIG_RFS_ACCEL
6787 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6788 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, 6624 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6789#endif 6625#endif
6790#ifdef CONFIG_SFC_MTD 6626#ifdef CONFIG_SFC_MTD
@@ -6897,7 +6733,6 @@ const struct efx_nic_type efx_hunt_a0_nic_type = {
6897 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, 6733 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6898 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, 6734 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6899#ifdef CONFIG_RFS_ACCEL 6735#ifdef CONFIG_RFS_ACCEL
6900 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6901 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, 6736 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6902#endif 6737#endif
6903#ifdef CONFIG_SFC_MTD 6738#ifdef CONFIG_SFC_MTD
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 7321a4cf6f4d..692dd729ee2a 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -340,7 +340,10 @@ static int efx_poll(struct napi_struct *napi, int budget)
340 efx_update_irq_mod(efx, channel); 340 efx_update_irq_mod(efx, channel);
341 } 341 }
342 342
343 efx_filter_rfs_expire(channel); 343#ifdef CONFIG_RFS_ACCEL
344 /* Perhaps expire some ARFS filters */
345 schedule_work(&channel->filter_work);
346#endif
344 347
345 /* There is no race here; although napi_disable() will 348 /* There is no race here; although napi_disable() will
346 * only wait for napi_complete(), this isn't a problem 349 * only wait for napi_complete(), this isn't a problem
@@ -470,6 +473,10 @@ efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
470 tx_queue->channel = channel; 473 tx_queue->channel = channel;
471 } 474 }
472 475
476#ifdef CONFIG_RFS_ACCEL
477 INIT_WORK(&channel->filter_work, efx_filter_rfs_expire);
478#endif
479
473 rx_queue = &channel->rx_queue; 480 rx_queue = &channel->rx_queue;
474 rx_queue->efx = efx; 481 rx_queue->efx = efx;
475 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 482 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
@@ -512,6 +519,9 @@ efx_copy_channel(const struct efx_channel *old_channel)
512 rx_queue->buffer = NULL; 519 rx_queue->buffer = NULL;
513 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 520 memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
514 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 521 timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
522#ifdef CONFIG_RFS_ACCEL
523 INIT_WORK(&channel->filter_work, efx_filter_rfs_expire);
524#endif
515 525
516 return channel; 526 return channel;
517} 527}
@@ -1773,7 +1783,6 @@ static int efx_probe_filters(struct efx_nic *efx)
1773{ 1783{
1774 int rc; 1784 int rc;
1775 1785
1776 spin_lock_init(&efx->filter_lock);
1777 init_rwsem(&efx->filter_sem); 1786 init_rwsem(&efx->filter_sem);
1778 mutex_lock(&efx->mac_lock); 1787 mutex_lock(&efx->mac_lock);
1779 down_write(&efx->filter_sem); 1788 down_write(&efx->filter_sem);
@@ -2648,6 +2657,7 @@ void efx_reset_down(struct efx_nic *efx, enum reset_type method)
2648 efx_disable_interrupts(efx); 2657 efx_disable_interrupts(efx);
2649 2658
2650 mutex_lock(&efx->mac_lock); 2659 mutex_lock(&efx->mac_lock);
2660 mutex_lock(&efx->rss_lock);
2651 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE && 2661 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2652 method != RESET_TYPE_DATAPATH) 2662 method != RESET_TYPE_DATAPATH)
2653 efx->phy_op->fini(efx); 2663 efx->phy_op->fini(efx);
@@ -2703,6 +2713,7 @@ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
2703 2713
2704 if (efx->type->rx_restore_rss_contexts) 2714 if (efx->type->rx_restore_rss_contexts)
2705 efx->type->rx_restore_rss_contexts(efx); 2715 efx->type->rx_restore_rss_contexts(efx);
2716 mutex_unlock(&efx->rss_lock);
2706 down_read(&efx->filter_sem); 2717 down_read(&efx->filter_sem);
2707 efx_restore_filters(efx); 2718 efx_restore_filters(efx);
2708 up_read(&efx->filter_sem); 2719 up_read(&efx->filter_sem);
@@ -2721,6 +2732,7 @@ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
2721fail: 2732fail:
2722 efx->port_initialized = false; 2733 efx->port_initialized = false;
2723 2734
2735 mutex_unlock(&efx->rss_lock);
2724 mutex_unlock(&efx->mac_lock); 2736 mutex_unlock(&efx->mac_lock);
2725 2737
2726 return rc; 2738 return rc;
@@ -3007,11 +3019,15 @@ static int efx_init_struct(struct efx_nic *efx,
3007 efx->rx_packet_ts_offset = 3019 efx->rx_packet_ts_offset =
3008 efx->type->rx_ts_offset - efx->type->rx_prefix_size; 3020 efx->type->rx_ts_offset - efx->type->rx_prefix_size;
3009 INIT_LIST_HEAD(&efx->rss_context.list); 3021 INIT_LIST_HEAD(&efx->rss_context.list);
3022 mutex_init(&efx->rss_lock);
3010 spin_lock_init(&efx->stats_lock); 3023 spin_lock_init(&efx->stats_lock);
3011 efx->vi_stride = EFX_DEFAULT_VI_STRIDE; 3024 efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
3012 efx->num_mac_stats = MC_CMD_MAC_NSTATS; 3025 efx->num_mac_stats = MC_CMD_MAC_NSTATS;
3013 BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END); 3026 BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
3014 mutex_init(&efx->mac_lock); 3027 mutex_init(&efx->mac_lock);
3028#ifdef CONFIG_RFS_ACCEL
3029 mutex_init(&efx->rps_mutex);
3030#endif
3015 efx->phy_op = &efx_dummy_phy_operations; 3031 efx->phy_op = &efx_dummy_phy_operations;
3016 efx->mdio.dev = net_dev; 3032 efx->mdio.dev = net_dev;
3017 INIT_WORK(&efx->mac_work, efx_mac_work); 3033 INIT_WORK(&efx->mac_work, efx_mac_work);
@@ -3079,11 +3095,14 @@ void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
3079/* RSS contexts. We're using linked lists and crappy O(n) algorithms, because 3095/* RSS contexts. We're using linked lists and crappy O(n) algorithms, because
3080 * (a) this is an infrequent control-plane operation and (b) n is small (max 64) 3096 * (a) this is an infrequent control-plane operation and (b) n is small (max 64)
3081 */ 3097 */
3082struct efx_rss_context *efx_alloc_rss_context_entry(struct list_head *head) 3098struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
3083{ 3099{
3100 struct list_head *head = &efx->rss_context.list;
3084 struct efx_rss_context *ctx, *new; 3101 struct efx_rss_context *ctx, *new;
3085 u32 id = 1; /* Don't use zero, that refers to the master RSS context */ 3102 u32 id = 1; /* Don't use zero, that refers to the master RSS context */
3086 3103
3104 WARN_ON(!mutex_is_locked(&efx->rss_lock));
3105
3087 /* Search for first gap in the numbering */ 3106 /* Search for first gap in the numbering */
3088 list_for_each_entry(ctx, head, list) { 3107 list_for_each_entry(ctx, head, list) {
3089 if (ctx->user_id != id) 3108 if (ctx->user_id != id)
@@ -3109,10 +3128,13 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct list_head *head)
3109 return new; 3128 return new;
3110} 3129}
3111 3130
3112struct efx_rss_context *efx_find_rss_context_entry(u32 id, struct list_head *head) 3131struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id)
3113{ 3132{
3133 struct list_head *head = &efx->rss_context.list;
3114 struct efx_rss_context *ctx; 3134 struct efx_rss_context *ctx;
3115 3135
3136 WARN_ON(!mutex_is_locked(&efx->rss_lock));
3137
3116 list_for_each_entry(ctx, head, list) 3138 list_for_each_entry(ctx, head, list)
3117 if (ctx->user_id == id) 3139 if (ctx->user_id == id)
3118 return ctx; 3140 return ctx;
diff --git a/drivers/net/ethernet/sfc/efx.h b/drivers/net/ethernet/sfc/efx.h
index 3429ae3f3b08..a3140e16fcef 100644
--- a/drivers/net/ethernet/sfc/efx.h
+++ b/drivers/net/ethernet/sfc/efx.h
@@ -170,22 +170,25 @@ static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
170int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb, 170int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
171 u16 rxq_index, u32 flow_id); 171 u16 rxq_index, u32 flow_id);
172bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned quota); 172bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned quota);
173static inline void efx_filter_rfs_expire(struct efx_channel *channel) 173static inline void efx_filter_rfs_expire(struct work_struct *data)
174{ 174{
175 struct efx_channel *channel = container_of(data, struct efx_channel,
176 filter_work);
177
175 if (channel->rfs_filters_added >= 60 && 178 if (channel->rfs_filters_added >= 60 &&
176 __efx_filter_rfs_expire(channel->efx, 100)) 179 __efx_filter_rfs_expire(channel->efx, 100))
177 channel->rfs_filters_added -= 60; 180 channel->rfs_filters_added -= 60;
178} 181}
179#define efx_filter_rfs_enabled() 1 182#define efx_filter_rfs_enabled() 1
180#else 183#else
181static inline void efx_filter_rfs_expire(struct efx_channel *channel) {} 184static inline void efx_filter_rfs_expire(struct work_struct *data) {}
182#define efx_filter_rfs_enabled() 0 185#define efx_filter_rfs_enabled() 0
183#endif 186#endif
184bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec); 187bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec);
185 188
186/* RSS contexts */ 189/* RSS contexts */
187struct efx_rss_context *efx_alloc_rss_context_entry(struct list_head *list); 190struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx);
188struct efx_rss_context *efx_find_rss_context_entry(u32 id, struct list_head *list); 191struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id);
189void efx_free_rss_context_entry(struct efx_rss_context *ctx); 192void efx_free_rss_context_entry(struct efx_rss_context *ctx);
190static inline bool efx_rss_active(struct efx_rss_context *ctx) 193static inline bool efx_rss_active(struct efx_rss_context *ctx)
191{ 194{
diff --git a/drivers/net/ethernet/sfc/ethtool.c b/drivers/net/ethernet/sfc/ethtool.c
index bb1c80d48d12..3143588ffd77 100644
--- a/drivers/net/ethernet/sfc/ethtool.c
+++ b/drivers/net/ethernet/sfc/ethtool.c
@@ -979,7 +979,7 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
979{ 979{
980 struct efx_nic *efx = netdev_priv(net_dev); 980 struct efx_nic *efx = netdev_priv(net_dev);
981 u32 rss_context = 0; 981 u32 rss_context = 0;
982 s32 rc; 982 s32 rc = 0;
983 983
984 switch (info->cmd) { 984 switch (info->cmd) {
985 case ETHTOOL_GRXRINGS: 985 case ETHTOOL_GRXRINGS:
@@ -989,15 +989,17 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
989 case ETHTOOL_GRXFH: { 989 case ETHTOOL_GRXFH: {
990 struct efx_rss_context *ctx = &efx->rss_context; 990 struct efx_rss_context *ctx = &efx->rss_context;
991 991
992 mutex_lock(&efx->rss_lock);
992 if (info->flow_type & FLOW_RSS && info->rss_context) { 993 if (info->flow_type & FLOW_RSS && info->rss_context) {
993 ctx = efx_find_rss_context_entry(info->rss_context, 994 ctx = efx_find_rss_context_entry(efx, info->rss_context);
994 &efx->rss_context.list); 995 if (!ctx) {
995 if (!ctx) 996 rc = -ENOENT;
996 return -ENOENT; 997 goto out_unlock;
998 }
997 } 999 }
998 info->data = 0; 1000 info->data = 0;
999 if (!efx_rss_active(ctx)) /* No RSS */ 1001 if (!efx_rss_active(ctx)) /* No RSS */
1000 return 0; 1002 goto out_unlock;
1001 switch (info->flow_type & ~FLOW_RSS) { 1003 switch (info->flow_type & ~FLOW_RSS) {
1002 case UDP_V4_FLOW: 1004 case UDP_V4_FLOW:
1003 if (ctx->rx_hash_udp_4tuple) 1005 if (ctx->rx_hash_udp_4tuple)
@@ -1024,7 +1026,9 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
1024 default: 1026 default:
1025 break; 1027 break;
1026 } 1028 }
1027 return 0; 1029out_unlock:
1030 mutex_unlock(&efx->rss_lock);
1031 return rc;
1028 } 1032 }
1029 1033
1030 case ETHTOOL_GRXCLSRLCNT: 1034 case ETHTOOL_GRXCLSRLCNT:
@@ -1084,6 +1088,7 @@ static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1084 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; 1088 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1085 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; 1089 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1086 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; 1090 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1091 u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
1087 struct ethhdr *mac_entry = &rule->h_u.ether_spec; 1092 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1088 struct ethhdr *mac_mask = &rule->m_u.ether_spec; 1093 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1089 enum efx_filter_flags flags = 0; 1094 enum efx_filter_flags flags = 0;
@@ -1117,14 +1122,14 @@ static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1117 if (rule->flow_type & FLOW_RSS) 1122 if (rule->flow_type & FLOW_RSS)
1118 spec.rss_context = rss_context; 1123 spec.rss_context = rss_context;
1119 1124
1120 switch (rule->flow_type & ~(FLOW_EXT | FLOW_RSS)) { 1125 switch (flow_type) {
1121 case TCP_V4_FLOW: 1126 case TCP_V4_FLOW:
1122 case UDP_V4_FLOW: 1127 case UDP_V4_FLOW:
1123 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | 1128 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1124 EFX_FILTER_MATCH_IP_PROTO); 1129 EFX_FILTER_MATCH_IP_PROTO);
1125 spec.ether_type = htons(ETH_P_IP); 1130 spec.ether_type = htons(ETH_P_IP);
1126 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? 1131 spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
1127 IPPROTO_TCP : IPPROTO_UDP); 1132 : IPPROTO_UDP;
1128 if (ip_mask->ip4dst) { 1133 if (ip_mask->ip4dst) {
1129 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) 1134 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1130 return -EINVAL; 1135 return -EINVAL;
@@ -1158,8 +1163,8 @@ static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1158 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | 1163 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1159 EFX_FILTER_MATCH_IP_PROTO); 1164 EFX_FILTER_MATCH_IP_PROTO);
1160 spec.ether_type = htons(ETH_P_IPV6); 1165 spec.ether_type = htons(ETH_P_IPV6);
1161 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ? 1166 spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
1162 IPPROTO_TCP : IPPROTO_UDP); 1167 : IPPROTO_UDP;
1163 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) { 1168 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1164 if (!ip6_mask_is_full(ip6_mask->ip6dst)) 1169 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1165 return -EINVAL; 1170 return -EINVAL;
@@ -1366,16 +1371,20 @@ static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1366{ 1371{
1367 struct efx_nic *efx = netdev_priv(net_dev); 1372 struct efx_nic *efx = netdev_priv(net_dev);
1368 struct efx_rss_context *ctx; 1373 struct efx_rss_context *ctx;
1369 int rc; 1374 int rc = 0;
1370 1375
1371 if (!efx->type->rx_pull_rss_context_config) 1376 if (!efx->type->rx_pull_rss_context_config)
1372 return -EOPNOTSUPP; 1377 return -EOPNOTSUPP;
1373 ctx = efx_find_rss_context_entry(rss_context, &efx->rss_context.list); 1378
1374 if (!ctx) 1379 mutex_lock(&efx->rss_lock);
1375 return -ENOENT; 1380 ctx = efx_find_rss_context_entry(efx, rss_context);
1381 if (!ctx) {
1382 rc = -ENOENT;
1383 goto out_unlock;
1384 }
1376 rc = efx->type->rx_pull_rss_context_config(efx, ctx); 1385 rc = efx->type->rx_pull_rss_context_config(efx, ctx);
1377 if (rc) 1386 if (rc)
1378 return rc; 1387 goto out_unlock;
1379 1388
1380 if (hfunc) 1389 if (hfunc)
1381 *hfunc = ETH_RSS_HASH_TOP; 1390 *hfunc = ETH_RSS_HASH_TOP;
@@ -1383,7 +1392,9 @@ static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1383 memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table)); 1392 memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
1384 if (key) 1393 if (key)
1385 memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size); 1394 memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
1386 return 0; 1395out_unlock:
1396 mutex_unlock(&efx->rss_lock);
1397 return rc;
1387} 1398}
1388 1399
1389static int efx_ethtool_set_rxfh_context(struct net_device *net_dev, 1400static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
@@ -1401,23 +1412,31 @@ static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1401 /* Hash function is Toeplitz, cannot be changed */ 1412 /* Hash function is Toeplitz, cannot be changed */
1402 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 1413 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1403 return -EOPNOTSUPP; 1414 return -EOPNOTSUPP;
1415
1416 mutex_lock(&efx->rss_lock);
1417
1404 if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) { 1418 if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1405 if (delete) 1419 if (delete) {
1406 /* alloc + delete == Nothing to do */ 1420 /* alloc + delete == Nothing to do */
1407 return -EINVAL; 1421 rc = -EINVAL;
1408 ctx = efx_alloc_rss_context_entry(&efx->rss_context.list); 1422 goto out_unlock;
1409 if (!ctx) 1423 }
1410 return -ENOMEM; 1424 ctx = efx_alloc_rss_context_entry(efx);
1425 if (!ctx) {
1426 rc = -ENOMEM;
1427 goto out_unlock;
1428 }
1411 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID; 1429 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
1412 /* Initialise indir table and key to defaults */ 1430 /* Initialise indir table and key to defaults */
1413 efx_set_default_rx_indir_table(efx, ctx); 1431 efx_set_default_rx_indir_table(efx, ctx);
1414 netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key)); 1432 netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1415 allocated = true; 1433 allocated = true;
1416 } else { 1434 } else {
1417 ctx = efx_find_rss_context_entry(*rss_context, 1435 ctx = efx_find_rss_context_entry(efx, *rss_context);
1418 &efx->rss_context.list); 1436 if (!ctx) {
1419 if (!ctx) 1437 rc = -ENOENT;
1420 return -ENOENT; 1438 goto out_unlock;
1439 }
1421 } 1440 }
1422 1441
1423 if (delete) { 1442 if (delete) {
@@ -1425,7 +1444,7 @@ static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1425 rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL); 1444 rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1426 if (!rc) 1445 if (!rc)
1427 efx_free_rss_context_entry(ctx); 1446 efx_free_rss_context_entry(ctx);
1428 return rc; 1447 goto out_unlock;
1429 } 1448 }
1430 1449
1431 if (!key) 1450 if (!key)
@@ -1438,6 +1457,8 @@ static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1438 efx_free_rss_context_entry(ctx); 1457 efx_free_rss_context_entry(ctx);
1439 else 1458 else
1440 *rss_context = ctx->user_id; 1459 *rss_context = ctx->user_id;
1460out_unlock:
1461 mutex_unlock(&efx->rss_lock);
1441 return rc; 1462 return rc;
1442} 1463}
1443 1464
diff --git a/drivers/net/ethernet/sfc/farch.c b/drivers/net/ethernet/sfc/farch.c
index ad001e77d554..4a19c7efdf8d 100644
--- a/drivers/net/ethernet/sfc/farch.c
+++ b/drivers/net/ethernet/sfc/farch.c
@@ -1878,6 +1878,7 @@ struct efx_farch_filter_table {
1878}; 1878};
1879 1879
1880struct efx_farch_filter_state { 1880struct efx_farch_filter_state {
1881 struct rw_semaphore lock; /* Protects table contents */
1881 struct efx_farch_filter_table table[EFX_FARCH_FILTER_TABLE_COUNT]; 1882 struct efx_farch_filter_table table[EFX_FARCH_FILTER_TABLE_COUNT];
1882}; 1883};
1883 1884
@@ -2397,9 +2398,13 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2397 if (rc) 2398 if (rc)
2398 return rc; 2399 return rc;
2399 2400
2401 down_write(&state->lock);
2402
2400 table = &state->table[efx_farch_filter_spec_table_id(&spec)]; 2403 table = &state->table[efx_farch_filter_spec_table_id(&spec)];
2401 if (table->size == 0) 2404 if (table->size == 0) {
2402 return -EINVAL; 2405 rc = -EINVAL;
2406 goto out_unlock;
2407 }
2403 2408
2404 netif_vdbg(efx, hw, efx->net_dev, 2409 netif_vdbg(efx, hw, efx->net_dev,
2405 "%s: type %d search_limit=%d", __func__, spec.type, 2410 "%s: type %d search_limit=%d", __func__, spec.type,
@@ -2412,8 +2417,6 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2412 EFX_FARCH_FILTER_MC_DEF - EFX_FARCH_FILTER_UC_DEF); 2417 EFX_FARCH_FILTER_MC_DEF - EFX_FARCH_FILTER_UC_DEF);
2413 rep_index = spec.type - EFX_FARCH_FILTER_UC_DEF; 2418 rep_index = spec.type - EFX_FARCH_FILTER_UC_DEF;
2414 ins_index = rep_index; 2419 ins_index = rep_index;
2415
2416 spin_lock_bh(&efx->filter_lock);
2417 } else { 2420 } else {
2418 /* Search concurrently for 2421 /* Search concurrently for
2419 * (1) a filter to be replaced (rep_index): any filter 2422 * (1) a filter to be replaced (rep_index): any filter
@@ -2443,8 +2446,6 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2443 ins_index = -1; 2446 ins_index = -1;
2444 depth = 1; 2447 depth = 1;
2445 2448
2446 spin_lock_bh(&efx->filter_lock);
2447
2448 for (;;) { 2449 for (;;) {
2449 if (!test_bit(i, table->used_bitmap)) { 2450 if (!test_bit(i, table->used_bitmap)) {
2450 if (ins_index < 0) 2451 if (ins_index < 0)
@@ -2463,7 +2464,7 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2463 /* Case (b) */ 2464 /* Case (b) */
2464 if (ins_index < 0) { 2465 if (ins_index < 0) {
2465 rc = -EBUSY; 2466 rc = -EBUSY;
2466 goto out; 2467 goto out_unlock;
2467 } 2468 }
2468 rep_index = -1; 2469 rep_index = -1;
2469 break; 2470 break;
@@ -2483,11 +2484,11 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2483 2484
2484 if (spec.priority == saved_spec->priority && !replace_equal) { 2485 if (spec.priority == saved_spec->priority && !replace_equal) {
2485 rc = -EEXIST; 2486 rc = -EEXIST;
2486 goto out; 2487 goto out_unlock;
2487 } 2488 }
2488 if (spec.priority < saved_spec->priority) { 2489 if (spec.priority < saved_spec->priority) {
2489 rc = -EPERM; 2490 rc = -EPERM;
2490 goto out; 2491 goto out_unlock;
2491 } 2492 }
2492 if (saved_spec->priority == EFX_FILTER_PRI_AUTO || 2493 if (saved_spec->priority == EFX_FILTER_PRI_AUTO ||
2493 saved_spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) 2494 saved_spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO)
@@ -2528,8 +2529,8 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
2528 __func__, spec.type, ins_index, spec.dmaq_id); 2529 __func__, spec.type, ins_index, spec.dmaq_id);
2529 rc = efx_farch_filter_make_id(&spec, ins_index); 2530 rc = efx_farch_filter_make_id(&spec, ins_index);
2530 2531
2531out: 2532out_unlock:
2532 spin_unlock_bh(&efx->filter_lock); 2533 up_write(&state->lock);
2533 return rc; 2534 return rc;
2534} 2535}
2535 2536
@@ -2604,11 +2605,11 @@ int efx_farch_filter_remove_safe(struct efx_nic *efx,
2604 filter_idx = efx_farch_filter_id_index(filter_id); 2605 filter_idx = efx_farch_filter_id_index(filter_id);
2605 if (filter_idx >= table->size) 2606 if (filter_idx >= table->size)
2606 return -ENOENT; 2607 return -ENOENT;
2608 down_write(&state->lock);
2607 spec = &table->spec[filter_idx]; 2609 spec = &table->spec[filter_idx];
2608 2610
2609 spin_lock_bh(&efx->filter_lock);
2610 rc = efx_farch_filter_remove(efx, table, filter_idx, priority); 2611 rc = efx_farch_filter_remove(efx, table, filter_idx, priority);
2611 spin_unlock_bh(&efx->filter_lock); 2612 up_write(&state->lock);
2612 2613
2613 return rc; 2614 return rc;
2614} 2615}
@@ -2622,30 +2623,28 @@ int efx_farch_filter_get_safe(struct efx_nic *efx,
2622 struct efx_farch_filter_table *table; 2623 struct efx_farch_filter_table *table;
2623 struct efx_farch_filter_spec *spec; 2624 struct efx_farch_filter_spec *spec;
2624 unsigned int filter_idx; 2625 unsigned int filter_idx;
2625 int rc; 2626 int rc = -ENOENT;
2627
2628 down_read(&state->lock);
2626 2629
2627 table_id = efx_farch_filter_id_table_id(filter_id); 2630 table_id = efx_farch_filter_id_table_id(filter_id);
2628 if ((unsigned int)table_id >= EFX_FARCH_FILTER_TABLE_COUNT) 2631 if ((unsigned int)table_id >= EFX_FARCH_FILTER_TABLE_COUNT)
2629 return -ENOENT; 2632 goto out_unlock;
2630 table = &state->table[table_id]; 2633 table = &state->table[table_id];
2631 2634
2632 filter_idx = efx_farch_filter_id_index(filter_id); 2635 filter_idx = efx_farch_filter_id_index(filter_id);
2633 if (filter_idx >= table->size) 2636 if (filter_idx >= table->size)
2634 return -ENOENT; 2637 goto out_unlock;
2635 spec = &table->spec[filter_idx]; 2638 spec = &table->spec[filter_idx];
2636 2639
2637 spin_lock_bh(&efx->filter_lock);
2638
2639 if (test_bit(filter_idx, table->used_bitmap) && 2640 if (test_bit(filter_idx, table->used_bitmap) &&
2640 spec->priority == priority) { 2641 spec->priority == priority) {
2641 efx_farch_filter_to_gen_spec(spec_buf, spec); 2642 efx_farch_filter_to_gen_spec(spec_buf, spec);
2642 rc = 0; 2643 rc = 0;
2643 } else {
2644 rc = -ENOENT;
2645 } 2644 }
2646 2645
2647 spin_unlock_bh(&efx->filter_lock); 2646out_unlock:
2648 2647 up_read(&state->lock);
2649 return rc; 2648 return rc;
2650} 2649}
2651 2650
@@ -2658,13 +2657,13 @@ efx_farch_filter_table_clear(struct efx_nic *efx,
2658 struct efx_farch_filter_table *table = &state->table[table_id]; 2657 struct efx_farch_filter_table *table = &state->table[table_id];
2659 unsigned int filter_idx; 2658 unsigned int filter_idx;
2660 2659
2661 spin_lock_bh(&efx->filter_lock); 2660 down_write(&state->lock);
2662 for (filter_idx = 0; filter_idx < table->size; ++filter_idx) { 2661 for (filter_idx = 0; filter_idx < table->size; ++filter_idx) {
2663 if (table->spec[filter_idx].priority != EFX_FILTER_PRI_AUTO) 2662 if (table->spec[filter_idx].priority != EFX_FILTER_PRI_AUTO)
2664 efx_farch_filter_remove(efx, table, 2663 efx_farch_filter_remove(efx, table,
2665 filter_idx, priority); 2664 filter_idx, priority);
2666 } 2665 }
2667 spin_unlock_bh(&efx->filter_lock); 2666 up_write(&state->lock);
2668} 2667}
2669 2668
2670int efx_farch_filter_clear_rx(struct efx_nic *efx, 2669int efx_farch_filter_clear_rx(struct efx_nic *efx,
@@ -2688,7 +2687,7 @@ u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
2688 unsigned int filter_idx; 2687 unsigned int filter_idx;
2689 u32 count = 0; 2688 u32 count = 0;
2690 2689
2691 spin_lock_bh(&efx->filter_lock); 2690 down_read(&state->lock);
2692 2691
2693 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 2692 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
2694 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 2693 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2701,7 +2700,7 @@ u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
2701 } 2700 }
2702 } 2701 }
2703 2702
2704 spin_unlock_bh(&efx->filter_lock); 2703 up_read(&state->lock);
2705 2704
2706 return count; 2705 return count;
2707} 2706}
@@ -2716,7 +2715,7 @@ s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
2716 unsigned int filter_idx; 2715 unsigned int filter_idx;
2717 s32 count = 0; 2716 s32 count = 0;
2718 2717
2719 spin_lock_bh(&efx->filter_lock); 2718 down_read(&state->lock);
2720 2719
2721 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 2720 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
2722 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 2721 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2735,7 +2734,7 @@ s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
2735 } 2734 }
2736 } 2735 }
2737out: 2736out:
2738 spin_unlock_bh(&efx->filter_lock); 2737 up_read(&state->lock);
2739 2738
2740 return count; 2739 return count;
2741} 2740}
@@ -2749,7 +2748,7 @@ void efx_farch_filter_table_restore(struct efx_nic *efx)
2749 efx_oword_t filter; 2748 efx_oword_t filter;
2750 unsigned int filter_idx; 2749 unsigned int filter_idx;
2751 2750
2752 spin_lock_bh(&efx->filter_lock); 2751 down_write(&state->lock);
2753 2752
2754 for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) { 2753 for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) {
2755 table = &state->table[table_id]; 2754 table = &state->table[table_id];
@@ -2770,7 +2769,7 @@ void efx_farch_filter_table_restore(struct efx_nic *efx)
2770 efx_farch_filter_push_rx_config(efx); 2769 efx_farch_filter_push_rx_config(efx);
2771 efx_farch_filter_push_tx_limits(efx); 2770 efx_farch_filter_push_tx_limits(efx);
2772 2771
2773 spin_unlock_bh(&efx->filter_lock); 2772 up_write(&state->lock);
2774} 2773}
2775 2774
2776void efx_farch_filter_table_remove(struct efx_nic *efx) 2775void efx_farch_filter_table_remove(struct efx_nic *efx)
@@ -2864,7 +2863,7 @@ void efx_farch_filter_update_rx_scatter(struct efx_nic *efx)
2864 efx_oword_t filter; 2863 efx_oword_t filter;
2865 unsigned int filter_idx; 2864 unsigned int filter_idx;
2866 2865
2867 spin_lock_bh(&efx->filter_lock); 2866 down_write(&state->lock);
2868 2867
2869 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 2868 for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
2870 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 2869 table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2896,33 +2895,30 @@ void efx_farch_filter_update_rx_scatter(struct efx_nic *efx)
2896 2895
2897 efx_farch_filter_push_rx_config(efx); 2896 efx_farch_filter_push_rx_config(efx);
2898 2897
2899 spin_unlock_bh(&efx->filter_lock); 2898 up_write(&state->lock);
2900} 2899}
2901 2900
2902#ifdef CONFIG_RFS_ACCEL 2901#ifdef CONFIG_RFS_ACCEL
2903 2902
2904s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
2905 struct efx_filter_spec *gen_spec)
2906{
2907 return efx_farch_filter_insert(efx, gen_spec, true);
2908}
2909
2910bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 2903bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
2911 unsigned int index) 2904 unsigned int index)
2912{ 2905{
2913 struct efx_farch_filter_state *state = efx->filter_state; 2906 struct efx_farch_filter_state *state = efx->filter_state;
2914 struct efx_farch_filter_table *table = 2907 struct efx_farch_filter_table *table;
2915 &state->table[EFX_FARCH_FILTER_TABLE_RX_IP]; 2908 bool ret = false;
2916 2909
2910 down_write(&state->lock);
2911 table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP];
2917 if (test_bit(index, table->used_bitmap) && 2912 if (test_bit(index, table->used_bitmap) &&
2918 table->spec[index].priority == EFX_FILTER_PRI_HINT && 2913 table->spec[index].priority == EFX_FILTER_PRI_HINT &&
2919 rps_may_expire_flow(efx->net_dev, table->spec[index].dmaq_id, 2914 rps_may_expire_flow(efx->net_dev, table->spec[index].dmaq_id,
2920 flow_id, index)) { 2915 flow_id, index)) {
2921 efx_farch_filter_table_clear_entry(efx, table, index); 2916 efx_farch_filter_table_clear_entry(efx, table, index);
2922 return true; 2917 ret = true;
2923 } 2918 }
2924 2919
2925 return false; 2920 up_write(&state->lock);
2921 return ret;
2926} 2922}
2927 2923
2928#endif /* CONFIG_RFS_ACCEL */ 2924#endif /* CONFIG_RFS_ACCEL */
diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h
index 2453f3849e72..5e379a83c729 100644
--- a/drivers/net/ethernet/sfc/net_driver.h
+++ b/drivers/net/ethernet/sfc/net_driver.h
@@ -430,6 +430,7 @@ enum efx_sync_events_state {
430 * @event_test_cpu: Last CPU to handle interrupt or test event for this channel 430 * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
431 * @irq_count: Number of IRQs since last adaptive moderation decision 431 * @irq_count: Number of IRQs since last adaptive moderation decision
432 * @irq_mod_score: IRQ moderation score 432 * @irq_mod_score: IRQ moderation score
433 * @filter_work: Work item for efx_filter_rfs_expire()
433 * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS, 434 * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
434 * indexed by filter ID 435 * indexed by filter ID
435 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors 436 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
@@ -475,6 +476,7 @@ struct efx_channel {
475 unsigned int irq_mod_score; 476 unsigned int irq_mod_score;
476#ifdef CONFIG_RFS_ACCEL 477#ifdef CONFIG_RFS_ACCEL
477 unsigned int rfs_filters_added; 478 unsigned int rfs_filters_added;
479 struct work_struct filter_work;
478#define RPS_FLOW_ID_INVALID 0xFFFFFFFF 480#define RPS_FLOW_ID_INVALID 0xFFFFFFFF
479 u32 *rps_flow_id; 481 u32 *rps_flow_id;
480#endif 482#endif
@@ -794,6 +796,7 @@ struct efx_rss_context {
794 * @rx_scatter: Scatter mode enabled for receives 796 * @rx_scatter: Scatter mode enabled for receives
795 * @rss_context: Main RSS context. Its @list member is the head of the list of 797 * @rss_context: Main RSS context. Its @list member is the head of the list of
796 * RSS contexts created by user requests 798 * RSS contexts created by user requests
799 * @rss_lock: Protects custom RSS context software state in @rss_context.list
797 * @int_error_count: Number of internal errors seen recently 800 * @int_error_count: Number of internal errors seen recently
798 * @int_error_expire: Time at which error count will be expired 801 * @int_error_expire: Time at which error count will be expired
799 * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will 802 * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
@@ -841,9 +844,9 @@ struct efx_rss_context {
841 * @loopback_mode: Loopback status 844 * @loopback_mode: Loopback status
842 * @loopback_modes: Supported loopback mode bitmask 845 * @loopback_modes: Supported loopback mode bitmask
843 * @loopback_selftest: Offline self-test private state 846 * @loopback_selftest: Offline self-test private state
844 * @filter_sem: Filter table rw_semaphore, for freeing the table 847 * @filter_sem: Filter table rw_semaphore, protects existence of @filter_state
845 * @filter_lock: Filter table lock, for mere content changes
846 * @filter_state: Architecture-dependent filter table state 848 * @filter_state: Architecture-dependent filter table state
849 * @rps_mutex: Protects RPS state of all channels
847 * @rps_expire_channel: Next channel to check for expiry 850 * @rps_expire_channel: Next channel to check for expiry
848 * @rps_expire_index: Next index to check for expiry in 851 * @rps_expire_index: Next index to check for expiry in
849 * @rps_expire_channel's @rps_flow_id 852 * @rps_expire_channel's @rps_flow_id
@@ -938,6 +941,7 @@ struct efx_nic {
938 int rx_packet_ts_offset; 941 int rx_packet_ts_offset;
939 bool rx_scatter; 942 bool rx_scatter;
940 struct efx_rss_context rss_context; 943 struct efx_rss_context rss_context;
944 struct mutex rss_lock;
941 945
942 unsigned int_error_count; 946 unsigned int_error_count;
943 unsigned long int_error_expire; 947 unsigned long int_error_expire;
@@ -995,9 +999,9 @@ struct efx_nic {
995 void *loopback_selftest; 999 void *loopback_selftest;
996 1000
997 struct rw_semaphore filter_sem; 1001 struct rw_semaphore filter_sem;
998 spinlock_t filter_lock;
999 void *filter_state; 1002 void *filter_state;
1000#ifdef CONFIG_RFS_ACCEL 1003#ifdef CONFIG_RFS_ACCEL
1004 struct mutex rps_mutex;
1001 unsigned int rps_expire_channel; 1005 unsigned int rps_expire_channel;
1002 unsigned int rps_expire_index; 1006 unsigned int rps_expire_index;
1003#endif 1007#endif
@@ -1152,10 +1156,6 @@ struct efx_udp_tunnel {
1152 * @filter_count_rx_used: Get the number of filters in use at a given priority 1156 * @filter_count_rx_used: Get the number of filters in use at a given priority
1153 * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1 1157 * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
1154 * @filter_get_rx_ids: Get list of RX filters at a given priority 1158 * @filter_get_rx_ids: Get list of RX filters at a given priority
1155 * @filter_rfs_insert: Add or replace a filter for RFS. This must be
1156 * atomic. The hardware change may be asynchronous but should
1157 * not be delayed for long. It may fail if this can't be done
1158 * atomically.
1159 * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS. 1159 * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
1160 * This must check whether the specified table entry is used by RFS 1160 * This must check whether the specified table entry is used by RFS
1161 * and that rps_may_expire_flow() returns true for it. 1161 * and that rps_may_expire_flow() returns true for it.
@@ -1306,8 +1306,6 @@ struct efx_nic_type {
1306 enum efx_filter_priority priority, 1306 enum efx_filter_priority priority,
1307 u32 *buf, u32 size); 1307 u32 *buf, u32 size);
1308#ifdef CONFIG_RFS_ACCEL 1308#ifdef CONFIG_RFS_ACCEL
1309 s32 (*filter_rfs_insert)(struct efx_nic *efx,
1310 struct efx_filter_spec *spec);
1311 bool (*filter_rfs_expire_one)(struct efx_nic *efx, u32 flow_id, 1309 bool (*filter_rfs_expire_one)(struct efx_nic *efx, u32 flow_id,
1312 unsigned int index); 1310 unsigned int index);
1313#endif 1311#endif
diff --git a/drivers/net/ethernet/sfc/nic.h b/drivers/net/ethernet/sfc/nic.h
index d080a414e8f2..5640034bda10 100644
--- a/drivers/net/ethernet/sfc/nic.h
+++ b/drivers/net/ethernet/sfc/nic.h
@@ -365,6 +365,8 @@ enum {
365 * @vi_base: Absolute index of first VI in this function 365 * @vi_base: Absolute index of first VI in this function
366 * @n_allocated_vis: Number of VIs allocated to this function 366 * @n_allocated_vis: Number of VIs allocated to this function
367 * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot 367 * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
368 * @must_restore_rss_contexts: Flag: RSS contexts have yet to be restored after
369 * MC reboot
368 * @must_restore_filters: Flag: filters have yet to be restored after MC reboot 370 * @must_restore_filters: Flag: filters have yet to be restored after MC reboot
369 * @n_piobufs: Number of PIO buffers allocated to this function 371 * @n_piobufs: Number of PIO buffers allocated to this function
370 * @wc_membase: Base address of write-combining mapping of the memory BAR 372 * @wc_membase: Base address of write-combining mapping of the memory BAR
@@ -407,6 +409,7 @@ struct efx_ef10_nic_data {
407 unsigned int vi_base; 409 unsigned int vi_base;
408 unsigned int n_allocated_vis; 410 unsigned int n_allocated_vis;
409 bool must_realloc_vis; 411 bool must_realloc_vis;
412 bool must_restore_rss_contexts;
410 bool must_restore_filters; 413 bool must_restore_filters;
411 unsigned int n_piobufs; 414 unsigned int n_piobufs;
412 void __iomem *wc_membase, *pio_write_base; 415 void __iomem *wc_membase, *pio_write_base;
@@ -601,8 +604,6 @@ s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
601 enum efx_filter_priority priority, u32 *buf, 604 enum efx_filter_priority priority, u32 *buf,
602 u32 size); 605 u32 size);
603#ifdef CONFIG_RFS_ACCEL 606#ifdef CONFIG_RFS_ACCEL
604s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
605 struct efx_filter_spec *spec);
606bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 607bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
607 unsigned int index); 608 unsigned int index);
608#endif 609#endif
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index cfe76aad79ee..95682831484e 100644
--- a/drivers/net/ethernet/sfc/rx.c
+++ b/drivers/net/ethernet/sfc/rx.c
@@ -827,14 +827,67 @@ MODULE_PARM_DESC(rx_refill_threshold,
827 827
828#ifdef CONFIG_RFS_ACCEL 828#ifdef CONFIG_RFS_ACCEL
829 829
830/**
831 * struct efx_async_filter_insertion - Request to asynchronously insert a filter
832 * @net_dev: Reference to the netdevice
833 * @spec: The filter to insert
834 * @work: Workitem for this request
835 * @rxq_index: Identifies the channel for which this request was made
836 * @flow_id: Identifies the kernel-side flow for which this request was made
837 */
838struct efx_async_filter_insertion {
839 struct net_device *net_dev;
840 struct efx_filter_spec spec;
841 struct work_struct work;
842 u16 rxq_index;
843 u32 flow_id;
844};
845
846static void efx_filter_rfs_work(struct work_struct *data)
847{
848 struct efx_async_filter_insertion *req = container_of(data, struct efx_async_filter_insertion,
849 work);
850 struct efx_nic *efx = netdev_priv(req->net_dev);
851 struct efx_channel *channel = efx_get_channel(efx, req->rxq_index);
852 int rc;
853
854 rc = efx->type->filter_insert(efx, &req->spec, false);
855 if (rc >= 0) {
856 /* Remember this so we can check whether to expire the filter
857 * later.
858 */
859 mutex_lock(&efx->rps_mutex);
860 channel->rps_flow_id[rc] = req->flow_id;
861 ++channel->rfs_filters_added;
862 mutex_unlock(&efx->rps_mutex);
863
864 if (req->spec.ether_type == htons(ETH_P_IP))
865 netif_info(efx, rx_status, efx->net_dev,
866 "steering %s %pI4:%u:%pI4:%u to queue %u [flow %u filter %d]\n",
867 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
868 req->spec.rem_host, ntohs(req->spec.rem_port),
869 req->spec.loc_host, ntohs(req->spec.loc_port),
870 req->rxq_index, req->flow_id, rc);
871 else
872 netif_info(efx, rx_status, efx->net_dev,
873 "steering %s [%pI6]:%u:[%pI6]:%u to queue %u [flow %u filter %d]\n",
874 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
875 req->spec.rem_host, ntohs(req->spec.rem_port),
876 req->spec.loc_host, ntohs(req->spec.loc_port),
877 req->rxq_index, req->flow_id, rc);
878 }
879
880 /* Release references */
881 dev_put(req->net_dev);
882 kfree(req);
883}
884
830int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb, 885int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
831 u16 rxq_index, u32 flow_id) 886 u16 rxq_index, u32 flow_id)
832{ 887{
833 struct efx_nic *efx = netdev_priv(net_dev); 888 struct efx_nic *efx = netdev_priv(net_dev);
834 struct efx_channel *channel; 889 struct efx_async_filter_insertion *req;
835 struct efx_filter_spec spec;
836 struct flow_keys fk; 890 struct flow_keys fk;
837 int rc;
838 891
839 if (flow_id == RPS_FLOW_ID_INVALID) 892 if (flow_id == RPS_FLOW_ID_INVALID)
840 return -EINVAL; 893 return -EINVAL;
@@ -847,50 +900,39 @@ int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
847 if (fk.control.flags & FLOW_DIS_IS_FRAGMENT) 900 if (fk.control.flags & FLOW_DIS_IS_FRAGMENT)
848 return -EPROTONOSUPPORT; 901 return -EPROTONOSUPPORT;
849 902
850 efx_filter_init_rx(&spec, EFX_FILTER_PRI_HINT, 903 req = kmalloc(sizeof(*req), GFP_ATOMIC);
904 if (!req)
905 return -ENOMEM;
906
907 efx_filter_init_rx(&req->spec, EFX_FILTER_PRI_HINT,
851 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, 908 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
852 rxq_index); 909 rxq_index);
853 spec.match_flags = 910 req->spec.match_flags =
854 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO | 911 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
855 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT | 912 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT |
856 EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT; 913 EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT;
857 spec.ether_type = fk.basic.n_proto; 914 req->spec.ether_type = fk.basic.n_proto;
858 spec.ip_proto = fk.basic.ip_proto; 915 req->spec.ip_proto = fk.basic.ip_proto;
859 916
860 if (fk.basic.n_proto == htons(ETH_P_IP)) { 917 if (fk.basic.n_proto == htons(ETH_P_IP)) {
861 spec.rem_host[0] = fk.addrs.v4addrs.src; 918 req->spec.rem_host[0] = fk.addrs.v4addrs.src;
862 spec.loc_host[0] = fk.addrs.v4addrs.dst; 919 req->spec.loc_host[0] = fk.addrs.v4addrs.dst;
863 } else { 920 } else {
864 memcpy(spec.rem_host, &fk.addrs.v6addrs.src, sizeof(struct in6_addr)); 921 memcpy(req->spec.rem_host, &fk.addrs.v6addrs.src,
865 memcpy(spec.loc_host, &fk.addrs.v6addrs.dst, sizeof(struct in6_addr)); 922 sizeof(struct in6_addr));
923 memcpy(req->spec.loc_host, &fk.addrs.v6addrs.dst,
924 sizeof(struct in6_addr));
866 } 925 }
867 926
868 spec.rem_port = fk.ports.src; 927 req->spec.rem_port = fk.ports.src;
869 spec.loc_port = fk.ports.dst; 928 req->spec.loc_port = fk.ports.dst;
870
871 rc = efx->type->filter_rfs_insert(efx, &spec);
872 if (rc < 0)
873 return rc;
874 929
875 /* Remember this so we can check whether to expire the filter later */ 930 dev_hold(req->net_dev = net_dev);
876 channel = efx_get_channel(efx, rxq_index); 931 INIT_WORK(&req->work, efx_filter_rfs_work);
877 channel->rps_flow_id[rc] = flow_id; 932 req->rxq_index = rxq_index;
878 ++channel->rfs_filters_added; 933 req->flow_id = flow_id;
879 934 schedule_work(&req->work);
880 if (spec.ether_type == htons(ETH_P_IP)) 935 return 0;
881 netif_info(efx, rx_status, efx->net_dev,
882 "steering %s %pI4:%u:%pI4:%u to queue %u [flow %u filter %d]\n",
883 (spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
884 spec.rem_host, ntohs(spec.rem_port), spec.loc_host,
885 ntohs(spec.loc_port), rxq_index, flow_id, rc);
886 else
887 netif_info(efx, rx_status, efx->net_dev,
888 "steering %s [%pI6]:%u:[%pI6]:%u to queue %u [flow %u filter %d]\n",
889 (spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
890 spec.rem_host, ntohs(spec.rem_port), spec.loc_host,
891 ntohs(spec.loc_port), rxq_index, flow_id, rc);
892
893 return rc;
894} 936}
895 937
896bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned int quota) 938bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned int quota)
@@ -899,9 +941,8 @@ bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned int quota)
899 unsigned int channel_idx, index, size; 941 unsigned int channel_idx, index, size;
900 u32 flow_id; 942 u32 flow_id;
901 943
902 if (!spin_trylock_bh(&efx->filter_lock)) 944 if (!mutex_trylock(&efx->rps_mutex))
903 return false; 945 return false;
904
905 expire_one = efx->type->filter_rfs_expire_one; 946 expire_one = efx->type->filter_rfs_expire_one;
906 channel_idx = efx->rps_expire_channel; 947 channel_idx = efx->rps_expire_channel;
907 index = efx->rps_expire_index; 948 index = efx->rps_expire_index;
@@ -926,7 +967,7 @@ bool __efx_filter_rfs_expire(struct efx_nic *efx, unsigned int quota)
926 efx->rps_expire_channel = channel_idx; 967 efx->rps_expire_channel = channel_idx;
927 efx->rps_expire_index = index; 968 efx->rps_expire_index = index;
928 969
929 spin_unlock_bh(&efx->filter_lock); 970 mutex_unlock(&efx->rps_mutex);
930 return true; 971 return true;
931} 972}
932 973
diff --git a/drivers/net/ethernet/sfc/siena.c b/drivers/net/ethernet/sfc/siena.c
index 18aab25234ba..65161f68265a 100644
--- a/drivers/net/ethernet/sfc/siena.c
+++ b/drivers/net/ethernet/sfc/siena.c
@@ -1035,7 +1035,6 @@ const struct efx_nic_type siena_a0_nic_type = {
1035 .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit, 1035 .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
1036 .filter_get_rx_ids = efx_farch_filter_get_rx_ids, 1036 .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
1037#ifdef CONFIG_RFS_ACCEL 1037#ifdef CONFIG_RFS_ACCEL
1038 .filter_rfs_insert = efx_farch_filter_rfs_insert,
1039 .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one, 1038 .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one,
1040#endif 1039#endif
1041#ifdef CONFIG_SFC_MTD 1040#ifdef CONFIG_SFC_MTD