Skip to content

Commit 23f8382

Browse files
DanielmachonPaolo Abeni
authored andcommitted
net: microchip: sparx5: add support for apptrust
Make use of set/getapptrust() to implement per-selector trust and trust order. Signed-off-by: Daniel Machon <daniel.machon@microchip.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 92ef3d0 commit 23f8382

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@
88

99
#include "sparx5_port.h"
1010

11+
enum sparx5_dcb_apptrust_values {
12+
SPARX5_DCB_APPTRUST_EMPTY,
13+
SPARX5_DCB_APPTRUST_DSCP,
14+
SPARX5_DCB_APPTRUST_PCP,
15+
SPARX5_DCB_APPTRUST_DSCP_PCP,
16+
__SPARX5_DCB_APPTRUST_MAX
17+
};
18+
19+
static const struct sparx5_dcb_apptrust {
20+
u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1];
21+
int nselectors;
22+
} *sparx5_port_apptrust[SPX5_PORTS];
23+
24+
static const char *sparx5_dcb_apptrust_names[__SPARX5_DCB_APPTRUST_MAX] = {
25+
[SPARX5_DCB_APPTRUST_EMPTY] = "empty",
26+
[SPARX5_DCB_APPTRUST_DSCP] = "dscp",
27+
[SPARX5_DCB_APPTRUST_PCP] = "pcp",
28+
[SPARX5_DCB_APPTRUST_DSCP_PCP] = "dscp pcp"
29+
};
30+
31+
/* Sparx5 supported apptrust policies */
32+
static const struct sparx5_dcb_apptrust
33+
sparx5_dcb_apptrust_policies[__SPARX5_DCB_APPTRUST_MAX] = {
34+
/* Empty *must* be first */
35+
[SPARX5_DCB_APPTRUST_EMPTY] = { { 0 }, 0 },
36+
[SPARX5_DCB_APPTRUST_DSCP] = { { IEEE_8021QAZ_APP_SEL_DSCP }, 1 },
37+
[SPARX5_DCB_APPTRUST_PCP] = { { DCB_APP_SEL_PCP }, 1 },
38+
[SPARX5_DCB_APPTRUST_DSCP_PCP] = { { IEEE_8021QAZ_APP_SEL_DSCP,
39+
DCB_APP_SEL_PCP }, 2 },
40+
};
41+
1142
/* Validate app entry.
1243
*
1344
* Check for valid selectors and valid protocol and priority ranges.
@@ -37,12 +68,62 @@ static int sparx5_dcb_app_validate(struct net_device *dev,
3768
return err;
3869
}
3970

71+
/* Validate apptrust configuration.
72+
*
73+
* Return index of supported apptrust configuration if valid, otherwise return
74+
* error.
75+
*/
76+
static int sparx5_dcb_apptrust_validate(struct net_device *dev, u8 *selectors,
77+
int nselectors, int *err)
78+
{
79+
bool match;
80+
int i, ii;
81+
82+
for (i = 0; i < ARRAY_SIZE(sparx5_dcb_apptrust_policies); i++) {
83+
if (sparx5_dcb_apptrust_policies[i].nselectors != nselectors)
84+
continue;
85+
match = true;
86+
for (ii = 0; ii < nselectors; ii++) {
87+
if (sparx5_dcb_apptrust_policies[i].selectors[ii] !=
88+
*(selectors + ii)) {
89+
match = false;
90+
break;
91+
}
92+
}
93+
if (match)
94+
break;
95+
}
96+
97+
/* Requested trust configuration is not supported */
98+
if (!match) {
99+
netdev_err(dev, "Valid apptrust configurations are:\n");
100+
for (i = 0; i < ARRAY_SIZE(sparx5_dcb_apptrust_names); i++)
101+
pr_info("order: %s\n", sparx5_dcb_apptrust_names[i]);
102+
*err = -EOPNOTSUPP;
103+
}
104+
105+
return i;
106+
}
107+
108+
static bool sparx5_dcb_apptrust_contains(int portno, u8 selector)
109+
{
110+
const struct sparx5_dcb_apptrust *conf = sparx5_port_apptrust[portno];
111+
int i;
112+
113+
for (i = 0; i < conf->nselectors; i++)
114+
if (conf->selectors[i] == selector)
115+
return true;
116+
117+
return false;
118+
}
119+
40120
static int sparx5_dcb_app_update(struct net_device *dev)
41121
{
42122
struct dcb_app app_itr = { .selector = DCB_APP_SEL_PCP };
43123
struct sparx5_port *port = netdev_priv(dev);
44124
struct sparx5_port_qos_pcp_map *pcp_map;
45125
struct sparx5_port_qos qos = {0};
126+
int portno = port->portno;
46127
int i;
47128

48129
pcp_map = &qos.pcp.map;
@@ -53,6 +134,12 @@ static int sparx5_dcb_app_update(struct net_device *dev)
53134
pcp_map->map[i] = dcb_getapp(dev, &app_itr);
54135
}
55136

137+
/* Enable use of pcp for queue classification ? */
138+
if (sparx5_dcb_apptrust_contains(portno, DCB_APP_SEL_PCP)) {
139+
qos.pcp.qos_enable = true;
140+
qos.pcp.dp_enable = qos.pcp.qos_enable;
141+
}
142+
56143
return sparx5_port_qos_set(port, &qos);
57144
}
58145

@@ -95,9 +182,40 @@ static int sparx5_dcb_ieee_delapp(struct net_device *dev, struct dcb_app *app)
95182
return sparx5_dcb_app_update(dev);
96183
}
97184

185+
static int sparx5_dcb_setapptrust(struct net_device *dev, u8 *selectors,
186+
int nselectors)
187+
{
188+
struct sparx5_port *port = netdev_priv(dev);
189+
int err = 0, idx;
190+
191+
idx = sparx5_dcb_apptrust_validate(dev, selectors, nselectors, &err);
192+
if (err < 0)
193+
return err;
194+
195+
sparx5_port_apptrust[port->portno] = &sparx5_dcb_apptrust_policies[idx];
196+
197+
return sparx5_dcb_app_update(dev);
198+
}
199+
200+
static int sparx5_dcb_getapptrust(struct net_device *dev, u8 *selectors,
201+
int *nselectors)
202+
{
203+
struct sparx5_port *port = netdev_priv(dev);
204+
const struct sparx5_dcb_apptrust *trust;
205+
206+
trust = sparx5_port_apptrust[port->portno];
207+
208+
memcpy(selectors, trust->selectors, trust->nselectors);
209+
*nselectors = trust->nselectors;
210+
211+
return 0;
212+
}
213+
98214
const struct dcbnl_rtnl_ops sparx5_dcbnl_ops = {
99215
.ieee_setapp = sparx5_dcb_ieee_setapp,
100216
.ieee_delapp = sparx5_dcb_ieee_delapp,
217+
.dcbnl_setapptrust = sparx5_dcb_setapptrust,
218+
.dcbnl_getapptrust = sparx5_dcb_getapptrust,
101219
};
102220

103221
int sparx5_dcb_init(struct sparx5 *sparx5)
@@ -110,6 +228,10 @@ int sparx5_dcb_init(struct sparx5 *sparx5)
110228
if (!port)
111229
continue;
112230
port->ndev->dcbnl_ops = &sparx5_dcbnl_ops;
231+
/* Initialize [dscp, pcp] default trust */
232+
sparx5_port_apptrust[port->portno] =
233+
&sparx5_dcb_apptrust_policies
234+
[SPARX5_DCB_APPTRUST_DSCP_PCP];
113235
}
114236

115237
return 0;

drivers/net/ethernet/microchip/sparx5/sparx5_port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ int sparx5_port_qos_pcp_set(const struct sparx5_port *port,
11631163
int i;
11641164

11651165
/* Enable/disable pcp and dp for qos classification. */
1166-
spx5_rmw(ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA_SET(1) |
1167-
ANA_CL_QOS_CFG_PCP_DEI_DP_ENA_SET(1),
1166+
spx5_rmw(ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA_SET(qos->qos_enable) |
1167+
ANA_CL_QOS_CFG_PCP_DEI_DP_ENA_SET(qos->dp_enable),
11681168
ANA_CL_QOS_CFG_PCP_DEI_QOS_ENA | ANA_CL_QOS_CFG_PCP_DEI_DP_ENA,
11691169
sparx5, ANA_CL_QOS_CFG(port->portno));
11701170

drivers/net/ethernet/microchip/sparx5/sparx5_port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct sparx5_port_qos_pcp_map {
101101

102102
struct sparx5_port_qos_pcp {
103103
struct sparx5_port_qos_pcp_map map;
104+
bool qos_enable;
105+
bool dp_enable;
104106
};
105107

106108
struct sparx5_port_qos {

0 commit comments

Comments
 (0)