225 lines · plain
1.. SPDX-License-Identifier: GPL-2.02.. include:: <isonum.txt>3 4===========================================5The PCI Express Port Bus Driver Guide HOWTO6===========================================7 8:Author: Tom L Nguyen tom.l.nguyen@intel.com 11/03/20049:Copyright: |copy| 2004 Intel Corporation10 11About this guide12================13 14This guide describes the basics of the PCI Express Port Bus driver15and provides information on how to enable the service drivers to16register/unregister with the PCI Express Port Bus Driver.17 18 19What is the PCI Express Port Bus Driver20=======================================21 22A PCI Express Port is a logical PCI-PCI Bridge structure. There23are two types of PCI Express Port: the Root Port and the Switch24Port. The Root Port originates a PCI Express link from a PCI Express25Root Complex and the Switch Port connects PCI Express links to26internal logical PCI buses. The Switch Port, which has its secondary27bus representing the switch's internal routing logic, is called the28switch's Upstream Port. The switch's Downstream Port is bridging from29switch's internal routing bus to a bus representing the downstream30PCI Express link from the PCI Express Switch.31 32A PCI Express Port can provide up to four distinct functions,33referred to in this document as services, depending on its port type.34PCI Express Port's services include native hotplug support (HP),35power management event support (PME), advanced error reporting36support (AER), and virtual channel support (VC). These services may37be handled by a single complex driver or be individually distributed38and handled by corresponding service drivers.39 40Why use the PCI Express Port Bus Driver?41========================================42 43In existing Linux kernels, the Linux Device Driver Model allows a44physical device to be handled by only a single driver. The PCI45Express Port is a PCI-PCI Bridge device with multiple distinct46services. To maintain a clean and simple solution each service47may have its own software service driver. In this case several48service drivers will compete for a single PCI-PCI Bridge device.49For example, if the PCI Express Root Port native hotplug service50driver is loaded first, it claims a PCI-PCI Bridge Root Port. The51kernel therefore does not load other service drivers for that Root52Port. In other words, it is impossible to have multiple service53drivers load and run on a PCI-PCI Bridge device simultaneously54using the current driver model.55 56To enable multiple service drivers running simultaneously requires57having a PCI Express Port Bus driver, which manages all populated58PCI Express Ports and distributes all provided service requests59to the corresponding service drivers as required. Some key60advantages of using the PCI Express Port Bus driver are listed below:61 62 - Allow multiple service drivers to run simultaneously on63 a PCI-PCI Bridge Port device.64 65 - Allow service drivers implemented in an independent66 staged approach.67 68 - Allow one service driver to run on multiple PCI-PCI Bridge69 Port devices.70 71 - Manage and distribute resources of a PCI-PCI Bridge Port72 device to requested service drivers.73 74Configuring the PCI Express Port Bus Driver vs. Service Drivers75===============================================================76 77Including the PCI Express Port Bus Driver Support into the Kernel78-----------------------------------------------------------------79 80Including the PCI Express Port Bus driver depends on whether the PCI81Express support is included in the kernel config. The kernel will82automatically include the PCI Express Port Bus driver as a kernel83driver when the PCI Express support is enabled in the kernel.84 85Enabling Service Driver Support86-------------------------------87 88PCI device drivers are implemented based on Linux Device Driver Model.89All service drivers are PCI device drivers. As discussed above, it is90impossible to load any service driver once the kernel has loaded the91PCI Express Port Bus Driver. To meet the PCI Express Port Bus Driver92Model requires some minimal changes on existing service drivers that93imposes no impact on the functionality of existing service drivers.94 95A service driver is required to use the two APIs shown below to96register its service with the PCI Express Port Bus driver (see97section 5.2.1 & 5.2.2). It is important that a service driver98initializes the pcie_port_service_driver data structure, included in99header file /include/linux/pcieport_if.h, before calling these APIs.100Failure to do so will result an identity mismatch, which prevents101the PCI Express Port Bus driver from loading a service driver.102 103pcie_port_service_register104~~~~~~~~~~~~~~~~~~~~~~~~~~105::106 107 int pcie_port_service_register(struct pcie_port_service_driver *new)108 109This API replaces the Linux Driver Model's pci_register_driver API. A110service driver should always calls pcie_port_service_register at111module init. Note that after service driver being loaded, calls112such as pci_enable_device(dev) and pci_set_master(dev) are no longer113necessary since these calls are executed by the PCI Port Bus driver.114 115pcie_port_service_unregister116~~~~~~~~~~~~~~~~~~~~~~~~~~~~117::118 119 void pcie_port_service_unregister(struct pcie_port_service_driver *new)120 121pcie_port_service_unregister replaces the Linux Driver Model's122pci_unregister_driver. It's always called by service driver when a123module exits.124 125Sample Code126~~~~~~~~~~~127 128Below is sample service driver code to initialize the port service129driver data structure.130::131 132 static struct pcie_port_service_id service_id[] = { {133 .vendor = PCI_ANY_ID,134 .device = PCI_ANY_ID,135 .port_type = PCIE_RC_PORT,136 .service_type = PCIE_PORT_SERVICE_AER,137 }, { /* end: all zeroes */ }138 };139 140 static struct pcie_port_service_driver root_aerdrv = {141 .name = (char *)device_name,142 .id_table = service_id,143 144 .probe = aerdrv_load,145 .remove = aerdrv_unload,146 147 .suspend = aerdrv_suspend,148 .resume = aerdrv_resume,149 };150 151Below is a sample code for registering/unregistering a service152driver.153::154 155 static int __init aerdrv_service_init(void)156 {157 int retval = 0;158 159 retval = pcie_port_service_register(&root_aerdrv);160 if (!retval) {161 /*162 * FIX ME163 */164 }165 return retval;166 }167 168 static void __exit aerdrv_service_exit(void)169 {170 pcie_port_service_unregister(&root_aerdrv);171 }172 173 module_init(aerdrv_service_init);174 module_exit(aerdrv_service_exit);175 176Possible Resource Conflicts177===========================178 179Since all service drivers of a PCI-PCI Bridge Port device are180allowed to run simultaneously, below lists a few of possible resource181conflicts with proposed solutions.182 183MSI and MSI-X Vector Resource184-----------------------------185 186Once MSI or MSI-X interrupts are enabled on a device, it stays in this187mode until they are disabled again. Since service drivers of the same188PCI-PCI Bridge port share the same physical device, if an individual189service driver enables or disables MSI/MSI-X mode it may result190unpredictable behavior.191 192To avoid this situation all service drivers are not permitted to193switch interrupt mode on its device. The PCI Express Port Bus driver194is responsible for determining the interrupt mode and this should be195transparent to service drivers. Service drivers need to know only196the vector IRQ assigned to the field irq of struct pcie_device, which197is passed in when the PCI Express Port Bus driver probes each service198driver. Service drivers should use (struct pcie_device*)dev->irq to199call request_irq/free_irq. In addition, the interrupt mode is stored200in the field interrupt_mode of struct pcie_device.201 202PCI Memory/IO Mapped Regions203----------------------------204 205Service drivers for PCI Express Power Management (PME), Advanced206Error Reporting (AER), Hot-Plug (HP) and Virtual Channel (VC) access207PCI configuration space on the PCI Express port. In all cases the208registers accessed are independent of each other. This patch assumes209that all service drivers will be well behaved and not overwrite210other service driver's configuration settings.211 212PCI Config Registers213--------------------214 215Each service driver runs its PCI config operations on its own216capability structure except the PCI Express capability structure,217that is shared between many drivers including the service drivers.218RMW Capability accessors (pcie_capability_clear_and_set_word(),219pcie_capability_set_word(), and pcie_capability_clear_word()) protect220a selected set of PCI Express Capability Registers (Link Control221Register and Root Control Register). Any change to those registers222should be performed using RMW accessors to avoid problems due to223concurrent updates. For the up-to-date list of protected registers,224see pcie_capability_clear_and_set_word().225