xref: /openbmc/linux/drivers/infiniband/hw/irdma/hmc.h (revision fadbafc1)
1 /* SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB */
2 /* Copyright (c) 2015 - 2020 Intel Corporation */
3 #ifndef IRDMA_HMC_H
4 #define IRDMA_HMC_H
5 
6 #include "defs.h"
7 
8 #define IRDMA_HMC_MAX_BP_COUNT			512
9 #define IRDMA_MAX_SD_ENTRIES			11
10 #define IRDMA_HW_DBG_HMC_INVALID_BP_MARK	0xca
11 #define IRDMA_HMC_INFO_SIGNATURE		0x484d5347
12 #define IRDMA_HMC_PD_CNT_IN_SD			512
13 #define IRDMA_HMC_DIRECT_BP_SIZE		0x200000
14 #define IRDMA_HMC_MAX_SD_COUNT			8192
15 #define IRDMA_HMC_PAGED_BP_SIZE			4096
16 #define IRDMA_HMC_PD_BP_BUF_ALIGNMENT		4096
17 #define IRDMA_FIRST_VF_FPM_ID			8
18 #define FPM_MULTIPLIER				1024
19 
20 enum irdma_hmc_rsrc_type {
21 	IRDMA_HMC_IW_QP		 = 0,
22 	IRDMA_HMC_IW_CQ		 = 1,
23 	IRDMA_HMC_IW_RESERVED	 = 2,
24 	IRDMA_HMC_IW_HTE	 = 3,
25 	IRDMA_HMC_IW_ARP	 = 4,
26 	IRDMA_HMC_IW_APBVT_ENTRY = 5,
27 	IRDMA_HMC_IW_MR		 = 6,
28 	IRDMA_HMC_IW_XF		 = 7,
29 	IRDMA_HMC_IW_XFFL	 = 8,
30 	IRDMA_HMC_IW_Q1		 = 9,
31 	IRDMA_HMC_IW_Q1FL	 = 10,
32 	IRDMA_HMC_IW_TIMER       = 11,
33 	IRDMA_HMC_IW_FSIMC       = 12,
34 	IRDMA_HMC_IW_FSIAV       = 13,
35 	IRDMA_HMC_IW_PBLE	 = 14,
36 	IRDMA_HMC_IW_RRF	 = 15,
37 	IRDMA_HMC_IW_RRFFL       = 16,
38 	IRDMA_HMC_IW_HDR	 = 17,
39 	IRDMA_HMC_IW_MD		 = 18,
40 	IRDMA_HMC_IW_OOISC       = 19,
41 	IRDMA_HMC_IW_OOISCFFL    = 20,
42 	IRDMA_HMC_IW_MAX, /* Must be last entry */
43 };
44 
45 enum irdma_sd_entry_type {
46 	IRDMA_SD_TYPE_INVALID = 0,
47 	IRDMA_SD_TYPE_PAGED   = 1,
48 	IRDMA_SD_TYPE_DIRECT  = 2,
49 };
50 
51 struct irdma_hmc_obj_info {
52 	u64 base;
53 	u32 max_cnt;
54 	u32 cnt;
55 	u64 size;
56 };
57 
58 struct irdma_hmc_bp {
59 	enum irdma_sd_entry_type entry_type;
60 	struct irdma_dma_mem addr;
61 	u32 sd_pd_index;
62 	u32 use_cnt;
63 };
64 
65 struct irdma_hmc_pd_entry {
66 	struct irdma_hmc_bp bp;
67 	u32 sd_index;
68 	bool rsrc_pg:1;
69 	bool valid:1;
70 };
71 
72 struct irdma_hmc_pd_table {
73 	struct irdma_dma_mem pd_page_addr;
74 	struct irdma_hmc_pd_entry *pd_entry;
75 	struct irdma_virt_mem pd_entry_virt_mem;
76 	u32 use_cnt;
77 	u32 sd_index;
78 };
79 
80 struct irdma_hmc_sd_entry {
81 	enum irdma_sd_entry_type entry_type;
82 	bool valid;
83 	union {
84 		struct irdma_hmc_pd_table pd_table;
85 		struct irdma_hmc_bp bp;
86 	} u;
87 };
88 
89 struct irdma_hmc_sd_table {
90 	struct irdma_virt_mem addr;
91 	u32 sd_cnt;
92 	u32 use_cnt;
93 	struct irdma_hmc_sd_entry *sd_entry;
94 };
95 
96 struct irdma_hmc_info {
97 	u32 signature;
98 	u8 hmc_fn_id;
99 	u16 first_sd_index;
100 	struct irdma_hmc_obj_info *hmc_obj;
101 	struct irdma_virt_mem hmc_obj_virt_mem;
102 	struct irdma_hmc_sd_table sd_table;
103 	u16 sd_indexes[IRDMA_HMC_MAX_SD_COUNT];
104 };
105 
106 struct irdma_update_sd_entry {
107 	u64 cmd;
108 	u64 data;
109 };
110 
111 struct irdma_update_sds_info {
112 	u32 cnt;
113 	u8 hmc_fn_id;
114 	struct irdma_update_sd_entry entry[IRDMA_MAX_SD_ENTRIES];
115 };
116 
117 struct irdma_ccq_cqe_info;
118 struct irdma_hmc_fcn_info {
119 	u32 vf_id;
120 	u8 free_fcn;
121 };
122 
123 struct irdma_hmc_create_obj_info {
124 	struct irdma_hmc_info *hmc_info;
125 	struct irdma_virt_mem add_sd_virt_mem;
126 	u32 rsrc_type;
127 	u32 start_idx;
128 	u32 count;
129 	u32 add_sd_cnt;
130 	enum irdma_sd_entry_type entry_type;
131 	bool privileged;
132 };
133 
134 struct irdma_hmc_del_obj_info {
135 	struct irdma_hmc_info *hmc_info;
136 	struct irdma_virt_mem del_sd_virt_mem;
137 	u32 rsrc_type;
138 	u32 start_idx;
139 	u32 count;
140 	u32 del_sd_cnt;
141 	bool privileged;
142 };
143 
144 int irdma_copy_dma_mem(struct irdma_hw *hw, void *dest_buf,
145 		       struct irdma_dma_mem *src_mem, u64 src_offset, u64 size);
146 int irdma_sc_create_hmc_obj(struct irdma_sc_dev *dev,
147 			    struct irdma_hmc_create_obj_info *info);
148 int irdma_sc_del_hmc_obj(struct irdma_sc_dev *dev,
149 			 struct irdma_hmc_del_obj_info *info, bool reset);
150 int irdma_hmc_sd_one(struct irdma_sc_dev *dev, u8 hmc_fn_id, u64 pa, u32 sd_idx,
151 		     enum irdma_sd_entry_type type,
152 		     bool setsd);
153 int irdma_update_sds_noccq(struct irdma_sc_dev *dev,
154 			   struct irdma_update_sds_info *info);
155 struct irdma_vfdev *irdma_vfdev_from_fpm(struct irdma_sc_dev *dev,
156 					 u8 hmc_fn_id);
157 struct irdma_hmc_info *irdma_vf_hmcinfo_from_fpm(struct irdma_sc_dev *dev,
158 						 u8 hmc_fn_id);
159 int irdma_add_sd_table_entry(struct irdma_hw *hw,
160 			     struct irdma_hmc_info *hmc_info, u32 sd_index,
161 			     enum irdma_sd_entry_type type, u64 direct_mode_sz);
162 int irdma_add_pd_table_entry(struct irdma_sc_dev *dev,
163 			     struct irdma_hmc_info *hmc_info, u32 pd_index,
164 			     struct irdma_dma_mem *rsrc_pg);
165 int irdma_remove_pd_bp(struct irdma_sc_dev *dev,
166 		       struct irdma_hmc_info *hmc_info, u32 idx);
167 int irdma_prep_remove_sd_bp(struct irdma_hmc_info *hmc_info, u32 idx);
168 int irdma_prep_remove_pd_page(struct irdma_hmc_info *hmc_info, u32 idx);
169 #endif /* IRDMA_HMC_H */
170