cxl_hw.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * CXL Flash Device Driver
  3. *
  4. * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
  5. * Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
  6. *
  7. * Copyright (C) 2018 IBM Corporation
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <misc/cxl.h>
  15. #include "backend.h"
  16. /*
  17. * The following routines map the cxlflash backend operations to existing CXL
  18. * kernel API function and are largely simple shims that provide an abstraction
  19. * for converting generic context and AFU cookies into cxl_context or cxl_afu
  20. * pointers.
  21. */
  22. static void __iomem *cxlflash_psa_map(void *ctx_cookie)
  23. {
  24. return cxl_psa_map(ctx_cookie);
  25. }
  26. static void cxlflash_psa_unmap(void __iomem *addr)
  27. {
  28. cxl_psa_unmap(addr);
  29. }
  30. static int cxlflash_process_element(void *ctx_cookie)
  31. {
  32. return cxl_process_element(ctx_cookie);
  33. }
  34. static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
  35. irq_handler_t handler, void *cookie, char *name)
  36. {
  37. return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
  38. }
  39. static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
  40. {
  41. cxl_unmap_afu_irq(ctx_cookie, num, cookie);
  42. }
  43. static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
  44. {
  45. /* Dummy fop for cxl */
  46. return 0;
  47. }
  48. static int cxlflash_start_context(void *ctx_cookie)
  49. {
  50. return cxl_start_context(ctx_cookie, 0, NULL);
  51. }
  52. static int cxlflash_stop_context(void *ctx_cookie)
  53. {
  54. return cxl_stop_context(ctx_cookie);
  55. }
  56. static int cxlflash_afu_reset(void *ctx_cookie)
  57. {
  58. return cxl_afu_reset(ctx_cookie);
  59. }
  60. static void cxlflash_set_master(void *ctx_cookie)
  61. {
  62. cxl_set_master(ctx_cookie);
  63. }
  64. static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
  65. {
  66. return cxl_get_context(dev);
  67. }
  68. static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
  69. {
  70. return cxl_dev_context_init(dev);
  71. }
  72. static int cxlflash_release_context(void *ctx_cookie)
  73. {
  74. return cxl_release_context(ctx_cookie);
  75. }
  76. static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
  77. {
  78. cxl_perst_reloads_same_image(afu_cookie, image);
  79. }
  80. static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
  81. void *buf, size_t count)
  82. {
  83. return cxl_read_adapter_vpd(dev, buf, count);
  84. }
  85. static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
  86. {
  87. return cxl_allocate_afu_irqs(ctx_cookie, num);
  88. }
  89. static void cxlflash_free_afu_irqs(void *ctx_cookie)
  90. {
  91. cxl_free_afu_irqs(ctx_cookie);
  92. }
  93. static void *cxlflash_create_afu(struct pci_dev *dev)
  94. {
  95. return cxl_pci_to_afu(dev);
  96. }
  97. static void cxlflash_destroy_afu(void *afu)
  98. {
  99. /* Dummy fop for cxl */
  100. }
  101. static struct file *cxlflash_get_fd(void *ctx_cookie,
  102. struct file_operations *fops, int *fd)
  103. {
  104. return cxl_get_fd(ctx_cookie, fops, fd);
  105. }
  106. static void *cxlflash_fops_get_context(struct file *file)
  107. {
  108. return cxl_fops_get_context(file);
  109. }
  110. static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
  111. {
  112. struct cxl_ioctl_start_work work = { 0 };
  113. work.num_interrupts = irqs;
  114. work.flags = CXL_START_WORK_NUM_IRQS;
  115. return cxl_start_work(ctx_cookie, &work);
  116. }
  117. static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
  118. {
  119. return cxl_fd_mmap(file, vm);
  120. }
  121. static int cxlflash_fd_release(struct inode *inode, struct file *file)
  122. {
  123. return cxl_fd_release(inode, file);
  124. }
  125. const struct cxlflash_backend_ops cxlflash_cxl_ops = {
  126. .module = THIS_MODULE,
  127. .psa_map = cxlflash_psa_map,
  128. .psa_unmap = cxlflash_psa_unmap,
  129. .process_element = cxlflash_process_element,
  130. .map_afu_irq = cxlflash_map_afu_irq,
  131. .unmap_afu_irq = cxlflash_unmap_afu_irq,
  132. .get_irq_objhndl = cxlflash_get_irq_objhndl,
  133. .start_context = cxlflash_start_context,
  134. .stop_context = cxlflash_stop_context,
  135. .afu_reset = cxlflash_afu_reset,
  136. .set_master = cxlflash_set_master,
  137. .get_context = cxlflash_get_context,
  138. .dev_context_init = cxlflash_dev_context_init,
  139. .release_context = cxlflash_release_context,
  140. .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
  141. .read_adapter_vpd = cxlflash_read_adapter_vpd,
  142. .allocate_afu_irqs = cxlflash_allocate_afu_irqs,
  143. .free_afu_irqs = cxlflash_free_afu_irqs,
  144. .create_afu = cxlflash_create_afu,
  145. .destroy_afu = cxlflash_destroy_afu,
  146. .get_fd = cxlflash_get_fd,
  147. .fops_get_context = cxlflash_fops_get_context,
  148. .start_work = cxlflash_start_work,
  149. .fd_mmap = cxlflash_fd_mmap,
  150. .fd_release = cxlflash_fd_release,
  151. };