linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE
@ 2025-08-28  2:55 Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
                   ` (5 more replies)
  0 siblings, 6 replies; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

Hi maintainers,

This patch series is v9 to introduce support for MUCSE N500/N210 1Gbps
Ethernet controllers. I divide codes into multiple series, this is the
first one which only register netdev without true tx/rx functions.

Changelog:
v8 -> v9:
1. update function description format '@return' to 'Return' 
2. update 'negative on failure' to 'negative errno on failure'

links:
v8: https://lore.kernel.org/netdev/20250827034509.501980-1-dong100@mucse.com/
v7: https://lore.kernel.org/netdev/20250822023453.1910972-1-dong100@mucse.com
v6: https://lore.kernel.org/netdev/20250820092154.1643120-1-dong100@mucse.com/
v5: https://lore.kernel.org/netdev/20250818112856.1446278-1-dong100@mucse.com/
v4: https://lore.kernel.org/netdev/20250814073855.1060601-1-dong100@mucse.com/
v3: https://lore.kernel.org/netdev/20250812093937.882045-1-dong100@mucse.com/
v2: https://lore.kernel.org/netdev/20250721113238.18615-1-dong100@mucse.com/
v1: https://lore.kernel.org/netdev/20250703014859.210110-1-dong100@mucse.com/

Dong Yibo (5):
  net: rnpgbe: Add build support for rnpgbe
  net: rnpgbe: Add n500/n210 chip support
  net: rnpgbe: Add basic mbx ops support
  net: rnpgbe: Add basic mbx_fw support
  net: rnpgbe: Add register_netdev

 .../device_drivers/ethernet/index.rst         |   1 +
 .../device_drivers/ethernet/mucse/rnpgbe.rst  |  21 +
 MAINTAINERS                                   |   8 +
 drivers/net/ethernet/Kconfig                  |   1 +
 drivers/net/ethernet/Makefile                 |   1 +
 drivers/net/ethernet/mucse/Kconfig            |  34 ++
 drivers/net/ethernet/mucse/Makefile           |   7 +
 drivers/net/ethernet/mucse/rnpgbe/Makefile    |  11 +
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h    |  98 +++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c   | 153 +++++++
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h |  18 +
 .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c   | 286 +++++++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c    | 393 ++++++++++++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h    |  25 ++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 253 +++++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 126 ++++++
 16 files changed, 1436 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst
 create mode 100644 drivers/net/ethernet/mucse/Kconfig
 create mode 100644 drivers/net/ethernet/mucse/Makefile
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/Makefile
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h

-- 
2.25.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
@ 2025-08-28  2:55 ` Dong Yibo
  2025-08-28 12:51   ` Andrew Lunn
  2025-08-28  2:55 ` [PATCH net-next v9 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

Add build options and doc for mucse.
Initialize pci device access for MUCSE devices.

Signed-off-by: Dong Yibo <dong100@mucse.com>
---
 .../device_drivers/ethernet/index.rst         |   1 +
 .../device_drivers/ethernet/mucse/rnpgbe.rst  |  21 +++
 MAINTAINERS                                   |   8 ++
 drivers/net/ethernet/Kconfig                  |   1 +
 drivers/net/ethernet/Makefile                 |   1 +
 drivers/net/ethernet/mucse/Kconfig            |  34 +++++
 drivers/net/ethernet/mucse/Makefile           |   7 +
 drivers/net/ethernet/mucse/rnpgbe/Makefile    |   8 ++
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h    |  24 ++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c   | 126 ++++++++++++++++++
 10 files changed, 231 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst
 create mode 100644 drivers/net/ethernet/mucse/Kconfig
 create mode 100644 drivers/net/ethernet/mucse/Makefile
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/Makefile
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c

diff --git a/Documentation/networking/device_drivers/ethernet/index.rst b/Documentation/networking/device_drivers/ethernet/index.rst
index 0b0a3eef6aae..41ff2152b7aa 100644
--- a/Documentation/networking/device_drivers/ethernet/index.rst
+++ b/Documentation/networking/device_drivers/ethernet/index.rst
@@ -47,6 +47,7 @@ Contents:
    mellanox/mlx5/index
    meta/fbnic
    microsoft/netvsc
+   mucse/rnpgbe
    neterion/s2io
    netronome/nfp
    pensando/ionic
diff --git a/Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst b/Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst
new file mode 100644
index 000000000000..7562fb6b8f61
--- /dev/null
+++ b/Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst
@@ -0,0 +1,21 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===========================================================
+Linux Base Driver for MUCSE(R) Gigabit PCI Express Adapters
+===========================================================
+
+MUCSE Gigabit Linux driver.
+Copyright (c) 2020 - 2025 MUCSE Co.,Ltd.
+
+Identifying Your Adapter
+========================
+The driver is compatible with devices based on the following:
+
+ * MUCSE(R) Ethernet Controller N500 series
+ * MUCSE(R) Ethernet Controller N210 series
+
+Support
+=======
+ If you have problems with the software or hardware, please contact our
+ customer support team via email at techsupport@mucse.com or check our
+ website at https://www.mucse.com/en/
diff --git a/MAINTAINERS b/MAINTAINERS
index bce96dd254b8..00b73e3631b4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17276,6 +17276,14 @@ T:	git git://linuxtv.org/media.git
 F:	Documentation/devicetree/bindings/media/i2c/aptina,mt9v111.yaml
 F:	drivers/media/i2c/mt9v111.c
 
+MUCSE ETHERNET DRIVER
+M:	Yibo Dong <dong100@mucse.com>
+L:	netdev@vger.kernel.org
+S:	Maintained
+W:	https://www.mucse.com/en/
+F:	Documentation/networking/device_drivers/ethernet/mucse/
+F:	drivers/net/ethernet/mucse/
+
 MULTIFUNCTION DEVICES (MFD)
 M:	Lee Jones <lee@kernel.org>
 S:	Maintained
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
index f86d4557d8d7..167388f9c744 100644
--- a/drivers/net/ethernet/Kconfig
+++ b/drivers/net/ethernet/Kconfig
@@ -129,6 +129,7 @@ source "drivers/net/ethernet/microchip/Kconfig"
 source "drivers/net/ethernet/mscc/Kconfig"
 source "drivers/net/ethernet/microsoft/Kconfig"
 source "drivers/net/ethernet/moxa/Kconfig"
+source "drivers/net/ethernet/mucse/Kconfig"
 source "drivers/net/ethernet/myricom/Kconfig"
 
 config FEALNX
diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile
index 67182339469a..1b8c4df3f594 100644
--- a/drivers/net/ethernet/Makefile
+++ b/drivers/net/ethernet/Makefile
@@ -65,6 +65,7 @@ obj-$(CONFIG_NET_VENDOR_MICREL) += micrel/
 obj-$(CONFIG_NET_VENDOR_MICROCHIP) += microchip/
 obj-$(CONFIG_NET_VENDOR_MICROSEMI) += mscc/
 obj-$(CONFIG_NET_VENDOR_MOXART) += moxa/
+obj-$(CONFIG_NET_VENDOR_MUCSE) += mucse/
 obj-$(CONFIG_NET_VENDOR_MYRI) += myricom/
 obj-$(CONFIG_FEALNX) += fealnx.o
 obj-$(CONFIG_NET_VENDOR_NATSEMI) += natsemi/
diff --git a/drivers/net/ethernet/mucse/Kconfig b/drivers/net/ethernet/mucse/Kconfig
new file mode 100644
index 000000000000..be0fdf268484
--- /dev/null
+++ b/drivers/net/ethernet/mucse/Kconfig
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Mucse network device configuration
+#
+
+config NET_VENDOR_MUCSE
+	bool "Mucse devices"
+	default y
+	help
+	  If you have a network (Ethernet) card from Mucse(R), say Y.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Mucse(R) cards. If you say Y, you will
+	  be asked for your specific card in the following questions.
+
+if NET_VENDOR_MUCSE
+
+config MGBE
+	tristate "Mucse(R) 1GbE PCI Express adapters support"
+	depends on PCI
+	select PAGE_POOL
+	help
+	  This driver supports Mucse(R) 1GbE PCI Express family of
+	  adapters.
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/mucse/rnpgbe.rst>.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called rnpgbe.
+
+endif # NET_VENDOR_MUCSE
+
diff --git a/drivers/net/ethernet/mucse/Makefile b/drivers/net/ethernet/mucse/Makefile
new file mode 100644
index 000000000000..675173fa05f7
--- /dev/null
+++ b/drivers/net/ethernet/mucse/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2020 - 2025 MUCSE Corporation.
+#
+# Makefile for the MUCSE(R) network device drivers
+#
+
+obj-$(CONFIG_MGBE) += rnpgbe/
diff --git a/drivers/net/ethernet/mucse/rnpgbe/Makefile b/drivers/net/ethernet/mucse/rnpgbe/Makefile
new file mode 100644
index 000000000000..9df536f0d04c
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2020 - 2025 MUCSE Corporation.
+#
+# Makefile for the MUCSE(R) 1GbE PCI Express ethernet driver
+#
+
+obj-$(CONFIG_MGBE) += rnpgbe.o
+rnpgbe-objs := rnpgbe_main.o
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
new file mode 100644
index 000000000000..64b2c093bc6e
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#ifndef _RNPGBE_H
+#define _RNPGBE_H
+
+enum rnpgbe_boards {
+	board_n500,
+	board_n210,
+	board_n210L,
+};
+
+struct mucse {
+	struct net_device *netdev;
+	struct pci_dev *pdev;
+};
+
+/* Device IDs */
+#define PCI_VENDOR_ID_MUCSE 0x8848
+#define PCI_DEVICE_ID_N500_QUAD_PORT 0x8308
+#define PCI_DEVICE_ID_N500_DUAL_PORT 0x8318
+#define PCI_DEVICE_ID_N210 0x8208
+#define PCI_DEVICE_ID_N210L 0x820a
+#endif /* _RNPGBE_H */
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
new file mode 100644
index 000000000000..98905607e74b
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "rnpgbe.h"
+
+static const char rnpgbe_driver_name[] = "rnpgbe";
+
+/* rnpgbe_pci_tbl - PCI Device ID Table
+ *
+ * { PCI_DEVICE(Vendor ID, Device ID),
+ *   driver_data (used for different hw chip) }
+ */
+static struct pci_device_id rnpgbe_pci_tbl[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_MUCSE, PCI_DEVICE_ID_N500_QUAD_PORT),
+	  .driver_data = board_n500},
+	{ PCI_DEVICE(PCI_VENDOR_ID_MUCSE, PCI_DEVICE_ID_N500_DUAL_PORT),
+	  .driver_data = board_n500},
+	{ PCI_DEVICE(PCI_VENDOR_ID_MUCSE, PCI_DEVICE_ID_N210),
+	  .driver_data = board_n210},
+	{ PCI_DEVICE(PCI_VENDOR_ID_MUCSE, PCI_DEVICE_ID_N210L),
+	  .driver_data = board_n210L},
+	/* required last entry */
+	{0, },
+};
+
+/**
+ * rnpgbe_probe - Device initialization routine
+ * @pdev: PCI device information struct
+ * @id: entry in rnpgbe_pci_tbl
+ *
+ * rnpgbe_probe initializes a PF adapter identified by a pci_dev
+ * structure.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	int err;
+
+	err = pci_enable_device_mem(pdev);
+	if (err)
+		return err;
+
+	err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(56));
+	if (err) {
+		dev_err(&pdev->dev,
+			"No usable DMA configuration, aborting %d\n", err);
+		goto err_disable_dev;
+	}
+
+	err = pci_request_mem_regions(pdev, rnpgbe_driver_name);
+	if (err) {
+		dev_err(&pdev->dev,
+			"pci_request_selected_regions failed %d\n", err);
+		goto err_disable_dev;
+	}
+
+	pci_set_master(pdev);
+	err = pci_save_state(pdev);
+	if (err) {
+		dev_err(&pdev->dev, "pci_save_state failed %d\n", err);
+		goto err_free_regions;
+	}
+
+	return 0;
+err_free_regions:
+	pci_release_mem_regions(pdev);
+err_disable_dev:
+	pci_disable_device(pdev);
+	return err;
+}
+
+/**
+ * rnpgbe_remove - Device removal routine
+ * @pdev: PCI device information struct
+ *
+ * rnpgbe_remove is called by the PCI subsystem to alert the driver
+ * that it should release a PCI device. This could be caused by a
+ * Hot-Plug event, or because the driver is going to be removed from
+ * memory.
+ **/
+static void rnpgbe_remove(struct pci_dev *pdev)
+{
+	pci_release_mem_regions(pdev);
+	pci_disable_device(pdev);
+}
+
+/**
+ * rnpgbe_dev_shutdown - Device shutdown routine
+ * @pdev: PCI device information struct
+ **/
+static void rnpgbe_dev_shutdown(struct pci_dev *pdev)
+{
+	pci_disable_device(pdev);
+}
+
+/**
+ * rnpgbe_shutdown - Device shutdown routine
+ * @pdev: PCI device information struct
+ *
+ * rnpgbe_shutdown is called by the PCI subsystem to alert the driver
+ * that os shutdown. Device should setup wakeup state here.
+ **/
+static void rnpgbe_shutdown(struct pci_dev *pdev)
+{
+	rnpgbe_dev_shutdown(pdev);
+}
+
+static struct pci_driver rnpgbe_driver = {
+	.name = rnpgbe_driver_name,
+	.id_table = rnpgbe_pci_tbl,
+	.probe = rnpgbe_probe,
+	.remove = rnpgbe_remove,
+	.shutdown = rnpgbe_shutdown,
+};
+
+module_pci_driver(rnpgbe_driver);
+
+MODULE_DEVICE_TABLE(pci, rnpgbe_pci_tbl);
+MODULE_AUTHOR("Mucse Corporation, <techsupport@mucse.com>");
+MODULE_DESCRIPTION("Mucse(R) 1 Gigabit PCI Express Network Driver");
+MODULE_LICENSE("GPL");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 2/5] net: rnpgbe: Add n500/n210 chip support
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
@ 2025-08-28  2:55 ` Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

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    | 34 ++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c   | 68 +++++++++++++++
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 16 ++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c   | 85 +++++++++++++++++++
 5 files changed, 205 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..9a86e67d6395 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -4,15 +4,49 @@
 #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_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;
+	struct pci_dev *pdev;
+	enum rnpgbe_hw_type hw_type;
+	struct mucse_mbx_info mbx;
+};
+
 struct mucse {
 	struct net_device *netdev;
 	struct pci_dev *pdev;
+	struct mucse_hw hw;
+};
+
+struct rnpgbe_info {
+	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..179621ea09f3
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
@@ -0,0 +1,68 @@
+// 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_mbx_info *mbx = &hw->mbx;
+
+	mbx->pf2fw_mbox_ctrl = GBE_PF2FW_MBX_MASK_OFFSET;
+	mbx->fw_pf_mbox_mask = GBE_FWPF_MBX_MASK;
+}
+
+/**
+ * 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 = N500_FW2PF_MBX_VEC_OFFSET;
+	mbx->fw_pf_shm_base = N500_FWPF_SHM_BASE_OFFSET;
+}
+
+/**
+ * rnpgbe_init_n210 - Setup n210 hw info
+ * @hw: hw information structure
+ *
+ * rnpgbe_init_n210 initializes all private
+ * structure, such as dma, eth, mac and mbx base on
+ * hw->hw_addr for n210
+ **/
+static void rnpgbe_init_n210(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+
+	rnpgbe_init_common(hw);
+
+	mbx->fw2pf_mbox_vec = N210_FW2PF_MBX_VEC_OFFSET;
+	mbx->fw_pf_shm_base = N210_FWPF_SHM_BASE_OFFSET;
+}
+
+const struct rnpgbe_info rnpgbe_n500_info = {
+	.hw_type = rnpgbe_hw_n500,
+	.init = &rnpgbe_init_n500,
+};
+
+const struct rnpgbe_info rnpgbe_n210_info = {
+	.hw_type = rnpgbe_hw_n210,
+	.init = &rnpgbe_init_n210,
+};
+
+const struct rnpgbe_info rnpgbe_n210L_info = {
+	.hw_type = rnpgbe_hw_n210L,
+	.init = &rnpgbe_init_n210,
+};
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
new file mode 100644
index 000000000000..746dca78f1df
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#ifndef _RNPGBE_HW_H
+#define _RNPGBE_HW_H
+
+/**************** MBX Resource ****************************/
+#define N500_FW2PF_MBX_VEC_OFFSET 0x28b00
+#define N500_FWPF_SHM_BASE_OFFSET 0x2d000
+#define GBE_PF2FW_MBX_MASK_OFFSET 0x5500
+#define GBE_FWPF_MBX_MASK 0x5700
+#define N210_FW2PF_MBX_VEC_OFFSET 0x29400
+#define N210_FWPF_SHM_BASE_OFFSET 0x2d900
+/**************** 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 98905607e74b..25b7119d6ecb 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -4,10 +4,18 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 
 #include "rnpgbe.h"
+#include "rnpgbe_hw.h"
 
 static const char rnpgbe_driver_name[] = "rnpgbe";
+static const struct rnpgbe_info *rnpgbe_info_tbl[] = {
+	[board_n500] = &rnpgbe_n500_info,
+	[board_n210] = &rnpgbe_n210_info,
+	[board_n210L] = &rnpgbe_n210L_info,
+};
 
 /* rnpgbe_pci_tbl - PCI Device ID Table
  *
@@ -27,6 +35,56 @@ static struct pci_device_id rnpgbe_pci_tbl[] = {
 	{0, },
 };
 
+/**
+ * rnpgbe_add_adapter - Add netdev for this pci_dev
+ * @pdev: PCI device information structure
+ * @info: chip info structure
+ *
+ * rnpgbe_add_adapter initializes a netdev for this pci_dev
+ * structure. Initializes Bar map, private structure, and a
+ * hardware reset occur.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+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;
+	int err;
+
+	netdev = alloc_etherdev_mq(sizeof(struct mucse), RNPGBE_MAX_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;
+	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;
+	}
+
+	hw->hw_addr = hw_addr;
+	info->init(hw);
+	return 0;
+
+err_free_net:
+	free_netdev(netdev);
+	return err;
+}
+
 /**
  * rnpgbe_probe - Device initialization routine
  * @pdev: PCI device information struct
@@ -39,6 +97,7 @@ static struct pci_device_id rnpgbe_pci_tbl[] = {
  **/
 static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
+	const struct rnpgbe_info *info = rnpgbe_info_tbl[id->driver_data];
 	int err;
 
 	err = pci_enable_device_mem(pdev);
@@ -65,6 +124,9 @@ static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		dev_err(&pdev->dev, "pci_save_state failed %d\n", err);
 		goto err_free_regions;
 	}
+	err = rnpgbe_add_adapter(pdev, info);
+	if (err)
+		goto err_free_regions;
 
 	return 0;
 err_free_regions:
@@ -74,6 +136,24 @@ static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	return err;
 }
 
+/**
+ * rnpgbe_rm_adapter - Remove netdev for this mucse structure
+ * @pdev: PCI device information struct
+ *
+ * rnpgbe_rm_adapter remove a netdev for this mucse structure
+ **/
+static void rnpgbe_rm_adapter(struct pci_dev *pdev)
+{
+	struct mucse *mucse = pci_get_drvdata(pdev);
+	struct net_device *netdev;
+
+	if (!mucse)
+		return;
+	netdev = mucse->netdev;
+	mucse->netdev = NULL;
+	free_netdev(netdev);
+}
+
 /**
  * rnpgbe_remove - Device removal routine
  * @pdev: PCI device information struct
@@ -85,6 +165,7 @@ static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  **/
 static void rnpgbe_remove(struct pci_dev *pdev)
 {
+	rnpgbe_rm_adapter(pdev);
 	pci_release_mem_regions(pdev);
 	pci_disable_device(pdev);
 }
@@ -95,6 +176,10 @@ static void rnpgbe_remove(struct pci_dev *pdev)
  **/
 static void rnpgbe_dev_shutdown(struct pci_dev *pdev)
 {
+	struct mucse *mucse = pci_get_drvdata(pdev);
+	struct net_device *netdev = mucse->netdev;
+
+	netif_device_detach(netdev);
 	pci_disable_device(pdev);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 3/5] net: rnpgbe: Add basic mbx ops support
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
@ 2025-08-28  2:55 ` Dong Yibo
  2025-08-28  2:55 ` [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

Initialize basic mbx function.

Signed-off-by: Dong Yibo <dong100@mucse.com>
---
 drivers/net/ethernet/mucse/rnpgbe/Makefile    |   3 +-
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h    |  16 +
 .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c   |   3 +
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c    | 393 ++++++++++++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h    |  25 ++
 5 files changed, 439 insertions(+), 1 deletion(-)
 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..5fc878ada4b1 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
+++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
@@ -6,4 +6,5 @@
 
 obj-$(CONFIG_MGBE) += rnpgbe.o
 rnpgbe-objs := rnpgbe_main.o\
-	       rnpgbe_chip.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 9a86e67d6395..7999bb99306b 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -5,6 +5,7 @@
 #define _RNPGBE_H
 
 #include <linux/types.h>
+#include <linux/mutex.h>
 
 extern const struct rnpgbe_info rnpgbe_n500_info;
 extern const struct rnpgbe_info rnpgbe_n210_info;
@@ -23,7 +24,22 @@ enum rnpgbe_hw_type {
 	rnpgbe_hw_unknown
 };
 
+struct mucse_mbx_stats {
+	u32 msgs_tx;
+	u32 msgs_rx;
+	u32 acks;
+	u32 reqs;
+};
+
 struct mucse_mbx_info {
+	struct mucse_mbx_stats stats;
+	u32 timeout;
+	u32 usec_delay;
+	u16 size;
+	u16 fw_req;
+	u16 fw_ack;
+	/* lock for only one use mbx */
+	struct mutex lock;
 	/* fw <--> pf mbx */
 	u32 fw_pf_shm_base;
 	u32 pf2fw_mbox_ctrl;
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
index 179621ea09f3..f38daef752a3 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
@@ -1,8 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright(c) 2020 - 2025 Mucse Corporation. */
 
+#include <linux/string.h>
+
 #include "rnpgbe.h"
 #include "rnpgbe_hw.h"
+#include "rnpgbe_mbx.h"
 
 /**
  * rnpgbe_init_common - Setup common attribute
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..856cd4c8ab6f
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
@@ -0,0 +1,393 @@
+// 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"
+
+/**
+ * mbx_data_rd32  - Reads reg with base mbx->fw_pf_shm_base
+ * @mbx: pointer to the MBX structure
+ * @reg: register offset
+ *
+ * Return: register value
+ **/
+static u32 mbx_data_rd32(struct mucse_mbx_info *mbx, u32 reg)
+{
+	struct mucse_hw *hw = container_of(mbx, struct mucse_hw, mbx);
+
+	return readl(hw->hw_addr + mbx->fw_pf_shm_base + reg);
+}
+
+/**
+ * mbx_data_wr32  - Writes value to reg with base mbx->fw_pf_shm_base
+ * @mbx: pointer to the MBX structure
+ * @reg: register offset
+ * @value: value to be written
+ *
+ **/
+static void mbx_data_wr32(struct mucse_mbx_info *mbx, u32 reg, u32 value)
+{
+	struct mucse_hw *hw = container_of(mbx, struct mucse_hw, mbx);
+
+	writel(value, hw->hw_addr + mbx->fw_pf_shm_base + reg);
+}
+
+/**
+ * mbx_ctrl_rd32  - Reads reg with base mbx->fw2pf_mbox_vec
+ * @mbx: pointer to the MBX structure
+ * @reg: register offset
+ *
+ * Return: register value
+ **/
+static u32 mbx_ctrl_rd32(struct mucse_mbx_info *mbx, u32 reg)
+{
+	struct mucse_hw *hw = container_of(mbx, struct mucse_hw, mbx);
+
+	return readl(hw->hw_addr + mbx->fw2pf_mbox_vec + reg);
+}
+
+/**
+ * mbx_ctrl_wr32  - Writes value to reg with base mbx->fw2pf_mbox_vec
+ * @mbx: pointer to the MBX structure
+ * @reg: register offset
+ * @value: value to be written
+ *
+ **/
+static void mbx_ctrl_wr32(struct mucse_mbx_info *mbx, u32 reg, u32 value)
+{
+	struct mucse_hw *hw = container_of(mbx, struct mucse_hw, mbx);
+
+	writel(value, hw->hw_addr + mbx->fw2pf_mbox_vec + reg);
+}
+
+/**
+ * mucse_mbx_get_fwreq - Read fw req from reg
+ * @mbx: pointer to the mbx structure
+ *
+ * Return: the fwreq value
+ **/
+static u16 mucse_mbx_get_fwreq(struct mucse_mbx_info *mbx)
+{
+	return mbx_data_rd32(mbx, MBX_FW2PF_COUNTER) & GENMASK_U32(15, 0);
+}
+
+/**
+ * mucse_mbx_get_fwack - Read fw ack from reg
+ * @mbx: pointer to the MBX structure
+ *
+ * Return: the fwack value
+ **/
+static u16 mucse_mbx_get_fwack(struct mucse_mbx_info *mbx)
+{
+	return (mbx_data_rd32(mbx, MBX_FW2PF_COUNTER) >> 16);
+}
+
+/**
+ * mucse_mbx_inc_pf_req - Increase req
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_inc_pf_req read pf_req from hw, then write
+ * new value back after increase
+ **/
+static void mucse_mbx_inc_pf_req(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	u16 req;
+	u32 v;
+
+	v = mbx_data_rd32(mbx, MBX_PF2FW_COUNTER);
+	req = (v & GENMASK_U32(15, 0));
+	req++;
+	v &= GENMASK_U32(31, 16);
+	v |= req;
+	mbx_data_wr32(mbx, MBX_PF2FW_COUNTER, v);
+	hw->mbx.stats.msgs_tx++;
+}
+
+/**
+ * mucse_mbx_inc_pf_ack - Increase ack
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_inc_pf_ack read pf_ack from hw, then write
+ * new value back after increase
+ **/
+static void mucse_mbx_inc_pf_ack(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	u16 ack;
+	u32 v;
+
+	v = mbx_data_rd32(mbx, MBX_PF2FW_COUNTER);
+	ack = (v >> 16) & GENMASK_U32(15, 0);
+	ack++;
+	v &= GENMASK_U32(15, 0);
+	v |= (ack << 16);
+	mbx_data_wr32(mbx, MBX_PF2FW_COUNTER, v);
+	hw->mbx.stats.msgs_rx++;
+}
+
+/**
+ * mucse_check_for_msg_pf - Check to see if the fw has sent mail
+ * @hw: pointer to the HW structure
+ *
+ * Return: 0 if the fw has set the Status bit or else -EIO
+ **/
+static int mucse_check_for_msg_pf(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	u16 hw_req_count;
+
+	hw_req_count = mucse_mbx_get_fwreq(mbx);
+	/* chip's register is reset to 0 when rc send reset
+	 * mbx command. This causes 'hw_req_count != hw->mbx.fw_req'
+	 * be TRUE before fw really reply. Driver must wait fw reset
+	 * done reply before using chip, we must check no-zero.
+	 **/
+	if (hw_req_count != 0 && hw_req_count != hw->mbx.fw_req) {
+		hw->mbx.stats.reqs++;
+		return 0;
+	}
+
+	return -EIO;
+}
+
+/**
+ * mucse_poll_for_msg - Wait for message notification
+ * @hw: pointer to the HW structure
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_poll_for_msg(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	int countdown = mbx->timeout;
+	int val;
+
+	return read_poll_timeout(mucse_check_for_msg_pf,
+				 val, val == 0, mbx->usec_delay,
+				 countdown * mbx->usec_delay,
+				 false, hw);
+}
+
+/**
+ * mucse_check_for_ack_pf - Check to see if the VF has ACKed
+ * @hw: pointer to the HW structure
+ *
+ * Return: 0 if the fw has set the Status bit or else -EIO
+ **/
+static int mucse_check_for_ack_pf(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	u16 hw_fw_ack;
+
+	hw_fw_ack = mucse_mbx_get_fwack(mbx);
+	/* chip's register is reset to 0 when rc send reset
+	 * mbx command. This causes 'hw_fw_ack != hw->mbx.fw_ack'
+	 * be TRUE before fw really reply. Driver must wait fw reset
+	 * done reply before using chip, we must check no-zero.
+	 **/
+	if (hw_fw_ack != 0 && hw_fw_ack != hw->mbx.fw_ack) {
+		hw->mbx.stats.acks++;
+		return 0;
+	}
+
+	return -EIO;
+}
+
+/**
+ * mucse_poll_for_ack - Wait for message acknowledgment
+ * @hw: pointer to the HW structure
+ *
+ * Return: 0 if it successfully received a message acknowledgment
+ **/
+static int mucse_poll_for_ack(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	int countdown = mbx->timeout;
+	int val;
+
+	return read_poll_timeout(mucse_check_for_ack_pf,
+				 val, val == 0, mbx->usec_delay,
+				 countdown * mbx->usec_delay,
+				 false, hw);
+}
+
+/**
+ * mucse_obtain_mbx_lock_pf - Obtain mailbox lock
+ * @hw: pointer to the HW structure
+ *
+ * This function maybe used in an irq handler.
+ *
+ * Return: 0 if we obtained the mailbox lock or else -EIO
+ **/
+static int mucse_obtain_mbx_lock_pf(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	int try_cnt = 5000;
+	u32 reg;
+
+	reg = PF2FW_MBOX_CTRL(mbx);
+	while (try_cnt-- > 0) {
+		mbx_ctrl_wr32(mbx, reg, MBOX_PF_HOLD);
+		/* force write back before check */
+		wmb();
+		if (mbx_ctrl_rd32(mbx, reg) & MBOX_PF_HOLD)
+			return 0;
+		udelay(100);
+	}
+	return -EIO;
+}
+
+/**
+ * mucse_read_mbx_pf - Read a message from the mailbox
+ * @hw: pointer to the HW structure
+ * @msg: the message buffer
+ * @size: length of buffer
+ *
+ * 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 fw request so no polling for message is needed.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_read_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	int size_inwords = size / 4;
+	u32 ctrl_reg;
+	int ret;
+	int i;
+
+	ctrl_reg = PF2FW_MBOX_CTRL(mbx);
+
+	ret = mucse_obtain_mbx_lock_pf(hw);
+	if (ret)
+		return ret;
+	for (i = 0; i < size_inwords; i++)
+		msg[i] = mbx_data_rd32(mbx, MBX_FW_PF_SHM_DATA + 4 * i);
+	/* Hw need write data_reg at last */
+	mbx_data_wr32(mbx, MBX_FW_PF_SHM_DATA, 0);
+	hw->mbx.fw_req = mucse_mbx_get_fwreq(mbx);
+	mucse_mbx_inc_pf_ack(hw);
+	mbx_ctrl_wr32(mbx, ctrl_reg, 0);
+
+	return 0;
+}
+
+/**
+ * mucse_read_posted_mbx - Wait for message notification and receive message
+ * @hw: pointer to the HW structure
+ * @msg: the message buffer
+ * @size: length of buffer
+ *
+ * Return: 0 if it successfully received a message notification and
+ * copied it into the receive buffer
+ **/
+int mucse_read_posted_mbx(struct mucse_hw *hw, u32 *msg, u16 size)
+{
+	int ret;
+
+	ret = mucse_poll_for_msg(hw);
+	if (ret)
+		return ret;
+
+	return mucse_read_mbx_pf(hw, msg, size);
+}
+
+/**
+ * mucse_mbx_reset - Reset mbx info, sync info from regs
+ * @hw: pointer to the HW structure
+ *
+ * This function reset all mbx variables to default.
+ **/
+static void mucse_mbx_reset(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	u32 v;
+
+	v = mbx_data_rd32(mbx, MBX_FW2PF_COUNTER);
+	hw->mbx.fw_req = v & GENMASK_U32(15, 0);
+	hw->mbx.fw_ack = (v >> 16) & GENMASK_U32(15, 0);
+	mbx_ctrl_wr32(mbx, PF2FW_MBOX_CTRL(mbx), 0);
+	mbx_ctrl_wr32(mbx, FW_PF_MBOX_MASK(mbx), GENMASK_U32(31, 16));
+}
+
+/**
+ * mucse_init_mbx_params_pf - Set initial values for pf mailbox
+ * @hw: pointer to the HW structure
+ *
+ * Initializes the hw->mbx struct to correct values for pf mailbox
+ */
+void mucse_init_mbx_params_pf(struct mucse_hw *hw)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+
+	mbx->usec_delay = 100;
+	mbx->timeout = (4 * USEC_PER_SEC) / mbx->usec_delay;
+	mbx->stats.msgs_tx = 0;
+	mbx->stats.msgs_rx = 0;
+	mbx->stats.reqs = 0;
+	mbx->stats.acks = 0;
+	mbx->size = MUCSE_MAILBOX_BYTES;
+	mutex_init(&mbx->lock);
+	mucse_mbx_reset(hw);
+}
+
+/**
+ * mucse_write_mbx_pf - Place a message in the mailbox
+ * @hw: pointer to the HW structure
+ * @msg: the message buffer
+ * @size: length of buffer
+ *
+ * This function maybe used in an irq handler.
+ *
+ * Return: 0 if it successfully copied message into the buffer
+ **/
+int mucse_write_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size)
+{
+	struct mucse_mbx_info *mbx = &hw->mbx;
+	int size_inwords = size / 4;
+	u32 ctrl_reg;
+	int ret;
+	int i;
+
+	ctrl_reg = PF2FW_MBOX_CTRL(mbx);
+	ret = mucse_obtain_mbx_lock_pf(hw);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < size_inwords; i++)
+		mbx_data_wr32(mbx, MBX_FW_PF_SHM_DATA + i * 4, msg[i]);
+
+	/* flush msg and acks as we are overwriting the message buffer */
+	hw->mbx.fw_ack = mucse_mbx_get_fwack(mbx);
+	mucse_mbx_inc_pf_req(hw);
+	mbx_ctrl_wr32(mbx, ctrl_reg, MBOX_CTRL_REQ);
+
+	return 0;
+}
+
+/**
+ * mucse_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
+ *
+ * Return: 0 if it successfully copied message into the buffer and
+ * received an ack to that message within delay * timeout period
+ **/
+int mucse_write_posted_mbx(struct mucse_hw *hw, u32 *msg, u16 size)
+{
+	int ret;
+
+	ret = mucse_write_mbx_pf(hw, msg, size);
+	if (ret)
+		return ret;
+	return mucse_poll_for_ack(hw);
+}
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h
new file mode 100644
index 000000000000..110c1ee025ba
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#ifndef _RNPGBE_MBX_H
+#define _RNPGBE_MBX_H
+
+#include "rnpgbe.h"
+
+#define MUCSE_MAILBOX_BYTES 56
+#define MBX_FW2PF_COUNTER 0
+#define MBX_PF2FW_COUNTER 4
+#define MBX_FW_PF_SHM_DATA 8
+#define FW2PF_MBOX_VEC 0
+#define PF2FW_MBOX_CTRL(mbx) ((mbx)->pf2fw_mbox_ctrl)
+#define FW_PF_MBOX_MASK(mbx) ((mbx)->fw_pf_mbox_mask)
+#define MBOX_CTRL_REQ BIT(0)
+#define MBOX_PF_HOLD BIT(3)
+#define MBOX_IRQ_EN 0
+#define MBOX_IRQ_DISABLE 1
+
+int mucse_write_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size);
+int mucse_write_posted_mbx(struct mucse_hw *hw, u32 *msg, u16 size);
+void mucse_init_mbx_params_pf(struct mucse_hw *hw);
+int mucse_read_posted_mbx(struct mucse_hw *hw, u32 *msg, u16 size);
+#endif /* _RNPGBE_MBX_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
                   ` (2 preceding siblings ...)
  2025-08-28  2:55 ` [PATCH net-next v9 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
@ 2025-08-28  2:55 ` Dong Yibo
  2025-08-28 13:09   ` Andrew Lunn
  2025-08-28  2:55 ` [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev Dong Yibo
  2025-08-28  5:22 ` [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE MD Danish Anwar
  5 siblings, 1 reply; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

Initialize basic mbx_fw ops, such as get_capability, reset phy
and so on.

Signed-off-by: Dong Yibo <dong100@mucse.com>
---
 drivers/net/ethernet/mucse/rnpgbe/Makefile    |   3 +-
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h    |   1 +
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 253 ++++++++++++++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 126 +++++++++
 4 files changed, 382 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
 create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h

diff --git a/drivers/net/ethernet/mucse/rnpgbe/Makefile b/drivers/net/ethernet/mucse/rnpgbe/Makefile
index 5fc878ada4b1..de8bcb7772ab 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
+++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
@@ -7,4 +7,5 @@
 obj-$(CONFIG_MGBE) += rnpgbe.o
 rnpgbe-objs := rnpgbe_main.o\
 	       rnpgbe_chip.o\
-	       rnpgbe_mbx.o
+	       rnpgbe_mbx.o\
+	       rnpgbe_mbx_fw.o
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
index 7999bb99306b..4d2cca59fb23 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -51,6 +51,7 @@ struct mucse_hw {
 	void __iomem *hw_addr;
 	struct pci_dev *pdev;
 	enum rnpgbe_hw_type hw_type;
+	u8 pfvfnum;
 	struct mucse_mbx_info mbx;
 };
 
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
new file mode 100644
index 000000000000..fe626deca3ed
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#include <linux/pci.h>
+#include <linux/if_ether.h>
+
+#include "rnpgbe.h"
+#include "rnpgbe_hw.h"
+#include "rnpgbe_mbx.h"
+#include "rnpgbe_mbx_fw.h"
+
+/**
+ * mucse_fw_send_cmd_wait - Send cmd req and wait for response
+ * @hw: pointer to the HW structure
+ * @req: pointer to the cmd req structure
+ * @reply: pointer to the fw reply structure
+ *
+ * mucse_fw_send_cmd_wait sends req to pf-fw mailbox and wait
+ * reply from fw.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_fw_send_cmd_wait(struct mucse_hw *hw,
+				  struct mbx_fw_cmd_req *req,
+				  struct mbx_fw_cmd_reply *reply)
+{
+	int len = le16_to_cpu(req->datalen);
+	int retry_cnt = 3;
+	int err;
+
+	err = mutex_lock_interruptible(&hw->mbx.lock);
+	if (err)
+		return err;
+	err = mucse_write_posted_mbx(hw, (u32 *)req, len);
+	if (err)
+		goto out;
+	do {
+		err = mucse_read_posted_mbx(hw, (u32 *)reply,
+					    sizeof(*reply));
+		if (err)
+			goto out;
+		/* mucse_write_posted_mbx return 0 means fw has
+		 * received request, wait for the expect opcode
+		 * reply with 'retry_cnt' times.
+		 */
+	} while (--retry_cnt >= 0 && reply->opcode != req->opcode);
+out:
+	mutex_unlock(&hw->mbx.lock);
+	if (!err && retry_cnt < 0)
+		return -ETIMEDOUT;
+	if (!err && reply->error_code)
+		return -EIO;
+	return err;
+}
+
+/**
+ * build_phy_abilities_req - build req with get_phy_ability opcode
+ * @req: pointer to the cmd req structure
+ **/
+static void build_phy_abilities_req(struct mbx_fw_cmd_req *req)
+{
+	req->flags = 0;
+	req->opcode = cpu_to_le16(GET_PHY_ABILITY);
+	req->datalen = cpu_to_le16(MBX_REQ_HDR_LEN);
+	req->reply_lo = 0;
+	req->reply_hi = 0;
+}
+
+/**
+ * mucse_fw_get_capability - Get hw abilities from fw
+ * @hw: pointer to the HW structure
+ * @abil: pointer to the hw_abilities structure
+ *
+ * mucse_fw_get_capability tries to get hw abilities from
+ * hw.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_fw_get_capability(struct mucse_hw *hw,
+				   struct hw_abilities *abil)
+{
+	struct mbx_fw_cmd_reply reply = {};
+	struct mbx_fw_cmd_req req = {};
+	int err;
+
+	build_phy_abilities_req(&req);
+	err = mucse_fw_send_cmd_wait(hw, &req, &reply);
+	if (!err)
+		memcpy(abil, &reply.hw_abilities, sizeof(*abil));
+	return err;
+}
+
+/**
+ * mucse_mbx_get_capability - Get hw abilities from fw
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_get_capability tries to get capabities from
+ * hw. Many retrys will do if it is failed.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_get_capability(struct mucse_hw *hw)
+{
+	struct hw_abilities ability = {};
+	int try_cnt = 3;
+	int err;
+	/* It is called once in probe, if failed nothing
+	 * (register network) todo. Try more times to get driver
+	 * and firmware in sync.
+	 */
+	do {
+		err = mucse_fw_get_capability(hw, &ability);
+		if (err)
+			continue;
+		break;
+	} while (try_cnt--);
+
+	if (!err)
+		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
+	return err;
+}
+
+/**
+ * build_ifinsmod - build req with insmod opcode
+ * @req: pointer to the cmd req structure
+ * @is_insmod: true for insmod, false for rmmod
+ **/
+static void build_ifinsmod(struct mbx_fw_cmd_req *req,
+			   bool is_insmod)
+{
+	req->flags = 0;
+	req->opcode = cpu_to_le16(DRIVER_INSMOD);
+	req->datalen = cpu_to_le16(sizeof(req->ifinsmod) +
+				   MBX_REQ_HDR_LEN);
+	req->reply_lo = 0;
+	req->reply_hi = 0;
+#define FIXED_VERSION 0xFFFFFFFF
+	req->ifinsmod.version = cpu_to_le32(FIXED_VERSION);
+	if (is_insmod)
+		req->ifinsmod.status = cpu_to_le32(1);
+	else
+		req->ifinsmod.status = cpu_to_le32(0);
+}
+
+/**
+ * mucse_mbx_ifinsmod - Echo driver insmod status to hw
+ * @hw: pointer to the HW structure
+ * @is_insmod: true for insmod, false for rmmod
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_ifinsmod(struct mucse_hw *hw, bool is_insmod)
+{
+	struct mbx_fw_cmd_req req = {};
+	int len;
+	int err;
+
+	build_ifinsmod(&req, is_insmod);
+	len = le16_to_cpu(req.datalen);
+	err = mutex_lock_interruptible(&hw->mbx.lock);
+	if (err)
+		return err;
+
+	if (is_insmod) {
+		err = mucse_write_posted_mbx(hw, (u32 *)&req,
+					     len);
+	} else {
+		err = mucse_write_mbx_pf(hw, (u32 *)&req,
+					 len);
+	}
+
+	mutex_unlock(&hw->mbx.lock);
+	return err;
+}
+
+/**
+ * build_reset_phy_req - build req with reset_phy opcode
+ * @req: pointer to the cmd req structure
+ **/
+static void build_reset_phy_req(struct mbx_fw_cmd_req *req)
+{
+	req->flags = 0;
+	req->opcode = cpu_to_le16(RESET_PHY);
+	req->datalen = cpu_to_le16(MBX_REQ_HDR_LEN);
+	req->reply_lo = 0;
+	req->reply_hi = 0;
+}
+
+/**
+ * mucse_mbx_fw_reset_phy - Posts a mbx req to reset hw
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_fw_reset_phy posts a mbx req to firmware to reset hw.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_fw_reset_phy(struct mucse_hw *hw)
+{
+	struct mbx_fw_cmd_reply reply = {};
+	struct mbx_fw_cmd_req req = {};
+
+	build_reset_phy_req(&req);
+	return mucse_fw_send_cmd_wait(hw, &req, &reply);
+}
+
+/**
+ * build_get_macaddress_req - build req with get_mac opcode
+ * @req: pointer to the cmd req structure
+ * @port_mask: port valid for this cmd
+ * @pfvfnum: pfvfnum for this cmd
+ **/
+static void build_get_macaddress_req(struct mbx_fw_cmd_req *req,
+				     int port_mask, int pfvfnum)
+{
+	req->flags = 0;
+	req->opcode = cpu_to_le16(GET_MAC_ADDRES);
+	req->datalen = cpu_to_le16(sizeof(req->get_mac_addr) +
+				   MBX_REQ_HDR_LEN);
+	req->reply_lo = 0;
+	req->reply_hi = 0;
+	req->get_mac_addr.port_mask = cpu_to_le32(port_mask);
+	req->get_mac_addr.pfvf_num = cpu_to_le32(pfvfnum);
+}
+
+/**
+ * mucse_fw_get_macaddr - Posts a mbx req to request macaddr
+ * @hw: pointer to the HW structure
+ * @pfvfnum: index of pf/vf num
+ * @mac_addr: pointer to store mac_addr
+ * @port: port index
+ *
+ * mucse_fw_get_macaddr posts a mbx req to firmware to get mac_addr.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_fw_get_macaddr(struct mucse_hw *hw, int pfvfnum,
+			 u8 *mac_addr,
+			 int port)
+{
+	struct mbx_fw_cmd_reply reply = {};
+	struct mbx_fw_cmd_req req = {};
+	int err;
+
+	build_get_macaddress_req(&req, BIT(port), pfvfnum);
+	err = mucse_fw_send_cmd_wait(hw, &req, &reply);
+	if (err)
+		return err;
+	if (le32_to_cpu(reply.mac_addr.ports) & BIT(port))
+		memcpy(mac_addr, reply.mac_addr.addrs[port].mac, ETH_ALEN);
+	else
+		return -ENODATA;
+	return 0;
+}
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h
new file mode 100644
index 000000000000..3efd23ba1aa0
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h
@@ -0,0 +1,126 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#ifndef _RNPGBE_MBX_FW_H
+#define _RNPGBE_MBX_FW_H
+
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/wait.h>
+
+#include "rnpgbe.h"
+
+#define MBX_REQ_HDR_LEN 24
+
+enum MUCSE_FW_CMD {
+	GET_PHY_ABILITY = 0x0601,
+	GET_MAC_ADDRES = 0x0602,
+	RESET_PHY = 0x0603,
+	DRIVER_INSMOD = 0x0803,
+};
+
+struct hw_abilities {
+	u8 link_stat;
+	u8 port_mask;
+	__le32 speed;
+	__le16 phy_type;
+	__le16 nic_mode;
+	__le16 pfnum;
+	__le32 fw_version;
+	__le32 axi_mhz;
+	union {
+		u8 port_id[4];
+		__le32 port_ids;
+	};
+	__le32 bd_uid;
+	__le32 phy_id;
+	__le32 wol_status;
+	union {
+		__le32 ext_ability;
+		struct {
+			u32 valid : 1;
+			u32 wol_en : 1;
+			u32 pci_preset_runtime_en : 1;
+			u32 smbus_en : 1;
+			u32 ncsi_en : 1;
+			u32 rpu_en : 1;
+			u32 v2 : 1;
+			u32 pxe_en : 1;
+			u32 mctp_en : 1;
+			u32 yt8614 : 1;
+			u32 pci_ext_reset : 1;
+			u32 rpu_availble : 1;
+			u32 fw_lldp_ability : 1;
+			u32 lldp_enabled : 1;
+			u32 only_1g : 1;
+			u32 force_down_en: 1;
+		} e_host;
+	};
+} __packed;
+
+/* FW stores extended ability information in 'ext_ability' as a 32-bit
+ * little-endian value. To make these flags easily accessible in the
+ * kernel (via named 'bitfields' instead of raw bitmask operations),
+ * we use the union's 'e_host' struct, which provides named bits
+ * (e.g., 'wol_en', 'smbus_en')
+ */
+static inline void ability_update_host_endian(struct hw_abilities *abi)
+{
+	u32 host_val = le32_to_cpu(abi->ext_ability);
+
+	abi->e_host = *(typeof(abi->e_host) *)&host_val;
+}
+
+#define FLAGS_DD BIT(0)
+#define FLAGS_ERR BIT(2)
+
+struct mbx_fw_cmd_req {
+	__le16 flags;
+	__le16 opcode;
+	__le16 datalen;
+	__le16 ret_value;
+	__le32 cookie_lo;
+	__le32 cookie_hi;
+	__le32 reply_lo;
+	__le32 reply_hi;
+	union {
+		u8 data[32];
+		struct {
+			__le32 version;
+			__le32 status;
+		} ifinsmod;
+		struct {
+			__le32 port_mask;
+			__le32 pfvf_num;
+		} get_mac_addr;
+	};
+} __packed;
+
+struct mbx_fw_cmd_reply {
+	__le16 flags;
+	__le16 opcode;
+	__le16 error_code;
+	__le16 datalen;
+	__le32 cookie_lo;
+	__le32 cookie_hi;
+	union {
+		u8 data[40];
+		struct mac_addr {
+			__le32 ports;
+			struct _addr {
+				/* for macaddr:01:02:03:04:05:06
+				 * mac-hi=0x01020304 mac-lo=0x05060000
+				 */
+				u8 mac[8];
+			} addrs[4];
+		} mac_addr;
+		struct hw_abilities hw_abilities;
+	};
+} __packed;
+
+int mucse_mbx_get_capability(struct mucse_hw *hw);
+int mucse_mbx_ifinsmod(struct mucse_hw *hw, bool status);
+int mucse_mbx_fw_reset_phy(struct mucse_hw *hw);
+int mucse_fw_get_macaddr(struct mucse_hw *hw, int pfvfnum,
+			 u8 *mac_addr, int port);
+#endif /* _RNPGBE_MBX_FW_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
                   ` (3 preceding siblings ...)
  2025-08-28  2:55 ` [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
@ 2025-08-28  2:55 ` Dong Yibo
  2025-08-28 13:20   ` Andrew Lunn
  2025-08-28  5:22 ` [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE MD Danish Anwar
  5 siblings, 1 reply; 24+ messages in thread
From: Dong Yibo @ 2025-08-28  2:55 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening, dong100

Initialize get mac from hw, register the netdev.

Signed-off-by: Dong Yibo <dong100@mucse.com>
---
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h    | 23 ++++++
 .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c   | 82 +++++++++++++++++++
 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h |  2 +
 .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c   | 75 +++++++++++++++++
 4 files changed, 182 insertions(+)

diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
index 4d2cca59fb23..33ee6f05e9b8 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;
@@ -24,6 +25,10 @@ enum rnpgbe_hw_type {
 	rnpgbe_hw_unknown
 };
 
+struct mucse_dma_info {
+	void __iomem *dma_base_addr;
+};
+
 struct mucse_mbx_stats {
 	u32 msgs_tx;
 	u32 msgs_rx;
@@ -47,12 +52,27 @@ struct mucse_mbx_info {
 	u32 fw2pf_mbox_vec;
 };
 
+struct mucse_hw;
+
+struct mucse_hw_operations {
+	int (*reset_hw)(struct mucse_hw *hw);
+	void (*driver_status)(struct mucse_hw *hw, bool enable, int mode);
+};
+
+enum {
+	mucse_driver_insmod,
+};
+
 struct mucse_hw {
 	void __iomem *hw_addr;
 	struct pci_dev *pdev;
 	enum rnpgbe_hw_type hw_type;
 	u8 pfvfnum;
+	const struct mucse_hw_operations *ops;
+	struct mucse_dma_info dma;
 	struct mucse_mbx_info mbx;
+	int port;
+	u8 perm_addr[ETH_ALEN];
 };
 
 struct mucse {
@@ -72,4 +92,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 rnpgbe_dma_wr32(dma, reg, val) \
+	writel((val), (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 f38daef752a3..f25dbc0dab5a 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
@@ -1,11 +1,87 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright(c) 2020 - 2025 Mucse Corporation. */
 
+#include <linux/pci.h>
 #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.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int rnpgbe_get_permanent_mac(struct mucse_hw *hw,
+				    u8 *mac_addr)
+{
+	struct device *dev = &hw->pdev->dev;
+	int err;
+
+	err = mucse_fw_get_macaddr(hw, hw->pfvfnum, mac_addr, hw->port);
+	if (err) {
+		dev_err(dev, "Failed to get MAC from FW %d\n", err);
+		return err;
+	}
+
+	if (!is_valid_ether_addr(mac_addr)) {
+		dev_err(dev, "Failed to get valid MAC from FW\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * 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 errno on failure
+ **/
+static int rnpgbe_reset_hw_ops(struct mucse_hw *hw)
+{
+	struct mucse_dma_info *dma = &hw->dma;
+	int err;
+
+	rnpgbe_dma_wr32(dma, RNPGBE_DMA_AXI_EN, 0);
+	err = mucse_mbx_fw_reset_phy(hw);
+	if (err)
+		return err;
+	return rnpgbe_get_permanent_mac(hw, hw->perm_addr);
+}
+
+/**
+ * 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
@@ -13,10 +89,16 @@
  **/
 static void rnpgbe_init_common(struct mucse_hw *hw)
 {
+	struct mucse_dma_info *dma = &hw->dma;
 	struct mucse_mbx_info *mbx = &hw->mbx;
 
+	dma->dma_base_addr = hw->hw_addr;
+
 	mbx->pf2fw_mbox_ctrl = GBE_PF2FW_MBX_MASK_OFFSET;
 	mbx->fw_pf_mbox_mask = GBE_FWPF_MBX_MASK;
+
+	hw->ops = &rnpgbe_hw_ops;
+	hw->port = 0;
 }
 
 /**
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
index 746dca78f1df..0ab2c328c9e9 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
@@ -11,6 +11,8 @@
 #define GBE_FWPF_MBX_MASK 0x5700
 #define N210_FW2PF_MBX_VEC_OFFSET 0x29400
 #define N210_FWPF_SHM_BASE_OFFSET 0x2d900
+/**************** DMA Registers ****************************/
+#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 25b7119d6ecb..82805b61cd07 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -9,6 +9,8 @@
 
 #include "rnpgbe.h"
 #include "rnpgbe_hw.h"
+#include "rnpgbe_mbx.h"
+#include "rnpgbe_mbx_fw.h"
 
 static const char rnpgbe_driver_name[] = "rnpgbe";
 static const struct rnpgbe_info *rnpgbe_info_tbl[] = {
@@ -35,6 +37,55 @@ 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);
+	netdev->stats.tx_dropped++;
+	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
@@ -78,6 +129,27 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
 
 	hw->hw_addr = hw_addr;
 	info->init(hw);
+	mucse_init_mbx_params_pf(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);
+	err = register_netdev(netdev);
+	if (err)
+		goto err_free_net;
 	return 0;
 
 err_free_net:
@@ -145,12 +217,15 @@ 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;
+	unregister_netdev(netdev);
 	mucse->netdev = NULL;
+	hw->ops->driver_status(hw, false, mucse_driver_insmod);
 	free_netdev(netdev);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE
  2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
                   ` (4 preceding siblings ...)
  2025-08-28  2:55 ` [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev Dong Yibo
@ 2025-08-28  5:22 ` MD Danish Anwar
  2025-08-28  5:36   ` Yibo Dong
  5 siblings, 1 reply; 24+ messages in thread
From: MD Danish Anwar @ 2025-08-28  5:22 UTC (permalink / raw)
  To: Dong Yibo, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
	corbet, gur.stavi, maddy, mpe, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko
  Cc: netdev, linux-doc, linux-kernel, linux-hardening

Hi Dong Yibo,

On 28/08/25 8:25 am, Dong Yibo wrote:
> Hi maintainers,
> 
> This patch series is v9 to introduce support for MUCSE N500/N210 1Gbps
> Ethernet controllers. I divide codes into multiple series, this is the
> first one which only register netdev without true tx/rx functions.
> 
> Changelog:
> v8 -> v9:
> 1. update function description format '@return' to 'Return' 
> 2. update 'negative on failure' to 'negative errno on failure'
> 
> links:
> v8: https://lore.kernel.org/netdev/20250827034509.501980-1-dong100@mucse.com/
> v7: https://lore.kernel.org/netdev/20250822023453.1910972-1-dong100@mucse.com
> v6: https://lore.kernel.org/netdev/20250820092154.1643120-1-dong100@mucse.com/
> v5: https://lore.kernel.org/netdev/20250818112856.1446278-1-dong100@mucse.com/
> v4: https://lore.kernel.org/netdev/20250814073855.1060601-1-dong100@mucse.com/
> v3: https://lore.kernel.org/netdev/20250812093937.882045-1-dong100@mucse.com/
> v2: https://lore.kernel.org/netdev/20250721113238.18615-1-dong100@mucse.com/
> v1: https://lore.kernel.org/netdev/20250703014859.210110-1-dong100@mucse.com/

Please wait for at least 24 hours before posting a new version. You
posted v8 yesterday and most folks won't have noticed v8 by now or they
maybe looking to give comments on v8. But before they could do that you
posted v9.

Keep good amount of gaps between the series so that more folks can look
at it. 24 hours is the minimum.

-- 
Thanks and Regards,
Danish


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE
  2025-08-28  5:22 ` [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE MD Danish Anwar
@ 2025-08-28  5:36   ` Yibo Dong
  2025-08-28  6:47     ` MD Danish Anwar
  2025-08-28 12:57     ` Andrew Lunn
  0 siblings, 2 replies; 24+ messages in thread
From: Yibo Dong @ 2025-08-28  5:36 UTC (permalink / raw)
  To: MD Danish Anwar
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, lee, gongfan1, lorenzo, geert+renesas,
	Parthiban.Veerasooran, lukas.bulwahn, alexanderduyck,
	richardcochran, kees, gustavoars, rdunlap, vadim.fedorenko,
	netdev, linux-doc, linux-kernel, linux-hardening

On Thu, Aug 28, 2025 at 10:52:21AM +0530, MD Danish Anwar wrote:
> Hi Dong Yibo,
> 
> On 28/08/25 8:25 am, Dong Yibo wrote:
> > Hi maintainers,
> > 
> > This patch series is v9 to introduce support for MUCSE N500/N210 1Gbps
> > Ethernet controllers. I divide codes into multiple series, this is the
> > first one which only register netdev without true tx/rx functions.
> > 
> > Changelog:
> > v8 -> v9:
> > 1. update function description format '@return' to 'Return' 
> > 2. update 'negative on failure' to 'negative errno on failure'
> > 
> > links:
> > v8: https://lore.kernel.org/netdev/20250827034509.501980-1-dong100@mucse.com/
> > v7: https://lore.kernel.org/netdev/20250822023453.1910972-1-dong100@mucse.com
> > v6: https://lore.kernel.org/netdev/20250820092154.1643120-1-dong100@mucse.com/
> > v5: https://lore.kernel.org/netdev/20250818112856.1446278-1-dong100@mucse.com/
> > v4: https://lore.kernel.org/netdev/20250814073855.1060601-1-dong100@mucse.com/
> > v3: https://lore.kernel.org/netdev/20250812093937.882045-1-dong100@mucse.com/
> > v2: https://lore.kernel.org/netdev/20250721113238.18615-1-dong100@mucse.com/
> > v1: https://lore.kernel.org/netdev/20250703014859.210110-1-dong100@mucse.com/
> 
> Please wait for at least 24 hours before posting a new version. You
> posted v8 yesterday and most folks won't have noticed v8 by now or they
> maybe looking to give comments on v8. But before they could do that you
> posted v9.
> 
> Keep good amount of gaps between the series so that more folks can look
> at it. 24 hours is the minimum.
> 
> -- 
> Thanks and Regards,
> Danish
> 
> 

Got it, I found the v8 pathes state in websit:
https://patchwork.kernel.org/project/netdevbpf/list/
It is 'Changes Requested'. 
I mistakenly thought that a new version needed to be sent. I will wait
more time in the next time.

Thanks for you feedback.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE
  2025-08-28  5:36   ` Yibo Dong
@ 2025-08-28  6:47     ` MD Danish Anwar
  2025-08-28 12:57     ` Andrew Lunn
  1 sibling, 0 replies; 24+ messages in thread
From: MD Danish Anwar @ 2025-08-28  6:47 UTC (permalink / raw)
  To: Yibo Dong
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, lee, gongfan1, lorenzo, geert+renesas,
	Parthiban.Veerasooran, lukas.bulwahn, alexanderduyck,
	richardcochran, kees, gustavoars, rdunlap, vadim.fedorenko,
	netdev, linux-doc, linux-kernel, linux-hardening



On 28/08/25 11:06 am, Yibo Dong wrote:
> On Thu, Aug 28, 2025 at 10:52:21AM +0530, MD Danish Anwar wrote:
>> Hi Dong Yibo,
>>
>> On 28/08/25 8:25 am, Dong Yibo wrote:
>>> Hi maintainers,
>>>
>>> This patch series is v9 to introduce support for MUCSE N500/N210 1Gbps
>>> Ethernet controllers. I divide codes into multiple series, this is the
>>> first one which only register netdev without true tx/rx functions.
>>>
>>> Changelog:
>>> v8 -> v9:
>>> 1. update function description format '@return' to 'Return' 
>>> 2. update 'negative on failure' to 'negative errno on failure'
>>>
>>> links:
>>> v8: https://lore.kernel.org/netdev/20250827034509.501980-1-dong100@mucse.com/
>>> v7: https://lore.kernel.org/netdev/20250822023453.1910972-1-dong100@mucse.com
>>> v6: https://lore.kernel.org/netdev/20250820092154.1643120-1-dong100@mucse.com/
>>> v5: https://lore.kernel.org/netdev/20250818112856.1446278-1-dong100@mucse.com/
>>> v4: https://lore.kernel.org/netdev/20250814073855.1060601-1-dong100@mucse.com/
>>> v3: https://lore.kernel.org/netdev/20250812093937.882045-1-dong100@mucse.com/
>>> v2: https://lore.kernel.org/netdev/20250721113238.18615-1-dong100@mucse.com/
>>> v1: https://lore.kernel.org/netdev/20250703014859.210110-1-dong100@mucse.com/
>>
>> Please wait for at least 24 hours before posting a new version. You
>> posted v8 yesterday and most folks won't have noticed v8 by now or they
>> maybe looking to give comments on v8. But before they could do that you
>> posted v9.
>>
>> Keep good amount of gaps between the series so that more folks can look
>> at it. 24 hours is the minimum.
>>
>> -- 
>> Thanks and Regards,
>> Danish
>>
>>
> 
> Got it, I found the v8 pathes state in websit:
> https://patchwork.kernel.org/project/netdevbpf/list/
> It is 'Changes Requested'. 
> I mistakenly thought that a new version needed to be sent. I will wait

That's correct. 'Changes Requested' means that version will no longer be
accepted and you have to send a newer one. But that doesn't mean you
have to send it immediately.

https://www.kernel.org/doc/html/v6.1/process/maintainer-netdev.html#i-have-received-review-feedback-when-should-i-post-a-revised-version-of-the-patches


> more time in the next time.
> 
> Thanks for you feedback.

-- 
Thanks and Regards,
Danish


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe
  2025-08-28  2:55 ` [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
@ 2025-08-28 12:51   ` Andrew Lunn
  2025-09-01  8:20     ` Yibo Dong
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Lunn @ 2025-08-28 12:51 UTC (permalink / raw)
  To: Dong Yibo
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Thu, Aug 28, 2025 at 10:55:43AM +0800, Dong Yibo wrote:
> Add build options and doc for mucse.
> Initialize pci device access for MUCSE devices.
> 
> Signed-off-by: Dong Yibo <dong100@mucse.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE
  2025-08-28  5:36   ` Yibo Dong
  2025-08-28  6:47     ` MD Danish Anwar
@ 2025-08-28 12:57     ` Andrew Lunn
  1 sibling, 0 replies; 24+ messages in thread
From: Andrew Lunn @ 2025-08-28 12:57 UTC (permalink / raw)
  To: Yibo Dong
  Cc: MD Danish Anwar, andrew+netdev, davem, edumazet, kuba, pabeni,
	horms, corbet, gur.stavi, maddy, mpe, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> Got it, I found the v8 pathes state in websit:
> https://patchwork.kernel.org/project/netdevbpf/list/
> It is 'Changes Requested'. 
> I mistakenly thought that a new version needed to be sent. I will wait
> more time in the next time.

We try to review patches within 3 working days. Depending on reviewer
work load, you might get comments really fast, or it might take 3
days. The 24 hour requirement between new spins is a compromise.  But
you should also listen to your audience. If there have been active
reviews and they have not commented yet, maybe wait the full three
days.

	Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-28  2:55 ` [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
@ 2025-08-28 13:09   ` Andrew Lunn
  2025-08-29  2:12     ` Yibo Dong
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Lunn @ 2025-08-28 13:09 UTC (permalink / raw)
  To: Dong Yibo
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> +/**
> + * mucse_mbx_get_capability - Get hw abilities from fw
> + * @hw: pointer to the HW structure
> + *
> + * mucse_mbx_get_capability tries to get capabities from
> + * hw. Many retrys will do if it is failed.
> + *
> + * Return: 0 on success, negative errno on failure
> + **/
> +int mucse_mbx_get_capability(struct mucse_hw *hw)
> +{
> +	struct hw_abilities ability = {};
> +	int try_cnt = 3;
> +	int err;
> +	/* It is called once in probe, if failed nothing
> +	 * (register network) todo. Try more times to get driver
> +	 * and firmware in sync.
> +	 */
> +	do {
> +		err = mucse_fw_get_capability(hw, &ability);
> +		if (err)
> +			continue;
> +		break;
> +	} while (try_cnt--);
> +
> +	if (!err)
> +		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
> +	return err;
> +}

I still think this should be a dedicated function to get the MAC
driver and firmware in sync, using a NOP or version request to the
firmware. The name mucse_mbx_get_capability() does not indicate this
function is special in any way, which is it.

> +/**
> + * build_ifinsmod - build req with insmod opcode
> + * @req: pointer to the cmd req structure
> + * @is_insmod: true for insmod, false for rmmod
> + **/
> +static void build_ifinsmod(struct mbx_fw_cmd_req *req,
> +			   bool is_insmod)
> +{
> +	req->flags = 0;
> +	req->opcode = cpu_to_le16(DRIVER_INSMOD);
> +	req->datalen = cpu_to_le16(sizeof(req->ifinsmod) +
> +				   MBX_REQ_HDR_LEN);
> +	req->reply_lo = 0;
> +	req->reply_hi = 0;
> +#define FIXED_VERSION 0xFFFFFFFF
> +	req->ifinsmod.version = cpu_to_le32(FIXED_VERSION);
> +	if (is_insmod)
> +		req->ifinsmod.status = cpu_to_le32(1);
> +	else
> +		req->ifinsmod.status = cpu_to_le32(0);
> +}

Why does the firmware care? What does the firmware do when there is no
kernel driver? How does it behaviour change when the driver loads?

Please try to ensure comment say why you are doing something, not what
you are doing.


    Andrew

---
pw-bot: cr

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev
  2025-08-28  2:55 ` [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev Dong Yibo
@ 2025-08-28 13:20   ` Andrew Lunn
  2025-08-29  2:36     ` Yibo Dong
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Lunn @ 2025-08-28 13:20 UTC (permalink / raw)
  To: Dong Yibo
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> +/**
> + * 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 errno on failure
> + **/
> +static int rnpgbe_reset_hw_ops(struct mucse_hw *hw)
> +{
> +	struct mucse_dma_info *dma = &hw->dma;
> +	int err;
> +
> +	rnpgbe_dma_wr32(dma, RNPGBE_DMA_AXI_EN, 0);
> +	err = mucse_mbx_fw_reset_phy(hw);
> +	if (err)
> +		return err;
> +	return rnpgbe_get_permanent_mac(hw, hw->perm_addr);

Why is a function named rnpgbe_reset_hw_ops() getting the permanent
MAC address? Reset should not have anything to do with MAC address.

If the MAC address is not valid, you normally use a random MAC
address. But you cannot easily differentiate between the reset failed,
the reset got ^C, and the MAC address was not valid.

> +/**
> + * 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);

Back to the ^C handling. This could be interrupted before the firmware
is told the driver is loaded. That EINTR is thrown away here, so the
driver thinks everything is O.K, but the firmware still thinks there
is no MAC driver. What happens then?

And this is the same problem i pointed out before, you ignore EINTR in
a void function. Rather than fix one instance, you should of reviewed
the whole driver and fixed them all. You cannot expect the Reviewers
to do this for you.

    Andrew

---
pw-bot: cr

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-28 13:09   ` Andrew Lunn
@ 2025-08-29  2:12     ` Yibo Dong
  2025-08-29 19:48       ` Andrew Lunn
  0 siblings, 1 reply; 24+ messages in thread
From: Yibo Dong @ 2025-08-29  2:12 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Thu, Aug 28, 2025 at 03:09:51PM +0200, Andrew Lunn wrote:
> > +/**
> > + * mucse_mbx_get_capability - Get hw abilities from fw
> > + * @hw: pointer to the HW structure
> > + *
> > + * mucse_mbx_get_capability tries to get capabities from
> > + * hw. Many retrys will do if it is failed.
> > + *
> > + * Return: 0 on success, negative errno on failure
> > + **/
> > +int mucse_mbx_get_capability(struct mucse_hw *hw)
> > +{
> > +	struct hw_abilities ability = {};
> > +	int try_cnt = 3;
> > +	int err;
> > +	/* It is called once in probe, if failed nothing
> > +	 * (register network) todo. Try more times to get driver
> > +	 * and firmware in sync.
> > +	 */
> > +	do {
> > +		err = mucse_fw_get_capability(hw, &ability);
> > +		if (err)
> > +			continue;
> > +		break;
> > +	} while (try_cnt--);
> > +
> > +	if (!err)
> > +		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
> > +	return err;
> > +}
> 
> I still think this should be a dedicated function to get the MAC
> driver and firmware in sync, using a NOP or version request to the
> firmware. The name mucse_mbx_get_capability() does not indicate this
> function is special in any way, which is it.
> 

Maybe I should rename it like this?

/**
 * mucse_mbx_sync_fw_by_get_capability - Try to sync driver and fw
 * @hw: pointer to the HW structure
 *
 * mucse_mbx_sync_fw_by_get_capability tries to sync driver and fw
 * by get capabitiy mbx cmd. Many retrys will do if it is failed.
 *
 * Return: 0 on success, negative errno on failure
 **/
int mucse_mbx_sync_fw_by_get_capability(struct mucse_hw *hw)
{
	struct hw_abilities ability = {};
	int try_cnt = 3;
	int err;
	/* It is called once in probe, if failed nothing
	 * (register network) todo. Try more times to get driver
	 * and firmware in sync.
	 */
	do {
		err = mucse_fw_get_capability(hw, &ability);
		if (err)
			continue;
		break;
	} while (try_cnt--);

	if (!err)
		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
	return err;
}

> > +/**
> > + * build_ifinsmod - build req with insmod opcode
> > + * @req: pointer to the cmd req structure
> > + * @is_insmod: true for insmod, false for rmmod
> > + **/
> > +static void build_ifinsmod(struct mbx_fw_cmd_req *req,
> > +			   bool is_insmod)
> > +{
> > +	req->flags = 0;
> > +	req->opcode = cpu_to_le16(DRIVER_INSMOD);
> > +	req->datalen = cpu_to_le16(sizeof(req->ifinsmod) +
> > +				   MBX_REQ_HDR_LEN);
> > +	req->reply_lo = 0;
> > +	req->reply_hi = 0;
> > +#define FIXED_VERSION 0xFFFFFFFF
> > +	req->ifinsmod.version = cpu_to_le32(FIXED_VERSION);
> > +	if (is_insmod)
> > +		req->ifinsmod.status = cpu_to_le32(1);
> > +	else
> > +		req->ifinsmod.status = cpu_to_le32(0);
> > +}
> 
> Why does the firmware care? What does the firmware do when there is no
> kernel driver? How does it behaviour change when the driver loads?
> 

fw reduce working frequency to save power if no driver is probed to this
chip. And fw change frequency to normal after recieve insmod mbx cmd.

Maybe I should add the comment to func "mucse_mbx_ifinsmod"? 
/**
 * mucse_mbx_ifinsmod - Echo driver insmod status to fw
 * @hw: pointer to the HW structure
 * @is_insmod: true for insmod, false for rmmod
 *
 * mucse_mbx_ifinsmod echo driver insmod status to fw. fw changes working
 * frequency to normal after recieve insmod status, and reduce working
 * frequency if no driver is probed.
 *
 * Return: 0 on success, negative errno on failure
 **/
int mucse_mbx_ifinsmod(struct mucse_hw *hw, bool is_insmod)
{


}

> Please try to ensure comment say why you are doing something, not what
> you are doing.
> 
> 
>     Andrew
> 
> ---
> pw-bot: cr
> 

Thanks for your feedback.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev
  2025-08-28 13:20   ` Andrew Lunn
@ 2025-08-29  2:36     ` Yibo Dong
  2025-08-29 19:51       ` Andrew Lunn
  0 siblings, 1 reply; 24+ messages in thread
From: Yibo Dong @ 2025-08-29  2:36 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Thu, Aug 28, 2025 at 03:20:04PM +0200, Andrew Lunn wrote:
> > +/**
> > + * 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 errno on failure
> > + **/
> > +static int rnpgbe_reset_hw_ops(struct mucse_hw *hw)
> > +{
> > +	struct mucse_dma_info *dma = &hw->dma;
> > +	int err;
> > +
> > +	rnpgbe_dma_wr32(dma, RNPGBE_DMA_AXI_EN, 0);
> > +	err = mucse_mbx_fw_reset_phy(hw);
> > +	if (err)
> > +		return err;
> > +	return rnpgbe_get_permanent_mac(hw, hw->perm_addr);
> 
> Why is a function named rnpgbe_reset_hw_ops() getting the permanent
> MAC address? Reset should not have anything to do with MAC address.
> 
> If the MAC address is not valid, you normally use a random MAC
> address. But you cannot easily differentiate between the reset failed,
> the reset got ^C, and the MAC address was not valid.
> 

Ok, I will remove call 'rnpgbe_get_permanent_mac' in function
'rnpgbe_reset_hw_ops'. And call it in probe.

> > +/**
> > + * 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);
> 
> Back to the ^C handling. This could be interrupted before the firmware
> is told the driver is loaded. That EINTR is thrown away here, so the
> driver thinks everything is O.K, but the firmware still thinks there
> is no MAC driver. What happens then?
> 

The performance will be very poor since low working frequency,
that is not we want.

> And this is the same problem i pointed out before, you ignore EINTR in
> a void function. Rather than fix one instance, you should of reviewed
> the whole driver and fixed them all. You cannot expect the Reviewers
> to do this for you.

I see, I will change 'void' to 'int' in order to handle err, and try to check
other functions.

> 
>     Andrew
> 
> ---
> pw-bot: cr
> 

Thanks for your feedback.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-29  2:12     ` Yibo Dong
@ 2025-08-29 19:48       ` Andrew Lunn
  2025-09-01  2:08         ` Yibo Dong
  2025-09-01  7:27         ` Yibo Dong
  0 siblings, 2 replies; 24+ messages in thread
From: Andrew Lunn @ 2025-08-29 19:48 UTC (permalink / raw)
  To: Yibo Dong
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> Maybe I should rename it like this?
> 
> /**
>  * mucse_mbx_sync_fw_by_get_capability - Try to sync driver and fw
>  * @hw: pointer to the HW structure
>  *
>  * mucse_mbx_sync_fw_by_get_capability tries to sync driver and fw
>  * by get capabitiy mbx cmd. Many retrys will do if it is failed.
>  *
>  * Return: 0 on success, negative errno on failure
>  **/
> int mucse_mbx_sync_fw_by_get_capability(struct mucse_hw *hw)
> {
> 	struct hw_abilities ability = {};
> 	int try_cnt = 3;
> 	int err;
> 	/* It is called once in probe, if failed nothing
> 	 * (register network) todo. Try more times to get driver
> 	 * and firmware in sync.
> 	 */
> 	do {
> 		err = mucse_fw_get_capability(hw, &ability);
> 		if (err)
> 			continue;
> 		break;
> 	} while (try_cnt--);
> 
> 	if (!err)
> 		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
> 	return err;
> }

Why so much resistance to a NOP or firmware version, something which
is not that important? Why do you want to combine getting sync and
getting the capabilities?

> fw reduce working frequency to save power if no driver is probed to this
> chip. And fw change frequency to normal after recieve insmod mbx cmd.

So why is this called ifinsmod? Why not power save? If you had called
this power save, i would not of questioned what this does, it is
pretty obvious, and other drivers probably have something
similar. Some drivers probably have something like open/close, which
do similar things. Again, i would not of asked. By not following what
other drivers are doing, you just cause problems for everybody.

So please give this a new name. Not just the function, but also the
name of the firmware op and everything else to do with this. The
firmware does not care what the driver calls it, all it sees is a
binary message format, no names.

Please also go through your driver and look at all the other names. Do
they match what other drivers use. If not, you might want to rename
them, in order to get your code merged with a lot less back and forth
with reviewers.

	Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev
  2025-08-29  2:36     ` Yibo Dong
@ 2025-08-29 19:51       ` Andrew Lunn
  2025-09-01  2:18         ` Yibo Dong
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Lunn @ 2025-08-29 19:51 UTC (permalink / raw)
  To: Yibo Dong
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> > Back to the ^C handling. This could be interrupted before the firmware
> > is told the driver is loaded. That EINTR is thrown away here, so the
> > driver thinks everything is O.K, but the firmware still thinks there
> > is no MAC driver. What happens then?
> > 
> 
> The performance will be very poor since low working frequency,
> that is not we want.
> 
> > And this is the same problem i pointed out before, you ignore EINTR in
> > a void function. Rather than fix one instance, you should of reviewed
> > the whole driver and fixed them all. You cannot expect the Reviewers
> > to do this for you.
> 
> I see, I will change 'void' to 'int' in order to handle err, and try to check
> other functions.

Also, consider, do you really want ^C handling? How many other drivers
do this? How much time and effort is it going to take you to fix up
all the calls which might return -EINTR and your code is currently
broken?

	Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-29 19:48       ` Andrew Lunn
@ 2025-09-01  2:08         ` Yibo Dong
  2025-09-01  7:27         ` Yibo Dong
  1 sibling, 0 replies; 24+ messages in thread
From: Yibo Dong @ 2025-09-01  2:08 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Fri, Aug 29, 2025 at 09:48:12PM +0200, Andrew Lunn wrote:
> > Maybe I should rename it like this?
> > 
> > /**
> >  * mucse_mbx_sync_fw_by_get_capability - Try to sync driver and fw
> >  * @hw: pointer to the HW structure
> >  *
> >  * mucse_mbx_sync_fw_by_get_capability tries to sync driver and fw
> >  * by get capabitiy mbx cmd. Many retrys will do if it is failed.
> >  *
> >  * Return: 0 on success, negative errno on failure
> >  **/
> > int mucse_mbx_sync_fw_by_get_capability(struct mucse_hw *hw)
> > {
> > 	struct hw_abilities ability = {};
> > 	int try_cnt = 3;
> > 	int err;
> > 	/* It is called once in probe, if failed nothing
> > 	 * (register network) todo. Try more times to get driver
> > 	 * and firmware in sync.
> > 	 */
> > 	do {
> > 		err = mucse_fw_get_capability(hw, &ability);
> > 		if (err)
> > 			continue;
> > 		break;
> > 	} while (try_cnt--);
> > 
> > 	if (!err)
> > 		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
> > 	return err;
> > }
> 
> Why so much resistance to a NOP or firmware version, something which
> is not that important? Why do you want to combine getting sync and
> getting the capabilities?
> 

But firmware not offer a NOP command.
(https://lore.kernel.org/netdev/8989E7A85A9468B0+20250825013053.GA2006401@nic-Precision-5820-Tower/) 

I will rename it like 'mucse_mbx_sync_fw', and rename opcode
'GET_PHY_ABILITY = 0x0601' to 'SYNC_FW = 0x0601'.

> > fw reduce working frequency to save power if no driver is probed to this
> > chip. And fw change frequency to normal after recieve insmod mbx cmd.
> 
> So why is this called ifinsmod? Why not power save? If you had called
> this power save, i would not of questioned what this does, it is
> pretty obvious, and other drivers probably have something
> similar. Some drivers probably have something like open/close, which
> do similar things. Again, i would not of asked. By not following what
> other drivers are doing, you just cause problems for everybody.

Sorry for it.

> 
> So please give this a new name. Not just the function, but also the
> name of the firmware op and everything else to do with this. The
> firmware does not care what the driver calls it, all it sees is a
> binary message format, no names.
> 
> Please also go through your driver and look at all the other names. Do
> they match what other drivers use. If not, you might want to rename
> them, in order to get your code merged with a lot less back and forth
> with reviewers.
> 

I see, I will check all names.

> 	Andrew
> 

Thanks for you feedback.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev
  2025-08-29 19:51       ` Andrew Lunn
@ 2025-09-01  2:18         ` Yibo Dong
  0 siblings, 0 replies; 24+ messages in thread
From: Yibo Dong @ 2025-09-01  2:18 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Fri, Aug 29, 2025 at 09:51:57PM +0200, Andrew Lunn wrote:
> > > Back to the ^C handling. This could be interrupted before the firmware
> > > is told the driver is loaded. That EINTR is thrown away here, so the
> > > driver thinks everything is O.K, but the firmware still thinks there
> > > is no MAC driver. What happens then?
> > > 
> > 
> > The performance will be very poor since low working frequency,
> > that is not we want.
> > 
> > > And this is the same problem i pointed out before, you ignore EINTR in
> > > a void function. Rather than fix one instance, you should of reviewed
> > > the whole driver and fixed them all. You cannot expect the Reviewers
> > > to do this for you.
> > 
> > I see, I will change 'void' to 'int' in order to handle err, and try to check
> > other functions.
> 
> Also, consider, do you really want ^C handling? How many other drivers
> do this? How much time and effort is it going to take you to fix up
> all the calls which might return -EINTR and your code is currently
> broken?
> 
> 	Andrew
> 

Originally ^C is designed to handle '/sys/xxx’, and as you said before,
'It is pretty unusual for ethernet drivers to export data in /sys'.
I should use 'metex_lock', not 'mutex_lock_interruptible'.

Thanks for your feedback.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-08-29 19:48       ` Andrew Lunn
  2025-09-01  2:08         ` Yibo Dong
@ 2025-09-01  7:27         ` Yibo Dong
  2025-09-03  0:54           ` Andrew Lunn
  1 sibling, 1 reply; 24+ messages in thread
From: Yibo Dong @ 2025-09-01  7:27 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Fri, Aug 29, 2025 at 09:48:12PM +0200, Andrew Lunn wrote:
> > Maybe I should rename it like this?
> > 
> > /**
> >  * mucse_mbx_sync_fw_by_get_capability - Try to sync driver and fw
> >  * @hw: pointer to the HW structure
> >  *
> >  * mucse_mbx_sync_fw_by_get_capability tries to sync driver and fw
> >  * by get capabitiy mbx cmd. Many retrys will do if it is failed.
> >  *
> >  * Return: 0 on success, negative errno on failure
> >  **/
> > int mucse_mbx_sync_fw_by_get_capability(struct mucse_hw *hw)
> > {
> > 	struct hw_abilities ability = {};
> > 	int try_cnt = 3;
> > 	int err;
> > 	/* It is called once in probe, if failed nothing
> > 	 * (register network) todo. Try more times to get driver
> > 	 * and firmware in sync.
> > 	 */
> > 	do {
> > 		err = mucse_fw_get_capability(hw, &ability);
> > 		if (err)
> > 			continue;
> > 		break;
> > 	} while (try_cnt--);
> > 
> > 	if (!err)
> > 		hw->pfvfnum = le16_to_cpu(ability.pfnum) & GENMASK_U16(7, 0);
> > 	return err;
> > }
> 
> Why so much resistance to a NOP or firmware version, something which
> is not that important? Why do you want to combine getting sync and
> getting the capabilities?
> 
Maybe like this? 
mucse_mbx_sync_fw is called in probe with try_cnt. 
mucse_mbx_get_info is the same as old mucse_mbx_get_capability.
One function one purpose, not combine two.

static int mucse_mbx_get_info(struct mucse_hw *hw)
{
        struct mbx_fw_cmd_reply reply = {};
        struct mbx_fw_cmd_req req = {};
        struct hw_info info = {};
        int err;

        build_get_fw_info_req(&req);
        err = mucse_fw_send_cmd_wait(hw, &req, &reply);
        if (!err) {
                memcpy(&info, &reply.hw_info, sizeof(struct hw_info));
                hw->pfvfnum = le16_to_cpu(info.pfnum) & GENMASK_U16(7, 0);
        }

        return err;
}

/**
 * mucse_mbx_sync_fw - Try to sync with fw
 * @hw: pointer to the HW structure
 *
 * mucse_mbx_sync_fw tries get sync to fw hw.
 * It is only called in probe
 *
 * Return: 0 on success, negative errno on failure
 **/
int mucse_mbx_sync_fw(struct mucse_hw *hw)
{
        int try_cnt = 3;
        int err;

        do {
                err = mucse_mbx_get_info(hw);
                if (err == -ETIMEDOUT)
                        continue;
                break;
        } while (try_cnt--);

        return err;
}


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe
  2025-08-28 12:51   ` Andrew Lunn
@ 2025-09-01  8:20     ` Yibo Dong
  2025-09-01  9:58       ` Vadim Fedorenko
  0 siblings, 1 reply; 24+ messages in thread
From: Yibo Dong @ 2025-09-01  8:20 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

On Thu, Aug 28, 2025 at 02:51:07PM +0200, Andrew Lunn wrote:
> On Thu, Aug 28, 2025 at 10:55:43AM +0800, Dong Yibo wrote:

Hi, Andrew:

> > Add build options and doc for mucse.
> > Initialize pci device access for MUCSE devices.
> > 
> > Signed-off-by: Dong Yibo <dong100@mucse.com>
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 
>     Andrew
> 

Should I add 'Reviewed-by: Andrew Lunn <andrew@lunn.ch>' to commit for
[PATCH 1/5] in the next version?

Thanks for your review.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe
  2025-09-01  8:20     ` Yibo Dong
@ 2025-09-01  9:58       ` Vadim Fedorenko
  2025-09-02  1:31         ` Yibo Dong
  0 siblings, 1 reply; 24+ messages in thread
From: Vadim Fedorenko @ 2025-09-01  9:58 UTC (permalink / raw)
  To: Yibo Dong, Andrew Lunn
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap, netdev,
	linux-doc, linux-kernel, linux-hardening

On 01/09/2025 09:20, Yibo Dong wrote:
> On Thu, Aug 28, 2025 at 02:51:07PM +0200, Andrew Lunn wrote:
>> On Thu, Aug 28, 2025 at 10:55:43AM +0800, Dong Yibo wrote:
> 
> Hi, Andrew:
> 
>>> Add build options and doc for mucse.
>>> Initialize pci device access for MUCSE devices.
>>>
>>> Signed-off-by: Dong Yibo <dong100@mucse.com>
>>
>> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
>>
>>      Andrew
>>
> 
> Should I add 'Reviewed-by: Andrew Lunn <andrew@lunn.ch>' to commit for
> [PATCH 1/5] in the next version?

The general rule is to carry over all the tags if there is no (big)
changes to the code in the patch.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe
  2025-09-01  9:58       ` Vadim Fedorenko
@ 2025-09-02  1:31         ` Yibo Dong
  0 siblings, 0 replies; 24+ messages in thread
From: Yibo Dong @ 2025-09-02  1:31 UTC (permalink / raw)
  To: Vadim Fedorenko
  Cc: Andrew Lunn, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
	corbet, gur.stavi, maddy, mpe, danishanwar, lee, gongfan1,
	lorenzo, geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap, netdev,
	linux-doc, linux-kernel, linux-hardening

On Mon, Sep 01, 2025 at 10:58:48AM +0100, Vadim Fedorenko wrote:
> On 01/09/2025 09:20, Yibo Dong wrote:
> > On Thu, Aug 28, 2025 at 02:51:07PM +0200, Andrew Lunn wrote:
> > > On Thu, Aug 28, 2025 at 10:55:43AM +0800, Dong Yibo wrote:
> > 
> > Hi, Andrew:
> > 
> > > > Add build options and doc for mucse.
> > > > Initialize pci device access for MUCSE devices.
> > > > 
> > > > Signed-off-by: Dong Yibo <dong100@mucse.com>
> > > 
> > > Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> > > 
> > >      Andrew
> > > 
> > 
> > Should I add 'Reviewed-by: Andrew Lunn <andrew@lunn.ch>' to commit for
> > [PATCH 1/5] in the next version?
> 
> The general rule is to carry over all the tags if there is no (big)
> changes to the code in the patch.
> 

Got it, thanks.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support
  2025-09-01  7:27         ` Yibo Dong
@ 2025-09-03  0:54           ` Andrew Lunn
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Lunn @ 2025-09-03  0:54 UTC (permalink / raw)
  To: Yibo Dong
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, corbet,
	gur.stavi, maddy, mpe, danishanwar, lee, gongfan1, lorenzo,
	geert+renesas, Parthiban.Veerasooran, lukas.bulwahn,
	alexanderduyck, richardcochran, kees, gustavoars, rdunlap,
	vadim.fedorenko, netdev, linux-doc, linux-kernel, linux-hardening

> static int mucse_mbx_get_info(struct mucse_hw *hw)
> {
>         struct mbx_fw_cmd_reply reply = {};
>         struct mbx_fw_cmd_req req = {};
>         struct hw_info info = {};
>         int err;
> 
>         build_get_fw_info_req(&req);
>         err = mucse_fw_send_cmd_wait(hw, &req, &reply);
>         if (!err) {
>                 memcpy(&info, &reply.hw_info, sizeof(struct hw_info));
>                 hw->pfvfnum = le16_to_cpu(info.pfnum) & GENMASK_U16(7, 0);
>         }
> 
>         return err;
> }
> 
> /**
>  * mucse_mbx_sync_fw - Try to sync with fw
>  * @hw: pointer to the HW structure
>  *
>  * mucse_mbx_sync_fw tries get sync to fw hw.
>  * It is only called in probe
>  *
>  * Return: 0 on success, negative errno on failure
>  **/
> int mucse_mbx_sync_fw(struct mucse_hw *hw)
> {
>         int try_cnt = 3;
>         int err;
> 
>         do {
>                 err = mucse_mbx_get_info(hw);
>                 if (err == -ETIMEDOUT)
>                         continue;
>                 break;
>         } while (try_cnt--);
> 
>         return err;
> }

This looks O.K.

     Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2025-09-03  0:55 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28  2:55 [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-08-28  2:55 ` [PATCH net-next v9 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-08-28 12:51   ` Andrew Lunn
2025-09-01  8:20     ` Yibo Dong
2025-09-01  9:58       ` Vadim Fedorenko
2025-09-02  1:31         ` Yibo Dong
2025-08-28  2:55 ` [PATCH net-next v9 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
2025-08-28  2:55 ` [PATCH net-next v9 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-08-28  2:55 ` [PATCH net-next v9 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-08-28 13:09   ` Andrew Lunn
2025-08-29  2:12     ` Yibo Dong
2025-08-29 19:48       ` Andrew Lunn
2025-09-01  2:08         ` Yibo Dong
2025-09-01  7:27         ` Yibo Dong
2025-09-03  0:54           ` Andrew Lunn
2025-08-28  2:55 ` [PATCH net-next v9 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-08-28 13:20   ` Andrew Lunn
2025-08-29  2:36     ` Yibo Dong
2025-08-29 19:51       ` Andrew Lunn
2025-09-01  2:18         ` Yibo Dong
2025-08-28  5:22 ` [PATCH net-next v9 0/5] Add driver for 1Gbe network chips from MUCSE MD Danish Anwar
2025-08-28  5:36   ` Yibo Dong
2025-08-28  6:47     ` MD Danish Anwar
2025-08-28 12:57     ` Andrew Lunn

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).