Add ingress ratelimit offload
Subsystems (4)
Subbaraya Sundeep
maintainercover Add ingress ratelimit offload
This patchset adds ingress rate limiting hardware offload support for CN10K silicons. Police actions are added for TC matchall and flower filters. CN10K has ingress rate limiting feature where a receive queue is mapped to bandwidth profile and the profile is configured with rate and burst parameters by software. CN10K hardware supports three levels of ingress policing or ratelimiting. Multiple leaf profiles can point to a single mid level profile and multiple mid level profile can point to a single top level one. Only leaf level profiles are used for configuring rate limiting.
Patch 1 adds the new bandwidth profile contexts
in AF driver similar to other hardware contexts Patch 2 adds the debugfs changes to dump bandwidth profile contexts
Patch 3 adds support for police action with TC matchall filter Patch 4 uses NL_SET_ERR_MSG_MOD for tc code
Patch 5 adds support for police action with TC flower filter
Subbaraya Sundeep (2):
octeontx2-pf: Use NL_SET_ERR_MSG_MOD for TC
octeontx2-pf: Add police action for TC flower
Sunil Goutham (3):
octeontx2-af: cn10k: Bandwidth profiles config support
octeontx2-af: cn10k: Debugfs support for bandwidth profiles
octeontx2-pf: TC_MATCHALL ingress ratelimiting offload
drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 40 +- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 8 + drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 16 + .../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 163 ++++++ .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 619 ++++++++++++++++++++- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 5 + .../net/ethernet/marvell/octeontx2/af/rvu_reg.h | 8 + .../net/ethernet/marvell/octeontx2/af/rvu_struct.h | 85 ++- drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c | 323 +++++++++++ drivers/net/ethernet/marvell/octeontx2/nic/cn10k.h | 11 + .../ethernet/marvell/octeontx2/nic/otx2_common.h | 3 + .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 6 + .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 + .../net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 299 ++++++++-- 14 files changed, 1554 insertions(+), 35 deletions(-)
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH 1/5 octeontx2-af: cn10k: Bandwidth profiles config support
From: Sunil Goutham <[email protected]>
CN10K silicons supports hierarchial ingress packet ratelimiting. There are 3 levels of profilers supported leaf, mid and top. Ratelimiting is done after packet forwarding decision is taken and a NIXLF's RQ is identified to DMA the packet. RQ's context points to a leaf bandwidth profile which can be configured to achieve desired ratelimit.
This patch adds logic for management of these bandwidth profiles ie profile alloc, free, context update etc.
--- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 40 +- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 11 + .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 619 ++++++++++++++++++++- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 5 + .../net/ethernet/marvell/octeontx2/af/rvu_reg.h | 8 + .../net/ethernet/marvell/octeontx2/af/rvu_struct.h | 78 ++- 6 files changed, 757 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +39 -1
@@ -260,7 +260,11 @@ M(NIX_BP_DISABLE, 0x8017, nix_bp_disable, nix_bp_cfg_req, msg_rsp) \ M(NIX_GET_MAC_ADDR, 0x8018, nix_get_mac_addr, msg_req, nix_get_mac_addr_rsp) \M (NIX_CN10K_AQ_ENQ ,0x8019 , nix_cn10k_aq_enq, nix_cn10k_aq_enq_req, \ nix_cn10k_aq_enq_rsp) \ -M (NIX_GET_HW_INFO ,0x801a , nix_get_hw_info, msg_req, nix_hw_info) +M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info) \ +M (NIX_BANDPROF_ALLOC ,0x801d , nix_bandprof_alloc, nix_bandprof_alloc_req, \ + nix_bandprof_alloc_rsp) \ +M (NIX_BANDPROF_FREE ,0x801e , nix_bandprof_free, nix_bandprof_free_req, \ + msg_rsp) /* Messages initiated by AF (range 0xC00 - 0xDFF) */#define MBOX_UP_CGX_MESSAGES \
@@ -615,6 +619,9 @@ enum nix_af_status {NIX_AF_ERR_PTP_CONFIG_FAIL =-423 ,NIX_AF_ERR_NPC_KEY_NOT_SUPP =-424 ,NIX_AF_ERR_INVALID_NIXBLK =-425 , +NIX_AF_ERR_INVALID_BANDPROF =-426 , +NIX_AF_ERR_IPOLICER_NOTSUPP =-427 , + NIX_AF_ERR_BANDPROF_INVAL_REQ = -428, };/* For NIX RX vtag action */
@@ -683,6 +690,7 @@ struct nix_cn10k_aq_enq_req {struct nix_cq_ctx_s cq;struct nix_rsse_s rss;struct nix_rx_mce_s mce; +struct nix_bandprof_s prof; };union {struct nix_cn10k_rq_ctx_s rq_mask;
@@ -690,6 +698,7 @@ struct nix_cn10k_aq_enq_req {struct nix_cq_ctx_s cq_mask;struct nix_rsse_s rss_mask;struct nix_rx_mce_s mce_mask; +struct nix_bandprof_s prof_mask; }; };
@@ -701,6 +710,7 @@ struct nix_cn10k_aq_enq_rsp {struct nix_cq_ctx_s cq;struct nix_rsse_s rss;struct nix_rx_mce_s mce; +struct nix_bandprof_s prof; }; };
@@ -716,6 +726,7 @@ struct nix_aq_enq_req {struct nix_cq_ctx_s cq;struct nix_rsse_s rss;struct nix_rx_mce_s mce; +u64 prof; };union {struct nix_rq_ctx_s rq_mask;
@@ -723,6 +734,7 @@ struct nix_aq_enq_req {struct nix_cq_ctx_s cq_mask;struct nix_rsse_s rss_mask;struct nix_rx_mce_s mce_mask; +u64 prof_mask; }; };
@@ -734,6 +746,7 @@ struct nix_aq_enq_rsp {struct nix_cq_ctx_s cq;struct nix_rsse_s rss;struct nix_rx_mce_s mce; +u64 prof; }; };
@@ -975,6 +988,31 @@ struct nix_hw_info {u16 min_mtu; }; +struct nix_bandprof_alloc_req { +struct mbox_msghdr hdr; +/* Count of profiles needed per layer */ +u16 prof_count[BAND_PROF_NUM_LAYERS ]; +}; + +struct nix_bandprof_alloc_rsp { +struct mbox_msghdr hdr; +u16 prof_count[BAND_PROF_NUM_LAYERS ]; + +/* There is no need to allocate morethan 1 bandwidth profile +* per RQ of a PF_FUNC's NIXLF. So limit the maximum +* profiles to 64 per PF_FUNC. +*/ +#define MAX_BANDPROF_PER_PFFUNC 64 +u16 prof_idx[BAND_PROF_NUM_LAYERS ][MAX_BANDPROF_PER_PFFUNC ]; +}; + +struct nix_bandprof_free_req { +struct mbox_msghdr hdr; +u8 free_all; +u16 prof_count[BAND_PROF_NUM_LAYERS ]; +u16 prof_idx[BAND_PROF_NUM_LAYERS ][MAX_BANDPROF_PER_PFFUNC ]; +}; +/* NPC mbox message structs */ #define NPC_MCAM_ENTRY_INVALID 0xFFFF
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +11 -0
@@ -296,6 +296,13 @@ struct nix_txvlan {struct mutex rsrc_lock;/* Serialize resource alloc/free */ }; +struct nix_ipolicer { +struct rsrc_bmap band_prof; +u16 *pfvf_map; +u16 *match_id; +u16 *ref_count; +}; +struct nix_hw {int blkaddr;struct rvu *rvu;
@@ -305,6 +312,7 @@ struct nix_hw {struct nix_mark_format mark_format;struct nix_lso lso;struct nix_txvlan txvlan; +struct nix_ipolicer *ipolicer; };/* RVU block's capabilities or functionality,
@@ -322,6 +330,7 @@ struct hw_cap {bool nix_rx_multicast;/* Rx packet replication support */ bool per_pf_mbox_regs;/* PF mbox specified in per PF registers ? */ bool programmable_chans;/* Channels programmable ? */ +bool ipolicer; };struct rvu_hwinfo {
@@ -672,6 +681,8 @@ int rvu_get_next_nix_blkaddr(struct rvu *rvu, int blkaddr);void rvu_nix_reset_mac (struct rvu_pfvf *pfvf,int pcifunc);int nix_get_struct_ptrs (struct rvu *rvu,u16 pcifunc,struct nix_hw **nix_hw,int *blkaddr); +int rvu_nix_setup_ratelimit_aggr (struct rvu *rvu,u16 pcifunc, +u16 rq_idx,u16 match_id);/* NPC APIs */ int rvu_npc_init (struct rvu *rvu);
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +617 -2
676 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +5 -0
@@ -1110,6 +1110,11 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target, req->vtag0_type == NIX_AF_LFX_RX_VTAG_TYPE7) rule->vfvlan_cfg = true; +if (is_npc_intf_rx (req->intf) && req->match_id && + (req->op ==NIX_RX_ACTIONOP_UCAST || req->op ==NIX_RX_ACTIONOP_RSS )) +return rvu_nix_setup_ratelimit_aggr (rvu, req->hdr.pcifunc, + req->index, req->match_id); +return 0 ; }
drivers/net/ethernet/marvell/octeontx2/af/rvu_reg.h +8 -0
@@ -171,6 +171,7 @@#define NIX_AF_SQ_CONST (0x0040)#define NIX_AF_CQ_CONST (0x0048)#define NIX_AF_RQ_CONST (0x0050) +#define NIX_AF_PL_CONST (0x0058)#define NIX_AF_PSE_CONST (0x0060)#define NIX_AF_TL1_CONST (0x0070)#define NIX_AF_TL2_CONST (0x0078)
@@ -181,6 +182,7 @@#define NIX_AF_LSO_CFG (0x00A8)#define NIX_AF_BLK_RST (0x00B0)#define NIX_AF_TX_TSTMP_CFG (0x00C0) +#define NIX_AF_PL_TS (0x00C8)#define NIX_AF_RX_CFG (0x00D0)#define NIX_AF_AVG_DELAY (0x00E0)#define NIX_AF_CINT_DELAY (0x00F0)
@@ -212,7 +214,9 @@#define NIX_AF_RX_DEF_OL2 (0x0200)#define NIX_AF_RX_DEF_OIP4 (0x0210)#define NIX_AF_RX_DEF_IIP4 (0x0220) +#define NIX_AF_RX_DEF_VLAN0_PCP_DEI (0x0228)#define NIX_AF_RX_DEF_OIP6 (0x0230) +#define NIX_AF_RX_DEF_VLAN1_PCP_DEI (0x0238)#define NIX_AF_RX_DEF_IIP6 (0x0240)#define NIX_AF_RX_DEF_OTCP (0x0250)#define NIX_AF_RX_DEF_ITCP (0x0260)
@@ -223,6 +227,10 @@#define NIX_AF_RX_DEF_ISCTP (0x02A0)#define NIX_AF_RX_DEF_IPSECX (0x02B0)#define NIX_AF_RX_DEF_CST_APAD1 (0x02A8) +#define NIX_AF_RX_DEF_IIP4_DSCP (0x02E0) +#define NIX_AF_RX_DEF_OIP4_DSCP (0x02E8) +#define NIX_AF_RX_DEF_IIP6_DSCP (0x02F0) +#define NIX_AF_RX_DEF_OIP6_DSCP (0x02F8)#define NIX_AF_RX_IPSEC_GEN_CFG (0x0300)#define NIX_AF_RX_CPTX_INST_ADDR (0x0310)#define NIX_AF_NDC_TX_SYNC (0x03F0)
drivers/net/ethernet/marvell/octeontx2/af/rvu_struct.h +77 -1
90 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [net-next PATCH 1/5] octeontx2-af: cn10k: Bandwidth profiles config support
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw, · line 911
Quoted 8 lines · Subbaraya Sundeep
[...]
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +3
-0@@ -885,6 +906,9 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,else if (req->ctype ==NIX_AQ_CTYPE_MCE )memcpy (&rsp->mce, ctx,sizeof (struct nix_rx_mce_s )); +else if (req->ctype ==NIX_AQ_CTYPE_BANDPROF ) +memcpy (&rsp->prof, ctx, +sizeof (struct nix_bandprof_s ));
rsp->prof is u64 not struct nix_bandprof_s, so the compiler thinks this memcpy() is overflowing the "prof" field.
Can you please fix this up?
Signature · 1 line
Kees Cook
Subbaraya Sundeep Bhatta
maintainerRe: [EXT] Re: [net-next PATCH 1/5] octeontx2-af: cn10k: Bandwidth profiles config support
Hi Kees Cook,
Thanks. I will send the fix to net.
Sundeep
________________________________________
From: Kees Cook <[email protected]>
Sent: Friday, June 18, 2021 9:37 PM
To: Subbaraya Sundeep Bhatta
Cc: [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham; Hariprasad Kelam; Geethasowjanya Akula
Subject: [EXT] Re: [net-next PATCH 1/5] octeontx2-af: cn10k: Bandwidth profiles config support
External Email
----------------------------------------------------------------------
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw, · line 911
Quoted 8 lines · Subbaraya Sundeep
[...]
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +3
-0@@ -885,6 +906,9 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,else if (req->ctype ==NIX_AQ_CTYPE_MCE )memcpy (&rsp->mce, ctx,sizeof (struct nix_rx_mce_s )); +else if (req->ctype ==NIX_AQ_CTYPE_BANDPROF ) +memcpy (&rsp->prof, ctx, +sizeof (struct nix_bandprof_s ));
rsp->prof is u64 not struct nix_bandprof_s, so the compiler thinks this memcpy() is overflowing the "prof" field.
Can you please fix this up?
--
Kees Cook
Subbaraya Sundeep
maintainerPATCH 2/5 octeontx2-af: cn10k: Debugfs support for bandwidth profiles
In reply to Subbaraya SundeepFrom: Sunil Goutham <[email protected]>
Added support for dumping current resource status of bandwidth profiles and contexts of allocated profiles via debugfs.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 8 + drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 5 + .../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 163 +++++++++++++++++++++ .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 8 +- .../net/ethernet/marvell/octeontx2/af/rvu_struct.h | 7 + 5 files changed, 187 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +8 -0
@@ -184,6 +184,14 @@ int rvu_rsrc_free_count(struct rsrc_bmap *rsrc)return (rsrc->max - used); } +bool is_rsrc_free (struct rsrc_bmap *rsrc,int id) +{ +if (!rsrc->bmap) +return false; + +return !test_bit (id, rsrc->bmap); +} +int rvu_alloc_bitmap (struct rsrc_bmap *rsrc) { rsrc->bmap = kcalloc(BITS_TO_LONGS(rsrc->max),
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +5 -0
@@ -596,6 +596,7 @@ static inline bool is_rvu_fwdata_valid(struct rvu *rvu)int rvu_alloc_bitmap (struct rsrc_bmap *rsrc);int rvu_alloc_rsrc (struct rsrc_bmap *rsrc);void rvu_free_rsrc (struct rsrc_bmap *rsrc,int id); +bool is_rsrc_free (struct rsrc_bmap *rsrc,int id);int rvu_rsrc_free_count (struct rsrc_bmap *rsrc);int rvu_alloc_rsrc_contig (struct rsrc_bmap *rsrc,int nrsrc);bool rvu_rsrc_check_contig (struct rsrc_bmap *rsrc,int nrsrc);
@@ -683,6 +684,10 @@ int nix_get_struct_ptrs(struct rvu *rvu, u16 pcifunc, struct nix_hw **nix_hw, int *blkaddr);int rvu_nix_setup_ratelimit_aggr (struct rvu *rvu,u16 pcifunc,u16 rq_idx,u16 match_id); +int nix_aq_context_read (struct rvu *rvu,struct nix_hw *nix_hw, +struct nix_cn10k_aq_enq_req *aq_req, +struct nix_cn10k_aq_enq_rsp *aq_rsp, +u16 pcifunc,u8 ctype,u32 qidx);/* NPC APIs */ int rvu_npc_init (struct rvu *rvu);
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +163 -0
175 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +4 -4
@@ -4365,10 +4365,10 @@ int rvu_mbox_handler_nix_bandprof_free(struct rvu *rvu,return 0 ; } -static int nix_aq_context_read (struct rvu *rvu,struct nix_hw *nix_hw, -struct nix_cn10k_aq_enq_req *aq_req, -struct nix_cn10k_aq_enq_rsp *aq_rsp, -u16 pcifunc,u8 ctype,u32 qidx) +int nix_aq_context_read (struct rvu *rvu,struct nix_hw *nix_hw, +struct nix_cn10k_aq_enq_req *aq_req, +struct nix_cn10k_aq_enq_rsp *aq_rsp, +u16 pcifunc,u8 ctype,u32 qidx) {memset (aq_req,0 ,sizeof (struct nix_cn10k_aq_enq_req )); aq_req->hdr.pcifunc = pcifunc;
drivers/net/ethernet/marvell/octeontx2/af/rvu_struct.h +7 -0
@@ -679,6 +679,13 @@ enum NIX_RX_BAND_PROF_ACTIONRESULT_E { NIX_RX_BAND_PROF_ACTIONRESULT_RED = 0x2, }; +enum nix_band_prof_pc_mode { +NIX_RX_PC_MODE_VLAN =0 , +NIX_RX_PC_MODE_DSCP =1 , +NIX_RX_PC_MODE_GEN =2 , +NIX_RX_PC_MODE_RSVD =3 , +}; +/* NIX ingress policer bandwidth profile structure */ struct nix_bandprof_s {uint64_t pc_mode :2 ;/* W0 */
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH 3/5 octeontx2-pf: TC_MATCHALL ingress ratelimiting offload
In reply to Subbaraya SundeepFrom: Sunil Goutham <[email protected]>
Add TC_MATCHALL ingress ratelimiting offload support with POLICE action for entire traffic coming into the interface.
Eg: To ratelimit ingress traffic to 100Mbps
$ ethtool -K eth0 hw-tc-offload on
$ tc qdisc add dev eth0 clsact
$ tc filter add dev eth0 ingress matchall skip_sw \
action police rate 100Mbit burst 32KbitTo support this, a leaf level bandwidth profile is allocated and all RQs' contexts used by this interface are updated to point to it. And the leaf level bandwidth profile is configured with user specified rate and burst sizes.
--- drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c | 323 +++++++++++++++++++++ drivers/net/ethernet/marvell/octeontx2/nic/cn10k.h | 11 + .../ethernet/marvell/octeontx2/nic/otx2_common.h | 2 + .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 + .../net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 84 ++++++ 5 files changed, 423 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c +323 -0
@@ -179,3 +179,326 @@ void cn10k_sqe_flush(void *dev, struct otx2_snd_queue *sq, int size, int qidx) sq->head++; sq->head &= (sq->sqe_cnt -1 ); } + +int cn10k_free_all_ipolicers (struct otx2_nic *pfvf) +{ +struct nix_bandprof_free_req *req; +int rc; + +if (is_dev_otx2 (pfvf->pdev)) +return 0 ; + +mutex_lock (&pfvf->mbox.lock); + + req =otx2_mbox_alloc_msg_nix_bandprof_free (&pfvf->mbox); +if (!req) { + rc = -ENOMEM ; + goto out; + } + +/* Free all bandwidth profiles allocated */ + req->free_all = true; + + rc =otx2_sync_mbox_msg (&pfvf->mbox); +out: +mutex_unlock (&pfvf->mbox.lock); +return rc; +} + +int cn10k_alloc_leaf_profile (struct otx2_nic *pfvf,u16 *leaf) +{ +struct nix_bandprof_alloc_req *req; +struct nix_bandprof_alloc_rsp *rsp; +int rc; + + req =otx2_mbox_alloc_msg_nix_bandprof_alloc (&pfvf->mbox); +if (!req) +return -ENOMEM ; + + req->prof_count[BAND_PROF_LEAF_LAYER ] =1 ; + + rc =otx2_sync_mbox_msg (&pfvf->mbox); +if (rc) + goto out; + + rsp = (struct nix_bandprof_alloc_rsp *) +otx2_mbox_get_rsp (&pfvf->mbox.mbox,0 , &req->hdr); +if (!rsp->prof_count[BAND_PROF_LEAF_LAYER ]) { + rc = -EIO ; + goto out; + } + + *leaf = rsp->prof_idx[BAND_PROF_LEAF_LAYER ][0 ]; +out: +if (rc) { +dev_warn (pfvf->dev, +"Failed to allocate ingress bandwidth policer\n" ); + } + +return rc; +} + +int cn10k_alloc_matchall_ipolicer (struct otx2_nic *pfvf) +{ +struct otx2_hw *hw = &pfvf->hw; +int ret; + +mutex_lock (&pfvf->mbox.lock); + + ret =cn10k_alloc_leaf_profile (pfvf, &hw->matchall_ipolicer); + +mutex_unlock (&pfvf->mbox.lock); + +return ret; +} + +#define POLICER_TIMESTAMP 1/* 1 second */ +#define MAX_RATE_EXP 22/* Valid rate exponent range: 0 - 22 */ + +static void cn10k_get_ingress_burst_cfg (u32 burst,u32 *burst_exp, +u32 *burst_mantissa) +{ +int tmp; + +/* Burst is calculated as +* (1+[BURST_MANTISSA]/256)*2^[BURST_EXPONENT] +* This is the upper limit on number tokens (bytes) that +* can be accumulated in the bucket. +*/ + *burst_exp =ilog2 (burst); +if (burst <256 ) { +/* No float: can't express mantissa in this case */ + *burst_mantissa =0 ; +return ; + } + +if (*burst_exp >MAX_RATE_EXP ) + *burst_exp =MAX_RATE_EXP ; + +/* Calculate mantissa +* Find remaining bytes 'burst - 2^burst_exp' +* mantissa = (remaining bytes) / 2^ (burst_exp - 8) +*/ + tmp = burst -rounddown_pow_of_two (burst); + *burst_mantissa = tmp / (1UL << (*burst_exp -8 )); +} + +static void cn10k_get_ingress_rate_cfg (u64 rate,u32 *rate_exp, +u32 *rate_mantissa,u32 *rdiv) +{ +u32 div =0 ; +u32 exp =0 ; +u64 tmp; + +/* Figure out mantissa, exponent and divider from given max pkt rate +* +* To achieve desired rate HW adds +* (1+[RATE_MANTISSA]/256)*2^[RATE_EXPONENT] tokens (bytes) at every +* policer timeunit * 2^rdiv ie 2 * 2^rdiv usecs, to the token bucket. +* Here policer timeunit is 2 usecs and rate is in bits per sec. +* Since floating point cannot be used below algorithm uses 1000000 +* scale factor to support rates upto 100Gbps. +*/ + tmp = rate *32 *2 ; +if (tmp <256000000 ) { +while (tmp <256000000 ) { + tmp = tmp *2 ; + div++; + } + }else { +for (exp =0 ; tmp >=512000000 && exp <=MAX_RATE_EXP ; exp++) + tmp = tmp /2 ; + +if (exp >MAX_RATE_EXP ) + exp =MAX_RATE_EXP ; + } + + *rate_mantissa = (tmp -256000000 ) /1000000 ; + *rate_exp = exp; + *rdiv = div; +} + +int cn10k_map_unmap_rq_policer (struct otx2_nic *pfvf,int rq_idx, +u16 policer,bool map) +{ +struct nix_cn10k_aq_enq_req *aq; + + aq =otx2_mbox_alloc_msg_nix_cn10k_aq_enq (&pfvf->mbox); +if (!aq) +return -ENOMEM ; + +/* Enable policing and set the bandwidth profile (policer) index */ +if (map) + aq->rq.policer_ena =1 ; +else + aq->rq.policer_ena =0 ; + aq->rq_mask.policer_ena =1 ; + + aq->rq.band_prof_id = policer; + aq->rq_mask.band_prof_id =GENMASK (9 ,0 ); + +/* Fill AQ info */ + aq->qidx = rq_idx; + aq->ctype =NIX_AQ_CTYPE_RQ ; + aq->op =NIX_AQ_INSTOP_WRITE ; + +return otx2_sync_mbox_msg (&pfvf->mbox); +} + +int cn10k_free_leaf_profile (struct otx2_nic *pfvf,u16 leaf) +{ +struct nix_bandprof_free_req *req; + + req =otx2_mbox_alloc_msg_nix_bandprof_free (&pfvf->mbox); +if (!req) +return -ENOMEM ; + + req->prof_count[BAND_PROF_LEAF_LAYER ] =1 ; + req->prof_idx[BAND_PROF_LEAF_LAYER ][0 ] = leaf; + +return otx2_sync_mbox_msg (&pfvf->mbox); +} + +int cn10k_free_matchall_ipolicer (struct otx2_nic *pfvf) +{ +struct otx2_hw *hw = &pfvf->hw; +int qidx, rc; + +mutex_lock (&pfvf->mbox.lock); + +/* Remove RQ's policer mapping */ +for (qidx =0 ; qidx < hw->rx_queues; qidx++) +cn10k_map_unmap_rq_policer (pfvf, qidx, + hw->matchall_ipolicer, false); + + rc =cn10k_free_leaf_profile (pfvf, hw->matchall_ipolicer); + +mutex_unlock (&pfvf->mbox.lock); +return rc; +} + +int cn10k_set_ipolicer_rate (struct otx2_nic *pfvf,u16 profile, +u32 burst,u64 rate,bool pps) +{ +struct nix_cn10k_aq_enq_req *aq; +u32 burst_exp, burst_mantissa; +u32 rate_exp, rate_mantissa; +u32 rdiv; + +/* Get exponent and mantissa values for the desired rate */ +cn10k_get_ingress_burst_cfg (burst, &burst_exp, &burst_mantissa); +cn10k_get_ingress_rate_cfg (rate, &rate_exp, &rate_mantissa, &rdiv); + +/* Init bandwidth profile */ + aq =otx2_mbox_alloc_msg_nix_cn10k_aq_enq (&pfvf->mbox); +if (!aq) +return -ENOMEM ; + +/* Set initial color mode to blind */ + aq->prof.icolor =0x03 ; + aq->prof_mask.icolor =0x03 ; + +/* Set rate and burst values */ + aq->prof.cir_exponent = rate_exp; + aq->prof_mask.cir_exponent =0x1F ; + + aq->prof.cir_mantissa = rate_mantissa; + aq->prof_mask.cir_mantissa =0xFF ; + + aq->prof.cbs_exponent = burst_exp; + aq->prof_mask.cbs_exponent =0x1F ; + + aq->prof.cbs_mantissa = burst_mantissa; + aq->prof_mask.cbs_mantissa =0xFF ; + + aq->prof.rdiv = rdiv; + aq->prof_mask.rdiv =0xF ; + +if (pps) { +/* The amount of decremented tokens is calculated according to +* the following equation: +* max([ LMODE ? 0 : (packet_length - LXPTR)] + +* ([ADJUST_MANTISSA]/256 - 1) * 2^[ADJUST_EXPONENT], +* 1/256) +* if LMODE is 1 then rate limiting will be based on +* PPS otherwise bps. +* The aim of the ADJUST value is to specify a token cost per +* packet in contrary to the packet length that specifies a +* cost per byte. To rate limit based on PPS adjust mantissa +* is set as 384 and exponent as 1 so that number of tokens +* decremented becomes 1 i.e, 1 token per packeet. +*/ + aq->prof.adjust_exponent =1 ; + aq->prof_mask.adjust_exponent =0x1F ; + + aq->prof.adjust_mantissa =384 ; + aq->prof_mask.adjust_mantissa =0x1FF ; + + aq->prof.lmode =0x1 ; + aq->prof_mask.lmode =0x1 ; + } + +/* Two rate three color marker +* With PEIR/EIR set to zero, color will be either green or red +*/ + aq->prof.meter_algo =2 ; + aq->prof_mask.meter_algo =0x3 ; + + aq->prof.rc_action =NIX_RX_BAND_PROF_ACTIONRESULT_DROP ; + aq->prof_mask.rc_action =0x3 ; + + aq->prof.yc_action =NIX_RX_BAND_PROF_ACTIONRESULT_PASS ; + aq->prof_mask.yc_action =0x3 ; + + aq->prof.gc_action =NIX_RX_BAND_PROF_ACTIONRESULT_PASS ; + aq->prof_mask.gc_action =0x3 ; + +/* Setting exponent value as 24 and mantissa as 0 configures +* the bucket with zero values making bucket unused. Peak +* information rate and Excess information rate buckets are +* unused here. +*/ + aq->prof.peir_exponent =24 ; + aq->prof_mask.peir_exponent =0x1F ; + + aq->prof.peir_mantissa =0 ; + aq->prof_mask.peir_mantissa =0xFF ; + + aq->prof.pebs_exponent =24 ; + aq->prof_mask.pebs_exponent =0x1F ; + + aq->prof.pebs_mantissa =0 ; + aq->prof_mask.pebs_mantissa =0xFF ; + +/* Fill AQ info */ + aq->qidx = profile; + aq->ctype =NIX_AQ_CTYPE_BANDPROF ; + aq->op =NIX_AQ_INSTOP_WRITE ; + +return otx2_sync_mbox_msg (&pfvf->mbox); +} + +int cn10k_set_matchall_ipolicer_rate (struct otx2_nic *pfvf, +u32 burst,u64 rate) +{ +struct otx2_hw *hw = &pfvf->hw; +int qidx, rc; + +mutex_lock (&pfvf->mbox.lock); + + rc =cn10k_set_ipolicer_rate (pfvf, hw->matchall_ipolicer, burst, + rate, false); +if (rc) + goto out; + +for (qidx =0 ; qidx < hw->rx_queues; qidx++) { + rc =cn10k_map_unmap_rq_policer (pfvf, qidx, + hw->matchall_ipolicer, true); +if (rc) +break ; + } + +out: +mutex_unlock (&pfvf->mbox.lock); +return rc; +}
drivers/net/ethernet/marvell/octeontx2/nic/cn10k.h +11 -0
@@ -14,4 +14,15 @@ void cn10k_sqe_flush(void *dev, struct otx2_snd_queue *sq, int size, int qidx);int cn10k_sq_aq_init (void *dev,u16 qidx,u16 sqb_aura);int cn10k_pf_lmtst_init (struct otx2_nic *pf);int cn10k_vf_lmtst_init (struct otx2_nic *vf); +int cn10k_free_all_ipolicers (struct otx2_nic *pfvf); +int cn10k_alloc_matchall_ipolicer (struct otx2_nic *pfvf); +int cn10k_free_matchall_ipolicer (struct otx2_nic *pfvf); +int cn10k_set_matchall_ipolicer_rate (struct otx2_nic *pfvf, +u32 burst,u64 rate); +int cn10k_map_unmap_rq_policer (struct otx2_nic *pfvf,int rq_idx, +u16 policer,bool map); +int cn10k_alloc_leaf_profile (struct otx2_nic *pfvf,u16 *leaf); +int cn10k_set_ipolicer_rate (struct otx2_nic *pfvf,u16 profile, +u32 burst,u64 rate,bool pps); +int cn10k_free_leaf_profile (struct otx2_nic *pfvf,u16 leaf);#endif /* CN10K_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +2 -0
@@ -180,6 +180,7 @@ struct otx2_hw {/* NIX */ u16 txschq_list[NIX_TXSCH_LVL_CNT ][MAX_TXSCHQ_PER_FUNC ]; +u16 matchall_ipolicer;/* HW settings, coalescing etc */ u16 rx_chan_base;
@@ -325,6 +326,7 @@ struct otx2_nic {#define OTX2_FLAG_TX_PAUSE_ENABLED BIT_ULL(10)#define OTX2_FLAG_TC_FLOWER_SUPPORT BIT_ULL(11)#define OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED BIT_ULL(12) +#define OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED BIT_ULL(13)u64 flags;struct otx2_qset qset;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3 -0
@@ -1461,6 +1461,9 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)otx2_free_cq_res (pf); +/* Free all ingress bandwidth profiles allocated */ +cn10k_free_all_ipolicers (pf); +mutex_lock (&mbox->lock);/* Reset NIX LF */ free_req =otx2_mbox_alloc_msg_nix_lf_free (mbox);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +84 -0
102 lines not on this page · raw message
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH 4/5 octeontx2-pf: Use NL_SET_ERR_MSG_MOD for TC
In reply to Subbaraya SundeepThis patch modifies all netdev_err messages in tc code to NL_SET_ERR_MSG_MOD. NL_SET_ERR_MSG_MOD does not support format specifiers yet hence netdev_err messages with only strings are modified.
--- .../net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +17 -12
@@ -223,15 +223,17 @@ static int otx2_tc_egress_matchall_delete(struct otx2_nic *nic,static int otx2_tc_parse_actions (struct otx2_nic *nic,struct flow_action *flow_action, -struct npc_install_flow_req *req) +struct npc_install_flow_req *req, +struct flow_cls_offload *f) { +struct netlink_ext_ack *extack = f->common.extack;struct flow_action_entry *act;struct net_device *target;struct otx2_nic *priv;int i;if (!flow_action_has_entries (flow_action)) { -netdev_info (nic->netdev,"no tc actions specified" ); +NL_SET_ERR_MSG_MOD (extack,"no tc actions specified" );return -EINVAL ; }
@@ -248,8 +250,8 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic, priv =netdev_priv (target);/* npc_install_flow_req doesn't support passing a target pcifunc */ if (rvu_get_pf (nic->pcifunc) !=rvu_get_pf (priv->pcifunc)) { -netdev_info (nic->netdev, -"can't redirect to other pf/vf\n" ); +NL_SET_ERR_MSG_MOD (extack, +"can't redirect to other pf/vf" );return -EOPNOTSUPP ; } req->vf = priv->pcifunc &RVU_PFVF_FUNC_MASK ;
@@ -272,6 +274,7 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic,struct flow_cls_offload *f, struct npc_install_flow_req *req) { + struct netlink_ext_ack *extack = f->common.extack;struct flow_msg *flow_spec = &req->packet;struct flow_msg *flow_mask = &req->mask;struct flow_dissector *dissector;
@@ -336,7 +339,7 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic,flow_rule_match_eth_addrs (rule, &match);if (!is_zero_ether_addr (match.mask->src)) { -netdev_err (nic->netdev,"src mac match not supported\n" ); +NL_SET_ERR_MSG_MOD (extack,"src mac match not supported" );return -EOPNOTSUPP ; }
@@ -354,11 +357,11 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic,flow_rule_match_ip (rule, &match);if ((ntohs (flow_spec->etype) !=ETH_P_IP ) && match.mask->tos) { -netdev_err (nic->netdev,"tos not supported\n" ); +NL_SET_ERR_MSG_MOD (extack,"tos not supported" );return -EOPNOTSUPP ; }if (match.mask->ttl) { -netdev_err (nic->netdev,"ttl not supported\n" ); +NL_SET_ERR_MSG_MOD (extack,"ttl not supported" );return -EOPNOTSUPP ; } flow_spec->tos = match.key->tos;
@@ -414,8 +417,8 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic,if (ipv6_addr_loopback (&match.key->dst) ||ipv6_addr_loopback (&match.key->src)) { -netdev_err (nic->netdev, -"Flow matching on IPv6 loopback addr is not supported\n" ); +NL_SET_ERR_MSG_MOD (extack, +"Flow matching IPv6 loopback addr not supported" );return -EOPNOTSUPP ; }
@@ -464,7 +467,7 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, req->features |=BIT_ULL (NPC_SPORT_SCTP ); } -return otx2_tc_parse_actions (nic, &rule->action, req); +return otx2_tc_parse_actions (nic, &rule->action, req, f); }static int otx2_del_mcam_flow_entry (struct otx2_nic *nic,u16 entry)
@@ -525,6 +528,7 @@ static int otx2_tc_del_flow(struct otx2_nic *nic,static int otx2_tc_add_flow (struct otx2_nic *nic,struct flow_cls_offload *tc_flow_cmd) { +struct netlink_ext_ack *extack = tc_flow_cmd->common.extack;struct otx2_tc_info *tc_info = &nic->tc_info;struct otx2_tc_flow *new_node, *old_node;struct npc_install_flow_req *req;
@@ -562,7 +566,8 @@ static int otx2_tc_add_flow(struct otx2_nic *nic,otx2_tc_del_flow (nic, tc_flow_cmd);if (bitmap_full (tc_info->tc_entries_bitmap, nic->flow_cfg->tc_max_flows)) { -netdev_err (nic->netdev,"Not enough MCAM space to add the flow\n" ); +NL_SET_ERR_MSG_MOD (extack, +"Not enough MCAM space to add the flow" );otx2_mbox_reset (&nic->mbox.mbox,0 );mutex_unlock (&nic->mbox.lock);return -ENOMEM ;
@@ -580,7 +585,7 @@ static int otx2_tc_add_flow(struct otx2_nic *nic,/* Send message to AF */ rc =otx2_sync_mbox_msg (&nic->mbox);if (rc) { -netdev_err (nic->netdev,"Failed to install MCAM flow entry\n" ); +NL_SET_ERR_MSG_MOD (extack,"Failed to install MCAM flow entry" );mutex_unlock (&nic->mbox.lock); goto out; }
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH 5/5 octeontx2-pf: Add police action for TC flower
In reply to Subbaraya SundeepAdded police action for ingress TC flower hardware offload. With this rate limiting can be done per flow. Since rate limiting is tied to RQs in hardware the number of TC flower filters with action as police is limited to number
of receive queues of the interface. Both bps and pps modes are supported.
Examples to rate limit a flow:
$ ethtool -K eth0 hw-tc-offload on $ tc qdisc add dev eth0 ingress $ tc filter add dev eth0 parent ffff: protocol ip \ flower ip_proto udp dst_port 80 action \ police rate 100Mbit burst 32Kbit
$ tc filter add dev eth0 parent ffff: \ protocol ip flower dst_mac 5e:b2:34:ee:29:49 \ action police pkts_rate 5000 pkts_burst 2048
--- .../ethernet/marvell/octeontx2/nic/otx2_common.h | 1 + .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 6 + .../net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 194 ++++++++++++++++++--- 3 files changed, 178 insertions(+), 23 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
@@ -370,6 +370,7 @@ struct otx2_nic {struct otx2_flow_config *flow_cfg;struct otx2_tc_info tc_info; +unsigned long rq_bmap; };static inline bool is_otx2_lbkvf (struct pci_dev *pdev)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +6 -0
@@ -286,6 +286,12 @@ static int otx2_set_channels(struct net_device *dev,if (!channel->rx_count || !channel->tx_count)return -EINVAL ; +if (bitmap_weight (&pfvf->rq_bmap, pfvf->hw.rx_queues) >1 ) { +netdev_err (dev, +"Receive queues are in use by TC police action\n" ); +return -EINVAL ; + } +if (if_up) dev->netdev_ops->ndo_stop (dev);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +171 -23
299 lines not on this page · raw message
Signature · 1 line
2.7.4
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 13 lines · On Tue, 15 Jun 2021 17:04:26 +0530 you wrote:
This patchset adds ingress rate limiting hardware offload support for CN10K silicons. Police actions are added for TC matchall and flower filters. CN10K has ingress rate limiting feature where a receive queue is mapped to bandwidth profile and the profile is configured with rate and burst parameters by software. CN10K hardware supports three levels of ingress policing or ratelimiting. Multiple leaf profiles can point to a single mid level profile and multiple mid level profile can point to a single top level one. Only leaf level profiles are used for configuring rate limiting.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,1/5] octeontx2-af: cn10k: Bandwidth profiles config support
https://git.kernel.org/netdev/net-next/c/e8e095b3b370 - [net-next,2/5] octeontx2-af: cn10k: Debugfs support for bandwidth profiles https://git.kernel.org/netdev/net-next/c/e7d8971763f3 - [net-next,3/5] octeontx2-pf: TC_MATCHALL ingress ratelimiting offload https://git.kernel.org/netdev/net-next/c/2ca89a2c3752 - [net-next,4/5] octeontx2-pf: Use NL_SET_ERR_MSG_MOD for TC https://git.kernel.org/netdev/net-next/c/5d2fdd86d517 - [net-next,5/5] octeontx2-pf: Add police action for TC flower https://git.kernel.org/netdev/net-next/c/68fbff68dbea
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html