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