ocxl_internal.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 reserved1[11];
  78. __be32 lpid;
  79. __be32 tid;
  80. __be32 pid;
  81. __be32 reserved2[10];
  82. __be64 amr;
  83. __be32 reserved3[3];
  84. __be32 software_state;
  85. };
  86. int ocxl_create_cdev(struct ocxl_afu *afu);
  87. void ocxl_destroy_cdev(struct ocxl_afu *afu);
  88. int ocxl_file_register_afu(struct ocxl_afu *afu);
  89. void ocxl_file_unregister_afu(struct ocxl_afu *afu);
  90. int ocxl_file_init(void);
  91. void ocxl_file_exit(void);
  92. int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size);
  93. void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  94. int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size);
  95. void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  96. /*
  97. * Get the max PASID value that can be used by the function
  98. */
  99. int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count);
  100. /*
  101. * Control whether the FPGA is reloaded on a link reset
  102. */
  103. int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val);
  104. int ocxl_config_set_reset_reload(struct pci_dev *dev, int val);
  105. /*
  106. * Check if an AFU index is valid for the given function.
  107. *
  108. * AFU indexes can be sparse, so a driver should check all indexes up
  109. * to the maximum found in the function description
  110. */
  111. int ocxl_config_check_afu_index(struct pci_dev *dev,
  112. struct ocxl_fn_config *fn, int afu_idx);
  113. /**
  114. * ocxl_link_update_pe() - Update values within a Process Element
  115. * @link_handle: the link handle associated with the process element
  116. * @pasid: the PASID for the AFU context
  117. * @tid: the new thread id for the process element
  118. *
  119. * Returns 0 on success
  120. */
  121. int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid);
  122. int ocxl_context_mmap(struct ocxl_context *ctx,
  123. struct vm_area_struct *vma);
  124. void ocxl_context_detach_all(struct ocxl_afu *afu);
  125. int ocxl_sysfs_register_afu(struct ocxl_file_info *info);
  126. void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info);
  127. int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset);
  128. u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id);
  129. void ocxl_afu_irq_free_all(struct ocxl_context *ctx);
  130. #endif /* _OCXL_INTERNAL_H_ */