1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
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.
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
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
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
21 #include "fm10k_tlv.h"
24 * fm10k_tlv_msg_init - Initialize message block for TLV data storage
25 * @msg: Pointer to message block
26 * @msg_id: Message ID indicating message type
28 * This function return success if provided with a valid message pointer
30 s32 fm10k_tlv_msg_init(u32 *msg, u16 msg_id)
32 /* verify pointer is not NULL */
34 return FM10K_ERR_PARAM;
36 *msg = (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT) | msg_id;
42 * fm10k_tlv_attr_put_null_string - Place null terminated string on message
43 * @msg: Pointer to message block
44 * @attr_id: Attribute ID
45 * @string: Pointer to string to be stored in attribute
47 * This function will reorder a string to be CPU endian and store it in
48 * the attribute buffer. It will return success if provided with a valid
51 s32 fm10k_tlv_attr_put_null_string(u32 *msg, u16 attr_id,
52 const unsigned char *string)
54 u32 attr_data = 0, len = 0;
57 /* verify pointers are not NULL */
59 return FM10K_ERR_PARAM;
61 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
63 /* copy string into local variable and then write to msg */
65 /* write data to message */
66 if (len && !(len % 4)) {
67 attr[len / 4] = attr_data;
71 /* record character to offset location */
72 attr_data |= (u32)(*string) << (8 * (len % 4));
75 /* test for NULL and then increment */
76 } while (*(string++));
78 /* write last piece of data to message */
79 attr[(len + 3) / 4] = attr_data;
81 /* record attribute header, update message length */
82 len <<= FM10K_TLV_LEN_SHIFT;
83 attr[0] = len | attr_id;
85 /* add header length to length */
86 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
87 *msg += FM10K_TLV_LEN_ALIGN(len);
93 * fm10k_tlv_attr_get_null_string - Get null terminated string from attribute
94 * @attr: Pointer to attribute
95 * @string: Pointer to location of destination string
97 * This function pulls the string back out of the attribute and will place
98 * it in the array pointed by by string. It will return success if provided
99 * with a valid pointers.
101 s32 fm10k_tlv_attr_get_null_string(u32 *attr, unsigned char *string)
105 /* verify pointers are not NULL */
106 if (!string || !attr)
107 return FM10K_ERR_PARAM;
109 len = *attr >> FM10K_TLV_LEN_SHIFT;
113 string[len] = (u8)(attr[len / 4] >> (8 * (len % 4)));
119 * fm10k_tlv_attr_put_mac_vlan - Store MAC/VLAN attribute in message
120 * @msg: Pointer to message block
121 * @attr_id: Attribute ID
122 * @mac_addr: MAC address to be stored
124 * This function will reorder a MAC address to be CPU endian and store it
125 * in the attribute buffer. It will return success if provided with a
128 s32 fm10k_tlv_attr_put_mac_vlan(u32 *msg, u16 attr_id,
129 const u8 *mac_addr, u16 vlan)
131 u32 len = ETH_ALEN << FM10K_TLV_LEN_SHIFT;
134 /* verify pointers are not NULL */
135 if (!msg || !mac_addr)
136 return FM10K_ERR_PARAM;
138 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
140 /* record attribute header, update message length */
141 attr[0] = len | attr_id;
143 /* copy value into local variable and then write to msg */
144 attr[1] = le32_to_cpu(*(const __le32 *)&mac_addr[0]);
145 attr[2] = le16_to_cpu(*(const __le16 *)&mac_addr[4]);
146 attr[2] |= (u32)vlan << 16;
148 /* add header length to length */
149 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
150 *msg += FM10K_TLV_LEN_ALIGN(len);
156 * fm10k_tlv_attr_get_mac_vlan - Get MAC/VLAN stored in attribute
157 * @attr: Pointer to attribute
158 * @attr_id: Attribute ID
159 * @mac_addr: location of buffer to store MAC address
161 * This function pulls the MAC address back out of the attribute and will
162 * place it in the array pointed by by mac_addr. It will return success
163 * if provided with a valid pointers.
165 s32 fm10k_tlv_attr_get_mac_vlan(u32 *attr, u8 *mac_addr, u16 *vlan)
167 /* verify pointers are not NULL */
168 if (!mac_addr || !attr)
169 return FM10K_ERR_PARAM;
171 *(__le32 *)&mac_addr[0] = cpu_to_le32(attr[1]);
172 *(__le16 *)&mac_addr[4] = cpu_to_le16((u16)(attr[2]));
173 *vlan = (u16)(attr[2] >> 16);
179 * fm10k_tlv_attr_put_bool - Add header indicating value "true"
180 * @msg: Pointer to message block
181 * @attr_id: Attribute ID
183 * This function will simply add an attribute header, the fact
184 * that the header is here means the attribute value is true, else
185 * it is false. The function will return success if provided with a
188 s32 fm10k_tlv_attr_put_bool(u32 *msg, u16 attr_id)
190 /* verify pointers are not NULL */
192 return FM10K_ERR_PARAM;
194 /* record attribute header */
195 msg[FM10K_TLV_DWORD_LEN(*msg)] = attr_id;
197 /* add header length to length */
198 *msg += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
204 * fm10k_tlv_attr_put_value - Store integer value attribute in message
205 * @msg: Pointer to message block
206 * @attr_id: Attribute ID
207 * @value: Value to be written
208 * @len: Size of value
210 * This function will place an integer value of up to 8 bytes in size
211 * in a message attribute. The function will return success provided
212 * that msg is a valid pointer, and len is 1, 2, 4, or 8.
214 s32 fm10k_tlv_attr_put_value(u32 *msg, u16 attr_id, s64 value, u32 len)
218 /* verify non-null msg and len is 1, 2, 4, or 8 */
219 if (!msg || !len || len > 8 || (len & (len - 1)))
220 return FM10K_ERR_PARAM;
222 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
225 attr[1] = (u32)value & ((0x1ul << (8 * len)) - 1);
227 attr[1] = (u32)value;
229 attr[2] = (u32)(value >> 32);
232 /* record attribute header, update message length */
233 len <<= FM10K_TLV_LEN_SHIFT;
234 attr[0] = len | attr_id;
236 /* add header length to length */
237 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
238 *msg += FM10K_TLV_LEN_ALIGN(len);
244 * fm10k_tlv_attr_get_value - Get integer value stored in attribute
245 * @attr: Pointer to attribute
246 * @value: Pointer to destination buffer
247 * @len: Size of value
249 * This function will place an integer value of up to 8 bytes in size
250 * in the offset pointed to by value. The function will return success
251 * provided that pointers are valid and the len value matches the
254 s32 fm10k_tlv_attr_get_value(u32 *attr, void *value, u32 len)
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];
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 /* verify non-null msg and len is in 32 bit words */
294 if (!msg || !len || (len % 4))
295 return FM10K_ERR_PARAM;
297 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
299 /* copy le32 structure into host byte order at 32b boundaries */
300 for (i = 0; i < (len / 4); i++)
301 attr[i + 1] = le32_to_cpu(le32_ptr[i]);
303 /* record attribute header, update message length */
304 len <<= FM10K_TLV_LEN_SHIFT;
305 attr[0] = len | attr_id;
307 /* add header length to length */
308 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
309 *msg += FM10K_TLV_LEN_ALIGN(len);
315 * fm10k_tlv_attr_get_le_struct - Get little endian struct form attribute
316 * @attr: Pointer to attribute
317 * @le_struct: Pointer to structure to be written
318 * @len: Size of structure
320 * This function will place a little endian structure in the buffer
321 * pointed to by le_struct. The function will return success
322 * provided that pointers are valid and the len value matches the
325 s32 fm10k_tlv_attr_get_le_struct(u32 *attr, void *le_struct, u32 len)
327 __le32 *le32_ptr = (__le32 *)le_struct;
330 /* verify pointers are not NULL */
331 if (!le_struct || !attr)
332 return FM10K_ERR_PARAM;
334 if ((*attr >> FM10K_TLV_LEN_SHIFT) != len)
335 return FM10K_ERR_PARAM;
339 for (i = 0; len; i++, len -= 4)
340 le32_ptr[i] = cpu_to_le32(attr[i]);
346 * fm10k_tlv_attr_nest_start - Start a set of nested attributes
347 * @msg: Pointer to message block
348 * @attr_id: Attribute ID
350 * This function will mark off a new nested region for encapsulating
351 * a given set of attributes. The idea is if you wish to place a secondary
352 * structure within the message this mechanism allows for that. The
353 * function will return NULL on failure, and a pointer to the start
354 * of the nested attributes on success.
356 u32 *fm10k_tlv_attr_nest_start(u32 *msg, u16 attr_id)
360 /* verify pointer is not NULL */
364 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
368 /* return pointer to nest header */
373 * fm10k_tlv_attr_nest_start - Start a set of nested attributes
374 * @msg: Pointer to message block
376 * This function closes off an existing set of nested attributes. The
377 * message pointer should be pointing to the parent of the nest. So in
378 * the case of a nest within the nest this would be the outer nest pointer.
379 * This function will return success provided all pointers are valid.
381 s32 fm10k_tlv_attr_nest_stop(u32 *msg)
386 /* verify pointer is not NULL */
388 return FM10K_ERR_PARAM;
390 /* locate the nested header and retrieve its length */
391 attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
392 len = (attr[0] >> FM10K_TLV_LEN_SHIFT) << FM10K_TLV_LEN_SHIFT;
394 /* only include nest if data was added to it */
396 len += FM10K_TLV_HDR_LEN << FM10K_TLV_LEN_SHIFT;
404 * fm10k_tlv_attr_validate - Validate attribute metadata
405 * @attr: Pointer to attribute
406 * @tlv_attr: Type and length info for attribute
408 * This function does some basic validation of the input TLV. It
409 * verifies the length, and in the case of null terminated strings
410 * it verifies that the last byte is null. The function will
411 * return FM10K_ERR_PARAM if any attribute is malformed, otherwise
414 static s32 fm10k_tlv_attr_validate(u32 *attr,
415 const struct fm10k_tlv_attr *tlv_attr)
417 u32 attr_id = *attr & FM10K_TLV_ID_MASK;
418 u16 len = *attr >> FM10K_TLV_LEN_SHIFT;
420 /* verify this is an attribute and not a message */
421 if (*attr & (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT))
422 return FM10K_ERR_PARAM;
424 /* search through the list of attributes to find a matching ID */
425 while (tlv_attr->id < attr_id)
428 /* if didn't find a match then we should exit */
429 if (tlv_attr->id != attr_id)
430 return FM10K_NOT_IMPLEMENTED;
432 /* move to start of attribute data */
435 switch (tlv_attr->type) {
436 case FM10K_TLV_NULL_STRING:
438 (attr[(len - 1) / 4] & (0xFF << (8 * ((len - 1) % 4)))))
439 return FM10K_ERR_PARAM;
440 if (len > tlv_attr->len)
441 return FM10K_ERR_PARAM;
443 case FM10K_TLV_MAC_ADDR:
445 return FM10K_ERR_PARAM;
449 return FM10K_ERR_PARAM;
451 case FM10K_TLV_UNSIGNED:
452 case FM10K_TLV_SIGNED:
453 if (len != tlv_attr->len)
454 return FM10K_ERR_PARAM;
456 case FM10K_TLV_LE_STRUCT:
457 /* struct must be 4 byte aligned */
458 if ((len % 4) || len != tlv_attr->len)
459 return FM10K_ERR_PARAM;
461 case FM10K_TLV_NESTED:
462 /* nested attributes must be 4 byte aligned */
464 return FM10K_ERR_PARAM;
467 /* attribute id is mapped to bad value */
468 return FM10K_ERR_PARAM;
475 * fm10k_tlv_attr_parse - Parses stream of attribute data
476 * @attr: Pointer to attribute list
477 * @results: Pointer array to store pointers to attributes
478 * @tlv_attr: Type and length info for attributes
480 * This function validates a stream of attributes and parses them
481 * up into an array of pointers stored in results. The function will
482 * return FM10K_ERR_PARAM on any input or message error,
483 * FM10K_NOT_IMPLEMENTED for any attribute that is outside of the array
486 s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results,
487 const struct fm10k_tlv_attr *tlv_attr)
489 u32 i, attr_id, offset = 0;
493 /* verify pointers are not NULL */
494 if (!attr || !results)
495 return FM10K_ERR_PARAM;
497 /* initialize results to NULL */
498 for (i = 0; i < FM10K_TLV_RESULTS_MAX; i++)
501 /* pull length from the message header */
502 len = *attr >> FM10K_TLV_LEN_SHIFT;
504 /* no attributes to parse if there is no length */
508 /* no attributes to parse, just raw data, message becomes attribute */
514 /* move to start of attribute data */
517 /* run through list parsing all attributes */
518 while (offset < len) {
519 attr_id = *attr & FM10K_TLV_ID_MASK;
521 if (attr_id < FM10K_TLV_RESULTS_MAX)
522 err = fm10k_tlv_attr_validate(attr, tlv_attr);
524 err = FM10K_NOT_IMPLEMENTED;
529 results[attr_id] = attr;
532 offset += FM10K_TLV_DWORD_LEN(*attr) * 4;
534 /* move to next attribute */
535 attr = &attr[FM10K_TLV_DWORD_LEN(*attr)];
538 /* we should find ourselves at the end of the list */
540 return FM10K_ERR_PARAM;
546 * fm10k_tlv_msg_parse - Parses message header and calls function handler
547 * @hw: Pointer to hardware structure
548 * @msg: Pointer to message
549 * @mbx: Pointer to mailbox information structure
550 * @func: Function array containing list of message handling functions
552 * This function should be the first function called upon receiving a
553 * message. The handler will identify the message type and call the correct
554 * handler for the given message. It will return the value from the function
555 * call on a recognized message type, otherwise it will return
556 * FM10K_NOT_IMPLEMENTED on an unrecognized type.
558 s32 fm10k_tlv_msg_parse(struct fm10k_hw *hw, u32 *msg,
559 struct fm10k_mbx_info *mbx,
560 const struct fm10k_msg_data *data)
562 u32 *results[FM10K_TLV_RESULTS_MAX];
566 /* verify pointer is not NULL */
568 return FM10K_ERR_PARAM;
570 /* verify this is a message and not an attribute */
571 if (!(*msg & (FM10K_TLV_FLAGS_MSG << FM10K_TLV_FLAGS_SHIFT)))
572 return FM10K_ERR_PARAM;
574 /* grab message ID */
575 msg_id = *msg & FM10K_TLV_ID_MASK;
577 while (data->id < msg_id)
580 /* if we didn't find it then pass it up as an error */
581 if (data->id != msg_id) {
582 while (data->id != FM10K_TLV_ERROR)
586 /* parse the attributes into the results list */
587 err = fm10k_tlv_attr_parse(msg, results, data->attr);
591 return data->func(hw, results, mbx);
595 * fm10k_tlv_msg_error - Default handler for unrecognized TLV message IDs
596 * @hw: Pointer to hardware structure
597 * @results: Pointer array to message, results[0] is pointer to message
598 * @mbx: Unused mailbox pointer
600 * This function is a default handler for unrecognized messages. At a
601 * a minimum it just indicates that the message requested was
604 s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
605 struct fm10k_mbx_info *mbx)
607 return FM10K_NOT_IMPLEMENTED;
610 static const unsigned char test_str[] = "fm10k";
611 static const unsigned char test_mac[ETH_ALEN] = { 0x12, 0x34, 0x56,
613 static const u16 test_vlan = 0x0FED;
614 static const u64 test_u64 = 0xfedcba9876543210ull;
615 static const u32 test_u32 = 0x87654321;
616 static const u16 test_u16 = 0x8765;
617 static const u8 test_u8 = 0x87;
618 static const s64 test_s64 = -0x123456789abcdef0ll;
619 static const s32 test_s32 = -0x1235678;
620 static const s16 test_s16 = -0x1234;
621 static const s8 test_s8 = -0x12;
622 static const __le32 test_le[2] = { cpu_to_le32(0x12345678),
623 cpu_to_le32(0x9abcdef0)};
625 /* The message below is meant to be used as a test message to demonstrate
626 * how to use the TLV interface and to test the types. Normally this code
627 * be compiled out by stripping the code wrapped in FM10K_TLV_TEST_MSG
629 const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[] = {
630 FM10K_TLV_ATTR_NULL_STRING(FM10K_TEST_MSG_STRING, 80),
631 FM10K_TLV_ATTR_MAC_ADDR(FM10K_TEST_MSG_MAC_ADDR),
632 FM10K_TLV_ATTR_U8(FM10K_TEST_MSG_U8),
633 FM10K_TLV_ATTR_U16(FM10K_TEST_MSG_U16),
634 FM10K_TLV_ATTR_U32(FM10K_TEST_MSG_U32),
635 FM10K_TLV_ATTR_U64(FM10K_TEST_MSG_U64),
636 FM10K_TLV_ATTR_S8(FM10K_TEST_MSG_S8),
637 FM10K_TLV_ATTR_S16(FM10K_TEST_MSG_S16),
638 FM10K_TLV_ATTR_S32(FM10K_TEST_MSG_S32),
639 FM10K_TLV_ATTR_S64(FM10K_TEST_MSG_S64),
640 FM10K_TLV_ATTR_LE_STRUCT(FM10K_TEST_MSG_LE_STRUCT, 8),
641 FM10K_TLV_ATTR_NESTED(FM10K_TEST_MSG_NESTED),
642 FM10K_TLV_ATTR_S32(FM10K_TEST_MSG_RESULT),
647 * fm10k_tlv_msg_test_generate_data - Stuff message with data
648 * @msg: Pointer to message
649 * @attr_flags: List of flags indicating what attributes to add
651 * This function is meant to load a message buffer with attribute data
653 static void fm10k_tlv_msg_test_generate_data(u32 *msg, u32 attr_flags)
655 if (attr_flags & (1 << FM10K_TEST_MSG_STRING))
656 fm10k_tlv_attr_put_null_string(msg, FM10K_TEST_MSG_STRING,
658 if (attr_flags & (1 << FM10K_TEST_MSG_MAC_ADDR))
659 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_TEST_MSG_MAC_ADDR,
660 test_mac, test_vlan);
661 if (attr_flags & (1 << FM10K_TEST_MSG_U8))
662 fm10k_tlv_attr_put_u8(msg, FM10K_TEST_MSG_U8, test_u8);
663 if (attr_flags & (1 << FM10K_TEST_MSG_U16))
664 fm10k_tlv_attr_put_u16(msg, FM10K_TEST_MSG_U16, test_u16);
665 if (attr_flags & (1 << FM10K_TEST_MSG_U32))
666 fm10k_tlv_attr_put_u32(msg, FM10K_TEST_MSG_U32, test_u32);
667 if (attr_flags & (1 << FM10K_TEST_MSG_U64))
668 fm10k_tlv_attr_put_u64(msg, FM10K_TEST_MSG_U64, test_u64);
669 if (attr_flags & (1 << FM10K_TEST_MSG_S8))
670 fm10k_tlv_attr_put_s8(msg, FM10K_TEST_MSG_S8, test_s8);
671 if (attr_flags & (1 << FM10K_TEST_MSG_S16))
672 fm10k_tlv_attr_put_s16(msg, FM10K_TEST_MSG_S16, test_s16);
673 if (attr_flags & (1 << FM10K_TEST_MSG_S32))
674 fm10k_tlv_attr_put_s32(msg, FM10K_TEST_MSG_S32, test_s32);
675 if (attr_flags & (1 << FM10K_TEST_MSG_S64))
676 fm10k_tlv_attr_put_s64(msg, FM10K_TEST_MSG_S64, test_s64);
677 if (attr_flags & (1 << FM10K_TEST_MSG_LE_STRUCT))
678 fm10k_tlv_attr_put_le_struct(msg, FM10K_TEST_MSG_LE_STRUCT,
683 * fm10k_tlv_msg_test_create - Create a test message testing all attributes
684 * @msg: Pointer to message
685 * @attr_flags: List of flags indicating what attributes to add
687 * This function is meant to load a message buffer with all attribute types
688 * including a nested attribute.
690 void fm10k_tlv_msg_test_create(u32 *msg, u32 attr_flags)
694 fm10k_tlv_msg_init(msg, FM10K_TLV_MSG_ID_TEST);
696 fm10k_tlv_msg_test_generate_data(msg, attr_flags);
698 /* check for nested attributes */
699 attr_flags >>= FM10K_TEST_MSG_NESTED;
702 nest = fm10k_tlv_attr_nest_start(msg, FM10K_TEST_MSG_NESTED);
704 fm10k_tlv_msg_test_generate_data(nest, attr_flags);
706 fm10k_tlv_attr_nest_stop(msg);
711 * fm10k_tlv_msg_test - Validate all results on test message receive
712 * @hw: Pointer to hardware structure
713 * @results: Pointer array to attributes in the message
714 * @mbx: Pointer to mailbox information structure
716 * This function does a check to verify all attributes match what the test
717 * message placed in the message buffer. It is the default handler
718 * for TLV test messages.
720 s32 fm10k_tlv_msg_test(struct fm10k_hw *hw, u32 **results,
721 struct fm10k_mbx_info *mbx)
723 u32 *nest_results[FM10K_TLV_RESULTS_MAX];
724 unsigned char result_str[80];
725 unsigned char result_mac[ETH_ALEN];
739 /* retrieve results of a previous test */
740 if (!!results[FM10K_TEST_MSG_RESULT])
741 return fm10k_tlv_attr_get_s32(results[FM10K_TEST_MSG_RESULT],
745 if (!!results[FM10K_TEST_MSG_STRING]) {
746 err = fm10k_tlv_attr_get_null_string(
747 results[FM10K_TEST_MSG_STRING],
749 if (!err && memcmp(test_str, result_str, sizeof(test_str)))
750 err = FM10K_ERR_INVALID_VALUE;
754 if (!!results[FM10K_TEST_MSG_MAC_ADDR]) {
755 err = fm10k_tlv_attr_get_mac_vlan(
756 results[FM10K_TEST_MSG_MAC_ADDR],
757 result_mac, &result_vlan);
758 if (!err && memcmp(test_mac, result_mac, ETH_ALEN))
759 err = FM10K_ERR_INVALID_VALUE;
760 if (!err && test_vlan != result_vlan)
761 err = FM10K_ERR_INVALID_VALUE;
765 if (!!results[FM10K_TEST_MSG_U8]) {
766 err = fm10k_tlv_attr_get_u8(results[FM10K_TEST_MSG_U8],
768 if (!err && test_u8 != result_u8)
769 err = FM10K_ERR_INVALID_VALUE;
773 if (!!results[FM10K_TEST_MSG_U16]) {
774 err = fm10k_tlv_attr_get_u16(results[FM10K_TEST_MSG_U16],
776 if (!err && test_u16 != result_u16)
777 err = FM10K_ERR_INVALID_VALUE;
781 if (!!results[FM10K_TEST_MSG_U32]) {
782 err = fm10k_tlv_attr_get_u32(results[FM10K_TEST_MSG_U32],
784 if (!err && test_u32 != result_u32)
785 err = FM10K_ERR_INVALID_VALUE;
789 if (!!results[FM10K_TEST_MSG_U64]) {
790 err = fm10k_tlv_attr_get_u64(results[FM10K_TEST_MSG_U64],
792 if (!err && test_u64 != result_u64)
793 err = FM10K_ERR_INVALID_VALUE;
797 if (!!results[FM10K_TEST_MSG_S8]) {
798 err = fm10k_tlv_attr_get_s8(results[FM10K_TEST_MSG_S8],
800 if (!err && test_s8 != result_s8)
801 err = FM10K_ERR_INVALID_VALUE;
805 if (!!results[FM10K_TEST_MSG_S16]) {
806 err = fm10k_tlv_attr_get_s16(results[FM10K_TEST_MSG_S16],
808 if (!err && test_s16 != result_s16)
809 err = FM10K_ERR_INVALID_VALUE;
813 if (!!results[FM10K_TEST_MSG_S32]) {
814 err = fm10k_tlv_attr_get_s32(results[FM10K_TEST_MSG_S32],
816 if (!err && test_s32 != result_s32)
817 err = FM10K_ERR_INVALID_VALUE;
821 if (!!results[FM10K_TEST_MSG_S64]) {
822 err = fm10k_tlv_attr_get_s64(results[FM10K_TEST_MSG_S64],
824 if (!err && test_s64 != result_s64)
825 err = FM10K_ERR_INVALID_VALUE;
829 if (!!results[FM10K_TEST_MSG_LE_STRUCT]) {
830 err = fm10k_tlv_attr_get_le_struct(
831 results[FM10K_TEST_MSG_LE_STRUCT],
834 if (!err && memcmp(test_le, result_le, sizeof(test_le)))
835 err = FM10K_ERR_INVALID_VALUE;
840 if (!!results[FM10K_TEST_MSG_NESTED]) {
841 /* clear any pointers */
842 memset(nest_results, 0, sizeof(nest_results));
844 /* parse the nested attributes into the nest results list */
845 err = fm10k_tlv_attr_parse(results[FM10K_TEST_MSG_NESTED],
847 fm10k_tlv_msg_test_attr);
851 /* loop back through to the start */
852 results = nest_results;
857 /* generate reply with test result */
858 fm10k_tlv_msg_init(reply, FM10K_TLV_MSG_ID_TEST);
859 fm10k_tlv_attr_put_s32(reply, FM10K_TEST_MSG_RESULT, err);
861 /* load onto outgoing mailbox */
862 return mbx->ops.enqueue_tx(hw, mbx, reply);