1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2012-2018 Solarflare Communications Inc.
10 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
12 #if EFSYS_OPT_VPD || EFSYS_OPT_NVRAM
14 #include "ef10_tlv_layout.h"
16 /* Cursor for TLV partition format */
17 typedef struct tlv_cursor_s {
18 uint32_t *block; /* Base of data block */
19 uint32_t *current; /* Cursor position */
20 uint32_t *end; /* End tag position */
21 uint32_t *limit; /* Last dword of data block */
24 typedef struct nvram_partition_s {
29 * The full length of the NVRAM partition.
30 * This is different from tlv_partition_header.total_length,
31 * which can be smaller.
36 tlv_cursor_t tlv_cursor;
40 static __checkReturn efx_rc_t
42 __inout tlv_cursor_t *cursor);
47 __out uint32_t *block)
49 *block = __CPU_TO_LE_32(TLV_TAG_END);
54 __in tlv_cursor_t *cursor)
58 dword = cursor->current[0];
59 tag = __LE_TO_CPU_32(dword);
66 __in tlv_cursor_t *cursor)
68 uint32_t dword, length;
70 if (tlv_tag(cursor) == TLV_TAG_END)
73 dword = cursor->current[1];
74 length = __LE_TO_CPU_32(dword);
76 return ((size_t)length);
81 __in tlv_cursor_t *cursor)
83 if (tlv_tag(cursor) == TLV_TAG_END)
86 return ((uint8_t *)(&cursor->current[2]));
91 __in tlv_cursor_t *cursor)
93 if (tlv_tag(cursor) == TLV_TAG_END)
96 return ((uint8_t *)cursor->current);
100 * TLV item DWORD length is tag + length + value (rounded up to DWORD)
101 * equivalent to tlv_n_words_for_len in mc-comms tlv.c
103 #define TLV_DWORD_COUNT(length) \
104 (1 + 1 + (((length) + sizeof (uint32_t) - 1) / sizeof (uint32_t)))
109 __in tlv_cursor_t *cursor)
113 length = tlv_length(cursor);
115 return (cursor->current + TLV_DWORD_COUNT(length));
118 static __checkReturn efx_rc_t
120 __inout tlv_cursor_t *cursor)
124 if ((rc = tlv_validate_state(cursor)) != 0)
127 if (cursor->current == cursor->end) {
128 /* No more tags after END tag */
129 cursor->current = NULL;
134 /* Advance to next item and validate */
135 cursor->current = tlv_next_item_ptr(cursor);
137 if ((rc = tlv_validate_state(cursor)) != 0)
147 EFSYS_PROBE1(fail1, efx_rc_t, rc);
154 __in tlv_cursor_t *cursor)
158 cursor->current = cursor->block;
160 if ((rc = tlv_validate_state(cursor)) != 0)
166 EFSYS_PROBE1(fail1, efx_rc_t, rc);
173 __inout tlv_cursor_t *cursor,
178 rc = tlv_rewind(cursor);
180 if (tlv_tag(cursor) == tag)
183 rc = tlv_advance(cursor);
188 static __checkReturn efx_rc_t
190 __inout tlv_cursor_t *cursor)
194 /* Check cursor position */
195 if (cursor->current < cursor->block) {
199 if (cursor->current > cursor->limit) {
204 if (tlv_tag(cursor) != TLV_TAG_END) {
205 /* Check current item has space for tag and length */
206 if (cursor->current > (cursor->limit - 2)) {
207 cursor->current = NULL;
212 /* Check we have value data for current item and another tag */
213 if (tlv_next_item_ptr(cursor) > (cursor->limit - 1)) {
214 cursor->current = NULL;
229 EFSYS_PROBE1(fail1, efx_rc_t, rc);
236 __out tlv_cursor_t *cursor,
237 __in uint32_t *block,
238 __in uint32_t *limit,
239 __in uint32_t *current)
241 cursor->block = block;
242 cursor->limit = limit;
244 cursor->current = current;
247 return (tlv_validate_state(cursor));
250 static __checkReturn efx_rc_t
251 tlv_init_cursor_from_size(
252 __out tlv_cursor_t *cursor,
258 limit = (uint32_t *)(block + size - sizeof (uint32_t));
259 return (tlv_init_cursor(cursor, (uint32_t *)block,
260 limit, (uint32_t *)block));
263 static __checkReturn efx_rc_t
264 tlv_init_cursor_at_offset(
265 __out tlv_cursor_t *cursor,
273 limit = (uint32_t *)(block + size - sizeof (uint32_t));
274 current = (uint32_t *)(block + offset);
275 return (tlv_init_cursor(cursor, (uint32_t *)block, limit, current));
278 static __checkReturn efx_rc_t
280 __inout tlv_cursor_t *cursor)
285 if (cursor->end == NULL) {
286 pos = cursor->current;
287 if ((rc = tlv_find(cursor, TLV_TAG_END)) != 0)
290 cursor->end = cursor->current;
291 cursor->current = pos;
297 EFSYS_PROBE1(fail1, efx_rc_t, rc);
303 tlv_block_length_used(
304 __inout tlv_cursor_t *cursor)
308 if ((rc = tlv_validate_state(cursor)) != 0)
311 if ((rc = tlv_require_end(cursor)) != 0)
314 /* Return space used (including the END tag) */
315 return (cursor->end + 1 - cursor->block) * sizeof (uint32_t);
320 EFSYS_PROBE1(fail1, efx_rc_t, rc);
326 tlv_last_segment_end(
327 __in tlv_cursor_t *cursor)
329 tlv_cursor_t segment_cursor;
330 uint32_t *last_segment_end = cursor->block;
331 uint32_t *segment_start = cursor->block;
334 * Go through each segment and check that it has an end tag. If there
335 * is no end tag then the previous segment was the last valid one,
336 * so return the pointer to its end tag.
339 if (tlv_init_cursor(&segment_cursor, segment_start,
340 cursor->limit, segment_start) != 0)
342 if (tlv_require_end(&segment_cursor) != 0)
344 last_segment_end = segment_cursor.end;
345 segment_start = segment_cursor.end + 1;
348 return (last_segment_end);
354 __in tlv_cursor_t *cursor,
356 __in_bcount(size) uint8_t *data,
362 ptr = cursor->current;
364 *ptr++ = __CPU_TO_LE_32(tag);
365 *ptr++ = __CPU_TO_LE_32(len);
368 ptr[(len - 1) / sizeof (uint32_t)] = 0;
369 memcpy(ptr, data, len);
370 ptr += P2ROUNDUP(len, sizeof (uint32_t)) / sizeof (*ptr);
376 static __checkReturn efx_rc_t
378 __inout tlv_cursor_t *cursor,
385 uint32_t *last_segment_end;
388 if ((rc = tlv_validate_state(cursor)) != 0)
391 if ((rc = tlv_require_end(cursor)) != 0)
394 if (tag == TLV_TAG_END) {
399 last_segment_end = tlv_last_segment_end(cursor);
401 delta = TLV_DWORD_COUNT(size);
402 if (last_segment_end + 1 + delta > cursor->limit) {
407 /* Move data up: new space at cursor->current */
408 memmove(cursor->current + delta, cursor->current,
409 (last_segment_end + 1 - cursor->current) * sizeof (uint32_t));
411 /* Adjust the end pointer */
412 cursor->end += delta;
414 /* Write new TLV item */
415 tlv_write(cursor, tag, data, size);
426 EFSYS_PROBE1(fail1, efx_rc_t, rc);
431 static __checkReturn efx_rc_t
433 __inout tlv_cursor_t *cursor)
436 uint32_t *last_segment_end;
439 if ((rc = tlv_validate_state(cursor)) != 0)
442 if (tlv_tag(cursor) == TLV_TAG_END) {
447 delta = TLV_DWORD_COUNT(tlv_length(cursor));
449 if ((rc = tlv_require_end(cursor)) != 0)
452 last_segment_end = tlv_last_segment_end(cursor);
454 /* Shuffle things down, destroying the item at cursor->current */
455 memmove(cursor->current, cursor->current + delta,
456 (last_segment_end + 1 - cursor->current) * sizeof (uint32_t));
457 /* Zero the new space at the end of the TLV chain */
458 memset(last_segment_end + 1 - delta, 0, delta * sizeof (uint32_t));
459 /* Adjust the end pointer */
460 cursor->end -= delta;
469 EFSYS_PROBE1(fail1, efx_rc_t, rc);
474 static __checkReturn efx_rc_t
476 __inout tlv_cursor_t *cursor,
483 unsigned int old_ndwords;
484 unsigned int new_ndwords;
486 uint32_t *last_segment_end;
489 if ((rc = tlv_validate_state(cursor)) != 0)
492 if (tlv_tag(cursor) == TLV_TAG_END) {
496 if (tlv_tag(cursor) != tag) {
501 old_ndwords = TLV_DWORD_COUNT(tlv_length(cursor));
502 new_ndwords = TLV_DWORD_COUNT(size);
504 if ((rc = tlv_require_end(cursor)) != 0)
507 last_segment_end = tlv_last_segment_end(cursor);
509 if (new_ndwords > old_ndwords) {
510 /* Expand space used for TLV item */
511 delta = new_ndwords - old_ndwords;
512 pos = cursor->current + old_ndwords;
514 if (last_segment_end + 1 + delta > cursor->limit) {
519 /* Move up: new space at (cursor->current + old_ndwords) */
520 memmove(pos + delta, pos,
521 (last_segment_end + 1 - pos) * sizeof (uint32_t));
523 /* Adjust the end pointer */
524 cursor->end += delta;
526 } else if (new_ndwords < old_ndwords) {
527 /* Shrink space used for TLV item */
528 delta = old_ndwords - new_ndwords;
529 pos = cursor->current + new_ndwords;
531 /* Move down: remove words at (cursor->current + new_ndwords) */
532 memmove(pos, pos + delta,
533 (last_segment_end + 1 - pos) * sizeof (uint32_t));
535 /* Zero the new space at the end of the TLV chain */
536 memset(last_segment_end + 1 - delta, 0,
537 delta * sizeof (uint32_t));
539 /* Adjust the end pointer */
540 cursor->end -= delta;
544 tlv_write(cursor, tag, data, size);
557 EFSYS_PROBE1(fail1, efx_rc_t, rc);
562 static uint32_t checksum_tlv_partition(
563 __in nvram_partition_t *partition)
565 tlv_cursor_t *cursor;
571 cursor = &partition->tlv_cursor;
572 len = tlv_block_length_used(cursor);
573 EFSYS_ASSERT3U((len & 3), ==, 0);
576 ptr = partition->data;
577 end = &ptr[len >> 2];
580 csum += __LE_TO_CPU_32(*ptr++);
585 static __checkReturn efx_rc_t
586 tlv_update_partition_len_and_cks(
587 __in tlv_cursor_t *cursor)
590 nvram_partition_t partition;
591 struct tlv_partition_header *header;
592 struct tlv_partition_trailer *trailer;
596 * We just modified the partition, so the total length may not be
597 * valid. Don't use tlv_find(), which performs some sanity checks
598 * that may fail here.
600 partition.data = cursor->block;
601 memcpy(&partition.tlv_cursor, cursor, sizeof (*cursor));
602 header = (struct tlv_partition_header *)partition.data;
604 if (__LE_TO_CPU_32(header->tag) != TLV_TAG_PARTITION_HEADER) {
608 new_len = tlv_block_length_used(&partition.tlv_cursor);
613 header->total_length = __CPU_TO_LE_32(new_len);
614 /* Ensure the modified partition always has a new generation count. */
615 header->generation = __CPU_TO_LE_32(
616 __LE_TO_CPU_32(header->generation) + 1);
618 trailer = (struct tlv_partition_trailer *)((uint8_t *)header +
619 new_len - sizeof (*trailer) - sizeof (uint32_t));
620 trailer->generation = header->generation;
621 trailer->checksum = __CPU_TO_LE_32(
622 __LE_TO_CPU_32(trailer->checksum) -
623 checksum_tlv_partition(&partition));
630 EFSYS_PROBE1(fail1, efx_rc_t, rc);
635 /* Validate buffer contents (before writing to flash) */
636 __checkReturn efx_rc_t
637 ef10_nvram_buffer_validate(
640 __in_bcount(partn_size) caddr_t partn_data,
641 __in size_t partn_size)
644 struct tlv_partition_header *header;
645 struct tlv_partition_trailer *trailer;
651 _NOTE(ARGUNUSED(enp, partn))
652 EFX_STATIC_ASSERT(sizeof (*header) <= EF10_NVRAM_CHUNK);
654 if ((partn_data == NULL) || (partn_size == 0)) {
659 /* The partition header must be the first item (at offset zero) */
660 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)partn_data,
665 if (tlv_tag(&cursor) != TLV_TAG_PARTITION_HEADER) {
669 header = (struct tlv_partition_header *)tlv_item(&cursor);
671 /* Check TLV partition length (includes the END tag) */
672 total_length = __LE_TO_CPU_32(header->total_length);
673 if (total_length > partn_size) {
678 /* Check partition ends with PARTITION_TRAILER and END tags */
679 if ((rc = tlv_find(&cursor, TLV_TAG_PARTITION_TRAILER)) != 0) {
683 trailer = (struct tlv_partition_trailer *)tlv_item(&cursor);
685 if ((rc = tlv_advance(&cursor)) != 0) {
689 if (tlv_tag(&cursor) != TLV_TAG_END) {
694 /* Check generation counts are consistent */
695 if (trailer->generation != header->generation) {
700 /* Verify partition checksum */
702 for (pos = 0; (size_t)pos < total_length; pos += sizeof (uint32_t)) {
703 cksum += *((uint32_t *)(partn_data + pos));
729 EFSYS_PROBE1(fail1, efx_rc_t, rc);
736 __checkReturn efx_rc_t
737 ef10_nvram_buffer_create(
739 __in uint16_t partn_type,
740 __in_bcount(partn_size) caddr_t partn_data,
741 __in size_t partn_size)
743 uint32_t *buf = (uint32_t *)partn_data;
746 struct tlv_partition_header header;
747 struct tlv_partition_trailer trailer;
749 unsigned int min_buf_size = sizeof (struct tlv_partition_header) +
750 sizeof (struct tlv_partition_trailer);
751 if (partn_size < min_buf_size) {
756 memset(buf, 0xff, partn_size);
759 if ((rc = tlv_init_cursor(&cursor, buf,
760 (uint32_t *)((uint8_t *)buf + partn_size),
765 header.tag = __CPU_TO_LE_32(TLV_TAG_PARTITION_HEADER);
766 header.length = __CPU_TO_LE_32(sizeof (header) - 8);
767 header.type_id = __CPU_TO_LE_16(partn_type);
769 header.generation = __CPU_TO_LE_32(1);
770 header.total_length = 0; /* This will be fixed below. */
771 if ((rc = tlv_insert(
772 &cursor, TLV_TAG_PARTITION_HEADER,
773 (uint8_t *)&header.type_id, sizeof (header) - 8)) != 0)
775 if ((rc = tlv_advance(&cursor)) != 0)
778 trailer.tag = __CPU_TO_LE_32(TLV_TAG_PARTITION_TRAILER);
779 trailer.length = __CPU_TO_LE_32(sizeof (trailer) - 8);
780 trailer.generation = header.generation;
781 trailer.checksum = 0; /* This will be fixed below. */
782 if ((rc = tlv_insert(&cursor, TLV_TAG_PARTITION_TRAILER,
783 (uint8_t *)&trailer.generation, sizeof (trailer) - 8)) != 0)
786 if ((rc = tlv_update_partition_len_and_cks(&cursor)) != 0)
789 /* Check that the partition is valid. */
790 if ((rc = ef10_nvram_buffer_validate(enp, partn_type,
791 partn_data, partn_size)) != 0)
809 EFSYS_PROBE1(fail1, efx_rc_t, rc);
816 __in uint32_t *position,
819 return (uint32_t)((uint8_t *)position - (uint8_t *)base);
822 __checkReturn efx_rc_t
823 ef10_nvram_buffer_find_item_start(
824 __in_bcount(buffer_size)
826 __in size_t buffer_size,
827 __out uint32_t *startp)
829 /* Read past partition header to find start address of the first key */
833 /* A PARTITION_HEADER tag must be the first item (at offset zero) */
834 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)bufferp,
835 buffer_size)) != 0) {
839 if (tlv_tag(&cursor) != TLV_TAG_PARTITION_HEADER) {
844 if ((rc = tlv_advance(&cursor)) != 0) {
848 *startp = byte_offset(cursor.current, cursor.block);
850 if ((rc = tlv_require_end(&cursor)) != 0)
862 EFSYS_PROBE1(fail1, efx_rc_t, rc);
867 __checkReturn efx_rc_t
868 ef10_nvram_buffer_find_end(
869 __in_bcount(buffer_size)
871 __in size_t buffer_size,
872 __in uint32_t offset,
873 __out uint32_t *endp)
875 /* Read to end of partition */
878 uint32_t *segment_used;
880 _NOTE(ARGUNUSED(offset))
882 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)bufferp,
883 buffer_size)) != 0) {
888 segment_used = cursor.block;
891 * Go through each segment and check that it has an end tag. If there
892 * is no end tag then the previous segment was the last valid one,
893 * so return the used space including that end tag.
895 while (tlv_tag(&cursor) == TLV_TAG_PARTITION_HEADER) {
896 if (tlv_require_end(&cursor) != 0) {
897 if (segment_used == cursor.block) {
899 * First segment is corrupt, so there is
900 * no valid data in partition.
907 segment_used = cursor.end + 1;
909 cursor.current = segment_used;
911 /* Return space used (including the END tag) */
912 *endp = (segment_used - cursor.block) * sizeof (uint32_t);
919 EFSYS_PROBE1(fail1, efx_rc_t, rc);
924 __checkReturn __success(return != B_FALSE) boolean_t
925 ef10_nvram_buffer_find_item(
926 __in_bcount(buffer_size)
928 __in size_t buffer_size,
929 __in uint32_t offset,
930 __out uint32_t *startp,
931 __out uint32_t *lengthp)
933 /* Find TLV at offset and return key start and length */
938 if (tlv_init_cursor_at_offset(&cursor, (uint8_t *)bufferp,
939 buffer_size, offset) != 0) {
943 while ((key = tlv_item(&cursor)) != NULL) {
944 tag = tlv_tag(&cursor);
945 if (tag == TLV_TAG_PARTITION_HEADER ||
946 tag == TLV_TAG_PARTITION_TRAILER) {
947 if (tlv_advance(&cursor) != 0) {
952 *startp = byte_offset(cursor.current, cursor.block);
953 *lengthp = byte_offset(tlv_next_item_ptr(&cursor),
961 __checkReturn efx_rc_t
962 ef10_nvram_buffer_get_item(
963 __in_bcount(buffer_size)
965 __in size_t buffer_size,
966 __in uint32_t offset,
967 __in uint32_t length,
968 __out_bcount_part(item_max_size, *lengthp)
970 __in size_t item_max_size,
971 __out uint32_t *lengthp)
975 uint32_t item_length;
977 if (item_max_size < length) {
982 if ((rc = tlv_init_cursor_at_offset(&cursor, (uint8_t *)bufferp,
983 buffer_size, offset)) != 0) {
987 item_length = tlv_length(&cursor);
988 if (length < item_length) {
992 memcpy(itemp, tlv_value(&cursor), item_length);
994 *lengthp = item_length;
1003 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1008 __checkReturn efx_rc_t
1009 ef10_nvram_buffer_insert_item(
1010 __in_bcount(buffer_size)
1012 __in size_t buffer_size,
1013 __in uint32_t offset,
1014 __in_bcount(length) caddr_t keyp,
1015 __in uint32_t length,
1016 __out uint32_t *lengthp)
1019 tlv_cursor_t cursor;
1021 if ((rc = tlv_init_cursor_at_offset(&cursor, (uint8_t *)bufferp,
1022 buffer_size, offset)) != 0) {
1026 rc = tlv_insert(&cursor, TLV_TAG_LICENSE, (uint8_t *)keyp, length);
1032 *lengthp = byte_offset(tlv_next_item_ptr(&cursor),
1040 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1045 __checkReturn efx_rc_t
1046 ef10_nvram_buffer_delete_item(
1047 __in_bcount(buffer_size)
1049 __in size_t buffer_size,
1050 __in uint32_t offset,
1051 __in uint32_t length,
1055 tlv_cursor_t cursor;
1057 _NOTE(ARGUNUSED(length, end))
1059 if ((rc = tlv_init_cursor_at_offset(&cursor, (uint8_t *)bufferp,
1060 buffer_size, offset)) != 0) {
1064 if ((rc = tlv_delete(&cursor)) != 0)
1072 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1077 __checkReturn efx_rc_t
1078 ef10_nvram_buffer_finish(
1079 __in_bcount(buffer_size)
1081 __in size_t buffer_size)
1084 tlv_cursor_t cursor;
1086 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)bufferp,
1087 buffer_size)) != 0) {
1092 if ((rc = tlv_require_end(&cursor)) != 0)
1095 if ((rc = tlv_update_partition_len_and_cks(&cursor)) != 0)
1105 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1113 * Read and validate a segment from a partition. A segment is a complete
1114 * tlv chain between PARTITION_HEADER and PARTITION_END tags. There may
1115 * be multiple segments in a partition, so seg_offset allows segments
1116 * beyond the first to be read.
1118 static __checkReturn efx_rc_t
1119 ef10_nvram_read_tlv_segment(
1120 __in efx_nic_t *enp,
1121 __in uint32_t partn,
1122 __in size_t seg_offset,
1123 __in_bcount(max_seg_size) caddr_t seg_data,
1124 __in size_t max_seg_size)
1126 tlv_cursor_t cursor;
1127 struct tlv_partition_header *header;
1128 struct tlv_partition_trailer *trailer;
1129 size_t total_length;
1134 EFX_STATIC_ASSERT(sizeof (*header) <= EF10_NVRAM_CHUNK);
1136 if ((seg_data == NULL) || (max_seg_size == 0)) {
1141 /* Read initial chunk of the segment, starting at offset */
1142 if ((rc = ef10_nvram_partn_read_mode(enp, partn, seg_offset, seg_data,
1144 MC_CMD_NVRAM_READ_IN_V2_TARGET_CURRENT)) != 0) {
1148 /* A PARTITION_HEADER tag must be the first item at the given offset */
1149 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)seg_data,
1150 max_seg_size)) != 0) {
1154 if (tlv_tag(&cursor) != TLV_TAG_PARTITION_HEADER) {
1158 header = (struct tlv_partition_header *)tlv_item(&cursor);
1160 /* Check TLV segment length (includes the END tag) */
1161 total_length = __LE_TO_CPU_32(header->total_length);
1162 if (total_length > max_seg_size) {
1167 /* Read the remaining segment content */
1168 if (total_length > EF10_NVRAM_CHUNK) {
1169 if ((rc = ef10_nvram_partn_read_mode(enp, partn,
1170 seg_offset + EF10_NVRAM_CHUNK,
1171 seg_data + EF10_NVRAM_CHUNK,
1172 total_length - EF10_NVRAM_CHUNK,
1173 MC_CMD_NVRAM_READ_IN_V2_TARGET_CURRENT)) != 0)
1177 /* Check segment ends with PARTITION_TRAILER and END tags */
1178 if ((rc = tlv_find(&cursor, TLV_TAG_PARTITION_TRAILER)) != 0) {
1182 trailer = (struct tlv_partition_trailer *)tlv_item(&cursor);
1184 if ((rc = tlv_advance(&cursor)) != 0) {
1188 if (tlv_tag(&cursor) != TLV_TAG_END) {
1193 /* Check data read from segment is consistent */
1194 if (trailer->generation != header->generation) {
1196 * The partition data may have been modified between successive
1197 * MCDI NVRAM_READ requests by the MC or another PCI function.
1199 * The caller must retry to obtain consistent partition data.
1205 /* Verify segment checksum */
1207 for (pos = 0; (size_t)pos < total_length; pos += sizeof (uint32_t)) {
1208 cksum += *((uint32_t *)(seg_data + pos));
1218 EFSYS_PROBE(fail11);
1220 EFSYS_PROBE(fail10);
1238 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1244 * Read a single TLV item from a host memory
1245 * buffer containing a TLV formatted segment.
1247 __checkReturn efx_rc_t
1248 ef10_nvram_buf_read_tlv(
1249 __in efx_nic_t *enp,
1250 __in_bcount(max_seg_size) caddr_t seg_data,
1251 __in size_t max_seg_size,
1253 __deref_out_bcount_opt(*sizep) caddr_t *datap,
1254 __out size_t *sizep)
1256 tlv_cursor_t cursor;
1262 _NOTE(ARGUNUSED(enp))
1264 if ((seg_data == NULL) || (max_seg_size == 0)) {
1269 /* Find requested TLV tag in segment data */
1270 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)seg_data,
1271 max_seg_size)) != 0) {
1275 if ((rc = tlv_find(&cursor, tag)) != 0) {
1279 value = (caddr_t)tlv_value(&cursor);
1280 length = tlv_length(&cursor);
1285 /* Copy out data from TLV item */
1286 EFSYS_KMEM_ALLOC(enp->en_esip, length, data);
1291 memcpy(data, value, length);
1306 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1311 /* Read a single TLV item from the first segment in a TLV formatted partition */
1312 __checkReturn efx_rc_t
1313 ef10_nvram_partn_read_tlv(
1314 __in efx_nic_t *enp,
1315 __in uint32_t partn,
1317 __deref_out_bcount_opt(*seg_sizep) caddr_t *seg_datap,
1318 __out size_t *seg_sizep)
1320 caddr_t seg_data = NULL;
1321 size_t partn_size = 0;
1327 /* Allocate sufficient memory for the entire partition */
1328 if ((rc = ef10_nvram_partn_size(enp, partn, &partn_size)) != 0)
1331 if (partn_size == 0) {
1336 EFSYS_KMEM_ALLOC(enp->en_esip, partn_size, seg_data);
1337 if (seg_data == NULL) {
1343 * Read the first segment in a TLV partition. Retry until consistent
1344 * segment contents are returned. Inconsistent data may be read if:
1345 * a) the segment contents are invalid
1346 * b) the MC has rebooted while we were reading the partition
1347 * c) the partition has been modified while we were reading it
1348 * Limit retry attempts to ensure forward progress.
1352 rc = ef10_nvram_read_tlv_segment(enp, partn, 0,
1353 seg_data, partn_size);
1354 } while ((rc == EAGAIN) && (--retry > 0));
1357 /* Failed to obtain consistent segment data */
1361 if ((rc = ef10_nvram_buf_read_tlv(enp, seg_data, partn_size,
1362 tag, &data, &length)) != 0)
1365 EFSYS_KMEM_FREE(enp->en_esip, partn_size, seg_data);
1368 *seg_sizep = length;
1377 EFSYS_KMEM_FREE(enp->en_esip, partn_size, seg_data);
1383 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1388 /* Compute the size of a segment. */
1389 static __checkReturn efx_rc_t
1390 ef10_nvram_buf_segment_size(
1391 __in caddr_t seg_data,
1392 __in size_t max_seg_size,
1393 __out size_t *seg_sizep)
1396 tlv_cursor_t cursor;
1397 struct tlv_partition_header *header;
1400 uint32_t *end_tag_position;
1401 uint32_t segment_length;
1403 /* A PARTITION_HEADER tag must be the first item at the given offset */
1404 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)seg_data,
1405 max_seg_size)) != 0) {
1409 if (tlv_tag(&cursor) != TLV_TAG_PARTITION_HEADER) {
1413 header = (struct tlv_partition_header *)tlv_item(&cursor);
1415 /* Check TLV segment length (includes the END tag) */
1416 *seg_sizep = __LE_TO_CPU_32(header->total_length);
1417 if (*seg_sizep > max_seg_size) {
1422 /* Check segment ends with PARTITION_TRAILER and END tags */
1423 if ((rc = tlv_find(&cursor, TLV_TAG_PARTITION_TRAILER)) != 0) {
1428 if ((rc = tlv_advance(&cursor)) != 0) {
1432 if (tlv_tag(&cursor) != TLV_TAG_END) {
1436 end_tag_position = cursor.current;
1438 /* Verify segment checksum */
1440 for (pos = 0; (size_t)pos < *seg_sizep; pos += sizeof (uint32_t)) {
1441 cksum += *((uint32_t *)(seg_data + pos));
1449 * Calculate total length from HEADER to END tags and compare to
1450 * max_seg_size and the total_length field in the HEADER tag.
1452 segment_length = tlv_block_length_used(&cursor);
1454 if (segment_length > max_seg_size) {
1459 if (segment_length != *seg_sizep) {
1464 /* Skip over the first HEADER tag. */
1465 rc = tlv_rewind(&cursor);
1466 rc = tlv_advance(&cursor);
1469 if (tlv_tag(&cursor) == TLV_TAG_END) {
1470 /* Check that the END tag is the one found earlier. */
1471 if (cursor.current != end_tag_position)
1475 /* Check for duplicate HEADER tags before the END tag. */
1476 if (tlv_tag(&cursor) == TLV_TAG_PARTITION_HEADER) {
1481 rc = tlv_advance(&cursor);
1489 EFSYS_PROBE(fail12);
1491 EFSYS_PROBE(fail11);
1493 EFSYS_PROBE(fail10);
1511 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1517 * Add or update a single TLV item in a host memory buffer containing a TLV
1518 * formatted segment. Historically partitions consisted of only one segment.
1520 __checkReturn efx_rc_t
1521 ef10_nvram_buf_write_tlv(
1522 __inout_bcount(max_seg_size) caddr_t seg_data,
1523 __in size_t max_seg_size,
1525 __in_bcount(tag_size) caddr_t tag_data,
1526 __in size_t tag_size,
1527 __out size_t *total_lengthp)
1529 tlv_cursor_t cursor;
1530 struct tlv_partition_header *header;
1531 struct tlv_partition_trailer *trailer;
1532 uint32_t generation;
1537 /* A PARTITION_HEADER tag must be the first item (at offset zero) */
1538 if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)seg_data,
1539 max_seg_size)) != 0) {
1543 if (tlv_tag(&cursor) != TLV_TAG_PARTITION_HEADER) {
1547 header = (struct tlv_partition_header *)tlv_item(&cursor);
1549 /* Update the TLV chain to contain the new data */
1550 if ((rc = tlv_find(&cursor, tag)) == 0) {
1551 /* Modify existing TLV item */
1552 if ((rc = tlv_modify(&cursor, tag,
1553 (uint8_t *)tag_data, tag_size)) != 0)
1556 /* Insert a new TLV item before the PARTITION_TRAILER */
1557 rc = tlv_find(&cursor, TLV_TAG_PARTITION_TRAILER);
1562 if ((rc = tlv_insert(&cursor, tag,
1563 (uint8_t *)tag_data, tag_size)) != 0) {
1569 /* Find the trailer tag */
1570 if ((rc = tlv_find(&cursor, TLV_TAG_PARTITION_TRAILER)) != 0) {
1574 trailer = (struct tlv_partition_trailer *)tlv_item(&cursor);
1576 /* Update PARTITION_HEADER and PARTITION_TRAILER fields */
1577 *total_lengthp = tlv_block_length_used(&cursor);
1578 if (*total_lengthp > max_seg_size) {
1582 generation = __LE_TO_CPU_32(header->generation) + 1;
1584 header->total_length = __CPU_TO_LE_32(*total_lengthp);
1585 header->generation = __CPU_TO_LE_32(generation);
1586 trailer->generation = __CPU_TO_LE_32(generation);
1588 /* Recompute PARTITION_TRAILER checksum */
1589 trailer->checksum = 0;
1591 for (pos = 0; (size_t)pos < *total_lengthp; pos += sizeof (uint32_t)) {
1592 cksum += *((uint32_t *)(seg_data + pos));
1594 trailer->checksum = ~cksum + 1;
1611 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1617 * Add or update a single TLV item in the first segment of a TLV formatted
1618 * dynamic config partition. The first segment is the current active
1621 __checkReturn efx_rc_t
1622 ef10_nvram_partn_write_tlv(
1623 __in efx_nic_t *enp,
1624 __in uint32_t partn,
1626 __in_bcount(size) caddr_t data,
1629 return ef10_nvram_partn_write_segment_tlv(enp, partn, tag, data,
1634 * Read a segment from nvram at the given offset into a buffer (segment_data)
1635 * and optionally write a new tag to it.
1637 static __checkReturn efx_rc_t
1638 ef10_nvram_segment_write_tlv(
1639 __in efx_nic_t *enp,
1640 __in uint32_t partn,
1642 __in_bcount(size) caddr_t data,
1644 __inout caddr_t *seg_datap,
1645 __inout size_t *partn_offsetp,
1646 __inout size_t *src_remain_lenp,
1647 __inout size_t *dest_remain_lenp,
1648 __in boolean_t write)
1652 size_t original_segment_size;
1653 size_t modified_segment_size;
1656 * Read the segment from NVRAM into the segment_data buffer and validate
1657 * it, returning if it does not validate. This is not a failure unless
1658 * this is the first segment in a partition. In this case the caller
1659 * must propagate the error.
1661 status = ef10_nvram_read_tlv_segment(enp, partn, *partn_offsetp,
1662 *seg_datap, *src_remain_lenp);
1668 status = ef10_nvram_buf_segment_size(*seg_datap,
1669 *src_remain_lenp, &original_segment_size);
1676 /* Update the contents of the segment in the buffer */
1677 if ((rc = ef10_nvram_buf_write_tlv(*seg_datap,
1678 *dest_remain_lenp, tag, data, size,
1679 &modified_segment_size)) != 0) {
1682 *dest_remain_lenp -= modified_segment_size;
1683 *seg_datap += modified_segment_size;
1686 * We won't modify this segment, but still need to update the
1687 * remaining lengths and pointers.
1689 *dest_remain_lenp -= original_segment_size;
1690 *seg_datap += original_segment_size;
1693 *partn_offsetp += original_segment_size;
1694 *src_remain_lenp -= original_segment_size;
1703 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1709 * Add or update a single TLV item in either the first segment or in all
1710 * segments in a TLV formatted dynamic config partition. Dynamic config
1711 * partitions on boards that support RFID are divided into a number of segments,
1712 * each formatted like a partition, with header, trailer and end tags. The first
1713 * segment is the current active configuration.
1715 * The segments are initialised by manftest and each contain a different
1716 * configuration e.g. firmware variant. The firmware can be instructed
1717 * via RFID to copy a segment to replace the first segment, hence changing the
1718 * active configuration. This allows ops to change the configuration of a board
1719 * prior to shipment using RFID.
1721 * Changes to the dynamic config may need to be written to all segments (e.g.
1722 * firmware versions) or just the first segment (changes to the active
1723 * configuration). See SF-111324-SW "The use of RFID in Solarflare Products".
1724 * If only the first segment is written the code still needs to be aware of the
1725 * possible presence of subsequent segments as writing to a segment may cause
1726 * its size to increase, which would overwrite the subsequent segments and
1729 __checkReturn efx_rc_t
1730 ef10_nvram_partn_write_segment_tlv(
1731 __in efx_nic_t *enp,
1732 __in uint32_t partn,
1734 __in_bcount(size) caddr_t data,
1736 __in boolean_t all_segments)
1738 size_t partn_size = 0;
1740 size_t total_length = 0;
1742 size_t current_offset = 0;
1743 size_t remaining_original_length;
1744 size_t remaining_modified_length;
1745 caddr_t segment_data;
1747 EFSYS_ASSERT3U(partn, ==, NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG);
1749 /* Allocate sufficient memory for the entire partition */
1750 if ((rc = ef10_nvram_partn_size(enp, partn, &partn_size)) != 0)
1753 EFSYS_KMEM_ALLOC(enp->en_esip, partn_size, partn_data);
1754 if (partn_data == NULL) {
1759 remaining_original_length = partn_size;
1760 remaining_modified_length = partn_size;
1761 segment_data = partn_data;
1763 /* Lock the partition */
1764 if ((rc = ef10_nvram_partn_lock(enp, partn)) != 0)
1767 /* Iterate over each (potential) segment to update it. */
1769 boolean_t write = all_segments || current_offset == 0;
1771 rc = ef10_nvram_segment_write_tlv(enp, partn, tag, data, size,
1772 &segment_data, ¤t_offset, &remaining_original_length,
1773 &remaining_modified_length, write);
1775 if (current_offset == 0) {
1777 * If no data has been read then the first
1778 * segment is invalid, which is an error.
1784 } while (current_offset < partn_size);
1786 total_length = segment_data - partn_data;
1789 * We've run out of space. This should actually be dealt with by
1790 * ef10_nvram_buf_write_tlv returning ENOSPC.
1792 if (total_length > partn_size) {
1797 /* Erase the whole partition in NVRAM */
1798 if ((rc = ef10_nvram_partn_erase(enp, partn, 0, partn_size)) != 0)
1801 /* Write new partition contents from the buffer to NVRAM */
1802 if ((rc = ef10_nvram_partn_write(enp, partn, 0, partn_data,
1803 total_length)) != 0)
1806 /* Unlock the partition */
1807 ef10_nvram_partn_unlock(enp, partn, NULL);
1809 EFSYS_KMEM_FREE(enp->en_esip, partn_size, partn_data);
1822 ef10_nvram_partn_unlock(enp, partn, NULL);
1826 EFSYS_KMEM_FREE(enp->en_esip, partn_size, partn_data);
1830 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1836 * Get the size of a NVRAM partition. This is the total size allocated in nvram,
1837 * not the data used by the segments in the partition.
1839 __checkReturn efx_rc_t
1840 ef10_nvram_partn_size(
1841 __in efx_nic_t *enp,
1842 __in uint32_t partn,
1843 __out size_t *sizep)
1847 if ((rc = efx_mcdi_nvram_info(enp, partn, sizep,
1848 NULL, NULL, NULL)) != 0)
1854 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1859 __checkReturn efx_rc_t
1860 ef10_nvram_partn_lock(
1861 __in efx_nic_t *enp,
1862 __in uint32_t partn)
1866 if ((rc = efx_mcdi_nvram_update_start(enp, partn)) != 0)
1872 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1877 __checkReturn efx_rc_t
1878 ef10_nvram_partn_read_mode(
1879 __in efx_nic_t *enp,
1880 __in uint32_t partn,
1881 __in unsigned int offset,
1882 __out_bcount(size) caddr_t data,
1890 chunk = MIN(size, EF10_NVRAM_CHUNK);
1892 if ((rc = efx_mcdi_nvram_read(enp, partn, offset,
1893 data, chunk, mode)) != 0) {
1905 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1910 __checkReturn efx_rc_t
1911 ef10_nvram_partn_read(
1912 __in efx_nic_t *enp,
1913 __in uint32_t partn,
1914 __in unsigned int offset,
1915 __out_bcount(size) caddr_t data,
1919 * An A/B partition has two data stores (current and backup).
1920 * Read requests which come in through the EFX API expect to read the
1921 * current, active store of an A/B partition. For non A/B partitions,
1922 * there is only a single store and so the mode param is ignored.
1924 return ef10_nvram_partn_read_mode(enp, partn, offset, data, size,
1925 MC_CMD_NVRAM_READ_IN_V2_TARGET_CURRENT);
1928 __checkReturn efx_rc_t
1929 ef10_nvram_partn_read_backup(
1930 __in efx_nic_t *enp,
1931 __in uint32_t partn,
1932 __in unsigned int offset,
1933 __out_bcount(size) caddr_t data,
1937 * An A/B partition has two data stores (current and backup).
1938 * Read the backup store of an A/B partition (i.e. the store currently
1939 * being written to if the partition is locked).
1941 * This is needed when comparing the existing partition content to avoid
1942 * unnecessary writes, or to read back what has been written to check
1943 * that the writes have succeeded.
1945 return ef10_nvram_partn_read_mode(enp, partn, offset, data, size,
1946 MC_CMD_NVRAM_READ_IN_V2_TARGET_BACKUP);
1949 __checkReturn efx_rc_t
1950 ef10_nvram_partn_erase(
1951 __in efx_nic_t *enp,
1952 __in uint32_t partn,
1953 __in unsigned int offset,
1957 uint32_t erase_size;
1959 if ((rc = efx_mcdi_nvram_info(enp, partn, NULL, NULL,
1960 &erase_size, NULL)) != 0)
1963 if (erase_size == 0) {
1964 if ((rc = efx_mcdi_nvram_erase(enp, partn, offset, size)) != 0)
1967 if (size % erase_size != 0) {
1972 if ((rc = efx_mcdi_nvram_erase(enp, partn, offset,
1975 offset += erase_size;
1989 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1994 __checkReturn efx_rc_t
1995 ef10_nvram_partn_write(
1996 __in efx_nic_t *enp,
1997 __in uint32_t partn,
1998 __in unsigned int offset,
1999 __out_bcount(size) caddr_t data,
2003 uint32_t write_size;
2006 if ((rc = efx_mcdi_nvram_info(enp, partn, NULL, NULL,
2007 NULL, &write_size)) != 0)
2010 if (write_size != 0) {
2012 * Check that the size is a multiple of the write chunk size if
2013 * the write chunk size is available.
2015 if (size % write_size != 0) {
2020 write_size = EF10_NVRAM_CHUNK;
2024 chunk = MIN(size, write_size);
2026 if ((rc = efx_mcdi_nvram_write(enp, partn, offset,
2027 data, chunk)) != 0) {
2043 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2048 __checkReturn efx_rc_t
2049 ef10_nvram_partn_unlock(
2050 __in efx_nic_t *enp,
2051 __in uint32_t partn,
2052 __out_opt uint32_t *verify_resultp)
2054 boolean_t reboot = B_FALSE;
2057 if (verify_resultp != NULL)
2058 *verify_resultp = MC_CMD_NVRAM_VERIFY_RC_UNKNOWN;
2060 rc = efx_mcdi_nvram_update_finish(enp, partn, reboot, verify_resultp);
2067 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2072 __checkReturn efx_rc_t
2073 ef10_nvram_partn_set_version(
2074 __in efx_nic_t *enp,
2075 __in uint32_t partn,
2076 __in_ecount(4) uint16_t version[4])
2078 struct tlv_partition_version partn_version;
2082 /* Add or modify partition version TLV item */
2083 partn_version.version_w = __CPU_TO_LE_16(version[0]);
2084 partn_version.version_x = __CPU_TO_LE_16(version[1]);
2085 partn_version.version_y = __CPU_TO_LE_16(version[2]);
2086 partn_version.version_z = __CPU_TO_LE_16(version[3]);
2088 size = sizeof (partn_version) - (2 * sizeof (uint32_t));
2090 /* Write the version number to all segments in the partition */
2091 if ((rc = ef10_nvram_partn_write_segment_tlv(enp,
2092 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
2093 TLV_TAG_PARTITION_VERSION(partn),
2094 (caddr_t)&partn_version.version_w, size, B_TRUE)) != 0)
2100 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2105 #endif /* EFSYS_OPT_VPD || EFSYS_OPT_NVRAM */
2109 typedef struct ef10_parttbl_entry_s {
2111 unsigned int port_mask;
2112 efx_nvram_type_t nvtype;
2113 } ef10_parttbl_entry_t;
2115 /* Port mask values */
2116 #define PORT_1 (1u << 1)
2117 #define PORT_2 (1u << 2)
2118 #define PORT_3 (1u << 3)
2119 #define PORT_4 (1u << 4)
2120 #define PORT_ALL (0xffffffffu)
2122 #define PARTN_MAP_ENTRY(partn, port_mask, nvtype) \
2123 { (NVRAM_PARTITION_TYPE_##partn), (PORT_##port_mask), (EFX_NVRAM_##nvtype) }
2125 /* Translate EFX NVRAM types to firmware partition types */
2126 static ef10_parttbl_entry_t hunt_parttbl[] = {
2127 /* partn ports nvtype */
2128 PARTN_MAP_ENTRY(MC_FIRMWARE, ALL, MC_FIRMWARE),
2129 PARTN_MAP_ENTRY(MC_FIRMWARE_BACKUP, ALL, MC_GOLDEN),
2130 PARTN_MAP_ENTRY(EXPANSION_ROM, ALL, BOOTROM),
2131 PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT0, 1, BOOTROM_CFG),
2132 PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT1, 2, BOOTROM_CFG),
2133 PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT2, 3, BOOTROM_CFG),
2134 PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT3, 4, BOOTROM_CFG),
2135 PARTN_MAP_ENTRY(DYNAMIC_CONFIG, ALL, DYNAMIC_CFG),
2136 PARTN_MAP_ENTRY(FPGA, ALL, FPGA),
2137 PARTN_MAP_ENTRY(FPGA_BACKUP, ALL, FPGA_BACKUP),
2138 PARTN_MAP_ENTRY(LICENSE, ALL, LICENSE),
2141 static ef10_parttbl_entry_t medford_parttbl[] = {
2142 /* partn ports nvtype */
2143 PARTN_MAP_ENTRY(MC_FIRMWARE, ALL, MC_FIRMWARE),
2144 PARTN_MAP_ENTRY(MC_FIRMWARE_BACKUP, ALL, MC_GOLDEN),
2145 PARTN_MAP_ENTRY(EXPANSION_ROM, ALL, BOOTROM),
2146 PARTN_MAP_ENTRY(EXPROM_CONFIG, ALL, BOOTROM_CFG),
2147 PARTN_MAP_ENTRY(DYNAMIC_CONFIG, ALL, DYNAMIC_CFG),
2148 PARTN_MAP_ENTRY(FPGA, ALL, FPGA),
2149 PARTN_MAP_ENTRY(FPGA_BACKUP, ALL, FPGA_BACKUP),
2150 PARTN_MAP_ENTRY(LICENSE, ALL, LICENSE),
2151 PARTN_MAP_ENTRY(EXPANSION_UEFI, ALL, UEFIROM),
2152 PARTN_MAP_ENTRY(MUM_FIRMWARE, ALL, MUM_FIRMWARE),
2155 static ef10_parttbl_entry_t medford2_parttbl[] = {
2156 /* partn ports nvtype */
2157 PARTN_MAP_ENTRY(MC_FIRMWARE, ALL, MC_FIRMWARE),
2158 PARTN_MAP_ENTRY(MC_FIRMWARE_BACKUP, ALL, MC_GOLDEN),
2159 PARTN_MAP_ENTRY(EXPANSION_ROM, ALL, BOOTROM),
2160 PARTN_MAP_ENTRY(EXPROM_CONFIG, ALL, BOOTROM_CFG),
2161 PARTN_MAP_ENTRY(DYNAMIC_CONFIG, ALL, DYNAMIC_CFG),
2162 PARTN_MAP_ENTRY(FPGA, ALL, FPGA),
2163 PARTN_MAP_ENTRY(FPGA_BACKUP, ALL, FPGA_BACKUP),
2164 PARTN_MAP_ENTRY(LICENSE, ALL, LICENSE),
2165 PARTN_MAP_ENTRY(EXPANSION_UEFI, ALL, UEFIROM),
2166 PARTN_MAP_ENTRY(MUM_FIRMWARE, ALL, MUM_FIRMWARE),
2169 static __checkReturn efx_rc_t
2171 __in efx_nic_t *enp,
2172 __out ef10_parttbl_entry_t **parttblp,
2173 __out size_t *parttbl_rowsp)
2175 switch (enp->en_family) {
2176 case EFX_FAMILY_HUNTINGTON:
2177 *parttblp = hunt_parttbl;
2178 *parttbl_rowsp = EFX_ARRAY_SIZE(hunt_parttbl);
2181 case EFX_FAMILY_MEDFORD:
2182 *parttblp = medford_parttbl;
2183 *parttbl_rowsp = EFX_ARRAY_SIZE(medford_parttbl);
2186 case EFX_FAMILY_MEDFORD2:
2187 *parttblp = medford2_parttbl;
2188 *parttbl_rowsp = EFX_ARRAY_SIZE(medford2_parttbl);
2192 EFSYS_ASSERT(B_FALSE);
2198 __checkReturn efx_rc_t
2199 ef10_nvram_type_to_partn(
2200 __in efx_nic_t *enp,
2201 __in efx_nvram_type_t type,
2202 __out uint32_t *partnp)
2204 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
2205 ef10_parttbl_entry_t *parttbl = NULL;
2206 size_t parttbl_rows = 0;
2209 EFSYS_ASSERT3U(type, !=, EFX_NVRAM_INVALID);
2210 EFSYS_ASSERT3U(type, <, EFX_NVRAM_NTYPES);
2211 EFSYS_ASSERT(partnp != NULL);
2213 if (ef10_parttbl_get(enp, &parttbl, &parttbl_rows) == 0) {
2214 for (i = 0; i < parttbl_rows; i++) {
2215 ef10_parttbl_entry_t *entry = &parttbl[i];
2217 if ((entry->nvtype == type) &&
2218 (entry->port_mask & (1u << emip->emi_port))) {
2219 *partnp = entry->partn;
2230 static __checkReturn efx_rc_t
2231 ef10_nvram_partn_to_type(
2232 __in efx_nic_t *enp,
2233 __in uint32_t partn,
2234 __out efx_nvram_type_t *typep)
2236 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
2237 ef10_parttbl_entry_t *parttbl = NULL;
2238 size_t parttbl_rows = 0;
2241 EFSYS_ASSERT(typep != NULL);
2243 if (ef10_parttbl_get(enp, &parttbl, &parttbl_rows) == 0) {
2244 for (i = 0; i < parttbl_rows; i++) {
2245 ef10_parttbl_entry_t *entry = &parttbl[i];
2247 if ((entry->partn == partn) &&
2248 (entry->port_mask & (1u << emip->emi_port))) {
2249 *typep = entry->nvtype;
2258 __checkReturn efx_rc_t
2260 __in efx_nic_t *enp)
2262 efx_nvram_type_t type;
2263 unsigned int npartns = 0;
2264 uint32_t *partns = NULL;
2269 /* Read available partitions from NVRAM partition map */
2270 size = MC_CMD_NVRAM_PARTITIONS_OUT_TYPE_ID_MAXNUM * sizeof (uint32_t);
2271 EFSYS_KMEM_ALLOC(enp->en_esip, size, partns);
2272 if (partns == NULL) {
2277 if ((rc = efx_mcdi_nvram_partitions(enp, (caddr_t)partns, size,
2282 for (i = 0; i < npartns; i++) {
2283 /* Check if the partition is supported for this port */
2284 if ((rc = ef10_nvram_partn_to_type(enp, partns[i], &type)) != 0)
2287 if ((rc = efx_mcdi_nvram_test(enp, partns[i])) != 0)
2291 EFSYS_KMEM_FREE(enp->en_esip, size, partns);
2298 EFSYS_KMEM_FREE(enp->en_esip, size, partns);
2300 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2304 #endif /* EFSYS_OPT_DIAG */
2306 __checkReturn efx_rc_t
2307 ef10_nvram_partn_get_version(
2308 __in efx_nic_t *enp,
2309 __in uint32_t partn,
2310 __out uint32_t *subtypep,
2311 __out_ecount(4) uint16_t version[4])
2315 /* FIXME: get highest partn version from all ports */
2316 /* FIXME: return partn description if available */
2318 if ((rc = efx_mcdi_nvram_metadata(enp, partn, subtypep,
2319 version, NULL, 0)) != 0)
2325 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2330 __checkReturn efx_rc_t
2331 ef10_nvram_partn_rw_start(
2332 __in efx_nic_t *enp,
2333 __in uint32_t partn,
2334 __out size_t *chunk_sizep)
2336 uint32_t write_size = 0;
2339 if ((rc = efx_mcdi_nvram_info(enp, partn, NULL, NULL,
2340 NULL, &write_size)) != 0)
2343 if ((rc = ef10_nvram_partn_lock(enp, partn)) != 0)
2346 if (chunk_sizep != NULL) {
2347 if (write_size == 0)
2348 *chunk_sizep = EF10_NVRAM_CHUNK;
2350 *chunk_sizep = write_size;
2358 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2363 __checkReturn efx_rc_t
2364 ef10_nvram_partn_rw_finish(
2365 __in efx_nic_t *enp,
2366 __in uint32_t partn,
2367 __out_opt uint32_t *verify_resultp)
2371 if ((rc = ef10_nvram_partn_unlock(enp, partn, verify_resultp)) != 0)
2377 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2382 #endif /* EFSYS_OPT_NVRAM */
2384 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */