18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright(c) 2013 - 2019 Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _FM10K_TLV_H_ 58c2ecf20Sopenharmony_ci#define _FM10K_TLV_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* forward declaration */ 88c2ecf20Sopenharmony_cistruct fm10k_msg_data; 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include "fm10k_type.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Message / Argument header format 138c2ecf20Sopenharmony_ci * 3 2 1 0 148c2ecf20Sopenharmony_ci * 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 158c2ecf20Sopenharmony_ci * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 168c2ecf20Sopenharmony_ci * | Length | Flags | Type / ID | 178c2ecf20Sopenharmony_ci * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * The message header format described here is used for messages that are 208c2ecf20Sopenharmony_ci * passed between the PF and the VF. To allow for messages larger then 218c2ecf20Sopenharmony_ci * mailbox size we will provide a message with the above header and it 228c2ecf20Sopenharmony_ci * will be segmented and transported to the mailbox to the other side where 238c2ecf20Sopenharmony_ci * it is reassembled. It contains the following fields: 248c2ecf20Sopenharmony_ci * Length: Length of the message in bytes excluding the message header 258c2ecf20Sopenharmony_ci * Flags: TBD 268c2ecf20Sopenharmony_ci * Type/ID: These will be the message/argument types we pass 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci/* message data header */ 298c2ecf20Sopenharmony_ci#define FM10K_TLV_ID_SHIFT 0 308c2ecf20Sopenharmony_ci#define FM10K_TLV_ID_SIZE 16 318c2ecf20Sopenharmony_ci#define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1) 328c2ecf20Sopenharmony_ci#define FM10K_TLV_FLAGS_SHIFT 16 338c2ecf20Sopenharmony_ci#define FM10K_TLV_FLAGS_MSG 0x1 348c2ecf20Sopenharmony_ci#define FM10K_TLV_FLAGS_SIZE 4 358c2ecf20Sopenharmony_ci#define FM10K_TLV_LEN_SHIFT 20 368c2ecf20Sopenharmony_ci#define FM10K_TLV_LEN_SIZE 12 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define FM10K_TLV_HDR_LEN 4ul 398c2ecf20Sopenharmony_ci#define FM10K_TLV_LEN_ALIGN_MASK \ 408c2ecf20Sopenharmony_ci ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT) 418c2ecf20Sopenharmony_ci#define FM10K_TLV_LEN_ALIGN(tlv) \ 428c2ecf20Sopenharmony_ci (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK) 438c2ecf20Sopenharmony_ci#define FM10K_TLV_DWORD_LEN(tlv) \ 448c2ecf20Sopenharmony_ci ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define FM10K_TLV_RESULTS_MAX 32 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cienum fm10k_tlv_type { 498c2ecf20Sopenharmony_ci FM10K_TLV_NULL_STRING, 508c2ecf20Sopenharmony_ci FM10K_TLV_MAC_ADDR, 518c2ecf20Sopenharmony_ci FM10K_TLV_BOOL, 528c2ecf20Sopenharmony_ci FM10K_TLV_UNSIGNED, 538c2ecf20Sopenharmony_ci FM10K_TLV_SIGNED, 548c2ecf20Sopenharmony_ci FM10K_TLV_LE_STRUCT, 558c2ecf20Sopenharmony_ci FM10K_TLV_NESTED, 568c2ecf20Sopenharmony_ci FM10K_TLV_MAX_TYPE 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define FM10K_TLV_ERROR (~0u) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct fm10k_tlv_attr { 628c2ecf20Sopenharmony_ci unsigned int id; 638c2ecf20Sopenharmony_ci enum fm10k_tlv_type type; 648c2ecf20Sopenharmony_ci u16 len; 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len } 688c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 } 698c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 } 708c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 } 718c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 } 728c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 } 738c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 } 748c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 } 758c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 } 768c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 } 778c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 } 788c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len } 798c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED, 0 } 808c2ecf20Sopenharmony_ci#define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR, 0, 0 } 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistruct fm10k_msg_data { 838c2ecf20Sopenharmony_ci unsigned int id; 848c2ecf20Sopenharmony_ci const struct fm10k_tlv_attr *attr; 858c2ecf20Sopenharmony_ci s32 (*func)(struct fm10k_hw *, u32 **, 868c2ecf20Sopenharmony_ci struct fm10k_mbx_info *); 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func } 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cis32 fm10k_tlv_msg_init(u32 *, u16); 928c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16); 938c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *); 948c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_put_bool(u32 *, u16); 958c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32); 968c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_u8(msg, attr_id, val) \ 978c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 1) 988c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_u16(msg, attr_id, val) \ 998c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 2) 1008c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_u32(msg, attr_id, val) \ 1018c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 4) 1028c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_u64(msg, attr_id, val) \ 1038c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 8) 1048c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_s8(msg, attr_id, val) \ 1058c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 1) 1068c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_s16(msg, attr_id, val) \ 1078c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 2) 1088c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_s32(msg, attr_id, val) \ 1098c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 4) 1108c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_put_s64(msg, attr_id, val) \ 1118c2ecf20Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 8) 1128c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_get_value(u32 *, void *, u32); 1138c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_u8(attr, ptr) \ 1148c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8)) 1158c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_u16(attr, ptr) \ 1168c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16)) 1178c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_u32(attr, ptr) \ 1188c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32)) 1198c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_u64(attr, ptr) \ 1208c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64)) 1218c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_s8(attr, ptr) \ 1228c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8)) 1238c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_s16(attr, ptr) \ 1248c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16)) 1258c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_s32(attr, ptr) \ 1268c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32)) 1278c2ecf20Sopenharmony_ci#define fm10k_tlv_attr_get_s64(attr, ptr) \ 1288c2ecf20Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64)) 1298c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32); 1308c2ecf20Sopenharmony_cis32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32); 1318c2ecf20Sopenharmony_cis32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *, 1328c2ecf20Sopenharmony_ci const struct fm10k_msg_data *); 1338c2ecf20Sopenharmony_cis32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results, 1348c2ecf20Sopenharmony_ci struct fm10k_mbx_info *); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define FM10K_TLV_MSG_ID_TEST 0 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cienum fm10k_tlv_test_attr_id { 1398c2ecf20Sopenharmony_ci FM10K_TEST_MSG_UNSET, 1408c2ecf20Sopenharmony_ci FM10K_TEST_MSG_STRING, 1418c2ecf20Sopenharmony_ci FM10K_TEST_MSG_MAC_ADDR, 1428c2ecf20Sopenharmony_ci FM10K_TEST_MSG_U8, 1438c2ecf20Sopenharmony_ci FM10K_TEST_MSG_U16, 1448c2ecf20Sopenharmony_ci FM10K_TEST_MSG_U32, 1458c2ecf20Sopenharmony_ci FM10K_TEST_MSG_U64, 1468c2ecf20Sopenharmony_ci FM10K_TEST_MSG_S8, 1478c2ecf20Sopenharmony_ci FM10K_TEST_MSG_S16, 1488c2ecf20Sopenharmony_ci FM10K_TEST_MSG_S32, 1498c2ecf20Sopenharmony_ci FM10K_TEST_MSG_S64, 1508c2ecf20Sopenharmony_ci FM10K_TEST_MSG_LE_STRUCT, 1518c2ecf20Sopenharmony_ci FM10K_TEST_MSG_NESTED, 1528c2ecf20Sopenharmony_ci FM10K_TEST_MSG_RESULT, 1538c2ecf20Sopenharmony_ci FM10K_TEST_MSG_MAX 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciextern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[]; 1578c2ecf20Sopenharmony_civoid fm10k_tlv_msg_test_create(u32 *, u32); 1588c2ecf20Sopenharmony_cis32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#define FM10K_TLV_MSG_TEST_HANDLER(func) \ 1618c2ecf20Sopenharmony_ci FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func) 1628c2ecf20Sopenharmony_ci#define FM10K_TLV_MSG_ERROR_HANDLER(func) \ 1638c2ecf20Sopenharmony_ci FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func) 1648c2ecf20Sopenharmony_ci#endif /* _FM10K_MSG_H_ */ 165