Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * File: portdrv.h |
Bjorn Helgaas | ef79426 | 2018-03-09 11:42:01 -0600 | [diff] [blame] | 4 | * Purpose: PCI Express Port Bus Driver's Data Structures |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Andrew Morton | 3ec6a8d | 2006-09-25 16:52:20 -0700 | [diff] [blame] | 13 | #include <linux/compiler.h> |
| 14 | |
Bjorn Helgaas | d850882 | 2018-03-09 11:21:30 -0600 | [diff] [blame^] | 15 | extern bool pcie_ports_native; |
Bjorn Helgaas | 842b447 | 2018-03-09 11:21:29 -0600 | [diff] [blame] | 16 | |
Bjorn Helgaas | ef79426 | 2018-03-09 11:42:01 -0600 | [diff] [blame] | 17 | /* Service Type */ |
| 18 | #define PCIE_PORT_SERVICE_PME_SHIFT 0 /* Power Management Event */ |
| 19 | #define PCIE_PORT_SERVICE_PME (1 << PCIE_PORT_SERVICE_PME_SHIFT) |
| 20 | #define PCIE_PORT_SERVICE_AER_SHIFT 1 /* Advanced Error Reporting */ |
| 21 | #define PCIE_PORT_SERVICE_AER (1 << PCIE_PORT_SERVICE_AER_SHIFT) |
| 22 | #define PCIE_PORT_SERVICE_HP_SHIFT 2 /* Native Hotplug */ |
| 23 | #define PCIE_PORT_SERVICE_HP (1 << PCIE_PORT_SERVICE_HP_SHIFT) |
Bjorn Helgaas | 168f3ae | 2018-03-09 11:21:24 -0600 | [diff] [blame] | 24 | #define PCIE_PORT_SERVICE_DPC_SHIFT 3 /* Downstream Port Containment */ |
Bjorn Helgaas | ef79426 | 2018-03-09 11:42:01 -0600 | [diff] [blame] | 25 | #define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT) |
| 26 | |
Bjorn Helgaas | 168f3ae | 2018-03-09 11:21:24 -0600 | [diff] [blame] | 27 | #define PCIE_PORT_DEVICE_MAXSERVICES 4 |
Bjorn Helgaas | ef79426 | 2018-03-09 11:42:01 -0600 | [diff] [blame] | 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 | |
Rafael J. Wysocki | b43d451 | 2009-01-24 00:23:22 +0100 | [diff] [blame] | 75 | /* |
Gabriele Paoloni | a1d5f18 | 2017-05-23 15:23:58 +0100 | [diff] [blame] | 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. |
Rafael J. Wysocki | b43d451 | 2009-01-24 00:23:22 +0100 | [diff] [blame] | 79 | */ |
Gabriele Paoloni | a1d5f18 | 2017-05-23 15:23:58 +0100 | [diff] [blame] | 80 | #define PCIE_PORT_MAX_MSI_ENTRIES 32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Keith Busch | 6d81417 | 2016-05-03 09:58:11 -0500 | [diff] [blame] | 82 | #define get_descriptor_id(type, service) (((type - 4) << 8) | service) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | extern struct bus_type pcie_port_bus_type; |
Bjorn Helgaas | f39d5b7 | 2013-04-12 12:02:59 -0600 | [diff] [blame] | 85 | int pcie_port_device_register(struct pci_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_PM |
Bjorn Helgaas | f39d5b7 | 2013-04-12 12:02:59 -0600 | [diff] [blame] | 87 | int pcie_port_device_suspend(struct device *dev); |
| 88 | int pcie_port_device_resume(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #endif |
Bjorn Helgaas | f39d5b7 | 2013-04-12 12:02:59 -0600 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Rafael J. Wysocki | 28eb5f2 | 2010-08-21 22:02:38 +0200 | [diff] [blame] | 94 | struct pci_dev; |
| 95 | |
Rafael J. Wysocki | c39fae1 | 2010-02-17 23:40:07 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_PCIE_PME |
| 97 | extern bool pcie_pme_msi_disabled; |
| 98 | |
| 99 | static inline void pcie_pme_disable_msi(void) |
| 100 | { |
| 101 | pcie_pme_msi_disabled = true; |
| 102 | } |
| 103 | |
| 104 | static inline bool pcie_pme_no_msi(void) |
| 105 | { |
| 106 | return pcie_pme_msi_disabled; |
| 107 | } |
Rafael J. Wysocki | 28eb5f2 | 2010-08-21 22:02:38 +0200 | [diff] [blame] | 108 | |
Bjorn Helgaas | f39d5b7 | 2013-04-12 12:02:59 -0600 | [diff] [blame] | 109 | void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable); |
Rafael J. Wysocki | c39fae1 | 2010-02-17 23:40:07 +0100 | [diff] [blame] | 110 | #else /* !CONFIG_PCIE_PME */ |
| 111 | static inline void pcie_pme_disable_msi(void) {} |
| 112 | static inline bool pcie_pme_no_msi(void) { return false; } |
Rafael J. Wysocki | 28eb5f2 | 2010-08-21 22:02:38 +0200 | [diff] [blame] | 113 | static inline void pcie_pme_interrupt_enable(struct pci_dev *dev, bool en) {} |
Rafael J. Wysocki | c39fae1 | 2010-02-17 23:40:07 +0100 | [diff] [blame] | 114 | #endif /* !CONFIG_PCIE_PME */ |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #endif /* _PORTDRV_H_ */ |