pci-epf.h 7.1 KB

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