1*06e9bfc1SLukas Bulwahn /* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */
2fbfb8031SShannon Nelson /* Copyright (c) 2018-2019 Pensando Systems, Inc. All rights reserved. */
3fbfb8031SShannon Nelson
4fbfb8031SShannon Nelson #ifndef IONIC_REGS_H
5fbfb8031SShannon Nelson #define IONIC_REGS_H
6fbfb8031SShannon Nelson
7fbfb8031SShannon Nelson #include <linux/io.h>
8fbfb8031SShannon Nelson
9fbfb8031SShannon Nelson /** struct ionic_intr - interrupt control register set.
10fbfb8031SShannon Nelson * @coal_init: coalesce timer initial value.
11fbfb8031SShannon Nelson * @mask: interrupt mask value.
12fbfb8031SShannon Nelson * @credits: interrupt credit count and return.
13fbfb8031SShannon Nelson * @mask_assert: interrupt mask value on assert.
14fbfb8031SShannon Nelson * @coal: coalesce timer time remaining.
15fbfb8031SShannon Nelson */
16fbfb8031SShannon Nelson struct ionic_intr {
17fbfb8031SShannon Nelson u32 coal_init;
18fbfb8031SShannon Nelson u32 mask;
19fbfb8031SShannon Nelson u32 credits;
20fbfb8031SShannon Nelson u32 mask_assert;
21fbfb8031SShannon Nelson u32 coal;
22fbfb8031SShannon Nelson u32 rsvd[3];
23fbfb8031SShannon Nelson };
24fbfb8031SShannon Nelson
256461b446SShannon Nelson #define IONIC_INTR_CTRL_REGS_MAX 2048
266461b446SShannon Nelson #define IONIC_INTR_CTRL_COAL_MAX 0x3F
276461b446SShannon Nelson
28fbfb8031SShannon Nelson /** enum ionic_intr_mask_vals - valid values for mask and mask_assert.
29fbfb8031SShannon Nelson * @IONIC_INTR_MASK_CLEAR: unmask interrupt.
30fbfb8031SShannon Nelson * @IONIC_INTR_MASK_SET: mask interrupt.
31fbfb8031SShannon Nelson */
32fbfb8031SShannon Nelson enum ionic_intr_mask_vals {
33fbfb8031SShannon Nelson IONIC_INTR_MASK_CLEAR = 0,
34fbfb8031SShannon Nelson IONIC_INTR_MASK_SET = 1,
35fbfb8031SShannon Nelson };
36fbfb8031SShannon Nelson
37fbfb8031SShannon Nelson /** enum ionic_intr_credits_bits - bitwise composition of credits values.
38fbfb8031SShannon Nelson * @IONIC_INTR_CRED_COUNT: bit mask of credit count, no shift needed.
39fbfb8031SShannon Nelson * @IONIC_INTR_CRED_COUNT_SIGNED: bit mask of credit count, including sign bit.
40fbfb8031SShannon Nelson * @IONIC_INTR_CRED_UNMASK: unmask the interrupt.
41fbfb8031SShannon Nelson * @IONIC_INTR_CRED_RESET_COALESCE: reset the coalesce timer.
42fbfb8031SShannon Nelson * @IONIC_INTR_CRED_REARM: unmask the and reset the timer.
43fbfb8031SShannon Nelson */
44fbfb8031SShannon Nelson enum ionic_intr_credits_bits {
45fbfb8031SShannon Nelson IONIC_INTR_CRED_COUNT = 0x7fffu,
46fbfb8031SShannon Nelson IONIC_INTR_CRED_COUNT_SIGNED = 0xffffu,
47fbfb8031SShannon Nelson IONIC_INTR_CRED_UNMASK = 0x10000u,
48fbfb8031SShannon Nelson IONIC_INTR_CRED_RESET_COALESCE = 0x20000u,
49fbfb8031SShannon Nelson IONIC_INTR_CRED_REARM = (IONIC_INTR_CRED_UNMASK |
50fbfb8031SShannon Nelson IONIC_INTR_CRED_RESET_COALESCE),
51fbfb8031SShannon Nelson };
52fbfb8031SShannon Nelson
ionic_intr_coal_init(struct ionic_intr __iomem * intr_ctrl,int intr_idx,u32 coal)53fbfb8031SShannon Nelson static inline void ionic_intr_coal_init(struct ionic_intr __iomem *intr_ctrl,
54fbfb8031SShannon Nelson int intr_idx, u32 coal)
55fbfb8031SShannon Nelson {
56fbfb8031SShannon Nelson iowrite32(coal, &intr_ctrl[intr_idx].coal_init);
57fbfb8031SShannon Nelson }
58fbfb8031SShannon Nelson
ionic_intr_mask(struct ionic_intr __iomem * intr_ctrl,int intr_idx,u32 mask)59fbfb8031SShannon Nelson static inline void ionic_intr_mask(struct ionic_intr __iomem *intr_ctrl,
60fbfb8031SShannon Nelson int intr_idx, u32 mask)
61fbfb8031SShannon Nelson {
62fbfb8031SShannon Nelson iowrite32(mask, &intr_ctrl[intr_idx].mask);
63fbfb8031SShannon Nelson }
64fbfb8031SShannon Nelson
ionic_intr_credits(struct ionic_intr __iomem * intr_ctrl,int intr_idx,u32 cred,u32 flags)65fbfb8031SShannon Nelson static inline void ionic_intr_credits(struct ionic_intr __iomem *intr_ctrl,
66fbfb8031SShannon Nelson int intr_idx, u32 cred, u32 flags)
67fbfb8031SShannon Nelson {
68fbfb8031SShannon Nelson if (WARN_ON_ONCE(cred > IONIC_INTR_CRED_COUNT)) {
69fbfb8031SShannon Nelson cred = ioread32(&intr_ctrl[intr_idx].credits);
70fbfb8031SShannon Nelson cred &= IONIC_INTR_CRED_COUNT_SIGNED;
71fbfb8031SShannon Nelson }
72fbfb8031SShannon Nelson
73fbfb8031SShannon Nelson iowrite32(cred | flags, &intr_ctrl[intr_idx].credits);
74fbfb8031SShannon Nelson }
75fbfb8031SShannon Nelson
ionic_intr_clean(struct ionic_intr __iomem * intr_ctrl,int intr_idx)76fbfb8031SShannon Nelson static inline void ionic_intr_clean(struct ionic_intr __iomem *intr_ctrl,
77fbfb8031SShannon Nelson int intr_idx)
78fbfb8031SShannon Nelson {
79fbfb8031SShannon Nelson u32 cred;
80fbfb8031SShannon Nelson
81fbfb8031SShannon Nelson cred = ioread32(&intr_ctrl[intr_idx].credits);
82fbfb8031SShannon Nelson cred &= IONIC_INTR_CRED_COUNT_SIGNED;
83fbfb8031SShannon Nelson cred |= IONIC_INTR_CRED_RESET_COALESCE;
84fbfb8031SShannon Nelson iowrite32(cred, &intr_ctrl[intr_idx].credits);
85fbfb8031SShannon Nelson }
86fbfb8031SShannon Nelson
ionic_intr_mask_assert(struct ionic_intr __iomem * intr_ctrl,int intr_idx,u32 mask)87fbfb8031SShannon Nelson static inline void ionic_intr_mask_assert(struct ionic_intr __iomem *intr_ctrl,
88fbfb8031SShannon Nelson int intr_idx, u32 mask)
89fbfb8031SShannon Nelson {
90fbfb8031SShannon Nelson iowrite32(mask, &intr_ctrl[intr_idx].mask_assert);
91fbfb8031SShannon Nelson }
92fbfb8031SShannon Nelson
93fbfb8031SShannon Nelson /** enum ionic_dbell_bits - bitwise composition of dbell values.
94fbfb8031SShannon Nelson *
95fbfb8031SShannon Nelson * @IONIC_DBELL_QID_MASK: unshifted mask of valid queue id bits.
96fbfb8031SShannon Nelson * @IONIC_DBELL_QID_SHIFT: queue id shift amount in dbell value.
97fbfb8031SShannon Nelson * @IONIC_DBELL_QID: macro to build QID component of dbell value.
98fbfb8031SShannon Nelson *
99fbfb8031SShannon Nelson * @IONIC_DBELL_RING_MASK: unshifted mask of valid ring bits.
100fbfb8031SShannon Nelson * @IONIC_DBELL_RING_SHIFT: ring shift amount in dbell value.
101fbfb8031SShannon Nelson * @IONIC_DBELL_RING: macro to build ring component of dbell value.
102fbfb8031SShannon Nelson *
103fbfb8031SShannon Nelson * @IONIC_DBELL_RING_0: ring zero dbell component value.
104fbfb8031SShannon Nelson * @IONIC_DBELL_RING_1: ring one dbell component value.
105fbfb8031SShannon Nelson * @IONIC_DBELL_RING_2: ring two dbell component value.
106fbfb8031SShannon Nelson * @IONIC_DBELL_RING_3: ring three dbell component value.
107fbfb8031SShannon Nelson *
108fbfb8031SShannon Nelson * @IONIC_DBELL_INDEX_MASK: bit mask of valid index bits, no shift needed.
109fbfb8031SShannon Nelson */
110fbfb8031SShannon Nelson enum ionic_dbell_bits {
111fbfb8031SShannon Nelson IONIC_DBELL_QID_MASK = 0xffffff,
112fbfb8031SShannon Nelson IONIC_DBELL_QID_SHIFT = 24,
113fbfb8031SShannon Nelson
114fbfb8031SShannon Nelson #define IONIC_DBELL_QID(n) \
115fbfb8031SShannon Nelson (((u64)(n) & IONIC_DBELL_QID_MASK) << IONIC_DBELL_QID_SHIFT)
116fbfb8031SShannon Nelson
117fbfb8031SShannon Nelson IONIC_DBELL_RING_MASK = 0x7,
118fbfb8031SShannon Nelson IONIC_DBELL_RING_SHIFT = 16,
119fbfb8031SShannon Nelson
120fbfb8031SShannon Nelson #define IONIC_DBELL_RING(n) \
121fbfb8031SShannon Nelson (((u64)(n) & IONIC_DBELL_RING_MASK) << IONIC_DBELL_RING_SHIFT)
122fbfb8031SShannon Nelson
123fbfb8031SShannon Nelson IONIC_DBELL_RING_0 = 0,
124fbfb8031SShannon Nelson IONIC_DBELL_RING_1 = IONIC_DBELL_RING(1),
125fbfb8031SShannon Nelson IONIC_DBELL_RING_2 = IONIC_DBELL_RING(2),
126fbfb8031SShannon Nelson IONIC_DBELL_RING_3 = IONIC_DBELL_RING(3),
127fbfb8031SShannon Nelson
128fbfb8031SShannon Nelson IONIC_DBELL_INDEX_MASK = 0xffff,
129fbfb8031SShannon Nelson };
130fbfb8031SShannon Nelson
ionic_dbell_ring(u64 __iomem * db_page,int qtype,u64 val)131fbfb8031SShannon Nelson static inline void ionic_dbell_ring(u64 __iomem *db_page, int qtype, u64 val)
132fbfb8031SShannon Nelson {
133fbfb8031SShannon Nelson writeq(val, &db_page[qtype]);
134fbfb8031SShannon Nelson }
135fbfb8031SShannon Nelson
136fbfb8031SShannon Nelson #endif /* IONIC_REGS_H */
137