Re: [PATCH] octeontx2-pf: Add RSS multi group support

2020-12-05 Thread Jakub Kicinski
On Fri,  4 Dec 2020 14:54:51 +0530 Geetha sowjanya wrote:
> Hardware supports 8 RSS groups per interface. Currently we are using
> only group '0'. This patch allows user to create new RSS groups/contexts
> and use the same as destination for flow steering rules.
> 
> usage:
> To steer the traffic to RQ 2,3
> 
> ethtool -X eth0 weight 0 0 1 1 context new
> (It will print the allocated context id number)
> New RSS context is 1
> 
> ethtool -N eth0 flow-type tcp4 dst-port 80 context 1 loc 1
> 
> To delete the context
> ethtool -X eth0 context 1 delete
> 
> When an RSS context is removed, the active classification
> rules using this context are also removed.
> 
> Signed-off-by: Sunil Kovvuri Goutham 
> Signed-off-by: Geetha sowjanya 

Looks good, minor coding nits below.

> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c 
> b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> index 73fb94d..0c84dcf 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -270,14 +270,17 @@ int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
>   return err;
>  }
>  
> -int otx2_set_rss_table(struct otx2_nic *pfvf)
> +int otx2_set_rss_table(struct otx2_nic *pfvf, int ctx_id)
>  {
>   struct otx2_rss_info *rss = >hw.rss_info;
> + int index = rss->rss_size * ctx_id;

const?

>   struct mbox *mbox = >mbox;
> + struct otx2_rss_ctx *rss_ctx;
>   struct nix_aq_enq_req *aq;
>   int idx, err;
>  
>   mutex_lock(>lock);
> + rss_ctx = rss->rss_ctx[ctx_id];
>   /* Get memory to put this msg */
>   for (idx = 0; idx < rss->rss_size; idx++) {
>   aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);

> +/* RSS context configuration */
> +static int otx2_set_rxfh_context(struct net_device *dev, const u32 *indir,
> +  const u8 *hkey, const u8 hfunc,
> +  u32 *rss_context, bool delete)
> +{
>   struct otx2_nic *pfvf = netdev_priv(dev);
> + struct otx2_rss_ctx *rss_ctx;
> + struct otx2_rss_info *rss;
> + int ret, idx;
> +
> + if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
> + return -EOPNOTSUPP;
> +
> + rss = >hw.rss_info;
>  
> - return pfvf->hw.rss_info.rss_size;
> + if (!rss->enable) {
> + netdev_err(dev, "RSS is disabled, cannot change settings\n");
> + return -EIO;
> + }
> +
> + if (hkey) {
> + memcpy(rss->key, hkey, sizeof(rss->key));
> + otx2_set_rss_key(pfvf);
> + }
> + if (delete)
> + return otx2_rss_ctx_delete(pfvf, *rss_context);
> +
> + if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
> + ret = otx2_rss_ctx_create(pfvf, rss_context);
> + if (ret)
> + return ret;
> + }
> + if (indir) {
> + rss_ctx = rss->rss_ctx[*rss_context];
> + for (idx = 0; idx < rss->rss_size; idx++)
> + rss_ctx->ind_tbl[idx] = indir[idx];
> + }
> + otx2_set_rss_table(pfvf, *rss_context);
> +
> + return 0;
> +}
> +
> +static int otx2_get_rxfh_context(struct net_device *dev, u32 *indir,
> +  u8 *hkey, u8 *hfunc, u32 rss_context)
> +{
> + struct otx2_nic *pfvf = netdev_priv(dev);
> + struct otx2_rss_ctx *rss_ctx;
> + struct otx2_rss_info *rss;
> + int idx;
> +
> + rss = >hw.rss_info;
> +
> + if (!rss->enable) {
> + netdev_err(dev, "RSS is disabled\n");
> + return -EIO;
> + }
> + if (rss_context >= MAX_RSS_GROUPS)
> + return -EINVAL;
> +
> + rss_ctx = rss->rss_ctx[rss_context];
> + if (!rss_ctx)
> + return -EINVAL;
> +
> + if (indir) {
> + for (idx = 0; idx < rss->rss_size; idx++)
> + indir[idx] = rss_ctx->ind_tbl[idx];
> + }
> + if (hkey)
> + memcpy(hkey, rss->key, sizeof(rss->key));
> +
> + if (hfunc)
> + *hfunc = ETH_RSS_HASH_TOP;
> +
> + return 0;
>  }

Can the old callbacks not be converted to something like:

static int otx2_get_rxfh(...)
{
return otx2_get_rxfh_context(..., DEFAULT_RSS_CONTEXT_GROUP);
}

?

> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c 
> b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
> index be8ccfc..e5f6b4a 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
> @@ -17,6 +17,7 @@ struct otx2_flow {
>   u16 entry;
>   bool is_vf;
>   int vf;
> + u8 rss_ctx_id;

If you put it next to the bool it will make the structure smaller (less
padding).

>  };
>  
>  int otx2_alloc_mcam_entries(struct otx2_nic *pfvf)

> @@ -521,7 +523,6 @@ static int otx2_add_flow_msg(struct otx2_nic *pfvf, 
> struct otx2_flow *flow)
>   mutex_unlock(>mbox.lock);
>   

[PATCH] octeontx2-pf: Add RSS multi group support

2020-12-04 Thread Geetha sowjanya
Hardware supports 8 RSS groups per interface. Currently we are using
only group '0'. This patch allows user to create new RSS groups/contexts
and use the same as destination for flow steering rules.

usage:
To steer the traffic to RQ 2,3

ethtool -X eth0 weight 0 0 1 1 context new
(It will print the allocated context id number)
New RSS context is 1

ethtool -N eth0 flow-type tcp4 dst-port 80 context 1 loc 1

To delete the context
ethtool -X eth0 context 1 delete

When an RSS context is removed, the active classification
rules using this context are also removed.

Signed-off-by: Sunil Kovvuri Goutham 
Signed-off-by: Geetha sowjanya 
---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  26 +++--
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  11 +-
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 124 -
 .../ethernet/marvell/octeontx2/nic/otx2_flows.c|  38 ++-
 4 files changed, 177 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c 
b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index 73fb94d..0c84dcf 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -270,14 +270,17 @@ int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
return err;
 }
 
-int otx2_set_rss_table(struct otx2_nic *pfvf)
+int otx2_set_rss_table(struct otx2_nic *pfvf, int ctx_id)
 {
struct otx2_rss_info *rss = >hw.rss_info;
+   int index = rss->rss_size * ctx_id;
struct mbox *mbox = >mbox;
+   struct otx2_rss_ctx *rss_ctx;
struct nix_aq_enq_req *aq;
int idx, err;
 
mutex_lock(>lock);
+   rss_ctx = rss->rss_ctx[ctx_id];
/* Get memory to put this msg */
for (idx = 0; idx < rss->rss_size; idx++) {
aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
@@ -297,10 +300,10 @@ int otx2_set_rss_table(struct otx2_nic *pfvf)
}
}
 
-   aq->rss.rq = rss->ind_tbl[idx];
+   aq->rss.rq = rss_ctx->ind_tbl[idx];
 
/* Fill AQ info */
-   aq->qidx = idx;
+   aq->qidx = index + idx;
aq->ctype = NIX_AQ_CTYPE_RSS;
aq->op = NIX_AQ_INSTOP_INIT;
}
@@ -335,9 +338,10 @@ void otx2_set_rss_key(struct otx2_nic *pfvf)
 int otx2_rss_init(struct otx2_nic *pfvf)
 {
struct otx2_rss_info *rss = >hw.rss_info;
+   struct otx2_rss_ctx *rss_ctx;
int idx, ret = 0;
 
-   rss->rss_size = sizeof(rss->ind_tbl);
+   rss->rss_size = sizeof(*rss->rss_ctx[DEFAULT_RSS_CONTEXT_GROUP]);
 
/* Init RSS key if it is not setup already */
if (!rss->enable)
@@ -345,13 +349,19 @@ int otx2_rss_init(struct otx2_nic *pfvf)
otx2_set_rss_key(pfvf);
 
if (!netif_is_rxfh_configured(pfvf->netdev)) {
-   /* Default indirection table */
+   /* Set RSS group 0 as default indirection table */
+   rss->rss_ctx[DEFAULT_RSS_CONTEXT_GROUP] = kzalloc(rss->rss_size,
+ GFP_KERNEL);
+   if (!rss->rss_ctx[DEFAULT_RSS_CONTEXT_GROUP])
+   return -ENOMEM;
+
+   rss_ctx = rss->rss_ctx[DEFAULT_RSS_CONTEXT_GROUP];
for (idx = 0; idx < rss->rss_size; idx++)
-   rss->ind_tbl[idx] =
+   rss_ctx->ind_tbl[idx] =
ethtool_rxfh_indir_default(idx,
   pfvf->hw.rx_queues);
}
-   ret = otx2_set_rss_table(pfvf);
+   ret = otx2_set_rss_table(pfvf, DEFAULT_RSS_CONTEXT_GROUP);
if (ret)
return ret;
 
@@ -986,7 +996,7 @@ int otx2_config_nix(struct otx2_nic *pfvf)
nixlf->sq_cnt = pfvf->hw.tx_queues;
nixlf->cq_cnt = pfvf->qset.cq_cnt;
nixlf->rss_sz = MAX_RSS_INDIR_TBL_SIZE;
-   nixlf->rss_grps = 1; /* Single RSS indir table supported, for now */
+   nixlf->rss_grps = MAX_RSS_GROUPS;
nixlf->xqe_sz = NIX_XQESZ_W16;
/* We don't know absolute NPA LF idx attached.
 * AF will replace 'RVU_DEFAULT_PF_FUNC' with
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h 
b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
index 1034304..143ae04 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
@@ -51,13 +51,17 @@ enum arua_mapped_qtypes {
 #define NIX_LF_POISON_VEC  0x82
 
 /* RSS configuration */
+struct otx2_rss_ctx {
+   u8  ind_tbl[MAX_RSS_INDIR_TBL_SIZE];
+};
+
 struct otx2_rss_info {
u8 enable;
u32 flowkey_cfg;
u16 rss_size;
-   u8  ind_tbl[MAX_RSS_INDIR_TBL_SIZE];
 #define RSS_HASH_KEY_SIZE  44   /* 352 bit key */
u8  key[RSS_HASH_KEY_SIZE];
+