2 * Copyright 2009 Solarflare Communications Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
31 #include "efx_types.h"
37 #if EFSYS_OPT_VPD || EFSYS_OPT_NVRAM
40 siena_nvram_partn_size(
42 __in unsigned int partn,
46 uint8_t payload[MAX(MC_CMD_NVRAM_INFO_IN_LEN,
47 MC_CMD_NVRAM_INFO_OUT_LEN)];
50 if ((1 << partn) & ~enp->en_u.siena.enu_partn_mask) {
55 req.emr_cmd = MC_CMD_NVRAM_INFO;
56 req.emr_in_buf = payload;
57 req.emr_in_length = MC_CMD_NVRAM_INFO_IN_LEN;
58 req.emr_out_buf = payload;
59 req.emr_out_length = MC_CMD_NVRAM_INFO_OUT_LEN;
61 MCDI_IN_SET_DWORD(req, NVRAM_INFO_IN_TYPE, partn);
63 efx_mcdi_execute(enp, &req);
65 if (req.emr_rc != 0) {
70 if (req.emr_out_length_used < MC_CMD_NVRAM_INFO_OUT_LEN) {
75 *sizep = MCDI_OUT_DWORD(req, NVRAM_INFO_OUT_SIZE);
84 EFSYS_PROBE1(fail1, int, rc);
90 siena_nvram_partn_lock(
92 __in unsigned int partn)
95 uint8_t payload[MC_CMD_NVRAM_UPDATE_START_IN_LEN];
98 req.emr_cmd = MC_CMD_NVRAM_UPDATE_START;
99 req.emr_in_buf = payload;
100 req.emr_in_length = MC_CMD_NVRAM_UPDATE_START_IN_LEN;
101 EFX_STATIC_ASSERT(MC_CMD_NVRAM_UPDATE_START_OUT_LEN == 0);
102 req.emr_out_buf = NULL;
103 req.emr_out_length = 0;
105 MCDI_IN_SET_DWORD(req, NVRAM_UPDATE_START_IN_TYPE, partn);
107 efx_mcdi_execute(enp, &req);
109 if (req.emr_rc != 0) {
117 EFSYS_PROBE1(fail1, int, rc);
123 siena_nvram_partn_read(
125 __in unsigned int partn,
126 __in unsigned int offset,
127 __out_bcount(size) caddr_t data,
131 uint8_t payload[MAX(MC_CMD_NVRAM_READ_IN_LEN,
132 MC_CMD_NVRAM_READ_OUT_LEN(SIENA_NVRAM_CHUNK))];
137 chunk = MIN(size, SIENA_NVRAM_CHUNK);
139 req.emr_cmd = MC_CMD_NVRAM_READ;
140 req.emr_in_buf = payload;
141 req.emr_in_length = MC_CMD_NVRAM_READ_IN_LEN;
142 req.emr_out_buf = payload;
144 MC_CMD_NVRAM_READ_OUT_LEN(SIENA_NVRAM_CHUNK);
146 MCDI_IN_SET_DWORD(req, NVRAM_READ_IN_TYPE, partn);
147 MCDI_IN_SET_DWORD(req, NVRAM_READ_IN_OFFSET, offset);
148 MCDI_IN_SET_DWORD(req, NVRAM_READ_IN_LENGTH, chunk);
150 efx_mcdi_execute(enp, &req);
152 if (req.emr_rc != 0) {
157 if (req.emr_out_length_used <
158 MC_CMD_NVRAM_READ_OUT_LEN(chunk)) {
164 MCDI_OUT2(req, uint8_t, NVRAM_READ_OUT_READ_BUFFER),
177 EFSYS_PROBE1(fail1, int, rc);
183 siena_nvram_partn_erase(
185 __in unsigned int partn,
186 __in unsigned int offset,
190 uint8_t payload[MC_CMD_NVRAM_ERASE_IN_LEN];
193 req.emr_cmd = MC_CMD_NVRAM_ERASE;
194 req.emr_in_buf = payload;
195 req.emr_in_length = MC_CMD_NVRAM_ERASE_IN_LEN;
196 EFX_STATIC_ASSERT(MC_CMD_NVRAM_ERASE_OUT_LEN == 0);
197 req.emr_out_buf = NULL;
198 req.emr_out_length = 0;
200 MCDI_IN_SET_DWORD(req, NVRAM_ERASE_IN_TYPE, partn);
201 MCDI_IN_SET_DWORD(req, NVRAM_ERASE_IN_OFFSET, offset);
202 MCDI_IN_SET_DWORD(req, NVRAM_ERASE_IN_LENGTH, size);
204 efx_mcdi_execute(enp, &req);
206 if (req.emr_rc != 0) {
214 EFSYS_PROBE1(fail1, int, rc);
220 siena_nvram_partn_write(
222 __in unsigned int partn,
223 __in unsigned int offset,
224 __out_bcount(size) caddr_t data,
228 uint8_t payload[MC_CMD_NVRAM_WRITE_IN_LEN(SIENA_NVRAM_CHUNK)];
233 chunk = MIN(size, SIENA_NVRAM_CHUNK);
235 req.emr_cmd = MC_CMD_NVRAM_WRITE;
236 req.emr_in_buf = payload;
237 req.emr_in_length = MC_CMD_NVRAM_WRITE_IN_LEN(chunk);
238 EFX_STATIC_ASSERT(MC_CMD_NVRAM_WRITE_OUT_LEN == 0);
239 req.emr_out_buf = NULL;
240 req.emr_out_length = 0;
242 MCDI_IN_SET_DWORD(req, NVRAM_WRITE_IN_TYPE, partn);
243 MCDI_IN_SET_DWORD(req, NVRAM_WRITE_IN_OFFSET, offset);
244 MCDI_IN_SET_DWORD(req, NVRAM_WRITE_IN_LENGTH, chunk);
246 memcpy(MCDI_IN2(req, uint8_t, NVRAM_WRITE_IN_WRITE_BUFFER),
249 efx_mcdi_execute(enp, &req);
251 if (req.emr_rc != 0) {
264 EFSYS_PROBE1(fail1, int, rc);
270 siena_nvram_partn_unlock(
272 __in unsigned int partn)
275 uint8_t payload[MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN];
279 req.emr_cmd = MC_CMD_NVRAM_UPDATE_FINISH;
280 req.emr_in_buf = payload;
281 req.emr_in_length = MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN;
282 EFX_STATIC_ASSERT(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN == 0);
283 req.emr_out_buf = NULL;
284 req.emr_out_length = 0;
287 * Reboot into the new image only for PHYs. The driver has to
288 * explicitly cope with an MC reboot after a firmware update.
290 reboot = (partn == MC_CMD_NVRAM_TYPE_PHY_PORT0 ||
291 partn == MC_CMD_NVRAM_TYPE_PHY_PORT1 ||
292 partn == MC_CMD_NVRAM_TYPE_DISABLED_CALLISTO);
294 MCDI_IN_SET_DWORD(req, NVRAM_UPDATE_FINISH_IN_TYPE, partn);
295 MCDI_IN_SET_DWORD(req, NVRAM_UPDATE_FINISH_IN_REBOOT, reboot);
297 efx_mcdi_execute(enp, &req);
299 if (req.emr_rc != 0) {
307 EFSYS_PROBE1(fail1, int, rc);
310 #endif /* EFSYS_OPT_VPD || EFSYS_OPT_NVRAM */
314 typedef struct siena_parttbl_entry_s {
317 efx_nvram_type_t nvtype;
318 } siena_parttbl_entry_t;
320 static siena_parttbl_entry_t siena_parttbl[] = {
321 {MC_CMD_NVRAM_TYPE_DISABLED_CALLISTO, 1, EFX_NVRAM_NULLPHY},
322 {MC_CMD_NVRAM_TYPE_DISABLED_CALLISTO, 2, EFX_NVRAM_NULLPHY},
323 {MC_CMD_NVRAM_TYPE_MC_FW, 1, EFX_NVRAM_MC_FIRMWARE},
324 {MC_CMD_NVRAM_TYPE_MC_FW, 2, EFX_NVRAM_MC_FIRMWARE},
325 {MC_CMD_NVRAM_TYPE_MC_FW_BACKUP, 1, EFX_NVRAM_MC_GOLDEN},
326 {MC_CMD_NVRAM_TYPE_MC_FW_BACKUP, 2, EFX_NVRAM_MC_GOLDEN},
327 {MC_CMD_NVRAM_TYPE_EXP_ROM, 1, EFX_NVRAM_BOOTROM},
328 {MC_CMD_NVRAM_TYPE_EXP_ROM, 2, EFX_NVRAM_BOOTROM},
329 {MC_CMD_NVRAM_TYPE_EXP_ROM_CFG_PORT0, 1, EFX_NVRAM_BOOTROM_CFG},
330 {MC_CMD_NVRAM_TYPE_EXP_ROM_CFG_PORT1, 2, EFX_NVRAM_BOOTROM_CFG},
331 {MC_CMD_NVRAM_TYPE_PHY_PORT0, 1, EFX_NVRAM_PHY},
332 {MC_CMD_NVRAM_TYPE_PHY_PORT1, 2, EFX_NVRAM_PHY},
336 static __checkReturn siena_parttbl_entry_t *
339 __in efx_nvram_type_t type)
341 efx_mcdi_iface_t *emip = &(enp->en_u.siena.enu_mip);
342 siena_parttbl_entry_t *entry;
344 EFSYS_ASSERT3U(type, <, EFX_NVRAM_NTYPES);
346 for (entry = siena_parttbl; entry->port > 0; ++entry) {
347 if (entry->port == emip->emi_port && entry->nvtype == type)
360 efx_mcdi_iface_t *emip = &(enp->en_u.siena.enu_mip);
361 siena_parttbl_entry_t *entry;
363 uint8_t payload[MAX(MC_CMD_NVRAM_TEST_IN_LEN,
364 MC_CMD_NVRAM_TEST_OUT_LEN)];
368 req.emr_cmd = MC_CMD_NVRAM_TEST;
369 req.emr_in_buf = payload;
370 req.emr_in_length = MC_CMD_NVRAM_TEST_IN_LEN;
371 req.emr_out_buf = payload;
372 req.emr_out_length = MC_CMD_NVRAM_TEST_OUT_LEN;
375 * Iterate over the list of supported partition types
376 * applicable to *this* port
378 for (entry = siena_parttbl; entry->port > 0; ++entry) {
379 if (entry->port != emip->emi_port ||
380 !(enp->en_u.siena.enu_partn_mask & (1 << entry->partn)))
383 MCDI_IN_SET_DWORD(req, NVRAM_TEST_IN_TYPE, entry->partn);
385 efx_mcdi_execute(enp, &req);
387 if (req.emr_rc != 0) {
392 if (req.emr_out_length_used < MC_CMD_NVRAM_TEST_OUT_LEN) {
397 result = MCDI_OUT_DWORD(req, NVRAM_TEST_OUT_RESULT);
398 if (result == MC_CMD_NVRAM_TEST_FAIL) {
400 EFSYS_PROBE1(nvram_test_failure, int, entry->partn);
414 EFSYS_PROBE1(fail1, int, rc);
419 #endif /* EFSYS_OPT_DIAG */
424 __in efx_nvram_type_t type,
427 siena_parttbl_entry_t *entry;
430 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
435 if ((rc = siena_nvram_partn_size(enp, entry->partn, sizep)) != 0)
443 EFSYS_PROBE1(fail1, int, rc);
450 #define SIENA_DYNAMIC_CFG_SIZE(_nitems) \
451 (sizeof (siena_mc_dynamic_config_hdr_t) + ((_nitems) * \
452 sizeof (((siena_mc_dynamic_config_hdr_t *)NULL)->fw_version[0])))
455 siena_nvram_get_dynamic_cfg(
457 __in unsigned int partn,
459 __out siena_mc_dynamic_config_hdr_t **dcfgp,
462 siena_mc_dynamic_config_hdr_t *dcfg;
465 unsigned int vpd_offset;
466 unsigned int vpd_length;
467 unsigned int hdr_length;
468 unsigned int nversions;
473 EFSYS_ASSERT(partn == MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT0 ||
474 partn == MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT1);
477 * Allocate sufficient memory for the entire dynamiccfg area, even
478 * if we're not actually going to read in the VPD.
480 if ((rc = siena_nvram_partn_size(enp, partn, &size)) != 0)
483 EFSYS_KMEM_ALLOC(enp->en_esip, size, dcfg);
489 if ((rc = siena_nvram_partn_read(enp, partn, 0,
490 (caddr_t)dcfg, SIENA_NVRAM_CHUNK)) != 0)
493 /* Verify the magic */
494 if (EFX_DWORD_FIELD(dcfg->magic, EFX_DWORD_0)
495 != SIENA_MC_DYNAMIC_CONFIG_MAGIC)
498 /* All future versions of the structure must be backwards compatable */
499 EFX_STATIC_ASSERT(SIENA_MC_DYNAMIC_CONFIG_VERSION == 0);
501 hdr_length = EFX_WORD_FIELD(dcfg->length, EFX_WORD_0);
502 nversions = EFX_DWORD_FIELD(dcfg->num_fw_version_items, EFX_DWORD_0);
503 vpd_offset = EFX_DWORD_FIELD(dcfg->dynamic_vpd_offset, EFX_DWORD_0);
504 vpd_length = EFX_DWORD_FIELD(dcfg->dynamic_vpd_length, EFX_DWORD_0);
506 /* Verify the hdr doesn't overflow the partn size */
507 if (hdr_length > size || vpd_offset > size || vpd_length > size ||
508 vpd_length + vpd_offset > size)
511 /* Verify the header has room for all it's versions */
512 if (hdr_length < SIENA_DYNAMIC_CFG_SIZE(0) ||
513 hdr_length < SIENA_DYNAMIC_CFG_SIZE(nversions))
517 * Read the remaining portion of the dcfg, either including
518 * the whole of VPD (there is no vpd length in this structure,
519 * so we have to parse each tag), or just the dcfg header itself
521 region = vpd ? vpd_offset + vpd_length : hdr_length;
522 if (region > SIENA_NVRAM_CHUNK) {
523 if ((rc = siena_nvram_partn_read(enp, partn, SIENA_NVRAM_CHUNK,
524 (caddr_t)dcfg + SIENA_NVRAM_CHUNK,
525 region - SIENA_NVRAM_CHUNK)) != 0)
529 /* Verify checksum */
531 for (pos = 0; pos < hdr_length; pos++)
532 cksum += ((uint8_t *)dcfg)[pos];
539 EFSYS_PROBE(invalid4);
541 EFSYS_PROBE(invalid3);
543 EFSYS_PROBE(invalid2);
545 EFSYS_PROBE(invalid1);
548 * Construct a new "null" dcfg, with an empty version vector,
549 * and an empty VPD chunk trailing. This has the neat side effect
550 * of testing the exception paths in the write path.
552 EFX_POPULATE_DWORD_1(dcfg->magic,
553 EFX_DWORD_0, SIENA_MC_DYNAMIC_CONFIG_MAGIC);
554 EFX_POPULATE_WORD_1(dcfg->length, EFX_WORD_0, sizeof (*dcfg));
555 EFX_POPULATE_BYTE_1(dcfg->version, EFX_BYTE_0,
556 SIENA_MC_DYNAMIC_CONFIG_VERSION);
557 EFX_POPULATE_DWORD_1(dcfg->dynamic_vpd_offset,
558 EFX_DWORD_0, sizeof (*dcfg));
559 EFX_POPULATE_DWORD_1(dcfg->dynamic_vpd_length, EFX_DWORD_0, 0);
560 EFX_POPULATE_DWORD_1(dcfg->num_fw_version_items, EFX_DWORD_0, 0);
575 EFSYS_KMEM_FREE(enp->en_esip, size, dcfg);
578 EFSYS_PROBE1(fail1, int, rc);
583 static __checkReturn int
584 siena_nvram_get_subtype(
586 __in unsigned int partn,
587 __out uint32_t *subtypep)
590 uint8_t outbuf[MC_CMD_GET_BOARD_CFG_OUT_LEN];
594 req.emr_cmd = MC_CMD_GET_BOARD_CFG;
595 EFX_STATIC_ASSERT(MC_CMD_GET_BOARD_CFG_IN_LEN == 0);
596 req.emr_in_buf = NULL;
597 req.emr_in_length = 0;
598 req.emr_out_buf = outbuf;
599 req.emr_out_length = sizeof (outbuf);
601 efx_mcdi_execute(enp, &req);
603 if (req.emr_rc != 0) {
608 if (req.emr_out_length_used < MC_CMD_GET_BOARD_CFG_OUT_LEN) {
613 fw_list = MCDI_OUT2(req, efx_word_t,
614 GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST);
615 *subtypep = EFX_WORD_FIELD(fw_list[partn], EFX_WORD_0);
622 EFSYS_PROBE1(fail1, int, rc);
628 siena_nvram_get_version(
630 __in efx_nvram_type_t type,
631 __out uint32_t *subtypep,
632 __out_ecount(4) uint16_t version[4])
634 siena_mc_dynamic_config_hdr_t *dcfg;
635 siena_parttbl_entry_t *entry;
636 unsigned int dcfg_partn;
640 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
644 partn = entry->partn;
646 if ((1 << partn) & ~enp->en_u.siena.enu_partn_mask) {
651 if ((rc = siena_nvram_get_subtype(enp, partn, subtypep)) != 0)
655 * Some partitions are accessible from both ports (for instance BOOTROM)
656 * Find the highest version reported by all dcfg structures on ports
657 * that have access to this partition.
659 version[0] = version[1] = version[2] = version[3] = 0;
660 for (entry = siena_parttbl; entry->port > 0; ++entry) {
665 if (entry->partn != partn)
668 dcfg_partn = (entry->port == 1)
669 ? MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT0
670 : MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT1;
672 * Ingore missing partitions on port 2, assuming they're due
673 * to to running on a single port part.
675 if ((1 << dcfg_partn) & ~enp->en_u.siena.enu_partn_mask) {
676 if (entry->port == 2)
680 if ((rc = siena_nvram_get_dynamic_cfg(enp, dcfg_partn,
681 B_FALSE, &dcfg, &length)) != 0)
684 nitems = EFX_DWORD_FIELD(dcfg->num_fw_version_items,
686 if (nitems < entry->partn)
689 temp[0] = EFX_WORD_FIELD(dcfg->fw_version[partn].version_w,
691 temp[1] = EFX_WORD_FIELD(dcfg->fw_version[partn].version_x,
693 temp[2] = EFX_WORD_FIELD(dcfg->fw_version[partn].version_y,
695 temp[3] = EFX_WORD_FIELD(dcfg->fw_version[partn].version_z,
697 if (memcmp(version, temp, sizeof (temp)) < 0)
698 memcpy(version, temp, sizeof (temp));
701 EFSYS_KMEM_FREE(enp->en_esip, length, dcfg);
713 EFSYS_PROBE1(fail1, int, rc);
719 siena_nvram_rw_start(
721 __in efx_nvram_type_t type,
722 __out size_t *chunk_sizep)
724 siena_parttbl_entry_t *entry;
727 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
732 if ((rc = siena_nvram_partn_lock(enp, entry->partn)) != 0)
735 if (chunk_sizep != NULL)
736 *chunk_sizep = SIENA_NVRAM_CHUNK;
743 EFSYS_PROBE1(fail1, int, rc);
749 siena_nvram_read_chunk(
751 __in efx_nvram_type_t type,
752 __in unsigned int offset,
753 __out_bcount(size) caddr_t data,
756 siena_parttbl_entry_t *entry;
759 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
764 if ((rc = siena_nvram_partn_read(enp, entry->partn,
765 offset, data, size)) != 0)
773 EFSYS_PROBE1(fail1, int, rc);
781 __in efx_nvram_type_t type)
783 siena_parttbl_entry_t *entry;
787 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
792 if ((rc = siena_nvram_partn_size(enp, entry->partn, &size)) != 0)
795 if ((rc = siena_nvram_partn_erase(enp, entry->partn, 0, size)) != 0)
805 EFSYS_PROBE1(fail1, int, rc);
811 siena_nvram_write_chunk(
813 __in efx_nvram_type_t type,
814 __in unsigned int offset,
815 __in_bcount(size) caddr_t data,
818 siena_parttbl_entry_t *entry;
821 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
826 if ((rc = siena_nvram_partn_write(enp, entry->partn,
827 offset, data, size)) != 0)
835 EFSYS_PROBE1(fail1, int, rc);
841 siena_nvram_rw_finish(
843 __in efx_nvram_type_t type)
845 siena_parttbl_entry_t *entry;
847 if ((entry = siena_parttbl_entry(enp, type)) != NULL)
848 siena_nvram_partn_unlock(enp, entry->partn);
852 siena_nvram_set_version(
854 __in efx_nvram_type_t type,
855 __out uint16_t version[4])
857 siena_mc_dynamic_config_hdr_t *dcfg = NULL;
858 siena_parttbl_entry_t *entry;
859 unsigned int dcfg_partn;
861 unsigned int hdr_length;
862 unsigned int vpd_length;
863 unsigned int vpd_offset;
865 unsigned int required_hdr_length;
872 if ((entry = siena_parttbl_entry(enp, type)) == NULL) {
877 dcfg_partn = (entry->port == 1)
878 ? MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT0
879 : MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT1;
881 if ((rc = siena_nvram_partn_size(enp, dcfg_partn, &partn_size)) != 0)
884 if ((rc = siena_nvram_partn_lock(enp, dcfg_partn)) != 0)
887 if ((rc = siena_nvram_get_dynamic_cfg(enp, dcfg_partn,
888 B_TRUE, &dcfg, &length)) != 0)
891 hdr_length = EFX_WORD_FIELD(dcfg->length, EFX_WORD_0);
892 nitems = EFX_DWORD_FIELD(dcfg->num_fw_version_items, EFX_DWORD_0);
893 vpd_length = EFX_DWORD_FIELD(dcfg->dynamic_vpd_length, EFX_DWORD_0);
894 vpd_offset = EFX_DWORD_FIELD(dcfg->dynamic_vpd_offset, EFX_DWORD_0);
897 * NOTE: This function will blatt any fields trailing the version
898 * vector, or the VPD chunk.
900 required_hdr_length = SIENA_DYNAMIC_CFG_SIZE(entry->partn + 1);
901 if (required_hdr_length + vpd_length > length) {
906 if (vpd_offset < required_hdr_length) {
907 (void) memmove((caddr_t)dcfg + required_hdr_length,
908 (caddr_t)dcfg + vpd_offset, vpd_length);
909 vpd_offset = required_hdr_length;
910 EFX_POPULATE_DWORD_1(dcfg->dynamic_vpd_offset,
911 EFX_DWORD_0, vpd_offset);
914 if (hdr_length < required_hdr_length) {
915 (void) memset((caddr_t)dcfg + hdr_length, 0,
916 required_hdr_length - hdr_length);
917 hdr_length = required_hdr_length;
918 EFX_POPULATE_WORD_1(dcfg->length,
919 EFX_WORD_0, hdr_length);
922 /* Get the subtype to insert into the fw_subtype array */
923 if ((rc = siena_nvram_get_subtype(enp, entry->partn, &subtype)) != 0)
926 /* Fill out the new version */
927 EFX_POPULATE_DWORD_1(dcfg->fw_version[entry->partn].fw_subtype,
928 EFX_DWORD_0, subtype);
929 EFX_POPULATE_WORD_1(dcfg->fw_version[entry->partn].version_w,
930 EFX_WORD_0, version[0]);
931 EFX_POPULATE_WORD_1(dcfg->fw_version[entry->partn].version_x,
932 EFX_WORD_0, version[1]);
933 EFX_POPULATE_WORD_1(dcfg->fw_version[entry->partn].version_y,
934 EFX_WORD_0, version[2]);
935 EFX_POPULATE_WORD_1(dcfg->fw_version[entry->partn].version_z,
936 EFX_WORD_0, version[3]);
938 /* Update the version count */
939 if (nitems < entry->partn + 1) {
940 nitems = entry->partn + 1;
941 EFX_POPULATE_DWORD_1(dcfg->num_fw_version_items,
942 EFX_DWORD_0, nitems);
945 /* Update the checksum */
947 for (pos = 0; pos < hdr_length; pos++)
948 cksum += ((uint8_t *)dcfg)[pos];
949 dcfg->csum.eb_u8[0] -= cksum;
951 /* Erase and write the new partition */
952 if ((rc = siena_nvram_partn_erase(enp, dcfg_partn, 0, partn_size)) != 0)
955 /* Write out the new structure to nvram */
956 if ((rc = siena_nvram_partn_write(enp, dcfg_partn, 0,
957 (caddr_t)dcfg, vpd_offset + vpd_length)) != 0)
960 EFSYS_KMEM_FREE(enp->en_esip, length, dcfg);
962 siena_nvram_partn_unlock(enp, dcfg_partn);
975 EFSYS_KMEM_FREE(enp->en_esip, length, dcfg);
981 EFSYS_PROBE1(fail1, int, rc);
986 #endif /* EFSYS_OPT_NVRAM */
988 #endif /* EFSYS_OPT_SIENA */