83 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 * CXL Flash Device Driver4 *5 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation6 * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation7 *8 * Copyright (C) 2015 IBM Corporation9 */10 11#ifndef _CXLFLASH_VLUN_H12#define _CXLFLASH_VLUN_H13 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 0xFF21 22/*23 * LXT - LBA Translation Table24 *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 which33 * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed34 * with a global port select bit-mask maintained by the driver.35 * In addition, it has permission bits that are ANDed with the36 * RHT permissions to arrive at the final permissions for the chunk.37 *38 * LXT tables are allocated dynamically in groups. This is done to avoid39 * 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 know42 * how many are allocated (used+free). The number of allocated entries is43 * 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 848#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 52struct 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 66struct 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 */76struct 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