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> 8cd248341SJan Glauber #include <asm-generic/pci.h> 9a755a45dSJan Glauber #include <asm/pci_clp.h> 10d0b08853SJan Glauber #include <asm/pci_debug.h> 11bd3a1725SMartin Schwidefsky #include <asm/sclp.h> 12c6557e7fSMartin Schwidefsky 13cd248341SJan Glauber #define PCIBIOS_MIN_IO 0x1000 14cd248341SJan Glauber #define PCIBIOS_MIN_MEM 0x10000000 15cd248341SJan Glauber 16cd248341SJan Glauber #define pcibios_assign_all_busses() (0) 17cd248341SJan Glauber 18cd248341SJan Glauber void __iomem *pci_iomap(struct pci_dev *, int, unsigned long); 19cd248341SJan Glauber void pci_iounmap(struct pci_dev *, void __iomem *); 20cd248341SJan Glauber int pci_domain_nr(struct pci_bus *); 21cd248341SJan Glauber int pci_proc_domain(struct pci_bus *); 22cd248341SJan Glauber 23cd248341SJan Glauber #define ZPCI_BUS_NR 0 /* default bus number */ 24cd248341SJan Glauber #define ZPCI_DEVFN 0 /* default device number */ 25cd248341SJan Glauber 26c840927cSSebastian Ott #define ZPCI_NR_DMA_SPACES 1 27c840927cSSebastian Ott #define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS 28c840927cSSebastian Ott 29cd248341SJan Glauber /* PCI Function Controls */ 30cd248341SJan Glauber #define ZPCI_FC_FN_ENABLED 0x80 31cd248341SJan Glauber #define ZPCI_FC_ERROR 0x40 32cd248341SJan Glauber #define ZPCI_FC_BLOCKED 0x20 33cd248341SJan Glauber #define ZPCI_FC_DMA_ENABLED 0x10 34cd248341SJan Glauber 35f9dc447eSSebastian Ott #define ZPCI_FMB_DMA_COUNTER_VALID (1 << 23) 36f9dc447eSSebastian Ott 37f9dc447eSSebastian Ott struct zpci_fmb_fmt0 { 38f9dc447eSSebastian Ott u64 dma_rbytes; 39f9dc447eSSebastian Ott u64 dma_wbytes; 40f9dc447eSSebastian Ott }; 41f9dc447eSSebastian Ott 42f9dc447eSSebastian Ott struct zpci_fmb_fmt1 { 43f9dc447eSSebastian Ott u64 rx_bytes; 44f9dc447eSSebastian Ott u64 rx_packets; 45f9dc447eSSebastian Ott u64 tx_bytes; 46f9dc447eSSebastian Ott u64 tx_packets; 47f9dc447eSSebastian Ott }; 48f9dc447eSSebastian Ott 49f9dc447eSSebastian Ott struct zpci_fmb_fmt2 { 50f9dc447eSSebastian Ott u64 consumed_work_units; 51f9dc447eSSebastian Ott u64 max_work_units; 52f9dc447eSSebastian Ott }; 53f9dc447eSSebastian Ott 540ac94282SSebastian Ott struct zpci_fmb_fmt3 { 550ac94282SSebastian Ott u64 tx_bytes; 560ac94282SSebastian Ott }; 570ac94282SSebastian Ott 58d0b08853SJan Glauber struct zpci_fmb { 59d0b08853SJan Glauber u32 format : 8; 60f9dc447eSSebastian Ott u32 fmt_ind : 24; 61d0b08853SJan Glauber u32 samples; 62d0b08853SJan Glauber u64 last_update; 63f9dc447eSSebastian Ott /* common counters */ 64d0b08853SJan Glauber u64 ld_ops; 65d0b08853SJan Glauber u64 st_ops; 66d0b08853SJan Glauber u64 stb_ops; 67d0b08853SJan Glauber u64 rpcit_ops; 68f9dc447eSSebastian Ott /* format specific counters */ 69f9dc447eSSebastian Ott union { 70f9dc447eSSebastian Ott struct zpci_fmb_fmt0 fmt0; 71f9dc447eSSebastian Ott struct zpci_fmb_fmt1 fmt1; 72f9dc447eSSebastian Ott struct zpci_fmb_fmt2 fmt2; 730ac94282SSebastian Ott struct zpci_fmb_fmt3 fmt3; 74f9dc447eSSebastian Ott }; 759d89d9e6SSebastian Ott } __packed __aligned(128); 76d0b08853SJan Glauber 77cd248341SJan Glauber enum zpci_state { 78783684f1SSebastian Ott ZPCI_FN_STATE_STANDBY = 0, 79783684f1SSebastian Ott ZPCI_FN_STATE_CONFIGURED = 1, 80783684f1SSebastian Ott ZPCI_FN_STATE_RESERVED = 2, 81783684f1SSebastian Ott ZPCI_FN_STATE_ONLINE = 3, 82cd248341SJan Glauber }; 83cd248341SJan Glauber 84cd248341SJan Glauber struct zpci_bar_struct { 857a572a3aSSebastian Ott struct resource *res; /* bus resource */ 8671ba41c9SSebastian Ott void __iomem *mio_wb; 8771ba41c9SSebastian Ott void __iomem *mio_wt; 88cd248341SJan Glauber u32 val; /* bar start & 3 flag bits */ 89cd248341SJan Glauber u16 map_idx; /* index into bar mapping array */ 907a572a3aSSebastian Ott u8 size; /* order 2 exponent */ 91cd248341SJan Glauber }; 92cd248341SJan Glauber 938128f23cSGerald Schaefer struct s390_domain; 948128f23cSGerald Schaefer 95cd248341SJan Glauber /* Private data per function */ 96cd248341SJan Glauber struct zpci_dev { 97cd248341SJan Glauber struct pci_bus *bus; 98cd248341SJan Glauber struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */ 99cd248341SJan Glauber 100cd248341SJan Glauber enum zpci_state state; 101cd248341SJan Glauber u32 fid; /* function ID, used by sclp */ 102cd248341SJan Glauber u32 fh; /* function handle, used by insn's */ 103ac4995b9SSebastian Ott u16 vfn; /* virtual function number */ 104cd248341SJan Glauber u16 pchid; /* physical channel ID */ 105cd248341SJan Glauber u8 pfgid; /* function group ID */ 106ac4995b9SSebastian Ott u8 pft; /* pci function type */ 107cd248341SJan Glauber u16 domain; 108cd248341SJan Glauber 10980ed156aSSebastian Ott struct mutex lock; 110ac4995b9SSebastian Ott u8 pfip[CLP_PFIP_NR_SEGMENTS]; /* pci function internal path */ 111ac4995b9SSebastian Ott u32 uid; /* user defined id */ 112ac4995b9SSebastian Ott u8 util_str[CLP_UTIL_STR_LEN]; /* utility string */ 113ac4995b9SSebastian Ott 1149a4da8a5SJan Glauber /* IRQ stuff */ 1159a4da8a5SJan Glauber u64 msi_addr; /* MSI address */ 116b19148f6SSebastian Ott unsigned int max_msi; /* maximum number of MSI's */ 117e979ce7bSSebastian Ott unsigned int msi_first_bit; 118e979ce7bSSebastian Ott unsigned int msi_nr_irqs; 1195d0d8f43SMartin Schwidefsky struct airq_iv *aibv; /* adapter interrupt bit vector */ 120795818e8SSebastian Ott unsigned long aisb; /* number of the summary bit */ 1219a4da8a5SJan Glauber 122828b35f6SJan Glauber /* DMA stuff */ 123828b35f6SJan Glauber unsigned long *dma_table; 124828b35f6SJan Glauber spinlock_t dma_table_lock; 125828b35f6SJan Glauber int tlb_refresh; 126828b35f6SJan Glauber 127828b35f6SJan Glauber spinlock_t iommu_bitmap_lock; 128828b35f6SJan Glauber unsigned long *iommu_bitmap; 12913954fd6SSebastian Ott unsigned long *lazy_bitmap; 130828b35f6SJan Glauber unsigned long iommu_size; 131828b35f6SJan Glauber unsigned long iommu_pages; 132828b35f6SJan Glauber unsigned int next_bit; 133828b35f6SJan Glauber 134f42c2235SJoerg Roedel struct iommu_device iommu_dev; /* IOMMU core handle */ 135f42c2235SJoerg Roedel 1367a572a3aSSebastian Ott char res_name[16]; 13771ba41c9SSebastian Ott bool mio_capable; 138c9c13ba4SDenis Efremov struct zpci_bar_struct bars[PCI_STD_NUM_BARS]; 139cd248341SJan Glauber 140828b35f6SJan Glauber u64 start_dma; /* Start of available DMA addresses */ 141828b35f6SJan Glauber u64 end_dma; /* End of available DMA addresses */ 142828b35f6SJan Glauber u64 dma_mask; /* DMA address space mask */ 143828b35f6SJan Glauber 144d0b08853SJan Glauber /* Function measurement block */ 145d0b08853SJan Glauber struct zpci_fmb *fmb; 146d0b08853SJan Glauber u16 fmb_update; /* update interval */ 1470b7589ecSSebastian Ott u16 fmb_length; 1486001018aSSebastian Ott /* software counters */ 1496001018aSSebastian Ott atomic64_t allocated_pages; 1506001018aSSebastian Ott atomic64_t mapped_pages; 1516001018aSSebastian Ott atomic64_t unmapped_pages; 152d0b08853SJan Glauber 153cd248341SJan Glauber enum pci_bus_speed max_bus_speed; 154d0b08853SJan Glauber 155d0b08853SJan Glauber struct dentry *debugfs_dev; 1568128f23cSGerald Schaefer 1578128f23cSGerald Schaefer struct s390_domain *s390_domain; /* s390 IOMMU domain data */ 158cd248341SJan Glauber }; 159cd248341SJan Glauber 160cd248341SJan Glauber static inline bool zdev_enabled(struct zpci_dev *zdev) 161cd248341SJan Glauber { 162cd248341SJan Glauber return (zdev->fh & (1UL << 31)) ? true : false; 163cd248341SJan Glauber } 164cd248341SJan Glauber 16593065d04SSebastian Ott extern const struct attribute_group *zpci_attr_groups[]; 166fbfe07d4SSebastian Ott extern unsigned int s390_pci_force_floating __initdata; 16793065d04SSebastian Ott 168cd248341SJan Glauber /* ----------------------------------------------------------------------------- 169cd248341SJan Glauber Prototypes 170cd248341SJan Glauber ----------------------------------------------------------------------------- */ 171cd248341SJan Glauber /* Base stuff */ 172cd248341SJan Glauber int zpci_create_device(struct zpci_dev *); 173623bd44dSSebastian Ott void zpci_remove_device(struct zpci_dev *zdev); 174cd248341SJan Glauber int zpci_enable_device(struct zpci_dev *); 175cb65a669SSebastian Ott int zpci_disable_device(struct zpci_dev *); 176828b35f6SJan Glauber int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64); 177828b35f6SJan Glauber int zpci_unregister_ioat(struct zpci_dev *, u8); 17801553d9aSSebastian Ott void zpci_remove_reserved_devices(void); 179cd248341SJan Glauber 180a755a45dSJan Glauber /* CLP */ 1811d578966SSebastian Ott int clp_scan_pci_devices(void); 1821d578966SSebastian Ott int clp_rescan_pci_devices(void); 18357b5918cSSebastian Ott int clp_rescan_pci_devices_simple(void); 184a755a45dSJan Glauber int clp_add_pci_device(u32, u32, int); 185a755a45dSJan Glauber int clp_enable_fh(struct zpci_dev *, u8); 186a755a45dSJan Glauber int clp_disable_fh(struct zpci_dev *); 187783684f1SSebastian Ott int clp_get_state(u32 fid, enum zpci_state *state); 188a755a45dSJan Glauber 189f42c2235SJoerg Roedel /* IOMMU Interface */ 190f42c2235SJoerg Roedel int zpci_init_iommu(struct zpci_dev *zdev); 191f42c2235SJoerg Roedel void zpci_destroy_iommu(struct zpci_dev *zdev); 192f42c2235SJoerg Roedel 1939a17e972SSebastian Ott #ifdef CONFIG_PCI 194c7ff0e91SSebastian Ott static inline bool zpci_use_mio(struct zpci_dev *zdev) 195c7ff0e91SSebastian Ott { 196c7ff0e91SSebastian Ott return static_branch_likely(&have_mio) && zdev->mio_capable; 197c7ff0e91SSebastian Ott } 198c7ff0e91SSebastian Ott 199cbc0dd1fSJan Glauber /* Error handling and recovery */ 200cbc0dd1fSJan Glauber void zpci_event_error(void *); 201cbc0dd1fSJan Glauber void zpci_event_availability(void *); 20257b5918cSSebastian Ott void zpci_rescan(void); 203aa3b7c29SSebastian Ott bool zpci_is_enabled(void); 2049a17e972SSebastian Ott #else /* CONFIG_PCI */ 2059a17e972SSebastian Ott static inline void zpci_event_error(void *e) {} 2069a17e972SSebastian Ott static inline void zpci_event_availability(void *e) {} 20757b5918cSSebastian Ott static inline void zpci_rescan(void) {} 2089a17e972SSebastian Ott #endif /* CONFIG_PCI */ 209cbc0dd1fSJan Glauber 21067f43f38SSebastian Ott #ifdef CONFIG_HOTPLUG_PCI_S390 21167f43f38SSebastian Ott int zpci_init_slot(struct zpci_dev *); 21267f43f38SSebastian Ott void zpci_exit_slot(struct zpci_dev *); 21367f43f38SSebastian Ott #else /* CONFIG_HOTPLUG_PCI_S390 */ 21467f43f38SSebastian Ott static inline int zpci_init_slot(struct zpci_dev *zdev) 21567f43f38SSebastian Ott { 21667f43f38SSebastian Ott return 0; 21767f43f38SSebastian Ott } 21867f43f38SSebastian Ott static inline void zpci_exit_slot(struct zpci_dev *zdev) {} 21967f43f38SSebastian Ott #endif /* CONFIG_HOTPLUG_PCI_S390 */ 22067f43f38SSebastian Ott 221cd248341SJan Glauber /* Helpers */ 222198a5278SSebastian Ott static inline struct zpci_dev *to_zpci(struct pci_dev *pdev) 223198a5278SSebastian Ott { 224198a5278SSebastian Ott return pdev->sysdata; 225198a5278SSebastian Ott } 226198a5278SSebastian Ott 227cd248341SJan Glauber struct zpci_dev *get_zdev_by_fid(u32); 228cd248341SJan Glauber 229828b35f6SJan Glauber /* DMA */ 230828b35f6SJan Glauber int zpci_dma_init(void); 231828b35f6SJan Glauber void zpci_dma_exit(void); 232828b35f6SJan Glauber 233c840927cSSebastian Ott int __init zpci_irq_init(void); 234c840927cSSebastian Ott void __init zpci_irq_exit(void); 235c840927cSSebastian Ott 236d0b08853SJan Glauber /* FMB */ 237d0b08853SJan Glauber int zpci_fmb_enable_device(struct zpci_dev *); 238d0b08853SJan Glauber int zpci_fmb_disable_device(struct zpci_dev *); 239d0b08853SJan Glauber 240d0b08853SJan Glauber /* Debug */ 241d0b08853SJan Glauber int zpci_debug_init(void); 242d0b08853SJan Glauber void zpci_debug_exit(void); 2439a99649fSSebastian Ott void zpci_debug_init_device(struct zpci_dev *, const char *); 244d0b08853SJan Glauber void zpci_debug_exit_device(struct zpci_dev *); 245d0b08853SJan Glauber void zpci_debug_info(struct zpci_dev *, struct seq_file *); 246d0b08853SJan Glauber 247bd3a1725SMartin Schwidefsky /* Error reporting */ 248bd3a1725SMartin Schwidefsky int zpci_report_error(struct pci_dev *, struct zpci_report_error_header *); 249bd3a1725SMartin Schwidefsky 2503a368f74SPhilipp Hachtmann #ifdef CONFIG_NUMA 2513a368f74SPhilipp Hachtmann 2523a368f74SPhilipp Hachtmann /* Returns the node based on PCI bus */ 2533a368f74SPhilipp Hachtmann static inline int __pcibus_to_node(const struct pci_bus *bus) 2543a368f74SPhilipp Hachtmann { 2553a368f74SPhilipp Hachtmann return NUMA_NO_NODE; 2563a368f74SPhilipp Hachtmann } 2573a368f74SPhilipp Hachtmann 2583a368f74SPhilipp Hachtmann static inline const struct cpumask * 2593a368f74SPhilipp Hachtmann cpumask_of_pcibus(const struct pci_bus *bus) 2603a368f74SPhilipp Hachtmann { 2613a368f74SPhilipp Hachtmann return cpu_online_mask; 2623a368f74SPhilipp Hachtmann } 2633a368f74SPhilipp Hachtmann 2643a368f74SPhilipp Hachtmann #endif /* CONFIG_NUMA */ 2653a368f74SPhilipp Hachtmann 266cd248341SJan Glauber #endif 267