2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2016 Solarflare Communications Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * The views and conclusions contained in the software and documentation are
29 * those of the authors and should not be interpreted as representing official
30 * policies, either expressed or implied, of the FreeBSD Project.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
42 * Maximum size of BOOTCFG block across all nics as understood by SFCgPXE.
43 * NOTE: This is larger than the Medford per-PF bootcfg sector.
45 #define BOOTCFG_MAX_SIZE 0x1000
47 /* Medford per-PF bootcfg sector */
48 #define BOOTCFG_PER_PF 0x800
49 #define BOOTCFG_PF_COUNT 16
51 #define DHCP_OPT_HAS_VALUE(opt) \
52 (((opt) > EFX_DHCP_PAD) && ((opt) < EFX_DHCP_END))
54 #define DHCP_MAX_VALUE 255
56 #define DHCP_ENCAPSULATOR(encap_opt) ((encap_opt) >> 8)
57 #define DHCP_ENCAPSULATED(encap_opt) ((encap_opt) & 0xff)
58 #define DHCP_IS_ENCAP_OPT(opt) DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATOR(opt))
60 typedef struct efx_dhcp_tag_hdr_s {
66 * Length calculations for tags with value field. PAD and END
67 * have a fixed length of 1, with no length or value field.
69 #define DHCP_FULL_TAG_LENGTH(hdr) \
70 (sizeof (efx_dhcp_tag_hdr_t) + (hdr)->length)
72 #define DHCP_NEXT_TAG(hdr) \
73 ((efx_dhcp_tag_hdr_t *)(((uint8_t *)(hdr)) + \
74 DHCP_FULL_TAG_LENGTH((hdr))))
76 #define DHCP_CALC_TAG_LENGTH(payload_len) \
77 ((payload_len) + sizeof (efx_dhcp_tag_hdr_t))
80 /* Report the layout of bootcfg sectors in NVRAM partition. */
81 __checkReturn efx_rc_t
82 efx_bootcfg_sector_info(
85 __out_opt uint32_t *sector_countp,
86 __out size_t *offsetp,
87 __out size_t *max_sizep)
94 switch (enp->en_family) {
96 case EFX_FAMILY_SIENA:
97 max_size = BOOTCFG_MAX_SIZE;
101 #endif /* EFSYS_OPT_SIENA */
103 #if EFSYS_OPT_HUNTINGTON
104 case EFX_FAMILY_HUNTINGTON:
105 max_size = BOOTCFG_MAX_SIZE;
109 #endif /* EFSYS_OPT_HUNTINGTON */
111 #if EFSYS_OPT_MEDFORD
112 case EFX_FAMILY_MEDFORD: {
113 /* Shared partition (array indexed by PF) */
114 max_size = BOOTCFG_PER_PF;
115 count = BOOTCFG_PF_COUNT;
120 offset = max_size * pf;
123 #endif /* EFSYS_OPT_MEDFORD */
125 #if EFSYS_OPT_MEDFORD2
126 case EFX_FAMILY_MEDFORD2: {
127 /* Shared partition (array indexed by PF) */
128 max_size = BOOTCFG_PER_PF;
129 count = BOOTCFG_PF_COUNT;
134 offset = max_size * pf;
137 #endif /* EFSYS_OPT_MEDFORD2 */
144 EFSYS_ASSERT3U(max_size, <=, BOOTCFG_MAX_SIZE);
146 if (sector_countp != NULL)
147 *sector_countp = count;
149 *max_sizep = max_size;
153 #if EFSYS_OPT_MEDFORD2
157 #if EFSYS_OPT_MEDFORD
162 EFSYS_PROBE1(fail1, efx_rc_t, rc);
167 __checkReturn uint8_t
169 __in_bcount(size) uint8_t const *data,
173 uint8_t checksum = 0;
175 for (pos = 0; pos < size; pos++)
176 checksum += data[pos];
180 __checkReturn efx_rc_t
182 __in_bcount(size) uint8_t const *data,
184 __out_opt size_t *usedp)
190 /* Start parsing tags immediately after the checksum */
191 for (offset = 1; offset < size; ) {
197 if (tag == EFX_DHCP_END) {
202 if (tag == EFX_DHCP_PAD) {
208 if (offset + 1 >= size) {
212 length = data[offset + 1];
214 /* Consume *length */
215 if (offset + 1 + length >= size) {
220 offset += 2 + length;
224 /* Checksum the entire sector, including bytes after any EFX_DHCP_END */
225 if (efx_dhcp_csum(data, size) != 0) {
240 EFSYS_PROBE1(fail1, efx_rc_t, rc);
246 * Walk the entire tag set looking for option. The sought option may be
247 * encapsulated. ENOENT indicates the walk completed without finding the
248 * option. If we run out of buffer during the walk the function will return
253 __deref_inout uint8_t **tagpp,
254 __inout size_t *buffer_sizep,
258 boolean_t is_encap = B_FALSE;
260 if (DHCP_IS_ENCAP_OPT(opt)) {
262 * Look for the encapsulator and, if found, limit ourselves
263 * to its payload. If it's not found then the entire tag
264 * cannot be found, so the encapsulated opt search is
267 rc = efx_dhcp_walk_tags(tagpp, buffer_sizep,
268 DHCP_ENCAPSULATOR(opt));
270 *buffer_sizep = ((efx_dhcp_tag_hdr_t *)*tagpp)->length;
271 (*tagpp) += sizeof (efx_dhcp_tag_hdr_t);
273 opt = DHCP_ENCAPSULATED(opt);
277 EFSYS_ASSERT(!DHCP_IS_ENCAP_OPT(opt));
282 if (*buffer_sizep == 0) {
287 if (DHCP_ENCAPSULATED(**tagpp) == opt)
290 if ((**tagpp) == EFX_DHCP_END) {
293 } else if ((**tagpp) == EFX_DHCP_PAD) {
296 if (*buffer_sizep < sizeof (efx_dhcp_tag_hdr_t)) {
302 DHCP_FULL_TAG_LENGTH((efx_dhcp_tag_hdr_t *)*tagpp);
305 if (size > *buffer_sizep) {
311 (*buffer_sizep) -= size;
313 if ((*buffer_sizep == 0) && is_encap) {
314 /* Search within encapulator tag finished */
321 * Returns 0 if found otherwise ENOENT indicating search finished
331 EFSYS_PROBE1(fail1, efx_rc_t, rc);
337 * Locate value buffer for option in the given buffer.
338 * Returns 0 if found, ENOENT indicating search finished
339 * correctly, otherwise search failed before completion.
341 __checkReturn efx_rc_t
343 __in_bcount(buffer_length) uint8_t *bufferp,
344 __in size_t buffer_length,
346 __deref_out uint8_t **valuepp,
347 __out size_t *value_lengthp)
350 uint8_t *tagp = bufferp;
351 size_t len = buffer_length;
353 rc = efx_dhcp_walk_tags(&tagp, &len, opt);
355 efx_dhcp_tag_hdr_t *hdrp;
357 hdrp = (efx_dhcp_tag_hdr_t *)tagp;
358 *valuepp = (uint8_t *)(&hdrp[1]);
359 *value_lengthp = hdrp->length;
360 } else if (rc != ENOENT) {
367 EFSYS_PROBE1(fail1, efx_rc_t, rc);
373 * Locate the end tag in the given buffer.
374 * Returns 0 if found, ENOENT indicating search finished
375 * correctly but end tag was not found; otherwise search
376 * failed before completion.
378 __checkReturn efx_rc_t
380 __in_bcount(buffer_length) uint8_t *bufferp,
381 __in size_t buffer_length,
382 __deref_out uint8_t **endpp)
385 uint8_t *endp = bufferp;
386 size_t len = buffer_length;
388 rc = efx_dhcp_walk_tags(&endp, &len, EFX_DHCP_END);
391 else if (rc != ENOENT)
397 EFSYS_PROBE1(fail1, efx_rc_t, rc);
404 * Delete the given tag from anywhere in the buffer. Copes with
405 * encapsulated tags, and updates or deletes the encapsulating opt as
408 __checkReturn efx_rc_t
410 __inout_bcount(buffer_length) uint8_t *bufferp,
411 __in size_t buffer_length,
415 efx_dhcp_tag_hdr_t *hdrp;
423 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
428 rc = efx_dhcp_walk_tags(&startp, &len, opt);
432 hdrp = (efx_dhcp_tag_hdr_t *)startp;
434 if (DHCP_IS_ENCAP_OPT(opt)) {
435 uint8_t tag_length = DHCP_FULL_TAG_LENGTH(hdrp);
436 uint8_t *encapp = bufferp;
437 efx_dhcp_tag_hdr_t *encap_hdrp;
440 rc = efx_dhcp_walk_tags(&encapp, &len,
441 DHCP_ENCAPSULATOR(opt));
445 encap_hdrp = (efx_dhcp_tag_hdr_t *)encapp;
446 if (encap_hdrp->length > tag_length) {
447 encap_hdrp->length = (uint8_t)(
448 (size_t)encap_hdrp->length - tag_length);
450 /* delete the encapsulating tag */
455 startp = (uint8_t *)hdrp;
456 endp = (uint8_t *)DHCP_NEXT_TAG(hdrp);
458 if (startp < bufferp) {
463 if (endp > &bufferp[buffer_length]) {
468 memmove(startp, endp,
469 buffer_length - (endp - bufferp));
480 EFSYS_PROBE1(fail1, efx_rc_t, rc);
486 * Write the tag header into write_pointp and optionally copies the payload
487 * into the space following.
491 __in uint8_t *write_pointp,
493 __in_bcount_opt(value_length)
495 __in size_t value_length)
497 efx_dhcp_tag_hdr_t *hdrp = (efx_dhcp_tag_hdr_t *)write_pointp;
498 hdrp->tag = DHCP_ENCAPSULATED(opt);
499 hdrp->length = (uint8_t)value_length;
500 if ((value_length > 0) && (valuep != NULL))
501 memcpy(&hdrp[1], valuep, value_length);
505 * Add the given tag to the end of the buffer. Copes with creating an
506 * encapsulated tag, and updates or creates the encapsulating opt as
509 __checkReturn efx_rc_t
511 __inout_bcount(buffer_length) uint8_t *bufferp,
512 __in size_t buffer_length,
514 __in_bcount_opt(value_length) uint8_t *valuep,
515 __in size_t value_length)
518 efx_dhcp_tag_hdr_t *encap_hdrp = NULL;
519 uint8_t *insert_pointp = NULL;
521 size_t available_space;
526 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
531 if (value_length > DHCP_MAX_VALUE) {
536 if ((value_length > 0) && (valuep == NULL)) {
542 available_space = buffer_length;
543 rc = efx_dhcp_walk_tags(&endp, &available_space, EFX_DHCP_END);
548 search_size = buffer_length;
549 if (DHCP_IS_ENCAP_OPT(opt)) {
550 rc = efx_dhcp_walk_tags(&searchp, &search_size,
551 DHCP_ENCAPSULATOR(opt));
553 encap_hdrp = (efx_dhcp_tag_hdr_t *)searchp;
555 /* Check encapsulated tag is not present */
556 search_size = encap_hdrp->length;
557 rc = efx_dhcp_walk_tags(&searchp, &search_size,
564 /* Check encapsulator will not overflow */
565 if (((size_t)encap_hdrp->length +
566 DHCP_CALC_TAG_LENGTH(value_length)) >
572 /* Insert at start of existing encapsulator */
573 insert_pointp = (uint8_t *)&encap_hdrp[1];
574 opt = DHCP_ENCAPSULATED(opt);
575 } else if (rc == ENOENT) {
581 /* Check unencapsulated tag is not present */
582 rc = efx_dhcp_walk_tags(&searchp, &search_size,
590 if (insert_pointp == NULL) {
591 /* Insert at end of existing tags */
592 insert_pointp = endp;
595 /* Includes the new encapsulator tag hdr if required */
596 added_length = DHCP_CALC_TAG_LENGTH(value_length) +
597 (DHCP_IS_ENCAP_OPT(opt) ? sizeof (efx_dhcp_tag_hdr_t) : 0);
599 if (available_space <= added_length) {
604 memmove(insert_pointp + added_length, insert_pointp,
605 available_space - added_length);
607 if (DHCP_IS_ENCAP_OPT(opt)) {
608 /* Create new encapsulator header */
609 added_length -= sizeof (efx_dhcp_tag_hdr_t);
610 efx_dhcp_write_tag(insert_pointp,
611 DHCP_ENCAPSULATOR(opt), NULL, added_length);
612 insert_pointp += sizeof (efx_dhcp_tag_hdr_t);
613 } else if (encap_hdrp)
614 /* Modify existing encapsulator header */
615 encap_hdrp->length +=
616 ((uint8_t)DHCP_CALC_TAG_LENGTH(value_length));
618 efx_dhcp_write_tag(insert_pointp, opt, valuep, value_length);
639 EFSYS_PROBE1(fail1, efx_rc_t, rc);
645 * Update an existing tag to the new value. Copes with encapsulated
646 * tags, and updates the encapsulating opt as necessary.
648 __checkReturn efx_rc_t
650 __inout_bcount(buffer_length) uint8_t *bufferp,
651 __in size_t buffer_length,
653 __in uint8_t *value_locationp,
654 __in_bcount_opt(value_length) uint8_t *valuep,
655 __in size_t value_length)
658 uint8_t *write_pointp = value_locationp - sizeof (efx_dhcp_tag_hdr_t);
659 efx_dhcp_tag_hdr_t *hdrp = (efx_dhcp_tag_hdr_t *)write_pointp;
660 efx_dhcp_tag_hdr_t *encap_hdrp = NULL;
663 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
668 if (value_length > DHCP_MAX_VALUE) {
673 if ((value_length > 0) && (valuep == NULL)) {
678 old_length = hdrp->length;
680 if (old_length < value_length) {
681 uint8_t *endp = bufferp;
682 size_t available_space = buffer_length;
684 rc = efx_dhcp_walk_tags(&endp, &available_space,
689 if (available_space < (value_length - old_length)) {
695 if (DHCP_IS_ENCAP_OPT(opt)) {
696 uint8_t *encapp = bufferp;
697 size_t following_encap = buffer_length;
700 rc = efx_dhcp_walk_tags(&encapp, &following_encap,
701 DHCP_ENCAPSULATOR(opt));
705 encap_hdrp = (efx_dhcp_tag_hdr_t *)encapp;
707 new_length = ((size_t)encap_hdrp->length +
708 value_length - old_length);
709 /* Check encapsulator will not overflow */
710 if (new_length > DHCP_MAX_VALUE) {
715 encap_hdrp->length = (uint8_t)new_length;
719 * Move the following data up/down to accommodate the new payload
722 if (old_length != value_length) {
723 uint8_t *destp = (uint8_t *)DHCP_NEXT_TAG(hdrp) +
724 value_length - old_length;
725 size_t count = &bufferp[buffer_length] -
726 (uint8_t *)DHCP_NEXT_TAG(hdrp);
728 memmove(destp, DHCP_NEXT_TAG(hdrp), count);
731 EFSYS_ASSERT(hdrp->tag == DHCP_ENCAPSULATED(opt));
732 efx_dhcp_write_tag(write_pointp, opt, valuep, value_length);
749 EFSYS_PROBE1(fail1, efx_rc_t, rc);
756 * Copy bootcfg sector data to a target buffer which may differ in size.
757 * Optionally corrects format errors in source buffer.
760 efx_bootcfg_copy_sector(
762 __inout_bcount(sector_length)
764 __in size_t sector_length,
765 __out_bcount(data_size) uint8_t *data,
766 __in size_t data_size,
767 __in boolean_t handle_format_errors)
769 _NOTE(ARGUNUSED(enp))
774 /* Minimum buffer is checksum byte and EFX_DHCP_END terminator */
780 /* Verify that the area is correctly formatted and checksummed */
781 rc = efx_dhcp_verify(sector, sector_length,
784 if (!handle_format_errors) {
788 if ((used_bytes < 2) ||
789 (sector[used_bytes - 1] != EFX_DHCP_END)) {
790 /* Block too short, or EFX_DHCP_END missing */
796 /* Synthesize empty format on verification failure */
797 if (rc != 0 || used_bytes == 0) {
799 sector[1] = EFX_DHCP_END;
802 EFSYS_ASSERT(used_bytes >= 2); /* checksum and EFX_DHCP_END */
803 EFSYS_ASSERT(used_bytes <= sector_length);
804 EFSYS_ASSERT(sector_length >= 2);
807 * Legacy bootcfg sectors don't terminate with an EFX_DHCP_END
808 * character. Modify the returned payload so it does.
809 * Reinitialise the sector if there isn't room for the character.
811 if (sector[used_bytes - 1] != EFX_DHCP_END) {
812 if (used_bytes >= sector_length) {
816 sector[used_bytes] = EFX_DHCP_END;
821 * Verify that the target buffer is large enough for the
822 * entire used bootcfg area, then copy into the target buffer.
824 if (used_bytes > data_size) {
829 data[0] = 0; /* checksum, updated below */
831 /* Copy all after the checksum to the target buffer */
832 memcpy(data + 1, sector + 1, used_bytes - 1);
834 /* Zero out the unused portion of the target buffer */
835 if (used_bytes < data_size)
836 (void) memset(data + used_bytes, 0, data_size - used_bytes);
839 * The checksum includes trailing data after any EFX_DHCP_END
840 * character, which we've just modified (by truncation or appending
843 data[0] -= efx_dhcp_csum(data, data_size);
854 EFSYS_PROBE1(fail1, efx_rc_t, rc);
862 __out_bcount(size) uint8_t *data,
865 uint8_t *payload = NULL;
868 size_t sector_length;
869 size_t sector_offset;
871 uint32_t sector_number;
873 /* Minimum buffer is checksum byte and EFX_DHCP_END terminator */
879 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
880 sector_number = enp->en_nic_cfg.enc_pf;
884 rc = efx_nvram_size(enp, EFX_NVRAM_BOOTROM_CFG, &partn_length);
888 /* The bootcfg sector may be stored in a (larger) shared partition */
889 rc = efx_bootcfg_sector_info(enp, sector_number,
890 NULL, §or_offset, §or_length);
894 if (sector_length < 2) {
899 if (sector_length > BOOTCFG_MAX_SIZE)
900 sector_length = BOOTCFG_MAX_SIZE;
902 if (sector_offset + sector_length > partn_length) {
903 /* Partition is too small */
909 * We need to read the entire BOOTCFG sector to ensure we read all
910 * tags, because legacy bootcfg sectors are not guaranteed to end
911 * with an EFX_DHCP_END character. If the user hasn't supplied a
912 * sufficiently large buffer then use our own buffer.
914 if (sector_length > size) {
915 EFSYS_KMEM_ALLOC(enp->en_esip, sector_length, payload);
916 if (payload == NULL) {
921 payload = (uint8_t *)data;
923 if ((rc = efx_nvram_rw_start(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
926 if ((rc = efx_nvram_read_chunk(enp, EFX_NVRAM_BOOTROM_CFG,
927 sector_offset, (caddr_t)payload, sector_length)) != 0) {
928 (void) efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
932 if ((rc = efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
935 /* Verify that the area is correctly formatted and checksummed */
936 rc = efx_dhcp_verify(payload, sector_length,
938 if (rc != 0 || used_bytes == 0) {
940 payload[1] = EFX_DHCP_END;
944 EFSYS_ASSERT(used_bytes >= 2); /* checksum and EFX_DHCP_END */
945 EFSYS_ASSERT(used_bytes <= sector_length);
948 * Legacy bootcfg sectors don't terminate with an EFX_DHCP_END
949 * character. Modify the returned payload so it does.
950 * BOOTCFG_MAX_SIZE is by definition large enough for any valid
951 * (per-port) bootcfg sector, so reinitialise the sector if there
952 * isn't room for the character.
954 if (payload[used_bytes - 1] != EFX_DHCP_END) {
955 if (used_bytes >= sector_length)
958 payload[used_bytes] = EFX_DHCP_END;
963 * Verify that the user supplied buffer is large enough for the
964 * entire used bootcfg area, then copy into the user supplied buffer.
966 if (used_bytes > size) {
971 data[0] = 0; /* checksum, updated below */
973 if (sector_length > size) {
974 /* Copy all after the checksum to the target buffer */
975 memcpy(data + 1, payload + 1, used_bytes - 1);
976 EFSYS_KMEM_FREE(enp->en_esip, sector_length, payload);
979 /* Zero out the unused portion of the user buffer */
980 if (used_bytes < size)
981 (void) memset(data + used_bytes, 0, size - used_bytes);
984 * The checksum includes trailing data after any EFX_DHCP_END character,
985 * which we've just modified (by truncation or appending EFX_DHCP_END).
987 data[0] -= efx_dhcp_csum(data, size);
999 if (sector_length > size)
1000 EFSYS_KMEM_FREE(enp->en_esip, sector_length, payload);
1012 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1019 __in efx_nic_t *enp,
1020 __in_bcount(size) uint8_t *data,
1023 uint8_t *partn_data;
1025 size_t partn_length;
1026 size_t sector_length;
1027 size_t sector_offset;
1030 uint32_t sector_number;
1032 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
1033 sector_number = enp->en_nic_cfg.enc_pf;
1038 rc = efx_nvram_size(enp, EFX_NVRAM_BOOTROM_CFG, &partn_length);
1042 /* The bootcfg sector may be stored in a (larger) shared partition */
1043 rc = efx_bootcfg_sector_info(enp, sector_number,
1044 NULL, §or_offset, §or_length);
1048 if (sector_length > BOOTCFG_MAX_SIZE)
1049 sector_length = BOOTCFG_MAX_SIZE;
1051 if (sector_offset + sector_length > partn_length) {
1052 /* Partition is too small */
1057 if ((rc = efx_dhcp_verify(data, size, &used_bytes)) != 0)
1061 * The caller *must* terminate their block with a EFX_DHCP_END
1064 if ((used_bytes < 2) || ((uint8_t)data[used_bytes - 1] !=
1066 /* Block too short or EFX_DHCP_END missing */
1071 /* Check that the hardware has support for this much data */
1072 if (used_bytes > MIN(sector_length, BOOTCFG_MAX_SIZE)) {
1078 * If the BOOTCFG sector is stored in a shared partition, then we must
1079 * read the whole partition and insert the updated bootcfg sector at the
1082 EFSYS_KMEM_ALLOC(enp->en_esip, partn_length, partn_data);
1083 if (partn_data == NULL) {
1088 rc = efx_nvram_rw_start(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
1092 /* Read the entire partition */
1093 rc = efx_nvram_read_chunk(enp, EFX_NVRAM_BOOTROM_CFG, 0,
1094 (caddr_t)partn_data, partn_length);
1099 * Insert the BOOTCFG sector into the partition, Zero out all data
1100 * after the EFX_DHCP_END tag, and adjust the checksum.
1102 (void) memset(partn_data + sector_offset, 0x0, sector_length);
1103 (void) memcpy(partn_data + sector_offset, data, used_bytes);
1105 checksum = efx_dhcp_csum(data, used_bytes);
1106 partn_data[sector_offset] -= checksum;
1108 if ((rc = efx_nvram_erase(enp, EFX_NVRAM_BOOTROM_CFG)) != 0)
1111 if ((rc = efx_nvram_write_chunk(enp, EFX_NVRAM_BOOTROM_CFG,
1112 0, (caddr_t)partn_data, partn_length)) != 0)
1115 if ((rc = efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
1118 EFSYS_KMEM_FREE(enp->en_esip, partn_length, partn_data);
1123 EFSYS_PROBE(fail12);
1125 EFSYS_PROBE(fail11);
1127 EFSYS_PROBE(fail10);
1131 (void) efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
1135 EFSYS_KMEM_FREE(enp->en_esip, partn_length, partn_data);
1149 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1154 #endif /* EFSYS_OPT_BOOTCFG */