162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * CXL Flash Device Driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 662306a36Sopenharmony_ci * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 2015 IBM Corporation 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef _CXLFLASH_VLUN_H 1262306a36Sopenharmony_ci#define _CXLFLASH_VLUN_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* RHT - Resource Handle Table */ 1562306a36Sopenharmony_ci#define MC_RHT_NMASK 16 /* in bits */ 1662306a36Sopenharmony_ci#define MC_CHUNK_SHIFT MC_RHT_NMASK /* shift to go from LBA to chunk# */ 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define HIBIT (BITS_PER_LONG - 1) 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define MAX_AUN_CLONE_CNT 0xFF 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * LXT - LBA Translation Table 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci * +-------+-------+-------+-------+-------+-------+-------+---+---+ 2662306a36Sopenharmony_ci * | RLBA_BASE |LUN_IDX| P |SEL| 2762306a36Sopenharmony_ci * +-------+-------+-------+-------+-------+-------+-------+---+---+ 2862306a36Sopenharmony_ci * 2962306a36Sopenharmony_ci * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE). 3062306a36Sopenharmony_ci * AFU ORes the low order bits from the virtual LBA (offset into the chunk) 3162306a36Sopenharmony_ci * with RLBA_BASE. The result is the physical LBA to be sent to storage. 3262306a36Sopenharmony_ci * The LXT Entry also contains an index to a LUN TBL and a bitmask of which 3362306a36Sopenharmony_ci * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed 3462306a36Sopenharmony_ci * with a global port select bit-mask maintained by the driver. 3562306a36Sopenharmony_ci * In addition, it has permission bits that are ANDed with the 3662306a36Sopenharmony_ci * RHT permissions to arrive at the final permissions for the chunk. 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci * LXT tables are allocated dynamically in groups. This is done to avoid 3962306a36Sopenharmony_ci * a malloc/free overhead each time the LXT has to grow or shrink. 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * Based on the current lxt_cnt (used), it is always possible to know 4262306a36Sopenharmony_ci * how many are allocated (used+free). The number of allocated entries is 4362306a36Sopenharmony_ci * not stored anywhere. 4462306a36Sopenharmony_ci * 4562306a36Sopenharmony_ci * The LXT table is re-allocated whenever it needs to cross into another group. 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_ci#define LXT_GROUP_SIZE 8 4862306a36Sopenharmony_ci#define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */ 4962306a36Sopenharmony_ci#define LXT_LUNIDX_SHIFT 8 /* LXT entry, shift for LUN index */ 5062306a36Sopenharmony_ci#define LXT_PERM_SHIFT 4 /* LXT entry, shift for permission bits */ 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistruct ba_lun_info { 5362306a36Sopenharmony_ci u64 *lun_alloc_map; 5462306a36Sopenharmony_ci u32 lun_bmap_size; 5562306a36Sopenharmony_ci u32 total_aus; 5662306a36Sopenharmony_ci u64 free_aun_cnt; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci /* indices to be used for elevator lookup of free map */ 5962306a36Sopenharmony_ci u32 free_low_idx; 6062306a36Sopenharmony_ci u32 free_curr_idx; 6162306a36Sopenharmony_ci u32 free_high_idx; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci u8 *aun_clone_map; 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistruct ba_lun { 6762306a36Sopenharmony_ci u64 lun_id; 6862306a36Sopenharmony_ci u64 wwpn; 6962306a36Sopenharmony_ci size_t lsize; /* LUN size in number of LBAs */ 7062306a36Sopenharmony_ci size_t lba_size; /* LBA size in number of bytes */ 7162306a36Sopenharmony_ci size_t au_size; /* Allocation Unit size in number of LBAs */ 7262306a36Sopenharmony_ci struct ba_lun_info *ba_lun_handle; 7362306a36Sopenharmony_ci}; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* Block Allocator */ 7662306a36Sopenharmony_cistruct blka { 7762306a36Sopenharmony_ci struct ba_lun ba_lun; 7862306a36Sopenharmony_ci u64 nchunk; /* number of chunks */ 7962306a36Sopenharmony_ci struct mutex mutex; 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 83