Merge tag 'fs.xattr.simple.noaudit.v6.2' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / linux / pci-epf.h
CommitLineData
8cfab3cf 1/* SPDX-License-Identifier: GPL-2.0 */
347269c1 2/*
5e8cb403
KVA
3 * PCI Endpoint *Function* (EPF) header file
4 *
5 * Copyright (C) 2017 Texas Instruments
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
5e8cb403
KVA
7 */
8
9#ifndef __LINUX_PCI_EPF_H
10#define __LINUX_PCI_EPF_H
11
38ad827e 12#include <linux/configfs.h>
5e8cb403
KVA
13#include <linux/device.h>
14#include <linux/mod_devicetable.h>
b352baf1 15#include <linux/pci.h>
5e8cb403
KVA
16
17struct pci_epf;
63840ff5 18enum pci_epc_interface_type;
5e8cb403 19
0ef22dcf
VS
20enum pci_notify_event {
21 CORE_INIT,
22 LINK_UP,
23};
24
5e8cb403 25enum pci_barno {
0e27aecc 26 NO_BAR = -1,
5e8cb403
KVA
27 BAR_0,
28 BAR_1,
29 BAR_2,
30 BAR_3,
31 BAR_4,
32 BAR_5,
33};
34
35/**
36 * struct pci_epf_header - represents standard configuration header
37 * @vendorid: identifies device manufacturer
38 * @deviceid: identifies a particular device
39 * @revid: specifies a device-specific revision identifier
40 * @progif_code: identifies a specific register-level programming interface
41 * @subclass_code: identifies more specifically the function of the device
42 * @baseclass_code: broadly classifies the type of function the device performs
43 * @cache_line_size: specifies the system cacheline size in units of DWORDs
44 * @subsys_vendor_id: vendor of the add-in card or subsystem
45 * @subsys_id: id specific to vendor
46 * @interrupt_pin: interrupt pin the device (or device function) uses
47 */
48struct pci_epf_header {
49 u16 vendorid;
50 u16 deviceid;
51 u8 revid;
52 u8 progif_code;
53 u8 subclass_code;
54 u8 baseclass_code;
55 u8 cache_line_size;
56 u16 subsys_vendor_id;
57 u16 subsys_id;
58 enum pci_interrupt_pin interrupt_pin;
59};
60
61/**
62 * struct pci_epf_ops - set of function pointers for performing EPF operations
63 * @bind: ops to perform when a EPC device has been bound to EPF device
64 * @unbind: ops to perform when a binding has been lost between a EPC device
65 * and EPF device
256ae475 66 * @add_cfs: ops to initialize function specific configfs attributes
5e8cb403
KVA
67 */
68struct pci_epf_ops {
69 int (*bind)(struct pci_epf *epf);
70 void (*unbind)(struct pci_epf *epf);
256ae475
KVA
71 struct config_group *(*add_cfs)(struct pci_epf *epf,
72 struct config_group *group);
5e8cb403
KVA
73};
74
75/**
76 * struct pci_epf_driver - represents the PCI EPF driver
77 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
78 * @remove: ops to perform when the binding between the EPF device and EPF
79 * driver is broken
80 * @driver: PCI EPF driver
81 * @ops: set of function pointers for performing EPF operations
82 * @owner: the owner of the module that registers the PCI EPF driver
ef1433f7 83 * @epf_group: list of configfs group corresponding to the PCI EPF driver
5e8cb403
KVA
84 * @id_table: identifies EPF devices for probing
85 */
86struct pci_epf_driver {
87 int (*probe)(struct pci_epf *epf);
dde0a318 88 void (*remove)(struct pci_epf *epf);
5e8cb403
KVA
89
90 struct device_driver driver;
91 struct pci_epf_ops *ops;
92 struct module *owner;
ef1433f7 93 struct list_head epf_group;
5e8cb403
KVA
94 const struct pci_epf_device_id *id_table;
95};
96
97#define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
98 driver))
99
100/**
101 * struct pci_epf_bar - represents the BAR of EPF device
102 * @phys_addr: physical address that should be mapped to the BAR
6f5e193b 103 * @addr: virtual address corresponding to the @phys_addr
5e8cb403 104 * @size: the size of the address space present in BAR
347269c1
KW
105 * @barno: BAR number
106 * @flags: flags that are set for the BAR
5e8cb403
KVA
107 */
108struct pci_epf_bar {
109 dma_addr_t phys_addr;
6f5e193b 110 void *addr;
5e8cb403 111 size_t size;
bc4a4897
NC
112 enum pci_barno barno;
113 int flags;
5e8cb403
KVA
114};
115
116/**
117 * struct pci_epf - represents the PCI EPF device
118 * @dev: the PCI EPF device
119 * @name: the name of the PCI EPF device
120 * @header: represents standard configuration header
121 * @bar: represents the BAR of EPF device
122 * @msi_interrupts: number of MSI interrupts required by this function
347269c1 123 * @msix_interrupts: number of MSI-X interrupts required by this function
1cf362e9
KVA
124 * @func_no: unique (physical) function number within this endpoint device
125 * @vfunc_no: unique virtual function number within a physical function
5e8cb403 126 * @epc: the EPC device to which this EPF device is bound
1cf362e9 127 * @epf_pf: the physical EPF device to which this virtual EPF device is bound
5e8cb403
KVA
128 * @driver: the EPF driver to which this EPF device is bound
129 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
5779dd0a 130 * @nb: notifier block to notify EPF of any EPC events (like linkup)
07301c98 131 * @lock: mutex to protect pci_epf_ops
63840ff5
KVA
132 * @sec_epc: the secondary EPC device to which this EPF device is bound
133 * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
134 * EPC device
135 * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
136 * @sec_epc_func_no: unique (physical) function number within the secondary EPC
38ad827e 137 * @group: configfs group associated with the EPF device
1cf362e9
KVA
138 * @is_bound: indicates if bind notification to function driver has been invoked
139 * @is_vf: true - virtual function, false - physical function
140 * @vfunction_num_map: bitmap to manage virtual function number
141 * @pci_vepf: list of virtual endpoint functions associated with this function
5e8cb403
KVA
142 */
143struct pci_epf {
144 struct device dev;
145 const char *name;
146 struct pci_epf_header *header;
147 struct pci_epf_bar bar[6];
148 u8 msi_interrupts;
8963106e 149 u16 msix_interrupts;
5e8cb403 150 u8 func_no;
1cf362e9 151 u8 vfunc_no;
5e8cb403
KVA
152
153 struct pci_epc *epc;
1cf362e9 154 struct pci_epf *epf_pf;
5e8cb403
KVA
155 struct pci_epf_driver *driver;
156 struct list_head list;
5779dd0a 157 struct notifier_block nb;
07301c98
KVA
158 /* mutex to protect against concurrent access of pci_epf_ops */
159 struct mutex lock;
63840ff5
KVA
160
161 /* Below members are to attach secondary EPC to an endpoint function */
162 struct pci_epc *sec_epc;
163 struct list_head sec_epc_list;
164 struct pci_epf_bar sec_epc_bar[6];
165 u8 sec_epc_func_no;
38ad827e 166 struct config_group *group;
1cf362e9
KVA
167 unsigned int is_bound;
168 unsigned int is_vf;
169 unsigned long vfunction_num_map;
170 struct list_head pci_vepf;
5e8cb403
KVA
171};
172
6f5e193b
KVA
173/**
174 * struct pci_epf_msix_tbl - represents the MSIX table entry structure
175 * @msg_addr: Writes to this address will trigger MSIX interrupt in host
176 * @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
177 * @vector_ctrl: Identifies if the function is prohibited from sending a message
178 * using this MSIX table entry
179 */
180struct pci_epf_msix_tbl {
181 u64 msg_addr;
182 u32 msg_data;
183 u32 vector_ctrl;
184};
185
5e8cb403
KVA
186#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
187
188#define pci_epf_register_driver(driver) \
189 __pci_epf_register_driver((driver), THIS_MODULE)
190
191static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
192{
193 dev_set_drvdata(&epf->dev, data);
194}
195
196static inline void *epf_get_drvdata(struct pci_epf *epf)
197{
198 return dev_get_drvdata(&epf->dev);
199}
200
201struct pci_epf *pci_epf_create(const char *name);
202void pci_epf_destroy(struct pci_epf *epf);
203int __pci_epf_register_driver(struct pci_epf_driver *driver,
204 struct module *owner);
205void pci_epf_unregister_driver(struct pci_epf_driver *driver);
2a9a8016 206void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
63840ff5
KVA
207 size_t align, enum pci_epc_interface_type type);
208void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
209 enum pci_epc_interface_type type);
5e8cb403
KVA
210int pci_epf_bind(struct pci_epf *epf);
211void pci_epf_unbind(struct pci_epf *epf);
256ae475
KVA
212struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf,
213 struct config_group *group);
1cf362e9
KVA
214int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
215void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
5e8cb403 216#endif /* __LINUX_PCI_EPF_H */