![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0+ 0002 // Copyright 2017 IBM Corp. 0003 #ifndef _MISC_OCXL_H_ 0004 #define _MISC_OCXL_H_ 0005 0006 #include <linux/pci.h> 0007 0008 /* 0009 * Opencapi drivers all need some common facilities, like parsing the 0010 * device configuration space, adding a Process Element to the Shared 0011 * Process Area, etc... 0012 * 0013 * The ocxl module provides a kernel API, to allow other drivers to 0014 * reuse common code. A bit like a in-kernel library. 0015 */ 0016 0017 #define OCXL_AFU_NAME_SZ (24+1) /* add 1 for NULL termination */ 0018 0019 0020 struct ocxl_afu_config { 0021 u8 idx; 0022 int dvsec_afu_control_pos; /* offset of AFU control DVSEC */ 0023 char name[OCXL_AFU_NAME_SZ]; 0024 u8 version_major; 0025 u8 version_minor; 0026 u8 afuc_type; 0027 u8 afum_type; 0028 u8 profile; 0029 u8 global_mmio_bar; /* global MMIO area */ 0030 u64 global_mmio_offset; 0031 u32 global_mmio_size; 0032 u8 pp_mmio_bar; /* per-process MMIO area */ 0033 u64 pp_mmio_offset; 0034 u32 pp_mmio_stride; 0035 u64 lpc_mem_offset; 0036 u64 lpc_mem_size; 0037 u64 special_purpose_mem_offset; 0038 u64 special_purpose_mem_size; 0039 u8 pasid_supported_log; 0040 u16 actag_supported; 0041 }; 0042 0043 struct ocxl_fn_config { 0044 int dvsec_tl_pos; /* offset of the Transaction Layer DVSEC */ 0045 int dvsec_function_pos; /* offset of the Function DVSEC */ 0046 int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */ 0047 s8 max_pasid_log; 0048 s8 max_afu_index; 0049 }; 0050 0051 enum ocxl_endian { 0052 OCXL_BIG_ENDIAN = 0, /**< AFU data is big-endian */ 0053 OCXL_LITTLE_ENDIAN = 1, /**< AFU data is little-endian */ 0054 OCXL_HOST_ENDIAN = 2, /**< AFU data is the same endianness as the host */ 0055 }; 0056 0057 // These are opaque outside the ocxl driver 0058 struct ocxl_afu; 0059 struct ocxl_fn; 0060 struct ocxl_context; 0061 0062 // Device detection & initialisation 0063 0064 /** 0065 * ocxl_function_open() - Open an OpenCAPI function on an OpenCAPI device 0066 * @dev: The PCI device that contains the function 0067 * 0068 * Returns an opaque pointer to the function, or an error pointer (check with IS_ERR) 0069 */ 0070 struct ocxl_fn *ocxl_function_open(struct pci_dev *dev); 0071 0072 /** 0073 * ocxl_function_afu_list() - Get the list of AFUs associated with a PCI function device 0074 * Returns a list of struct ocxl_afu * 0075 * 0076 * @fn: The OpenCAPI function containing the AFUs 0077 */ 0078 struct list_head *ocxl_function_afu_list(struct ocxl_fn *fn); 0079 0080 /** 0081 * ocxl_function_fetch_afu() - Fetch an AFU instance from an OpenCAPI function 0082 * @fn: The OpenCAPI function to get the AFU from 0083 * @afu_idx: The index of the AFU to get 0084 * 0085 * If successful, the AFU should be released with ocxl_afu_put() 0086 * 0087 * Returns a pointer to the AFU, or NULL on error 0088 */ 0089 struct ocxl_afu *ocxl_function_fetch_afu(struct ocxl_fn *fn, u8 afu_idx); 0090 0091 /** 0092 * ocxl_afu_get() - Take a reference to an AFU 0093 * @afu: The AFU to increment the reference count on 0094 */ 0095 void ocxl_afu_get(struct ocxl_afu *afu); 0096 0097 /** 0098 * ocxl_afu_put() - Release a reference to an AFU 0099 * @afu: The AFU to decrement the reference count on 0100 */ 0101 void ocxl_afu_put(struct ocxl_afu *afu); 0102 0103 0104 /** 0105 * ocxl_function_config() - Get the configuration information for an OpenCAPI function 0106 * @fn: The OpenCAPI function to get the config for 0107 * 0108 * Returns the function config, or NULL on error 0109 */ 0110 const struct ocxl_fn_config *ocxl_function_config(struct ocxl_fn *fn); 0111 0112 /** 0113 * ocxl_function_close() - Close an OpenCAPI function 0114 * This will free any AFUs previously retrieved from the function, and 0115 * detach and associated contexts. The contexts must by freed by the caller. 0116 * 0117 * @fn: The OpenCAPI function to close 0118 * 0119 */ 0120 void ocxl_function_close(struct ocxl_fn *fn); 0121 0122 // Context allocation 0123 0124 /** 0125 * ocxl_context_alloc() - Allocate an OpenCAPI context 0126 * @context: The OpenCAPI context to allocate, must be freed with ocxl_context_free 0127 * @afu: The AFU the context belongs to 0128 * @mapping: The mapping to unmap when the context is closed (may be NULL) 0129 */ 0130 int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, 0131 struct address_space *mapping); 0132 0133 /** 0134 * ocxl_context_free() - Free an OpenCAPI context 0135 * @ctx: The OpenCAPI context to free 0136 */ 0137 void ocxl_context_free(struct ocxl_context *ctx); 0138 0139 /** 0140 * ocxl_context_attach() - Grant access to an MM to an OpenCAPI context 0141 * @ctx: The OpenCAPI context to attach 0142 * @amr: The value of the AMR register to restrict access 0143 * @mm: The mm to attach to the context 0144 * 0145 * Returns 0 on success, negative on failure 0146 */ 0147 int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, 0148 struct mm_struct *mm); 0149 0150 /** 0151 * ocxl_context_detach() - Detach an MM from an OpenCAPI context 0152 * @ctx: The OpenCAPI context to attach 0153 * 0154 * Returns 0 on success, negative on failure 0155 */ 0156 int ocxl_context_detach(struct ocxl_context *ctx); 0157 0158 // AFU IRQs 0159 0160 /** 0161 * ocxl_afu_irq_alloc() - Allocate an IRQ associated with an AFU context 0162 * @ctx: the AFU context 0163 * @irq_id: out, the IRQ ID 0164 * 0165 * Returns 0 on success, negative on failure 0166 */ 0167 int ocxl_afu_irq_alloc(struct ocxl_context *ctx, int *irq_id); 0168 0169 /** 0170 * ocxl_afu_irq_free() - Frees an IRQ associated with an AFU context 0171 * @ctx: the AFU context 0172 * @irq_id: the IRQ ID 0173 * 0174 * Returns 0 on success, negative on failure 0175 */ 0176 int ocxl_afu_irq_free(struct ocxl_context *ctx, int irq_id); 0177 0178 /** 0179 * ocxl_afu_irq_get_addr() - Gets the address of the trigger page for an IRQ 0180 * This can then be provided to an AFU which will write to that 0181 * page to trigger the IRQ. 0182 * @ctx: The AFU context that the IRQ is associated with 0183 * @irq_id: The IRQ ID 0184 * 0185 * returns the trigger page address, or 0 if the IRQ is not valid 0186 */ 0187 u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, int irq_id); 0188 0189 /** 0190 * ocxl_irq_set_handler() - Provide a callback to be called when an IRQ is triggered 0191 * @ctx: The AFU context that the IRQ is associated with 0192 * @irq_id: The IRQ ID 0193 * @handler: the callback to be called when the IRQ is triggered 0194 * @free_private: the callback to be called when the IRQ is freed (may be NULL) 0195 * @private: Private data to be passed to the callbacks 0196 * 0197 * Returns 0 on success, negative on failure 0198 */ 0199 int ocxl_irq_set_handler(struct ocxl_context *ctx, int irq_id, 0200 irqreturn_t (*handler)(void *private), 0201 void (*free_private)(void *private), 0202 void *private); 0203 0204 // AFU Metadata 0205 0206 /** 0207 * ocxl_afu_config() - Get a pointer to the config for an AFU 0208 * @afu: a pointer to the AFU to get the config for 0209 * 0210 * Returns a pointer to the AFU config 0211 */ 0212 struct ocxl_afu_config *ocxl_afu_config(struct ocxl_afu *afu); 0213 0214 /** 0215 * ocxl_afu_set_private() - Assign opaque hardware specific information to an OpenCAPI AFU. 0216 * @afu: The OpenCAPI AFU 0217 * @private: the opaque hardware specific information to assign to the driver 0218 */ 0219 void ocxl_afu_set_private(struct ocxl_afu *afu, void *private); 0220 0221 /** 0222 * ocxl_afu_get_private() - Fetch the hardware specific information associated with 0223 * an external OpenCAPI AFU. This may be consumed by an external OpenCAPI driver. 0224 * @afu: The OpenCAPI AFU 0225 * 0226 * Returns the opaque pointer associated with the device, or NULL if not set 0227 */ 0228 void *ocxl_afu_get_private(struct ocxl_afu *afu); 0229 0230 // Global MMIO 0231 /** 0232 * ocxl_global_mmio_read32() - Read a 32 bit value from global MMIO 0233 * @afu: The AFU 0234 * @offset: The Offset from the start of MMIO 0235 * @endian: the endianness that the MMIO data is in 0236 * @val: returns the value 0237 * 0238 * Returns 0 for success, negative on error 0239 */ 0240 int ocxl_global_mmio_read32(struct ocxl_afu *afu, size_t offset, 0241 enum ocxl_endian endian, u32 *val); 0242 0243 /** 0244 * ocxl_global_mmio_read64() - Read a 64 bit value from global MMIO 0245 * @afu: The AFU 0246 * @offset: The Offset from the start of MMIO 0247 * @endian: the endianness that the MMIO data is in 0248 * @val: returns the value 0249 * 0250 * Returns 0 for success, negative on error 0251 */ 0252 int ocxl_global_mmio_read64(struct ocxl_afu *afu, size_t offset, 0253 enum ocxl_endian endian, u64 *val); 0254 0255 /** 0256 * ocxl_global_mmio_write32() - Write a 32 bit value to global MMIO 0257 * @afu: The AFU 0258 * @offset: The Offset from the start of MMIO 0259 * @endian: the endianness that the MMIO data is in 0260 * @val: The value to write 0261 * 0262 * Returns 0 for success, negative on error 0263 */ 0264 int ocxl_global_mmio_write32(struct ocxl_afu *afu, size_t offset, 0265 enum ocxl_endian endian, u32 val); 0266 0267 /** 0268 * ocxl_global_mmio_write64() - Write a 64 bit value to global MMIO 0269 * @afu: The AFU 0270 * @offset: The Offset from the start of MMIO 0271 * @endian: the endianness that the MMIO data is in 0272 * @val: The value to write 0273 * 0274 * Returns 0 for success, negative on error 0275 */ 0276 int ocxl_global_mmio_write64(struct ocxl_afu *afu, size_t offset, 0277 enum ocxl_endian endian, u64 val); 0278 0279 /** 0280 * ocxl_global_mmio_set32() - Set bits in a 32 bit global MMIO register 0281 * @afu: The AFU 0282 * @offset: The Offset from the start of MMIO 0283 * @endian: the endianness that the MMIO data is in 0284 * @mask: a mask of the bits to set 0285 * 0286 * Returns 0 for success, negative on error 0287 */ 0288 int ocxl_global_mmio_set32(struct ocxl_afu *afu, size_t offset, 0289 enum ocxl_endian endian, u32 mask); 0290 0291 /** 0292 * ocxl_global_mmio_set64() - Set bits in a 64 bit global MMIO register 0293 * @afu: The AFU 0294 * @offset: The Offset from the start of MMIO 0295 * @endian: the endianness that the MMIO data is in 0296 * @mask: a mask of the bits to set 0297 * 0298 * Returns 0 for success, negative on error 0299 */ 0300 int ocxl_global_mmio_set64(struct ocxl_afu *afu, size_t offset, 0301 enum ocxl_endian endian, u64 mask); 0302 0303 /** 0304 * ocxl_global_mmio_clear32() - Set bits in a 32 bit global MMIO register 0305 * @afu: The AFU 0306 * @offset: The Offset from the start of MMIO 0307 * @endian: the endianness that the MMIO data is in 0308 * @mask: a mask of the bits to set 0309 * 0310 * Returns 0 for success, negative on error 0311 */ 0312 int ocxl_global_mmio_clear32(struct ocxl_afu *afu, size_t offset, 0313 enum ocxl_endian endian, u32 mask); 0314 0315 /** 0316 * ocxl_global_mmio_clear64() - Set bits in a 64 bit global MMIO register 0317 * @afu: The AFU 0318 * @offset: The Offset from the start of MMIO 0319 * @endian: the endianness that the MMIO data is in 0320 * @mask: a mask of the bits to set 0321 * 0322 * Returns 0 for success, negative on error 0323 */ 0324 int ocxl_global_mmio_clear64(struct ocxl_afu *afu, size_t offset, 0325 enum ocxl_endian endian, u64 mask); 0326 0327 // Functions left here are for compatibility with the cxlflash driver 0328 0329 /* 0330 * Read the configuration space of a function for the AFU specified by 0331 * the index 'afu_idx'. Fills in a ocxl_afu_config structure 0332 */ 0333 int ocxl_config_read_afu(struct pci_dev *dev, 0334 struct ocxl_fn_config *fn, 0335 struct ocxl_afu_config *afu, 0336 u8 afu_idx); 0337 0338 /* 0339 * Tell an AFU, by writing in the configuration space, the PASIDs that 0340 * it can use. Range starts at 'pasid_base' and its size is a multiple 0341 * of 2 0342 * 0343 * 'afu_control_offset' is the offset of the AFU control DVSEC which 0344 * can be found in the function configuration 0345 */ 0346 void ocxl_config_set_afu_pasid(struct pci_dev *dev, 0347 int afu_control_offset, 0348 int pasid_base, u32 pasid_count_log); 0349 0350 /* 0351 * Get the actag configuration for the function: 0352 * 'base' is the first actag value that can be used. 0353 * 'enabled' it the number of actags available, starting from base. 0354 * 'supported' is the total number of actags desired by all the AFUs 0355 * of the function. 0356 */ 0357 int ocxl_config_get_actag_info(struct pci_dev *dev, 0358 u16 *base, u16 *enabled, u16 *supported); 0359 0360 /* 0361 * Tell a function, by writing in the configuration space, the actags 0362 * it can use. 0363 * 0364 * 'func_offset' is the offset of the Function DVSEC that can found in 0365 * the function configuration 0366 */ 0367 void ocxl_config_set_actag(struct pci_dev *dev, int func_offset, 0368 u32 actag_base, u32 actag_count); 0369 0370 /* 0371 * Tell an AFU, by writing in the configuration space, the actags it 0372 * can use. 0373 * 0374 * 'afu_control_offset' is the offset of the AFU control DVSEC for the 0375 * desired AFU. It can be found in the AFU configuration 0376 */ 0377 void ocxl_config_set_afu_actag(struct pci_dev *dev, 0378 int afu_control_offset, 0379 int actag_base, int actag_count); 0380 0381 /* 0382 * Enable/disable an AFU, by writing in the configuration space. 0383 * 0384 * 'afu_control_offset' is the offset of the AFU control DVSEC for the 0385 * desired AFU. It can be found in the AFU configuration 0386 */ 0387 void ocxl_config_set_afu_state(struct pci_dev *dev, 0388 int afu_control_offset, int enable); 0389 0390 /* 0391 * Set the Transaction Layer configuration in the configuration space. 0392 * Only needed for function 0. 0393 * 0394 * It queries the host TL capabilities, find some common ground 0395 * between the host and device, and set the Transaction Layer on both 0396 * accordingly. 0397 */ 0398 int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec); 0399 0400 /* 0401 * Request an AFU to terminate a PASID. 0402 * Will return once the AFU has acked the request, or an error in case 0403 * of timeout. 0404 * 0405 * The hardware can only terminate one PASID at a time, so caller must 0406 * guarantee some kind of serialization. 0407 * 0408 * 'afu_control_offset' is the offset of the AFU control DVSEC for the 0409 * desired AFU. It can be found in the AFU configuration 0410 */ 0411 int ocxl_config_terminate_pasid(struct pci_dev *dev, 0412 int afu_control_offset, int pasid); 0413 0414 /* 0415 * Read the configuration space of a function and fill in a 0416 * ocxl_fn_config structure with all the function details 0417 */ 0418 int ocxl_config_read_function(struct pci_dev *dev, 0419 struct ocxl_fn_config *fn); 0420 0421 /* 0422 * Set up the opencapi link for the function. 0423 * 0424 * When called for the first time for a link, it sets up the Shared 0425 * Process Area for the link and the interrupt handler to process 0426 * translation faults. 0427 * 0428 * Returns a 'link handle' that should be used for further calls for 0429 * the link 0430 */ 0431 int ocxl_link_setup(struct pci_dev *dev, int PE_mask, 0432 void **link_handle); 0433 0434 /* 0435 * Remove the association between the function and its link. 0436 */ 0437 void ocxl_link_release(struct pci_dev *dev, void *link_handle); 0438 0439 /* 0440 * Add a Process Element to the Shared Process Area for a link. 0441 * The process is defined by its PASID, pid, tid and its mm_struct. 0442 * 0443 * 'xsl_err_cb' is an optional callback if the driver wants to be 0444 * notified when the translation fault interrupt handler detects an 0445 * address error. 0446 * 'xsl_err_data' is an argument passed to the above callback, if 0447 * defined 0448 */ 0449 int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr, 0450 u64 amr, u16 bdf, struct mm_struct *mm, 0451 void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr), 0452 void *xsl_err_data); 0453 0454 /* 0455 * Remove a Process Element from the Shared Process Area for a link 0456 */ 0457 int ocxl_link_remove_pe(void *link_handle, int pasid); 0458 0459 /* 0460 * Allocate an AFU interrupt associated to the link. 0461 * 0462 * 'hw_irq' is the hardware interrupt number 0463 */ 0464 int ocxl_link_irq_alloc(void *link_handle, int *hw_irq); 0465 0466 /* 0467 * Free a previously allocated AFU interrupt 0468 */ 0469 void ocxl_link_free_irq(void *link_handle, int hw_irq); 0470 0471 #endif /* _MISC_OCXL_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |