| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0+ */ |
|---|
| 2 | 2 | // Copyright 2017 IBM Corp. |
|---|
| 3 | 3 | #ifndef _OCXL_INTERNAL_H_ |
|---|
| 4 | 4 | #define _OCXL_INTERNAL_H_ |
|---|
| .. | .. |
|---|
| 11 | 11 | #define MAX_IRQ_PER_LINK 2000 |
|---|
| 12 | 12 | #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK |
|---|
| 13 | 13 | |
|---|
| 14 | | -#define to_ocxl_function(d) container_of(d, struct ocxl_fn, dev) |
|---|
| 15 | | -#define to_ocxl_afu(d) container_of(d, struct ocxl_afu, dev) |
|---|
| 16 | | - |
|---|
| 17 | 14 | extern struct pci_driver ocxl_pci_driver; |
|---|
| 18 | | - |
|---|
| 19 | 15 | |
|---|
| 20 | 16 | struct ocxl_fn { |
|---|
| 21 | 17 | struct device dev; |
|---|
| .. | .. |
|---|
| 31 | 27 | void *link; |
|---|
| 32 | 28 | }; |
|---|
| 33 | 29 | |
|---|
| 34 | | -struct ocxl_afu { |
|---|
| 35 | | - struct ocxl_fn *fn; |
|---|
| 36 | | - struct list_head list; |
|---|
| 30 | +struct ocxl_file_info { |
|---|
| 31 | + struct ocxl_afu *afu; |
|---|
| 37 | 32 | struct device dev; |
|---|
| 38 | 33 | struct cdev cdev; |
|---|
| 34 | + struct bin_attribute attr_global_mmio; |
|---|
| 35 | +}; |
|---|
| 36 | + |
|---|
| 37 | +struct ocxl_afu { |
|---|
| 38 | + struct kref kref; |
|---|
| 39 | + struct ocxl_fn *fn; |
|---|
| 40 | + struct list_head list; |
|---|
| 39 | 41 | struct ocxl_afu_config config; |
|---|
| 40 | 42 | int pasid_base; |
|---|
| 41 | 43 | int pasid_count; /* opened contexts */ |
|---|
| .. | .. |
|---|
| 49 | 51 | u64 irq_base_offset; |
|---|
| 50 | 52 | void __iomem *global_mmio_ptr; |
|---|
| 51 | 53 | u64 pp_mmio_start; |
|---|
| 52 | | - struct bin_attribute attr_global_mmio; |
|---|
| 54 | + void *private; |
|---|
| 53 | 55 | }; |
|---|
| 54 | 56 | |
|---|
| 55 | 57 | enum ocxl_context_status { |
|---|
| .. | .. |
|---|
| 92 | 94 | __be32 software_state; |
|---|
| 93 | 95 | }; |
|---|
| 94 | 96 | |
|---|
| 97 | +int ocxl_create_cdev(struct ocxl_afu *afu); |
|---|
| 98 | +void ocxl_destroy_cdev(struct ocxl_afu *afu); |
|---|
| 99 | +int ocxl_file_register_afu(struct ocxl_afu *afu); |
|---|
| 100 | +void ocxl_file_unregister_afu(struct ocxl_afu *afu); |
|---|
| 95 | 101 | |
|---|
| 96 | | -extern struct ocxl_afu *ocxl_afu_get(struct ocxl_afu *afu); |
|---|
| 97 | | -extern void ocxl_afu_put(struct ocxl_afu *afu); |
|---|
| 102 | +int ocxl_file_init(void); |
|---|
| 103 | +void ocxl_file_exit(void); |
|---|
| 98 | 104 | |
|---|
| 99 | | -extern int ocxl_create_cdev(struct ocxl_afu *afu); |
|---|
| 100 | | -extern void ocxl_destroy_cdev(struct ocxl_afu *afu); |
|---|
| 101 | | -extern int ocxl_register_afu(struct ocxl_afu *afu); |
|---|
| 102 | | -extern void ocxl_unregister_afu(struct ocxl_afu *afu); |
|---|
| 105 | +int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); |
|---|
| 106 | +void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); |
|---|
| 107 | +int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); |
|---|
| 108 | +void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size); |
|---|
| 103 | 109 | |
|---|
| 104 | | -extern int ocxl_file_init(void); |
|---|
| 105 | | -extern void ocxl_file_exit(void); |
|---|
| 110 | +/* |
|---|
| 111 | + * Get the max PASID value that can be used by the function |
|---|
| 112 | + */ |
|---|
| 113 | +int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count); |
|---|
| 106 | 114 | |
|---|
| 107 | | -extern int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); |
|---|
| 108 | | -extern void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); |
|---|
| 109 | | -extern int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); |
|---|
| 110 | | -extern void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size); |
|---|
| 115 | +/* |
|---|
| 116 | + * Control whether the FPGA is reloaded on a link reset |
|---|
| 117 | + */ |
|---|
| 118 | +int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val); |
|---|
| 119 | +int ocxl_config_set_reset_reload(struct pci_dev *dev, int val); |
|---|
| 111 | 120 | |
|---|
| 112 | | -extern struct ocxl_context *ocxl_context_alloc(void); |
|---|
| 113 | | -extern int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, |
|---|
| 114 | | - struct address_space *mapping); |
|---|
| 115 | | -extern int ocxl_context_attach(struct ocxl_context *ctx, u64 amr); |
|---|
| 116 | | -extern int ocxl_context_mmap(struct ocxl_context *ctx, |
|---|
| 121 | +/* |
|---|
| 122 | + * Check if an AFU index is valid for the given function. |
|---|
| 123 | + * |
|---|
| 124 | + * AFU indexes can be sparse, so a driver should check all indexes up |
|---|
| 125 | + * to the maximum found in the function description |
|---|
| 126 | + */ |
|---|
| 127 | +int ocxl_config_check_afu_index(struct pci_dev *dev, |
|---|
| 128 | + struct ocxl_fn_config *fn, int afu_idx); |
|---|
| 129 | + |
|---|
| 130 | +/** |
|---|
| 131 | + * ocxl_link_update_pe() - Update values within a Process Element |
|---|
| 132 | + * @link_handle: the link handle associated with the process element |
|---|
| 133 | + * @pasid: the PASID for the AFU context |
|---|
| 134 | + * @tid: the new thread id for the process element |
|---|
| 135 | + * |
|---|
| 136 | + * Returns 0 on success |
|---|
| 137 | + */ |
|---|
| 138 | +int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid); |
|---|
| 139 | + |
|---|
| 140 | +int ocxl_context_mmap(struct ocxl_context *ctx, |
|---|
| 117 | 141 | struct vm_area_struct *vma); |
|---|
| 118 | | -extern int ocxl_context_detach(struct ocxl_context *ctx); |
|---|
| 119 | | -extern void ocxl_context_detach_all(struct ocxl_afu *afu); |
|---|
| 120 | | -extern void ocxl_context_free(struct ocxl_context *ctx); |
|---|
| 142 | +void ocxl_context_detach_all(struct ocxl_afu *afu); |
|---|
| 121 | 143 | |
|---|
| 122 | | -extern int ocxl_sysfs_add_afu(struct ocxl_afu *afu); |
|---|
| 123 | | -extern void ocxl_sysfs_remove_afu(struct ocxl_afu *afu); |
|---|
| 144 | +int ocxl_sysfs_register_afu(struct ocxl_file_info *info); |
|---|
| 145 | +void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info); |
|---|
| 124 | 146 | |
|---|
| 125 | | -extern int ocxl_afu_irq_alloc(struct ocxl_context *ctx, u64 *irq_offset); |
|---|
| 126 | | -extern int ocxl_afu_irq_free(struct ocxl_context *ctx, u64 irq_offset); |
|---|
| 127 | | -extern void ocxl_afu_irq_free_all(struct ocxl_context *ctx); |
|---|
| 128 | | -extern int ocxl_afu_irq_set_fd(struct ocxl_context *ctx, u64 irq_offset, |
|---|
| 129 | | - int eventfd); |
|---|
| 130 | | -extern u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, u64 irq_offset); |
|---|
| 147 | +int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset); |
|---|
| 148 | +u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id); |
|---|
| 149 | +void ocxl_afu_irq_free_all(struct ocxl_context *ctx); |
|---|
| 131 | 150 | |
|---|
| 132 | 151 | #endif /* _OCXL_INTERNAL_H_ */ |
|---|