Skip to content

Commit bc88ac4

Browse files
Matthew R. Ochsmartinkpetersen
authored andcommitted
scsi: cxlflash: Support AFU debug
Adopt the SISLite AFU debug capability to allow future CXL Flash adapters the ability to better debug AFU issues. Update the SISLite header with the changes necessary to support AFU debug operations and create a host ioctl interface for user debug software. Also update the cxlflash documentation to describe this new host ioctl. Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com> Signed-off-by: Uma Krishnan <ukrishn@linux.vnet.ibm.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9cf43a3 commit bc88ac4

6 files changed

Lines changed: 152 additions & 3 deletions

File tree

‎Documentation/powerpc/cxlflash.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,17 @@ HT_CXLFLASH_LUN_PROVISION
413413

414414
With this information, the number of available LUNs and capacity can be
415415
can be calculated.
416+
417+
HT_CXLFLASH_AFU_DEBUG
418+
---------------------
419+
This ioctl is used to debug AFUs by supporting a command pass-through
420+
interface. It is only valid when used with AFUs that support the AFU
421+
debug capability.
422+
423+
With exception of buffer management, AFU debug commands are opaque to
424+
cxlflash and treated as pass-through. For debug commands that do require
425+
data transfer, the user supplies an adequately sized data buffer and must
426+
specify the data transfer direction with respect to the host. There is a
427+
maximum transfer size of 256K imposed. Note that partial read completions
428+
are not supported - when errors are experienced with a host read data
429+
transfer, the data buffer is not copied back to the user.

‎drivers/scsi/cxlflash/common.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ static inline bool afu_has_cap(struct afu *afu, u64 cap)
262262
return afu_cap & cap;
263263
}
264264

265+
static inline bool afu_is_afu_debug(struct afu *afu)
266+
{
267+
return afu_has_cap(afu, SISL_INTVER_CAP_AFU_DEBUG);
268+
}
269+
265270
static inline bool afu_is_lun_provision(struct afu *afu)
266271
{
267272
return afu_has_cap(afu, SISL_INTVER_CAP_LUN_PROVISION);

‎drivers/scsi/cxlflash/main.c‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,99 @@ static int cxlflash_lun_provision(struct cxlflash_cfg *cfg,
33253325
return rc;
33263326
}
33273327

3328+
/**
3329+
* cxlflash_afu_debug() - host AFU debug handler
3330+
* @cfg: Internal structure associated with the host.
3331+
* @arg: Kernel copy of userspace ioctl data structure.
3332+
*
3333+
* For debug requests requiring a data buffer, always provide an aligned
3334+
* (cache line) buffer to the AFU to appease any alignment requirements.
3335+
*
3336+
* Return: 0 on success, -errno on failure
3337+
*/
3338+
static int cxlflash_afu_debug(struct cxlflash_cfg *cfg,
3339+
struct ht_cxlflash_afu_debug *afu_dbg)
3340+
{
3341+
struct afu *afu = cfg->afu;
3342+
struct device *dev = &cfg->dev->dev;
3343+
struct sisl_ioarcb rcb;
3344+
struct sisl_ioasa asa;
3345+
char *buf = NULL;
3346+
char *kbuf = NULL;
3347+
void __user *ubuf = (__force void __user *)afu_dbg->data_ea;
3348+
u16 req_flags = SISL_REQ_FLAGS_AFU_CMD;
3349+
u32 ulen = afu_dbg->data_len;
3350+
bool is_write = afu_dbg->hdr.flags & HT_CXLFLASH_HOST_WRITE;
3351+
int rc = 0;
3352+
3353+
if (!afu_is_afu_debug(afu)) {
3354+
rc = -ENOTSUPP;
3355+
goto out;
3356+
}
3357+
3358+
if (ulen) {
3359+
req_flags |= SISL_REQ_FLAGS_SUP_UNDERRUN;
3360+
3361+
if (ulen > HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN) {
3362+
rc = -EINVAL;
3363+
goto out;
3364+
}
3365+
3366+
if (unlikely(!access_ok(is_write ? VERIFY_READ : VERIFY_WRITE,
3367+
ubuf, ulen))) {
3368+
rc = -EFAULT;
3369+
goto out;
3370+
}
3371+
3372+
buf = kmalloc(ulen + cache_line_size() - 1, GFP_KERNEL);
3373+
if (unlikely(!buf)) {
3374+
rc = -ENOMEM;
3375+
goto out;
3376+
}
3377+
3378+
kbuf = PTR_ALIGN(buf, cache_line_size());
3379+
3380+
if (is_write) {
3381+
req_flags |= SISL_REQ_FLAGS_HOST_WRITE;
3382+
3383+
rc = copy_from_user(kbuf, ubuf, ulen);
3384+
if (unlikely(rc))
3385+
goto out;
3386+
}
3387+
}
3388+
3389+
memset(&rcb, 0, sizeof(rcb));
3390+
memset(&asa, 0, sizeof(asa));
3391+
3392+
rcb.req_flags = req_flags;
3393+
rcb.msi = SISL_MSI_RRQ_UPDATED;
3394+
rcb.timeout = MC_AFU_DEBUG_TIMEOUT;
3395+
rcb.ioasa = &asa;
3396+
3397+
if (ulen) {
3398+
rcb.data_len = ulen;
3399+
rcb.data_ea = (uintptr_t)kbuf;
3400+
}
3401+
3402+
rcb.cdb[0] = SISL_AFU_CMD_DEBUG;
3403+
memcpy(&rcb.cdb[4], afu_dbg->afu_subcmd,
3404+
HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN);
3405+
3406+
rc = send_afu_cmd(afu, &rcb);
3407+
if (rc) {
3408+
dev_err(dev, "%s: send_afu_cmd failed rc=%d asc=%08x afux=%x\n",
3409+
__func__, rc, asa.ioasc, asa.afu_extra);
3410+
goto out;
3411+
}
3412+
3413+
if (ulen && !is_write)
3414+
rc = copy_to_user(ubuf, kbuf, ulen);
3415+
out:
3416+
kfree(buf);
3417+
dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
3418+
return rc;
3419+
}
3420+
33283421
/**
33293422
* cxlflash_chr_ioctl() - character device IOCTL handler
33303423
* @file: File pointer for this device.
@@ -3363,6 +3456,8 @@ static long cxlflash_chr_ioctl(struct file *file, unsigned int cmd,
33633456
} ioctl_tbl[] = { /* NOTE: order matters here */
33643457
{ sizeof(struct ht_cxlflash_lun_provision),
33653458
(hioctl)cxlflash_lun_provision },
3459+
{ sizeof(struct ht_cxlflash_afu_debug),
3460+
(hioctl)cxlflash_afu_debug },
33663461
};
33673462

33683463
/* Hold read semaphore so we can drain if needed */
@@ -3373,6 +3468,7 @@ static long cxlflash_chr_ioctl(struct file *file, unsigned int cmd,
33733468

33743469
switch (cmd) {
33753470
case HT_CXLFLASH_LUN_PROVISION:
3471+
case HT_CXLFLASH_AFU_DEBUG:
33763472
known_ioctl = true;
33773473
idx = _IOC_NR(HT_CXLFLASH_LUN_PROVISION) - _IOC_NR(cmd);
33783474
size = ioctl_tbl[idx].size;

‎drivers/scsi/cxlflash/main.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
/* AFU command timeout values */
6969
#define MC_AFU_SYNC_TIMEOUT 5 /* 5 secs */
7070
#define MC_LUN_PROV_TIMEOUT 5 /* 5 secs */
71+
#define MC_AFU_DEBUG_TIMEOUT 5 /* 5 secs */
7172

7273
/* AFU command room retry limit */
7374
#define MC_ROOM_RETRY_CNT 10

‎drivers/scsi/cxlflash/sislite.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct sisl_ioarcb {
7474
u8 cdb[16]; /* must be in big endian */
7575
#define SISL_AFU_CMD_SYNC 0xC0 /* AFU sync command */
7676
#define SISL_AFU_CMD_LUN_PROVISION 0xD0 /* AFU LUN provision command */
77+
#define SISL_AFU_CMD_DEBUG 0xE0 /* AFU debug command */
7778

7879
#define SISL_AFU_LUN_PROVISION_CREATE 0x00 /* LUN provision create type */
7980
#define SISL_AFU_LUN_PROVISION_DELETE 0x01 /* LUN provision delete type */
@@ -412,6 +413,7 @@ struct sisl_global_regs {
412413
#define SISL_INTVER_CAP_RESERVED_CMD_MODE_A 0x200000000000ULL
413414
#define SISL_INTVER_CAP_RESERVED_CMD_MODE_B 0x100000000000ULL
414415
#define SISL_INTVER_CAP_LUN_PROVISION 0x080000000000ULL
416+
#define SISL_INTVER_CAP_AFU_DEBUG 0x040000000000ULL
415417
};
416418

417419
#define CXLFLASH_NUM_FC_PORTS_PER_BANK 2 /* fixed # of ports per bank */

‎include/uapi/scsi/cxlflash_ioctl.h‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
#include <linux/types.h>
1919

20+
/*
21+
* Structure and definitions for all CXL Flash ioctls
22+
*/
23+
#define CXLFLASH_WWID_LEN 16
24+
2025
/*
2126
* Structure and flag definitions CXL Flash superpipe ioctls
2227
*/
@@ -151,7 +156,7 @@ struct dk_cxlflash_recover_afu {
151156
__u64 reserved[8]; /* Reserved for future use */
152157
};
153158

154-
#define DK_CXLFLASH_MANAGE_LUN_WWID_LEN 16
159+
#define DK_CXLFLASH_MANAGE_LUN_WWID_LEN CXLFLASH_WWID_LEN
155160
#define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL
156161
#define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL
157162
#define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL
@@ -209,27 +214,52 @@ struct ht_cxlflash_hdr {
209214
__u64 return_flags; /* Returned flags */
210215
};
211216

217+
/*
218+
* Input flag definitions available to all host ioctls
219+
*
220+
* These are grown from the bottom-up with the intention that ioctl-specific
221+
* input flag definitions would grow from the top-down, allowing the two sets
222+
* to co-exist. While not required/enforced at this time, this provides future
223+
* flexibility.
224+
*/
225+
#define HT_CXLFLASH_HOST_READ 0x0000000000000000ULL
226+
#define HT_CXLFLASH_HOST_WRITE 0x0000000000000001ULL
227+
212228
#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_CREATE_LUN 0x0001
213229
#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_DELETE_LUN 0x0002
214230
#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_QUERY_PORT 0x0003
215-
#define HT_CXLFLASH_LUN_PROVISION_WWID_LEN 16
216231

217232
struct ht_cxlflash_lun_provision {
218233
struct ht_cxlflash_hdr hdr; /* Common fields */
219234
__u16 port; /* Target port for provision request */
220235
__u16 reserved16[3]; /* Reserved for future use */
221236
__u64 size; /* Size of LUN (4K blocks) */
222237
__u64 lun_id; /* SCSI LUN ID */
223-
__u8 wwid[HT_CXLFLASH_LUN_PROVISION_WWID_LEN]; /* Page83 WWID, NAA-6 */
238+
__u8 wwid[CXLFLASH_WWID_LEN];/* Page83 WWID, NAA-6 */
224239
__u64 max_num_luns; /* Maximum number of LUNs provisioned */
225240
__u64 cur_num_luns; /* Current number of LUNs provisioned */
226241
__u64 max_cap_port; /* Total capacity for port (4K blocks) */
227242
__u64 cur_cap_port; /* Current capacity for port (4K blocks) */
228243
__u64 reserved[8]; /* Reserved for future use */
229244
};
230245

246+
#define HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN 262144 /* 256K */
247+
#define HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN 12
248+
struct ht_cxlflash_afu_debug {
249+
struct ht_cxlflash_hdr hdr; /* Common fields */
250+
__u8 reserved8[4]; /* Reserved for future use */
251+
__u8 afu_subcmd[HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN]; /* AFU subcommand,
252+
* (pass through)
253+
*/
254+
__u64 data_ea; /* Data buffer effective address */
255+
__u32 data_len; /* Data buffer length */
256+
__u32 reserved32; /* Reserved for future use */
257+
__u64 reserved[8]; /* Reserved for future use */
258+
};
259+
231260
union cxlflash_ht_ioctls {
232261
struct ht_cxlflash_lun_provision lun_provision;
262+
struct ht_cxlflash_afu_debug afu_debug;
233263
};
234264

235265
#define MAX_HT_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ht_ioctls))
@@ -239,6 +269,7 @@ union cxlflash_ht_ioctls {
239269
* region (0xBF) and grow downwards.
240270
*/
241271
#define HT_CXLFLASH_LUN_PROVISION CXL_IOWR(0xBF, ht_cxlflash_lun_provision)
272+
#define HT_CXLFLASH_AFU_DEBUG CXL_IOWR(0xBE, ht_cxlflash_afu_debug)
242273

243274

244275
#endif /* ifndef _CXLFLASH_IOCTL_H */

0 commit comments

Comments
 (0)