162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright(c) 2013 - 2019 Intel Corporation. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef _FM10K_TLV_H_ 562306a36Sopenharmony_ci#define _FM10K_TLV_H_ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* forward declaration */ 862306a36Sopenharmony_cistruct fm10k_msg_data; 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "fm10k_type.h" 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* Message / Argument header format 1362306a36Sopenharmony_ci * 3 2 1 0 1462306a36Sopenharmony_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 1562306a36Sopenharmony_ci * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1662306a36Sopenharmony_ci * | Length | Flags | Type / ID | 1762306a36Sopenharmony_ci * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * The message header format described here is used for messages that are 2062306a36Sopenharmony_ci * passed between the PF and the VF. To allow for messages larger then 2162306a36Sopenharmony_ci * mailbox size we will provide a message with the above header and it 2262306a36Sopenharmony_ci * will be segmented and transported to the mailbox to the other side where 2362306a36Sopenharmony_ci * it is reassembled. It contains the following fields: 2462306a36Sopenharmony_ci * Length: Length of the message in bytes excluding the message header 2562306a36Sopenharmony_ci * Flags: TBD 2662306a36Sopenharmony_ci * Type/ID: These will be the message/argument types we pass 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci/* message data header */ 2962306a36Sopenharmony_ci#define FM10K_TLV_ID_SHIFT 0 3062306a36Sopenharmony_ci#define FM10K_TLV_ID_SIZE 16 3162306a36Sopenharmony_ci#define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1) 3262306a36Sopenharmony_ci#define FM10K_TLV_FLAGS_SHIFT 16 3362306a36Sopenharmony_ci#define FM10K_TLV_FLAGS_MSG 0x1 3462306a36Sopenharmony_ci#define FM10K_TLV_FLAGS_SIZE 4 3562306a36Sopenharmony_ci#define FM10K_TLV_LEN_SHIFT 20 3662306a36Sopenharmony_ci#define FM10K_TLV_LEN_SIZE 12 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define FM10K_TLV_HDR_LEN 4ul 3962306a36Sopenharmony_ci#define FM10K_TLV_LEN_ALIGN_MASK \ 4062306a36Sopenharmony_ci ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT) 4162306a36Sopenharmony_ci#define FM10K_TLV_LEN_ALIGN(tlv) \ 4262306a36Sopenharmony_ci (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK) 4362306a36Sopenharmony_ci#define FM10K_TLV_DWORD_LEN(tlv) \ 4462306a36Sopenharmony_ci ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define FM10K_TLV_RESULTS_MAX 32 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cienum fm10k_tlv_type { 4962306a36Sopenharmony_ci FM10K_TLV_NULL_STRING, 5062306a36Sopenharmony_ci FM10K_TLV_MAC_ADDR, 5162306a36Sopenharmony_ci FM10K_TLV_BOOL, 5262306a36Sopenharmony_ci FM10K_TLV_UNSIGNED, 5362306a36Sopenharmony_ci FM10K_TLV_SIGNED, 5462306a36Sopenharmony_ci FM10K_TLV_LE_STRUCT, 5562306a36Sopenharmony_ci FM10K_TLV_NESTED, 5662306a36Sopenharmony_ci FM10K_TLV_MAX_TYPE 5762306a36Sopenharmony_ci}; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci#define FM10K_TLV_ERROR (~0u) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistruct fm10k_tlv_attr { 6262306a36Sopenharmony_ci unsigned int id; 6362306a36Sopenharmony_ci enum fm10k_tlv_type type; 6462306a36Sopenharmony_ci u16 len; 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len } 6862306a36Sopenharmony_ci#define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 } 6962306a36Sopenharmony_ci#define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 } 7062306a36Sopenharmony_ci#define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 } 7162306a36Sopenharmony_ci#define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 } 7262306a36Sopenharmony_ci#define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 } 7362306a36Sopenharmony_ci#define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 } 7462306a36Sopenharmony_ci#define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 } 7562306a36Sopenharmony_ci#define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 } 7662306a36Sopenharmony_ci#define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 } 7762306a36Sopenharmony_ci#define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 } 7862306a36Sopenharmony_ci#define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len } 7962306a36Sopenharmony_ci#define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED, 0 } 8062306a36Sopenharmony_ci#define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR, 0, 0 } 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_cistruct fm10k_msg_data { 8362306a36Sopenharmony_ci unsigned int id; 8462306a36Sopenharmony_ci const struct fm10k_tlv_attr *attr; 8562306a36Sopenharmony_ci s32 (*func)(struct fm10k_hw *, u32 **, 8662306a36Sopenharmony_ci struct fm10k_mbx_info *); 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func } 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cis32 fm10k_tlv_msg_init(u32 *, u16); 9262306a36Sopenharmony_cis32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16); 9362306a36Sopenharmony_cis32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *); 9462306a36Sopenharmony_cis32 fm10k_tlv_attr_put_bool(u32 *, u16); 9562306a36Sopenharmony_cis32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32); 9662306a36Sopenharmony_ci#define fm10k_tlv_attr_put_u8(msg, attr_id, val) \ 9762306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 1) 9862306a36Sopenharmony_ci#define fm10k_tlv_attr_put_u16(msg, attr_id, val) \ 9962306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 2) 10062306a36Sopenharmony_ci#define fm10k_tlv_attr_put_u32(msg, attr_id, val) \ 10162306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 4) 10262306a36Sopenharmony_ci#define fm10k_tlv_attr_put_u64(msg, attr_id, val) \ 10362306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 8) 10462306a36Sopenharmony_ci#define fm10k_tlv_attr_put_s8(msg, attr_id, val) \ 10562306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 1) 10662306a36Sopenharmony_ci#define fm10k_tlv_attr_put_s16(msg, attr_id, val) \ 10762306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 2) 10862306a36Sopenharmony_ci#define fm10k_tlv_attr_put_s32(msg, attr_id, val) \ 10962306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 4) 11062306a36Sopenharmony_ci#define fm10k_tlv_attr_put_s64(msg, attr_id, val) \ 11162306a36Sopenharmony_ci fm10k_tlv_attr_put_value(msg, attr_id, val, 8) 11262306a36Sopenharmony_cis32 fm10k_tlv_attr_get_value(u32 *, void *, u32); 11362306a36Sopenharmony_ci#define fm10k_tlv_attr_get_u8(attr, ptr) \ 11462306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8)) 11562306a36Sopenharmony_ci#define fm10k_tlv_attr_get_u16(attr, ptr) \ 11662306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16)) 11762306a36Sopenharmony_ci#define fm10k_tlv_attr_get_u32(attr, ptr) \ 11862306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32)) 11962306a36Sopenharmony_ci#define fm10k_tlv_attr_get_u64(attr, ptr) \ 12062306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64)) 12162306a36Sopenharmony_ci#define fm10k_tlv_attr_get_s8(attr, ptr) \ 12262306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8)) 12362306a36Sopenharmony_ci#define fm10k_tlv_attr_get_s16(attr, ptr) \ 12462306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16)) 12562306a36Sopenharmony_ci#define fm10k_tlv_attr_get_s32(attr, ptr) \ 12662306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32)) 12762306a36Sopenharmony_ci#define fm10k_tlv_attr_get_s64(attr, ptr) \ 12862306a36Sopenharmony_ci fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64)) 12962306a36Sopenharmony_cis32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32); 13062306a36Sopenharmony_cis32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32); 13162306a36Sopenharmony_cis32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *, 13262306a36Sopenharmony_ci const struct fm10k_msg_data *); 13362306a36Sopenharmony_cis32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results, 13462306a36Sopenharmony_ci struct fm10k_mbx_info *); 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define FM10K_TLV_MSG_ID_TEST 0 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cienum fm10k_tlv_test_attr_id { 13962306a36Sopenharmony_ci FM10K_TEST_MSG_UNSET, 14062306a36Sopenharmony_ci FM10K_TEST_MSG_STRING, 14162306a36Sopenharmony_ci FM10K_TEST_MSG_MAC_ADDR, 14262306a36Sopenharmony_ci FM10K_TEST_MSG_U8, 14362306a36Sopenharmony_ci FM10K_TEST_MSG_U16, 14462306a36Sopenharmony_ci FM10K_TEST_MSG_U32, 14562306a36Sopenharmony_ci FM10K_TEST_MSG_U64, 14662306a36Sopenharmony_ci FM10K_TEST_MSG_S8, 14762306a36Sopenharmony_ci FM10K_TEST_MSG_S16, 14862306a36Sopenharmony_ci FM10K_TEST_MSG_S32, 14962306a36Sopenharmony_ci FM10K_TEST_MSG_S64, 15062306a36Sopenharmony_ci FM10K_TEST_MSG_LE_STRUCT, 15162306a36Sopenharmony_ci FM10K_TEST_MSG_NESTED, 15262306a36Sopenharmony_ci FM10K_TEST_MSG_RESULT, 15362306a36Sopenharmony_ci FM10K_TEST_MSG_MAX 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ciextern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[]; 15762306a36Sopenharmony_civoid fm10k_tlv_msg_test_create(u32 *, u32); 15862306a36Sopenharmony_cis32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *); 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci#define FM10K_TLV_MSG_TEST_HANDLER(func) \ 16162306a36Sopenharmony_ci FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func) 16262306a36Sopenharmony_ci#define FM10K_TLV_MSG_ERROR_HANDLER(func) \ 16362306a36Sopenharmony_ci FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func) 16462306a36Sopenharmony_ci#endif /* _FM10K_MSG_H_ */ 165