New upstream version 18.08
[deb_dpdk.git] / drivers / net / bnxt / bnxt_cpr.c
index 737bb06..ff20b6f 100644 (file)
@@ -1,34 +1,6 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) Broadcom Limited.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Broadcom Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   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.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2014-2018 Broadcom
+ * All rights reserved.
  */
 
 #include <rte_malloc.h>
@@ -55,6 +27,7 @@ void bnxt_handle_async_event(struct bnxt *bp,
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
+               /* FALLTHROUGH */
                bnxt_link_update_op(bp->eth_dev, 1);
                break;
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
@@ -159,69 +132,31 @@ reject:
        return;
 }
 
-/* For the default completion ring only */
-int bnxt_alloc_def_cp_ring(struct bnxt *bp)
+int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
 {
-       struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
-       struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
-       int rc;
-
-       rc = bnxt_hwrm_ring_alloc(bp, cp_ring,
-                                 HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL,
-                                 0, HWRM_NA_SIGNATURE,
-                                 HWRM_NA_SIGNATURE);
-       if (rc)
-               goto err_out;
-       cpr->cp_doorbell = bp->pdev->mem_resource[2].addr;
-       B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
-       if (BNXT_PF(bp))
-               rc = bnxt_hwrm_func_cfg_def_cp(bp);
-       else
-               rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
-
-err_out:
-       return rc;
-}
+       bool evt = 0;
 
-void bnxt_free_def_cp_ring(struct bnxt *bp)
-{
-       struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
-
-       if (cpr == NULL)
-               return;
+       if (bp == NULL || cmp == NULL) {
+               PMD_DRV_LOG(ERR, "invalid NULL argument\n");
+               return evt;
+       }
 
-       bnxt_free_ring(cpr->cp_ring_struct);
-       cpr->cp_ring_struct = NULL;
-       rte_free(cpr->cp_ring_struct);
-       rte_free(cpr);
-       bp->def_cp_ring = NULL;
-}
+       switch (CMP_TYPE(cmp)) {
+       case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
+               /* Handle any async event */
+               bnxt_handle_async_event(bp, cmp);
+               evt = 1;
+               break;
+       case CMPL_BASE_TYPE_HWRM_FWD_RESP:
+               /* Handle HWRM forwarded responses */
+               bnxt_handle_fwd_req(bp, cmp);
+               evt = 1;
+               break;
+       default:
+               /* Ignore any other events */
+               PMD_DRV_LOG(INFO, "Ignoring %02x completion\n", CMP_TYPE(cmp));
+               break;
+       }
 
-/* For the default completion ring only */
-int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id)
-{
-       struct bnxt_cp_ring_info *cpr;
-       struct bnxt_ring *ring;
-
-       cpr = rte_zmalloc_socket("cpr",
-                                sizeof(struct bnxt_cp_ring_info),
-                                RTE_CACHE_LINE_SIZE, socket_id);
-       if (cpr == NULL)
-               return -ENOMEM;
-       bp->def_cp_ring = cpr;
-
-       ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
-                                 sizeof(struct bnxt_ring),
-                                 RTE_CACHE_LINE_SIZE, socket_id);
-       if (ring == NULL)
-               return -ENOMEM;
-       cpr->cp_ring_struct = ring;
-       ring->bd = (void *)cpr->cp_desc_ring;
-       ring->bd_dma = cpr->cp_desc_mapping;
-       ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
-       ring->ring_mask = ring->ring_size - 1;
-       ring->vmem_size = 0;
-       ring->vmem = NULL;
-
-       return 0;
+       return evt;
 }