Skip to contentSkip to conversation

net: Add support for Qualcomm ethqos

PATCH Superseded Vinod Koul 5 participants 17 messages Jan 2, 2019 – Jan 14, 2019

Subsystems (9)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

cover net: Add support for Qualcomm ethqos

Some Qualcomm SoCs sport a ethqos controller which use DW ip, so add the glue driver which uses stmmac driver along with DT bindings for this device.

This controller supports rgmii mode and doesn't work with existing phy drivers as they do not remove the phy delay delay in this mode, so add a DT property and disable the delay when this property is present, this is done for two phys at803x and qca8k.

Vinod Koul (7):
dt-bindings: net: Add Qualcomm ethqos binding
net: stmmac: Add driver for Qualcomm ethqos
dt-bindings: net: stmmac: Add the bindings documentation for delays
MAINTAINER: Add entry for Qualcomm ETHQOS ethernet driver
net: phy: at803x: Rework at803x_config_init()
net: phy: at803x: Add support to disable tx/rx delays
net: dsa: qca8k: handle disable tx/rx delay

 .../devicetree/bindings/net/qcom,dwmac.txt    | 129 +++++
 .../devicetree/bindings/net/stmmac.txt        |   2 +
 MAINTAINERS                                   |   8 +
 drivers/net/dsa/qca8k.c                       |  27 +-
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  10 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../stmicro/stmmac/dwmac-qcom-ethqos.c        | 545 ++++++++++++++++++
 drivers/net/phy/at803x.c                      |  48 +-
 8 files changed, 758 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/qcom,dwmac.txt
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/7 dt-bindings: net: Add Qualcomm ethqos binding

Add support for Qualcomm ethqos found in some SoCs like QCS404.

---
 .../devicetree/bindings/net/qcom,dwmac.txt    | 129 ++++++++++++++++++
 1 file changed, 129 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom,dwmac.txt
Documentation/devicetree/bindings/net/qcom,dwmac.txt new file +129 -0
new file mode 100644
index 000000000000..e3a412695afb
@@ -0,0 +1,129 @@
+Qualcomm Ethernet ETHQOS device
+
+This device has following properties:
+
+Required properties:
+
+- compatible: Should be qcom,ethqos-qcs404"
+
+- reg: Address and length of the register set for the device
+
+- reg-names: Should contain register names "stmmaceth", "rgmii"
+
+- clocks: Should contain phandle to clocks
+
+- clock-names: Should contain clock names "stmmaceth", "pclk",
+		"ptp_ref", "rgmii"
+
+- interrupts: Should contain phandle to interrupts
+
+- interrupt-names: Should contain interrupt names "macirq", "eth_lpi"
+
+Rest of the properties are defined in stmmac.txt file in same directory
+
+
+Example:
+
+ethernet: ethernet@7a80000 {
+	compatible = "qcom,ethqos-qcs404";
+	reg = <0x07a80000 0x10000>,
+		<0x07a96000 0x100>;
+	reg-names = "stmmaceth", "rgmii";
+	clock-names = "stmmaceth", "pclk", "ptp_ref", "rgmii";
+	clocks = <&gcc GCC_ETH_AXI_CLK>,
+		<&gcc GCC_ETH_SLAVE_AHB_CLK>,
+		<&gcc GCC_ETH_PTP_CLK>,
+		<&gcc GCC_ETH_RGMII_CLK>;
+	interrupts = <GIC_SPI 56 IRQ_TYPE_LEVEL_HIGH>,
+			<GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>;
+	interrupt-names = "macirq", "eth_lpi";
+	snps,reset-gpio = <&tlmm 60 GPIO_ACTIVE_LOW>;
+	snps,reset-active-low;
+	snps,axi-config = <&stmmac_axi_setup>;
+	snps,mtl-rx-config = <&mtl_rx_setup>;
+	snps,mtl-tx-config = <&mtl_tx_setup>;
+
+	snps,txpbl = <8>;
+	snps,rxpbl = <2>;
+	snps,aal;
+	snps,tso;
+
+	phy-handle = <&phy1>;
+	phy-mode = "rgmii";
+
+	stmmac_axi_setup: stmmac-axi-config {
+		snps,wr_osr_lmt = <15>;
+		snps,rd_osr_lmt = <15>;
+		snps,blen = <256 128 64 32 0 0 0>;
+	};
+
+	mtl_rx_setup: rx-queues-config {
+		snps,rx-queues-to-use = <4>;
+		snps,rx-sched-sp;
+		queue0 {
+			snps,dcb-algorithm;
+			snps,map-to-dma-channel = <0x0>;
+			snps,priority = <0x0>;
+		};
+		queue1 {
+			snps,dcb-algorithm;
+			snps,map-to-dma-channel = <0x1>;
+			snps,priority = <0x1>;
+		};
+		queue2 {
+			snps,dcb-algorithm;
+			snps,map-to-dma-channel = <0x2>;
+			snps,priority = <0x1>;
+		};
+		queue3 {
+			snps,dcb-algorithm;
+			snps,map-to-dma-channel = <0x3>;
+			snps,priority = <0x1>;
+		};
+	};
+
+	mtl_tx_setup: tx-queues-config {
+		snps,tx-queues-to-use = <4>;
+		snps,tx-sched-wrr;
+		queue0 {
+			snps,weight = <0x10>;
+			snps,dcb-algorithm;
+			snps,priority = <0x0>;
+		};
+		queue1 {
+			snps,avb-algorithm;
+			snps,send_slope = <0x1000>;
+			snps,idle_slope = <0x1000>;
+			snps,high_credit = <0x3E800>;
+			snps,low_credit = <0xFFC18000>;
+			snps,priority = <0x1>;
+		};
+		queue2 {
+			snps,avb-algorithm;
+			snps,send_slope = <0x1000>;
+			snps,idle_slope = <0x1000>;
+			snps,high_credit = <0x3E800>;
+			snps,low_credit = <0xFFC18000>;
+			snps,priority = <0x1>;
+		};
+		queue3 {
+			snps,avb-algorithm;
+			snps,send_slope = <0x1000>;
+			snps,idle_slope = <0x1000>;
+			snps,high_credit = <0x3E800>;
+			snps,low_credit = <0xFFC18000>;
+			snps,priority = <0x1>;
+		};
+	};
+
+	mdio {
+		#address-cells = <0x1>;
+		#size-cells = <0x0>;
+		compatible = "snps,dwmac-mdio";
+		phy1: phy@1 {
+			device_type = "ethernet-phy";
+			reg = <0x4>;
+		};
+	};
+
+};
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH 1/7] dt-bindings: net: Add Qualcomm ethqos binding

Documentation/devicetree/bindings/net/qcom,dwmac.txt line 123

Quoted 5 lines
Documentation/devicetree/bindings/net/qcom,dwmac.txt new file +5 -0
+	mdio {
+		#address-cells = <0x1>;
+		#size-cells = <0x0>;
+		compatible = "snps,dwmac-mdio";
+		phy1: phy@1 {

phy@4 since reg = 0x4

Documentation/devicetree/bindings/net/qcom,dwmac.txt line 125

Quoted 2 lines
Documentation/devicetree/bindings/net/qcom,dwmac.txt new file +2 -0
+			device_type = "ethernet-phy";
+			reg = <0x4>;

Thanks,
Andrew

author
#3 lore raw

Re: [PATCH 1/7] dt-bindings: net: Add Qualcomm ethqos binding

Quoted 7 lines · Andrew Lunn

Documentation/devicetree/bindings/net/qcom,dwmac.txt line 123

Quoted 5 lines
Documentation/devicetree/bindings/net/qcom,dwmac.txt new file +5 -0
+	mdio {
+		#address-cells = <0x1>;
+		#size-cells = <0x0>;
+		compatible = "snps,dwmac-mdio";
+		phy1: phy@1 {

phy@4 since reg = 0x4

Right, will fix this

Signature · 1 line
~Vinod
author
#4 lore raw

PATCH 2/7 net: stmmac: Add driver for Qualcomm ethqos

In reply to Vinod Koul

Add glue driver to support Qualcomm ETHQOS using stmmac driver.

This is based on downstream driver written by Siddarth Gupta, Sunil Kumar Paidimarri, Rahul Ankushrao Kawadgave, Nisha Menon, Jagadeesh Babu Challagundla, Chaitanya Pratapa, Lakshit Tyagi, Suraj Jaiswal, Sneh Shah and Ventrapragada Ravi Kanth

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  10 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../stmicro/stmmac/dwmac-qcom-ethqos.c        | 545 ++++++++++++++++++
 3 files changed, 556 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
drivers/net/ethernet/stmicro/stmmac/Kconfig +10 -0
index 324049eebb9b..fc36f035f112 100644
@@ -97,6 +97,16 @@ config DWMAC_OXNAS
 	  This selects the Oxford Semiconductor OXNASSoC glue layer support for
 	  the stmmac device driver. This driver is used for OX820.
 
+config DWMAC_QCOM_ETHQOS
+	tristate "Qualcomm ETHQOS support"
+	default ARCH_QCOM
+	depends on OF && (ARCH_QCOM || COMPILE_TEST)
+	help
+	  Support for the Qualcomm ETHQOS core.
+
+	  This selects the Qualcomm ETHQOS glue layer support for the
+	  stmmac device driver.
+
 config DWMAC_ROCKCHIP
 	tristate "Rockchip dwmac support"
 	default ARCH_ROCKCHIP
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index 99967a80a8c8..78b92316e87d 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_DWMAC_IPQ806X)	+= dwmac-ipq806x.o
 obj-$(CONFIG_DWMAC_LPC18XX)	+= dwmac-lpc18xx.o
 obj-$(CONFIG_DWMAC_MESON)	+= dwmac-meson.o dwmac-meson8b.o
 obj-$(CONFIG_DWMAC_OXNAS)	+= dwmac-oxnas.o
+obj-$(CONFIG_DWMAC_QCOM_ETHQOS)	+= dwmac-qcom-ethqos.o
 obj-$(CONFIG_DWMAC_ROCKCHIP)	+= dwmac-rk.o
 obj-$(CONFIG_DWMAC_SOCFPGA)	+= dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_STI)		+= dwmac-sti.o
drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c new file +545 -0

545 lines not on this page · raw message

Signature · 1 line
2.20.1
author
#5 lore raw

PATCH 3/7 dt-bindings: net: stmmac: Add the bindings documentation for delays

In reply to Vinod Koul

Some controllers require that phy delay should be disabled. So add optional properties rx-disable-delay and tx-disable-delay for it.

---
 Documentation/devicetree/bindings/net/stmmac.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/net/stmmac.txt +2 -0
index cb694062afff..ec18897e22c8 100644
@@ -74,6 +74,8 @@ Optional properties:
 	- snps,mb: mixed-burst
 	- snps,rb: rebuild INCRx Burst
 - mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
+- rx-delay-disable: bool, when present disable the rx delay
+- tx-delay-disable: bool, when present disable the tx delay
 - Multiple RX Queues parameters: below the list of all the parameters to
 				 configure the multiple RX queues:
 	- snps,rx-queues-to-use: number of RX queues to be used in the driver
Signature · 1 line
2.20.1
maintainer
#6 lore raw

Re: [PATCH 3/7] dt-bindings: net: stmmac: Add the bindings documentation for delays

Quoted 1 line · Vinod Koul

Some controllers require that phy delay should be disabled. So add

If the MAC requires it, then the compatible string should imply this. If it depends on the PHY, then okay.

Quoted 12 lines

optional properties rx-disable-delay and tx-disable-delay for it.

---
 Documentation/devicetree/bindings/net/stmmac.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/net/stmmac.txt +0 -0
index cb694062afff..ec18897e22c8 100644

Documentation/devicetree/bindings/net/stmmac.txt Optional properties: · line 78

Quoted 5 lines
Documentation/devicetree/bindings/net/stmmac.txt +2 -0
@@ -74,6 +74,8 @@ Optional properties:
 	- snps,mb: mixed-burst
 	- snps,rb: rebuild INCRx Burst
 - mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
+- rx-delay-disable: bool, when present disable the rx delay
+- tx-delay-disable: bool, when present disable the tx delay

Needs a vendor prefix.

Quoted 6 lines
Documentation/devicetree/bindings/net/stmmac.txt +0 -0
 - Multiple RX Queues parameters: below the list of all the parameters to
 				 configure the multiple RX queues:
 	- snps,rx-queues-to-use: number of RX queues to be used in the driver
Signature · 1 line
2.20.1
author
#7 lore raw

Re: [PATCH 3/7] dt-bindings: net: stmmac: Add the bindings documentation for delays

HI Rob,

Quoted 5 lines · Rob Herring
Quoted 1 line · Vinod Koul

Some controllers require that phy delay should be disabled. So add

If the MAC requires it, then the compatible string should imply this. If it depends on the PHY, then okay.

Thanks for the review, yes this was targeted to PHY. After feedback from Andrew, I have removed this is v2 posted earlier!

Signature · 1 line
~Vinod
#8 lore raw

Re: [PATCH 3/7] dt-bindings: net: stmmac: Add the bindings documentation for delays

In reply to Rob Herring
Quoted 13 lines · Rob Herring
Quoted 1 line · Vinod Koul

Some controllers require that phy delay should be disabled. So add

If the MAC requires it, then the compatible string should imply this. If it depends on the PHY, then okay.

Quoted 7 lines

optional properties rx-disable-delay and tx-disable-delay for it.

---
 Documentation/devicetree/bindings/net/stmmac.txt | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines

Documentation/devicetree/bindings/net/stmmac.txt Optional properties: · line 78

Quoted 10 lines
Documentation/devicetree/bindings/net/stmmac.txt +2 -0
index cb694062afff..ec18897e22c8 100644
@@ -74,6 +74,8 @@ Optional properties:
 	- snps,mb: mixed-burst
 	- snps,rb: rebuild INCRx Burst
 - mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
+- rx-delay-disable: bool, when present disable the rx delay
+- tx-delay-disable: bool, when present disable the tx delay

Needs a vendor prefix.

Indeed, and it would actually be nicer to allow specifying delays directly in ps units, see:

Documentation/devicetree/bindings/net/dwmac-sun8i.txt Documentation/devicetree/bindings/net/mediatek-dwmac.txt

for examples.

Signature · 1 line
Florian
author
#9 lore raw

PATCH 4/7 MAINTAINER: Add entry for Qualcomm ETHQOS ethernet driver

In reply to Vinod Koul

Add myself and Nikals as maintainers for this driver

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index f4855974f325..0e3f4d97efd7 100644
@@ -12329,6 +12329,14 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/qualcomm/emac/
 
+QUALCOMM ETHQOS ETHERNET DRIVER
+M:	Vinod Koul <[email protected]>
+M:	Niklas Cassel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+F:	Documentation/devicetree/bindings/net/qcom,dwmac.txt
+
 QUALCOMM GENERIC INTERFACE I2C DRIVER
 M:	Alok Chauhan <[email protected]>
 M:	Karthikeyan Ramasubramanian <[email protected]>
Signature · 1 line
2.20.1
#10 lore raw

Re: [PATCH 4/7] MAINTAINER: Add entry for Qualcomm ETHQOS ethernet driver

Hello!

Quoted 1 line · Vinod Koul

Add myself and Nikals as maintainers for this driver

Niklas?

Quoted 15 lines
---
  MAINTAINERS | 8 ++++++++
  1 file changed, 8 insertions(+)
MAINTAINERS +1 -0
index f4855974f325..0e3f4d97efd7 100644
@@ -12329,6 +12329,14 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/net/ethernet/qualcomm/emac/
 
+QUALCOMM ETHQOS ETHERNET DRIVER

MAINTAINERS L: [email protected] · line 12342

Quoted 10 lines
MAINTAINERS +7 -0
+M:	Vinod Koul <[email protected]>
+M:	Niklas Cassel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+F:	Documentation/devicetree/bindings/net/qcom,dwmac.txt
+
  QUALCOMM GENERIC INTERFACE I2C DRIVER
  M:	Alok Chauhan <[email protected]>
  M:	Karthikeyan Ramasubramanian <[email protected]>

MBR, Sergei

author
#11 lore raw

Re: [PATCH 4/7] MAINTAINER: Add entry for Qualcomm ETHQOS ethernet driver

Quoted 7 lines · Sergei Shtylyov

Hello!

Quoted 1 line · Vinod Koul

Add myself and Nikals as maintainers for this driver

Niklas?

Damn.. will update after getting other comments. Thanks for pointing

Quoted 27 lines
Quoted 15 lines
---
  MAINTAINERS | 8 ++++++++
  1 file changed, 8 insertions(+)
MAINTAINERS +1 -0
index f4855974f325..0e3f4d97efd7 100644
@@ -12329,6 +12329,14 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/net/ethernet/qualcomm/emac/
+QUALCOMM ETHQOS ETHERNET DRIVER

MAINTAINERS L: [email protected] · line 12341

Quoted 10 lines
MAINTAINERS +7 -0
+M:	Vinod Koul <[email protected]>
+M:	Niklas Cassel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+F:	Documentation/devicetree/bindings/net/qcom,dwmac.txt
+
  QUALCOMM GENERIC INTERFACE I2C DRIVER
  M:	Alok Chauhan <[email protected]>
  M:	Karthikeyan Ramasubramanian <[email protected]>

MBR, Sergei

Signature · 1 line
~Vinod
author
#12 lore raw

PATCH 5/7 net: phy: at803x: Rework at803x_config_init()

In reply to Vinod Koul

Rework at803x_config_init() function to check and program the tx and rx delay enable separately. This will help in checking the delay to be programmed based on other conditions as well.

---
 drivers/net/phy/at803x.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/phy/at803x.c +9 -3
index e74a047a846e..63e3d3d774d1 100644
@@ -249,6 +249,7 @@ static int at803x_probe(struct phy_device *phydev)
 
 static int at803x_config_init(struct phy_device *phydev)
 {
+	bool rx_delay = false, tx_delay = false;
 	int ret;
 
 	ret = genphy_config_init(phydev);
@@ -256,14 +257,19 @@ static int at803x_config_init(struct phy_device *phydev)
 		return ret;
 
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
-			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
+			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+		rx_delay = true;
+	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
+			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+		tx_delay = true;
+
+	if (rx_delay) {
 		ret = at803x_enable_rx_delay(phydev);
 		if (ret < 0)
 			return ret;
 	}
 
-	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
-			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
+	if (tx_delay) {
 		ret = at803x_enable_tx_delay(phydev);
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.20.1
author
#13 lore raw

PATCH 6/7 net: phy: at803x: Add support to disable tx/rx delays

In reply to Vinod Koul

Some controllers require the tx and rx delays to be disabled. So check the property and if present do not enable the delay and disable the delay explicitly.

---
 drivers/net/phy/at803x.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/phy/at803x.c +36 -0
index 63e3d3d774d1..9bfc0d381159 100644
@@ -122,6 +122,17 @@ static inline int at803x_enable_tx_delay(struct phy_device *phydev)
 					AT803X_DEBUG_TX_CLK_DLY_EN);
 }
 
+static inline int at803x_disable_rx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
+					AT803X_DEBUG_RX_CLK_DLY_EN, 0);
+}
+
+static inline int at803x_disable_tx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
+					AT803X_DEBUG_TX_CLK_DLY_EN, 0);
+}
 /* save relevant PHY registers to private copy */
 static void at803x_context_save(struct phy_device *phydev,
 				struct at803x_context *context)
@@ -250,12 +261,18 @@ static int at803x_probe(struct phy_device *phydev)
 static int at803x_config_init(struct phy_device *phydev)
 {
 	bool rx_delay = false, tx_delay = false;
+	bool rx_disable_prop, tx_disable_prop;
 	int ret;
 
 	ret = genphy_config_init(phydev);
 	if (ret < 0)
 		return ret;
 
+	rx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+	tx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
 			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
 		rx_delay = true;
@@ -263,6 +280,12 @@ static int at803x_config_init(struct phy_device *phydev)
 			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
 		tx_delay = true;
 
+	/* if DT specified disable delay then don't enable it */
+	if (rx_disable_prop)
+		rx_delay = false;
+	if (tx_disable_prop)
+		tx_delay = false;
+
 	if (rx_delay) {
 		ret = at803x_enable_rx_delay(phydev);
 		if (ret < 0)
@@ -275,6 +298,19 @@ static int at803x_config_init(struct phy_device *phydev)
 			return ret;
 	}
 
+	/* if DT specified disable delay then disable it explicitly */
+	if (rx_disable_prop) {
+		ret = at803x_disable_rx_delay(phydev);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (tx_disable_prop) {
+		ret = at803x_disable_tx_delay(phydev);
+		if (ret < 0)
+			return ret;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.20.1
maintainer
#14 lore raw

Re: [PATCH 6/7] net: phy: at803x: Add support to disable tx/rx delays

Quoted 37 lines · Vinod Koul

Some controllers require the tx and rx delays to be disabled. So check the property and if present do not enable the delay and disable the delay explicitly.

---
 drivers/net/phy/at803x.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/phy/at803x.c +12 -0
index 63e3d3d774d1..9bfc0d381159 100644
@@ -122,6 +122,17 @@ static inline int at803x_enable_tx_delay(struct phy_device *phydev)
 					AT803X_DEBUG_TX_CLK_DLY_EN);
 }
 
+static inline int at803x_disable_rx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
+					AT803X_DEBUG_RX_CLK_DLY_EN, 0);
+}
+
+static inline int at803x_disable_tx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
+					AT803X_DEBUG_TX_CLK_DLY_EN, 0);
+}
 /* save relevant PHY registers to private copy */
 static void at803x_context_save(struct phy_device *phydev,
 				struct at803x_context *context)
@@ -250,12 +261,18 @@ static int at803x_probe(struct phy_device *phydev)
 static int at803x_config_init(struct phy_device *phydev)
 {
 	bool rx_delay = false, tx_delay = false;
+	bool rx_disable_prop, tx_disable_prop;
 	int ret;

drivers/net/phy/at803x.c static int at803x_probe(struct phy_device *phydev) · line 275

Quoted 10 lines
drivers/net/phy/at803x.c +5 -0
 
 	ret = genphy_config_init(phydev);
 	if (ret < 0)
 		return ret;
 
+	rx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+	tx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+

Hi Vinod

I understand why you are doing this, to not break backwards compatibility, but it is ugly. Lets see if we can avoid it. Thinking allowed here. Here are the use cases i can think of:

1) The DT does not specify any phy-mode. The board works because delays are enable by the bootloader

2) The DT correctly specifies RXID/ID/TXID and the driver does the right thing.

3) The DT incorrectly specifies no delay, the bootloader however sets delays, and the driver does not disable the delay.

4) The DT correctly specifies no delay, but the driver does not disable delays, and it does not work.

You are interested in 4) if i understand this patch correct.

1) should not be a problem. If phy-mode is not one of the RGMII values, don't touch the delays.

2) works

3) is the tricky one. But i would also say that is a bug in the DT. The question is, do we want to keep bug compatible?

I say don't add these new properties. If we have a phy-mode which explicitly specifies no delay, clear the delay. And we then fixup anything which breaks because of DT bugs.

Andrew

author
#15 lore raw

Re: [PATCH 6/7] net: phy: at803x: Add support to disable tx/rx delays

Hi Andrew,

Thanks for the comments,

Quoted 51 lines · Andrew Lunn
Quoted 37 lines · Vinod Koul

Some controllers require the tx and rx delays to be disabled. So check the property and if present do not enable the delay and disable the delay explicitly.

---
 drivers/net/phy/at803x.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/phy/at803x.c +12 -0
index 63e3d3d774d1..9bfc0d381159 100644
@@ -122,6 +122,17 @@ static inline int at803x_enable_tx_delay(struct phy_device *phydev)
 					AT803X_DEBUG_TX_CLK_DLY_EN);
 }
 
+static inline int at803x_disable_rx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
+					AT803X_DEBUG_RX_CLK_DLY_EN, 0);
+}
+
+static inline int at803x_disable_tx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
+					AT803X_DEBUG_TX_CLK_DLY_EN, 0);
+}
 /* save relevant PHY registers to private copy */
 static void at803x_context_save(struct phy_device *phydev,
 				struct at803x_context *context)
@@ -250,12 +261,18 @@ static int at803x_probe(struct phy_device *phydev)
 static int at803x_config_init(struct phy_device *phydev)
 {
 	bool rx_delay = false, tx_delay = false;
+	bool rx_disable_prop, tx_disable_prop;
 	int ret;

drivers/net/phy/at803x.c static int at803x_probe(struct phy_device *phydev) · line 275

Quoted 10 lines
drivers/net/phy/at803x.c +5 -0
 
 	ret = genphy_config_init(phydev);
 	if (ret < 0)
 		return ret;
 
+	rx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+	tx_disable_prop = device_property_read_bool(&phydev->mdio.dev,
+						    "rx-delay-disable");
+

Hi Vinod

Quoted 2 lines

I understand why you are doing this, to not break backwards compatibility, but it is ugly. Lets see if we can avoid it. Thinking

Agreed this is ugly and the reason to do this is not to break existing users

Quoted 8 lines

allowed here. Here are the use cases i can think of:

1) The DT does not specify any phy-mode. The board works because delays are enable by the bootloader

2) The DT correctly specifies RXID/ID/TXID and the driver does the right thing.

Quoted 7 lines

3) The DT incorrectly specifies no delay, the bootloader however sets delays, and the driver does not disable the delay.

4) The DT correctly specifies no delay, but the driver does not disable delays, and it does not work.

You are interested in 4) if i understand this patch correct.

that is correct reading of the patch :-)

Quoted 11 lines

1) should not be a problem. If phy-mode is not one of the RGMII values, don't touch the delays.

2) works

3) is the tricky one. But i would also say that is a bug in the DT. The question is, do we want to keep bug compatible?

I say don't add these new properties. If we have a phy-mode which explicitly specifies no delay, clear the delay. And we then fixup anything which breaks because of DT bugs.

I do not mind fixing this and doing disable delays for rgmii mode, if we agree that it would break devices and those should be fixed and not treated as a regression due to this fix. As long as Dave agree to this, I can spin a v2 and post :)

~Vinod

author
#16 lore raw

PATCH 7/7 net: dsa: qca8k: handle disable tx/rx delay

In reply to Vinod Koul

We should disable tx/rx delay in rgmii mode, but driver doesn't do so. Hence add a device tree property to avoid breaking current users and disable only when this property is set

<Fixme: change author to ...>

---
 drivers/net/dsa/qca8k.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/net/dsa/qca8k.c +18 -9
index 7e97e620bd44..6dfb390ebe66 100644
@@ -420,7 +420,9 @@ qca8k_mib_init(struct qca8k_priv *priv)
 static int
 qca8k_set_pad_ctrl(struct qca8k_priv *priv, int port, int mode)
 {
-	u32 reg;
+	u32 reg, val;
+	struct dsa_switch *ds = priv->ds;
+	bool rx_delay_disable, tx_delay_disable;
 
 	switch (port) {
 	case 0:
@@ -439,17 +441,24 @@ qca8k_set_pad_ctrl(struct qca8k_priv *priv, int port, int mode)
 	 */
 	switch (mode) {
 	case PHY_INTERFACE_MODE_RGMII:
-		qca8k_write(priv, reg,
-			    QCA8K_PORT_PAD_RGMII_EN |
-			    QCA8K_PORT_PAD_RGMII_TX_DELAY(3) |
-			    QCA8K_PORT_PAD_RGMII_RX_DELAY(3));
-
-		/* According to the datasheet, RGMII delay is enabled through
+		rx_delay_disable = of_property_read_bool(ds->dst->cpu_dp->dn,
+							 "rx-delay-disable");
+		tx_delay_disable = of_property_read_bool(ds->dst->cpu_dp->dn,
+							 "tx-delay-disable");
+		val = QCA8K_PORT_PAD_RGMII_EN;
+		if (!rx_delay_disable)
+			val |= QCA8K_PORT_PAD_RGMII_RX_DELAY(3);
+		if (!tx_delay_disable)
+			val |= QCA8K_PORT_PAD_RGMII_TX_DELAY(3);
+		qca8k_write(priv, reg, val);
+
+		/* According to the datasheet, RGMII rx delay is enabled through
 		 * PORT5_PAD_CTRL for all ports, rather than individual port
 		 * registers
 		 */
-		qca8k_write(priv, QCA8K_REG_PORT5_PAD_CTRL,
-			    QCA8K_PORT_PAD_RGMII_RX_DELAY_EN);
+		if (!rx_delay_disable)
+			qca8k_write(priv, QCA8K_REG_PORT5_PAD_CTRL,
+				    QCA8K_PORT_PAD_RGMII_RX_DELAY_EN);
 		break;
 	case PHY_INTERFACE_MODE_SGMII:
 		qca8k_write(priv, reg, QCA8K_PORT_PAD_SGMII_EN);
Signature · 1 line
2.20.1