162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
462306a36Sopenharmony_ci/*          Kai Shen <kaishen@linux.alibaba.com> */
562306a36Sopenharmony_ci/* Copyright (c) 2020-2022, Alibaba Group. */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef __ERDMA_HW_H__
862306a36Sopenharmony_ci#define __ERDMA_HW_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/kernel.h>
1162306a36Sopenharmony_ci#include <linux/types.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* PCIe device related definition. */
1462306a36Sopenharmony_ci#define PCI_VENDOR_ID_ALIBABA 0x1ded
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define ERDMA_PCI_WIDTH 64
1762306a36Sopenharmony_ci#define ERDMA_FUNC_BAR 0
1862306a36Sopenharmony_ci#define ERDMA_MISX_BAR 2
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define ERDMA_BAR_MASK (BIT(ERDMA_FUNC_BAR) | BIT(ERDMA_MISX_BAR))
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* MSI-X related. */
2362306a36Sopenharmony_ci#define ERDMA_NUM_MSIX_VEC 32U
2462306a36Sopenharmony_ci#define ERDMA_MSIX_VECTOR_CMDQ 0
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/* PCIe Bar0 Registers. */
2762306a36Sopenharmony_ci#define ERDMA_REGS_VERSION_REG 0x0
2862306a36Sopenharmony_ci#define ERDMA_REGS_DEV_CTRL_REG 0x10
2962306a36Sopenharmony_ci#define ERDMA_REGS_DEV_ST_REG 0x14
3062306a36Sopenharmony_ci#define ERDMA_REGS_NETDEV_MAC_L_REG 0x18
3162306a36Sopenharmony_ci#define ERDMA_REGS_NETDEV_MAC_H_REG 0x1C
3262306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_SQ_ADDR_L_REG 0x20
3362306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_SQ_ADDR_H_REG 0x24
3462306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_CQ_ADDR_L_REG 0x28
3562306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_CQ_ADDR_H_REG 0x2C
3662306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_DEPTH_REG 0x30
3762306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_EQ_DEPTH_REG 0x34
3862306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_EQ_ADDR_L_REG 0x38
3962306a36Sopenharmony_ci#define ERDMA_REGS_CMDQ_EQ_ADDR_H_REG 0x3C
4062306a36Sopenharmony_ci#define ERDMA_REGS_AEQ_ADDR_L_REG 0x40
4162306a36Sopenharmony_ci#define ERDMA_REGS_AEQ_ADDR_H_REG 0x44
4262306a36Sopenharmony_ci#define ERDMA_REGS_AEQ_DEPTH_REG 0x48
4362306a36Sopenharmony_ci#define ERDMA_REGS_GRP_NUM_REG 0x4c
4462306a36Sopenharmony_ci#define ERDMA_REGS_AEQ_DB_REG 0x50
4562306a36Sopenharmony_ci#define ERDMA_CMDQ_SQ_DB_HOST_ADDR_REG 0x60
4662306a36Sopenharmony_ci#define ERDMA_CMDQ_CQ_DB_HOST_ADDR_REG 0x68
4762306a36Sopenharmony_ci#define ERDMA_CMDQ_EQ_DB_HOST_ADDR_REG 0x70
4862306a36Sopenharmony_ci#define ERDMA_AEQ_DB_HOST_ADDR_REG 0x78
4962306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TSO_IN_PKTS_REG 0x80
5062306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TSO_OUT_PKTS_REG 0x88
5162306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TSO_OUT_BYTES_REG 0x90
5262306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TX_DROP_PKTS_REG 0x98
5362306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TX_BPS_METER_DROP_PKTS_REG 0xa0
5462306a36Sopenharmony_ci#define ERDMA_REGS_STATS_TX_PPS_METER_DROP_PKTS_REG 0xa8
5562306a36Sopenharmony_ci#define ERDMA_REGS_STATS_RX_PKTS_REG 0xc0
5662306a36Sopenharmony_ci#define ERDMA_REGS_STATS_RX_BYTES_REG 0xc8
5762306a36Sopenharmony_ci#define ERDMA_REGS_STATS_RX_DROP_PKTS_REG 0xd0
5862306a36Sopenharmony_ci#define ERDMA_REGS_STATS_RX_BPS_METER_DROP_PKTS_REG 0xd8
5962306a36Sopenharmony_ci#define ERDMA_REGS_STATS_RX_PPS_METER_DROP_PKTS_REG 0xe0
6062306a36Sopenharmony_ci#define ERDMA_REGS_CEQ_DB_BASE_REG 0x100
6162306a36Sopenharmony_ci#define ERDMA_CMDQ_SQDB_REG 0x200
6262306a36Sopenharmony_ci#define ERDMA_CMDQ_CQDB_REG 0x300
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/* DEV_CTRL_REG details. */
6562306a36Sopenharmony_ci#define ERDMA_REG_DEV_CTRL_RESET_MASK 0x00000001
6662306a36Sopenharmony_ci#define ERDMA_REG_DEV_CTRL_INIT_MASK 0x00000002
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* DEV_ST_REG details. */
6962306a36Sopenharmony_ci#define ERDMA_REG_DEV_ST_RESET_DONE_MASK 0x00000001U
7062306a36Sopenharmony_ci#define ERDMA_REG_DEV_ST_INIT_DONE_MASK 0x00000002U
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* eRDMA PCIe DBs definition. */
7362306a36Sopenharmony_ci#define ERDMA_BAR_DB_SPACE_BASE 4096
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define ERDMA_BAR_SQDB_SPACE_OFFSET ERDMA_BAR_DB_SPACE_BASE
7662306a36Sopenharmony_ci#define ERDMA_BAR_SQDB_SPACE_SIZE (384 * 1024)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define ERDMA_BAR_RQDB_SPACE_OFFSET \
7962306a36Sopenharmony_ci	(ERDMA_BAR_SQDB_SPACE_OFFSET + ERDMA_BAR_SQDB_SPACE_SIZE)
8062306a36Sopenharmony_ci#define ERDMA_BAR_RQDB_SPACE_SIZE (96 * 1024)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define ERDMA_BAR_CQDB_SPACE_OFFSET \
8362306a36Sopenharmony_ci	(ERDMA_BAR_RQDB_SPACE_OFFSET + ERDMA_BAR_RQDB_SPACE_SIZE)
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define ERDMA_SDB_SHARED_PAGE_INDEX 95
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* Doorbell related. */
8862306a36Sopenharmony_ci#define ERDMA_DB_SIZE 8
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define ERDMA_CQDB_IDX_MASK GENMASK_ULL(63, 56)
9162306a36Sopenharmony_ci#define ERDMA_CQDB_CQN_MASK GENMASK_ULL(55, 32)
9262306a36Sopenharmony_ci#define ERDMA_CQDB_ARM_MASK BIT_ULL(31)
9362306a36Sopenharmony_ci#define ERDMA_CQDB_SOL_MASK BIT_ULL(30)
9462306a36Sopenharmony_ci#define ERDMA_CQDB_CMDSN_MASK GENMASK_ULL(29, 28)
9562306a36Sopenharmony_ci#define ERDMA_CQDB_CI_MASK GENMASK_ULL(23, 0)
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define ERDMA_EQDB_ARM_MASK BIT(31)
9862306a36Sopenharmony_ci#define ERDMA_EQDB_CI_MASK GENMASK_ULL(23, 0)
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#define ERDMA_PAGE_SIZE_SUPPORT 0x7FFFF000
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* Hardware page size definition */
10362306a36Sopenharmony_ci#define ERDMA_HW_PAGE_SHIFT 12
10462306a36Sopenharmony_ci#define ERDMA_HW_PAGE_SIZE 4096
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* WQE related. */
10762306a36Sopenharmony_ci#define EQE_SIZE 16
10862306a36Sopenharmony_ci#define EQE_SHIFT 4
10962306a36Sopenharmony_ci#define RQE_SIZE 32
11062306a36Sopenharmony_ci#define RQE_SHIFT 5
11162306a36Sopenharmony_ci#define CQE_SIZE 32
11262306a36Sopenharmony_ci#define CQE_SHIFT 5
11362306a36Sopenharmony_ci#define SQEBB_SIZE 32
11462306a36Sopenharmony_ci#define SQEBB_SHIFT 5
11562306a36Sopenharmony_ci#define SQEBB_MASK (~(SQEBB_SIZE - 1))
11662306a36Sopenharmony_ci#define SQEBB_ALIGN(size) ((size + SQEBB_SIZE - 1) & SQEBB_MASK)
11762306a36Sopenharmony_ci#define SQEBB_COUNT(size) (SQEBB_ALIGN(size) >> SQEBB_SHIFT)
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define ERDMA_MAX_SQE_SIZE 128
12062306a36Sopenharmony_ci#define ERDMA_MAX_WQEBB_PER_SQE 4
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* CMDQ related. */
12362306a36Sopenharmony_ci#define ERDMA_CMDQ_MAX_OUTSTANDING 128
12462306a36Sopenharmony_ci#define ERDMA_CMDQ_SQE_SIZE 128
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* cmdq sub module definition. */
12762306a36Sopenharmony_cienum CMDQ_WQE_SUB_MOD {
12862306a36Sopenharmony_ci	CMDQ_SUBMOD_RDMA = 0,
12962306a36Sopenharmony_ci	CMDQ_SUBMOD_COMMON = 1
13062306a36Sopenharmony_ci};
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_cienum CMDQ_RDMA_OPCODE {
13362306a36Sopenharmony_ci	CMDQ_OPCODE_QUERY_DEVICE = 0,
13462306a36Sopenharmony_ci	CMDQ_OPCODE_CREATE_QP = 1,
13562306a36Sopenharmony_ci	CMDQ_OPCODE_DESTROY_QP = 2,
13662306a36Sopenharmony_ci	CMDQ_OPCODE_MODIFY_QP = 3,
13762306a36Sopenharmony_ci	CMDQ_OPCODE_CREATE_CQ = 4,
13862306a36Sopenharmony_ci	CMDQ_OPCODE_DESTROY_CQ = 5,
13962306a36Sopenharmony_ci	CMDQ_OPCODE_REFLUSH = 6,
14062306a36Sopenharmony_ci	CMDQ_OPCODE_REG_MR = 8,
14162306a36Sopenharmony_ci	CMDQ_OPCODE_DEREG_MR = 9
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cienum CMDQ_COMMON_OPCODE {
14562306a36Sopenharmony_ci	CMDQ_OPCODE_CREATE_EQ = 0,
14662306a36Sopenharmony_ci	CMDQ_OPCODE_DESTROY_EQ = 1,
14762306a36Sopenharmony_ci	CMDQ_OPCODE_QUERY_FW_INFO = 2,
14862306a36Sopenharmony_ci	CMDQ_OPCODE_CONF_MTU = 3,
14962306a36Sopenharmony_ci	CMDQ_OPCODE_CONF_DEVICE = 5,
15062306a36Sopenharmony_ci	CMDQ_OPCODE_ALLOC_DB = 8,
15162306a36Sopenharmony_ci	CMDQ_OPCODE_FREE_DB = 9,
15262306a36Sopenharmony_ci};
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* cmdq-SQE HDR */
15562306a36Sopenharmony_ci#define ERDMA_CMD_HDR_WQEBB_CNT_MASK GENMASK_ULL(54, 52)
15662306a36Sopenharmony_ci#define ERDMA_CMD_HDR_CONTEXT_COOKIE_MASK GENMASK_ULL(47, 32)
15762306a36Sopenharmony_ci#define ERDMA_CMD_HDR_SUB_MOD_MASK GENMASK_ULL(25, 24)
15862306a36Sopenharmony_ci#define ERDMA_CMD_HDR_OPCODE_MASK GENMASK_ULL(23, 16)
15962306a36Sopenharmony_ci#define ERDMA_CMD_HDR_WQEBB_INDEX_MASK GENMASK_ULL(15, 0)
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistruct erdma_cmdq_destroy_cq_req {
16262306a36Sopenharmony_ci	u64 hdr;
16362306a36Sopenharmony_ci	u32 cqn;
16462306a36Sopenharmony_ci};
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#define ERDMA_EQ_TYPE_AEQ 0
16762306a36Sopenharmony_ci#define ERDMA_EQ_TYPE_CEQ 1
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_cistruct erdma_cmdq_create_eq_req {
17062306a36Sopenharmony_ci	u64 hdr;
17162306a36Sopenharmony_ci	u64 qbuf_addr;
17262306a36Sopenharmony_ci	u8 vector_idx;
17362306a36Sopenharmony_ci	u8 eqn;
17462306a36Sopenharmony_ci	u8 depth;
17562306a36Sopenharmony_ci	u8 qtype;
17662306a36Sopenharmony_ci	u32 db_dma_addr_l;
17762306a36Sopenharmony_ci	u32 db_dma_addr_h;
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistruct erdma_cmdq_destroy_eq_req {
18162306a36Sopenharmony_ci	u64 hdr;
18262306a36Sopenharmony_ci	u64 rsvd0;
18362306a36Sopenharmony_ci	u8 vector_idx;
18462306a36Sopenharmony_ci	u8 eqn;
18562306a36Sopenharmony_ci	u8 rsvd1;
18662306a36Sopenharmony_ci	u8 qtype;
18762306a36Sopenharmony_ci};
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* config device cfg */
19062306a36Sopenharmony_ci#define ERDMA_CMD_CONFIG_DEVICE_PS_EN_MASK BIT(31)
19162306a36Sopenharmony_ci#define ERDMA_CMD_CONFIG_DEVICE_PGSHIFT_MASK GENMASK(4, 0)
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistruct erdma_cmdq_config_device_req {
19462306a36Sopenharmony_ci	u64 hdr;
19562306a36Sopenharmony_ci	u32 cfg;
19662306a36Sopenharmony_ci	u32 rsvd[5];
19762306a36Sopenharmony_ci};
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_cistruct erdma_cmdq_config_mtu_req {
20062306a36Sopenharmony_ci	u64 hdr;
20162306a36Sopenharmony_ci	u32 mtu;
20262306a36Sopenharmony_ci};
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci/* ext db requests(alloc and free) cfg */
20562306a36Sopenharmony_ci#define ERDMA_CMD_EXT_DB_CQ_EN_MASK BIT(2)
20662306a36Sopenharmony_ci#define ERDMA_CMD_EXT_DB_RQ_EN_MASK BIT(1)
20762306a36Sopenharmony_ci#define ERDMA_CMD_EXT_DB_SQ_EN_MASK BIT(0)
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_cistruct erdma_cmdq_ext_db_req {
21062306a36Sopenharmony_ci	u64 hdr;
21162306a36Sopenharmony_ci	u32 cfg;
21262306a36Sopenharmony_ci	u16 rdb_off;
21362306a36Sopenharmony_ci	u16 sdb_off;
21462306a36Sopenharmony_ci	u16 rsvd0;
21562306a36Sopenharmony_ci	u16 cdb_off;
21662306a36Sopenharmony_ci	u32 rsvd1[3];
21762306a36Sopenharmony_ci};
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci/* alloc db response qword 0 definition */
22062306a36Sopenharmony_ci#define ERDMA_CMD_ALLOC_DB_RESP_RDB_MASK GENMASK_ULL(63, 48)
22162306a36Sopenharmony_ci#define ERDMA_CMD_ALLOC_DB_RESP_CDB_MASK GENMASK_ULL(47, 32)
22262306a36Sopenharmony_ci#define ERDMA_CMD_ALLOC_DB_RESP_SDB_MASK GENMASK_ULL(15, 0)
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci/* create_cq cfg0 */
22562306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_DEPTH_MASK GENMASK(31, 24)
22662306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_PAGESIZE_MASK GENMASK(23, 20)
22762306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_CQN_MASK GENMASK(19, 0)
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci/* create_cq cfg1 */
23062306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_MTT_CNT_MASK GENMASK(31, 16)
23162306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK BIT(15)
23262306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_MTT_DB_CFG_MASK BIT(11)
23362306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_EQN_MASK GENMASK(9, 0)
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/* create_cq cfg2 */
23662306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_CQ_DB_CFG_MASK GENMASK(15, 0)
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_cistruct erdma_cmdq_create_cq_req {
23962306a36Sopenharmony_ci	u64 hdr;
24062306a36Sopenharmony_ci	u32 cfg0;
24162306a36Sopenharmony_ci	u32 qbuf_addr_l;
24262306a36Sopenharmony_ci	u32 qbuf_addr_h;
24362306a36Sopenharmony_ci	u32 cfg1;
24462306a36Sopenharmony_ci	u64 cq_db_info_addr;
24562306a36Sopenharmony_ci	u32 first_page_offset;
24662306a36Sopenharmony_ci	u32 cfg2;
24762306a36Sopenharmony_ci};
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* regmr/deregmr cfg0 */
25062306a36Sopenharmony_ci#define ERDMA_CMD_MR_VALID_MASK BIT(31)
25162306a36Sopenharmony_ci#define ERDMA_CMD_MR_VERSION_MASK GENMASK(30, 28)
25262306a36Sopenharmony_ci#define ERDMA_CMD_MR_KEY_MASK GENMASK(27, 20)
25362306a36Sopenharmony_ci#define ERDMA_CMD_MR_MPT_IDX_MASK GENMASK(19, 0)
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/* regmr cfg1 */
25662306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_PD_MASK GENMASK(31, 12)
25762306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_TYPE_MASK GENMASK(7, 6)
25862306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_RIGHT_MASK GENMASK(5, 1)
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci/* regmr cfg2 */
26162306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_PAGESIZE_MASK GENMASK(31, 27)
26262306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_MTT_PAGESIZE_MASK GENMASK(26, 24)
26362306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_MTT_LEVEL_MASK GENMASK(21, 20)
26462306a36Sopenharmony_ci#define ERDMA_CMD_REGMR_MTT_CNT_MASK GENMASK(19, 0)
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_cistruct erdma_cmdq_reg_mr_req {
26762306a36Sopenharmony_ci	u64 hdr;
26862306a36Sopenharmony_ci	u32 cfg0;
26962306a36Sopenharmony_ci	u32 cfg1;
27062306a36Sopenharmony_ci	u64 start_va;
27162306a36Sopenharmony_ci	u32 size;
27262306a36Sopenharmony_ci	u32 cfg2;
27362306a36Sopenharmony_ci	union {
27462306a36Sopenharmony_ci		u64 phy_addr[4];
27562306a36Sopenharmony_ci		struct {
27662306a36Sopenharmony_ci			u64 rsvd;
27762306a36Sopenharmony_ci			u32 size_h;
27862306a36Sopenharmony_ci			u32 mtt_cnt_h;
27962306a36Sopenharmony_ci		};
28062306a36Sopenharmony_ci	};
28162306a36Sopenharmony_ci};
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_cistruct erdma_cmdq_dereg_mr_req {
28462306a36Sopenharmony_ci	u64 hdr;
28562306a36Sopenharmony_ci	u32 cfg;
28662306a36Sopenharmony_ci};
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci/* modify qp cfg */
28962306a36Sopenharmony_ci#define ERDMA_CMD_MODIFY_QP_STATE_MASK GENMASK(31, 24)
29062306a36Sopenharmony_ci#define ERDMA_CMD_MODIFY_QP_CC_MASK GENMASK(23, 20)
29162306a36Sopenharmony_ci#define ERDMA_CMD_MODIFY_QP_QPN_MASK GENMASK(19, 0)
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_cistruct erdma_cmdq_modify_qp_req {
29462306a36Sopenharmony_ci	u64 hdr;
29562306a36Sopenharmony_ci	u32 cfg;
29662306a36Sopenharmony_ci	u32 cookie;
29762306a36Sopenharmony_ci	__be32 dip;
29862306a36Sopenharmony_ci	__be32 sip;
29962306a36Sopenharmony_ci	__be16 sport;
30062306a36Sopenharmony_ci	__be16 dport;
30162306a36Sopenharmony_ci	u32 send_nxt;
30262306a36Sopenharmony_ci	u32 recv_nxt;
30362306a36Sopenharmony_ci};
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci/* create qp cfg0 */
30662306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_SQ_DEPTH_MASK GENMASK(31, 20)
30762306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_QPN_MASK GENMASK(19, 0)
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci/* create qp cfg1 */
31062306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_RQ_DEPTH_MASK GENMASK(31, 20)
31162306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_PD_MASK GENMASK(19, 0)
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci/* create qp cqn_mtt_cfg */
31462306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_PAGE_SIZE_MASK GENMASK(31, 28)
31562306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_DB_CFG_MASK BIT(25)
31662306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_CQN_MASK GENMASK(23, 0)
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci/* create qp mtt_cfg */
31962306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_PAGE_OFFSET_MASK GENMASK(31, 12)
32062306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_MTT_CNT_MASK GENMASK(11, 1)
32162306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_MTT_LEVEL_MASK BIT(0)
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci/* create qp db cfg */
32462306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_SQDB_CFG_MASK GENMASK(31, 16)
32562306a36Sopenharmony_ci#define ERDMA_CMD_CREATE_QP_RQDB_CFG_MASK GENMASK(15, 0)
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci#define ERDMA_CMDQ_CREATE_QP_RESP_COOKIE_MASK GENMASK_ULL(31, 0)
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_cistruct erdma_cmdq_create_qp_req {
33062306a36Sopenharmony_ci	u64 hdr;
33162306a36Sopenharmony_ci	u32 cfg0;
33262306a36Sopenharmony_ci	u32 cfg1;
33362306a36Sopenharmony_ci	u32 sq_cqn_mtt_cfg;
33462306a36Sopenharmony_ci	u32 rq_cqn_mtt_cfg;
33562306a36Sopenharmony_ci	u64 sq_buf_addr;
33662306a36Sopenharmony_ci	u64 rq_buf_addr;
33762306a36Sopenharmony_ci	u32 sq_mtt_cfg;
33862306a36Sopenharmony_ci	u32 rq_mtt_cfg;
33962306a36Sopenharmony_ci	u64 sq_db_info_dma_addr;
34062306a36Sopenharmony_ci	u64 rq_db_info_dma_addr;
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	u64 sq_mtt_entry[3];
34362306a36Sopenharmony_ci	u64 rq_mtt_entry[3];
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	u32 db_cfg;
34662306a36Sopenharmony_ci};
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_cistruct erdma_cmdq_destroy_qp_req {
34962306a36Sopenharmony_ci	u64 hdr;
35062306a36Sopenharmony_ci	u32 qpn;
35162306a36Sopenharmony_ci};
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_cistruct erdma_cmdq_reflush_req {
35462306a36Sopenharmony_ci	u64 hdr;
35562306a36Sopenharmony_ci	u32 qpn;
35662306a36Sopenharmony_ci	u32 sq_pi;
35762306a36Sopenharmony_ci	u32 rq_pi;
35862306a36Sopenharmony_ci};
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci/* cap qword 0 definition */
36162306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_MAX_CQE_MASK GENMASK_ULL(47, 40)
36262306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_FLAGS_MASK GENMASK_ULL(31, 24)
36362306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_MAX_RECV_WR_MASK GENMASK_ULL(23, 16)
36462306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_MAX_MR_SIZE_MASK GENMASK_ULL(7, 0)
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ci/* cap qword 1 definition */
36762306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_DMA_LOCAL_KEY_MASK GENMASK_ULL(63, 32)
36862306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_DEFAULT_CC_MASK GENMASK_ULL(31, 28)
36962306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_QBLOCK_MASK GENMASK_ULL(27, 16)
37062306a36Sopenharmony_ci#define ERDMA_CMD_DEV_CAP_MAX_MW_MASK GENMASK_ULL(7, 0)
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci#define ERDMA_NQP_PER_QBLOCK 1024
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_cienum {
37562306a36Sopenharmony_ci	ERDMA_DEV_CAP_FLAGS_ATOMIC = 1 << 7,
37662306a36Sopenharmony_ci	ERDMA_DEV_CAP_FLAGS_MTT_VA = 1 << 5,
37762306a36Sopenharmony_ci	ERDMA_DEV_CAP_FLAGS_EXTEND_DB = 1 << 3,
37862306a36Sopenharmony_ci};
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci#define ERDMA_CMD_INFO0_FW_VER_MASK GENMASK_ULL(31, 0)
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_ci/* CQE hdr */
38362306a36Sopenharmony_ci#define ERDMA_CQE_HDR_OWNER_MASK BIT(31)
38462306a36Sopenharmony_ci#define ERDMA_CQE_HDR_OPCODE_MASK GENMASK(23, 16)
38562306a36Sopenharmony_ci#define ERDMA_CQE_HDR_QTYPE_MASK GENMASK(15, 8)
38662306a36Sopenharmony_ci#define ERDMA_CQE_HDR_SYNDROME_MASK GENMASK(7, 0)
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci#define ERDMA_CQE_QTYPE_SQ 0
38962306a36Sopenharmony_ci#define ERDMA_CQE_QTYPE_RQ 1
39062306a36Sopenharmony_ci#define ERDMA_CQE_QTYPE_CMDQ 2
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_cistruct erdma_cqe {
39362306a36Sopenharmony_ci	__be32 hdr;
39462306a36Sopenharmony_ci	__be32 qe_idx;
39562306a36Sopenharmony_ci	__be32 qpn;
39662306a36Sopenharmony_ci	union {
39762306a36Sopenharmony_ci		__le32 imm_data;
39862306a36Sopenharmony_ci		__be32 inv_rkey;
39962306a36Sopenharmony_ci	};
40062306a36Sopenharmony_ci	__be32 size;
40162306a36Sopenharmony_ci	__be32 rsvd[3];
40262306a36Sopenharmony_ci};
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_cistruct erdma_sge {
40562306a36Sopenharmony_ci	__aligned_le64 addr;
40662306a36Sopenharmony_ci	__le32 length;
40762306a36Sopenharmony_ci	__le32 key;
40862306a36Sopenharmony_ci};
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci/* Receive Queue Element */
41162306a36Sopenharmony_cistruct erdma_rqe {
41262306a36Sopenharmony_ci	__le16 qe_idx;
41362306a36Sopenharmony_ci	__le16 rsvd0;
41462306a36Sopenharmony_ci	__le32 qpn;
41562306a36Sopenharmony_ci	__le32 rsvd1;
41662306a36Sopenharmony_ci	__le32 rsvd2;
41762306a36Sopenharmony_ci	__le64 to;
41862306a36Sopenharmony_ci	__le32 length;
41962306a36Sopenharmony_ci	__le32 stag;
42062306a36Sopenharmony_ci};
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci/* SQE */
42362306a36Sopenharmony_ci#define ERDMA_SQE_HDR_SGL_LEN_MASK GENMASK_ULL(63, 56)
42462306a36Sopenharmony_ci#define ERDMA_SQE_HDR_WQEBB_CNT_MASK GENMASK_ULL(54, 52)
42562306a36Sopenharmony_ci#define ERDMA_SQE_HDR_QPN_MASK GENMASK_ULL(51, 32)
42662306a36Sopenharmony_ci#define ERDMA_SQE_HDR_OPCODE_MASK GENMASK_ULL(31, 27)
42762306a36Sopenharmony_ci#define ERDMA_SQE_HDR_DWQE_MASK BIT_ULL(26)
42862306a36Sopenharmony_ci#define ERDMA_SQE_HDR_INLINE_MASK BIT_ULL(25)
42962306a36Sopenharmony_ci#define ERDMA_SQE_HDR_FENCE_MASK BIT_ULL(24)
43062306a36Sopenharmony_ci#define ERDMA_SQE_HDR_SE_MASK BIT_ULL(23)
43162306a36Sopenharmony_ci#define ERDMA_SQE_HDR_CE_MASK BIT_ULL(22)
43262306a36Sopenharmony_ci#define ERDMA_SQE_HDR_WQEBB_INDEX_MASK GENMASK_ULL(15, 0)
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci/* REG MR attrs */
43562306a36Sopenharmony_ci#define ERDMA_SQE_MR_ACCESS_MASK GENMASK(5, 1)
43662306a36Sopenharmony_ci#define ERDMA_SQE_MR_MTT_TYPE_MASK GENMASK(7, 6)
43762306a36Sopenharmony_ci#define ERDMA_SQE_MR_MTT_CNT_MASK GENMASK(31, 12)
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_cistruct erdma_write_sqe {
44062306a36Sopenharmony_ci	__le64 hdr;
44162306a36Sopenharmony_ci	__be32 imm_data;
44262306a36Sopenharmony_ci	__le32 length;
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci	__le32 sink_stag;
44562306a36Sopenharmony_ci	__le32 sink_to_l;
44662306a36Sopenharmony_ci	__le32 sink_to_h;
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci	__le32 rsvd;
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ci	struct erdma_sge sgl[];
45162306a36Sopenharmony_ci};
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_cistruct erdma_send_sqe {
45462306a36Sopenharmony_ci	__le64 hdr;
45562306a36Sopenharmony_ci	union {
45662306a36Sopenharmony_ci		__be32 imm_data;
45762306a36Sopenharmony_ci		__le32 invalid_stag;
45862306a36Sopenharmony_ci	};
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci	__le32 length;
46162306a36Sopenharmony_ci	struct erdma_sge sgl[];
46262306a36Sopenharmony_ci};
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_cistruct erdma_readreq_sqe {
46562306a36Sopenharmony_ci	__le64 hdr;
46662306a36Sopenharmony_ci	__le32 invalid_stag;
46762306a36Sopenharmony_ci	__le32 length;
46862306a36Sopenharmony_ci	__le32 sink_stag;
46962306a36Sopenharmony_ci	__le32 sink_to_l;
47062306a36Sopenharmony_ci	__le32 sink_to_h;
47162306a36Sopenharmony_ci	__le32 rsvd;
47262306a36Sopenharmony_ci};
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_cistruct erdma_atomic_sqe {
47562306a36Sopenharmony_ci	__le64 hdr;
47662306a36Sopenharmony_ci	__le64 rsvd;
47762306a36Sopenharmony_ci	__le64 fetchadd_swap_data;
47862306a36Sopenharmony_ci	__le64 cmp_data;
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci	struct erdma_sge remote;
48162306a36Sopenharmony_ci	struct erdma_sge sgl;
48262306a36Sopenharmony_ci};
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_cistruct erdma_reg_mr_sqe {
48562306a36Sopenharmony_ci	__le64 hdr;
48662306a36Sopenharmony_ci	__le64 addr;
48762306a36Sopenharmony_ci	__le32 length;
48862306a36Sopenharmony_ci	__le32 stag;
48962306a36Sopenharmony_ci	__le32 attrs;
49062306a36Sopenharmony_ci	__le32 rsvd;
49162306a36Sopenharmony_ci};
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci/* EQ related. */
49462306a36Sopenharmony_ci#define ERDMA_DEFAULT_EQ_DEPTH 4096
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci/* ceqe */
49762306a36Sopenharmony_ci#define ERDMA_CEQE_HDR_DB_MASK BIT_ULL(63)
49862306a36Sopenharmony_ci#define ERDMA_CEQE_HDR_PI_MASK GENMASK_ULL(55, 32)
49962306a36Sopenharmony_ci#define ERDMA_CEQE_HDR_O_MASK BIT_ULL(31)
50062306a36Sopenharmony_ci#define ERDMA_CEQE_HDR_CQN_MASK GENMASK_ULL(19, 0)
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ci/* aeqe */
50362306a36Sopenharmony_ci#define ERDMA_AEQE_HDR_O_MASK BIT(31)
50462306a36Sopenharmony_ci#define ERDMA_AEQE_HDR_TYPE_MASK GENMASK(23, 16)
50562306a36Sopenharmony_ci#define ERDMA_AEQE_HDR_SUBTYPE_MASK GENMASK(7, 0)
50662306a36Sopenharmony_ci
50762306a36Sopenharmony_ci#define ERDMA_AE_TYPE_QP_FATAL_EVENT 0
50862306a36Sopenharmony_ci#define ERDMA_AE_TYPE_QP_ERQ_ERR_EVENT 1
50962306a36Sopenharmony_ci#define ERDMA_AE_TYPE_ACC_ERR_EVENT 2
51062306a36Sopenharmony_ci#define ERDMA_AE_TYPE_CQ_ERR 3
51162306a36Sopenharmony_ci#define ERDMA_AE_TYPE_OTHER_ERROR 4
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_cistruct erdma_aeqe {
51462306a36Sopenharmony_ci	__le32 hdr;
51562306a36Sopenharmony_ci	__le32 event_data0;
51662306a36Sopenharmony_ci	__le32 event_data1;
51762306a36Sopenharmony_ci	__le32 rsvd;
51862306a36Sopenharmony_ci};
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_cienum erdma_opcode {
52162306a36Sopenharmony_ci	ERDMA_OP_WRITE = 0,
52262306a36Sopenharmony_ci	ERDMA_OP_READ = 1,
52362306a36Sopenharmony_ci	ERDMA_OP_SEND = 2,
52462306a36Sopenharmony_ci	ERDMA_OP_SEND_WITH_IMM = 3,
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci	ERDMA_OP_RECEIVE = 4,
52762306a36Sopenharmony_ci	ERDMA_OP_RECV_IMM = 5,
52862306a36Sopenharmony_ci	ERDMA_OP_RECV_INV = 6,
52962306a36Sopenharmony_ci
53062306a36Sopenharmony_ci	ERDMA_OP_RSVD0 = 7,
53162306a36Sopenharmony_ci	ERDMA_OP_RSVD1 = 8,
53262306a36Sopenharmony_ci	ERDMA_OP_WRITE_WITH_IMM = 9,
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_ci	ERDMA_OP_RSVD2 = 10,
53562306a36Sopenharmony_ci	ERDMA_OP_RSVD3 = 11,
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci	ERDMA_OP_RSP_SEND_IMM = 12,
53862306a36Sopenharmony_ci	ERDMA_OP_SEND_WITH_INV = 13,
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci	ERDMA_OP_REG_MR = 14,
54162306a36Sopenharmony_ci	ERDMA_OP_LOCAL_INV = 15,
54262306a36Sopenharmony_ci	ERDMA_OP_READ_WITH_INV = 16,
54362306a36Sopenharmony_ci	ERDMA_OP_ATOMIC_CAS = 17,
54462306a36Sopenharmony_ci	ERDMA_OP_ATOMIC_FAA = 18,
54562306a36Sopenharmony_ci	ERDMA_NUM_OPCODES = 19,
54662306a36Sopenharmony_ci	ERDMA_OP_INVALID = ERDMA_NUM_OPCODES + 1
54762306a36Sopenharmony_ci};
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_cienum erdma_wc_status {
55062306a36Sopenharmony_ci	ERDMA_WC_SUCCESS = 0,
55162306a36Sopenharmony_ci	ERDMA_WC_GENERAL_ERR = 1,
55262306a36Sopenharmony_ci	ERDMA_WC_RECV_WQE_FORMAT_ERR = 2,
55362306a36Sopenharmony_ci	ERDMA_WC_RECV_STAG_INVALID_ERR = 3,
55462306a36Sopenharmony_ci	ERDMA_WC_RECV_ADDR_VIOLATION_ERR = 4,
55562306a36Sopenharmony_ci	ERDMA_WC_RECV_RIGHT_VIOLATION_ERR = 5,
55662306a36Sopenharmony_ci	ERDMA_WC_RECV_PDID_ERR = 6,
55762306a36Sopenharmony_ci	ERDMA_WC_RECV_WARRPING_ERR = 7,
55862306a36Sopenharmony_ci	ERDMA_WC_SEND_WQE_FORMAT_ERR = 8,
55962306a36Sopenharmony_ci	ERDMA_WC_SEND_WQE_ORD_EXCEED = 9,
56062306a36Sopenharmony_ci	ERDMA_WC_SEND_STAG_INVALID_ERR = 10,
56162306a36Sopenharmony_ci	ERDMA_WC_SEND_ADDR_VIOLATION_ERR = 11,
56262306a36Sopenharmony_ci	ERDMA_WC_SEND_RIGHT_VIOLATION_ERR = 12,
56362306a36Sopenharmony_ci	ERDMA_WC_SEND_PDID_ERR = 13,
56462306a36Sopenharmony_ci	ERDMA_WC_SEND_WARRPING_ERR = 14,
56562306a36Sopenharmony_ci	ERDMA_WC_FLUSH_ERR = 15,
56662306a36Sopenharmony_ci	ERDMA_WC_RETRY_EXC_ERR = 16,
56762306a36Sopenharmony_ci	ERDMA_NUM_WC_STATUS
56862306a36Sopenharmony_ci};
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_cienum erdma_vendor_err {
57162306a36Sopenharmony_ci	ERDMA_WC_VENDOR_NO_ERR = 0,
57262306a36Sopenharmony_ci	ERDMA_WC_VENDOR_INVALID_RQE = 1,
57362306a36Sopenharmony_ci	ERDMA_WC_VENDOR_RQE_INVALID_STAG = 2,
57462306a36Sopenharmony_ci	ERDMA_WC_VENDOR_RQE_ADDR_VIOLATION = 3,
57562306a36Sopenharmony_ci	ERDMA_WC_VENDOR_RQE_ACCESS_RIGHT_ERR = 4,
57662306a36Sopenharmony_ci	ERDMA_WC_VENDOR_RQE_INVALID_PD = 5,
57762306a36Sopenharmony_ci	ERDMA_WC_VENDOR_RQE_WRAP_ERR = 6,
57862306a36Sopenharmony_ci	ERDMA_WC_VENDOR_INVALID_SQE = 0x20,
57962306a36Sopenharmony_ci	ERDMA_WC_VENDOR_ZERO_ORD = 0x21,
58062306a36Sopenharmony_ci	ERDMA_WC_VENDOR_SQE_INVALID_STAG = 0x30,
58162306a36Sopenharmony_ci	ERDMA_WC_VENDOR_SQE_ADDR_VIOLATION = 0x31,
58262306a36Sopenharmony_ci	ERDMA_WC_VENDOR_SQE_ACCESS_ERR = 0x32,
58362306a36Sopenharmony_ci	ERDMA_WC_VENDOR_SQE_INVALID_PD = 0x33,
58462306a36Sopenharmony_ci	ERDMA_WC_VENDOR_SQE_WARP_ERR = 0x34
58562306a36Sopenharmony_ci};
58662306a36Sopenharmony_ci
58762306a36Sopenharmony_ci#endif
588