Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * PCI Endpoint *Function* (EPF) header file
0004  *
0005  * Copyright (C) 2017 Texas Instruments
0006  * Author: Kishon Vijay Abraham I <kishon@ti.com>
0007  */
0008 
0009 #ifndef __LINUX_PCI_EPF_H
0010 #define __LINUX_PCI_EPF_H
0011 
0012 #include <linux/configfs.h>
0013 #include <linux/device.h>
0014 #include <linux/mod_devicetable.h>
0015 #include <linux/pci.h>
0016 
0017 struct pci_epf;
0018 enum pci_epc_interface_type;
0019 
0020 enum pci_notify_event {
0021     CORE_INIT,
0022     LINK_UP,
0023 };
0024 
0025 enum pci_barno {
0026     NO_BAR = -1,
0027     BAR_0,
0028     BAR_1,
0029     BAR_2,
0030     BAR_3,
0031     BAR_4,
0032     BAR_5,
0033 };
0034 
0035 /**
0036  * struct pci_epf_header - represents standard configuration header
0037  * @vendorid: identifies device manufacturer
0038  * @deviceid: identifies a particular device
0039  * @revid: specifies a device-specific revision identifier
0040  * @progif_code: identifies a specific register-level programming interface
0041  * @subclass_code: identifies more specifically the function of the device
0042  * @baseclass_code: broadly classifies the type of function the device performs
0043  * @cache_line_size: specifies the system cacheline size in units of DWORDs
0044  * @subsys_vendor_id: vendor of the add-in card or subsystem
0045  * @subsys_id: id specific to vendor
0046  * @interrupt_pin: interrupt pin the device (or device function) uses
0047  */
0048 struct pci_epf_header {
0049     u16 vendorid;
0050     u16 deviceid;
0051     u8  revid;
0052     u8  progif_code;
0053     u8  subclass_code;
0054     u8  baseclass_code;
0055     u8  cache_line_size;
0056     u16 subsys_vendor_id;
0057     u16 subsys_id;
0058     enum pci_interrupt_pin interrupt_pin;
0059 };
0060 
0061 /**
0062  * struct pci_epf_ops - set of function pointers for performing EPF operations
0063  * @bind: ops to perform when a EPC device has been bound to EPF device
0064  * @unbind: ops to perform when a binding has been lost between a EPC device
0065  *      and EPF device
0066  * @add_cfs: ops to initialize function specific configfs attributes
0067  */
0068 struct pci_epf_ops {
0069     int (*bind)(struct pci_epf *epf);
0070     void    (*unbind)(struct pci_epf *epf);
0071     struct config_group *(*add_cfs)(struct pci_epf *epf,
0072                     struct config_group *group);
0073 };
0074 
0075 /**
0076  * struct pci_epf_driver - represents the PCI EPF driver
0077  * @probe: ops to perform when a new EPF device has been bound to the EPF driver
0078  * @remove: ops to perform when the binding between the EPF device and EPF
0079  *      driver is broken
0080  * @driver: PCI EPF driver
0081  * @ops: set of function pointers for performing EPF operations
0082  * @owner: the owner of the module that registers the PCI EPF driver
0083  * @epf_group: list of configfs group corresponding to the PCI EPF driver
0084  * @id_table: identifies EPF devices for probing
0085  */
0086 struct pci_epf_driver {
0087     int (*probe)(struct pci_epf *epf);
0088     void    (*remove)(struct pci_epf *epf);
0089 
0090     struct device_driver    driver;
0091     struct pci_epf_ops  *ops;
0092     struct module       *owner;
0093     struct list_head    epf_group;
0094     const struct pci_epf_device_id  *id_table;
0095 };
0096 
0097 #define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
0098                 driver))
0099 
0100 /**
0101  * struct pci_epf_bar - represents the BAR of EPF device
0102  * @phys_addr: physical address that should be mapped to the BAR
0103  * @addr: virtual address corresponding to the @phys_addr
0104  * @size: the size of the address space present in BAR
0105  * @barno: BAR number
0106  * @flags: flags that are set for the BAR
0107  */
0108 struct pci_epf_bar {
0109     dma_addr_t  phys_addr;
0110     void        *addr;
0111     size_t      size;
0112     enum pci_barno  barno;
0113     int     flags;
0114 };
0115 
0116 /**
0117  * struct pci_epf - represents the PCI EPF device
0118  * @dev: the PCI EPF device
0119  * @name: the name of the PCI EPF device
0120  * @header: represents standard configuration header
0121  * @bar: represents the BAR of EPF device
0122  * @msi_interrupts: number of MSI interrupts required by this function
0123  * @msix_interrupts: number of MSI-X interrupts required by this function
0124  * @func_no: unique (physical) function number within this endpoint device
0125  * @vfunc_no: unique virtual function number within a physical function
0126  * @epc: the EPC device to which this EPF device is bound
0127  * @epf_pf: the physical EPF device to which this virtual EPF device is bound
0128  * @driver: the EPF driver to which this EPF device is bound
0129  * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
0130  * @nb: notifier block to notify EPF of any EPC events (like linkup)
0131  * @lock: mutex to protect pci_epf_ops
0132  * @sec_epc: the secondary EPC device to which this EPF device is bound
0133  * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
0134  *   EPC device
0135  * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
0136  * @sec_epc_func_no: unique (physical) function number within the secondary EPC
0137  * @group: configfs group associated with the EPF device
0138  * @is_bound: indicates if bind notification to function driver has been invoked
0139  * @is_vf: true - virtual function, false - physical function
0140  * @vfunction_num_map: bitmap to manage virtual function number
0141  * @pci_vepf: list of virtual endpoint functions associated with this function
0142  */
0143 struct pci_epf {
0144     struct device       dev;
0145     const char      *name;
0146     struct pci_epf_header   *header;
0147     struct pci_epf_bar  bar[6];
0148     u8          msi_interrupts;
0149     u16         msix_interrupts;
0150     u8          func_no;
0151     u8          vfunc_no;
0152 
0153     struct pci_epc      *epc;
0154     struct pci_epf      *epf_pf;
0155     struct pci_epf_driver   *driver;
0156     struct list_head    list;
0157     struct notifier_block   nb;
0158     /* mutex to protect against concurrent access of pci_epf_ops */
0159     struct mutex        lock;
0160 
0161     /* Below members are to attach secondary EPC to an endpoint function */
0162     struct pci_epc      *sec_epc;
0163     struct list_head    sec_epc_list;
0164     struct pci_epf_bar  sec_epc_bar[6];
0165     u8          sec_epc_func_no;
0166     struct config_group *group;
0167     unsigned int        is_bound;
0168     unsigned int        is_vf;
0169     unsigned long       vfunction_num_map;
0170     struct list_head    pci_vepf;
0171 };
0172 
0173 /**
0174  * struct pci_epf_msix_tbl - represents the MSIX table entry structure
0175  * @msg_addr: Writes to this address will trigger MSIX interrupt in host
0176  * @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
0177  * @vector_ctrl: Identifies if the function is prohibited from sending a message
0178  * using this MSIX table entry
0179  */
0180 struct pci_epf_msix_tbl {
0181     u64 msg_addr;
0182     u32 msg_data;
0183     u32 vector_ctrl;
0184 };
0185 
0186 #define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
0187 
0188 #define pci_epf_register_driver(driver)    \
0189         __pci_epf_register_driver((driver), THIS_MODULE)
0190 
0191 static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
0192 {
0193     dev_set_drvdata(&epf->dev, data);
0194 }
0195 
0196 static inline void *epf_get_drvdata(struct pci_epf *epf)
0197 {
0198     return dev_get_drvdata(&epf->dev);
0199 }
0200 
0201 struct pci_epf *pci_epf_create(const char *name);
0202 void pci_epf_destroy(struct pci_epf *epf);
0203 int __pci_epf_register_driver(struct pci_epf_driver *driver,
0204                   struct module *owner);
0205 void pci_epf_unregister_driver(struct pci_epf_driver *driver);
0206 void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
0207               size_t align, enum pci_epc_interface_type type);
0208 void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
0209             enum pci_epc_interface_type type);
0210 int pci_epf_bind(struct pci_epf *epf);
0211 void pci_epf_unbind(struct pci_epf *epf);
0212 struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf,
0213                       struct config_group *group);
0214 int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
0215 void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
0216 #endif /* __LINUX_PCI_EPF_H */