Skip to content

Commit fc7a6c2

Browse files
ecree-solarflaredavem330
authored andcommitted
sfc: use a semaphore to lock farch filters too
With this change, the spinlock efx->filter_lock is no longer used and is thus removed. Signed-off-by: Edward Cree <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c2bebe3 commit fc7a6c2

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

drivers/net/ethernet/sfc/farch.c

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ struct efx_farch_filter_table {
18781878
};
18791879

18801880
struct efx_farch_filter_state {
1881+
struct rw_semaphore lock; /* Protects table contents */
18811882
struct efx_farch_filter_table table[EFX_FARCH_FILTER_TABLE_COUNT];
18821883
};
18831884

@@ -2397,9 +2398,13 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
23972398
if (rc)
23982399
return rc;
23992400

2401+
down_write(&state->lock);
2402+
24002403
table = &state->table[efx_farch_filter_spec_table_id(&spec)];
2401-
if (table->size == 0)
2402-
return -EINVAL;
2404+
if (table->size == 0) {
2405+
rc = -EINVAL;
2406+
goto out_unlock;
2407+
}
24032408

24042409
netif_vdbg(efx, hw, efx->net_dev,
24052410
"%s: type %d search_limit=%d", __func__, spec.type,
@@ -2412,8 +2417,6 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
24122417
EFX_FARCH_FILTER_MC_DEF - EFX_FARCH_FILTER_UC_DEF);
24132418
rep_index = spec.type - EFX_FARCH_FILTER_UC_DEF;
24142419
ins_index = rep_index;
2415-
2416-
spin_lock_bh(&efx->filter_lock);
24172420
} else {
24182421
/* Search concurrently for
24192422
* (1) a filter to be replaced (rep_index): any filter
@@ -2443,8 +2446,6 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
24432446
ins_index = -1;
24442447
depth = 1;
24452448

2446-
spin_lock_bh(&efx->filter_lock);
2447-
24482449
for (;;) {
24492450
if (!test_bit(i, table->used_bitmap)) {
24502451
if (ins_index < 0)
@@ -2463,7 +2464,7 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
24632464
/* Case (b) */
24642465
if (ins_index < 0) {
24652466
rc = -EBUSY;
2466-
goto out;
2467+
goto out_unlock;
24672468
}
24682469
rep_index = -1;
24692470
break;
@@ -2483,11 +2484,11 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
24832484

24842485
if (spec.priority == saved_spec->priority && !replace_equal) {
24852486
rc = -EEXIST;
2486-
goto out;
2487+
goto out_unlock;
24872488
}
24882489
if (spec.priority < saved_spec->priority) {
24892490
rc = -EPERM;
2490-
goto out;
2491+
goto out_unlock;
24912492
}
24922493
if (saved_spec->priority == EFX_FILTER_PRI_AUTO ||
24932494
saved_spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO)
@@ -2528,8 +2529,8 @@ s32 efx_farch_filter_insert(struct efx_nic *efx,
25282529
__func__, spec.type, ins_index, spec.dmaq_id);
25292530
rc = efx_farch_filter_make_id(&spec, ins_index);
25302531

2531-
out:
2532-
spin_unlock_bh(&efx->filter_lock);
2532+
out_unlock:
2533+
up_write(&state->lock);
25332534
return rc;
25342535
}
25352536

@@ -2604,11 +2605,11 @@ int efx_farch_filter_remove_safe(struct efx_nic *efx,
26042605
filter_idx = efx_farch_filter_id_index(filter_id);
26052606
if (filter_idx >= table->size)
26062607
return -ENOENT;
2608+
down_write(&state->lock);
26072609
spec = &table->spec[filter_idx];
26082610

2609-
spin_lock_bh(&efx->filter_lock);
26102611
rc = efx_farch_filter_remove(efx, table, filter_idx, priority);
2611-
spin_unlock_bh(&efx->filter_lock);
2612+
up_write(&state->lock);
26122613

26132614
return rc;
26142615
}
@@ -2622,30 +2623,28 @@ int efx_farch_filter_get_safe(struct efx_nic *efx,
26222623
struct efx_farch_filter_table *table;
26232624
struct efx_farch_filter_spec *spec;
26242625
unsigned int filter_idx;
2625-
int rc;
2626+
int rc = -ENOENT;
2627+
2628+
down_read(&state->lock);
26262629

26272630
table_id = efx_farch_filter_id_table_id(filter_id);
26282631
if ((unsigned int)table_id >= EFX_FARCH_FILTER_TABLE_COUNT)
2629-
return -ENOENT;
2632+
goto out_unlock;
26302633
table = &state->table[table_id];
26312634

26322635
filter_idx = efx_farch_filter_id_index(filter_id);
26332636
if (filter_idx >= table->size)
2634-
return -ENOENT;
2637+
goto out_unlock;
26352638
spec = &table->spec[filter_idx];
26362639

2637-
spin_lock_bh(&efx->filter_lock);
2638-
26392640
if (test_bit(filter_idx, table->used_bitmap) &&
26402641
spec->priority == priority) {
26412642
efx_farch_filter_to_gen_spec(spec_buf, spec);
26422643
rc = 0;
2643-
} else {
2644-
rc = -ENOENT;
26452644
}
26462645

2647-
spin_unlock_bh(&efx->filter_lock);
2648-
2646+
out_unlock:
2647+
up_read(&state->lock);
26492648
return rc;
26502649
}
26512650

@@ -2658,13 +2657,13 @@ efx_farch_filter_table_clear(struct efx_nic *efx,
26582657
struct efx_farch_filter_table *table = &state->table[table_id];
26592658
unsigned int filter_idx;
26602659

2661-
spin_lock_bh(&efx->filter_lock);
2660+
down_write(&state->lock);
26622661
for (filter_idx = 0; filter_idx < table->size; ++filter_idx) {
26632662
if (table->spec[filter_idx].priority != EFX_FILTER_PRI_AUTO)
26642663
efx_farch_filter_remove(efx, table,
26652664
filter_idx, priority);
26662665
}
2667-
spin_unlock_bh(&efx->filter_lock);
2666+
up_write(&state->lock);
26682667
}
26692668

26702669
int efx_farch_filter_clear_rx(struct efx_nic *efx,
@@ -2688,7 +2687,7 @@ u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
26882687
unsigned int filter_idx;
26892688
u32 count = 0;
26902689

2691-
spin_lock_bh(&efx->filter_lock);
2690+
down_read(&state->lock);
26922691

26932692
for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
26942693
table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2701,7 +2700,7 @@ u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
27012700
}
27022701
}
27032702

2704-
spin_unlock_bh(&efx->filter_lock);
2703+
up_read(&state->lock);
27052704

27062705
return count;
27072706
}
@@ -2716,7 +2715,7 @@ s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
27162715
unsigned int filter_idx;
27172716
s32 count = 0;
27182717

2719-
spin_lock_bh(&efx->filter_lock);
2718+
down_read(&state->lock);
27202719

27212720
for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
27222721
table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2735,7 +2734,7 @@ s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
27352734
}
27362735
}
27372736
out:
2738-
spin_unlock_bh(&efx->filter_lock);
2737+
up_read(&state->lock);
27392738

27402739
return count;
27412740
}
@@ -2749,7 +2748,7 @@ void efx_farch_filter_table_restore(struct efx_nic *efx)
27492748
efx_oword_t filter;
27502749
unsigned int filter_idx;
27512750

2752-
spin_lock_bh(&efx->filter_lock);
2751+
down_write(&state->lock);
27532752

27542753
for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) {
27552754
table = &state->table[table_id];
@@ -2770,7 +2769,7 @@ void efx_farch_filter_table_restore(struct efx_nic *efx)
27702769
efx_farch_filter_push_rx_config(efx);
27712770
efx_farch_filter_push_tx_limits(efx);
27722771

2773-
spin_unlock_bh(&efx->filter_lock);
2772+
up_write(&state->lock);
27742773
}
27752774

27762775
void efx_farch_filter_table_remove(struct efx_nic *efx)
@@ -2864,7 +2863,7 @@ void efx_farch_filter_update_rx_scatter(struct efx_nic *efx)
28642863
efx_oword_t filter;
28652864
unsigned int filter_idx;
28662865

2867-
spin_lock_bh(&efx->filter_lock);
2866+
down_write(&state->lock);
28682867

28692868
for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP;
28702869
table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF;
@@ -2896,7 +2895,7 @@ void efx_farch_filter_update_rx_scatter(struct efx_nic *efx)
28962895

28972896
efx_farch_filter_push_rx_config(efx);
28982897

2899-
spin_unlock_bh(&efx->filter_lock);
2898+
up_write(&state->lock);
29002899
}
29012900

29022901
#ifdef CONFIG_RFS_ACCEL
@@ -2908,7 +2907,7 @@ bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
29082907
struct efx_farch_filter_table *table;
29092908
bool ret = false;
29102909

2911-
spin_lock_bh(&efx->filter_lock);
2910+
down_write(&state->lock);
29122911
table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP];
29132912
if (test_bit(index, table->used_bitmap) &&
29142913
table->spec[index].priority == EFX_FILTER_PRI_HINT &&
@@ -2918,7 +2917,7 @@ bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
29182917
ret = true;
29192918
}
29202919

2921-
spin_unlock_bh(&efx->filter_lock);
2920+
up_write(&state->lock);
29222921
return ret;
29232922
}
29242923

drivers/net/ethernet/sfc/net_driver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ struct efx_rss_context {
844844
* @loopback_modes: Supported loopback mode bitmask
845845
* @loopback_selftest: Offline self-test private state
846846
* @filter_sem: Filter table rw_semaphore, protects existence of @filter_state
847-
* @filter_lock: Filter table lock, for mere content changes
848847
* @filter_state: Architecture-dependent filter table state
849848
* @rps_mutex: Protects RPS state of all channels
850849
* @rps_expire_channel: Next channel to check for expiry
@@ -998,7 +997,6 @@ struct efx_nic {
998997
void *loopback_selftest;
999998

1000999
struct rw_semaphore filter_sem;
1001-
spinlock_t filter_lock;
10021000
void *filter_state;
10031001
#ifdef CONFIG_RFS_ACCEL
10041002
struct mutex rps_mutex;

0 commit comments

Comments
 (0)