vfdi.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2010-2012 Solarflare Communications Inc.
  5. */
  6. #ifndef _VFDI_H
  7. #define _VFDI_H
  8. /**
  9. * DOC: Virtual Function Driver Interface
  10. *
  11. * This file contains software structures used to form a two way
  12. * communication channel between the VF driver and the PF driver,
  13. * named Virtual Function Driver Interface (VFDI).
  14. *
  15. * For the purposes of VFDI, a page is a memory region with size and
  16. * alignment of 4K. All addresses are DMA addresses to be used within
  17. * the domain of the relevant VF.
  18. *
  19. * The only hardware-defined channels for a VF driver to communicate
  20. * with the PF driver are the event mailboxes (%FR_CZ_USR_EV
  21. * registers). Writing to these registers generates an event with
  22. * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox
  23. * and USER_EV_REG_VALUE set to the value written. The PF driver may
  24. * direct or disable delivery of these events by setting
  25. * %FR_CZ_USR_EV_CFG.
  26. *
  27. * The PF driver can send arbitrary events to arbitrary event queues.
  28. * However, for consistency, VFDI events from the PF are defined to
  29. * follow the same form and be sent to the first event queue assigned
  30. * to the VF while that queue is enabled by the VF driver.
  31. *
  32. * The general form of the variable bits of VFDI events is:
  33. *
  34. * 0 16 24 31
  35. * | DATA | TYPE | SEQ |
  36. *
  37. * SEQ is a sequence number which should be incremented by 1 (modulo
  38. * 256) for each event. The sequence numbers used in each direction
  39. * are independent.
  40. *
  41. * The VF submits requests of type &struct vfdi_req by sending the
  42. * address of the request (ADDR) in a series of 4 events:
  43. *
  44. * 0 16 24 31
  45. * | ADDR[0:15] | VFDI_EV_TYPE_REQ_WORD0 | SEQ |
  46. * | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |
  47. * | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |
  48. * | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |
  49. *
  50. * The address must be page-aligned. After receiving such a valid
  51. * series of events, the PF driver will attempt to read the request
  52. * and write a response to the same address. In case of an invalid
  53. * sequence of events or a DMA error, there will be no response.
  54. *
  55. * The VF driver may request that the PF driver writes status
  56. * information into its domain asynchronously. After writing the
  57. * status, the PF driver will send an event of the form:
  58. *
  59. * 0 16 24 31
  60. * | reserved | VFDI_EV_TYPE_STATUS | SEQ |
  61. *
  62. * In case the VF must be reset for any reason, the PF driver will
  63. * send an event of the form:
  64. *
  65. * 0 16 24 31
  66. * | reserved | VFDI_EV_TYPE_RESET | SEQ |
  67. *
  68. * It is then the responsibility of the VF driver to request
  69. * reinitialisation of its queues.
  70. */
  71. #define VFDI_EV_SEQ_LBN 24
  72. #define VFDI_EV_SEQ_WIDTH 8
  73. #define VFDI_EV_TYPE_LBN 16
  74. #define VFDI_EV_TYPE_WIDTH 8
  75. #define VFDI_EV_TYPE_REQ_WORD0 0
  76. #define VFDI_EV_TYPE_REQ_WORD1 1
  77. #define VFDI_EV_TYPE_REQ_WORD2 2
  78. #define VFDI_EV_TYPE_REQ_WORD3 3
  79. #define VFDI_EV_TYPE_STATUS 4
  80. #define VFDI_EV_TYPE_RESET 5
  81. #define VFDI_EV_DATA_LBN 0
  82. #define VFDI_EV_DATA_WIDTH 16
  83. struct vfdi_endpoint {
  84. u8 mac_addr[ETH_ALEN];
  85. __be16 tci;
  86. };
  87. /**
  88. * enum vfdi_op - VFDI operation enumeration
  89. * @VFDI_OP_RESPONSE: Indicates a response to the request.
  90. * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.
  91. * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.
  92. * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.
  93. * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then
  94. * finalize the SRAM entries.
  95. * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ.
  96. * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.
  97. * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates
  98. * from PF and write the initial status.
  99. * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status
  100. * updates from PF.
  101. */
  102. enum vfdi_op {
  103. VFDI_OP_RESPONSE = 0,
  104. VFDI_OP_INIT_EVQ = 1,
  105. VFDI_OP_INIT_RXQ = 2,
  106. VFDI_OP_INIT_TXQ = 3,
  107. VFDI_OP_FINI_ALL_QUEUES = 4,
  108. VFDI_OP_INSERT_FILTER = 5,
  109. VFDI_OP_REMOVE_ALL_FILTERS = 6,
  110. VFDI_OP_SET_STATUS_PAGE = 7,
  111. VFDI_OP_CLEAR_STATUS_PAGE = 8,
  112. VFDI_OP_LIMIT,
  113. };
  114. /* Response codes for VFDI operations. Other values may be used in future. */
  115. #define VFDI_RC_SUCCESS 0
  116. #define VFDI_RC_ENOMEM (-12)
  117. #define VFDI_RC_EINVAL (-22)
  118. #define VFDI_RC_EOPNOTSUPP (-95)
  119. #define VFDI_RC_ETIMEDOUT (-110)
  120. /**
  121. * struct vfdi_req - Request from VF driver to PF driver
  122. * @op: Operation code or response indicator, taken from &enum vfdi_op.
  123. * @rc: Response code. Set to 0 on success or a negative error code on failure.
  124. * @u.init_evq.index: Index of event queue to create.
  125. * @u.init_evq.buf_count: Number of 4k buffers backing event queue.
  126. * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA
  127. * address of each page backing the event queue.
  128. * @u.init_rxq.index: Index of receive queue to create.
  129. * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.
  130. * @u.init_rxq.evq: Instance of event queue to target receive events at.
  131. * @u.init_rxq.label: Label used in receive events.
  132. * @u.init_rxq.flags: Unused.
  133. * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA
  134. * address of each page backing the receive queue.
  135. * @u.init_txq.index: Index of transmit queue to create.
  136. * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.
  137. * @u.init_txq.evq: Instance of event queue to target transmit completion
  138. * events at.
  139. * @u.init_txq.label: Label used in transmit completion events.
  140. * @u.init_txq.flags: Checksum offload flags.
  141. * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA
  142. * address of each page backing the transmit queue.
  143. * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting
  144. * all traffic at this receive queue.
  145. * @u.mac_filter.flags: MAC filter flags.
  146. * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.
  147. * This address must be page-aligned and the PF may write up to a
  148. * whole page (allowing for extension of the structure).
  149. * @u.set_status_page.peer_page_count: Number of additional pages the VF
  150. * has provided into which peer addresses may be DMAd.
  151. * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.
  152. * If the number of peers exceeds 256, then the VF must provide
  153. * additional pages in this array. The PF will then DMA up to
  154. * 512 vfdi_endpoint structures into each page. These addresses
  155. * must be page-aligned.
  156. */
  157. struct vfdi_req {
  158. u32 op;
  159. u32 reserved1;
  160. s32 rc;
  161. u32 reserved2;
  162. union {
  163. struct {
  164. u32 index;
  165. u32 buf_count;
  166. u64 addr[];
  167. } init_evq;
  168. struct {
  169. u32 index;
  170. u32 buf_count;
  171. u32 evq;
  172. u32 label;
  173. u32 flags;
  174. #define VFDI_RXQ_FLAG_SCATTER_EN 1
  175. u32 reserved;
  176. u64 addr[];
  177. } init_rxq;
  178. struct {
  179. u32 index;
  180. u32 buf_count;
  181. u32 evq;
  182. u32 label;
  183. u32 flags;
  184. #define VFDI_TXQ_FLAG_IP_CSUM_DIS 1
  185. #define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2
  186. u32 reserved;
  187. u64 addr[];
  188. } init_txq;
  189. struct {
  190. u32 rxq;
  191. u32 flags;
  192. #define VFDI_MAC_FILTER_FLAG_RSS 1
  193. #define VFDI_MAC_FILTER_FLAG_SCATTER 2
  194. } mac_filter;
  195. struct {
  196. u64 dma_addr;
  197. u64 peer_page_count;
  198. u64 peer_page_addr[];
  199. } set_status_page;
  200. } u;
  201. };
  202. /**
  203. * struct vfdi_status - Status provided by PF driver to VF driver
  204. * @generation_start: A generation count DMA'd to VF *before* the
  205. * rest of the structure.
  206. * @generation_end: A generation count DMA'd to VF *after* the
  207. * rest of the structure.
  208. * @version: Version of this structure; currently set to 1. Later
  209. * versions must either be layout-compatible or only be sent to VFs
  210. * that specifically request them.
  211. * @length: Total length of this structure including embedded tables
  212. * @vi_scale: log2 the number of VIs available on this VF. This quantity
  213. * is used by the hardware for register decoding.
  214. * @max_tx_channels: The maximum number of transmit queues the VF can use.
  215. * @rss_rxq_count: The number of receive queues present in the shared RSS
  216. * indirection table.
  217. * @peer_count: Total number of peers in the complete peer list. If larger
  218. * than ARRAY_SIZE(%peers), then the VF must provide sufficient
  219. * additional pages each of which is filled with vfdi_endpoint structures.
  220. * @local: The MAC address and outer VLAN tag of *this* VF
  221. * @peers: Table of peer addresses. The @tci fields in these structures
  222. * are currently unused and must be ignored. Additional peers are
  223. * written into any additional pages provided by the VF.
  224. * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)
  225. * for interrupt moderation timers, in nanoseconds. This member is only
  226. * present if @length is sufficiently large.
  227. */
  228. struct vfdi_status {
  229. u32 generation_start;
  230. u32 generation_end;
  231. u32 version;
  232. u32 length;
  233. u8 vi_scale;
  234. u8 max_tx_channels;
  235. u8 rss_rxq_count;
  236. u8 reserved1;
  237. u16 peer_count;
  238. u16 reserved2;
  239. struct vfdi_endpoint local;
  240. struct vfdi_endpoint peers[256];
  241. /* Members below here extend version 1 of this structure */
  242. u32 timer_quantum_ns;
  243. };
  244. #endif