aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/cxl/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/cxl/file.c')
-rw-r--r--drivers/misc/cxl/file.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 2364bcadb9a9..e3f4b69527a9 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -96,7 +96,8 @@ err_put_adapter:
96 put_device(&adapter->dev); 96 put_device(&adapter->dev);
97 return rc; 97 return rc;
98} 98}
99static int afu_open(struct inode *inode, struct file *file) 99
100int afu_open(struct inode *inode, struct file *file)
100{ 101{
101 return __afu_open(inode, file, false); 102 return __afu_open(inode, file, false);
102} 103}
@@ -106,7 +107,7 @@ static int afu_master_open(struct inode *inode, struct file *file)
106 return __afu_open(inode, file, true); 107 return __afu_open(inode, file, true);
107} 108}
108 109
109static int afu_release(struct inode *inode, struct file *file) 110int afu_release(struct inode *inode, struct file *file)
110{ 111{
111 struct cxl_context *ctx = file->private_data; 112 struct cxl_context *ctx = file->private_data;
112 113
@@ -128,7 +129,6 @@ static int afu_release(struct inode *inode, struct file *file)
128 */ 129 */
129 cxl_context_free(ctx); 130 cxl_context_free(ctx);
130 131
131 cxl_ctx_put();
132 return 0; 132 return 0;
133} 133}
134 134
@@ -191,7 +191,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
191 191
192 if ((rc = cxl_attach_process(ctx, false, work.work_element_descriptor, 192 if ((rc = cxl_attach_process(ctx, false, work.work_element_descriptor,
193 amr))) { 193 amr))) {
194 afu_release_irqs(ctx); 194 afu_release_irqs(ctx, ctx);
195 goto out; 195 goto out;
196 } 196 }
197 197
@@ -212,7 +212,26 @@ static long afu_ioctl_process_element(struct cxl_context *ctx,
212 return 0; 212 return 0;
213} 213}
214 214
215static long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 215static 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
234long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
216{ 235{
217 struct cxl_context *ctx = file->private_data; 236 struct cxl_context *ctx = file->private_data;
218 237
@@ -225,17 +244,20 @@ static long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
225 return afu_ioctl_start_work(ctx, (struct cxl_ioctl_start_work __user *)arg); 244 return afu_ioctl_start_work(ctx, (struct cxl_ioctl_start_work __user *)arg);
226 case CXL_IOCTL_GET_PROCESS_ELEMENT: 245 case CXL_IOCTL_GET_PROCESS_ELEMENT:
227 return afu_ioctl_process_element(ctx, (__u32 __user *)arg); 246 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);
228 } 250 }
229 return -EINVAL; 251 return -EINVAL;
230} 252}
231 253
232static long afu_compat_ioctl(struct file *file, unsigned int cmd, 254long afu_compat_ioctl(struct file *file, unsigned int cmd,
233 unsigned long arg) 255 unsigned long arg)
234{ 256{
235 return afu_ioctl(file, cmd, arg); 257 return afu_ioctl(file, cmd, arg);
236} 258}
237 259
238static int afu_mmap(struct file *file, struct vm_area_struct *vm) 260int afu_mmap(struct file *file, struct vm_area_struct *vm)
239{ 261{
240 struct cxl_context *ctx = file->private_data; 262 struct cxl_context *ctx = file->private_data;
241 263
@@ -246,7 +268,7 @@ static int afu_mmap(struct file *file, struct vm_area_struct *vm)
246 return cxl_context_iomap(ctx, vm); 268 return cxl_context_iomap(ctx, vm);
247} 269}
248 270
249static unsigned int afu_poll(struct file *file, struct poll_table_struct *poll) 271unsigned int afu_poll(struct file *file, struct poll_table_struct *poll)
250{ 272{
251 struct cxl_context *ctx = file->private_data; 273 struct cxl_context *ctx = file->private_data;
252 int mask = 0; 274 int mask = 0;
@@ -278,7 +300,7 @@ static inline int ctx_event_pending(struct cxl_context *ctx)
278 ctx->pending_afu_err || (ctx->status == CLOSED)); 300 ctx->pending_afu_err || (ctx->status == CLOSED));
279} 301}
280 302
281static ssize_t afu_read(struct file *file, char __user *buf, size_t count, 303ssize_t afu_read(struct file *file, char __user *buf, size_t count,
282 loff_t *off) 304 loff_t *off)
283{ 305{
284 struct cxl_context *ctx = file->private_data; 306 struct cxl_context *ctx = file->private_data;
@@ -359,7 +381,11 @@ out:
359 return rc; 381 return rc;
360} 382}
361 383
362static const struct file_operations afu_fops = { 384/*
385 * Note: if this is updated, we need to update api.c to patch the new ones in
386 * too
387 */
388const struct file_operations afu_fops = {
363 .owner = THIS_MODULE, 389 .owner = THIS_MODULE,
364 .open = afu_open, 390 .open = afu_open,
365 .poll = afu_poll, 391 .poll = afu_poll,
@@ -370,7 +396,7 @@ static const struct file_operations afu_fops = {
370 .mmap = afu_mmap, 396 .mmap = afu_mmap,
371}; 397};
372 398
373static const struct file_operations afu_master_fops = { 399const struct file_operations afu_master_fops = {
374 .owner = THIS_MODULE, 400 .owner = THIS_MODULE,
375 .open = afu_master_open, 401 .open = afu_master_open,
376 .poll = afu_poll, 402 .poll = afu_poll,