api.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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/pci.h>
  10. #include <linux/slab.h>
  11. #include <linux/file.h>
  12. #include <misc/cxl.h>
  13. #include <linux/msi.h>
  14. #include <linux/module.h>
  15. #include <linux/mount.h>
  16. #include <linux/sched/mm.h>
  17. #include "cxl.h"
  18. /*
  19. * Since we want to track memory mappings to be able to force-unmap
  20. * when the AFU is no longer reachable, we need an inode. For devices
  21. * opened through the cxl user API, this is not a problem, but a
  22. * userland process can also get a cxl fd through the cxl_get_fd()
  23. * API, which is used by the cxlflash driver.
  24. *
  25. * Therefore we implement our own simple pseudo-filesystem and inode
  26. * allocator. We don't use the anonymous inode, as we need the
  27. * meta-data associated with it (address_space) and it is shared by
  28. * other drivers/processes, so it could lead to cxl unmapping VMAs
  29. * from random processes.
  30. */
  31. #define CXL_PSEUDO_FS_MAGIC 0x1697697f
  32. static int cxl_fs_cnt;
  33. static struct vfsmount *cxl_vfs_mount;
  34. static const struct dentry_operations cxl_fs_dops = {
  35. .d_dname = simple_dname,
  36. };
  37. static struct dentry *cxl_fs_mount(struct file_system_type *fs_type, int flags,
  38. const char *dev_name, void *data)
  39. {
  40. return mount_pseudo(fs_type, "cxl:", NULL, &cxl_fs_dops,
  41. CXL_PSEUDO_FS_MAGIC);
  42. }
  43. static struct file_system_type cxl_fs_type = {
  44. .name = "cxl",
  45. .owner = THIS_MODULE,
  46. .mount = cxl_fs_mount,
  47. .kill_sb = kill_anon_super,
  48. };
  49. void cxl_release_mapping(struct cxl_context *ctx)
  50. {
  51. if (ctx->kernelapi && ctx->mapping)
  52. simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
  53. }
  54. static struct file *cxl_getfile(const char *name,
  55. const struct file_operations *fops,
  56. void *priv, int flags)
  57. {
  58. struct qstr this;
  59. struct path path;
  60. struct file *file;
  61. struct inode *inode = NULL;
  62. int rc;
  63. /* strongly inspired by anon_inode_getfile() */
  64. if (fops->owner && !try_module_get(fops->owner))
  65. return ERR_PTR(-ENOENT);
  66. rc = simple_pin_fs(&cxl_fs_type, &cxl_vfs_mount, &cxl_fs_cnt);
  67. if (rc < 0) {
  68. pr_err("Cannot mount cxl pseudo filesystem: %d\n", rc);
  69. file = ERR_PTR(rc);
  70. goto err_module;
  71. }
  72. inode = alloc_anon_inode(cxl_vfs_mount->mnt_sb);
  73. if (IS_ERR(inode)) {
  74. file = ERR_CAST(inode);
  75. goto err_fs;
  76. }
  77. file = ERR_PTR(-ENOMEM);
  78. this.name = name;
  79. this.len = strlen(name);
  80. this.hash = 0;
  81. path.dentry = d_alloc_pseudo(cxl_vfs_mount->mnt_sb, &this);
  82. if (!path.dentry)
  83. goto err_inode;
  84. path.mnt = mntget(cxl_vfs_mount);
  85. d_instantiate(path.dentry, inode);
  86. file = alloc_file(&path, OPEN_FMODE(flags), fops);
  87. if (IS_ERR(file)) {
  88. path_put(&path);
  89. goto err_fs;
  90. }
  91. file->f_flags = flags & (O_ACCMODE | O_NONBLOCK);
  92. file->private_data = priv;
  93. return file;
  94. err_inode:
  95. iput(inode);
  96. err_fs:
  97. simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
  98. err_module:
  99. module_put(fops->owner);
  100. return file;
  101. }
  102. struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
  103. {
  104. struct cxl_afu *afu;
  105. struct cxl_context *ctx;
  106. int rc;
  107. afu = cxl_pci_to_afu(dev);
  108. if (IS_ERR(afu))
  109. return ERR_CAST(afu);
  110. ctx = cxl_context_alloc();
  111. if (!ctx)
  112. return ERR_PTR(-ENOMEM);
  113. ctx->kernelapi = true;
  114. /* Make it a slave context. We can promote it later? */
  115. rc = cxl_context_init(ctx, afu, false);
  116. if (rc)
  117. goto err_ctx;
  118. return ctx;
  119. err_ctx:
  120. kfree(ctx);
  121. return ERR_PTR(rc);
  122. }
  123. EXPORT_SYMBOL_GPL(cxl_dev_context_init);
  124. struct cxl_context *cxl_get_context(struct pci_dev *dev)
  125. {
  126. return dev->dev.archdata.cxl_ctx;
  127. }
  128. EXPORT_SYMBOL_GPL(cxl_get_context);
  129. int cxl_release_context(struct cxl_context *ctx)
  130. {
  131. if (ctx->status >= STARTED)
  132. return -EBUSY;
  133. cxl_context_free(ctx);
  134. return 0;
  135. }
  136. EXPORT_SYMBOL_GPL(cxl_release_context);
  137. static irq_hw_number_t cxl_find_afu_irq(struct cxl_context *ctx, int num)
  138. {
  139. __u16 range;
  140. int r;
  141. for (r = 0; r < CXL_IRQ_RANGES; r++) {
  142. range = ctx->irqs.range[r];
  143. if (num < range) {
  144. return ctx->irqs.offset[r] + num;
  145. }
  146. num -= range;
  147. }
  148. return 0;
  149. }
  150. int _cxl_next_msi_hwirq(struct pci_dev *pdev, struct cxl_context **ctx, int *afu_irq)
  151. {
  152. if (*ctx == NULL || *afu_irq == 0) {
  153. *afu_irq = 1;
  154. *ctx = cxl_get_context(pdev);
  155. } else {
  156. (*afu_irq)++;
  157. if (*afu_irq > cxl_get_max_irqs_per_process(pdev)) {
  158. *ctx = list_next_entry(*ctx, extra_irq_contexts);
  159. *afu_irq = 1;
  160. }
  161. }
  162. return cxl_find_afu_irq(*ctx, *afu_irq);
  163. }
  164. /* Exported via cxl_base */
  165. int cxl_set_priv(struct cxl_context *ctx, void *priv)
  166. {
  167. if (!ctx)
  168. return -EINVAL;
  169. ctx->priv = priv;
  170. return 0;
  171. }
  172. EXPORT_SYMBOL_GPL(cxl_set_priv);
  173. void *cxl_get_priv(struct cxl_context *ctx)
  174. {
  175. if (!ctx)
  176. return ERR_PTR(-EINVAL);
  177. return ctx->priv;
  178. }
  179. EXPORT_SYMBOL_GPL(cxl_get_priv);
  180. int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num)
  181. {
  182. int res;
  183. irq_hw_number_t hwirq;
  184. if (num == 0)
  185. num = ctx->afu->pp_irqs;
  186. res = afu_allocate_irqs(ctx, num);
  187. if (res)
  188. return res;
  189. if (!cpu_has_feature(CPU_FTR_HVMODE)) {
  190. /* In a guest, the PSL interrupt is not multiplexed. It was
  191. * allocated above, and we need to set its handler
  192. */
  193. hwirq = cxl_find_afu_irq(ctx, 0);
  194. if (hwirq)
  195. cxl_map_irq(ctx->afu->adapter, hwirq, cxl_ops->psl_interrupt, ctx, "psl");
  196. }
  197. if (ctx->status == STARTED) {
  198. if (cxl_ops->update_ivtes)
  199. cxl_ops->update_ivtes(ctx);
  200. else WARN(1, "BUG: cxl_allocate_afu_irqs must be called prior to starting the context on this platform\n");
  201. }
  202. return res;
  203. }
  204. EXPORT_SYMBOL_GPL(cxl_allocate_afu_irqs);
  205. void cxl_free_afu_irqs(struct cxl_context *ctx)
  206. {
  207. irq_hw_number_t hwirq;
  208. unsigned int virq;
  209. if (!cpu_has_feature(CPU_FTR_HVMODE)) {
  210. hwirq = cxl_find_afu_irq(ctx, 0);
  211. if (hwirq) {
  212. virq = irq_find_mapping(NULL, hwirq);
  213. if (virq)
  214. cxl_unmap_irq(virq, ctx);
  215. }
  216. }
  217. afu_irq_name_free(ctx);
  218. cxl_ops->release_irq_ranges(&ctx->irqs, ctx->afu->adapter);
  219. }
  220. EXPORT_SYMBOL_GPL(cxl_free_afu_irqs);
  221. int cxl_map_afu_irq(struct cxl_context *ctx, int num,
  222. irq_handler_t handler, void *cookie, char *name)
  223. {
  224. irq_hw_number_t hwirq;
  225. /*
  226. * Find interrupt we are to register.
  227. */
  228. hwirq = cxl_find_afu_irq(ctx, num);
  229. if (!hwirq)
  230. return -ENOENT;
  231. return cxl_map_irq(ctx->afu->adapter, hwirq, handler, cookie, name);
  232. }
  233. EXPORT_SYMBOL_GPL(cxl_map_afu_irq);
  234. void cxl_unmap_afu_irq(struct cxl_context *ctx, int num, void *cookie)
  235. {
  236. irq_hw_number_t hwirq;
  237. unsigned int virq;
  238. hwirq = cxl_find_afu_irq(ctx, num);
  239. if (!hwirq)
  240. return;
  241. virq = irq_find_mapping(NULL, hwirq);
  242. if (virq)
  243. cxl_unmap_irq(virq, cookie);
  244. }
  245. EXPORT_SYMBOL_GPL(cxl_unmap_afu_irq);
  246. /*
  247. * Start a context
  248. * Code here similar to afu_ioctl_start_work().
  249. */
  250. int cxl_start_context(struct cxl_context *ctx, u64 wed,
  251. struct task_struct *task)
  252. {
  253. int rc = 0;
  254. bool kernel = true;
  255. pr_devel("%s: pe: %i\n", __func__, ctx->pe);
  256. mutex_lock(&ctx->status_mutex);
  257. if (ctx->status == STARTED)
  258. goto out; /* already started */
  259. /*
  260. * Increment the mapped context count for adapter. This also checks
  261. * if adapter_context_lock is taken.
  262. */
  263. rc = cxl_adapter_context_get(ctx->afu->adapter);
  264. if (rc)
  265. goto out;
  266. if (task) {
  267. ctx->pid = get_task_pid(task, PIDTYPE_PID);
  268. kernel = false;
  269. ctx->real_mode = false;
  270. /* acquire a reference to the task's mm */
  271. ctx->mm = get_task_mm(current);
  272. /* ensure this mm_struct can't be freed */
  273. cxl_context_mm_count_get(ctx);
  274. /* decrement the use count */
  275. if (ctx->mm)
  276. mmput(ctx->mm);
  277. }
  278. /*
  279. * Increment driver use count. Enables global TLBIs for hash
  280. * and callbacks to handle the segment table
  281. */
  282. cxl_ctx_get();
  283. if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
  284. put_pid(ctx->pid);
  285. ctx->pid = NULL;
  286. cxl_adapter_context_put(ctx->afu->adapter);
  287. cxl_ctx_put();
  288. if (task)
  289. cxl_context_mm_count_put(ctx);
  290. goto out;
  291. }
  292. ctx->status = STARTED;
  293. out:
  294. mutex_unlock(&ctx->status_mutex);
  295. return rc;
  296. }
  297. EXPORT_SYMBOL_GPL(cxl_start_context);
  298. int cxl_process_element(struct cxl_context *ctx)
  299. {
  300. return ctx->external_pe;
  301. }
  302. EXPORT_SYMBOL_GPL(cxl_process_element);
  303. /* Stop a context. Returns 0 on success, otherwise -Errno */
  304. int cxl_stop_context(struct cxl_context *ctx)
  305. {
  306. return __detach_context(ctx);
  307. }
  308. EXPORT_SYMBOL_GPL(cxl_stop_context);
  309. void cxl_set_master(struct cxl_context *ctx)
  310. {
  311. ctx->master = true;
  312. }
  313. EXPORT_SYMBOL_GPL(cxl_set_master);
  314. int cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode)
  315. {
  316. if (ctx->status == STARTED) {
  317. /*
  318. * We could potentially update the PE and issue an update LLCMD
  319. * to support this, but it doesn't seem to have a good use case
  320. * since it's trivial to just create a second kernel context
  321. * with different translation modes, so until someone convinces
  322. * me otherwise:
  323. */
  324. return -EBUSY;
  325. }
  326. ctx->real_mode = real_mode;
  327. return 0;
  328. }
  329. EXPORT_SYMBOL_GPL(cxl_set_translation_mode);
  330. /* wrappers around afu_* file ops which are EXPORTED */
  331. int cxl_fd_open(struct inode *inode, struct file *file)
  332. {
  333. return afu_open(inode, file);
  334. }
  335. EXPORT_SYMBOL_GPL(cxl_fd_open);
  336. int cxl_fd_release(struct inode *inode, struct file *file)
  337. {
  338. return afu_release(inode, file);
  339. }
  340. EXPORT_SYMBOL_GPL(cxl_fd_release);
  341. long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  342. {
  343. return afu_ioctl(file, cmd, arg);
  344. }
  345. EXPORT_SYMBOL_GPL(cxl_fd_ioctl);
  346. int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm)
  347. {
  348. return afu_mmap(file, vm);
  349. }
  350. EXPORT_SYMBOL_GPL(cxl_fd_mmap);
  351. unsigned int cxl_fd_poll(struct file *file, struct poll_table_struct *poll)
  352. {
  353. return afu_poll(file, poll);
  354. }
  355. EXPORT_SYMBOL_GPL(cxl_fd_poll);
  356. ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
  357. loff_t *off)
  358. {
  359. return afu_read(file, buf, count, off);
  360. }
  361. EXPORT_SYMBOL_GPL(cxl_fd_read);
  362. #define PATCH_FOPS(NAME) if (!fops->NAME) fops->NAME = afu_fops.NAME
  363. /* Get a struct file and fd for a context and attach the ops */
  364. struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
  365. int *fd)
  366. {
  367. struct file *file;
  368. int rc, flags, fdtmp;
  369. char *name = NULL;
  370. /* only allow one per context */
  371. if (ctx->mapping)
  372. return ERR_PTR(-EEXIST);
  373. flags = O_RDWR | O_CLOEXEC;
  374. /* This code is similar to anon_inode_getfd() */
  375. rc = get_unused_fd_flags(flags);
  376. if (rc < 0)
  377. return ERR_PTR(rc);
  378. fdtmp = rc;
  379. /*
  380. * Patch the file ops. Needs to be careful that this is rentrant safe.
  381. */
  382. if (fops) {
  383. PATCH_FOPS(open);
  384. PATCH_FOPS(poll);
  385. PATCH_FOPS(read);
  386. PATCH_FOPS(release);
  387. PATCH_FOPS(unlocked_ioctl);
  388. PATCH_FOPS(compat_ioctl);
  389. PATCH_FOPS(mmap);
  390. } else /* use default ops */
  391. fops = (struct file_operations *)&afu_fops;
  392. name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
  393. file = cxl_getfile(name, fops, ctx, flags);
  394. kfree(name);
  395. if (IS_ERR(file))
  396. goto err_fd;
  397. cxl_context_set_mapping(ctx, file->f_mapping);
  398. *fd = fdtmp;
  399. return file;
  400. err_fd:
  401. put_unused_fd(fdtmp);
  402. return NULL;
  403. }
  404. EXPORT_SYMBOL_GPL(cxl_get_fd);
  405. struct cxl_context *cxl_fops_get_context(struct file *file)
  406. {
  407. return file->private_data;
  408. }
  409. EXPORT_SYMBOL_GPL(cxl_fops_get_context);
  410. void cxl_set_driver_ops(struct cxl_context *ctx,
  411. struct cxl_afu_driver_ops *ops)
  412. {
  413. WARN_ON(!ops->fetch_event || !ops->event_delivered);
  414. atomic_set(&ctx->afu_driver_events, 0);
  415. ctx->afu_driver_ops = ops;
  416. }
  417. EXPORT_SYMBOL_GPL(cxl_set_driver_ops);
  418. void cxl_context_events_pending(struct cxl_context *ctx,
  419. unsigned int new_events)
  420. {
  421. atomic_add(new_events, &ctx->afu_driver_events);
  422. wake_up_all(&ctx->wq);
  423. }
  424. EXPORT_SYMBOL_GPL(cxl_context_events_pending);
  425. int cxl_start_work(struct cxl_context *ctx,
  426. struct cxl_ioctl_start_work *work)
  427. {
  428. int rc;
  429. /* code taken from afu_ioctl_start_work */
  430. if (!(work->flags & CXL_START_WORK_NUM_IRQS))
  431. work->num_interrupts = ctx->afu->pp_irqs;
  432. else if ((work->num_interrupts < ctx->afu->pp_irqs) ||
  433. (work->num_interrupts > ctx->afu->irqs_max)) {
  434. return -EINVAL;
  435. }
  436. rc = afu_register_irqs(ctx, work->num_interrupts);
  437. if (rc)
  438. return rc;
  439. rc = cxl_start_context(ctx, work->work_element_descriptor, current);
  440. if (rc < 0) {
  441. afu_release_irqs(ctx, ctx);
  442. return rc;
  443. }
  444. return 0;
  445. }
  446. EXPORT_SYMBOL_GPL(cxl_start_work);
  447. void __iomem *cxl_psa_map(struct cxl_context *ctx)
  448. {
  449. if (ctx->status != STARTED)
  450. return NULL;
  451. pr_devel("%s: psn_phys%llx size:%llx\n",
  452. __func__, ctx->psn_phys, ctx->psn_size);
  453. return ioremap(ctx->psn_phys, ctx->psn_size);
  454. }
  455. EXPORT_SYMBOL_GPL(cxl_psa_map);
  456. void cxl_psa_unmap(void __iomem *addr)
  457. {
  458. iounmap(addr);
  459. }
  460. EXPORT_SYMBOL_GPL(cxl_psa_unmap);
  461. int cxl_afu_reset(struct cxl_context *ctx)
  462. {
  463. struct cxl_afu *afu = ctx->afu;
  464. int rc;
  465. rc = cxl_ops->afu_reset(afu);
  466. if (rc)
  467. return rc;
  468. return cxl_ops->afu_check_and_enable(afu);
  469. }
  470. EXPORT_SYMBOL_GPL(cxl_afu_reset);
  471. void cxl_perst_reloads_same_image(struct cxl_afu *afu,
  472. bool perst_reloads_same_image)
  473. {
  474. afu->adapter->perst_same_image = perst_reloads_same_image;
  475. }
  476. EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image);
  477. ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count)
  478. {
  479. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  480. if (IS_ERR(afu))
  481. return -ENODEV;
  482. return cxl_ops->read_adapter_vpd(afu->adapter, buf, count);
  483. }
  484. EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd);
  485. int cxl_set_max_irqs_per_process(struct pci_dev *dev, int irqs)
  486. {
  487. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  488. if (IS_ERR(afu))
  489. return -ENODEV;
  490. if (irqs > afu->adapter->user_irqs)
  491. return -EINVAL;
  492. /* Limit user_irqs to prevent the user increasing this via sysfs */
  493. afu->adapter->user_irqs = irqs;
  494. afu->irqs_max = irqs;
  495. return 0;
  496. }
  497. EXPORT_SYMBOL_GPL(cxl_set_max_irqs_per_process);
  498. int cxl_get_max_irqs_per_process(struct pci_dev *dev)
  499. {
  500. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  501. if (IS_ERR(afu))
  502. return -ENODEV;
  503. return afu->irqs_max;
  504. }
  505. EXPORT_SYMBOL_GPL(cxl_get_max_irqs_per_process);
  506. /*
  507. * This is a special interrupt allocation routine called from the PHB's MSI
  508. * setup function. When capi interrupts are allocated in this manner they must
  509. * still be associated with a running context, but since the MSI APIs have no
  510. * way to specify this we use the default context associated with the device.
  511. *
  512. * The Mellanox CX4 has a hardware limitation that restricts the maximum AFU
  513. * interrupt number, so in order to overcome this their driver informs us of
  514. * the restriction by setting the maximum interrupts per context, and we
  515. * allocate additional contexts as necessary so that we can keep the AFU
  516. * interrupt number within the supported range.
  517. */
  518. int _cxl_cx4_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
  519. {
  520. struct cxl_context *ctx, *new_ctx, *default_ctx;
  521. int remaining;
  522. int rc;
  523. ctx = default_ctx = cxl_get_context(pdev);
  524. if (WARN_ON(!default_ctx))
  525. return -ENODEV;
  526. remaining = nvec;
  527. while (remaining > 0) {
  528. rc = cxl_allocate_afu_irqs(ctx, min(remaining, ctx->afu->irqs_max));
  529. if (rc) {
  530. pr_warn("%s: Failed to find enough free MSIs\n", pci_name(pdev));
  531. return rc;
  532. }
  533. remaining -= ctx->afu->irqs_max;
  534. if (ctx != default_ctx && default_ctx->status == STARTED) {
  535. WARN_ON(cxl_start_context(ctx,
  536. be64_to_cpu(default_ctx->elem->common.wed),
  537. NULL));
  538. }
  539. if (remaining > 0) {
  540. new_ctx = cxl_dev_context_init(pdev);
  541. if (IS_ERR(new_ctx)) {
  542. pr_warn("%s: Failed to allocate enough contexts for MSIs\n", pci_name(pdev));
  543. return -ENOSPC;
  544. }
  545. list_add(&new_ctx->extra_irq_contexts, &ctx->extra_irq_contexts);
  546. ctx = new_ctx;
  547. }
  548. }
  549. return 0;
  550. }
  551. /* Exported via cxl_base */
  552. void _cxl_cx4_teardown_msi_irqs(struct pci_dev *pdev)
  553. {
  554. struct cxl_context *ctx, *pos, *tmp;
  555. ctx = cxl_get_context(pdev);
  556. if (WARN_ON(!ctx))
  557. return;
  558. cxl_free_afu_irqs(ctx);
  559. list_for_each_entry_safe(pos, tmp, &ctx->extra_irq_contexts, extra_irq_contexts) {
  560. cxl_stop_context(pos);
  561. cxl_free_afu_irqs(pos);
  562. list_del(&pos->extra_irq_contexts);
  563. cxl_release_context(pos);
  564. }
  565. }
  566. /* Exported via cxl_base */