net: dsa: motorcomm: TC offload follow-ups
David Yang
maintainerv2 cover net: dsa: motorcomm: TC offload follow-ups
This series continues the traffic control work on the Motorcomm YT9215S DSA driver: it reorganizes the offload code and then adds ACL enablement on demand and flower priority mapping.
v2:
- move type casting helper into chip.h
- remove flow statistics and broadcast/multicast policers
v1: https://lore.kernel.org/r/[email protected]
David Yang (5):
net: dsa: motorcomm: Hoist type casting helper into chip.h
net: dsa: motorcomm: Split TC module
net: dsa: motorcomm: Use NSEC_PER_SEC
net: dsa: motorcomm: Enable ACL on demand
net: dsa: motorcomm: Add TC prio support
drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 1568 +------------------------- drivers/net/dsa/motorcomm/chip.h | 355 +----- drivers/net/dsa/motorcomm/leds.c | 7 +- drivers/net/dsa/motorcomm/mdio_bus.c | 10 +- drivers/net/dsa/motorcomm/pcs-921x.c | 8 +- drivers/net/dsa/motorcomm/tc.c | 1524 +++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 379 +++++++ 8 files changed, 1982 insertions(+), 1870 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/tc.c create mode 100644 drivers/net/dsa/motorcomm/tc.h
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v2 1/5 net: dsa: motorcomm: Hoist type casting helper into chip.h
Rename and move dsa_to_yt921x_priv() and yt921x_priv_to_device() to chip.h so all files use one definition.
--- drivers/net/dsa/motorcomm/chip.c | 127 +++++++++++++-------------- drivers/net/dsa/motorcomm/chip.h | 2 + drivers/net/dsa/motorcomm/leds.c | 7 +- drivers/net/dsa/motorcomm/mdio_bus.c | 10 +-- drivers/net/dsa/motorcomm/pcs-921x.c | 8 +- 5 files changed, 74 insertions(+), 80 deletions(-)
drivers/net/dsa/motorcomm/chip.c +62 -65
@@ -171,9 +171,6 @@ struct yt921x_reg_mdio {/* TODO: SPI/I2C */ -#define to_yt921x_priv (_ds) container_of_const(_ds, struct yt921x_priv, ds) -#define to_device (priv) ((priv)->ds.dev) -static u32 ethaddr_hi4_to_u32 (const unsigned char *addr) {return (addr[0 ] <<24 ) | (addr[1 ] <<16 ) | (addr[2 ] <<8 ) | addr[3 ];
@@ -272,7 +269,7 @@ static const struct yt921x_reg_ops yt921x_reg_ops_mdio = {static int yt921x_read_mib (struct yt921x_priv *priv,int port) {struct yt921x_port *pp = &priv->ports[port]; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct yt921x_mib *mib = &pp->mib;int res =0 ;
@@ -364,7 +361,7 @@ yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset,static void yt921x_dsa_get_ethtool_stats (struct dsa_switch *ds,int port,uint64_t *data) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;size_t j;
@@ -406,7 +403,7 @@ static void yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, struct ethtool_eth_mac_stats *mac_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;
@@ -442,7 +439,7 @@ static void yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, struct ethtool_eth_ctrl_stats *ctrl_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;
@@ -471,7 +468,7 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port,struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;
@@ -507,7 +504,7 @@ static void yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, struct rtnl_link_stats64 *stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;
@@ -543,7 +540,7 @@ static void yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, struct ethtool_pause_stats *pause_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_port *pp = &priv->ports[port];struct yt921x_mib *mib = &pp->mib;
@@ -598,7 +595,7 @@ yt921x_set_eee(struct yt921x_priv *priv, int port, struct ethtool_keee *e)static int yt921x_dsa_set_mac_eee (struct dsa_switch *ds,int port,struct ethtool_keee *e) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);int res;mutex_lock (&priv->reg_lock);
@@ -622,7 +619,7 @@ yt921x_dsa_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)* maximum after reset */ -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);struct dsa_port *dp =dsa_to_port (ds, port);int frame_size;int res;
@@ -697,7 +694,7 @@ yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, {const int C = flags &YT921X_MARKER_PKT_MODE ?YT921X_TOKEN_PKT_C :YT921X_TOKEN_BYTE_C ; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct yt921x_marker m;u64 burst_est;u64 burst_sug;
@@ -873,8 +870,8 @@ yt921x_meter_config(struct yt921x_priv *priv, unsigned int id,static void yt921x_dsa_port_policer_del (struct dsa_switch *ds,int port) { -struct yt921x_priv *priv =to_yt921x_priv (ds); -struct device *dev =to_device (priv); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv);int res;mutex_lock (&priv->reg_lock);
@@ -891,7 +888,7 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port,const struct flow_action_police *police, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct yt921x_marker marker;u32 ctrl;int res;
@@ -921,7 +918,7 @@ static int yt921x_dsa_port_setup_tc_tbf_port(struct dsa_switch *ds, int port, const struct tc_tbf_qopt_offload *qopt) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct netlink_ext_ack *extack = qopt->extack;u32 ctrls[2 ];int res;
@@ -1970,7 +1967,7 @@ static int yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;mutex_lock (&priv->reg_lock);
@@ -1985,7 +1982,7 @@ yt921x_dsa_cls_flower_add(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress) {struct netlink_ext_ack *extack = cls->common.extack; -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);struct yt921x_acl_rule_ext ruleext;int res;
@@ -2056,8 +2053,8 @@ static void yt921x_dsa_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror) { - struct yt921x_priv *priv = to_yt921x_priv(ds); -struct device *dev =to_device (priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); +struct device *dev =yt921x_priv_to_device (priv);int res;mutex_lock (&priv->reg_lock);
@@ -2074,7 +2071,7 @@ yt921x_dsa_port_mirror_add(struct dsa_switch *ds, int port,struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;mutex_lock (&priv->reg_lock);
@@ -2143,7 +2140,7 @@ static int yt921x_lag_set(struct yt921x_priv *priv, u8 index, u16 ports_mask)static int yt921x_dsa_port_lag_leave (struct dsa_switch *ds,int port,struct dsa_lag lag) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);struct dsa_port *dp;u32 ctrl;int res;
@@ -2206,7 +2203,7 @@ yt921x_dsa_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag,struct netdev_lag_upper_info *info, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);struct dsa_port *dp;bool unique_lag;unsigned int i;
@@ -2269,7 +2266,7 @@ yt921x_dsa_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag,static int yt921x_fdb_wait (struct yt921x_priv *priv,u32 *valp) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);u32 val =YT921X_FDB_RESULT_DONE ;int res;
@@ -2338,7 +2335,7 @@ static int yt921x_fdb_read(struct yt921x_priv *priv, unsigned char *addr, u16 *vidp, u16 *ports_maskp, u16 *indexp, u8 *statusp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv);u16 index;u32 data0;u32 data1;
@@ -2629,7 +2626,7 @@ static int yt921x_dsa_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;mutex_lock (&priv->reg_lock);
@@ -2644,8 +2641,8 @@ yt921x_dsa_port_fdb_dump(struct dsa_switch *ds, int port,static void yt921x_dsa_port_fast_age (struct dsa_switch *ds,int port) { -struct yt921x_priv *priv =to_yt921x_priv (ds); -struct device *dev =to_device (priv); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv);int res;mutex_lock (&priv->reg_lock);
@@ -2660,7 +2657,7 @@ static void yt921x_dsa_port_fast_age(struct dsa_switch *ds, int port)static int yt921x_dsa_set_ageing_time (struct dsa_switch *ds,unsigned int msecs) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);u32 ctrl;int res;
@@ -2678,7 +2675,7 @@ static int yt921x_dsa_port_fdb_del(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;mutex_lock (&priv->reg_lock);
@@ -2692,7 +2689,7 @@ static int yt921x_dsa_port_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;mutex_lock (&priv->reg_lock);
@@ -2707,7 +2704,7 @@ yt921x_dsa_port_mdb_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);const unsigned char *addr = mdb->addr;u16 vid = mdb->vid;int res;
@@ -2724,7 +2721,7 @@ yt921x_dsa_port_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);const unsigned char *addr = mdb->addr;u16 vid = mdb->vid;int res;
@@ -2889,7 +2886,7 @@ yt921x_dsa_port_vlan_filtering(struct dsa_switch *ds, int port,bool vlan_filtering, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;if (dsa_is_cpu_port (ds, port))
@@ -2906,7 +2903,7 @@ static int yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u16 vid = vlan->vid;u16 pvid;int res;
@@ -2940,7 +2937,7 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u16 vid = vlan->vid;u16 pvid;int res;
@@ -3185,7 +3182,7 @@ yt921x_dsa_port_bridge_flags(struct dsa_switch *ds, int port,struct switchdev_brport_flags flags, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);int res;if (dsa_is_cpu_port (ds, port))
@@ -3202,8 +3199,8 @@ static void yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) { - struct yt921x_priv *priv = to_yt921x_priv(ds); -struct device *dev =to_device (priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); +struct device *dev =yt921x_priv_to_device (priv);int res;if (dsa_is_cpu_port (ds, port))
@@ -3223,7 +3220,7 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u16 ports_mask;int res;
@@ -3244,7 +3241,7 @@ static int yt921x_dsa_port_mst_state_set(struct dsa_switch *ds, int port, const struct switchdev_mst_state *st) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u32 mask;u32 ctrl;int res;
@@ -3278,7 +3275,7 @@ static int yt921x_dsa_vlan_msti_set(struct dsa_switch *ds, struct dsa_bridge bridge, const struct switchdev_vlan_msti *msti) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u32 masks[2 ];u32 ctrls[2 ];int res;
@@ -3304,9 +3301,9 @@ yt921x_dsa_vlan_msti_set(struct dsa_switch *ds, struct dsa_bridge bridge,static void yt921x_dsa_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);struct dsa_port *dp =dsa_to_port (ds, port); -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);bool learning;u32 mask;u32 ctrl;
@@ -3356,7 +3353,7 @@ yt921x_dsa_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)static int __maybe_unused yt921x_dsa_port_get_default_prio (struct dsa_switch *ds,int port) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);u32 val;int res;
@@ -3373,7 +3370,7 @@ yt921x_dsa_port_get_default_prio(struct dsa_switch *ds, int port)static int __maybe_unused yt921x_dsa_port_set_default_prio (struct dsa_switch *ds,int port,u8 prio) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);u32 mask;u32 ctrl;int res;
@@ -3399,7 +3396,7 @@ static int __maybe_unused yt921x_dsa_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nselp) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);u8 appprios[2 ][2 ] = {};int nsel;u32 val;
@@ -3433,8 +3430,8 @@ static int __maybe_unused yt921x_dsa_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel, int nsel) { - struct yt921x_priv *priv = to_yt921x_priv(ds); -struct device *dev =to_device (priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); +struct device *dev =yt921x_priv_to_device (priv);u32 ctrl;int res;
@@ -3576,7 +3573,7 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, {const struct yt921x_info *info = priv->info;struct yt921x_port *pp = &priv->ports[port]; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);u32 mask;int res;
@@ -3628,7 +3625,7 @@ yt921x_phylink_mac_select_pcs(struct phylink_config *config, phy_interface_t interface) {struct dsa_port *dp =dsa_phylink_to_port (config); -struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (dp->ds);const struct yt921x_info *info = priv->info;int port = dp->index;
@@ -3651,7 +3648,7 @@ yt921x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, phy_interface_t interface) {struct dsa_port *dp =dsa_phylink_to_port (config); -struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (dp->ds);int port = dp->index;int res;
@@ -3674,7 +3671,7 @@ yt921x_phylink_mac_link_up(struct phylink_config *config, bool tx_pause, bool rx_pause) {struct dsa_port *dp =dsa_phylink_to_port (config); -struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (dp->ds);int port = dp->index;int res;
@@ -3695,7 +3692,7 @@ yt921x_phylink_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) {struct dsa_port *dp =dsa_phylink_to_port (config); -struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (dp->ds);int port = dp->index;int res;
@@ -3712,7 +3709,7 @@ static void yt921x_dsa_phylink_get_caps(struct dsa_switch *ds, int port, struct phylink_config *config) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);const struct yt921x_info *info = priv->info; config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
@@ -3803,7 +3800,7 @@ yt921x_dsa_get_tag_protocol(struct dsa_switch *ds, int port,static int yt921x_dsa_port_setup (struct dsa_switch *ds,int port) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);int res;mutex_lock (&priv->reg_lock);
@@ -3817,7 +3814,7 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port)static int __maybe_unused yt921x_dsa_port_get_dscp_prio (struct dsa_switch *ds,int port,u8 dscp) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);u32 val;int res;
@@ -3834,7 +3831,7 @@ yt921x_dsa_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp)static int __maybe_unused yt921x_dsa_port_del_dscp_prio (struct dsa_switch *ds,int port,u8 dscp,u8 prio) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);u32 val;int res;
@@ -3859,7 +3856,7 @@ yt921x_dsa_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio)static int __maybe_unused yt921x_dsa_port_add_dscp_prio (struct dsa_switch *ds,int port,u8 dscp,u8 prio) { -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);int res;if (prio >=YT921X_PRIO_NUM )
@@ -3920,7 +3917,7 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp)static void yt921x_dsa_teardown (struct dsa_switch *ds) {#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) -struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds);yt921x_leds_remove (priv);#endif
@@ -3928,7 +3925,7 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds)static int yt921x_chip_detect (struct yt921x_priv *priv) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);const struct yt921x_info *info;u8 extmode;u32 chipid;
@@ -3995,7 +3992,7 @@ static int yt921x_chip_detect(struct yt921x_priv *priv)static int yt921x_chip_reset (struct yt921x_priv *priv) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);u16 eth_p_tag;u32 val;int res;
@@ -4243,8 +4240,8 @@ static int yt921x_chip_setup(struct yt921x_priv *priv)static int yt921x_dsa_setup (struct dsa_switch *ds) { -struct yt921x_priv *priv =to_yt921x_priv (ds); -struct device *dev =to_device (priv); +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv);struct device_node *np = dev->of_node;struct device_node *child;unsigned long mask;
drivers/net/dsa/motorcomm/chip.h +2 -0
@@ -984,8 +984,10 @@ struct yt921x_priv {struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM ]; }; +#define dsa_to_yt921x_priv (_ds) container_of_const(_ds, struct yt921x_priv, ds)#define yt921x_port_to_priv (pp) \ container_of_const((pp), struct yt921x_priv, ports[(pp)->index]) +#define yt921x_priv_to_device (priv) ((priv)->ds.dev)static inline int ethtool_speed_to_yt921x (int speed) {
drivers/net/dsa/motorcomm/leds.c +3 -4
@@ -12,7 +12,6 @@#define to_yt921x_led (led_cdev) \ container_of_const((led_cdev), struct yt921x_led, cdev)#define to_yt921x_port (led) ((led)->port) -#define to_device (priv) ((priv)->ds.dev)static u32 yt921x_led_regaddr (struct yt921x_priv *priv,int port,int group) {
@@ -414,7 +413,7 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, struct fwnode_handle *fwnode) {struct yt921x_port *pp = &priv->ports[port]; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct led_init_data init_data;struct led_classdev *led_cdev;char name[LED_MAX_NAME_SIZE ];
@@ -569,7 +568,7 @@ yt921x_led_setup(struct yt921x_priv *priv, int port,static void yt921x_leds_remove_port (struct yt921x_priv *priv,int port) {struct yt921x_port *pp = &priv->ports[port]; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);for (int group =0 ; group <YT921X_LED_GROUP_NUM ; group++) {struct yt921x_led *led = pp->leds[group];
@@ -587,7 +586,7 @@ static void yt921x_leds_remove_port(struct yt921x_priv *priv, int port)static int yt921x_leds_setup_port (struct yt921x_priv *priv,int port) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct dsa_switch *ds = &priv->ds;struct device_node *leds_np;struct dsa_port *dp;
drivers/net/dsa/motorcomm/mdio_bus.c +4 -6
@@ -9,8 +9,6 @@#include "mdio_bus.h" #include "smi.h" -#define to_device (priv) ((priv)->ds.dev) -static int yt921x_intif_wait (struct yt921x_priv *priv) {u32 val =0 ;
@@ -21,7 +19,7 @@ static int yt921x_intif_wait(struct yt921x_priv *priv)int yt921x_intif_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);u32 mask;u32 ctrl;u32 val;
@@ -145,7 +143,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)int yt921x_mbus_int_init (struct yt921x_priv *priv,struct device_node *mnp) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct mii_bus *mbus;int res;
@@ -181,7 +179,7 @@ static int yt921x_extif_wait(struct yt921x_priv *priv)static int yt921x_extif_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);u32 mask;u32 ctrl;u32 val;
@@ -275,7 +273,7 @@ yt921x_mbus_ext_write(struct mii_bus *mbus, int port, int reg, u16 data)int yt921x_mbus_ext_init (struct yt921x_priv *priv,struct device_node *mnp) { -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct mii_bus *mbus;int res;
drivers/net/dsa/motorcomm/pcs-921x.c +3 -5
@@ -8,8 +8,6 @@#include "pcs.h" #include "smi.h" -#define to_device (priv) ((priv)->ds.dev) - static int yt921x_serdes_config(struct yt921x_priv *priv, int port, unsigned int neg_mode, phy_interface_t interface,
@@ -116,7 +114,7 @@ yt921x_phylink_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, {struct yt921x_port *pp =pcs_to_yt921x_port (pcs);struct yt921x_priv *priv =yt921x_port_to_priv (pp); -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);int port = pp->index;u16 bmsr;u16 lpa;
@@ -155,7 +153,7 @@ static void yt921x_phylink_pcs_an_restart(struct phylink_pcs *pcs) {struct yt921x_port *pp =pcs_to_yt921x_port (pcs);struct yt921x_priv *priv =yt921x_port_to_priv (pp); -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);int port = pp->index;u16 val;int res;
@@ -181,7 +179,7 @@ static void yt921x_phylink_pcs_disable(struct phylink_pcs *pcs) {struct yt921x_port *pp =pcs_to_yt921x_port (pcs);struct yt921x_priv *priv =yt921x_port_to_priv (pp); -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);int port = pp->index;int res;
Signature · 1 line
2.53.0
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/5] net: dsa: motorcomm: Hoist type casting helper into chip.h
drivers/net/dsa/motorcomm/chip.c static const struct yt921x_reg_ops yt921x_reg_ops_mdio = { · line 274
Quoted 7 lines
static int
yt921x_read_mib(struct yt921x_priv *priv, int port){drivers/net/dsa/motorcomm/chip.c +1
-1struct yt921x_port *pp = &priv->ports[port]; -struct device *dev =to_device (priv); +struct device *dev =yt921x_priv_to_device (priv);struct yt921x_mib *mib = &pp->mib;int res =0 ;
Reverse Christmas tree. Plain search/replace does not work here.
There might be other instances, i did not look at all the patch.
Andrew
---
pw-bot: cr
David Yang
maintainerPATCH v2 2/5 net: dsa: motorcomm: Split TC module
In reply to David YangMove the traffic control code from chip.c into a separate tc.c, to reduce the length of chip.c.
--- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 1458 +--------------------------- drivers/net/dsa/motorcomm/chip.h | 351 +------ drivers/net/dsa/motorcomm/tc.c | 1454 +++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 378 ++++++++ 5 files changed, 1844 insertions(+), 1798 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/tc.c create mode 100644 drivers/net/dsa/motorcomm/tc.h
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -5,3 +5,4 @@ yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += mdio_bus.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o +yt921x-objs += tc.o
drivers/net/dsa/motorcomm/chip.c +1 -1457
1,488 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +10 -341
393 lines not on this page · raw message
drivers/net/dsa/motorcomm/tc.c new file +1454 -0
1,115 lines not on this page · raw message
drivers/net/dsa/motorcomm/tc.h new file +378 -0
378 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.53.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH net-next v2 2/5] net: dsa: motorcomm: Split TC module
Quoted 4 lines · David Yang
Move the traffic control code from
chip.cinto a separatetc.c, to reduce the length ofchip.c.Signed-off-by David Yang <[email protected]>
Andrew
David Yang
maintainerPATCH v2 3/5 net: dsa: motorcomm: Use NSEC_PER_SEC
In reply to David YangGet rid of magic numbers.
--- drivers/net/dsa/motorcomm/tc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/tc.c +3 -3
@@ -25,14 +25,14 @@ static u32 rate2token(u64 rate, unsigned int slot_ns, int unit, int C) {int e =2 * unit +C +YT921X_TOKEN_RATE_C ; -return div_u64 (ldexpu64 (slot_ns * rate, -e),1000000000 ); +return div_u64 (ldexpu64 (slot_ns * rate, -e),NSEC_PER_SEC ); }static u64 token2rate (u32 token,unsigned int slot_ns,int unit,int C ) {int e =2 * unit +C +YT921X_TOKEN_RATE_C ; -return div_u64 (ldexpu64 (mul_u32_u32 (1000000000 , token), e), slot_ns); +return div_u64 (ldexpu64 (mul_u32_u32 (NSEC_PER_SEC , token), e), slot_ns); }/* burst = 2^C * token * 4^unit */
@@ -83,7 +83,7 @@ yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, }/* Check for matching burst */ - burst_est =div_u64 (slot_ns * rate,1000000000 ); + burst_est =div_u64 (slot_ns * rate,NSEC_PER_SEC ); burst_sug = burst_est;if (flags &YT921X_MARKER_PKT_MODE ) burst_sug++;
Signature · 1 line
2.53.0
Re: [PATCH net-next v2 3/5] net: dsa: motorcomm: Use NSEC_PER_SEC
Quoted 3 lines · David Yang
Get rid of magic numbers.
Signed-off-by David Yang <[email protected]>
Andrew
David Yang
maintainerPATCH v2 4/5 net: dsa: motorcomm: Enable ACL on demand
In reply to David YangTrack the usage of ACL rules and enable it per port only when it is actually used.
--- drivers/net/dsa/motorcomm/chip.c | 3 +- drivers/net/dsa/motorcomm/chip.h | 2 + drivers/net/dsa/motorcomm/tc.c | 63 +++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 7 deletions(-)
drivers/net/dsa/motorcomm/chip.c +1 -2
@@ -2686,8 +2686,7 @@ static int yt921x_chip_setup_acl(struct yt921x_priv *priv)if (res)return res; - ctrl =YT921X_ACL_PORT_PORTS_M ; - res =yt921x_reg_write (priv,YT921X_ACL_PORT , ctrl); + res =yt921x_reg_write (priv,YT921X_ACL_PORT ,0 );if (res)return res;
drivers/net/dsa/motorcomm/chip.h +2 -0
@@ -581,6 +581,8 @@ struct yt921x_port {u64 rx_frames;u64 tx_frames; +unsigned short acl_cnt; +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS )unsigned char led_duty;unsigned short led_cycle;
drivers/net/dsa/motorcomm/tc.c +58 -5
121 lines not on this page · raw message
Signature · 1 line
2.53.0
Andrew Lunn
maintainerRe: [PATCH net-next v2 4/5] net: dsa: motorcomm: Enable ACL on demand
Quoted 2 lines · David Yang
Track the usage of ACL rules and enable it per port only when it is actually used.
Does having it activated when not needed actually matter?
You are missing the answer to the question 'why?'
Andrew
[email protected]
AI reviewRe: [PATCH net-next v2 4/5] net: dsa: motorcomm: Enable ACL on demand
In reply to David YangThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Memory leak on an error path in yt921x_acl_add() (drivers/net/dsa/motorcomm/tc.c).
- [Low] The hardware ACL port-enable register can disagree with the software acl_cnt bookkeeping after errors.
--
net: dsa: motorcomm: Enable ACL on demand
This patch stops yt921x_chip_setup_acl() from enabling ACL on all ports. It adds a per-port acl_cnt counter instead. yt921x_acl_add() sets a port's YT921X_ACL_PORT bit when the port gets its first rule, and yt921x_acl_del() refreshes the register once the last rule for that port is removed.
Quoted 4 lines
drivers/net/dsa/motorcomm/tc.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/tc.c +1
-0@@ -1312,6 +1347,19 @@ yt921x_acl_add(struct yt921x_priv *priv,else aclrule->action[0 ] &= ~YT921X_ACL_ACTa_METER_EN; +/* Activate ACL if needed */
drivers/net/dsa/motorcomm/tc.c yt921x_acl_add(struct yt921x_priv *priv, · line 1360
Quoted 10 lines
drivers/net/dsa/motorcomm/tc.c +10
-0+ ctrl =0 ; + m =FIELD_GET (YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0 ].key[1 ]); +for_each_set_bit (o, &m,YT921X_PORT_NUM ) +if (!priv->ports[o].acl_cnt) + ctrl |=YT921X_ACL_PORT_PORTn (o); +if (ctrl) { + ctrl |=yt921x_acl_activated_ports (priv); + res =yt921x_reg_write (priv,YT921X_ACL_PORT , ctrl); +if (res) +return res;
[Severity: Medium]
Does this early return leak aclrule?
At this point aclrule has already been allocated by kvmemdup(), but it hasn't been stored in aclblk->rules[binid] yet:
aclrule = kvmemdup(&ruleext->r, offsetof(struct yt921x_acl_rule, entries[entscnt]), GFP_KERNEL);
The teardown in chip.c only frees rules it can reach through priv->acl_blks[]->rules[], so nothing would ever free this one.
The return also skips the err: label:
err:
if (!priv->acl_masks[blkid]) {
kvfree(aclblk);
priv->acl_blks[blkid] = NULL;
}If aclblk was freshly allocated for this rule, it stays in priv->acl_blks[blkid] even though the block is empty. That isn't a permanent leak, since a later add can reuse it and remove frees it.
This happens when a source port has acl_cnt == 0 and the YT921X_ACL_PORT write fails. Should this path do kvfree(aclrule) and then goto err, like the yt921x_acl_commit() failure path does?
drivers/net/dsa/motorcomm/tc.c yt921x_acl_add(struct yt921x_priv *priv, · line 1365
Quoted 5 lines
drivers/net/dsa/motorcomm/tc.c +2
-0+ } +/* Write rules */ aclblk->rules[binid] = aclrule; res =yt921x_acl_commit (priv, entid, aclrule->mask);
[Severity: Low]
Can YT921X_ACL_PORT end up out of sync with acl_cnt here?
The port bits are set in hardware before yt921x_acl_commit() runs. If any register write inside yt921x_acl_commit() fails, the existing error branch only rolls back software state:
if (res) {
aclblk->rules[binid] = NULL;
kvfree(aclrule);
goto err;
}acl_cnt++ only runs after a successful commit. So the port stays ACL-enabled in hardware while acl_cnt for it is still 0.
yt921x_acl_del() has the same problem in reverse. acl_cnt is decremented to 0 first, and then the register is refreshed:
if (refresh_en) {
ctrl = yt921x_acl_activated_ports(priv);
res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl);
if (res)
ret = res;
}If that write fails, the bit stays set while software counts no rules on the port.
In both cases the stale bit is only cleared when a later add or del rewrites the whole register. Unmatched traffic is still permitted because YT921X_ACL_PERMIT_UNMATCH is set for all ports, but the port keeps doing ACL lookups when ACL isn't "actually used" on it.
Should the yt921x_acl_add() commit failure path write yt921x_acl_activated_ports(priv) back to YT921X_ACL_PORT?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261001204851.2576101-1-mmyangfl%40gmail.com
David Yang
maintainerPATCH v2 5/5 net: dsa: motorcomm: Add TC prio support
In reply to David YangThe HW supports fewer ACL priorities than TC does. Notice the default priority for flower is 49152 and catchall filter has priority 65535, so scale the priority accordingly and reject the ones that do not map onto a hardware priority.
--- drivers/net/dsa/motorcomm/tc.c | 19 ++++++++++++++++++- drivers/net/dsa/motorcomm/tc.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/net/dsa/motorcomm/tc.c +18 -1
@@ -1029,7 +1029,10 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, const struct flow_cls_offload *cls, bool ingress, struct yt921x_priv *priv) { + const unsigned int scale = (U16_MAX + 1) / YT921X_ACL_ORD_NUM;struct netlink_ext_ack *extack = cls->common.extack; +u32 prio = cls->common.prio; +u32 ord;int res;if (!ingress) {
@@ -1042,6 +1045,20 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,return -EOPNOTSUPP ; } +/* TC prio can't be 0 & TC lowest first -> HW highest first +* map 1...U16_MAX to (ACL_ORD_NUM - 1)...0 +*/ +if (prio ==U16_MAX ) { + ord =0 ; + }else if (!(prio % scale)) { + ord =YT921X_ACL_ORD_NUM - prio / scale; + }else { +NL_SET_ERR_MSG_FMT_MOD (extack, +"Invalid priority %u, must be a multiple of %u or 65535" , + prio, scale); +return -EOPNOTSUPP ; + } + res =yt921x_acl_rule_ext_parse_flow_action (ruleext, cls, priv, port);if (res)return res;
@@ -1049,7 +1066,7 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,if (res)return res; -yt921x_acl_rule_set_ports (&ruleext->r,0 ,BIT (port)); +yt921x_acl_rule_set_ports (&ruleext->r, ord,BIT (port)); ruleext->r.tag = cls->cookie; ruleext->r.type =TC_SETUP_CLSFLOWER ;return 0 ;
drivers/net/dsa/motorcomm/tc.h +1 -0
@@ -331,6 +331,7 @@ enum yt921x_l4_type {#define YT921X_ACL_ENT_PER_BLK 8#define YT921X_ACL_NUM 384 +#define YT921X_ACL_ORD_NUM 512#define YT921X_UDF_NUM 8struct yt921x_acl_entry {
Signature · 1 line
2.53.0
Andrew Lunn
maintainerRe: [PATCH net-next v2 5/5] net: dsa: motorcomm: Add TC prio support
Quoted 4 lines · David Yang
The HW supports fewer ACL priorities than TC does. Notice the default priority for flower is 49152 and catchall filter has priority 65535, so scale the priority accordingly and reject the ones that do not map onto a hardware priority.
It would be good to document what the actual mapping is. I think you divide by 512, and then invert?
The code itself looks O.K.
Andrew
[email protected]
AI reviewRe: [PATCH net-next v2 5/5] net: dsa: motorcomm: Add TC prio support
In reply to David YangThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new comment in yt921x_acl_rule_ext_parse_flow() (drivers/net/dsa/motorcomm/tc.c) says "map 1...U16_MAX to (ACL_ORD_NUM…
--
net: dsa: motorcomm: Add TC prio support
This commit maps TC flower priorities onto the hardware ACL order field. TC priorities that are multiples of (U16_MAX + 1) / YT921X_ACL_ORD_NUM are scaled down. 65535 maps to order 0, and every other value is rejected.
Quoted 4 lines
drivers/net/dsa/motorcomm/tc.c +0
-0
[ ... ]
drivers/net/dsa/motorcomm/tc.c yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, · line 1050
Quoted 7 lines
drivers/net/dsa/motorcomm/tc.c +3
-0@@ -1042,6 +1045,20 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,return -EOPNOTSUPP ; } +/* TC prio can't be 0 & TC lowest first -> HW highest first +* map 1...U16_MAX to (ACL_ORD_NUM - 1)...0 +*/
[Severity: Low]
This isn't a bug, but the comment doesn't match what the code below does.
With scale = 65536 / 512 = 128, the only values accepted are:
prio == k * 128 (k = 1..511) -> ord = 512 - k prio == 65535 -> ord = 0
The other values in 1...U16_MAX are rejected with -EOPNOTSUPP. That includes prio 1, which is where the comment says the range starts. Ord 511 comes from prio 128, not prio 1.
Could the comment describe the discrete mapping instead, in line with the extack message "must be a multiple of %u or 65535"?
Quoted 11 lines
drivers/net/dsa/motorcomm/tc.c +11
-0+if (prio ==U16_MAX ) { + ord =0 ; + }else if (!(prio % scale)) { + ord =YT921X_ACL_ORD_NUM - prio / scale; + }else { +NL_SET_ERR_MSG_FMT_MOD (extack, +"Invalid priority %u, must be a multiple of %u or 65535" , + prio, scale); +return -EOPNOTSUPP ; + } +
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261001204851.2576101-1-mmyangfl%40gmail.com