fm10k_tlv.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_TLV_H_
  21. #define _FM10K_TLV_H_
  22. /* forward declaration */
  23. struct fm10k_msg_data;
  24. #include "fm10k_type.h"
  25. /* Message / Argument header format
  26. * 3 2 1 0
  27. * 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
  28. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  29. * | Length | Flags | Type / ID |
  30. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  31. *
  32. * The message header format described here is used for messages that are
  33. * passed between the PF and the VF. To allow for messages larger then
  34. * mailbox size we will provide a message with the above header and it
  35. * will be segmented and transported to the mailbox to the other side where
  36. * it is reassembled. It contains the following fields:
  37. * Len: Length of the message in bytes excluding the message header
  38. * Flags: TBD
  39. * Rule: These will be the message/argument types we pass
  40. */
  41. /* message data header */
  42. #define FM10K_TLV_ID_SHIFT 0
  43. #define FM10K_TLV_ID_SIZE 16
  44. #define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1)
  45. #define FM10K_TLV_FLAGS_SHIFT 16
  46. #define FM10K_TLV_FLAGS_MSG 0x1
  47. #define FM10K_TLV_FLAGS_SIZE 4
  48. #define FM10K_TLV_LEN_SHIFT 20
  49. #define FM10K_TLV_LEN_SIZE 12
  50. #define FM10K_TLV_HDR_LEN 4ul
  51. #define FM10K_TLV_LEN_ALIGN_MASK \
  52. ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT)
  53. #define FM10K_TLV_LEN_ALIGN(tlv) \
  54. (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK)
  55. #define FM10K_TLV_DWORD_LEN(tlv) \
  56. ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1)
  57. #define FM10K_TLV_RESULTS_MAX 32
  58. enum fm10k_tlv_type {
  59. FM10K_TLV_NULL_STRING,
  60. FM10K_TLV_MAC_ADDR,
  61. FM10K_TLV_BOOL,
  62. FM10K_TLV_UNSIGNED,
  63. FM10K_TLV_SIGNED,
  64. FM10K_TLV_LE_STRUCT,
  65. FM10K_TLV_NESTED,
  66. FM10K_TLV_MAX_TYPE
  67. };
  68. #define FM10K_TLV_ERROR (~0u)
  69. struct fm10k_tlv_attr {
  70. unsigned int id;
  71. enum fm10k_tlv_type type;
  72. u16 len;
  73. };
  74. #define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len }
  75. #define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 }
  76. #define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 }
  77. #define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 }
  78. #define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 }
  79. #define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 }
  80. #define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 }
  81. #define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 }
  82. #define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 }
  83. #define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 }
  84. #define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 }
  85. #define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len }
  86. #define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED }
  87. #define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR }
  88. struct fm10k_msg_data {
  89. unsigned int id;
  90. const struct fm10k_tlv_attr *attr;
  91. s32 (*func)(struct fm10k_hw *, u32 **,
  92. struct fm10k_mbx_info *);
  93. };
  94. #define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func }
  95. s32 fm10k_tlv_msg_init(u32 *, u16);
  96. s32 fm10k_tlv_attr_put_null_string(u32 *, u16, const unsigned char *);
  97. s32 fm10k_tlv_attr_get_null_string(u32 *, unsigned char *);
  98. s32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16);
  99. s32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *);
  100. s32 fm10k_tlv_attr_put_bool(u32 *, u16);
  101. s32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32);
  102. #define fm10k_tlv_attr_put_u8(msg, attr_id, val) \
  103. fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
  104. #define fm10k_tlv_attr_put_u16(msg, attr_id, val) \
  105. fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
  106. #define fm10k_tlv_attr_put_u32(msg, attr_id, val) \
  107. fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
  108. #define fm10k_tlv_attr_put_u64(msg, attr_id, val) \
  109. fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
  110. #define fm10k_tlv_attr_put_s8(msg, attr_id, val) \
  111. fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
  112. #define fm10k_tlv_attr_put_s16(msg, attr_id, val) \
  113. fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
  114. #define fm10k_tlv_attr_put_s32(msg, attr_id, val) \
  115. fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
  116. #define fm10k_tlv_attr_put_s64(msg, attr_id, val) \
  117. fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
  118. s32 fm10k_tlv_attr_get_value(u32 *, void *, u32);
  119. #define fm10k_tlv_attr_get_u8(attr, ptr) \
  120. fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8))
  121. #define fm10k_tlv_attr_get_u16(attr, ptr) \
  122. fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16))
  123. #define fm10k_tlv_attr_get_u32(attr, ptr) \
  124. fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32))
  125. #define fm10k_tlv_attr_get_u64(attr, ptr) \
  126. fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64))
  127. #define fm10k_tlv_attr_get_s8(attr, ptr) \
  128. fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8))
  129. #define fm10k_tlv_attr_get_s16(attr, ptr) \
  130. fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16))
  131. #define fm10k_tlv_attr_get_s32(attr, ptr) \
  132. fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32))
  133. #define fm10k_tlv_attr_get_s64(attr, ptr) \
  134. fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64))
  135. s32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32);
  136. s32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32);
  137. u32 *fm10k_tlv_attr_nest_start(u32 *, u16);
  138. s32 fm10k_tlv_attr_nest_stop(u32 *);
  139. s32 fm10k_tlv_attr_parse(u32 *, u32 **, const struct fm10k_tlv_attr *);
  140. s32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *,
  141. const struct fm10k_msg_data *);
  142. s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
  143. struct fm10k_mbx_info *);
  144. #define FM10K_TLV_MSG_ID_TEST 0
  145. enum fm10k_tlv_test_attr_id {
  146. FM10K_TEST_MSG_UNSET,
  147. FM10K_TEST_MSG_STRING,
  148. FM10K_TEST_MSG_MAC_ADDR,
  149. FM10K_TEST_MSG_U8,
  150. FM10K_TEST_MSG_U16,
  151. FM10K_TEST_MSG_U32,
  152. FM10K_TEST_MSG_U64,
  153. FM10K_TEST_MSG_S8,
  154. FM10K_TEST_MSG_S16,
  155. FM10K_TEST_MSG_S32,
  156. FM10K_TEST_MSG_S64,
  157. FM10K_TEST_MSG_LE_STRUCT,
  158. FM10K_TEST_MSG_NESTED,
  159. FM10K_TEST_MSG_RESULT,
  160. FM10K_TEST_MSG_MAX
  161. };
  162. extern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[];
  163. void fm10k_tlv_msg_test_create(u32 *, u32);
  164. s32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *);
  165. #define FM10K_TLV_MSG_TEST_HANDLER(func) \
  166. FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func)
  167. #define FM10K_TLV_MSG_ERROR_HANDLER(func) \
  168. FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func)
  169. #endif /* _FM10K_MSG_H_ */