Skip to contentSkip to conversation

net: ipqess: introduce Qualcomm IPQESS driver

PATCH Superseded Maxime Chevallier 8 participants 24 messages May 14, 2022 – May 19, 2022

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: ipqess: introduce Qualcomm IPQESS driver

Hello everyone,

This is the 2nd iteration of a series that introduces a new driver, for the Qualcomm IPQESS Ethernet Controller, found on the IPQ4019.

Notables changes on V2 :
- Put the DSA tag in the skb itself instead of using skb->shinfo
- Fixed the initialisation sequence based on Andrew's comments
- Reworked the error paths in the init sequence
- Add support for the clock and reset lines on that controller
- Fixed and updated the binding

The driver itself is pretty straightforward, but has lived out-of-tree for a while. I've done my best to clean-up some outdated API calls, but some might remain.

This controller is somewhat special, since it's part of the IPQ4019 SoC which also includes an QCA8K switch, and uses the IPQESS controller for the CPU port. The switch is so tightly intergrated with the MAC that it is connected to the MAC using an internal link (hence the fact that we only support PHY_INTERFACE_MODE_INTERNAL), and this has some consequences on the DSA side.

The tagging for the switch isn't done inband as most switch do, but out-of-band, the DSA tag being included in the DMA descriptor.

This series includes a new out-of-band tagger that uses the skb headroom to convey the tag between the tagger and the MAC driver.

Thanks to the Sartura folks who worked on a base version of this driver, and provided test hardware.

Best regards,

Maxime Chevallier

Maxime Chevallier (5):
net: ipqess: introduce the Qualcomm IPQESS driver
net: dsa: add out-of-band tagging protocol
net: ipqess: Add out-of-band DSA tagging support
net: dt-bindings: Introduce the Qualcomm IPQESS Ethernet controller
ARM: dts: qcom: ipq4019: Add description for the IPQESS Ethernet
controller

 .../devicetree/bindings/net/qcom,ipqess.yaml  |  104 ++
 MAINTAINERS                                   |    6 +
 arch/arm/boot/dts/qcom-ipq4019.dtsi           |   46 +
 drivers/net/ethernet/qualcomm/Kconfig         |   12 +
 drivers/net/ethernet/qualcomm/Makefile        |    2 +
 drivers/net/ethernet/qualcomm/ipqess/Makefile |    8 +
 drivers/net/ethernet/qualcomm/ipqess/ipqess.c | 1296 +++++++++++++++++
 drivers/net/ethernet/qualcomm/ipqess/ipqess.h |  518 +++++++
 .../ethernet/qualcomm/ipqess/ipqess_ethtool.c |  168 +++
 include/linux/dsa/oob.h                       |   17 +
 include/net/dsa.h                             |    2 +
 net/dsa/Kconfig                               |    7 +
 net/dsa/Makefile                              |    1 +
 net/dsa/tag_oob.c                             |   84 ++
 14 files changed, 2271 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom,ipqess.yaml
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.c
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.h
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess_ethtool.c
 create mode 100644 include/linux/dsa/oob.h
 create mode 100644 net/dsa/tag_oob.c
Signature · 1 line
2.36.1
#1 lore raw

PATCH v2 1/5 net: ipqess: introduce the Qualcomm IPQESS driver

The Qualcomm IPQESS controller is a simple 1G Ethernet controller found on the IPQ4019 chip. This controller has some specificities, in that the IPQ4019 platform that includes that controller also has an internal switch, based on the QCA8K IP.

It is connected to that switch through an internal link, and doesn't expose directly any external interface, hence it only supports the PHY_INTERFACE_MODE_INTERNAL for now.

It has 16 RX and TX queues, with a very basic RSS fanout configured at init time.

---
V1->V2 :
- Reworked the init sequence, following Andrew's comments
- Added clock and reset support
- Reworked the error paths
- Added extra endianness wrappers to fix sparse warnings

 MAINTAINERS                                   |    6 +
 drivers/net/ethernet/qualcomm/Kconfig         |   11 +
 drivers/net/ethernet/qualcomm/Makefile        |    2 +
 drivers/net/ethernet/qualcomm/ipqess/Makefile |    8 +
 drivers/net/ethernet/qualcomm/ipqess/ipqess.c | 1269 +++++++++++++++++
 drivers/net/ethernet/qualcomm/ipqess/ipqess.h |  518 +++++++
 .../ethernet/qualcomm/ipqess/ipqess_ethtool.c |  168 +++
 7 files changed, 1982 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.c
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.h
 create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess_ethtool.c
MAINTAINERS +6 -0
index 9b0480f1b153..29e6ec4f975a 100644
@@ -16308,6 +16308,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/qualcomm/emac/
 
+QUALCOMM IPQESS ETHERNET DRIVER
+M:	Maxime Chevallier <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/qualcomm/ipqess/
+
 QUALCOMM ETHQOS ETHERNET DRIVER
 M:	Vinod Koul <[email protected]>
 L:	[email protected]
drivers/net/ethernet/qualcomm/Kconfig +11 -0
index a4434eb38950..a723ddbea248 100644
@@ -60,6 +60,17 @@ config QCOM_EMAC
 	  low power, Receive-Side Scaling (RSS), and IEEE 1588-2008
 	  Precision Clock Synchronization Protocol.
 
+config QCOM_IPQ4019_ESS_EDMA
+	tristate "Qualcomm Atheros IPQ4019 ESS EDMA support"
+	depends on OF
+	select PHYLINK
+	help
+	  This driver supports the Qualcomm Atheros IPQ40xx built-in
+	  ESS EDMA ethernet controller.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ipqess.
+
 source "drivers/net/ethernet/qualcomm/rmnet/Kconfig"
 
 endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 9250976dd884..db463c9ea1f9 100644
@@ -11,4 +11,6 @@ qcauart-objs := qca_uart.o
 
 obj-y += emac/
 
+obj-$(CONFIG_QCOM_IPQ4019_ESS_EDMA) += ipqess/
+
 obj-$(CONFIG_RMNET) += rmnet/
drivers/net/ethernet/qualcomm/ipqess/Makefile new file +8 -0
new file mode 100644
index 000000000000..4f2db7283ebf
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for the IPQ ESS driver
+#
+
+obj-$(CONFIG_QCOM_IPQ4019_ESS_EDMA) += ipq_ess.o
+
+ipq_ess-objs := ipqess.o ipqess_ethtool.o
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +1269 -0

1,269 lines not on this page · raw message

drivers/net/ethernet/qualcomm/ipqess/ipqess.h new file +518 -0

518 lines not on this page · raw message

drivers/net/ethernet/qualcomm/ipqess/ipqess_ethtool.c new file +168 -0

168 lines not on this page · raw message

Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

Quoted 5 lines · Maxime Chevallier
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +5 -0
+static int ipqess_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
+{
+	struct ipqess *ess = netdev_priv(netdev);
+
+	switch (cmd) {

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 664

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+	case SIOCGMIIPHY:
+	case SIOCGMIIREG:
+	case SIOCSMIIREG:
+		return phylink_mii_ioctl(ess->phylink, ifr, cmd);
+	default:
+		break;
+	}
+
+	return -EOPNOTSUPP;
+}

Is there a reason this isn't just:

	return phylink_mii_ioctl(ess->phylink, ifr, cmd);

?

Quoted 38 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +38 -0
+static int ipqess_axi_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct net_device *netdev;
+	phy_interface_t phy_mode;
+	struct resource *res;
+	struct ipqess *ess;
+	int i, err = 0;
+
+	netdev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(struct ipqess),
+					 IPQESS_NETDEV_QUEUES,
+					 IPQESS_NETDEV_QUEUES);
+	if (!netdev)
+		return -ENOMEM;
+
+	ess = netdev_priv(netdev);
+	ess->netdev = netdev;
+	ess->pdev = pdev;
+	spin_lock_init(&ess->stats_lock);
+	SET_NETDEV_DEV(netdev, &pdev->dev);
+	platform_set_drvdata(pdev, netdev);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ess->hw_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ess->hw_addr))
+		return PTR_ERR(ess->hw_addr);
+
+	err = of_get_phy_mode(np, &phy_mode);
+	if (err) {
+		dev_err(&pdev->dev, "incorrect phy-mode\n");
+		return err;
+	}
+
+	ess->ess_clk = devm_clk_get(&pdev->dev, "ess");
+	if (!IS_ERR(ess->ess_clk))
+		clk_prepare_enable(ess->ess_clk);
+
+	ess->ess_rst = devm_reset_control_get(&pdev->dev, "ess");

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 1160

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+	if (IS_ERR(ess->ess_rst))
+		goto err_clk;
+
+	ipqess_reset(ess);
+
+	ess->phylink_config.dev = &netdev->dev;
+	ess->phylink_config.type = PHYLINK_NETDEV;
+
+	__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+		  ess->phylink_config.supported_interfaces);

No mac capabilities?

Quoted 4 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +4 -0
+
+	ess->phylink = phylink_create(&ess->phylink_config,
+				      of_fwnode_handle(np), phy_mode,
+				      &ipqess_phylink_mac_ops);
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#3 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

Hello Russell,

Thanks for the review.

Quoted 19 lines · On Sat, 14 May 2022 18:18:17 +0100 "Russell King (Oracle)"…
Quoted 5 lines · Maxime Chevallier

+static int ipqess_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) +{

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +3 -0
+	struct ipqess *ess = netdev_priv(netdev);
+
+	switch (cmd) {

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 664

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+	case SIOCGMIIPHY:
+	case SIOCGMIIREG:
+	case SIOCSMIIREG:
+		return phylink_mii_ioctl(ess->phylink, ifr, cmd);
+	default:
+		break;
+	}
+
+	return -EOPNOTSUPP;
+}  

Is there a reason this isn't just:

Quoted 1 line
	return phylink_mii_ioctl(ess->phylink, ifr, cmd);

Not really, an oversight on my part, I'll address that in v3

Quoted 45 lines

?

Quoted 43 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+static int ipqess_axi_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct net_device *netdev;
+	phy_interface_t phy_mode;
+	struct resource *res;
+	struct ipqess *ess;
+	int i, err = 0;
+
+	netdev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(struct

ipqess),

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +32 -0
+					 IPQESS_NETDEV_QUEUES,
+					 IPQESS_NETDEV_QUEUES);
+	if (!netdev)
+		return -ENOMEM;
+
+	ess = netdev_priv(netdev);
+	ess->netdev = netdev;
+	ess->pdev = pdev;
+	spin_lock_init(&ess->stats_lock);
+	SET_NETDEV_DEV(netdev, &pdev->dev);
+	platform_set_drvdata(pdev, netdev);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ess->hw_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ess->hw_addr))
+		return PTR_ERR(ess->hw_addr);
+
+	err = of_get_phy_mode(np, &phy_mode);
+	if (err) {
+		dev_err(&pdev->dev, "incorrect phy-mode\n");
+		return err;
+	}
+
+	ess->ess_clk = devm_clk_get(&pdev->dev, "ess");
+	if (!IS_ERR(ess->ess_clk))
+		clk_prepare_enable(ess->ess_clk);
+
+	ess->ess_rst = devm_reset_control_get(&pdev->dev, "ess");
+	if (IS_ERR(ess->ess_rst))
+		goto err_clk;
+
+	ipqess_reset(ess);
Quoted 8 lines

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 1160

Quoted 6 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +6 -0
+
+	ess->phylink_config.dev = &netdev->dev;
+	ess->phylink_config.type = PHYLINK_NETDEV;
+
+	__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+		  ess->phylink_config.supported_interfaces);  

No mac capabilities?

My bad too, I also missed that. I'll also address that in v3.

Quoted 6 lines

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 1164

Quoted 5 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +3 -0
+
+	ess->phylink = phylink_create(&ess->phylink_config,
+				      of_fwnode_handle(np),

phy_mode,

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +1 -0
+				      &ipqess_phylink_mac_ops);  

Thanks,

Maxime

#4 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

In reply to Maxime Chevallier
Quoted 48 lines · Maxime Chevallier
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +48 -0
+/* locking is handled by the caller */
+static int ipqess_rx_buf_alloc_napi(struct ipqess_rx_ring *rx_ring)
+{
+	struct ipqess_buf *buf = &rx_ring->buf[rx_ring->head];
+
+	buf->skb = napi_alloc_skb(&rx_ring->napi_rx, IPQESS_RX_HEAD_BUFF_SIZE);
+	if (!buf->skb)
+		return -ENOMEM;
+
+	return ipqess_rx_buf_prepare(buf, rx_ring);
+}
+
+static int ipqess_rx_buf_alloc(struct ipqess_rx_ring *rx_ring)
+{
+	struct ipqess_buf *buf = &rx_ring->buf[rx_ring->head];
+
+	buf->skb = netdev_alloc_skb_ip_align(rx_ring->ess->netdev,
+					     IPQESS_RX_HEAD_BUFF_SIZE);
+
+	if (!buf->skb)
+		return -ENOMEM;
+
+	return ipqess_rx_buf_prepare(buf, rx_ring);
+}
+
+static void ipqess_refill_work(struct work_struct *work)
+{
+	struct ipqess_rx_ring_refill *rx_refill = container_of(work,
+		struct ipqess_rx_ring_refill, refill_work);
+	struct ipqess_rx_ring *rx_ring = rx_refill->rx_ring;
+	int refill = 0;
+
+	/* don't let this loop by accident. */
+	while (atomic_dec_and_test(&rx_ring->refill_count)) {
+		napi_disable(&rx_ring->napi_rx);
+		if (ipqess_rx_buf_alloc(rx_ring)) {
+			refill++;
+			dev_dbg(rx_ring->ppdev,
+				"Not all buffers were reallocated");
+		}
+		napi_enable(&rx_ring->napi_rx);
+	}
+
+	if (atomic_add_return(refill, &rx_ring->refill_count))
+		schedule_work(&rx_refill->refill_work);
+}
+
+static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int budget)

drivers/net/ethernet/qualcomm/ipqess/ipqess.c

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +8 -0
+{
 
+	while (done < budget) {
 
+		num_desc += atomic_xchg(&rx_ring->refill_count, 0);
+		while (num_desc) {
+			if (ipqess_rx_buf_alloc_napi(rx_ring)) {
+				num_desc = atomic_add_return(num_desc,
+							     &rx_ring->refill_count);
+				if (num_desc >= ((4 * IPQESS_RX_RING_SIZE + 6) / 7))

DIV_ROUND_UP(IPQESS_RX_RING_SIZE * 4, 7)
Also, why this number?

Quoted 13 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +13 -0
+					schedule_work(&rx_ring->ess->rx_refill[rx_ring->ring_id].refill_work);
+				break;
+			}
+			num_desc--;
+		}
+	}
+
+	ipqess_w32(rx_ring->ess, IPQESS_REG_RX_SW_CONS_IDX_Q(rx_ring->idx),
+		   rx_ring_tail);
+	rx_ring->tail = rx_ring_tail;
+
+	return done;
+}

drivers/net/ethernet/qualcomm/ipqess/ipqess.c

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +9 -0
 
+static void ipqess_rx_ring_free(struct ipqess *ess)
+{
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		int j;
+
+		atomic_set(&ess->rx_ring[i].refill_count, 0);
+		cancel_work_sync(&ess->rx_refill[i].refill_work);

When refill_work is currently scheduled and executing the while loop, will refill_count underflow due to the possibility of calling atomic_dec_and_test(0)?

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+
+		for (j = 0; j < IPQESS_RX_RING_SIZE; j++) {
+			dma_unmap_single(&ess->pdev->dev,
+					 ess->rx_ring[i].buf[j].dma,
+					 ess->rx_ring[i].buf[j].length,
+					 DMA_FROM_DEVICE);
+			dev_kfree_skb_any(ess->rx_ring[i].buf[j].skb);
+		}
+	}
+}
#5 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

Hello Vlad,

Quoted 56 lines · On Sat, 14 May 2022 20:44:38 +0000 Vladimir Oltean <[email protected]>…
Quoted 54 lines · Maxime Chevallier
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +6 -0
+/* locking is handled by the caller */
+static int ipqess_rx_buf_alloc_napi(struct ipqess_rx_ring *rx_ring)
+{
+	struct ipqess_buf *buf = &rx_ring->buf[rx_ring->head];
+
+	buf->skb = napi_alloc_skb(&rx_ring->napi_rx,

IPQESS_RX_HEAD_BUFF_SIZE);

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +12 -0
+	if (!buf->skb)
+		return -ENOMEM;
+
+	return ipqess_rx_buf_prepare(buf, rx_ring);
+}
+
+static int ipqess_rx_buf_alloc(struct ipqess_rx_ring *rx_ring)
+{
+	struct ipqess_buf *buf = &rx_ring->buf[rx_ring->head];
+
+	buf->skb = netdev_alloc_skb_ip_align(rx_ring->ess->netdev,
+

IPQESS_RX_HEAD_BUFF_SIZE); +

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +9 -0
+	if (!buf->skb)
+		return -ENOMEM;
+
+	return ipqess_rx_buf_prepare(buf, rx_ring);
+}
+
+static void ipqess_refill_work(struct work_struct *work)
+{
+	struct ipqess_rx_ring_refill *rx_refill =

container_of(work,

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +11 -0
+		struct ipqess_rx_ring_refill, refill_work);
+	struct ipqess_rx_ring *rx_ring = rx_refill->rx_ring;
+	int refill = 0;
+
+	/* don't let this loop by accident. */
+	while (atomic_dec_and_test(&rx_ring->refill_count)) {
+		napi_disable(&rx_ring->napi_rx);
+		if (ipqess_rx_buf_alloc(rx_ring)) {
+			refill++;
+			dev_dbg(rx_ring->ppdev,
+				"Not all buffers were

reallocated");

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +9 -0
+		}
+		napi_enable(&rx_ring->napi_rx);
+	}
+
+	if (atomic_add_return(refill, &rx_ring->refill_count))
+		schedule_work(&rx_refill->refill_work);
+}
+
+static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int

budget) +{

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +1 -0
+	while (done < budget) {  
Quoted 12 lines
Quoted 9 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +4 -0
+		num_desc += atomic_xchg(&rx_ring->refill_count, 0);
+		while (num_desc) {
+			if (ipqess_rx_buf_alloc_napi(rx_ring)) {
+				num_desc =

atomic_add_return(num_desc,
+
&rx_ring->refill_count);

(quoted diff) +1 -0
+				if (num_desc >= ((4 *

IPQESS_RX_RING_SIZE + 6) / 7))

DIV_ROUND_UP(IPQESS_RX_RING_SIZE * 4, 7)
Also, why this number?

Ah this was from the original out-of-tree driver... I'll try to figure out what's going on an replace that by some #define that would make more sense.

Quoted 16 lines
Quoted 15 lines

+ schedule_work(&rx_ring->ess->rx_refill[rx_ring->ring_id].refill_work);

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +7 -0
+				break;
+			}
+			num_desc--;
+		}
+	}
+
+	ipqess_w32(rx_ring->ess,

IPQESS_REG_RX_SW_CONS_IDX_Q(rx_ring->idx),

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +5 -0
+		   rx_ring_tail);
+	rx_ring->tail = rx_ring_tail;
+
+	return done;
+}  
Quoted 13 lines

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 302

Quoted 9 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +9 -0
+static void ipqess_rx_ring_free(struct ipqess *ess)
+{
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		int j;
+
+		atomic_set(&ess->rx_ring[i].refill_count, 0);
+		cancel_work_sync(&ess->rx_refill[i].refill_work);  

When refill_work is currently scheduled and executing the while loop, will refill_count underflow due to the possibility of calling atomic_dec_and_test(0)?

Good question, I'll double-check, you might be correct. Nice catch

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +4 -0
+
+		for (j = 0; j < IPQESS_RX_RING_SIZE; j++) {
+			dma_unmap_single(&ess->pdev->dev,
+

ess->rx_ring[i].buf[j].dma,

Quoted 8 lines

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 42

Quoted 8 lines

+
ess->rx_ring[i].buf[j].length,

(quoted diff) +2 -0
+					 DMA_FROM_DEVICE);
+

dev_kfree_skb_any(ess->rx_ring[i].buf[j].skb);

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +3 -0
+		}
+	}
+  

Thanks,

Maxime

maintainer
#6 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

In reply to Maxime Chevallier
Quoted 12 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +12 -0
+static int ipqess_tx_ring_alloc(struct ipqess *ess)
+{
+	struct device *dev = &ess->pdev->dev;
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		struct ipqess_tx_ring *tx_ring = &ess->tx_ring[i];
+		size_t size;
+		u32 idx;
+
+		tx_ring->ess = ess;
+		tx_ring->ring_id = i;

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 108

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+		tx_ring->idx = i * 4;
+		tx_ring->count = IPQESS_TX_RING_SIZE;
+		tx_ring->nq = netdev_get_tx_queue(ess->netdev, i);
+
+		size = sizeof(struct ipqess_buf) * IPQESS_TX_RING_SIZE;
+		tx_ring->buf = devm_kzalloc(dev, size, GFP_KERNEL);
+		if (!tx_ring->buf) {
+			netdev_err(ess->netdev, "buffer alloc of tx ring failed");
+			return -ENOMEM;
+		}

kzalloc() is pretty loud when there is no memory. So you see patches removing such warning messages.

Quoted 12 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +12 -0
+static int ipqess_rx_napi(struct napi_struct *napi, int budget)
+{
+	struct ipqess_rx_ring *rx_ring = container_of(napi, struct ipqess_rx_ring,
+						    napi_rx);
+	struct ipqess *ess = rx_ring->ess;
+	u32 rx_mask = BIT(rx_ring->idx);
+	int remain_budget = budget;
+	int rx_done;
+	u32 status;
+
+poll_again:
+	ipqess_w32(ess, IPQESS_REG_RX_ISR, rx_mask);

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 523

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+	rx_done = ipqess_rx_poll(rx_ring, remain_budget);
+
+	if (rx_done == remain_budget)
+		return budget;
+
+	status = ipqess_r32(ess, IPQESS_REG_RX_ISR);
+	if (status & rx_mask) {
+		remain_budget -= rx_done;
+		goto poll_again;
+	}

Could this be turned into a do while() loop?

Quoted 11 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +11 -0
+static void ipqess_irq_enable(struct ipqess *ess)
+{
+	int i;
+
+	ipqess_w32(ess, IPQESS_REG_RX_ISR, 0xff);
+	ipqess_w32(ess, IPQESS_REG_TX_ISR, 0xffff);
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		ipqess_w32(ess, IPQESS_REG_RX_INT_MASK_Q(ess->rx_ring[i].idx), 1);
+		ipqess_w32(ess, IPQESS_REG_TX_INT_MASK_Q(ess->tx_ring[i].idx), 1);
+	}
+}

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 577

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+
+static void ipqess_irq_disable(struct ipqess *ess)
+{
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		ipqess_w32(ess, IPQESS_REG_RX_INT_MASK_Q(ess->rx_ring[i].idx), 0);
+		ipqess_w32(ess, IPQESS_REG_TX_INT_MASK_Q(ess->tx_ring[i].idx), 0);
+	}
+}

Enable and disable are not symmetric?

Quoted 1 line

+static inline void ipqess_kick_tx(struct ipqess_tx_ring *tx_ring)

No inline functions please in .c files. Let the compiler decide.

Andrew

#7 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

Hi Andrew,

Quoted 19 lines · On Mon, 16 May 2022 04:51:03 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 19 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +17 -0
+static int ipqess_tx_ring_alloc(struct ipqess *ess)
+{
+	struct device *dev = &ess->pdev->dev;
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		struct ipqess_tx_ring *tx_ring = &ess->tx_ring[i];
+		size_t size;
+		u32 idx;
+
+		tx_ring->ess = ess;
+		tx_ring->ring_id = i;
+		tx_ring->idx = i * 4;
+		tx_ring->count = IPQESS_TX_RING_SIZE;
+		tx_ring->nq = netdev_get_tx_queue(ess->netdev, i);
+
+		size = sizeof(struct ipqess_buf) *

IPQESS_TX_RING_SIZE;

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +1 -0
+		tx_ring->buf = devm_kzalloc(dev, size, GFP_KERNEL);
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+		if (!tx_ring->buf) {
+			netdev_err(ess->netdev, "buffer alloc of

tx ring failed");

(quoted diff) +2 -0
+			return -ENOMEM;
+		}  

kzalloc() is pretty loud when there is no memory. So you see patches removing such warning messages.

Ack, I'll remove that

Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +3 -0
+static int ipqess_rx_napi(struct napi_struct *napi, int budget)
+{
+	struct ipqess_rx_ring *rx_ring = container_of(napi, struct

ipqess_rx_ring,

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +13 -0
+						    napi_rx);
+	struct ipqess *ess = rx_ring->ess;
+	u32 rx_mask = BIT(rx_ring->idx);
+	int remain_budget = budget;
+	int rx_done;
+	u32 status;
+
+poll_again:
+	ipqess_w32(ess, IPQESS_REG_RX_ISR, rx_mask);
+	rx_done = ipqess_rx_poll(rx_ring, remain_budget);
+
+	if (rx_done == remain_budget)
+		return budget;
Quoted 8 lines

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 523

Quoted 6 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +6 -0
+
+	status = ipqess_r32(ess, IPQESS_REG_RX_ISR);
+	if (status & rx_mask) {
+		remain_budget -= rx_done;
+		goto poll_again;
+	}  

Could this be turned into a do while() loop?

Yes indeed, I'll fix this for v3

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +8 -0
+static void ipqess_irq_enable(struct ipqess *ess)
+{
+	int i;
+
+	ipqess_w32(ess, IPQESS_REG_RX_ISR, 0xff);
+	ipqess_w32(ess, IPQESS_REG_TX_ISR, 0xffff);
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		ipqess_w32(ess,

IPQESS_REG_RX_INT_MASK_Q(ess->rx_ring[i].idx), 1);

(quoted diff) +1 -0
+		ipqess_w32(ess,

IPQESS_REG_TX_INT_MASK_Q(ess->tx_ring[i].idx), 1);

drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +8 -0
+	}
+}
+
+static void ipqess_irq_disable(struct ipqess *ess)
+{
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +1 -0
+		ipqess_w32(ess,

IPQESS_REG_RX_INT_MASK_Q(ess->rx_ring[i].idx), 0);

(quoted diff) +1 -0
+		ipqess_w32(ess,

IPQESS_REG_TX_INT_MASK_Q(ess->tx_ring[i].idx), 0);

(quoted diff) +2 -0
+	}
+}  

Enable and disable are not symmetric?

Ah nice catch too, I'll dig into this, either to make it symmetric or to explain with a comment why it isn't

Quoted 4 lines
Quoted 2 lines

+static inline void ipqess_kick_tx(struct ipqess_tx_ring *tx_ring)

No inline functions please in .c files. Let the compiler decide.

Ack, I'll address that.

Quoted 1 line

Andrew

Thanks again for the review

Maxime

#8 lore raw

Re: [PATCH net-next v2 1/5] net: ipqess: introduce the Qualcomm IPQESS driver

In reply to Maxime Chevallier

Le 14/05/2022 à 17:06, Maxime Chevallier a écrit :

Quoted 205 lines

The Qualcomm IPQESS controller is a simple 1G Ethernet controller found on the IPQ4019 chip. This controller has some specificities, in that the IPQ4019 platform that includes that controller also has an internal switch, based on the QCA8K IP.

It is connected to that switch through an internal link, and doesn't expose directly any external interface, hence it only supports the PHY_INTERFACE_MODE_INTERNAL for now.

It has 16 RX and TX queues, with a very basic RSS fanout configured at init time.

---
V1->V2 :
- Reworked the init sequence, following Andrew's comments
- Added clock and reset support
- Reworked the error paths
- Added extra endianness wrappers to fix sparse warnings

  MAINTAINERS                                   |    6 +
  drivers/net/ethernet/qualcomm/Kconfig         |   11 +
  drivers/net/ethernet/qualcomm/Makefile        |    2 +
  drivers/net/ethernet/qualcomm/ipqess/Makefile |    8 +
  drivers/net/ethernet/qualcomm/ipqess/ipqess.c | 1269 +++++++++++++++++
  drivers/net/ethernet/qualcomm/ipqess/ipqess.h |  518 +++++++
  .../ethernet/qualcomm/ipqess/ipqess_ethtool.c |  168 +++
  7 files changed, 1982 insertions(+)

create mode 100644 drivers/net/ethernet/qualcomm/ipqess/Makefile create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.c create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess.h create mode 100644 drivers/net/ethernet/qualcomm/ipqess/ipqess_ethtool.c

MAINTAINERS +6 -0
index 9b0480f1b153..29e6ec4f975a 100644
@@ -16308,6 +16308,12 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/net/ethernet/qualcomm/emac/
 
+QUALCOMM IPQESS ETHERNET DRIVER
+M:	Maxime Chevallier <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/qualcomm/ipqess/
+
  QUALCOMM ETHQOS ETHERNET DRIVER
  M:	Vinod Koul <[email protected]>
  L:	[email protected]
drivers/net/ethernet/qualcomm/Kconfig +11 -0
index a4434eb38950..a723ddbea248 100644
@@ -60,6 +60,17 @@ config QCOM_EMAC
  	  low power, Receive-Side Scaling (RSS), and IEEE 1588-2008
  	  Precision Clock Synchronization Protocol.
 
+config QCOM_IPQ4019_ESS_EDMA
+	tristate "Qualcomm Atheros IPQ4019 ESS EDMA support"
+	depends on OF
+	select PHYLINK
+	help
+	  This driver supports the Qualcomm Atheros IPQ40xx built-in
+	  ESS EDMA ethernet controller.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ipqess.
+
  source "drivers/net/ethernet/qualcomm/rmnet/Kconfig"
 
  endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 9250976dd884..db463c9ea1f9 100644
@@ -11,4 +11,6 @@ qcauart-objs := qca_uart.o
 
  obj-y += emac/
 
+obj-$(CONFIG_QCOM_IPQ4019_ESS_EDMA) += ipqess/
+
  obj-$(CONFIG_RMNET) += rmnet/
drivers/net/ethernet/qualcomm/ipqess/Makefile new file +8 -0
new file mode 100644
index 000000000000..4f2db7283ebf
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for the IPQ ESS driver
+#
+
+obj-$(CONFIG_QCOM_IPQ4019_ESS_EDMA) += ipq_ess.o
+
+ipq_ess-objs := ipqess.o ipqess_ethtool.o
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +102 -0
new file mode 100644
index 000000000000..b11f11f23c11
@@ -0,0 +1,1269 @@
+// SPDX-License-Identifier: GPL-2.0 OR ISC
+/* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017 - 2018, John Crispin <[email protected]>
+ * Copyright (c) 2018 - 2019, Christian Lamparter <[email protected]>
+ * Copyright (c) 2020 - 2021, Gabor Juhos <[email protected]>
+ * Copyright (c) 2021 - 2022, Maxime Chevallier <[email protected]>
+ *
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/if_vlan.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/phylink.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/skbuff.h>
+#include <linux/vmalloc.h>
+#include <net/checksum.h>
+#include <net/ip6_checksum.h>
+
+#include "ipqess.h"
+
+#define IPQESS_RRD_SIZE		16
+#define IPQESS_NEXT_IDX(X, Y)  (((X) + 1) & ((Y) - 1))
+#define IPQESS_TX_DMA_BUF_LEN	0x3fff
+
+static void ipqess_w32(struct ipqess *ess, u32 reg, u32 val)
+{
+	writel(val, ess->hw_addr + reg);
+}
+
+static u32 ipqess_r32(struct ipqess *ess, u16 reg)
+{
+	return readl(ess->hw_addr + reg);
+}
+
+static void ipqess_m32(struct ipqess *ess, u32 mask, u32 val, u16 reg)
+{
+	u32 _val = ipqess_r32(ess, reg);
+
+	_val &= ~mask;
+	_val |= val;
+
+	ipqess_w32(ess, reg, _val);
+}
+
+void ipqess_update_hw_stats(struct ipqess *ess)
+{
+	u32 *p;
+	u32 stat;
+	int i;
+
+	lockdep_assert_held(&ess->stats_lock);
+
+	p = (u32 *)&ess->ipqess_stats;
+	for (i = 0; i < IPQESS_MAX_TX_QUEUE; i++) {
+		stat = ipqess_r32(ess, IPQESS_REG_TX_STAT_PKT_Q(i));
+		*p += stat;
+		p++;
+	}
+
+	for (i = 0; i < IPQESS_MAX_TX_QUEUE; i++) {
+		stat = ipqess_r32(ess, IPQESS_REG_TX_STAT_BYTE_Q(i));
+		*p += stat;
+		p++;
+	}
+
+	for (i = 0; i < IPQESS_MAX_RX_QUEUE; i++) {
+		stat = ipqess_r32(ess, IPQESS_REG_RX_STAT_PKT_Q(i));
+		*p += stat;
+		p++;
+	}
+
+	for (i = 0; i < IPQESS_MAX_RX_QUEUE; i++) {
+		stat = ipqess_r32(ess, IPQESS_REG_RX_STAT_BYTE_Q(i));
+		*p += stat;
+		p++;
+	}
+}
+
+static int ipqess_tx_ring_alloc(struct ipqess *ess)
+{
+	struct device *dev = &ess->pdev->dev;
+	int i;
+
+	for (i = 0; i < IPQESS_NETDEV_QUEUES; i++) {
+		struct ipqess_tx_ring *tx_ring = &ess->tx_ring[i];
+		size_t size;
+		u32 idx;
+
+		tx_ring->ess = ess;
+		tx_ring->ring_id = i;
+		tx_ring->idx = i * 4;
+		tx_ring->count = IPQESS_TX_RING_SIZE;
+		tx_ring->nq = netdev_get_tx_queue(ess->netdev, i);
+

drivers/net/ethernet/qualcomm/ipqess/ipqess.c line 112

Quoted 10 lines
drivers/net/ethernet/qualcomm/ipqess/ipqess.c new file +10 -0
+		size = sizeof(struct ipqess_buf) * IPQESS_TX_RING_SIZE;
+		tx_ring->buf = devm_kzalloc(dev, size, GFP_KERNEL);
+		if (!tx_ring->buf) {
+			netdev_err(ess->netdev, "buffer alloc of tx ring failed");
+			return -ENOMEM;
+		}
+
+		size = sizeof(struct ipqess_tx_desc) * IPQESS_TX_RING_SIZE;
+		tx_ring->hw_desc = dmam_alloc_coherent(dev, size, &tx_ring->dma,
+						       GFP_KERNEL | __GFP_ZERO);

Hi,

Nitpicking: I think that __GFP_ZERO is useless (and harmless) because dma_alloc_coherent() always zeroes the memory that is allocated.

CJ

#9 lore raw

PATCH v2 2/5 net: dsa: add out-of-band tagging protocol

In reply to Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

---
V1->V2:
- Reworked the tagging method, putting the tag at skb->head instead of putting it into skb->shinfo, as per Andrew, Florian and Vlad's reviews

 include/linux/dsa/oob.h | 17 +++++++++
 include/net/dsa.h       |  2 +
 net/dsa/Kconfig         |  7 ++++
 net/dsa/Makefile        |  1 +
 net/dsa/tag_oob.c       | 84 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 111 insertions(+)
 create mode 100644 include/linux/dsa/oob.h
 create mode 100644 net/dsa/tag_oob.c
include/linux/dsa/oob.h new file +17 -0
new file mode 100644
index 000000000000..dbb4a6fb1ce4
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ * Copyright (C) 2022 Maxime Chevallier <[email protected]>
+ */
+
+#ifndef _NET_DSA_OOB_H
+#define _NET_DSA_OOB_H
+
+#include <linux/skbuff.h>
+
+struct dsa_oob_tag_info {
+	u16 proto;
+	u16 dp;
+};
+
+int dsa_oob_tag_push(struct sk_buff *skb, struct dsa_oob_tag_info *ti);
+int dsa_oob_tag_pop(struct sk_buff *skb, struct dsa_oob_tag_info *ti);
+#endif
include/net/dsa.h +2 -0
index 14e10cda7267..9951df858912 100644
@@ -53,6 +53,7 @@ struct phylink_link_state;
 #define DSA_TAG_PROTO_SJA1110_VALUE		23
 #define DSA_TAG_PROTO_RTL8_4_VALUE		24
 #define DSA_TAG_PROTO_RTL8_4T_VALUE		25
+#define DSA_TAG_PROTO_OOB_VALUE			26
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -81,6 +82,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_SJA1110		= DSA_TAG_PROTO_SJA1110_VALUE,
 	DSA_TAG_PROTO_RTL8_4		= DSA_TAG_PROTO_RTL8_4_VALUE,
 	DSA_TAG_PROTO_RTL8_4T		= DSA_TAG_PROTO_RTL8_4T_VALUE,
+	DSA_TAG_PROTO_OOB		= DSA_TAG_PROTO_OOB_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +7 -0
index 8cb87b5067ee..b7aa4d8552b2 100644
@@ -57,6 +57,13 @@ config NET_DSA_TAG_HELLCREEK
 	  Say Y or M if you want to enable support for tagging frames
 	  for the Hirschmann Hellcreek TSN switches.
 
+config NET_DSA_TAG_OOB
+	tristate "Tag driver for Out-of-band tagging drivers"
+	help
+	  Say Y or M if you want to enable support for tagging out-of-band. In
+	  that case, the MAC driver becomes responsible for sending the tag to
+	  the switch, outside the inband data.
+
 config NET_DSA_TAG_GSWIP
 	tristate "Tag driver for Lantiq / Intel GSWIP switches"
 	help
net/dsa/Makefile +1 -0
index 9f75820e7c98..b156e20f9c0a 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o
 obj-$(CONFIG_NET_DSA_TAG_DSA_COMMON) += tag_dsa.o
 obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
 obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o
+obj-$(CONFIG_NET_DSA_TAG_OOB) += tag_oob.o
 obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
net/dsa/tag_oob.c new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.36.1
#10 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Hi Maxime,

Quoted 12 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

Quoted 9 lines

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

What I like about your approach is that you have aligned the way an out of band switch tag is communicated to the networking stack the same way that an "in-band" switch tag would be communicated. I think this is a good way forward to provide the out of band tag and I don't think it creates a performance problem because the Ethernet frame is hot in the cache (dma_unmap_single()) and we already have an "expensive" read of the DMA descriptor in coherent memory anyway.

You could possibly optimize the data flow a bit to limit the amount of sk_buff data movement by asking your Ethernet controller to DMA into the data buffer N bytes into the beginning of the data buffer. That way, if you have reserved say, 2 bytes at the front data buffer you can deposit the QCA tag there and you do not need to push, process the tag, then pop it, just process and pop. Consider using the 2byte stuffing that the Ethernet controller might be adding to the beginning of the Ethernet frame to align the IP header on a 4-byte boundary to provide the tag in there?

If we want to have a generic out of band tagger like you propose, it seems to me that we will need to invent a synthetic DSA tagging format which is the largest common denominator of the out of band tags that we want to support. We could imagine being more compact in the representation for instance by using an u8 for storing a bitmask of ports (works for both RX and TX then) and another u8 for various packet forwarding reasons.

Then we would request the various Ethernet MAC drivers to marshall their proprietary tag into the DSA synthetic one on receive, and unmarshall it on transmit.

Another approach IMHO which maybe helps the maintainability of the code moving forward as well as ensuring that all Ethernet switch tagging code lives in one place, is to teach each tagger driver how to optimize their data paths to minimize the amount of data movements and checksum re-calculations, this is what I had in mind a few years ago:

https://lore.kernel.org/lkml/1438322920.20182.144.camel@edumazet-glaptop2.roam.corp.google.com/T/

This might scale a little less well, and maybe this makes too many assumptions as to where and how the checksums are calculated on the packet contents, but at least, you don't have logic processing the same type of switch tag scattered between the Ethernet MAC drivers (beyond copying/pushing) and DSA switch taggers.

I would like to hear other's opinion on this.

Signature · 1 line
Florian
#11 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Hi Florian,

Quoted 45 lines · On Sat, 14 May 2022 09:33:44 -0700 Florian Fainelli <[email protected]>…

Hi Maxime,

Quoted 13 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

Quoted 10 lines

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

What I like about your approach is that you have aligned the way an out of band switch tag is communicated to the networking stack the same way that an "in-band" switch tag would be communicated. I think this is a good way forward to provide the out of band tag and I don't think it creates a performance problem because the Ethernet frame is hot in the cache (dma_unmap_single()) and we already have an "expensive" read of the DMA descriptor in coherent memory anyway.

You could possibly optimize the data flow a bit to limit the amount of sk_buff data movement by asking your Ethernet controller to DMA into the data buffer N bytes into the beginning of the data buffer. That way, if you have reserved say, 2 bytes at the front data buffer you can deposit the QCA tag there and you do not need to push, process the tag, then pop it, just process and pop. Consider using the 2byte stuffing that the Ethernet controller might be adding to the beginning of the Ethernet frame to align the IP header on a 4-byte boundary to provide the tag in there?

Quoted 7 lines

If we want to have a generic out of band tagger like you propose, it seems to me that we will need to invent a synthetic DSA tagging format which is the largest common denominator of the out of band tags that we want to support. We could imagine being more compact in the representation for instance by using an u8 for storing a bitmask of ports (works for both RX and TX then) and another u8 for various packet forwarding reasons.

Thanks, that was my initial idea indeed. Having a generic tagger that can be re-used would be great IMO. I'll modify the format as you propose, and also give a try to you approach of DMA'ing 2 bytes forward so that the tag location is already allocated, that's a nice idea.

Quoted 11 lines

Then we would request the various Ethernet MAC drivers to marshall their proprietary tag into the DSA synthetic one on receive, and unmarshall it on transmit.

Another approach IMHO which maybe helps the maintainability of the code moving forward as well as ensuring that all Ethernet switch tagging code lives in one place, is to teach each tagger driver how to optimize their data paths to minimize the amount of data movements and checksum re-calculations, this is what I had in mind a few years ago:

Quoted 7 lines

https://lore.kernel.org/lkml/1438322920.20182.144.camel@edumazet-glaptop2.roam.corp.google.com/T/

This might scale a little less well, and maybe this makes too many assumptions as to where and how the checksums are calculated on the packet contents, but at least, you don't have logic processing the same type of switch tag scattered between the Ethernet MAC drivers (beyond copying/pushing) and DSA switch taggers.

That would definitely fit well with this tagger, I didn't know about that series !

Thanks for the review,

Maxime

Quoted 1 line

I would like to hear other's opinion on this.

#12 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

In reply to Maxime Chevallier
Quoted 22 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 2 lines

---

Why put the DSA pseudo-header at skb->head rather than push it using skb_push()? I thought you were going to check for the presence of a DSA header using something like skb->mac_len == ETH_HLEN + tag len, but right now it sounds like treating garbage in the headroom as a valid DSA tag is indeed a potential problem. If you can't sort that out using information from the header offsets alone, maybe an skb extension is required?

#13 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Hi Vlad,

Quoted 28 lines · On Sat, 14 May 2022 22:40:03 +0000 Vladimir Oltean <[email protected]>…
Quoted 24 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 2 lines

---

Quoted 7 lines

Why put the DSA pseudo-header at skb->head rather than push it using skb_push()? I thought you were going to check for the presence of a DSA header using something like skb->mac_len == ETH_HLEN + tag len, but right now it sounds like treating garbage in the headroom as a valid DSA tag is indeed a potential problem. If you can't sort that out using information from the header offsets alone, maybe an skb extension is required?

Indeed, I thought of that, the main reason is that pushing/poping in itself is not enough, you also have to move the whole mac_header to leave room for the tag, and then re-set it in it's original location. There's nothing wrong with this, but it looked a bit cumbersome just to insert a dummy tag that gets removed rightaway. Does that make sense ?

But yes I would really like to get a way to know wether the tag is there or not, I'll dig a bit more to see if I can find a way to get this info from the various skb offsets in a reliable way.

Thanks,

Maxime

#14 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Quoted 41 lines · Maxime Chevallier

Hi Vlad,

Quoted 28 lines · On Sat, 14 May 2022 22:40:03 +0000 Vladimir Oltean <[email protected]>…
Quoted 24 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 2 lines

---

Quoted 7 lines

Why put the DSA pseudo-header at skb->head rather than push it using skb_push()? I thought you were going to check for the presence of a DSA header using something like skb->mac_len == ETH_HLEN + tag len, but right now it sounds like treating garbage in the headroom as a valid DSA tag is indeed a potential problem. If you can't sort that out using information from the header offsets alone, maybe an skb extension is required?

Quoted 5 lines

Indeed, I thought of that, the main reason is that pushing/poping in itself is not enough, you also have to move the whole mac_header to leave room for the tag, and then re-set it in it's original location. There's nothing wrong with this, but it looked a bit cumbersome just to insert a dummy tag that gets removed rightaway. Does that make sense ?

You're thinking about inserting a header before the EtherType. But what has been said was to _prepend_ a header, i.e. put it before the Ethernet MAC DA. That way you don't need to move the Ethernet header.

But anyway, too much talk for mostly nothing, see below.

Quoted 3 lines

But yes I would really like to get a way to know wether the tag is there or not, I'll dig a bit more to see if I can find a way to get this info from the various skb offsets in a reliable way.

Without an skb extension, this seems like an impossible task to me (which should also answer Florian's request for feedback on the proposal to share skb->cb with GRO, the qdisc, and whomever else there might be in the path between the DSA master and the switch).

#15 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Quoted 54 lines · Vladimir Oltean
Quoted 41 lines · Maxime Chevallier

Hi Vlad,

Quoted 28 lines · On Sat, 14 May 2022 22:40:03 +0000 Vladimir Oltean <[email protected]>…
Quoted 24 lines · Maxime Chevallier

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 2 lines

---

Quoted 7 lines

Why put the DSA pseudo-header at skb->head rather than push it using skb_push()? I thought you were going to check for the presence of a DSA header using something like skb->mac_len == ETH_HLEN + tag len, but right now it sounds like treating garbage in the headroom as a valid DSA tag is indeed a potential problem. If you can't sort that out using information from the header offsets alone, maybe an skb extension is required?

Quoted 5 lines

Indeed, I thought of that, the main reason is that pushing/poping in itself is not enough, you also have to move the whole mac_header to leave room for the tag, and then re-set it in it's original location. There's nothing wrong with this, but it looked a bit cumbersome just to insert a dummy tag that gets removed rightaway. Does that make sense ?

You're thinking about inserting a header before the EtherType. But what has been said was to _prepend_ a header, i.e. put it before the Ethernet MAC DA. That way you don't need to move the Ethernet header.

But anyway, too much talk for mostly nothing, see below.

Quoted 8 lines
Quoted 3 lines

But yes I would really like to get a way to know wether the tag is there or not, I'll dig a bit more to see if I can find a way to get this info from the various skb offsets in a reliable way.

Without an skb extension, this seems like an impossible task to me (which should also answer Florian's request for feedback on the proposal to share skb->cb with GRO, the qdisc, and whomever else there might be in the path between the DSA master and the switch).

Sorry I should have been clearer, the patch series that I pointed Maxime at earlier:

https://lore.kernel.org/lkml/1438322920.20182.144.camel@edumazet-glaptop2.roam.corp.google.com/T/

was initially accepted only to be reverted later on because on 64-bit host, there was not enough room in skb->cb[] to insert 4 bytes, so it got reverted.

So yes, I think we need to allocate a custom SKB extension if we want to convey the tag, unless we somehow manage to put it in the linear portion of the SKB to avoid using any control buffer or extension.

Signature · 1 line
Florian
#16 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Quoted 2 lines · Florian Fainelli

unless we somehow manage to put it in the linear portion of the SKB to avoid using any control buffer or extension.

But how? Essentially the DSA master has to look at a packet and determine whether it came from DSA based on something which non-DSA code could not have done. In fact, I'm looking at the calls to skb_reset_mac_{header,len} from net/core/skbuff.c, specifically at VLAN and MPLS, and I believe (but haven't tested) that pushing such headers would also alter skb->mac_len to some value != ETH_HLEN. So simply having the DSA master check whether DSA was there by checking whether skb->mac_len is ETH_HLEN + DSA tag len could easily confuse DSA with some other protocol of same header size.

maintainer
#17 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

In reply to Maxime Chevallier
Quoted 22 lines · On Sat, 14 May 2022 17:06:53 +0200 Maxime Chevallier wrote:

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 1 line

This must had been asked on v1 but there's no trace of it in the current submission afaict...

If the tag is passed in the descriptor how is this not a pure switchdev driver? The explanation must be preserved somehow.

#18 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Hello Jakub,

Quoted 25 lines · On Mon, 16 May 2022 12:20:48 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 24 lines · On Sat, 14 May 2022 17:06:53 +0200 Maxime Chevallier wrote:

This tagging protocol is designed for the situation where the link between the MAC and the Switch is designed such that the Destination Port, which is usually embedded in some part of the Ethernet Header, is sent out-of-band, and isn't present at all in the Ethernet frame.

This can happen when the MAC and Switch are tightly integrated on an SoC, as is the case with the Qualcomm IPQ4019 for example, where the DSA tag is inserted directly into the DMA descriptors. In that case, the MAC driver is responsible for sending the tag to the switch using the out-of-band medium. To do so, the MAC driver needs to have the information of the destination port for that skb.

This out-of-band tagging protocol is using the very beggining of the skb headroom to store the tag. The drawback of this approch is that the headroom isn't initialized upon allocating it, therefore we have a chance that the garbage data that lies there at allocation time actually ressembles a valid oob tag. This is only problematic if we are sending/receiving traffic on the master port, which isn't a valid DSA use-case from the beggining. When dealing from traffic to/from a slave port, then the oob tag will be initialized properly by the tagger or the mac driver through the use of the dsa_oob_tag_push() call.

Quoted 4 lines
Quoted 1 line

This must had been asked on v1 but there's no trace of it in the current submission afaict...

No you're correct, this wasn't explained.

Quoted 2 lines

If the tag is passed in the descriptor how is this not a pure switchdev driver? The explanation must be preserved somehow.

The main reason is that although the MAC and switch are rightly coupled on that platform, the switch is actually a QC8K that can live on it's own, as an external switch. Here, it's just a slightly modified version of this IP.

The same goes for the MAC IP, but so far we don't support any other platform that have the MAC as a standalone controller. As far as we can tell, platforms that have this MAC also include a QCA8K, but the datasheet also mentions other modes (like outputing RGMII).

Is this valid to have it as a standalone ethernet driver in that situation ?

Thanks,

Maxime

maintainer
#19 lore raw

Re: [PATCH net-next v2 2/5] net: dsa: add out-of-band tagging protocol

Quoted 13 lines · On Tue, 17 May 2022 08:53:55 +0200 Maxime Chevallier wrote:
Quoted 2 lines

This must had been asked on v1 but there's no trace of it in the current submission afaict...

No you're correct, this wasn't explained.

Quoted 2 lines

If the tag is passed in the descriptor how is this not a pure switchdev driver? The explanation must be preserved somehow.

The main reason is that although the MAC and switch are rightly coupled on that platform, the switch is actually a QC8K that can live on it's own, as an external switch. Here, it's just a slightly modified version of this IP.

Quoted 4 lines

The same goes for the MAC IP, but so far we don't support any other platform that have the MAC as a standalone controller. As far as we can tell, platforms that have this MAC also include a QCA8K, but the datasheet also mentions other modes (like outputing RGMII).

Got it, thanks! Please weave this justification more explicitly into the cover letter.

Quoted 2 lines

Is this valid to have it as a standalone ethernet driver in that situation ?

Quite possibly.. I won't pretend I've looked at the code, I defer to the reviewers :)

#20 lore raw

PATCH v2 3/5 net: ipqess: Add out-of-band DSA tagging support

In reply to Maxime Chevallier

On the IPQ4019, there's an 5 ports switch connected to the CPU through the IPQESS Ethernet controller. The way the DSA tag is sent-out to that switch is through the DMA descriptor, due to how tightly it is integrated with the switch.

This commit uses the out-of-band tagging protocol by getting the source port from the descriptor, push it into the skb, and have the tagger pull it to infer the destination netdev. The reverse process is done on the TX side, where the driver pulls the tag from the skb and builds the descriptor accordingly.

---
V1->V2:
- Use the new tagger, and the dsa_oob_tag_* helpers

 drivers/net/ethernet/qualcomm/Kconfig         |  3 ++-
 drivers/net/ethernet/qualcomm/ipqess/ipqess.c | 27 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/Kconfig +2 -1
index a723ddbea248..eeb2c608d6b9 100644
@@ -62,8 +62,9 @@ config QCOM_EMAC
 
 config QCOM_IPQ4019_ESS_EDMA
 	tristate "Qualcomm Atheros IPQ4019 ESS EDMA support"
-	depends on OF
+	depends on OF && NET_DSA
 	select PHYLINK
+	select NET_DSA_TAG_OOB
 	help
 	  This driver supports the Qualcomm Atheros IPQ40xx built-in
 	  ESS EDMA ethernet controller.
drivers/net/ethernet/qualcomm/ipqess/ipqess.c +27 -0
index b11f11f23c11..a068dff19943 100644
@@ -9,6 +9,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/clk.h>
+#include <linux/dsa/oob.h>
 #include <linux/if_vlan.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
@@ -22,6 +23,7 @@
 #include <linux/skbuff.h>
 #include <linux/vmalloc.h>
 #include <net/checksum.h>
+#include <net/dsa.h>
 #include <net/ip6_checksum.h>
 
 #include "ipqess.h"
@@ -334,6 +336,7 @@ static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int budget)
 	tail &= IPQESS_RFD_CONS_IDX_MASK;
 
 	while (done < budget) {
+		struct dsa_oob_tag_info tag_info;
 		struct ipqess_rx_desc *rd;
 		struct sk_buff *skb;
 
@@ -413,6 +416,12 @@ static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int budget)
 			__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD),
 					       rd->rrd4);
 
+		if (netdev_uses_dsa(rx_ring->ess->netdev)) {
+			tag_info.dp = FIELD_GET(IPQESS_RRD_PORT_ID_MASK, rd->rrd1);
+			tag_info.proto = DSA_TAG_PROTO_OOB;
+			dsa_oob_tag_push(skb, &tag_info);
+		}
+
 		napi_gro_receive(&rx_ring->napi_rx, skb);
 
 		rx_ring->ess->stats.rx_packets++;
@@ -727,6 +736,22 @@ static void ipqess_rollback_tx(struct ipqess *eth,
 	tx_ring->head = start_index;
 }
 
+static void ipqess_process_dsa_tag_sh(struct ipqess *ess, struct sk_buff *skb,
+				      u32 *word3)
+{
+	struct dsa_oob_tag_info tag_info;
+
+	if (!netdev_uses_dsa(ess->netdev))
+		return;
+
+	if (dsa_oob_tag_pop(skb, &tag_info))
+		return;
+
+	*word3 |= tag_info.dp << IPQESS_TPD_PORT_BITMAP_SHIFT;
+	*word3 |= BIT(IPQESS_TPD_FROM_CPU_SHIFT);
+	*word3 |= 0x3e << IPQESS_TPD_PORT_BITMAP_SHIFT;
+}
+
 static int ipqess_tx_map_and_fill(struct ipqess_tx_ring *tx_ring,
 				  struct sk_buff *skb)
 {
@@ -737,6 +762,8 @@ static int ipqess_tx_map_and_fill(struct ipqess_tx_ring *tx_ring,
 	u16 len;
 	int i;
 
+	ipqess_process_dsa_tag_sh(tx_ring->ess, skb, &word3);
+
 	if (skb_is_gso(skb)) {
 		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) {
 			lso_word1 |= IPQESS_TPD_IPV4_EN;
Signature · 1 line
2.36.1
#21 lore raw

PATCH v2 4/5 net: dt-bindings: Introduce the Qualcomm IPQESS Ethernet controller

In reply to Maxime Chevallier

Add the DT binding for the IPQESS Ethernet Controller. This is a simple controller, only requiring the phy-mode, interrupts, clocks, and possibly a MAC address setting.

---
V1->V2:
- Fixed the example
- Added reset and clocks
- Removed generic ethernet attributes

 .../devicetree/bindings/net/qcom,ipqess.yaml  | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom,ipqess.yaml
Documentation/devicetree/bindings/net/qcom,ipqess.yaml new file +104 -0
new file mode 100644
index 000000000000..ea0023509737
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/qcom,ipqess.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm IPQ ESS EDMA Ethernet Controller
+
+maintainers:
+  - Maxime Chevallier <[email protected]>
+
+allOf:
+  - $ref: "ethernet-controller.yaml#"
+
+properties:
+  compatible:
+    const: qcom,ipq4019e-ess-edma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 2
+    maxItems: 32
+    description: One interrupt per tx and rx queue, with up to 16 queues.
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: ess
+
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: ess
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - phy-mode
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,gcc-ipq4019.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    gmac: ethernet@c080000 {
+        compatible = "qcom,ipq4019-ess-edma";
+        reg = <0xc080000 0x8000>;
+        resets = <&gcc ESS_RESET>;
+        reset-names = "ess";
+        clocks = <&gcc GCC_ESS_CLK>;
+        clock-names = "ess";
+        interrupts = <GIC_SPI  65 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  66 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  67 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  68 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  69 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  70 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  71 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  72 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  73 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  74 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  75 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  76 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  77 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  78 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  79 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  80 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 240 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 241 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 242 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 243 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 244 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 245 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 246 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 247 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 248 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 249 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 250 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 251 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 252 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 253 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 254 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 255 IRQ_TYPE_EDGE_RISING>;
+
+        phy-mode = "internal";
+        fixed-link {
+            speed = <1000>;
+            full-duplex;
+            pause;
+            asym-pause;
+        };
+    };
+
+...
Signature · 1 line
2.36.1
maintainer
#22 lore raw

Re: [PATCH net-next v2 4/5] net: dt-bindings: Introduce the Qualcomm IPQESS Ethernet controller

Quoted 42 lines · Maxime Chevallier

Add the DT binding for the IPQESS Ethernet Controller. This is a simple controller, only requiring the phy-mode, interrupts, clocks, and possibly a MAC address setting.

---
V1->V2:
- Fixed the example
- Added reset and clocks
- Removed generic ethernet attributes

 .../devicetree/bindings/net/qcom,ipqess.yaml  | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom,ipqess.yaml
Documentation/devicetree/bindings/net/qcom,ipqess.yaml new file +21 -0
new file mode 100644
index 000000000000..ea0023509737
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/qcom,ipqess.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm IPQ ESS EDMA Ethernet Controller
+
+maintainers:
+  - Maxime Chevallier <[email protected]>
+
+allOf:
+  - $ref: "ethernet-controller.yaml#"
+
+properties:
+  compatible:
+    const: qcom,ipq4019e-ess-edma
+
+  reg:
+    maxItems: 1
+

Documentation/devicetree/bindings/net/qcom,ipqess.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom,ipqess.yaml new file +10 -0
+  interrupts:
+    minItems: 2
+    maxItems: 32
+    description: One interrupt per tx and rx queue, with up to 16 queues.
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: ess

Always kind of pointless to have a single *-names entry when it's just the block name.

Documentation/devicetree/bindings/net/qcom,ipqess.yaml line 37

Quoted 6 lines
Documentation/devicetree/bindings/net/qcom,ipqess.yaml new file +6 -0
+
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: ess

ditto

Quoted 71 lines
Documentation/devicetree/bindings/net/qcom,ipqess.yaml new file +67 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - phy-mode
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,gcc-ipq4019.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    gmac: ethernet@c080000 {
+        compatible = "qcom,ipq4019-ess-edma";
+        reg = <0xc080000 0x8000>;
+        resets = <&gcc ESS_RESET>;
+        reset-names = "ess";
+        clocks = <&gcc GCC_ESS_CLK>;
+        clock-names = "ess";
+        interrupts = <GIC_SPI  65 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  66 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  67 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  68 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  69 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  70 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  71 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  72 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  73 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  74 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  75 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  76 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  77 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  78 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  79 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI  80 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 240 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 241 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 242 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 243 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 244 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 245 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 246 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 247 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 248 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 249 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 250 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 251 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 252 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 253 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 254 IRQ_TYPE_EDGE_RISING>,
+                     <GIC_SPI 255 IRQ_TYPE_EDGE_RISING>;
+
+        phy-mode = "internal";
+        fixed-link {
+            speed = <1000>;
+            full-duplex;
+            pause;
+            asym-pause;
+        };
+    };
+
+...
Signature · 1 line
2.36.1
#23 lore raw

PATCH v2 5/5 ARM: dts: qcom: ipq4019: Add description for the IPQESS Ethernet controller

In reply to Maxime Chevallier

The Qualcomm IPQ4019 includes an internal 5 ports switch, which is connected to the CPU through the internal IPQESS Ethernet controller.

This commit adds support for this internal interface, which is internally connected to a modified version of the QCA8K Ethernet switch.

This Ethernet controller only support a specific internal interface mode for connection to the switch.

---
V1->V2:
- Added clock and resets

 arch/arm/boot/dts/qcom-ipq4019.dtsi | 46 +++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
arch/arm/boot/dts/qcom-ipq4019.dtsi +46 -0
index cac92dde040f..1afabee37fc6 100644
@@ -38,6 +38,7 @@ aliases {
 		spi1 = &blsp1_spi2;
 		i2c0 = &blsp1_i2c3;
 		i2c1 = &blsp1_i2c4;
+		ethernet0 = &gmac;
 	};
 
 	cpus {
@@ -668,6 +669,51 @@ swport5: port@5 { /* MAC5 */
 			};
 		};
 
+		gmac: ethernet@c080000 {
+			compatible = "qcom,ipq4019-ess-edma";
+			reg = <0xc080000 0x8000>;
+			resets = <&gcc ESS_RESET>;
+			reset-names = "ess";
+			clocks = <&gcc GCC_ESS_CLK>;
+			clock-names = "ess";
+			interrupts = <GIC_SPI  65 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  66 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  67 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  68 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  69 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  70 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  71 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  72 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  73 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  74 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  75 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  76 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  77 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  78 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  79 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI  80 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 240 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 241 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 242 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 243 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 244 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 245 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 246 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 247 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 248 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 249 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 250 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 251 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 252 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 253 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 254 IRQ_TYPE_EDGE_RISING>,
+				     <GIC_SPI 255 IRQ_TYPE_EDGE_RISING>;
+
+			status = "disabled";
+
+			phy-mode = "internal";
+		};
+
 		mdio: mdio@90000 {
 			#address-cells = <1>;
 			#size-cells = <0>;
Signature · 1 line
2.36.1