// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2013 - 2019 Intel Corporation. */ #include "fm10k_tlv.h" /** * fm10k_tlv_msg_init - Initialize message block for TLV data storage * @msg: Pointer to message block * @msg_id: Message ID indicating message type * * This function return success if provided with a valid message pointer **/ s32 fm10k_tlv_msg_init(u32 *msg, u16 msg_id) { … } /** * fm10k_tlv_attr_put_null_string - Place null terminated string on message * @msg: Pointer to message block * @attr_id: Attribute ID * @string: Pointer to string to be stored in attribute * * This function will reorder a string to be CPU endian and store it in * the attribute buffer. It will return success if provided with a valid * pointers. **/ static s32 fm10k_tlv_attr_put_null_string(u32 *msg, u16 attr_id, const unsigned char *string) { … } /** * fm10k_tlv_attr_get_null_string - Get null terminated string from attribute * @attr: Pointer to attribute * @string: Pointer to location of destination string * * This function pulls the string back out of the attribute and will place * it in the array pointed by string. It will return success if provided * with a valid pointers. **/ static s32 fm10k_tlv_attr_get_null_string(u32 *attr, unsigned char *string) { … } /** * fm10k_tlv_attr_put_mac_vlan - Store MAC/VLAN attribute in message * @msg: Pointer to message block * @attr_id: Attribute ID * @mac_addr: MAC address to be stored * @vlan: VLAN to be stored * * This function will reorder a MAC address to be CPU endian and store it * in the attribute buffer. It will return success if provided with a * valid pointers. **/ s32 fm10k_tlv_attr_put_mac_vlan(u32 *msg, u16 attr_id, const u8 *mac_addr, u16 vlan) { … } /** * fm10k_tlv_attr_get_mac_vlan - Get MAC/VLAN stored in attribute * @attr: Pointer to attribute * @mac_addr: location of buffer to store MAC address * @vlan: location of buffer to store VLAN * * This function pulls the MAC address back out of the attribute and will * place it in the array pointed by mac_addr. It will return success * if provided with a valid pointers. **/ s32 fm10k_tlv_attr_get_mac_vlan(u32 *attr, u8 *mac_addr, u16 *vlan) { … } /** * fm10k_tlv_attr_put_bool - Add header indicating value "true" * @msg: Pointer to message block * @attr_id: Attribute ID * * This function will simply add an attribute header, the fact * that the header is here means the attribute value is true, else * it is false. The function will return success if provided with a * valid pointers. **/ s32 fm10k_tlv_attr_put_bool(u32 *msg, u16 attr_id) { … } /** * fm10k_tlv_attr_put_value - Store integer value attribute in message * @msg: Pointer to message block * @attr_id: Attribute ID * @value: Value to be written * @len: Size of value * * This function will place an integer value of up to 8 bytes in size * in a message attribute. The function will return success provided * that msg is a valid pointer, and len is 1, 2, 4, or 8. **/ s32 fm10k_tlv_attr_put_value(u32 *msg, u16 attr_id, s64 value, u32 len) { … } /** * fm10k_tlv_attr_get_value - Get integer value stored in attribute * @attr: Pointer to attribute * @value: Pointer to destination buffer * @len: Size of value * * This function will place an integer value of up to 8 bytes in size * in the offset pointed to by value. The function will return success * provided that pointers are valid and the len value matches the * attribute length. **/ s32 fm10k_tlv_attr_get_value(u32 *attr, void *value, u32 len) { … } /** * fm10k_tlv_attr_put_le_struct - Store little endian structure in message * @msg: Pointer to message block * @attr_id: Attribute ID * @le_struct: Pointer to structure to be written * @len: Size of le_struct * * This function will place a little endian structure value in a message * attribute. The function will return success provided that all pointers * are valid and length is a non-zero multiple of 4. **/ s32 fm10k_tlv_attr_put_le_struct(u32 *msg, u16 attr_id, const void *le_struct, u32 len) { … } /** * fm10k_tlv_attr_get_le_struct - Get little endian struct form attribute * @attr: Pointer to attribute * @le_struct: Pointer to structure to be written * @len: Size of structure * * This function will place a little endian structure in the buffer * pointed to by le_struct. The function will return success * provided that pointers are valid and the len value matches the * attribute length. **/ s32 fm10k_tlv_attr_get_le_struct(u32 *attr, void *le_struct, u32 len) { … } /** * fm10k_tlv_attr_nest_start - Start a set of nested attributes * @msg: Pointer to message block * @attr_id: Attribute ID * * This function will mark off a new nested region for encapsulating * a given set of attributes. The idea is if you wish to place a secondary * structure within the message this mechanism allows for that. The * function will return NULL on failure, and a pointer to the start * of the nested attributes on success. **/ static u32 *fm10k_tlv_attr_nest_start(u32 *msg, u16 attr_id) { … } /** * fm10k_tlv_attr_nest_stop - Stop a set of nested attributes * @msg: Pointer to message block * * This function closes off an existing set of nested attributes. The * message pointer should be pointing to the parent of the nest. So in * the case of a nest within the nest this would be the outer nest pointer. * This function will return success provided all pointers are valid. **/ static s32 fm10k_tlv_attr_nest_stop(u32 *msg) { … } /** * fm10k_tlv_attr_validate - Validate attribute metadata * @attr: Pointer to attribute * @tlv_attr: Type and length info for attribute * * This function does some basic validation of the input TLV. It * verifies the length, and in the case of null terminated strings * it verifies that the last byte is null. The function will * return FM10K_ERR_PARAM if any attribute is malformed, otherwise * it returns 0. **/ static s32 fm10k_tlv_attr_validate(u32 *attr, const struct fm10k_tlv_attr *tlv_attr) { … } /** * fm10k_tlv_attr_parse - Parses stream of attribute data * @attr: Pointer to attribute list * @results: Pointer array to store pointers to attributes * @tlv_attr: Type and length info for attributes * * This function validates a stream of attributes and parses them * up into an array of pointers stored in results. The function will * return FM10K_ERR_PARAM on any input or message error, * FM10K_NOT_IMPLEMENTED for any attribute that is outside of the array * and 0 on success. Any attributes not found in tlv_attr will be silently * ignored. **/ static s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results, const struct fm10k_tlv_attr *tlv_attr) { … } /** * fm10k_tlv_msg_parse - Parses message header and calls function handler * @hw: Pointer to hardware structure * @msg: Pointer to message * @mbx: Pointer to mailbox information structure * @data: Pointer to message handler data structure * * This function should be the first function called upon receiving a * message. The handler will identify the message type and call the correct * handler for the given message. It will return the value from the function * call on a recognized message type, otherwise it will return * FM10K_NOT_IMPLEMENTED on an unrecognized type. **/ s32 fm10k_tlv_msg_parse(struct fm10k_hw *hw, u32 *msg, struct fm10k_mbx_info *mbx, const struct fm10k_msg_data *data) { … } /** * fm10k_tlv_msg_error - Default handler for unrecognized TLV message IDs * @hw: Pointer to hardware structure * @results: Pointer array to message, results[0] is pointer to message * @mbx: Unused mailbox pointer * * This function is a default handler for unrecognized messages. At a * minimum it just indicates that the message requested was * unimplemented. **/ s32 fm10k_tlv_msg_error(struct fm10k_hw __always_unused *hw, u32 __always_unused **results, struct fm10k_mbx_info __always_unused *mbx) { … } static const unsigned char test_str[] = …; static const unsigned char test_mac[ETH_ALEN] = …; static const u16 test_vlan = …; static const u64 test_u64 = …; static const u32 test_u32 = …; static const u16 test_u16 = …; static const u8 test_u8 = …; static const s64 test_s64 = …; static const s32 test_s32 = …; static const s16 test_s16 = …; static const s8 test_s8 = …; static const __le32 test_le[2] = …; /* The message below is meant to be used as a test message to demonstrate * how to use the TLV interface and to test the types. Normally this code * be compiled out by stripping the code wrapped in FM10K_TLV_TEST_MSG */ const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[] = …; /** * fm10k_tlv_msg_test_generate_data - Stuff message with data * @msg: Pointer to message * @attr_flags: List of flags indicating what attributes to add * * This function is meant to load a message buffer with attribute data **/ static void fm10k_tlv_msg_test_generate_data(u32 *msg, u32 attr_flags) { … } /** * fm10k_tlv_msg_test_create - Create a test message testing all attributes * @msg: Pointer to message * @attr_flags: List of flags indicating what attributes to add * * This function is meant to load a message buffer with all attribute types * including a nested attribute. **/ void fm10k_tlv_msg_test_create(u32 *msg, u32 attr_flags) { … } /** * fm10k_tlv_msg_test - Validate all results on test message receive * @hw: Pointer to hardware structure * @results: Pointer array to attributes in the message * @mbx: Pointer to mailbox information structure * * This function does a check to verify all attributes match what the test * message placed in the message buffer. It is the default handler * for TLV test messages. **/ s32 fm10k_tlv_msg_test(struct fm10k_hw *hw, u32 **results, struct fm10k_mbx_info *mbx) { … }