public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia•com>
To: Daniel Machon <daniel.machon@microchip•com>
Cc: <netdev@vger•kernel.org>, <davem@davemloft•net>,
	<petrm@nvidia•com>, <maxime.chevallier@bootlin•com>,
	<thomas.petazzoni@bootlin•com>, <edumazet@google•com>,
	<kuba@kernel•org>, <pabeni@redhat•com>,
	<lars.povlsen@microchip•com>, <Steen.Hegelund@microchip•com>,
	<UNGLinuxDriver@microchip•com>, <joe@perches•com>,
	<linux@armlinux•org.uk>, <horatiu.vultur@microchip•com>,
	<Julia.Lawall@inria•fr>, <vladimir.oltean@nxp•com>,
	<linux-kernel@vger•kernel.org>,
	<linux-arm-kernel@lists•infradead.org>
Subject: Re: [PATCH net-next v2 4/6] net: microchip: sparx5: add support for apptrust
Date: Fri, 30 Sep 2022 17:49:15 +0200	[thread overview]
Message-ID: <87zgegu9kq.fsf@nvidia.com> (raw)
In-Reply-To: <20220929185207.2183473-5-daniel.machon@microchip.com>


Daniel Machon <daniel.machon@microchip•com> writes:

> Make use of set/getapptrust() to implement per-selector trust and trust
> order.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip•com>
> ---
>  .../ethernet/microchip/sparx5/sparx5_dcb.c    | 116 ++++++++++++++++++
>  .../ethernet/microchip/sparx5/sparx5_main.h   |   3 +
>  .../ethernet/microchip/sparx5/sparx5_port.c   |   4 +-
>  .../ethernet/microchip/sparx5/sparx5_port.h   |   2 +
>  .../ethernet/microchip/sparx5/sparx5_qos.c    |   4 +
>  5 files changed, 127 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c b/drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c
> index db17c124dac8..10aeb422b1ae 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c
> @@ -8,6 +8,22 @@
>
>  #include "sparx5_port.h"
>
> +static const struct sparx5_dcb_apptrust {
> +	u8 selectors[256];
> +	int nselectors;
> +	char *names;

I think this should be just "name".

> +} *apptrust[SPX5_PORTS];
> +
> +/* Sparx5 supported apptrust configurations */
> +static const struct sparx5_dcb_apptrust apptrust_conf[4] = {
> +	/* Empty *must* be first */
> +	{ { 0                         }, 0, "empty"    },
> +	{ { IEEE_8021QAZ_APP_SEL_DSCP }, 1, "dscp"     },
> +	{ { DCB_APP_SEL_PCP           }, 1, "pcp"      },
> +	{ { IEEE_8021QAZ_APP_SEL_DSCP,
> +	    DCB_APP_SEL_PCP           }, 2, "dscp pcp" },
> +};
> +
>  /* Validate app entry.
>   *
>   * Check for valid selectors and valid protocol and priority ranges.
> @@ -37,12 +53,59 @@ static int sparx5_dcb_app_validate(struct net_device *dev,
>  	return err;
>  }
>
> +/* Validate apptrust configuration.
> + *
> + * Return index of supported apptrust configuration if valid, otherwise return
> + * error.
> + */
> +static int sparx5_dcb_apptrust_validate(struct net_device *dev, u8 *selectors,
> +					int nselectors, int *err)
> +{
> +	bool match;
> +	int i, ii;
> +
> +	for (i = 0; i < ARRAY_SIZE(apptrust_conf); i++) {

I would do this here:

    if (apptrust_conf[i].nselectors != nselectors) continue;

to avoid having to think about the semantics of comparing to all those
zeroes in apptrust_conf.selectors array.

> +		match = true;
> +		for (ii = 0; ii < nselectors; ii++) {
> +			if (apptrust_conf[i].selectors[ii] !=
> +			    *(selectors + ii)) {
> +				match = false;
> +				break;
> +			}
> +		}
> +		if (match)
> +			break;
> +	}
> +
> +	/* Requested trust configuration is not supported */
> +	if (!match) {
> +		netdev_err(dev, "Valid apptrust configurations are:\n");
> +		for (i = 0; i < ARRAY_SIZE(apptrust_conf); i++)
> +			pr_info("order: %s\n", apptrust_conf[i].names);
> +		*err = -EOPNOTSUPP;
> +	}
> +
> +	return i;
> +}
> +
> +static bool sparx5_dcb_apptrust_contains(int portno, u8 selector)
> +{
> +	int i;
> +
> +	for (i = 0; i < IEEE_8021QAZ_APP_SEL_MAX + 1; i++)
> +		if (apptrust[portno]->selectors[i] == selector)
> +			return true;
> +
> +	return false;
> +}
> +
>  static int sparx5_dcb_app_update(struct net_device *dev)
>  {
>  	struct dcb_app app_itr = { .selector = DCB_APP_SEL_PCP };
>  	struct sparx5_port *port = netdev_priv(dev);
>  	struct sparx5_port_qos_pcp_map *pcp_map;
>  	struct sparx5_port_qos qos = {0};
> +	int portno = port->portno;
>  	int i;
>
>  	pcp_map = &qos.pcp.map;
> @@ -53,6 +116,12 @@ static int sparx5_dcb_app_update(struct net_device *dev)
>  		pcp_map->map[i] = dcb_getapp(dev, &app_itr);
>  	}
>
> +	/* Enable use of pcp for queue classification ? */
> +	if (sparx5_dcb_apptrust_contains(portno, DCB_APP_SEL_PCP)) {
> +		qos.pcp.qos_enable = true;
> +		qos.pcp.dp_enable = qos.pcp.qos_enable;
> +	}
> +
>  	return sparx5_port_qos_set(port, &qos);
>  }
>
> @@ -95,7 +164,54 @@ static int sparx5_dcb_ieee_delapp(struct net_device *dev, struct dcb_app *app)
>  	return sparx5_dcb_app_update(dev);
>  }
>
> +static int sparx5_dcb_setapptrust(struct net_device *dev, u8 *selectors,
> +				  int nselectors)
> +{
> +	struct sparx5_port *port = netdev_priv(dev);
> +	int err = 0, idx;
> +
> +	idx = sparx5_dcb_apptrust_validate(dev, selectors, nselectors, &err);
> +	if (err < 0)
> +		return err;
> +
> +	apptrust[port->portno] = &apptrust_conf[idx];
> +
> +	return sparx5_dcb_app_update(dev);
> +}
> +
> +static int sparx5_dcb_getapptrust(struct net_device *dev, u8 *selectors,
> +				  int *nselectors)
> +{
> +	struct sparx5_port *port = netdev_priv(dev);
> +	const struct sparx5_dcb_apptrust *trust;
> +
> +	trust = apptrust[port->portno];
> +
> +	memcpy(selectors, trust->selectors, trust->nselectors);
> +	*nselectors = trust->nselectors;
> +
> +	return 0;
> +}
> +
> +int sparx5_dcb_init(struct sparx5 *sparx5)
> +{
> +	struct sparx5_port *port;
> +	int i;
> +
> +	for (i = 0; i < SPX5_PORTS; i++) {
> +		port = sparx5->ports[i];
> +		if (!port)
> +			continue;
> +		/* Initialize [dscp, pcp] default trust */
> +		apptrust[port->portno] = &apptrust_conf[3];
> +	}
> +
> +	return sparx5_dcb_app_update(port->ndev);
> +}
> +
>  const struct dcbnl_rtnl_ops sparx5_dcbnl_ops = {
>  	.ieee_setapp = sparx5_dcb_ieee_setapp,
>  	.ieee_delapp = sparx5_dcb_ieee_delapp,
> +	.dcbnl_setapptrust = sparx5_dcb_setapptrust,
> +	.dcbnl_getapptrust = sparx5_dcb_getapptrust,
>  };
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> index 0d8e04c64584..d07ef2e8b321 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> @@ -357,6 +357,9 @@ int sparx5_config_dsm_calendar(struct sparx5 *sparx5);
>  void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats);
>  int sparx_stats_init(struct sparx5 *sparx5);
>
> +/* sparx5_dcb.c */
> +int sparx5_dcb_init(struct sparx5 *sparx5);
> +
>  /* sparx5_netdev.c */
>  void sparx5_set_port_ifh_timestamp(void *ifh_hdr, u64 timestamp);
>  void sparx5_set_port_ifh_rew_op(void *ifh_hdr, u32 rew_op);
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_port.c b/drivers/net/ethernet/microchip/sparx5/sparx5_port.c
> index 9ffaaf34d196..99e86e87aa16 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_port.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_port.c
> @@ -1163,8 +1163,8 @@ int sparx5_port_qos_pcp_set(const struct sparx5_port *port,
>  	int i;
>
>  	/* Enable/disable pcp and dp for qos classification. */
> -	spx5_rmw(ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA_SET(1) |
> -		 ANA_CL_QOS_CFG_PCP_DEI_DP_ENA_SET(1),
> +	spx5_rmw(ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA_SET(qos->qos_enable) |
> +		 ANA_CL_QOS_CFG_PCP_DEI_DP_ENA_SET(qos->dp_enable),
>  		 ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA | ANA_CL_QOS_CFG_PCP_DEI_DP_ENA,
>  		 sparx5, ANA_CL_QOS_CFG(port->portno));
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_port.h b/drivers/net/ethernet/microchip/sparx5/sparx5_port.h
> index 9c5fb6b651db..fae9f5464548 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_port.h
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_port.h
> @@ -97,6 +97,8 @@ struct sparx5_port_qos_pcp_map {
>
>  struct sparx5_port_qos_pcp {
>  	struct sparx5_port_qos_pcp_map map;
> +	bool qos_enable;
> +	bool dp_enable;
>  };
>
>  struct sparx5_port_qos {
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c
> index 1e79d0ef0cb8..379e540e5e6a 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c
> @@ -389,6 +389,10 @@ int sparx5_qos_init(struct sparx5 *sparx5)
>  	if (ret < 0)
>  		return ret;
>
> +	ret = sparx5_dcb_init(sparx5);
> +	if (ret < 0)
> +		return ret;
> +
>  	return 0;
>  }


  reply	other threads:[~2022-09-30 16:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 18:52 [PATCH net-next v2 0/6] Add new PCP and APPTRUST attributes to dcbnl Daniel Machon
2022-09-29 18:52 ` [PATCH net-next v2 1/6] net: dcb: add new pcp selector to app object Daniel Machon
2022-09-30 12:20   ` Petr Machata
2022-09-30 15:41     ` Petr Machata
2022-10-01  0:54     ` Jakub Kicinski
2022-10-03  7:52       ` Petr Machata
2022-10-03 16:25         ` Jakub Kicinski
2022-10-03 21:59           ` Daniel.Machon
2022-10-03 23:34             ` Jakub Kicinski
2022-10-04 10:56               ` Petr Machata
2022-10-04 10:20           ` Petr Machata
2022-10-04 10:52             ` Petr Machata
2022-10-04 19:51               ` Jakub Kicinski
2022-10-03  6:48     ` Daniel.Machon
2022-10-03  8:22       ` Petr Machata
2022-10-03  9:33         ` Daniel.Machon
2022-10-05 10:09           ` Petr Machata
2022-09-29 18:52 ` [PATCH net-next v2 2/6] net: dcb: add new apptrust attribute Daniel Machon
2022-09-30 13:03   ` Petr Machata
2022-09-29 18:52 ` [PATCH net-next v2 3/6] net: microchip: sparx5: add support for offloading pcp table Daniel Machon
2022-09-30 20:44   ` kernel test robot
2022-09-29 18:52 ` [PATCH net-next v2 4/6] net: microchip: sparx5: add support for apptrust Daniel Machon
2022-09-30 15:49   ` Petr Machata [this message]
2022-10-03  6:52     ` Daniel.Machon
2022-10-03  8:01       ` Petr Machata
2022-10-03  8:17         ` Daniel.Machon
2022-10-03  9:34           ` Petr Machata
2022-09-29 18:52 ` [PATCH net-next v2 5/6] net: microchip: sparx5: add support for offloading dscp table Daniel Machon
2022-09-30 23:23   ` kernel test robot
2022-09-29 18:52 ` [PATCH net-next v2 6/6] net: microchip: sparx5: add support for offloading default prio Daniel Machon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zgegu9kq.fsf@nvidia.com \
    --to=petrm@nvidia$(echo .)com \
    --cc=Julia.Lawall@inria$(echo .)fr \
    --cc=Steen.Hegelund@microchip$(echo .)com \
    --cc=UNGLinuxDriver@microchip$(echo .)com \
    --cc=daniel.machon@microchip$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=edumazet@google$(echo .)com \
    --cc=horatiu.vultur@microchip$(echo .)com \
    --cc=joe@perches$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=lars.povlsen@microchip$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux@armlinux$(echo .)org.uk \
    --cc=maxime.chevallier@bootlin$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=pabeni@redhat$(echo .)com \
    --cc=thomas.petazzoni@bootlin$(echo .)com \
    --cc=vladimir.oltean@nxp$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox