summaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/ti/icssg/icssg_queues.c
blob: 3c34f61ad40b0e3e881b5d62e1e4fd305c108e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}