Lines Matching +full:value +full:- +full:start

1 // SPDX-License-Identifier: GPL-2.0
14 * fbnic_tlv_msg_alloc - Allocate page and initialize FW message header
17 * Return: pointer to start of message, or NULL on failure.
19 * Allocates a page and initializes message header at start of page.
31 /* Start with zero filled header and then back fill with data */ in fbnic_tlv_msg_alloc()
36 /* Copy header into start of message */ in fbnic_tlv_msg_alloc()
37 msg->hdr = hdr; in fbnic_tlv_msg_alloc()
43 * fbnic_tlv_attr_put_flag - Add flag value to message
47 * Return: -ENOSPC if there is no room for the attribute. Otherwise 0.
50 * attribute can be used as a boolean value indicating true, otherwise the
51 * value is considered false.
55 int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg); in fbnic_tlv_attr_put_flag()
59 attr_max_len -= le16_to_cpu(msg->hdr.len) * sizeof(u32); in fbnic_tlv_attr_put_flag()
61 return -ENOSPC; in fbnic_tlv_attr_put_flag()
63 /* Get header pointer and bump attr to start of data */ in fbnic_tlv_attr_put_flag()
64 attr = &msg[le16_to_cpu(msg->hdr.len)]; in fbnic_tlv_attr_put_flag()
70 attr->hdr = hdr; in fbnic_tlv_attr_put_flag()
71 le16_add_cpu(&msg->hdr.len, in fbnic_tlv_attr_put_flag()
78 * fbnic_tlv_attr_put_value - Add data to message
81 * @value: Pointer to data to be stored
84 * Return: -ENOSPC if there is no room for the attribute. Otherwise 0.
86 * Adds header and copies data pointed to by value into the message. The
90 * The assumption is that the value field is in a format where byte
95 const void *value, const int len) in fbnic_tlv_attr_put_value() argument
97 int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg); in fbnic_tlv_attr_put_value()
101 attr_max_len -= le16_to_cpu(msg->hdr.len) * sizeof(u32); in fbnic_tlv_attr_put_value()
103 return -ENOSPC; in fbnic_tlv_attr_put_value()
105 /* Get header pointer and bump attr to start of data */ in fbnic_tlv_attr_put_value()
106 attr = &msg[le16_to_cpu(msg->hdr.len)]; in fbnic_tlv_attr_put_value()
114 attr->value[len / sizeof(hdr)] = 0; in fbnic_tlv_attr_put_value()
117 memcpy(attr->value, value, len); in fbnic_tlv_attr_put_value()
119 attr->hdr = hdr; in fbnic_tlv_attr_put_value()
120 le16_add_cpu(&msg->hdr.len, in fbnic_tlv_attr_put_value()
127 * __fbnic_tlv_attr_put_int - Add integer to message
130 * @value: Data to be stored
133 * Return: -ENOSPC if there is no room for the attribute. Otherwise 0.
135 * Adds header and copies data pointed to by value into the message. Will
139 s64 value, const int len) in __fbnic_tlv_attr_put_int() argument
141 __le64 le64_value = cpu_to_le64(value); in __fbnic_tlv_attr_put_int()
147 * fbnic_tlv_attr_put_mac_addr - Add mac_addr to message
152 * Return: -ENOSPC if there is no room for the attribute. Otherwise 0.
155 * copy the address raw so it will be in big endian with start of MAC
156 * address at start of attribute.
165 * fbnic_tlv_attr_put_string - Add string to message
170 * Return: -ENOSPC if there is no room for the attribute. Otherwise 0.
178 int attr_max_len = PAGE_SIZE - sizeof(*msg); in fbnic_tlv_attr_put_string()
186 * the final value, so start with that as our initial value. in fbnic_tlv_attr_put_string()
190 attr_max_len -= le16_to_cpu(msg->hdr.len) * sizeof(u32); in fbnic_tlv_attr_put_string()
197 * fbnic_tlv_attr_get_unsigned - Retrieve unsigned value from result
200 * Return: unsigned 64b value containing integer value
206 memcpy(&le64_value, &attr->value[0], in fbnic_tlv_attr_get_unsigned()
207 le16_to_cpu(attr->hdr.len) - sizeof(*attr)); in fbnic_tlv_attr_get_unsigned()
213 * fbnic_tlv_attr_get_signed - Retrieve signed value from result
216 * Return: signed 64b value containing integer value
220 int shift = (8 + sizeof(*attr) - le16_to_cpu(attr->hdr.len)) * 8; in fbnic_tlv_attr_get_signed()
222 s64 value; in fbnic_tlv_attr_get_signed() local
224 /* Copy the value and adjust for byte ordering */ in fbnic_tlv_attr_get_signed()
225 memcpy(&le64_value, &attr->value[0], in fbnic_tlv_attr_get_signed()
226 le16_to_cpu(attr->hdr.len) - sizeof(*attr)); in fbnic_tlv_attr_get_signed()
227 value = le64_to_cpu(le64_value); in fbnic_tlv_attr_get_signed()
229 /* Sign extend the return value by using a pair of shifts */ in fbnic_tlv_attr_get_signed()
230 return (value << shift) >> shift; in fbnic_tlv_attr_get_signed()
234 * fbnic_tlv_attr_get_string - Retrieve string value from result
245 (le16_to_cpu(attr->hdr.len) * 4) - sizeof(*attr)); in fbnic_tlv_attr_get_string()
246 memcpy(str, &attr->value, max_size); in fbnic_tlv_attr_get_string()
252 * fbnic_tlv_attr_nest_start - Add nested attribute header to message
264 int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg); in fbnic_tlv_attr_nest_start()
265 struct fbnic_tlv_msg *attr = &msg[le16_to_cpu(msg->hdr.len)]; in fbnic_tlv_attr_nest_start()
269 attr_max_len -= le16_to_cpu(msg->hdr.len) * sizeof(u32); in fbnic_tlv_attr_nest_start()
282 attr->hdr = hdr; in fbnic_tlv_attr_nest_start()
288 * fbnic_tlv_attr_nest_stop - Close out nested attribute and add it to message
296 struct fbnic_tlv_msg *attr = &msg[le16_to_cpu(msg->hdr.len)]; in fbnic_tlv_attr_nest_stop()
297 u16 len = le16_to_cpu(attr->hdr.len); in fbnic_tlv_attr_nest_stop()
303 le16_add_cpu(&msg->hdr.len, len); in fbnic_tlv_attr_nest_stop()
306 attr->hdr.len = cpu_to_le16(len * sizeof(u32)); in fbnic_tlv_attr_nest_stop()
313 u16 len = le16_to_cpu(attr->hdr.len) - sizeof(*attr); in fbnic_tlv_attr_validate()
314 u16 attr_id = attr->hdr.type; in fbnic_tlv_attr_validate()
315 __le32 *value = &attr->value[0]; in fbnic_tlv_attr_validate() local
317 if (attr->hdr.is_msg) in fbnic_tlv_attr_validate()
318 return -EINVAL; in fbnic_tlv_attr_validate()
321 return -EINVAL; in fbnic_tlv_attr_validate()
323 while (tlv_index->id != attr_id) { in fbnic_tlv_attr_validate()
324 if (tlv_index->id == FBNIC_TLV_ATTR_ID_UNKNOWN) { in fbnic_tlv_attr_validate()
325 if (attr->hdr.cannot_ignore) in fbnic_tlv_attr_validate()
326 return -ENOENT; in fbnic_tlv_attr_validate()
327 return le16_to_cpu(attr->hdr.len); in fbnic_tlv_attr_validate()
333 if (offset_in_page(attr) + len > PAGE_SIZE - sizeof(*attr)) in fbnic_tlv_attr_validate()
334 return -E2BIG; in fbnic_tlv_attr_validate()
336 switch (tlv_index->type) { in fbnic_tlv_attr_validate()
338 if (!len || len > tlv_index->len) in fbnic_tlv_attr_validate()
339 return -EINVAL; in fbnic_tlv_attr_validate()
340 if (((char *)value)[len - 1]) in fbnic_tlv_attr_validate()
341 return -EINVAL; in fbnic_tlv_attr_validate()
345 return -EINVAL; in fbnic_tlv_attr_validate()
349 if (tlv_index->len > sizeof(__le64)) in fbnic_tlv_attr_validate()
350 return -EINVAL; in fbnic_tlv_attr_validate()
353 if (!len || len > tlv_index->len) in fbnic_tlv_attr_validate()
354 return -EINVAL; in fbnic_tlv_attr_validate()
359 return -EINVAL; in fbnic_tlv_attr_validate()
362 return -EINVAL; in fbnic_tlv_attr_validate()
369 * fbnic_tlv_attr_parse_array - Parse array of attributes into results array
370 * @attr: Start of attributes in the message
377 * Return: zero on success, or negative value on error.
398 u16 attr_id = attr->hdr.type; in fbnic_tlv_attr_parse_array()
403 return -EINVAL; in fbnic_tlv_attr_parse_array()
411 return -ENOSPC; in fbnic_tlv_attr_parse_array()
415 attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); in fbnic_tlv_attr_parse_array()
416 len -= attr_len; in fbnic_tlv_attr_parse_array()
420 return len == 0 ? 0 : -EINVAL; in fbnic_tlv_attr_parse_array()
424 * fbnic_tlv_attr_parse - Parse attributes into a list of attribute results
425 * @attr: Start of attributes in the message
430 * Return: zero on success, or negative value on error.
449 u16 attr_id = attr->hdr.type; in fbnic_tlv_attr_parse()
460 return -EADDRINUSE; in fbnic_tlv_attr_parse()
465 attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); in fbnic_tlv_attr_parse()
466 len -= attr_len; in fbnic_tlv_attr_parse()
470 return len == 0 ? 0 : -EINVAL; in fbnic_tlv_attr_parse()
474 * fbnic_tlv_msg_parse - Parse message and process via predetermined functions
475 * @opaque: Value passed to parser function to enable driver access
479 * Return: zero on success, or negative value on error.
488 u16 msg_id = msg->hdr.type; in fbnic_tlv_msg_parse()
491 if (!msg->hdr.is_msg) in fbnic_tlv_msg_parse()
492 return -EINVAL; in fbnic_tlv_msg_parse()
494 if (le16_to_cpu(msg->hdr.len) > PAGE_SIZE / sizeof(u32)) in fbnic_tlv_msg_parse()
495 return -E2BIG; in fbnic_tlv_msg_parse()
497 while (parser->id != msg_id) { in fbnic_tlv_msg_parse()
498 if (parser->id == FBNIC_TLV_MSG_ID_UNKNOWN) in fbnic_tlv_msg_parse()
499 return -ENOENT; in fbnic_tlv_msg_parse()
503 err = fbnic_tlv_attr_parse(&msg[1], le16_to_cpu(msg->hdr.len) - 1, in fbnic_tlv_msg_parse()
504 results, parser->attr); in fbnic_tlv_msg_parse()
508 return parser->func(opaque, results); in fbnic_tlv_msg_parse()
512 * fbnic_tlv_parser_error - called if message doesn't match known type
516 * Return: -EBADMSG to indicate the message is an unsupported type
520 return -EBADMSG; in fbnic_tlv_parser_error()