Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB */
0002 /* Copyright (c) 2015 - 2019 Intel Corporation */
0003 #ifndef IRDMA_PBLE_H
0004 #define IRDMA_PBLE_H
0005 
0006 #define PBLE_SHIFT      6
0007 #define PBLE_PER_PAGE       512
0008 #define HMC_PAGED_BP_SHIFT  12
0009 #define PBLE_512_SHIFT      9
0010 #define PBLE_INVALID_IDX    0xffffffff
0011 
0012 enum irdma_pble_level {
0013     PBLE_LEVEL_0 = 0,
0014     PBLE_LEVEL_1 = 1,
0015     PBLE_LEVEL_2 = 2,
0016 };
0017 
0018 enum irdma_alloc_type {
0019     PBLE_NO_ALLOC     = 0,
0020     PBLE_SD_CONTIGOUS = 1,
0021     PBLE_SD_PAGED     = 2,
0022 };
0023 
0024 struct irdma_chunk;
0025 
0026 struct irdma_pble_chunkinfo {
0027     struct irdma_chunk *pchunk;
0028     u64 bit_idx;
0029     u64 bits_used;
0030 };
0031 
0032 struct irdma_pble_info {
0033     u64 *addr;
0034     u32 idx;
0035     u32 cnt;
0036     struct irdma_pble_chunkinfo chunkinfo;
0037 };
0038 
0039 struct irdma_pble_level2 {
0040     struct irdma_pble_info root;
0041     struct irdma_pble_info *leaf;
0042     struct irdma_virt_mem leafmem;
0043     u32 leaf_cnt;
0044 };
0045 
0046 struct irdma_pble_alloc {
0047     u32 total_cnt;
0048     enum irdma_pble_level level;
0049     union {
0050         struct irdma_pble_info level1;
0051         struct irdma_pble_level2 level2;
0052     };
0053 };
0054 
0055 struct sd_pd_idx {
0056     u32 sd_idx;
0057     u32 pd_idx;
0058     u32 rel_pd_idx;
0059 };
0060 
0061 struct irdma_add_page_info {
0062     struct irdma_chunk *chunk;
0063     struct irdma_hmc_sd_entry *sd_entry;
0064     struct irdma_hmc_info *hmc_info;
0065     struct sd_pd_idx idx;
0066     u32 pages;
0067 };
0068 
0069 struct irdma_chunk {
0070     struct list_head list;
0071     struct irdma_dma_info dmainfo;
0072     unsigned long *bitmapbuf;
0073 
0074     u32 sizeofbitmap;
0075     u64 size;
0076     void *vaddr;
0077     u64 fpm_addr;
0078     u32 pg_cnt;
0079     enum irdma_alloc_type type;
0080     struct irdma_sc_dev *dev;
0081     struct irdma_virt_mem chunkmem;
0082 };
0083 
0084 struct irdma_pble_prm {
0085     struct list_head clist;
0086     spinlock_t prm_lock; /* protect prm bitmap */
0087     u64 total_pble_alloc;
0088     u64 free_pble_cnt;
0089     u8 pble_shift;
0090 };
0091 
0092 struct irdma_hmc_pble_rsrc {
0093     u32 unallocated_pble;
0094     struct mutex pble_mutex_lock; /* protect PBLE resource */
0095     struct irdma_sc_dev *dev;
0096     u64 fpm_base_addr;
0097     u64 next_fpm_addr;
0098     struct irdma_pble_prm pinfo;
0099     u64 allocdpbles;
0100     u64 freedpbles;
0101     u32 stats_direct_sds;
0102     u32 stats_paged_sds;
0103     u64 stats_alloc_ok;
0104     u64 stats_alloc_fail;
0105     u64 stats_alloc_freed;
0106     u64 stats_lvl1;
0107     u64 stats_lvl2;
0108 };
0109 
0110 void irdma_destroy_pble_prm(struct irdma_hmc_pble_rsrc *pble_rsrc);
0111 int irdma_hmc_init_pble(struct irdma_sc_dev *dev,
0112             struct irdma_hmc_pble_rsrc *pble_rsrc);
0113 void irdma_free_pble(struct irdma_hmc_pble_rsrc *pble_rsrc,
0114              struct irdma_pble_alloc *palloc);
0115 int irdma_get_pble(struct irdma_hmc_pble_rsrc *pble_rsrc,
0116            struct irdma_pble_alloc *palloc, u32 pble_cnt,
0117            bool level1_only);
0118 int irdma_prm_add_pble_mem(struct irdma_pble_prm *pprm,
0119                struct irdma_chunk *pchunk);
0120 int irdma_prm_get_pbles(struct irdma_pble_prm *pprm,
0121             struct irdma_pble_chunkinfo *chunkinfo, u64 mem_size,
0122             u64 **vaddr, u64 *fpm_addr);
0123 void irdma_prm_return_pbles(struct irdma_pble_prm *pprm,
0124                 struct irdma_pble_chunkinfo *chunkinfo);
0125 void irdma_pble_acquire_lock(struct irdma_hmc_pble_rsrc *pble_rsrc,
0126                  unsigned long *flags);
0127 void irdma_pble_release_lock(struct irdma_hmc_pble_rsrc *pble_rsrc,
0128                  unsigned long *flags);
0129 void irdma_pble_free_paged_mem(struct irdma_chunk *chunk);
0130 int irdma_pble_get_paged_mem(struct irdma_chunk *chunk, u32 pg_cnt);
0131 void irdma_prm_rem_bitmapmem(struct irdma_hw *hw, struct irdma_chunk *chunk);
0132 #endif /* IRDMA_PBLE_H */