1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * CXL Flash Device Driver 4 * 5 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 6 * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 7 * 8 * Copyright (C) 2015 IBM Corporation 9 */ 10 11 #ifndef _CXLFLASH_VLUN_H 12 #define _CXLFLASH_VLUN_H 13 14 /* RHT - Resource Handle Table */ 15 #define MC_RHT_NMASK 16 /* in bits */ 16 #define MC_CHUNK_SHIFT MC_RHT_NMASK /* shift to go from LBA to chunk# */ 17 18 #define HIBIT (BITS_PER_LONG - 1) 19 20 #define MAX_AUN_CLONE_CNT 0xFF 21 22 /* 23 * LXT - LBA Translation Table 24 * 25 * +-------+-------+-------+-------+-------+-------+-------+---+---+ 26 * | RLBA_BASE |LUN_IDX| P |SEL| 27 * +-------+-------+-------+-------+-------+-------+-------+---+---+ 28 * 29 * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE). 30 * AFU ORes the low order bits from the virtual LBA (offset into the chunk) 31 * with RLBA_BASE. The result is the physical LBA to be sent to storage. 32 * The LXT Entry also contains an index to a LUN TBL and a bitmask of which 33 * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed 34 * with a global port select bit-mask maintained by the driver. 35 * In addition, it has permission bits that are ANDed with the 36 * RHT permissions to arrive at the final permissions for the chunk. 37 * 38 * LXT tables are allocated dynamically in groups. This is done to avoid 39 * a malloc/free overhead each time the LXT has to grow or shrink. 40 * 41 * Based on the current lxt_cnt (used), it is always possible to know 42 * how many are allocated (used+free). The number of allocated entries is 43 * not stored anywhere. 44 * 45 * The LXT table is re-allocated whenever it needs to cross into another group. 46 */ 47 #define LXT_GROUP_SIZE 8 48 #define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */ 49 #define LXT_LUNIDX_SHIFT 8 /* LXT entry, shift for LUN index */ 50 #define LXT_PERM_SHIFT 4 /* LXT entry, shift for permission bits */ 51 52 struct ba_lun_info { 53 u64 *lun_alloc_map; 54 u32 lun_bmap_size; 55 u32 total_aus; 56 u64 free_aun_cnt; 57 58 /* indices to be used for elevator lookup of free map */ 59 u32 free_low_idx; 60 u32 free_curr_idx; 61 u32 free_high_idx; 62 63 u8 *aun_clone_map; 64 }; 65 66 struct ba_lun { 67 u64 lun_id; 68 u64 wwpn; 69 size_t lsize; /* LUN size in number of LBAs */ 70 size_t lba_size; /* LBA size in number of bytes */ 71 size_t au_size; /* Allocation Unit size in number of LBAs */ 72 struct ba_lun_info *ba_lun_handle; 73 }; 74 75 /* Block Allocator */ 76 struct blka { 77 struct ba_lun ba_lun; 78 u64 nchunk; /* number of chunks */ 79 struct mutex mutex; 80 }; 81 82 #endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 83