xref: /openbmc/linux/drivers/pci/pcie/portdrv.h (revision 2e6ae11dd0d1c37f44cec51a58fb2092e55ed0f5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Purpose:	PCI Express Port Bus Driver's Internal Data Structures
4  *
5  * Copyright (C) 2004 Intel
6  * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7  */
8 
9 #ifndef _PORTDRV_H_
10 #define _PORTDRV_H_
11 
12 #include <linux/compiler.h>
13 
14 /* Service Type */
15 #define PCIE_PORT_SERVICE_PME_SHIFT	0	/* Power Management Event */
16 #define PCIE_PORT_SERVICE_PME		(1 << PCIE_PORT_SERVICE_PME_SHIFT)
17 #define PCIE_PORT_SERVICE_AER_SHIFT	1	/* Advanced Error Reporting */
18 #define PCIE_PORT_SERVICE_AER		(1 << PCIE_PORT_SERVICE_AER_SHIFT)
19 #define PCIE_PORT_SERVICE_HP_SHIFT	2	/* Native Hotplug */
20 #define PCIE_PORT_SERVICE_HP		(1 << PCIE_PORT_SERVICE_HP_SHIFT)
21 #define PCIE_PORT_SERVICE_DPC_SHIFT	3	/* Downstream Port Containment */
22 #define PCIE_PORT_SERVICE_DPC		(1 << PCIE_PORT_SERVICE_DPC_SHIFT)
23 
24 #define PCIE_PORT_DEVICE_MAXSERVICES   4
25 
26 /* Port Type */
27 #define PCIE_ANY_PORT			(~0)
28 
29 struct pcie_device {
30 	int		irq;	    /* Service IRQ/MSI/MSI-X Vector */
31 	struct pci_dev *port;	    /* Root/Upstream/Downstream Port */
32 	u32		service;    /* Port service this device represents */
33 	void		*priv_data; /* Service Private Data */
34 	struct device	device;     /* Generic Device Interface */
35 };
36 #define to_pcie_device(d) container_of(d, struct pcie_device, device)
37 
38 static inline void set_service_data(struct pcie_device *dev, void *data)
39 {
40 	dev->priv_data = data;
41 }
42 
43 static inline void *get_service_data(struct pcie_device *dev)
44 {
45 	return dev->priv_data;
46 }
47 
48 struct pcie_port_service_driver {
49 	const char *name;
50 	int (*probe) (struct pcie_device *dev);
51 	void (*remove) (struct pcie_device *dev);
52 	int (*suspend) (struct pcie_device *dev);
53 	int (*resume_noirq) (struct pcie_device *dev);
54 	int (*resume) (struct pcie_device *dev);
55 
56 	/* Device driver may resume normal operations */
57 	void (*error_resume)(struct pci_dev *dev);
58 
59 	/* Link Reset Capability - AER service driver specific */
60 	pci_ers_result_t (*reset_link) (struct pci_dev *dev);
61 
62 	int port_type;  /* Type of the port this driver can handle */
63 	u32 service;    /* Port service this device represents */
64 
65 	struct device_driver driver;
66 };
67 #define to_service_driver(d) \
68 	container_of(d, struct pcie_port_service_driver, driver)
69 
70 int pcie_port_service_register(struct pcie_port_service_driver *new);
71 void pcie_port_service_unregister(struct pcie_port_service_driver *new);
72 
73 /*
74  * The PCIe Capability Interrupt Message Number (PCIe r3.1, sec 7.8.2) must
75  * be one of the first 32 MSI-X entries.  Per PCI r3.0, sec 6.8.3.1, MSI
76  * supports a maximum of 32 vectors per function.
77  */
78 #define PCIE_PORT_MAX_MSI_ENTRIES	32
79 
80 #define get_descriptor_id(type, service) (((type - 4) << 8) | service)
81 
82 extern struct bus_type pcie_port_bus_type;
83 int pcie_port_device_register(struct pci_dev *dev);
84 #ifdef CONFIG_PM
85 int pcie_port_device_suspend(struct device *dev);
86 int pcie_port_device_resume_noirq(struct device *dev);
87 int pcie_port_device_resume(struct device *dev);
88 #endif
89 void pcie_port_device_remove(struct pci_dev *dev);
90 int __must_check pcie_port_bus_register(void);
91 void pcie_port_bus_unregister(void);
92 
93 struct pci_dev;
94 
95 #ifdef CONFIG_PCIE_PME
96 extern bool pcie_pme_msi_disabled;
97 
98 static inline void pcie_pme_disable_msi(void)
99 {
100 	pcie_pme_msi_disabled = true;
101 }
102 
103 static inline bool pcie_pme_no_msi(void)
104 {
105 	return pcie_pme_msi_disabled;
106 }
107 
108 void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable);
109 #else /* !CONFIG_PCIE_PME */
110 static inline void pcie_pme_disable_msi(void) {}
111 static inline bool pcie_pme_no_msi(void) { return false; }
112 static inline void pcie_pme_interrupt_enable(struct pci_dev *dev, bool en) {}
113 #endif /* !CONFIG_PCIE_PME */
114 
115 #ifdef CONFIG_ACPI_APEI
116 int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
117 #else
118 static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
119 {
120 	if (pci_dev->__aer_firmware_first_valid)
121 		return pci_dev->__aer_firmware_first;
122 	return 0;
123 }
124 #endif
125 
126 #ifdef CONFIG_PCIEAER
127 irqreturn_t aer_irq(int irq, void *context);
128 #endif
129 
130 struct pcie_port_service_driver *pcie_port_find_service(struct pci_dev *dev,
131 							u32 service);
132 struct device *pcie_port_find_device(struct pci_dev *dev, u32 service);
133 #endif /* _PORTDRV_H_ */
134