18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_S390_PCI_H 38c2ecf20Sopenharmony_ci#define __ASM_S390_PCI_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/pci.h> 68c2ecf20Sopenharmony_ci#include <linux/mutex.h> 78c2ecf20Sopenharmony_ci#include <linux/iommu.h> 88c2ecf20Sopenharmony_ci#include <linux/pci_hotplug.h> 98c2ecf20Sopenharmony_ci#include <asm-generic/pci.h> 108c2ecf20Sopenharmony_ci#include <asm/pci_clp.h> 118c2ecf20Sopenharmony_ci#include <asm/pci_debug.h> 128c2ecf20Sopenharmony_ci#include <asm/sclp.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define PCIBIOS_MIN_IO 0x1000 158c2ecf20Sopenharmony_ci#define PCIBIOS_MIN_MEM 0x10000000 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define pcibios_assign_all_busses() (0) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_civoid __iomem *pci_iomap(struct pci_dev *, int, unsigned long); 208c2ecf20Sopenharmony_civoid pci_iounmap(struct pci_dev *, void __iomem *); 218c2ecf20Sopenharmony_ciint pci_domain_nr(struct pci_bus *); 228c2ecf20Sopenharmony_ciint pci_proc_domain(struct pci_bus *); 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define ZPCI_BUS_NR 0 /* default bus number */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define ZPCI_NR_DMA_SPACES 1 278c2ecf20Sopenharmony_ci#define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS 288c2ecf20Sopenharmony_ci#define ZPCI_DOMAIN_BITMAP_SIZE (1 << 16) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#ifdef PCI 318c2ecf20Sopenharmony_ci#if (ZPCI_NR_DEVICES > ZPCI_DOMAIN_BITMAP_SIZE) 328c2ecf20Sopenharmony_ci# error ZPCI_NR_DEVICES can not be bigger than ZPCI_DOMAIN_BITMAP_SIZE 338c2ecf20Sopenharmony_ci#endif 348c2ecf20Sopenharmony_ci#endif /* PCI */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* PCI Function Controls */ 378c2ecf20Sopenharmony_ci#define ZPCI_FC_FN_ENABLED 0x80 388c2ecf20Sopenharmony_ci#define ZPCI_FC_ERROR 0x40 398c2ecf20Sopenharmony_ci#define ZPCI_FC_BLOCKED 0x20 408c2ecf20Sopenharmony_ci#define ZPCI_FC_DMA_ENABLED 0x10 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define ZPCI_FMB_DMA_COUNTER_VALID (1 << 23) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistruct zpci_fmb_fmt0 { 458c2ecf20Sopenharmony_ci u64 dma_rbytes; 468c2ecf20Sopenharmony_ci u64 dma_wbytes; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct zpci_fmb_fmt1 { 508c2ecf20Sopenharmony_ci u64 rx_bytes; 518c2ecf20Sopenharmony_ci u64 rx_packets; 528c2ecf20Sopenharmony_ci u64 tx_bytes; 538c2ecf20Sopenharmony_ci u64 tx_packets; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct zpci_fmb_fmt2 { 578c2ecf20Sopenharmony_ci u64 consumed_work_units; 588c2ecf20Sopenharmony_ci u64 max_work_units; 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct zpci_fmb_fmt3 { 628c2ecf20Sopenharmony_ci u64 tx_bytes; 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistruct zpci_fmb { 668c2ecf20Sopenharmony_ci u32 format : 8; 678c2ecf20Sopenharmony_ci u32 fmt_ind : 24; 688c2ecf20Sopenharmony_ci u32 samples; 698c2ecf20Sopenharmony_ci u64 last_update; 708c2ecf20Sopenharmony_ci /* common counters */ 718c2ecf20Sopenharmony_ci u64 ld_ops; 728c2ecf20Sopenharmony_ci u64 st_ops; 738c2ecf20Sopenharmony_ci u64 stb_ops; 748c2ecf20Sopenharmony_ci u64 rpcit_ops; 758c2ecf20Sopenharmony_ci /* format specific counters */ 768c2ecf20Sopenharmony_ci union { 778c2ecf20Sopenharmony_ci struct zpci_fmb_fmt0 fmt0; 788c2ecf20Sopenharmony_ci struct zpci_fmb_fmt1 fmt1; 798c2ecf20Sopenharmony_ci struct zpci_fmb_fmt2 fmt2; 808c2ecf20Sopenharmony_ci struct zpci_fmb_fmt3 fmt3; 818c2ecf20Sopenharmony_ci }; 828c2ecf20Sopenharmony_ci} __packed __aligned(128); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cienum zpci_state { 858c2ecf20Sopenharmony_ci ZPCI_FN_STATE_STANDBY = 0, 868c2ecf20Sopenharmony_ci ZPCI_FN_STATE_CONFIGURED = 1, 878c2ecf20Sopenharmony_ci ZPCI_FN_STATE_RESERVED = 2, 888c2ecf20Sopenharmony_ci ZPCI_FN_STATE_ONLINE = 3, 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistruct zpci_bar_struct { 928c2ecf20Sopenharmony_ci struct resource *res; /* bus resource */ 938c2ecf20Sopenharmony_ci void __iomem *mio_wb; 948c2ecf20Sopenharmony_ci void __iomem *mio_wt; 958c2ecf20Sopenharmony_ci u32 val; /* bar start & 3 flag bits */ 968c2ecf20Sopenharmony_ci u16 map_idx; /* index into bar mapping array */ 978c2ecf20Sopenharmony_ci u8 size; /* order 2 exponent */ 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct s390_domain; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define ZPCI_FUNCTIONS_PER_BUS 256 1038c2ecf20Sopenharmony_cistruct zpci_bus { 1048c2ecf20Sopenharmony_ci struct kref kref; 1058c2ecf20Sopenharmony_ci struct pci_bus *bus; 1068c2ecf20Sopenharmony_ci struct zpci_dev *function[ZPCI_FUNCTIONS_PER_BUS]; 1078c2ecf20Sopenharmony_ci struct list_head resources; 1088c2ecf20Sopenharmony_ci struct list_head bus_next; 1098c2ecf20Sopenharmony_ci struct resource bus_resource; 1108c2ecf20Sopenharmony_ci int pchid; 1118c2ecf20Sopenharmony_ci int domain_nr; 1128c2ecf20Sopenharmony_ci bool multifunction; 1138c2ecf20Sopenharmony_ci enum pci_bus_speed max_bus_speed; 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/* Private data per function */ 1178c2ecf20Sopenharmony_cistruct zpci_dev { 1188c2ecf20Sopenharmony_ci struct zpci_bus *zbus; 1198c2ecf20Sopenharmony_ci struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */ 1208c2ecf20Sopenharmony_ci struct list_head bus_next; 1218c2ecf20Sopenharmony_ci struct kref kref; 1228c2ecf20Sopenharmony_ci struct hotplug_slot hotplug_slot; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci enum zpci_state state; 1258c2ecf20Sopenharmony_ci u32 fid; /* function ID, used by sclp */ 1268c2ecf20Sopenharmony_ci u32 fh; /* function handle, used by insn's */ 1278c2ecf20Sopenharmony_ci u16 vfn; /* virtual function number */ 1288c2ecf20Sopenharmony_ci u16 pchid; /* physical channel ID */ 1298c2ecf20Sopenharmony_ci u8 pfgid; /* function group ID */ 1308c2ecf20Sopenharmony_ci u8 pft; /* pci function type */ 1318c2ecf20Sopenharmony_ci u8 port; 1328c2ecf20Sopenharmony_ci u8 rid_available : 1; 1338c2ecf20Sopenharmony_ci u8 has_hp_slot : 1; 1348c2ecf20Sopenharmony_ci u8 is_physfn : 1; 1358c2ecf20Sopenharmony_ci u8 util_str_avail : 1; 1368c2ecf20Sopenharmony_ci u8 reserved : 4; 1378c2ecf20Sopenharmony_ci unsigned int devfn; /* DEVFN part of the RID*/ 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci struct mutex lock; 1408c2ecf20Sopenharmony_ci u8 pfip[CLP_PFIP_NR_SEGMENTS]; /* pci function internal path */ 1418c2ecf20Sopenharmony_ci u32 uid; /* user defined id */ 1428c2ecf20Sopenharmony_ci u8 util_str[CLP_UTIL_STR_LEN]; /* utility string */ 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci /* IRQ stuff */ 1458c2ecf20Sopenharmony_ci u64 msi_addr; /* MSI address */ 1468c2ecf20Sopenharmony_ci unsigned int max_msi; /* maximum number of MSI's */ 1478c2ecf20Sopenharmony_ci unsigned int msi_first_bit; 1488c2ecf20Sopenharmony_ci unsigned int msi_nr_irqs; 1498c2ecf20Sopenharmony_ci struct airq_iv *aibv; /* adapter interrupt bit vector */ 1508c2ecf20Sopenharmony_ci unsigned long aisb; /* number of the summary bit */ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci /* DMA stuff */ 1538c2ecf20Sopenharmony_ci unsigned long *dma_table; 1548c2ecf20Sopenharmony_ci spinlock_t dma_table_lock; 1558c2ecf20Sopenharmony_ci int tlb_refresh; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci spinlock_t iommu_bitmap_lock; 1588c2ecf20Sopenharmony_ci unsigned long *iommu_bitmap; 1598c2ecf20Sopenharmony_ci unsigned long *lazy_bitmap; 1608c2ecf20Sopenharmony_ci unsigned long iommu_size; 1618c2ecf20Sopenharmony_ci unsigned long iommu_pages; 1628c2ecf20Sopenharmony_ci unsigned int next_bit; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci struct iommu_device iommu_dev; /* IOMMU core handle */ 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci char res_name[16]; 1678c2ecf20Sopenharmony_ci bool mio_capable; 1688c2ecf20Sopenharmony_ci struct zpci_bar_struct bars[PCI_STD_NUM_BARS]; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci u64 start_dma; /* Start of available DMA addresses */ 1718c2ecf20Sopenharmony_ci u64 end_dma; /* End of available DMA addresses */ 1728c2ecf20Sopenharmony_ci u64 dma_mask; /* DMA address space mask */ 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci /* Function measurement block */ 1758c2ecf20Sopenharmony_ci struct zpci_fmb *fmb; 1768c2ecf20Sopenharmony_ci u16 fmb_update; /* update interval */ 1778c2ecf20Sopenharmony_ci u16 fmb_length; 1788c2ecf20Sopenharmony_ci /* software counters */ 1798c2ecf20Sopenharmony_ci atomic64_t allocated_pages; 1808c2ecf20Sopenharmony_ci atomic64_t mapped_pages; 1818c2ecf20Sopenharmony_ci atomic64_t unmapped_pages; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci u8 version; 1848c2ecf20Sopenharmony_ci enum pci_bus_speed max_bus_speed; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci struct dentry *debugfs_dev; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci struct s390_domain *s390_domain; /* s390 IOMMU domain data */ 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic inline bool zdev_enabled(struct zpci_dev *zdev) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci return (zdev->fh & (1UL << 31)) ? true : false; 1948c2ecf20Sopenharmony_ci} 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ciextern const struct attribute_group *zpci_attr_groups[]; 1978c2ecf20Sopenharmony_ciextern unsigned int s390_pci_force_floating __initdata; 1988c2ecf20Sopenharmony_ciextern unsigned int s390_pci_no_rid; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 2018c2ecf20Sopenharmony_ci Prototypes 2028c2ecf20Sopenharmony_ci----------------------------------------------------------------------------- */ 2038c2ecf20Sopenharmony_ci/* Base stuff */ 2048c2ecf20Sopenharmony_ciint zpci_create_device(u32 fid, u32 fh, enum zpci_state state); 2058c2ecf20Sopenharmony_civoid zpci_remove_device(struct zpci_dev *zdev, bool set_error); 2068c2ecf20Sopenharmony_ciint zpci_enable_device(struct zpci_dev *); 2078c2ecf20Sopenharmony_ciint zpci_disable_device(struct zpci_dev *); 2088c2ecf20Sopenharmony_civoid zpci_device_reserved(struct zpci_dev *zdev); 2098c2ecf20Sopenharmony_cibool zpci_is_device_configured(struct zpci_dev *zdev); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ciint zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64); 2128c2ecf20Sopenharmony_ciint zpci_unregister_ioat(struct zpci_dev *, u8); 2138c2ecf20Sopenharmony_civoid zpci_remove_reserved_devices(void); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* CLP */ 2168c2ecf20Sopenharmony_ciint clp_setup_writeback_mio(void); 2178c2ecf20Sopenharmony_ciint clp_scan_pci_devices(void); 2188c2ecf20Sopenharmony_ciint clp_query_pci_fn(struct zpci_dev *zdev); 2198c2ecf20Sopenharmony_ciint clp_enable_fh(struct zpci_dev *, u8); 2208c2ecf20Sopenharmony_ciint clp_disable_fh(struct zpci_dev *); 2218c2ecf20Sopenharmony_ciint clp_get_state(u32 fid, enum zpci_state *state); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* UID */ 2248c2ecf20Sopenharmony_civoid update_uid_checking(bool new); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci/* IOMMU Interface */ 2278c2ecf20Sopenharmony_ciint zpci_init_iommu(struct zpci_dev *zdev); 2288c2ecf20Sopenharmony_civoid zpci_destroy_iommu(struct zpci_dev *zdev); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI 2318c2ecf20Sopenharmony_cistatic inline bool zpci_use_mio(struct zpci_dev *zdev) 2328c2ecf20Sopenharmony_ci{ 2338c2ecf20Sopenharmony_ci return static_branch_likely(&have_mio) && zdev->mio_capable; 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci/* Error handling and recovery */ 2378c2ecf20Sopenharmony_civoid zpci_event_error(void *); 2388c2ecf20Sopenharmony_civoid zpci_event_availability(void *); 2398c2ecf20Sopenharmony_cibool zpci_is_enabled(void); 2408c2ecf20Sopenharmony_ci#else /* CONFIG_PCI */ 2418c2ecf20Sopenharmony_cistatic inline void zpci_event_error(void *e) {} 2428c2ecf20Sopenharmony_cistatic inline void zpci_event_availability(void *e) {} 2438c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI */ 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci#ifdef CONFIG_HOTPLUG_PCI_S390 2468c2ecf20Sopenharmony_ciint zpci_init_slot(struct zpci_dev *); 2478c2ecf20Sopenharmony_civoid zpci_exit_slot(struct zpci_dev *); 2488c2ecf20Sopenharmony_ci#else /* CONFIG_HOTPLUG_PCI_S390 */ 2498c2ecf20Sopenharmony_cistatic inline int zpci_init_slot(struct zpci_dev *zdev) 2508c2ecf20Sopenharmony_ci{ 2518c2ecf20Sopenharmony_ci return 0; 2528c2ecf20Sopenharmony_ci} 2538c2ecf20Sopenharmony_cistatic inline void zpci_exit_slot(struct zpci_dev *zdev) {} 2548c2ecf20Sopenharmony_ci#endif /* CONFIG_HOTPLUG_PCI_S390 */ 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/* Helpers */ 2578c2ecf20Sopenharmony_cistatic inline struct zpci_dev *to_zpci(struct pci_dev *pdev) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci struct zpci_bus *zbus = pdev->sysdata; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci return zbus->function[pdev->devfn]; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic inline struct zpci_dev *to_zpci_dev(struct device *dev) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci return to_zpci(to_pci_dev(dev)); 2678c2ecf20Sopenharmony_ci} 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistruct zpci_dev *get_zdev_by_fid(u32); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci/* DMA */ 2728c2ecf20Sopenharmony_ciint zpci_dma_init(void); 2738c2ecf20Sopenharmony_civoid zpci_dma_exit(void); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ciint __init zpci_irq_init(void); 2768c2ecf20Sopenharmony_civoid __init zpci_irq_exit(void); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci/* FMB */ 2798c2ecf20Sopenharmony_ciint zpci_fmb_enable_device(struct zpci_dev *); 2808c2ecf20Sopenharmony_ciint zpci_fmb_disable_device(struct zpci_dev *); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/* Debug */ 2838c2ecf20Sopenharmony_ciint zpci_debug_init(void); 2848c2ecf20Sopenharmony_civoid zpci_debug_exit(void); 2858c2ecf20Sopenharmony_civoid zpci_debug_init_device(struct zpci_dev *, const char *); 2868c2ecf20Sopenharmony_civoid zpci_debug_exit_device(struct zpci_dev *); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* Error reporting */ 2898c2ecf20Sopenharmony_ciint zpci_report_error(struct pci_dev *, struct zpci_report_error_header *); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci#ifdef CONFIG_NUMA 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* Returns the node based on PCI bus */ 2948c2ecf20Sopenharmony_cistatic inline int __pcibus_to_node(const struct pci_bus *bus) 2958c2ecf20Sopenharmony_ci{ 2968c2ecf20Sopenharmony_ci return NUMA_NO_NODE; 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistatic inline const struct cpumask * 3008c2ecf20Sopenharmony_cicpumask_of_pcibus(const struct pci_bus *bus) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci return cpu_online_mask; 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci#endif /* CONFIG_NUMA */ 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci#endif 308