fm10k_mbx.h 12 KB

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