vfdi.h 9.3 KB

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