fm10k_mbx.h 12 KB

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