net: dsa: realtek: MDIO interface and RTL8367S,RTL8367RB-VB
Luiz Angelo Daros de Luca
maintainerv6 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.
I couldn't identify a fixed relation between port numbers (0..9) and external interfaces (0..2), and I'm not sure if it is fixed for each chip version or a device configuration. Until there is more info about it, there is a new port property "realtek,ext-int" that can inform the external interface.
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
v5) sent again v4 branch. Sorry
v4-v6)
- 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 v6 1/13 net: dsa: realtek-smi: fix kdoc warnings
Removed kdoc mark for incomplete struct description. Added a return description for rtl8366rb_drop_untagged.
--- drivers/net/dsa/realtek-smi-core.h | 4 ++-- drivers/net/dsa/rtl8366rb.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek-smi-core.h +2 -2
@@ -25,7 +25,7 @@ struct rtl8366_mib_counter {const char *name; }; -/** +/* * struct rtl8366_vlan_mc - Virtual LAN member configuration */ struct rtl8366_vlan_mc {
@@ -74,7 +74,7 @@ struct realtek_smi {void *chip_data;/* Per-chip extra variant data */ }; -/** +/* * struct realtek_smi_ops - vtable for the per-SMI-chiptype operations * @detect: detects the chiptype */
drivers/net/dsa/rtl8366rb.c +2 -0
@@ -1252,6 +1252,8 @@ rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,* @smi: SMI state container * @port: the port to drop untagged and C-tagged frames on * @drop: whether to drop or pass untagged and C-tagged frames +* +* Return: zero for success, a negative number on error. */ static int rtl8366rb_drop_untagged (struct realtek_smi *smi,int port,bool drop) {
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 01/13] net: dsa: realtek-smi: fix kdoc warnings
Quoted 4 lines · Luiz Angelo Daros de Luca
Removed kdoc mark for incomplete struct description. Added a return description for
rtl8366rb_drop_untagged.Signed-off-by Luiz Angelo Daros de Luca <[email protected]>
Signature · 1 line
Florian
Luiz Angelo Daros de Luca
maintainerPATCH v6 2/13 net: dsa: realtek-smi: move to subdirectory
In reply to Luiz Angelo Daros de Luca---
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 v6 3/13 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 v6 4/13 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 | 16 +++++++++------- drivers/net/dsa/realtek/realtek.h | 7 ++----- drivers/net/dsa/realtek/rtl8365mb.c | 15 ++++++++------- drivers/net/dsa/realtek/rtl8366rb.c | 14 ++++++++------ 4 files changed, 27 insertions(+), 25 deletions(-)
drivers/net/dsa/realtek/realtek-smi-core.c +9 -7
@@ -292,12 +292,10 @@ 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 (void *ctx,u32 reg,u32 val) { -return realtek_smi_write_reg (priv, addr, data, false); +return realtek_smi_write_reg (ctx, reg, val, false); } -EXPORT_SYMBOL_GPL (realtek_smi_write_reg_noack);/* Regmap accessors */
@@ -342,8 +340,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 +362,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 +412,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)(void *ctx,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 +8 -7
@@ -1767,9 +1767,8 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv) {u32 val; -realtek_smi_write_reg_noack (priv,RTL8365MB_CHIP_RESET_REG , -FIELD_PREP (RTL8365MB_CHIP_RESET_HW_MASK , -1 )); + priv->write_reg_noack (priv,RTL8365MB_CHIP_RESET_REG , +FIELD_PREP (RTL8365MB_CHIP_RESET_HW_MASK ,1 ));/* Realtek documentation says the chip needs 1 second to reset. Sleep * for 100 ms before accessing any registers to prevent ACK timeouts.
@@ -1849,10 +1848,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 +8 -6
@@ -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 ;
@@ -1707,8 +1709,8 @@ static int rtl8366rb_reset_chip(struct realtek_priv *priv)u32 val;int ret; -realtek_smi_write_reg_noack (priv,RTL8366RB_RESET_CTRL_REG , -RTL8366RB_CHIP_CTRL_RESET_HW ); + priv->write_reg_noack (priv,RTL8366RB_RESET_CTRL_REG , +RTL8366RB_CHIP_CTRL_RESET_HW ); do { usleep_range(20000, 25000); ret = regmap_read(priv->map, RTL8366RB_RESET_CTRL_REG, &val);
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v6 5/13 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
@@ -494,19 +494,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);
@@ -522,4 +526,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
@@ -1986,3 +1986,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
@@ -1816,3 +1816,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
Jakub Kicinski
maintainerRe: [PATCH net-next v6 05/13] net: dsa: realtek: convert subdrivers into modules
Quoted 25 lines · On Fri, 28 Jan 2022 03:05:01 -0300 Luiz Angelo Daros de Luca wrote:
drivers/net/dsa/realtek/Kconfig +8
-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
drivers/net/dsa/realtek/Kconfig config NET_DSA_REALTEK_SMI · line 36
Quoted 10 lines
drivers/net/dsa/realtek/Kconfig +10
-0+ 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
Why did all these new config options grow a 'default y'? Our usual policy is to default drivers to disabled.
Re: [PATCH net-next v6 05/13] net: dsa: realtek: convert subdrivers into modules
Quoted 31 lines · Jakub Kicinski
Quoted 30 lines · On Fri, 28 Jan 2022 03:05:01 -0300 Luiz Angelo Daros de Luca wrote:
drivers/net/dsa/realtek/Kconfig +13
-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
Quoted 8 lines
drivers/net/dsa/realtek/Kconfig config NET_DSA_REALTEK_SMI · line 36
Quoted 5 lines
drivers/net/dsa/realtek/Kconfig +5
-0+ depends on NET_DSA_REALTEK + depends on NET_DSA_REALTEK_SMI + select NET_DSA_TAG_RTL4_A + help + Select to enable support for Realtek RTL8366RBWhy did all these new config options grow a 'default y'? Our usual policy is to default drivers to disabled.
NET_DSA_REALTEK_SMI and NET_DSA_REALTEK_MDIO also have got "default y".
Respectively:319a70a5fea9 ("net: dsa: realtek-smi: move to subdirectory") aac94001067d ("net: dsa: realtek: add new mdio interface for drivers")
Jakub Kicinski
maintainerRe: [PATCH net-next v6 05/13] net: dsa: realtek: convert subdrivers into modules
Quoted 5 lines · On Fri, 4 Feb 2022 10:57:22 +0300 Arınç ÜNAL wrote:
Quoted 2 lines
Why did all these new config options grow a 'default y'? Our usual policy is to default drivers to disabled.
NET_DSA_REALTEK_SMIandNET_DSA_REALTEK_MDIOalso have got "default y".
Quoted 7 lines
Respectively:
319a70a5fea9("net: dsa: realtek-smi: move to subdirectory")aac94001067d("net: dsa: realtek: add new mdio interface for drivers")
Indeed, so far we had been doing the opposite what this driver has done
- set the "vendor selection" i.e. NET_DSA_REALTEK default to y since it doesn't build any code, and the actual code default to n. We are considering defaulting everything to n now, but it's WIP.
Let me send a patch dropping the default y, please object if there was a strong reason to do it this way!
Luiz Angelo Daros de Luca
maintainerPATCH v6 6/13 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).
ds_ops was duplicated for smi and mdio usage as mdio interfaces uses phy_{read,write} in ds_ops and the presence of phy_read is incompatible with external slave_mii_bus allocation.
--- drivers/net/dsa/realtek/Kconfig | 12 +- drivers/net/dsa/realtek/Makefile | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 228 +++++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 2 +- drivers/net/dsa/realtek/realtek.h | 5 +- drivers/net/dsa/realtek/rtl8365mb.c | 36 +++- drivers/net/dsa/realtek/rtl8366rb.c | 41 ++++- 7 files changed, 317 insertions(+), 8 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-mdio.c
drivers/net/dsa/realtek/Kconfig +10 -2
@@ -9,6 +9,14 @@ 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 +29,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 +38,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 +228 -0
228 lines not on this page · raw message
drivers/net/dsa/realtek/realtek-smi.c +1 -1
@@ -455,7 +455,7 @@ static int realtek_smi_probe(struct platform_device *pdev) priv->ds->num_ports = priv->num_ports; priv->ds->priv = priv; - priv->ds->ops = var->ds_ops; + priv->ds->ops = var->ds_ops_smi; ret =dsa_register_switch (priv->ds);if (ret) {dev_err_probe (dev, ret,"unable to register switch\n" );
drivers/net/dsa/realtek/realtek.h +4 -1
@@ -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 mdio_addr;unsigned int clk_delay;u8 cmd_read;
@@ -109,7 +111,8 @@ struct realtek_ops { };struct realtek_variant { -const struct dsa_switch_ops *ds_ops; +const struct dsa_switch_ops *ds_ops_smi; +const struct dsa_switch_ops *ds_ops_mdio;const struct realtek_ops *ops;unsigned int clk_delay;u8 cmd_read;
drivers/net/dsa/realtek/rtl8365mb.c +34 -2
@@ -730,6 +730,17 @@ static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum,return 0 ; } +static int rtl8365mb_dsa_phy_read (struct dsa_switch *ds,int phy,int regnum) +{ +return rtl8365mb_phy_read (ds->priv, phy, regnum); +} + +static int rtl8365mb_dsa_phy_write (struct dsa_switch *ds,int phy,int regnum, +u16 val) +{ +return rtl8365mb_phy_write (ds->priv, phy, regnum, val); +} +static enum dsa_tag_protocol rtl8365mb_get_tag_protocol (struct dsa_switch *ds,int port,enum dsa_tag_protocol mp)
@@ -1953,7 +1964,25 @@ static int rtl8365mb_detect(struct realtek_priv *priv)return 0 ; } -static const struct dsa_switch_ops rtl8365mb_switch_ops = { +static const struct dsa_switch_ops rtl8365mb_switch_ops_smi = { + .get_tag_protocol = rtl8365mb_get_tag_protocol, + .setup = rtl8365mb_setup, + .teardown = rtl8365mb_teardown, + .phylink_validate = rtl8365mb_phylink_validate, + .phylink_mac_config = rtl8365mb_phylink_mac_config, + .phylink_mac_link_down = rtl8365mb_phylink_mac_link_down, + .phylink_mac_link_up = rtl8365mb_phylink_mac_link_up, + .port_stp_state_set = rtl8365mb_port_stp_state_set, + .get_strings = rtl8365mb_get_strings, + .get_ethtool_stats = rtl8365mb_get_ethtool_stats, + .get_sset_count = rtl8365mb_get_sset_count, + .get_eth_phy_stats = rtl8365mb_get_phy_stats, + .get_eth_mac_stats = rtl8365mb_get_mac_stats, + .get_eth_ctrl_stats = rtl8365mb_get_ctrl_stats, + .get_stats64 = rtl8365mb_get_stats64, +}; + +static const struct dsa_switch_ops rtl8365mb_switch_ops_mdio = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .setup = rtl8365mb_setup, .teardown = rtl8365mb_teardown,
@@ -1961,6 +1990,8 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = { .phylink_mac_config = rtl8365mb_phylink_mac_config, .phylink_mac_link_down = rtl8365mb_phylink_mac_link_down, .phylink_mac_link_up = rtl8365mb_phylink_mac_link_up, + .phy_read = rtl8365mb_dsa_phy_read, + .phy_write = rtl8365mb_dsa_phy_write, .port_stp_state_set = rtl8365mb_port_stp_state_set, .get_strings = rtl8365mb_get_strings, .get_ethtool_stats = rtl8365mb_get_ethtool_stats,
@@ -1978,7 +2009,8 @@ static const struct realtek_ops rtl8365mb_ops = { };const struct realtek_variant rtl8365mb_variant = { - .ds_ops = &rtl8365mb_switch_ops, + .ds_ops_smi = &rtl8365mb_switch_ops_smi, + .ds_ops_mdio = &rtl8365mb_switch_ops_mdio, .ops = &rtl8365mb_ops, .clk_delay =10 , .cmd_read =0xb9 ,
drivers/net/dsa/realtek/rtl8366rb.c +39 -2
61 lines not on this page · raw message
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v6 7/13 net: dsa: realtek: rtl8365mb: rename extport to extint
In reply to Luiz Angelo Daros de Luca"extport" 0, 1, 2 was used to reference external ports id (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 id.
The macros that map extint numbers to registers addresses now use inline ifs instead of binary arithmetic.
Realtek uses in docs and drivers EXT_PORT0 (GMAC1) and EXT_PORT1 (GMAC2), with EXT_PORT0 being converted to ext_id == 1 and so on. It might introduce some confusing while reading datasheets but it will not be exposed to users.
"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 it came from a map between port number and external interface id number.
This patch still does not allow multiple CPU ports nor extint as a non CPU port.
--- drivers/net/dsa/realtek/rtl8365mb.c | 124 +++++++++++++++++----------- 1 file changed, 76 insertions(+), 48 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +76 -48
@@ -105,6 +105,7 @@#define RTL8365MB_CHIP_ID_8365MB_VC 0x6367#define RTL8365MB_CPU_PORT_NUM_8365MB_VC 6#define RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC 2112 +static const int rtl8365mb_extint_port_map[] = {-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 };/* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7
@@ -191,7 +192,7 @@/* 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 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 +208,56 @@#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))) +/* Realtek docs and driver uses logic number as EXT_PORT0=16, EXT_PORT1=17, +* EXT_PORT2=18, to interact with switch ports. That logic number is internally +* converted to either a physical port number (0..9) or an external interface id (0..2), +* depending on which function was called. The external interface id is calculated as +* (ext_id=logic_port-15), while the logical to physical map depends on the chip id/version. +* +* EXT_PORT0 mentioned in datasheets and rtl8367c driver is used in this driver +* as extid==1, EXT_PORT2, mentioned in Realtek rtl8367c driver for 10-port switches, +* would have an ext_id of 3 (out of range for most extint macros) and ext_id 0 does +* not seem to be used as well for this family. +*/ + +/* 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
@@ -755,20 +773,25 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,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; + ext_int = rtl8365mb_extint_port_map[port]; + +if (ext_int <=0 ) { +dev_err (priv->dev,"Port %d is not an external interface port\n" , port); +return -EINVAL ; + } +/* Set the RGMII TX/RX delay * * The Realtek vendor driver indicates the following possible
@@ -798,7 +821,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)) {
@@ -808,11 +831,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) |
@@ -821,11 +844,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;
@@ -841,14 +864,19 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port,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 ; + } + + ext_int = rtl8365mb_extint_port_map[port]; + +if (ext_int <=0 ) { +dev_err (priv->dev,"Port %d is not an external interface port\n" , port);return -EINVAL ; }
@@ -898,7 +926,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;
@@ -1831,10 +1859,6 @@ static int rtl8365mb_setup(struct dsa_switch *ds)if (dsa_is_unused_port (priv->ds, i))continue ; -/* Set up per-port private data */ - p->priv = priv; - p->index = i; -/* Forward only to the CPU */ ret =rtl8365mb_port_set_isolation (priv, i,BIT (priv->cpu_port));if (ret)
@@ -1850,6 +1874,10 @@ 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; }/* Set maximum packet length to 1536 bytes */
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v6 8/13 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
@@ -1968,7 +1968,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 v6 9/13 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,7 +103,6 @@/* 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 2112static const int rtl8365mb_extint_port_map[] = {-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 };
@@ -111,7 +110,7 @@ static const int rtl8365mb_extint_port_map[] = { -1, -1, -1, -1, -1, -1, 1 };#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
@@ -1821,6 +1820,7 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)static int rtl8365mb_setup (struct dsa_switch *ds) {struct realtek_priv *priv = ds->priv; +struct dsa_port *cpu_dp;struct rtl8365mb *mb;int ret;int i;
@@ -1848,9 +1848,17 @@ 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; +/* Currently, only one CPU port is supported */ +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++) {
@@ -1962,8 +1970,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;
@@ -1974,8 +1981,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 v6 10/13 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 | 42 +++++++++++++++++++------- 4 files changed, 37 insertions(+), 12 deletions(-)
drivers/net/dsa/realtek/Kconfig +1 -1
@@ -32,7 +32,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
@@ -206,6 +206,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
@@ -510,6 +510,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 +31 -11
62 lines not on this page · raw message
Signature · 1 line
2.34.1
Luiz Angelo Daros de Luca
maintainerPATCH v6 11/13 net: dsa: realtek: rtl8365mb: add RTL8367RB-VB support
In reply to Luiz Angelo Daros de LucaRTL8367RB-VB is a 5+2 port 10/100/1000M Ethernet switch. It is similar to RTL8367S but in this version, both external interfaces are RGMII.
--- drivers/net/dsa/realtek/rtl8365mb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/dsa/realtek/rtl8365mb.c +8 -0
@@ -108,6 +108,9 @@#define RTL8365MB_CHIP_ID_8367S 0x6367#define RTL8365MB_CHIP_VER_8367S 0x00A0 +#define RTL8365MB_CHIP_ID_8367RB 0x6367 +#define RTL8365MB_CHIP_VER_8367RB 0x0020 +/* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7#define RTL8365MB_NUM_PHYREGS 32
@@ -1979,6 +1982,11 @@ static int rtl8365mb_detect(struct realtek_priv *priv)"found an RTL8365MB-VC switch (ver=0x%04x)\n" , chip_ver);break ; +case RTL8365MB_CHIP_VER_8367RB : +dev_info (priv->dev, +"found an RTL8367RB-VB 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",
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 11/13] net: dsa: realtek: rtl8365mb: add RTL8367RB-VB support
Quoted 25 lines · Luiz Angelo Daros de Luca
RTL8367RB-VB is a 5+2 port 10/100/1000M Ethernet switch. It is similar to RTL8367S but in this version, both external interfaces are RGMII.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/dsa/realtek/rtl8365mb.c +3
-0@@ -108,6 +108,9 @@#define RTL8365MB_CHIP_ID_8367S 0x6367#define RTL8365MB_CHIP_VER_8367S 0x00A0 +#define RTL8365MB_CHIP_ID_8367RB 0x6367 +#define RTL8365MB_CHIP_VER_8367RB 0x0020 +/* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7#define RTL8365MB_NUM_PHYREGS 32@@ -1979,6 +1982,11 @@ static int rtl8365mb_detect(struct realtek_priv *priv) "found an RTL8365MB-VC switch (ver=0x%04x)\n",
drivers/net/dsa/realtek/rtl8365mb.c static int rtl8365mb_detect(struct realtek_priv *priv) · line 1992
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb.c +5
-0chip_ver);break ; +case RTL8365MB_CHIP_VER_8367RB : +dev_info (priv->dev, +"found an RTL8367RB-VB 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",
You should mention the support for this chip model on kconfig like on "net: dsa: realtek: rtl8365mb: add RTL8367S support".
Don't you also need to match the "realtek,rtl8367rb" compatible string to rtl8365mb_variant on SMI and MDIO drivers?
Arınç
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v6 11/13] net: dsa: realtek: rtl8365mb: add RTL8367RB-VB support
Quoted 6 lines
You should mention the support for this chip model on kconfig like on "net: dsa: realtek: rtl8365mb: add RTL8367S support".
Don't you also need to match the "realtek,rtl8367rb" compatible string to
rtl8365mb_varianton SMI and MDIO drivers?
Yes Arinç. You are right. Thanks. The driver will work "as is" using any of existing compatible strings but I'll send a patch to fix that after Documentation is updated.
Quoted 1 line
Arınç
Luiz Angelo Daros de Luca
maintainerPATCH v6 12/13 net: dsa: realtek: rtl8365mb: allow non-cpu extint ports
In reply to Luiz Angelo Daros de LucaExternal interfaces can be configured, even if they are not CPU ports. The first CPU port will also be the trap port (for receiving trapped frames from the switch).
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.
The supported modes check now uses port type and not port usage.
As a byproduct, more than one CPU can be configured. although this might not work well with DSA setups. Also, this driver is still only blindly forwarding all traffic to CPU port(s).
This change was not tested in a device with multiple active external interfaces ports.
realtek_priv->cpu_port is now only used by rtl8366rb.c
--- drivers/net/dsa/realtek/rtl8365mb.c | 61 ++++++++++++----------------- 1 file changed, 26 insertions(+), 35 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +26 -35
@@ -566,7 +566,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
@@ -581,7 +580,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;
@@ -786,14 +784,6 @@ 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" ); -return -EINVAL ; - } - - dp =dsa_to_port (priv->ds, port); - dn = dp->dn; - ext_int = rtl8365mb_extint_port_map[port];if (ext_int <=0 ) {
@@ -801,6 +791,9 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,return -EINVAL ; } + dp =dsa_to_port (priv->ds, port); + dn = dp->dn; +/* Set the RGMII TX/RX delay * * The Realtek vendor driver indicates the following possible
@@ -877,11 +870,6 @@ 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 ; - } - ext_int = rtl8365mb_extint_port_map[port];if (ext_int <=0 ) {
@@ -946,13 +934,17 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port,static bool rtl8365mb_phy_mode_supported (struct dsa_switch *ds,int port,phy_interface_t interface) { -if (dsa_is_user_port (ds, port) && +int ext_int; + + ext_int = rtl8365mb_extint_port_map[port]; + +if (ext_int <0 && (interface ==PHY_INTERFACE_MODE_NA || interface ==PHY_INTERFACE_MODE_INTERNAL || interface ==PHY_INTERFACE_MODE_GMII ))/* Internal PHY */ return true; -else if (dsa_is_cpu_port (ds, port) && +else if ((ext_int >=1 ) &&phy_interface_mode_is_rgmii (interface))/* Extension MAC */ return true;
@@ -1755,10 +1747,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,const struct rtl8365mb_cpu *cpu) { -struct rtl8365mb *mb = priv->chip_data; -struct rtl8365mb_cpu *cpu = &mb->cpu;u32 val;int ret;
@@ -1830,6 +1820,7 @@ 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 = {0 };struct dsa_port *cpu_dp;struct rtl8365mb *mb;int ret;
@@ -1858,18 +1849,24 @@ static int rtl8365mb_setup(struct dsa_switch *ds)dev_info (priv->dev,"no interrupt support\n" );/* Configure CPU tagging */ -/* Currently, only one CPU port is supported */ + cpu.trap_port =RTL8365MB_MAX_NUM_PORTS ;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; + cpu.mask |=BIT (cpu_dp->index); -break ; +if (cpu.trap_port ==RTL8365MB_MAX_NUM_PORTS ) + cpu.trap_port = cpu_dp->index; } + cpu.enable = cpu.mask >0 ; + 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 ; + + ret =rtl8365mb_cpu_config (priv, &cpu); +if (ret) + goto out_teardown_irq; +/* Configure ports */ for (i =0 ; i < priv->num_ports; i++) {struct rtl8365mb_port *p = &mb->ports[i];
@@ -1878,7 +1875,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)continue ;/* 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;
@@ -2008,12 +2005,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
Luiz Angelo Daros de Luca
maintainerPATCH v6 13/13 net: dsa: realtek: rtl8365mb: fix trap_door > 7
In reply to Luiz Angelo Daros de LucaTrap door number is a 4-bit number divided in two regions (3 and 1-bit). Both values were not masked properly. This bug does not affect supported devices as they use up to port 7 (ext2). It would only be a problem if the driver becomes compatible with 10-port switches like RTL8370MB and RTL8310SR.
--- drivers/net/dsa/realtek/rtl8365mb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +2 -2
@@ -1764,9 +1764,9 @@ static int rtl8365mb_cpu_config(struct realtek_priv *priv, const struct rtl8365mFIELD_PREP (RTL8365MB_CPU_CTRL_TAG_POSITION_MASK , cpu->position) |FIELD_PREP (RTL8365MB_CPU_CTRL_RXBYTECOUNT_MASK , cpu->rx_length) |FIELD_PREP (RTL8365MB_CPU_CTRL_TAG_FORMAT_MASK , cpu->format) | -FIELD_PREP (RTL8365MB_CPU_CTRL_TRAP_PORT_MASK , cpu->trap_port) | +FIELD_PREP (RTL8365MB_CPU_CTRL_TRAP_PORT_MASK , cpu->trap_port &0x7 ) |FIELD_PREP (RTL8365MB_CPU_CTRL_TRAP_PORT_EXT_MASK , - cpu->trap_port >>3 ); + cpu->trap_port >>3 &0x1 ); ret =regmap_write (priv->map,RTL8365MB_CPU_CTRL_REG , val);if (ret)return ret;
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 10 lines · On Fri, 28 Jan 2022 03:04:56 -0300 you wrote:
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.
[...]
Here is the summary with links:
- [net-next,v6,01/13] net: dsa: realtek-smi: fix kdoc warnings
https://git.kernel.org/netdev/net-next/c/0f0c6da03ba3 - [net-next,v6,02/13] net: dsa: realtek-smi: move to subdirectory https://git.kernel.org/netdev/net-next/c/319a70a5fea9 - [net-next,v6,03/13] net: dsa: realtek: rename realtek_smi to realtek_priv https://git.kernel.org/netdev/net-next/c/f5f119077b1c - [net-next,v6,04/13] net: dsa: realtek: remove direct calls to realtek-smi https://git.kernel.org/netdev/net-next/c/cd645dc556e2 - [net-next,v6,05/13] net: dsa: realtek: convert subdrivers into modules https://git.kernel.org/netdev/net-next/c/765c39a4fafe - [net-next,v6,06/13] net: dsa: realtek: add new mdio interface for drivers https://git.kernel.org/netdev/net-next/c/aac94001067d - [net-next,v6,07/13] net: dsa: realtek: rtl8365mb: rename extport to extint https://git.kernel.org/netdev/net-next/c/d18b59f48b31 - [net-next,v6,08/13] net: dsa: realtek: rtl8365mb: use GENMASK(n-1,0) instead of BIT(n)-1 https://git.kernel.org/netdev/net-next/c/c45e0fef9f89 - [net-next,v6,09/13] net: dsa: realtek: rtl8365mb: use DSA CPU port https://git.kernel.org/netdev/net-next/c/7fa8af30ecdf - [net-next,v6,10/13] net: dsa: realtek: rtl8365mb: add RTL8367S support https://git.kernel.org/netdev/net-next/c/d40f607c181f - [net-next,v6,11/13] net: dsa: realtek: rtl8365mb: add RTL8367RB-VB support https://git.kernel.org/netdev/net-next/c/84a10aecdcc0 - [net-next,v6,12/13] net: dsa: realtek: rtl8365mb: allow non-cpu extint ports https://git.kernel.org/netdev/net-next/c/6147631c079f - [net-next,v6,13/13] net: dsa: realtek: rtl8365mb: fix trap_door > 7 https://git.kernel.org/netdev/net-next/c/078ae1bdd32d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html