ocxl.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // SPDX-License-Identifier: GPL-2.0+
  2. // Copyright 2017 IBM Corp.
  3. #ifndef _MISC_OCXL_H_
  4. #define _MISC_OCXL_H_
  5. #include <linux/pci.h>
  6. /*
  7. * Opencapi drivers all need some common facilities, like parsing the
  8. * device configuration space, adding a Process Element to the Shared
  9. * Process Area, etc...
  10. *
  11. * The ocxl module provides a kernel API, to allow other drivers to
  12. * reuse common code. A bit like a in-kernel library.
  13. */
  14. #define OCXL_AFU_NAME_SZ (24+1) /* add 1 for NULL termination */
  15. /*
  16. * The following 2 structures are a fairly generic way of representing
  17. * the configuration data for a function and AFU, as read from the
  18. * configuration space.
  19. */
  20. struct ocxl_afu_config {
  21. u8 idx;
  22. int dvsec_afu_control_pos; /* offset of AFU control DVSEC */
  23. char name[OCXL_AFU_NAME_SZ];
  24. u8 version_major;
  25. u8 version_minor;
  26. u8 afuc_type;
  27. u8 afum_type;
  28. u8 profile;
  29. u8 global_mmio_bar; /* global MMIO area */
  30. u64 global_mmio_offset;
  31. u32 global_mmio_size;
  32. u8 pp_mmio_bar; /* per-process MMIO area */
  33. u64 pp_mmio_offset;
  34. u32 pp_mmio_stride;
  35. u8 log_mem_size;
  36. u8 pasid_supported_log;
  37. u16 actag_supported;
  38. };
  39. struct ocxl_fn_config {
  40. int dvsec_tl_pos; /* offset of the Transaction Layer DVSEC */
  41. int dvsec_function_pos; /* offset of the Function DVSEC */
  42. int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */
  43. s8 max_pasid_log;
  44. s8 max_afu_index;
  45. };
  46. /*
  47. * Read the configuration space of a function and fill in a
  48. * ocxl_fn_config structure with all the function details
  49. */
  50. extern int ocxl_config_read_function(struct pci_dev *dev,
  51. struct ocxl_fn_config *fn);
  52. /*
  53. * Check if an AFU index is valid for the given function.
  54. *
  55. * AFU indexes can be sparse, so a driver should check all indexes up
  56. * to the maximum found in the function description
  57. */
  58. extern int ocxl_config_check_afu_index(struct pci_dev *dev,
  59. struct ocxl_fn_config *fn, int afu_idx);
  60. /*
  61. * Read the configuration space of a function for the AFU specified by
  62. * the index 'afu_idx'. Fills in a ocxl_afu_config structure
  63. */
  64. extern int ocxl_config_read_afu(struct pci_dev *dev,
  65. struct ocxl_fn_config *fn,
  66. struct ocxl_afu_config *afu,
  67. u8 afu_idx);
  68. /*
  69. * Get the max PASID value that can be used by the function
  70. */
  71. extern int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count);
  72. /*
  73. * Tell an AFU, by writing in the configuration space, the PASIDs that
  74. * it can use. Range starts at 'pasid_base' and its size is a multiple
  75. * of 2
  76. *
  77. * 'afu_control_offset' is the offset of the AFU control DVSEC which
  78. * can be found in the function configuration
  79. */
  80. extern void ocxl_config_set_afu_pasid(struct pci_dev *dev,
  81. int afu_control_offset,
  82. int pasid_base, u32 pasid_count_log);
  83. /*
  84. * Get the actag configuration for the function:
  85. * 'base' is the first actag value that can be used.
  86. * 'enabled' it the number of actags available, starting from base.
  87. * 'supported' is the total number of actags desired by all the AFUs
  88. * of the function.
  89. */
  90. extern int ocxl_config_get_actag_info(struct pci_dev *dev,
  91. u16 *base, u16 *enabled, u16 *supported);
  92. /*
  93. * Tell a function, by writing in the configuration space, the actags
  94. * it can use.
  95. *
  96. * 'func_offset' is the offset of the Function DVSEC that can found in
  97. * the function configuration
  98. */
  99. extern void ocxl_config_set_actag(struct pci_dev *dev, int func_offset,
  100. u32 actag_base, u32 actag_count);
  101. /*
  102. * Tell an AFU, by writing in the configuration space, the actags it
  103. * can use.
  104. *
  105. * 'afu_control_offset' is the offset of the AFU control DVSEC for the
  106. * desired AFU. It can be found in the AFU configuration
  107. */
  108. extern void ocxl_config_set_afu_actag(struct pci_dev *dev,
  109. int afu_control_offset,
  110. int actag_base, int actag_count);
  111. /*
  112. * Enable/disable an AFU, by writing in the configuration space.
  113. *
  114. * 'afu_control_offset' is the offset of the AFU control DVSEC for the
  115. * desired AFU. It can be found in the AFU configuration
  116. */
  117. extern void ocxl_config_set_afu_state(struct pci_dev *dev,
  118. int afu_control_offset, int enable);
  119. /*
  120. * Set the Transaction Layer configuration in the configuration space.
  121. * Only needed for function 0.
  122. *
  123. * It queries the host TL capabilities, find some common ground
  124. * between the host and device, and set the Transaction Layer on both
  125. * accordingly.
  126. */
  127. extern int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec);
  128. /*
  129. * Request an AFU to terminate a PASID.
  130. * Will return once the AFU has acked the request, or an error in case
  131. * of timeout.
  132. *
  133. * The hardware can only terminate one PASID at a time, so caller must
  134. * guarantee some kind of serialization.
  135. *
  136. * 'afu_control_offset' is the offset of the AFU control DVSEC for the
  137. * desired AFU. It can be found in the AFU configuration
  138. */
  139. extern int ocxl_config_terminate_pasid(struct pci_dev *dev,
  140. int afu_control_offset, int pasid);
  141. /*
  142. * Set up the opencapi link for the function.
  143. *
  144. * When called for the first time for a link, it sets up the Shared
  145. * Process Area for the link and the interrupt handler to process
  146. * translation faults.
  147. *
  148. * Returns a 'link handle' that should be used for further calls for
  149. * the link
  150. */
  151. extern int ocxl_link_setup(struct pci_dev *dev, int PE_mask,
  152. void **link_handle);
  153. /*
  154. * Remove the association between the function and its link.
  155. */
  156. extern void ocxl_link_release(struct pci_dev *dev, void *link_handle);
  157. /*
  158. * Add a Process Element to the Shared Process Area for a link.
  159. * The process is defined by its PASID, pid, tid and its mm_struct.
  160. *
  161. * 'xsl_err_cb' is an optional callback if the driver wants to be
  162. * notified when the translation fault interrupt handler detects an
  163. * address error.
  164. * 'xsl_err_data' is an argument passed to the above callback, if
  165. * defined
  166. */
  167. extern int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr,
  168. u64 amr, struct mm_struct *mm,
  169. void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr),
  170. void *xsl_err_data);
  171. /**
  172. * Update values within a Process Element
  173. *
  174. * link_handle: the link handle associated with the process element
  175. * pasid: the PASID for the AFU context
  176. * tid: the new thread id for the process element
  177. */
  178. extern int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid);
  179. /*
  180. * Remove a Process Element from the Shared Process Area for a link
  181. */
  182. extern int ocxl_link_remove_pe(void *link_handle, int pasid);
  183. /*
  184. * Allocate an AFU interrupt associated to the link.
  185. *
  186. * 'hw_irq' is the hardware interrupt number
  187. * 'obj_handle' is the 64-bit object handle to be passed to the AFU to
  188. * trigger the interrupt.
  189. * On P9, 'obj_handle' is an address, which, if written, triggers the
  190. * interrupt. It is an MMIO address which needs to be remapped (one
  191. * page).
  192. */
  193. extern int ocxl_link_irq_alloc(void *link_handle, int *hw_irq,
  194. u64 *obj_handle);
  195. /*
  196. * Free a previously allocated AFU interrupt
  197. */
  198. extern void ocxl_link_free_irq(void *link_handle, int hw_irq);
  199. #endif /* _MISC_OCXL_H_ */