From aa44ccdc46f3e4972b4e3f98ea1c2cbae4719221 Mon Sep 17 00:00:00 2001
From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: Tue, 18 May 2021 23:37:33 +0300
Subject: [PATCH] net: ethernet: ti: icssg_prueth: add am64x icssg support

Add AM64x ICSSG support which is similar to am65x SR2.0, but required:
- all ring configured in exposed ring mode
- always fill both original and buffer fields in cppi5 desc

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
 .../bindings/net/ti,icssg-prueth.txt          |  1 +
 drivers/net/ethernet/ti/icssg_prueth.c        | 20 ++++++++++++++-----
 drivers/net/ethernet/ti/icssg_prueth.h        |  9 +++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/ti,icssg-prueth.txt b/Documentation/devicetree/bindings/net/ti,icssg-prueth.txt
index 67609e26afa5..125a204ef2d2 100644
--- a/Documentation/devicetree/bindings/net/ti,icssg-prueth.txt
+++ b/Documentation/devicetree/bindings/net/ti,icssg-prueth.txt
@@ -4,6 +4,7 @@ Texas Instruments ICSSG PRUSS Ethernet
 Required properties:
 - compatible       : Should be "ti,am654-icssg-prueth" for AM65x Family SoCs
 		     "ti,am654-icssg-prueth-sr1" for SR1.0
+		     "ti,am642-icssg-prueth" for AM64x
 - ti,prus             : list of pHandles to the PRU, RTU and TX_PRU nodes
 - firmware-name    : should contain the name of the firmware image
 			file located in the firmware search path
diff --git a/drivers/net/ethernet/ti/icssg_prueth.c b/drivers/net/ethernet/ti/icssg_prueth.c
index f18af03964b1..c8cd1bb2c7be 100644
--- a/drivers/net/ethernet/ti/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg_prueth.c
@@ -409,12 +409,11 @@ static int prueth_init_rx_chns(struct prueth_emac *emac,
 	for (i = 0; i < rx_cfg.flow_id_num; i++) {
 		struct k3_ring_cfg rxring_cfg = {
 			.elm_size = K3_RINGACC_RING_ELSIZE_8,
-			.mode = K3_RINGACC_RING_MODE_MESSAGE,
+			.mode = K3_RINGACC_RING_MODE_RING,
 			.flags = 0,
 		};
 		struct k3_ring_cfg fdqring_cfg = {
 			.elm_size = K3_RINGACC_RING_ELSIZE_8,
-			.mode = K3_RINGACC_RING_MODE_MESSAGE,
 			.flags = K3_RINGACC_RING_SHARED,
 		};
 		struct k3_udma_glue_rx_flow_cfg rx_flow_cfg = {
@@ -428,6 +427,7 @@ static int prueth_init_rx_chns(struct prueth_emac *emac,
 		rx_flow_cfg.ring_rxfdq0_id = fdqring_id;
 		rx_flow_cfg.rx_cfg.size = max_desc_num;
 		rx_flow_cfg.rxfdq_cfg.size = max_desc_num;
+		rx_flow_cfg.rxfdq_cfg.mode = emac->prueth->pdata.fdqring_mode;
 
 		ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chn,
 						i, &rx_flow_cfg);
@@ -480,7 +480,7 @@ static int prueth_dma_rx_push(struct prueth_emac *emac,
 
 	cppi5_hdesc_init(desc_rx, CPPI5_INFO0_HDESC_EPIB_PRESENT,
 			 PRUETH_NAV_PS_DATA_SIZE);
-	cppi5_hdesc_attach_buf(desc_rx, 0, 0, buf_dma, skb_tailroom(skb));
+	cppi5_hdesc_attach_buf(desc_rx, buf_dma, skb_tailroom(skb), buf_dma, skb_tailroom(skb));
 
 	swdata = cppi5_hdesc_get_swdata(desc_rx);
 	*swdata = skb;
@@ -2318,6 +2318,7 @@ static int prueth_probe(struct platform_device *pdev)
 
 	dev_set_drvdata(dev, prueth);
 	prueth->pdev = pdev;
+	prueth->pdata = *(const struct prueth_pdata *)match->data;
 
 	if (of_device_is_compatible(np, "ti,am654-icssg-prueth-sr1"))
 		prueth->is_sr1 = true;
@@ -2668,9 +2669,18 @@ static const struct dev_pm_ops prueth_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(prueth_suspend, prueth_resume)
 };
 
+static const struct prueth_pdata am654_icssg_pdata = {
+	.fdqring_mode = K3_RINGACC_RING_MODE_MESSAGE,
+};
+
+static const struct prueth_pdata am64x_icssg_pdata = {
+	.fdqring_mode = K3_RINGACC_RING_MODE_RING,
+};
+
 static const struct of_device_id prueth_dt_match[] = {
-	{ .compatible = "ti,am654-icssg-prueth-sr1", },
-	{ .compatible = "ti,am654-icssg-prueth", },
+	{ .compatible = "ti,am654-icssg-prueth-sr1", .data = &am654_icssg_pdata },
+	{ .compatible = "ti,am654-icssg-prueth", .data = &am654_icssg_pdata },
+	{ .compatible = "ti,am642-icssg-prueth", .data = &am64x_icssg_pdata },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, prueth_dt_match);
diff --git a/drivers/net/ethernet/ti/icssg_prueth.h b/drivers/net/ethernet/ti/icssg_prueth.h
index 156716bf0a76..b536ac5ec0bf 100644
--- a/drivers/net/ethernet/ti/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg_prueth.h
@@ -170,6 +170,14 @@ struct prueth_emac {
 	struct pruss_mem_region dram;
 };
 
+/**
+ * struct prueth - PRUeth platform data
+ * @fdqring_mode: Free desc queue mode
+ */
+struct prueth_pdata {
+	enum k3_ring_mode fdqring_mode;
+};
+
 /**
  * struct prueth - PRUeth structure
  * @is_sr1: device is pg1.0 (pg1.0 will be deprecated upstream)
@@ -214,6 +222,7 @@ struct prueth {
 	struct icss_iep *iep0;
 	struct icss_iep *iep1;
 	int iep_initialized;
+	struct prueth_pdata pdata;
 };
 
 struct emac_tx_ts_response_sr1 {
