Add enum rtl8365mb_family and struct rtl8365mb_family_info, which holds the data shared by all chips of one family: the family id and the init jam table. Fold rtl8365mb_init_jam_common into the family C init jam table (renamed to rtl8365mb_c_init_jam) and drop the separate common jam loop from rtl8365mb_switch_init(), as family D does not use these writes. struct rtl8365mb_chip_info now points to the family info through a family_info member, and all existing chips use the RTL8365MB_FAMILY_C instance. rtl8365mb_get_family_info() and rtl8365mb_is_d() are declared in a new rtl8365mb.h so that the VLAN code can use them too. The available ports of a chip are already described by port_mask in struct rtl8365mb_chip_info, so the family info does not carry a port count. RTL8365MB_FAMILY_D is defined here but no chip uses it yet; it is needed by the following patches, which add family D handling for chips whose register layout differs from the existing ones. No functional change. Tested-by: Gustavo Foletto Mora Tested-by: Stanislaw Pal Tested-by: Oleg Gavrilov Signed-off-by: Mieczyslaw Nalewaj Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl8365mb.h | 28 ++++++++++ drivers/net/dsa/realtek/rtl8365mb_main.c | 69 ++++++++++++------------ 2 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h new file mode 100644 index 0000000..7b0c710 --- /dev/null +++ b/drivers/net/dsa/realtek/rtl8365mb.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _RTL8365MB_H +#define _RTL8365MB_H + +#include "realtek.h" + +enum rtl8365mb_family { + RTL8365MB_FAMILY_C, + RTL8365MB_FAMILY_D, +}; + +struct rtl8365mb_jam_tbl_entry; + +struct rtl8365mb_family_info { + enum rtl8365mb_family family; + const struct rtl8365mb_jam_tbl_entry *jam_table; + size_t jam_size; +}; + +const struct rtl8365mb_family_info * +rtl8365mb_get_family_info(struct realtek_priv *priv); + +static inline bool rtl8365mb_is_d(struct realtek_priv *priv) +{ + return rtl8365mb_get_family_info(priv)->family == RTL8365MB_FAMILY_D; +} + +#endif /* _RTL8365MB_H */ diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 6c11c36..19bba90 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -112,6 +112,7 @@ #include "rtl8365mb_qos.h" #include "rtl8365mb_l2.h" #include "rtl8365mb_vlan.h" +#include "rtl8365mb.h" /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7 @@ -638,20 +639,16 @@ struct rtl8365mb_jam_tbl_entry { }; /* Lifted from the vendor driver sources */ -static const struct rtl8365mb_jam_tbl_entry rtl8365mb_init_jam_8365mb_vc[] = { +static const struct rtl8365mb_jam_tbl_entry rtl8365mb_c_init_jam[] = { { 0x13EB, 0x15BB }, { 0x1303, 0x06D6 }, { 0x1304, 0x0700 }, { 0x13E2, 0x003F }, { 0x13F9, 0x0090 }, { 0x121E, 0x03CA }, { 0x1233, 0x0352 }, { 0x1237, 0x00A0 }, { 0x123A, 0x0030 }, { 0x1239, 0x0084 }, { 0x0301, 0x1000 }, { 0x1349, 0x001F }, { 0x18E0, 0x4004 }, { 0x122B, 0x241C }, { 0x1305, 0xC000 }, - { 0x13F0, 0x0000 }, -}; - -static const struct rtl8365mb_jam_tbl_entry rtl8365mb_init_jam_common[] = { - { 0x1200, 0x7FCB }, { 0x0884, 0x0003 }, { 0x06EB, 0x0001 }, - { 0x03Fa, 0x0007 }, { 0x08C8, 0x00C0 }, { 0x0A30, 0x020E }, - { 0x0800, 0x0000 }, { 0x0802, 0x0000 }, { 0x09DA, 0x0013 }, - { 0x1D32, 0x0002 }, + { 0x13F0, 0x0000 }, { 0x1200, 0x7FCB }, { 0x0884, 0x0003 }, + { 0x06EB, 0x0001 }, { 0x03Fa, 0x0007 }, { 0x08C8, 0x00C0 }, + { 0x0A30, 0x020E }, { 0x0800, 0x0000 }, { 0x0802, 0x0000 }, + { 0x09DA, 0x0013 }, { 0x1D32, 0x0002 }, }; /* SGMII SerDes tuning parameters, lifted from the vendor driver sources. The @@ -704,15 +701,20 @@ struct rtl8365mb_extint { unsigned int supported_interfaces; }; +static const struct rtl8365mb_family_info rtl8365mb_family_c = { + .family = RTL8365MB_FAMILY_C, + .jam_table = rtl8365mb_c_init_jam, + .jam_size = ARRAY_SIZE(rtl8365mb_c_init_jam), +}; + /** * struct rtl8365mb_chip_info - static chip-specific info * @name: human-readable chip name * @chip_id: chip identifier * @chip_ver: chip silicon revision * @port_mask: ports the chip has + * @family_info: data shared by all chips of the same family * @extints: available external interfaces - * @jam_table: chip-specific initialization jam table - * @jam_size: size of the chip's jam table * @num_tx_queues: number of egress queues exposed by the chip * * These data are specific to a given chip in the family of switches supported @@ -724,9 +726,8 @@ struct rtl8365mb_chip_info { u32 chip_id; u32 chip_ver; u32 port_mask; + const struct rtl8365mb_family_info *family_info; const struct rtl8365mb_extint extints[RTL8365MB_MAX_NUM_EXTINTS]; - const struct rtl8365mb_jam_tbl_entry *jam_table; - size_t jam_size; unsigned int num_tx_queues; }; @@ -746,33 +747,32 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .name = "RTL8365MB-VC", .chip_id = 0x6367, .chip_ver = 0x0040, + .family_info = &rtl8365mb_family_c, .port_mask = PORT_MASK(GENMASK(3, 0) | BIT(6)), .extints = { { 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) | PHY_INTF(RMII) | PHY_INTF(RGMII) }, }, - .jam_table = rtl8365mb_init_jam_8365mb_vc, - .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), .num_tx_queues = 8, }, { .name = "RTL8367S", .chip_id = 0x6367, .chip_ver = 0x00A0, + .family_info = &rtl8365mb_family_c, .port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)), .extints = { { 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) }, { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | PHY_INTF(RMII) | PHY_INTF(RGMII) }, }, - .jam_table = rtl8365mb_init_jam_8365mb_vc, - .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), .num_tx_queues = 8, }, { .name = "RTL8367SB", .chip_id = 0x6367, .chip_ver = 0x0010, + .family_info = &rtl8365mb_family_c, .port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)), .extints = { { 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) | @@ -781,14 +781,13 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | PHY_INTF(RMII) | PHY_INTF(RGMII) }, }, - .jam_table = rtl8365mb_init_jam_8365mb_vc, - .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), .num_tx_queues = 8, }, { .name = "RTL8367RB-VB", .chip_id = 0x6367, .chip_ver = 0x0020, + .family_info = &rtl8365mb_family_c, .port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)), .extints = { { 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) | @@ -796,8 +795,6 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | PHY_INTF(RMII) | PHY_INTF(RGMII) }, }, - .jam_table = rtl8365mb_init_jam_8365mb_vc, - .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), .num_tx_queues = 8, }, }; @@ -897,6 +894,14 @@ struct rtl8365mb { #define pcs_to_rtl8365mb(_pcs) container_of((_pcs), struct rtl8365mb, pcs) +const struct rtl8365mb_family_info * +rtl8365mb_get_family_info(struct realtek_priv *priv) +{ + struct rtl8365mb *mb = priv->chip_data; + + return mb->chip_info->family_info; +} + static int rtl8365mb_phy_poll_busy(struct realtek_priv *priv) { u32 val; @@ -3059,30 +3064,22 @@ static int rtl8365mb_change_tag_protocol(struct dsa_switch *ds, static int rtl8365mb_switch_init(struct realtek_priv *priv) { struct rtl8365mb *mb = priv->chip_data; - const struct rtl8365mb_chip_info *ci; + const struct rtl8365mb_family_info *fi; int ret; int i; - ci = mb->chip_info; + fi = mb->chip_info->family_info; - /* Do any chip-specific init jam before getting to the common stuff */ - if (ci->jam_table) { - for (i = 0; i < ci->jam_size; i++) { - ret = regmap_write(priv->map, ci->jam_table[i].reg, - ci->jam_table[i].val); + /* Do any family-specific init jam */ + if (fi->jam_table) { + for (i = 0; i < fi->jam_size; i++) { + ret = regmap_write(priv->map, fi->jam_table[i].reg, + fi->jam_table[i].val); if (ret) return ret; } } - /* Common init jam */ - for (i = 0; i < ARRAY_SIZE(rtl8365mb_init_jam_common); i++) { - ret = regmap_write(priv->map, rtl8365mb_init_jam_common[i].reg, - rtl8365mb_init_jam_common[i].val); - if (ret) - return ret; - } - return 0; } -- 2.53.0