49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright (c) 2009-2015 Solarflare Communications Inc.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Redistribution and use in source and binary forms, with or without
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * modification, are permitted provided that the following conditions are met:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 1. Redistributions of source code must retain the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer in the documentation
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and/or other materials provided with the distribution.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The views and conclusions contained in the software and documentation are
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * those of the authors and should not be interpreted as representing official
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * policies, either expressed or implied, of the FreeBSD Project.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The VPD interface exposes VPD resources from the combined static and
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * dynamic VPD storage. As the static VPD configuration should *never*
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * change, we can cache it.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Unprivileged functions cannot access VPD */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_verify(svpd, svpd_size, NULL)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore enp->en_arch.ef10.ena_svpd_length = svpd_size;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_KMEM_FREE(enp->en_esip, svpd_size, svpd);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * This function returns the total size the user should allocate
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * for all VPD operations. We've already cached the static vpd,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * so we just need to return an upper bound on the dynamic vpd,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * which is the size of the DYNAMIC_CONFIG partition.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_mcdi_nvram_info(enp, NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Pad data with all-1s, consistent with update operations */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) memset(data + dvpd_size, 0xff, size - dvpd_size);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Strictly you could take the view that dynamic vpd is optional.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Instead, to conform more closely to the read/verify/reinit()
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * paradigm, we require dynamic vpd. ef10_vpd_reinit() will
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * reinitialize it as required.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_verify(data, size, NULL)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Verify that there is no duplication between the static and
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * dynamic cfg sectors.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_next(data, size, &dtag,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Skip the RV keyword. It should be present in both the static
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and dynamic cfg sectors.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (dtag == EFX_VPD_RO && dkey == EFX_VPD_KEYWORD('R', 'V'))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore enp->en_arch.ef10.ena_svpd_length, &stag, &skey,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Only create an ID string if the dynamic cfg doesn't have one
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_reinit(data, size, wantpid)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Attempt to satisfy the request from svpd first */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (enp->en_arch.ef10.ena_svpd_length > 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore evvp->evv_keyword, &offset, &length)) == 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore enp->en_arch.ef10.ena_svpd + offset, length);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* And then from the provided data buffer */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_get(data, size, evvp->evv_tag,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) memcpy(evvp->evv_value, data + offset, length);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* If the provided (tag,keyword) exists in svpd, then it is readonly */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (enp->en_arch.ef10.ena_svpd_length > 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore evvp->evv_keyword, &offset, &length)) == 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_set(data, size, evvp)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _NOTE(ARGUNUSED(enp, data, size, evvp, contp))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Determine total length of new dynamic VPD */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_hunk_length(data, size, &vpd_length)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Store new dynamic VPD in all segments in DYNAMIC_CONFIG partition */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = ef10_nvram_partn_write_segment_tlv(enp,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (enp->en_arch.ef10.ena_svpd_length > 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_KMEM_FREE(enp->en_esip, enp->en_arch.ef10.ena_svpd_length,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#endif /* EFSYS_OPT_VPD */