fm10k_mbx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #ifndef _FM10K_MBX_H_
  4. #define _FM10K_MBX_H_
  5. /* forward declaration */
  6. struct fm10k_mbx_info;
  7. #include "fm10k_type.h"
  8. #include "fm10k_tlv.h"
  9. /* PF Mailbox Registers */
  10. #define FM10K_MBMEM(_n) ((_n) + 0x18000)
  11. #define FM10K_MBMEM_VF(_n, _m) (((_n) * 0x10) + (_m) + 0x18000)
  12. #define FM10K_MBMEM_SM(_n) ((_n) + 0x18400)
  13. #define FM10K_MBMEM_PF(_n) ((_n) + 0x18600)
  14. /* XOR provides means of switching from Tx to Rx FIFO */
  15. #define FM10K_MBMEM_PF_XOR (FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))
  16. #define FM10K_MBX(_n) ((_n) + 0x18800)
  17. #define FM10K_MBX_REQ 0x00000002
  18. #define FM10K_MBX_ACK 0x00000004
  19. #define FM10K_MBX_REQ_INTERRUPT 0x00000008
  20. #define FM10K_MBX_ACK_INTERRUPT 0x00000010
  21. #define FM10K_MBX_INTERRUPT_ENABLE 0x00000020
  22. #define FM10K_MBX_INTERRUPT_DISABLE 0x00000040
  23. #define FM10K_MBX_GLOBAL_REQ_INTERRUPT 0x00000200
  24. #define FM10K_MBX_GLOBAL_ACK_INTERRUPT 0x00000400
  25. #define FM10K_MBICR(_n) ((_n) + 0x18840)
  26. #define FM10K_GMBX 0x18842
  27. /* VF Mailbox Registers */
  28. #define FM10K_VFMBX 0x00010
  29. #define FM10K_VFMBMEM(_n) ((_n) + 0x00020)
  30. #define FM10K_VFMBMEM_LEN 16
  31. #define FM10K_VFMBMEM_VF_XOR (FM10K_VFMBMEM_LEN / 2)
  32. /* Delays/timeouts */
  33. #define FM10K_MBX_DISCONNECT_TIMEOUT 500
  34. #define FM10K_MBX_POLL_DELAY 19
  35. #define FM10K_MBX_INT_DELAY 20
  36. /* PF/VF Mailbox state machine
  37. *
  38. * +----------+ connect() +----------+
  39. * | CLOSED | --------------> | CONNECT |
  40. * +----------+ +----------+
  41. * ^ ^ |
  42. * | rcv: rcv: | | rcv:
  43. * | Connect Disconnect | | Connect
  44. * | Disconnect Error | | Data
  45. * | | |
  46. * | | V
  47. * +----------+ disconnect() +----------+
  48. * |DISCONNECT| <-------------- | OPEN |
  49. * +----------+ +----------+
  50. *
  51. * The diagram above describes the PF/VF mailbox state machine. There
  52. * are four main states to this machine.
  53. * Closed: This state represents a mailbox that is in a standby state
  54. * with interrupts disabled. In this state the mailbox should not
  55. * read the mailbox or write any data. The only means of exiting
  56. * this state is for the system to make the connect() call for the
  57. * mailbox, it will then transition to the connect state.
  58. * Connect: In this state the mailbox is seeking a connection. It will
  59. * post a connect message with no specified destination and will
  60. * wait for a reply from the other side of the mailbox. This state
  61. * is exited when either a connect with the local mailbox as the
  62. * destination is received or when a data message is received with
  63. * a valid sequence number.
  64. * Open: In this state the mailbox is able to transfer data between the local
  65. * entity and the remote. It will fall back to connect in the event of
  66. * receiving either an error message, or a disconnect message. It will
  67. * transition to disconnect on a call to disconnect();
  68. * Disconnect: In this state the mailbox is attempting to gracefully terminate
  69. * the connection. It will do so at the first point where it knows
  70. * that the remote endpoint is either done sending, or when the
  71. * remote endpoint has fallen back into connect.
  72. */
  73. enum fm10k_mbx_state {
  74. FM10K_STATE_CLOSED,
  75. FM10K_STATE_CONNECT,
  76. FM10K_STATE_OPEN,
  77. FM10K_STATE_DISCONNECT,
  78. };
  79. /* PF/VF Mailbox header format
  80. * 3 2 1 0
  81. * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  82. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  83. * | Size/Err_no/CRC | Rsvd0 | Head | Tail | Type |
  84. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  85. *
  86. * The layout above describes the format for the header used in the PF/VF
  87. * mailbox. The header is broken out into the following fields:
  88. * Type: There are 4 supported message types
  89. * 0x8: Data header - used to transport message data
  90. * 0xC: Connect header - used to establish connection
  91. * 0xD: Disconnect header - used to tear down a connection
  92. * 0xE: Error header - used to address message exceptions
  93. * Tail: Tail index for local FIFO
  94. * Tail index actually consists of two parts. The MSB of
  95. * the head is a loop tracker, it is 0 on an even numbered
  96. * loop through the FIFO, and 1 on the odd numbered loops.
  97. * To get the actual mailbox offset based on the tail it
  98. * is necessary to add bit 3 to bit 0 and clear bit 3. This
  99. * gives us a valid range of 0x1 - 0xE.
  100. * Head: Head index for remote FIFO
  101. * Head index follows the same format as the tail index.
  102. * Rsvd0: Reserved 0 portion of the mailbox header
  103. * CRC: Running CRC for all data since connect plus current message header
  104. * Size: Maximum message size - Applies only to connect headers
  105. * The maximum message size is provided during connect to avoid
  106. * jamming the mailbox with messages that do not fit.
  107. * Err_no: Error number - Applies only to error headers
  108. * The error number provides an indication of the type of error
  109. * experienced.
  110. */
  111. /* macros for retrieving and setting header values */
  112. #define FM10K_MSG_HDR_MASK(name) \
  113. ((0x1u << FM10K_MSG_##name##_SIZE) - 1)
  114. #define FM10K_MSG_HDR_FIELD_SET(value, name) \
  115. (((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)
  116. #define FM10K_MSG_HDR_FIELD_GET(value, name) \
  117. ((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))
  118. /* offsets shared between all headers */
  119. #define FM10K_MSG_TYPE_SHIFT 0
  120. #define FM10K_MSG_TYPE_SIZE 4
  121. #define FM10K_MSG_TAIL_SHIFT 4
  122. #define FM10K_MSG_TAIL_SIZE 4
  123. #define FM10K_MSG_HEAD_SHIFT 8
  124. #define FM10K_MSG_HEAD_SIZE 4
  125. #define FM10K_MSG_RSVD0_SHIFT 12
  126. #define FM10K_MSG_RSVD0_SIZE 4
  127. /* offsets for data/disconnect headers */
  128. #define FM10K_MSG_CRC_SHIFT 16
  129. #define FM10K_MSG_CRC_SIZE 16
  130. /* offsets for connect headers */
  131. #define FM10K_MSG_CONNECT_SIZE_SHIFT 16
  132. #define FM10K_MSG_CONNECT_SIZE_SIZE 16
  133. /* offsets for error headers */
  134. #define FM10K_MSG_ERR_NO_SHIFT 16
  135. #define FM10K_MSG_ERR_NO_SIZE 16
  136. enum fm10k_msg_type {
  137. FM10K_MSG_DATA = 0x8,
  138. FM10K_MSG_CONNECT = 0xC,
  139. FM10K_MSG_DISCONNECT = 0xD,
  140. FM10K_MSG_ERROR = 0xE,
  141. };
  142. /* HNI/SM Mailbox FIFO format
  143. * 3 2 1 0
  144. * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  145. * +-------+-----------------------+-------+-----------------------+
  146. * | Error | Remote Head |Version| Local Tail |
  147. * +-------+-----------------------+-------+-----------------------+
  148. * | |
  149. * . Local FIFO Data .
  150. * . .
  151. * +-------+-----------------------+-------+-----------------------+
  152. *
  153. * The layout above describes the format for the FIFOs used by the host
  154. * network interface and the switch manager to communicate messages back
  155. * and forth. Both the HNI and the switch maintain one such FIFO. The
  156. * layout in memory has the switch manager FIFO followed immediately by
  157. * the HNI FIFO. For this reason I am using just the pointer to the
  158. * HNI FIFO in the mailbox ops as the offset between the two is fixed.
  159. *
  160. * The header for the FIFO is broken out into the following fields:
  161. * Local Tail: Offset into FIFO region for next DWORD to write.
  162. * Version: Version info for mailbox, only values of 0/1 are supported.
  163. * Remote Head: Offset into remote FIFO to indicate how much we have read.
  164. * Error: Error indication, values TBD.
  165. */
  166. /* version number for switch manager mailboxes */
  167. #define FM10K_SM_MBX_VERSION 1
  168. #define FM10K_SM_MBX_FIFO_LEN (FM10K_MBMEM_PF_XOR - 1)
  169. /* offsets shared between all SM FIFO headers */
  170. #define FM10K_MSG_SM_TAIL_SHIFT 0
  171. #define FM10K_MSG_SM_TAIL_SIZE 12
  172. #define FM10K_MSG_SM_VER_SHIFT 12
  173. #define FM10K_MSG_SM_VER_SIZE 4
  174. #define FM10K_MSG_SM_HEAD_SHIFT 16
  175. #define FM10K_MSG_SM_HEAD_SIZE 12
  176. #define FM10K_MSG_SM_ERR_SHIFT 28
  177. #define FM10K_MSG_SM_ERR_SIZE 4
  178. /* All error messages returned by mailbox functions
  179. * The value -511 is 0xFE01 in hex. The idea is to order the errors
  180. * from 0xFE01 - 0xFEFF so error codes are easily visible in the mailbox
  181. * messages. This also helps to avoid error number collisions as Linux
  182. * doesn't appear to use error numbers 256 - 511.
  183. */
  184. #define FM10K_MBX_ERR(_n) ((_n) - 512)
  185. #define FM10K_MBX_ERR_NO_MBX FM10K_MBX_ERR(0x01)
  186. #define FM10K_MBX_ERR_NO_SPACE FM10K_MBX_ERR(0x03)
  187. #define FM10K_MBX_ERR_TAIL FM10K_MBX_ERR(0x05)
  188. #define FM10K_MBX_ERR_HEAD FM10K_MBX_ERR(0x06)
  189. #define FM10K_MBX_ERR_SRC FM10K_MBX_ERR(0x08)
  190. #define FM10K_MBX_ERR_TYPE FM10K_MBX_ERR(0x09)
  191. #define FM10K_MBX_ERR_SIZE FM10K_MBX_ERR(0x0B)
  192. #define FM10K_MBX_ERR_BUSY FM10K_MBX_ERR(0x0C)
  193. #define FM10K_MBX_ERR_RSVD0 FM10K_MBX_ERR(0x0E)
  194. #define FM10K_MBX_ERR_CRC FM10K_MBX_ERR(0x0F)
  195. #define FM10K_MBX_CRC_SEED 0xFFFF
  196. struct fm10k_mbx_ops {
  197. s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);
  198. void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);
  199. bool (*rx_ready)(struct fm10k_mbx_info *);
  200. bool (*tx_ready)(struct fm10k_mbx_info *, u16);
  201. bool (*tx_complete)(struct fm10k_mbx_info *);
  202. s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,
  203. const u32 *);
  204. s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);
  205. s32 (*register_handlers)(struct fm10k_mbx_info *,
  206. const struct fm10k_msg_data *);
  207. };
  208. struct fm10k_mbx_fifo {
  209. u32 *buffer;
  210. u16 head;
  211. u16 tail;
  212. u16 size;
  213. };
  214. /* size of buffer to be stored in mailbox for FIFOs */
  215. #define FM10K_MBX_TX_BUFFER_SIZE 512
  216. #define FM10K_MBX_RX_BUFFER_SIZE 128
  217. #define FM10K_MBX_BUFFER_SIZE \
  218. (FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)
  219. /* minimum and maximum message size in dwords */
  220. #define FM10K_MBX_MSG_MAX_SIZE \
  221. ((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))
  222. #define FM10K_VFMBX_MSG_MTU ((FM10K_VFMBMEM_LEN / 2) - 1)
  223. #define FM10K_MBX_INIT_TIMEOUT 2000 /* number of retries on mailbox */
  224. #define FM10K_MBX_INIT_DELAY 500 /* microseconds between retries */
  225. struct fm10k_mbx_info {
  226. /* function pointers for mailbox operations */
  227. struct fm10k_mbx_ops ops;
  228. const struct fm10k_msg_data *msg_data;
  229. /* message FIFOs */
  230. struct fm10k_mbx_fifo rx;
  231. struct fm10k_mbx_fifo tx;
  232. /* delay for handling timeouts */
  233. u32 timeout;
  234. u32 udelay;
  235. /* mailbox state info */
  236. u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;
  237. u16 max_size, mbmem_len;
  238. u16 tail, tail_len, pulled;
  239. u16 head, head_len, pushed;
  240. u16 local, remote;
  241. enum fm10k_mbx_state state;
  242. /* result of last mailbox test */
  243. s32 test_result;
  244. /* statistics */
  245. u64 tx_busy;
  246. u64 tx_dropped;
  247. u64 tx_messages;
  248. u64 tx_dwords;
  249. u64 tx_mbmem_pulled;
  250. u64 rx_messages;
  251. u64 rx_dwords;
  252. u64 rx_mbmem_pushed;
  253. u64 rx_parse_err;
  254. /* Buffer to store messages */
  255. u32 buffer[FM10K_MBX_BUFFER_SIZE];
  256. };
  257. s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
  258. const struct fm10k_msg_data *, u8);
  259. s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
  260. const struct fm10k_msg_data *);
  261. #endif /* _FM10K_MBX_H_ */