xref: /openbmc/linux/arch/s390/include/asm/pci.h (revision b2441318)
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 
5cd248341SJan Glauber /* must be set before including asm-generic/pci.h */
6c6557e7fSMartin Schwidefsky #define PCI_DMA_BUS_IS_PHYS (0)
7cd248341SJan Glauber /* must be set before including pci_clp.h */
8cd248341SJan Glauber #define PCI_BAR_COUNT	6
9c6557e7fSMartin Schwidefsky 
1057b5918cSSebastian Ott #include <linux/pci.h>
1180ed156aSSebastian Ott #include <linux/mutex.h>
12f42c2235SJoerg Roedel #include <linux/iommu.h>
13cd248341SJan Glauber #include <asm-generic/pci.h>
14a755a45dSJan Glauber #include <asm/pci_clp.h>
15d0b08853SJan Glauber #include <asm/pci_debug.h>
16bd3a1725SMartin Schwidefsky #include <asm/sclp.h>
17c6557e7fSMartin Schwidefsky 
18cd248341SJan Glauber #define PCIBIOS_MIN_IO		0x1000
19cd248341SJan Glauber #define PCIBIOS_MIN_MEM		0x10000000
20cd248341SJan Glauber 
21cd248341SJan Glauber #define pcibios_assign_all_busses()	(0)
22cd248341SJan Glauber 
23cd248341SJan Glauber void __iomem *pci_iomap(struct pci_dev *, int, unsigned long);
24cd248341SJan Glauber void pci_iounmap(struct pci_dev *, void __iomem *);
25cd248341SJan Glauber int pci_domain_nr(struct pci_bus *);
26cd248341SJan Glauber int pci_proc_domain(struct pci_bus *);
27cd248341SJan Glauber 
28cd248341SJan Glauber #define ZPCI_BUS_NR			0	/* default bus number */
29cd248341SJan Glauber #define ZPCI_DEVFN			0	/* default device number */
30cd248341SJan Glauber 
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 
56d0b08853SJan Glauber struct zpci_fmb {
57d0b08853SJan Glauber 	u32 format	: 8;
58f9dc447eSSebastian Ott 	u32 fmt_ind	: 24;
59d0b08853SJan Glauber 	u32 samples;
60d0b08853SJan Glauber 	u64 last_update;
61f9dc447eSSebastian Ott 	/* common counters */
62d0b08853SJan Glauber 	u64 ld_ops;
63d0b08853SJan Glauber 	u64 st_ops;
64d0b08853SJan Glauber 	u64 stb_ops;
65d0b08853SJan Glauber 	u64 rpcit_ops;
66f9dc447eSSebastian Ott 	/* format specific counters */
67f9dc447eSSebastian Ott 	union {
68f9dc447eSSebastian Ott 		struct zpci_fmb_fmt0 fmt0;
69f9dc447eSSebastian Ott 		struct zpci_fmb_fmt1 fmt1;
70f9dc447eSSebastian Ott 		struct zpci_fmb_fmt2 fmt2;
71f9dc447eSSebastian Ott 	};
729d89d9e6SSebastian Ott } __packed __aligned(128);
73d0b08853SJan Glauber 
74cd248341SJan Glauber enum zpci_state {
75783684f1SSebastian Ott 	ZPCI_FN_STATE_STANDBY = 0,
76783684f1SSebastian Ott 	ZPCI_FN_STATE_CONFIGURED = 1,
77783684f1SSebastian Ott 	ZPCI_FN_STATE_RESERVED = 2,
78783684f1SSebastian Ott 	ZPCI_FN_STATE_ONLINE = 3,
79cd248341SJan Glauber };
80cd248341SJan Glauber 
81cd248341SJan Glauber struct zpci_bar_struct {
827a572a3aSSebastian Ott 	struct resource *res;		/* bus resource */
83cd248341SJan Glauber 	u32		val;		/* bar start & 3 flag bits */
84cd248341SJan Glauber 	u16		map_idx;	/* index into bar mapping array */
857a572a3aSSebastian Ott 	u8		size;		/* order 2 exponent */
86cd248341SJan Glauber };
87cd248341SJan Glauber 
888128f23cSGerald Schaefer struct s390_domain;
898128f23cSGerald Schaefer 
90cd248341SJan Glauber /* Private data per function */
91cd248341SJan Glauber struct zpci_dev {
92cd248341SJan Glauber 	struct pci_bus	*bus;
93cd248341SJan Glauber 	struct list_head entry;		/* list of all zpci_devices, needed for hotplug, etc. */
94cd248341SJan Glauber 
95cd248341SJan Glauber 	enum zpci_state state;
96cd248341SJan Glauber 	u32		fid;		/* function ID, used by sclp */
97cd248341SJan Glauber 	u32		fh;		/* function handle, used by insn's */
98ac4995b9SSebastian Ott 	u16		vfn;		/* virtual function number */
99cd248341SJan Glauber 	u16		pchid;		/* physical channel ID */
100cd248341SJan Glauber 	u8		pfgid;		/* function group ID */
101ac4995b9SSebastian Ott 	u8		pft;		/* pci function type */
102cd248341SJan Glauber 	u16		domain;
103cd248341SJan Glauber 
10480ed156aSSebastian Ott 	struct mutex lock;
105ac4995b9SSebastian Ott 	u8 pfip[CLP_PFIP_NR_SEGMENTS];	/* pci function internal path */
106ac4995b9SSebastian Ott 	u32 uid;			/* user defined id */
107ac4995b9SSebastian Ott 	u8 util_str[CLP_UTIL_STR_LEN];	/* utility string */
108ac4995b9SSebastian Ott 
1099a4da8a5SJan Glauber 	/* IRQ stuff */
1109a4da8a5SJan Glauber 	u64		msi_addr;	/* MSI address */
111b19148f6SSebastian Ott 	unsigned int	max_msi;	/* maximum number of MSI's */
1125d0d8f43SMartin Schwidefsky 	struct airq_iv *aibv;		/* adapter interrupt bit vector */
113795818e8SSebastian Ott 	unsigned long	aisb;		/* number of the summary bit */
1149a4da8a5SJan Glauber 
115828b35f6SJan Glauber 	/* DMA stuff */
116828b35f6SJan Glauber 	unsigned long	*dma_table;
117828b35f6SJan Glauber 	spinlock_t	dma_table_lock;
118828b35f6SJan Glauber 	int		tlb_refresh;
119828b35f6SJan Glauber 
120828b35f6SJan Glauber 	spinlock_t	iommu_bitmap_lock;
121828b35f6SJan Glauber 	unsigned long	*iommu_bitmap;
12213954fd6SSebastian Ott 	unsigned long	*lazy_bitmap;
123828b35f6SJan Glauber 	unsigned long	iommu_size;
124828b35f6SJan Glauber 	unsigned long	iommu_pages;
125828b35f6SJan Glauber 	unsigned int	next_bit;
126828b35f6SJan Glauber 
127f42c2235SJoerg Roedel 	struct iommu_device iommu_dev;  /* IOMMU core handle */
128f42c2235SJoerg Roedel 
1297a572a3aSSebastian Ott 	char res_name[16];
130cd248341SJan Glauber 	struct zpci_bar_struct bars[PCI_BAR_COUNT];
131cd248341SJan Glauber 
132828b35f6SJan Glauber 	u64		start_dma;	/* Start of available DMA addresses */
133828b35f6SJan Glauber 	u64		end_dma;	/* End of available DMA addresses */
134828b35f6SJan Glauber 	u64		dma_mask;	/* DMA address space mask */
135828b35f6SJan Glauber 
136d0b08853SJan Glauber 	/* Function measurement block */
137d0b08853SJan Glauber 	struct zpci_fmb *fmb;
138d0b08853SJan Glauber 	u16		fmb_update;	/* update interval */
1390b7589ecSSebastian Ott 	u16		fmb_length;
1406001018aSSebastian Ott 	/* software counters */
1416001018aSSebastian Ott 	atomic64_t allocated_pages;
1426001018aSSebastian Ott 	atomic64_t mapped_pages;
1436001018aSSebastian Ott 	atomic64_t unmapped_pages;
144d0b08853SJan Glauber 
145cd248341SJan Glauber 	enum pci_bus_speed max_bus_speed;
146d0b08853SJan Glauber 
147d0b08853SJan Glauber 	struct dentry	*debugfs_dev;
148d0b08853SJan Glauber 	struct dentry	*debugfs_perf;
1498128f23cSGerald Schaefer 
1508128f23cSGerald Schaefer 	struct s390_domain *s390_domain; /* s390 IOMMU domain data */
151cd248341SJan Glauber };
152cd248341SJan Glauber 
153cd248341SJan Glauber static inline bool zdev_enabled(struct zpci_dev *zdev)
154cd248341SJan Glauber {
155cd248341SJan Glauber 	return (zdev->fh & (1UL << 31)) ? true : false;
156cd248341SJan Glauber }
157cd248341SJan Glauber 
15893065d04SSebastian Ott extern const struct attribute_group *zpci_attr_groups[];
15993065d04SSebastian Ott 
160cd248341SJan Glauber /* -----------------------------------------------------------------------------
161cd248341SJan Glauber   Prototypes
162cd248341SJan Glauber ----------------------------------------------------------------------------- */
163cd248341SJan Glauber /* Base stuff */
164cd248341SJan Glauber int zpci_create_device(struct zpci_dev *);
165623bd44dSSebastian Ott void zpci_remove_device(struct zpci_dev *zdev);
166cd248341SJan Glauber int zpci_enable_device(struct zpci_dev *);
167cb65a669SSebastian Ott int zpci_disable_device(struct zpci_dev *);
168828b35f6SJan Glauber int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
169828b35f6SJan Glauber int zpci_unregister_ioat(struct zpci_dev *, u8);
17001553d9aSSebastian Ott void zpci_remove_reserved_devices(void);
171cd248341SJan Glauber 
172a755a45dSJan Glauber /* CLP */
1731d578966SSebastian Ott int clp_scan_pci_devices(void);
1741d578966SSebastian Ott int clp_rescan_pci_devices(void);
17557b5918cSSebastian Ott int clp_rescan_pci_devices_simple(void);
176a755a45dSJan Glauber int clp_add_pci_device(u32, u32, int);
177a755a45dSJan Glauber int clp_enable_fh(struct zpci_dev *, u8);
178a755a45dSJan Glauber int clp_disable_fh(struct zpci_dev *);
179783684f1SSebastian Ott int clp_get_state(u32 fid, enum zpci_state *state);
180a755a45dSJan Glauber 
181f42c2235SJoerg Roedel /* IOMMU Interface */
182f42c2235SJoerg Roedel int zpci_init_iommu(struct zpci_dev *zdev);
183f42c2235SJoerg Roedel void zpci_destroy_iommu(struct zpci_dev *zdev);
184f42c2235SJoerg Roedel 
1859a17e972SSebastian Ott #ifdef CONFIG_PCI
186cbc0dd1fSJan Glauber /* Error handling and recovery */
187cbc0dd1fSJan Glauber void zpci_event_error(void *);
188cbc0dd1fSJan Glauber void zpci_event_availability(void *);
18957b5918cSSebastian Ott void zpci_rescan(void);
190aa3b7c29SSebastian Ott bool zpci_is_enabled(void);
1919a17e972SSebastian Ott #else /* CONFIG_PCI */
1929a17e972SSebastian Ott static inline void zpci_event_error(void *e) {}
1939a17e972SSebastian Ott static inline void zpci_event_availability(void *e) {}
19457b5918cSSebastian Ott static inline void zpci_rescan(void) {}
1959a17e972SSebastian Ott #endif /* CONFIG_PCI */
196cbc0dd1fSJan Glauber 
19767f43f38SSebastian Ott #ifdef CONFIG_HOTPLUG_PCI_S390
19867f43f38SSebastian Ott int zpci_init_slot(struct zpci_dev *);
19967f43f38SSebastian Ott void zpci_exit_slot(struct zpci_dev *);
20067f43f38SSebastian Ott #else /* CONFIG_HOTPLUG_PCI_S390 */
20167f43f38SSebastian Ott static inline int zpci_init_slot(struct zpci_dev *zdev)
20267f43f38SSebastian Ott {
20367f43f38SSebastian Ott 	return 0;
20467f43f38SSebastian Ott }
20567f43f38SSebastian Ott static inline void zpci_exit_slot(struct zpci_dev *zdev) {}
20667f43f38SSebastian Ott #endif /* CONFIG_HOTPLUG_PCI_S390 */
20767f43f38SSebastian Ott 
208cd248341SJan Glauber /* Helpers */
209198a5278SSebastian Ott static inline struct zpci_dev *to_zpci(struct pci_dev *pdev)
210198a5278SSebastian Ott {
211198a5278SSebastian Ott 	return pdev->sysdata;
212198a5278SSebastian Ott }
213198a5278SSebastian Ott 
214cd248341SJan Glauber struct zpci_dev *get_zdev_by_fid(u32);
215cd248341SJan Glauber 
216828b35f6SJan Glauber /* DMA */
217828b35f6SJan Glauber int zpci_dma_init(void);
218828b35f6SJan Glauber void zpci_dma_exit(void);
219828b35f6SJan Glauber 
220d0b08853SJan Glauber /* FMB */
221d0b08853SJan Glauber int zpci_fmb_enable_device(struct zpci_dev *);
222d0b08853SJan Glauber int zpci_fmb_disable_device(struct zpci_dev *);
223d0b08853SJan Glauber 
224d0b08853SJan Glauber /* Debug */
225d0b08853SJan Glauber int zpci_debug_init(void);
226d0b08853SJan Glauber void zpci_debug_exit(void);
2279a99649fSSebastian Ott void zpci_debug_init_device(struct zpci_dev *, const char *);
228d0b08853SJan Glauber void zpci_debug_exit_device(struct zpci_dev *);
229d0b08853SJan Glauber void zpci_debug_info(struct zpci_dev *, struct seq_file *);
230d0b08853SJan Glauber 
231bd3a1725SMartin Schwidefsky /* Error reporting */
232bd3a1725SMartin Schwidefsky int zpci_report_error(struct pci_dev *, struct zpci_report_error_header *);
233bd3a1725SMartin Schwidefsky 
2343a368f74SPhilipp Hachtmann #ifdef CONFIG_NUMA
2353a368f74SPhilipp Hachtmann 
2363a368f74SPhilipp Hachtmann /* Returns the node based on PCI bus */
2373a368f74SPhilipp Hachtmann static inline int __pcibus_to_node(const struct pci_bus *bus)
2383a368f74SPhilipp Hachtmann {
2393a368f74SPhilipp Hachtmann 	return NUMA_NO_NODE;
2403a368f74SPhilipp Hachtmann }
2413a368f74SPhilipp Hachtmann 
2423a368f74SPhilipp Hachtmann static inline const struct cpumask *
2433a368f74SPhilipp Hachtmann cpumask_of_pcibus(const struct pci_bus *bus)
2443a368f74SPhilipp Hachtmann {
2453a368f74SPhilipp Hachtmann 	return cpu_online_mask;
2463a368f74SPhilipp Hachtmann }
2473a368f74SPhilipp Hachtmann 
2483a368f74SPhilipp Hachtmann #endif /* CONFIG_NUMA */
2493a368f74SPhilipp Hachtmann 
250cd248341SJan Glauber #endif
251