@@ -8,6 +8,22 @@
#include "sparx5_port.h"
+static const struct sparx5_dcb_apptrust {
+ u8 selectors[256];
+ int nselectors;
+ const 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,62 @@ 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++) {
+ if (apptrust_conf[i].nselectors != nselectors)
+ continue;
+ 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)
+{
+ const struct sparx5_dcb_apptrust *conf = apptrust[portno];
+ int i;
+
+ for (i = 0; i < conf->nselectors; i++)
+ if (conf->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 +119,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,9 +167,40 @@ 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;
+}
+
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,
};
int sparx5_dcb_init(struct sparx5 *sparx5)
@@ -110,6 +213,8 @@ int sparx5_dcb_init(struct sparx5 *sparx5)
if (!port)
continue;
port->ndev->dcbnl_ops = &sparx5_dcbnl_ops;
+ /* Initialize [dscp, pcp] default trust */
+ apptrust[port->portno] = &apptrust_conf[3];
}
return 0;
@@ -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));
@@ -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 {