The shared QoS layer hands the backend internal priorities that are 802.1Q traffic types, and the backend stores them in the chip as they are, together with a separate per-port PCP for untagged frames. Family D numbers its internal priorities differently and has no separate untagged-PCP register, which the next patch adds. Move the conversion between a traffic type and the chip's priority, and the programming of the PCP of untagged frames, behind three new hooks in struct rtl8365mb_family_info, as for the VLAN, PVID and L2 helpers: qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp. The existing behaviour becomes the family C implementation: the traffic type is stored as it is and the untagged PCP register is written as before. rtl8365mb_qos_qmap_init() now iterates over the chip's priorities and converts each one back to its traffic type. No functional change. Tested-by: Gustavo Foletto Mora Signed-off-by: Mieczyslaw Nalewaj --- drivers/net/dsa/realtek/rtl8365mb.h | 4 + drivers/net/dsa/realtek/rtl8365mb_main.c | 3 + drivers/net/dsa/realtek/rtl8365mb_qos.c | 102 +++++++++++++++++++---- drivers/net/dsa/realtek/rtl8365mb_qos.h | 6 ++ 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h index 9a69e85..d34c9b6 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.h +++ b/drivers/net/dsa/realtek/rtl8365mb.h @@ -38,6 +38,10 @@ struct rtl8365mb_family_info { void (*l2_uc_to_data)(const struct rtl8365mb_l2_uc *uc, u16 *data); void (*l2_data_to_mc)(const u16 *data, struct rtl8365mb_l2_mc *mc); void (*l2_mc_to_data)(const struct rtl8365mb_l2_mc *mc, u16 *data); + int (*qos_iprio_to_hw)(u8 iprio); + int (*qos_hw_to_iprio)(u8 hw); + int (*qos_set_untag_pcp)(struct realtek_priv *priv, int port, + u8 hw_prio, u8 untag_pcp); }; const struct rtl8365mb_family_info * diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index bf508ed..639e6b6 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -830,6 +830,9 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = { .l2_uc_to_data = rtl8365mb_c_l2_uc_to_data, .l2_data_to_mc = rtl8365mb_c_l2_data_to_mc, .l2_mc_to_data = rtl8365mb_c_l2_mc_to_data, + .qos_iprio_to_hw = rtl8365mb_c_qos_iprio_to_hw, + .qos_hw_to_iprio = rtl8365mb_c_qos_hw_to_iprio, + .qos_set_untag_pcp = rtl8365mb_c_qos_set_untag_pcp, }; /** diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c index 5b9e1ab..b61ffdb 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_qos.c +++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c @@ -18,6 +18,7 @@ #include #include "realtek.h" +#include "rtl8365mb.h" #include "rtl8365mb_qos.h" /* The chip's eight internal priorities carry 802.1Q traffic types, one @@ -218,54 +219,113 @@ static int rtl8365mb_qos_check_port(struct realtek_priv *priv, int port) return 0; } +/* Family C stores the traffic type as the chip's priority */ +int rtl8365mb_c_qos_iprio_to_hw(u8 iprio) +{ + return iprio; +} + +int rtl8365mb_c_qos_hw_to_iprio(u8 hw) +{ + return hw; +} + +int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port, + u8 hw_prio, u8 untag_pcp) +{ + return rtl8365mb_qos_regmap_update_field(priv, + RTL8365MB_QOS_PORT_UNTAG_PCP_REG(port), + rtl8365mb_qos_sel_mask(port), + untag_pcp); +} + +/* Convert an internal priority (an 802.1Q traffic type) to the value the + * chip uses. Return the value or a negative errno. + */ +static int rtl8365mb_qos_iprio_to_hw(struct realtek_priv *priv, u8 iprio) +{ + return rtl8365mb_get_family_info(priv)->qos_iprio_to_hw(iprio); +} + +/* Convert a chip priority back to an internal priority (a traffic type) */ +static int rtl8365mb_qos_hw_to_iprio(struct realtek_priv *priv, u8 hw) +{ + return rtl8365mb_get_family_info(priv)->qos_hw_to_iprio(hw); +} + int rtl8365mb_qos_get_port_prio(struct realtek_priv *priv, int port) { - return rtl8365mb_qos_regmap_read_field(priv, - RTL8365MB_QOS_PORT_PRI_REG(port), - rtl8365mb_qos_sel_mask(port)); + int val; + + val = rtl8365mb_qos_regmap_read_field(priv, + RTL8365MB_QOS_PORT_PRI_REG(port), + rtl8365mb_qos_sel_mask(port)); + if (val < 0) + return val; + + return rtl8365mb_qos_hw_to_iprio(priv, val); } int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio, u8 untag_pcp) { - u32 untag_reg = RTL8365MB_QOS_PORT_UNTAG_PCP_REG(port); u32 reg = RTL8365MB_QOS_PORT_PRI_REG(port); u32 mask = rtl8365mb_qos_sel_mask(port); - int ret; + int hw, ret; ret = rtl8365mb_qos_check_port(priv, port); if (ret) return ret; - ret = rtl8365mb_qos_regmap_update_field(priv, untag_reg, mask, - untag_pcp); + hw = rtl8365mb_qos_iprio_to_hw(priv, iprio); + if (hw < 0) + return hw; + + ret = rtl8365mb_get_family_info(priv)->qos_set_untag_pcp(priv, port, hw, + untag_pcp); if (ret) return ret; - return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio); + return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw); } int rtl8365mb_qos_set_pcp_prio(struct realtek_priv *priv, u8 pcp, u8 iprio) { u32 reg = RTL8365MB_QOS_1Q_REMAP_REG(pcp); u32 mask = rtl8365mb_qos_sel_mask(pcp); + int hw; - return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio); + hw = rtl8365mb_qos_iprio_to_hw(priv, iprio); + if (hw < 0) + return hw; + + return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw); } int rtl8365mb_qos_get_dscp_prio(struct realtek_priv *priv, u8 dscp) { - return rtl8365mb_qos_regmap_read_field(priv, - RTL8365MB_QOS_DSCP_PRI_REG(dscp), - rtl8365mb_qos_sel_mask(dscp)); + int val; + + val = rtl8365mb_qos_regmap_read_field(priv, + RTL8365MB_QOS_DSCP_PRI_REG(dscp), + rtl8365mb_qos_sel_mask(dscp)); + if (val < 0) + return val; + + return rtl8365mb_qos_hw_to_iprio(priv, val); } int rtl8365mb_qos_set_dscp_prio(struct realtek_priv *priv, u8 dscp, u8 iprio) { u32 reg = RTL8365MB_QOS_DSCP_PRI_REG(dscp); u32 mask = rtl8365mb_qos_sel_mask(dscp); + int hw; - return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio); + hw = rtl8365mb_qos_iprio_to_hw(priv, iprio); + if (hw < 0) + return hw; + + return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw); } static int rtl8365mb_qos_set_port_qmap(struct realtek_priv *priv, int port, @@ -306,19 +366,27 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv) { unsigned int nq = priv->ds.num_tx_queues; struct dsa_port *dp; - int iprio, ret; + int prio, ret; - for (iprio = 0; iprio < RTL8365MB_NUM_INTERNAL_PRIOS; iprio++) { - int tc = ieee8021q_tt_to_tc(iprio, nq); + /* The table is indexed by the chip's priority, not by the traffic + * type. + */ + for (prio = 0; prio < RTL8365MB_NUM_INTERNAL_PRIOS; prio++) { + int tt = rtl8365mb_qos_hw_to_iprio(priv, prio); + int tc; u8 qid; + if (tt < 0) + return tt; + + tc = ieee8021q_tt_to_tc(tt, nq); if (tc < 0) return tc; qid = rtl8365mb_qos_tc_to_qid(nq, tc); ret = rtl8365mb_qos_set_qmap_qid(priv, RTL8365MB_QOS_QMAP_DEFAULT, - iprio, qid); + prio, qid); if (ret) return ret; } diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h index 9602807..d68b2bd 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_qos.h +++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h @@ -30,4 +30,10 @@ int rtl8365mb_qos_set_apptrust(struct realtek_priv *priv, int port, int rtl8365mb_qos_get_apptrust(struct realtek_priv *priv, int port, bool *trust, unsigned int n); +/* Hooks of struct rtl8365mb_family_info, one set per chip family */ +int rtl8365mb_c_qos_iprio_to_hw(u8 iprio); +int rtl8365mb_c_qos_hw_to_iprio(u8 hw); +int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port, + u8 hw_prio, u8 untag_pcp); + #endif /* _REALTEK_RTL8365MB_QOS_H */ -- 2.53.0