1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2c6557e7fSMartin Schwidefsky #ifndef __ASM_S390_PCI_H 3c6557e7fSMartin Schwidefsky #define __ASM_S390_PCI_H 4c6557e7fSMartin Schwidefsky 557b5918cSSebastian Ott #include <linux/pci.h> 680ed156aSSebastian Ott #include <linux/mutex.h> 7f42c2235SJoerg Roedel #include <linux/iommu.h> 8035f212fSPierre Morel #include <linux/pci_hotplug.h> 9cd248341SJan Glauber #include <asm-generic/pci.h> 10a755a45dSJan Glauber #include <asm/pci_clp.h> 11d0b08853SJan Glauber #include <asm/pci_debug.h> 12bd3a1725SMartin Schwidefsky #include <asm/sclp.h> 13c6557e7fSMartin Schwidefsky 14cd248341SJan Glauber #define PCIBIOS_MIN_IO 0x1000 15cd248341SJan Glauber #define PCIBIOS_MIN_MEM 0x10000000 16cd248341SJan Glauber 17cd248341SJan Glauber #define pcibios_assign_all_busses() (0) 18cd248341SJan Glauber 19cd248341SJan Glauber void __iomem *pci_iomap(struct pci_dev *, int, unsigned long); 20cd248341SJan Glauber void pci_iounmap(struct pci_dev *, void __iomem *); 21cd248341SJan Glauber int pci_domain_nr(struct pci_bus *); 22cd248341SJan Glauber int pci_proc_domain(struct pci_bus *); 23cd248341SJan Glauber 24cd248341SJan Glauber #define ZPCI_BUS_NR 0 /* default bus number */ 25cd248341SJan Glauber #define ZPCI_DEVFN 0 /* default device number */ 26cd248341SJan Glauber 27c840927cSSebastian Ott #define ZPCI_NR_DMA_SPACES 1 28c840927cSSebastian Ott #define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS 29969ae01bSNiklas Schnelle #define ZPCI_DOMAIN_BITMAP_SIZE (1 << 16) 30c840927cSSebastian Ott 31cd248341SJan Glauber /* PCI Function Controls */ 32cd248341SJan Glauber #define ZPCI_FC_FN_ENABLED 0x80 33cd248341SJan Glauber #define ZPCI_FC_ERROR 0x40 34cd248341SJan Glauber #define ZPCI_FC_BLOCKED 0x20 35cd248341SJan Glauber #define ZPCI_FC_DMA_ENABLED 0x10 36cd248341SJan Glauber 37f9dc447eSSebastian Ott #define ZPCI_FMB_DMA_COUNTER_VALID (1 << 23) 38f9dc447eSSebastian Ott 39f9dc447eSSebastian Ott struct zpci_fmb_fmt0 { 40f9dc447eSSebastian Ott u64 dma_rbytes; 41f9dc447eSSebastian Ott u64 dma_wbytes; 42f9dc447eSSebastian Ott }; 43f9dc447eSSebastian Ott 44f9dc447eSSebastian Ott struct zpci_fmb_fmt1 { 45f9dc447eSSebastian Ott u64 rx_bytes; 46f9dc447eSSebastian Ott u64 rx_packets; 47f9dc447eSSebastian Ott u64 tx_bytes; 48f9dc447eSSebastian Ott u64 tx_packets; 49f9dc447eSSebastian Ott }; 50f9dc447eSSebastian Ott 51f9dc447eSSebastian Ott struct zpci_fmb_fmt2 { 52f9dc447eSSebastian Ott u64 consumed_work_units; 53f9dc447eSSebastian Ott u64 max_work_units; 54f9dc447eSSebastian Ott }; 55f9dc447eSSebastian Ott 560ac94282SSebastian Ott struct zpci_fmb_fmt3 { 570ac94282SSebastian Ott u64 tx_bytes; 580ac94282SSebastian Ott }; 590ac94282SSebastian Ott 60d0b08853SJan Glauber struct zpci_fmb { 61d0b08853SJan Glauber u32 format : 8; 62f9dc447eSSebastian Ott u32 fmt_ind : 24; 63d0b08853SJan Glauber u32 samples; 64d0b08853SJan Glauber u64 last_update; 65f9dc447eSSebastian Ott /* common counters */ 66d0b08853SJan Glauber u64 ld_ops; 67d0b08853SJan Glauber u64 st_ops; 68d0b08853SJan Glauber u64 stb_ops; 69d0b08853SJan Glauber u64 rpcit_ops; 70f9dc447eSSebastian Ott /* format specific counters */ 71f9dc447eSSebastian Ott union { 72f9dc447eSSebastian Ott struct zpci_fmb_fmt0 fmt0; 73f9dc447eSSebastian Ott struct zpci_fmb_fmt1 fmt1; 74f9dc447eSSebastian Ott struct zpci_fmb_fmt2 fmt2; 750ac94282SSebastian Ott struct zpci_fmb_fmt3 fmt3; 76f9dc447eSSebastian Ott }; 779d89d9e6SSebastian Ott } __packed __aligned(128); 78d0b08853SJan Glauber 79cd248341SJan Glauber enum zpci_state { 80783684f1SSebastian Ott ZPCI_FN_STATE_STANDBY = 0, 81783684f1SSebastian Ott ZPCI_FN_STATE_CONFIGURED = 1, 82783684f1SSebastian Ott ZPCI_FN_STATE_RESERVED = 2, 83783684f1SSebastian Ott ZPCI_FN_STATE_ONLINE = 3, 84cd248341SJan Glauber }; 85cd248341SJan Glauber 86cd248341SJan Glauber struct zpci_bar_struct { 877a572a3aSSebastian Ott struct resource *res; /* bus resource */ 8871ba41c9SSebastian Ott void __iomem *mio_wb; 8971ba41c9SSebastian Ott void __iomem *mio_wt; 90cd248341SJan Glauber u32 val; /* bar start & 3 flag bits */ 91cd248341SJan Glauber u16 map_idx; /* index into bar mapping array */ 927a572a3aSSebastian Ott u8 size; /* order 2 exponent */ 93cd248341SJan Glauber }; 94cd248341SJan Glauber 958128f23cSGerald Schaefer struct s390_domain; 968128f23cSGerald Schaefer 97cd248341SJan Glauber /* Private data per function */ 98cd248341SJan Glauber struct zpci_dev { 99cd248341SJan Glauber struct pci_bus *bus; 100cd248341SJan Glauber struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */ 101035f212fSPierre Morel struct hotplug_slot hotplug_slot; 102cd248341SJan Glauber 103cd248341SJan Glauber enum zpci_state state; 104cd248341SJan Glauber u32 fid; /* function ID, used by sclp */ 105cd248341SJan Glauber u32 fh; /* function handle, used by insn's */ 106ac4995b9SSebastian Ott u16 vfn; /* virtual function number */ 107cd248341SJan Glauber u16 pchid; /* physical channel ID */ 108cd248341SJan Glauber u8 pfgid; /* function group ID */ 109ac4995b9SSebastian Ott u8 pft; /* pci function type */ 110cd248341SJan Glauber u16 domain; 111e6ab7490SAlexander Schmidt u8 port; 112cd248341SJan Glauber 11380ed156aSSebastian Ott struct mutex lock; 114ac4995b9SSebastian Ott u8 pfip[CLP_PFIP_NR_SEGMENTS]; /* pci function internal path */ 115ac4995b9SSebastian Ott u32 uid; /* user defined id */ 116ac4995b9SSebastian Ott u8 util_str[CLP_UTIL_STR_LEN]; /* utility string */ 117ac4995b9SSebastian Ott 1189a4da8a5SJan Glauber /* IRQ stuff */ 1199a4da8a5SJan Glauber u64 msi_addr; /* MSI address */ 120b19148f6SSebastian Ott unsigned int max_msi; /* maximum number of MSI's */ 121e979ce7bSSebastian Ott unsigned int msi_first_bit; 122e979ce7bSSebastian Ott unsigned int msi_nr_irqs; 1235d0d8f43SMartin Schwidefsky struct airq_iv *aibv; /* adapter interrupt bit vector */ 124795818e8SSebastian Ott unsigned long aisb; /* number of the summary bit */ 1259a4da8a5SJan Glauber 126828b35f6SJan Glauber /* DMA stuff */ 127828b35f6SJan Glauber unsigned long *dma_table; 128828b35f6SJan Glauber spinlock_t dma_table_lock; 129828b35f6SJan Glauber int tlb_refresh; 130828b35f6SJan Glauber 131828b35f6SJan Glauber spinlock_t iommu_bitmap_lock; 132828b35f6SJan Glauber unsigned long *iommu_bitmap; 13313954fd6SSebastian Ott unsigned long *lazy_bitmap; 134828b35f6SJan Glauber unsigned long iommu_size; 135828b35f6SJan Glauber unsigned long iommu_pages; 136828b35f6SJan Glauber unsigned int next_bit; 137828b35f6SJan Glauber 138f42c2235SJoerg Roedel struct iommu_device iommu_dev; /* IOMMU core handle */ 139f42c2235SJoerg Roedel 1407a572a3aSSebastian Ott char res_name[16]; 14171ba41c9SSebastian Ott bool mio_capable; 142c9c13ba4SDenis Efremov struct zpci_bar_struct bars[PCI_STD_NUM_BARS]; 143cd248341SJan Glauber 144828b35f6SJan Glauber u64 start_dma; /* Start of available DMA addresses */ 145828b35f6SJan Glauber u64 end_dma; /* End of available DMA addresses */ 146828b35f6SJan Glauber u64 dma_mask; /* DMA address space mask */ 147828b35f6SJan Glauber 148d0b08853SJan Glauber /* Function measurement block */ 149d0b08853SJan Glauber struct zpci_fmb *fmb; 150d0b08853SJan Glauber u16 fmb_update; /* update interval */ 1510b7589ecSSebastian Ott u16 fmb_length; 1526001018aSSebastian Ott /* software counters */ 1536001018aSSebastian Ott atomic64_t allocated_pages; 1546001018aSSebastian Ott atomic64_t mapped_pages; 1556001018aSSebastian Ott atomic64_t unmapped_pages; 156d0b08853SJan Glauber 157cd248341SJan Glauber enum pci_bus_speed max_bus_speed; 158d0b08853SJan Glauber 159d0b08853SJan Glauber struct dentry *debugfs_dev; 1608128f23cSGerald Schaefer 1618128f23cSGerald Schaefer struct s390_domain *s390_domain; /* s390 IOMMU domain data */ 162cd248341SJan Glauber }; 163cd248341SJan Glauber 164cd248341SJan Glauber static inline bool zdev_enabled(struct zpci_dev *zdev) 165cd248341SJan Glauber { 166cd248341SJan Glauber return (zdev->fh & (1UL << 31)) ? true : false; 167cd248341SJan Glauber } 168cd248341SJan Glauber 16993065d04SSebastian Ott extern const struct attribute_group *zpci_attr_groups[]; 170fbfe07d4SSebastian Ott extern unsigned int s390_pci_force_floating __initdata; 17193065d04SSebastian Ott 172cd248341SJan Glauber /* ----------------------------------------------------------------------------- 173cd248341SJan Glauber Prototypes 174cd248341SJan Glauber ----------------------------------------------------------------------------- */ 175cd248341SJan Glauber /* Base stuff */ 176cd248341SJan Glauber int zpci_create_device(struct zpci_dev *); 177623bd44dSSebastian Ott void zpci_remove_device(struct zpci_dev *zdev); 178cd248341SJan Glauber int zpci_enable_device(struct zpci_dev *); 179cb65a669SSebastian Ott int zpci_disable_device(struct zpci_dev *); 180828b35f6SJan Glauber int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64); 181828b35f6SJan Glauber int zpci_unregister_ioat(struct zpci_dev *, u8); 18201553d9aSSebastian Ott void zpci_remove_reserved_devices(void); 183cd248341SJan Glauber 184a755a45dSJan Glauber /* CLP */ 1851d578966SSebastian Ott int clp_scan_pci_devices(void); 1861d578966SSebastian Ott int clp_rescan_pci_devices(void); 18717cdec96SNiklas Schnelle int clp_rescan_pci_devices_simple(u32 *fid); 188a755a45dSJan Glauber int clp_add_pci_device(u32, u32, int); 189a755a45dSJan Glauber int clp_enable_fh(struct zpci_dev *, u8); 190a755a45dSJan Glauber int clp_disable_fh(struct zpci_dev *); 191783684f1SSebastian Ott int clp_get_state(u32 fid, enum zpci_state *state); 192a755a45dSJan Glauber 1937a11c67aSNiklas Schnelle /* UID */ 1947a11c67aSNiklas Schnelle void update_uid_checking(bool new); 1957a11c67aSNiklas Schnelle 196f42c2235SJoerg Roedel /* IOMMU Interface */ 197f42c2235SJoerg Roedel int zpci_init_iommu(struct zpci_dev *zdev); 198f42c2235SJoerg Roedel void zpci_destroy_iommu(struct zpci_dev *zdev); 199f42c2235SJoerg Roedel 2009a17e972SSebastian Ott #ifdef CONFIG_PCI 201c7ff0e91SSebastian Ott static inline bool zpci_use_mio(struct zpci_dev *zdev) 202c7ff0e91SSebastian Ott { 203c7ff0e91SSebastian Ott return static_branch_likely(&have_mio) && zdev->mio_capable; 204c7ff0e91SSebastian Ott } 205c7ff0e91SSebastian Ott 206cbc0dd1fSJan Glauber /* Error handling and recovery */ 207cbc0dd1fSJan Glauber void zpci_event_error(void *); 208cbc0dd1fSJan Glauber void zpci_event_availability(void *); 20957b5918cSSebastian Ott void zpci_rescan(void); 210aa3b7c29SSebastian Ott bool zpci_is_enabled(void); 2119a17e972SSebastian Ott #else /* CONFIG_PCI */ 2129a17e972SSebastian Ott static inline void zpci_event_error(void *e) {} 2139a17e972SSebastian Ott static inline void zpci_event_availability(void *e) {} 21457b5918cSSebastian Ott static inline void zpci_rescan(void) {} 2159a17e972SSebastian Ott #endif /* CONFIG_PCI */ 216cbc0dd1fSJan Glauber 21767f43f38SSebastian Ott #ifdef CONFIG_HOTPLUG_PCI_S390 21867f43f38SSebastian Ott int zpci_init_slot(struct zpci_dev *); 21967f43f38SSebastian Ott void zpci_exit_slot(struct zpci_dev *); 22067f43f38SSebastian Ott #else /* CONFIG_HOTPLUG_PCI_S390 */ 22167f43f38SSebastian Ott static inline int zpci_init_slot(struct zpci_dev *zdev) 22267f43f38SSebastian Ott { 22367f43f38SSebastian Ott return 0; 22467f43f38SSebastian Ott } 22567f43f38SSebastian Ott static inline void zpci_exit_slot(struct zpci_dev *zdev) {} 22667f43f38SSebastian Ott #endif /* CONFIG_HOTPLUG_PCI_S390 */ 22767f43f38SSebastian Ott 228cd248341SJan Glauber /* Helpers */ 229198a5278SSebastian Ott static inline struct zpci_dev *to_zpci(struct pci_dev *pdev) 230198a5278SSebastian Ott { 231198a5278SSebastian Ott return pdev->sysdata; 232198a5278SSebastian Ott } 233198a5278SSebastian Ott 234d08d6f5dSPierre Morel static inline struct zpci_dev *to_zpci_dev(struct device *dev) 235d08d6f5dSPierre Morel { 236d08d6f5dSPierre Morel return to_zpci(to_pci_dev(dev)); 237d08d6f5dSPierre Morel } 238d08d6f5dSPierre Morel 239cd248341SJan Glauber struct zpci_dev *get_zdev_by_fid(u32); 240cd248341SJan Glauber 241828b35f6SJan Glauber /* DMA */ 242828b35f6SJan Glauber int zpci_dma_init(void); 243828b35f6SJan Glauber void zpci_dma_exit(void); 244828b35f6SJan Glauber 245c840927cSSebastian Ott int __init zpci_irq_init(void); 246c840927cSSebastian Ott void __init zpci_irq_exit(void); 247c840927cSSebastian Ott 248d0b08853SJan Glauber /* FMB */ 249d0b08853SJan Glauber int zpci_fmb_enable_device(struct zpci_dev *); 250d0b08853SJan Glauber int zpci_fmb_disable_device(struct zpci_dev *); 251d0b08853SJan Glauber 252d0b08853SJan Glauber /* Debug */ 253d0b08853SJan Glauber int zpci_debug_init(void); 254d0b08853SJan Glauber void zpci_debug_exit(void); 2559a99649fSSebastian Ott void zpci_debug_init_device(struct zpci_dev *, const char *); 256d0b08853SJan Glauber void zpci_debug_exit_device(struct zpci_dev *); 257d0b08853SJan Glauber void zpci_debug_info(struct zpci_dev *, struct seq_file *); 258d0b08853SJan Glauber 259bd3a1725SMartin Schwidefsky /* Error reporting */ 260bd3a1725SMartin Schwidefsky int zpci_report_error(struct pci_dev *, struct zpci_report_error_header *); 261bd3a1725SMartin Schwidefsky 2623a368f74SPhilipp Hachtmann #ifdef CONFIG_NUMA 2633a368f74SPhilipp Hachtmann 2643a368f74SPhilipp Hachtmann /* Returns the node based on PCI bus */ 2653a368f74SPhilipp Hachtmann static inline int __pcibus_to_node(const struct pci_bus *bus) 2663a368f74SPhilipp Hachtmann { 2673a368f74SPhilipp Hachtmann return NUMA_NO_NODE; 2683a368f74SPhilipp Hachtmann } 2693a368f74SPhilipp Hachtmann 2703a368f74SPhilipp Hachtmann static inline const struct cpumask * 2713a368f74SPhilipp Hachtmann cpumask_of_pcibus(const struct pci_bus *bus) 2723a368f74SPhilipp Hachtmann { 2733a368f74SPhilipp Hachtmann return cpu_online_mask; 2743a368f74SPhilipp Hachtmann } 2753a368f74SPhilipp Hachtmann 2763a368f74SPhilipp Hachtmann #endif /* CONFIG_NUMA */ 2773a368f74SPhilipp Hachtmann 278cd248341SJan Glauber #endif 279