Skip to contentSkip to conversation

net: cortina_ni: Add eth support for Cortina Access CAxxxx SoCs

PATCH New Alex Nemirovsky 2 participants 10 messages Sep 24, 2020 – Sep 29, 2020

Subsystems (3)

v3 of 4 New Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 net: cortina_ni: Add eth support for Cortina Access CAxxxx SoCs

From: Abbie Chang <[email protected]>

Add Cortina Access Ethernet device driver for CAxxxx SoCs. This driver supports both legacy and DM_ETH network models.

CC Joe Hershberger <[email protected]>
CC Abbie Chang <[email protected]>
CC Tom Rini <[email protected]>

---

Changes in v3:
- cleanup up usage of ca_status to return errno

Changes in v2:
- clean up old debug code
- reference CRC functions already provided in u-boot core
- remove unused code, ex: CA_IN/CA_OUT
- refactor the design of register read/write, union -> struct
- remove platform dependent code

 MAINTAINERS              |    4 +
 drivers/net/Kconfig      |    7 +
 drivers/net/Makefile     |    1 +
 drivers/net/cortina_ni.c | 1168 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/cortina_ni.h |  405 ++++++++++++++++
 5 files changed, 1585 insertions(+)
 create mode 100644 drivers/net/cortina_ni.c
 create mode 100644 drivers/net/cortina_ni.h
MAINTAINERS +4 -0
index 101f4e1..dd4156c 100644
@@ -197,6 +197,8 @@ F:	drivers/led/led_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
+F:	drivers/net/cortina_ni.c
+F:	drivers/net/cortina_ni.h
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:	Marek Behun <[email protected]>
@@ -781,6 +783,8 @@ F:	drivers/led/led_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
+F:	drivers/net/cortina_ni.c
+F:	drivers/net/cortina_ni.h
 
 MIPS MSCC
 M:	Gregory CLEMENT <[email protected]>
drivers/net/Kconfig +7 -0
index 039f9fb..893a159 100644
@@ -149,6 +149,13 @@ config BCMGENET
 	help
 	  This driver supports the BCMGENET Ethernet MAC.
 
+config CORTINA_NI_ENET
+	bool "Cortina-Access Ethernet driver"
+	depends on DM_ETH && CORTINA_PLATFORM
+	help
+	  This driver supports the Cortina-Access Ethernet MAC for
+	  all supported CAxxxx SoCs.
+
 config DWC_ETH_QOS
 	bool "Synopsys DWC Ethernet QOS device support"
 	depends on DM_ETH
drivers/net/Makefile +1 -0
index 1ecdc40..a6f04bc 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_DRIVER_AX88180) += ax88180.o
 obj-$(CONFIG_BCM_SF2_ETH) += bcm-sf2-eth.o
 obj-$(CONFIG_BCM_SF2_ETH_GMAC) += bcm-sf2-eth-gmac.o
 obj-$(CONFIG_CALXEDA_XGMAC) += calxedaxgmac.o
+obj-$(CONFIG_CORTINA_NI_ENET) += cortina_ni.o
 obj-$(CONFIG_CS8900) += cs8900.o
 obj-$(CONFIG_TULIP) += dc2114x.o
 obj-$(CONFIG_ETH_DESIGNWARE) += designware.o
drivers/net/cortina_ni.c new file +1168 -0

1,168 lines not on this page · raw message

drivers/net/cortina_ni.h new file +405 -0

405 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 2/3 net: phy: ca_phy: Add driver for CAxxxx SoCs

From: Abbie Chang <[email protected]>

Add phy driver support for MACs embedded inside Cortina Access SoCs

CC Joe Hershberger <[email protected]>
CC Tom Rini <[email protected]>
CC Aaron Tseng <[email protected]>

Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver

---

(no changes since v1)

 MAINTAINERS              |   2 +
 drivers/net/phy/Kconfig  |   9 ++++
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/ca_phy.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c    |   2 +
 include/phy.h            |   1 +
 6 files changed, 148 insertions(+)
 create mode 100644 drivers/net/phy/ca_phy.c
MAINTAINERS +2 -0
index dd4156c..a9ab791 100644
@@ -199,6 +199,7 @@ F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
 F:	drivers/net/cortina_ni.c
 F:	drivers/net/cortina_ni.h
+F:	drivers/net/phy/ca_phy.c
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:	Marek Behun <[email protected]>
@@ -785,6 +786,7 @@ F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
 F:	drivers/net/cortina_ni.c
 F:	drivers/net/cortina_ni.h
+F:	drivers/net/phy/ca_phy.c
 
 MIPS MSCC
 M:	Gregory CLEMENT <[email protected]>
drivers/net/phy/Kconfig +9 -0
index 4e1a93b..7aa60be 100644
@@ -122,6 +122,15 @@ config SYS_CORTINA_FW_IN_SPIFLASH
 
 endchoice
 
+config PHY_CORTINA_ACCESS
+	bool "Cortina Access Ethernet PHYs support"
+	default y
+	depends on CORTINA_NI_ENET
+	help
+		Cortina Access Ethernet PHYs support
+
+		Cortina Access Ethernet PHYs init process
+
 config PHY_DAVICOM
 	bool "Davicom Ethernet PHYs support"
 
drivers/net/phy/Makefile +1 -0
index 6e72233..e967f82 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_AQUANTIA) += aquantia.o
 obj-$(CONFIG_PHY_ATHEROS) += atheros.o
 obj-$(CONFIG_PHY_BROADCOM) += broadcom.o
 obj-$(CONFIG_PHY_CORTINA) += cortina.o
+obj-$(CONFIG_PHY_CORTINA_ACCESS) += ca_phy.o
 obj-$(CONFIG_PHY_DAVICOM) += davicom.o
 obj-$(CONFIG_PHY_ET1011C) += et1011c.o
 obj-$(CONFIG_PHY_LXT) += lxt.o
drivers/net/phy/ca_phy.c new file +133 -0

133 lines not on this page · raw message

drivers/net/phy/phy.c +2 -0
index 6778989..f0b4aa4 100644
@@ -500,6 +500,8 @@ int phy_init(void)
 #ifdef CONFIG_PHY_CORTINA
 	phy_cortina_init();
 #endif
+	if (IS_ENABLED(CONFIG_PHY_CORTINA_ACCESS))
+		phy_cortina_access_init();
 #ifdef CONFIG_PHY_DAVICOM
 	phy_davicom_init();
 #endif
include/phy.h +1 -0
index 1dbbf65..c2ecd70 100644
@@ -493,6 +493,7 @@ int phy_aquantia_init(void);
 int phy_atheros_init(void);
 int phy_broadcom_init(void);
 int phy_cortina_init(void);
+int phy_cortina_access_init(void);
 int phy_davicom_init(void);
 int phy_et1011c_init(void);
 int phy_lxt_init(void);
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 2/3 net: phy: ca_phy: Add driver for CAxxxx SoCs

Quoted 13 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add phy driver support for MACs embedded inside Cortina Access SoCs

CC Joe Hershberger <[email protected]>
CC Tom Rini <[email protected]>
CC Aaron Tseng <[email protected]>

Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver

[snip]

Quoted 64 lines
drivers/net/phy/ca_phy.c new file +64 -0
+__weak void __internal_phy_init(struct phy_device *phydev, int reset_phy)
+{
+	u8 phy_addr;
+	u16     data;
+
+	/* should initialize 4 GPHYs at once */
+	for (phy_addr = 4; phy_addr > 0; phy_addr--) {
+		phydev->addr = phy_addr;
+		phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0BC6);
+		phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x0053);
+		phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x4003);
+		phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x7e01);
+		phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A42);
+		phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A40);
+		phy_write(phydev, MDIO_DEVAD_NONE,  0, 0x1140);
+	}
+
+	/* workaround to fix GPHY fail */
+	for (phy_addr = 1; phy_addr < 5; phy_addr++) {
+		/* Clear clock fail interrupt */
+		phydev->addr = phy_addr;
+		phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+		data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+		if (data == 0x10) {
+			phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+			data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+			printf("%s: read again.\n", __func__);
+		}
+
+		printf("%s: phy_addr=%d, read register 19, value=0x%x\n",
+		       __func__, phy_addr, data);
+	}
+}
+
+__weak void __external_phy_init(struct phy_device *phydev, int reset_phy)
+{
+	u16 val;
+
+	/* Disable response PHYAD=0 function of RTL8211 series PHY */
+	/* REG31 write 0x0007, set to extension page */
+	phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0007);
+
+	/* REG30 write 0x002C, set to extension page 44 */
+	phy_write(phydev, MDIO_DEVAD_NONE, 30, 0x002C);
+
+	/*
+	 * REG27 write bit[2] = 0 disable response PHYAD = 0 function.
+	 * we should read REG27 and clear bit[2], and write back
+	 */
+	val = phy_read(phydev, MDIO_DEVAD_NONE, 27);
+	val &= ~(1 << 2);
+	phy_write(phydev, MDIO_DEVAD_NONE, 27, val);
+
+	/* REG31 write 0X0000, back to page0 */
+	phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000);
+}
+
+static int rtl8211_external_config(struct phy_device *phydev)
+{
+	__external_phy_init(phydev, 0);
+	printf("%s: initialize RTL8211 external done.\n", __func__);
+	return 0;
+}
+

drivers/net/phy/ca_phy.c line 97

Quoted 10 lines
drivers/net/phy/ca_phy.c new file +10 -0
+static int rtl8211_internal_config(struct phy_device *phydev)
+{
+	struct phy_device phydev_init;
+
+	memcpy(&phydev_init, phydev, sizeof(struct phy_device));
+	/* should initialize 4 GPHYs at once */
+	__internal_phy_init(&phydev_init, 0);
+	printf("%s: initialize RTL8211 internal done.\n", __func__);
+	return 0;
+}

Why do we have two weak functions (which have very generic names and could get overwritten by accident) and not just inlining them to the functions?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200929/8272d949/attachment.sig>
#3 lore raw

PATCH v3 2/3 net: phy: ca_phy: Add driver for CAxxxx SoCs

Tom,
Yes the intent is to allow overwrite the functionality elsewhere. I agree that the name is too generic and should be more unique to avoid name space conflicts.

Abbie,
Please Review and update per Tom?s request.

Quoted 98 lines · Tom Rini
Quoted 13 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add phy driver support for MACs embedded inside Cortina Access SoCs

CC Joe Hershberger <[email protected]>
CC Tom Rini <[email protected]>
CC Aaron Tseng <[email protected]>

Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver

[snip]

Quoted 64 lines
drivers/net/phy/ca_phy.c new file +64 -0
+__weak void __internal_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u8 phy_addr;
+    u16     data;
+
+    /* should initialize 4 GPHYs at once */
+    for (phy_addr = 4; phy_addr > 0; phy_addr--) {
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0BC6);
+        phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x0053);
+        phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x4003);
+        phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x7e01);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A42);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A40);
+        phy_write(phydev, MDIO_DEVAD_NONE,  0, 0x1140);
+    }
+
+    /* workaround to fix GPHY fail */
+    for (phy_addr = 1; phy_addr < 5; phy_addr++) {
+        /* Clear clock fail interrupt */
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+        data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+        if (data == 0x10) {
+            phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+            data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+            printf("%s: read again.\n", __func__);
+        }
+
+        printf("%s: phy_addr=%d, read register 19, value=0x%x\n",
+               __func__, phy_addr, data);
+    }
+}
+
+__weak void __external_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u16 val;
+
+    /* Disable response PHYAD=0 function of RTL8211 series PHY */
+    /* REG31 write 0x0007, set to extension page */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0007);
+
+    /* REG30 write 0x002C, set to extension page 44 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 30, 0x002C);
+
+    /*
+     * REG27 write bit[2] = 0 disable response PHYAD = 0 function.
+     * we should read REG27 and clear bit[2], and write back
+     */
+    val = phy_read(phydev, MDIO_DEVAD_NONE, 27);
+    val &= ~(1 << 2);
+    phy_write(phydev, MDIO_DEVAD_NONE, 27, val);
+
+    /* REG31 write 0X0000, back to page0 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000);
+}
+
+static int rtl8211_external_config(struct phy_device *phydev)
+{
+    __external_phy_init(phydev, 0);
+    printf("%s: initialize RTL8211 external done.\n", __func__);
+    return 0;
+}
+

drivers/net/phy/ca_phy.c line 97

Quoted 10 lines
drivers/net/phy/ca_phy.c new file +10 -0
+static int rtl8211_internal_config(struct phy_device *phydev)
+{
+    struct phy_device phydev_init;
+
+    memcpy(&phydev_init, phydev, sizeof(struct phy_device));
+    /* should initialize 4 GPHYs at once */
+    __internal_phy_init(&phydev_init, 0);
+    printf("%s: initialize RTL8211 internal done.\n", __func__);
+    return 0;
+}

Why do we have two weak functions (which have very generic names and could get overwritten by accident) and not just inlining them to the functions?

Signature · 1 line
Tom
#4 lore raw

PATCH v3 2/3 net: phy: ca_phy: Add driver for CAxxxx SoCs

Quoted 2 lines · Alex Nemirovsky

Tom,
Yes the intent is to allow overwrite the functionality elsewhere. I agree that the name is too generic and should be more unique to avoid name space conflicts.

Any sort of board specific tweaking should be done via device tree properties, I strongly suspect.

Quoted 101 lines

Abbie,
Please Review and update per Tom?s request.

Quoted 98 lines · Tom Rini
Quoted 13 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add phy driver support for MACs embedded inside Cortina Access SoCs

CC Joe Hershberger <[email protected]>
CC Tom Rini <[email protected]>
CC Aaron Tseng <[email protected]>

Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver

[snip]

Quoted 64 lines
drivers/net/phy/ca_phy.c new file +64 -0
+__weak void __internal_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u8 phy_addr;
+    u16     data;
+
+    /* should initialize 4 GPHYs at once */
+    for (phy_addr = 4; phy_addr > 0; phy_addr--) {
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0BC6);
+        phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x0053);
+        phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x4003);
+        phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x7e01);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A42);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A40);
+        phy_write(phydev, MDIO_DEVAD_NONE,  0, 0x1140);
+    }
+
+    /* workaround to fix GPHY fail */
+    for (phy_addr = 1; phy_addr < 5; phy_addr++) {
+        /* Clear clock fail interrupt */
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+        data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+        if (data == 0x10) {
+            phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+            data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+            printf("%s: read again.\n", __func__);
+        }
+
+        printf("%s: phy_addr=%d, read register 19, value=0x%x\n",
+               __func__, phy_addr, data);
+    }
+}
+
+__weak void __external_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u16 val;
+
+    /* Disable response PHYAD=0 function of RTL8211 series PHY */
+    /* REG31 write 0x0007, set to extension page */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0007);
+
+    /* REG30 write 0x002C, set to extension page 44 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 30, 0x002C);
+
+    /*
+     * REG27 write bit[2] = 0 disable response PHYAD = 0 function.
+     * we should read REG27 and clear bit[2], and write back
+     */
+    val = phy_read(phydev, MDIO_DEVAD_NONE, 27);
+    val &= ~(1 << 2);
+    phy_write(phydev, MDIO_DEVAD_NONE, 27, val);
+
+    /* REG31 write 0X0000, back to page0 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000);
+}
+
+static int rtl8211_external_config(struct phy_device *phydev)
+{
+    __external_phy_init(phydev, 0);
+    printf("%s: initialize RTL8211 external done.\n", __func__);
+    return 0;
+}
+

drivers/net/phy/ca_phy.c line 97

Quoted 10 lines
drivers/net/phy/ca_phy.c new file +10 -0
+static int rtl8211_internal_config(struct phy_device *phydev)
+{
+    struct phy_device phydev_init;
+
+    memcpy(&phydev_init, phydev, sizeof(struct phy_device));
+    /* should initialize 4 GPHYs at once */
+    __internal_phy_init(&phydev_init, 0);
+    printf("%s: initialize RTL8211 internal done.\n", __func__);
+    return 0;
+}

Why do we have two weak functions (which have very generic names and could get overwritten by accident) and not just inlining them to the functions?

Signature · 1 line
Tom
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200929/c2af2f75/attachment.sig>
#5 lore raw

PATCH v3 2/3 net: phy: ca_phy: Add driver for CAxxxx SoCs

Tom,

Quoted 9 lines · Tom Rini
Quoted 2 lines · Alex Nemirovsky

Tom,
Yes the intent is to allow overwrite the functionality elsewhere. I agree that the name is too generic and should be more unique to avoid name space conflicts.

Any sort of board specific tweaking should be done via device tree properties, I strongly suspect.

You maybe right. That might be a design possibility. I personally don?t know enough about this to comment either way. I?ll pass this on to the team for consideration and review of the overall approach.

Quoted 105 lines
Quoted 102 lines

Abbie,
Please Review and update per Tom?s request.

Quoted 98 lines
Quoted 1 line · Tom Rini
Quoted 13 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add phy driver support for MACs embedded inside Cortina Access SoCs

CC Joe Hershberger <[email protected]>
CC Tom Rini <[email protected]>
CC Aaron Tseng <[email protected]>

Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver

[snip]

Quoted 64 lines
drivers/net/phy/ca_phy.c new file +64 -0
+__weak void __internal_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u8 phy_addr;
+    u16     data;
+
+    /* should initialize 4 GPHYs at once */
+    for (phy_addr = 4; phy_addr > 0; phy_addr--) {
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0BC6);
+        phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x0053);
+        phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x4003);
+        phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x7e01);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A42);
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A40);
+        phy_write(phydev, MDIO_DEVAD_NONE,  0, 0x1140);
+    }
+
+    /* workaround to fix GPHY fail */
+    for (phy_addr = 1; phy_addr < 5; phy_addr++) {
+        /* Clear clock fail interrupt */
+        phydev->addr = phy_addr;
+        phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+        data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+        if (data == 0x10) {
+            phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90);
+            data = phy_read(phydev, MDIO_DEVAD_NONE, 19);
+            printf("%s: read again.\n", __func__);
+        }
+
+        printf("%s: phy_addr=%d, read register 19, value=0x%x\n",
+               __func__, phy_addr, data);
+    }
+}
+
+__weak void __external_phy_init(struct phy_device *phydev, int reset_phy)
+{
+    u16 val;
+
+    /* Disable response PHYAD=0 function of RTL8211 series PHY */
+    /* REG31 write 0x0007, set to extension page */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0007);
+
+    /* REG30 write 0x002C, set to extension page 44 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 30, 0x002C);
+
+    /*
+     * REG27 write bit[2] = 0 disable response PHYAD = 0 function.
+     * we should read REG27 and clear bit[2], and write back
+     */
+    val = phy_read(phydev, MDIO_DEVAD_NONE, 27);
+    val &= ~(1 << 2);
+    phy_write(phydev, MDIO_DEVAD_NONE, 27, val);
+
+    /* REG31 write 0X0000, back to page0 */
+    phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000);
+}
+
+static int rtl8211_external_config(struct phy_device *phydev)
+{
+    __external_phy_init(phydev, 0);
+    printf("%s: initialize RTL8211 external done.\n", __func__);
+    return 0;
+}
+

drivers/net/phy/ca_phy.c line 97

Quoted 10 lines
drivers/net/phy/ca_phy.c new file +10 -0
+static int rtl8211_internal_config(struct phy_device *phydev)
+{
+    struct phy_device phydev_init;
+
+    memcpy(&phydev_init, phydev, sizeof(struct phy_device));
+    /* should initialize 4 GPHYs at once */
+    __internal_phy_init(&phydev_init, 0);
+    printf("%s: initialize RTL8211 internal done.\n", __func__);
+    return 0;
+}

Why do we have two weak functions (which have very generic names and could get overwritten by accident) and not just inlining them to the functions?

Signature · 1 line
Tom
Signature · 1 line
Tom
#6 lore raw

PATCH v3 3/3 board: presidio-asic: Add CAxxxx Ethernet support

In reply to Alex Nemirovsky

Add CAxxxx Ethernet support for the Cortina Access Presidio Engineering Board

---

(no changes since v2)

Changes in v2:
- only support DM_ETH network models by removing
code for legacy mode support

 arch/arm/dts/ca-presidio-engboard.dts        |  6 ++++++
 board/cortina/presidio-asic/presidio.c       | 31 ++++++++++++++++++++++++++++
 configs/cortina_presidio-asic-emmc_defconfig |  4 +++-
 include/configs/presidio_asic.h              | 15 +++++++++++++-
 4 files changed, 54 insertions(+), 2 deletions(-)
arch/arm/dts/ca-presidio-engboard.dts +6 -0
index eef433e..d45b28b 100644
@@ -95,4 +95,10 @@
 		};
 
 	};
+	eth: ethnet at 0xf4300000 {
+		compatible = "eth_cortina";
+		reg = <0x0 0xf4320000 0x34>,
+		      <0x0 0xf43290d8 0x04>,
+		      <0x0 0xf4304000 0x04>;
+	};
 };
board/cortina/presidio-asic/presidio.c +31 -0
index 3c132f1..74e0ba6 100644
@@ -134,3 +134,34 @@ int last_stage_init(void)
 	return 0;
 }
 #endif
+
+enum ca_port_t {
+	NI_PORT_0 = 0,
+	NI_PORT_1,
+	NI_PORT_2,
+	NI_PORT_3,
+	NI_PORT_4,
+	NI_PORT_5,
+	NI_PORT_MAX,
+};
+
+struct port_map_s {
+	int active_port;
+	int phy_addr;
+};
+
+/* port0: phy address 1 - GMAC0: port 0
+ * port1: phy address 2 - GMAC1: port 1
+ * port2: phy address 3 - GMAC2: port 2
+ * port3: phy address 4 - GMAC3: port 3
+ * port4: phy address 5 - RGMII: port 4
+ */
+struct port_map_s port_map[NI_PORT_MAX] = {
+	{NI_PORT_0, 1},
+	{NI_PORT_1, 2},
+	{NI_PORT_2, 3},
+	{NI_PORT_3, 4},
+	{NI_PORT_4, 5}
+};
+
+int active_port = NI_PORT_3;  /* Physical port 3 */
configs/cortina_presidio-asic-emmc_defconfig +3 -1
index faffdd4..eec9584 100644
@@ -22,7 +22,6 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_OF_CONTROL=y
 CONFIG_OF_LIVE=y
-# CONFIG_NET is not set
 CONFIG_DM=y
 CONFIG_CORTINA_GPIO=y
 CONFIG_DM_I2C=y
@@ -30,6 +29,9 @@ CONFIG_SYS_I2C_CA=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_DW_CORTINA=y
+CONFIG_PHYLIB=y
+CONFIG_DM_ETH=y
+CONFIG_CORTINA_NI_ENET=y
 CONFIG_DM_SERIAL=y
 CONFIG_CORTINA_UART=y
 CONFIG_WDT=y
include/configs/presidio_asic.h +14 -1
index 34235b5..c2082b4 100644
@@ -2,7 +2,7 @@
 /*
  * Copyright (C) 2020 Cortina Access Inc.
  *
- * Configuration for Cortina-Access Presidio board.
+ * Configuration for Cortina-Access Presidio board
  */
 
 #ifndef __PRESIDIO_ASIC_H
@@ -63,6 +63,19 @@
 					sizeof(CONFIG_SYS_PROMPT) + 16)
 #define CONFIG_SYS_BARGSIZE		CONFIG_SYS_CBSIZE
 
+#define KSEG1_ATU_XLAT(x) (x)
+
+/* HW REG ADDR */
+#define NI_READ_POLL_COUNT                      1000
+#define CA_NI_MDIO_REG_BASE                     0xF4338
+#define NI_HV_GLB_MAC_ADDR_CFG0_OFFSET          0x010
+#define NI_HV_GLB_MAC_ADDR_CFG1_OFFSET          0x014
+#define NI_HV_PT_BASE                           0x400
+#define NI_HV_XRAM_BASE                         0x820
+#define GLOBAL_BLOCK_RESET_OFFSET               0x04
+#define GLOBAL_GLOBAL_CONFIG_OFFSET             0x20
+#define GLOBAL_IO_DRIVE_CONTROL_OFFSET          0x4c
+
 /* max command args */
 #define CONFIG_SYS_MAXARGS		64
 #define CONFIG_EXTRA_ENV_SETTINGS	"silent=y\0"
Signature · 1 line
2.7.4
#7 lore raw

PATCH v3 1/3 net: cortina_ni: Add eth support for Cortina Access CAxxxx SoCs

In reply to Alex Nemirovsky
Quoted 5 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add Cortina Access Ethernet device driver for CAxxxx SoCs. This driver supports both legacy and DM_ETH network models.

Quoted 7 lines
CC Joe Hershberger <[email protected]>
CC Abbie Chang <[email protected]>
CC Tom Rini <[email protected]>

[snip]

Again, please give the whole driver a read and compare it with other network drivers that've been most recently added. I question things like:

Quoted 7 lines
drivers/net/cortina_ni.c new file +7 -0
+static u32 *rdwrptr_adv_one(u32 *x, unsigned long base, unsigned long max)
+{
+	if (x + 1 >= (u32 *)max)
+		return (u32 *)base;
+	else
+		return (x + 1);
+}

[snip]

Quoted 4 lines
drivers/net/cortina_ni.c new file +4 -0
+static u32 REG_TO_U32(void *reg)
+{
+	return *(u32 *)reg;
+}

[snip]

Quoted 5 lines
drivers/net/cortina_ni.c new file +5 -0
+int ca_miiphy_read(const char *devname,
+		   unsigned char addr,
+		   unsigned char reg,
+		   unsigned short *value)
+{

drivers/net/cortina_ni.c line 232

Quoted 10 lines
drivers/net/cortina_ni.c new file +10 -0
+	return ca_mdio_read(addr, reg, value);
+}
+
+int ca_miiphy_write(const char *devname,
+		    unsigned char addr,
+		    unsigned char reg,
+		    unsigned short value)
+{
+	return ca_mdio_write(addr, reg, value);
+}

And lots of other simple looking wrappers.

[snip]

drivers/net/cortina_ni.c line 257

Quoted 9 lines
drivers/net/cortina_ni.c new file +9 -0
+static void ca_ni_setup_mac_addr(void)
+{
+	unsigned char mac[6];
+
+	struct NI_HV_GLB_MAC_ADDR_CFG0_t	mac_addr_cfg0;
+	struct NI_HV_GLB_MAC_ADDR_CFG1_t	mac_addr_cfg1;
+	struct NI_HV_PT_PORT_STATIC_CFG_t	port_static_cfg;
+	struct NI_HV_XRAM_CPUXRAM_CFG_t		cpuxram_cfg;
+	struct cortina_ni_priv *priv = dev_get_priv(curr_dev);

While checkpatch didn't complain, can you please fix the driver to use consistent spacing?

I feel like I asked before about Linux upstreaming of these drivers and the answer was that it was planned for later, is that right?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200929/46927711/attachment.sig>
#8 lore raw

PATCH v3 1/3 net: cortina_ni: Add eth support for Cortina Access CAxxxx SoCs

Abbie,

Please have a look at Tom?s feedback to address his concerns.

Quoted 53 lines · Tom Rini
Quoted 5 lines · Alex Nemirovsky

From: Abbie Chang <[email protected]>

Add Cortina Access Ethernet device driver for CAxxxx SoCs. This driver supports both legacy and DM_ETH network models.

Quoted 7 lines
CC Joe Hershberger <[email protected]>
CC Abbie Chang <[email protected]>
CC Tom Rini <[email protected]>

[snip]

Again, please give the whole driver a read and compare it with other network drivers that've been most recently added. I question things like:

Quoted 7 lines
drivers/net/cortina_ni.c new file +7 -0
+static u32 *rdwrptr_adv_one(u32 *x, unsigned long base, unsigned long max)
+{
+    if (x + 1 >= (u32 *)max)
+        return (u32 *)base;
+    else
+        return (x + 1);
+}

[snip]

Quoted 4 lines
drivers/net/cortina_ni.c new file +4 -0
+static u32 REG_TO_U32(void *reg)
+{
+    return *(u32 *)reg;
+}

[snip]

Quoted 5 lines
drivers/net/cortina_ni.c new file +5 -0
+int ca_miiphy_read(const char *devname,
+           unsigned char addr,
+           unsigned char reg,
+           unsigned short *value)
+{

drivers/net/cortina_ni.c line 232

Quoted 10 lines
drivers/net/cortina_ni.c new file +10 -0
+    return ca_mdio_read(addr, reg, value);
+}
+
+int ca_miiphy_write(const char *devname,
+            unsigned char addr,
+            unsigned char reg,
+            unsigned short value)
+{
+    return ca_mdio_write(addr, reg, value);
+}

And lots of other simple looking wrappers.

[snip]

Quoted 12 lines

drivers/net/cortina_ni.c line 257

Quoted 9 lines
drivers/net/cortina_ni.c new file +9 -0
+static void ca_ni_setup_mac_addr(void)
+{
+    unsigned char mac[6];
+
+    struct NI_HV_GLB_MAC_ADDR_CFG0_t    mac_addr_cfg0;
+    struct NI_HV_GLB_MAC_ADDR_CFG1_t    mac_addr_cfg1;
+    struct NI_HV_PT_PORT_STATIC_CFG_t    port_static_cfg;
+    struct NI_HV_XRAM_CPUXRAM_CFG_t        cpuxram_cfg;
+    struct cortina_ni_priv *priv = dev_get_priv(curr_dev);

While checkpatch didn't complain, can you please fix the driver to use consistent spacing?

Abbie,
Please look at the spacing.

Quoted 3 lines

I feel like I asked before about Linux upstreaming of these drivers and the answer was that it was planned for later, is that right?

IIRC you asked for the Linux drivers and I responded that there are no Linux drivers upstream and that management has not asked for them to be upstreamed.

Thanks for your patience on this one. I know we have been successful with most of the other code that has been submitted upstream. This one seems to be a challenge. Could you give us your honest constructive criticism on this code and I will be happy to pass it up to management for consideration.

Thanks Tom.

Quoted 3 lines
Signature · 2 lines
-- 
Tom
#9 lore raw

PATCH v3 1/3 net: cortina_ni: Add eth support for Cortina Access CAxxxx SoCs

Moved my comment from prior response so that it?s more likely to be seen:

Thanks for your patience on this one. I know we have been successful with most of the other code that has been submitted upstream. This one seems to be a challenge. Could you give us your honest constructive criticism on this code and I will be happy to pass it up to management for consideration.

Thanks Tom.

Quoted 86 lines · Alex Nemirovsky

?Abbie,

Please have a look at Tom?s feedback to address his concerns.

Quoted 53 lines
Quoted 9 lines · Tom Rini

?On Wed, Sep 23, 2020 at 05:59:12PM -0700, Alex Nemirovsky wrote:

From: Abbie Chang <[email protected]>

Add Cortina Access Ethernet device driver for CAxxxx SoCs. This driver supports both legacy and DM_ETH network models.

Quoted 7 lines
CC Joe Hershberger <[email protected]>
CC Abbie Chang <[email protected]>
CC Tom Rini <[email protected]>

[snip]

Again, please give the whole driver a read and compare it with other network drivers that've been most recently added. I question things like:

Quoted 7 lines
drivers/net/cortina_ni.c new file +7 -0
+static u32 *rdwrptr_adv_one(u32 *x, unsigned long base, unsigned long max)
+{
+    if (x + 1 >= (u32 *)max)
+        return (u32 *)base;
+    else
+        return (x + 1);
+}

[snip]

Quoted 4 lines
drivers/net/cortina_ni.c new file +4 -0
+static u32 REG_TO_U32(void *reg)
+{
+    return *(u32 *)reg;
+}

[snip]

Quoted 5 lines
drivers/net/cortina_ni.c new file +5 -0
+int ca_miiphy_read(const char *devname,
+           unsigned char addr,
+           unsigned char reg,
+           unsigned short *value)
+{

drivers/net/cortina_ni.c line 232

Quoted 10 lines
drivers/net/cortina_ni.c new file +10 -0
+    return ca_mdio_read(addr, reg, value);
+}
+
+int ca_miiphy_write(const char *devname,
+            unsigned char addr,
+            unsigned char reg,
+            unsigned short value)
+{
+    return ca_mdio_write(addr, reg, value);
+}

And lots of other simple looking wrappers.

[snip]

Quoted 12 lines

drivers/net/cortina_ni.c line 257

Quoted 9 lines
drivers/net/cortina_ni.c new file +9 -0
+static void ca_ni_setup_mac_addr(void)
+{
+    unsigned char mac[6];
+
+    struct NI_HV_GLB_MAC_ADDR_CFG0_t    mac_addr_cfg0;
+    struct NI_HV_GLB_MAC_ADDR_CFG1_t    mac_addr_cfg1;
+    struct NI_HV_PT_PORT_STATIC_CFG_t    port_static_cfg;
+    struct NI_HV_XRAM_CPUXRAM_CFG_t        cpuxram_cfg;
+    struct cortina_ni_priv *priv = dev_get_priv(curr_dev);

While checkpatch didn't complain, can you please fix the driver to use consistent spacing?

Abbie,
Please look at the spacing.

Quoted 3 lines

I feel like I asked before about Linux upstreaming of these drivers and the answer was that it was planned for later, is that right?

IIRC you asked for the Linux drivers and I responded that there are no Linux drivers upstream and that management has not asked for them to be upstreamed.

Thanks for your patience on this one. I know we have been successful with most of the other code that has been submitted upstream. This one seems to be a challenge. Could you give us your honest constructive criticism on this code and I will be happy to pass it up to management for consideration.

Thanks Tom.

Quoted 3 lines
Signature · 2 lines
-- 
Tom