net: dsa: realtek: MDIO interface and RTL8367S,RTL8367RB-VB
Luiz Angelo Daros de Luca
maintainerv5 cover net: dsa: realtek: MDIO interface and RTL8367S,RTL8367RB-VB
The old realtek-smi driver was linking subdrivers into a single realtek-smi.ko After this series, each subdriver will be an independent module required by either realtek-smi (platform driver) or the new realtek-mdio (mdio driver). Both interface drivers (SMI or MDIO) are independent, and they might even work side-by-side, although it will be difficult to find such device. The subdriver can be individually selected but only at buildtime, saving some storage space for custom embedded systems.
Existing realtek-smi devices continue to work untouched during the tests. The realtek-smi was moved into a realtek subdirectory, but it normally does not break things.
The rtl8365mb might now handle multiple CPU ports and extint ports not used as CPU ports. RTL8367S has an SGMII external interface, but my test device (TP-Link Archer C5v4) uses only the second RGMII interface. We need a test device with more external ports to test these features. The driver still cannot handle SGMII ports.
RTL8367RB-VB support was added using information from Frank Wunderlich <[email protected]> but I didn't test it myself.
The rtl8365mb was tested with a MDIO-connected RTL8367S (TP-Link Acher C5v4) and a SMI-connected RTL8365MB-VC switch (Asus RT-AC88U)
The rtl8366rb subdriver was not tested with this patch series, but it was only slightly touched. It would be nice to test it, especially in an MDIO-connected switch.
Best,
Luiz
Changelog:
v1-v2)
- formatting fixes
- dropped the rtl8365mb->rtl8367c rename
- other suggestions
v2-v3)
* realtek-mdio.c:
- cleanup realtek-mdio.c (BUG_ON, comments and includes)
- check devm_regmap_init return code
- removed realtek,rtl8366s string from realtek-mdio
* realtek-smi.c:
- removed void* type cast
* rtl8365mb.c:
- using macros to identify EXT interfaces
- rename some extra extport->extint cases
- allow extint as non cpu (not tested)
- allow multple cpu ports (not tested)
- dropped cpu info from struct rtl8365mb
* dropped dt-bindings changes (dealing outside this series)
* formatting issues fixed
v3-v4)
* fix cover message numbering 0/13 -> 0/11
* use static for realtek_mdio_read_reg
- Reported-by: kernel test robot <[email protected]>
* use dsa_switch_for_each_cpu_port
* mention realtek_smi_{variant,ops} to realtek_{variant,ops} in commit message
v4-v5)
- added support for RTL8367RB-VB
- cleanup mdio_{read,write}, removing misterious START_OP, checking and returning errors
- renamed priv->phy_id to priv->mdio_addr
- duplicated priv->ds_ops into ds_ops_{smi,mdio}. ds_ops_smi must not set
phy_read or else both dsa and this driver might free slave_mii.
Dropped
401fd75c92f37
- Map port to extint using code instead of device-tree property. Added comment
about port number, port description and external interfaces. Dropped 'realtek,ext-int' device-tree property
- Redacted the non-cpu ext port commit message, not highlighting the possibility of using multiple CPU ports as it was just a byproduct.
- In a possible case of multiple cpu ports, use the first one as the trap port.
Dropped 'realtek,trap-port' device-tree property
- Some formatting fixes
- BUG: rtl8365mb_phy_mode_supported was still checking for a cpu port and not
an external interface
- BUG: fix trapdoor masking for port>7. Got a compiler error with a bigger
constant value
- WARN: completed kdoc for rtl8366rb_drop_untagged()
- WARN: removed marks from incomplete kdoc
Luiz Angelo Daros de Luca
maintainerPATCH v5 1/11 net: dsa: realtek-smi: move to subdirectory
---
MAINTAINERS | 3 +--
drivers/net/dsa/Kconfig | 12 +----------
drivers/net/dsa/Makefile | 3 +--
drivers/net/dsa/realtek/Kconfig | 20 +++++++++++++++++++
drivers/net/dsa/realtek/Makefile | 3 +++
.../net/dsa/{ => realtek}/realtek-smi-core.c | 0
.../net/dsa/{ => realtek}/realtek-smi-core.h | 0
drivers/net/dsa/{ => realtek}/rtl8365mb.c | 0
drivers/net/dsa/{ => realtek}/rtl8366.c | 0
drivers/net/dsa/{ => realtek}/rtl8366rb.c | 0
10 files changed, 26 insertions(+), 15 deletions(-)
create mode 100644 drivers/net/dsa/realtek/Kconfig
create mode 100644 drivers/net/dsa/realtek/Makefile
rename drivers/net/dsa/{ => realtek}/realtek-smi-core.c (100%)
rename drivers/net/dsa/{ => realtek}/realtek-smi-core.h (100%)
rename drivers/net/dsa/{ => realtek}/rtl8365mb.c (100%)
rename drivers/net/dsa/{ => realtek}/rtl8366.c (100%)
rename drivers/net/dsa/{ => realtek}/rtl8366rb.c (100%)MAINTAINERS +1 -2
@@ -16161,8 +16161,7 @@ REALTEK RTL83xx SMI DSA ROUTER CHIPS M: Linus Walleij <[email protected]> S: Maintained F: Documentation/devicetree/bindings/net/dsa/realtek-smi.txt -F: drivers/net/dsa/realtek-smi* -F: drivers/net/dsa/rtl83* +F: drivers/net/dsa/realtek/* REALTEK WIRELESS DRIVER (rtlwifi family) M: Ping-Ke Shih <[email protected]>
drivers/net/dsa/Kconfig +1 -11
@@ -67,17 +67,7 @@ config NET_DSA_QCA8K This enables support for the Qualcomm Atheros QCA8K Ethernet switch chips. -config NET_DSA_REALTEK_SMI - tristate "Realtek SMI Ethernet switch family support" - select NET_DSA_TAG_RTL4_A - select NET_DSA_TAG_RTL8_4 - select FIXED_PHY - select IRQ_DOMAIN - select REALTEK_PHY - select REGMAP - help - This enables support for the Realtek SMI-based switch - chips, currently only RTL8366RB. +source "drivers/net/dsa/realtek/Kconfig" config NET_DSA_SMSC_LAN9303 tristate
drivers/net/dsa/Makefile +1 -2
@@ -9,8 +9,6 @@ obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o -realtek-smi-objs := realtek-smi-core.o rtl8366.o rtl8366rb.o rtl8365mb.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
@@ -23,5 +21,6 @@ obj-y += microchip/ obj-y += mv88e6xxx/ obj-y += ocelot/ obj-y += qca/ +obj-y += realtek/ obj-y += sja1105/ obj-y += xrs700x/
drivers/net/dsa/realtek/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +menuconfig NET_DSA_REALTEK + tristate "Realtek Ethernet switch family support" + depends on NET_DSA + select NET_DSA_TAG_RTL4_A + select NET_DSA_TAG_RTL8_4 + select FIXED_PHY + select IRQ_DOMAIN + select REALTEK_PHY + select REGMAP + help + Select to enable support for Realtek Ethernet switch chips. + +config NET_DSA_REALTEK_SMI + tristate "Realtek SMI connected switch driver" + depends on NET_DSA_REALTEK + default y + help + Select to enable support for registering switches connected + through SMI.
drivers/net/dsa/realtek/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-smi-objs := realtek-smi-core.o rtl8366.o rtl8366rb.o rtl8365mb.o
drivers/net/dsa/realtek/realtek-smi-core.c renamed from drivers/net/dsa/realtek-smi-core.c +0 -0
drivers/net/dsa/realtek/realtek-smi-core.h renamed from drivers/net/dsa/realtek-smi-core.h +0 -0
drivers/net/dsa/realtek/rtl8365mb.c renamed from drivers/net/dsa/rtl8365mb.c +0 -0
drivers/net/dsa/realtek/rtl8366.c renamed from drivers/net/dsa/rtl8366.c +0 -0
drivers/net/dsa/realtek/rtl8366rb.c renamed from drivers/net/dsa/rtl8366rb.c +0 -0
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 2/11 net: dsa: realtek: rename realtek_smi to realtek_priv
In reply to Luiz Angelo Daros de LucaIn preparation to adding other interfaces, the private data structure was renamed to priv. Also, realtek_smi_variant and realtek_smi_ops were renamed to realtek_variant and realtek_ops as those structs are not SMI specific.
---
drivers/net/dsa/realtek/realtek-smi-core.c | 316 +++++++-------
.../realtek/{realtek-smi-core.h => realtek.h} | 68 +--
drivers/net/dsa/realtek/rtl8365mb.c | 394 ++++++++---------
drivers/net/dsa/realtek/rtl8366.c | 164 +++----
drivers/net/dsa/realtek/rtl8366rb.c | 402 +++++++++---------
5 files changed, 672 insertions(+), 672 deletions(-)
rename drivers/net/dsa/realtek/{realtek-smi-core.h => realtek.h} (57%)drivers/net/dsa/realtek/realtek-smi-core.c +158 -158
@@ -40,105 +40,105 @@#include <linux/bitops.h> #include <linux/if_bridge.h> -#include "realtek-smi-core.h" +#include "realtek.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5#define REALTEK_SMI_HW_STOP_DELAY 25/* msecs */ #define REALTEK_SMI_HW_START_DELAY 100/* msecs */ -static inline void realtek_smi_clk_delay (struct realtek_smi *smi) +static inline void realtek_smi_clk_delay (struct realtek_priv *priv) { -ndelay (smi->clk_delay); +ndelay (priv->clk_delay); } -static void realtek_smi_start (struct realtek_smi *smi) +static void realtek_smi_start (struct realtek_priv *priv) {/* Set GPIO pins to output mode, with initial state: * SCK = 0, SDA = 1 */ -gpiod_direction_output (smi->mdc,0 ); -gpiod_direction_output (smi->mdio,1 ); -realtek_smi_clk_delay (smi); +gpiod_direction_output (priv->mdc,0 ); +gpiod_direction_output (priv->mdio,1 ); +realtek_smi_clk_delay (priv);/* CLK 1: 0 -> 1, 1 -> 0 */ -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,0 ); -realtek_smi_clk_delay (smi); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,0 ); +realtek_smi_clk_delay (priv);/* CLK 2: */ -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdio,0 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,0 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdio,1 ); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdio,0 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,0 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdio,1 ); } -static void realtek_smi_stop (struct realtek_smi *smi) +static void realtek_smi_stop (struct realtek_priv *priv) { -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdio,0 ); -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdio,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,0 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdio,0 ); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdio,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,0 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,1 );/* Add a click */ -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,0 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,0 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,1 );/* Set GPIO pins to input mode */ -gpiod_direction_input (smi->mdio); -gpiod_direction_input (smi->mdc); +gpiod_direction_input (priv->mdio); +gpiod_direction_input (priv->mdc); } -static void realtek_smi_write_bits (struct realtek_smi *smi,u32 data,u32 len) +static void realtek_smi_write_bits (struct realtek_priv *priv,u32 data,u32 len) {for (; len >0 ; len--) { -realtek_smi_clk_delay (smi); +realtek_smi_clk_delay (priv);/* Prepare data */ -gpiod_set_value (smi->mdio, !!(data & (1 << (len -1 )))); -realtek_smi_clk_delay (smi); +gpiod_set_value (priv->mdio, !!(data & (1 << (len -1 )))); +realtek_smi_clk_delay (priv);/* Clocking */ -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); -gpiod_set_value (smi->mdc,0 ); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); +gpiod_set_value (priv->mdc,0 ); } } -static void realtek_smi_read_bits (struct realtek_smi *smi,u32 len,u32 *data) +static void realtek_smi_read_bits (struct realtek_priv *priv,u32 len,u32 *data) { -gpiod_direction_input (smi->mdio); +gpiod_direction_input (priv->mdio);for (*data =0 ; len >0 ; len--) {u32 u; -realtek_smi_clk_delay (smi); +realtek_smi_clk_delay (priv);/* Clocking */ -gpiod_set_value (smi->mdc,1 ); -realtek_smi_clk_delay (smi); - u = !!gpiod_get_value (smi->mdio); -gpiod_set_value (smi->mdc,0 ); +gpiod_set_value (priv->mdc,1 ); +realtek_smi_clk_delay (priv); + u = !!gpiod_get_value (priv->mdio); +gpiod_set_value (priv->mdc,0 ); *data |= (u << (len -1 )); } -gpiod_direction_output (smi->mdio,0 ); +gpiod_direction_output (priv->mdio,0 ); } -static int realtek_smi_wait_for_ack (struct realtek_smi *smi) +static int realtek_smi_wait_for_ack (struct realtek_priv *priv) {int retry_cnt;
@@ -146,12 +146,12 @@ static int realtek_smi_wait_for_ack(struct realtek_smi *smi)do {u32 ack; -realtek_smi_read_bits (smi,1 , &ack); +realtek_smi_read_bits (priv,1 , &ack);if (ack ==0 )break ;if (++retry_cnt >REALTEK_SMI_ACK_RETRY_COUNT ) { -dev_err (smi->dev,"ACK timeout\n" ); +dev_err (priv->dev,"ACK timeout\n" );return -ETIMEDOUT ; } }while (1 );
@@ -159,131 +159,131 @@ static int realtek_smi_wait_for_ack(struct realtek_smi *smi)return 0 ; } -static int realtek_smi_write_byte (struct realtek_smi *smi,u8 data) +static int realtek_smi_write_byte (struct realtek_priv *priv,u8 data) { -realtek_smi_write_bits (smi, data,8 ); -return realtek_smi_wait_for_ack (smi); +realtek_smi_write_bits (priv, data,8 ); +return realtek_smi_wait_for_ack (priv); } -static int realtek_smi_write_byte_noack (struct realtek_smi *smi,u8 data) +static int realtek_smi_write_byte_noack (struct realtek_priv *priv,u8 data) { -realtek_smi_write_bits (smi, data,8 ); +realtek_smi_write_bits (priv, data,8 );return 0 ; } -static int realtek_smi_read_byte0 (struct realtek_smi *smi,u8 *data) +static int realtek_smi_read_byte0 (struct realtek_priv *priv,u8 *data) {u32 t;/* Read data */ -realtek_smi_read_bits (smi,8 , &t); +realtek_smi_read_bits (priv,8 , &t); *data = (t &0xff );/* Send an ACK */ -realtek_smi_write_bits (smi,0x00 ,1 ); +realtek_smi_write_bits (priv,0x00 ,1 );return 0 ; } -static int realtek_smi_read_byte1 (struct realtek_smi *smi,u8 *data) +static int realtek_smi_read_byte1 (struct realtek_priv *priv,u8 *data) {u32 t;/* Read data */ -realtek_smi_read_bits (smi,8 , &t); +realtek_smi_read_bits (priv,8 , &t); *data = (t &0xff );/* Send an ACK */ -realtek_smi_write_bits (smi,0x01 ,1 ); +realtek_smi_write_bits (priv,0x01 ,1 );return 0 ; } -static int realtek_smi_read_reg (struct realtek_smi *smi,u32 addr,u32 *data) +static int realtek_smi_read_reg (struct realtek_priv *priv,u32 addr,u32 *data) {unsigned long flags;u8 lo =0 ;u8 hi =0 ;int ret; -spin_lock_irqsave (&smi->lock, flags); +spin_lock_irqsave (&priv->lock, flags); -realtek_smi_start (smi); +realtek_smi_start (priv);/* Send READ command */ - ret =realtek_smi_write_byte (smi, smi->cmd_read); + ret =realtek_smi_write_byte (priv, priv->cmd_read);if (ret) goto out;/* Set ADDR[7:0] */ - ret =realtek_smi_write_byte (smi, addr &0xff ); + ret =realtek_smi_write_byte (priv, addr &0xff );if (ret) goto out;/* Set ADDR[15:8] */ - ret =realtek_smi_write_byte (smi, addr >>8 ); + ret =realtek_smi_write_byte (priv, addr >>8 );if (ret) goto out;/* Read DATA[7:0] */ -realtek_smi_read_byte0 (smi, &lo); +realtek_smi_read_byte0 (priv, &lo);/* Read DATA[15:8] */ -realtek_smi_read_byte1 (smi, &hi); +realtek_smi_read_byte1 (priv, &hi); *data = ((u32 )lo) | (((u32 )hi) <<8 ); ret =0 ; out: -realtek_smi_stop (smi); -spin_unlock_irqrestore (&smi->lock, flags); +realtek_smi_stop (priv); +spin_unlock_irqrestore (&priv->lock, flags);return ret; } -static int realtek_smi_write_reg (struct realtek_smi *smi, +static int realtek_smi_write_reg (struct realtek_priv *priv,u32 addr,u32 data,bool ack) {unsigned long flags;int ret; -spin_lock_irqsave (&smi->lock, flags); +spin_lock_irqsave (&priv->lock, flags); -realtek_smi_start (smi); +realtek_smi_start (priv);/* Send WRITE command */ - ret =realtek_smi_write_byte (smi, smi->cmd_write); + ret =realtek_smi_write_byte (priv, priv->cmd_write);if (ret) goto out;/* Set ADDR[7:0] */ - ret =realtek_smi_write_byte (smi, addr &0xff ); + ret =realtek_smi_write_byte (priv, addr &0xff );if (ret) goto out;/* Set ADDR[15:8] */ - ret =realtek_smi_write_byte (smi, addr >>8 ); + ret =realtek_smi_write_byte (priv, addr >>8 );if (ret) goto out;/* Write DATA[7:0] */ - ret =realtek_smi_write_byte (smi, data &0xff ); + ret =realtek_smi_write_byte (priv, data &0xff );if (ret) goto out;/* Write DATA[15:8] */ if (ack) - ret =realtek_smi_write_byte (smi, data >>8 ); + ret =realtek_smi_write_byte (priv, data >>8 );else - ret =realtek_smi_write_byte_noack (smi, data >>8 ); + ret =realtek_smi_write_byte_noack (priv, data >>8 );if (ret) goto out; ret =0 ; out: -realtek_smi_stop (smi); -spin_unlock_irqrestore (&smi->lock, flags); +realtek_smi_stop (priv); +spin_unlock_irqrestore (&priv->lock, flags);return ret; }
@@ -292,10 +292,10 @@ static int realtek_smi_write_reg(struct realtek_smi *smi,* is when issueing soft reset. Since the device reset as soon as we write * that bit, no ACK will come back for natural reasons. */ -int realtek_smi_write_reg_noack (struct realtek_smi *smi,u32 addr, +int realtek_smi_write_reg_noack (struct realtek_priv *priv,u32 addr,u32 data) { -return realtek_smi_write_reg (smi, addr, data, false); +return realtek_smi_write_reg (priv, addr, data, false); }EXPORT_SYMBOL_GPL (realtek_smi_write_reg_noack);
@@ -303,16 +303,16 @@ EXPORT_SYMBOL_GPL(realtek_smi_write_reg_noack);static int realtek_smi_write (void *ctx,u32 reg,u32 val) { -struct realtek_smi *smi = ctx; +struct realtek_priv *priv = ctx; -return realtek_smi_write_reg (smi, reg, val, true); +return realtek_smi_write_reg (priv, reg, val, true); }static int realtek_smi_read (void *ctx,u32 reg,u32 *val) { -struct realtek_smi *smi = ctx; +struct realtek_priv *priv = ctx; -return realtek_smi_read_reg (smi, reg, val); +return realtek_smi_read_reg (priv, reg, val); }static const struct regmap_config realtek_smi_mdio_regmap_config = {
@@ -329,49 +329,49 @@ static const struct regmap_config realtek_smi_mdio_regmap_config = {static int realtek_smi_mdio_read (struct mii_bus *bus,int addr,int regnum) { -struct realtek_smi *smi = bus->priv; +struct realtek_priv *priv = bus->priv; -return smi->ops->phy_read (smi, addr, regnum); +return priv->ops->phy_read (priv, addr, regnum); }static int realtek_smi_mdio_write (struct mii_bus *bus,int addr,int regnum,u16 val) { -struct realtek_smi *smi = bus->priv; +struct realtek_priv *priv = bus->priv; -return smi->ops->phy_write (smi, addr, regnum, val); +return priv->ops->phy_write (priv, addr, regnum, val); } -int realtek_smi_setup_mdio (struct realtek_smi *smi) +int realtek_smi_setup_mdio (struct realtek_priv *priv) {struct device_node *mdio_np;int ret; - mdio_np =of_get_compatible_child (smi->dev->of_node,"realtek,smi-mdio" ); + mdio_np =of_get_compatible_child (priv->dev->of_node,"realtek,smi-mdio" );if (!mdio_np) { -dev_err (smi->dev,"no MDIO bus node\n" ); +dev_err (priv->dev,"no MDIO bus node\n" );return -ENODEV ; } - smi->slave_mii_bus =devm_mdiobus_alloc (smi->dev); -if (!smi->slave_mii_bus) { + priv->slave_mii_bus =devm_mdiobus_alloc (priv->dev); +if (!priv->slave_mii_bus) { ret = -ENOMEM ; goto err_put_node; } - smi->slave_mii_bus->priv = smi; - smi->slave_mii_bus->name ="SMI slave MII" ; - smi->slave_mii_bus->read = realtek_smi_mdio_read; - smi->slave_mii_bus->write = realtek_smi_mdio_write; -snprintf (smi->slave_mii_bus->id,MII_BUS_ID_SIZE ,"SMI-%d" , - smi->ds->index); - smi->slave_mii_bus->dev.of_node = mdio_np; - smi->slave_mii_bus->parent = smi->dev; - smi->ds->slave_mii_bus = smi->slave_mii_bus; - - ret =devm_of_mdiobus_register (smi->dev, smi->slave_mii_bus, mdio_np); + priv->slave_mii_bus->priv = priv; + priv->slave_mii_bus->name ="SMI slave MII" ; + priv->slave_mii_bus->read = realtek_smi_mdio_read; + priv->slave_mii_bus->write = realtek_smi_mdio_write; +snprintf (priv->slave_mii_bus->id,MII_BUS_ID_SIZE ,"SMI-%d" , + priv->ds->index); + priv->slave_mii_bus->dev.of_node = mdio_np; + priv->slave_mii_bus->parent = priv->dev; + priv->ds->slave_mii_bus = priv->slave_mii_bus; + + ret =devm_of_mdiobus_register (priv->dev, priv->slave_mii_bus, mdio_np);if (ret) { -dev_err (smi->dev,"unable to register MDIO bus %s\n" , - smi->slave_mii_bus->id); +dev_err (priv->dev,"unable to register MDIO bus %s\n" , + priv->slave_mii_bus->id); goto err_put_node; }
@@ -385,76 +385,76 @@ int realtek_smi_setup_mdio(struct realtek_smi *smi)static int realtek_smi_probe (struct platform_device *pdev) { -const struct realtek_smi_variant *var; +const struct realtek_variant *var;struct device *dev = &pdev->dev; -struct realtek_smi *smi; +struct realtek_priv *priv;struct device_node *np;int ret; var =of_device_get_match_data (dev); np = dev->of_node; - smi =devm_kzalloc (dev,sizeof (*smi) + var->chip_data_sz,GFP_KERNEL ); -if (!smi) + priv =devm_kzalloc (dev,sizeof (*priv) + var->chip_data_sz,GFP_KERNEL ); +if (!priv)return -ENOMEM ; - smi->chip_data = (void *)smi +sizeof (*smi); - smi->map =devm_regmap_init (dev,NULL , smi, - &realtek_smi_mdio_regmap_config); -if (IS_ERR (smi->map)) { - ret =PTR_ERR (smi->map); + priv->chip_data = (void *)priv +sizeof (*priv); + priv->map =devm_regmap_init (dev,NULL , priv, + &realtek_smi_mdio_regmap_config); +if (IS_ERR (priv->map)) { + ret =PTR_ERR (priv->map);dev_err (dev,"regmap init failed: %d\n" , ret);return ret; }/* Link forward and backward */ - smi->dev = dev; - smi->clk_delay = var->clk_delay; - smi->cmd_read = var->cmd_read; - smi->cmd_write = var->cmd_write; - smi->ops = var->ops; + priv->dev = dev; + priv->clk_delay = var->clk_delay; + priv->cmd_read = var->cmd_read; + priv->cmd_write = var->cmd_write; + priv->ops = var->ops; -dev_set_drvdata (dev, smi); -spin_lock_init (&smi->lock); +dev_set_drvdata (dev, priv); +spin_lock_init (&priv->lock);/* TODO: if power is software controlled, set up any regulators here */ /* Assert then deassert RESET */ - smi->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); -if (IS_ERR (smi->reset)) { + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (priv->reset)) {dev_err (dev,"failed to get RESET GPIO\n" ); -return PTR_ERR (smi->reset); +return PTR_ERR (priv->reset); }msleep (REALTEK_SMI_HW_STOP_DELAY ); -gpiod_set_value (smi->reset,0 ); +gpiod_set_value (priv->reset,0 );msleep (REALTEK_SMI_HW_START_DELAY );dev_info (dev,"deasserted RESET\n" );/* Fetch MDIO pins */ - smi->mdc =devm_gpiod_get_optional (dev,"mdc" ,GPIOD_OUT_LOW ); -if (IS_ERR (smi->mdc)) -return PTR_ERR (smi->mdc); - smi->mdio =devm_gpiod_get_optional (dev,"mdio" ,GPIOD_OUT_LOW ); -if (IS_ERR (smi->mdio)) -return PTR_ERR (smi->mdio); + priv->mdc =devm_gpiod_get_optional (dev,"mdc" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->mdc)) +return PTR_ERR (priv->mdc); + priv->mdio =devm_gpiod_get_optional (dev,"mdio" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->mdio)) +return PTR_ERR (priv->mdio); - smi->leds_disabled =of_property_read_bool (np,"realtek,disable-leds" ); + priv->leds_disabled =of_property_read_bool (np,"realtek,disable-leds" ); - ret = smi->ops->detect (smi); + ret = priv->ops->detect (priv);if (ret) {dev_err (dev,"unable to detect switch\n" );return ret; } - smi->ds =devm_kzalloc (dev,sizeof (*smi->ds),GFP_KERNEL ); -if (!smi->ds) + priv->ds =devm_kzalloc (dev,sizeof (*priv->ds),GFP_KERNEL ); +if (!priv->ds)return -ENOMEM ; - smi->ds->dev = dev; - smi->ds->num_ports = smi->num_ports; - smi->ds->priv = smi; + priv->ds->dev = dev; + priv->ds->num_ports = priv->num_ports; + priv->ds->priv = priv; - smi->ds->ops = var->ds_ops; - ret =dsa_register_switch (smi->ds); + priv->ds->ops = var->ds_ops; + ret =dsa_register_switch (priv->ds);if (ret) {dev_err_probe (dev, ret,"unable to register switch\n" );return ret;
@@ -464,15 +464,15 @@ static int realtek_smi_probe(struct platform_device *pdev)static int realtek_smi_remove (struct platform_device *pdev) { -struct realtek_smi *smi =platform_get_drvdata (pdev); +struct realtek_priv *priv =platform_get_drvdata (pdev); -if (!smi) +if (!priv)return 0 ; -dsa_unregister_switch (smi->ds); -if (smi->slave_mii_bus) -of_node_put (smi->slave_mii_bus->dev.of_node); -gpiod_set_value (smi->reset,1 ); +dsa_unregister_switch (priv->ds); +if (priv->slave_mii_bus) +of_node_put (priv->slave_mii_bus->dev.of_node); +gpiod_set_value (priv->reset,1 );platform_set_drvdata (pdev,NULL );
@@ -481,12 +481,12 @@ static int realtek_smi_remove(struct platform_device *pdev)static void realtek_smi_shutdown (struct platform_device *pdev) { -struct realtek_smi *smi =platform_get_drvdata (pdev); +struct realtek_priv *priv =platform_get_drvdata (pdev); -if (!smi) +if (!priv)return ; -dsa_switch_shutdown (smi->ds); +dsa_switch_shutdown (priv->ds);platform_set_drvdata (pdev,NULL ); }
drivers/net/dsa/realtek/realtek.h renamed from drivers/net/dsa/realtek/realtek-smi-core.h +34 -34
121 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8365mb.c +197 -197
1,160 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8366.c +82 -82
452 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8366rb.c +201 -201
683 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Luiz Angelo Daros de Luca
maintainerPATCH v5 3/11 net: dsa: realtek: remove direct calls to realtek-smi
In reply to Luiz Angelo Daros de LucaRemove the only two direct calls from subdrivers to realtek-smi. Now they are called from realtek_priv. Subdrivers can now be linked independently from realtek-smi.
--- drivers/net/dsa/realtek/realtek-smi-core.c | 15 +++++++++------ drivers/net/dsa/realtek/realtek.h | 7 ++----- drivers/net/dsa/realtek/rtl8365mb.c | 12 +++++++----- drivers/net/dsa/realtek/rtl8366rb.c | 12 +++++++----- 4 files changed, 25 insertions(+), 21 deletions(-)
drivers/net/dsa/realtek/realtek-smi-core.c +9 -6
@@ -292,12 +292,11 @@ static int realtek_smi_write_reg(struct realtek_priv *priv,* is when issueing soft reset. Since the device reset as soon as we write * that bit, no ACK will come back for natural reasons. */ -int realtek_smi_write_reg_noack (struct realtek_priv *priv,u32 addr, -u32 data) +static int realtek_smi_write_reg_noack (struct realtek_priv *priv,u32 addr, +u32 data) {return realtek_smi_write_reg (priv, addr, data, false); } -EXPORT_SYMBOL_GPL (realtek_smi_write_reg_noack);/* Regmap accessors */
@@ -342,8 +341,9 @@ static int realtek_smi_mdio_write(struct mii_bus *bus, int addr, int regnum,return priv->ops->phy_write (priv, addr, regnum, val); } -int realtek_smi_setup_mdio (struct realtek_priv *priv) +static int realtek_smi_setup_mdio (struct dsa_switch *ds) { +struct realtek_priv *priv = ds->priv;struct device_node *mdio_np;int ret;
@@ -363,10 +363,10 @@ int realtek_smi_setup_mdio(struct realtek_priv *priv) priv->slave_mii_bus->read = realtek_smi_mdio_read; priv->slave_mii_bus->write = realtek_smi_mdio_write;snprintf (priv->slave_mii_bus->id,MII_BUS_ID_SIZE ,"SMI-%d" , - priv->ds->index); + ds->index); priv->slave_mii_bus->dev.of_node = mdio_np; priv->slave_mii_bus->parent = priv->dev; - priv->ds->slave_mii_bus = priv->slave_mii_bus; + ds->slave_mii_bus = priv->slave_mii_bus; ret =devm_of_mdiobus_register (priv->dev, priv->slave_mii_bus, mdio_np);if (ret) {
@@ -413,6 +413,9 @@ static int realtek_smi_probe(struct platform_device *pdev) priv->cmd_write = var->cmd_write; priv->ops = var->ops; + priv->setup_interface = realtek_smi_setup_mdio; + priv->write_reg_noack = realtek_smi_write_reg_noack; +dev_set_drvdata (dev, priv);spin_lock_init (&priv->lock);
drivers/net/dsa/realtek/realtek.h +2 -5
@@ -66,6 +66,8 @@ struct realtek_priv {struct rtl8366_mib_counter *mib_counters;const struct realtek_ops *ops; +int (*setup_interface)(struct dsa_switch *ds); +int (*write_reg_noack)(struct realtek_priv *priv,u32 addr,u32 data);int vlan_enabled;int vlan4k_enabled;
@@ -115,11 +117,6 @@ struct realtek_variant {size_t chip_data_sz; }; -/* SMI core calls */ -int realtek_smi_write_reg_noack (struct realtek_priv *priv,u32 addr, -u32 data); -int realtek_smi_setup_mdio (struct realtek_priv *priv); -/* RTL8366 library helpers */ int rtl8366_mc_is_used (struct realtek_priv *priv,int mc_index,int *used); int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member,
drivers/net/dsa/realtek/rtl8365mb.c +7 -5
@@ -1767,7 +1767,7 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv) {u32 val; -realtek_smi_write_reg_noack (priv,RTL8365MB_CHIP_RESET_REG , + priv->write_reg_noack (priv,RTL8365MB_CHIP_RESET_REG ,FIELD_PREP (RTL8365MB_CHIP_RESET_HW_MASK ,1 ));
@@ -1849,10 +1849,12 @@ static int rtl8365mb_setup(struct dsa_switch *ds)if (ret) goto out_teardown_irq; - ret =realtek_smi_setup_mdio (priv); -if (ret) { -dev_err (priv->dev,"could not set up MDIO bus\n" ); - goto out_teardown_irq; +if (priv->setup_interface) { + ret = priv->setup_interface (ds); +if (ret) { +dev_err (priv->dev,"could not set up MDIO bus\n" ); + goto out_teardown_irq; + } }/* Start statistics counter polling */
drivers/net/dsa/realtek/rtl8366rb.c +7 -5
@@ -1030,10 +1030,12 @@ static int rtl8366rb_setup(struct dsa_switch *ds)if (ret)dev_info (priv->dev,"no interrupt support\n" ); - ret =realtek_smi_setup_mdio (priv); -if (ret) { -dev_info (priv->dev,"could not set up MDIO bus\n" ); -return -ENODEV ; +if (priv->setup_interface) { + ret = priv->setup_interface (ds); +if (ret) { +dev_err (priv->dev,"could not set up MDIO bus\n" ); +return -ENODEV ; + } }return 0 ;
@@ -1705,7 +1707,7 @@ static int rtl8366rb_reset_chip(struct realtek_priv *priv)u32 val;int ret; -realtek_smi_write_reg_noack (priv,RTL8366RB_RESET_CTRL_REG , + priv->write_reg_noack (priv,RTL8366RB_RESET_CTRL_REG ,RTL8366RB_CHIP_CTRL_RESET_HW ); do { usleep_range(20000, 25000);
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 4/11 net: dsa: realtek: convert subdrivers into modules
In reply to Luiz Angelo Daros de LucaPreparing for multiple interfaces support, the drivers must be independent of realtek-smi.
---
drivers/net/dsa/realtek/Kconfig | 20 +++++++++++++++++--
drivers/net/dsa/realtek/Makefile | 4 +++-
.../{realtek-smi-core.c => realtek-smi.c} | 6 ++++++
drivers/net/dsa/realtek/rtl8365mb.c | 4 ++++
.../dsa/realtek/{rtl8366.c => rtl8366-core.c} | 0
drivers/net/dsa/realtek/rtl8366rb.c | 4 ++++
6 files changed, 35 insertions(+), 3 deletions(-)
rename drivers/net/dsa/realtek/{realtek-smi-core.c => realtek-smi.c} (97%)
rename drivers/net/dsa/realtek/{rtl8366.c => rtl8366-core.c} (100%)drivers/net/dsa/realtek/Kconfig +18 -2
@@ -2,8 +2,6 @@ menuconfig NET_DSA_REALTEK tristate "Realtek Ethernet switch family support" depends on NET_DSA - select NET_DSA_TAG_RTL4_A - select NET_DSA_TAG_RTL8_4 select FIXED_PHY select IRQ_DOMAIN select REALTEK_PHY
@@ -18,3 +16,21 @@ config NET_DSA_REALTEK_SMI help Select to enable support for registering switches connected through SMI. + +config NET_DSA_REALTEK_RTL8365MB + tristate "Realtek RTL8365MB switch subdriver" + default y + depends on NET_DSA_REALTEK + depends on NET_DSA_REALTEK_SMI + select NET_DSA_TAG_RTL8_4 + help + Select to enable support for Realtek RTL8365MB + +config NET_DSA_REALTEK_RTL8366RB + tristate "Realtek RTL8366RB switch subdriver" + default y + depends on NET_DSA_REALTEK + depends on NET_DSA_REALTEK_SMI + select NET_DSA_TAG_RTL4_A + help + Select to enable support for Realtek RTL8366RB
drivers/net/dsa/realtek/Makefile +3 -1
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o -realtek-smi-objs := realtek-smi-core.o rtl8366.o rtl8366rb.o rtl8365mb.o +obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o +rtl8366-objs := rtl8366-core.o rtl8366rb.o +obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
drivers/net/dsa/realtek/realtek-smi.c renamed from drivers/net/dsa/realtek/realtek-smi-core.c +6 -0
@@ -495,19 +495,23 @@ static void realtek_smi_shutdown(struct platform_device *pdev) }static const struct of_device_id realtek_smi_of_match[] = { +#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB) { .compatible ="realtek,rtl8366rb" , .data = &rtl8366rb_variant, }, +#endif {/* FIXME: add support for RTL8366S and more */ .compatible ="realtek,rtl8366s" , .data =NULL , }, +#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) { .compatible ="realtek,rtl8365mb" , .data = &rtl8365mb_variant, }, +#endif {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, realtek_smi_of_match);
@@ -523,4 +527,6 @@ static struct platform_driver realtek_smi_driver = { };module_platform_driver (realtek_smi_driver); +MODULE_AUTHOR ("Linus Walleij <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for Realtek ethernet switch connected via SMI interface" );MODULE_LICENSE ("GPL" );
drivers/net/dsa/realtek/rtl8365mb.c +4 -0
@@ -1987,3 +1987,7 @@ const struct realtek_variant rtl8365mb_variant = { .chip_data_sz = sizeof(struct rtl8365mb), };EXPORT_SYMBOL_GPL (rtl8365mb_variant); + +MODULE_AUTHOR ("Alvin Šipraga <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for RTL8365MB-VC ethernet switch" ); +MODULE_LICENSE ("GPL" );
drivers/net/dsa/realtek/rtl8366-core.c renamed from drivers/net/dsa/realtek/rtl8366.c +0 -0
drivers/net/dsa/realtek/rtl8366rb.c +4 -0
@@ -1814,3 +1814,7 @@ const struct realtek_variant rtl8366rb_variant = { .chip_data_sz = sizeof(struct rtl8366rb), };EXPORT_SYMBOL_GPL (rtl8366rb_variant); + +MODULE_AUTHOR ("Linus Walleij <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for RTL8366RB ethernet switch" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 5/11 net: dsa: realtek: use phy_read in ds->ops
In reply to Luiz Angelo Daros de LucaThe ds->ops->phy_read will only be used if the ds->slave_mii_bus was not initialized. Calling realtek_smi_setup_mdio will create a ds->slave_mii_bus, making ds->ops->phy_read dormant.
Using ds->ops->phy_read will allow switches connected through non-SMI interfaces (like mdio) to let ds allocate slave_mii_bus and reuse the same code.
--- drivers/net/dsa/realtek/realtek-smi.c | 6 ++++-- drivers/net/dsa/realtek/realtek.h | 3 --- drivers/net/dsa/realtek/rtl8365mb.c | 10 ++++++---- drivers/net/dsa/realtek/rtl8366rb.c | 10 ++++++---- 4 files changed, 16 insertions(+), 13 deletions(-)
drivers/net/dsa/realtek/realtek-smi.c +4 -2
@@ -329,16 +329,18 @@ static const struct regmap_config realtek_smi_mdio_regmap_config = {static int realtek_smi_mdio_read (struct mii_bus *bus,int addr,int regnum) {struct realtek_priv *priv = bus->priv; +struct dsa_switch *ds = priv->ds; -return priv->ops->phy_read (priv, addr, regnum); +return ds->ops->phy_read (ds, addr, regnum); }static int realtek_smi_mdio_write (struct mii_bus *bus,int addr,int regnum,u16 val) {struct realtek_priv *priv = bus->priv; +struct dsa_switch *ds = priv->ds; -return priv->ops->phy_write (priv, addr, regnum, val); +return ds->ops->phy_write (ds, addr, regnum, val); }static int realtek_smi_setup_mdio (struct dsa_switch *ds)
drivers/net/dsa/realtek/realtek.h +0 -3
@@ -103,9 +103,6 @@ struct realtek_ops {int (*enable_vlan)(struct realtek_priv *priv,bool enable);int (*enable_vlan4k)(struct realtek_priv *priv,bool enable);int (*enable_port)(struct realtek_priv *priv,int port,bool enable); -int (*phy_read)(struct realtek_priv *priv,int phy,int regnum); -int (*phy_write)(struct realtek_priv *priv,int phy,int regnum, -u16 val); };struct realtek_variant {
drivers/net/dsa/realtek/rtl8365mb.c +6 -4
@@ -674,8 +674,9 @@ static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy,return 0 ; } -static int rtl8365mb_phy_read (struct realtek_priv *priv,int phy,int regnum) +static int rtl8365mb_phy_read (struct dsa_switch *ds,int phy,int regnum) { +struct realtek_priv *priv = ds->priv;u32 ocp_addr;u16 val;int ret;
@@ -702,9 +703,10 @@ static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)return val; } -static int rtl8365mb_phy_write (struct realtek_priv *priv,int phy,int regnum, +static int rtl8365mb_phy_write (struct dsa_switch *ds,int phy,int regnum,u16 val) { +struct realtek_priv *priv = (struct realtek_priv *)ds->priv;u32 ocp_addr;int ret;
@@ -1958,6 +1960,8 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .setup = rtl8365mb_setup, .teardown = rtl8365mb_teardown, + .phy_read = rtl8365mb_phy_read, + .phy_write = rtl8365mb_phy_write, .phylink_validate = rtl8365mb_phylink_validate, .phylink_mac_config = rtl8365mb_phylink_mac_config, .phylink_mac_link_down = rtl8365mb_phylink_mac_link_down,
@@ -1974,8 +1978,6 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = {static const struct realtek_ops rtl8365mb_ops = { .detect = rtl8365mb_detect, - .phy_read = rtl8365mb_phy_read, - .phy_write = rtl8365mb_phy_write, };const struct realtek_variant rtl8365mb_variant = {
drivers/net/dsa/realtek/rtl8366rb.c +6 -4
@@ -1641,8 +1641,9 @@ static int rtl8366rb_enable_vlan4k(struct realtek_priv *priv, bool enable) enable ? RTL8366RB_SGCR_EN_VLAN_4KTB : 0); } -static int rtl8366rb_phy_read (struct realtek_priv *priv,int phy,int regnum) +static int rtl8366rb_phy_read (struct dsa_switch *ds,int phy,int regnum) { +struct realtek_priv *priv = ds->priv;u32 val;u32 reg;int ret;
@@ -1675,9 +1676,10 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)return val; } -static int rtl8366rb_phy_write (struct realtek_priv *priv,int phy,int regnum, +static int rtl8366rb_phy_write (struct dsa_switch *ds,int phy,int regnum,u16 val) { +struct realtek_priv *priv = ds->priv;u32 reg;int ret;
@@ -1769,6 +1771,8 @@ static int rtl8366rb_detect(struct realtek_priv *priv)static const struct dsa_switch_ops rtl8366rb_switch_ops = { .get_tag_protocol = rtl8366_get_tag_protocol, .setup = rtl8366rb_setup, + .phy_read = rtl8366rb_phy_read, + .phy_write = rtl8366rb_phy_write, .phylink_mac_link_up = rtl8366rb_mac_link_up, .phylink_mac_link_down = rtl8366rb_mac_link_down, .get_strings = rtl8366_get_strings,
@@ -1801,8 +1805,6 @@ static const struct realtek_ops rtl8366rb_ops = { .is_vlan_valid = rtl8366rb_is_vlan_valid, .enable_vlan = rtl8366rb_enable_vlan, .enable_vlan4k = rtl8366rb_enable_vlan4k, - .phy_read = rtl8366rb_phy_read, - .phy_write = rtl8366rb_phy_write, };const struct realtek_variant rtl8366rb_variant = {
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 6/11 net: dsa: realtek: add new mdio interface for drivers
In reply to Luiz Angelo Daros de LucaThis driver is a mdio_driver instead of a platform driver (like realtek-smi).
--- drivers/net/dsa/realtek/Kconfig | 11 +- drivers/net/dsa/realtek/Makefile | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 221 +++++++++++++++++++++++++ drivers/net/dsa/realtek/realtek.h | 2 + 4 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-mdio.c
drivers/net/dsa/realtek/Kconfig +9 -2
@@ -9,6 +9,13 @@ menuconfig NET_DSA_REALTEK help Select to enable support for Realtek Ethernet switch chips. +config NET_DSA_REALTEK_MDIO + tristate "Realtek MDIO connected switch driver" + depends on NET_DSA_REALTEK + default y + help + Select to enable support for registering switches configured + through MDIO. config NET_DSA_REALTEK_SMI tristate "Realtek SMI connected switch driver" depends on NET_DSA_REALTEK
@@ -21,7 +28,7 @@ config NET_DSA_REALTEK_RTL8365MB tristate "Realtek RTL8365MB switch subdriver" default y depends on NET_DSA_REALTEK - depends on NET_DSA_REALTEK_SMI + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL8_4 help Select to enable support for Realtek RTL8365MB
@@ -30,7 +37,7 @@ config NET_DSA_REALTEK_RTL8366RB tristate "Realtek RTL8366RB switch subdriver" default y depends on NET_DSA_REALTEK - depends on NET_DSA_REALTEK_SMI + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL4_A help Select to enable support for Realtek RTL8366RB
drivers/net/dsa/realtek/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o
drivers/net/dsa/realtek/realtek-mdio.c new file +221 -0
221 lines not on this page · raw message
drivers/net/dsa/realtek/realtek.h +2 -0
@@ -50,6 +50,8 @@ struct realtek_priv {struct gpio_desc *mdio;struct regmap *map;struct mii_bus *slave_mii_bus; +struct mii_bus *bus; +int phy_id;unsigned int clk_delay;u8 cmd_read;
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 7/11 net: dsa: realtek: rtl8365mb: rename extport to extint, add "realtek,ext-int"
In reply to Luiz Angelo Daros de Luca"extport" 0, 1, 2 was used to reference external ports (ext0, ext1, ext2). Meanwhile, port 0..9 is used as switch ports, including external ports. "extport" was renamed to extint to make it clear it does not mean the port number but the external interface number.
The macros that map extint numbers to registers addresses now use inline ifs instead of binary arithmetic.
"extint" was hardcoded to 1. However, some chips have multiple external interfaces. It's not right to assume the CPU port uses extint 1 nor that all extint are CPU ports. Now the association between the port and the external interface can be defined with a device-tree port property "realtek,ext-int".
This patch still does not allow multiple CPU ports nor extint as a non CPU port.
--- drivers/net/dsa/realtek/rtl8365mb.c | 135 ++++++++++++++++++---------- 1 file changed, 88 insertions(+), 47 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +88 -47
@@ -191,7 +191,13 @@/* The PHY OCP addresses of PHY registers 0~31 start here */ #define RTL8365MB_PHY_OCP_ADDR_PHYREG_BASE 0xA400 -/* EXT port interface mode values - used in DIGITAL_INTERFACE_SELECT */ +/* EXT interface numbers */ +#define RTL8365MB_NOT_EXT -1 +#define RTL8365MB_EXT0 0 +#define RTL8365MB_EXT1 1 +#define RTL8365MB_EXT2 2 + +/* EXT interface port mode values - used in DIGITAL_INTERFACE_SELECT */ #define RTL8365MB_EXT_PORT_MODE_DISABLE 0#define RTL8365MB_EXT_PORT_MODE_RGMII 1#define RTL8365MB_EXT_PORT_MODE_MII_MAC 2
@@ -207,39 +213,44 @@#define RTL8365MB_EXT_PORT_MODE_1000X 12#define RTL8365MB_EXT_PORT_MODE_100FX 13 -/* EXT port interface mode configuration registers 0~1 */ -#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG0 0x1305 -#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 0x13C3 -#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG (_extport) \ - (RTL8365MB_DIGITAL_INTERFACE_SELECT_REG0 + \ - ((_extport) >> 1) * (0x13C3 - 0x1305)) -#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK (_extport) \ - (0xF << (((_extport) % 2))) -#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET (_extport) \ - (((_extport) % 2) * 4) - -/* EXT port RGMII TX/RX delay configuration registers 1~2 */ -#define RTL8365MB_EXT_RGMXF_REG1 0x1307 -#define RTL8365MB_EXT_RGMXF_REG2 0x13C5 -#define RTL8365MB_EXT_RGMXF_REG (_extport) \ - (RTL8365MB_EXT_RGMXF_REG1 + \ - (((_extport) >> 1) * (0x13C5 - 0x1307))) +/* EXT interface mode configuration registers 0~1 */ +#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG0 0x1305/* EXT1 */ +#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 0x13C3/* EXT2 */ +#define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG (_extint) \ + ((_extint) == 1 ? RTL8365MB_DIGITAL_INTERFACE_SELECT_REG0 : \ + (_extint) == 2 ? RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 : \ + 0x0) +#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK (_extint) \ + (0xF << (((_extint) % 2))) +#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET (_extint) \ + (((_extint) % 2) * 4) + +/* EXT interface RGMII TX/RX delay configuration registers 0~2 */ +#define RTL8365MB_EXT_RGMXF_REG0 0x1306/* EXT0 */ +#define RTL8365MB_EXT_RGMXF_REG1 0x1307/* EXT1 */ +#define RTL8365MB_EXT_RGMXF_REG2 0x13C5/* EXT2 */ +#define RTL8365MB_EXT_RGMXF_REG (_extint) \ + ((_extint) == 0 ? RTL8365MB_EXT_RGMXF_REG0 : \ + (_extint) == 1 ? RTL8365MB_EXT_RGMXF_REG1 : \ + (_extint) == 2 ? RTL8365MB_EXT_RGMXF_REG2 : \ + 0x0)#define RTL8365MB_EXT_RGMXF_RXDELAY_MASK 0x0007#define RTL8365MB_EXT_RGMXF_TXDELAY_MASK 0x0008 -/* External port speed values - used in DIGITAL_INTERFACE_FORCE */ +/* External interface port speed values - used in DIGITAL_INTERFACE_FORCE */ #define RTL8365MB_PORT_SPEED_10M 0#define RTL8365MB_PORT_SPEED_100M 1#define RTL8365MB_PORT_SPEED_1000M 2 -/* EXT port force configuration registers 0~2 */ -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 0x1310 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG1 0x1311 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG2 0x13C4 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (_extport) \ - (RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 + \ - ((_extport) & 0x1) + \ - ((((_extport) >> 1) & 0x1) * (0x13C4 - 0x1310))) +/* EXT interface force configuration registers 0~2 */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 0x1310/* EXT0 */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG1 0x1311/* EXT1 */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG2 0x13C4/* EXT2 */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (_extint) \ + ((_extint) == 0 ? RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 : \ + (_extint) == 1 ? RTL8365MB_DIGITAL_INTERFACE_FORCE_REG1 : \ + (_extint) == 2 ? RTL8365MB_DIGITAL_INTERFACE_FORCE_REG2 : \ + 0x0)#define RTL8365MB_DIGITAL_INTERFACE_FORCE_EN_MASK 0x1000#define RTL8365MB_DIGITAL_INTERFACE_FORCE_NWAY_MASK 0x0080#define RTL8365MB_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK 0x0040
@@ -522,6 +533,7 @@ struct rtl8365mb_cpu {* access via rtl8365mb_get_stats64 * @stats_lock: protect the stats structure during read/update * @mib_work: delayed work for polling MIB counters +* @ext_int: the external interface port related to this port, RTL8365MB_NOT_EXT(-1) if none */ struct rtl8365mb_port {struct realtek_priv *priv;
@@ -529,6 +541,7 @@ struct rtl8365mb_port {struct rtnl_link_stats64 stats;spinlock_t stats_lock;struct delayed_work mib_work; +int ext_int; };/**
@@ -742,24 +755,28 @@ rtl8365mb_get_tag_protocol(struct dsa_switch *ds, int port,static int rtl8365mb_ext_config_rgmii (struct realtek_priv *priv,int port,phy_interface_t interface) { +struct rtl8365mb_port *p;struct device_node *dn; +struct rtl8365mb *mb;struct dsa_port *dp;int tx_delay =0 ;int rx_delay =0 ; -int ext_port; +int ext_int;u32 val;int ret; -if (port == priv->cpu_port) { - ext_port =1 ; - }else { -dev_err (priv->dev,"only one EXT port is currently supported\n" ); +if (port != priv->cpu_port) { +dev_err (priv->dev,"only one EXT interface is currently supported\n" );return -EINVAL ; } dp =dsa_to_port (priv->ds, port); dn = dp->dn; + mb = priv->chip_data; + p = &mb->ports[port]; + ext_int = p->ext_int; +/* Set the RGMII TX/RX delay * * The Realtek vendor driver indicates the following possible
@@ -789,7 +806,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, tx_delay = val /2 ; else dev_warn(priv->dev, - "EXT port TX delay must be 0 or 2 ns\n"); + "EXT interface TX delay must be 0 or 2 ns\n"); }if (!of_property_read_u32 (dn,"rx-internal-delay-ps" , &val)) {
@@ -799,11 +816,11 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, rx_delay = val; else dev_warn(priv->dev, - "EXT port RX delay must be 0 to 2.1 ns\n"); + "EXT interface RX delay must be 0 to 2.1 ns\n"); } ret = regmap_update_bits( - priv->map, RTL8365MB_EXT_RGMXF_REG(ext_port), + priv->map, RTL8365MB_EXT_RGMXF_REG(ext_int), RTL8365MB_EXT_RGMXF_TXDELAY_MASK | RTL8365MB_EXT_RGMXF_RXDELAY_MASK, FIELD_PREP(RTL8365MB_EXT_RGMXF_TXDELAY_MASK, tx_delay) |
@@ -812,11 +829,11 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,return ret; ret =regmap_update_bits ( - priv->map,RTL8365MB_DIGITAL_INTERFACE_SELECT_REG (ext_port), -RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK (ext_port), + priv->map,RTL8365MB_DIGITAL_INTERFACE_SELECT_REG (ext_int), +RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK (ext_int),RTL8365MB_EXT_PORT_MODE_RGMII <<RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET ( - ext_port)); + ext_int));if (ret)return ret;
@@ -827,22 +844,26 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port, bool link, int speed, int duplex, bool tx_pause, bool rx_pause) { + struct rtl8365mb_port *p; +struct rtl8365mb *mb;u32 r_tx_pause;u32 r_rx_pause;u32 r_duplex;u32 r_speed;u32 r_link; -int ext_port; +int ext_int;int val;int ret; -if (port == priv->cpu_port) { - ext_port =1 ; - }else { -dev_err (priv->dev,"only one EXT port is currently supported\n" ); +if (port != priv->cpu_port) { +dev_err (priv->dev,"only one EXT interface is currently supported\n" );return -EINVAL ; } + mb = priv->chip_data; + p = &mb->ports[port]; + ext_int = p->ext_int; +if (link) {/* Force the link up with the desired configuration */ r_link =1 ;
@@ -889,7 +910,7 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port, r_duplex) |FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK , r_speed); ret =regmap_write (priv->map, -RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (ext_port), +RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (ext_int), val);if (ret)return ret;
@@ -1819,13 +1840,13 @@ static int rtl8365mb_setup(struct dsa_switch *ds)/* Configure ports */ for (i =0 ; i < priv->num_ports; i++) {struct rtl8365mb_port *p = &mb->ports[i]; +struct device_node *dn; +u32 val;if (dsa_is_unused_port (priv->ds, i))continue ; -/* Set up per-port private data */ - p->priv = priv; - p->index = i; + dn =dsa_to_port (priv->ds, i)->dn;/* Forward only to the CPU */ ret =rtl8365mb_port_set_isolation (priv, i,BIT (priv->cpu_port));
@@ -1842,6 +1863,26 @@ static int rtl8365mb_setup(struct dsa_switch *ds)* administratively down by default. */ rtl8365mb_port_stp_state_set (priv->ds, i,BR_STATE_DISABLED ); + +/* Set up per-port private data */ + p->priv = priv; + p->index = i; + +if (!of_property_read_u32 (dn,"realtek,ext-int" , &val)) { +if (val <0 || val >2 ) { +dev_err (priv->dev, +"realtek,ext-int must be between 0 and 2\n" ); +return -EINVAL ; + } + + p->ext_int = val; + }else { +if (dsa_is_cpu_port (priv->ds, i)) +/* Default for compatibility with older device trees */ + p->ext_int =RTL8365MB_EXT1 ; +else + p->ext_int =RTL8365MB_NOT_EXT ; + } }/* Set maximum packet length to 1536 bytes */
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 8/11 net: dsa: realtek: rtl8365mb: use GENMASK(n-1,0) instead of BIT(n)-1
In reply to Luiz Angelo Daros de Luca--- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/realtek/rtl8365mb.c +1 -1
@@ -1973,7 +1973,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->priv = priv; mb->chip_id = chip_id; mb->chip_ver = chip_ver; - mb->port_mask =BIT (priv->num_ports) -1 ; + mb->port_mask =GENMASK (priv->num_ports -1 ,0 ); mb->learn_limit_max =RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC ; mb->jam_table = rtl8365mb_init_jam_8365mb_vc; mb->jam_size =ARRAY_SIZE (rtl8365mb_init_jam_8365mb_vc);
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 9/11 net: dsa: realtek: rtl8365mb: use DSA CPU port
In reply to Luiz Angelo Daros de LucaInstead of a fixed CPU port, assume that DSA is correct.
--- drivers/net/dsa/realtek/rtl8365mb.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +14 -9
@@ -103,14 +103,13 @@/* Chip-specific data and limits */ #define RTL8365MB_CHIP_ID_8365MB_VC 0x6367 -#define RTL8365MB_CPU_PORT_NUM_8365MB_VC 6#define RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC 2112/* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7#define RTL8365MB_NUM_PHYREGS 32#define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) -#define RTL8365MB_MAX_NUM_PORTS (RTL8365MB_CPU_PORT_NUM_8365MB_VC + 1) +#define RTL8365MB_MAX_NUM_PORTS 7/* Chip identification registers */ #define RTL8365MB_CHIP_ID_REG 0x1300
@@ -1806,6 +1805,8 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)static int rtl8365mb_setup (struct dsa_switch *ds) {struct realtek_priv *priv = ds->priv; +struct rtl8365mb_cpu cpu; +struct dsa_port *cpu_dp;struct rtl8365mb *mb;int ret;int i;
@@ -1833,9 +1834,16 @@ static int rtl8365mb_setup(struct dsa_switch *ds)dev_info (priv->dev,"no interrupt support\n" );/* Configure CPU tagging */ - ret =rtl8365mb_cpu_config (priv); -if (ret) - goto out_teardown_irq; +dsa_switch_for_each_cpu_port (cpu_dp, priv->ds) { + priv->cpu_port = cpu_dp->index; + mb->cpu.mask =BIT (priv->cpu_port); + mb->cpu.trap_port = priv->cpu_port; + ret =rtl8365mb_cpu_config (priv); +if (ret) + goto out_teardown_irq; + +break ; + }/* Configure ports */ for (i =0 ; i < priv->num_ports; i++) {
@@ -1967,8 +1975,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv)"found an RTL8365MB-VC switch (ver=0x%04x)\n" , chip_ver); - priv->cpu_port =RTL8365MB_CPU_PORT_NUM_8365MB_VC ; - priv->num_ports = priv->cpu_port +1 ; + priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; mb->priv = priv; mb->chip_id = chip_id;
@@ -1979,8 +1986,6 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->jam_size =ARRAY_SIZE (rtl8365mb_init_jam_8365mb_vc); mb->cpu.enable =1 ; - mb->cpu.mask =BIT (priv->cpu_port); - mb->cpu.trap_port = priv->cpu_port; mb->cpu.insert =RTL8365MB_CPU_INSERT_TO_ALL ; mb->cpu.position =RTL8365MB_CPU_POS_AFTER_SA ; mb->cpu.rx_length =RTL8365MB_CPU_RXLEN_64BYTES ;
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 10/11 net: dsa: realtek: rtl8365mb: add RTL8367S support
In reply to Luiz Angelo Daros de LucaRealtek's RTL8367S, a 5+2 port 10/100/1000M Ethernet switch. It shares the same driver family (RTL8367C) with other models as the RTL8365MB-VC. Its compatible string is "realtek,rtl8367s".
It was tested only with MDIO interface (realtek-mdio), although it might work out-of-the-box with SMI interface (using realtek-smi).
This patch was based on an unpublished patch from Alvin Šipraga <[email protected]>.
--- drivers/net/dsa/realtek/Kconfig | 2 +- drivers/net/dsa/realtek/realtek-mdio.c | 1 + drivers/net/dsa/realtek/realtek-smi.c | 4 +++ drivers/net/dsa/realtek/rtl8365mb.c | 38 +++++++++++++++++++------- 4 files changed, 34 insertions(+), 11 deletions(-)
drivers/net/dsa/realtek/Kconfig +1 -1
@@ -31,7 +31,7 @@ config NET_DSA_REALTEK_RTL8365MB depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL8_4 help - Select to enable support for Realtek RTL8365MB + Select to enable support for Realtek RTL8365MB-VC and RTL8367S. config NET_DSA_REALTEK_RTL8366RB tristate "Realtek RTL8366RB switch subdriver"
drivers/net/dsa/realtek/realtek-mdio.c +1 -0
@@ -199,6 +199,7 @@ static const struct of_device_id realtek_mdio_of_match[] = {#endif #if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, }, + { .compatible = "realtek,rtl8367s", .data = &rtl8365mb_variant, }, #endif { /* sentinel */ }, };
drivers/net/dsa/realtek/realtek-smi.c +4 -0
@@ -513,6 +513,10 @@ static const struct of_device_id realtek_smi_of_match[] = { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, }, + { + .compatible = "realtek,rtl8367s", + .data = &rtl8365mb_variant, + },#endif { /* sentinel */ }, };
drivers/net/dsa/realtek/rtl8365mb.c +28 -10
@@ -102,14 +102,19 @@#include "realtek.h" /* Chip-specific data and limits */ -#define RTL8365MB_CHIP_ID_8365MB_VC 0x6367 -#define RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC 2112 +#define RTL8365MB_CHIP_ID_8365MB_VC 0x6367 +#define RTL8365MB_CHIP_VER_8365MB_VC 0x0040 + +#define RTL8365MB_CHIP_ID_8367S 0x6367 +#define RTL8365MB_CHIP_VER_8367S 0x00A0/* Family-specific data and limits */ -#define RTL8365MB_PHYADDRMAX 7 -#define RTL8365MB_NUM_PHYREGS 32 -#define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) -#define RTL8365MB_MAX_NUM_PORTS 7 +#define RTL8365MB_PHYADDRMAX 7 +#define RTL8365MB_NUM_PHYREGS 32 +#define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) +/* RTL8370MB and RTL8310SR, possibly suportable by this driver, have 10 ports */ +#define RTL8365MB_MAX_NUM_PORTS 10 +#define RTL8365MB_LEARN_LIMIT_MAX 2112/* Chip identification registers */ #define RTL8365MB_CHIP_ID_REG 0x1300
@@ -1971,9 +1976,22 @@ static int rtl8365mb_detect(struct realtek_priv *priv)switch (chip_id) {case RTL8365MB_CHIP_ID_8365MB_VC : -dev_info (priv->dev, -"found an RTL8365MB-VC switch (ver=0x%04x)\n" , - chip_ver); +switch (chip_ver) { +case RTL8365MB_CHIP_VER_8365MB_VC : +dev_info (priv->dev, +"found an RTL8365MB-VC switch (ver=0x%04x)\n" , + chip_ver); +break ; +case RTL8365MB_CHIP_VER_8367S : +dev_info (priv->dev, +"found an RTL8367S switch (ver=0x%04x)\n" , + chip_ver); +break ; +default : +dev_err (priv->dev,"unrecognized switch version (ver=0x%04x)" , + chip_ver); +return -ENODEV ; + } priv->num_ports =RTL8365MB_MAX_NUM_PORTS ;
@@ -1981,7 +1999,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->chip_id = chip_id; mb->chip_ver = chip_ver; mb->port_mask =GENMASK (priv->num_ports -1 ,0 ); - mb->learn_limit_max =RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC ; + mb->learn_limit_max =RTL8365MB_LEARN_LIMIT_MAX ; mb->jam_table = rtl8365mb_init_jam_8365mb_vc; mb->jam_size =ARRAY_SIZE (rtl8365mb_init_jam_8365mb_vc);
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v5 11/11 net: dsa: realtek: rtl8365mb: multiple cpu ports, non cpu extint
In reply to Luiz Angelo Daros de LucaNow CPU port is not limited to a single port. Also, extint can be used as non-cpu ports, as long as it defines relatek,ext-int. The last cpu port will be used as trap_port.
The CPU information was dropped from chip data as it was not used outside setup. The only other place it was used is when it wrongly checks for CPU port when it should check for extint.
realtek_priv->cpu_port is now only used by rtl8366rb.c
--- drivers/net/dsa/realtek/rtl8365mb.c | 53 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 26 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +27 -26
@@ -556,7 +556,6 @@ struct rtl8365mb_port {* @chip_ver: chip silicon revision * @port_mask: mask of all ports * @learn_limit_max: maximum number of L2 addresses the chip can learn -* @cpu: CPU tagging and CPU port configuration for this chip * @mib_lock: prevent concurrent reads of MIB counters * @ports: per-port data * @jam_table: chip-specific initialization jam table
@@ -571,7 +570,6 @@ struct rtl8365mb {u32 chip_ver;u32 port_mask;u32 learn_limit_max; -struct rtl8365mb_cpu cpu;struct mutex mib_lock;struct rtl8365mb_port ports[RTL8365MB_MAX_NUM_PORTS ];const struct rtl8365mb_jam_tbl_entry *jam_table;
@@ -769,17 +767,20 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,u32 val;int ret; -if (port != priv->cpu_port) { -dev_err (priv->dev,"only one EXT interface is currently supported\n" ); + mb = priv->chip_data; + p = &mb->ports[port]; + ext_int = p->ext_int; + +if (ext_int ==RTL8365MB_NOT_EXT ) { +dev_err (priv->dev, +"Port %d is not identified as extenal interface.\n" , + port);return -EINVAL ; } dp =dsa_to_port (priv->ds, port); dn = dp->dn; - mb = priv->chip_data; - p = &mb->ports[port]; - ext_int = p->ext_int;/* Set the RGMII TX/RX delay *
@@ -859,15 +860,17 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port,int val;int ret; -if (port != priv->cpu_port) { -dev_err (priv->dev,"only one EXT interface is currently supported\n" ); -return -EINVAL ; - } - mb = priv->chip_data; p = &mb->ports[port]; ext_int = p->ext_int; +if (ext_int ==RTL8365MB_NOT_EXT ) { +dev_err (priv->dev, +"Port %d is not identified as extenal interface.\n" , + port); +return -EINVAL ; + } +if (link) {/* Force the link up with the desired configuration */ r_link =1 ;
@@ -1734,10 +1737,8 @@ static void rtl8365mb_irq_teardown(struct realtek_priv *priv) } } -static int rtl8365mb_cpu_config (struct realtek_priv *priv) +static int rtl8365mb_cpu_config (struct realtek_priv *priv,struct rtl8365mb_cpu *cpu) { -struct rtl8365mb *mb = priv->chip_data; -struct rtl8365mb_cpu *cpu = &mb->cpu;u32 val;int ret;
@@ -1839,11 +1840,17 @@ static int rtl8365mb_setup(struct dsa_switch *ds)dev_info (priv->dev,"no interrupt support\n" );/* Configure CPU tagging */ + cpu.mask =0 ;dsa_switch_for_each_cpu_port (cpu_dp, priv->ds) { - priv->cpu_port = cpu_dp->index; - mb->cpu.mask =BIT (priv->cpu_port); - mb->cpu.trap_port = priv->cpu_port; - ret =rtl8365mb_cpu_config (priv); + cpu.enable =1 ; + cpu.insert =RTL8365MB_CPU_INSERT_TO_ALL ; + cpu.position =RTL8365MB_CPU_POS_AFTER_SA ; + cpu.rx_length =RTL8365MB_CPU_RXLEN_64BYTES ; + cpu.format =RTL8365MB_CPU_FORMAT_8BYTES ; + cpu.trap_port = cpu_dp->index; + cpu.mask |=BIT (cpu_dp->index); + + ret =rtl8365mb_cpu_config (priv, &cpu);if (ret) goto out_teardown_irq;
@@ -1862,7 +1869,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds) dn =dsa_to_port (priv->ds, i)->dn;/* Forward only to the CPU */ - ret =rtl8365mb_port_set_isolation (priv, i,BIT (priv->cpu_port)); + ret =rtl8365mb_port_set_isolation (priv, i, cpu.mask);if (ret) goto out_teardown_irq;
@@ -2003,12 +2010,6 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->jam_table = rtl8365mb_init_jam_8365mb_vc; mb->jam_size =ARRAY_SIZE (rtl8365mb_init_jam_8365mb_vc); - mb->cpu.enable =1 ; - mb->cpu.insert =RTL8365MB_CPU_INSERT_TO_ALL ; - mb->cpu.position =RTL8365MB_CPU_POS_AFTER_SA ; - mb->cpu.rx_length =RTL8365MB_CPU_RXLEN_64BYTES ; - mb->cpu.format =RTL8365MB_CPU_FORMAT_8BYTES ; -break ;default : dev_err(priv->dev,
Signature · 1 line
2.34.1