From: Wenbo Cao <caowenbo@mucse.com>
To: thomas@monjalon.net, Wenbo Cao <caowenbo@mucse.com>
Cc: stephen@networkplumber.org, dev@dpdk.org, ferruh.yigit@amd.com,
andrew.rybchenko@oktetlabs.ru, yaojun@mucse.com
Subject: [PATCH v7 04/28] net/rnp: support mailbox basic operate
Date: Sat, 8 Feb 2025 10:43:41 +0800 [thread overview]
Message-ID: <1738982645-34550-5-git-send-email-caowenbo@mucse.com> (raw)
In-Reply-To: <1738982645-34550-1-git-send-email-caowenbo@mucse.com>
This patch adds support for mailbox of rnp PMD driver,
mailbox is used for communication between pf with fw
and vf driver.
Signed-off-by: Wenbo Cao <caowenbo@mucse.com>
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/rnp/base/meson.build | 22 ++
drivers/net/rnp/base/rnp_hw.h | 76 ++++++
drivers/net/rnp/base/rnp_mbx.c | 512 +++++++++++++++++++++++++++++++++++++++
drivers/net/rnp/base/rnp_mbx.h | 58 +++++
drivers/net/rnp/base/rnp_osdep.h | 53 ++++
drivers/net/rnp/meson.build | 5 +
drivers/net/rnp/rnp.h | 19 ++
7 files changed, 745 insertions(+)
create mode 100644 drivers/net/rnp/base/meson.build
create mode 100644 drivers/net/rnp/base/rnp_hw.h
create mode 100644 drivers/net/rnp/base/rnp_mbx.c
create mode 100644 drivers/net/rnp/base/rnp_mbx.h
create mode 100644 drivers/net/rnp/base/rnp_osdep.h
diff --git a/drivers/net/rnp/base/meson.build b/drivers/net/rnp/base/meson.build
new file mode 100644
index 0000000..9ea88c3
--- /dev/null
+++ b/drivers/net/rnp/base/meson.build
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(C) 2023 Mucse IC Design Ltd.
+
+sources = [
+ 'rnp_mbx.c',
+]
+
+error_cflags = ['-Wno-unused-value',
+ '-Wno-unused-but-set-variable',
+ '-Wno-unused-parameter',
+ ]
+c_args = cflags
+foreach flag: error_cflags
+ if cc.has_argument(flag)
+ c_args += flag
+ endif
+endforeach
+
+base_lib = static_library('rnp_base', sources,
+ dependencies: [static_rte_eal, static_rte_net, static_rte_ethdev],
+ c_args: c_args)
+base_objs = base_lib.extract_all_objects(recursive: true)
diff --git a/drivers/net/rnp/base/rnp_hw.h b/drivers/net/rnp/base/rnp_hw.h
new file mode 100644
index 0000000..959b4c3
--- /dev/null
+++ b/drivers/net/rnp/base/rnp_hw.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Mucse IC Design Ltd.
+ */
+#ifndef __RNP_HW_H__
+#define __RNP_HW_H__
+
+#include "rnp_osdep.h"
+
+struct rnp_hw;
+/* Mailbox Operate Info */
+enum RNP_MBX_ID {
+ RNP_MBX_PF = 0,
+ RNP_MBX_VF,
+ RNP_MBX_FW = 64,
+};
+
+struct rnp_mbx_ops {
+ int (*read)(struct rnp_hw *hw,
+ u32 *msg,
+ u16 size,
+ enum RNP_MBX_ID);
+ int (*write)(struct rnp_hw *hw,
+ u32 *msg,
+ u16 size,
+ enum RNP_MBX_ID);
+ int (*read_posted)(struct rnp_hw *hw,
+ u32 *msg,
+ u16 size,
+ enum RNP_MBX_ID);
+ int (*write_posted)(struct rnp_hw *hw,
+ u32 *msg,
+ u16 size,
+ enum RNP_MBX_ID);
+ int (*check_for_msg)(struct rnp_hw *hw, enum RNP_MBX_ID);
+ int (*check_for_ack)(struct rnp_hw *hw, enum RNP_MBX_ID);
+ int (*check_for_rst)(struct rnp_hw *hw, enum RNP_MBX_ID);
+};
+
+struct rnp_mbx_sync {
+ u16 req;
+ u16 ack;
+};
+
+struct rnp_mbx_info {
+ const struct rnp_mbx_ops *ops;
+ u32 usec_delay; /* retry interval delay time */
+ u32 timeout; /* retry ops timeout limit */
+ u16 size; /* data buffer size*/
+ u16 vf_num; /* Virtual Function num */
+ u16 pf_num; /* Physical Function num */
+ u16 sriov_st; /* Sriov state */
+ u16 en_vfs; /* user enabled vf num */
+ bool is_pf;
+
+ struct rnp_mbx_sync syncs[RNP_MBX_FW];
+};
+
+struct rnp_eth_adapter;
+
+/* hw device description */
+struct rnp_hw {
+ struct rnp_eth_adapter *back; /* backup to the adapter handle */
+ void __iomem *e_ctrl; /* ethernet control bar */
+ void __iomem *c_ctrl; /* crypto control bar */
+ u32 c_blen; /* crypto bar size */
+
+ /* pci device info */
+ u16 device_id;
+ u16 vendor_id;
+ u16 max_vfs; /* device max support vf */
+
+ u16 pf_vf_num;
+ struct rnp_mbx_info mbx;
+};
+
+#endif /* __RNP_H__*/
diff --git a/drivers/net/rnp/base/rnp_mbx.c b/drivers/net/rnp/base/rnp_mbx.c
new file mode 100644
index 0000000..a53404a
--- /dev/null
+++ b/drivers/net/rnp/base/rnp_mbx.c
@@ -0,0 +1,512 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Mucse IC Design Ltd.
+ */
+
+#include <string.h>
+
+#include "rnp_hw.h"
+#include "rnp_mbx.h"
+#include "../rnp.h"
+
+/****************************PF MBX OPS************************************/
+static inline u16
+rnp_mbx_get_req(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 reg = 0;
+
+ if (mbx_id == RNP_MBX_FW)
+ reg = RNP_FW2PF_SYNC;
+ else
+ reg = RNP_VF2PF_SYNC(mbx_id);
+ mb();
+
+ return RNP_E_REG_RD(hw, reg) & RNP_MBX_SYNC_REQ_MASK;
+}
+
+static inline u16
+rnp_mbx_get_ack(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 reg = 0;
+ u32 v = 0;
+
+ if (mbx_id == RNP_MBX_FW)
+ reg = RNP_FW2PF_SYNC;
+ else
+ reg = RNP_VF2PF_SYNC(mbx_id);
+ mb();
+ v = RNP_E_REG_RD(hw, reg);
+
+ return (v & RNP_MBX_SYNC_ACK_MASK) >> RNP_MBX_SYNC_ACK_S;
+}
+
+/*
+ * rnp_mbx_inc_pf_ack - increase ack num of mailbox sync info
+ * @hw pointer to the HW structure
+ * @sync_base: addr of sync
+ */
+static inline void
+rnp_mbx_inc_pf_req(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 sync_base;
+ u32 req;
+ u32 v;
+
+ if (mbx_id == RNP_MBX_FW)
+ sync_base = RNP_PF2FW_SYNC;
+ else
+ sync_base = RNP_PF2VF_SYNC(mbx_id);
+ v = RNP_E_REG_RD(hw, sync_base);
+ req = (v & RNP_MBX_SYNC_REQ_MASK);
+ req++;
+ /* clear sync req value */
+ v &= ~(RNP_MBX_SYNC_REQ_MASK);
+ v |= req;
+
+ mb();
+ RNP_E_REG_WR(hw, sync_base, v);
+}
+
+/*
+ * rnp_mbx_inc_pf_ack - increase ack num of maixbox sync info
+ * @hw pointer to the HW structure
+ * @sync_base: addr of sync
+ */
+static inline void
+rnp_mbx_inc_pf_ack(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 ack;
+ u32 reg;
+ u32 v;
+
+ if (mbx_id == RNP_MBX_FW)
+ reg = RNP_PF2FW_SYNC;
+ else
+ reg = RNP_PF2VF_SYNC(mbx_id);
+ v = RNP_E_REG_RD(hw, reg);
+ ack = (v & RNP_MBX_SYNC_ACK_MASK) >> RNP_MBX_SYNC_ACK_S;
+ ack++;
+ /* clear old sync ack */
+ v &= ~RNP_MBX_SYNC_ACK_MASK;
+ v |= (ack << RNP_MBX_SYNC_ACK_S);
+ mb();
+ RNP_E_REG_WR(hw, reg, v);
+}
+
+static void
+rnp_mbx_write_msg(struct rnp_hw *hw,
+ u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ u32 msg_base;
+ u16 i = 0;
+
+ if (mbx_id == RNP_MBX_FW)
+ msg_base = RNP_FW2PF_MSG_DATA;
+ else
+ msg_base = RNP_PF2VF_MSG_DATA(mbx_id);
+ for (i = 0; i < size; i++)
+ RNP_E_REG_WR(hw, msg_base + i * 4, msg[i]);
+}
+
+static void
+rnp_mbx_read_msg(struct rnp_hw *hw,
+ u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ u32 msg_base;
+ u16 i = 0;
+
+ if (mbx_id == RNP_MBX_FW)
+ msg_base = RNP_FW2PF_MSG_DATA;
+ else
+ msg_base = RNP_PF2VF_MSG_DATA(mbx_id);
+ for (i = 0; i < size; i++)
+ msg[i] = RNP_E_REG_RD(hw, msg_base + 4 * i);
+ mb();
+ /* clear msg cmd */
+ RNP_E_REG_WR(hw, msg_base, 0);
+}
+
+/*
+ * rnp_poll_for_msg - Wait for message notification
+ * @hw: pointer to the HW structure
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if it successfully received a message notification
+ */
+static int
+rnp_poll_for_msg(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ u32 countdown = mbx->timeout;
+
+ if (!countdown || !mbx->ops->check_for_msg)
+ goto out;
+
+ while (countdown && mbx->ops->check_for_msg(hw, mbx_id)) {
+ countdown--;
+ if (!countdown)
+ break;
+ udelay(mbx->usec_delay);
+ }
+out:
+ return countdown ? 0 : -ETIME;
+}
+
+/*
+ * rnp_poll_for_ack - Wait for message acknowledgment
+ * @hw: pointer to the HW structure
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if it successfully received a message acknowledgment
+ */
+static int
+rnp_poll_for_ack(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ int countdown = mbx->timeout;
+
+ if (!countdown || !mbx->ops->check_for_ack)
+ goto out;
+
+ while (countdown && mbx->ops->check_for_ack(hw, mbx_id)) {
+ countdown--;
+ if (!countdown)
+ break;
+ udelay(mbx->usec_delay);
+ }
+
+out:
+ return countdown ? 0 : -ETIME;
+}
+
+static int
+rnp_read_mbx_msg(struct rnp_hw *hw, u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ int ret = RNP_ERR_MBX;
+
+ if (size > mbx->size)
+ return -EINVAL;
+ if (mbx->ops->read)
+ return mbx->ops->read(hw, msg, size, mbx_id);
+ return ret;
+}
+
+static int
+rnp_write_mbx_msg(struct rnp_hw *hw, u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ int ret = RNP_ERR_MBX;
+
+ /* exit if either we can't write or there isn't a defined timeout */
+ if (size > mbx->size)
+ return -EINVAL;
+ if (mbx->ops->write)
+ return mbx->ops->write(hw, msg, size, mbx_id);
+ return ret;
+}
+
+/*
+ * rnp_obtain_mbx_lock_pf - obtain mailbox lock
+ * @hw: pointer to the HW structure
+ * @ctrl_base: ctrl mbx addr
+ *
+ * return SUCCESS if we obtained the mailbox lock
+ */
+static int rnp_obtain_mbx_lock_pf(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ int ret_val = -ETIME;
+ u32 try_cnt = 5000; /* 500ms */
+ u32 ctrl_base;
+
+ if (mbx_id == RNP_MBX_FW)
+ ctrl_base = RNP_PF2FW_MBX_CTRL;
+ else
+ ctrl_base = RNP_PF2VF_MBX_CTRL(mbx_id);
+ while (try_cnt-- > 0) {
+ /* take ownership of the buffer */
+ RNP_E_REG_WR(hw, ctrl_base, RNP_MBX_CTRL_PF_HOLD);
+ wmb();
+ /* reserve mailbox for pf used */
+ if (RNP_E_REG_RD(hw, ctrl_base) & RNP_MBX_CTRL_PF_HOLD)
+ return 0;
+ udelay(100);
+ }
+
+ RNP_PMD_LOG(WARNING, "%s: failed to get:lock\n",
+ __func__);
+ return ret_val;
+}
+
+static void
+rnp_obtain_mbx_unlock_pf(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 ctrl_base;
+
+ if (mbx_id == RNP_MBX_FW)
+ ctrl_base = RNP_PF2FW_MBX_CTRL;
+ else
+ ctrl_base = RNP_PF2VF_MBX_CTRL(mbx_id);
+ RNP_E_REG_WR(hw, ctrl_base, 0);
+}
+
+static void
+rnp_mbx_send_irq_pf(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ u32 ctrl_base;
+
+ if (mbx_id == RNP_MBX_FW)
+ ctrl_base = RNP_PF2FW_MBX_CTRL;
+ else
+ ctrl_base = RNP_PF2VF_MBX_CTRL(mbx_id);
+
+ RNP_E_REG_WR(hw, ctrl_base, RNP_MBX_CTRL_REQ);
+}
+/*
+ * rnp_read_mbx_pf - Read a message from the mailbox
+ * @hw: pointer to the HW structure
+ * @msg: The message buffer
+ * @size: Length of buffer
+ * @mbx_id: id of request mbx target
+ *
+ * This function copies a message from the mailbox buffer to the caller's
+ * memory buffer. The presumption is that the caller knows that there was
+ * a message due to a VF/FW request so no polling for message is needed.
+ */
+static int rnp_read_mbx_pf(struct rnp_hw *hw, u32 *msg,
+ u16 size, enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_sync *sync = &hw->mbx.syncs[mbx_id];
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ int ret_val = -EBUSY;
+
+ if (size > mbx->size) {
+ RNP_PMD_LOG(ERR, "%s: mbx msg block size:%d should <%d\n",
+ __func__, size, mbx->size);
+ return -EINVAL;
+ }
+ memset(msg, 0, sizeof(*msg) * size);
+ /* lock the mailbox to prevent pf/vf race condition */
+ ret_val = rnp_obtain_mbx_lock_pf(hw, mbx_id);
+ if (ret_val)
+ goto out_no_read;
+ /* copy the message from the mailbox memory buffer */
+ rnp_mbx_read_msg(hw, msg, size, mbx_id);
+ /* update req. sync with fw or vf */
+ sync->req = rnp_mbx_get_req(hw, mbx_id);
+ /* Acknowledge receipt and release mailbox, then we're done */
+ rnp_mbx_inc_pf_ack(hw, mbx_id);
+ mb();
+ /* free ownership of the buffer */
+ rnp_obtain_mbx_unlock_pf(hw, mbx_id);
+
+out_no_read:
+
+ return ret_val;
+}
+
+/*
+ * rnp_write_mbx_pf - Places a message in the mailbox
+ * @hw: pointer to the HW structure
+ * @msg: The message buffer
+ * @size: Length of buffer
+ * @mbx_id: id of request mbx target
+ *
+ * returns SUCCESS if it successfully copied message into the buffer
+ */
+static int rnp_write_mbx_pf(struct rnp_hw *hw, u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_sync *sync = &hw->mbx.syncs[mbx_id];
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ int ret_val = 0;
+
+ if (size > mbx->size) {
+ RNP_PMD_LOG(ERR, "%s: size:%d should <%d\n", __func__, size,
+ mbx->size);
+ return -EINVAL;
+ }
+ /* lock the mailbox to prevent pf/vf/cpu race condition */
+ ret_val = rnp_obtain_mbx_lock_pf(hw, mbx_id);
+ if (ret_val) {
+ RNP_PMD_LOG(ERR, "%s: get mbx:%d wlock failed. "
+ "msg:0x%08x-0x%08x\n", __func__, mbx_id,
+ msg[0], msg[1]);
+ goto out_no_write;
+ }
+ /* copy the caller specified message to the mailbox memory buffer */
+ rnp_mbx_write_msg(hw, msg, size, mbx_id);
+ /* flush msg and acks as we are overwriting the message buffer */
+ sync->ack = rnp_mbx_get_ack(hw, mbx_id);
+ rnp_mbx_inc_pf_req(hw, mbx_id);
+ udelay(300);
+ mb();
+ /* interrupt VF/FW to tell it a message has been sent and release buf */
+ rnp_mbx_send_irq_pf(hw, mbx_id);
+
+out_no_write:
+
+ return ret_val;
+}
+
+/*
+ * rnp_read_posted_mbx - Wait for message notification and receive message
+ * @hw: pointer to the HW structure
+ * @msg: The message buffer
+ * @size: Length of buffer
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if it successfully received a message notification and
+ * copied it into the receive buffer.
+ */
+static int32_t
+rnp_read_posted_mbx(struct rnp_hw *hw,
+ u32 *msg, u16 size, enum RNP_MBX_ID mbx_id)
+{
+ int ret_val = -EINVAL;
+
+ ret_val = rnp_poll_for_msg(hw, mbx_id);
+ /* if ack received read message, otherwise we timed out */
+ if (!ret_val)
+ return rnp_read_mbx_msg(hw, msg, size, mbx_id);
+ return ret_val;
+}
+
+/*
+ * rnp_write_posted_mbx - Write a message to the mailbox, wait for ack
+ * @hw: pointer to the HW structure
+ * @msg: The message buffer
+ * @size: Length of buffer
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if it successfully copied message into the buffer and
+ * received an ack to that message within delay * timeout period
+ */
+static int rnp_write_posted_mbx(struct rnp_hw *hw,
+ u32 *msg, u16 size,
+ enum RNP_MBX_ID mbx_id)
+{
+ int ret_val = RNP_ERR_MBX;
+
+ ret_val = rnp_write_mbx_msg(hw, msg, size, mbx_id);
+ if (ret_val)
+ return ret_val;
+ /* if msg sent wait until we receive an ack */
+ if (!ret_val)
+ ret_val = rnp_poll_for_ack(hw, mbx_id);
+ return ret_val;
+}
+
+/*
+ * rnp_check_for_msg_pf - checks to see if the VF/FW has sent mail
+ * @hw: pointer to the HW structure
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
+ */
+static int rnp_check_for_msg_pf(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_sync *sync = &hw->mbx.syncs[mbx_id];
+ int ret_val = RNP_ERR_MBX;
+
+ if (rnp_mbx_get_req(hw, mbx_id) != sync->req)
+ ret_val = 0;
+
+ return ret_val;
+}
+
+/*
+ * rnp_check_for_ack_pf - checks to see if the VF/FW has ACKed
+ * @hw: pointer to the HW structure
+ * @mbx_id: id of mailbox to write
+ *
+ * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
+ */
+static int rnp_check_for_ack_pf(struct rnp_hw *hw, enum RNP_MBX_ID mbx_id)
+{
+ struct rnp_mbx_sync *sync = &hw->mbx.syncs[mbx_id];
+ int ret_val = RNP_ERR_MBX;
+
+ if (rnp_mbx_get_ack(hw, mbx_id) != sync->ack)
+ ret_val = 0;
+
+ return ret_val;
+}
+
+const struct rnp_mbx_ops rnp_mbx_ops_pf = {
+ .read = rnp_read_mbx_pf,
+ .write = rnp_write_mbx_pf,
+ .read_posted = rnp_read_posted_mbx,
+ .write_posted = rnp_write_posted_mbx,
+ .check_for_msg = rnp_check_for_msg_pf,
+ .check_for_ack = rnp_check_for_ack_pf,
+};
+
+static int rnp_get_pfvfnum(struct rnp_hw *hw)
+{
+ u32 addr_mask;
+ u32 offset;
+ u32 val;
+
+ addr_mask = hw->c_blen - 1;
+ offset = RNP_SRIOV_INFO & addr_mask;
+ val = RNP_REG_RD(hw->c_ctrl, offset);
+
+ return val >> RNP_PFVF_SHIFT;
+}
+
+static void rnp_mbx_reset(struct rnp_hw *hw)
+{
+ struct rnp_mbx_sync *sync = hw->mbx.syncs;
+ int idx = 0;
+ u32 v = 0;
+
+ for (idx = 0; idx < hw->mbx.en_vfs; idx++) {
+ v = RNP_E_REG_RD(hw, RNP_VF2PF_SYNC(idx));
+ sync[idx].ack = (v & RNP_MBX_SYNC_ACK_MASK) >> RNP_MBX_SYNC_ACK_S;
+ sync[idx].req = v & RNP_MBX_SYNC_REQ_MASK;
+ /* release pf<->vf pf used buffer lock */
+ RNP_E_REG_WR(hw, RNP_PF2VF_MBX_CTRL(idx), 0);
+ }
+ /* reset pf->fw status */
+ v = RNP_E_REG_RD(hw, RNP_FW2PF_SYNC);
+ sync[RNP_MBX_FW].ack = (v & RNP_MBX_SYNC_ACK_MASK) >> RNP_MBX_SYNC_ACK_S;
+ sync[RNP_MBX_FW].req = v & RNP_MBX_SYNC_REQ_MASK;
+
+ RNP_PMD_LOG(INFO, "now fw_req %d fw_ack %d\n",
+ hw->mbx.syncs[idx].req, hw->mbx.syncs[idx].ack);
+ /* release pf->fw buffer lock */
+ RNP_E_REG_WR(hw, RNP_PF2FW_MBX_CTRL, 0);
+ /* setup mailbox vec id */
+ RNP_E_REG_WR(hw, RNP_FW2PF_MBOX_VEC, RNP_MISC_VEC_ID);
+ /* enable 0-31 vf interrupt */
+ RNP_E_REG_WR(hw, RNP_PF2VF_INTR_MASK(0), 0);
+ /* enable 32-63 vf interrupt */
+ RNP_E_REG_WR(hw, RNP_PF2VF_INTR_MASK(33), 0);
+ /* enable firmware interrupt */
+ RNP_E_REG_WR(hw, RNP_FW2PF_INTR_MASK, 0);
+}
+
+int rnp_init_mbx_pf(struct rnp_hw *hw)
+{
+ struct rnp_proc_priv *proc_priv = RNP_DEV_TO_PROC_PRIV(hw->back->eth_dev);
+ struct rnp_mbx_info *mbx = &hw->mbx;
+ u32 pf_vf_num;
+
+ pf_vf_num = rnp_get_pfvfnum(hw);
+ mbx->usec_delay = RNP_MBX_DELAY_US;
+ mbx->timeout = RNP_MBX_MAX_TM_SEC / mbx->usec_delay;
+ mbx->size = RNP_MBX_MSG_BLOCK_SIZE;
+ mbx->pf_num = (pf_vf_num & RNP_PF_BIT_MASK) ? 1 : 0;
+ mbx->vf_num = UINT16_MAX;
+ mbx->ops = &rnp_mbx_ops_pf;
+ proc_priv->mbx_ops = &rnp_mbx_ops_pf;
+ hw->pf_vf_num = pf_vf_num;
+ mbx->is_pf = 1;
+ rnp_mbx_reset(hw);
+
+ return 0;
+}
diff --git a/drivers/net/rnp/base/rnp_mbx.h b/drivers/net/rnp/base/rnp_mbx.h
new file mode 100644
index 0000000..b241657
--- /dev/null
+++ b/drivers/net/rnp/base/rnp_mbx.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Mucse IC Design Ltd.
+ */
+
+#ifndef __RNP_MBX_H__
+#define __RNP_MBX_H__
+
+#include "rnp_osdep.h"
+
+#include "rnp_hw.h"
+
+#define RNP_ISOLATE_CTRL (0x7982fc)
+#define RNP_SRIOV_INFO (0x75f000)
+#define RNP_PFVF_SHIFT (4)
+#define RNP_PF_BIT_MASK RTE_BIT32(6)
+
+#define RNP_MBX_MSG_BLOCK_SIZE (14)
+/* mailbox share memory detail divide */
+/*|0------------------15|---------------------31|
+ *|------master-req-----|-------master-ack------|
+ *|------slave-req------|-------slave-ack-------|
+ *|---------------------|-----------------------|
+ *| data(56 bytes) |
+ *----------------------------------------------|
+ */
+/* FW <--> PF */
+#define RNP_FW2PF_MBOX_VEC _MSI_(0x5300)
+#define RNP_FW2PF_MEM_BASE _MSI_(0xa000)
+#define RNP_FW2PF_SYNC (RNP_FW2PF_MEM_BASE + 0)
+#define RNP_PF2FW_SYNC (RNP_FW2PF_MEM_BASE + 4)
+#define RNP_FW2PF_MSG_DATA (RNP_FW2PF_MEM_BASE + 8)
+#define RNP_PF2FW_MBX_CTRL _MSI_(0xa100)
+#define RNP_FW2PF_MBX_CTRL _MSI_(0xa200)
+#define RNP_FW2PF_INTR_MASK _MSI_(0xa300)
+/* PF <-> VF */
+#define RNP_PF2VF_MBOX_VEC(vf) _MSI_(0x5100 + (4 * (vf)))
+#define RNP_PF2VF_MEM_BASE(vf) _MSI_(0x6000 + (64 * (vf)))
+#define RNP_PF2VF_SYNC(vf) (RNP_PF2VF_MEM_BASE(vf) + 0)
+#define RNP_VF2PF_SYNC(vf) (RNP_PF2VF_MEM_BASE(vf) + 4)
+#define RNP_PF2VF_MSG_DATA(vf) (RNP_PF2VF_MEM_BASE(vf) + 8)
+#define RNP_VF2PF_MBX_CTRL(vf) _MSI_(0x7000 + ((vf) * 4))
+#define RNP_PF2VF_MBX_CTRL(vf) _MSI_(0x7100 + ((vf) * 4))
+#define RNP_PF2VF_INTR_MASK(vf) _MSI_(0x7200 + ((((vf) & 32) / 32) * 0x4))
+/* sync memory define */
+#define RNP_MBX_SYNC_REQ_MASK RTE_GENMASK32(15, 0)
+#define RNP_MBX_SYNC_ACK_MASK RTE_GENMASK32(31, 16)
+#define RNP_MBX_SYNC_ACK_S (16)
+/* for pf <--> fw/vf */
+#define RNP_MBX_CTRL_PF_HOLD RTE_BIT32(3) /* VF:RO, PF:WR */
+#define RNP_MBX_CTRL_REQ RTE_BIT32(0) /* msg write request */
+
+#define RNP_MBX_DELAY_US (100) /* delay us for retry */
+#define RNP_MBX_MAX_TM_SEC (4 * 1000 * 1000) /* 4 sec */
+
+#define RNP_ERR_MBX (-100)
+int rnp_init_mbx_pf(struct rnp_hw *hw);
+
+#endif /* _RNP_MBX_H_ */
diff --git a/drivers/net/rnp/base/rnp_osdep.h b/drivers/net/rnp/base/rnp_osdep.h
new file mode 100644
index 0000000..b0b3f34
--- /dev/null
+++ b/drivers/net/rnp/base/rnp_osdep.h
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Mucse IC Design Ltd.
+ */
+
+#ifndef _RNP_OSDEP_H
+#define _RNP_OSDEP_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <inttypes.h>
+
+#include <rte_io.h>
+#include <rte_log.h>
+#include <rte_cycles.h>
+
+#include "../rnp_logs.h"
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+
+#define mb() rte_mb()
+#define wmb() rte_wmb()
+
+#define udelay(x) rte_delay_us(x)
+
+#define _MSI_(off) ((off) + (0xA0000))
+
+#define __iomem
+static inline u32
+rnp_reg_read32(void *base, size_t offset)
+{
+ unsigned int v = rte_read32(((u8 *)base + offset));
+
+ RNP_PMD_REG_LOG(DEBUG, "offset=0x%08lx val=0x%04x",
+ (unsigned long)offset, v);
+ return v;
+}
+
+static inline void
+rnp_reg_write32(void *base, size_t offset, u32 val)
+{
+ RNP_PMD_REG_LOG(DEBUG, "offset=0x%08lx val=0x%08x",
+ (unsigned long)offset, val);
+ rte_write32(val, ((u8 *)base + offset));
+}
+
+#define RNP_REG_RD(base, offset) rnp_reg_read32(base, offset)
+#define RNP_REG_WR(base, offset) rnp_reg_write32(base, offset)
+#define RNP_E_REG_WR(hw, off, value) rnp_reg_write32((hw)->e_ctrl, (off), (value))
+#define RNP_E_REG_RD(hw, off) rnp_reg_read32((hw)->e_ctrl, (off))
+
+#endif /* _RNP_OSDEP_H_ */
diff --git a/drivers/net/rnp/meson.build b/drivers/net/rnp/meson.build
index 4f37c6b..d6cb380 100644
--- a/drivers/net/rnp/meson.build
+++ b/drivers/net/rnp/meson.build
@@ -6,6 +6,11 @@ if not is_linux
reason = 'only supported on Linux'
endif
+subdir('base')
+objs = [base_objs]
+
+includes += include_directories('base')
+
sources = files(
'rnp_ethdev.c',
)
diff --git a/drivers/net/rnp/rnp.h b/drivers/net/rnp/rnp.h
index 6cd717a..904b7ad 100644
--- a/drivers/net/rnp/rnp.h
+++ b/drivers/net/rnp/rnp.h
@@ -4,10 +4,29 @@
#ifndef __RNP_H__
#define __RNP_H__
+#include <ethdev_driver.h>
+#include <rte_interrupts.h>
+
+#include "base/rnp_hw.h"
+
#define PCI_VENDOR_ID_MUCSE (0x8848)
#define RNP_DEV_ID_N10G (0x1000)
+#define RNP_MAX_VF_NUM (64)
+#define RNP_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
+
+struct rnp_proc_priv {
+ const struct rnp_mbx_ops *mbx_ops;
+};
struct rnp_eth_port {
};
+struct rnp_eth_adapter {
+ struct rnp_hw hw;
+ struct rte_eth_dev *eth_dev; /* alloc eth_dev by platform */
+};
+
+#define RNP_DEV_TO_PROC_PRIV(eth_dev) \
+ ((struct rnp_proc_priv *)(eth_dev)->process_private)
+
#endif /* __RNP_H__ */
--
1.8.3.1
next prev parent reply other threads:[~2025-02-08 2:44 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-08 2:43 [PATCH v7 00/28] [v6]drivers/net Add Support mucse N10 Pmd Driver Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 01/28] net/rnp: add skeleton Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 02/28] net/rnp: add ethdev probe and remove Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 03/28] net/rnp: add log Wenbo Cao
2025-02-08 2:43 ` Wenbo Cao [this message]
2025-02-08 2:43 ` [PATCH v7 05/28] net/rnp: add device init and uninit Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 06/28] net/rnp: add get device information operation Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 07/28] net/rnp: add support mac promisc mode Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 08/28] net/rnp: add queue setup and release operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 09/28] net/rnp: add queue stop and start operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 10/28] net/rnp: add support device start stop operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 11/28] net/rnp: add RSS support operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 12/28] net/rnp: add support link update operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 13/28] net/rnp: add support link setup operations Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 14/28] net/rnp: add Rx burst simple support Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 15/28] net/rnp: add Tx " Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 16/28] net/rnp: add MTU set operation Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 17/28] net/rnp: add Rx scatter segment version Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 18/28] net/rnp: add Tx multiple " Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 19/28] net/rnp: add support basic stats operation Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 20/28] net/rnp: add support xstats operation Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 21/28] net/rnp: add unicast MAC filter operation Wenbo Cao
2025-02-08 2:43 ` [PATCH v7 22/28] net/rnp: add supported packet types Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 23/28] net/rnp: add support Rx checksum offload Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 24/28] net/rnp: add support Tx TSO offload Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 25/28] net/rnp: support VLAN offloads Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 26/28] net/rnp: add support VLAN filters operations Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 27/28] net/rnp: add queue info operation Wenbo Cao
2025-02-08 2:44 ` [PATCH v7 28/28] net/rnp: support Rx/Tx burst mode info Wenbo Cao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1738982645-34550-5-git-send-email-caowenbo@mucse.com \
--to=caowenbo@mucse.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
--cc=yaojun@mucse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).