1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013 - 2015 Intel Corporation
8 * fm10k_tlv_msg_init - Initialize message block for TLV data storage
9 * @msg: Pointer to message block
10 * @msg_id: Message ID indicating message type
12 * This function return success if provided with a valid message pointer
14 s32 fm10k_tlv_msg_init(u32 *msg, u16 msg_id)
16 DEBUGFUNC("fm10k_tlv_msg_init");
18 /* verify pointer is not NULL */
20 return FM10K_ERR_PARAM;
22 *msg = (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT) | msg_id;
28 * fm10k_tlv_attr_put_null_string - Place null terminated string on message
29 * @msg: Pointer to message block
30 * @attr_id: Attribute ID
31 * @string: Pointer to string to be stored in attribute
33 * This function will reorder a string to be CPU endian and store it in
34 * the attribute buffer. It will return success if provided with a valid
37 static s32 fm10k_tlv_attr_put_null_string(u32 *msg, u16 attr_id,
38 const unsigned char *string)
40 u32 attr_data = 0, len = 0;
43 DEBUGFUNC("fm10k_tlv_attr_put_null_string");
45 /* verify pointers are not NULL */
47 return FM10K_ERR_PARAM;
49 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
51 /* copy string into local variable and then write to msg */
53 /* write data to message */
54 if (len && !(len % 4)) {
55 attr[len / 4] = attr_data;
59 /* record character to offset location */
60 attr_data |= (u32)(*string) << (8 * (len % 4));
63 /* test for NULL and then increment */
64 } while (*(string++));
66 /* write last piece of data to message */
67 attr[(len + 3) / 4] = attr_data;
69 /* record attribute header, update message length */
70 len <<= FM10K_TLV_LEN_SHIFT;
71 attr[0] = len | attr_id;
73 /* add header length to length */
74 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
75 *msg += FM10K_TLV_LEN_ALIGN(len);
81 * fm10k_tlv_attr_get_null_string - Get null terminated string from attribute
82 * @attr: Pointer to attribute
83 * @string: Pointer to location of destination string
85 * This function pulls the string back out of the attribute and will place
86 * it in the array pointed by by string. It will return success if provided
87 * with a valid pointers.
89 static s32 fm10k_tlv_attr_get_null_string(u32 *attr, unsigned char *string)
93 DEBUGFUNC("fm10k_tlv_attr_get_null_string");
95 /* verify pointers are not NULL */
97 return FM10K_ERR_PARAM;
99 len = *attr >> FM10K_TLV_LEN_SHIFT;
103 string[len] = (u8)(attr[len / 4] >> (8 * (len % 4)));
105 return FM10K_SUCCESS;
109 * fm10k_tlv_attr_put_mac_vlan - Store MAC/VLAN attribute in message
110 * @msg: Pointer to message block
111 * @attr_id: Attribute ID
112 * @mac_addr: MAC address to be stored
114 * This function will reorder a MAC address to be CPU endian and store it
115 * in the attribute buffer. It will return success if provided with a
118 s32 fm10k_tlv_attr_put_mac_vlan(u32 *msg, u16 attr_id,
119 const u8 *mac_addr, u16 vlan)
121 u32 len = ETH_ALEN << FM10K_TLV_LEN_SHIFT;
124 DEBUGFUNC("fm10k_tlv_attr_put_mac_vlan");
126 /* verify pointers are not NULL */
127 if (!msg || !mac_addr)
128 return FM10K_ERR_PARAM;
130 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
132 /* record attribute header, update message length */
133 attr[0] = len | attr_id;
135 /* copy value into local variable and then write to msg */
136 attr[1] = FM10K_LE32_TO_CPU(*(const __le32 *)&mac_addr[0]);
137 attr[2] = FM10K_LE16_TO_CPU(*(const __le16 *)&mac_addr[4]);
138 attr[2] |= (u32)vlan << 16;
140 /* add header length to length */
141 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
142 *msg += FM10K_TLV_LEN_ALIGN(len);
144 return FM10K_SUCCESS;
148 * fm10k_tlv_attr_get_mac_vlan - Get MAC/VLAN stored in attribute
149 * @attr: Pointer to attribute
150 * @attr_id: Attribute ID
151 * @mac_addr: location of buffer to store MAC address
153 * This function pulls the MAC address back out of the attribute and will
154 * place it in the array pointed by by mac_addr. It will return success
155 * if provided with a valid pointers.
157 s32 fm10k_tlv_attr_get_mac_vlan(u32 *attr, u8 *mac_addr, u16 *vlan)
159 DEBUGFUNC("fm10k_tlv_attr_get_mac_vlan");
161 /* verify pointers are not NULL */
162 if (!mac_addr || !attr)
163 return FM10K_ERR_PARAM;
165 *(__le32 *)&mac_addr[0] = FM10K_CPU_TO_LE32(attr[1]);
166 *(__le16 *)&mac_addr[4] = FM10K_CPU_TO_LE16((u16)(attr[2]));
167 *vlan = (u16)(attr[2] >> 16);
169 return FM10K_SUCCESS;
173 * fm10k_tlv_attr_put_bool - Add header indicating value "true"
174 * @msg: Pointer to message block
175 * @attr_id: Attribute ID
177 * This function will simply add an attribute header, the fact
178 * that the header is here means the attribute value is true, else
179 * it is false. The function will return success if provided with a
182 s32 fm10k_tlv_attr_put_bool(u32 *msg, u16 attr_id)
184 DEBUGFUNC("fm10k_tlv_attr_put_bool");
186 /* verify pointers are not NULL */
188 return FM10K_ERR_PARAM;
190 /* record attribute header */
191 msg[FM10K_TLV_DWORD_LEN(*msg)] = attr_id;
193 /* add header length to length */
194 *msg += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
196 return FM10K_SUCCESS;
200 * fm10k_tlv_attr_put_value - Store integer value attribute in message
201 * @msg: Pointer to message block
202 * @attr_id: Attribute ID
203 * @value: Value to be written
204 * @len: Size of value
206 * This function will place an integer value of up to 8 bytes in size
207 * in a message attribute. The function will return success provided
208 * that msg is a valid pointer, and len is 1, 2, 4, or 8.
210 s32 fm10k_tlv_attr_put_value(u32 *msg, u16 attr_id, s64 value, u32 len)
214 DEBUGFUNC("fm10k_tlv_attr_put_value");
216 /* verify non-null msg and len is 1, 2, 4, or 8 */
217 if (!msg || !len || len > 8 || (len & (len - 1)))
218 return FM10K_ERR_PARAM;
220 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
223 attr[1] = (u32)value & (BIT(8 * len) - 1);
225 attr[1] = (u32)value;
227 attr[2] = (u32)(value >> 32);
230 /* record attribute header, update message length */
231 len <<= FM10K_TLV_LEN_SHIFT;
232 attr[0] = len | attr_id;
234 /* add header length to length */
235 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
236 *msg += FM10K_TLV_LEN_ALIGN(len);
238 return FM10K_SUCCESS;
242 * fm10k_tlv_attr_get_value - Get integer value stored in attribute
243 * @attr: Pointer to attribute
244 * @value: Pointer to destination buffer
245 * @len: Size of value
247 * This function will place an integer value of up to 8 bytes in size
248 * in the offset pointed to by value. The function will return success
249 * provided that pointers are valid and the len value matches the
252 s32 fm10k_tlv_attr_get_value(u32 *attr, void *value, u32 len)
254 DEBUGFUNC("fm10k_tlv_attr_get_value");
256 /* verify pointers are not NULL */
258 return FM10K_ERR_PARAM;
260 if ((*attr >> FM10K_TLV_LEN_SHIFT) != len)
261 return FM10K_ERR_PARAM;
264 *(u64 *)value = ((u64)attr[2] << 32) | attr[1];
266 *(u32 *)value = attr[1];
268 *(u16 *)value = (u16)attr[1];
270 *(u8 *)value = (u8)attr[1];
272 return FM10K_SUCCESS;
276 * fm10k_tlv_attr_put_le_struct - Store little endian structure in message
277 * @msg: Pointer to message block
278 * @attr_id: Attribute ID
279 * @le_struct: Pointer to structure to be written
280 * @len: Size of le_struct
282 * This function will place a little endian structure value in a message
283 * attribute. The function will return success provided that all pointers
284 * are valid and length is a non-zero multiple of 4.
286 s32 fm10k_tlv_attr_put_le_struct(u32 *msg, u16 attr_id,
287 const void *le_struct, u32 len)
289 const __le32 *le32_ptr = (const __le32 *)le_struct;
293 DEBUGFUNC("fm10k_tlv_attr_put_le_struct");
295 /* verify non-null msg and len is in 32 bit words */
296 if (!msg || !len || (len % 4))
297 return FM10K_ERR_PARAM;
299 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
301 /* copy le32 structure into host byte order at 32b boundaries */
302 for (i = 0; i < (len / 4); i++)
303 attr[i + 1] = FM10K_LE32_TO_CPU(le32_ptr[i]);
305 /* record attribute header, update message length */
306 len <<= FM10K_TLV_LEN_SHIFT;
307 attr[0] = len | attr_id;
309 /* add header length to length */
310 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
311 *msg += FM10K_TLV_LEN_ALIGN(len);
313 return FM10K_SUCCESS;
317 * fm10k_tlv_attr_get_le_struct - Get little endian struct form attribute
318 * @attr: Pointer to attribute
319 * @le_struct: Pointer to structure to be written
320 * @len: Size of structure
322 * This function will place a little endian structure in the buffer
323 * pointed to by le_struct. The function will return success
324 * provided that pointers are valid and the len value matches the
327 s32 fm10k_tlv_attr_get_le_struct(u32 *attr, void *le_struct, u32 len)
329 __le32 *le32_ptr = (__le32 *)le_struct;
332 DEBUGFUNC("fm10k_tlv_attr_get_le_struct");
334 /* verify pointers are not NULL */
335 if (!le_struct || !attr)
336 return FM10K_ERR_PARAM;
338 if ((*attr >> FM10K_TLV_LEN_SHIFT) != len)
339 return FM10K_ERR_PARAM;
343 for (i = 0; len; i++, len -= 4)
344 le32_ptr[i] = FM10K_CPU_TO_LE32(attr[i]);
346 return FM10K_SUCCESS;
350 * fm10k_tlv_attr_nest_start - Start a set of nested attributes
351 * @msg: Pointer to message block
352 * @attr_id: Attribute ID
354 * This function will mark off a new nested region for encapsulating
355 * a given set of attributes. The idea is if you wish to place a secondary
356 * structure within the message this mechanism allows for that. The
357 * function will return NULL on failure, and a pointer to the start
358 * of the nested attributes on success.
360 static u32 *fm10k_tlv_attr_nest_start(u32 *msg, u16 attr_id)
364 DEBUGFUNC("fm10k_tlv_attr_nest_start");
366 /* verify pointer is not NULL */
370 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
374 /* return pointer to nest header */
379 * fm10k_tlv_attr_nest_stop - Stop a set of nested attributes
380 * @msg: Pointer to message block
382 * This function closes off an existing set of nested attributes. The
383 * message pointer should be pointing to the parent of the nest. So in
384 * the case of a nest within the nest this would be the outer nest pointer.
385 * This function will return success provided all pointers are valid.
387 static s32 fm10k_tlv_attr_nest_stop(u32 *msg)
392 DEBUGFUNC("fm10k_tlv_attr_nest_stop");
394 /* verify pointer is not NULL */
396 return FM10K_ERR_PARAM;
398 /* locate the nested header and retrieve its length */
399 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
400 len = (attr[0] >> FM10K_TLV_LEN_SHIFT) << FM10K_TLV_LEN_SHIFT;
402 /* only include nest if data was added to it */
404 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
408 return FM10K_SUCCESS;
412 * fm10k_tlv_attr_validate - Validate attribute metadata
413 * @attr: Pointer to attribute
414 * @tlv_attr: Type and length info for attribute
416 * This function does some basic validation of the input TLV. It
417 * verifies the length, and in the case of null terminated strings
418 * it verifies that the last byte is null. The function will
419 * return FM10K_ERR_PARAM if any attribute is malformed, otherwise
422 STATIC s32 fm10k_tlv_attr_validate(u32 *attr,
423 const struct fm10k_tlv_attr *tlv_attr)
425 u32 attr_id = *attr & FM10K_TLV_ID_MASK;
426 u16 len = *attr >> FM10K_TLV_LEN_SHIFT;
428 DEBUGFUNC("fm10k_tlv_attr_validate");
430 /* verify this is an attribute and not a message */
431 if (*attr & (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT))
432 return FM10K_ERR_PARAM;
434 /* search through the list of attributes to find a matching ID */
435 while (tlv_attr->id < attr_id)
438 /* if didn't find a match then we should exit */
439 if (tlv_attr->id != attr_id)
440 return FM10K_NOT_IMPLEMENTED;
442 /* move to start of attribute data */
445 switch (tlv_attr->type) {
446 case FM10K_TLV_NULL_STRING:
448 (attr[(len - 1) / 4] & (0xFF << (8 * ((len - 1) % 4)))))
449 return FM10K_ERR_PARAM;
450 if (len > tlv_attr->len)
451 return FM10K_ERR_PARAM;
453 case FM10K_TLV_MAC_ADDR:
455 return FM10K_ERR_PARAM;
459 return FM10K_ERR_PARAM;
461 case FM10K_TLV_UNSIGNED:
462 case FM10K_TLV_SIGNED:
463 if (len != tlv_attr->len)
464 return FM10K_ERR_PARAM;
466 case FM10K_TLV_LE_STRUCT:
467 /* struct must be 4 byte aligned */
468 if ((len % 4) || len != tlv_attr->len)
469 return FM10K_ERR_PARAM;
471 case FM10K_TLV_NESTED:
472 /* nested attributes must be 4 byte aligned */
474 return FM10K_ERR_PARAM;
477 /* attribute id is mapped to bad value */
478 return FM10K_ERR_PARAM;
481 return FM10K_SUCCESS;
485 * fm10k_tlv_attr_parse - Parses stream of attribute data
486 * @attr: Pointer to attribute list
487 * @results: Pointer array to store pointers to attributes
488 * @tlv_attr: Type and length info for attributes
490 * This function validates a stream of attributes and parses them
491 * up into an array of pointers stored in results. The function will
492 * return FM10K_ERR_PARAM on any input or message error,
493 * FM10K_NOT_IMPLEMENTED for any attribute that is outside of the array
494 * and 0 on success. Any attributes not found in tlv_attr will be silently
497 static s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results,
498 const struct fm10k_tlv_attr *tlv_attr)
500 u32 i, attr_id, offset = 0;
504 DEBUGFUNC("fm10k_tlv_attr_parse");
506 /* verify pointers are not NULL */
507 if (!attr || !results)
508 return FM10K_ERR_PARAM;
510 /* initialize results to NULL */
511 for (i = 0; i < FM10K_TLV_RESULTS_MAX; i++)
514 /* pull length from the message header */
515 len = *attr >> FM10K_TLV_LEN_SHIFT;
517 /* no attributes to parse if there is no length */
519 return FM10K_SUCCESS;
521 /* no attributes to parse, just raw data, message becomes attribute */
524 return FM10K_SUCCESS;
527 /* move to start of attribute data */
530 /* run through list parsing all attributes */
531 while (offset < len) {
532 attr_id = *attr & FM10K_TLV_ID_MASK;
534 if (attr_id >= FM10K_TLV_RESULTS_MAX)
535 return FM10K_NOT_IMPLEMENTED;
537 err = fm10k_tlv_attr_validate(attr, tlv_attr);
538 if (err == FM10K_NOT_IMPLEMENTED)
539 ; /* silently ignore non-implemented attributes */
543 results[attr_id] = attr;
546 offset += FM10K_TLV_DWORD_LEN(*attr) * 4;
548 /* move to next attribute */
549 attr = &attr[FM10K_TLV_DWORD_LEN(*attr)];
552 /* we should find ourselves at the end of the list */
554 return FM10K_ERR_PARAM;
556 return FM10K_SUCCESS;
560 * fm10k_tlv_msg_parse - Parses message header and calls function handler
561 * @hw: Pointer to hardware structure
562 * @msg: Pointer to message
563 * @mbx: Pointer to mailbox information structure
564 * @func: Function array containing list of message handling functions
566 * This function should be the first function called upon receiving a
567 * message. The handler will identify the message type and call the correct
568 * handler for the given message. It will return the value from the function
569 * call on a recognized message type, otherwise it will return
570 * FM10K_NOT_IMPLEMENTED on an unrecognized type.
572 s32 fm10k_tlv_msg_parse(struct fm10k_hw *hw, u32 *msg,
573 struct fm10k_mbx_info *mbx,
574 const struct fm10k_msg_data *data)
576 u32 *results[FM10K_TLV_RESULTS_MAX];
580 DEBUGFUNC("fm10k_tlv_msg_parse");
582 /* verify pointer is not NULL */
584 return FM10K_ERR_PARAM;
586 /* verify this is a message and not an attribute */
587 if (!(*msg & (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT)))
588 return FM10K_ERR_PARAM;
590 /* grab message ID */
591 msg_id = *msg & FM10K_TLV_ID_MASK;
593 while (data->id < msg_id)
596 /* if we didn't find it then pass it up as an error */
597 if (data->id != msg_id) {
598 while (data->id != FM10K_TLV_ERROR)
602 /* parse the attributes into the results list */
603 err = fm10k_tlv_attr_parse(msg, results, data->attr);
607 return data->func(hw, results, mbx);
611 * fm10k_tlv_msg_error - Default handler for unrecognized TLV message IDs
612 * @hw: Pointer to hardware structure
613 * @results: Pointer array to message, results[0] is pointer to message
614 * @mbx: Unused mailbox pointer
616 * This function is a default handler for unrecognized messages. At a
617 * a minimum it just indicates that the message requested was
620 s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
621 struct fm10k_mbx_info *mbx)
623 UNREFERENCED_3PARAMETER(hw, results, mbx);
624 DEBUGOUT1("Unknown message ID %u\n", **results & FM10K_TLV_ID_MASK);
625 return FM10K_NOT_IMPLEMENTED;
628 STATIC const unsigned char test_str[] = "fm10k";
629 STATIC const unsigned char test_mac[ETH_ALEN] = { 0x12, 0x34, 0x56,
631 STATIC const u16 test_vlan = 0x0FED;
632 STATIC const u64 test_u64 = 0xfedcba9876543210ull;
633 STATIC const u32 test_u32 = 0x87654321;
634 STATIC const u16 test_u16 = 0x8765;
635 STATIC const u8 test_u8 = 0x87;
636 STATIC const s64 test_s64 = -0x123456789abcdef0ll;
637 STATIC const s32 test_s32 = -0x1235678;
638 STATIC const s16 test_s16 = -0x1234;
639 STATIC const s8 test_s8 = -0x12;
640 STATIC const __le32 test_le[2] = { FM10K_CPU_TO_LE32(0x12345678),
641 FM10K_CPU_TO_LE32(0x9abcdef0)};
643 /* The message below is meant to be used as a test message to demonstrate
644 * how to use the TLV interface and to test the types. Normally this code
645 * be compiled out by stripping the code wrapped in FM10K_TLV_TEST_MSG
647 const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[] = {
648 FM10K_TLV_ATTR_NULL_STRING(FM10K_TEST_MSG_STRING, 80),
649 FM10K_TLV_ATTR_MAC_ADDR(FM10K_TEST_MSG_MAC_ADDR),
650 FM10K_TLV_ATTR_U8(FM10K_TEST_MSG_U8),
651 FM10K_TLV_ATTR_U16(FM10K_TEST_MSG_U16),
652 FM10K_TLV_ATTR_U32(FM10K_TEST_MSG_U32),
653 FM10K_TLV_ATTR_U64(FM10K_TEST_MSG_U64),
654 FM10K_TLV_ATTR_S8(FM10K_TEST_MSG_S8),
655 FM10K_TLV_ATTR_S16(FM10K_TEST_MSG_S16),
656 FM10K_TLV_ATTR_S32(FM10K_TEST_MSG_S32),
657 FM10K_TLV_ATTR_S64(FM10K_TEST_MSG_S64),
658 FM10K_TLV_ATTR_LE_STRUCT(FM10K_TEST_MSG_LE_STRUCT, 8),
659 FM10K_TLV_ATTR_NESTED(FM10K_TEST_MSG_NESTED),
660 FM10K_TLV_ATTR_S32(FM10K_TEST_MSG_RESULT),
665 * fm10k_tlv_msg_test_generate_data - Stuff message with data
666 * @msg: Pointer to message
667 * @attr_flags: List of flags indicating what attributes to add
669 * This function is meant to load a message buffer with attribute data
671 STATIC void fm10k_tlv_msg_test_generate_data(u32 *msg, u32 attr_flags)
673 DEBUGFUNC("fm10k_tlv_msg_test_generate_data");
675 if (attr_flags & BIT(FM10K_TEST_MSG_STRING))
676 fm10k_tlv_attr_put_null_string(msg, FM10K_TEST_MSG_STRING,
678 if (attr_flags & BIT(FM10K_TEST_MSG_MAC_ADDR))
679 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_TEST_MSG_MAC_ADDR,
680 test_mac, test_vlan);
681 if (attr_flags & BIT(FM10K_TEST_MSG_U8))
682 fm10k_tlv_attr_put_u8(msg, FM10K_TEST_MSG_U8, test_u8);
683 if (attr_flags & BIT(FM10K_TEST_MSG_U16))
684 fm10k_tlv_attr_put_u16(msg, FM10K_TEST_MSG_U16, test_u16);
685 if (attr_flags & BIT(FM10K_TEST_MSG_U32))
686 fm10k_tlv_attr_put_u32(msg, FM10K_TEST_MSG_U32, test_u32);
687 if (attr_flags & BIT(FM10K_TEST_MSG_U64))
688 fm10k_tlv_attr_put_u64(msg, FM10K_TEST_MSG_U64, test_u64);
689 if (attr_flags & BIT(FM10K_TEST_MSG_S8))
690 fm10k_tlv_attr_put_s8(msg, FM10K_TEST_MSG_S8, test_s8);
691 if (attr_flags & BIT(FM10K_TEST_MSG_S16))
692 fm10k_tlv_attr_put_s16(msg, FM10K_TEST_MSG_S16, test_s16);
693 if (attr_flags & BIT(FM10K_TEST_MSG_S32))
694 fm10k_tlv_attr_put_s32(msg, FM10K_TEST_MSG_S32, test_s32);
695 if (attr_flags & BIT(FM10K_TEST_MSG_S64))
696 fm10k_tlv_attr_put_s64(msg, FM10K_TEST_MSG_S64, test_s64);
697 if (attr_flags & BIT(FM10K_TEST_MSG_LE_STRUCT))
698 fm10k_tlv_attr_put_le_struct(msg, FM10K_TEST_MSG_LE_STRUCT,
703 * fm10k_tlv_msg_test_create - Create a test message testing all attributes
704 * @msg: Pointer to message
705 * @attr_flags: List of flags indicating what attributes to add
707 * This function is meant to load a message buffer with all attribute types
708 * including a nested attribute.
710 void fm10k_tlv_msg_test_create(u32 *msg, u32 attr_flags)
714 DEBUGFUNC("fm10k_tlv_msg_test_create");
716 fm10k_tlv_msg_init(msg, FM10K_TLV_MSG_ID_TEST);
718 fm10k_tlv_msg_test_generate_data(msg, attr_flags);
720 /* check for nested attributes */
721 attr_flags >>= FM10K_TEST_MSG_NESTED;
724 nest = fm10k_tlv_attr_nest_start(msg, FM10K_TEST_MSG_NESTED);
726 fm10k_tlv_msg_test_generate_data(nest, attr_flags);
728 fm10k_tlv_attr_nest_stop(msg);
733 * fm10k_tlv_msg_test - Validate all results on test message receive
734 * @hw: Pointer to hardware structure
735 * @results: Pointer array to attributes in the message
736 * @mbx: Pointer to mailbox information structure
738 * This function does a check to verify all attributes match what the test
739 * message placed in the message buffer. It is the default handler
740 * for TLV test messages.
742 s32 fm10k_tlv_msg_test(struct fm10k_hw *hw, u32 **results,
743 struct fm10k_mbx_info *mbx)
745 u32 *nest_results[FM10K_TLV_RESULTS_MAX];
746 unsigned char result_str[80];
747 unsigned char result_mac[ETH_ALEN];
748 s32 err = FM10K_SUCCESS;
761 DEBUGFUNC("fm10k_tlv_msg_test");
763 /* retrieve results of a previous test */
764 if (!!results[FM10K_TEST_MSG_RESULT])
765 return fm10k_tlv_attr_get_s32(results[FM10K_TEST_MSG_RESULT],
769 if (!!results[FM10K_TEST_MSG_STRING]) {
770 err = fm10k_tlv_attr_get_null_string(
771 results[FM10K_TEST_MSG_STRING],
773 if (!err && memcmp(test_str, result_str, sizeof(test_str)))
774 err = FM10K_ERR_INVALID_VALUE;
778 if (!!results[FM10K_TEST_MSG_MAC_ADDR]) {
779 err = fm10k_tlv_attr_get_mac_vlan(
780 results[FM10K_TEST_MSG_MAC_ADDR],
781 result_mac, &result_vlan);
782 if (!err && memcmp(test_mac, result_mac, ETH_ALEN))
783 err = FM10K_ERR_INVALID_VALUE;
784 if (!err && test_vlan != result_vlan)
785 err = FM10K_ERR_INVALID_VALUE;
789 if (!!results[FM10K_TEST_MSG_U8]) {
790 err = fm10k_tlv_attr_get_u8(results[FM10K_TEST_MSG_U8],
792 if (!err && test_u8 != result_u8)
793 err = FM10K_ERR_INVALID_VALUE;
797 if (!!results[FM10K_TEST_MSG_U16]) {
798 err = fm10k_tlv_attr_get_u16(results[FM10K_TEST_MSG_U16],
800 if (!err && test_u16 != result_u16)
801 err = FM10K_ERR_INVALID_VALUE;
805 if (!!results[FM10K_TEST_MSG_U32]) {
806 err = fm10k_tlv_attr_get_u32(results[FM10K_TEST_MSG_U32],
808 if (!err && test_u32 != result_u32)
809 err = FM10K_ERR_INVALID_VALUE;
813 if (!!results[FM10K_TEST_MSG_U64]) {
814 err = fm10k_tlv_attr_get_u64(results[FM10K_TEST_MSG_U64],
816 if (!err && test_u64 != result_u64)
817 err = FM10K_ERR_INVALID_VALUE;
821 if (!!results[FM10K_TEST_MSG_S8]) {
822 err = fm10k_tlv_attr_get_s8(results[FM10K_TEST_MSG_S8],
824 if (!err && test_s8 != result_s8)
825 err = FM10K_ERR_INVALID_VALUE;
829 if (!!results[FM10K_TEST_MSG_S16]) {
830 err = fm10k_tlv_attr_get_s16(results[FM10K_TEST_MSG_S16],
832 if (!err && test_s16 != result_s16)
833 err = FM10K_ERR_INVALID_VALUE;
837 if (!!results[FM10K_TEST_MSG_S32]) {
838 err = fm10k_tlv_attr_get_s32(results[FM10K_TEST_MSG_S32],
840 if (!err && test_s32 != result_s32)
841 err = FM10K_ERR_INVALID_VALUE;
845 if (!!results[FM10K_TEST_MSG_S64]) {
846 err = fm10k_tlv_attr_get_s64(results[FM10K_TEST_MSG_S64],
848 if (!err && test_s64 != result_s64)
849 err = FM10K_ERR_INVALID_VALUE;
853 if (!!results[FM10K_TEST_MSG_LE_STRUCT]) {
854 err = fm10k_tlv_attr_get_le_struct(
855 results[FM10K_TEST_MSG_LE_STRUCT],
858 if (!err && memcmp(test_le, result_le, sizeof(test_le)))
859 err = FM10K_ERR_INVALID_VALUE;
864 if (!!results[FM10K_TEST_MSG_NESTED]) {
865 /* clear any pointers */
866 memset(nest_results, 0, sizeof(nest_results));
868 /* parse the nested attributes into the nest results list */
869 err = fm10k_tlv_attr_parse(results[FM10K_TEST_MSG_NESTED],
871 fm10k_tlv_msg_test_attr);
875 /* loop back through to the start */
876 results = nest_results;
881 /* generate reply with test result */
882 fm10k_tlv_msg_init(reply, FM10K_TLV_MSG_ID_TEST);
883 fm10k_tlv_attr_put_s32(reply, FM10K_TEST_MSG_RESULT, err);
885 /* load onto outgoing mailbox */
886 return mbx->ops.enqueue_tx(hw, mbx, reply);