Skip to content

Commit 28b3870

Browse files
RajuRangojudavem330
authored andcommitted
cxgb4: Re-work the logic for mps refcounting
Remove existing mps refcounting code which was added only for encap filters and add necessary data structures/functions to support mps reference counting for all the mac filters. Also add wrapper functions for allocating and freeing encap mac filters. Signed-off-by: Raju Rangoju <rajur@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0fec7e7 commit 28b3870

File tree

5 files changed

+134
-22
lines changed

5 files changed

+134
-22
lines changed

drivers/net/ethernet/chelsio/cxgb4/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obj-$(CONFIG_CHELSIO_T4) += cxgb4.o
77

88
cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o \
99
cxgb4_uld.o srq.o sched.o cxgb4_filter.o cxgb4_tc_u32.o \
10-
cxgb4_ptp.o cxgb4_tc_flower.o cxgb4_cudbg.o \
10+
cxgb4_ptp.o cxgb4_tc_flower.o cxgb4_cudbg.o cxgb4_mps.o \
1111
cudbg_common.o cudbg_lib.o cudbg_zlib.o
1212
cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o
1313
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,6 @@ struct mbox_list {
905905
struct list_head list;
906906
};
907907

908-
struct mps_encap_entry {
909-
atomic_t refcnt;
910-
};
911-
912908
#if IS_ENABLED(CONFIG_THERMAL)
913909
struct ch_thermal {
914910
struct thermal_zone_device *tzdev;
@@ -917,6 +913,14 @@ struct ch_thermal {
917913
};
918914
#endif
919915

916+
struct mps_entries_ref {
917+
struct list_head list;
918+
u8 addr[ETH_ALEN];
919+
u8 mask[ETH_ALEN];
920+
u16 idx;
921+
refcount_t refcnt;
922+
};
923+
920924
struct adapter {
921925
void __iomem *regs;
922926
void __iomem *bar2;
@@ -969,14 +973,15 @@ struct adapter {
969973
unsigned int rawf_start;
970974
unsigned int rawf_cnt;
971975
struct smt_data *smt;
972-
struct mps_encap_entry *mps_encap;
973976
struct cxgb4_uld_info *uld;
974977
void *uld_handle[CXGB4_ULD_MAX];
975978
unsigned int num_uld;
976979
unsigned int num_ofld_uld;
977980
struct list_head list_node;
978981
struct list_head rcu_node;
979982
struct list_head mac_hlist; /* list of MAC addresses in MPS Hash */
983+
struct list_head mps_ref;
984+
spinlock_t mps_ref_lock; /* lock for syncing mps ref/def activities */
980985

981986
void *iscsi_ppm;
982987

@@ -1906,4 +1911,13 @@ int cxgb4_set_msix_aff(struct adapter *adap, unsigned short vec,
19061911
cpumask_var_t *aff_mask, int idx);
19071912
void cxgb4_clear_msix_aff(unsigned short vec, cpumask_var_t aff_mask);
19081913

1914+
int cxgb4_init_mps_ref_entries(struct adapter *adap);
1915+
void cxgb4_free_mps_ref_entries(struct adapter *adap);
1916+
int cxgb4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
1917+
const u8 *addr, const u8 *mask,
1918+
unsigned int vni, unsigned int vni_mask,
1919+
u8 dip_hit, u8 lookup_type, bool sleep_ok);
1920+
int cxgb4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
1921+
int idx, bool sleep_ok);
1922+
19091923
#endif /* __CXGB4_H__ */

drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,8 @@ void clear_filter(struct adapter *adap, struct filter_entry *f)
727727
cxgb4_smt_release(f->smt);
728728

729729
if (f->fs.val.encap_vld && f->fs.val.ovlan_vld)
730-
if (atomic_dec_and_test(&adap->mps_encap[f->fs.val.ovlan &
731-
0x1ff].refcnt))
732-
t4_free_encap_mac_filt(adap, pi->viid,
733-
f->fs.val.ovlan & 0x1ff, 0);
730+
t4_free_encap_mac_filt(adap, pi->viid,
731+
f->fs.val.ovlan & 0x1ff, 0);
734732

735733
if ((f->fs.hash || is_t6(adap->params.chip)) && f->fs.type)
736734
cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
@@ -1177,7 +1175,6 @@ static int cxgb4_set_hash_filter(struct net_device *dev,
11771175
if (ret < 0)
11781176
goto free_atid;
11791177

1180-
atomic_inc(&adapter->mps_encap[ret].refcnt);
11811178
f->fs.val.ovlan = ret;
11821179
f->fs.mask.ovlan = 0xffff;
11831180
f->fs.val.ovlan_vld = 1;
@@ -1420,7 +1417,6 @@ int __cxgb4_set_filter(struct net_device *dev, int filter_id,
14201417
if (ret < 0)
14211418
goto free_clip;
14221419

1423-
atomic_inc(&adapter->mps_encap[ret].refcnt);
14241420
f->fs.val.ovlan = ret;
14251421
f->fs.mask.ovlan = 0x1ff;
14261422
f->fs.val.ovlan_vld = 1;

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,8 +3273,6 @@ static void cxgb_del_udp_tunnel(struct net_device *netdev,
32733273
i);
32743274
return;
32753275
}
3276-
atomic_dec(&adapter->mps_encap[adapter->rawf_start +
3277-
pi->port_id].refcnt);
32783276
}
32793277
}
32803278

@@ -3363,7 +3361,6 @@ static void cxgb_add_udp_tunnel(struct net_device *netdev,
33633361
cxgb_del_udp_tunnel(netdev, ti);
33643362
return;
33653363
}
3366-
atomic_inc(&adapter->mps_encap[ret].refcnt);
33673364
}
33683365
}
33693366

@@ -5446,7 +5443,6 @@ static void free_some_resources(struct adapter *adapter)
54465443
{
54475444
unsigned int i;
54485445

5449-
kvfree(adapter->mps_encap);
54505446
kvfree(adapter->smt);
54515447
kvfree(adapter->l2t);
54525448
kvfree(adapter->srq);
@@ -5972,12 +5968,6 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
59725968
adapter->params.offload = 0;
59735969
}
59745970

5975-
adapter->mps_encap = kvcalloc(adapter->params.arch.mps_tcam_size,
5976-
sizeof(struct mps_encap_entry),
5977-
GFP_KERNEL);
5978-
if (!adapter->mps_encap)
5979-
dev_warn(&pdev->dev, "could not allocate MPS Encap entries, continuing\n");
5980-
59815971
#if IS_ENABLED(CONFIG_IPV6)
59825972
if (chip_ver <= CHELSIO_T5 &&
59835973
(!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
@@ -6053,6 +6043,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
60536043
/* check for PCI Express bandwidth capabiltites */
60546044
pcie_print_link_status(pdev);
60556045

6046+
cxgb4_init_mps_ref_entries(adapter);
6047+
60566048
err = init_rss(adapter);
60576049
if (err)
60586050
goto out_free_dev;
@@ -6179,6 +6171,8 @@ static void remove_one(struct pci_dev *pdev)
61796171

61806172
disable_interrupts(adapter);
61816173

6174+
cxgb4_free_mps_ref_entries(adapter);
6175+
61826176
for_each_port(adapter, i)
61836177
if (adapter->port[i]->reg_state == NETREG_REGISTERED)
61846178
unregister_netdev(adapter->port[i]);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2019 Chelsio Communications, Inc. All rights reserved. */
3+
4+
#include "cxgb4.h"
5+
6+
static int cxgb4_mps_ref_dec(struct adapter *adap, u16 idx)
7+
{
8+
struct mps_entries_ref *mps_entry, *tmp;
9+
int ret = -EINVAL;
10+
11+
spin_lock(&adap->mps_ref_lock);
12+
list_for_each_entry_safe(mps_entry, tmp, &adap->mps_ref, list) {
13+
if (mps_entry->idx == idx) {
14+
if (!refcount_dec_and_test(&mps_entry->refcnt)) {
15+
spin_unlock(&adap->mps_ref_lock);
16+
return -EBUSY;
17+
}
18+
list_del(&mps_entry->list);
19+
kfree(mps_entry);
20+
ret = 0;
21+
break;
22+
}
23+
}
24+
spin_unlock(&adap->mps_ref_lock);
25+
return ret;
26+
}
27+
28+
static int cxgb4_mps_ref_inc(struct adapter *adap, const u8 *mac_addr,
29+
u16 idx, const u8 *mask)
30+
{
31+
u8 bitmask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
32+
struct mps_entries_ref *mps_entry;
33+
int ret = 0;
34+
35+
spin_lock_bh(&adap->mps_ref_lock);
36+
list_for_each_entry(mps_entry, &adap->mps_ref, list) {
37+
if (mps_entry->idx == idx) {
38+
refcount_inc(&mps_entry->refcnt);
39+
goto unlock;
40+
}
41+
}
42+
mps_entry = kzalloc(sizeof(*mps_entry), GFP_ATOMIC);
43+
if (!mps_entry) {
44+
ret = -ENOMEM;
45+
goto unlock;
46+
}
47+
ether_addr_copy(mps_entry->mask, mask ? mask : bitmask);
48+
ether_addr_copy(mps_entry->addr, mac_addr);
49+
mps_entry->idx = idx;
50+
refcount_set(&mps_entry->refcnt, 1);
51+
list_add_tail(&mps_entry->list, &adap->mps_ref);
52+
unlock:
53+
spin_unlock_bh(&adap->mps_ref_lock);
54+
return ret;
55+
}
56+
57+
int cxgb4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
58+
int idx, bool sleep_ok)
59+
{
60+
int ret = 0;
61+
62+
if (!cxgb4_mps_ref_dec(adap, idx))
63+
ret = t4_free_encap_mac_filt(adap, viid, idx, sleep_ok);
64+
65+
return ret;
66+
}
67+
68+
int cxgb4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
69+
const u8 *addr, const u8 *mask,
70+
unsigned int vni, unsigned int vni_mask,
71+
u8 dip_hit, u8 lookup_type, bool sleep_ok)
72+
{
73+
int ret;
74+
75+
ret = t4_alloc_encap_mac_filt(adap, viid, addr, mask, vni, vni_mask,
76+
dip_hit, lookup_type, sleep_ok);
77+
if (ret < 0)
78+
return ret;
79+
80+
if (cxgb4_mps_ref_inc(adap, addr, ret, mask)) {
81+
ret = -ENOMEM;
82+
t4_free_encap_mac_filt(adap, viid, ret, sleep_ok);
83+
}
84+
return ret;
85+
}
86+
87+
int cxgb4_init_mps_ref_entries(struct adapter *adap)
88+
{
89+
spin_lock_init(&adap->mps_ref_lock);
90+
INIT_LIST_HEAD(&adap->mps_ref);
91+
92+
return 0;
93+
}
94+
95+
void cxgb4_free_mps_ref_entries(struct adapter *adap)
96+
{
97+
struct mps_entries_ref *mps_entry, *tmp;
98+
99+
if (!list_empty(&adap->mps_ref))
100+
return;
101+
102+
spin_lock(&adap->mps_ref_lock);
103+
list_for_each_entry_safe(mps_entry, tmp, &adap->mps_ref, list) {
104+
list_del(&mps_entry->list);
105+
kfree(mps_entry);
106+
}
107+
spin_unlock(&adap->mps_ref_lock);
108+
}

0 commit comments

Comments
 (0)