Skip to content

Commit 96c9bed

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Refactor L2 filter alloc/free firmware commands.
Refactor the L2 filter alloc/free logic so that these filters can be added/deleted by the user. The bp->ntp_fltr_bmap allocated size is also increased to allow enough IDs for L2 filters. Reviewed-by: Vasundhara Volam <[email protected]> Reviewed-by: Andy Gospodarek <[email protected]> Reviewed-by: Pavan Chebbi <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bfeabf7 commit 96c9bed

File tree

2 files changed

+112
-54
lines changed

2 files changed

+112
-54
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 109 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,7 +4834,7 @@ static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
48344834
INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
48354835

48364836
bp->ntp_fltr_count = 0;
4837-
bp->ntp_fltr_bmap = bitmap_zalloc(BNXT_NTP_FLTR_MAX_FLTR, GFP_KERNEL);
4837+
bp->ntp_fltr_bmap = bitmap_zalloc(BNXT_MAX_FLTR, GFP_KERNEL);
48384838

48394839
if (!bp->ntp_fltr_bmap)
48404840
rc = -ENOMEM;
@@ -5396,6 +5396,15 @@ static int bnxt_init_l2_filter(struct bnxt *bp, struct bnxt_l2_filter *fltr,
53965396
ether_addr_copy(fltr->l2_key.dst_mac_addr, key->dst_mac_addr);
53975397
fltr->l2_key.vlan = key->vlan;
53985398
fltr->base.type = BNXT_FLTR_TYPE_L2;
5399+
if (fltr->base.flags) {
5400+
int bit_id;
5401+
5402+
bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
5403+
BNXT_MAX_FLTR, 0);
5404+
if (bit_id < 0)
5405+
return -ENOMEM;
5406+
fltr->base.sw_id = (u16)bit_id;
5407+
}
53995408
head = &bp->l2_fltr_hash_tbl[idx];
54005409
hlist_add_head_rcu(&fltr->base.hash, head);
54015410
atomic_set(&fltr->refcnt, 1);
@@ -5429,6 +5438,96 @@ static struct bnxt_l2_filter *bnxt_alloc_l2_filter(struct bnxt *bp,
54295438
return fltr;
54305439
}
54315440

5441+
static u16 bnxt_vf_target_id(struct bnxt_pf_info *pf, u16 vf_idx)
5442+
{
5443+
#ifdef CONFIG_BNXT_SRIOV
5444+
struct bnxt_vf_info *vf = &pf->vf[vf_idx];
5445+
5446+
return vf->fw_fid;
5447+
#else
5448+
return INVALID_HW_RING_ID;
5449+
#endif
5450+
}
5451+
5452+
int bnxt_hwrm_l2_filter_free(struct bnxt *bp, struct bnxt_l2_filter *fltr)
5453+
{
5454+
struct hwrm_cfa_l2_filter_free_input *req;
5455+
u16 target_id = 0xffff;
5456+
int rc;
5457+
5458+
if (fltr->base.flags & BNXT_ACT_FUNC_DST) {
5459+
struct bnxt_pf_info *pf = &bp->pf;
5460+
5461+
if (fltr->base.vf_idx >= pf->active_vfs)
5462+
return -EINVAL;
5463+
5464+
target_id = bnxt_vf_target_id(pf, fltr->base.vf_idx);
5465+
if (target_id == INVALID_HW_RING_ID)
5466+
return -EINVAL;
5467+
}
5468+
5469+
rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_FREE);
5470+
if (rc)
5471+
return rc;
5472+
5473+
req->target_id = cpu_to_le16(target_id);
5474+
req->l2_filter_id = fltr->base.filter_id;
5475+
return hwrm_req_send(bp, req);
5476+
}
5477+
5478+
int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr)
5479+
{
5480+
struct hwrm_cfa_l2_filter_alloc_output *resp;
5481+
struct hwrm_cfa_l2_filter_alloc_input *req;
5482+
u16 target_id = 0xffff;
5483+
int rc;
5484+
5485+
if (fltr->base.flags & BNXT_ACT_FUNC_DST) {
5486+
struct bnxt_pf_info *pf = &bp->pf;
5487+
5488+
if (fltr->base.vf_idx >= pf->active_vfs)
5489+
return -EINVAL;
5490+
5491+
target_id = bnxt_vf_target_id(pf, fltr->base.vf_idx);
5492+
}
5493+
rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_ALLOC);
5494+
if (rc)
5495+
return rc;
5496+
5497+
req->target_id = cpu_to_le16(target_id);
5498+
req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
5499+
5500+
if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
5501+
req->flags |=
5502+
cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
5503+
req->dst_id = cpu_to_le16(fltr->base.fw_vnic_id);
5504+
req->enables =
5505+
cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
5506+
CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
5507+
CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
5508+
ether_addr_copy(req->l2_addr, fltr->l2_key.dst_mac_addr);
5509+
eth_broadcast_addr(req->l2_addr_mask);
5510+
5511+
if (fltr->l2_key.vlan) {
5512+
req->enables |=
5513+
cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_IVLAN |
5514+
CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_IVLAN_MASK |
5515+
CFA_L2_FILTER_ALLOC_REQ_ENABLES_NUM_VLANS);
5516+
req->num_vlans = 1;
5517+
req->l2_ivlan = cpu_to_le16(fltr->l2_key.vlan);
5518+
req->l2_ivlan_mask = cpu_to_le16(0xfff);
5519+
}
5520+
5521+
resp = hwrm_req_hold(bp, req);
5522+
rc = hwrm_req_send(bp, req);
5523+
if (!rc) {
5524+
fltr->base.filter_id = resp->l2_filter_id;
5525+
set_bit(BNXT_FLTR_VALID, &fltr->base.state);
5526+
}
5527+
hwrm_req_drop(bp, req);
5528+
return rc;
5529+
}
5530+
54325531
#ifdef CONFIG_RFS_ACCEL
54335532
static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
54345533
struct bnxt_ntuple_filter *fltr)
@@ -5538,8 +5637,6 @@ static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
55385637
static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
55395638
const u8 *mac_addr)
55405639
{
5541-
struct hwrm_cfa_l2_filter_alloc_output *resp;
5542-
struct hwrm_cfa_l2_filter_alloc_input *req;
55435640
struct bnxt_l2_filter *fltr;
55445641
struct bnxt_l2_key key;
55455642
int rc;
@@ -5550,66 +5647,33 @@ static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
55505647
if (IS_ERR(fltr))
55515648
return PTR_ERR(fltr);
55525649

5553-
rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_ALLOC);
5650+
fltr->base.fw_vnic_id = bp->vnic_info[vnic_id].fw_vnic_id;
5651+
rc = bnxt_hwrm_l2_filter_alloc(bp, fltr);
55545652
if (rc)
5555-
return rc;
5556-
5557-
req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
5558-
if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
5559-
req->flags |=
5560-
cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
5561-
req->dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
5562-
req->enables =
5563-
cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
5564-
CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
5565-
CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
5566-
memcpy(req->l2_addr, mac_addr, ETH_ALEN);
5567-
req->l2_addr_mask[0] = 0xff;
5568-
req->l2_addr_mask[1] = 0xff;
5569-
req->l2_addr_mask[2] = 0xff;
5570-
req->l2_addr_mask[3] = 0xff;
5571-
req->l2_addr_mask[4] = 0xff;
5572-
req->l2_addr_mask[5] = 0xff;
5573-
5574-
resp = hwrm_req_hold(bp, req);
5575-
rc = hwrm_req_send(bp, req);
5576-
if (rc) {
55775653
bnxt_del_l2_filter(bp, fltr);
5578-
} else {
5579-
fltr->base.filter_id = resp->l2_filter_id;
5580-
set_bit(BNXT_FLTR_VALID, &fltr->base.state);
5654+
else
55815655
bp->vnic_info[vnic_id].l2_filters[idx] = fltr;
5582-
}
5583-
hwrm_req_drop(bp, req);
55845656
return rc;
55855657
}
55865658

55875659
static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
55885660
{
5589-
struct hwrm_cfa_l2_filter_free_input *req;
55905661
u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
5591-
int rc;
5662+
int rc = 0;
55925663

55935664
/* Any associated ntuple filters will also be cleared by firmware. */
5594-
rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_FREE);
5595-
if (rc)
5596-
return rc;
5597-
hwrm_req_hold(bp, req);
55985665
for (i = 0; i < num_of_vnics; i++) {
55995666
struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
56005667

56015668
for (j = 0; j < vnic->uc_filter_count; j++) {
5602-
struct bnxt_l2_filter *fltr;
5603-
5604-
fltr = vnic->l2_filters[j];
5605-
req->l2_filter_id = fltr->base.filter_id;
5669+
struct bnxt_l2_filter *fltr = vnic->l2_filters[j];
56065670

5607-
rc = hwrm_req_send(bp, req);
5671+
bnxt_hwrm_l2_filter_free(bp, fltr);
56085672
bnxt_del_l2_filter(bp, fltr);
56095673
}
56105674
vnic->uc_filter_count = 0;
56115675
}
5612-
hwrm_req_drop(bp, req);
5676+
56135677
return rc;
56145678
}
56155679

@@ -11898,7 +11962,6 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
1189811962
{
1189911963
struct net_device *dev = bp->dev;
1190011964
struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
11901-
struct hwrm_cfa_l2_filter_free_input *req;
1190211965
struct netdev_hw_addr *ha;
1190311966
int i, off = 0, rc;
1190411967
bool uc_update;
@@ -11910,19 +11973,12 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
1191011973
if (!uc_update)
1191111974
goto skip_uc;
1191211975

11913-
rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_FREE);
11914-
if (rc)
11915-
return rc;
11916-
hwrm_req_hold(bp, req);
1191711976
for (i = 1; i < vnic->uc_filter_count; i++) {
1191811977
struct bnxt_l2_filter *fltr = vnic->l2_filters[i];
1191911978

11920-
req->l2_filter_id = fltr->base.filter_id;
11921-
11922-
rc = hwrm_req_send(bp, req);
11979+
bnxt_hwrm_l2_filter_free(bp, fltr);
1192311980
bnxt_del_l2_filter(bp, fltr);
1192411981
}
11925-
hwrm_req_drop(bp, req);
1192611982

1192711983
vnic->uc_filter_count = 1;
1192811984

@@ -13823,8 +13879,7 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1382313879
rcu_read_unlock();
1382413880

1382513881
spin_lock_bh(&bp->ntp_fltr_lock);
13826-
bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
13827-
BNXT_NTP_FLTR_MAX_FLTR, 0);
13882+
bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0);
1382813883
if (bit_id < 0) {
1382913884
spin_unlock_bh(&bp->ntp_fltr_lock);
1383013885
rc = -ENOMEM;

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,7 @@ struct bnxt {
23982398
int db_size;
23992399

24002400
#define BNXT_NTP_FLTR_MAX_FLTR 4096
2401+
#define BNXT_MAX_FLTR (BNXT_NTP_FLTR_MAX_FLTR + BNXT_L2_FLTR_MAX_FLTR)
24012402
#define BNXT_NTP_FLTR_HASH_SIZE 512
24022403
#define BNXT_NTP_FLTR_HASH_MASK (BNXT_NTP_FLTR_HASH_SIZE - 1)
24032404
struct hlist_head ntp_fltr_hash_tbl[BNXT_NTP_FLTR_HASH_SIZE];
@@ -2621,6 +2622,8 @@ int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp, unsigned long *bmap,
26212622
int bmap_size, bool async_only);
26222623
int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp);
26232624
void bnxt_del_l2_filter(struct bnxt *bp, struct bnxt_l2_filter *fltr);
2625+
int bnxt_hwrm_l2_filter_free(struct bnxt *bp, struct bnxt_l2_filter *fltr);
2626+
int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr);
26242627
int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings);
26252628
int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id);
26262629
int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);

0 commit comments

Comments
 (0)