1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2009-2018 Solarflare Communications Inc.
13 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
15 #include "ef10_tlv_layout.h"
17 __checkReturn efx_rc_t
27 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
28 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
29 enp->en_family == EFX_FAMILY_MEDFORD);
31 if (enp->en_nic_cfg.enc_vpd_is_global) {
32 tag = TLV_TAG_GLOBAL_STATIC_VPD;
34 pci_pf = enp->en_nic_cfg.enc_pf;
35 tag = TLV_TAG_PF_STATIC_VPD(pci_pf);
39 * The VPD interface exposes VPD resources from the combined static and
40 * dynamic VPD storage. As the static VPD configuration should *never*
41 * change, we can cache it.
45 rc = ef10_nvram_partn_read_tlv(enp,
46 NVRAM_PARTITION_TYPE_STATIC_CONFIG,
47 tag, &svpd, &svpd_size);
50 /* Unprivileged functions cannot access VPD */
56 if (svpd != NULL && svpd_size > 0) {
57 if ((rc = efx_vpd_hunk_verify(svpd, svpd_size, NULL)) != 0)
61 enp->en_arch.ef10.ena_svpd = svpd;
62 enp->en_arch.ef10.ena_svpd_length = svpd_size;
70 EFSYS_KMEM_FREE(enp->en_esip, svpd_size, svpd);
72 EFSYS_PROBE1(fail1, efx_rc_t, rc);
77 __checkReturn efx_rc_t
84 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
85 enp->en_family == EFX_FAMILY_MEDFORD);
88 * This function returns the total size the user should allocate
89 * for all VPD operations. We've already cached the static vpd,
90 * so we just need to return an upper bound on the dynamic vpd,
91 * which is the size of the DYNAMIC_CONFIG partition.
93 if ((rc = efx_mcdi_nvram_info(enp, NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
94 sizep, NULL, NULL, NULL)) != 0)
100 EFSYS_PROBE1(fail1, efx_rc_t, rc);
105 __checkReturn efx_rc_t
108 __out_bcount(size) caddr_t data,
117 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
118 enp->en_family == EFX_FAMILY_MEDFORD);
120 if (enp->en_nic_cfg.enc_vpd_is_global) {
121 tag = TLV_TAG_GLOBAL_DYNAMIC_VPD;
123 pci_pf = enp->en_nic_cfg.enc_pf;
124 tag = TLV_TAG_PF_DYNAMIC_VPD(pci_pf);
127 if ((rc = ef10_nvram_partn_read_tlv(enp,
128 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
129 tag, &dvpd, &dvpd_size)) != 0)
132 if (dvpd_size > size) {
136 memcpy(data, dvpd, dvpd_size);
138 /* Pad data with all-1s, consistent with update operations */
139 memset(data + dvpd_size, 0xff, size - dvpd_size);
141 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
148 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
150 EFSYS_PROBE1(fail1, efx_rc_t, rc);
155 __checkReturn efx_rc_t
158 __in_bcount(size) caddr_t data,
163 efx_vpd_keyword_t skey;
164 efx_vpd_keyword_t dkey;
169 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
170 enp->en_family == EFX_FAMILY_MEDFORD);
173 * Strictly you could take the view that dynamic vpd is optional.
174 * Instead, to conform more closely to the read/verify/reinit()
175 * paradigm, we require dynamic vpd. ef10_vpd_reinit() will
176 * reinitialize it as required.
178 if ((rc = efx_vpd_hunk_verify(data, size, NULL)) != 0)
182 * Verify that there is no duplication between the static and
183 * dynamic cfg sectors.
185 if (enp->en_arch.ef10.ena_svpd_length == 0)
189 _NOTE(CONSTANTCONDITION)
191 if ((rc = efx_vpd_hunk_next(data, size, &dtag,
192 &dkey, NULL, NULL, &dcont)) != 0)
198 * Skip the RV keyword. It should be present in both the static
199 * and dynamic cfg sectors.
201 if (dtag == EFX_VPD_RO && dkey == EFX_VPD_KEYWORD('R', 'V'))
205 _NOTE(CONSTANTCONDITION)
207 if ((rc = efx_vpd_hunk_next(
208 enp->en_arch.ef10.ena_svpd,
209 enp->en_arch.ef10.ena_svpd_length, &stag, &skey,
210 NULL, NULL, &scont)) != 0)
215 if (stag == dtag && skey == dkey) {
232 EFSYS_PROBE1(fail1, efx_rc_t, rc);
237 __checkReturn efx_rc_t
240 __in_bcount(size) caddr_t data,
247 * Only create an ID string if the dynamic cfg doesn't have one
249 if (enp->en_arch.ef10.ena_svpd_length == 0)
255 rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
256 enp->en_arch.ef10.ena_svpd_length,
257 EFX_VPD_ID, 0, &offset, &length);
260 else if (rc == ENOENT)
266 if ((rc = efx_vpd_hunk_reinit(data, size, wantpid)) != 0)
274 EFSYS_PROBE1(fail1, efx_rc_t, rc);
279 __checkReturn efx_rc_t
282 __in_bcount(size) caddr_t data,
284 __inout efx_vpd_value_t *evvp)
290 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
291 enp->en_family == EFX_FAMILY_MEDFORD);
293 /* Attempt to satisfy the request from svpd first */
294 if (enp->en_arch.ef10.ena_svpd_length > 0) {
295 if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
296 enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
297 evvp->evv_keyword, &offset, &length)) == 0) {
298 evvp->evv_length = length;
299 memcpy(evvp->evv_value,
300 enp->en_arch.ef10.ena_svpd + offset, length);
302 } else if (rc != ENOENT)
306 /* And then from the provided data buffer */
307 if ((rc = efx_vpd_hunk_get(data, size, evvp->evv_tag,
308 evvp->evv_keyword, &offset, &length)) != 0) {
314 evvp->evv_length = length;
315 memcpy(evvp->evv_value, data + offset, length);
322 EFSYS_PROBE1(fail1, efx_rc_t, rc);
327 __checkReturn efx_rc_t
330 __in_bcount(size) caddr_t data,
332 __in efx_vpd_value_t *evvp)
336 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
337 enp->en_family == EFX_FAMILY_MEDFORD);
339 /* If the provided (tag,keyword) exists in svpd, then it is readonly */
340 if (enp->en_arch.ef10.ena_svpd_length > 0) {
344 if ((rc = efx_vpd_hunk_get(enp->en_arch.ef10.ena_svpd,
345 enp->en_arch.ef10.ena_svpd_length, evvp->evv_tag,
346 evvp->evv_keyword, &offset, &length)) == 0) {
352 if ((rc = efx_vpd_hunk_set(data, size, evvp)) != 0)
360 EFSYS_PROBE1(fail1, efx_rc_t, rc);
365 __checkReturn efx_rc_t
368 __in_bcount(size) caddr_t data,
370 __out efx_vpd_value_t *evvp,
371 __inout unsigned int *contp)
373 _NOTE(ARGUNUSED(enp, data, size, evvp, contp))
378 __checkReturn efx_rc_t
381 __in_bcount(size) caddr_t data,
389 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
390 enp->en_family == EFX_FAMILY_MEDFORD);
392 if (enp->en_nic_cfg.enc_vpd_is_global) {
393 tag = TLV_TAG_GLOBAL_DYNAMIC_VPD;
395 pci_pf = enp->en_nic_cfg.enc_pf;
396 tag = TLV_TAG_PF_DYNAMIC_VPD(pci_pf);
399 /* Determine total length of new dynamic VPD */
400 if ((rc = efx_vpd_hunk_length(data, size, &vpd_length)) != 0)
403 /* Store new dynamic VPD in all segments in DYNAMIC_CONFIG partition */
404 if ((rc = ef10_nvram_partn_write_segment_tlv(enp,
405 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
406 tag, data, vpd_length, B_TRUE)) != 0) {
416 EFSYS_PROBE1(fail1, efx_rc_t, rc);
425 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
426 enp->en_family == EFX_FAMILY_MEDFORD);
428 if (enp->en_arch.ef10.ena_svpd_length > 0) {
429 EFSYS_KMEM_FREE(enp->en_esip, enp->en_arch.ef10.ena_svpd_length,
430 enp->en_arch.ef10.ena_svpd);
432 enp->en_arch.ef10.ena_svpd = NULL;
433 enp->en_arch.ef10.ena_svpd_length = 0;
437 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
439 #endif /* EFSYS_OPT_VPD */