]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/bng_re: Initialize the Firmware and Hardware
authorSiva Reddy Kallam <siva.kallam@broadcom.com>
Mon, 17 Nov 2025 17:11:26 +0000 (17:11 +0000)
committerLeon Romanovsky <leon@kernel.org>
Mon, 24 Nov 2025 07:58:29 +0000 (02:58 -0500)
Initialize the firmware and hardware with HWRM command.

Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>
Link: https://patch.msgid.link/20251117171136.128193-9-siva.kallam@broadcom.com
Reviewed-by: Usman Ansari <usman.ansari@broadcom.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/bng_re/bng_dev.c
drivers/infiniband/hw/bng_re/bng_fw.c
drivers/infiniband/hw/bng_re/bng_fw.h
drivers/infiniband/hw/bng_re/bng_re.h
drivers/infiniband/hw/bng_re/bng_res.c
drivers/infiniband/hw/bng_re/bng_res.h

index 9f5efe59d105fd8e34885be8a1472a989dc84d45..d8f8d7f7075f03548e3da9e969c1f2f8a9b17b54 100644 (file)
@@ -178,6 +178,56 @@ static int bng_re_net_ring_alloc(struct bng_re_dev *rdev,
        return rc;
 }
 
+static int bng_re_stats_ctx_free(struct bng_re_dev *rdev)
+{
+       struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+       struct hwrm_stat_ctx_free_input req = {};
+       struct hwrm_stat_ctx_free_output resp = {};
+       struct bnge_fw_msg fw_msg = {};
+       int rc = -EINVAL;
+
+       if (!aux_dev)
+               return rc;
+
+       bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_FREE);
+       req.stat_ctx_id = cpu_to_le32(rdev->stats_ctx.fw_id);
+       bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+                          sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+       rc = bnge_send_msg(aux_dev, &fw_msg);
+       if (rc)
+               ibdev_err(&rdev->ibdev, "Failed to free HW stats context %#x",
+                         rc);
+
+       return rc;
+}
+
+static int bng_re_stats_ctx_alloc(struct bng_re_dev *rdev)
+{
+       struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+       struct bng_re_stats *stats = &rdev->stats_ctx;
+       struct hwrm_stat_ctx_alloc_output resp = {};
+       struct hwrm_stat_ctx_alloc_input req = {};
+       struct bnge_fw_msg fw_msg = {};
+       int rc = -EINVAL;
+
+       stats->fw_id = BNGE_INVALID_STATS_CTX_ID;
+
+       if (!aux_dev)
+               return rc;
+
+       bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_ALLOC);
+       req.update_period_ms = cpu_to_le32(1000);
+       req.stats_dma_addr = cpu_to_le64(stats->dma_map);
+       req.stats_dma_length = cpu_to_le16(rdev->chip_ctx->hw_stats_size);
+       req.stat_ctx_flags = STAT_CTX_ALLOC_REQ_STAT_CTX_FLAGS_ROCE;
+       bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+                          sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+       rc = bnge_send_msg(aux_dev, &fw_msg);
+       if (!rc)
+               stats->fw_id = le32_to_cpu(resp.stat_ctx_id);
+       return rc;
+}
+
 static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 {
        struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
@@ -216,11 +266,21 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 
 static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 {
+       int rc;
        bng_re_debugfs_rem_pdev(rdev);
-       bng_re_disable_rcfw_channel(&rdev->rcfw);
-       bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
+
+       if (test_and_clear_bit(BNG_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags)) {
+               rc = bng_re_deinit_rcfw(&rdev->rcfw);
+               if (rc)
+                       ibdev_warn(&rdev->ibdev,
+                                  "Failed to deinitialize RCFW: %#x", rc);
+               bng_re_stats_ctx_free(rdev);
+               bng_re_free_stats_ctx_mem(rdev->bng_res.pdev, &rdev->stats_ctx);
+               bng_re_disable_rcfw_channel(&rdev->rcfw);
+               bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
                             RING_ALLOC_REQ_RING_TYPE_NQ);
-       bng_re_free_rcfw_channel(&rdev->rcfw);
+               bng_re_free_rcfw_channel(&rdev->rcfw);
+       }
 
        kfree(rdev->nqr);
        rdev->nqr = NULL;
@@ -318,8 +378,34 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
                goto disable_rcfw;
 
        bng_re_debugfs_add_pdev(rdev);
+       rc = bng_re_alloc_stats_ctx_mem(rdev->bng_res.pdev, rdev->chip_ctx,
+                                       &rdev->stats_ctx);
+       if (rc) {
+               ibdev_err(&rdev->ibdev,
+                         "Failed to allocate stats context: %#x\n", rc);
+               goto disable_rcfw;
+       }
+
+       rc = bng_re_stats_ctx_alloc(rdev);
+       if (rc) {
+               ibdev_err(&rdev->ibdev,
+                         "Failed to allocate QPLIB context: %#x\n", rc);
+               goto free_stats_ctx;
+       }
+
+       rc = bng_re_init_rcfw(&rdev->rcfw, &rdev->stats_ctx);
+       if (rc) {
+               ibdev_err(&rdev->ibdev,
+                         "Failed to initialize RCFW: %#x\n", rc);
+               goto free_sctx;
+       }
+       set_bit(BNG_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags);
 
        return 0;
+free_sctx:
+       bng_re_stats_ctx_free(rdev);
+free_stats_ctx:
+       bng_re_free_stats_ctx_mem(rdev->bng_res.pdev, &rdev->stats_ctx);
 disable_rcfw:
        bng_re_disable_rcfw_channel(&rdev->rcfw);
 free_ring:
index f16fd21dfbce3ca10de46439666bca453b7de07e..803610fb9c58b858ae9ea26624a34e39d73291f9 100644 (file)
@@ -5,6 +5,7 @@
 #include "roce_hsi.h"
 #include "bng_res.h"
 #include "bng_fw.h"
+#include "bng_sp.h"
 
 /**
  * bng_re_map_rc  -  map return type based on opcode
@@ -700,3 +701,67 @@ int bng_re_enable_fw_channel(struct bng_re_rcfw *rcfw,
        bng_re_start_rcfw(rcfw);
        return 0;
 }
+
+int bng_re_deinit_rcfw(struct bng_re_rcfw *rcfw)
+{
+       struct creq_deinitialize_fw_resp resp = {};
+       struct cmdq_deinitialize_fw req = {};
+       struct bng_re_cmdqmsg msg = {};
+       int rc;
+
+       bng_re_rcfw_cmd_prep((struct cmdq_base *)&req,
+                            CMDQ_BASE_OPCODE_DEINITIALIZE_FW,
+                            sizeof(req));
+       bng_re_fill_cmdqmsg(&msg, &req, &resp, NULL,
+                           sizeof(req), sizeof(resp), 0);
+       rc = bng_re_rcfw_send_message(rcfw, &msg);
+       if (rc)
+               return rc;
+
+       clear_bit(FIRMWARE_INITIALIZED_FLAG, &rcfw->cmdq.flags);
+       return 0;
+}
+static inline bool _is_hw_retx_supported(u16 dev_cap_flags)
+{
+       return dev_cap_flags &
+               (CREQ_QUERY_FUNC_RESP_SB_HW_REQUESTER_RETX_ENABLED |
+                CREQ_QUERY_FUNC_RESP_SB_HW_RESPONDER_RETX_ENABLED);
+}
+
+#define BNG_RE_HW_RETX(a) _is_hw_retx_supported((a))
+static inline bool _is_optimize_modify_qp_supported(u16 dev_cap_ext_flags2)
+{
+       return dev_cap_ext_flags2 &
+              CREQ_QUERY_FUNC_RESP_SB_OPTIMIZE_MODIFY_QP_SUPPORTED;
+}
+
+int bng_re_init_rcfw(struct bng_re_rcfw *rcfw,
+                    struct bng_re_stats *stats_ctx)
+{
+       struct creq_initialize_fw_resp resp = {};
+       struct cmdq_initialize_fw req = {};
+       struct bng_re_cmdqmsg msg = {};
+       int rc;
+       u16 flags = 0;
+
+       bng_re_rcfw_cmd_prep((struct cmdq_base *)&req,
+                            CMDQ_BASE_OPCODE_INITIALIZE_FW,
+                            sizeof(req));
+       /* Supply (log-base-2-of-host-page-size - base-page-shift)
+        * to bono to adjust the doorbell page sizes.
+        */
+       req.log2_dbr_pg_size = cpu_to_le16(PAGE_SHIFT -
+                                          BNG_FW_DBR_BASE_PAGE_SHIFT);
+       if (BNG_RE_HW_RETX(rcfw->res->dattr->dev_cap_flags))
+               flags |= CMDQ_INITIALIZE_FW_FLAGS_HW_REQUESTER_RETX_SUPPORTED;
+       if (_is_optimize_modify_qp_supported(rcfw->res->dattr->dev_cap_flags2))
+               flags |= CMDQ_INITIALIZE_FW_FLAGS_OPTIMIZE_MODIFY_QP_SUPPORTED;
+       req.flags |= cpu_to_le16(flags);
+       req.stat_ctx_id = cpu_to_le32(stats_ctx->fw_id);
+       bng_re_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req), sizeof(resp), 0);
+       rc = bng_re_rcfw_send_message(rcfw, &msg);
+       if (rc)
+               return rc;
+       set_bit(FIRMWARE_INITIALIZED_FLAG, &rcfw->cmdq.flags);
+       return 0;
+}
index 88476d6c1d073c236feca945d46ad99d9ee7f163..c89c926ec2fc051a10395516db34c615a416d8bb 100644 (file)
@@ -10,6 +10,7 @@
 #define BNG_FW_CMDQ_TRIG_VAL           1
 #define BNG_FW_COMM_PCI_BAR_REGION     0
 #define BNG_FW_COMM_CONS_PCI_BAR_REGION        2
+#define BNG_FW_DBR_BASE_PAGE_SHIFT     12
 #define BNG_FW_COMM_SIZE               0x104
 #define BNG_FW_COMM_BASE_OFFSET                0x600
 #define BNG_FW_COMM_TRIG_OFFSET                0x100
@@ -204,4 +205,7 @@ int bng_re_rcfw_start_irq(struct bng_re_rcfw *rcfw, int msix_vector,
 void bng_re_rcfw_stop_irq(struct bng_re_rcfw *rcfw, bool kill);
 int bng_re_rcfw_send_message(struct bng_re_rcfw *rcfw,
                             struct bng_re_cmdqmsg *msg);
+int bng_re_init_rcfw(struct bng_re_rcfw *rcfw,
+                    struct bng_re_stats *stats_ctx);
+int bng_re_deinit_rcfw(struct bng_re_rcfw *rcfw);
 #endif
index 2faeb9d3e6e3b141f613370c08ff465b05e58250..dae4862621a79fb3ac064dfa4a6e1f5c927ce89e 100644 (file)
@@ -16,6 +16,8 @@
 #define BNG_RE_MAX_MSIX                BNGE_MAX_ROCE_MSIX
 
 #define BNG_RE_CREQ_NQ_IDX     0
+
+#define BNGE_INVALID_STATS_CTX_ID      -1
 /* NQ specific structures  */
 struct bng_re_nq_db {
        struct bng_re_reg_desc  reg;
@@ -65,6 +67,7 @@ struct bng_re_dev {
        struct ib_device                ibdev;
        unsigned long                   flags;
 #define BNG_RE_FLAG_NETDEV_REGISTERED          0
+#define BNG_RE_FLAG_RCFW_CHANNEL_EN            1
        struct net_device               *netdev;
        struct auxiliary_device         *adev;
        struct bnge_auxr_dev            *aux_dev;
@@ -76,6 +79,7 @@ struct bng_re_dev {
        /* Device Resources */
        struct bng_re_dev_attr          *dev_attr;
        struct dentry                   *dbg_root;
+       struct bng_re_stats             stats_ctx;
 };
 
 #endif
index cb42c0fd2cdfe60739b32198d6d536932e71b2a6..c50823758b535f9b50aaf2b0cdd5031f27401711 100644 (file)
@@ -9,6 +9,33 @@
 #include "bng_res.h"
 #include "roce_hsi.h"
 
+/* Stats */
+void bng_re_free_stats_ctx_mem(struct pci_dev *pdev,
+                              struct bng_re_stats *stats)
+{
+       if (stats->dma) {
+               dma_free_coherent(&pdev->dev, stats->size,
+                                 stats->dma, stats->dma_map);
+       }
+       memset(stats, 0, sizeof(*stats));
+       stats->fw_id = -1;
+}
+
+int bng_re_alloc_stats_ctx_mem(struct pci_dev *pdev,
+                              struct bng_re_chip_ctx *cctx,
+                              struct bng_re_stats *stats)
+{
+       memset(stats, 0, sizeof(*stats));
+       stats->fw_id = -1;
+       stats->size = cctx->hw_stats_size;
+       stats->dma = dma_alloc_coherent(&pdev->dev, stats->size,
+                                       &stats->dma_map, GFP_KERNEL);
+       if (!stats->dma)
+               return -ENOMEM;
+
+       return 0;
+}
+
 static void bng_free_pbl(struct bng_re_res  *res, struct bng_re_pbl *pbl)
 {
        struct pci_dev *pdev = res->pdev;
index 7315db347aa604921ff11ba4a3abb2510def4be4..9997f86d6a0e0e6e76787cc327c238cb38590b5b 100644 (file)
@@ -125,6 +125,13 @@ struct bng_re_hwq {
        u16                             qe_ppg;
 };
 
+struct bng_re_stats {
+       dma_addr_t                      dma_map;
+       void                            *dma;
+       u32                             size;
+       u32                             fw_id;
+};
+
 struct bng_re_res {
        struct pci_dev                  *pdev;
        struct bng_re_chip_ctx          *cctx;
@@ -198,4 +205,11 @@ void bng_re_free_hwq(struct bng_re_res *res,
 
 int bng_re_alloc_init_hwq(struct bng_re_hwq *hwq,
                          struct bng_re_hwq_attr *hwq_attr);
+
+void bng_re_free_stats_ctx_mem(struct pci_dev *pdev,
+                              struct bng_re_stats *stats);
+
+int bng_re_alloc_stats_ctx_mem(struct pci_dev *pdev,
+                              struct bng_re_chip_ctx *cctx,
+                              struct bng_re_stats *stats);
 #endif