Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * CXL Flash Device Driver
0004  *
0005  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
0006  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
0007  *
0008  * Copyright (C) 2015 IBM Corporation
0009  */
0010 
0011 #ifndef _CXLFLASH_VLUN_H
0012 #define _CXLFLASH_VLUN_H
0013 
0014 /* RHT - Resource Handle Table */
0015 #define MC_RHT_NMASK      16    /* in bits */
0016 #define MC_CHUNK_SHIFT    MC_RHT_NMASK  /* shift to go from LBA to chunk# */
0017 
0018 #define HIBIT             (BITS_PER_LONG - 1)
0019 
0020 #define MAX_AUN_CLONE_CNT 0xFF
0021 
0022 /*
0023  * LXT - LBA Translation Table
0024  *
0025  * +-------+-------+-------+-------+-------+-------+-------+---+---+
0026  * | RLBA_BASE                                     |LUN_IDX| P |SEL|
0027  * +-------+-------+-------+-------+-------+-------+-------+---+---+
0028  *
0029  * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE).
0030  * AFU ORes the low order bits from the virtual LBA (offset into the chunk)
0031  * with RLBA_BASE. The result is the physical LBA to be sent to storage.
0032  * The LXT Entry also contains an index to a LUN TBL and a bitmask of which
0033  * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed
0034  * with a global port select bit-mask maintained by the driver.
0035  * In addition, it has permission bits that are ANDed with the
0036  * RHT permissions to arrive at the final permissions for the chunk.
0037  *
0038  * LXT tables are allocated dynamically in groups. This is done to avoid
0039  * a malloc/free overhead each time the LXT has to grow or shrink.
0040  *
0041  * Based on the current lxt_cnt (used), it is always possible to know
0042  * how many are allocated (used+free). The number of allocated entries is
0043  * not stored anywhere.
0044  *
0045  * The LXT table is re-allocated whenever it needs to cross into another group.
0046  */
0047 #define LXT_GROUP_SIZE          8
0048 #define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */
0049 #define LXT_LUNIDX_SHIFT  8 /* LXT entry, shift for LUN index */
0050 #define LXT_PERM_SHIFT    4 /* LXT entry, shift for permission bits */
0051 
0052 struct ba_lun_info {
0053     u64 *lun_alloc_map;
0054     u32 lun_bmap_size;
0055     u32 total_aus;
0056     u64 free_aun_cnt;
0057 
0058     /* indices to be used for elevator lookup of free map */
0059     u32 free_low_idx;
0060     u32 free_curr_idx;
0061     u32 free_high_idx;
0062 
0063     u8 *aun_clone_map;
0064 };
0065 
0066 struct ba_lun {
0067     u64 lun_id;
0068     u64 wwpn;
0069     size_t lsize;       /* LUN size in number of LBAs             */
0070     size_t lba_size;    /* LBA size in number of bytes            */
0071     size_t au_size;     /* Allocation Unit size in number of LBAs */
0072     struct ba_lun_info *ba_lun_handle;
0073 };
0074 
0075 /* Block Allocator */
0076 struct blka {
0077     struct ba_lun ba_lun;
0078     u64 nchunk;     /* number of chunks */
0079     struct mutex mutex;
0080 };
0081 
0082 #endif /* ifndef _CXLFLASH_SUPERPIPE_H */