Skip to content

Commit 045df37

Browse files
committed
Merge branch 'cxgb4-Reference-count-MPS-TCAM-entries-within-a-PF'
Raju Rangoju says: ==================== cxgb4: Reference count MPS TCAM entries within a PF Firmware reference counts the MPS TCAM entries by PF and VF, but it does not do it for usage within a PF or VF. This patch adds the support to track MPS TCAM entries within a PF. v2->v3: Fixed the compiler errors due to incorrect patch Also, removed the new blank line at EOF v1->v2: Use refcount_t type instead of atomic_t for mps reference count ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 0fec7e7 + f9f329a commit 045df37

File tree

5 files changed

+312
-32
lines changed

5 files changed

+312
-32
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: 48 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,42 @@ 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_change_mac(struct port_info *pi, unsigned int viid,
1915+
int *tcam_idx, const u8 *addr,
1916+
bool persistent, u8 *smt_idx);
1917+
1918+
int cxgb4_alloc_mac_filt(struct adapter *adap, unsigned int viid,
1919+
bool free, unsigned int naddr,
1920+
const u8 **addr, u16 *idx,
1921+
u64 *hash, bool sleep_ok);
1922+
int cxgb4_free_mac_filt(struct adapter *adap, unsigned int viid,
1923+
unsigned int naddr, const u8 **addr, bool sleep_ok);
1924+
int cxgb4_init_mps_ref_entries(struct adapter *adap);
1925+
void cxgb4_free_mps_ref_entries(struct adapter *adap);
1926+
int cxgb4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
1927+
const u8 *addr, const u8 *mask,
1928+
unsigned int vni, unsigned int vni_mask,
1929+
u8 dip_hit, u8 lookup_type, bool sleep_ok);
1930+
int cxgb4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
1931+
int idx, bool sleep_ok);
1932+
int cxgb4_free_raw_mac_filt(struct adapter *adap,
1933+
unsigned int viid,
1934+
const u8 *addr,
1935+
const u8 *mask,
1936+
unsigned int idx,
1937+
u8 lookup_type,
1938+
u8 port_id,
1939+
bool sleep_ok);
1940+
int cxgb4_alloc_raw_mac_filt(struct adapter *adap,
1941+
unsigned int viid,
1942+
const u8 *addr,
1943+
const u8 *mask,
1944+
unsigned int idx,
1945+
u8 lookup_type,
1946+
u8 port_id,
1947+
bool sleep_ok);
1948+
int cxgb4_update_mac_filt(struct port_info *pi, unsigned int viid,
1949+
int *tcam_idx, const u8 *addr,
1950+
bool persistent, u8 *smt_idx);
1951+
19091952
#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: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,19 @@ static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
366366
int ret;
367367
u64 mhash = 0;
368368
u64 uhash = 0;
369+
/* idx stores the index of allocated filters,
370+
* its size should be modified based on the number of
371+
* MAC addresses that we allocate filters for
372+
*/
373+
374+
u16 idx[1] = {};
369375
bool free = false;
370376
bool ucast = is_unicast_ether_addr(mac_addr);
371377
const u8 *maclist[1] = {mac_addr};
372378
struct hash_mac_addr *new_entry;
373379

374-
ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
375-
NULL, ucast ? &uhash : &mhash, false);
380+
ret = cxgb4_alloc_mac_filt(adap, pi->viid, free, 1, maclist,
381+
idx, ucast ? &uhash : &mhash, false);
376382
if (ret < 0)
377383
goto out;
378384
/* if hash != 0, then add the addr to hash addr list
@@ -410,7 +416,7 @@ static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
410416
}
411417
}
412418

413-
ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
419+
ret = cxgb4_free_mac_filt(adap, pi->viid, 1, maclist, false);
414420
return ret < 0 ? -EINVAL : 0;
415421
}
416422

@@ -449,9 +455,9 @@ static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
449455
* Addresses are programmed to hash region, if tcam runs out of entries.
450456
*
451457
*/
452-
static int cxgb4_change_mac(struct port_info *pi, unsigned int viid,
453-
int *tcam_idx, const u8 *addr, bool persist,
454-
u8 *smt_idx)
458+
int cxgb4_change_mac(struct port_info *pi, unsigned int viid,
459+
int *tcam_idx, const u8 *addr, bool persist,
460+
u8 *smt_idx)
455461
{
456462
struct adapter *adapter = pi->adapter;
457463
struct hash_mac_addr *entry, *new_entry;
@@ -505,8 +511,8 @@ static int link_start(struct net_device *dev)
505511
ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
506512
!!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
507513
if (ret == 0)
508-
ret = cxgb4_change_mac(pi, pi->viid, &pi->xact_addr_filt,
509-
dev->dev_addr, true, &pi->smt_idx);
514+
ret = cxgb4_update_mac_filt(pi, pi->viid, &pi->xact_addr_filt,
515+
dev->dev_addr, true, &pi->smt_idx);
510516
if (ret == 0)
511517
ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
512518
&pi->link_cfg);
@@ -3020,8 +3026,8 @@ static int cxgb_set_mac_addr(struct net_device *dev, void *p)
30203026
if (!is_valid_ether_addr(addr->sa_data))
30213027
return -EADDRNOTAVAIL;
30223028

3023-
ret = cxgb4_change_mac(pi, pi->viid, &pi->xact_addr_filt,
3024-
addr->sa_data, true, &pi->smt_idx);
3029+
ret = cxgb4_update_mac_filt(pi, pi->viid, &pi->xact_addr_filt,
3030+
addr->sa_data, true, &pi->smt_idx);
30253031
if (ret < 0)
30263032
return ret;
30273033

@@ -3273,8 +3279,6 @@ static void cxgb_del_udp_tunnel(struct net_device *netdev,
32733279
i);
32743280
return;
32753281
}
3276-
atomic_dec(&adapter->mps_encap[adapter->rawf_start +
3277-
pi->port_id].refcnt);
32783282
}
32793283
}
32803284

@@ -3363,7 +3367,6 @@ static void cxgb_add_udp_tunnel(struct net_device *netdev,
33633367
cxgb_del_udp_tunnel(netdev, ti);
33643368
return;
33653369
}
3366-
atomic_inc(&adapter->mps_encap[ret].refcnt);
33673370
}
33683371
}
33693372

@@ -5446,7 +5449,6 @@ static void free_some_resources(struct adapter *adapter)
54465449
{
54475450
unsigned int i;
54485451

5449-
kvfree(adapter->mps_encap);
54505452
kvfree(adapter->smt);
54515453
kvfree(adapter->l2t);
54525454
kvfree(adapter->srq);
@@ -5972,12 +5974,6 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
59725974
adapter->params.offload = 0;
59735975
}
59745976

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-
59815977
#if IS_ENABLED(CONFIG_IPV6)
59825978
if (chip_ver <= CHELSIO_T5 &&
59835979
(!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
@@ -6053,6 +6049,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
60536049
/* check for PCI Express bandwidth capabiltites */
60546050
pcie_print_link_status(pdev);
60556051

6052+
cxgb4_init_mps_ref_entries(adapter);
6053+
60566054
err = init_rss(adapter);
60576055
if (err)
60586056
goto out_free_dev;
@@ -6179,6 +6177,8 @@ static void remove_one(struct pci_dev *pdev)
61796177

61806178
disable_interrupts(adapter);
61816179

6180+
cxgb4_free_mps_ref_entries(adapter);
6181+
61826182
for_each_port(adapter, i)
61836183
if (adapter->port[i]->reg_state == NETREG_REGISTERED)
61846184
unregister_netdev(adapter->port[i]);

0 commit comments

Comments
 (0)