18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci// Copyright 2017 IBM Corp. 38c2ecf20Sopenharmony_ci#ifndef _OCXL_INTERNAL_H_ 48c2ecf20Sopenharmony_ci#define _OCXL_INTERNAL_H_ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/pci.h> 78c2ecf20Sopenharmony_ci#include <linux/cdev.h> 88c2ecf20Sopenharmony_ci#include <linux/list.h> 98c2ecf20Sopenharmony_ci#include <misc/ocxl.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define MAX_IRQ_PER_LINK 2000 128c2ecf20Sopenharmony_ci#define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciextern struct pci_driver ocxl_pci_driver; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct ocxl_fn { 178c2ecf20Sopenharmony_ci struct device dev; 188c2ecf20Sopenharmony_ci int bar_used[3]; 198c2ecf20Sopenharmony_ci struct ocxl_fn_config config; 208c2ecf20Sopenharmony_ci struct list_head afu_list; 218c2ecf20Sopenharmony_ci int pasid_base; 228c2ecf20Sopenharmony_ci int actag_base; 238c2ecf20Sopenharmony_ci int actag_enabled; 248c2ecf20Sopenharmony_ci int actag_supported; 258c2ecf20Sopenharmony_ci struct list_head pasid_list; 268c2ecf20Sopenharmony_ci struct list_head actag_list; 278c2ecf20Sopenharmony_ci void *link; 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct ocxl_file_info { 318c2ecf20Sopenharmony_ci struct ocxl_afu *afu; 328c2ecf20Sopenharmony_ci struct device dev; 338c2ecf20Sopenharmony_ci struct cdev cdev; 348c2ecf20Sopenharmony_ci struct bin_attribute attr_global_mmio; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct ocxl_afu { 388c2ecf20Sopenharmony_ci struct kref kref; 398c2ecf20Sopenharmony_ci struct ocxl_fn *fn; 408c2ecf20Sopenharmony_ci struct list_head list; 418c2ecf20Sopenharmony_ci struct ocxl_afu_config config; 428c2ecf20Sopenharmony_ci int pasid_base; 438c2ecf20Sopenharmony_ci int pasid_count; /* opened contexts */ 448c2ecf20Sopenharmony_ci int pasid_max; /* maximum number of contexts */ 458c2ecf20Sopenharmony_ci int actag_base; 468c2ecf20Sopenharmony_ci int actag_enabled; 478c2ecf20Sopenharmony_ci struct mutex contexts_lock; 488c2ecf20Sopenharmony_ci struct idr contexts_idr; 498c2ecf20Sopenharmony_ci struct mutex afu_control_lock; 508c2ecf20Sopenharmony_ci u64 global_mmio_start; 518c2ecf20Sopenharmony_ci u64 irq_base_offset; 528c2ecf20Sopenharmony_ci void __iomem *global_mmio_ptr; 538c2ecf20Sopenharmony_ci u64 pp_mmio_start; 548c2ecf20Sopenharmony_ci void *private; 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cienum ocxl_context_status { 588c2ecf20Sopenharmony_ci CLOSED, 598c2ecf20Sopenharmony_ci OPENED, 608c2ecf20Sopenharmony_ci ATTACHED, 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci// Contains metadata about a translation fault 648c2ecf20Sopenharmony_cistruct ocxl_xsl_error { 658c2ecf20Sopenharmony_ci u64 addr; // The address that triggered the fault 668c2ecf20Sopenharmony_ci u64 dsisr; // the value of the dsisr register 678c2ecf20Sopenharmony_ci u64 count; // The number of times this fault has been triggered 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct ocxl_context { 718c2ecf20Sopenharmony_ci struct ocxl_afu *afu; 728c2ecf20Sopenharmony_ci int pasid; 738c2ecf20Sopenharmony_ci struct mutex status_mutex; 748c2ecf20Sopenharmony_ci enum ocxl_context_status status; 758c2ecf20Sopenharmony_ci struct address_space *mapping; 768c2ecf20Sopenharmony_ci struct mutex mapping_lock; 778c2ecf20Sopenharmony_ci wait_queue_head_t events_wq; 788c2ecf20Sopenharmony_ci struct mutex xsl_error_lock; 798c2ecf20Sopenharmony_ci struct ocxl_xsl_error xsl_error; 808c2ecf20Sopenharmony_ci struct mutex irq_lock; 818c2ecf20Sopenharmony_ci struct idr irq_idr; 828c2ecf20Sopenharmony_ci u16 tidr; // Thread ID used for P9 wait implementation 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistruct ocxl_process_element { 868c2ecf20Sopenharmony_ci __be64 config_state; 878c2ecf20Sopenharmony_ci __be32 reserved1[11]; 888c2ecf20Sopenharmony_ci __be32 lpid; 898c2ecf20Sopenharmony_ci __be32 tid; 908c2ecf20Sopenharmony_ci __be32 pid; 918c2ecf20Sopenharmony_ci __be32 reserved2[10]; 928c2ecf20Sopenharmony_ci __be64 amr; 938c2ecf20Sopenharmony_ci __be32 reserved3[3]; 948c2ecf20Sopenharmony_ci __be32 software_state; 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciint ocxl_create_cdev(struct ocxl_afu *afu); 988c2ecf20Sopenharmony_civoid ocxl_destroy_cdev(struct ocxl_afu *afu); 998c2ecf20Sopenharmony_ciint ocxl_file_register_afu(struct ocxl_afu *afu); 1008c2ecf20Sopenharmony_civoid ocxl_file_unregister_afu(struct ocxl_afu *afu); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciint ocxl_file_init(void); 1038c2ecf20Sopenharmony_civoid ocxl_file_exit(void); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciint ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); 1068c2ecf20Sopenharmony_civoid ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); 1078c2ecf20Sopenharmony_ciint ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); 1088c2ecf20Sopenharmony_civoid ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci/* 1118c2ecf20Sopenharmony_ci * Get the max PASID value that can be used by the function 1128c2ecf20Sopenharmony_ci */ 1138c2ecf20Sopenharmony_ciint ocxl_config_get_pasid_info(struct pci_dev *dev, int *count); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* 1168c2ecf20Sopenharmony_ci * Control whether the FPGA is reloaded on a link reset 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ciint ocxl_config_get_reset_reload(struct pci_dev *dev, int *val); 1198c2ecf20Sopenharmony_ciint ocxl_config_set_reset_reload(struct pci_dev *dev, int val); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* 1228c2ecf20Sopenharmony_ci * Check if an AFU index is valid for the given function. 1238c2ecf20Sopenharmony_ci * 1248c2ecf20Sopenharmony_ci * AFU indexes can be sparse, so a driver should check all indexes up 1258c2ecf20Sopenharmony_ci * to the maximum found in the function description 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_ciint ocxl_config_check_afu_index(struct pci_dev *dev, 1288c2ecf20Sopenharmony_ci struct ocxl_fn_config *fn, int afu_idx); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/** 1318c2ecf20Sopenharmony_ci * ocxl_link_update_pe() - Update values within a Process Element 1328c2ecf20Sopenharmony_ci * @link_handle: the link handle associated with the process element 1338c2ecf20Sopenharmony_ci * @pasid: the PASID for the AFU context 1348c2ecf20Sopenharmony_ci * @tid: the new thread id for the process element 1358c2ecf20Sopenharmony_ci * 1368c2ecf20Sopenharmony_ci * Returns 0 on success 1378c2ecf20Sopenharmony_ci */ 1388c2ecf20Sopenharmony_ciint ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciint ocxl_context_mmap(struct ocxl_context *ctx, 1418c2ecf20Sopenharmony_ci struct vm_area_struct *vma); 1428c2ecf20Sopenharmony_civoid ocxl_context_detach_all(struct ocxl_afu *afu); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciint ocxl_sysfs_register_afu(struct ocxl_file_info *info); 1458c2ecf20Sopenharmony_civoid ocxl_sysfs_unregister_afu(struct ocxl_file_info *info); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ciint ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset); 1488c2ecf20Sopenharmony_ciu64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id); 1498c2ecf20Sopenharmony_civoid ocxl_afu_irq_free_all(struct ocxl_context *ctx); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#endif /* _OCXL_INTERNAL_H_ */ 152