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))
79 /* Report the layout of bootcfg sectors in NVRAM partition. */
80 __checkReturn efx_rc_t
81 efx_bootcfg_sector_info(
84 __out_opt uint32_t *sector_countp,
85 __out size_t *offsetp,
86 __out size_t *max_sizep)
93 switch (enp->en_family) {
95 case EFX_FAMILY_SIENA:
96 max_size = BOOTCFG_MAX_SIZE;
100 #endif /* EFSYS_OPT_SIENA */
102 #if EFSYS_OPT_HUNTINGTON
103 case EFX_FAMILY_HUNTINGTON:
104 max_size = BOOTCFG_MAX_SIZE;
108 #endif /* EFSYS_OPT_HUNTINGTON */
110 #if EFSYS_OPT_MEDFORD
111 case EFX_FAMILY_MEDFORD: {
112 /* Shared partition (array indexed by PF) */
113 max_size = BOOTCFG_PER_PF;
114 count = BOOTCFG_PF_COUNT;
119 offset = max_size * pf;
122 #endif /* EFSYS_OPT_MEDFORD */
124 #if EFSYS_OPT_MEDFORD2
125 case EFX_FAMILY_MEDFORD2: {
126 /* Shared partition (array indexed by PF) */
127 max_size = BOOTCFG_PER_PF;
128 count = BOOTCFG_PF_COUNT;
133 offset = max_size * pf;
136 #endif /* EFSYS_OPT_MEDFORD2 */
143 EFSYS_ASSERT3U(max_size, <=, BOOTCFG_MAX_SIZE);
145 if (sector_countp != NULL)
146 *sector_countp = count;
148 *max_sizep = max_size;
152 #if EFSYS_OPT_MEDFORD2
156 #if EFSYS_OPT_MEDFORD
161 EFSYS_PROBE1(fail1, efx_rc_t, rc);
165 __checkReturn uint8_t
167 __in_bcount(size) uint8_t const *data,
171 uint8_t checksum = 0;
173 for (pos = 0; pos < size; pos++)
174 checksum += data[pos];
178 __checkReturn efx_rc_t
180 __in_bcount(size) uint8_t const *data,
182 __out_opt size_t *usedp)
188 /* Start parsing tags immediately after the checksum */
189 for (offset = 1; offset < size; ) {
195 if (tag == EFX_DHCP_END) {
200 if (tag == EFX_DHCP_PAD) {
206 if (offset + 1 >= size) {
210 length = data[offset + 1];
212 /* Consume *length */
213 if (offset + 1 + length >= size) {
218 offset += 2 + length;
222 /* Checksum the entire sector, including bytes after any EFX_DHCP_END */
223 if (efx_dhcp_csum(data, size) != 0) {
238 EFSYS_PROBE1(fail1, efx_rc_t, rc);
244 * Walk the entire tag set looking for option. The sought option may be
245 * encapsulated. ENOENT indicates the walk completed without finding the
246 * option. If we run out of buffer during the walk the function will return
251 __deref_inout uint8_t **tagpp,
252 __inout size_t *buffer_sizep,
256 boolean_t is_encap = B_FALSE;
258 if (DHCP_IS_ENCAP_OPT(opt)) {
260 * Look for the encapsulator and, if found, limit ourselves
261 * to its payload. If it's not found then the entire tag
262 * cannot be found, so the encapsulated opt search is
265 rc = efx_dhcp_walk_tags(tagpp, buffer_sizep,
266 DHCP_ENCAPSULATOR(opt));
268 *buffer_sizep = ((efx_dhcp_tag_hdr_t *)*tagpp)->length;
269 (*tagpp) += sizeof (efx_dhcp_tag_hdr_t);
271 opt = DHCP_ENCAPSULATED(opt);
275 EFSYS_ASSERT(!DHCP_IS_ENCAP_OPT(opt));
280 if (*buffer_sizep == 0) {
285 if (DHCP_ENCAPSULATED(**tagpp) == opt)
288 if ((**tagpp) == EFX_DHCP_END) {
291 } else if ((**tagpp) == EFX_DHCP_PAD) {
294 if (*buffer_sizep < sizeof (efx_dhcp_tag_hdr_t)) {
300 DHCP_FULL_TAG_LENGTH((efx_dhcp_tag_hdr_t *)*tagpp);
303 if (size > *buffer_sizep) {
309 (*buffer_sizep) -= size;
311 if ((*buffer_sizep == 0) && is_encap) {
312 /* Search within encapulator tag finished */
319 * Returns 0 if found otherwise ENOENT indicating search finished
329 EFSYS_PROBE1(fail1, efx_rc_t, rc);
335 * Locate value buffer for option in the given buffer.
336 * Returns 0 if found, ENOENT indicating search finished
337 * correctly, otherwise search failed before completion.
339 __checkReturn efx_rc_t
341 __in_bcount(buffer_length) uint8_t *bufferp,
342 __in size_t buffer_length,
344 __deref_out uint8_t **valuepp,
345 __out size_t *value_lengthp)
348 uint8_t *tagp = bufferp;
349 size_t len = buffer_length;
351 rc = efx_dhcp_walk_tags(&tagp, &len, opt);
353 efx_dhcp_tag_hdr_t *hdrp;
355 hdrp = (efx_dhcp_tag_hdr_t *)tagp;
356 *valuepp = (uint8_t *)(&hdrp[1]);
357 *value_lengthp = hdrp->length;
358 } else if (rc != ENOENT) {
365 EFSYS_PROBE1(fail1, efx_rc_t, rc);
371 * Locate the end tag in the given buffer.
372 * Returns 0 if found, ENOENT indicating search finished
373 * correctly but end tag was not found; otherwise search
374 * failed before completion.
376 __checkReturn efx_rc_t
378 __in_bcount(buffer_length) uint8_t *bufferp,
379 __in size_t buffer_length,
380 __deref_out uint8_t **endpp)
383 uint8_t *endp = bufferp;
384 size_t len = buffer_length;
386 rc = efx_dhcp_walk_tags(&endp, &len, EFX_DHCP_END);
389 else if (rc != ENOENT)
395 EFSYS_PROBE1(fail1, efx_rc_t, rc);
401 * Delete the given tag from anywhere in the buffer. Copes with
402 * encapsulated tags, and updates or deletes the encapsulating opt as
405 __checkReturn efx_rc_t
407 __inout_bcount(buffer_length) uint8_t *bufferp,
408 __in size_t buffer_length,
412 efx_dhcp_tag_hdr_t *hdrp;
420 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
425 rc = efx_dhcp_walk_tags(&startp, &len, opt);
429 hdrp = (efx_dhcp_tag_hdr_t *)startp;
431 if (DHCP_IS_ENCAP_OPT(opt)) {
432 uint8_t tag_length = DHCP_FULL_TAG_LENGTH(hdrp);
433 uint8_t *encapp = bufferp;
434 efx_dhcp_tag_hdr_t *encap_hdrp;
437 rc = efx_dhcp_walk_tags(&encapp, &len,
438 DHCP_ENCAPSULATOR(opt));
442 encap_hdrp = (efx_dhcp_tag_hdr_t *)encapp;
443 if (encap_hdrp->length > tag_length) {
444 encap_hdrp->length = (uint8_t)(
445 (size_t)encap_hdrp->length - tag_length);
447 /* delete the encapsulating tag */
452 startp = (uint8_t *)hdrp;
453 endp = (uint8_t *)DHCP_NEXT_TAG(hdrp);
455 if (startp < bufferp) {
460 if (endp > &bufferp[buffer_length]) {
465 memmove(startp, endp,
466 buffer_length - (endp - bufferp));
477 EFSYS_PROBE1(fail1, efx_rc_t, rc);
483 * Write the tag header into write_pointp and optionally copies the payload
484 * into the space following.
488 __in uint8_t *write_pointp,
490 __in_bcount_opt(value_length)
492 __in size_t value_length)
494 efx_dhcp_tag_hdr_t *hdrp = (efx_dhcp_tag_hdr_t *)write_pointp;
495 hdrp->tag = DHCP_ENCAPSULATED(opt);
496 hdrp->length = (uint8_t)value_length;
497 if ((value_length > 0) && (valuep != NULL))
498 memcpy(&hdrp[1], valuep, value_length);
502 * Add the given tag to the end of the buffer. Copes with creating an
503 * encapsulated tag, and updates or creates the encapsulating opt as
506 __checkReturn efx_rc_t
508 __inout_bcount(buffer_length) uint8_t *bufferp,
509 __in size_t buffer_length,
511 __in_bcount_opt(value_length) uint8_t *valuep,
512 __in size_t value_length)
515 efx_dhcp_tag_hdr_t *encap_hdrp = NULL;
516 uint8_t *insert_pointp = NULL;
518 size_t available_space;
523 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
528 if (value_length > DHCP_MAX_VALUE) {
533 if ((value_length > 0) && (valuep == NULL)) {
539 available_space = buffer_length;
540 rc = efx_dhcp_walk_tags(&endp, &available_space, EFX_DHCP_END);
545 search_size = buffer_length;
546 if (DHCP_IS_ENCAP_OPT(opt)) {
547 rc = efx_dhcp_walk_tags(&searchp, &search_size,
548 DHCP_ENCAPSULATOR(opt));
550 encap_hdrp = (efx_dhcp_tag_hdr_t *)searchp;
552 /* Check encapsulated tag is not present */
553 search_size = encap_hdrp->length;
554 rc = efx_dhcp_walk_tags(&searchp, &search_size,
561 /* Check encapsulator will not overflow */
562 if (((size_t)encap_hdrp->length +
563 DHCP_CALC_TAG_LENGTH(value_length)) >
569 /* Insert at start of existing encapsulator */
570 insert_pointp = (uint8_t *)&encap_hdrp[1];
571 opt = DHCP_ENCAPSULATED(opt);
572 } else if (rc == ENOENT) {
578 /* Check unencapsulated tag is not present */
579 rc = efx_dhcp_walk_tags(&searchp, &search_size,
587 if (insert_pointp == NULL) {
588 /* Insert at end of existing tags */
589 insert_pointp = endp;
592 /* Includes the new encapsulator tag hdr if required */
593 added_length = DHCP_CALC_TAG_LENGTH(value_length) +
594 (DHCP_IS_ENCAP_OPT(opt) ? sizeof (efx_dhcp_tag_hdr_t) : 0);
596 if (available_space <= added_length) {
601 memmove(insert_pointp + added_length, insert_pointp,
602 available_space - added_length);
604 if (DHCP_IS_ENCAP_OPT(opt)) {
605 /* Create new encapsulator header */
606 added_length -= sizeof (efx_dhcp_tag_hdr_t);
607 efx_dhcp_write_tag(insert_pointp,
608 DHCP_ENCAPSULATOR(opt), NULL, added_length);
609 insert_pointp += sizeof (efx_dhcp_tag_hdr_t);
610 } else if (encap_hdrp)
611 /* Modify existing encapsulator header */
612 encap_hdrp->length +=
613 ((uint8_t)DHCP_CALC_TAG_LENGTH(value_length));
615 efx_dhcp_write_tag(insert_pointp, opt, valuep, value_length);
636 EFSYS_PROBE1(fail1, efx_rc_t, rc);
642 * Update an existing tag to the new value. Copes with encapsulated
643 * tags, and updates the encapsulating opt as necessary.
645 __checkReturn efx_rc_t
647 __inout_bcount(buffer_length) uint8_t *bufferp,
648 __in size_t buffer_length,
650 __in uint8_t *value_locationp,
651 __in_bcount_opt(value_length) uint8_t *valuep,
652 __in size_t value_length)
655 uint8_t *write_pointp = value_locationp - sizeof (efx_dhcp_tag_hdr_t);
656 efx_dhcp_tag_hdr_t *hdrp = (efx_dhcp_tag_hdr_t *)write_pointp;
657 efx_dhcp_tag_hdr_t *encap_hdrp = NULL;
660 if (!DHCP_OPT_HAS_VALUE(DHCP_ENCAPSULATED(opt))) {
665 if (value_length > DHCP_MAX_VALUE) {
670 if ((value_length > 0) && (valuep == NULL)) {
675 old_length = hdrp->length;
677 if (old_length < value_length) {
678 uint8_t *endp = bufferp;
679 size_t available_space = buffer_length;
681 rc = efx_dhcp_walk_tags(&endp, &available_space,
686 if (available_space < (value_length - old_length)) {
692 if (DHCP_IS_ENCAP_OPT(opt)) {
693 uint8_t *encapp = bufferp;
694 size_t following_encap = buffer_length;
697 rc = efx_dhcp_walk_tags(&encapp, &following_encap,
698 DHCP_ENCAPSULATOR(opt));
702 encap_hdrp = (efx_dhcp_tag_hdr_t *)encapp;
704 new_length = ((size_t)encap_hdrp->length +
705 value_length - old_length);
706 /* Check encapsulator will not overflow */
707 if (new_length > DHCP_MAX_VALUE) {
712 encap_hdrp->length = (uint8_t)new_length;
716 * Move the following data up/down to accommodate the new payload
719 if (old_length != value_length) {
720 uint8_t *destp = (uint8_t *)DHCP_NEXT_TAG(hdrp) +
721 value_length - old_length;
722 size_t count = &bufferp[buffer_length] -
723 (uint8_t *)DHCP_NEXT_TAG(hdrp);
725 memmove(destp, DHCP_NEXT_TAG(hdrp), count);
728 EFSYS_ASSERT(hdrp->tag == DHCP_ENCAPSULATED(opt));
729 efx_dhcp_write_tag(write_pointp, opt, valuep, value_length);
746 EFSYS_PROBE1(fail1, efx_rc_t, rc);
752 * Copy bootcfg sector data to a target buffer which may differ in size.
753 * Optionally corrects format errors in source buffer.
756 efx_bootcfg_copy_sector(
758 __inout_bcount(sector_length)
760 __in size_t sector_length,
761 __out_bcount(data_size) uint8_t *data,
762 __in size_t data_size,
763 __in boolean_t handle_format_errors)
765 _NOTE(ARGUNUSED(enp))
770 /* Minimum buffer is checksum byte and EFX_DHCP_END terminator */
776 /* Verify that the area is correctly formatted and checksummed */
777 rc = efx_dhcp_verify(sector, sector_length,
780 if (!handle_format_errors) {
784 if ((used_bytes < 2) ||
785 (sector[used_bytes - 1] != EFX_DHCP_END)) {
786 /* Block too short, or EFX_DHCP_END missing */
792 /* Synthesize empty format on verification failure */
793 if (rc != 0 || used_bytes == 0) {
795 sector[1] = EFX_DHCP_END;
798 EFSYS_ASSERT(used_bytes >= 2); /* checksum and EFX_DHCP_END */
799 EFSYS_ASSERT(used_bytes <= sector_length);
800 EFSYS_ASSERT(sector_length >= 2);
803 * Legacy bootcfg sectors don't terminate with an EFX_DHCP_END
804 * character. Modify the returned payload so it does.
805 * Reinitialise the sector if there isn't room for the character.
807 if (sector[used_bytes - 1] != EFX_DHCP_END) {
808 if (used_bytes >= sector_length) {
812 sector[used_bytes] = EFX_DHCP_END;
817 * Verify that the target buffer is large enough for the
818 * entire used bootcfg area, then copy into the target buffer.
820 if (used_bytes > data_size) {
825 data[0] = 0; /* checksum, updated below */
827 /* Copy all after the checksum to the target buffer */
828 memcpy(data + 1, sector + 1, used_bytes - 1);
830 /* Zero out the unused portion of the target buffer */
831 if (used_bytes < data_size)
832 (void) memset(data + used_bytes, 0, data_size - used_bytes);
835 * The checksum includes trailing data after any EFX_DHCP_END
836 * character, which we've just modified (by truncation or appending
839 data[0] -= efx_dhcp_csum(data, data_size);
850 EFSYS_PROBE1(fail1, efx_rc_t, rc);
858 __out_bcount(size) uint8_t *data,
861 uint8_t *payload = NULL;
864 size_t sector_length;
865 size_t sector_offset;
867 uint32_t sector_number;
869 /* Minimum buffer is checksum byte and EFX_DHCP_END terminator */
875 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
876 sector_number = enp->en_nic_cfg.enc_pf;
880 rc = efx_nvram_size(enp, EFX_NVRAM_BOOTROM_CFG, &partn_length);
884 /* The bootcfg sector may be stored in a (larger) shared partition */
885 rc = efx_bootcfg_sector_info(enp, sector_number,
886 NULL, §or_offset, §or_length);
890 if (sector_length < 2) {
895 if (sector_length > BOOTCFG_MAX_SIZE)
896 sector_length = BOOTCFG_MAX_SIZE;
898 if (sector_offset + sector_length > partn_length) {
899 /* Partition is too small */
905 * We need to read the entire BOOTCFG sector to ensure we read all
906 * tags, because legacy bootcfg sectors are not guaranteed to end
907 * with an EFX_DHCP_END character. If the user hasn't supplied a
908 * sufficiently large buffer then use our own buffer.
910 if (sector_length > size) {
911 EFSYS_KMEM_ALLOC(enp->en_esip, sector_length, payload);
912 if (payload == NULL) {
917 payload = (uint8_t *)data;
919 if ((rc = efx_nvram_rw_start(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
922 if ((rc = efx_nvram_read_chunk(enp, EFX_NVRAM_BOOTROM_CFG,
923 sector_offset, (caddr_t)payload, sector_length)) != 0) {
924 (void) efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
928 if ((rc = efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
931 /* Verify that the area is correctly formatted and checksummed */
932 rc = efx_dhcp_verify(payload, sector_length,
934 if (rc != 0 || used_bytes == 0) {
936 payload[1] = EFX_DHCP_END;
940 EFSYS_ASSERT(used_bytes >= 2); /* checksum and EFX_DHCP_END */
941 EFSYS_ASSERT(used_bytes <= sector_length);
944 * Legacy bootcfg sectors don't terminate with an EFX_DHCP_END
945 * character. Modify the returned payload so it does.
946 * BOOTCFG_MAX_SIZE is by definition large enough for any valid
947 * (per-port) bootcfg sector, so reinitialise the sector if there
948 * isn't room for the character.
950 if (payload[used_bytes - 1] != EFX_DHCP_END) {
951 if (used_bytes >= sector_length)
954 payload[used_bytes] = EFX_DHCP_END;
959 * Verify that the user supplied buffer is large enough for the
960 * entire used bootcfg area, then copy into the user supplied buffer.
962 if (used_bytes > size) {
967 data[0] = 0; /* checksum, updated below */
969 if (sector_length > size) {
970 /* Copy all after the checksum to the target buffer */
971 memcpy(data + 1, payload + 1, used_bytes - 1);
972 EFSYS_KMEM_FREE(enp->en_esip, sector_length, payload);
975 /* Zero out the unused portion of the user buffer */
976 if (used_bytes < size)
977 (void) memset(data + used_bytes, 0, size - used_bytes);
980 * The checksum includes trailing data after any EFX_DHCP_END character,
981 * which we've just modified (by truncation or appending EFX_DHCP_END).
983 data[0] -= efx_dhcp_csum(data, size);
995 if (sector_length > size)
996 EFSYS_KMEM_FREE(enp->en_esip, sector_length, payload);
1008 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1015 __in efx_nic_t *enp,
1016 __in_bcount(size) uint8_t *data,
1019 uint8_t *partn_data;
1021 size_t partn_length;
1022 size_t sector_length;
1023 size_t sector_offset;
1026 uint32_t sector_number;
1028 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
1029 sector_number = enp->en_nic_cfg.enc_pf;
1034 rc = efx_nvram_size(enp, EFX_NVRAM_BOOTROM_CFG, &partn_length);
1038 /* The bootcfg sector may be stored in a (larger) shared partition */
1039 rc = efx_bootcfg_sector_info(enp, sector_number,
1040 NULL, §or_offset, §or_length);
1044 if (sector_length > BOOTCFG_MAX_SIZE)
1045 sector_length = BOOTCFG_MAX_SIZE;
1047 if (sector_offset + sector_length > partn_length) {
1048 /* Partition is too small */
1053 if ((rc = efx_dhcp_verify(data, size, &used_bytes)) != 0)
1057 * The caller *must* terminate their block with a EFX_DHCP_END
1060 if ((used_bytes < 2) || ((uint8_t)data[used_bytes - 1] !=
1062 /* Block too short or EFX_DHCP_END missing */
1067 /* Check that the hardware has support for this much data */
1068 if (used_bytes > MIN(sector_length, BOOTCFG_MAX_SIZE)) {
1074 * If the BOOTCFG sector is stored in a shared partition, then we must
1075 * read the whole partition and insert the updated bootcfg sector at the
1078 EFSYS_KMEM_ALLOC(enp->en_esip, partn_length, partn_data);
1079 if (partn_data == NULL) {
1084 rc = efx_nvram_rw_start(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
1088 /* Read the entire partition */
1089 rc = efx_nvram_read_chunk(enp, EFX_NVRAM_BOOTROM_CFG, 0,
1090 (caddr_t)partn_data, partn_length);
1095 * Insert the BOOTCFG sector into the partition, Zero out all data
1096 * after the EFX_DHCP_END tag, and adjust the checksum.
1098 (void) memset(partn_data + sector_offset, 0x0, sector_length);
1099 (void) memcpy(partn_data + sector_offset, data, used_bytes);
1101 checksum = efx_dhcp_csum(data, used_bytes);
1102 partn_data[sector_offset] -= checksum;
1104 if ((rc = efx_nvram_erase(enp, EFX_NVRAM_BOOTROM_CFG)) != 0)
1107 if ((rc = efx_nvram_write_chunk(enp, EFX_NVRAM_BOOTROM_CFG,
1108 0, (caddr_t)partn_data, partn_length)) != 0)
1111 if ((rc = efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL)) != 0)
1114 EFSYS_KMEM_FREE(enp->en_esip, partn_length, partn_data);
1119 EFSYS_PROBE(fail12);
1121 EFSYS_PROBE(fail11);
1123 EFSYS_PROBE(fail10);
1127 (void) efx_nvram_rw_finish(enp, EFX_NVRAM_BOOTROM_CFG, NULL);
1131 EFSYS_KMEM_FREE(enp->en_esip, partn_length, partn_data);
1145 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1150 #endif /* EFSYS_OPT_BOOTCFG */