xref: /linux/drivers/net/ethernet/ti/icssg/icssg_queues.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1b8d5008fSMD Danish Anwar // SPDX-License-Identifier: GPL-2.0
2b8d5008fSMD Danish Anwar /* ICSSG Buffer queue helpers
3b8d5008fSMD Danish Anwar  *
4b8d5008fSMD Danish Anwar  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
5b8d5008fSMD Danish Anwar  */
6b8d5008fSMD Danish Anwar 
7b8d5008fSMD Danish Anwar #include <linux/regmap.h>
8b8d5008fSMD Danish Anwar #include "icssg_prueth.h"
9b8d5008fSMD Danish Anwar 
10b8d5008fSMD Danish Anwar #define ICSSG_QUEUES_MAX		64
11b8d5008fSMD Danish Anwar #define ICSSG_QUEUE_OFFSET		0xd00
12b8d5008fSMD Danish Anwar #define ICSSG_QUEUE_PEEK_OFFSET		0xe00
13b8d5008fSMD Danish Anwar #define ICSSG_QUEUE_CNT_OFFSET		0xe40
14b8d5008fSMD Danish Anwar #define	ICSSG_QUEUE_RESET_OFFSET	0xf40
15b8d5008fSMD Danish Anwar 
icssg_queue_pop(struct prueth * prueth,u8 queue)16b8d5008fSMD Danish Anwar int icssg_queue_pop(struct prueth *prueth, u8 queue)
17b8d5008fSMD Danish Anwar {
18b8d5008fSMD Danish Anwar 	u32 val, cnt;
19b8d5008fSMD Danish Anwar 
20b8d5008fSMD Danish Anwar 	if (queue >= ICSSG_QUEUES_MAX)
21b8d5008fSMD Danish Anwar 		return -EINVAL;
22b8d5008fSMD Danish Anwar 
23b8d5008fSMD Danish Anwar 	regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &cnt);
24b8d5008fSMD Danish Anwar 	if (!cnt)
25b8d5008fSMD Danish Anwar 		return -EINVAL;
26b8d5008fSMD Danish Anwar 
27b8d5008fSMD Danish Anwar 	regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, &val);
28b8d5008fSMD Danish Anwar 
29b8d5008fSMD Danish Anwar 	return val;
30b8d5008fSMD Danish Anwar }
31*a8ea8d53SMD Danish Anwar EXPORT_SYMBOL_GPL(icssg_queue_pop);
32b8d5008fSMD Danish Anwar 
icssg_queue_push(struct prueth * prueth,int queue,u16 addr)33b8d5008fSMD Danish Anwar void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
34b8d5008fSMD Danish Anwar {
35b8d5008fSMD Danish Anwar 	if (queue >= ICSSG_QUEUES_MAX)
36b8d5008fSMD Danish Anwar 		return;
37b8d5008fSMD Danish Anwar 
38b8d5008fSMD Danish Anwar 	regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
39b8d5008fSMD Danish Anwar }
40*a8ea8d53SMD Danish Anwar EXPORT_SYMBOL_GPL(icssg_queue_push);
41b8d5008fSMD Danish Anwar 
icssg_queue_level(struct prueth * prueth,int queue)42b8d5008fSMD Danish Anwar u32 icssg_queue_level(struct prueth *prueth, int queue)
43b8d5008fSMD Danish Anwar {
44b8d5008fSMD Danish Anwar 	u32 reg;
45b8d5008fSMD Danish Anwar 
46b8d5008fSMD Danish Anwar 	if (queue >= ICSSG_QUEUES_MAX)
47b8d5008fSMD Danish Anwar 		return 0;
48b8d5008fSMD Danish Anwar 
49b8d5008fSMD Danish Anwar 	regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &reg);
50b8d5008fSMD Danish Anwar 
51b8d5008fSMD Danish Anwar 	return reg;
52b8d5008fSMD Danish Anwar }
53