Merge branch 'address-masking'
[linux-2.6-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;
e891becd 18struct pci_epc_features;
63840ff5 19enum pci_epc_interface_type;
5e8cb403 20
5e8cb403 21enum pci_barno {
0e27aecc 22 NO_BAR = -1,
5e8cb403
KVA
23 BAR_0,
24 BAR_1,
25 BAR_2,
26 BAR_3,
27 BAR_4,
28 BAR_5,
29};
30
31/**
32 * struct pci_epf_header - represents standard configuration header
33 * @vendorid: identifies device manufacturer
34 * @deviceid: identifies a particular device
35 * @revid: specifies a device-specific revision identifier
36 * @progif_code: identifies a specific register-level programming interface
37 * @subclass_code: identifies more specifically the function of the device
38 * @baseclass_code: broadly classifies the type of function the device performs
39 * @cache_line_size: specifies the system cacheline size in units of DWORDs
40 * @subsys_vendor_id: vendor of the add-in card or subsystem
41 * @subsys_id: id specific to vendor
42 * @interrupt_pin: interrupt pin the device (or device function) uses
43 */
44struct pci_epf_header {
45 u16 vendorid;
46 u16 deviceid;
47 u8 revid;
48 u8 progif_code;
49 u8 subclass_code;
50 u8 baseclass_code;
51 u8 cache_line_size;
52 u16 subsys_vendor_id;
53 u16 subsys_id;
54 enum pci_interrupt_pin interrupt_pin;
55};
56
57/**
58 * struct pci_epf_ops - set of function pointers for performing EPF operations
59 * @bind: ops to perform when a EPC device has been bound to EPF device
60 * @unbind: ops to perform when a binding has been lost between a EPC device
61 * and EPF device
256ae475 62 * @add_cfs: ops to initialize function specific configfs attributes
5e8cb403
KVA
63 */
64struct pci_epf_ops {
65 int (*bind)(struct pci_epf *epf);
66 void (*unbind)(struct pci_epf *epf);
256ae475
KVA
67 struct config_group *(*add_cfs)(struct pci_epf *epf,
68 struct config_group *group);
5e8cb403
KVA
69};
70
838125b0 71/**
2db6b72c 72 * struct pci_epc_event_ops - Callbacks for capturing the EPC events
4edd7dc8 73 * @epc_init: Callback for the EPC initialization complete event
473b2cf9 74 * @epc_deinit: Callback for the EPC deinitialization event
f5edd871 75 * @link_up: Callback for the EPC link up event
a1f6c3d7 76 * @link_down: Callback for the EPC link down event
f58838d7 77 * @bus_master_enable: Callback for the EPC Bus Master Enable event
838125b0
MS
78 */
79struct pci_epc_event_ops {
4edd7dc8 80 int (*epc_init)(struct pci_epf *epf);
473b2cf9 81 void (*epc_deinit)(struct pci_epf *epf);
f5edd871 82 int (*link_up)(struct pci_epf *epf);
a1f6c3d7 83 int (*link_down)(struct pci_epf *epf);
f58838d7 84 int (*bus_master_enable)(struct pci_epf *epf);
838125b0
MS
85};
86
5e8cb403
KVA
87/**
88 * struct pci_epf_driver - represents the PCI EPF driver
89 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
90 * @remove: ops to perform when the binding between the EPF device and EPF
91 * driver is broken
92 * @driver: PCI EPF driver
93 * @ops: set of function pointers for performing EPF operations
94 * @owner: the owner of the module that registers the PCI EPF driver
ef1433f7 95 * @epf_group: list of configfs group corresponding to the PCI EPF driver
5e8cb403
KVA
96 * @id_table: identifies EPF devices for probing
97 */
98struct pci_epf_driver {
081c715d
MS
99 int (*probe)(struct pci_epf *epf,
100 const struct pci_epf_device_id *id);
dde0a318 101 void (*remove)(struct pci_epf *epf);
5e8cb403
KVA
102
103 struct device_driver driver;
86362293 104 const struct pci_epf_ops *ops;
5e8cb403 105 struct module *owner;
ef1433f7 106 struct list_head epf_group;
5e8cb403
KVA
107 const struct pci_epf_device_id *id_table;
108};
109
d69d8048 110#define to_pci_epf_driver(drv) container_of_const((drv), struct pci_epf_driver, driver)
5e8cb403
KVA
111
112/**
113 * struct pci_epf_bar - represents the BAR of EPF device
114 * @phys_addr: physical address that should be mapped to the BAR
6f5e193b 115 * @addr: virtual address corresponding to the @phys_addr
5e8cb403 116 * @size: the size of the address space present in BAR
347269c1
KW
117 * @barno: BAR number
118 * @flags: flags that are set for the BAR
5e8cb403
KVA
119 */
120struct pci_epf_bar {
121 dma_addr_t phys_addr;
6f5e193b 122 void *addr;
5e8cb403 123 size_t size;
bc4a4897
NC
124 enum pci_barno barno;
125 int flags;
5e8cb403
KVA
126};
127
128/**
129 * struct pci_epf - represents the PCI EPF device
130 * @dev: the PCI EPF device
131 * @name: the name of the PCI EPF device
132 * @header: represents standard configuration header
133 * @bar: represents the BAR of EPF device
134 * @msi_interrupts: number of MSI interrupts required by this function
347269c1 135 * @msix_interrupts: number of MSI-X interrupts required by this function
1cf362e9
KVA
136 * @func_no: unique (physical) function number within this endpoint device
137 * @vfunc_no: unique virtual function number within a physical function
5e8cb403 138 * @epc: the EPC device to which this EPF device is bound
1cf362e9 139 * @epf_pf: the physical EPF device to which this virtual EPF device is bound
5e8cb403 140 * @driver: the EPF driver to which this EPF device is bound
081c715d 141 * @id: Pointer to the EPF device ID
5e8cb403 142 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
07301c98 143 * @lock: mutex to protect pci_epf_ops
63840ff5
KVA
144 * @sec_epc: the secondary EPC device to which this EPF device is bound
145 * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
146 * EPC device
147 * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
148 * @sec_epc_func_no: unique (physical) function number within the secondary EPC
38ad827e 149 * @group: configfs group associated with the EPF device
1cf362e9
KVA
150 * @is_bound: indicates if bind notification to function driver has been invoked
151 * @is_vf: true - virtual function, false - physical function
152 * @vfunction_num_map: bitmap to manage virtual function number
153 * @pci_vepf: list of virtual endpoint functions associated with this function
838125b0 154 * @event_ops: Callbacks for capturing the EPC events
5e8cb403
KVA
155 */
156struct pci_epf {
157 struct device dev;
158 const char *name;
159 struct pci_epf_header *header;
160 struct pci_epf_bar bar[6];
161 u8 msi_interrupts;
8963106e 162 u16 msix_interrupts;
5e8cb403 163 u8 func_no;
1cf362e9 164 u8 vfunc_no;
5e8cb403
KVA
165
166 struct pci_epc *epc;
1cf362e9 167 struct pci_epf *epf_pf;
5e8cb403 168 struct pci_epf_driver *driver;
081c715d 169 const struct pci_epf_device_id *id;
5e8cb403 170 struct list_head list;
07301c98
KVA
171 /* mutex to protect against concurrent access of pci_epf_ops */
172 struct mutex lock;
63840ff5
KVA
173
174 /* Below members are to attach secondary EPC to an endpoint function */
175 struct pci_epc *sec_epc;
176 struct list_head sec_epc_list;
177 struct pci_epf_bar sec_epc_bar[6];
178 u8 sec_epc_func_no;
38ad827e 179 struct config_group *group;
1cf362e9
KVA
180 unsigned int is_bound;
181 unsigned int is_vf;
182 unsigned long vfunction_num_map;
183 struct list_head pci_vepf;
838125b0 184 const struct pci_epc_event_ops *event_ops;
5e8cb403
KVA
185};
186
6f5e193b
KVA
187/**
188 * struct pci_epf_msix_tbl - represents the MSIX table entry structure
189 * @msg_addr: Writes to this address will trigger MSIX interrupt in host
190 * @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
191 * @vector_ctrl: Identifies if the function is prohibited from sending a message
192 * using this MSIX table entry
193 */
194struct pci_epf_msix_tbl {
195 u64 msg_addr;
196 u32 msg_data;
197 u32 vector_ctrl;
198};
199
5e8cb403
KVA
200#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
201
202#define pci_epf_register_driver(driver) \
203 __pci_epf_register_driver((driver), THIS_MODULE)
204
205static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
206{
207 dev_set_drvdata(&epf->dev, data);
208}
209
210static inline void *epf_get_drvdata(struct pci_epf *epf)
211{
212 return dev_get_drvdata(&epf->dev);
213}
214
215struct pci_epf *pci_epf_create(const char *name);
216void pci_epf_destroy(struct pci_epf *epf);
217int __pci_epf_register_driver(struct pci_epf_driver *driver,
218 struct module *owner);
219void pci_epf_unregister_driver(struct pci_epf_driver *driver);
2a9a8016 220void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
e891becd
NC
221 const struct pci_epc_features *epc_features,
222 enum pci_epc_interface_type type);
63840ff5
KVA
223void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
224 enum pci_epc_interface_type type);
5e8cb403
KVA
225int pci_epf_bind(struct pci_epf *epf);
226void pci_epf_unbind(struct pci_epf *epf);
1cf362e9
KVA
227int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
228void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
5e8cb403 229#endif /* __LINUX_PCI_EPF_H */