file.c 16 KB

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