2 * Copyright (c) 2009-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
39 #include "ef10_tlv_layout.h"
41 __checkReturn efx_rc_t
51 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
52 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
53 enp->en_family == EFX_FAMILY_MEDFORD);
55 if (enp->en_nic_cfg.enc_vpd_is_global) {
56 tag = TLV_TAG_GLOBAL_STATIC_VPD;
58 pci_pf = enp->en_nic_cfg.enc_pf;
59 tag = TLV_TAG_PF_STATIC_VPD(pci_pf);
63 * The VPD interface exposes VPD resources from the combined static and
64 * dynamic VPD storage. As the static VPD configuration should *never*
65 * change, we can cache it.
69 rc = ef10_nvram_partn_read_tlv(enp,
70 NVRAM_PARTITION_TYPE_STATIC_CONFIG,
71 tag, &svpd, &svpd_size);
74 /* Unprivileged functions cannot access VPD */
80 if (svpd != NULL && svpd_size > 0) {
81 if ((rc = efx_vpd_hunk_verify(svpd, svpd_size, NULL)) != 0)
85 enp->en_arch.ef10.ena_svpd = svpd;
86 enp->en_arch.ef10.ena_svpd_length = svpd_size;
94 EFSYS_KMEM_FREE(enp->en_esip, svpd_size, svpd);
96 EFSYS_PROBE1(fail1, efx_rc_t, rc);
101 __checkReturn efx_rc_t
108 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
109 enp->en_family == EFX_FAMILY_MEDFORD);
112 * This function returns the total size the user should allocate
113 * for all VPD operations. We've already cached the static vpd,
114 * so we just need to return an upper bound on the dynamic vpd,
115 * which is the size of the DYNAMIC_CONFIG partition.
117 if ((rc = efx_mcdi_nvram_info(enp, NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
118 sizep, NULL, NULL, NULL)) != 0)
124 EFSYS_PROBE1(fail1, efx_rc_t, rc);
129 __checkReturn efx_rc_t
132 __out_bcount(size) caddr_t data,
141 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
142 enp->en_family == EFX_FAMILY_MEDFORD);
144 if (enp->en_nic_cfg.enc_vpd_is_global) {
145 tag = TLV_TAG_GLOBAL_DYNAMIC_VPD;
147 pci_pf = enp->en_nic_cfg.enc_pf;
148 tag = TLV_TAG_PF_DYNAMIC_VPD(pci_pf);
151 if ((rc = ef10_nvram_partn_read_tlv(enp,
152 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
153 tag, &dvpd, &dvpd_size)) != 0)
156 if (dvpd_size > size) {
160 memcpy(data, dvpd, dvpd_size);
162 /* Pad data with all-1s, consistent with update operations */
163 memset(data + dvpd_size, 0xff, size - dvpd_size);
165 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
172 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
174 EFSYS_PROBE1(fail1, efx_rc_t, rc);
179 __checkReturn efx_rc_t
182 __in_bcount(size) caddr_t data,
187 efx_vpd_keyword_t skey;
188 efx_vpd_keyword_t dkey;
193 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
194 enp->en_family == EFX_FAMILY_MEDFORD);
197 * Strictly you could take the view that dynamic vpd is optional.
198 * Instead, to conform more closely to the read/verify/reinit()
199 * paradigm, we require dynamic vpd. ef10_vpd_reinit() will
200 * reinitialize it as required.
202 if ((rc = efx_vpd_hunk_verify(data, size, NULL)) != 0)
206 * Verify that there is no duplication between the static and
207 * dynamic cfg sectors.
209 if (enp->en_arch.ef10.ena_svpd_length == 0)
213 _NOTE(CONSTANTCONDITION)
215 if ((rc = efx_vpd_hunk_next(data, size, &dtag,
216 &dkey, NULL, NULL, &dcont)) != 0)
222 * Skip the RV keyword. It should be present in both the static
223 * and dynamic cfg sectors.
225 if (dtag == EFX_VPD_RO && dkey == EFX_VPD_KEYWORD('R', 'V'))
229 _NOTE(CONSTANTCONDITION)
231 if ((rc = efx_vpd_hunk_next(
232 enp->en_arch.ef10.ena_svpd,
233 enp->en_arch.ef10.ena_svpd_length, &stag, &skey,
234 NULL, NULL, &scont)) != 0)
239 if (stag == dtag && skey == dkey) {
256 EFSYS_PROBE1(fail1, efx_rc_t, rc);
261 __checkReturn efx_rc_t
264 __in_bcount(size) caddr_t data,
271 * Only create an ID string if the dynamic cfg doesn't have one
273 if (enp->en_arch.ef10.ena_svpd_length == 0)
279 rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
280 enp->en_arch.ef10.ena_svpd_length,
281 EFX_VPD_ID, 0, &offset, &length);
284 else if (rc == ENOENT)
290 if ((rc = efx_vpd_hunk_reinit(data, size, wantpid)) != 0)
298 EFSYS_PROBE1(fail1, efx_rc_t, rc);
303 __checkReturn efx_rc_t
306 __in_bcount(size) caddr_t data,
308 __inout efx_vpd_value_t *evvp)
314 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
315 enp->en_family == EFX_FAMILY_MEDFORD);
317 /* Attempt to satisfy the request from svpd first */
318 if (enp->en_arch.ef10.ena_svpd_length > 0) {
319 if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
320 enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
321 evvp->evv_keyword, &offset, &length)) == 0) {
322 evvp->evv_length = length;
323 memcpy(evvp->evv_value,
324 enp->en_arch.ef10.ena_svpd + offset, length);
326 } else if (rc != ENOENT)
330 /* And then from the provided data buffer */
331 if ((rc = efx_vpd_hunk_get(data, size, evvp->evv_tag,
332 evvp->evv_keyword, &offset, &length)) != 0) {
338 evvp->evv_length = length;
339 memcpy(evvp->evv_value, data + offset, length);
346 EFSYS_PROBE1(fail1, efx_rc_t, rc);
351 __checkReturn efx_rc_t
354 __in_bcount(size) caddr_t data,
356 __in efx_vpd_value_t *evvp)
360 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
361 enp->en_family == EFX_FAMILY_MEDFORD);
363 /* If the provided (tag,keyword) exists in svpd, then it is readonly */
364 if (enp->en_arch.ef10.ena_svpd_length > 0) {
368 if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
369 enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
370 evvp->evv_keyword, &offset, &length)) == 0) {
376 if ((rc = efx_vpd_hunk_set(data, size, evvp)) != 0)
384 EFSYS_PROBE1(fail1, efx_rc_t, rc);
389 __checkReturn efx_rc_t
392 __in_bcount(size) caddr_t data,
394 __out efx_vpd_value_t *evvp,
395 __inout unsigned int *contp)
397 _NOTE(ARGUNUSED(enp, data, size, evvp, contp))
402 __checkReturn efx_rc_t
405 __in_bcount(size) caddr_t data,
413 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
414 enp->en_family == EFX_FAMILY_MEDFORD);
416 if (enp->en_nic_cfg.enc_vpd_is_global) {
417 tag = TLV_TAG_GLOBAL_DYNAMIC_VPD;
419 pci_pf = enp->en_nic_cfg.enc_pf;
420 tag = TLV_TAG_PF_DYNAMIC_VPD(pci_pf);
423 /* Determine total length of new dynamic VPD */
424 if ((rc = efx_vpd_hunk_length(data, size, &vpd_length)) != 0)
427 /* Store new dynamic VPD in all segments in DYNAMIC_CONFIG partition */
428 if ((rc = ef10_nvram_partn_write_segment_tlv(enp,
429 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
430 tag, data, vpd_length, B_TRUE)) != 0) {
440 EFSYS_PROBE1(fail1, efx_rc_t, rc);
449 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
450 enp->en_family == EFX_FAMILY_MEDFORD);
452 if (enp->en_arch.ef10.ena_svpd_length > 0) {
453 EFSYS_KMEM_FREE(enp->en_esip, enp->en_arch.ef10.ena_svpd_length,
454 enp->en_arch.ef10.ena_svpd);
456 enp->en_arch.ef10.ena_svpd = NULL;
457 enp->en_arch.ef10.ena_svpd_length = 0;
461 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
463 #endif /* EFSYS_OPT_VPD */