Commit 04e031ff authored by Siva Reddy Kallam's avatar Siva Reddy Kallam Committed by Leon Romanovsky
Browse files

RDMA/bng_re: Initialize the Firmware and Hardware

parent 99e4e102
Loading
Loading
Loading
Loading
+89 −3
Original line number Diff line number Diff line
@@ -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);

	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);
	}

	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:
+65 −0
Original line number Diff line number Diff line
@@ -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;
}
+4 −0
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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
+27 −0
Original line number Diff line number Diff line
@@ -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;
Loading