Skip to contentSkip to conversation

Add Realtek automotive PCIe driver

PATCH Superseded Justin Lai 3 participants 9 messages Aug 22, 2023 – Aug 23, 2023

Subsystems (3)

v6 of 30 Superseded Latest is v30 →

lore
Share & tools
lore

Justin Lai

author maintainer
#0 lore raw

v6 cover Add Realtek automotive PCIe driver

This series includes adding realtek automotive ethernet driver and adding rtase ethernet driver entry in MAINTAINERS file.

This ethernet device driver for the PCIe interface
of Realtek Automotive Ethernet Switch,
applicable to RTL9054, RTL9068, RTL9072, RTL9075, RTL9068, RTL9071.

v5 -> v6:
- Some old macro definitions have been removed
and replaced with the lastest usage.
- Replace s32 with int to ensure consistency.
- Clearly point out the objects of the service
and remove unnecessary struct.

Justin Lai (2):
net/ethernet/realtek: Add Realtek automotive PCIe driver code
MAINTAINERS: Add the rtase ethernet driver entry

 MAINTAINERS                                   |    7 +
 drivers/net/ethernet/realtek/Kconfig          |   17 +
 drivers/net/ethernet/realtek/Makefile         |    1 +
 drivers/net/ethernet/realtek/rtase/Makefile   |   10 +
 drivers/net/ethernet/realtek/rtase/rtase.h    |  372 +++
 .../net/ethernet/realtek/rtase/rtase_main.c   | 2432 +++++++++++++++++
 6 files changed, 2839 insertions(+)
 create mode 100644 drivers/net/ethernet/realtek/rtase/Makefile
 create mode 100644 drivers/net/ethernet/realtek/rtase/rtase.h
 create mode 100644 drivers/net/ethernet/realtek/rtase/rtase_main.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v6 1/2 net/ethernet/realtek: Add Realtek automotive PCIe driver code

This patch is to add the ethernet device driver
for the PCIe interface of Realtek Automotive Ethernet Switch, applicable to RTL9054, RTL9068, RTL9072, RTL9075, RTL9068, RTL9071.

Below is a simplified block diagram of the chip and its relevant interfaces.

*************************
* *
* CPU network device *
* ____________ *
* | | *
* | PCIE Host | *
*************************
||
PCIE
||
****************************************

  *          | PCIE Endpoint |           *
  *          |---------------|           *
  *              | GMAC |                *
  *              |------|  Realtek       *
  *                 ||   RTL90xx Series  *
  *                 ||                   *
  *    _____________||______________     *
  *   |            |MAC|            |    *
  *   |            |---|            |    *
  *   |                             |    *
  *   |     Ethernet Switch Core    |    *
  *   |                             |    *
  *   |  -----             -----    |    *
  *   |  |MAC| ............|MAC|    |    *
  *   |__|___|_____________|___|____|    *
  *      |PHY| ............|PHY|         *
  *      -----             -----         *

*********||****************||***********

The block of the Realtek RTL90xx series is our entire chip architecture, the GMAC is connected to the switch core,and there is no PHY in between. In addition, this driver is mainly used to control GMAC,
but does not control the switch core, so it is not the same as DSA.

---
 drivers/net/ethernet/realtek/Kconfig          |   17 +
 drivers/net/ethernet/realtek/Makefile         |    1 +
 drivers/net/ethernet/realtek/rtase/Makefile   |   10 +
 drivers/net/ethernet/realtek/rtase/rtase.h    |  372 +++
 .../net/ethernet/realtek/rtase/rtase_main.c   | 2432 +++++++++++++++++
 5 files changed, 2832 insertions(+)
 create mode 100644 drivers/net/ethernet/realtek/rtase/Makefile
 create mode 100644 drivers/net/ethernet/realtek/rtase/rtase.h
 create mode 100644 drivers/net/ethernet/realtek/rtase/rtase_main.c
drivers/net/ethernet/realtek/Kconfig +17 -0
index 93d9df55b361..0250d1c3874b 100644
@@ -113,4 +113,21 @@ config R8169
 	  To compile this driver as a module, choose M here: the module
 	  will be called r8169.  This is recommended.
 
+config RTASE
+	tristate "Realtek Automotive Switch 9054/9068/9072/9075/9068/9071 PCIe Interface support"
+	depends on PCI
+	select CRC32
+	help
+	  Say Y here if you have a Realtek Ethernet adapter belonging to
+	  the following families:
+	  RTL9054 5GBit Ethernet
+	  RTL9068 5GBit Ethernet
+	  RTL9072 5GBit Ethernet
+	  RTL9075 5GBit Ethernet
+	  RTL9068 5GBit Ethernet
+	  RTL9071 5GBit Ethernet
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called rtase.  This is recommended.
+
 endif # NET_VENDOR_REALTEK
drivers/net/ethernet/realtek/Makefile +1 -0
index 2e1d78b106b0..0c1c16f63e9a 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_8139TOO) += 8139too.o
 obj-$(CONFIG_ATP) += atp.o
 r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o
 obj-$(CONFIG_R8169) += r8169.o
+obj-$(CONFIG_RTASE) += rtase/
drivers/net/ethernet/realtek/rtase/Makefile new file +10 -0
new file mode 100644
index 000000000000..5205bd330041
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
+
+#
+# Makefile for the Realtek PCIe driver
+#
+
+obj-$(CONFIG_RTASE) += rtase.o
+
+rtase-objs := rtase_main.o
drivers/net/ethernet/realtek/rtase/rtase.h new file +372 -0

372 lines not on this page · raw message

drivers/net/ethernet/realtek/rtase/rtase_main.c new file +2432 -0

2,432 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

Quoted 3 lines · On Tue, 22 Aug 2023 11:18:04 +0800 Justin Lai wrote:
 drivers/net/ethernet/realtek/rtase/rtase.h    |  372 +++
 .../net/ethernet/realtek/rtase/rtase_main.c   | 2432 +++++++++++++++++
 5 files changed, 2832 insertions(+)

Please split this into multiple patches, I already asked you to do so.

Individual ethtool ops and vlan support should be separate patches, perhaps you can separate other features out, too.

author maintainer
#3 lore raw

RE: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

Quoted 10 lines · On Tue, 22 Aug 2023 11:18:04 +0800 Justin Lai wrote:
Quoted 3 lines
 drivers/net/ethernet/realtek/rtase/rtase.h    |  372 +++
 .../net/ethernet/realtek/rtase/rtase_main.c   | 2432 +++++++++++++++++
 5 files changed, 2832 insertions(+)

Please split this into multiple patches, I already asked you to do so.

Individual ethtool ops and vlan support should be separate patches, perhaps you can separate other features out, too.

Thanks for your review, I will make this change in the next version.

#4 lore raw

Re: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

In reply to Justin Lai
Quoted 6 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +6 -0
+static int rtase_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
+{
+	const struct rtase_private *tp = netdev_priv(dev);
+	u16 value = RTL_R16(tp, CPLUS_CMD);
+
+	value &= ~(FORCE_TXFLOW_EN | FORCE_RXFLOW_EN);

drivers/net/ethernet/realtek/rtase/rtase_main.c line 579

Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10 -0
+
+	if (pause->tx_pause)
+		value |= FORCE_TXFLOW_EN;
+
+	if (pause->rx_pause)
+		value |= FORCE_RXFLOW_EN;
+
+	RTL_W16(tp, CPLUS_CMD, value);
+	return 0;
+}

I'm pretty sure i said if pause->autoneg is true, you should return -EOPNOTUSPP.

Andrew

author maintainer
#5 lore raw

RE: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

Quoted 20 lines
Quoted 6 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +6 -0
+static int rtase_set_pauseparam(struct net_device *dev, struct
+ethtool_pauseparam *pause) {
+     const struct rtase_private *tp = netdev_priv(dev);
+     u16 value = RTL_R16(tp, CPLUS_CMD);
+
+     value &= ~(FORCE_TXFLOW_EN | FORCE_RXFLOW_EN);

drivers/net/ethernet/realtek/rtase/rtase_main.c line 579

Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10 -0
+
+     if (pause->tx_pause)
+             value |= FORCE_TXFLOW_EN;
+
+     if (pause->rx_pause)
+             value |= FORCE_RXFLOW_EN;
+
+     RTL_W16(tp, CPLUS_CMD, value);
+     return 0;
+}

I'm pretty sure i said if pause->autoneg is true, you should return -EOPNOTUSPP.

Quoted 1 line

Andrew

Sorry this part has not been changed, I will modify this part in the next version.

#6 lore raw

Re: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

In reply to Justin Lai

drivers/net/ethernet/realtek/rtase/rtase_main.c line 350

Quoted 12 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +12 -0
+	do {
+		status = RTL_R32(tp, ivec->isr_addr);
+
+		handled = 1;
+		RTL_W32(tp, ivec->imr_addr, 0x0);
+		RTL_W32(tp, ivec->isr_addr, (status & ~FOVW));
+
+		if ((status & ivec->imr)) {
+			if (likely(napi_schedule_prep(&ivec->napi)))
+				__napi_schedule(&ivec->napi);
+		}
+	} while (false);

Remember i said that if you do something which no other network driver does, it is probably wrong. How many drivers have a do {} while (false); loop?

Please spend a few days just reading other drivers, and compare your code with those drivers. Try to find all the things your driver does which no other driver has. That code is probably wrong and you should fix it.

Andrew

author maintainer
#7 lore raw

RE: [PATCH net-next v6 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code

Quoted 17 lines

drivers/net/ethernet/realtek/rtase/rtase_main.c line 350

Quoted 13 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +12 -0
+     do {
+             status = RTL_R32(tp, ivec->isr_addr);
+
+             handled = 1;
+             RTL_W32(tp, ivec->imr_addr, 0x0);
+             RTL_W32(tp, ivec->isr_addr, (status & ~FOVW));
+
+             if ((status & ivec->imr)) {
+                     if (likely(napi_schedule_prep(&ivec->napi)))
+                             __napi_schedule(&ivec->napi);
+             }
+     } while (false);

Remember i said that if you do something which no other network driver does, it is probably wrong. How many drivers have a do {} while (false); loop?

Quoted 6 lines

Please spend a few days just reading other drivers, and compare your code with those drivers. Try to find all the things your driver does which no other driver has. That code is probably wrong and you should fix it.

Andrew

Thank you for your suggestions, I will read other drivers and modify some problems of this driver.

author maintainer
#8 lore raw

PATCH v6 2/2 MAINTAINERS: Add the rtase ethernet driver entry

In reply to Justin Lai

Add myself and Larry Chiu as the maintainer for the rtase ethernet driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 53b7ca804465..239aae94dc0f 100644
@@ -18476,6 +18476,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/tty/rpmsg_tty.c
 
+RTASE ETHERNET DRIVER
+M:	Justin Lai <[email protected]>
+M:	Larry Chiu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/realtek/rtase/
+
 RTL2830 MEDIA DRIVER
 M:	Antti Palosaari <[email protected]>
 L:	[email protected]
Signature · 1 line
2.34.1