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