file.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright 2014 IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/spinlock.h>
  10. #include <linux/module.h>
  11. #include <linux/export.h>
  12. #include <linux/kernel.h>
  13. #include <linux/bitmap.h>
  14. #include <linux/sched.h>
  15. #include <linux/poll.h>
  16. #include <linux/pid.h>
  17. #include <linux/fs.h>
  18. #include <linux/mm.h>
  19. #include <linux/slab.h>
  20. #include <asm/cputable.h>
  21. #include <asm/current.h>
  22. #include <asm/copro.h>
  23. #include "cxl.h"
  24. #include "trace.h"
  25. #define CXL_NUM_MINORS 256 /* Total to reserve */
  26. #define CXL_AFU_MINOR_D(afu) (CXL_CARD_MINOR(afu->adapter) + 1 + (3 * afu->slice))
  27. #define CXL_AFU_MINOR_M(afu) (CXL_AFU_MINOR_D(afu) + 1)
  28. #define CXL_AFU_MINOR_S(afu) (CXL_AFU_MINOR_D(afu) + 2)
  29. #define CXL_AFU_MKDEV_D(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_D(afu))
  30. #define CXL_AFU_MKDEV_M(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_M(afu))
  31. #define CXL_AFU_MKDEV_S(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_S(afu))
  32. #define CXL_DEVT_AFU(dev) ((MINOR(dev) % CXL_DEV_MINORS - 1) / 3)
  33. #define CXL_DEVT_IS_CARD(dev) (MINOR(dev) % CXL_DEV_MINORS == 0)
  34. static dev_t cxl_dev;
  35. static struct class *cxl_class;
  36. static int __afu_open(struct inode *inode, struct file *file, bool master)
  37. {
  38. struct cxl *adapter;
  39. struct cxl_afu *afu;
  40. struct cxl_context *ctx;
  41. int adapter_num = CXL_DEVT_ADAPTER(inode->i_rdev);
  42. int slice = CXL_DEVT_AFU(inode->i_rdev);
  43. int rc = -ENODEV;
  44. pr_devel("afu_open afu%i.%i\n", slice, adapter_num);
  45. if (!(adapter = get_cxl_adapter(adapter_num)))
  46. return -ENODEV;
  47. if (slice > adapter->slices)
  48. goto err_put_adapter;
  49. spin_lock(&adapter->afu_list_lock);
  50. if (!(afu = adapter->afu[slice])) {
  51. spin_unlock(&adapter->afu_list_lock);
  52. goto err_put_adapter;
  53. }
  54. /*
  55. * taking a ref to the afu so that it doesn't go away
  56. * for rest of the function. This ref is released before
  57. * we return.
  58. */
  59. cxl_afu_get(afu);
  60. spin_unlock(&adapter->afu_list_lock);
  61. if (!afu->current_mode)
  62. goto err_put_afu;
  63. if (!cxl_ops->link_ok(adapter, afu)) {
  64. rc = -EIO;
  65. goto err_put_afu;
  66. }
  67. if (!(ctx = cxl_context_alloc())) {
  68. rc = -ENOMEM;
  69. goto err_put_afu;
  70. }
  71. if ((rc = cxl_context_init(ctx, afu, master, inode->i_mapping)))
  72. goto err_put_afu;
  73. pr_devel("afu_open pe: %i\n", ctx->pe);
  74. file->private_data = ctx;
  75. /* indicate success */
  76. rc = 0;
  77. err_put_afu:
  78. /* release the ref taken earlier */
  79. cxl_afu_put(afu);
  80. err_put_adapter:
  81. put_device(&adapter->dev);
  82. return rc;
  83. }
  84. int afu_open(struct inode *inode, struct file *file)
  85. {
  86. return __afu_open(inode, file, false);
  87. }
  88. static int afu_master_open(struct inode *inode, struct file *file)
  89. {
  90. return __afu_open(inode, file, true);
  91. }
  92. int afu_release(struct inode *inode, struct file *file)
  93. {
  94. struct cxl_context *ctx = file->private_data;
  95. pr_devel("%s: closing cxl file descriptor. pe: %i\n",
  96. __func__, ctx->pe);
  97. cxl_context_detach(ctx);
  98. /*
  99. * Delete the context's mapping pointer, unless it's created by the
  100. * kernel API, in which case leave it so it can be freed by reclaim_ctx()
  101. */
  102. if (!ctx->kernelapi) {
  103. mutex_lock(&ctx->mapping_lock);
  104. ctx->mapping = NULL;
  105. mutex_unlock(&ctx->mapping_lock);
  106. }
  107. /*
  108. * At this this point all bottom halfs have finished and we should be
  109. * getting no more IRQs from the hardware for this context. Once it's
  110. * removed from the IDR (and RCU synchronised) it's safe to free the
  111. * sstp and context.
  112. */
  113. cxl_context_free(ctx);
  114. return 0;
  115. }
  116. static long afu_ioctl_start_work(struct cxl_context *ctx,
  117. struct cxl_ioctl_start_work __user *uwork)
  118. {
  119. struct cxl_ioctl_start_work work;
  120. u64 amr = 0;
  121. int rc;
  122. pr_devel("%s: pe: %i\n", __func__, ctx->pe);
  123. /* Do this outside the status_mutex to avoid a circular dependency with
  124. * the locking in cxl_mmap_fault() */
  125. if (copy_from_user(&work, uwork, sizeof(work)))
  126. return -EFAULT;
  127. mutex_lock(&ctx->status_mutex);
  128. if (ctx->status != OPENED) {
  129. rc = -EIO;
  130. goto out;
  131. }
  132. /*
  133. * if any of the reserved fields are set or any of the unused
  134. * flags are set it's invalid
  135. */
  136. if (work.reserved1 || work.reserved2 || work.reserved3 ||
  137. work.reserved4 || work.reserved5 || work.reserved6 ||
  138. (work.flags & ~CXL_START_WORK_ALL)) {
  139. rc = -EINVAL;
  140. goto out;
  141. }
  142. if (!(work.flags & CXL_START_WORK_NUM_IRQS))
  143. work.num_interrupts = ctx->afu->pp_irqs;
  144. else if ((work.num_interrupts < ctx->afu->pp_irqs) ||
  145. (work.num_interrupts > ctx->afu->irqs_max)) {
  146. rc = -EINVAL;
  147. goto out;
  148. }
  149. if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
  150. goto out;
  151. if (work.flags & CXL_START_WORK_AMR)
  152. amr = work.amr & mfspr(SPRN_UAMOR);
  153. ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
  154. /*
  155. * Increment the mapped context count for adapter. This also checks
  156. * if adapter_context_lock is taken.
  157. */
  158. rc = cxl_adapter_context_get(ctx->afu->adapter);
  159. if (rc) {
  160. afu_release_irqs(ctx, ctx);
  161. goto out;
  162. }
  163. /*
  164. * We grab the PID here and not in the file open to allow for the case
  165. * where a process (master, some daemon, etc) has opened the chardev on
  166. * behalf of another process, so the AFU's mm gets bound to the process
  167. * that performs this ioctl and not the process that opened the file.
  168. * Also we grab the PID of the group leader so that if the task that
  169. * has performed the attach operation exits the mm context of the
  170. * process is still accessible.
  171. */
  172. ctx->pid = get_task_pid(current, PIDTYPE_PID);
  173. ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);
  174. /*
  175. * Increment driver use count. Enables global TLBIs for hash
  176. * and callbacks to handle the segment table
  177. */
  178. cxl_ctx_get();
  179. trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
  180. if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor,
  181. amr))) {
  182. afu_release_irqs(ctx, ctx);
  183. cxl_adapter_context_put(ctx->afu->adapter);
  184. put_pid(ctx->glpid);
  185. put_pid(ctx->pid);
  186. ctx->glpid = ctx->pid = NULL;
  187. cxl_ctx_put();
  188. goto out;
  189. }
  190. ctx->status = STARTED;
  191. rc = 0;
  192. out:
  193. mutex_unlock(&ctx->status_mutex);
  194. return rc;
  195. }
  196. static long afu_ioctl_process_element(struct cxl_context *ctx,
  197. int __user *upe)
  198. {
  199. pr_devel("%s: pe: %i\n", __func__, ctx->pe);
  200. if (copy_to_user(upe, &ctx->external_pe, sizeof(__u32)))
  201. return -EFAULT;
  202. return 0;
  203. }
  204. static long afu_ioctl_get_afu_id(struct cxl_context *ctx,
  205. struct cxl_afu_id __user *upafuid)
  206. {
  207. struct cxl_afu_id afuid = { 0 };
  208. afuid.card_id = ctx->afu->adapter->adapter_num;
  209. afuid.afu_offset = ctx->afu->slice;
  210. afuid.afu_mode = ctx->afu->current_mode;
  211. /* set the flag bit in case the afu is a slave */
  212. if (ctx->afu->current_mode == CXL_MODE_DIRECTED && !ctx->master)
  213. afuid.flags |= CXL_AFUID_FLAG_SLAVE;
  214. if (copy_to_user(upafuid, &afuid, sizeof(afuid)))
  215. return -EFAULT;
  216. return 0;
  217. }
  218. long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  219. {
  220. struct cxl_context *ctx = file->private_data;
  221. if (ctx->status == CLOSED)
  222. return -EIO;
  223. if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu))
  224. return -EIO;
  225. pr_devel("afu_ioctl\n");
  226. switch (cmd) {
  227. case CXL_IOCTL_START_WORK:
  228. return afu_ioctl_start_work(ctx, (struct cxl_ioctl_start_work __user *)arg);
  229. case CXL_IOCTL_GET_PROCESS_ELEMENT:
  230. return afu_ioctl_process_element(ctx, (__u32 __user *)arg);
  231. case CXL_IOCTL_GET_AFU_ID:
  232. return afu_ioctl_get_afu_id(ctx, (struct cxl_afu_id __user *)
  233. arg);
  234. }
  235. return -EINVAL;
  236. }
  237. static long afu_compat_ioctl(struct file *file, unsigned int cmd,
  238. unsigned long arg)
  239. {
  240. return afu_ioctl(file, cmd, arg);
  241. }
  242. int afu_mmap(struct file *file, struct vm_area_struct *vm)
  243. {
  244. struct cxl_context *ctx = file->private_data;
  245. /* AFU must be started before we can MMIO */
  246. if (ctx->status != STARTED)
  247. return -EIO;
  248. if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu))
  249. return -EIO;
  250. return cxl_context_iomap(ctx, vm);
  251. }
  252. static inline bool ctx_event_pending(struct cxl_context *ctx)
  253. {
  254. if (ctx->pending_irq || ctx->pending_fault || ctx->pending_afu_err)
  255. return true;
  256. if (ctx->afu_driver_ops && atomic_read(&ctx->afu_driver_events))
  257. return true;
  258. return false;
  259. }
  260. unsigned int afu_poll(struct file *file, struct poll_table_struct *poll)
  261. {
  262. struct cxl_context *ctx = file->private_data;
  263. int mask = 0;
  264. unsigned long flags;
  265. poll_wait(file, &ctx->wq, poll);
  266. pr_devel("afu_poll wait done pe: %i\n", ctx->pe);
  267. spin_lock_irqsave(&ctx->lock, flags);
  268. if (ctx_event_pending(ctx))
  269. mask |= POLLIN | POLLRDNORM;
  270. else if (ctx->status == CLOSED)
  271. /* Only error on closed when there are no futher events pending
  272. */
  273. mask |= POLLERR;
  274. spin_unlock_irqrestore(&ctx->lock, flags);
  275. pr_devel("afu_poll pe: %i returning %#x\n", ctx->pe, mask);
  276. return mask;
  277. }
  278. static ssize_t afu_driver_event_copy(struct cxl_context *ctx,
  279. char __user *buf,
  280. struct cxl_event *event,
  281. struct cxl_event_afu_driver_reserved *pl)
  282. {
  283. /* Check event */
  284. if (!pl) {
  285. ctx->afu_driver_ops->event_delivered(ctx, pl, -EINVAL);
  286. return -EFAULT;
  287. }
  288. /* Check event size */
  289. event->header.size += pl->data_size;
  290. if (event->header.size > CXL_READ_MIN_SIZE) {
  291. ctx->afu_driver_ops->event_delivered(ctx, pl, -EINVAL);
  292. return -EFAULT;
  293. }
  294. /* Copy event header */
  295. if (copy_to_user(buf, event, sizeof(struct cxl_event_header))) {
  296. ctx->afu_driver_ops->event_delivered(ctx, pl, -EFAULT);
  297. return -EFAULT;
  298. }
  299. /* Copy event data */
  300. buf += sizeof(struct cxl_event_header);
  301. if (copy_to_user(buf, &pl->data, pl->data_size)) {
  302. ctx->afu_driver_ops->event_delivered(ctx, pl, -EFAULT);
  303. return -EFAULT;
  304. }
  305. ctx->afu_driver_ops->event_delivered(ctx, pl, 0); /* Success */
  306. return event->header.size;
  307. }
  308. ssize_t afu_read(struct file *file, char __user *buf, size_t count,
  309. loff_t *off)
  310. {
  311. struct cxl_context *ctx = file->private_data;
  312. struct cxl_event_afu_driver_reserved *pl = NULL;
  313. struct cxl_event event;
  314. unsigned long flags;
  315. int rc;
  316. DEFINE_WAIT(wait);
  317. if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu))
  318. return -EIO;
  319. if (count < CXL_READ_MIN_SIZE)
  320. return -EINVAL;
  321. spin_lock_irqsave(&ctx->lock, flags);
  322. for (;;) {
  323. prepare_to_wait(&ctx->wq, &wait, TASK_INTERRUPTIBLE);
  324. if (ctx_event_pending(ctx) || (ctx->status == CLOSED))
  325. break;
  326. if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) {
  327. rc = -EIO;
  328. goto out;
  329. }
  330. if (file->f_flags & O_NONBLOCK) {
  331. rc = -EAGAIN;
  332. goto out;
  333. }
  334. if (signal_pending(current)) {
  335. rc = -ERESTARTSYS;
  336. goto out;
  337. }
  338. spin_unlock_irqrestore(&ctx->lock, flags);
  339. pr_devel("afu_read going to sleep...\n");
  340. schedule();
  341. pr_devel("afu_read woken up\n");
  342. spin_lock_irqsave(&ctx->lock, flags);
  343. }
  344. finish_wait(&ctx->wq, &wait);
  345. memset(&event, 0, sizeof(event));
  346. event.header.process_element = ctx->pe;
  347. event.header.size = sizeof(struct cxl_event_header);
  348. if (ctx->afu_driver_ops && atomic_read(&ctx->afu_driver_events)) {
  349. pr_devel("afu_read delivering AFU driver specific event\n");
  350. pl = ctx->afu_driver_ops->fetch_event(ctx);
  351. atomic_dec(&ctx->afu_driver_events);
  352. event.header.type = CXL_EVENT_AFU_DRIVER;
  353. } else if (ctx->pending_irq) {
  354. pr_devel("afu_read delivering AFU interrupt\n");
  355. event.header.size += sizeof(struct cxl_event_afu_interrupt);
  356. event.header.type = CXL_EVENT_AFU_INTERRUPT;
  357. event.irq.irq = find_first_bit(ctx->irq_bitmap, ctx->irq_count) + 1;
  358. clear_bit(event.irq.irq - 1, ctx->irq_bitmap);
  359. if (bitmap_empty(ctx->irq_bitmap, ctx->irq_count))
  360. ctx->pending_irq = false;
  361. } else if (ctx->pending_fault) {
  362. pr_devel("afu_read delivering data storage fault\n");
  363. event.header.size += sizeof(struct cxl_event_data_storage);
  364. event.header.type = CXL_EVENT_DATA_STORAGE;
  365. event.fault.addr = ctx->fault_addr;
  366. event.fault.dsisr = ctx->fault_dsisr;
  367. ctx->pending_fault = false;
  368. } else if (ctx->pending_afu_err) {
  369. pr_devel("afu_read delivering afu error\n");
  370. event.header.size += sizeof(struct cxl_event_afu_error);
  371. event.header.type = CXL_EVENT_AFU_ERROR;
  372. event.afu_error.error = ctx->afu_err;
  373. ctx->pending_afu_err = false;
  374. } else if (ctx->status == CLOSED) {
  375. pr_devel("afu_read fatal error\n");
  376. spin_unlock_irqrestore(&ctx->lock, flags);
  377. return -EIO;
  378. } else
  379. WARN(1, "afu_read must be buggy\n");
  380. spin_unlock_irqrestore(&ctx->lock, flags);
  381. if (event.header.type == CXL_EVENT_AFU_DRIVER)
  382. return afu_driver_event_copy(ctx, buf, &event, pl);
  383. if (copy_to_user(buf, &event, event.header.size))
  384. return -EFAULT;
  385. return event.header.size;
  386. out:
  387. finish_wait(&ctx->wq, &wait);
  388. spin_unlock_irqrestore(&ctx->lock, flags);
  389. return rc;
  390. }
  391. /*
  392. * Note: if this is updated, we need to update api.c to patch the new ones in
  393. * too
  394. */
  395. const struct file_operations afu_fops = {
  396. .owner = THIS_MODULE,
  397. .open = afu_open,
  398. .poll = afu_poll,
  399. .read = afu_read,
  400. .release = afu_release,
  401. .unlocked_ioctl = afu_ioctl,
  402. .compat_ioctl = afu_compat_ioctl,
  403. .mmap = afu_mmap,
  404. };
  405. static const struct file_operations afu_master_fops = {
  406. .owner = THIS_MODULE,
  407. .open = afu_master_open,
  408. .poll = afu_poll,
  409. .read = afu_read,
  410. .release = afu_release,
  411. .unlocked_ioctl = afu_ioctl,
  412. .compat_ioctl = afu_compat_ioctl,
  413. .mmap = afu_mmap,
  414. };
  415. static char *cxl_devnode(struct device *dev, umode_t *mode)
  416. {
  417. if (cpu_has_feature(CPU_FTR_HVMODE) &&
  418. CXL_DEVT_IS_CARD(dev->devt)) {
  419. /*
  420. * These minor numbers will eventually be used to program the
  421. * PSL and AFUs once we have dynamic reprogramming support
  422. */
  423. return NULL;
  424. }
  425. return kasprintf(GFP_KERNEL, "cxl/%s", dev_name(dev));
  426. }
  427. extern struct class *cxl_class;
  428. static int cxl_add_chardev(struct cxl_afu *afu, dev_t devt, struct cdev *cdev,
  429. struct device **chardev, char *postfix, char *desc,
  430. const struct file_operations *fops)
  431. {
  432. struct device *dev;
  433. int rc;
  434. cdev_init(cdev, fops);
  435. if ((rc = cdev_add(cdev, devt, 1))) {
  436. dev_err(&afu->dev, "Unable to add %s chardev: %i\n", desc, rc);
  437. return rc;
  438. }
  439. dev = device_create(cxl_class, &afu->dev, devt, afu,
  440. "afu%i.%i%s", afu->adapter->adapter_num, afu->slice, postfix);
  441. if (IS_ERR(dev)) {
  442. dev_err(&afu->dev, "Unable to create %s chardev in sysfs: %i\n", desc, rc);
  443. rc = PTR_ERR(dev);
  444. goto err;
  445. }
  446. *chardev = dev;
  447. return 0;
  448. err:
  449. cdev_del(cdev);
  450. return rc;
  451. }
  452. int cxl_chardev_d_afu_add(struct cxl_afu *afu)
  453. {
  454. return cxl_add_chardev(afu, CXL_AFU_MKDEV_D(afu), &afu->afu_cdev_d,
  455. &afu->chardev_d, "d", "dedicated",
  456. &afu_master_fops); /* Uses master fops */
  457. }
  458. int cxl_chardev_m_afu_add(struct cxl_afu *afu)
  459. {
  460. return cxl_add_chardev(afu, CXL_AFU_MKDEV_M(afu), &afu->afu_cdev_m,
  461. &afu->chardev_m, "m", "master",
  462. &afu_master_fops);
  463. }
  464. int cxl_chardev_s_afu_add(struct cxl_afu *afu)
  465. {
  466. return cxl_add_chardev(afu, CXL_AFU_MKDEV_S(afu), &afu->afu_cdev_s,
  467. &afu->chardev_s, "s", "shared",
  468. &afu_fops);
  469. }
  470. void cxl_chardev_afu_remove(struct cxl_afu *afu)
  471. {
  472. if (afu->chardev_d) {
  473. cdev_del(&afu->afu_cdev_d);
  474. device_unregister(afu->chardev_d);
  475. afu->chardev_d = NULL;
  476. }
  477. if (afu->chardev_m) {
  478. cdev_del(&afu->afu_cdev_m);
  479. device_unregister(afu->chardev_m);
  480. afu->chardev_m = NULL;
  481. }
  482. if (afu->chardev_s) {
  483. cdev_del(&afu->afu_cdev_s);
  484. device_unregister(afu->chardev_s);
  485. afu->chardev_s = NULL;
  486. }
  487. }
  488. int cxl_register_afu(struct cxl_afu *afu)
  489. {
  490. afu->dev.class = cxl_class;
  491. return device_register(&afu->dev);
  492. }
  493. int cxl_register_adapter(struct cxl *adapter)
  494. {
  495. adapter->dev.class = cxl_class;
  496. /*
  497. * Future: When we support dynamically reprogramming the PSL & AFU we
  498. * will expose the interface to do that via a chardev:
  499. * adapter->dev.devt = CXL_CARD_MKDEV(adapter);
  500. */
  501. return device_register(&adapter->dev);
  502. }
  503. dev_t cxl_get_dev(void)
  504. {
  505. return cxl_dev;
  506. }
  507. int __init cxl_file_init(void)
  508. {
  509. int rc;
  510. /*
  511. * If these change we really need to update API. Either change some
  512. * flags or update API version number CXL_API_VERSION.
  513. */
  514. BUILD_BUG_ON(CXL_API_VERSION != 3);
  515. BUILD_BUG_ON(sizeof(struct cxl_ioctl_start_work) != 64);
  516. BUILD_BUG_ON(sizeof(struct cxl_event_header) != 8);
  517. BUILD_BUG_ON(sizeof(struct cxl_event_afu_interrupt) != 8);
  518. BUILD_BUG_ON(sizeof(struct cxl_event_data_storage) != 32);
  519. BUILD_BUG_ON(sizeof(struct cxl_event_afu_error) != 16);
  520. if ((rc = alloc_chrdev_region(&cxl_dev, 0, CXL_NUM_MINORS, "cxl"))) {
  521. pr_err("Unable to allocate CXL major number: %i\n", rc);
  522. return rc;
  523. }
  524. pr_devel("CXL device allocated, MAJOR %i\n", MAJOR(cxl_dev));
  525. cxl_class = class_create(THIS_MODULE, "cxl");
  526. if (IS_ERR(cxl_class)) {
  527. pr_err("Unable to create CXL class\n");
  528. rc = PTR_ERR(cxl_class);
  529. goto err;
  530. }
  531. cxl_class->devnode = cxl_devnode;
  532. return 0;
  533. err:
  534. unregister_chrdev_region(cxl_dev, CXL_NUM_MINORS);
  535. return rc;
  536. }
  537. void cxl_file_exit(void)
  538. {
  539. unregister_chrdev_region(cxl_dev, CXL_NUM_MINORS);
  540. class_destroy(cxl_class);
  541. }