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