2 * Copyright (c) 2009-2015 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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
36 #include "efx_types.h"
43 #if EFSYS_OPT_HUNTINGTON
45 #include "ef10_tlv_layout.h"
56 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
57 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
59 pci_pf = enp->en_nic_cfg.enc_pf;
61 * The VPD interface exposes VPD resources from the combined static and
62 * dynamic VPD storage. As the static VPD configuration should *never*
63 * change, we can cache it.
67 rc = hunt_nvram_partn_read_tlv(enp,
68 NVRAM_PARTITION_TYPE_STATIC_CONFIG,
69 TLV_TAG_PF_STATIC_VPD(pci_pf),
73 /* Unpriviledged functions cannot access VPD */
79 if (svpd != NULL && svpd_size > 0) {
80 if ((rc = efx_vpd_hunk_verify(svpd, svpd_size, NULL)) != 0)
84 enp->en_u.hunt.enu_svpd = svpd;
85 enp->en_u.hunt.enu_svpd_length = svpd_size;
93 EFSYS_KMEM_FREE(enp->en_esip, svpd_size, svpd);
95 EFSYS_PROBE1(fail1, int, rc);
107 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
110 * This function returns the total size the user should allocate
111 * for all VPD operations. We've already cached the static vpd,
112 * so we just need to return an upper bound on the dynamic vpd,
113 * which is the size of the DYNAMIC_CONFIG partition.
115 if ((rc = efx_mcdi_nvram_info(enp, NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
116 sizep, NULL, NULL)) != 0)
122 EFSYS_PROBE1(fail1, int, rc);
130 __out_bcount(size) caddr_t data,
138 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
140 pci_pf = enp->en_nic_cfg.enc_pf;
142 if ((rc = hunt_nvram_partn_read_tlv(enp,
143 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
144 TLV_TAG_PF_DYNAMIC_VPD(pci_pf),
145 &dvpd, &dvpd_size)) != 0)
148 if (dvpd_size > size) {
152 memcpy(data, dvpd, dvpd_size);
154 /* Pad data with all-1s, consistent with update operations */
155 memset(data + dvpd_size, 0xff, size - dvpd_size);
157 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
164 EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
166 EFSYS_PROBE1(fail1, int, rc);
174 __in_bcount(size) caddr_t data,
179 efx_vpd_keyword_t skey;
180 efx_vpd_keyword_t dkey;
185 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
188 * Strictly you could take the view that dynamic vpd is optional.
189 * Instead, to conform more closely to the read/verify/reinit()
190 * paradigm, we require dynamic vpd. hunt_vpd_reinit() will
191 * reinitialize it as required.
193 if ((rc = efx_vpd_hunk_verify(data, size, NULL)) != 0)
197 * Verify that there is no duplication between the static and
198 * dynamic cfg sectors.
200 if (enp->en_u.hunt.enu_svpd_length == 0)
204 _NOTE(CONSTANTCONDITION)
206 if ((rc = efx_vpd_hunk_next(data, size, &dtag,
207 &dkey, NULL, NULL, &dcont)) != 0)
213 _NOTE(CONSTANTCONDITION)
215 if ((rc = efx_vpd_hunk_next(
216 enp->en_u.hunt.enu_svpd,
217 enp->en_u.hunt.enu_svpd_length, &stag, &skey,
218 NULL, NULL, &scont)) != 0)
223 if (stag == dtag && skey == dkey) {
240 EFSYS_PROBE1(fail1, int, rc);
248 __in_bcount(size) caddr_t data,
255 * Only create an ID string if the dynamic cfg doesn't have one
257 if (enp->en_u.hunt.enu_svpd_length == 0)
263 rc = efx_vpd_hunk_get(enp->en_u.hunt.enu_svpd,
264 enp->en_u.hunt.enu_svpd_length,
265 EFX_VPD_ID, 0, &offset, &length);
268 else if (rc == ENOENT)
274 if ((rc = efx_vpd_hunk_reinit(data, size, wantpid)) != 0)
282 EFSYS_PROBE1(fail1, int, rc);
290 __in_bcount(size) caddr_t data,
292 __inout efx_vpd_value_t *evvp)
298 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
300 /* Attempt to satisfy the request from svpd first */
301 if (enp->en_u.hunt.enu_svpd_length > 0) {
302 if ((rc = efx_vpd_hunk_get(enp->en_u.hunt.enu_svpd,
303 enp->en_u.hunt.enu_svpd_length, evvp->evv_tag,
304 evvp->evv_keyword, &offset, &length)) == 0) {
305 evvp->evv_length = length;
306 memcpy(evvp->evv_value,
307 enp->en_u.hunt.enu_svpd + offset, length);
309 } else if (rc != ENOENT)
313 /* And then from the provided data buffer */
314 if ((rc = efx_vpd_hunk_get(data, size, evvp->evv_tag,
315 evvp->evv_keyword, &offset, &length)) != 0)
318 evvp->evv_length = length;
319 memcpy(evvp->evv_value, data + offset, length);
326 EFSYS_PROBE1(fail1, int, rc);
334 __in_bcount(size) caddr_t data,
336 __in efx_vpd_value_t *evvp)
340 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
342 /* If the provided (tag,keyword) exists in svpd, then it is readonly */
343 if (enp->en_u.hunt.enu_svpd_length > 0) {
347 if ((rc = efx_vpd_hunk_get(enp->en_u.hunt.enu_svpd,
348 enp->en_u.hunt.enu_svpd_length, evvp->evv_tag,
349 evvp->evv_keyword, &offset, &length)) == 0) {
355 if ((rc = efx_vpd_hunk_set(data, size, evvp)) != 0)
363 EFSYS_PROBE1(fail1, int, rc);
371 __in_bcount(size) caddr_t data,
373 __out efx_vpd_value_t *evvp,
374 __inout unsigned int *contp)
376 _NOTE(ARGUNUSED(enp, data, size, evvp, contp))
384 __in_bcount(size) caddr_t data,
391 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
393 pci_pf = enp->en_nic_cfg.enc_pf;
395 /* Determine total length of new dynamic VPD */
396 if ((rc = efx_vpd_hunk_length(data, size, &vpd_length)) != 0)
399 /* Store new dynamic VPD in DYNAMIC_CONFIG partition */
400 if ((rc = hunt_nvram_partn_write_tlv(enp,
401 NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,
402 TLV_TAG_PF_DYNAMIC_VPD(pci_pf),
403 data, vpd_length)) != 0) {
413 EFSYS_PROBE1(fail1, int, rc);
422 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
424 if (enp->en_u.hunt.enu_svpd_length > 0) {
425 EFSYS_KMEM_FREE(enp->en_esip, enp->en_u.hunt.enu_svpd_length,
426 enp->en_u.hunt.enu_svpd);
428 enp->en_u.hunt.enu_svpd = NULL;
429 enp->en_u.hunt.enu_svpd_length = 0;
433 #endif /* EFSYS_OPT_HUNTINGTON */
435 #endif /* EFSYS_OPT_VPD */