1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2015 - 2019 Intel Corporation */
7 #define PBLE_PER_PAGE 512
8 #define HMC_PAGED_BP_SHIFT 12
9 #define PBLE_512_SHIFT 9
10 #define PBLE_INVALID_IDX 0xffffffff
12 enum irdma_pble_level {
18 enum irdma_alloc_type {
20 PBLE_SD_CONTIGOUS = 1,
26 struct irdma_pble_chunkinfo {
27 struct irdma_chunk *pchunk;
32 struct irdma_pble_info {
36 struct irdma_pble_chunkinfo chunkinfo;
39 struct irdma_pble_level2 {
40 struct irdma_pble_info root;
41 struct irdma_pble_info *leaf;
42 struct irdma_virt_mem leafmem;
46 struct irdma_pble_alloc {
48 enum irdma_pble_level level;
50 struct irdma_pble_info level1;
51 struct irdma_pble_level2 level2;
61 struct irdma_add_page_info {
62 struct irdma_chunk *chunk;
63 struct irdma_hmc_sd_entry *sd_entry;
64 struct irdma_hmc_info *hmc_info;
70 struct list_head list;
71 struct irdma_dma_info dmainfo;
72 unsigned long *bitmapbuf;
79 enum irdma_alloc_type type;
80 struct irdma_sc_dev *dev;
81 struct irdma_virt_mem chunkmem;
84 struct irdma_pble_prm {
85 struct list_head clist;
86 spinlock_t prm_lock; /* protect prm bitmap */
92 struct irdma_hmc_pble_rsrc {
94 struct mutex pble_mutex_lock; /* protect PBLE resource */
95 struct irdma_sc_dev *dev;
98 struct irdma_pble_prm pinfo;
101 u32 stats_direct_sds;
104 u64 stats_alloc_fail;
105 u64 stats_alloc_freed;
110 void irdma_destroy_pble_prm(struct irdma_hmc_pble_rsrc *pble_rsrc);
111 int irdma_hmc_init_pble(struct irdma_sc_dev *dev,
112 struct irdma_hmc_pble_rsrc *pble_rsrc);
113 void irdma_free_pble(struct irdma_hmc_pble_rsrc *pble_rsrc,
114 struct irdma_pble_alloc *palloc);
115 int irdma_get_pble(struct irdma_hmc_pble_rsrc *pble_rsrc,
116 struct irdma_pble_alloc *palloc, u32 pble_cnt,
118 int irdma_prm_add_pble_mem(struct irdma_pble_prm *pprm,
119 struct irdma_chunk *pchunk);
120 int irdma_prm_get_pbles(struct irdma_pble_prm *pprm,
121 struct irdma_pble_chunkinfo *chunkinfo, u64 mem_size,
122 u64 **vaddr, u64 *fpm_addr);
123 void irdma_prm_return_pbles(struct irdma_pble_prm *pprm,
124 struct irdma_pble_chunkinfo *chunkinfo);
125 void irdma_pble_acquire_lock(struct irdma_hmc_pble_rsrc *pble_rsrc,
126 unsigned long *flags);
127 void irdma_pble_release_lock(struct irdma_hmc_pble_rsrc *pble_rsrc,
128 unsigned long *flags);
129 void irdma_pble_free_paged_mem(struct irdma_chunk *chunk);
130 int irdma_pble_get_paged_mem(struct irdma_chunk *chunk, u32 pg_cnt);
131 void irdma_prm_rem_bitmapmem(struct irdma_hw *hw, struct irdma_chunk *chunk);
132 #endif /* IRDMA_PBLE_H */