Introduce new DCB rewrite table
Subsystems (3)
Daniel Machon
maintainerv2 cover Introduce new DCB rewrite table
There is currently no support for per-port egress mapping of priority to PCP and priority to DSCP. Some support for expressing egress mapping of PCP is supported through ip link, with the 'egress-qos-map', however this command only maps priority to PCP, and for vlan interfaces only. DCB APP already has support for per-port ingress mapping of PCP/DEI, DSCP and a bunch of other stuff. So why not take advantage of this fact, and add a new table that does the reverse.
This patch series introduces the new DCB rewrite table. Whereas the DCB APP table deals with ingress mapping of PID (protocol identifier) to priority, the rewrite table deals with egress mapping of priority to PID.
It is indeed possible to integrate rewrite in the existing APP table, by introducing new dedicated rewrite selectors, and altering existing functions to treat rewrite entries specially. However, I feel like this is not a good solution, and will pollute the APP namespace. APP is well-defined in IEEE, and some userspace relies of advertised entries - for this fact, separating APP and rewrite into to completely separate objects, seems to me the best solution.
The new table shares much functionality with the APP table, and as such, much existing code is reused, or slightly modified, to work for both.
================================================================================
DCB rewrite table in a nutshell
================================================================================
The table is implemented as a simple linked list, and uses the same lock as the APP table. New functions for getting, setting and deleting entries have been added, and these are exported, so they can be used by the stack or drivers. Additionnaly, new dcbnl_setrewr and dcnl_delrewr hooks has been added, to support hardware offload of the entries.
================================================================================
Sparx5 per-port PCP rewrite support
================================================================================
Sparx5 supports PCP egress mapping through two eight-entry switch tables. One table maps QoS class 0-7 to PCP for DE0 (DP levels mapped to drop-eligibility 0) and the other for DE1. DCB does currently not have support for expressing DP/color, so instead, the tagged DEI bit will reflect the DP levels, for any rewrite entries> 7 ('de').
The driver will take apptrust (contributed earlier) into consideration, so that the mapping tables only be used, if PCP is trusted *and* the rewrite table has active mappings, otherwise classified PCP (same as frame PCP) will be used instead.
================================================================================
Sparx5 per-port DSCP rewrite support
================================================================================
Sparx5 support DSCP egress mapping through a single 32-entry table. This table maps classified QoS class and DP level to classified DSCP, and is consulted by the switch Analyzer Classifier at ingress. At egress, the frame DSCP can either be rewritten to classified DSCP to frame DSCP.
The driver will take apptrust into consideration, so that the mapping tables only be used, if DSCP is trusted *and* the rewrite table has active mappings, otherwise frame DSCP will be used instead.
================================================================================
Patches
================================================================================
Patch #1 modifies dcb_app_add to work for both APP and rewrite
Patch #2 adds dcbnl_app_table_setdel() for setting and deleting both APP and
rewrite entries.
Patch #3 adds the rewrite table and all required functions, offload hooks and
bookkeeping for maintaining it.
Patch #4 adds two new helper functions for getting a priority to PCP bitmask
map, and a priority to DSCP bitmask map.
Patch #5 adds support for PCP rewrite in the Sparx5 driver. Patch #6 adds support for DSCP rewrite in the Sparx5 driver.
================================================================================
v1 -> v2:
In dcb_setrewr() change proto to u16 as it ought to be, and remove zero initialization of err. (Dan Carpenter).
Change name of dcbnl_apprewr_setdel -> dcbnl_app_table_setdel and change the function signature to take a single function pointer. Update uses accordingly (Petr Machata).
Daniel Machon (6):
net: dcb: modify dcb_app_add to take list_head ptr as parameter
net: dcb: add new common function for set/del of app/rewr entries
net: dcb: add new rewrite table
net: dcb: add helper functions to retrieve PCP and DSCP rewrite maps
net: microchip: sparx5: add support for PCP rewrite
net: microchip: sparx5: add support for DSCP rewrite
.../ethernet/microchip/sparx5/sparx5_dcb.c | 121 +++++++- .../microchip/sparx5/sparx5_main_regs.h | 70 ++++- .../ethernet/microchip/sparx5/sparx5_port.c | 97 +++++++ .../ethernet/microchip/sparx5/sparx5_port.h | 41 +++ include/net/dcbnl.h | 18 ++ include/uapi/linux/dcbnl.h | 2 + net/dcb/dcbnl.c | 271 ++++++++++++++---- 7 files changed, 547 insertions(+), 73 deletions(-)
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Daniel Machon
maintainerPATCH v2 1/6 net: dcb: modify dcb_app_add to take list_head ptr as parameter
In preparation to DCB rewrite. Modify dcb_app_add to take new struct list_head * as parameter, to make the used list configurable. This is done to allow reusing the function for adding rewrite entries to the rewrite table, which is introduced in a later patch.
--- net/dcb/dcbnl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/dcb/dcbnl.c +5 -4
@@ -1955,7 +1955,8 @@ static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app,return NULL ; } -static int dcb_app_add (const struct dcb_app *app,int ifindex) +static int dcb_app_add (struct list_head *list,const struct dcb_app *app, +int ifindex) {struct dcb_app_type *entry;
@@ -1965,7 +1966,7 @@ static int dcb_app_add(const struct dcb_app *app, int ifindex)memcpy (&entry->app, app,sizeof (*app)); entry->ifindex = ifindex; -list_add (&entry->list, &dcb_app_list); +list_add (&entry->list, list);return 0 ; }
@@ -2028,7 +2029,7 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new) }/* App type does not exist add new application type */ if (new->priority) - err =dcb_app_add (new, dev->ifindex); + err =dcb_app_add (&dcb_app_list, new, dev->ifindex); out:spin_unlock_bh (&dcb_lock);if (!err)
@@ -2088,7 +2089,7 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) goto out; } - err =dcb_app_add (new, dev->ifindex); + err =dcb_app_add (&dcb_app_list, new, dev->ifindex); out:spin_unlock_bh (&dcb_lock);if (!err)
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 1/6] net: dcb: modify dcb_app_add to take list_head ptr as parameter
Quoted 6 lines · Daniel Machon
In preparation to DCB rewrite. Modify
dcb_app_addto take new structlist_head* as parameter, to make the used list configurable. This is done to allow reusing the function for adding rewrite entries to the rewrite table, which is introduced in a later patch.Signed-off-by Daniel Machon <[email protected]>
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Daniel Machon
maintainerPATCH v2 2/6 net: dcb: add new common function for set/del of app/rewr entries
In reply to Daniel MachonIn preparation for DCB rewrite. Add a new function for setting and deleting both app and rewrite entries. Moving this into a separate function reduces duplicate code, as both type of entries requires the same set of checks. The function will now iterate through a configurable nested attribute (app or rewrite attr), validate each attribute and call the appropriate set- or delete function.
Note that this function always checks for nla_len(attr_itr) < sizeof(struct dcb_app), which was only done in dcbnl_ieee_set and not in dcbnl_ieee_del prior to this patch. This means, that any userspace tool that used to shove in data < sizeof(struct dcb_app) would now receive -ERANGE.
--- net/dcb/dcbnl.c | 100 ++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 55 deletions(-)
net/dcb/dcbnl.c +45 -55
@@ -1099,6 +1099,41 @@ static int dcbnl_getapptrust(struct net_device *netdev, struct sk_buff *skb)return err; } +/* Set or delete APP table or rewrite table entries. The APP struct is validated +* and the appropriate callback function is called. +*/ +static int dcbnl_app_table_setdel (struct nlattr *attr, +struct net_device *netdev, +int (*setdel)(struct net_device *dev, +struct dcb_app *app)) +{ +struct dcb_app *app_data; +enum ieee_attrs_app type; +struct nlattr *attr_itr; +int rem, err; + +nla_for_each_nested (attr_itr, attr, rem) { + type =nla_type (attr_itr); + +if (!dcbnl_app_attr_type_validate (type)) +continue ; + +if (nla_len (attr_itr) <sizeof (struct dcb_app )) +return -ERANGE ; + + app_data =nla_data (attr_itr); + +if (!dcbnl_app_selector_validate (type, app_data->selector)) +return -EINVAL ; + + err =setdel (netdev, app_data); +if (err) +return err; + } + +return 0 ; +} +/* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */ static int dcbnl_ieee_fill (struct sk_buff *skb,struct net_device *netdev) {
@@ -1568,36 +1603,11 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, }if (ieee[DCB_ATTR_IEEE_APP_TABLE ]) { -struct nlattr *attr; -int rem; - -nla_for_each_nested (attr, ieee[DCB_ATTR_IEEE_APP_TABLE ], rem) { -enum ieee_attrs_app type =nla_type (attr); -struct dcb_app *app_data; - -if (!dcbnl_app_attr_type_validate (type)) -continue ; - -if (nla_len (attr) <sizeof (struct dcb_app )) { - err = -ERANGE ; - goto err; - } - - app_data =nla_data (attr); - -if (!dcbnl_app_selector_validate (type, - app_data->selector)) { - err = -EINVAL ; - goto err; - } - -if (ops->ieee_setapp) - err = ops->ieee_setapp (netdev, app_data); -else - err =dcb_ieee_setapp (netdev, app_data); -if (err) - goto err; - } + err =dcbnl_app_table_setdel (ieee[DCB_ATTR_IEEE_APP_TABLE ], + netdev, ops->ieee_setapp ?: + dcb_ieee_setapp); +if (err) + goto err; }if (ieee[DCB_ATTR_DCB_APP_TRUST_TABLE ]) {
@@ -1684,31 +1694,11 @@ static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh,return err;if (ieee[DCB_ATTR_IEEE_APP_TABLE ]) { -struct nlattr *attr; -int rem; - -nla_for_each_nested (attr, ieee[DCB_ATTR_IEEE_APP_TABLE ], rem) { -enum ieee_attrs_app type =nla_type (attr); -struct dcb_app *app_data; - -if (!dcbnl_app_attr_type_validate (type)) -continue ; - - app_data =nla_data (attr); - -if (!dcbnl_app_selector_validate (type, - app_data->selector)) { - err = -EINVAL ; - goto err; - } - -if (ops->ieee_delapp) - err = ops->ieee_delapp (netdev, app_data); -else - err =dcb_ieee_delapp (netdev, app_data); -if (err) - goto err; - } + err =dcbnl_app_table_setdel (ieee[DCB_ATTR_IEEE_APP_TABLE ], + netdev, ops->ieee_delapp ?: + dcb_ieee_delapp); +if (err) + goto err; } err:
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 2/6] net: dcb: add new common function for set/del of app/rewr entries
Quoted 7 lines · Daniel Machon
In preparation for DCB rewrite. Add a new function for setting and deleting both app and rewrite entries. Moving this into a separate function reduces duplicate code, as both type of entries requires the same set of checks. The function will now iterate through a configurable nested attribute (app or rewrite attr), validate each attribute and call the appropriate set- or delete function.
Quoted 7 lines
Note that this function always checks for
nla_len(attr_itr)<sizeof(struct dcb_app), which was only done indcbnl_ieee_setand not indcbnl_ieee_delprior to this patch. This means, that any userspace tool that used to shove in data <sizeof(struct dcb_app)would now receive-ERANGE.Signed-off-by Daniel Machon <[email protected]>
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 2/6] net: dcb: add new common function for set/del of app/rewr entries
Quoted 15 lines · Petr Machata
Quoted 13 lines · Daniel Machon
In preparation for DCB rewrite. Add a new function for setting and deleting both app and rewrite entries. Moving this into a separate function reduces duplicate code, as both type of entries requires the same set of checks. The function will now iterate through a configurable nested attribute (app or rewrite attr), validate each attribute and call the appropriate set- or delete function.
Note that this function always checks for
nla_len(attr_itr)<sizeof(struct dcb_app), which was only done indcbnl_ieee_setand not indcbnl_ieee_delprior to this patch. This means, that any userspace tool that used to shove in data <sizeof(struct dcb_app)would now receive-ERANGE.
Quoted 3 lines
Quoted 1 line
Signed-off-by Daniel Machon <[email protected]>Reviewed-by Petr Machata <[email protected]>
... though, now that I found some issues in 3/6, if you would somehow reformat the ?: expression that's now awkwardly split to two unaligned lines, that would placate my OCD:
+ err = dcbnl_app_table_setdel(ieee[DCB_ATTR_IEEE_APP_TABLE],
+ netdev, ops->ieee_setapp ?:
+ dcb_ieee_setapp);
(and the one other).
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
[email protected]
maintainerRe: [PATCH net-next v2 2/6] net: dcb: add new common function for set/del of app/rewr entries
Quoted 25 lines
Quoted 15 lines · Petr Machata
Quoted 13 lines · Daniel Machon
In preparation for DCB rewrite. Add a new function for setting and deleting both app and rewrite entries. Moving this into a separate function reduces duplicate code, as both type of entries requires the same set of checks. The function will now iterate through a configurable nested attribute (app or rewrite attr), validate each attribute and call the appropriate set- or delete function.
Note that this function always checks for
nla_len(attr_itr)<sizeof(struct dcb_app), which was only done indcbnl_ieee_setand not indcbnl_ieee_delprior to this patch. This means, that any userspace tool that used to shove in data <sizeof(struct dcb_app)would now receive-ERANGE.Quoted 3 lines
Quoted 1 line
Signed-off-by Daniel Machon <[email protected]>Reviewed-by Petr Machata <[email protected]>... though, now that I found some issues in 3/6, if you would somehow reformat the ?: expression that's now awkwardly split to two unaligned lines, that would placate my OCD:
net/dcb/dcbnl.c static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, · line 1608
Quoted 3 lines
net/dcb/dcbnl.c +3
-0+ err =dcbnl_app_table_setdel (ieee[DCB_ATTR_IEEE_APP_TABLE ], + netdev, ops->ieee_setapp ?: + dcb_ieee_setapp);
Putting the expression on the same line will violate the 80 char limit. Does splitting it like that hurt anything - other than your OCD :-P At least checkpatch didn't complain.
/Daniel
Quoted 2 lines
(and the one other).
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 2/6] net: dcb: add new common function for set/del of app/rewr entries
Quoted 25 lines · <[email protected]> writes:
Quoted 25 lines
Quoted 15 lines · Petr Machata
Quoted 13 lines · Daniel Machon
In preparation for DCB rewrite. Add a new function for setting and deleting both app and rewrite entries. Moving this into a separate function reduces duplicate code, as both type of entries requires the same set of checks. The function will now iterate through a configurable nested attribute (app or rewrite attr), validate each attribute and call the appropriate set- or delete function.
Note that this function always checks for
nla_len(attr_itr)<sizeof(struct dcb_app), which was only done indcbnl_ieee_setand not indcbnl_ieee_delprior to this patch. This means, that any userspace tool that used to shove in data <sizeof(struct dcb_app)would now receive-ERANGE.Quoted 3 lines
Quoted 1 line
Signed-off-by Daniel Machon <[email protected]>Reviewed-by Petr Machata <[email protected]>... though, now that I found some issues in 3/6, if you would somehow reformat the ?: expression that's now awkwardly split to two unaligned lines, that would placate my OCD:
Quoted 7 lines
net/dcb/dcbnl.c static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, · line 1608
Quoted 3 lines
net/dcb/dcbnl.c +3
-0+ err =dcbnl_app_table_setdel (ieee[DCB_ATTR_IEEE_APP_TABLE ], + netdev, ops->ieee_setapp ?: + dcb_ieee_setapp);Putting the expression on the same line will violate the 80 char limit. Does splitting it like that hurt anything - other than your OCD :-P At least checkpatch didn't complain.
Yeah, don't worry about it.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Daniel Machon
maintainerPATCH v2 3/6 net: dcb: add new rewrite table
In reply to Daniel MachonAdd new rewrite table and all the required functions, offload hooks and bookkeeping for maintaining it. The rewrite table reuses the app struct, and the entire set of app selectors. As such, some bookeeping code can be shared between the rewrite- and the APP table.
New functions for getting, setting and deleting entries has been added. Apart from operating on the rewrite list, these functions do not emit a DCB_APP_EVENT when the list os modified. The new dcb_getrewr does a lookup based on selector and priority and returns the protocol, so that mappings from priority to protocol, for a given selector and ifindex is obtained.
Also, a new nested attribute has been added, that encapsulates one or more app structs. This attribute is used to distinguish the two tables.
The dcb_lock used for the APP table is reused for the rewrite table.
--- include/net/dcbnl.h | 8 +++ include/uapi/linux/dcbnl.h | 2 + net/dcb/dcbnl.c | 112 ++++++++++++++++++++++++++++++++++++- 3 files changed, 121 insertions(+), 1 deletion(-)
include/net/dcbnl.h +8 -0
@@ -19,6 +19,10 @@ struct dcb_app_type {u8 dcbx; }; +u16 dcb_getrewr (struct net_device *dev,struct dcb_app *app); +int dcb_setrewr (struct net_device *dev,struct dcb_app *app); +int dcb_delrewr (struct net_device *dev,struct dcb_app *app); +int dcb_setapp (struct net_device *,struct dcb_app *);u8 dcb_getapp (struct net_device *,struct dcb_app *);int dcb_ieee_setapp (struct net_device *,struct dcb_app *);
@@ -113,6 +117,10 @@ struct dcbnl_rtnl_ops {/* apptrust */ int (*dcbnl_setapptrust)(struct net_device *,u8 *,int );int (*dcbnl_getapptrust)(struct net_device *,u8 *,int *); + +/* rewrite */ +int (*dcbnl_setrewr)(struct net_device *dev,struct dcb_app *app); + int (*dcbnl_delrewr)(struct net_device *dev, struct dcb_app *app); };#endif /* __NET_DCBNL_H__ */
include/uapi/linux/dcbnl.h +2 -0
@@ -411,6 +411,7 @@ enum dcbnl_attrs {* @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 table +* @DCB_ATTR_DCB_REWR_TABLE: rewrite configuration */ enum ieee_attrs {DCB_ATTR_IEEE_UNSPEC ,
@@ -425,6 +426,7 @@ enum ieee_attrs {DCB_ATTR_IEEE_QCN_STATS ,DCB_ATTR_DCB_BUFFER ,DCB_ATTR_DCB_APP_TRUST_TABLE , +DCB_ATTR_DCB_REWR_TABLE , __DCB_ATTR_IEEE_MAX };#define DCB_ATTR_IEEE_MAX (__DCB_ATTR_IEEE_MAX - 1)
net/dcb/dcbnl.c +111 -1
154 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
Quoted 22 lines · Daniel Machon
net/dcb/dcbnl.c +2
-1@@ -178,6 +178,7 @@ static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = { };static LIST_HEAD (dcb_app_list); +static LIST_HEAD (dcb_rewr_list);static DEFINE_SPINLOCK (dcb_lock);static enum ieee_attrs_app dcbnl_app_attr_type_get (u8 selector)@@ -1138,7 +1139,7 @@ static int dcbnl_app_table_setdel(struct nlattr *attr,static int dcbnl_ieee_fill (struct sk_buff *skb,struct net_device *netdev) {const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; -struct nlattr *ieee, *app; +struct nlattr *ieee, *app, *rewr;struct dcb_app_type *itr;int dcbx;int err;
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1247
Quoted 6 lines
net/dcb/dcbnl.c +3
-0@@ -1241,6 +1242,26 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)spin_unlock_bh (&dcb_lock);nla_nest_end (skb, app); + rewr =nla_nest_start_noflag (skb,DCB_ATTR_DCB_REWR_TABLE ); +if (!rewr) +return -EMSGSIZE ;
This being new code, don't use _noflag please.
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1256
Quoted 9 lines
net/dcb/dcbnl.c +9
-0+ +spin_lock_bh (&dcb_lock); +list_for_each_entry (itr, &dcb_rewr_list, list) { +if (itr->ifindex == netdev->ifindex) { +enum ieee_attrs_app type = +dcbnl_app_attr_type_get (itr->app.selector); + err =nla_put (skb, type,sizeof (itr->app), &itr->app); +if (err) { +spin_unlock_bh (&dcb_lock);
This should cancel the nest started above.
I wonder if it would be cleaner in a separate function, so that there can be a dedicated clean-up block to goto.
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1267
Quoted 11 lines
net/dcb/dcbnl.c +8
-0+return -EMSGSIZE ; + } + } + } + +spin_unlock_bh (&dcb_lock); +nla_nest_end (skb, rewr); +if (ops->dcbnl_getapptrust) { err =dcbnl_getapptrust (netdev, skb);if (err)
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
[email protected]
maintainerRe: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
Quoted 5 lines
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1247
Quoted 3 lines
net/dcb/dcbnl.c +3
-0+ rewr =nla_nest_start_noflag (skb,DCB_ATTR_DCB_REWR_TABLE ); +if (!rewr) +return -EMSGSIZE ;This being new code, don't use
_noflagplease.
Ack.
Quoted 11 lines
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1256
Quoted 10 lines
net/dcb/dcbnl.c +9
-0+ +spin_lock_bh (&dcb_lock); +list_for_each_entry (itr, &dcb_rewr_list, list) { +if (itr->ifindex == netdev->ifindex) { +enum ieee_attrs_app type = +dcbnl_app_attr_type_get (itr->app.selector); + err =nla_put (skb, type,sizeof (itr->app), &itr->app); +if (err) { +spin_unlock_bh (&dcb_lock);
Quoted 1 line
This should cancel the nest started above.
Yes, it should.
Quoted 3 lines
I wonder if it would be cleaner in a separate function, so that there can be a dedicated clean-up block to goto.
Well yes. That would make sense if the function were reused for both APP and rewr.
Though in the APP equivalent code, nla_nest_start_noflag is used, and dcbnl_ops->getdcbx() is called. Is there any userspace side-effect of using nla_nest_start for APP too?
dcbnl_ops->getdcbx() would then be left outside of the shared function. Does that call even have to hold the dcb_lock? Not as far as I can tell.
something like:
err = dcbnl_app_table_get(ndev, skb, &dcb_app_list,
DCB_ATTR_IEEE_APP_TABLE); if (err) return -EMSGSIZE;
err = dcbnl_app_table_get(ndev, skb, &dcb_rewr_list,
DCB_ATTR_DCB_REWR_TABLE);
if (err)
return -EMSGSIZE;if (netdev->dcbnl_ops->getdcbx)
dcbx = netdev->dcbnl_ops->getdcbx(netdev); <-- without lock held else dcbx = -EOPNOTSUPP;
Let me hear your thoughts.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
Quoted 21 lines · <[email protected]> writes:
Quoted 5 lines
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1247
Quoted 3 lines
net/dcb/dcbnl.c +3
-0+ rewr =nla_nest_start_noflag (skb,DCB_ATTR_DCB_REWR_TABLE ); +if (!rewr) +return -EMSGSIZE ;This being new code, don't use
_noflagplease.Ack.
Quoted 11 lines
net/dcb/dcbnl.c static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1256
Quoted 10 lines
net/dcb/dcbnl.c +9
-0+ +spin_lock_bh (&dcb_lock); +list_for_each_entry (itr, &dcb_rewr_list, list) { +if (itr->ifindex == netdev->ifindex) { +enum ieee_attrs_app type = +dcbnl_app_attr_type_get (itr->app.selector); + err =nla_put (skb, type,sizeof (itr->app), &itr->app); +if (err) { +spin_unlock_bh (&dcb_lock);Quoted 1 line
This should cancel the nest started above.
Quoted 8 lines
Yes, it should.
Quoted 3 lines
I wonder if it would be cleaner in a separate function, so that there can be a dedicated clean-up block to goto.
Well yes. That would make sense if the function were reused for both APP and rewr.
I meant purely for to make the cleanup clear. The function would be approximately:
static int dcbnl_ieee_fill_rewr(struct sk_buff *skb, struct net_device *netdev)
{
struct dcb_app_type *itr;
struct nlattr *rewr;
int err;
rewr = nla_nest_start_noflag(skb, DCB_ATTR_DCB_REWR_TABLE);
if (!rewr)
return -EMSGSIZE;
spin_lock_bh(&dcb_lock);
list_for_each_entry(itr, &dcb_rewr_list, list) {
if (itr->ifindex == netdev->ifindex) {
enum ieee_attrs_app type =
dcbnl_app_attr_type_get(itr->app.selector);
err = nla_put(skb, type, sizeof(itr->app), &itr->app);
if (err)
goto err_out;
}
}
spin_unlock_bh(&dcb_lock);
nla_nest_end(skb, rewr);
return 0;err_out:
spin_unlock_bh(&dcb_lock); nla_nest_cancel(skb, rewr); return err; }
Which uses an idiomatic style with the cleanup block at the end, instead of stashing the individual cleanups before the return statement. I find it easier to reason about.
But it's not a big deal. Your thing is readable just fine.
Quoted 3 lines
Though in the APP equivalent code,
nla_nest_start_noflagis used, anddcbnl_ops->getdcbx()is called. Is there any userspace side-effect of usingnla_nest_startfor APP too?
Yeah, the clients would be looking for code DCB_ATTR_IEEE_APP_TABLE, but would get DCB_ATTR_IEEE_APP_TABLE | NLA_F_NESTED, and get confused.
For reuse between APP_TABLE and REWR_TABLE, you could just always call _noflag in the helper, and pass the actual attribute in an argument. Then the argument would be either DCB_ATTR_DCB_REWR_TABLE | NLA_F_NESTED, or just plain DCB_ATTR_IEEE_APP_TABLE.
But that makes the code less clear, and I don't feel it brings much.
Quoted 15 lines
dcbnl_ops->getdcbx()would then be left outside of the shared function. Does that call even have to hold thedcb_lock? Not as far as I can tell.something like:
err = dcbnl_app_table_get(ndev, skb,
&dcb_app_list,DCB_ATTR_IEEE_APP_TABLE); if (err) return -EMSGSIZE;err = dcbnl_app_table_get(ndev, skb,
&dcb_rewr_list,DCB_ATTR_DCB_REWR_TABLE); if (err) return -EMSGSIZE;
Quoted 6 lines
if (
netdev->dcbnl_ops->getdcbx)dcbx = netdev->dcbnl_ops->getdcbx(netdev); <-- without lock held else dcbx = -EOPNOTSUPP;Let me hear your thoughts.
Yeah, and the dcbx stuff is the added wrinkle.
Dunno, I'd not force it. This redundancy is not great, but the code is small and easy to understand, so I find it's not an issue.
Re: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
In reply to Petr MachataQuoted 25 lines · Petr Machata
Review static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1247
Quoted 7 lines
(quoted diff) +3
-0@@ -1241,6 +1242,26 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) spin_unlock_bh(&dcb_lock); nla_nest_end(skb, app); + rewr = nla_nest_start_noflag(skb, DCB_ATTR_DCB_REWR_TABLE); + if (!rewr) + return -EMSGSIZE;This being new code, don't use
_noflagplease.Review static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1256
Quoted 9 lines
(quoted diff) +9
-0+ + spin_lock_bh(&dcb_lock); + list_for_each_entry(itr, &dcb_rewr_list, list) { + if (itr->ifindex == netdev->ifindex) { + enum ieee_attrs_app type = + dcbnl_app_attr_type_get(itr->app.selector); + err = nla_put(skb, type, sizeof(itr->app), &itr->app); + if (err) { + spin_unlock_bh(&dcb_lock);This should cancel the nest started above.
I wonder if it would be cleaner in a separate function, so that there can be a dedicated clean-up block to goto.
Quoted 7 lines
Review static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) · line 1263
Quoted 7 lines
(quoted diff) +7
-0+ return -EMSGSIZE; + } + } + } + + spin_unlock_bh(&dcb_lock); + nla_nest_end(skb, rewr);
If you see a bug like this, you may as well ask Julia or me to add a static checker warning for it. We're both already on the CC list but we might not be following the conversation closely...
In Smatch, I thought it would be easy but it turned out I need to add a hack around to change the second nla_nest_start_noflag() from unknown to valid pointer.
check_unwind.c +5 -0
@@ -94,6 +94,11 @@ static struct ref_func_info func_table[] = { { "ieee80211_alloc_hw", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, { "ieee80211_free_hw", RELEASE, 0, "$" }, + + { "nla_nest_start_noflag", ALLOC, 0, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, + { "nla_nest_start", ALLOC, 0, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, + { "nla_nest_end", RELEASE, 0, "$" }, + { "nla_nest_cancel", RELEASE, 0, "$" }, };static struct smatch_state *unmatched_state (struct sm_state *sm)
smatch_data/db/kernel.return_fixes +1 -0
@@ -90,3 +90,4 @@ dma_resv_wait_timeout s64min-(-1),1-s64max 1-s64max[<=$3] mmc_io_rw_direct_host s32min-(-1),1-s32max (-4095)-(-1) ad3552r_transfer s32min-(-1),1-s32max (-4095)-(-1) adin1110_read_reg s32min-(-1),1-s32max (-4095)-(-1) +nla_nest_start_noflag 0-u64max 4096-ptr_max
Unfortunately, there is something weird going on and only my unreleased version of Smatch finds the bug:
net/dcb/dcbnl.c:1306 dcbnl_ieee_fill() warn: 'skb' from nla_nest_start_noflag() not released on lines: 1160,1171,1184,1197,1207,1217,1222,1232,1257. net/dcb/dcbnl.c:1502 dcbnl_cee_fill() warn: 'skb' from nla_nest_start_noflag() not released on lines: 1502.
I have been working on that check recently... Both the released and unreleased versions of Smatch have the following complaints:
net/dcb/dcbnl.c:400 dcbnl_getnumtcs() warn: 'skb' from nla_nest_start_noflag() not released on lines: 396. net/dcb/dcbnl.c:1061 dcbnl_build_peer_app() warn: 'skb' from nla_nest_start_noflag() not released on lines: 1061. net/dcb/dcbnl.c:1359 dcbnl_cee_pg_fill() warn: 'skb' from nla_nest_start_noflag() not released on lines: 1324,1342.
regards,
dan carpenter
Re: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
Quoted 3 lines · Dan Carpenter
In Smatch, I thought it would be easy but it turned out I need to add a hack around to change the second
nla_nest_start_noflag()from unknown to valid pointer.
The second nla_nest_start_noflag() *return*, I meant.
Quoted 1 line
+nla_nest_start_noflag 0-u64max 4096-ptr_max
regards,
dan carpenter
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 3/6] net: dcb: add new rewrite table
In reply to Dan CarpenterQuoted 14 lines · Dan Carpenter
Quoted 12 lines · Petr Machata
Review
Quoted 9 lines
(quoted diff) +9
-0+ + spin_lock_bh(&dcb_lock); + list_for_each_entry(itr, &dcb_rewr_list, list) { + if (itr->ifindex == netdev->ifindex) { + enum ieee_attrs_app type = + dcbnl_app_attr_type_get(itr->app.selector); + err = nla_put(skb, type, sizeof(itr->app), &itr->app); + if (err) { + spin_unlock_bh(&dcb_lock);This should cancel the nest started above.
Quoted 3 lines
If you see a bug like this, you may as well ask Julia or me to add a static checker warning for it. We're both already on the CC list but we might not be following the conversation closely...
I'll try to remember next time.
Quoted 30 lines
In Smatch, I thought it would be easy but it turned out I need to add a hack around to change the second
nla_nest_start_noflag()from unknown to valid pointer.check_unwind.c +5
-0@@ -94,6 +94,11 @@ static struct ref_func_info func_table[] = { { "ieee80211_alloc_hw", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, { "ieee80211_free_hw", RELEASE, 0, "$" }, + + { "nla_nest_start_noflag", ALLOC, 0, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, + { "nla_nest_start", ALLOC, 0, "$", &valid_ptr_min_sval, &valid_ptr_max_sval }, + { "nla_nest_end", RELEASE, 0, "$" }, + { "nla_nest_cancel", RELEASE, 0, "$" }, };static struct smatch_state *unmatched_state (struct sm_state *sm)smatch_data/db/kernel.return_fixes +1
-0@@ -90,3 +90,4 @@ dma_resv_wait_timeout s64min-(-1),1-s64max 1-s64max[<=$3] mmc_io_rw_direct_host s32min-(-1),1-s32max (-4095)-(-1) ad3552r_transfer s32min-(-1),1-s32max (-4095)-(-1) adin1110_read_reg s32min-(-1),1-s32max (-4095)-(-1) +nla_nest_start_noflag 0-u64max 4096-ptr_max
Quoted 5 lines
Unfortunately, there is something weird going on and only my unreleased version of Smatch finds the bug:
net/dcb/dcbnl.c:1306dcbnl_ieee_fill()warn: 'skb' fromnla_nest_start_noflag()not released on lines: 1160,1171,1184,1197,1207,1217,1222,1232,1257.net/dcb/dcbnl.c:1502dcbnl_cee_fill()warn: 'skb' fromnla_nest_start_noflag()not released on lines: 1502.
Looking at a couple of those, yeah, it looks legit. Those are missing the cancel on error returns.
Quoted 6 lines
I have been working on that check recently... Both the released and unreleased versions of Smatch have the following complaints:
net/dcb/dcbnl.c:400dcbnl_getnumtcs()warn: 'skb' fromnla_nest_start_noflag()not released on lines: 396.net/dcb/dcbnl.c:1061dcbnl_build_peer_app()warn: 'skb' fromnla_nest_start_noflag()not released on lines: 1061.net/dcb/dcbnl.c:1359dcbnl_cee_pg_fill()warn: 'skb' fromnla_nest_start_noflag()not released on lines: 1324,1342.
Likewise. Strange that each version reports a different subset. Or is that just selective quoting?
Daniel Machon
maintainerPATCH v2 4/6 net: dcb: add helper functions to retrieve PCP and DSCP rewrite maps
In reply to Daniel MachonAdd two new helper functions to retrieve a mapping of priority to PCP and DSCP bitmasks, where each bitmap contains ones in positions that match a rewrite entry.
dcb_ieee_getrewr_prio_dscp_mask_map() reuses the dcb_ieee_app_prio_map, as this struct is already used for a similar mapping in the app table.
--- include/net/dcbnl.h | 10 +++++++++ net/dcb/dcbnl.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
include/net/dcbnl.h +10 -0
@@ -29,12 +29,22 @@ int dcb_ieee_setapp(struct net_device *, struct dcb_app *);int dcb_ieee_delapp (struct net_device *,struct dcb_app *);u8 dcb_ieee_getapp_mask (struct net_device *,struct dcb_app *); +struct dcb_rewr_prio_pcp_map { +u16 map[IEEE_8021QAZ_MAX_TCS ]; +}; + +void dcb_getrewr_prio_pcp_mask_map (const struct net_device *dev, +struct dcb_rewr_prio_pcp_map *p_map); +struct dcb_ieee_app_prio_map {u64 map[IEEE_8021QAZ_MAX_TCS ]; };void dcb_ieee_getapp_prio_dscp_mask_map (const struct net_device *dev,struct dcb_ieee_app_prio_map *p_map); +void dcb_getrewr_prio_dscp_mask_map (const struct net_device *dev, +struct dcb_ieee_app_prio_map *p_map); +struct dcb_ieee_app_dscp_map {u8 map[64 ]; };
net/dcb/dcbnl.c +52 -0
58 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH net-next v2 4/6] net: dcb: add helper functions to retrieve PCP and DSCP rewrite maps
Quoted 8 lines · Daniel Machon
Add two new helper functions to retrieve a mapping of priority to PCP and DSCP bitmasks, where each bitmap contains ones in positions that match a rewrite entry.
dcb_ieee_getrewr_prio_dscp_mask_map()reuses thedcb_ieee_app_prio_map, as this struct is already used for a similar mapping in the app table.Signed-off-by Daniel Machon <[email protected]>
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Daniel Machon
maintainerPATCH v2 5/6 net: microchip: sparx5: add support for PCP rewrite
In reply to Daniel MachonAdd support for rewrite of PCP and DEI, based on classified Quality of Service (QoS) class and Drop-Precedence (DP) level.
The DCB rewrite table is queried for mappings between priority and PCP/DEI. The classified DP level is then encoded in the DEI bit, if a mapping for DEI exists.
Sparx5 has four DP levels, where by default, 0 is mapped to DE0 and 1-3 are mapped to DE1. If a mapping exists where DEI=1, then all classified DP levels mapped to DE1 will set the DEI bit. The other way around for DEI=0. Effectively, this means that the tagged DEI bit will reflect the DP level for any mappings where DEI=1.
Map priority=1 to PCP=1 and DEI=1:
$ dcb rewr add dev eth0 pcp-prio 1:1de
Map priority=7 to PCP=2 and DEI=0
$ dcb rewr add dev eth0 pcp-prio 7:2nd
Also, sparx5_dcb_ieee_dscp_setdel() has been refactored, to work for both APP and rewrite entries.
--- .../ethernet/microchip/sparx5/sparx5_dcb.c | 86 ++++++++++++++++--- .../microchip/sparx5/sparx5_main_regs.h | 44 +++++++++- .../ethernet/microchip/sparx5/sparx5_port.c | 57 ++++++++++++ .../ethernet/microchip/sparx5/sparx5_port.h | 18 ++++ 4 files changed, 191 insertions(+), 14 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c +74 -12
@@ -133,12 +133,14 @@ static bool sparx5_dcb_apptrust_contains(int portno, u8 selector)static int sparx5_dcb_app_update (struct net_device *dev) { +struct dcb_rewr_prio_pcp_map pcp_rewr_map = {0 };struct sparx5_port *port =netdev_priv (dev);struct sparx5_port_qos_dscp_map *dscp_map;struct sparx5_port_qos_pcp_map *pcp_map;struct sparx5_port_qos qos = {0 };struct dcb_app app_itr = {0 };int portno = port->portno; +bool pcp_rewr = false;int i; dscp_map = &qos.dscp.map;
@@ -163,10 +165,24 @@ static int sparx5_dcb_app_update(struct net_device *dev) pcp_map->map[i] =dcb_getapp (dev, &app_itr); } +/* Get pcp rewrite mapping */ +dcb_getrewr_prio_pcp_mask_map (dev, &pcp_rewr_map); +for (i =0 ; i <ARRAY_SIZE (pcp_rewr_map.map); i++) { +if (!pcp_rewr_map.map[i]) +continue ; + pcp_rewr = true; + qos.pcp_rewr.map.map[i] =fls (pcp_rewr_map.map[i]) -1 ; + } +/* 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; +/* Enable rewrite of PCP and DEI if PCP is trusted *and* rewrite +* table is not empty. +*/ +if (pcp_rewr) + qos.pcp_rewr.enable = true; }/* Enable use of dscp for queue classification ? */
@@ -178,16 +194,17 @@ static int sparx5_dcb_app_update(struct net_device *dev)return sparx5_port_qos_set (port, &qos); } -/* Set or delete dscp app entry. +/* Set or delete DSCP app entry. * -* Dscp mapping is global for all ports, so set and delete app entries are +* DSCP mapping is global for all ports, so set and delete app entries are * replicated for each port. */ -static int sparx5_dcb_ieee_dscp_setdel_app (struct net_device *dev, -struct dcb_app *app,bool del) +static int sparx5_dcb_ieee_dscp_setdel (struct net_device *dev, +struct dcb_app *app, +int (*setdel)(struct net_device *, +struct dcb_app *)) {struct sparx5_port *port =netdev_priv (dev); -struct dcb_app apps[SPX5_PORTS ];struct sparx5_port *port_itr;int err, i;
@@ -195,11 +212,7 @@ static int sparx5_dcb_ieee_dscp_setdel_app(struct net_device *dev, port_itr = port->sparx5->ports[i];if (!port_itr)continue ; -memcpy (&apps[i], app,sizeof (struct dcb_app )); -if (del) - err =dcb_ieee_delapp (port_itr->ndev, &apps[i]); -else - err =dcb_ieee_setapp (port_itr->ndev, &apps[i]); + err =setdel (port_itr->ndev, app);if (err)return err; }
@@ -226,7 +239,7 @@ static int sparx5_dcb_ieee_setapp(struct net_device *dev, struct dcb_app *app) }if (app->selector ==IEEE_8021QAZ_APP_SEL_DSCP ) - err =sparx5_dcb_ieee_dscp_setdel_app (dev, app, false); + err =sparx5_dcb_ieee_dscp_setdel (dev, app, dcb_ieee_setapp);else err =dcb_ieee_setapp (dev, app);
@@ -244,7 +257,7 @@ static int sparx5_dcb_ieee_delapp(struct net_device *dev, struct dcb_app *app)int err;if (app->selector ==IEEE_8021QAZ_APP_SEL_DSCP ) - err =sparx5_dcb_ieee_dscp_setdel_app (dev, app, true); + err =sparx5_dcb_ieee_dscp_setdel (dev, app, dcb_ieee_delapp);else err =dcb_ieee_delapp (dev, app);
@@ -283,11 +296,60 @@ static int sparx5_dcb_getapptrust(struct net_device *dev, u8 *selectors,return 0 ; } +static int sparx5_dcb_delrewr (struct net_device *dev,struct dcb_app *app) +{ +int err; + +if (app->selector ==IEEE_8021QAZ_APP_SEL_DSCP ) + err =sparx5_dcb_ieee_dscp_setdel (dev, app, dcb_delrewr); +else + err =dcb_delrewr (dev, app); + +if (err <0 ) +return err; + +return sparx5_dcb_app_update (dev); +} + +static int sparx5_dcb_setrewr (struct net_device *dev,struct dcb_app *app) +{ +struct dcb_app app_itr; +int err =0 ; +u16 proto; + + err =sparx5_dcb_app_validate (dev, app); +if (err) + goto out; + +/* Delete current mapping, if it exists. */ + proto =dcb_getrewr (dev, app); +if (proto) { + app_itr = *app; + app_itr.protocol = proto; +sparx5_dcb_delrewr (dev, &app_itr); + } + +if (app->selector ==IEEE_8021QAZ_APP_SEL_DSCP ) + err =sparx5_dcb_ieee_dscp_setdel (dev, app, dcb_setrewr); +else + err =dcb_setrewr (dev, app); + +if (err) + goto out; + +sparx5_dcb_app_update (dev); + +out: +return err; +} +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, + .dcbnl_setrewr = sparx5_dcb_setrewr, + .dcbnl_delrewr = sparx5_dcb_delrewr, };int sparx5_dcb_init (struct sparx5 *sparx5)
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +42 -2
56 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_port.c +57 -0
68 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_port.h +18 -0
@@ -9,6 +9,11 @@#include "sparx5_main.h" +/* Port PCP rewrite mode */ +#define SPARX5_PORT_REW_TAG_CTRL_CLASSIFIED 0 +#define SPARX5_PORT_REW_TAG_CTRL_DEFAULT 1 +#define SPARX5_PORT_REW_TAG_CTRL_MAPPED 2 +static inline bool sparx5_port_is_2g5 (int portno) {return portno >=16 && portno <=47 ;
@@ -99,6 +104,10 @@ struct sparx5_port_qos_pcp_map {u8 map[SPARX5_PORT_QOS_PCP_DEI_COUNT ]; }; +struct sparx5_port_qos_pcp_rewr_map { +u16 map[SPX5_PRIOS ]; +}; +#define SPARX5_PORT_QOS_DSCP_COUNT 64struct sparx5_port_qos_dscp_map {u8 map[SPARX5_PORT_QOS_DSCP_COUNT ];
@@ -110,6 +119,11 @@ struct sparx5_port_qos_pcp {bool dp_enable; }; +struct sparx5_port_qos_pcp_rewr { +struct sparx5_port_qos_pcp_rewr_map map; +bool enable; +}; +struct sparx5_port_qos_dscp {struct sparx5_port_qos_dscp_map map;bool qos_enable;
@@ -118,6 +132,7 @@ struct sparx5_port_qos_dscp {struct sparx5_port_qos {struct sparx5_port_qos_pcp pcp; +struct sparx5_port_qos_pcp_rewr pcp_rewr;struct sparx5_port_qos_dscp dscp;u8 default_prio; };
@@ -127,6 +142,9 @@ int sparx5_port_qos_set(struct sparx5_port *port, struct sparx5_port_qos *qos);int sparx5_port_qos_pcp_set (const struct sparx5_port *port,struct sparx5_port_qos_pcp *qos); +int sparx5_port_qos_pcp_rewr_set (const struct sparx5_port *port, +struct sparx5_port_qos_pcp_rewr *qos); +int sparx5_port_qos_dscp_set (const struct sparx5_port *port,struct sparx5_port_qos_dscp *qos);
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Daniel Machon
maintainerPATCH v2 6/6 net: microchip: sparx5: add support for DSCP rewrite
In reply to Daniel MachonAdd support for DSCP rewrite in Sparx5 driver. On egress DSCP is rewritten from either classified DSCP, or frame DSCP. Classified DSCP is determined by the Analyzer Classifier on ingress, and is mapped from classified QoS class and DP level. Classification of DSCP is by default enabled for all ports.
It is required that DSCP is trusted for the egress port *and* rewrite table is not empty, in order to rewrite DSCP based on classified DSCP, otherwise DSCP is always rewritten from frame DSCP.
classified_dscp = qos_dscp_map[8 * dp_level + qos_class]; if (active_mappings && dscp_is_trusted)
rewritten_dscp = classified_dscp
else
rewritten_dscp = frame_dscp
To rewrite DSCP to 20 for any frames with priority 7:
$ dcb apptrust set dev eth0 order dscp $ dcb rewr add dev eth0 7:20 <-- not in iproute2/dcb yet
--- .../ethernet/microchip/sparx5/sparx5_dcb.c | 35 ++++++++++++++++ .../microchip/sparx5/sparx5_main_regs.h | 26 ++++++++++++ .../ethernet/microchip/sparx5/sparx5_port.c | 40 +++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_port.h | 23 +++++++++++ 4 files changed, 124 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c +35 -0
@@ -133,6 +133,7 @@ static bool sparx5_dcb_apptrust_contains(int portno, u8 selector)static int sparx5_dcb_app_update (struct net_device *dev) { +struct dcb_ieee_app_prio_map dscp_rewr_map = {0 };struct dcb_rewr_prio_pcp_map pcp_rewr_map = {0 };struct sparx5_port *port =netdev_priv (dev);struct sparx5_port_qos_dscp_map *dscp_map;
@@ -140,7 +141,9 @@ static int sparx5_dcb_app_update(struct net_device *dev)struct sparx5_port_qos qos = {0 };struct dcb_app app_itr = {0 };int portno = port->portno; +bool dscp_rewr = false;bool pcp_rewr = false; +u16 dscp;int i; dscp_map = &qos.dscp.map;
@@ -174,6 +177,26 @@ static int sparx5_dcb_app_update(struct net_device *dev) qos.pcp_rewr.map.map[i] =fls (pcp_rewr_map.map[i]) -1 ; } +/* Get dscp rewrite mapping */ +dcb_getrewr_prio_dscp_mask_map (dev, &dscp_rewr_map); +for (i =0 ; i <ARRAY_SIZE (dscp_rewr_map.map); i++) { +if (!dscp_rewr_map.map[i]) +continue ; + +/* The rewrite table of the switch has 32 entries; one for each +* priority for each DP level. Currently, the rewrite map does +* not indicate DP level, so we map classified QoS class to +* classified DSCP, for each classified DP level. Rewrite of +* DSCP is only enabled, if we have active mappings. +*/ + dscp_rewr = true; + dscp =fls64 (dscp_rewr_map.map[i]) -1 ; + qos.dscp_rewr.map.map[i] = dscp;/* DP 0 */ + qos.dscp_rewr.map.map[i +8 ] = dscp;/* DP 1 */ + qos.dscp_rewr.map.map[i +16 ] = dscp;/* DP 2 */ + qos.dscp_rewr.map.map[i +24 ] = dscp;/* DP 3 */ + } +/* Enable use of pcp for queue classification ? */ if (sparx5_dcb_apptrust_contains (portno,DCB_APP_SEL_PCP )) { qos.pcp.qos_enable = true;
@@ -189,6 +212,12 @@ static int sparx5_dcb_app_update(struct net_device *dev)if (sparx5_dcb_apptrust_contains (portno,IEEE_8021QAZ_APP_SEL_DSCP )) { qos.dscp.qos_enable = true; qos.dscp.dp_enable = qos.dscp.qos_enable; +if (dscp_rewr) +/* Do not enable rewrite if no mappings are active, as +* classified DSCP will then be zero for all classified +* QoS class and DP combinations. +*/ + qos.dscp_rewr.enable = true; }return sparx5_port_qos_set (port, &qos);
@@ -366,6 +395,12 @@ int sparx5_dcb_init(struct sparx5 *sparx5) sparx5_port_apptrust[port->portno] = &sparx5_dcb_apptrust_policies [SPARX5_DCB_APPTRUST_DSCP_PCP ]; + +/* Enable DSCP classification based on classified QoS class and +* DP, for all DSCP values, for all ports. +*/ +sparx5_port_qos_dscp_rewr_mode_set (port, +SPARX5_PORT_REW_DSCP_ALL ); }return 0 ;
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +26 -0
@@ -885,6 +885,16 @@ enum sparx5_target {#define ANA_CL_DSCP_CFG_DSCP_TRUST_ENA_GET (x)\ FIELD_GET(ANA_CL_DSCP_CFG_DSCP_TRUST_ENA, x) +/* ANA_CL:COMMON:QOS_MAP_CFG */ +#define ANA_CL_QOS_MAP_CFG (r) \ + __REG(TARGET_ANA_CL, 0, 1, 166912, 0, 1, 756, 512, r, 32, 4) + +#define ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL GENMASK(9, 4) +#define ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL_SET (x)\ + FIELD_PREP(ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL, x) +#define ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL_GET (x)\ + FIELD_GET(ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL, x) +/* ANA_L2:COMMON:AUTO_LRN_CFG */ #define ANA_L2_AUTO_LRN_CFG __REG(TARGET_ANA_L2, 0, 1, 566024, 0, 1, 700, 24, 0, 1, 4)
@@ -5385,6 +5395,22 @@ enum sparx5_target {#define REW_DEI_MAP_DE1_DEI_DE1_GET (x)\ FIELD_GET(REW_DEI_MAP_DE1_DEI_DE1, x) +/* REW:PORT:DSCP_MAP */ +#define REW_DSCP_MAP (g) \ + __REG(TARGET_REW, 0, 1, 360448, g, 70, 256, 136, 0, 1, 4) + +#define REW_DSCP_MAP_DSCP_UPDATE_ENA BIT(1) +#define REW_DSCP_MAP_DSCP_UPDATE_ENA_SET (x)\ + FIELD_PREP(REW_DSCP_MAP_DSCP_UPDATE_ENA, x) +#define REW_DSCP_MAP_DSCP_UPDATE_ENA_GET (x)\ + FIELD_GET(REW_DSCP_MAP_DSCP_UPDATE_ENA, x) + +#define REW_DSCP_MAP_DSCP_REMAP_ENA BIT(0) +#define REW_DSCP_MAP_DSCP_REMAP_ENA_SET (x)\ + FIELD_PREP(REW_DSCP_MAP_DSCP_REMAP_ENA, x) +#define REW_DSCP_MAP_DSCP_REMAP_ENA_GET (x)\ + FIELD_GET(REW_DSCP_MAP_DSCP_REMAP_ENA, x) +/* REW:PORT:TAG_CTRL */ #define REW_TAG_CTRL (g) __REG(TARGET_REW, 0, 1, 360448, g, 70, 256, 132, 0, 1, 4)
drivers/net/ethernet/microchip/sparx5/sparx5_port.c +40 -0
@@ -1152,6 +1152,7 @@ int sparx5_port_qos_set(struct sparx5_port *port,sparx5_port_qos_dscp_set (port, &qos->dscp);sparx5_port_qos_pcp_set (port, &qos->pcp);sparx5_port_qos_pcp_rewr_set (port, &qos->pcp_rewr); +sparx5_port_qos_dscp_rewr_set (port, &qos->dscp_rewr);sparx5_port_qos_default_set (port, qos);return 0 ;
@@ -1241,6 +1242,45 @@ int sparx5_port_qos_pcp_set(const struct sparx5_port *port,return 0 ; } +void sparx5_port_qos_dscp_rewr_mode_set (const struct sparx5_port *port, +int mode) +{ +spx5_rmw (ANA_CL_QOS_CFG_DSCP_REWR_MODE_SEL_SET (mode), +ANA_CL_QOS_CFG_DSCP_REWR_MODE_SEL , port->sparx5, +ANA_CL_QOS_CFG (port->portno)); +} + +int sparx5_port_qos_dscp_rewr_set (const struct sparx5_port *port, +struct sparx5_port_qos_dscp_rewr *qos) +{ +struct sparx5 *sparx5 = port->sparx5; +bool rewr = false; +u16 dscp; +int i; + +/* On egress, rewrite DSCP value to either classified DSCP or frame +* DSCP. If enabled; classified DSCP, if disabled; frame DSCP. +*/ +if (qos->enable) + rewr = true; + +spx5_rmw (REW_DSCP_MAP_DSCP_UPDATE_ENA_SET (rewr), +REW_DSCP_MAP_DSCP_UPDATE_ENA , sparx5, +REW_DSCP_MAP (port->portno)); + +/* On ingress, map each classified QoS class and DP to classified DSCP +* value. This mapping table is global for all ports. +*/ +for (i =0 ; i <ARRAY_SIZE (qos->map.map); i++) { + dscp = qos->map.map[i]; +spx5_rmw (ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL_SET (dscp), +ANA_CL_QOS_MAP_CFG_DSCP_REWR_VAL , sparx5, +ANA_CL_QOS_MAP_CFG (i)); + } + +return 0 ; +} +int sparx5_port_qos_dscp_set (const struct sparx5_port *port,struct sparx5_port_qos_dscp *qos) {
drivers/net/ethernet/microchip/sparx5/sparx5_port.h +23 -0
@@ -14,6 +14,12 @@#define SPARX5_PORT_REW_TAG_CTRL_DEFAULT 1#define SPARX5_PORT_REW_TAG_CTRL_MAPPED 2 +/* Port DSCP rewrite mode */ +#define SPARX5_PORT_REW_DSCP_NONE 0 +#define SPARX5_PORT_REW_DSCP_IF_ZERO 1 +#define SPARX5_PORT_REW_DSCP_SELECTED 2 +#define SPARX5_PORT_REW_DSCP_ALL 3 +static inline bool sparx5_port_is_2g5 (int portno) {return portno >=16 && portno <=47 ;
@@ -108,6 +114,11 @@ struct sparx5_port_qos_pcp_rewr_map {u16 map[SPX5_PRIOS ]; }; +#define SPARX5_PORT_QOS_DP_NUM 4 +struct sparx5_port_qos_dscp_rewr_map { +u16 map[SPX5_PRIOS *SPARX5_PORT_QOS_DP_NUM ]; +}; +#define SPARX5_PORT_QOS_DSCP_COUNT 64struct sparx5_port_qos_dscp_map {u8 map[SPARX5_PORT_QOS_DSCP_COUNT ];
@@ -130,10 +141,16 @@ struct sparx5_port_qos_dscp {bool dp_enable; }; +struct sparx5_port_qos_dscp_rewr { +struct sparx5_port_qos_dscp_rewr_map map; +bool enable; +}; +struct sparx5_port_qos {struct sparx5_port_qos_pcp pcp;struct sparx5_port_qos_pcp_rewr pcp_rewr;struct sparx5_port_qos_dscp dscp; +struct sparx5_port_qos_dscp_rewr dscp_rewr;u8 default_prio; };
@@ -148,6 +165,12 @@ int sparx5_port_qos_pcp_rewr_set(const struct sparx5_port *port,int sparx5_port_qos_dscp_set (const struct sparx5_port *port,struct sparx5_port_qos_dscp *qos); +void sparx5_port_qos_dscp_rewr_mode_set (const struct sparx5_port *port, +int mode); + +int sparx5_port_qos_dscp_rewr_set (const struct sparx5_port *port, +struct sparx5_port_qos_dscp_rewr *qos); +int sparx5_port_qos_default_set (const struct sparx5_port *port,const struct sparx5_port_qos *qos);
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 18 lines · Daniel Machon
There is currently no support for per-port egress mapping of priority to PCP and priority to DSCP. Some support for expressing egress mapping of PCP is supported through ip link, with the 'egress-qos-map', however this command only maps priority to PCP, and for vlan interfaces only. DCB APP already has support for per-port ingress mapping of PCP/DEI, DSCP and a bunch of other stuff. So why not take advantage of this fact, and add a new table that does the reverse.
This patch series introduces the new DCB rewrite table. Whereas the DCB APP table deals with ingress mapping of PID (protocol identifier) to priority, the rewrite table deals with egress mapping of priority to PID.
It is indeed possible to integrate rewrite in the existing APP table, by introducing new dedicated rewrite selectors, and altering existing functions to treat rewrite entries specially. However, I feel like this is not a good solution, and will pollute the APP namespace. APP is well-defined in IEEE, and some userspace relies of advertised entries - for this fact, separating APP and rewrite into to completely separate objects, seems to me the best solution.
Quoted 2 lines
The new table shares much functionality with the APP table, and as such, much existing code is reused, or slightly modified, to work for both.
Thanks Daniel,
FWIIW, this looks nice and clean to me.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel