17ed42113SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */ 25ef3166eSFrederic Barrat // Copyright 2017 IBM Corp. 35ef3166eSFrederic Barrat #ifndef _OCXL_INTERNAL_H_ 45ef3166eSFrederic Barrat #define _OCXL_INTERNAL_H_ 55ef3166eSFrederic Barrat 65ef3166eSFrederic Barrat #include <linux/pci.h> 75ef3166eSFrederic Barrat #include <linux/cdev.h> 85ef3166eSFrederic Barrat #include <linux/list.h> 9280b983cSFrederic Barrat #include <misc/ocxl.h> 105ef3166eSFrederic Barrat 115ef3166eSFrederic Barrat #define MAX_IRQ_PER_LINK 2000 125ef3166eSFrederic Barrat #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK 135ef3166eSFrederic Barrat 145ef3166eSFrederic Barrat extern struct pci_driver ocxl_pci_driver; 155ef3166eSFrederic Barrat 165ef3166eSFrederic Barrat struct ocxl_fn { 175ef3166eSFrederic Barrat struct device dev; 185ef3166eSFrederic Barrat int bar_used[3]; 195ef3166eSFrederic Barrat struct ocxl_fn_config config; 205ef3166eSFrederic Barrat struct list_head afu_list; 215ef3166eSFrederic Barrat int pasid_base; 225ef3166eSFrederic Barrat int actag_base; 235ef3166eSFrederic Barrat int actag_enabled; 245ef3166eSFrederic Barrat int actag_supported; 255ef3166eSFrederic Barrat struct list_head pasid_list; 265ef3166eSFrederic Barrat struct list_head actag_list; 275ef3166eSFrederic Barrat void *link; 285ef3166eSFrederic Barrat }; 295ef3166eSFrederic Barrat 3075ca758aSAlastair D'Silva struct ocxl_file_info { 3175ca758aSAlastair D'Silva struct ocxl_afu *afu; 325ef3166eSFrederic Barrat struct device dev; 335ef3166eSFrederic Barrat struct cdev cdev; 3475ca758aSAlastair D'Silva struct bin_attribute attr_global_mmio; 3575ca758aSAlastair D'Silva }; 3675ca758aSAlastair D'Silva 3775ca758aSAlastair D'Silva struct ocxl_afu { 3875ca758aSAlastair D'Silva struct kref kref; 3975ca758aSAlastair D'Silva struct ocxl_fn *fn; 4075ca758aSAlastair D'Silva struct list_head list; 415ef3166eSFrederic Barrat struct ocxl_afu_config config; 425ef3166eSFrederic Barrat int pasid_base; 435ef3166eSFrederic Barrat int pasid_count; /* opened contexts */ 445ef3166eSFrederic Barrat int pasid_max; /* maximum number of contexts */ 455ef3166eSFrederic Barrat int actag_base; 465ef3166eSFrederic Barrat int actag_enabled; 475ef3166eSFrederic Barrat struct mutex contexts_lock; 485ef3166eSFrederic Barrat struct idr contexts_idr; 495ef3166eSFrederic Barrat struct mutex afu_control_lock; 505ef3166eSFrederic Barrat u64 global_mmio_start; 515ef3166eSFrederic Barrat u64 irq_base_offset; 525ef3166eSFrederic Barrat void __iomem *global_mmio_ptr; 535ef3166eSFrederic Barrat u64 pp_mmio_start; 5475ca758aSAlastair D'Silva void *private; 555ef3166eSFrederic Barrat }; 565ef3166eSFrederic Barrat 575ef3166eSFrederic Barrat enum ocxl_context_status { 585ef3166eSFrederic Barrat CLOSED, 595ef3166eSFrederic Barrat OPENED, 605ef3166eSFrederic Barrat ATTACHED, 615ef3166eSFrederic Barrat }; 625ef3166eSFrederic Barrat 635ef3166eSFrederic Barrat // Contains metadata about a translation fault 645ef3166eSFrederic Barrat struct ocxl_xsl_error { 655ef3166eSFrederic Barrat u64 addr; // The address that triggered the fault 665ef3166eSFrederic Barrat u64 dsisr; // the value of the dsisr register 675ef3166eSFrederic Barrat u64 count; // The number of times this fault has been triggered 685ef3166eSFrederic Barrat }; 695ef3166eSFrederic Barrat 705ef3166eSFrederic Barrat struct ocxl_context { 715ef3166eSFrederic Barrat struct ocxl_afu *afu; 725ef3166eSFrederic Barrat int pasid; 735ef3166eSFrederic Barrat struct mutex status_mutex; 745ef3166eSFrederic Barrat enum ocxl_context_status status; 755ef3166eSFrederic Barrat struct address_space *mapping; 765ef3166eSFrederic Barrat struct mutex mapping_lock; 775ef3166eSFrederic Barrat wait_queue_head_t events_wq; 785ef3166eSFrederic Barrat struct mutex xsl_error_lock; 795ef3166eSFrederic Barrat struct ocxl_xsl_error xsl_error; 805ef3166eSFrederic Barrat struct mutex irq_lock; 815ef3166eSFrederic Barrat struct idr irq_idr; 82e948e06fSAlastair D'Silva u16 tidr; // Thread ID used for P9 wait implementation 835ef3166eSFrederic Barrat }; 845ef3166eSFrederic Barrat 855ef3166eSFrederic Barrat struct ocxl_process_element { 865ef3166eSFrederic Barrat __be64 config_state; 87*d731feeaSChristophe Lombard __be32 pasid; 88*d731feeaSChristophe Lombard __be16 bdf; 89*d731feeaSChristophe Lombard __be16 reserved1; 90*d731feeaSChristophe Lombard __be32 reserved2[9]; 915ef3166eSFrederic Barrat __be32 lpid; 925ef3166eSFrederic Barrat __be32 tid; 935ef3166eSFrederic Barrat __be32 pid; 94*d731feeaSChristophe Lombard __be32 reserved3[10]; 955ef3166eSFrederic Barrat __be64 amr; 96*d731feeaSChristophe Lombard __be32 reserved4[3]; 975ef3166eSFrederic Barrat __be32 software_state; 985ef3166eSFrederic Barrat }; 995ef3166eSFrederic Barrat 10053e3e745SAlastair D'Silva int ocxl_create_cdev(struct ocxl_afu *afu); 10153e3e745SAlastair D'Silva void ocxl_destroy_cdev(struct ocxl_afu *afu); 10275ca758aSAlastair D'Silva int ocxl_file_register_afu(struct ocxl_afu *afu); 10375ca758aSAlastair D'Silva void ocxl_file_unregister_afu(struct ocxl_afu *afu); 1045ef3166eSFrederic Barrat 10553e3e745SAlastair D'Silva int ocxl_file_init(void); 10653e3e745SAlastair D'Silva void ocxl_file_exit(void); 1075ef3166eSFrederic Barrat 10853e3e745SAlastair D'Silva int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); 10953e3e745SAlastair D'Silva void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); 11053e3e745SAlastair D'Silva int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); 11153e3e745SAlastair D'Silva void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size); 1125ef3166eSFrederic Barrat 113b696d282SAlastair D'Silva /* 114b696d282SAlastair D'Silva * Get the max PASID value that can be used by the function 115b696d282SAlastair D'Silva */ 116b696d282SAlastair D'Silva int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count); 117b696d282SAlastair D'Silva 118b696d282SAlastair D'Silva /* 11987db7579SPhilippe Bergheaud * Control whether the FPGA is reloaded on a link reset 12087db7579SPhilippe Bergheaud */ 12187db7579SPhilippe Bergheaud int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val); 12287db7579SPhilippe Bergheaud int ocxl_config_set_reset_reload(struct pci_dev *dev, int val); 12387db7579SPhilippe Bergheaud 12487db7579SPhilippe Bergheaud /* 125b696d282SAlastair D'Silva * Check if an AFU index is valid for the given function. 126b696d282SAlastair D'Silva * 127b696d282SAlastair D'Silva * AFU indexes can be sparse, so a driver should check all indexes up 128b696d282SAlastair D'Silva * to the maximum found in the function description 129b696d282SAlastair D'Silva */ 130b696d282SAlastair D'Silva int ocxl_config_check_afu_index(struct pci_dev *dev, 131b696d282SAlastair D'Silva struct ocxl_fn_config *fn, int afu_idx); 132b696d282SAlastair D'Silva 133b696d282SAlastair D'Silva /** 1343591538aSAlastair D'Silva * ocxl_link_update_pe() - Update values within a Process Element 1353591538aSAlastair D'Silva * @link_handle: the link handle associated with the process element 1363591538aSAlastair D'Silva * @pasid: the PASID for the AFU context 1373591538aSAlastair D'Silva * @tid: the new thread id for the process element 138b696d282SAlastair D'Silva * 1393591538aSAlastair D'Silva * Returns 0 on success 140b696d282SAlastair D'Silva */ 141b696d282SAlastair D'Silva int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid); 142b696d282SAlastair D'Silva 14353e3e745SAlastair D'Silva int ocxl_context_mmap(struct ocxl_context *ctx, 1445ef3166eSFrederic Barrat struct vm_area_struct *vma); 14553e3e745SAlastair D'Silva void ocxl_context_detach_all(struct ocxl_afu *afu); 1465ef3166eSFrederic Barrat 14775ca758aSAlastair D'Silva int ocxl_sysfs_register_afu(struct ocxl_file_info *info); 14875ca758aSAlastair D'Silva void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info); 1495ef3166eSFrederic Barrat 1502ec3b7edSAlastair D'Silva int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset); 1512ec3b7edSAlastair D'Silva u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id); 15253e3e745SAlastair D'Silva void ocxl_afu_irq_free_all(struct ocxl_context *ctx); 153aeddad17SFrederic Barrat 1545ef3166eSFrederic Barrat #endif /* _OCXL_INTERNAL_H_ */ 155