18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CXL Flash Device Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 68c2ecf20Sopenharmony_ci * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 2015 IBM Corporation 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef _CXLFLASH_VLUN_H 128c2ecf20Sopenharmony_ci#define _CXLFLASH_VLUN_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* RHT - Resource Handle Table */ 158c2ecf20Sopenharmony_ci#define MC_RHT_NMASK 16 /* in bits */ 168c2ecf20Sopenharmony_ci#define MC_CHUNK_SHIFT MC_RHT_NMASK /* shift to go from LBA to chunk# */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define HIBIT (BITS_PER_LONG - 1) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define MAX_AUN_CLONE_CNT 0xFF 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * LXT - LBA Translation Table 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * +-------+-------+-------+-------+-------+-------+-------+---+---+ 268c2ecf20Sopenharmony_ci * | RLBA_BASE |LUN_IDX| P |SEL| 278c2ecf20Sopenharmony_ci * +-------+-------+-------+-------+-------+-------+-------+---+---+ 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE). 308c2ecf20Sopenharmony_ci * AFU ORes the low order bits from the virtual LBA (offset into the chunk) 318c2ecf20Sopenharmony_ci * with RLBA_BASE. The result is the physical LBA to be sent to storage. 328c2ecf20Sopenharmony_ci * The LXT Entry also contains an index to a LUN TBL and a bitmask of which 338c2ecf20Sopenharmony_ci * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed 348c2ecf20Sopenharmony_ci * with a global port select bit-mask maintained by the driver. 358c2ecf20Sopenharmony_ci * In addition, it has permission bits that are ANDed with the 368c2ecf20Sopenharmony_ci * RHT permissions to arrive at the final permissions for the chunk. 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * LXT tables are allocated dynamically in groups. This is done to avoid 398c2ecf20Sopenharmony_ci * a malloc/free overhead each time the LXT has to grow or shrink. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * Based on the current lxt_cnt (used), it is always possible to know 428c2ecf20Sopenharmony_ci * how many are allocated (used+free). The number of allocated entries is 438c2ecf20Sopenharmony_ci * not stored anywhere. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * The LXT table is re-allocated whenever it needs to cross into another group. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci#define LXT_GROUP_SIZE 8 488c2ecf20Sopenharmony_ci#define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */ 498c2ecf20Sopenharmony_ci#define LXT_LUNIDX_SHIFT 8 /* LXT entry, shift for LUN index */ 508c2ecf20Sopenharmony_ci#define LXT_PERM_SHIFT 4 /* LXT entry, shift for permission bits */ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct ba_lun_info { 538c2ecf20Sopenharmony_ci u64 *lun_alloc_map; 548c2ecf20Sopenharmony_ci u32 lun_bmap_size; 558c2ecf20Sopenharmony_ci u32 total_aus; 568c2ecf20Sopenharmony_ci u64 free_aun_cnt; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci /* indices to be used for elevator lookup of free map */ 598c2ecf20Sopenharmony_ci u32 free_low_idx; 608c2ecf20Sopenharmony_ci u32 free_curr_idx; 618c2ecf20Sopenharmony_ci u32 free_high_idx; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci u8 *aun_clone_map; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistruct ba_lun { 678c2ecf20Sopenharmony_ci u64 lun_id; 688c2ecf20Sopenharmony_ci u64 wwpn; 698c2ecf20Sopenharmony_ci size_t lsize; /* LUN size in number of LBAs */ 708c2ecf20Sopenharmony_ci size_t lba_size; /* LBA size in number of bytes */ 718c2ecf20Sopenharmony_ci size_t au_size; /* Allocation Unit size in number of LBAs */ 728c2ecf20Sopenharmony_ci struct ba_lun_info *ba_lun_handle; 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Block Allocator */ 768c2ecf20Sopenharmony_cistruct blka { 778c2ecf20Sopenharmony_ci struct ba_lun ba_lun; 788c2ecf20Sopenharmony_ci u64 nchunk; /* number of chunks */ 798c2ecf20Sopenharmony_ci struct mutex mutex; 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 83