diff options
Diffstat (limited to 'include/misc/cxl.h')
-rw-r--r-- | include/misc/cxl.h | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/include/misc/cxl.h b/include/misc/cxl.h index 56560c5781b4..480d50a0b8ba 100644 --- a/include/misc/cxl.h +++ b/include/misc/cxl.h | |||
@@ -24,6 +24,46 @@ | |||
24 | * generic PCI API. This API is agnostic to the actual AFU. | 24 | * generic PCI API. This API is agnostic to the actual AFU. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #define CXL_SLOT_FLAG_DMA 0x1 | ||
28 | |||
29 | /* | ||
30 | * Checks if the given card is in a cxl capable slot. Pass CXL_SLOT_FLAG_DMA if | ||
31 | * the card requires CAPP DMA mode to also check if the system supports it. | ||
32 | * This is intended to be used by bi-modal devices to determine if they can use | ||
33 | * cxl mode or if they should continue running in PCI mode. | ||
34 | * | ||
35 | * Note that this only checks if the slot is cxl capable - it does not | ||
36 | * currently check if the CAPP is currently available for chips where it can be | ||
37 | * assigned to different PHBs on a first come first serve basis (i.e. P8) | ||
38 | */ | ||
39 | bool cxl_slot_is_supported(struct pci_dev *dev, int flags); | ||
40 | |||
41 | |||
42 | #define CXL_BIMODE_CXL 1 | ||
43 | #define CXL_BIMODE_PCI 2 | ||
44 | |||
45 | /* | ||
46 | * Check the mode that the given bi-modal CXL adapter is currently in and | ||
47 | * change it if necessary. This does not apply to AFU drivers. | ||
48 | * | ||
49 | * If the mode matches the requested mode this function will return 0 - if the | ||
50 | * driver was expecting the generic CXL driver to have bound to the adapter and | ||
51 | * it gets this return value it should fail the probe function to give the CXL | ||
52 | * driver a chance to probe it. | ||
53 | * | ||
54 | * If the mode does not match it will start a background task to unplug the | ||
55 | * device from Linux and switch its mode, and will return -EBUSY. At this | ||
56 | * point the calling driver should make sure it has released the device and | ||
57 | * fail its probe function. | ||
58 | * | ||
59 | * The offset of the CXL VSEC can be provided to this function. If 0 is passed, | ||
60 | * this function will search for a CXL VSEC with ID 0x1280 and return -ENODEV | ||
61 | * if it is not found. | ||
62 | */ | ||
63 | #ifdef CONFIG_CXL_BIMODAL | ||
64 | int cxl_check_and_switch_mode(struct pci_dev *dev, int mode, int vsec); | ||
65 | #endif | ||
66 | |||
27 | /* Get the AFU associated with a pci_dev */ | 67 | /* Get the AFU associated with a pci_dev */ |
28 | struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev); | 68 | struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev); |
29 | 69 | ||
@@ -86,6 +126,13 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev); | |||
86 | int cxl_release_context(struct cxl_context *ctx); | 126 | int cxl_release_context(struct cxl_context *ctx); |
87 | 127 | ||
88 | /* | 128 | /* |
129 | * Set and get private data associated with a context. Allows drivers to have a | ||
130 | * back pointer to some useful structure. | ||
131 | */ | ||
132 | int cxl_set_priv(struct cxl_context *ctx, void *priv); | ||
133 | void *cxl_get_priv(struct cxl_context *ctx); | ||
134 | |||
135 | /* | ||
89 | * Allocate AFU interrupts for this context. num=0 will allocate the default | 136 | * Allocate AFU interrupts for this context. num=0 will allocate the default |
90 | * for this AFU as given in the AFU descriptor. This number doesn't include the | 137 | * for this AFU as given in the AFU descriptor. This number doesn't include the |
91 | * interrupt 0 (CAIA defines AFU IRQ 0 for page faults). Each interrupt to be | 138 | * interrupt 0 (CAIA defines AFU IRQ 0 for page faults). Each interrupt to be |
@@ -144,6 +191,25 @@ void cxl_psa_unmap(void __iomem *addr); | |||
144 | /* Get the process element for this context */ | 191 | /* Get the process element for this context */ |
145 | int cxl_process_element(struct cxl_context *ctx); | 192 | int cxl_process_element(struct cxl_context *ctx); |
146 | 193 | ||
194 | /* | ||
195 | * Limit the number of interrupts that a single context can allocate via | ||
196 | * cxl_start_work. If using the api with a real phb, this may be used to | ||
197 | * request that additional default contexts be created when allocating | ||
198 | * interrupts via pci_enable_msix_range. These will be set to the same running | ||
199 | * state as the default context, and if that is running it will reuse the | ||
200 | * parameters previously passed to cxl_start_context for the default context. | ||
201 | */ | ||
202 | int cxl_set_max_irqs_per_process(struct pci_dev *dev, int irqs); | ||
203 | int cxl_get_max_irqs_per_process(struct pci_dev *dev); | ||
204 | |||
205 | /* | ||
206 | * Use to simultaneously iterate over hardware interrupt numbers, contexts and | ||
207 | * afu interrupt numbers allocated for the device via pci_enable_msix_range and | ||
208 | * is a useful convenience function when working with hardware that has | ||
209 | * limitations on the number of interrupts per process. *ctx and *afu_irq | ||
210 | * should be NULL and 0 to start the iteration. | ||
211 | */ | ||
212 | int cxl_next_msi_hwirq(struct pci_dev *pdev, struct cxl_context **ctx, int *afu_irq); | ||
147 | 213 | ||
148 | /* | 214 | /* |
149 | * These calls allow drivers to create their own file descriptors and make them | 215 | * These calls allow drivers to create their own file descriptors and make them |
@@ -220,4 +286,52 @@ void cxl_perst_reloads_same_image(struct cxl_afu *afu, | |||
220 | */ | 286 | */ |
221 | ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count); | 287 | ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count); |
222 | 288 | ||
289 | /* | ||
290 | * AFU driver ops allow an AFU driver to create their own events to pass to | ||
291 | * userspace through the file descriptor as a simpler alternative to overriding | ||
292 | * the read() and poll() calls that works with the generic cxl events. These | ||
293 | * events are given priority over the generic cxl events, so they will be | ||
294 | * delivered first if multiple types of events are pending. | ||
295 | * | ||
296 | * The AFU driver must call cxl_context_events_pending() to notify the cxl | ||
297 | * driver that new events are ready to be delivered for a specific context. | ||
298 | * cxl_context_events_pending() will adjust the current count of AFU driver | ||
299 | * events for this context, and wake up anyone waiting on the context wait | ||
300 | * queue. | ||
301 | * | ||
302 | * The cxl driver will then call fetch_event() to get a structure defining | ||
303 | * the size and address of the driver specific event data. The cxl driver | ||
304 | * will build a cxl header with type and process_element fields filled in, | ||
305 | * and header.size set to sizeof(struct cxl_event_header) + data_size. | ||
306 | * The total size of the event is limited to CXL_READ_MIN_SIZE (4K). | ||
307 | * | ||
308 | * fetch_event() is called with a spin lock held, so it must not sleep. | ||
309 | * | ||
310 | * The cxl driver will then deliver the event to userspace, and finally | ||
311 | * call event_delivered() to return the status of the operation, identified | ||
312 | * by cxl context and AFU driver event data pointers. | ||
313 | * 0 Success | ||
314 | * -EFAULT copy_to_user() has failed | ||
315 | * -EINVAL Event data pointer is NULL, or event size is greater than | ||
316 | * CXL_READ_MIN_SIZE. | ||
317 | */ | ||
318 | struct cxl_afu_driver_ops { | ||
319 | struct cxl_event_afu_driver_reserved *(*fetch_event) ( | ||
320 | struct cxl_context *ctx); | ||
321 | void (*event_delivered) (struct cxl_context *ctx, | ||
322 | struct cxl_event_afu_driver_reserved *event, | ||
323 | int rc); | ||
324 | }; | ||
325 | |||
326 | /* | ||
327 | * Associate the above driver ops with a specific context. | ||
328 | * Reset the current count of AFU driver events. | ||
329 | */ | ||
330 | void cxl_set_driver_ops(struct cxl_context *ctx, | ||
331 | struct cxl_afu_driver_ops *ops); | ||
332 | |||
333 | /* Notify cxl driver that new events are ready to be delivered for context */ | ||
334 | void cxl_context_events_pending(struct cxl_context *ctx, | ||
335 | unsigned int new_events); | ||
336 | |||
223 | #endif /* _MISC_CXL_H */ | 337 | #endif /* _MISC_CXL_H */ |