Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / ethernet / ti / icssg / icssg_queues.c
blobe5052d9e7807811c5c3a653878cadde196bbf14c
1 // SPDX-License-Identifier: GPL-2.0
2 /* ICSSG Buffer queue helpers
4 * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
5 */
7 #include <linux/regmap.h>
8 #include "icssg_prueth.h"
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
16 int icssg_queue_pop(struct prueth *prueth, u8 queue)
18 u32 val, cnt;
20 if (queue >= ICSSG_QUEUES_MAX)
21 return -EINVAL;
23 regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &cnt);
24 if (!cnt)
25 return -EINVAL;
27 regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, &val);
29 return val;
31 EXPORT_SYMBOL_GPL(icssg_queue_pop);
33 void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
35 if (queue >= ICSSG_QUEUES_MAX)
36 return;
38 regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
40 EXPORT_SYMBOL_GPL(icssg_queue_push);
42 u32 icssg_queue_level(struct prueth *prueth, int queue)
44 u32 reg;
46 if (queue >= ICSSG_QUEUES_MAX)
47 return 0;
49 regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &reg);
51 return reg;