From: MD Danish Anwar <danishanwar@ti.com>
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>, <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 v4 2/5] net: rnpgbe: Add n500/n210 chip support
Date: Thu, 14 Aug 2025 17:37:21 +0530 [thread overview]
Message-ID: <8a041e8e-b9a8-4bd9-ab1a-de66f943dea6@ti.com> (raw)
In-Reply-To: <20250814073855.1060601-3-dong100@mucse.com>
On 14/08/25 1:08 pm, Dong Yibo wrote:
> Initialize n500/n210 chip bar resource map and
> dma, eth, mbx ... info for future use.
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> drivers/net/ethernet/mucse/rnpgbe/Makefile | 3 +-
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 55 +++++++++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 85 +++++++++++++
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 12 ++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 112 ++++++++++++++++++
> 5 files changed, 266 insertions(+), 1 deletion(-)
> create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
>
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/Makefile b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> index 9df536f0d04c..42c359f459d9 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
> +++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> @@ -5,4 +5,5 @@
> #
>
> obj-$(CONFIG_MGBE) += rnpgbe.o
> -rnpgbe-objs := rnpgbe_main.o
> +rnpgbe-objs := rnpgbe_main.o\
> + rnpgbe_chip.o
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> index 64b2c093bc6e..08faac3a67af 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> @@ -4,15 +4,70 @@
> #ifndef _RNPGBE_H
> #define _RNPGBE_H
>
> +#include <linux/types.h>
> +
> +extern const struct rnpgbe_info rnpgbe_n500_info;
> +extern const struct rnpgbe_info rnpgbe_n210_info;
> +extern const struct rnpgbe_info rnpgbe_n210L_info;
> +
> enum rnpgbe_boards {
> board_n500,
> board_n210,
> board_n210L,
> };
>
> +enum rnpgbe_hw_type {
> + rnpgbe_hw_n500 = 0,
> + rnpgbe_hw_n210,
> + rnpgbe_hw_n210L,
> + rnpgbe_hw_unknown
> +};
> +
> +struct mucse_dma_info {
> + void __iomem *dma_base_addr;
> + void __iomem *dma_ring_addr;
> + u32 dma_version;
> +};
> +
> +struct mucse_eth_info {
> + void __iomem *eth_base_addr;
> +};
> +
> +struct mucse_mac_info {
> + void __iomem *mac_addr;
> +};
> +
> +struct mucse_mbx_info {
> + /* fw <--> pf mbx */
> + u32 fw_pf_shm_base;
> + u32 pf2fw_mbox_ctrl;
> + u32 fw_pf_mbox_mask;
> + u32 fw2pf_mbox_vec;
> +};
> +
> +struct mucse_hw {
> + void __iomem *hw_addr;
> + void __iomem *ring_msix_base;
> + struct pci_dev *pdev;
> + enum rnpgbe_hw_type hw_type;
> + struct mucse_dma_info dma;
> + struct mucse_eth_info eth;
> + struct mucse_mac_info mac;
> + struct mucse_mbx_info mbx;
> + u32 driver_version;
> + u16 usecstocount;
> +};
> +
> struct mucse {
> struct net_device *netdev;
> struct pci_dev *pdev;
> + struct mucse_hw hw;
> +};
> +
> +struct rnpgbe_info {
> + int total_queue_pair_cnts;
> + enum rnpgbe_hw_type hw_type;
> + void (*init)(struct mucse_hw *hw);
> };
>
> /* Device IDs */
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> new file mode 100644
> index 000000000000..79aefd7e335d
> --- /dev/null
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> @@ -0,0 +1,85 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright(c) 2020 - 2025 Mucse Corporation. */
> +
> +#include "rnpgbe.h"
> +#include "rnpgbe_hw.h"
> +
> +/**
> + * rnpgbe_init_common - Setup common attribute
> + * @hw: hw information structure
> + **/
> +static void rnpgbe_init_common(struct mucse_hw *hw)
> +{
> + struct mucse_dma_info *dma = &hw->dma;
> + struct mucse_eth_info *eth = &hw->eth;
> + struct mucse_mac_info *mac = &hw->mac;
> +
> + dma->dma_base_addr = hw->hw_addr;
> + dma->dma_ring_addr = hw->hw_addr + RNPGBE_RING_BASE;
> +
> + eth->eth_base_addr = hw->hw_addr + RNPGBE_ETH_BASE;
> +
> + mac->mac_addr = hw->hw_addr + RNPGBE_MAC_BASE;
> +}
> +
> +/**
> + * rnpgbe_init_n500 - Setup n500 hw info
> + * @hw: hw information structure
> + *
> + * rnpgbe_init_n500 initializes all private
> + * structure, such as dma, eth, mac and mbx base on
> + * hw->hw_addr for n500
> + **/
> +static void rnpgbe_init_n500(struct mucse_hw *hw)
> +{
> + struct mucse_mbx_info *mbx = &hw->mbx;
> +
> + rnpgbe_init_common(hw);
> +
> + mbx->fw2pf_mbox_vec = 0x28b00;
> + mbx->fw_pf_shm_base = 0x2d000;
> + mbx->pf2fw_mbox_ctrl = 0x2e000;
> + mbx->fw_pf_mbox_mask = 0x2e200;
> + hw->ring_msix_base = hw->hw_addr + 0x28700;
> + hw->usecstocount = 125;
> +}
These hardcoded values should be defined in rnpgbe_hw.h as macros rather
than using magic numbers.
> +
> +/**
> + * rnpgbe_init_n210 - Setup n210 hw info
> +static int rnpgbe_add_adapter(struct pci_dev *pdev,
> + const struct rnpgbe_info *info)
> +{
> + struct net_device *netdev;
> + void __iomem *hw_addr;
> + struct mucse *mucse;
> + struct mucse_hw *hw;
> + u32 dma_version = 0;
> + u32 queues;
> + int err;
> +
> + queues = info->total_queue_pair_cnts;
> + netdev = alloc_etherdev_mq(sizeof(struct mucse), queues);
> + if (!netdev)
> + return -ENOMEM;
> +
> + SET_NETDEV_DEV(netdev, &pdev->dev);
> + mucse = netdev_priv(netdev);
> + mucse->netdev = netdev;
> + mucse->pdev = pdev;
> + pci_set_drvdata(pdev, mucse);
> +
> + hw = &mucse->hw;
> + hw->hw_type = info->hw_type;
> + hw->pdev = pdev;
> +
> + switch (hw->hw_type) {
> + case rnpgbe_hw_n500:
> + hw_addr = devm_ioremap(&pdev->dev,
> + pci_resource_start(pdev, 2),
> + pci_resource_len(pdev, 2));
> + if (!hw_addr) {
> + err = -EIO;
> + goto err_free_net;
> + }
> +
> + dma_version = readl(hw_addr);
> + break;
> + case rnpgbe_hw_n210:
> + case rnpgbe_hw_n210L:
> + hw_addr = devm_ioremap(&pdev->dev,
> + pci_resource_start(pdev, 2),
> + pci_resource_len(pdev, 2));
> + if (!hw_addr) {
> + err = -EIO;
> + goto err_free_net;
> + }
> +
> + dma_version = readl(hw_addr);
> + break;
The code in both case branches is identical. Remove the switch statement
and use the common code instead.
> + default:
> + err = -EIO;
> + goto err_free_net;
> + }
> + hw->hw_addr = hw_addr;
> + hw->dma.dma_version = dma_version;
> + hw->driver_version = 0x0002040f;
> + info->init(hw);
> + return 0;
> +
> +err_free_net:
> + free_netdev(netdev);
> + return err;
> +}
> +
--
Thanks and Regards,
Danish
next prev parent reply other threads:[~2025-08-14 12:08 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 7:38 [PATCH v4 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-08-14 7:38 ` [PATCH v4 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-08-15 1:58 ` Andrew Lunn
2025-08-14 7:38 ` [PATCH v4 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
2025-08-14 12:07 ` MD Danish Anwar [this message]
2025-08-14 13:52 ` Yibo Dong
2025-08-15 2:07 ` Andrew Lunn
2025-08-15 2:05 ` Andrew Lunn
2025-08-15 2:38 ` Yibo Dong
2025-08-15 3:56 ` Andrew Lunn
2025-08-15 7:21 ` Yibo Dong
2025-08-15 13:36 ` Andrew Lunn
2025-08-18 1:14 ` Yibo Dong
2025-08-14 7:38 ` [PATCH v4 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-08-15 2:13 ` Andrew Lunn
2025-08-15 2:43 ` Yibo Dong
2025-08-15 3:59 ` Andrew Lunn
2025-08-15 7:22 ` Yibo Dong
2025-08-15 2:29 ` Andrew Lunn
2025-08-15 3:15 ` Yibo Dong
2025-08-14 7:38 ` [PATCH v4 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-08-14 12:10 ` MD Danish Anwar
2025-08-14 13:54 ` Yibo Dong
2025-08-15 3:27 ` Andrew Lunn
2025-08-15 6:36 ` Yibo Dong
2025-08-15 13:21 ` Andrew Lunn
2025-08-18 2:14 ` Yibo Dong
2025-08-14 7:38 ` [PATCH v4 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-08-14 12:14 ` MD Danish Anwar
2025-08-14 13:59 ` Yibo Dong
2025-08-15 2:28 ` Yibo Dong
2025-08-15 3:42 ` Andrew Lunn
2025-08-15 6:44 ` Yibo Dong
2025-08-15 18:06 ` Andrew Lunn
2025-08-18 1:21 ` 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=8a041e8e-b9a8-4bd9-ab1a-de66f943dea6@ti.com \
--to=danishanwar@ti.com \
--cc=Parthiban.Veerasooran@microchip.com \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--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
all inboxes | Powered by JetHome®