fm10k_mbx.h 11 KB

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