From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Dong Yibo <dong100@mucse.com>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
corbet@lwn.net, gur.stavi@huawei.com, maddy@linux.ibm.com,
mpe@ellerman.id.au, danishanwar@ti.com, lee@trager.us,
gongfan1@huawei.com, lorenzo@kernel.org, geert+renesas@glider.be,
Parthiban.Veerasooran@microchip.com, lukas.bulwahn@redhat.com,
alexanderduyck@fb.com, richardcochran@gmail.com
Cc: netdev@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/15] net: rnpgbe: Add basic mbx ops support
Date: Mon, 21 Jul 2025 15:40:51 +0100 [thread overview]
Message-ID: <165897af-fa84-428d-9e93-52be1f2d09e5@linux.dev> (raw)
In-Reply-To: <20250721113238.18615-4-dong100@mucse.com>
On 21/07/2025 12:32, Dong Yibo wrote:
> Initialize basic mbx function.
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> drivers/net/ethernet/mucse/rnpgbe/Makefile | 5 +-
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 46 ++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 5 +-
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 2 +
> .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 1 +
> .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 623 ++++++++++++++++++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 48 ++
> 7 files changed, 727 insertions(+), 3 deletions(-)
> create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
> create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h
>
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/Makefile b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> index 42c359f459d9..41177103b50c 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
> +++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> @@ -5,5 +5,6 @@
> #
>
> obj-$(CONFIG_MGBE) += rnpgbe.o
> -rnpgbe-objs := rnpgbe_main.o\
> - rnpgbe_chip.o
> +rnpgbe-objs := rnpgbe_main.o \
> + rnpgbe_chip.o \
> + rnpgbe_mbx.o
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> index 2ae836fc8951..46e2bb2fe71e 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> @@ -63,9 +63,51 @@ struct mucse_mac_info {
> int clk_csr;
> };
>
> +struct mucse_hw;
> +
> +enum MBX_ID {
> + MBX_VF0 = 0,
> + MBX_VF1,
> + MBX_VF2,
> + MBX_VF3,
> + MBX_VF4,
> + MBX_VF5,
> + MBX_VF6,
> + MBX_VF7,
> + MBX_CM3CPU,
> + MBX_FW = MBX_CM3CPU,
> + MBX_VFCNT
> +};
> +
> +struct mucse_mbx_operations {
> + void (*init_params)(struct mucse_hw *hw);
> + int (*read)(struct mucse_hw *hw, u32 *msg,
> + u16 size, enum MBX_ID id);
> + int (*write)(struct mucse_hw *hw, u32 *msg,
> + u16 size, enum MBX_ID id);
> + int (*read_posted)(struct mucse_hw *hw, u32 *msg,
> + u16 size, enum MBX_ID id);
> + int (*write_posted)(struct mucse_hw *hw, u32 *msg,
> + u16 size, enum MBX_ID id);
> + int (*check_for_msg)(struct mucse_hw *hw, enum MBX_ID id);
> + int (*check_for_ack)(struct mucse_hw *hw, enum MBX_ID id);
> + void (*configure)(struct mucse_hw *hw, int num_vec,
> + bool enable);
> +};
> +
> +struct mucse_mbx_stats {
> + u32 msgs_tx;
> + u32 msgs_rx;
> + u32 acks;
> + u32 reqs;
> + u32 rsts;
> +};
> +
> #define MAX_VF_NUM (8)
>
> struct mucse_mbx_info {
> + struct mucse_mbx_operations ops;
> + struct mucse_mbx_stats stats;
> u32 timeout;
> u32 usec_delay;
> u32 v2p_mailbox;
> @@ -99,6 +141,8 @@ struct mucse_mbx_info {
> int share_size;
> };
>
> +#include "rnpgbe_mbx.h"
> +
> struct mucse_hw {
> void *back;
> u8 pfvfnum;
> @@ -110,6 +154,8 @@ struct mucse_hw {
> u16 vendor_id;
> u16 subsystem_device_id;
> u16 subsystem_vendor_id;
> + int max_vfs;
> + int max_vfs_noari;
> enum rnpgbe_hw_type hw_type;
> struct mucse_dma_info dma;
> struct mucse_eth_info eth;
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> index 38c094965db9..b0e5fda632f3 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> @@ -6,6 +6,7 @@
>
> #include "rnpgbe.h"
> #include "rnpgbe_hw.h"
> +#include "rnpgbe_mbx.h"
>
> /**
> * rnpgbe_get_invariants_n500 - setup for hw info
> @@ -67,7 +68,7 @@ static void rnpgbe_get_invariants_n500(struct mucse_hw *hw)
> mbx->fw_pf_mbox_mask = 0x2e200;
> mbx->fw_vf_share_ram = 0x2b000;
> mbx->share_size = 512;
> -
> + memcpy(&hw->mbx.ops, &mucse_mbx_ops_generic, sizeof(hw->mbx.ops));
that's bad pattern. it's better to have a constant set of callbacks per
device type and assign const pointer to it. It will make further debugs
much easier.
> /* setup net feature here */
> hw->feature_flags |= M_NET_FEATURE_SG |
> M_NET_FEATURE_TX_CHECKSUM |
> @@ -83,6 +84,7 @@ static void rnpgbe_get_invariants_n500(struct mucse_hw *hw)
> M_NET_FEATURE_STAG_OFFLOAD;
> /* start the default ahz, update later */
> hw->usecstocount = 125;
> + hw->max_vfs = 7;
> }
>
> /**
> @@ -117,6 +119,7 @@ static void rnpgbe_get_invariants_n210(struct mucse_hw *hw)
> /* update hw feature */
> hw->feature_flags |= M_HW_FEATURE_EEE;
> hw->usecstocount = 62;
> + hw->max_vfs_noari = 7;
> }
>
> const struct rnpgbe_info rnpgbe_n500_info = {
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> index 2c7372a5e88d..ff7bd9b21550 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> @@ -14,6 +14,8 @@
> #define RNPGBE_RING_BASE (0x1000)
> #define RNPGBE_MAC_BASE (0x20000)
> #define RNPGBE_ETH_BASE (0x10000)
> +
> +#define RNPGBE_DMA_DUMY (0x000c)
> /* chip resourse */
> #define RNPGBE_MAX_QUEUES (8)
> /* multicast control table */
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> index 08f773199e9b..1e8360cae560 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> @@ -114,6 +114,7 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
> hw->hw_addr = hw_addr;
> hw->dma.dma_version = dma_version;
> ii->get_invariants(hw);
> + hw->mbx.ops.init_params(hw);
>
> return 0;
>
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
> new file mode 100644
> index 000000000000..56ace3057fea
> --- /dev/null
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
> @@ -0,0 +1,623 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright(c) 2022 - 2025 Mucse Corporation. */
> +
> +#include <linux/pci.h>
> +#include <linux/errno.h>
> +#include <linux/delay.h>
> +#include <linux/iopoll.h>
> +#include "rnpgbe.h"
> +#include "rnpgbe_mbx.h"
> +#include "rnpgbe_hw.h"
> +
> +/**
> + * mucse_read_mbx - Reads a message from the mailbox
> + * @hw: Pointer to the HW structure
> + * @msg: The message buffer
> + * @size: Length of buffer
> + * @mbx_id: Id of vf/fw to read
> + *
> + * @return: 0 on success, negative on failure
> + **/
> +int mucse_read_mbx(struct mucse_hw *hw, u32 *msg, u16 size,
> + enum MBX_ID mbx_id)
> +{
> + struct mucse_mbx_info *mbx = &hw->mbx;
> +
> + /* limit read to size of mailbox */
> + if (size > mbx->size)
> + size = mbx->size;
> +
> + if (!mbx->ops.read)
> + return -EIO;
is it even possible? you control the set of callbacks, and these
operations must be setup to have HW working. avoid defensive programming
here and in other places you use callbacks.
> +
> + return mbx->ops.read(hw, msg, size, mbx_id);
> +}
> +
[...]
next prev parent reply other threads:[~2025-07-21 14:40 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 11:32 [PATCH v2 00/15] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-07-21 11:32 ` [PATCH v2 01/15] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-07-21 13:30 ` Vadim Fedorenko
2025-07-21 14:57 ` Andrew Lunn
2025-07-22 3:02 ` Yibo Dong
2025-07-22 10:17 ` Vadim Fedorenko
2025-07-22 11:05 ` Yibo Dong
2025-07-21 14:55 ` Andrew Lunn
2025-07-22 3:38 ` Yibo Dong
2025-07-22 14:58 ` Andrew Lunn
2025-07-21 21:23 ` Brett Creeley
2025-07-22 4:59 ` Yibo Dong
2025-07-22 11:29 ` Simon Horman
2025-07-23 3:01 ` Yibo Dong
2025-07-23 20:09 ` Simon Horman
2025-07-24 6:10 ` Yibo Dong
2025-07-25 9:51 ` Simon Horman
2025-07-21 11:32 ` [PATCH v2 02/15] net: rnpgbe: Add n500/n210 chip support Dong Yibo
2025-07-21 14:21 ` Vadim Fedorenko
2025-07-22 9:51 ` Yibo Dong
2025-07-22 10:26 ` Vadim Fedorenko
2025-07-22 11:09 ` Yibo Dong
2025-07-21 15:25 ` Andrew Lunn
2025-07-22 6:21 ` Yibo Dong
2025-07-22 13:56 ` Andrew Lunn
2025-07-21 11:32 ` [PATCH v2 03/15] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-07-21 14:40 ` Vadim Fedorenko [this message]
2025-07-21 15:43 ` Andrew Lunn
2025-07-22 6:45 ` Yibo Dong
2025-07-22 13:50 ` Andrew Lunn
2025-07-23 10:27 ` Yibo Dong
2025-07-21 21:54 ` Brett Creeley
2025-07-22 7:39 ` Yibo Dong
2025-07-22 11:35 ` Simon Horman
2025-07-23 3:07 ` Yibo Dong
2025-07-23 14:38 ` Andrew Lunn
2025-07-25 10:11 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 04/15] net: rnpgbe: Add get_capability mbx_fw " Dong Yibo
2025-07-21 22:08 ` Brett Creeley
2025-07-22 8:04 ` Yibo Dong
2025-07-22 13:19 ` Simon Horman
2025-07-23 3:15 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 05/15] net: rnpgbe: Add download firmware for n210 chip Dong Yibo
2025-07-21 11:32 ` [PATCH v2 06/15] net: rnpgbe: Add some functions for hw->ops Dong Yibo
2025-07-21 11:32 ` [PATCH v2 07/15] net: rnpgbe: Add get mac from hw Dong Yibo
2025-07-21 11:32 ` [PATCH v2 08/15] net: rnpgbe: Add irq support Dong Yibo
2025-07-22 13:25 ` Simon Horman
2025-07-23 3:21 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 09/15] net: rnpgbe: Add netdev register and init tx/rx memory Dong Yibo
2025-07-21 11:32 ` [PATCH v2 10/15] net: rnpgbe: Add netdev irq in open Dong Yibo
2025-07-22 14:03 ` Simon Horman
2025-07-23 6:13 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 11/15] net: rnpgbe: Add setup hw ring-vector, true up/down hw Dong Yibo
2025-07-21 11:32 ` [PATCH v2 12/15] net: rnpgbe: Add link up handler Dong Yibo
2025-07-21 15:47 ` Andrew Lunn
2025-07-22 6:48 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 13/15] net: rnpgbe: Add base tx functions Dong Yibo
2025-07-21 11:32 ` [PATCH v2 14/15] net: rnpgbe: Add base rx function Dong Yibo
2025-07-22 14:14 ` Simon Horman
2025-07-23 6:49 ` Yibo Dong
2025-07-21 11:32 ` [PATCH v2 15/15] net: rnpgbe: Add ITR for rx Dong Yibo
2025-07-22 11:20 ` [PATCH v2 00/15] Add driver for 1Gbe network chips from MUCSE MD Danish Anwar
2025-07-22 11:35 ` Yibo Dong
2025-07-22 15:07 ` Andrew Lunn
2025-07-23 10:42 ` Yibo Dong
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=165897af-fa84-428d-9e93-52be1f2d09e5@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=Parthiban.Veerasooran@microchip.com \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=danishanwar@ti.com \
--cc=davem@davemloft.net \
--cc=dong100@mucse.com \
--cc=edumazet@google.com \
--cc=geert+renesas@glider.be \
--cc=gongfan1@huawei.com \
--cc=gur.stavi@huawei.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=lee@trager.us \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=lukas.bulwahn@redhat.com \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.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).