]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/seastar/dpdk/drivers/net/sfc/base/siena_nvram.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / drivers / net / sfc / base / siena_nvram.c
index af4cf172fbea1a6d050b39f902b1c05fc5322cf5..b8ea8a757ffd22ac1ab265e01f20ad7db7dcf8fd 100644 (file)
@@ -1,31 +1,7 @@
-/*
- * Copyright (c) 2009-2016 Solarflare Communications Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
+/* SPDX-License-Identifier: BSD-3-Clause
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of the FreeBSD Project.
+ * Copyright (c) 2009-2018 Solarflare Communications Inc.
+ * All rights reserved.
  */
 
 #include "efx.h"
@@ -170,7 +146,8 @@ fail1:
        __checkReturn           efx_rc_t
 siena_nvram_partn_unlock(
        __in                    efx_nic_t *enp,
-       __in                    uint32_t partn)
+       __in                    uint32_t partn,
+       __out_opt               uint32_t *verify_resultp)
 {
        boolean_t reboot;
        efx_rc_t rc;
@@ -183,7 +160,7 @@ siena_nvram_partn_unlock(
                    partn == MC_CMD_NVRAM_TYPE_PHY_PORT1 ||
                    partn == MC_CMD_NVRAM_TYPE_DISABLED_CALLISTO);
 
-       rc = efx_mcdi_nvram_update_finish(enp, partn, reboot, NULL);
+       rc = efx_mcdi_nvram_update_finish(enp, partn, reboot, verify_resultp);
        if (rc != 0)
                goto fail1;
 
@@ -239,6 +216,7 @@ siena_nvram_type_to_partn(
        efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
        unsigned int i;
 
+       EFSYS_ASSERT3U(type, !=, EFX_NVRAM_INVALID);
        EFSYS_ASSERT3U(type, <, EFX_NVRAM_NTYPES);
        EFSYS_ASSERT(partnp != NULL);
 
@@ -326,15 +304,20 @@ siena_nvram_get_dynamic_cfg(
        if ((rc = siena_nvram_partn_size(enp, partn, &size)) != 0)
                goto fail1;
 
+       if (size < SIENA_NVRAM_CHUNK) {
+               rc = EINVAL;
+               goto fail2;
+       }
+
        EFSYS_KMEM_ALLOC(enp->en_esip, size, dcfg);
        if (dcfg == NULL) {
                rc = ENOMEM;
-               goto fail2;
+               goto fail3;
        }
 
        if ((rc = siena_nvram_partn_read(enp, partn, 0,
            (caddr_t)dcfg, SIENA_NVRAM_CHUNK)) != 0)
-               goto fail3;
+               goto fail4;
 
        /* Verify the magic */
        if (EFX_DWORD_FIELD(dcfg->magic, EFX_DWORD_0)
@@ -369,7 +352,7 @@ siena_nvram_get_dynamic_cfg(
                if ((rc = siena_nvram_partn_read(enp, partn, SIENA_NVRAM_CHUNK,
                    (caddr_t)dcfg + SIENA_NVRAM_CHUNK,
                    region - SIENA_NVRAM_CHUNK)) != 0)
-                       goto fail4;
+                       goto fail5;
        }
 
        /* Verify checksum */
@@ -411,13 +394,15 @@ done:
 
        return (0);
 
+fail5:
+       EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
-fail3:
-       EFSYS_PROBE(fail3);
 
        EFSYS_KMEM_FREE(enp->en_esip, size, dcfg);
 
+fail3:
+       EFSYS_PROBE(fail3);
 fail2:
        EFSYS_PROBE(fail2);
 fail1:
@@ -433,12 +418,11 @@ siena_nvram_get_subtype(
        __out                   uint32_t *subtypep)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_GET_BOARD_CFG_IN_LEN,
-                           MC_CMD_GET_BOARD_CFG_OUT_LENMAX)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_BOARD_CFG_IN_LEN,
+               MC_CMD_GET_BOARD_CFG_OUT_LENMAX);
        efx_word_t *fw_list;
        efx_rc_t rc;
 
-       (void) memset(payload, 0, sizeof (payload));
        req.emr_cmd = MC_CMD_GET_BOARD_CFG;
        req.emr_in_buf = payload;
        req.emr_in_length = MC_CMD_GET_BOARD_CFG_IN_LEN;
@@ -587,11 +571,12 @@ fail1:
        __checkReturn           efx_rc_t
 siena_nvram_partn_rw_finish(
        __in                    efx_nic_t *enp,
-       __in                    uint32_t partn)
+       __in                    uint32_t partn,
+       __out_opt               uint32_t *verify_resultp)
 {
        efx_rc_t rc;
 
-       if ((rc = siena_nvram_partn_unlock(enp, partn)) != 0)
+       if ((rc = siena_nvram_partn_unlock(enp, partn, verify_resultp)) != 0)
                goto fail1;
 
        return (0);
@@ -705,7 +690,7 @@ siena_nvram_partn_set_version(
 
        EFSYS_KMEM_FREE(enp->en_esip, length, dcfg);
 
-       siena_nvram_partn_unlock(enp, dcfg_partn);
+       siena_nvram_partn_unlock(enp, dcfg_partn, NULL);
 
        return (0);