Skip to content

Commit 27d4dc7

Browse files
vaibhav92mpe
authored andcommitted
cxl: Implement an ioctl to fetch afu card-id, offset-id and mode
Given a file descriptor on an afu device, libcxl currently uses the major/minor number obtained from fstat on the fd to construct path to the afu's sysfs directory. However it is possible that rather than using one of the device in /dev/cxl, a kernel driver creates its own device which export generic cxl interface to the userspace. This causes problems with libcxl as it tries to use a wrong major/minor number to construct the sysfs path and fail. So this patch introduces a new ioctl called CXL_IOCTL_GET_AFU_ID on the afu file descriptor to fetch the cxl_afu_id struct that holds the card/offset-id and mode information. These info is then used by libcxl to construct the correct path to the afu sysfs directory. Testing: - Build against pseries be/le configs - Testing with corresponding libcxl changes to verify that it constructs right sysfs path to the afu. Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com> Acked-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 989898b commit 27d4dc7

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎drivers/misc/cxl/cxl.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
315315
#define CXL_MAX_SLICES 4
316316
#define MAX_AFU_MMIO_REGS 3
317317

318-
#define CXL_MODE_DEDICATED 0x1
319-
#define CXL_MODE_DIRECTED 0x2
320318
#define CXL_MODE_TIME_SLICED 0x4
321319
#define CXL_SUPPORTED_MODES (CXL_MODE_DEDICATED | CXL_MODE_DIRECTED)
322320

‎drivers/misc/cxl/file.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ static long afu_ioctl_process_element(struct cxl_context *ctx,
212212
return 0;
213213
}
214214

215+
static long afu_ioctl_get_afu_id(struct cxl_context *ctx,
216+
struct cxl_afu_id __user *upafuid)
217+
{
218+
struct cxl_afu_id afuid = { 0 };
219+
220+
afuid.card_id = ctx->afu->adapter->adapter_num;
221+
afuid.afu_offset = ctx->afu->slice;
222+
afuid.afu_mode = ctx->afu->current_mode;
223+
224+
/* set the flag bit in case the afu is a slave */
225+
if (ctx->afu->current_mode == CXL_MODE_DIRECTED && !ctx->master)
226+
afuid.flags |= CXL_AFUID_FLAG_SLAVE;
227+
228+
if (copy_to_user(upafuid, &afuid, sizeof(afuid)))
229+
return -EFAULT;
230+
231+
return 0;
232+
}
233+
215234
static long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
216235
{
217236
struct cxl_context *ctx = file->private_data;
@@ -225,6 +244,9 @@ static long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
225244
return afu_ioctl_start_work(ctx, (struct cxl_ioctl_start_work __user *)arg);
226245
case CXL_IOCTL_GET_PROCESS_ELEMENT:
227246
return afu_ioctl_process_element(ctx, (__u32 __user *)arg);
247+
case CXL_IOCTL_GET_AFU_ID:
248+
return afu_ioctl_get_afu_id(ctx, (struct cxl_afu_id __user *)
249+
arg);
228250
}
229251
return -EINVAL;
230252
}

‎include/uapi/misc/cxl.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,32 @@ struct cxl_ioctl_start_work {
3232
#define CXL_START_WORK_ALL (CXL_START_WORK_AMR |\
3333
CXL_START_WORK_NUM_IRQS)
3434

35+
36+
/* Possible modes that an afu can be in */
37+
#define CXL_MODE_DEDICATED 0x1
38+
#define CXL_MODE_DIRECTED 0x2
39+
40+
/* possible flags for the cxl_afu_id flags field */
41+
#define CXL_AFUID_FLAG_SLAVE 0x1 /* In directed-mode afu is in slave mode */
42+
43+
struct cxl_afu_id {
44+
__u64 flags; /* One of CXL_AFUID_FLAG_X */
45+
__u32 card_id;
46+
__u32 afu_offset;
47+
__u32 afu_mode; /* one of the CXL_MODE_X */
48+
__u32 reserved1;
49+
__u64 reserved2;
50+
__u64 reserved3;
51+
__u64 reserved4;
52+
__u64 reserved5;
53+
__u64 reserved6;
54+
};
55+
3556
/* ioctl numbers */
3657
#define CXL_MAGIC 0xCA
3758
#define CXL_IOCTL_START_WORK _IOW(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)
3859
#define CXL_IOCTL_GET_PROCESS_ELEMENT _IOR(CXL_MAGIC, 0x01, __u32)
60+
#define CXL_IOCTL_GET_AFU_ID _IOR(CXL_MAGIC, 0x02, struct cxl_afu_id)
3961

4062
#define CXL_READ_MIN_SIZE 0x1000 /* 4K */
4163

0 commit comments

Comments
 (0)