All of lore.kernel.org
 help / color / mirror / Atom feed
From: luizluca@gmail.com
To: netdev@vger.kernel.org
Cc: linus.walleij@linaro.org, andrew@lunn.ch,
	vivien.didelot@gmail.com, f.fainelli@gmail.com,
	olteanv@gmail.com, alsi@bang-olufsen.dk, arinc.unal@arinc9.com,
	Luiz Angelo Daros de Luca <luizluca@gmail.com>
Subject: [PATCH net-next 10/13] net: dsa: realtek: rtl8367c: rename extport to extint, add "realtek,ext-int"
Date: Thu, 16 Dec 2021 17:13:39 -0300	[thread overview]
Message-ID: <20211216201342.25587-11-luizluca@gmail.com> (raw)
In-Reply-To: <20211216201342.25587-1-luizluca@gmail.com>

From: Luiz Angelo Daros de Luca <luizluca@gmail.com>

"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. Now it can be defined with a device-tree
port property "realtek,ext-int";

Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 .../bindings/net/dsa/realtek-smi.txt          |   4 +
 drivers/net/dsa/realtek/rtl8367c.c            | 106 ++++++++++++------
 2 files changed, 74 insertions(+), 36 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/dsa/realtek-smi.txt b/Documentation/devicetree/bindings/net/dsa/realtek-smi.txt
index 3a60e77ceed4..acdb026e5307 100644
--- a/Documentation/devicetree/bindings/net/dsa/realtek-smi.txt
+++ b/Documentation/devicetree/bindings/net/dsa/realtek-smi.txt
@@ -56,6 +56,10 @@ See net/mdio.txt for additional MDIO bus properties.
 See net/dsa/dsa.txt for a list of additional required and optional properties
 and subnodes of DSA switches.
 
+Optional properties of dsa port:
+
+- realtek,ext-int: defines the external interface number (0, 1, 2). By default, 1.
+
 Examples:
 
 An example for the RTL8366RB:
diff --git a/drivers/net/dsa/realtek/rtl8367c.c b/drivers/net/dsa/realtek/rtl8367c.c
index 98ec793a82bc..6aca48165d1f 100644
--- a/drivers/net/dsa/realtek/rtl8367c.c
+++ b/drivers/net/dsa/realtek/rtl8367c.c
@@ -197,22 +197,26 @@
 #define RTL8367C_EXT_PORT_MODE_100FX		13
 
 /* EXT port interface mode configuration registers 0~1 */
-#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG0		0x1305
-#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG1		0x13C3
-#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG(_extport)   \
-		(RTL8367C_DIGITAL_INTERFACE_SELECT_REG0 + \
-		 ((_extport) >> 1) * (0x13C3 - 0x1305))
-#define   RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_MASK(_extport) \
-		(0xF << (((_extport) % 2)))
-#define   RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(_extport) \
-		(((_extport) % 2) * 4)
-
-/* EXT port RGMII TX/RX delay configuration registers 1~2 */
-#define RTL8367C_EXT_RGMXF_REG1		0x1307
-#define RTL8367C_EXT_RGMXF_REG2		0x13C5
-#define RTL8367C_EXT_RGMXF_REG(_extport)   \
-		(RTL8367C_EXT_RGMXF_REG1 + \
-		 (((_extport) >> 1) * (0x13C5 - 0x1307)))
+#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG0		0x1305 /*EXT1*/
+#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG1		0x13C3 /*EXT2*/
+#define RTL8367C_DIGITAL_INTERFACE_SELECT_REG(_extint) \
+		(_extint==1 ? RTL8367C_DIGITAL_INTERFACE_SELECT_REG0 : \
+		 _extint==2 ? RTL8367C_DIGITAL_INTERFACE_SELECT_REG1 : \
+		 0x0)
+#define   RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_MASK(_extint) \
+		(0xF << (((_extint) % 2)))
+#define   RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(_extint) \
+		(((_extint) % 2) * 4)
+
+/* EXT port RGMII TX/RX delay configuration registers 0~2 */
+#define RTL8367C_EXT_RGMXF_REG0		0x1306 /*EXT0*/
+#define RTL8367C_EXT_RGMXF_REG1		0x1307 /*EXT1*/
+#define RTL8367C_EXT_RGMXF_REG2		0x13C5 /*EXT2*/
+#define RTL8367C_EXT_RGMXF_REG(_extint) \
+		(_extint==0 ? RTL8367C_EXT_RGMXF_REG0 : \
+		 _extint==1 ? RTL8367C_EXT_RGMXF_REG1 : \
+		 _extint==2 ? RTL8367C_EXT_RGMXF_REG2 : \
+		 0x0)
 #define   RTL8367C_EXT_RGMXF_RXDELAY_MASK	0x0007
 #define   RTL8367C_EXT_RGMXF_TXDELAY_MASK	0x0008
 
@@ -222,13 +226,14 @@
 #define RTL8367C_PORT_SPEED_1000M	2
 
 /* EXT port force configuration registers 0~2 */
-#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG0			0x1310
-#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG1			0x1311
-#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG2			0x13C4
-#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG(_extport)   \
-		(RTL8367C_DIGITAL_INTERFACE_FORCE_REG0 + \
-		 ((_extport) & 0x1) +                     \
-		 ((((_extport) >> 1) & 0x1) * (0x13C4 - 0x1310)))
+#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG0		0x1310 /*EXT0*/
+#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG1		0x1311 /*EXT1*/
+#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG2		0x13C4 /*EXT2*/
+#define RTL8367C_DIGITAL_INTERFACE_FORCE_REG(_extint) \
+		(_extint==0 ? RTL8367C_DIGITAL_INTERFACE_FORCE_REG0 : \
+		 _extint==1 ? RTL8367C_DIGITAL_INTERFACE_FORCE_REG1 : \
+		 _extint==2 ? RTL8367C_DIGITAL_INTERFACE_FORCE_REG2 : \
+		 0x0)
 #define   RTL8367C_DIGITAL_INTERFACE_FORCE_EN_MASK		0x1000
 #define   RTL8367C_DIGITAL_INTERFACE_FORCE_NWAY_MASK		0x0080
 #define   RTL8367C_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK		0x0040
@@ -511,6 +516,7 @@ struct rtl8367c_cpu {
  *         access via rtl8367c_get_stats64
  * @stats_lock: protect the stats structure during read/update
  * @mib_work: delayed work for polling MIB counters
+ * @ext_int: the external interface related to this port (-1 to none)
  */
 struct rtl8367c_port {
 	struct realtek_priv *priv;
@@ -518,6 +524,7 @@ struct rtl8367c_port {
 	struct rtnl_link_stats64 stats;
 	spinlock_t stats_lock;
 	struct delayed_work mib_work;
+	int ext_int;
 };
 
 /**
@@ -733,15 +740,15 @@ static int rtl8367c_ext_config_rgmii(struct realtek_priv *priv, int port,
 {
 	struct device_node *dn;
 	struct dsa_port *dp;
+	struct rtl8367c_port *p;
+	struct rtl8367c *mb;
 	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 {
+	if (port != priv->cpu_port) {
 		dev_err(priv->dev, "only one EXT port is currently supported\n");
 		return -EINVAL;
 	}
@@ -749,6 +756,10 @@ static int rtl8367c_ext_config_rgmii(struct realtek_priv *priv, int port,
 	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
@@ -792,7 +803,7 @@ static int rtl8367c_ext_config_rgmii(struct realtek_priv *priv, int port,
 	}
 
 	ret = regmap_update_bits(
-		priv->map, RTL8367C_EXT_RGMXF_REG(ext_port),
+		priv->map, RTL8367C_EXT_RGMXF_REG(ext_int),
 		RTL8367C_EXT_RGMXF_TXDELAY_MASK |
 			RTL8367C_EXT_RGMXF_RXDELAY_MASK,
 		FIELD_PREP(RTL8367C_EXT_RGMXF_TXDELAY_MASK, tx_delay) |
@@ -801,11 +812,11 @@ static int rtl8367c_ext_config_rgmii(struct realtek_priv *priv, int port,
 		return ret;
 
 	ret = regmap_update_bits(
-		priv->map, RTL8367C_DIGITAL_INTERFACE_SELECT_REG(ext_port),
-		RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_MASK(ext_port),
+		priv->map, RTL8367C_DIGITAL_INTERFACE_SELECT_REG(ext_int),
+		RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_MASK(ext_int),
 		RTL8367C_EXT_PORT_MODE_RGMII
 			<< RTL8367C_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(
-				   ext_port));
+				   ext_int));
 	if (ret)
 		return ret;
 
@@ -816,22 +827,26 @@ static int rtl8367c_ext_config_forcemode(struct realtek_priv *priv, int port,
 					  bool link, int speed, int duplex,
 					  bool tx_pause, bool rx_pause)
 {
+	struct rtl8367c_port *p;
+	struct rtl8367c *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 {
+	if (port != priv->cpu_port) {
 		dev_err(priv->dev, "only one EXT port 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;
@@ -878,7 +893,7 @@ static int rtl8367c_ext_config_forcemode(struct realtek_priv *priv, int port,
 			 r_duplex) |
 	      FIELD_PREP(RTL8367C_DIGITAL_INTERFACE_FORCE_SPEED_MASK, r_speed);
 	ret = regmap_write(priv->map,
-			   RTL8367C_DIGITAL_INTERFACE_FORCE_REG(ext_port),
+			   RTL8367C_DIGITAL_INTERFACE_FORCE_REG(ext_int),
 			   val);
 	if (ret)
 		return ret;
@@ -1807,7 +1822,9 @@ static int rtl8367c_setup(struct dsa_switch *ds)
 
 	/* Configure ports */
 	for (i = 0; i < priv->num_ports; i++) {
+		struct device_node *dn;
 		struct rtl8367c_port *p = &mb->ports[i];
+		u32 val;
 
 		if (dsa_is_unused_port(priv->ds, i))
 			continue;
@@ -1831,6 +1848,23 @@ static int rtl8367c_setup(struct dsa_switch *ds)
 		 * administratively down by default.
 		 */
 		rtl8367c_port_stp_state_set(priv->ds, i, BR_STATE_DISABLED);
+
+		dn = dsa_to_port(priv->ds, i)->dn;
+
+		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))
+				/* existing default */
+				p->ext_int = 1;
+			else
+				p->ext_int = -1;
+		}
 	}
 
 	/* Set maximum packet length to 1536 bytes */
-- 
2.34.0


  parent reply	other threads:[~2021-12-16 20:14 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 20:13 [PATCH net-next 00/13] net: dsa: realtek: MDIO interface and RTL8367S luizluca
2021-12-16 20:13 ` [PATCH net-next 01/13] dt-bindings: net: dsa: realtek-smi: remove unsupported switches luizluca
2021-12-16 23:20   ` Alvin Šipraga
2021-12-18  2:41   ` Linus Walleij
2021-12-18  6:12     ` Luiz Angelo Daros de Luca
2021-12-19 22:27       ` Linus Walleij
2021-12-16 20:13 ` [PATCH net-next 02/13] net: dsa: realtek-smi: move to subdirectory luizluca
2021-12-16 23:21   ` Alvin Šipraga
2021-12-18  2:41   ` Linus Walleij
2021-12-16 20:13 ` [PATCH net-next 03/13] net: dsa: realtek: rename realtek_smi to realtek_priv luizluca
2021-12-16 23:22   ` Alvin Šipraga
2021-12-17  6:21     ` Luiz Angelo Daros de Luca
2021-12-18  2:45       ` Linus Walleij
2021-12-18  6:15         ` Luiz Angelo Daros de Luca
2021-12-17  9:21     ` Andrew Lunn
2021-12-16 20:13 ` [PATCH net-next 04/13] net: dsa: realtek: convert subdrivers into modules luizluca
2021-12-16 23:29   ` Alvin Šipraga
2021-12-17  6:50     ` Luiz Angelo Daros de Luca
2021-12-17  2:31   ` kernel test robot
2021-12-17  2:31     ` kernel test robot
2021-12-16 20:13 ` [PATCH net-next 05/13] net: dsa: realtek: use phy_read in ds->ops luizluca
2021-12-18  2:50   ` Linus Walleij
2021-12-18  6:24     ` Luiz Angelo Daros de Luca
2021-12-16 20:13 ` [PATCH net-next 06/13] net: dsa: rtl8365mb: move rtl8365mb.c to rtl8367c.c luizluca
2021-12-19 22:29   ` Linus Walleij
2021-12-19 23:21     ` Alvin Šipraga
2021-12-16 20:13 ` [PATCH net-next 07/13] net: dsa: rtl8365mb: rename rtl8365mb to rtl8367c luizluca
2021-12-16 23:41   ` Alvin Šipraga
2021-12-17  7:24     ` Luiz Angelo Daros de Luca
2021-12-17 12:15       ` Alvin Šipraga
2021-12-17 22:50         ` Arınç ÜNAL
2021-12-18  6:08         ` Luiz Angelo Daros de Luca
2021-12-17 10:57     ` Arınç ÜNAL
2021-12-16 20:13 ` [PATCH net-next 08/13] net: dsa: realtek: add new mdio interface for drivers luizluca
2021-12-17  0:11   ` Alvin Šipraga
2021-12-17  3:33   ` kernel test robot
2021-12-17  3:33     ` kernel test robot
2021-12-18  2:54   ` Linus Walleij
2021-12-16 20:13 ` [PATCH net-next 09/13] dt-bindings: net: dsa: realtek-mdio: document new interface luizluca
2021-12-18  2:57   ` Linus Walleij
2021-12-18  6:26     ` Luiz Angelo Daros de Luca
2021-12-16 20:13 ` luizluca [this message]
2021-12-16 20:13 ` [PATCH net-next 11/13] net: dsa: realtek: rtl8367c: use GENMASK(n-1,0) instead of BIT(n)-1 luizluca
2021-12-18  2:59   ` Linus Walleij
2021-12-19 20:06   ` Florian Fainelli
2021-12-19 20:28     ` Luiz Angelo Daros de Luca
2021-12-16 20:13 ` [PATCH net-next 12/13] net: dsa: realtek: rtl8367c: use DSA CPU port luizluca
2021-12-16 20:13 ` [PATCH net-next 13/13] net: dsa: realtek: rtl8367c: add RTL8367S support luizluca
2021-12-16 22:30 ` [PATCH net-next 00/13] net: dsa: realtek: MDIO interface and RTL8367S Arınç ÜNAL
2021-12-17  0:25 ` Jakub Kicinski
2021-12-17  8:53   ` Luiz Angelo Daros de Luca
2021-12-17  9:26     ` Andrew Lunn
2021-12-17 10:19       ` Luiz Angelo Daros de Luca
2021-12-18  8:14 ` Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 01/13] dt-bindings: net: dsa: realtek-smi: mark unsupported switches Luiz Angelo Daros de Luca
2021-12-19 19:46     ` Linus Walleij
2021-12-18  8:14   ` [PATCH net-next v2 02/13] net: dsa: realtek-smi: move to subdirectory Luiz Angelo Daros de Luca
2021-12-19 21:43     ` Alvin Šipraga
2021-12-18  8:14   ` [PATCH net-next v2 03/13] net: dsa: realtek: rename realtek_smi to realtek_priv Luiz Angelo Daros de Luca
2021-12-19 22:24     ` Linus Walleij
2021-12-18  8:14   ` [PATCH net-next v2 04/13] net: dsa: realtek: remove direct calls to realtek-smi Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 05/13] net: dsa: realtek: convert subdrivers into modules Luiz Angelo Daros de Luca
2021-12-19 22:25     ` Linus Walleij
2021-12-18  8:14   ` [PATCH net-next v2 06/13] net: dsa: realtek: use phy_read in ds->ops Luiz Angelo Daros de Luca
2021-12-19 19:58     ` Florian Fainelli
2021-12-30 19:44       ` Luiz Angelo Daros de Luca
2021-12-30 20:00         ` Andrew Lunn
2021-12-31  2:30           ` Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 07/13] net: dsa: realtek: add new mdio interface for drivers Luiz Angelo Daros de Luca
2021-12-19 21:17     ` Alvin Šipraga
2021-12-19 21:44       ` Andrew Lunn
2021-12-19 22:32       ` Linus Walleij
2021-12-28  8:21       ` Luiz Angelo Daros de Luca
2021-12-28  9:57         ` Andrew Lunn
2021-12-31  3:10       ` Luiz Angelo Daros de Luca
2021-12-20 14:49     ` kernel test robot
2021-12-20 14:49       ` kernel test robot
2021-12-18  8:14   ` [PATCH net-next v2 08/13] dt-bindings: net: dsa: realtek-mdio: document new interface Luiz Angelo Daros de Luca
2021-12-19 19:57     ` Florian Fainelli
2021-12-19 21:53     ` Arınç ÜNAL
2021-12-20  7:50       ` Arınç ÜNAL
2021-12-18  8:14   ` [PATCH net-next v2 09/13] net: dsa: realtek: rtl8365mb: rename extport to extint, add "realtek,ext-int" Luiz Angelo Daros de Luca
2021-12-19 22:45     ` Alvin Šipraga
2021-12-18  8:14   ` [PATCH net-next v2 10/13] net: dsa: realtek: rtl8365mb: use GENMASK(n-1,0) instead of BIT(n)-1 Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 11/13] net: dsa: realtek: rtl8365mb: use DSA CPU port Luiz Angelo Daros de Luca
2021-12-19 22:19     ` Vladimir Oltean
2021-12-19 23:19       ` Alvin Šipraga
2021-12-28  8:48         ` Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 12/13] net: dsa: realtek: rtl8365mb: add RTL8367S support Luiz Angelo Daros de Luca
2021-12-19 21:43     ` Alvin Šipraga
2021-12-31  0:18       ` Luiz Angelo Daros de Luca
2021-12-18  8:14   ` [PATCH net-next v2 13/13] dt-bindings: net: dsa: realtek-{smi,mdio}: add rtl8367s Luiz Angelo Daros de Luca
2021-12-18  8:19   ` net: dsa: realtek: MDIO interface and RTL8367S Luiz Angelo Daros de Luca
2021-12-19 23:28   ` Alvin Šipraga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211216201342.25587-11-luizluca@gmail.com \
    --to=luizluca@gmail.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=arinc.unal@arinc9.com \
    --cc=f.fainelli@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.