event/dlb2: add v2.5 domain reset
[dpdk.git] / drivers / event / dlb2 / pf / base / dlb2_hw_types.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4
5 #ifndef __DLB2_HW_TYPES_H
6 #define __DLB2_HW_TYPES_H
7
8 #include "../../dlb2_priv.h"
9 #include "dlb2_user.h"
10
11 #include "dlb2_osdep_list.h"
12 #include "dlb2_osdep_types.h"
13
14 #define DLB2_MAX_NUM_VDEVS                      16
15 #define DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS     2
16 #define DLB2_NUM_ARB_WEIGHTS                    8
17 #define DLB2_MAX_NUM_AQED_ENTRIES               2048
18 #define DLB2_MAX_WEIGHT                         255
19 #define DLB2_NUM_COS_DOMAINS                    4
20 #define DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS     2
21 #define DLB2_MAX_NUM_SEQUENCE_NUMBER_MODES      5
22 #define DLB2_MAX_CQ_COMP_CHECK_LOOPS            409600
23 #define DLB2_MAX_QID_EMPTY_CHECK_LOOPS          (32 * 64 * 1024 * (800 / 30))
24
25 #define DLB2_FUNC_BAR                           0
26 #define DLB2_CSR_BAR                            2
27
28 #define PCI_DEVICE_ID_INTEL_DLB2_PF 0x2710
29 #define PCI_DEVICE_ID_INTEL_DLB2_VF 0x2711
30
31 #define PCI_DEVICE_ID_INTEL_DLB2_5_PF 0x2714
32 #define PCI_DEVICE_ID_INTEL_DLB2_5_VF 0x2715
33
34 #define DLB2_ALARM_HW_SOURCE_SYS 0
35 #define DLB2_ALARM_HW_SOURCE_DLB 1
36
37 #define DLB2_ALARM_HW_UNIT_CHP 4
38
39 #define DLB2_ALARM_SYS_AID_ILLEGAL_QID          3
40 #define DLB2_ALARM_SYS_AID_DISABLED_QID         4
41 #define DLB2_ALARM_SYS_AID_ILLEGAL_HCW          5
42 #define DLB2_ALARM_HW_CHP_AID_ILLEGAL_ENQ       1
43 #define DLB2_ALARM_HW_CHP_AID_EXCESS_TOKEN_POPS 2
44
45 /*
46  * Hardware-defined base addresses. Those prefixed 'DLB2_DRV' are only used by
47  * the PF driver.
48  */
49 #define DLB2_DRV_LDB_PP_BASE   0x2300000
50 #define DLB2_DRV_LDB_PP_STRIDE 0x1000
51 #define DLB2_DRV_LDB_PP_BOUND  (DLB2_DRV_LDB_PP_BASE + \
52                                 DLB2_DRV_LDB_PP_STRIDE * DLB2_MAX_NUM_LDB_PORTS)
53 #define DLB2_DRV_DIR_PP_BASE   0x2200000
54 #define DLB2_DRV_DIR_PP_STRIDE 0x1000
55 #define DLB2_DRV_DIR_PP_BOUND  (DLB2_DRV_DIR_PP_BASE + \
56                                 DLB2_DRV_DIR_PP_STRIDE * DLB2_MAX_NUM_DIR_PORTS)
57 #define DLB2_LDB_PP_BASE       0x2100000
58 #define DLB2_LDB_PP_STRIDE     0x1000
59 #define DLB2_LDB_PP_BOUND      (DLB2_LDB_PP_BASE + \
60                                 DLB2_LDB_PP_STRIDE * DLB2_MAX_NUM_LDB_PORTS)
61 #define DLB2_LDB_PP_OFFS(id)   (DLB2_LDB_PP_BASE + (id) * DLB2_PP_SIZE)
62 #define DLB2_DIR_PP_BASE       0x2000000
63 #define DLB2_DIR_PP_STRIDE     0x1000
64 #define DLB2_DIR_PP_BOUND      (DLB2_DIR_PP_BASE + \
65                                 DLB2_DIR_PP_STRIDE * \
66                                 DLB2_MAX_NUM_DIR_PORTS_V2_5)
67 #define DLB2_DIR_PP_OFFS(id)   (DLB2_DIR_PP_BASE + (id) * DLB2_PP_SIZE)
68
69 struct dlb2_resource_id {
70         u32 phys_id;
71         u32 virt_id;
72         u8 vdev_owned;
73         u8 vdev_id;
74 };
75
76 struct dlb2_freelist {
77         u32 base;
78         u32 bound;
79         u32 offset;
80 };
81
82 static inline u32 dlb2_freelist_count(struct dlb2_freelist *list)
83 {
84         return list->bound - list->base - list->offset;
85 }
86
87 struct dlb2_hcw {
88         u64 data;
89         /* Word 3 */
90         u16 opaque;
91         u8 qid;
92         u8 sched_type:2;
93         u8 priority:3;
94         u8 msg_type:3;
95         /* Word 4 */
96         u16 lock_id;
97         u8 ts_flag:1;
98         u8 rsvd1:2;
99         u8 no_dec:1;
100         u8 cmp_id:4;
101         u8 cq_token:1;
102         u8 qe_comp:1;
103         u8 qe_frag:1;
104         u8 qe_valid:1;
105         u8 int_arm:1;
106         u8 error:1;
107         u8 rsvd:2;
108 };
109
110 struct dlb2_ldb_queue {
111         struct dlb2_list_entry domain_list;
112         struct dlb2_list_entry func_list;
113         struct dlb2_resource_id id;
114         struct dlb2_resource_id domain_id;
115         u32 num_qid_inflights;
116         u32 aqed_limit;
117         u32 sn_group; /* sn == sequence number */
118         u32 sn_slot;
119         u32 num_mappings;
120         u8 sn_cfg_valid;
121         u8 num_pending_additions;
122         u8 owned;
123         u8 configured;
124 };
125
126 /*
127  * Directed ports and queues are paired by nature, so the driver tracks them
128  * with a single data structure.
129  */
130 struct dlb2_dir_pq_pair {
131         struct dlb2_list_entry domain_list;
132         struct dlb2_list_entry func_list;
133         struct dlb2_resource_id id;
134         struct dlb2_resource_id domain_id;
135         u32 ref_cnt;
136         u8 init_tkn_cnt;
137         u8 queue_configured;
138         u8 port_configured;
139         u8 owned;
140         u8 enabled;
141 };
142
143 enum dlb2_qid_map_state {
144         /* The slot doesn't contain a valid queue mapping */
145         DLB2_QUEUE_UNMAPPED,
146         /* The slot contains a valid queue mapping */
147         DLB2_QUEUE_MAPPED,
148         /* The driver is mapping a queue into this slot */
149         DLB2_QUEUE_MAP_IN_PROG,
150         /* The driver is unmapping a queue from this slot */
151         DLB2_QUEUE_UNMAP_IN_PROG,
152         /*
153          * The driver is unmapping a queue from this slot, and once complete
154          * will replace it with another mapping.
155          */
156         DLB2_QUEUE_UNMAP_IN_PROG_PENDING_MAP,
157 };
158
159 struct dlb2_ldb_port_qid_map {
160         enum dlb2_qid_map_state state;
161         u16 qid;
162         u16 pending_qid;
163         u8 priority;
164         u8 pending_priority;
165 };
166
167 struct dlb2_ldb_port {
168         struct dlb2_list_entry domain_list;
169         struct dlb2_list_entry func_list;
170         struct dlb2_resource_id id;
171         struct dlb2_resource_id domain_id;
172         /* The qid_map represents the hardware QID mapping state. */
173         struct dlb2_ldb_port_qid_map qid_map[DLB2_MAX_NUM_QIDS_PER_LDB_CQ];
174         u32 hist_list_entry_base;
175         u32 hist_list_entry_limit;
176         u32 ref_cnt;
177         u8 init_tkn_cnt;
178         u8 num_pending_removals;
179         u8 num_mappings;
180         u8 owned;
181         u8 enabled;
182         u8 configured;
183 };
184
185 struct dlb2_sn_group {
186         u32 mode;
187         u32 sequence_numbers_per_queue;
188         u32 slot_use_bitmap;
189         u32 id;
190 };
191
192 static inline bool dlb2_sn_group_full(struct dlb2_sn_group *group)
193 {
194         const u32 mask[] = {
195                 0x0000ffff,  /* 64 SNs per queue */
196                 0x000000ff,  /* 128 SNs per queue */
197                 0x0000000f,  /* 256 SNs per queue */
198                 0x00000003,  /* 512 SNs per queue */
199                 0x00000001}; /* 1024 SNs per queue */
200
201         return group->slot_use_bitmap == mask[group->mode];
202 }
203
204 static inline int dlb2_sn_group_alloc_slot(struct dlb2_sn_group *group)
205 {
206         const u32 bound[] = {16, 8, 4, 2, 1};
207         u32 i;
208
209         for (i = 0; i < bound[group->mode]; i++) {
210                 if (!(group->slot_use_bitmap & (1 << i))) {
211                         group->slot_use_bitmap |= 1 << i;
212                         return i;
213                 }
214         }
215
216         return -1;
217 }
218
219 static inline void
220 dlb2_sn_group_free_slot(struct dlb2_sn_group *group, int slot)
221 {
222         group->slot_use_bitmap &= ~(1 << slot);
223 }
224
225 static inline int dlb2_sn_group_used_slots(struct dlb2_sn_group *group)
226 {
227         int i, cnt = 0;
228
229         for (i = 0; i < 32; i++)
230                 cnt += !!(group->slot_use_bitmap & (1 << i));
231
232         return cnt;
233 }
234
235 struct dlb2_hw_domain {
236         struct dlb2_function_resources *parent_func;
237         struct dlb2_list_entry func_list;
238         struct dlb2_list_head used_ldb_queues;
239         struct dlb2_list_head used_ldb_ports[DLB2_NUM_COS_DOMAINS];
240         struct dlb2_list_head used_dir_pq_pairs;
241         struct dlb2_list_head avail_ldb_queues;
242         struct dlb2_list_head avail_ldb_ports[DLB2_NUM_COS_DOMAINS];
243         struct dlb2_list_head avail_dir_pq_pairs;
244         u32 total_hist_list_entries;
245         u32 avail_hist_list_entries;
246         u32 hist_list_entry_base;
247         u32 hist_list_entry_offset;
248         u32 num_ldb_credits;
249         u32 num_dir_credits;
250         u32 num_avail_aqed_entries;
251         u32 num_used_aqed_entries;
252         struct dlb2_resource_id id;
253         int num_pending_removals;
254         int num_pending_additions;
255         u8 configured;
256         u8 started;
257 };
258
259 struct dlb2_bitmap;
260
261 struct dlb2_function_resources {
262         struct dlb2_list_head avail_domains;
263         struct dlb2_list_head used_domains;
264         struct dlb2_list_head avail_ldb_queues;
265         struct dlb2_list_head avail_ldb_ports[DLB2_NUM_COS_DOMAINS];
266         struct dlb2_list_head avail_dir_pq_pairs;
267         struct dlb2_bitmap *avail_hist_list_entries;
268         u32 num_avail_domains;
269         u32 num_avail_ldb_queues;
270         u32 num_avail_ldb_ports[DLB2_NUM_COS_DOMAINS];
271         u32 num_avail_dir_pq_pairs;
272         u32 num_avail_qed_entries;
273         u32 num_avail_dqed_entries;
274         u32 num_avail_aqed_entries;
275         u8 locked; /* (VDEV only) */
276 };
277
278 /*
279  * After initialization, each resource in dlb2_hw_resources is located in one
280  * of the following lists:
281  * -- The PF's available resources list. These are unconfigured resources owned
282  *      by the PF and not allocated to a dlb2 scheduling domain.
283  * -- A VDEV's available resources list. These are VDEV-owned unconfigured
284  *      resources not allocated to a dlb2 scheduling domain.
285  * -- A domain's available resources list. These are domain-owned unconfigured
286  *      resources.
287  * -- A domain's used resources list. These are domain-owned configured
288  *      resources.
289  *
290  * A resource moves to a new list when a VDEV or domain is created or destroyed,
291  * or when the resource is configured.
292  */
293 struct dlb2_hw_resources {
294         struct dlb2_ldb_queue ldb_queues[DLB2_MAX_NUM_LDB_QUEUES];
295         struct dlb2_ldb_port ldb_ports[DLB2_MAX_NUM_LDB_PORTS];
296         struct dlb2_dir_pq_pair dir_pq_pairs[DLB2_MAX_NUM_DIR_PORTS_V2_5];
297         struct dlb2_sn_group sn_groups[DLB2_MAX_NUM_SEQUENCE_NUMBER_GROUPS];
298 };
299
300 struct dlb2_mbox {
301         u32 *mbox;
302         u32 *isr_in_progress;
303 };
304
305 struct dlb2_sw_mbox {
306         struct dlb2_mbox vdev_to_pf;
307         struct dlb2_mbox pf_to_vdev;
308         void (*pf_to_vdev_inject)(void *arg);
309         void *pf_to_vdev_inject_arg;
310 };
311
312 struct dlb2_hw {
313         uint8_t ver;
314
315         /* BAR 0 address */
316         void *csr_kva;
317         unsigned long csr_phys_addr;
318         /* BAR 2 address */
319         void *func_kva;
320         unsigned long func_phys_addr;
321
322         /* Resource tracking */
323         struct dlb2_hw_resources rsrcs;
324         struct dlb2_function_resources pf;
325         struct dlb2_function_resources vdev[DLB2_MAX_NUM_VDEVS];
326         struct dlb2_hw_domain domains[DLB2_MAX_NUM_DOMAINS];
327         u8 cos_reservation[DLB2_NUM_COS_DOMAINS];
328
329         /* Virtualization */
330         int virt_mode;
331         struct dlb2_sw_mbox mbox[DLB2_MAX_NUM_VDEVS];
332         unsigned int pasid[DLB2_MAX_NUM_VDEVS];
333 };
334
335 #endif /* __DLB2_HW_TYPES_H */