Make use of set/getapptrust() to implement per-selector trust and trust
order.
Signed-off-by: Daniel Machon <[email protected]>
---
.../ethernet/microchip/sparx5/sparx5_dcb.c | 116 ++++++++++++++++++
.../ethernet/microchip/sparx5/sparx5_port.c | 4 +-
.../ethernet/microchip/sparx5/sparx5_port.h | 2 +
.../ethernet/microchip/sparx5/sparx5_qos.c | 4 +
.../ethernet/microchip/sparx5/sparx5_qos.h | 3 +
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;
+} *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++) {
+ 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_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;
}
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h
index ced35033a6c5..6d248cbd485b 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h
@@ -61,6 +61,9 @@ struct sparx5_dwrr {
int sparx5_qos_init(struct sparx5 *sparx5);
+/* sparx5_dcb.c */
+int sparx5_dcb_init(struct sparx5 *sparx5);
+
/* Multi-Queue Priority */
int sparx5_tc_mqprio_add(struct net_device *ndev, u8 num_tc);
int sparx5_tc_mqprio_del(struct net_device *ndev);
--
2.34.1
Hi Daniel,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Machon/Add-new-PCP-and-APPTRUST-attributes-to-dcbnl/20220929-195750
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 0e9804cff18223e750f3af52a2701945bb362f55
config: sh-allmodconfig
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b0191a19df159a4f61797bb6d98052d4f27a9894
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Daniel-Machon/Add-new-PCP-and-APPTRUST-attributes-to-dcbnl/20220929-195750
git checkout b0191a19df159a4f61797bb6d98052d4f27a9894
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/net/ethernet/microchip/sparx5/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c:196:5: warning: no previous prototype for 'sparx5_dcb_init' [-Wmissing-prototypes]
196 | int sparx5_dcb_init(struct sparx5 *sparx5)
| ^~~~~~~~~~~~~~~
vim +/sparx5_dcb_init +196 drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c
195
> 196 int sparx5_dcb_init(struct sparx5 *sparx5)
197 {
198 struct sparx5_port *port;
199 int i;
200
201 for (i = 0; i < SPX5_PORTS; i++) {
202 port = sparx5->ports[i];
203 if (!port)
204 continue;
205 /* Initialize [dscp, pcp] default trust */
206 apptrust[port->portno] = &apptrust_conf[3];
207 }
208
209 return sparx5_dcb_app_update(port->ndev);
210 }
211
--
0-DAY CI Kernel Test Service
https://01.org/lkp