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