Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 2015 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #ifndef _MISC_CXL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #define _MISC_CXL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <uapi/misc/cxl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * This documents the in kernel API for driver to use CXL. It allows kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * drivers to bind to AFUs using an AFU configuration record exposed as a PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * configuration record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * This API enables control over AFU and contexts which can't be part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * generic PCI API. This API is agnostic to the actual AFU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* Get the AFU associated with a pci_dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* Get the AFU conf record number associated with a pci_dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) unsigned int cxl_pci_to_cfg_record(struct pci_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * Context lifetime overview:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * An AFU context may be inited and then started and stoppped multiple times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * before it's released. ie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *    - cxl_dev_context_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *      - cxl_start_context()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *      - cxl_stop_context()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *      - cxl_start_context()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *      - cxl_stop_context()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *     ...repeat...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *    - cxl_release_context()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * Once released, a context can't be started again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * One context is inited by the cxl driver for every pci_dev. This is to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * used as a default kernel context. cxl_get_context() will get this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * context. This context will be released by PCI hot unplug, so doesn't need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * be released explicitly by drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Additional kernel contexts may be inited using cxl_dev_context_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * These must be released using cxl_context_detach().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * Once a context has been inited, IRQs may be configured. Firstly these IRQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * must be allocated (cxl_allocate_afu_irqs()), then individually mapped to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * specific handlers (cxl_map_afu_irq()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * These IRQs can be unmapped (cxl_unmap_afu_irq()) and finally released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * (cxl_free_afu_irqs()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * The AFU can be reset (cxl_afu_reset()). This will cause the PSL/AFU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * hardware to lose track of all contexts. It's upto the caller of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * cxl_afu_reset() to restart these contexts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * On pci_enabled_device(), the cxl driver will init a single cxl context for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * use by the driver. It doesn't start this context (as that will likely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * generate DMA traffic for most AFUs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * This gets the default context associated with this pci_dev.  This context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * doesn't need to be released as this will be done by the PCI subsystem on hot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * unplug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) struct cxl_context *cxl_get_context(struct pci_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * Allocate and initalise a context associated with a AFU PCI device. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * doesn't start the context in the AFU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) struct cxl_context *cxl_dev_context_init(struct pci_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * Release and free a context. Context should be stopped before calling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) int cxl_release_context(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * Set and get private data associated with a context. Allows drivers to have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * back pointer to some useful structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) int cxl_set_priv(struct cxl_context *ctx, void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) void *cxl_get_priv(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * Allocate AFU interrupts for this context. num=0 will allocate the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * for this AFU as given in the AFU descriptor. This number doesn't include the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * interrupt 0 (CAIA defines AFU IRQ 0 for page faults). Each interrupt to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * used must map a handler with cxl_map_afu_irq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) int cxl_allocate_afu_irqs(struct cxl_context *cxl, int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) /* Free allocated interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) void cxl_free_afu_irqs(struct cxl_context *cxl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Map a handler for an AFU interrupt associated with a particular context. AFU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * IRQS numbers start from 1 (CAIA defines AFU IRQ 0 for page faults). cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * is private data is that will be provided to the interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int cxl_map_afu_irq(struct cxl_context *cxl, int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		    irq_handler_t handler, void *cookie, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* unmap mapped IRQ handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void cxl_unmap_afu_irq(struct cxl_context *cxl, int num, void *cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * Start work on the AFU. This starts an cxl context and associates it with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * task. task == NULL will make it a kernel context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int cxl_start_context(struct cxl_context *ctx, u64 wed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		      struct task_struct *task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * Stop a context and remove it from the PSL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int cxl_stop_context(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* Reset the AFU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int cxl_afu_reset(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * Set a context as a master context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * This sets the default problem space area mapped as the full space, rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * than just the per context area (for slaves).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void cxl_set_master(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * Map and unmap the AFU Problem Space area. The amount and location mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * depends on if this context is a master or slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void __iomem *cxl_psa_map(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void cxl_psa_unmap(void __iomem *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*  Get the process element for this context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int cxl_process_element(struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * These calls allow drivers to create their own file descriptors and make them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * identical to the cxl file descriptor user API. An example use case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * struct file_operations cxl_my_fops = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * ......
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  *	// Init the context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  *	ctx = cxl_dev_context_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  *	if (IS_ERR(ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *		return PTR_ERR(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *	// Create and attach a new file descriptor to my file ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *	file = cxl_get_fd(ctx, &cxl_my_fops, &fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  *	// Start context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *	rc = cxl_start_work(ctx, &work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  *	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *		fput(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *		put_unused_fd(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  *	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *	// No error paths after installing the fd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *	fd_install(fd, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  *	return fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * This inits a context, and gets a file descriptor and associates some file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * ops to that file descriptor. If the file ops are blank, the cxl driver will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * fill them in with the default ones that mimic the standard user API.  Once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * completed, the file descriptor can be installed. Once the file descriptor is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * installed, it's visible to the user so no errors must occur past this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * If cxl_fd_release() file op call is installed, the context will be stopped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * and released when the fd is released. Hence the driver won't need to manage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * this itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * Take a context and associate it with my file ops. Returns the associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * file and file descriptor. Any file ops which are blank are filled in by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * cxl driver with the default ops to mimic the standard API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			int *fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Get the context associated with this file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct cxl_context *cxl_fops_get_context(struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * Start a context associated a struct cxl_ioctl_start_work used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * standard cxl user API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int cxl_start_work(struct cxl_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		   struct cxl_ioctl_start_work *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * Export all the existing fops so drivers can use them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int cxl_fd_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int cxl_fd_release(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) __poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			   loff_t *off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * For EEH, a driver may want to assert a PERST will reload the same image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * from flash into the FPGA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * This is a property of the entire adapter, not a single AFU, so drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * should set this property with care!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) void cxl_perst_reloads_same_image(struct cxl_afu *afu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				  bool perst_reloads_same_image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * Read the VPD for the card where the AFU resides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * AFU driver ops allow an AFU driver to create their own events to pass to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * userspace through the file descriptor as a simpler alternative to overriding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * the read() and poll() calls that works with the generic cxl events. These
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * events are given priority over the generic cxl events, so they will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * delivered first if multiple types of events are pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * The AFU driver must call cxl_context_events_pending() to notify the cxl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * driver that new events are ready to be delivered for a specific context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * cxl_context_events_pending() will adjust the current count of AFU driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * events for this context, and wake up anyone waiting on the context wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * The cxl driver will then call fetch_event() to get a structure defining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * the size and address of the driver specific event data. The cxl driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * will build a cxl header with type and process_element fields filled in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * and header.size set to sizeof(struct cxl_event_header) + data_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * The total size of the event is limited to CXL_READ_MIN_SIZE (4K).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * fetch_event() is called with a spin lock held, so it must not sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * The cxl driver will then deliver the event to userspace, and finally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * call event_delivered() to return the status of the operation, identified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * by cxl context and AFU driver event data pointers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  *   0        Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  *   -EFAULT  copy_to_user() has failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *   -EINVAL  Event data pointer is NULL, or event size is greater than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  *            CXL_READ_MIN_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct cxl_afu_driver_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct cxl_event_afu_driver_reserved *(*fetch_event) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 						struct cxl_context *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	void (*event_delivered) (struct cxl_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				 struct cxl_event_afu_driver_reserved *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				 int rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * Associate the above driver ops with a specific context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * Reset the current count of AFU driver events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void cxl_set_driver_ops(struct cxl_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			struct cxl_afu_driver_ops *ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Notify cxl driver that new events are ready to be delivered for context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) void cxl_context_events_pending(struct cxl_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				unsigned int new_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #endif /* _MISC_CXL_H */