2022-09-29 19:40:35

by Daniel Machon

[permalink] [raw]
Subject: [PATCH net-next v2 0/6] Add new PCP and APPTRUST attributes to dcbnl

This patch series adds new extension attributes to dcbnl, for PCP queue
classification and per-selector trust and trust order. Additionally, the
microchip sparx5 driver has been dcb-enabled to make use of the new
attributes to offload PCP, DSCP and Default prio to the switch, and
implement trust order of selectors.

For pre-RFC discussion see:
https://lore.kernel.org/netdev/Yv9VO1DYAxNduw6A@DEN-LT-70577/

For RFC series see:
https://lore.kernel.org/netdev/[email protected]/

In summary: there currently exist no convenient way to offload per-port
PCP-based queue classification to hardware. Similarly, there is no way
to indicate the notion of trust for APP table selectors. This patch
series addresses both topics.

PCP based queue classification:
- 8021Q standardizes the Priority Code Point table (see 6.9.3 of IEEE
Std 802.1Q-2018). This patch series makes it possible, to offload
the PCP classification to said table. The new PCP selector is not a
standard part of the APP managed object, therefore it is
encapsulated in a new non-std extension attribute.

Selector trust:
- ASIC's often has the notion of trust DSCP and trust PCP. The new
attribute makes it possible to specify a trust order of app
selectors, which drivers can then react on.

DCB-enable sparx5 driver:
- Now supports offloading of DSCP, PCP and default priority. Only one
mapping of protocol:priority is allowed. Consecutive mappings of the
same protocol to some new priority, will overwrite the previous. This
is to keep a consistent view of the app table and the hardware.
- Now supports dscp and pcp trust, by use of the introduced
dcbnl_set/getapptrust ops. Sparx5 supports trust orders: [], [dscp],
[pcp] and [dscp, pcp]. For now, only DSCP and PCP selectors are
supported by the driver, everything else is bounced.

Patch #1 introduces a new PCP selector to the APP object, which makes it
possible to encode PCP and DEI in the app triplet and offload it to the
PCP table of the ASIC.

Patch #2 Introduces the new extension attributes
DCB_ATTR_DCB_APP_TRUST_TABLE and DCB_ATTR_DCB_APP_TRUST. Trusted
selectors are passed in the nested DCB_ATTR_DCB_APP_TRUST_TABLE
attribute, and assembled into an array of selectors:

u8 selectors[256];

where lower indexes has higher precedence. In the array, selectors are
stored consecutively, starting from index zero. With a maximum number of
256 unique selectors, the list has the same maximum size.

Patch #3 Sets up the dcbnl ops hook, and adds support for offloading pcp
app entries, to the PCP table of the switch.

Patch #4 Makes use of the dcbnl_set/getapptrust ops, to set a per-port
trust order.

Patch #5 Adds support for offloading dscp app entries to the DSCP table
of the switch.

Patch #6 Adds support for offloading default prio app entries to the
switch.

================================================================================

RFC v1:
https://lore.kernel.org/netdev/[email protected]/

RFC v1 -> RFC v2:
- Added new nested attribute type DCB_ATTR_DCB_APP_TRUST_TABLE.
- Renamed attributes from DCB_ATTR_IEEE_* to DCB_ATTR_DCB_*.
- Renamed ieee_set/getapptrust to dcbnl_set/getapptrust.
- Added -EOPNOTSUPP if dcbnl_setapptrust is not set.
- Added sanitization of selector array, before passing to driver.

RFC v2 -> (non-RFC) v1
- Added additional check for selector validity.
- Fixed a few style errors.
- using nla_start_nest() instead of nla_start_nest_no_flag().
- Moved DCB_ATTR_DCB_APP_TRUST into new enum.
- Added new DCB_ATTR_DCB_APP extension attribute, for non-std selector
values.
- Added support for offloading dscp, pcp and default prio in the sparx5
driver.
- Added support for per-selector trust and trust order in the sparx5
driver.

v1 -> v2
- Fixed compiler and kdoc warning

Daniel Machon (6):
net: dcb: add new pcp selector to app object
net: dcb: add new apptrust attribute
net: microchip: sparx5: add support for offloading pcp table
net: microchip: sparx5: add support for apptrust
net: microchip: sparx5: add support for offloading dscp table
net: microchip: sparx5: add support for offloading default prio

.../net/ethernet/microchip/sparx5/Makefile | 2 +-
.../ethernet/microchip/sparx5/sparx5_dcb.c | 287 ++++++++++++++++++
.../ethernet/microchip/sparx5/sparx5_main.h | 4 +
.../microchip/sparx5/sparx5_main_regs.h | 127 +++++++-
.../ethernet/microchip/sparx5/sparx5_netdev.c | 1 +
.../ethernet/microchip/sparx5/sparx5_port.c | 99 ++++++
.../ethernet/microchip/sparx5/sparx5_port.h | 33 ++
.../ethernet/microchip/sparx5/sparx5_qos.c | 4 +
include/net/dcbnl.h | 4 +
include/uapi/linux/dcbnl.h | 15 +
net/dcb/dcbnl.c | 126 +++++++-
11 files changed, 691 insertions(+), 11 deletions(-)
create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c

--
2.34.1


2022-09-29 19:54:10

by Daniel Machon

[permalink] [raw]
Subject: [PATCH net-next v2 2/6] net: dcb: add new apptrust attribute

Add new apptrust extension attributes to the 8021Qaz APP managed object.

Two new attributes, DCB_ATTR_DCB_APP_TRUST_TABLE and
DCB_ATTR_DCB_APP_TRUST, has been added. Trusted selectors are passed in
the nested attribute DCB_ATTR_DCB_APP_TRUST, in order of precedence.

The new attributes are meant to allow drivers, whose hw supports the
notion of trust, to be able to set whether a particular app selector is
trusted - and in which order.

Signed-off-by: Daniel Machon <[email protected]>
---
include/net/dcbnl.h | 4 ++
include/uapi/linux/dcbnl.h | 9 +++++
net/dcb/dcbnl.c | 77 ++++++++++++++++++++++++++++++++++++--
3 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/include/net/dcbnl.h b/include/net/dcbnl.h
index 2b2d86fb3131..8841ab6c2de7 100644
--- a/include/net/dcbnl.h
+++ b/include/net/dcbnl.h
@@ -109,6 +109,10 @@ struct dcbnl_rtnl_ops {
/* buffer settings */
int (*dcbnl_getbuffer)(struct net_device *, struct dcbnl_buffer *);
int (*dcbnl_setbuffer)(struct net_device *, struct dcbnl_buffer *);
+
+ /* apptrust */
+ int (*dcbnl_setapptrust)(struct net_device *, u8 *, int);
+ int (*dcbnl_getapptrust)(struct net_device *, u8 *, int *);
};

#endif /* __NET_DCBNL_H__ */
diff --git a/include/uapi/linux/dcbnl.h b/include/uapi/linux/dcbnl.h
index 9f68dc501cc1..f892cd945695 100644
--- a/include/uapi/linux/dcbnl.h
+++ b/include/uapi/linux/dcbnl.h
@@ -410,6 +410,7 @@ enum dcbnl_attrs {
* @DCB_ATTR_IEEE_PEER_ETS: peer ETS configuration - get only
* @DCB_ATTR_IEEE_PEER_PFC: peer PFC configuration - get only
* @DCB_ATTR_IEEE_PEER_APP: peer APP tlv - get only
+ * @DCB_ATTR_DCB_APP_TRUST_TABLE: selector trust order
*/
enum ieee_attrs {
DCB_ATTR_IEEE_UNSPEC,
@@ -423,6 +424,7 @@ enum ieee_attrs {
DCB_ATTR_IEEE_QCN,
DCB_ATTR_IEEE_QCN_STATS,
DCB_ATTR_DCB_BUFFER,
+ DCB_ATTR_DCB_APP_TRUST_TABLE,
__DCB_ATTR_IEEE_MAX
};
#define DCB_ATTR_IEEE_MAX (__DCB_ATTR_IEEE_MAX - 1)
@@ -435,6 +437,13 @@ enum ieee_attrs_app {
};
#define DCB_ATTR_IEEE_APP_MAX (__DCB_ATTR_IEEE_APP_MAX - 1)

+enum dcbnl_attrs_apptrust {
+ DCB_ATTR_DCB_APP_TRUST_UNSPEC,
+ DCB_ATTR_DCB_APP_TRUST,
+ __DCB_ATTR_DCB_APP_TRUST_MAX
+};
+#define DCB_ATTR_DCB_APP_TRUST_MAX (__DCB_ATTR_DCB_APP_TRUST_MAX - 1)
+
/**
* enum cee_attrs - CEE DCBX get attributes.
*
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 580d26acfc84..ad84f70e3eb3 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -166,6 +166,7 @@ static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
[DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)},
[DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)},
[DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)},
+ [DCB_ATTR_DCB_APP_TRUST_TABLE] = {.type = NLA_NESTED},
};

/* DCB number of traffic classes nested attributes. */
@@ -1070,11 +1071,11 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
/* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
{
- struct nlattr *ieee, *app;
- struct dcb_app_type *itr;
const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
+ struct nlattr *ieee, *app, *apptrust;
+ struct dcb_app_type *itr;
+ int err, i;
int dcbx;
- int err;

if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
return -EMSGSIZE;
@@ -1174,6 +1175,24 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
spin_unlock_bh(&dcb_lock);
nla_nest_end(skb, app);

+ if (ops->dcbnl_getapptrust) {
+ u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
+ int nselectors;
+
+ apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
+ if (!app)
+ return -EMSGSIZE;
+
+ err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
+ if (err)
+ return -EMSGSIZE;
+
+ for (i = 0; i < nselectors; i++)
+ nla_put_u8(skb, DCB_ATTR_DCB_APP_TRUST, selectors[i]);
+
+ nla_nest_end(skb, apptrust);
+ }
+
/* get peer info if available */
if (ops->ieee_peer_getets) {
struct ieee_ets ets;
@@ -1467,8 +1486,8 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
{
const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
+ int err, i;
int prio;
- int err;

if (!ops)
return -EOPNOTSUPP;
@@ -1554,6 +1573,56 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
}
}

+ if (ieee[DCB_ATTR_DCB_APP_TRUST_TABLE]) {
+ u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
+ struct nlattr *attr;
+ int nselectors = 0;
+ u8 selector;
+ int rem;
+
+ if (!ops->dcbnl_setapptrust) {
+ err = -EOPNOTSUPP;
+ goto err;
+ }
+
+ nla_for_each_nested(attr, ieee[DCB_ATTR_DCB_APP_TRUST_TABLE],
+ rem) {
+ if (nla_type(attr) != DCB_ATTR_DCB_APP_TRUST ||
+ nla_len(attr) != 1 ||
+ nselectors >= sizeof(selectors)) {
+ err = -EINVAL;
+ goto err;
+ }
+
+ selector = nla_get_u8(attr);
+ switch (selector) {
+ case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
+ case IEEE_8021QAZ_APP_SEL_STREAM:
+ case IEEE_8021QAZ_APP_SEL_DGRAM:
+ case IEEE_8021QAZ_APP_SEL_ANY:
+ case IEEE_8021QAZ_APP_SEL_DSCP:
+ case DCB_APP_SEL_PCP:
+ break;
+ default:
+ err = -EINVAL;
+ goto err;
+ }
+ /* Duplicate selector ? */
+ for (i = 0; i < nselectors; i++) {
+ if (selectors[i] == selector) {
+ err = -EINVAL;
+ goto err;
+ }
+ }
+
+ selectors[nselectors++] = selector;
+ }
+
+ err = ops->dcbnl_setapptrust(netdev, selectors, nselectors);
+ if (err)
+ goto err;
+ }
+
err:
err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
--
2.34.1

2022-09-30 13:13:40

by Petr Machata

[permalink] [raw]
Subject: Re: [PATCH net-next v2 2/6] net: dcb: add new apptrust attribute


Daniel Machon <[email protected]> writes:

> Add new apptrust extension attributes to the 8021Qaz APP managed object.
>
> Two new attributes, DCB_ATTR_DCB_APP_TRUST_TABLE and
> DCB_ATTR_DCB_APP_TRUST, has been added. Trusted selectors are passed in
> the nested attribute DCB_ATTR_DCB_APP_TRUST, in order of precedence.
>
> The new attributes are meant to allow drivers, whose hw supports the
> notion of trust, to be able to set whether a particular app selector is
> trusted - and in which order.
>
> Signed-off-by: Daniel Machon <[email protected]>
> ---
> include/net/dcbnl.h | 4 ++
> include/uapi/linux/dcbnl.h | 9 +++++
> net/dcb/dcbnl.c | 77 ++++++++++++++++++++++++++++++++++++--
> 3 files changed, 86 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/dcbnl.h b/include/net/dcbnl.h
> index 2b2d86fb3131..8841ab6c2de7 100644
> --- a/include/net/dcbnl.h
> +++ b/include/net/dcbnl.h
> @@ -109,6 +109,10 @@ struct dcbnl_rtnl_ops {
> /* buffer settings */
> int (*dcbnl_getbuffer)(struct net_device *, struct dcbnl_buffer *);
> int (*dcbnl_setbuffer)(struct net_device *, struct dcbnl_buffer *);
> +
> + /* apptrust */
> + int (*dcbnl_setapptrust)(struct net_device *, u8 *, int);
> + int (*dcbnl_getapptrust)(struct net_device *, u8 *, int *);
> };
>
> #endif /* __NET_DCBNL_H__ */
> diff --git a/include/uapi/linux/dcbnl.h b/include/uapi/linux/dcbnl.h
> index 9f68dc501cc1..f892cd945695 100644
> --- a/include/uapi/linux/dcbnl.h
> +++ b/include/uapi/linux/dcbnl.h
> @@ -410,6 +410,7 @@ enum dcbnl_attrs {
> * @DCB_ATTR_IEEE_PEER_ETS: peer ETS configuration - get only
> * @DCB_ATTR_IEEE_PEER_PFC: peer PFC configuration - get only
> * @DCB_ATTR_IEEE_PEER_APP: peer APP tlv - get only
> + * @DCB_ATTR_DCB_APP_TRUST_TABLE: selector trust order
> */
> enum ieee_attrs {
> DCB_ATTR_IEEE_UNSPEC,
> @@ -423,6 +424,7 @@ enum ieee_attrs {
> DCB_ATTR_IEEE_QCN,
> DCB_ATTR_IEEE_QCN_STATS,
> DCB_ATTR_DCB_BUFFER,
> + DCB_ATTR_DCB_APP_TRUST_TABLE,
> __DCB_ATTR_IEEE_MAX
> };
> #define DCB_ATTR_IEEE_MAX (__DCB_ATTR_IEEE_MAX - 1)
> @@ -435,6 +437,13 @@ enum ieee_attrs_app {
> };
> #define DCB_ATTR_IEEE_APP_MAX (__DCB_ATTR_IEEE_APP_MAX - 1)
>
> +enum dcbnl_attrs_apptrust {
> + DCB_ATTR_DCB_APP_TRUST_UNSPEC,
> + DCB_ATTR_DCB_APP_TRUST,
> + __DCB_ATTR_DCB_APP_TRUST_MAX
> +};
> +#define DCB_ATTR_DCB_APP_TRUST_MAX (__DCB_ATTR_DCB_APP_TRUST_MAX - 1)
> +
> /**
> * enum cee_attrs - CEE DCBX get attributes.
> *
> diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
> index 580d26acfc84..ad84f70e3eb3 100644
> --- a/net/dcb/dcbnl.c
> +++ b/net/dcb/dcbnl.c
> @@ -166,6 +166,7 @@ static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
> [DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)},
> [DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)},
> [DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)},
> + [DCB_ATTR_DCB_APP_TRUST_TABLE] = {.type = NLA_NESTED},
> };
>
> /* DCB number of traffic classes nested attributes. */
> @@ -1070,11 +1071,11 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
> /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
> static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
> {
> - struct nlattr *ieee, *app;
> - struct dcb_app_type *itr;
> const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
> + struct nlattr *ieee, *app, *apptrust;
> + struct dcb_app_type *itr;
> + int err, i;
> int dcbx;
> - int err;
>
> if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
> return -EMSGSIZE;
> @@ -1174,6 +1175,24 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
> spin_unlock_bh(&dcb_lock);
> nla_nest_end(skb, app);
>
> + if (ops->dcbnl_getapptrust) {
> + u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};

BTW, the MAX value is currently 255, which made some sort of sense when
that was the value used for PCP. But we currently only need 24, and
actually like... 6 or whatever? Since the selectors are not supposed to
duplicate, and there are only about that number of them?

Though actually since the new attribute route won't work (as explained
in the other e-mail), it's an open question what the PCP selector value
will be.

> + int nselectors;
> +
> + apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
> + if (!app)
> + return -EMSGSIZE;
> +
> + err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
> + if (err)
> + return -EMSGSIZE;
> +
> + for (i = 0; i < nselectors; i++)
> + nla_put_u8(skb, DCB_ATTR_DCB_APP_TRUST, selectors[i]);
> +
> + nla_nest_end(skb, apptrust);
> + }
> +
> /* get peer info if available */
> if (ops->ieee_peer_getets) {
> struct ieee_ets ets;
> @@ -1467,8 +1486,8 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
> {
> const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
> struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
> + int err, i;
> int prio;
> - int err;
>
> if (!ops)
> return -EOPNOTSUPP;
> @@ -1554,6 +1573,56 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
> }
> }
>
> + if (ieee[DCB_ATTR_DCB_APP_TRUST_TABLE]) {
> + u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
> + struct nlattr *attr;
> + int nselectors = 0;
> + u8 selector;
> + int rem;
> +
> + if (!ops->dcbnl_setapptrust) {
> + err = -EOPNOTSUPP;
> + goto err;
> + }
> +
> + nla_for_each_nested(attr, ieee[DCB_ATTR_DCB_APP_TRUST_TABLE],
> + rem) {
> + if (nla_type(attr) != DCB_ATTR_DCB_APP_TRUST ||
> + nla_len(attr) != 1 ||
> + nselectors >= sizeof(selectors)) {
> + err = -EINVAL;
> + goto err;
> + }
> +
> + selector = nla_get_u8(attr);
> + switch (selector) {
> + case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
> + case IEEE_8021QAZ_APP_SEL_STREAM:
> + case IEEE_8021QAZ_APP_SEL_DGRAM:
> + case IEEE_8021QAZ_APP_SEL_ANY:
> + case IEEE_8021QAZ_APP_SEL_DSCP:
> + case DCB_APP_SEL_PCP:
> + break;
> + default:
> + err = -EINVAL;
> + goto err;
> + }
> + /* Duplicate selector ? */
> + for (i = 0; i < nselectors; i++) {
> + if (selectors[i] == selector) {
> + err = -EINVAL;
> + goto err;
> + }
> + }
> +
> + selectors[nselectors++] = selector;
> + }
> +
> + err = ops->dcbnl_setapptrust(netdev, selectors, nselectors);
> + if (err)
> + goto err;
> + }
> +
> err:
> err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
> dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);