net: ti: icssg-prueth: Add icssg queues APIs and macros
authorMD Danish Anwar <danishanwar@ti.com>
Tue, 1 Aug 2023 09:14:22 +0000 (14:44 +0530)
committerDavid S. Miller <davem@davemloft.net>
Wed, 2 Aug 2023 09:38:11 +0000 (10:38 +0100)
Add icssg_queue.c file. This file introduces macros and APIs related to
ICSSG queues. These will be used by ICSSG Ethernet driver.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/icssg/icssg_prueth.h
drivers/net/ethernet/ti/icssg/icssg_queues.c [new file with mode: 0644]

index e93488a79dbff093ba1d51d45b0b64ddf79acdca..42fdf4005010a87a5ddb727f2c1fbbdca1989b60 100644 (file)
@@ -209,4 +209,9 @@ int emac_set_port_state(struct prueth_emac *emac,
                        enum icssg_port_state_cmd state);
 void icssg_config_set_speed(struct prueth_emac *emac);
 
+/* Buffer queue helpers */
+int icssg_queue_pop(struct prueth *prueth, u8 queue);
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr);
+u32 icssg_queue_level(struct prueth *prueth, int queue);
+
 #endif /* __NET_TI_ICSSG_PRUETH_H */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_queues.c b/drivers/net/ethernet/ti/icssg/icssg_queues.c
new file mode 100644 (file)
index 0000000..3c34f61
--- /dev/null
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+/* ICSSG Buffer queue helpers
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include <linux/regmap.h>
+#include "icssg_prueth.h"
+
+#define ICSSG_QUEUES_MAX               64
+#define ICSSG_QUEUE_OFFSET             0xd00
+#define ICSSG_QUEUE_PEEK_OFFSET                0xe00
+#define ICSSG_QUEUE_CNT_OFFSET         0xe40
+#define        ICSSG_QUEUE_RESET_OFFSET        0xf40
+
+int icssg_queue_pop(struct prueth *prueth, u8 queue)
+{
+       u32 val, cnt;
+
+       if (queue >= ICSSG_QUEUES_MAX)
+               return -EINVAL;
+
+       regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &cnt);
+       if (!cnt)
+               return -EINVAL;
+
+       regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, &val);
+
+       return val;
+}
+
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
+{
+       if (queue >= ICSSG_QUEUES_MAX)
+               return;
+
+       regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
+}
+
+u32 icssg_queue_level(struct prueth *prueth, int queue)
+{
+       u32 reg;
+
+       if (queue >= ICSSG_QUEUES_MAX)
+               return 0;
+
+       regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &reg);
+
+       return reg;
+}