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