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 v3 5/5] net: rnpgbe: Add register_netdev
Date: Tue, 12 Aug 2025 16:32:00 +0100 [thread overview]
Message-ID: <e410918e-98aa-4a14-8fb4-5d9e73f7375e@linux.dev> (raw)
In-Reply-To: <20250812093937.882045-6-dong100@mucse.com>
On 12/08/2025 10:39, Dong Yibo wrote:
> Initialize get mac from hw, register the netdev.
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 22 ++++++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 73 ++++++++++++++++++
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 1 +
> .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 76 +++++++++++++++++++
> 4 files changed, 172 insertions(+)
>
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> index 6cb14b79cbfe..644b8c85c29d 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
> @@ -6,6 +6,7 @@
>
> #include <linux/types.h>
> #include <linux/mutex.h>
> +#include <linux/netdevice.h>
>
> extern const struct rnpgbe_info rnpgbe_n500_info;
> extern const struct rnpgbe_info rnpgbe_n210_info;
> @@ -86,6 +87,18 @@ struct mucse_mbx_info {
> u32 fw2pf_mbox_vec;
> };
>
> +struct mucse_hw_operations {
> + int (*init_hw)(struct mucse_hw *hw);
> + int (*reset_hw)(struct mucse_hw *hw);
> + void (*start_hw)(struct mucse_hw *hw);
> + void (*init_rx_addrs)(struct mucse_hw *hw);
> + void (*driver_status)(struct mucse_hw *hw, bool enable, int mode);
> +};
> +
> +enum {
> + mucse_driver_insmod,
> +};
> +
> struct mucse_hw {
> void *back;
> u8 pfvfnum;
> @@ -96,12 +109,18 @@ struct mucse_hw {
> u32 axi_mhz;
> u32 bd_uid;
> enum rnpgbe_hw_type hw_type;
> + const struct mucse_hw_operations *ops;
> struct mucse_dma_info dma;
> struct mucse_eth_info eth;
> struct mucse_mac_info mac;
> struct mucse_mbx_info mbx;
> + u32 flags;
> +#define M_FLAGS_INIT_MAC_ADDRESS BIT(0)
> u32 driver_version;
> u16 usecstocount;
> + int lane;
> + u8 addr[ETH_ALEN];
> + u8 perm_addr[ETH_ALEN];
why do you need both addresses if you have this info already in netdev?
> };
>
> struct mucse {
> @@ -123,4 +142,7 @@ struct rnpgbe_info {
> #define PCI_DEVICE_ID_N500_DUAL_PORT 0x8318
> #define PCI_DEVICE_ID_N210 0x8208
> #define PCI_DEVICE_ID_N210L 0x820a
> +
> +#define dma_wr32(dma, reg, val) writel((val), (dma)->dma_base_addr + (reg))
> +#define dma_rd32(dma, reg) readl((dma)->dma_base_addr + (reg))
> #endif /* _RNPGBE_H */
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> index 16d0a76114b5..3eaa0257f3bb 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> @@ -2,10 +2,82 @@
> /* Copyright(c) 2020 - 2025 Mucse Corporation. */
>
> #include <linux/string.h>
> +#include <linux/etherdevice.h>
>
> #include "rnpgbe.h"
> #include "rnpgbe_hw.h"
> #include "rnpgbe_mbx.h"
> +#include "rnpgbe_mbx_fw.h"
> +
> +/**
> + * rnpgbe_get_permanent_mac - Get permanent mac
> + * @hw: hw information structure
> + * @mac_addr: pointer to store mac
> + *
> + * rnpgbe_get_permanent_mac tries to get mac from hw.
> + * It use eth_random_addr if failed.
> + **/
> +static void rnpgbe_get_permanent_mac(struct mucse_hw *hw,
> + u8 *mac_addr)
> +{
> + if (mucse_fw_get_macaddr(hw, hw->pfvfnum, mac_addr, hw->lane)) {
> + eth_random_addr(mac_addr);
> + } else {
> + if (!is_valid_ether_addr(mac_addr))
> + eth_random_addr(mac_addr);
> + }
well, this can be done in one if() statement using logical "or"
> +
> + hw->flags |= M_FLAGS_INIT_MAC_ADDRESS;
> +}
> +
> +/**
> + * rnpgbe_reset_hw_ops - Do a hardware reset
> + * @hw: hw information structure
> + *
> + * rnpgbe_reset_hw_ops calls fw to do a hardware
> + * reset, and cleans some regs to default.
> + *
> + * @return: 0 on success, negative on failure
> + **/
> +static int rnpgbe_reset_hw_ops(struct mucse_hw *hw)
> +{
> + struct mucse_dma_info *dma = &hw->dma;
> + int err;
> +
> + dma_wr32(dma, RNPGBE_DMA_AXI_EN, 0);
> + err = mucse_mbx_fw_reset_phy(hw);
> + if (err)
> + return err;
> + /* Store the permanent mac address */
> + if (!(hw->flags & M_FLAGS_INIT_MAC_ADDRESS)) {
> + rnpgbe_get_permanent_mac(hw, hw->perm_addr);
> + memcpy(hw->addr, hw->perm_addr, ETH_ALEN);
> + }
> +
> + return 0;
> +}
> +
> +/**
> + * rnpgbe_driver_status_hw_ops - Echo driver status to hw
> + * @hw: hw information structure
> + * @enable: true or false status
> + * @mode: status mode
> + **/
> +static void rnpgbe_driver_status_hw_ops(struct mucse_hw *hw,
> + bool enable,
> + int mode)
> +{
> + switch (mode) {
> + case mucse_driver_insmod:
> + mucse_mbx_ifinsmod(hw, enable);
> + break;
> + }
> +}
> +
> +static const struct mucse_hw_operations rnpgbe_hw_ops = {
> + .reset_hw = &rnpgbe_reset_hw_ops,
> + .driver_status = &rnpgbe_driver_status_hw_ops,
> +};
>
> /**
> * rnpgbe_init_common - Setup common attribute
> @@ -28,6 +100,7 @@ static void rnpgbe_init_common(struct mucse_hw *hw)
> mac->back = hw;
>
> hw->mbx.ops = &mucse_mbx_ops_generic;
> + hw->ops = &rnpgbe_hw_ops;
> }
>
> /**
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> index aee037e3219d..4e07328ccf82 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
> @@ -9,6 +9,7 @@
> #define RNPGBE_ETH_BASE 0x10000
> /**************** DMA Registers ****************************/
> #define RNPGBE_DMA_DUMY 0x000c
> +#define RNPGBE_DMA_AXI_EN 0x0010
> /**************** CHIP Resource ****************************/
> #define RNPGBE_MAX_QUEUES 8
> #endif /* _RNPGBE_HW_H */
> diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> index c151995309f8..e0a08fa5b297 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
> @@ -8,6 +8,7 @@
> #include <linux/etherdevice.h>
>
> #include "rnpgbe.h"
> +#include "rnpgbe_mbx_fw.h"
>
> static const char rnpgbe_driver_name[] = "rnpgbe";
> static const struct rnpgbe_info *rnpgbe_info_tbl[] = {
> @@ -34,6 +35,54 @@ static struct pci_device_id rnpgbe_pci_tbl[] = {
> {0, },
> };
>
> +/**
> + * rnpgbe_open - Called when a network interface is made active
> + * @netdev: network interface device structure
> + *
> + * The open entry point is called when a network interface is made
> + * active by the system (IFF_UP).
> + *
> + * @return: 0 on success, negative value on failure
> + **/
> +static int rnpgbe_open(struct net_device *netdev)
> +{
> + return 0;
> +}
> +
> +/**
> + * rnpgbe_close - Disables a network interface
> + * @netdev: network interface device structure
> + *
> + * The close entry point is called when an interface is de-activated
> + * by the OS.
> + *
> + * @return: 0, this is not allowed to fail
> + **/
> +static int rnpgbe_close(struct net_device *netdev)
> +{
> + return 0;
> +}
> +
> +/**
> + * rnpgbe_xmit_frame - Send a skb to driver
> + * @skb: skb structure to be sent
> + * @netdev: network interface device structure
> + *
> + * @return: NETDEV_TX_OK or NETDEV_TX_BUSY
> + **/
> +static netdev_tx_t rnpgbe_xmit_frame(struct sk_buff *skb,
> + struct net_device *netdev)
> +{
> + dev_kfree_skb_any(skb);
> + return NETDEV_TX_OK;
> +}
> +
> +static const struct net_device_ops rnpgbe_netdev_ops = {
> + .ndo_open = rnpgbe_open,
> + .ndo_stop = rnpgbe_close,
> + .ndo_start_xmit = rnpgbe_xmit_frame,
> +};
> +
> /**
> * rnpgbe_add_adapter - Add netdev for this pci_dev
> * @pdev: PCI device information structure
> @@ -106,6 +155,29 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
> hw->dma.dma_version = dma_version;
> hw->driver_version = 0x0002040f;
> info->init(hw);
> + hw->mbx.ops->init_params(hw);
> + /* echo fw driver insmod to control hw */
> + hw->ops->driver_status(hw, true, mucse_driver_insmod);
> + err = mucse_mbx_get_capability(hw);
> + if (err) {
> + dev_err(&pdev->dev,
> + "mucse_mbx_get_capability failed! %d\n",
> + err);
> + goto err_free_net;
> + }
> + netdev->netdev_ops = &rnpgbe_netdev_ops;
> + netdev->watchdog_timeo = 5 * HZ;
> + err = hw->ops->reset_hw(hw);
> + if (err) {
> + dev_err(&pdev->dev, "Hw reset failed %d\n", err);
> + goto err_free_net;
> + }
> + eth_hw_addr_set(netdev, hw->perm_addr);
> + memcpy(netdev->perm_addr, hw->perm_addr, netdev->addr_len);
the comment from register_netdevice() says:
/* If the device has permanent device address, driver should
* set dev_addr and also addr_assign_type should be set to
* NET_ADDR_PERM (default value).
*/
dev_addr is set by eth_hw_addr_set, perm_addr will be set by
register_netdev(), no need to manually copy it.
> + ether_addr_copy(hw->addr, hw->perm_addr);
your init() function has the same copy operation...
> + err = register_netdev(netdev);
> + if (err)
> + goto err_free_net;
> return 0;
>
> err_free_net:
> @@ -170,12 +242,16 @@ static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> static void rnpgbe_rm_adapter(struct pci_dev *pdev)
> {
> struct mucse *mucse = pci_get_drvdata(pdev);
> + struct mucse_hw *hw = &mucse->hw;
> struct net_device *netdev;
>
> if (!mucse)
> return;
> netdev = mucse->netdev;
> + if (netdev->reg_state == NETREG_REGISTERED)
> + unregister_netdev(netdev);
> mucse->netdev = NULL;
> + hw->ops->driver_status(hw, false, mucse_driver_insmod);
> free_netdev(netdev);
> }
>
next prev parent reply other threads:[~2025-08-12 15:32 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 9:39 [PATCH v3 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-08-12 9:39 ` [PATCH v3 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-08-12 15:37 ` Vadim Fedorenko
2025-08-13 6:18 ` Yibo Dong
2025-08-12 16:18 ` Anwar, Md Danish
2025-08-13 6:44 ` Yibo Dong
2025-08-13 7:51 ` MD Danish Anwar
2025-08-13 8:00 ` Yibo Dong
2025-08-12 9:39 ` [PATCH v3 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
2025-08-12 15:49 ` Vadim Fedorenko
2025-08-13 7:01 ` Yibo Dong
2025-08-12 16:25 ` Anwar, Md Danish
2025-08-13 7:07 ` Yibo Dong
2025-08-12 9:39 ` [PATCH v3 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-08-12 16:07 ` Vadim Fedorenko
2025-08-12 16:30 ` Anwar, Md Danish
2025-08-13 7:46 ` Yibo Dong
2025-08-14 23:55 ` Andrew Lunn
2025-08-15 1:31 ` Yibo Dong
2025-08-15 4:07 ` Andrew Lunn
2025-08-12 9:39 ` [PATCH v3 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-08-12 16:14 ` Vadim Fedorenko
2025-08-13 8:12 ` Yibo Dong
2025-08-13 9:52 ` Yibo Dong
2025-08-13 11:05 ` Geert Uytterhoeven
2025-08-13 21:32 ` Jakub Kicinski
2025-08-13 13:33 ` Vadim Fedorenko
2025-08-14 1:53 ` Yibo Dong
2025-08-15 0:04 ` Andrew Lunn
2025-08-15 1:36 ` Yibo Dong
2025-08-13 8:20 ` MD Danish Anwar
2025-08-13 9:24 ` Yibo Dong
2025-08-12 9:39 ` [PATCH v3 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-08-12 15:32 ` Vadim Fedorenko [this message]
2025-08-13 9:04 ` Yibo Dong
2025-08-13 12:50 ` Vadim Fedorenko
2025-08-14 1:52 ` Yibo Dong
2025-08-13 8:26 ` MD Danish Anwar
2025-08-13 9:49 ` 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=e410918e-98aa-4a14-8fb4-5d9e73f7375e@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).