ocxl_internal.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. // Copyright 2017 IBM Corp.
  3. #ifndef _OCXL_INTERNAL_H_
  4. #define _OCXL_INTERNAL_H_
  5. #include <linux/pci.h>
  6. #include <linux/cdev.h>
  7. #include <linux/list.h>
  8. #include <misc/ocxl.h>
  9. #define MAX_IRQ_PER_LINK 2000
  10. #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK
  11. extern struct pci_driver ocxl_pci_driver;
  12. struct ocxl_fn {
  13. struct device dev;
  14. int bar_used[3];
  15. struct ocxl_fn_config config;
  16. struct list_head afu_list;
  17. int pasid_base;
  18. int actag_base;
  19. int actag_enabled;
  20. int actag_supported;
  21. struct list_head pasid_list;
  22. struct list_head actag_list;
  23. void *link;
  24. };
  25. struct ocxl_file_info {
  26. struct ocxl_afu *afu;
  27. struct device dev;
  28. struct cdev cdev;
  29. struct bin_attribute attr_global_mmio;
  30. };
  31. struct ocxl_afu {
  32. struct kref kref;
  33. struct ocxl_fn *fn;
  34. struct list_head list;
  35. struct ocxl_afu_config config;
  36. int pasid_base;
  37. int pasid_count; /* opened contexts */
  38. int pasid_max; /* maximum number of contexts */
  39. int actag_base;
  40. int actag_enabled;
  41. struct mutex contexts_lock;
  42. struct idr contexts_idr;
  43. struct mutex afu_control_lock;
  44. u64 global_mmio_start;
  45. u64 irq_base_offset;
  46. void __iomem *global_mmio_ptr;
  47. u64 pp_mmio_start;
  48. void *private;
  49. };
  50. enum ocxl_context_status {
  51. CLOSED,
  52. OPENED,
  53. ATTACHED,
  54. };
  55. // Contains metadata about a translation fault
  56. struct ocxl_xsl_error {
  57. u64 addr; // The address that triggered the fault
  58. u64 dsisr; // the value of the dsisr register
  59. u64 count; // The number of times this fault has been triggered
  60. };
  61. struct ocxl_context {
  62. struct ocxl_afu *afu;
  63. int pasid;
  64. struct mutex status_mutex;
  65. enum ocxl_context_status status;
  66. struct address_space *mapping;
  67. struct mutex mapping_lock;
  68. wait_queue_head_t events_wq;
  69. struct mutex xsl_error_lock;
  70. struct ocxl_xsl_error xsl_error;
  71. struct mutex irq_lock;
  72. struct idr irq_idr;
  73. u16 tidr; // Thread ID used for P9 wait implementation
  74. };
  75. struct ocxl_process_element {
  76. __be64 config_state;
  77. __be32 pasid;
  78. __be16 bdf;
  79. __be16 reserved1;
  80. __be32 reserved2[9];
  81. __be32 lpid;
  82. __be32 tid;
  83. __be32 pid;
  84. __be32 reserved3[10];
  85. __be64 amr;
  86. __be32 reserved4[3];
  87. __be32 software_state;
  88. };
  89. int ocxl_create_cdev(struct ocxl_afu *afu);
  90. void ocxl_destroy_cdev(struct ocxl_afu *afu);
  91. int ocxl_file_register_afu(struct ocxl_afu *afu);
  92. void ocxl_file_unregister_afu(struct ocxl_afu *afu);
  93. int ocxl_file_init(void);
  94. void ocxl_file_exit(void);
  95. int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size);
  96. void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  97. int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size);
  98. void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  99. /*
  100. * Get the max PASID value that can be used by the function
  101. */
  102. int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count);
  103. /*
  104. * Control whether the FPGA is reloaded on a link reset
  105. */
  106. int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val);
  107. int ocxl_config_set_reset_reload(struct pci_dev *dev, int val);
  108. /*
  109. * Check if an AFU index is valid for the given function.
  110. *
  111. * AFU indexes can be sparse, so a driver should check all indexes up
  112. * to the maximum found in the function description
  113. */
  114. int ocxl_config_check_afu_index(struct pci_dev *dev,
  115. struct ocxl_fn_config *fn, int afu_idx);
  116. /**
  117. * ocxl_link_update_pe() - Update values within a Process Element
  118. * @link_handle: the link handle associated with the process element
  119. * @pasid: the PASID for the AFU context
  120. * @tid: the new thread id for the process element
  121. *
  122. * Returns 0 on success
  123. */
  124. int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid);
  125. int ocxl_context_mmap(struct ocxl_context *ctx,
  126. struct vm_area_struct *vma);
  127. void ocxl_context_detach_all(struct ocxl_afu *afu);
  128. int ocxl_sysfs_register_afu(struct ocxl_file_info *info);
  129. void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info);
  130. int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset);
  131. u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id);
  132. void ocxl_afu_irq_free_all(struct ocxl_context *ctx);
  133. #endif /* _OCXL_INTERNAL_H_ */