Skip to content

Commit 2cb7926

Browse files
Matthew R. OchsJames Bottomley
authored andcommitted
cxlflash: Virtual LUN support
Add support for physical LUN segmentation (virtual LUNs) to device driver supporting the IBM CXL Flash adapter. This patch allows user space applications to virtually segment a physical LUN into N virtual LUNs, taking advantage of the translation features provided by this adapter. Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com> Signed-off-by: Manoj N. Kumar <manoj@linux.vnet.ibm.com> Reviewed-by: Michael Neuling <mikey@neuling.org> Reviewed-by: Wen Xiong <wenxiong@linux.vnet.ibm.com> Signed-off-by: James Bottomley <JBottomley@Odin.com>
1 parent 65be2c7 commit 2cb7926

11 files changed

Lines changed: 1550 additions & 17 deletions

File tree

‎Documentation/powerpc/cxlflash.txt‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ DK_CXLFLASH_ATTACH
163163

164164
- These tokens are only valid for the process under which they
165165
were created. The child of a forked process cannot continue
166-
to use the context id or file descriptor created by its parent.
166+
to use the context id or file descriptor created by its parent
167+
(see DK_CXLFLASH_VLUN_CLONE for further details).
167168

168169
- These tokens are only valid for the lifetime of the context and
169170
the process under which they were created. Once either is
@@ -193,6 +194,45 @@ DK_CXLFLASH_USER_DIRECT
193194
treated as a resource handle that is returned to the user. The user
194195
is then able to use the handle to reference the LUN during I/O.
195196

197+
DK_CXLFLASH_USER_VIRTUAL
198+
------------------------
199+
This ioctl is responsible for transitioning the LUN to virtual mode
200+
of access and configuring the AFU for virtual access from user space
201+
on a per-context basis. Additionally, the block size and last logical
202+
block address (LBA) are returned to the user.
203+
204+
As mentioned previously, when operating in user space access mode,
205+
LUNs may be accessed in whole or in part. Only one mode is allowed
206+
at a time and if one mode is active (outstanding references exist),
207+
requests to use the LUN in a different mode are denied.
208+
209+
The AFU is configured for virtual access from user space by adding
210+
an entry to the AFU's resource handle table. The index of the entry
211+
is treated as a resource handle that is returned to the user. The
212+
user is then able to use the handle to reference the LUN during I/O.
213+
214+
By default, the virtual LUN is created with a size of 0. The user
215+
would need to use the DK_CXLFLASH_VLUN_RESIZE ioctl to adjust the grow
216+
the virtual LUN to a desired size. To avoid having to perform this
217+
resize for the initial creation of the virtual LUN, the user has the
218+
option of specifying a size as part of the DK_CXLFLASH_USER_VIRTUAL
219+
ioctl, such that when success is returned to the user, the
220+
resource handle that is provided is already referencing provisioned
221+
storage. This is reflected by the last LBA being a non-zero value.
222+
223+
DK_CXLFLASH_VLUN_RESIZE
224+
-----------------------
225+
This ioctl is responsible for resizing a previously created virtual
226+
LUN and will fail if invoked upon a LUN that is not in virtual
227+
mode. Upon success, an updated last LBA is returned to the user
228+
indicating the new size of the virtual LUN associated with the
229+
resource handle.
230+
231+
The partitioning of virtual LUNs is jointly mediated by the cxlflash
232+
driver and the AFU. An allocation table is kept for each LUN that is
233+
operating in the virtual mode and used to program a LUN translation
234+
table that the AFU references when provided with a resource handle.
235+
196236
DK_CXLFLASH_RELEASE
197237
-------------------
198238
This ioctl is responsible for releasing a previously obtained
@@ -214,6 +254,27 @@ DK_CXLFLASH_DETACH
214254
success, all "tokens" which had been provided to the user from the
215255
DK_CXLFLASH_ATTACH onward are no longer valid.
216256

257+
DK_CXLFLASH_VLUN_CLONE
258+
----------------------
259+
This ioctl is responsible for cloning a previously created
260+
context to a more recently created context. It exists solely to
261+
support maintaining user space access to storage after a process
262+
forks. Upon success, the child process (which invoked the ioctl)
263+
will have access to the same LUNs via the same resource handle(s)
264+
and fd2 as the parent, but under a different context.
265+
266+
Context sharing across processes is not supported with CXL and
267+
therefore each fork must be met with establishing a new context
268+
for the child process. This ioctl simplifies the state management
269+
and playback required by a user in such a scenario. When a process
270+
forks, child process can clone the parents context by first creating
271+
a context (via DK_CXLFLASH_ATTACH) and then using this ioctl to
272+
perform the clone from the parent to the child.
273+
274+
The clone itself is fairly simple. The resource handle and lun
275+
translation tables are copied from the parent context to the child's
276+
and then synced with the AFU.
277+
217278
DK_CXLFLASH_VERIFY
218279
------------------
219280
This ioctl is used to detect various changes such as the capacity of

‎drivers/scsi/cxlflash/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
obj-$(CONFIG_CXLFLASH) += cxlflash.o
2-
cxlflash-y += main.o superpipe.o lunmgt.o
2+
cxlflash-y += main.o superpipe.o lunmgt.o vlun.o

‎drivers/scsi/cxlflash/common.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ struct cxlflash_cfg {
116116

117117
atomic_t num_user_contexts;
118118

119+
/* Parameters that are LUN table related */
120+
int last_lun_index[CXLFLASH_NUM_FC_PORTS];
121+
int promote_lun_index;
119122
struct list_head lluns; /* list of llun_info structs */
120123

121124
wait_queue_head_t tmf_waitq;
@@ -200,5 +203,6 @@ int cxlflash_ioctl(struct scsi_device *, int, void __user *);
200203
void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *);
201204
int cxlflash_mark_contexts_error(struct cxlflash_cfg *);
202205
void cxlflash_term_local_luns(struct cxlflash_cfg *);
206+
void cxlflash_restore_luntable(struct cxlflash_cfg *);
203207

204208
#endif /* ifndef _CXLFLASH_COMMON_H */

‎drivers/scsi/cxlflash/lunmgt.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "sislite.h"
2222
#include "common.h"
23+
#include "vlun.h"
2324
#include "superpipe.h"
2425

2526
/**
@@ -42,6 +43,7 @@ static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)
4243
lli->sdev = sdev;
4344
lli->newly_created = true;
4445
lli->host_no = sdev->host->host_no;
46+
lli->in_table = false;
4547

4648
memcpy(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
4749
out:
@@ -208,6 +210,7 @@ void cxlflash_term_global_luns(void)
208210
mutex_lock(&global.mutex);
209211
list_for_each_entry_safe(gli, temp, &global.gluns, list) {
210212
list_del(&gli->list);
213+
cxlflash_ba_terminate(&gli->blka.ba_lun);
211214
kfree(gli);
212215
}
213216
mutex_unlock(&global.mutex);

‎drivers/scsi/cxlflash/main.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,8 @@ static int init_afu(struct cxlflash_cfg *cfg)
19891989
afu_err_intr_init(cfg->afu);
19901990
atomic64_set(&afu->room, readq_be(&afu->host_map->cmd_room));
19911991

1992+
/* Restore the LUN mappings */
1993+
cxlflash_restore_luntable(cfg);
19921994
err1:
19931995
pr_debug("%s: returning rc=%d\n", __func__, rc);
19941996
return rc;
@@ -2286,6 +2288,17 @@ static int cxlflash_probe(struct pci_dev *pdev,
22862288

22872289
cfg->init_state = INIT_STATE_NONE;
22882290
cfg->dev = pdev;
2291+
2292+
/*
2293+
* The promoted LUNs move to the top of the LUN table. The rest stay
2294+
* on the bottom half. The bottom half grows from the end
2295+
* (index = 255), whereas the top half grows from the beginning
2296+
* (index = 0).
2297+
*/
2298+
cfg->promote_lun_index = 0;
2299+
cfg->last_lun_index[0] = CXLFLASH_NUM_VLUNS/2 - 1;
2300+
cfg->last_lun_index[1] = CXLFLASH_NUM_VLUNS/2 - 1;
2301+
22892302
cfg->dev_id = (struct pci_device_id *)dev_id;
22902303
cfg->mcctx = NULL;
22912304

‎drivers/scsi/cxlflash/sislite.h‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,17 @@ struct cxlflash_afu_map {
397397
};
398398
};
399399

400-
/* LBA translation control blocks */
401-
400+
/*
401+
* LXT - LBA Translation Table
402+
* LXT control blocks
403+
*/
402404
struct sisl_lxt_entry {
403405
u64 rlba_base; /* bits 0:47 is base
404-
* b48:55 is lun index
405-
* b58:59 is write & read perms
406-
* (if no perm, afu_rc=0x15)
407-
* b60:63 is port_sel mask
408-
*/
409-
406+
* b48:55 is lun index
407+
* b58:59 is write & read perms
408+
* (if no perm, afu_rc=0x15)
409+
* b60:63 is port_sel mask
410+
*/
410411
};
411412

412413
/*
@@ -465,4 +466,7 @@ struct sisl_rht_entry_f1 {
465466
#define TMF_LUN_RESET 0x1U
466467
#define TMF_CLEAR_ACA 0x2U
467468

469+
470+
#define SISLITE_MAX_WS_BLOCKS 512
471+
468472
#endif /* _SISLITE_H */

0 commit comments

Comments
 (0)