Add Realtek automotive PCIe driver
Subsystems (3)
Justin Lai
maintainerv3 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.
v2 -> v3:
- Remove SR-IOV function - We will add the SR-IOV function together when uploading the vf driver in the future.
- Remove other unnecessary code and macro.
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 | 403 +++ .../net/ethernet/realtek/rtase/rtase_main.c | 2696 +++++++++++++++++ 6 files changed, 3134 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
Justin Lai
maintainerPATCH v3 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| * * ----- ----- *
*********||****************||***********
This driver is mainly used to control GMAC, but does not control the switch core, so it is not the same as DSA. In addition, the GMAC is not directly connected to the PHY, but directly connected to the mac of the switch core, so there is no need for PHY handing.
--- 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 | 403 +++ .../net/ethernet/realtek/rtase/rtase_main.c | 2696 +++++++++++++++++ 5 files changed, 3127 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
@@ -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
@@ -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
@@ -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 +403 -0
403 lines not on this page · raw message
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +2696 -0
2,562 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.
Re: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 33 lines · Justin Lai
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| * * ----- ----- *
Quoted 4 lines
*********||****************||***********
This driver is mainly used to control GMAC, but does not control the switch core, so it is not the same as DSA. In addition, the GMAC is not directly connected to the PHY, but directly connected to the mac of the switch core, so there is no need for PHY handing.
So this describes your board? Is the MAC and the swtich two separate chips? Is it however possible to connect the GMAC to a PHY? Could some OEM purchase the chipset and build a board with a PHY? We write MAC drivers around what the MAC can do, not what one specific board allows.
What MAC drivers do to support being connected to a switch like this is use a fixed-link PHY, via phylink. This gives a virtual PHY, which supports one speed. The MAC driver then just uses the phylink API as normal.
On your board, how is the switch controlled? Is there an MDIO bus as part of the MAC? If so, you should add an MDIO bus master driver.
Quoted 4 lines
+/******************************************************************************
+ * This product is covered by one or more of the following patents:
+ * US6,570,884, US6,115,776, and US6,327,625.
+ ******************************************************************************/
How many other drivers mentions patents? I'm not a lawyer, but doesn't the GPL say something about this?
drivers/net/ethernet/realtek/rtase/rtase.h line 58
Quoted 2 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +2
-0+/* 0x05F3 = 1522bye + 1 */ +#define RX_BUF_SIZE 0x05F3u
Why not just use:
#define RX_BUF_SIZE 1522 + 1
You don't need the comment then. Better still if you can express this in terms of ETH_FRAME_LEN, ETH_FCS_LEN etc.
drivers/net/ethernet/realtek/rtase/rtase.h line 63
Quoted 4 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +4
-0+/* write/read MMIO register */ +#define RTL_W8 (reg, val8) writeb((val8), ioaddr + (reg)) +#define RTL_W16 (reg, val16) writew((val16), ioaddr + (reg)) +#define RTL_W32 (reg, val32) writel((val32), ioaddr + (reg))
macros should only access what is passed to them. ioaddr is not passed...
Using small functions would be better, you can then do type checking, ensure that val8 is a u8, val16 is a u16 etc.
drivers/net/ethernet/realtek/rtase/rtase.h line 70
Quoted 3 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +3
-0+/*****************************************************************************/ +#define RTL_NETIF_RX_SCHEDULE_PREP (dev, napi) napi_schedule_prep(napi) +#define __RTL_NETIF_RX_SCHEDULE (dev, napi) __napi_schedule(napi)
No wrappers. Also, it seems odd you are using a __foo function. Anything with a __ prefix is mean to be hidden.
Quoted 33 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +33
-0+#include <linux/module.h> +#include <linux/version.h> +#include <linux/cdev.h> +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/delay.h> +#include <linux/if_vlan.h> +#include <linux/crc32.h> +#include <linux/interrupt.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <linux/tcp.h> +#include <linux/init.h> +#include <linux/rtnetlink.h> +#include <linux/prefetch.h> +#include <linux/dma-mapping.h> +#include <linux/moduleparam.h> +#include <linux/mdio.h> +#include <net/ip6_checksum.h> +#include <net/pkt_cls.h> +#include <linux/io.h> +#include <asm/irq.h> + +#include "rtase.h" + +/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). +* The RTL chips use a 64 element hash table based on the Ethernet CRC. +*/ +#define _R (NAME ,MAC ,JUM_FRAME_SZ ) \ + { \ + .name = NAME, .mcfg = MAC, .jumbo_frame_sz = JUM_FRAME_SZ \
drivers/net/ethernet/realtek/rtase/rtase_main.c line 86
Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10
-0+ } + +static const struct { +const char *name; +u8 mcfg; +u16 jumbo_frame_sz; +} rtl_chip_info[] = {_R ("RTL9072" ,CFG_METHOD_1 ,JUMBO_FRAME_9K ), + +_R ("Unknown" ,CFG_METHOD_DEFAULT ,JUMBO_FRAME_1K )}; +#undef _R
The R macro just seems like obfuscation.
Quoted 13 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +13
-0+/****************************************************************************** +* Module Parameters +******************************************************************************/ +static unsigned int txq_ctrl =1 ; +static unsigned int func_txq_num =1 ; +static unsigned int func_rxq_num =1 ; +static unsigned int interrupt_num =1 ; +static int rx_copybreak; + +module_param (txq_ctrl, uint,0 ); +MODULE_PARM_DESC (txq_ctrl,"The maximum number of TX queues for PF." ); + +module_param (func_txq_num, uint,0 );
drivers/net/ethernet/realtek/rtase/rtase_main.c line 123
Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10
-0+MODULE_PARM_DESC (func_txq_num,"TX queue number for this function." ); + +module_param (func_rxq_num, uint,0 ); +MODULE_PARM_DESC (func_rxq_num,"RX queue number for this function." ); + +module_param (interrupt_num, uint,0 ); +MODULE_PARM_DESC (interrupt_num,"Interrupt Vector number for this function." ); + +module_param (rx_copybreak, int,0 ); +MODULE_PARM_DESC (rx_copybreak,"Copy breakpoint for copy-only-tiny-frames" );
No module parameters. Please delete them.
Quoted 20 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +20
-0+static int rtase_open (struct net_device *dev); +static netdev_tx_t rtase_start_xmit (struct sk_buff *skb,struct net_device *dev); +static void rtase_set_rx_mode (struct net_device *dev); +static int rtase_set_mac_address (struct net_device *dev,void *p); +static int rtase_change_mtu (struct net_device *dev,int new_mtu); +static void rtase_tx_timeout (struct net_device *dev,unsigned int txqueue); +static void rtase_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats); +static int rtase_vlan_rx_add_vid (struct net_device *dev,__be16 protocol,u16 vid); +static int rtase_vlan_rx_kill_vid (struct net_device *dev,__be16 protocol,u16 vid); +static int rtase_setup_tc (struct net_device *dev,enum tc_setup_type type,void *type_data); + +static irqreturn_t rtase_interrupt (int irq,void *dev_instance); +static irqreturn_t rtase_q_interrupt (int irq,void *dev_instance); +static void rtase_hw_config (struct net_device *dev); +static int rtase_close (struct net_device *dev); +static void rtase_down (struct net_device *dev); +static s32 rtase_init_ring (const struct net_device *dev); +static void rtase_init_netdev_ops (struct net_device *dev); +static void rtase_rar_set (const struct rtase_private *tp,const uint8_t *addr); +static void rtase_desc_addr_fill (const struct rtase_private *tp);
drivers/net/ethernet/realtek/rtase/rtase_main.c line 157
Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10
-0+static void rtase_tx_desc_init (struct rtase_private *tp,u16 idx); +static void rtase_rx_desc_init (struct rtase_private *tp,u16 idx); +static void rtase_set_mar (const struct rtase_private *tp); +static s32 tx_handler (struct rtase_ring *ring,s32 budget); +static s32 rx_handler (struct rtase_ring *ring,s32 budget); +static int rtase_poll (struct napi_struct *napi,int budget); +static void rtase_sw_reset (struct net_device *dev); +static void rtase_hw_start (const struct net_device *dev); +static void rtase_dump_tally_counter (const struct rtase_private *tp,dma_addr_t paddr); +static void mac_ocp_write (const struct rtase_private *tp,u16 reg_addr,u16 value);
Remove all these put the code in the right order so that they are not needed. The only time you need forward definitions is for recursion.
Andrew
---
pw-bot: cr
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 47 lines · Justin Lai
Quoted 2 lines
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.
Quoted 31 lines
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| * * ----- ----- *Quoted 2 lines
*********||****************||***********
This driver is mainly used to control GMAC, but does not control the switchcore, so it is not the same as DSA.
Quoted 2 lines
In addition, the GMAC is not directly connected to the PHY, but directly connected to the mac of the switch core, so there is no need for PHY
handing.
So this describes your board? Is the MAC and the swtich two separate chips? Is it however possible to connect the GMAC to a PHY? Could some OEM purchase the chipset and build a board with a PHY? We write MAC drivers around what the MAC can do, not what one specific board allows.
Quoted 6 lines
What MAC drivers do to support being connected to a switch like this is use a fixed-link PHY, via phylink. This gives a virtual PHY, which supports one speed. The MAC driver then just uses the phylink API as normal.
On your board, how is the switch controlled? Is there an MDIO bus as part of the MAC? If so, you should add an MDIO bus master driver.
Hi, Andrew
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. So customers don't need to consider that.
We have some externally controlled interfaces to control switch core, such as I2C, MDIO, SPI, etc., but these are not controlled by GMAC .
Quoted 170 lines
Quoted 1 line
+/**************************************************************
******drivers/net/ethernet/realtek/rtase/rtase.h line 18
Quoted 5 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +4
-0+********** + * This product is covered by one or more of the following patents: + * US6,570,884, US6,115,776, and US6,327,625. ++***************************************************************
******Quoted 1 line
+*********/
How many other drivers mentions patents? I'm not a lawyer, but doesn't the GPL say something about this?
drivers/net/ethernet/realtek/rtase/rtase.h line 58
Quoted 2 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +2
-0+/* 0x05F3 = 1522bye + 1 */ +#define RX_BUF_SIZE 0x05F3uWhy not just use:
#define
RX_BUF_SIZE1522 + 1You don't need the comment then. Better still if you can express this in terms of
ETH_FRAME_LEN,ETH_FCS_LENetc.drivers/net/ethernet/realtek/rtase/rtase.h
Quoted 4 lines
drivers/net/ethernet/realtek/rtase/rtase.h new file +4
-0+/* write/read MMIO register */ +#define RTL_W8 (reg, val8) writeb((val8), ioaddr + (reg)) +#define RTL_W16 (reg, val16) writew((val16), ioaddr + (reg)) #define +RTL_W32(reg, val32) writel((val32), ioaddr + (reg))macros should only access what is passed to them. ioaddr is not passed...
Using small functions would be better, you can then do type checking, ensure that val8 is a u8, val16 is a u16 etc.
Quoted 1 line
+/**************************************************************
******Review
Quoted 3 lines
(quoted diff) +3
-0+*********/ #define RTL_NETIF_RX_SCHEDULE_PREP(dev, napi) +napi_schedule_prep(napi) +#define __RTL_NETIF_RX_SCHEDULE(dev, napi) __napi_schedule(napi)No wrappers. Also, it seems odd you are using a
__foofunction. Anything with a __ prefix is mean to be hidden.Quoted 21 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +21
-0+#include <linux/module.h> +#include <linux/version.h> +#include <linux/cdev.h> +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/delay.h> +#include <linux/if_vlan.h> +#include <linux/crc32.h> +#include <linux/interrupt.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <linux/tcp.h> +#include <linux/init.h> +#include <linux/rtnetlink.h> +#include <linux/prefetch.h> +#include <linux/dma-mapping.h> +#include <linux/moduleparam.h> +#include <linux/mdio.h> +#include <net/ip6_checksum.h> drivers/net/ethernet/realtek/rtase/rtase_main.c
Quoted 10 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +10
-0+#include <net/pkt_cls.h> +#include <linux/io.h> +#include <asm/irq.h> + +#include "rtase.h" + +/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). +* The RTL chips use a 64 element hash table based on the Ethernet CRC. +*/ +#define _R (NAME ,MAC ,JUM_FRAME_SZ )\
Quoted 1 line
+
{
\Quoted 1 line
+ .name = NAME, .mcfg = MAC, .jumbo_frame_sz =
JUM_FRAME_SZ\drivers/net/ethernet/realtek/rtase/rtase_main.c
Quoted 9 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +9
-0+ } + +static const struct { +const char *name; +u8 mcfg; +u16 jumbo_frame_sz; +} rtl_chip_info[] = {_R ("RTL9072" ,CFG_METHOD_1 ,JUMBO_FRAME_9K ), + + _R("Unknown", CFG_METHOD_DEFAULT,
JUMBO_FRAME_1K)};Quoted 1 line
+#undef _R
The R macro just seems like obfuscation.
Quoted 1 line
+/**************************************************************
******drivers/net/ethernet/realtek/rtase/rtase_main.c line 109
Quoted 4 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +3
-0+********** + * Module Parameters ++***************************************************************
******Review
Quoted 12 lines
(quoted diff) +12
-0+*********/ +static unsigned int txq_ctrl = 1; +static unsigned int func_txq_num = 1; static unsigned int +func_rxq_num = 1; static unsigned int interrupt_num = 1; static int +rx_copybreak; + +module_param(txq_ctrl, uint, 0); +MODULE_PARM_DESC(txq_ctrl, "The maximum number of TX queues for +PF."); + +module_param(func_txq_num, uint, 0); +MODULE_PARM_DESC(func_txq_num, "TX queue number for thisfunction.");
drivers/net/ethernet/realtek/rtase/rtase_main.c
Quoted 3 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +3
-0+ +module_param (func_rxq_num, uint,0 ); +MODULE_PARM_DESC(func_rxq_num, "RX queue number for thisfunction.");
drivers/net/ethernet/realtek/rtase/rtase_main.c line 119
Quoted 2 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +2
-0+ +module_param (interrupt_num, uint,0 );MODULE_PARM_DESC(interrupt_num,
drivers/net/ethernet/realtek/rtase/rtase_main.c
Quoted 5 lines
+"Interrupt Vector number for this function.");
drivers/net/ethernet/realtek/rtase/rtase_main.c new file +4
-0+ +module_param (rx_copybreak, int,0 ); +MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for +copy-only-tiny-frames");No module parameters. Please delete them.
Quoted 22 lines
(quoted diff) +22
-0+static int rtase_open(struct net_device *dev); static netdev_tx_t +rtase_start_xmit(struct sk_buff *skb, struct net_device *dev); static +void rtase_set_rx_mode(struct net_device *dev); static int +rtase_set_mac_address(struct net_device *dev, void *p); static int +rtase_change_mtu(struct net_device *dev, int new_mtu); static void +rtase_tx_timeout(struct net_device *dev, unsigned int txqueue); +static void rtase_get_stats64(struct net_device *dev, struct +rtnl_link_stats64 *stats); static int rtase_vlan_rx_add_vid(struct +net_device *dev, __be16 protocol, u16 vid); static int +rtase_vlan_rx_kill_vid(struct net_device *dev, __be16 protocol, u16 +vid); static int rtase_setup_tc(struct net_device *dev, enum +tc_setup_type type, void *type_data); + +static irqreturn_t rtase_interrupt(int irq, void *dev_instance); +static irqreturn_t rtase_q_interrupt(int irq, void *dev_instance); +static void rtase_hw_config(struct net_device *dev); static int +rtase_close(struct net_device *dev); static void rtase_down(struct +net_device *dev); static s32 rtase_init_ring(const struct net_device +*dev); static void rtase_init_netdev_ops(struct net_device *dev); +static void rtase_rar_set(const struct rtase_private *tp, const +uint8_t *addr); static void rtase_desc_addr_fill(const struct +rtase_private *tp); static void rtase_tx_desc_init(structReview
Quoted 10 lines
(quoted diff) +10
-0+rtase_private *tp, u16 idx); static void rtase_rx_desc_init(struct +rtase_private *tp, u16 idx); static void rtase_set_mar(const struct +rtase_private *tp); static s32 tx_handler(struct rtase_ring *ring, +s32 budget); static s32 rx_handler(struct rtase_ring *ring, s32 +budget); static int rtase_poll(struct napi_struct *napi, int budget); +static void rtase_sw_reset(struct net_device *dev); static void +rtase_hw_start(const struct net_device *dev); static void +rtase_dump_tally_counter(const struct rtase_private *tp, dma_addr_t +paddr); static void mac_ocp_write(const struct rtase_private *tp, u16 +reg_addr, u16 value);Remove all these put the code in the right order so that they are not needed. The only time you need forward definitions is for recursion.
Quoted 1 line
Andrew
Thanks for your quick review. I will make some code modifications for the problems you mentioned
Quoted 5 lines
---
pw-bot: cr------Please consider the environment before printing this e-mail.
Re: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 55 lines · Justin Lai
Quoted 47 lines · Justin Lai
Quoted 2 lines
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.
Quoted 31 lines
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| * * ----- ----- *Quoted 2 lines
*********||****************||***********
This driver is mainly used to control GMAC, but does not control the switchcore, so it is not the same as DSA.
Quoted 2 lines
In addition, the GMAC is not directly connected to the PHY, but directly connected to the mac of the switch core, so there is no need for PHY
handing.
So this describes your board? Is the MAC and the swtich two separate chips? Is it however possible to connect the GMAC to a PHY? Could some OEM purchase the chipset and build a board with a PHY? We write MAC drivers around what the MAC can do, not what one specific board allows.
Quoted 6 lines
What MAC drivers do to support being connected to a switch like this is use a fixed-link PHY, via phylink. This gives a virtual PHY, which supports one speed. The MAC driver then just uses the phylink API as normal.
On your board, how is the switch controlled? Is there an MDIO bus as part of the MAC? If so, you should add an MDIO bus master driver.
Quoted 5 lines
Hi, Andrew
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. So customers don't need to consider that.
O.K. It would of been helpful if you had said this right at the beginning. It is good to point out anything unusual with your hardware, otherwise reviewers are going to make wrong assumptions, and then ask lots of questions.
Is the 'line' speed of the MAC fixed? It operates at one speed, and that is it? What about pause? You cannot negotiate pause, but can it be forced?
Quoted 3 lines
We have some externally controlled interfaces to control switch core, such as I2C, MDIO, SPI, etc., but these are not controlled by GMAC .
And just for conformation, there is no extra fields in the DMA descriptors, etc, to help the switch? You will at some point write a DSA driver for the switch, and there will be a tagging protocol, extra headers added to the frame, in order to direct frames out the correct port of the switch?
Are the I2C, MDIO and SPI bus masters also hanging off a PCIE endpoint? Can they probe independently? I'm just want to check this should not be part of an MFD driver.
Is there a public data sheet for this device?
Andrew
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 68 lines · Justin Lai
Quoted 7 lines
Quoted 7 lines · Justin Lai
Quoted 3 lines
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.
Quoted 2 lines
Below is a simplified block diagram of the chip and its relevant
interfaces.
Quoted 36 lines
Quoted 36 lines
Quoted 29 lines
*************************
* *
* CPU network device *
* ____________ *
* | | *
* | PCIE Host | *
*************************
||
PCIE
||
***************************************** | PCIE Endpoint | * * |---------------| * * | GMAC | * * |------| Realtek * * || RTL90xx Series * * || * * _____________||______________ * * | |MAC| | * * | |---| | * * | | * * | Ethernet Switch Core | * * | | * * | ----- ----- | * * | |MAC| ............|MAC| | * * |__|___|_____________|___|____| * * |PHY| ............|PHY| * * ----- ----- *Quoted 3 lines
*********||****************||***********
This driver is mainly used to control GMAC, but does not control the switchcore, so it is not the same as DSA.
Quoted 3 lines
In addition, the GMAC is not directly connected to the PHY, but directly connected to the mac of the switch core, so there is no need for PHY
Quoted 6 lines
Quoted 6 lines
handing.
So this describes your board? Is the MAC and the swtich two separate chips? Is it however possible to connect the GMAC to a PHY? Could some OEM purchase the chipset and build a board with a PHY? We write MAC drivers around what the MAC can do, not what one specific board
allows.
Quoted 3 lines
Quoted 3 lines
What MAC drivers do to support being connected to a switch like this is use a fixed-link PHY, via phylink. This gives a virtual PHY, which supports
one speed.
Quoted 11 lines
Quoted 4 lines
The MAC driver then just uses the phylink API as normal.
On your board, how is the switch controlled? Is there an MDIO bus as part of the MAC? If so, you should add an MDIO bus master driver.
Hi, Andrew
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. So customers don't need to consider that.
Quoted 5 lines
O.K. It would of been helpful if you had said this right at the beginning. It is good to point out anything unusual with your hardware, otherwise reviewers are going to make wrong assumptions, and then ask lots of questions.
Is the 'line' speed of the MAC fixed? It operates at one speed, and that is it?
Hi, Andrew
The "line" speed of the MAC is fixed 5G, but the throughput will be determined according to the speed of the PCIe link. For example, if the link speed is gen 3, the throughput will be 5G. if the link speed is gen 2, the throughput will be 2.5G. if the link speed is gen 1, the throughput will be 1G.
Quoted 1 line
What about pause? You cannot negotiate pause, but can it be forced?
We do not support negotiate pause, but it can be forced.
Quoted 7 lines
Quoted 2 lines
We have some externally controlled interfaces to control switch core, such as I2C, MDIO, SPI, etc., but these are not controlled by GMAC .
And just for conformation, there is no extra fields in the DMA descriptors, etc, to help the switch? You will at some point write a DSA driver for the switch, and there will be a tagging protocol, extra headers added to the frame, in order to direct frames out the correct port of the switch?
There is no extra fields in DMA descriptors for tagging protocol. The tag added by switch hardware instead of this driver.
Quoted 4 lines
Are the I2C, MDIO and SPI bus masters also hanging off a PCIE endpoint? Can they probe independently? I'm just want to check this should not be part of an MFD driver.
The I2C, MDIO and SPI bus masters are not hanging off the PCIE endpoints, but on the switch core.
Quoted 2 lines
Is there a public data sheet for this device?
We currently do not have a public data sheet to provide.
Quoted 3 lines
Andrew
Re: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 10 lines
Quoted 1 line
Is the 'line' speed of the MAC fixed? It operates at one speed, and that is it?
Hi, Andrew
The "line" speed of the MAC is fixed 5G, but the throughput will be determined according to the speed of the PCIe link. For example, if the link speed is gen 3, the throughput will be 5G. if the link speed is gen 2, the throughput will be 2.5G. if the link speed is gen 1, the throughput will be 1G.
ksettings does not return throughput, it returns the line speed. throughput is determined by a lot of different things, can the CPU handle frames fast enough, is the memory bandwidth high enough, what is happening on other ports of the PCIe switch etc.
There is at least one driver i know of which reports a warning at probe time, if it finds the device is on a bus which cannot support the full bandwidth. Maybe copy that.
Quoted 10 lines
There is no extra fields in DMA descriptors for tagging protocol. The tag added by switch hardware instead of this driver.
Quoted 3 lines
Are the I2C, MDIO and SPI bus masters also hanging off a PCIE endpoint? Can they probe independently? I'm just want to check this should not be part of an MFD driver.
The I2C, MDIO and SPI bus masters are not hanging off the PCIE endpoints, but on the switch core.
So the switch core is also an PCIE endpoint?
Andrew
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Is the 'line' speed of the MAC fixed? It operates at one speed, and that is
it?
Quoted 9 lines
Hi, Andrew
The "line" speed of the MAC is fixed 5G, but the throughput will be determined according to the speed of the PCIe link. For example, if the link speed is gen 3, the throughput will be 5G. if the link speed is gen 2, the throughput will be 2.5G. if the link speed is gen 1, the throughput will be 1G.
Quoted 9 lines
ksettings does not return throughput, it returns the line speed. throughput is determined by a lot of different things, can the CPU handle frames fast enough, is the memory bandwidth high enough, what is happening on other ports of the PCIe switch etc.
There is at least one driver i know of which reports a warning at probe time, if it finds the device is on a bus which cannot support the full bandwidth. Maybe copy that.
Hi, Andrew
Thanks for your guidance, we have represented the actual connection speed in the next version.
Quoted 8 lines
Quoted 7 lines
There is no extra fields in DMA descriptors for tagging protocol. The tag added by switch hardware instead of this driver.
Quoted 3 lines
Are the I2C, MDIO and SPI bus masters also hanging off a PCIE endpoint? Can they probe independently? I'm just want to check this should not be part of an MFD driver.
Quoted 4 lines
Quoted 2 lines
The I2C, MDIO and SPI bus masters are not hanging off the PCIE endpoints, but on the switch core.
So the switch core is also an PCIE endpoint?
Sorry, please allow me to explain again.
The RTL90xx Series supports I2C, MDC/MDIO and SPI slave to access the registers of Ethernet Switch Core and the external CPU could manage it via these pins. You are right, there is a tag protocol in the switch core. But It's for the other ports, usually the cpu port, not this pcie gmac interface. You can think of this pcie gmac as a NIC connecting to the external ethernet switch directly.
Quoted 3 lines
Andrew
.
Re: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 2 lines
Sorry, please allow me to explain again.
The RTL90xx Series supports I2C, MDC/MDIO and SPI slave to access the registers of Ethernet Switch Core and the external CPU could manage it via these pins.
I was wondering if you had mis-understood my question. The bus 'master' is the device which controls the bus. SPI and MDIO has one bus master, and there can be multiple clients on the bus. I2C in theory can have multiple bus masters on one bus, bit it is not done too often. Your switch is a client.
So my question was, are the bus masters also on PCIE enpoints within the chip. From an architecture standpoint, it would make sense they are, all you need is one 4x PCIE slot, and this chip gives you everything you need. But you can also make use of the SoCs I2C, SPI or MDIO bus.
Andrew
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 10 lines
Quoted 2 lines
Sorry, please allow me to explain again.
The RTL90xx Series supports I2C, MDC/MDIO and SPI slave to access theregisters of Ethernet Switch Core and the external CPU could manage it via these pins.
I was wondering if you had mis-understood my question. The bus 'master' is the device which controls the bus. SPI and MDIO has one bus master, and there can be multiple clients on the bus. I2C in theory can have multiple bus masters on one bus, bit it is not done too often. Your switch is a client.
Quoted 6 lines
So my question was, are the bus masters also on PCIE enpoints within the chip. From an architecture standpoint, it would make sense they are, all you need is one 4x PCIE slot, and this chip gives you everything you need. But you can also make use of the SoCs I2C, SPI or MDIO bus.
Andrew
Thanks, I understand what you mean.
But I2C, SPI, MDIO are connected to the SoC through this chip's external pins, not on the PCIe bus. Actually, there is the other function in the PCIe GMAC(Multiple function) to manage the registers of Switch Core. Should they be integrated into the MFD driver?
Not everyone will use this function.
Re: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 2 lines
But I2C, SPI, MDIO are connected to the SoC through this chip's external pins, not on the PCIe bus.
Thanks, that was the information i was trying to get at.
Quoted 3 lines
Actually, there is the other function in the PCIe GMAC(Multiple function) to manage the registers of Switch Core. Should they be integrated into the MFD driver?
Can you cleanly attach another PCI driver to those functions?
You need to use an MFD when there is a single top level addressable block of hardware which has multiple functions. Thank of an I2C device, which has a single address on the bus, but multiple functions. Access to that one address needs to be shared via multiple drivers. The MFD framework provides the glue to share access to the hardware.
However, PCI identification and addressing is more flexible. So long as they are separate PCI functions, you should be able to load two drivers and not have problems. Then you don't need an MFD.
Andrew
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 10 lines
Quoted 2 lines
But I2C, SPI, MDIO are connected to the SoC through this chip's external pins, not on the PCIe bus.
Thanks, that was the information i was trying to get at.
Quoted 3 lines
Actually, there is the other function in the PCIe GMAC(Multiple function) to manage the registers of Switch Core. Should they be integrated into the MFD driver?
Can you cleanly attach another PCI driver to those functions?
Yes, they could be attached individually
Quoted 9 lines
You need to use an MFD when there is a single top level addressable block of hardware which has multiple functions. Thank of an I2C device, which has a single address on the bus, but multiple functions.
Access to that one address needs to be shared via multiple drivers. The MFD framework provides the glue to share access to the hardware.However, PCI identification and addressing is more flexible. So long as they are separate PCI functions, you should be able to load two drivers and not have problems. Then you don't need an MFD.
Thank you very much for your comments and time for review.
Jakub Kicinski
maintainerRe: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
In reply to Justin LaiQuoted 2 lines · On Tue, 15 Aug 2023 22:37:55 +0800 Justin Lai wrote:
.../net/ethernet/realtek/rtase/rtase_main.c | 2696 +++++++++++++++++ 5 files changed, 3127 insertions(+)
Please try to make this patch smaller, usually breaking out ethtool operations and any offloads to separate patches does the trick. Keep in mind the driver must be operational after each patch.
Justin Lai
maintainerRE: [PATCH net-next v3 1/2] net/ethernet/realtek: Add Realtek automotive PCIe driver code
Quoted 7 lines · On Tue, 15 Aug 2023 22:37:55 +0800 Justin Lai wrote:
Quoted 2 lines
.../net/ethernet/realtek/rtase/rtase_main.c | 2696 +++++++++++++++++ 5 files changed, 3127 insertions(+)Please try to make this patch smaller, usually breaking out ethtool operations and any offloads to separate patches does the trick.
Keep in mind the driver must be operational after each patch.
Thank you for your review, I will make this change in version 5.
Justin Lai
maintainerPATCH v3 2/2 MAINTAINERS: Add the rtase ethernet driver entry
In reply to Justin LaiAdd myself and Larry Chiu as the maintainer for the rtase ethernet driver.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -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