1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
3 #ifndef _IDXD_REGISTERS_H_
4 #define _IDXD_REGISTERS_H_
6 #include <uapi/linux/idxd.h>
9 #define PCI_DEVICE_ID_INTEL_DSA_GNRD 0x11fb
10 #define PCI_DEVICE_ID_INTEL_DSA_DMR 0x1212
11 #define PCI_DEVICE_ID_INTEL_IAA_DMR 0x1216
13 #define DEVICE_VERSION_1 0x100
14 #define DEVICE_VERSION_2 0x200
16 #define IDXD_MMIO_BAR 0
18 #define IDXD_PORTAL_SIZE PAGE_SIZE
20 /* MMIO Device BAR0 Registers */
21 #define IDXD_VER_OFFSET 0x00
22 #define IDXD_VER_MAJOR_MASK 0xf0
23 #define IDXD_VER_MINOR_MASK 0x0f
24 #define GET_IDXD_VER_MAJOR(x) (((x) & IDXD_VER_MAJOR_MASK) >> 4)
25 #define GET_IDXD_VER_MINOR(x) ((x) & IDXD_VER_MINOR_MASK)
31 u64 cache_control_mem
:1;
32 u64 cache_control_cache
:1;
39 u64 batch_continuation
:1;
41 u64 max_batch_shift
:4;
48 #define IDXD_GENCAP_OFFSET 0x10
68 #define IDXD_WQCAP_OFFSET 0x20
69 #define IDXD_WQCFG_MIN 5
74 u64 total_rdbufs
:8; /* formerly total_tokens */
75 u64 rdbuf_ctrl
:1; /* formerly token_en */
76 u64 rdbuf_limit
:1; /* formerly token_limit */
77 u64 progress_limit
:1; /* descriptor and batch descriptor */
82 #define IDXD_GRPCAP_OFFSET 0x30
84 union engine_cap_reg
{
92 #define IDXD_ENGCAP_OFFSET 0x38
94 #define IDXD_OPCAP_NOOP 0x0001
95 #define IDXD_OPCAP_BATCH 0x0002
96 #define IDXD_OPCAP_MEMMOVE 0x0008
101 #define IDXD_MAX_OPCAP_BITS 256U
103 #define IDXD_OPCAP_OFFSET 0x40
105 #define IDXD_TABLE_OFFSET 0x60
118 #define IDXD_TABLE_MULT 0x100
120 #define IDXD_GENCFG_OFFSET 0x80
132 #define IDXD_GENCTRL_OFFSET 0x88
135 u32 softerr_int_en
:1;
143 #define IDXD_GENSTATS_OFFSET 0x90
153 enum idxd_device_status_state
{
154 IDXD_DEVICE_STATE_DISABLED
= 0,
155 IDXD_DEVICE_STATE_ENABLED
,
156 IDXD_DEVICE_STATE_DRAIN
,
157 IDXD_DEVICE_STATE_HALT
,
160 enum idxd_device_reset_type
{
161 IDXD_DEVICE_RESET_SOFTWARE
= 0,
162 IDXD_DEVICE_RESET_FLR
,
163 IDXD_DEVICE_RESET_WARM
,
164 IDXD_DEVICE_RESET_COLD
,
167 #define IDXD_INTCAUSE_OFFSET 0x98
168 #define IDXD_INTC_ERR 0x01
169 #define IDXD_INTC_CMD 0x02
170 #define IDXD_INTC_OCCUPY 0x04
171 #define IDXD_INTC_PERFMON_OVFL 0x08
172 #define IDXD_INTC_HALT_STATE 0x10
173 #define IDXD_INTC_EVL 0x20
174 #define IDXD_INTC_INT_HANDLE_REVOKED 0x80000000
176 #define IDXD_CMD_OFFSET 0xa0
177 union idxd_command_reg
{
188 IDXD_CMD_ENABLE_DEVICE
= 1,
189 IDXD_CMD_DISABLE_DEVICE
,
192 IDXD_CMD_RESET_DEVICE
,
198 IDXD_CMD_DRAIN_PASID
,
199 IDXD_CMD_ABORT_PASID
,
200 IDXD_CMD_REQUEST_INT_HANDLE
,
201 IDXD_CMD_RELEASE_INT_HANDLE
,
204 #define CMD_INT_HANDLE_IMS 0x10000
206 #define IDXD_CMDSTS_OFFSET 0xa8
216 #define IDXD_CMDSTS_ACTIVE 0x80000000
217 #define IDXD_CMDSTS_ERR_MASK 0xff
218 #define IDXD_CMDSTS_RES_SHIFT 8
220 enum idxd_cmdsts_err
{
221 IDXD_CMDSTS_SUCCESS
= 0,
222 IDXD_CMDSTS_INVAL_CMD
,
223 IDXD_CMDSTS_INVAL_WQIDX
,
225 /* enable device errors */
226 IDXD_CMDSTS_ERR_DEV_ENABLED
= 0x10,
227 IDXD_CMDSTS_ERR_CONFIG
,
228 IDXD_CMDSTS_ERR_BUSMASTER_EN
,
229 IDXD_CMDSTS_ERR_PASID_INVAL
,
230 IDXD_CMDSTS_ERR_WQ_SIZE_ERANGE
,
231 IDXD_CMDSTS_ERR_GRP_CONFIG
,
232 IDXD_CMDSTS_ERR_GRP_CONFIG2
,
233 IDXD_CMDSTS_ERR_GRP_CONFIG3
,
234 IDXD_CMDSTS_ERR_GRP_CONFIG4
,
235 /* enable wq errors */
236 IDXD_CMDSTS_ERR_DEV_NOTEN
= 0x20,
237 IDXD_CMDSTS_ERR_WQ_ENABLED
,
238 IDXD_CMDSTS_ERR_WQ_SIZE
,
239 IDXD_CMDSTS_ERR_WQ_PRIOR
,
240 IDXD_CMDSTS_ERR_WQ_MODE
,
241 IDXD_CMDSTS_ERR_BOF_EN
,
242 IDXD_CMDSTS_ERR_PASID_EN
,
243 IDXD_CMDSTS_ERR_MAX_BATCH_SIZE
,
244 IDXD_CMDSTS_ERR_MAX_XFER_SIZE
,
245 /* disable device errors */
246 IDXD_CMDSTS_ERR_DIS_DEV_EN
= 0x31,
247 /* disable WQ, drain WQ, abort WQ, reset WQ */
248 IDXD_CMDSTS_ERR_DEV_NOT_EN
,
249 /* request interrupt handle */
250 IDXD_CMDSTS_ERR_INVAL_INT_IDX
= 0x41,
251 IDXD_CMDSTS_ERR_NO_HANDLE
,
254 #define IDXD_CMDCAP_OFFSET 0xb0
256 #define IDXD_SWERR_OFFSET 0xc0
257 #define IDXD_SWERR_VALID 0x00000001
258 #define IDXD_SWERR_OVERFLOW 0x00000002
259 #define IDXD_SWERR_ACK (IDXD_SWERR_VALID | IDXD_SWERR_OVERFLOW)
279 u64 invalid_flags
:32;
290 u64 dec_aecs_format_ver
:1;
291 u64 drop_init_bits
:1;
293 u64 force_array_output_mod
:1;
294 u64 load_part_aecs
:1;
295 u64 comp_early_abort
:1;
307 #define IDXD_IAACAP_OFFSET 0x180
309 #define IDXD_EVLCFG_OFFSET 0xe0
324 #define IDXD_EVL_SIZE_MIN 0x0040
325 #define IDXD_EVL_SIZE_MAX 0xffff
343 u64 use_rdbuf_limit
:1;
344 u64 rdbufs_reserved
:8;
346 u64 rdbufs_allowed
:8;
348 u64 desc_progress_limit
:2;
350 u64 batch_progress_limit
:2;
359 union group_flags flags
;
373 u32 mode
:1; /* shared or dedicated */
374 u32 bof
:1; /* block on fault */
375 u32 wq_ats_disable
:1;
376 u32 wq_prs_disable
:1;
384 u32 max_xfer_shift
:5;
385 u32 max_batch_shift
:4;
390 u16 occupancy_table_sel
:1;
395 u16 occupancy_int_en
:1;
414 #define WQCFG_PASID_IDX 2
415 #define WQCFG_PRIVL_IDX 2
416 #define WQCFG_OCCUP_IDX 6
418 #define WQCFG_OCCUP_MASK 0xffff
421 * This macro calculates the offset into the WQCFG register
422 * idxd - struct idxd *
424 * ofs - the index of the 32b dword for the config register
426 * The WQCFG register block is divided into groups per each wq. The n index
427 * allows us to move to the register group that's for that particular wq.
428 * Each register is 32bits. The ofs gives us the number of register to access.
430 #define WQCFG_OFFSET(_idxd_dev, n, ofs) \
432 typeof(_idxd_dev) __idxd_dev = (_idxd_dev); \
433 (__idxd_dev)->wqcfg_offset + (n) * (__idxd_dev)->wqcfg_size + sizeof(u32) * (ofs); \
436 #define WQCFG_STRIDES(_idxd_dev) ((_idxd_dev)->wqcfg_size / sizeof(u32))
438 #define GRPCFG_SIZE 64
439 #define GRPWQCFG_STRIDES 4
442 * This macro calculates the offset into the GRPCFG register
443 * idxd - struct idxd *
445 * ofs - the index of the 64b qword for the config register
447 * The GRPCFG register block is divided into three sub-registers, which
448 * are GRPWQCFG, GRPENGCFG and GRPFLGCFG. The n index allows us to move
449 * to the register block that contains the three sub-registers.
450 * Each register block is 64bits. And the ofs gives us the offset
451 * within the GRPWQCFG register to access.
453 #define GRPWQCFG_OFFSET(idxd_dev, n, ofs) ((idxd_dev)->grpcfg_offset +\
454 (n) * GRPCFG_SIZE + sizeof(u64) * (ofs))
455 #define GRPENGCFG_OFFSET(idxd_dev, n) ((idxd_dev)->grpcfg_offset + (n) * GRPCFG_SIZE + 32)
456 #define GRPFLGCFG_OFFSET(idxd_dev, n) ((idxd_dev)->grpcfg_offset + (n) * GRPCFG_SIZE + 40)
458 /* Following is performance monitor registers */
459 #define IDXD_PERFCAP_OFFSET 0x0
462 u64 num_perf_counter
:6;
465 u64 num_event_category
:4;
466 u64 global_event_category
:16;
469 u64 cap_per_counter
:1;
470 u64 writeable_counter
:1;
471 u64 counter_freeze
:1;
472 u64 overflow_interrupt
:1;
478 #define IDXD_EVNTCAP_OFFSET 0x80
490 u32 event_category
:4;
497 #define IDXD_CNTRCAP_OFFSET 0x800
498 struct idxd_cntrcap
{
507 struct idxd_event events
[];
510 #define IDXD_PERFRST_OFFSET 0x10
513 u32 perfrst_config
:1;
514 u32 perfrst_counter
:1;
520 #define IDXD_OVFSTATUS_OFFSET 0x30
521 #define IDXD_PERFFRZ_OFFSET 0x20
522 #define IDXD_CNTRCFG_OFFSET 0x100
527 u64 global_freeze_ovf
:1;
529 u64 event_category
:4;
537 #define IDXD_FLTCFG_OFFSET 0x300
539 #define IDXD_CNTRDATA_OFFSET 0x200
540 union idxd_cntrdata
{
542 u64 event_count_value
;
566 #define IDXD_EVLSTATUS_OFFSET 0xf0
568 union evl_status_reg
{
584 #define IDXD_MAX_BATCH_IDENT 256
593 u64 err_info_valid
:1;
604 /* Invalid Flags 0x11 */
606 /* Invalid Int Handle 0x19 */
607 /* Page fault 0x1a */
608 /* Page fault 0x06, 0x1f, only operand_id */
609 /* Page fault before drain or in batch, 0x26, 0x27 */
615 u16 first_err_in_batch
:1;
624 struct dsa_evl_entry
{
625 struct __evl_entry e
;
626 struct dsa_completion_record cr
;
629 struct iax_evl_entry
{
630 struct __evl_entry e
;
632 struct iax_completion_record cr
;