* [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE
@ 2025-09-09 12:09 Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
` (4 more replies)
0 siblings, 5 replies; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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 adds support for MUCSE RNPGBE 1Gbps PCIe Ethernet controllers
(N500/N210 series), including build infrastructure, hardware initialization,
mailbox (MBX) communication with firmware, and basic netdev registration
(Can show mac that is got from firmware, and tx/rx will be added later).
Series breakdown (5 patches):
01/05: net: ethernet/mucse: Add build support for rnpgbe
- Kconfig/Makefile for MUCSE vendor, basic PCI probe (no netdev)
02/05: net: ethernet/mucse: Add N500/N210 chip support
- netdev allocation, BAR mapping
03/05: net: ethernet/mucse: Add basic MBX ops for PF-FW communication
- base read/write, write with poll ack, poll and read data
04/05: net: ethernet/mucse: Add FW commands (sync, reset, MAC query)
- FW sync retry logic, MAC address retrieval, reset hw with
base mbx ops in patch4
05/05: net: ethernet/mucse: Complete netdev registration
- HW reset, MAC setup, netdev_ops registration
Changelog:
v10 -> v11:
Check include files for all patch, update commit info.
[patch 2/5]:
1. Move mbx relative struct to patch3.
[patch 3/5]:
1. move mbx->lock to patch4.
2. Use FIELD_GET, FIELD_PREP instead << >>.
3. Add mucse_release_mbx_lock_pf.
4. Rename function according to the function's functionality.
5. Reorder function to make call relationships clearer.
[patch 5/5]:
1. Add commit for powerup and sync_fw.
2. Rename function according to the function's functionality.
links:
v10: https://lore.kernel.org/netdev/20250903025430.864836-1-dong100@mucse.com/
v9 : https://lore.kernel.org/netdev/20250828025547.568563-1-dong100@mucse.com/
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 with BAR2 mapping
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 | 82 ++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 155 +++++++
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 18 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 310 +++++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 426 ++++++++++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 20 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 249 ++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 121 +++++
16 files changed, 1465 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] 25+ messages in thread
* [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
@ 2025-09-09 12:09 ` Dong Yibo
2025-09-09 12:37 ` Vadim Fedorenko
2025-09-09 12:09 ` [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping Dong Yibo
` (3 subsequent siblings)
4 siblings, 1 reply; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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,
Andrew Lunn
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>
---
.../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 | 18 +++
.../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 124 ++++++++++++++++++
10 files changed, 223 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 b81595e9ea95..39b862347145 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17306,6 +17306,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..3c37fe2534a8
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -0,0 +1,18 @@
+/* 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
+};
+
+/* 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..60bbc806f17b
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#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_n210},
+ /* 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] 25+ messages in thread
* [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
@ 2025-09-09 12:09 ` Dong Yibo
2025-09-09 12:41 ` Vadim Fedorenko
2025-09-09 12:09 ` [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
` (2 subsequent siblings)
4 siblings, 1 reply; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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 hardware initialization foundation for MUCSE 1Gbe controller,
including:
1. Map PCI BAR2 as hardware register base;
2. Bind PCI device to driver private data (struct mucse) and
initialize hardware context (struct mucse_hw);
3. Reserve board-specific init framework via rnpgbe_init_hw.
Signed-off-by: Dong Yibo <dong100@mucse.com>
---
drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 10 +++
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 9 +++
.../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 79 +++++++++++++++++++
3 files changed, 98 insertions(+)
create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
index 3c37fe2534a8..3b122dd508ce 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -9,6 +9,16 @@ enum rnpgbe_boards {
board_n210
};
+struct mucse_hw {
+ void __iomem *hw_addr;
+};
+
+struct mucse {
+ struct net_device *netdev;
+ struct pci_dev *pdev;
+ struct mucse_hw hw;
+};
+
/* Device IDs */
#define PCI_VENDOR_ID_MUCSE 0x8848
#define PCI_DEVICE_ID_N500_QUAD_PORT 0x8308
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..1a0b22d651b9
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#ifndef _RNPGBE_HW_H
+#define _RNPGBE_HW_H
+
+/**************** 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 60bbc806f17b..0afe39621661 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -2,8 +2,11 @@
/* Copyright(c) 2020 - 2025 Mucse Corporation. */
#include <linux/pci.h>
+#include <net/rtnetlink.h>
+#include <linux/etherdevice.h>
#include "rnpgbe.h"
+#include "rnpgbe_hw.h"
static const char rnpgbe_driver_name[] = "rnpgbe";
@@ -25,6 +28,54 @@ static struct pci_device_id rnpgbe_pci_tbl[] = {
{0, },
};
+/**
+ * rnpgbe_add_adapter - Add netdev for this pci_dev
+ * @pdev: PCI device information structure
+ * @board_type: board type
+ *
+ * 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,
+ int board_type)
+{
+ 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_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;
+
+ return 0;
+
+err_free_net:
+ free_netdev(netdev);
+ return err;
+}
+
/**
* rnpgbe_probe - Device initialization routine
* @pdev: PCI device information struct
@@ -37,6 +88,7 @@ static struct pci_device_id rnpgbe_pci_tbl[] = {
**/
static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
+ int board_type = id->driver_data;
int err;
err = pci_enable_device_mem(pdev);
@@ -63,6 +115,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, board_type);
+ if (err)
+ goto err_free_regions;
return 0;
err_free_regions:
@@ -72,6 +127,23 @@ 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;
+ free_netdev(netdev);
+}
+
/**
* rnpgbe_remove - Device removal routine
* @pdev: PCI device information struct
@@ -83,6 +155,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);
}
@@ -93,6 +166,12 @@ 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;
+
+ rtnl_lock();
+ netif_device_detach(netdev);
+ rtnl_unlock();
pci_disable_device(pdev);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping Dong Yibo
@ 2025-09-09 12:09 ` Dong Yibo
2025-09-09 14:22 ` Anwar, Md Danish
2025-09-09 12:09 ` [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev Dong Yibo
4 siblings, 1 reply; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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 fundamental mailbox (MBX) communication operations between PF (Physical
Function) and firmware for n500/n210 chips
Signed-off-by: Dong Yibo <dong100@mucse.com>
---
drivers/net/ethernet/mucse/rnpgbe/Makefile | 4 +-
drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 25 ++
.../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 70 +++
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 7 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 5 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 425 ++++++++++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 20 +
7 files changed, 555 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
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 9df536f0d04c..5fc878ada4b1 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
+++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
@@ -5,4 +5,6 @@
#
obj-$(CONFIG_MGBE) += rnpgbe.o
-rnpgbe-objs := rnpgbe_main.o
+rnpgbe-objs := rnpgbe_main.o\
+ rnpgbe_chip.o\
+ rnpgbe_mbx.o
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
index 3b122dd508ce..ac28502a8860 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -4,13 +4,36 @@
#ifndef _RNPGBE_H
#define _RNPGBE_H
+#include <linux/types.h>
+
enum rnpgbe_boards {
board_n500,
board_n210
};
+struct mucse_mbx_stats {
+ u32 msgs_tx; /* Number of messages sent from PF to fw */
+ u32 msgs_rx; /* Number of messages received from fw to PF */
+ u32 acks; /* Number of ACKs received from firmware */
+ u32 reqs; /* Number of requests sent to firmware */
+};
+
+struct mucse_mbx_info {
+ struct mucse_mbx_stats stats;
+ u32 timeout_cnt;
+ u32 usec_delay;
+ u16 fw_req;
+ u16 fw_ack;
+ /* fw <--> pf mbx */
+ u32 fwpf_shm_base;
+ u32 pf2fw_mbx_ctrl;
+ u32 fwpf_mbx_mask;
+ u32 fwpf_ctrl_base;
+};
+
struct mucse_hw {
void __iomem *hw_addr;
+ struct mucse_mbx_info mbx;
};
struct mucse {
@@ -19,6 +42,8 @@ struct mucse {
struct mucse_hw hw;
};
+int rnpgbe_init_hw(struct mucse_hw *hw, int board_type);
+
/* Device IDs */
#define PCI_VENDOR_ID_MUCSE 0x8848
#define PCI_DEVICE_ID_N500_QUAD_PORT 0x8308
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..0e277e7557ee
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#include <linux/errno.h>
+
+#include "rnpgbe.h"
+#include "rnpgbe_hw.h"
+#include "rnpgbe_mbx.h"
+
+/**
+ * rnpgbe_init_n500 - Setup n500 hw info
+ * @hw: hw information structure
+ *
+ * rnpgbe_init_n500 initializes all private
+ * structure for n500
+ **/
+static void rnpgbe_init_n500(struct mucse_hw *hw)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+
+ mbx->fwpf_ctrl_base = MUCSE_N500_FWPF_CTRL_BASE;
+ mbx->fwpf_shm_base = MUCSE_N500_FWPF_SHM_BASE;
+}
+
+/**
+ * rnpgbe_init_n210 - Setup n210 hw info
+ * @hw: hw information structure
+ *
+ * rnpgbe_init_n210 initializes all private
+ * structure for n210
+ **/
+static void rnpgbe_init_n210(struct mucse_hw *hw)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+
+ mbx->fwpf_ctrl_base = MUCSE_N210_FWPF_CTRL_BASE;
+ mbx->fwpf_shm_base = MUCSE_N210_FWPF_SHM_BASE;
+}
+
+/**
+ * rnpgbe_init_hw - Setup hw info according to board_type
+ * @hw: hw information structure
+ * @board_type: board type
+ *
+ * rnpgbe_init_hw initializes all hw data
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+
+ mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
+ mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
+
+ switch (board_type) {
+ case board_n500:
+ rnpgbe_init_n500(hw);
+ break;
+ case board_n210:
+ rnpgbe_init_n210(hw);
+ break;
+ default:
+ return -EINVAL;
+ }
+ /* init_params with mbx base */
+ mucse_init_mbx_params_pf(hw);
+
+ return 0;
+}
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
index 1a0b22d651b9..612f0ba65265 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
@@ -4,6 +4,13 @@
#ifndef _RNPGBE_HW_H
#define _RNPGBE_HW_H
+/**************** MBX Resource ****************************/
+#define MUCSE_N500_FWPF_CTRL_BASE 0x28b00
+#define MUCSE_N500_FWPF_SHM_BASE 0x2d000
+#define MUCSE_GBE_PFFW_MBX_CTRL_OFFSET 0x5500
+#define MUCSE_GBE_FWPF_MBX_MASK_OFFSET 0x5700
+#define MUCSE_N210_FWPF_CTRL_BASE 0x29400
+#define MUCSE_N210_FWPF_SHM_BASE 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 0afe39621661..c6cfb54f7c59 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -68,6 +68,11 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
}
hw->hw_addr = hw_addr;
+ err = rnpgbe_init_hw(hw, board_type);
+ if (err) {
+ dev_err(&pdev->dev, "Init hw err %d\n", err);
+ goto err_free_net;
+ }
return 0;
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
new file mode 100644
index 000000000000..9fcafda1bc5b
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2022 - 2025 Mucse Corporation. */
+
+#include <linux/errno.h>
+#include <linux/bitfield.h>
+#include <linux/iopoll.h>
+
+#include "rnpgbe_mbx.h"
+
+/**
+ * mbx_data_rd32 - Reads reg with base mbx->fwpf_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->fwpf_shm_base + reg);
+}
+
+/**
+ * mbx_data_wr32 - Writes value to reg with base mbx->fwpf_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->fwpf_shm_base + reg);
+}
+
+/**
+ * mbx_ctrl_rd32 - Reads reg with base mbx->fwpf_ctrl_base
+ * @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->fwpf_ctrl_base + reg);
+}
+
+/**
+ * mbx_ctrl_wr32 - Writes value to reg with base mbx->fwpf_ctrl_base
+ * @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->fwpf_ctrl_base + reg);
+}
+
+/**
+ * mucse_mbx_get_lock_pf - Write ctrl and read back lock status
+ * @hw: pointer to the HW structure
+ *
+ * Return: register value after write
+ **/
+static u32 mucse_mbx_get_lock_pf(struct mucse_hw *hw)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+ u32 reg = MUCSE_MBX_PF2FW_CTRL(mbx);
+
+ mbx_ctrl_wr32(mbx, reg, MUCSE_MBX_PFU);
+
+ return mbx_ctrl_rd32(mbx, reg);
+}
+
+/**
+ * mucse_obtain_mbx_lock_pf - Obtain mailbox lock
+ * @hw: pointer to the HW structure
+ *
+ * Pair with mucse_release_mbx_lock_pf()
+ * This function maybe used in an irq handler.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_obtain_mbx_lock_pf(struct mucse_hw *hw)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+ int count = mbx->timeout_cnt;
+ u32 val;
+
+ return read_poll_timeout_atomic(mucse_mbx_get_lock_pf,
+ val, val & MUCSE_MBX_PFU,
+ mbx->usec_delay,
+ count * mbx->usec_delay,
+ false, hw);
+}
+
+/**
+ * mucse_release_mbx_lock_pf - Release mailbox lock
+ * @hw: pointer to the HW structure
+ * @req: send a request or not
+ *
+ * Pair with mucse_obtain_mbx_lock_pf():
+ * - Releases the mailbox lock by clearing MUCSE_MBX_PFU bit
+ * - Simultaneously sends the request by setting MUCSE_MBX_REQ bit
+ * if req is true
+ * (Both bits are in the same mailbox control register,
+ * so operations are combined)
+ **/
+static void mucse_release_mbx_lock_pf(struct mucse_hw *hw, bool req)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+ u32 reg = MUCSE_MBX_PF2FW_CTRL(mbx);
+
+ if (req)
+ mbx_ctrl_wr32(mbx, reg, MUCSE_MBX_REQ);
+ else
+ mbx_ctrl_wr32(mbx, reg, 0);
+}
+
+/**
+ * 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)
+{
+ u32 val = mbx_data_rd32(mbx, MUCSE_MBX_FW2PF_CNT);
+
+ return FIELD_GET(GENMASK_U32(15, 0), val);
+}
+
+/**
+ * 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 val;
+
+ val = mbx_data_rd32(mbx, MUCSE_MBX_PF2FW_CNT);
+ ack = FIELD_GET(GENMASK_U32(31, 16), val);
+ ack++;
+ val &= ~GENMASK_U32(31, 16);
+ val |= FIELD_PREP(GENMASK_U32(31, 16), ack);
+ mbx_data_wr32(mbx, MUCSE_MBX_PF2FW_CNT, val);
+ hw->mbx.stats.msgs_rx++;
+}
+
+/**
+ * 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_in_words = size / 4;
+ int ret;
+ int i;
+
+ ret = mucse_obtain_mbx_lock_pf(hw);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < size_in_words; i++)
+ msg[i] = mbx_data_rd32(mbx, MUCSE_MBX_FWPF_SHM + 4 * i);
+ /* Hw needs write data_reg at last */
+ mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM, 0);
+ /* flush reqs as we have read this request data */
+ hw->mbx.fw_req = mucse_mbx_get_fwreq(mbx);
+ mucse_mbx_inc_pf_ack(hw);
+ mucse_release_mbx_lock_pf(hw, false);
+
+ return 0;
+}
+
+/**
+ * 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 fw_req;
+
+ fw_req = mucse_mbx_get_fwreq(mbx);
+ /* chip's register is reset to 0 when rc send reset
+ * mbx command. This causes 'fw_req != 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 (fw_req != 0 && fw_req != 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 count = mbx->timeout_cnt;
+ int val;
+
+ return read_poll_timeout(mucse_check_for_msg_pf,
+ val, !val, mbx->usec_delay,
+ count * mbx->usec_delay,
+ false, hw);
+}
+
+/**
+ * mucse_poll_and_read_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_poll_and_read_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_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)
+{
+ u32 val = mbx_data_rd32(mbx, MUCSE_MBX_FW2PF_CNT);
+
+ return FIELD_GET(GENMASK_U32(31, 16), val);
+}
+
+/**
+ * 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 val;
+
+ val = mbx_data_rd32(mbx, MUCSE_MBX_PF2FW_CNT);
+ req = FIELD_GET(GENMASK_U32(15, 0), val);
+ req++;
+ val &= ~GENMASK_U32(15, 0);
+ val |= FIELD_PREP(GENMASK_U32(15, 0), req);
+ mbx_data_wr32(mbx, MUCSE_MBX_PF2FW_CNT, val);
+ hw->mbx.stats.msgs_tx++;
+}
+
+/**
+ * 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
+ **/
+static int mucse_write_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+ int size_in_words = size / 4;
+ int ret;
+ int i;
+
+ ret = mucse_obtain_mbx_lock_pf(hw);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < size_in_words; i++)
+ mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM + i * 4, msg[i]);
+
+ /* flush acks as we are overwriting the message buffer */
+ hw->mbx.fw_ack = mucse_mbx_get_fwack(mbx);
+ mucse_mbx_inc_pf_req(hw);
+ mucse_release_mbx_lock_pf(hw, true);
+
+ return 0;
+}
+
+/**
+ * mucse_check_for_ack_pf - Check to see if the fw 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 fw_ack;
+
+ fw_ack = mucse_mbx_get_fwack(mbx);
+ /* chip's register is reset to 0 when rc send reset
+ * mbx command. This causes '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 (fw_ack != 0 && 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,
+ * else negative errno
+ **/
+static int mucse_poll_for_ack(struct mucse_hw *hw)
+{
+ struct mucse_mbx_info *mbx = &hw->mbx;
+ int count = mbx->timeout_cnt;
+ int val;
+
+ return read_poll_timeout(mucse_check_for_ack_pf,
+ val, !val, mbx->usec_delay,
+ count * mbx->usec_delay,
+ false, hw);
+}
+
+/**
+ * mucse_write_and_wait_ack_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_cnt period
+ **/
+int mucse_write_and_wait_ack_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);
+}
+
+/**
+ * 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, MUCSE_MBX_FW2PF_CNT);
+ hw->mbx.fw_req = FIELD_GET(GENMASK_U32(15, 0), v);
+ hw->mbx.fw_ack = FIELD_GET(GENMASK_U32(31, 16), v);
+ mbx_ctrl_wr32(mbx, MUCSE_MBX_PF2FW_CTRL(mbx), 0);
+ mbx_ctrl_wr32(mbx, MUCSE_MBX_FWPF_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_cnt = (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;
+ mucse_mbx_reset(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..eac99f13b6ff
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h
@@ -0,0 +1,20 @@
+/* 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_MBX_FW2PF_CNT 0
+#define MUCSE_MBX_PF2FW_CNT 4
+#define MUCSE_MBX_FWPF_SHM 8
+#define MUCSE_MBX_PF2FW_CTRL(mbx) ((mbx)->pf2fw_mbx_ctrl)
+#define MUCSE_MBX_FWPF_MASK(mbx) ((mbx)->fwpf_mbx_mask)
+#define MUCSE_MBX_REQ BIT(0) /* Request a req to mailbox */
+#define MUCSE_MBX_PFU BIT(3) /* PF owns the mailbox buffer */
+
+int mucse_write_and_wait_ack_mbx(struct mucse_hw *hw, u32 *msg, u16 size);
+void mucse_init_mbx_params_pf(struct mucse_hw *hw);
+int mucse_poll_and_read_mbx(struct mucse_hw *hw, u32 *msg, u16 size);
+#endif /* _RNPGBE_MBX_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
` (2 preceding siblings ...)
2025-09-09 12:09 ` [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
@ 2025-09-09 12:09 ` Dong Yibo
2025-09-09 14:29 ` Anwar, Md Danish
2025-09-09 12:09 ` [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev Dong Yibo
4 siblings, 1 reply; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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 fundamental firmware (FW) communication operations via PF-FW mailbox,
including:
- FW sync (via HW info query with retries)
- HW reset (post FW command to reset hardware)
- MAC address retrieval (request FW for port-specific MAC)
- Power management (powerup/powerdown notification to FW)
Signed-off-by: Dong Yibo <dong100@mucse.com>
---
drivers/net/ethernet/mucse/rnpgbe/Makefile | 3 +-
drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 4 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 1 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 249 ++++++++++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 121 +++++++++
5 files changed, 377 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 ac28502a8860..3a1ad82c24bd 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>
enum rnpgbe_boards {
board_n500,
@@ -24,6 +25,8 @@ struct mucse_mbx_info {
u32 usec_delay;
u16 fw_req;
u16 fw_ack;
+ /* lock for only one use mbx */
+ struct mutex lock;
/* fw <--> pf mbx */
u32 fwpf_shm_base;
u32 pf2fw_mbx_ctrl;
@@ -34,6 +37,7 @@ struct mucse_mbx_info {
struct mucse_hw {
void __iomem *hw_addr;
struct mucse_mbx_info mbx;
+ u8 pfvfnum;
};
struct mucse {
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
index 9fcafda1bc5b..6ff3655033de 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c
@@ -421,5 +421,6 @@ void mucse_init_mbx_params_pf(struct mucse_hw *hw)
mbx->stats.msgs_rx = 0;
mbx->stats.reqs = 0;
mbx->stats.acks = 0;
+ mutex_init(&mbx->lock);
mucse_mbx_reset(hw);
}
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..9b81ee679622
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
@@ -0,0 +1,249 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+
+#include <linux/if_ether.h>
+#include <linux/bitfield.h>
+
+#include "rnpgbe.h"
+#include "rnpgbe_mbx.h"
+#include "rnpgbe_mbx_fw.h"
+
+/**
+ * mucse_fw_send_cmd_wait_resp - 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_resp 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_resp(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;
+
+ mutex_lock(&hw->mbx.lock);
+ err = mucse_write_and_wait_ack_mbx(hw, (u32 *)req, len);
+ if (err)
+ goto out;
+ do {
+ err = mucse_poll_and_read_mbx(hw, (u32 *)reply,
+ sizeof(*reply));
+ if (err)
+ goto out;
+ /* mucse_write_and_wait_ack_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_get_hw_info_req - build req with GET_HW_INFO opcode
+ * @req: pointer to the cmd req structure
+ **/
+static void build_get_hw_info_req(struct mbx_fw_cmd_req *req)
+{
+ req->flags = 0;
+ req->opcode = cpu_to_le16(GET_HW_INFO);
+ req->datalen = cpu_to_le16(MUCSE_MBX_REQ_HDR_LEN);
+ req->reply_lo = 0;
+ req->reply_hi = 0;
+}
+
+/**
+ * mucse_mbx_get_info - Get hw info from fw
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_get_info tries to get hw info from hw.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int mucse_mbx_get_info(struct mucse_hw *hw)
+{
+ struct mbx_fw_cmd_reply reply = {};
+ struct mbx_fw_cmd_req req = {};
+ struct mucse_hw_info info = {};
+ int err;
+
+ build_get_hw_info_req(&req);
+
+ err = mucse_fw_send_cmd_wait_resp(hw, &req, &reply);
+ if (!err) {
+ memcpy(&info, &reply.hw_info, sizeof(struct mucse_hw_info));
+ mucse_hw_info_update_host_endian(&info);
+ hw->pfvfnum = FIELD_GET(GENMASK_U16(7, 0),
+ le16_to_cpu(info.pfnum));
+ }
+
+ return err;
+}
+
+/**
+ * mucse_mbx_sync_fw - Try to sync with fw
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_sync_fw tries to sync with fw. It is only called in
+ * probe. Nothing (register network) todo if failed.
+ * Try more times to do sync.
+ *
+ * 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;
+}
+
+/**
+ * build_powerup - build req with powerup opcode
+ * @req: pointer to the cmd req structure
+ * @is_powerup: true for powerup, false for powerdown
+ **/
+static void build_powerup(struct mbx_fw_cmd_req *req,
+ bool is_powerup)
+{
+ req->flags = 0;
+ req->opcode = cpu_to_le16(POWER_UP);
+ req->datalen = cpu_to_le16(sizeof(req->powerup) +
+ MUCSE_MBX_REQ_HDR_LEN);
+ req->reply_lo = 0;
+ req->reply_hi = 0;
+ /* fw needs this to reply correct cmd */
+ req->powerup.version = cpu_to_le32(GENMASK_U32(31, 0));
+ if (is_powerup)
+ req->powerup.status = cpu_to_le32(1);
+ else
+ req->powerup.status = cpu_to_le32(0);
+}
+
+/**
+ * mucse_mbx_powerup - Echo fw to powerup
+ * @hw: pointer to the HW structure
+ * @is_powerup: true for powerup, false for powerdown
+ *
+ * mucse_mbx_powerup echo fw to change working frequency
+ * to normal after received true, and reduce working frequency
+ * if false.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_powerup(struct mucse_hw *hw, bool is_powerup)
+{
+ struct mbx_fw_cmd_req req = {};
+ int len;
+ int err;
+
+ build_powerup(&req, is_powerup);
+ len = le16_to_cpu(req.datalen);
+ mutex_lock(&hw->mbx.lock);
+ err = mucse_write_and_wait_ack_mbx(hw, (u32 *)&req, len);
+ mutex_unlock(&hw->mbx.lock);
+
+ return err;
+}
+
+/**
+ * build_reset_hw_req - build req with RESET_HW opcode
+ * @req: pointer to the cmd req structure
+ **/
+static void build_reset_hw_req(struct mbx_fw_cmd_req *req)
+{
+ req->flags = 0;
+ req->opcode = cpu_to_le16(RESET_HW);
+ req->datalen = cpu_to_le16(MUCSE_MBX_REQ_HDR_LEN);
+ req->reply_lo = 0;
+ req->reply_hi = 0;
+}
+
+/**
+ * mucse_mbx_reset_hw - Posts a mbx req to reset hw
+ * @hw: pointer to the HW structure
+ *
+ * mucse_mbx_reset_hw posts a mbx req to firmware to reset hw.
+ * We use mucse_fw_send_cmd_wait_resp to wait hw reset ok.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_reset_hw(struct mucse_hw *hw)
+{
+ struct mbx_fw_cmd_reply reply = {};
+ struct mbx_fw_cmd_req req = {};
+
+ build_reset_hw_req(&req);
+
+ return mucse_fw_send_cmd_wait_resp(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_ADDRESS);
+ req->datalen = cpu_to_le16(sizeof(req->get_mac_addr) +
+ MUCSE_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_mbx_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_mbx_get_macaddr posts a mbx req to firmware to get mac_addr.
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+int mucse_mbx_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_resp(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..9dee6029e630
--- /dev/null
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h
@@ -0,0 +1,121 @@
+/* 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 "rnpgbe.h"
+
+#define MUCSE_MBX_REQ_HDR_LEN 24
+
+enum MUCSE_FW_CMD {
+ GET_HW_INFO = 0x0601,
+ GET_MAC_ADDRESS = 0x0602,
+ RESET_HW = 0x0603,
+ POWER_UP = 0x0803,
+};
+
+struct mucse_hw_info {
+ 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_info;
+ 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 information in 'ext_info' 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 mucse_hw_info_update_host_endian(struct mucse_hw_info *info)
+{
+ u32 host_val = le32_to_cpu(info->ext_info);
+
+ memcpy(&info->e_host, &host_val, sizeof(info->e_host));
+}
+
+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;
+ } powerup;
+ 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 mucse_hw_info hw_info;
+ };
+} __packed;
+
+int mucse_mbx_sync_fw(struct mucse_hw *hw);
+int mucse_mbx_powerup(struct mucse_hw *hw, bool is_powerup);
+int mucse_mbx_reset_hw(struct mucse_hw *hw);
+int mucse_mbx_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] 25+ messages in thread
* [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
` (3 preceding siblings ...)
2025-09-09 12:09 ` [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
@ 2025-09-09 12:09 ` Dong Yibo
2025-09-09 14:31 ` Anwar, Md Danish
2025-09-09 14:37 ` Vadim Fedorenko
4 siblings, 2 replies; 25+ messages in thread
From: Dong Yibo @ 2025-09-09 12:09 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
Complete the network device (netdev) registration flow for Mucse Gbe
Ethernet chips, including:
1. Hardware state initialization:
- Send powerup notification to firmware (via echo_fw_status)
- Sync with firmware
- Reset hardware
2. MAC address handling:
- Retrieve permanent MAC from firmware (via mucse_mbx_get_macaddr)
- Fallback to random valid MAC (eth_random_addr) if not valid mac
from Fw
Signed-off-by: Dong Yibo <dong100@mucse.com>
---
drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 25 +++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 85 +++++++++++++++
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 2 +
.../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 102 ++++++++++++++++++
4 files changed, 214 insertions(+)
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
index 3a1ad82c24bd..5278cb1d421e 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h
@@ -6,12 +6,17 @@
#include <linux/types.h>
#include <linux/mutex.h>
+#include <linux/netdevice.h>
enum rnpgbe_boards {
board_n500,
board_n210
};
+struct mucse_dma_info {
+ void __iomem *dma_base_addr;
+};
+
struct mucse_mbx_stats {
u32 msgs_tx; /* Number of messages sent from PF to fw */
u32 msgs_rx; /* Number of messages received from fw to PF */
@@ -34,9 +39,26 @@ struct mucse_mbx_info {
u32 fwpf_ctrl_base;
};
+struct mucse_hw;
+
+struct mucse_hw_operations {
+ int (*reset_hw)(struct mucse_hw *hw);
+ int (*get_perm_mac)(struct mucse_hw *hw);
+ int (*mbx_send_notify)(struct mucse_hw *hw, bool enable, int mode);
+};
+
+enum {
+ mucse_fw_powerup,
+};
+
struct mucse_hw {
void __iomem *hw_addr;
+ struct pci_dev *pdev;
+ const struct mucse_hw_operations *ops;
+ struct mucse_dma_info dma;
struct mucse_mbx_info mbx;
+ int port;
+ u8 perm_addr[ETH_ALEN];
u8 pfvfnum;
};
@@ -54,4 +76,7 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type);
#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 0e277e7557ee..436fb03f9736 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
@@ -1,11 +1,90 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2020 - 2025 Mucse Corporation. */
+#include <linux/pci.h>
#include <linux/errno.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
+ *
+ * rnpgbe_get_permanent_mac tries to get mac from hw
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int rnpgbe_get_permanent_mac(struct mucse_hw *hw)
+{
+ struct device *dev = &hw->pdev->dev;
+ u8 *mac_addr = hw->perm_addr;
+ int err;
+
+ err = mucse_mbx_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 - Do a hardware reset
+ * @hw: hw information structure
+ *
+ * rnpgbe_reset 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(struct mucse_hw *hw)
+{
+ struct mucse_dma_info *dma = &hw->dma;
+
+ rnpgbe_dma_wr32(dma, RNPGBE_DMA_AXI_EN, 0);
+ return mucse_mbx_reset_hw(hw);
+}
+
+/**
+ * rnpgbe_mbx_send_notify - Echo fw status
+ * @hw: hw information structure
+ * @enable: true or false status
+ * @mode: status mode
+ *
+ * Return: 0 on success, negative errno on failure
+ **/
+static int rnpgbe_mbx_send_notify(struct mucse_hw *hw,
+ bool enable,
+ int mode)
+{
+ int err;
+
+ switch (mode) {
+ case mucse_fw_powerup:
+ err = mucse_mbx_powerup(hw, enable);
+ break;
+ default:
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+static const struct mucse_hw_operations rnpgbe_hw_ops = {
+ .reset_hw = rnpgbe_reset,
+ .get_perm_mac = rnpgbe_get_permanent_mac,
+ .mbx_send_notify = rnpgbe_mbx_send_notify,
+};
/**
* rnpgbe_init_n500 - Setup n500 hw info
@@ -48,8 +127,14 @@ static void rnpgbe_init_n210(struct mucse_hw *hw)
**/
int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
{
+ struct mucse_dma_info *dma = &hw->dma;
struct mucse_mbx_info *mbx = &hw->mbx;
+ hw->ops = &rnpgbe_hw_ops;
+ hw->port = 0;
+
+ dma->dma_base_addr = hw->hw_addr;
+
mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
index 612f0ba65265..00bf7571bf35 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h
@@ -11,6 +11,8 @@
#define MUCSE_GBE_FWPF_MBX_MASK_OFFSET 0x5700
#define MUCSE_N210_FWPF_CTRL_BASE 0x29400
#define MUCSE_N210_FWPF_SHM_BASE 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 c6cfb54f7c59..94de1693c4a0 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
@@ -7,6 +7,7 @@
#include "rnpgbe.h"
#include "rnpgbe_hw.h"
+#include "rnpgbe_mbx_fw.h"
static const char rnpgbe_driver_name[] = "rnpgbe";
@@ -28,6 +29,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
@@ -68,11 +118,55 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
}
hw->hw_addr = hw_addr;
+ hw->pdev = pdev;
+
err = rnpgbe_init_hw(hw, board_type);
if (err) {
dev_err(&pdev->dev, "Init hw err %d\n", err);
goto err_free_net;
}
+ /* Step 1: Send power-up notification to firmware (no response expected)
+ * This informs firmware to initialize hardware power state, but
+ * firmware only acknowledges receipt without returning data. Must be
+ * done before synchronization as firmware may be in low-power idle
+ * state initially.
+ */
+ err = hw->ops->mbx_send_notify(hw, true, mucse_fw_powerup);
+ if (err) {
+ dev_warn(&pdev->dev, "Send powerup to hw failed %d\n", err);
+ dev_warn(&pdev->dev, "Maybe low performance\n");
+ }
+ /* Step 2: Synchronize mailbox communication with firmware (requires
+ * response) After power-up, confirm firmware is ready to process
+ * requests with responses. This ensures subsequent request/response
+ * interactions work reliably.
+ */
+ err = mucse_mbx_sync_fw(hw);
+ if (err) {
+ dev_err(&pdev->dev, "Sync fw failed! %d\n", err);
+ goto err_free_net;
+ }
+
+ netdev->netdev_ops = &rnpgbe_netdev_ops;
+ err = hw->ops->reset_hw(hw);
+ if (err) {
+ dev_err(&pdev->dev, "Hw reset failed %d\n", err);
+ goto err_free_net;
+ }
+
+ err = hw->ops->get_perm_mac(hw);
+ if (err == -EINVAL) {
+ dev_warn(&pdev->dev, "Using random MAC\n");
+ eth_random_addr(hw->perm_addr);
+ } else if (err) {
+ dev_err(&pdev->dev, "get perm_addr 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;
@@ -141,11 +235,17 @@ 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;
+ int err;
if (!mucse)
return;
netdev = mucse->netdev;
+ unregister_netdev(netdev);
+ err = hw->ops->mbx_send_notify(hw, false, mucse_fw_powerup);
+ if (err)
+ dev_warn(&pdev->dev, "Send powerdown to hw failed %d\n", err);
free_netdev(netdev);
}
@@ -176,6 +276,8 @@ static void rnpgbe_dev_shutdown(struct pci_dev *pdev)
rtnl_lock();
netif_device_detach(netdev);
+ if (netif_running(netdev))
+ rnpgbe_close(netdev);
rtnl_unlock();
pci_disable_device(pdev);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe
2025-09-09 12:09 ` [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
@ 2025-09-09 12:37 ` Vadim Fedorenko
0 siblings, 0 replies; 25+ messages in thread
From: Vadim Fedorenko @ 2025-09-09 12:37 UTC (permalink / raw)
To: Dong Yibo, 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
Cc: netdev, linux-doc, linux-kernel, linux-hardening, Andrew Lunn
On 09/09/2025 13:09, 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>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping
2025-09-09 12:09 ` [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping Dong Yibo
@ 2025-09-09 12:41 ` Vadim Fedorenko
0 siblings, 0 replies; 25+ messages in thread
From: Vadim Fedorenko @ 2025-09-09 12:41 UTC (permalink / raw)
To: Dong Yibo, 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
Cc: netdev, linux-doc, linux-kernel, linux-hardening
On 09/09/2025 13:09, Dong Yibo wrote:
> Add hardware initialization foundation for MUCSE 1Gbe controller,
> including:
> 1. Map PCI BAR2 as hardware register base;
> 2. Bind PCI device to driver private data (struct mucse) and
> initialize hardware context (struct mucse_hw);
> 3. Reserve board-specific init framework via rnpgbe_init_hw.
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-09 12:09 ` [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
@ 2025-09-09 14:22 ` Anwar, Md Danish
2025-09-09 20:55 ` Jakub Kicinski
2025-09-10 5:52 ` Yibo Dong
0 siblings, 2 replies; 25+ messages in thread
From: Anwar, Md Danish @ 2025-09-09 14:22 UTC (permalink / raw)
To: Dong Yibo, 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
On 9/9/2025 5:39 PM, Dong Yibo wrote:
> Add fundamental mailbox (MBX) communication operations between PF (Physical
> Function) and firmware for n500/n210 chips
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> drivers/net/ethernet/mucse/rnpgbe/Makefile | 4 +-
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 25 ++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 70 +++
> drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 7 +
> .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 5 +
> .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 425 ++++++++++++++++++
> .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 20 +
> 7 files changed, 555 insertions(+), 1 deletion(-)
> create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> 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 9df536f0d04c..5fc878ada4b1 100644
> --- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
> +++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> @@ -5,4 +5,6 @@
> #
[ ... ]
> +
> +/**
> + * rnpgbe_init_hw - Setup hw info according to board_type
> + * @hw: hw information structure
> + * @board_type: board type
> + *
> + * rnpgbe_init_hw initializes all hw data
> + *
> + * Return: 0 on success, negative errno on failure
> + **/
> +int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
> +{
> + struct mucse_mbx_info *mbx = &hw->mbx;
> +
> + mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
> + mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
> +
> + switch (board_type) {
> + case board_n500:
> + rnpgbe_init_n500(hw);
> + break;
> + case board_n210:
> + rnpgbe_init_n210(hw);
> + break;
> + default:
> + return -EINVAL;
> + }
The indentation of this switch block seems off to me.
As per the coding guidlines
https://www.kernel.org/doc/html/v4.14/process/coding-style.html#indentation
Break statements should be at the same indentation level as the case
code. The current indentation has the "break" statements at the same
level as the case labels, which is inconsistent.
This should be like,
switch (board_type) {
case board_n500:
rnpgbe_init_n500(hw);
break;
case board_n210:
rnpgbe_init_n210(hw);
break;
default:
return -EINVAL;
}
> + /* init_params with mbx base */
> + mucse_init_mbx_params_pf(hw);
> +
> + return 0;
> +}
[ ... ]
> +/**
> + * 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_in_words = size / 4;
> + int ret;
> + int i;
> +
> + ret = mucse_obtain_mbx_lock_pf(hw);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < size_in_words; i++)
> + msg[i] = mbx_data_rd32(mbx, MUCSE_MBX_FWPF_SHM + 4 * i);
The array indexing calculation should use multiplication by sizeof(u32)
instead of hardcoded 4.
> + /* Hw needs write data_reg at last */
> + mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM, 0);
> + /* flush reqs as we have read this request data */
> + hw->mbx.fw_req = mucse_mbx_get_fwreq(mbx);
> + mucse_mbx_inc_pf_ack(hw);
> + mucse_release_mbx_lock_pf(hw, false);
> +
> + return 0;
> +}
> +
> +/**
> + * 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 fw_req;
> +
> + fw_req = mucse_mbx_get_fwreq(mbx);
> + /* chip's register is reset to 0 when rc send reset
> + * mbx command. This causes 'fw_req != 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 (fw_req != 0 && fw_req != 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 count = mbx->timeout_cnt;
> + int val;
> +
> + return read_poll_timeout(mucse_check_for_msg_pf,
> + val, !val, mbx->usec_delay,
> + count * mbx->usec_delay,
> + false, hw);
> +}
> +
> +/**
> + * mucse_poll_and_read_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_poll_and_read_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_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)
> +{
> + u32 val = mbx_data_rd32(mbx, MUCSE_MBX_FW2PF_CNT);
> +
> + return FIELD_GET(GENMASK_U32(31, 16), val);
> +}
> +
> +/**
> + * 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 val;
> +
> + val = mbx_data_rd32(mbx, MUCSE_MBX_PF2FW_CNT);
> + req = FIELD_GET(GENMASK_U32(15, 0), val);
> + req++;
> + val &= ~GENMASK_U32(15, 0);
> + val |= FIELD_PREP(GENMASK_U32(15, 0), req);
> + mbx_data_wr32(mbx, MUCSE_MBX_PF2FW_CNT, val);
> + hw->mbx.stats.msgs_tx++;
> +}
> +
> +/**
> + * 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
> + **/
> +static int mucse_write_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size)
> +{
> + struct mucse_mbx_info *mbx = &hw->mbx;
> + int size_in_words = size / 4;
> + int ret;
> + int i;
> +
> + ret = mucse_obtain_mbx_lock_pf(hw);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < size_in_words; i++)
> + mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM + i * 4, msg[i]);
Same issue as above - should use sizeof(u32) instead of hardcoded 4 for
portability.
> +
> + /* flush acks as we are overwriting the message buffer */
> + hw->mbx.fw_ack = mucse_mbx_get_fwack(mbx);
--
Thanks and Regards,
Md Danish Anwar
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-09 12:09 ` [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
@ 2025-09-09 14:29 ` Anwar, Md Danish
2025-09-09 20:58 ` Jakub Kicinski
0 siblings, 1 reply; 25+ messages in thread
From: Anwar, Md Danish @ 2025-09-09 14:29 UTC (permalink / raw)
To: Dong Yibo, 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
On 9/9/2025 5:39 PM, Dong Yibo wrote:
> Add fundamental firmware (FW) communication operations via PF-FW mailbox,
> including:
> - FW sync (via HW info query with retries)
> - HW reset (post FW command to reset hardware)
> - MAC address retrieval (request FW for port-specific MAC)
> - Power management (powerup/powerdown notification to FW)
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> +/**
> + * mucse_mbx_sync_fw - Try to sync with fw
> + * @hw: pointer to the HW structure
> + *
> + * mucse_mbx_sync_fw tries to sync with fw. It is only called in
> + * probe. Nothing (register network) todo if failed.
> + * Try more times to do sync.
> + *
> + * 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;
> +}
There's a logical issue in the code. The loop structure attempts to
retry on ETIMEDOUT errors, but the unconditional break statement after
the if-check will always exit the loop after the first attempt,
regardless of the error. The do-while loop will never actually retry
because the break statement is placed outside of the if condition that
checks for timeout errors.
--
Thanks and Regards,
Md Danish Anwar
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev
2025-09-09 12:09 ` [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev Dong Yibo
@ 2025-09-09 14:31 ` Anwar, Md Danish
2025-09-10 6:10 ` Yibo Dong
2025-09-09 14:37 ` Vadim Fedorenko
1 sibling, 1 reply; 25+ messages in thread
From: Anwar, Md Danish @ 2025-09-09 14:31 UTC (permalink / raw)
To: Dong Yibo, 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
On 9/9/2025 5:39 PM, Dong Yibo wrote:
> Complete the network device (netdev) registration flow for Mucse Gbe
> Ethernet chips, including:
> 1. Hardware state initialization:
> - Send powerup notification to firmware (via echo_fw_status)
> - Sync with firmware
> - Reset hardware
> 2. MAC address handling:
> - Retrieve permanent MAC from firmware (via mucse_mbx_get_macaddr)
> - Fallback to random valid MAC (eth_random_addr) if not valid mac
> from Fw
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
> ---
> +/**
> + * 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;
> +}
The function comment says it returns NETDEV_TX_OK or NETDEV_TX_BUSY, but
it only returns NETDEV_TX_OK.
--
Thanks and Regards,
Md Danish Anwar
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev
2025-09-09 12:09 ` [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-09-09 14:31 ` Anwar, Md Danish
@ 2025-09-09 14:37 ` Vadim Fedorenko
2025-09-10 6:22 ` Yibo Dong
1 sibling, 1 reply; 25+ messages in thread
From: Vadim Fedorenko @ 2025-09-09 14:37 UTC (permalink / raw)
To: Dong Yibo, 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
Cc: netdev, linux-doc, linux-kernel, linux-hardening
On 09/09/2025 13:09, Dong Yibo wrote:
> Complete the network device (netdev) registration flow for Mucse Gbe
> Ethernet chips, including:
> 1. Hardware state initialization:
> - Send powerup notification to firmware (via echo_fw_status)
> - Sync with firmware
> - Reset hardware
> 2. MAC address handling:
> - Retrieve permanent MAC from firmware (via mucse_mbx_get_macaddr)
> - Fallback to random valid MAC (eth_random_addr) if not valid mac
> from Fw
>
> Signed-off-by: Dong Yibo <dong100@mucse.com>
[...]
> +struct mucse_hw;
why do you need this forward declaration ...> +
> +struct mucse_hw_operations {
> + int (*reset_hw)(struct mucse_hw *hw);
> + int (*get_perm_mac)(struct mucse_hw *hw);
> + int (*mbx_send_notify)(struct mucse_hw *hw, bool enable, int mode);
> +};
> +
> +enum {
> + mucse_fw_powerup,
> +};
> +
> struct mucse_hw {
> void __iomem *hw_addr;
> + struct pci_dev *pdev;
> + const struct mucse_hw_operations *ops;
> + struct mucse_dma_info dma;
> struct mucse_mbx_info mbx;
> + int port;
> + u8 perm_addr[ETH_ALEN];
> u8 pfvfnum;
> };
... if you can simply move mucse_hw_operations down here?
>
> @@ -54,4 +76,7 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type);
> #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))
[...]
> @@ -48,8 +127,14 @@ static void rnpgbe_init_n210(struct mucse_hw *hw)
> **/
> int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
> {
> + struct mucse_dma_info *dma = &hw->dma;
> struct mucse_mbx_info *mbx = &hw->mbx;
>
> + hw->ops = &rnpgbe_hw_ops;
> + hw->port = 0;
> +
> + dma->dma_base_addr = hw->hw_addr;
not quite sure why do you need additional structure just to store the
value that already exists in mucse_hw?
> +
> mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
> mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-09 14:22 ` Anwar, Md Danish
@ 2025-09-09 20:55 ` Jakub Kicinski
2025-09-10 5:56 ` Yibo Dong
2025-09-10 5:52 ` Yibo Dong
1 sibling, 1 reply; 25+ messages in thread
From: Jakub Kicinski @ 2025-09-09 20:55 UTC (permalink / raw)
To: Anwar, Md Danish
Cc: Dong Yibo, andrew+netdev, davem, edumazet, 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 Tue, 9 Sep 2025 19:52:21 +0530 Anwar, Md Danish wrote:
> > + for (i = 0; i < size_in_words; i++)
> > + msg[i] = mbx_data_rd32(mbx, MUCSE_MBX_FWPF_SHM + 4 * i);
>
> The array indexing calculation should use multiplication by sizeof(u32)
> instead of hardcoded 4.
Not sure this is really necessary, I'd expect C programmers to intuit
that 4 is the number of bytes in u32 here. sizeof(u32) is going to
overflow 80 char line limit and cause more harm than good.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-09 14:29 ` Anwar, Md Danish
@ 2025-09-09 20:58 ` Jakub Kicinski
2025-09-10 6:08 ` Yibo Dong
0 siblings, 1 reply; 25+ messages in thread
From: Jakub Kicinski @ 2025-09-09 20:58 UTC (permalink / raw)
To: Anwar, Md Danish
Cc: Dong Yibo, andrew+netdev, davem, edumazet, 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 Tue, 9 Sep 2025 19:59:11 +0530 Anwar, Md Danish wrote:
> > +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;
> > +}
>
> There's a logical issue in the code. The loop structure attempts to
> retry on ETIMEDOUT errors, but the unconditional break statement after
> the if-check will always exit the loop after the first attempt,
> regardless of the error. The do-while loop will never actually retry
> because the break statement is placed outside of the if condition that
> checks for timeout errors.
The other way around. continue; in a do {} while () look does *not*
evaluate the condition. So this can loop forever.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-09 14:22 ` Anwar, Md Danish
2025-09-09 20:55 ` Jakub Kicinski
@ 2025-09-10 5:52 ` Yibo Dong
1 sibling, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-10 5:52 UTC (permalink / raw)
To: Anwar, Md Danish
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 Tue, Sep 09, 2025 at 07:52:21PM +0530, Anwar, Md Danish wrote:
> On 9/9/2025 5:39 PM, Dong Yibo wrote:
> > Add fundamental mailbox (MBX) communication operations between PF (Physical
> > Function) and firmware for n500/n210 chips
> >
> > Signed-off-by: Dong Yibo <dong100@mucse.com>
> > ---
> > drivers/net/ethernet/mucse/rnpgbe/Makefile | 4 +-
> > drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 25 ++
> > .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 70 +++
> > drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 7 +
> > .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 5 +
> > .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 425 ++++++++++++++++++
> > .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 20 +
> > 7 files changed, 555 insertions(+), 1 deletion(-)
> > create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c
> > 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 9df536f0d04c..5fc878ada4b1 100644
> > --- a/drivers/net/ethernet/mucse/rnpgbe/Makefile
> > +++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile
> > @@ -5,4 +5,6 @@
> > #
>
> [ ... ]
>
> > +
> > +/**
> > + * rnpgbe_init_hw - Setup hw info according to board_type
> > + * @hw: hw information structure
> > + * @board_type: board type
> > + *
> > + * rnpgbe_init_hw initializes all hw data
> > + *
> > + * Return: 0 on success, negative errno on failure
> > + **/
> > +int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
> > +{
> > + struct mucse_mbx_info *mbx = &hw->mbx;
> > +
> > + mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
> > + mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
> > +
> > + switch (board_type) {
> > + case board_n500:
> > + rnpgbe_init_n500(hw);
> > + break;
> > + case board_n210:
> > + rnpgbe_init_n210(hw);
> > + break;
> > + default:
> > + return -EINVAL;
> > + }
>
> The indentation of this switch block seems off to me.
>
> As per the coding guidlines
> https://www.kernel.org/doc/html/v4.14/process/coding-style.html#indentation
>
> Break statements should be at the same indentation level as the case
> code. The current indentation has the "break" statements at the same
> level as the case labels, which is inconsistent.
>
> This should be like,
>
> switch (board_type) {
> case board_n500:
> rnpgbe_init_n500(hw);
> break;
> case board_n210:
> rnpgbe_init_n210(hw);
> break;
> default:
> return -EINVAL;
> }
>
Sorry for the bad code style. I will fix this in next version.
> > + /* init_params with mbx base */
> > + mucse_init_mbx_params_pf(hw);
> > +
> > + return 0;
> > +}
>
[ ... ]
>
>
>
> --
> Thanks and Regards,
> Md Danish Anwar
>
>
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-09 20:55 ` Jakub Kicinski
@ 2025-09-10 5:56 ` Yibo Dong
2025-09-11 1:02 ` Jakub Kicinski
0 siblings, 1 reply; 25+ messages in thread
From: Yibo Dong @ 2025-09-10 5:56 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Tue, Sep 09, 2025 at 01:55:54PM -0700, Jakub Kicinski wrote:
> On Tue, 9 Sep 2025 19:52:21 +0530 Anwar, Md Danish wrote:
> > > + for (i = 0; i < size_in_words; i++)
> > > + msg[i] = mbx_data_rd32(mbx, MUCSE_MBX_FWPF_SHM + 4 * i);
> >
> > The array indexing calculation should use multiplication by sizeof(u32)
> > instead of hardcoded 4.
>
> Not sure this is really necessary, I'd expect C programmers to intuit
> that 4 is the number of bytes in u32 here. sizeof(u32) is going to
> overflow 80 char line limit and cause more harm than good.
>
I found similar code in other drivers, ixgbe, it like this:
#define IXGBE_READ_REG_ARRAY(a, reg, offset) \
ixgbe_read_reg((a), (reg) + ((offset) << 2))
for (i = 0; i < size; i++)
msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i);
Maybe I should follow that style?
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-09 20:58 ` Jakub Kicinski
@ 2025-09-10 6:08 ` Yibo Dong
2025-09-10 8:21 ` Jörg Sommer
2025-09-11 1:03 ` Jakub Kicinski
0 siblings, 2 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-10 6:08 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Tue, Sep 09, 2025 at 01:58:22PM -0700, Jakub Kicinski wrote:
> On Tue, 9 Sep 2025 19:59:11 +0530 Anwar, Md Danish wrote:
> > > +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;
> > > +}
> >
> > There's a logical issue in the code. The loop structure attempts to
> > retry on ETIMEDOUT errors, but the unconditional break statement after
> > the if-check will always exit the loop after the first attempt,
> > regardless of the error. The do-while loop will never actually retry
> > because the break statement is placed outside of the if condition that
> > checks for timeout errors.
>
What is expected is 'retry on ETIMEDOUT' and 'no retry others'.
https://lore.kernel.org/netdev/a066746c-2f12-4e70-b63a-7996392a9132@lunn.ch/
> The other way around. continue; in a do {} while () look does *not*
> evaluate the condition. So this can loop forever.
>
Maybe I can update like this ?
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)
break;
/* only retry with ETIMEDOUT, others just return */
} while (try_cnt--);
return err;
}
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev
2025-09-09 14:31 ` Anwar, Md Danish
@ 2025-09-10 6:10 ` Yibo Dong
0 siblings, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-10 6:10 UTC (permalink / raw)
To: Anwar, Md Danish
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 Tue, Sep 09, 2025 at 08:01:33PM +0530, Anwar, Md Danish wrote:
> On 9/9/2025 5:39 PM, Dong Yibo wrote:
> > Complete the network device (netdev) registration flow for Mucse Gbe
> > Ethernet chips, including:
> > 1. Hardware state initialization:
> > - Send powerup notification to firmware (via echo_fw_status)
> > - Sync with firmware
> > - Reset hardware
> > 2. MAC address handling:
> > - Retrieve permanent MAC from firmware (via mucse_mbx_get_macaddr)
> > - Fallback to random valid MAC (eth_random_addr) if not valid mac
> > from Fw
> >
> > Signed-off-by: Dong Yibo <dong100@mucse.com>
> > ---
>
> > +/**
> > + * 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;
> > +}
>
> The function comment says it returns NETDEV_TX_OK or NETDEV_TX_BUSY, but
> it only returns NETDEV_TX_OK.
>
>
Got it, I will fix it, and also check other functions.
> --
> Thanks and Regards,
> Md Danish Anwar
>
>
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev
2025-09-09 14:37 ` Vadim Fedorenko
@ 2025-09-10 6:22 ` Yibo Dong
0 siblings, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-10 6:22 UTC (permalink / raw)
To: Vadim Fedorenko
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 Tue, Sep 09, 2025 at 03:37:19PM +0100, Vadim Fedorenko wrote:
> On 09/09/2025 13:09, Dong Yibo wrote:
> > Complete the network device (netdev) registration flow for Mucse Gbe
> > Ethernet chips, including:
> > 1. Hardware state initialization:
> > - Send powerup notification to firmware (via echo_fw_status)
> > - Sync with firmware
> > - Reset hardware
> > 2. MAC address handling:
> > - Retrieve permanent MAC from firmware (via mucse_mbx_get_macaddr)
> > - Fallback to random valid MAC (eth_random_addr) if not valid mac
> > from Fw
> >
> > Signed-off-by: Dong Yibo <dong100@mucse.com>
>
> [...]
>
> > +struct mucse_hw;
>
> why do you need this forward declaration ...> +
> > +struct mucse_hw_operations {
> > + int (*reset_hw)(struct mucse_hw *hw);
> > + int (*get_perm_mac)(struct mucse_hw *hw);
> > + int (*mbx_send_notify)(struct mucse_hw *hw, bool enable, int mode);
> > +};
> > +
> > +enum {
> > + mucse_fw_powerup,
> > +};
> > +
> > struct mucse_hw {
> > void __iomem *hw_addr;
> > + struct pci_dev *pdev;
> > + const struct mucse_hw_operations *ops;
> > + struct mucse_dma_info dma;
> > struct mucse_mbx_info mbx;
> > + int port;
> > + u8 perm_addr[ETH_ALEN];
> > u8 pfvfnum;
> > };
>
> ... if you can simply move mucse_hw_operations down here?
>
Got it, I will update it. At the beginning I defined
'struct mucse_hw_operations ops' in 'struct mucse_hw'. I missed to
consider this when it is changed to 'struct mucse_hw_operations *ops'.
> > @@ -54,4 +76,7 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type);
> > #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))
>
> [...]
>
> > @@ -48,8 +127,14 @@ static void rnpgbe_init_n210(struct mucse_hw *hw)
> > **/
> > int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
> > {
> > + struct mucse_dma_info *dma = &hw->dma;
> > struct mucse_mbx_info *mbx = &hw->mbx;
> > + hw->ops = &rnpgbe_hw_ops;
> > + hw->port = 0;
> > +
> > + dma->dma_base_addr = hw->hw_addr;
>
> not quite sure why do you need additional structure just to store the
> value that already exists in mucse_hw?
>
The original meaning was that all submodules have their own base, such
as dma, mbx... Just that 'dma_base_addr' is 'offset 0 from hw_addr'.
And maybe it is not good to do it like this?
...
#define MUCSE_GBE_DMA_BASE 0
dma->dma_base_addr = hw->hw_addr + MUCSE_GBE_DMA_BASE;
...
If so, I will remove dma_base_addr, and use hw_addr instead.
> > +
> > mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
> > mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
>
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-10 6:08 ` Yibo Dong
@ 2025-09-10 8:21 ` Jörg Sommer
2025-09-11 1:46 ` Yibo Dong
2025-09-11 1:03 ` Jakub Kicinski
1 sibling, 1 reply; 25+ messages in thread
From: Jörg Sommer @ 2025-09-10 8:21 UTC (permalink / raw)
To: Yibo Dong
Cc: Jakub Kicinski, Anwar, Md Danish, andrew+netdev, davem, edumazet,
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
[-- Attachment #1: Type: text/plain, Size: 2115 bytes --]
Yibo Dong schrieb am Mi 10. Sep, 14:08 (+0800):
> On Tue, Sep 09, 2025 at 01:58:22PM -0700, Jakub Kicinski wrote:
> > On Tue, 9 Sep 2025 19:59:11 +0530 Anwar, Md Danish wrote:
> > > > +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;
> > > > +}
> > >
> > > There's a logical issue in the code. The loop structure attempts to
> > > retry on ETIMEDOUT errors, but the unconditional break statement after
> > > the if-check will always exit the loop after the first attempt,
> > > regardless of the error. The do-while loop will never actually retry
> > > because the break statement is placed outside of the if condition that
> > > checks for timeout errors.
> >
>
> What is expected is 'retry on ETIMEDOUT' and 'no retry others'.
> https://lore.kernel.org/netdev/a066746c-2f12-4e70-b63a-7996392a9132@lunn.ch/
>
> > The other way around. continue; in a do {} while () look does *not*
> > evaluate the condition. So this can loop forever.
> >
>
> Maybe I can update like this ?
>
> 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)
> break;
> /* only retry with ETIMEDOUT, others just return */
> } while (try_cnt--);
>
> return err;
> }
How about something like this?
int mucse_mbx_sync_fw(struct mucse_hw *hw)
{
for (int try = 3; try; --try) {
int err = mucse_mbx_get_info(hw);
if (err != -ETIMEDOUT)
return err;
}
return ETIMEDOUT;
}
My 2cent.
Regards Jörg
--
„Es wurden und werden zu viele sprachlose Bücher gedruckt, nach deren
schon flüchtiger Lektüre man all die Bäume um Vergebung bitten möchte,
die für den Schund ihr Leben lassen mussten.“ (Michael Jürgs,
Seichtgebiete – Warum wir hemmungslos verblöden)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-10 5:56 ` Yibo Dong
@ 2025-09-11 1:02 ` Jakub Kicinski
2025-09-11 1:38 ` Yibo Dong
0 siblings, 1 reply; 25+ messages in thread
From: Jakub Kicinski @ 2025-09-11 1:02 UTC (permalink / raw)
To: Yibo Dong
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Wed, 10 Sep 2025 13:56:36 +0800 Yibo Dong wrote:
> > Not sure this is really necessary, I'd expect C programmers to intuit
> > that 4 is the number of bytes in u32 here. sizeof(u32) is going to
> > overflow 80 char line limit and cause more harm than good.
> >
>
> I found similar code in other drivers, ixgbe, it like this:
>
> #define IXGBE_READ_REG_ARRAY(a, reg, offset) \
> ixgbe_read_reg((a), (reg) + ((offset) << 2))
>
> for (i = 0; i < size; i++)
> msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i);
>
> Maybe I should follow that style?
Personal preference at this stage, but I like your code more.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-10 6:08 ` Yibo Dong
2025-09-10 8:21 ` Jörg Sommer
@ 2025-09-11 1:03 ` Jakub Kicinski
2025-09-11 1:41 ` Yibo Dong
1 sibling, 1 reply; 25+ messages in thread
From: Jakub Kicinski @ 2025-09-11 1:03 UTC (permalink / raw)
To: Yibo Dong
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Wed, 10 Sep 2025 14:08:21 +0800 Yibo Dong wrote:
> do {
> err = mucse_mbx_get_info(hw);
> if (err != -ETIMEDOUT)
> break;
> /* only retry with ETIMEDOUT, others just return */
> } while (try_cnt--);
do {
err = bla();
} while (err == -ETIMEDOUT && try_cnt--);
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support
2025-09-11 1:02 ` Jakub Kicinski
@ 2025-09-11 1:38 ` Yibo Dong
0 siblings, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-11 1:38 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Wed, Sep 10, 2025 at 06:02:07PM -0700, Jakub Kicinski wrote:
> On Wed, 10 Sep 2025 13:56:36 +0800 Yibo Dong wrote:
> > > Not sure this is really necessary, I'd expect C programmers to intuit
> > > that 4 is the number of bytes in u32 here. sizeof(u32) is going to
> > > overflow 80 char line limit and cause more harm than good.
> > >
> >
> > I found similar code in other drivers, ixgbe, it like this:
> >
> > #define IXGBE_READ_REG_ARRAY(a, reg, offset) \
> > ixgbe_read_reg((a), (reg) + ((offset) << 2))
> >
> > for (i = 0; i < size; i++)
> > msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i);
> >
> > Maybe I should follow that style?
>
> Personal preference at this stage, but I like your code more.
>
Ok, then I'll keep this code as it is.
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-11 1:03 ` Jakub Kicinski
@ 2025-09-11 1:41 ` Yibo Dong
0 siblings, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-11 1:41 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Anwar, Md Danish, andrew+netdev, davem, edumazet, 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 Wed, Sep 10, 2025 at 06:03:34PM -0700, Jakub Kicinski wrote:
> On Wed, 10 Sep 2025 14:08:21 +0800 Yibo Dong wrote:
> > do {
> > err = mucse_mbx_get_info(hw);
> > if (err != -ETIMEDOUT)
> > break;
> > /* only retry with ETIMEDOUT, others just return */
> > } while (try_cnt--);
>
> do {
> err = bla();
> } while (err == -ETIMEDOUT && try_cnt--);
>
Got it, I will fix it in next version.
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support
2025-09-10 8:21 ` Jörg Sommer
@ 2025-09-11 1:46 ` Yibo Dong
0 siblings, 0 replies; 25+ messages in thread
From: Yibo Dong @ 2025-09-11 1:46 UTC (permalink / raw)
To: Jörg Sommer
Cc: Jakub Kicinski, Anwar, Md Danish, andrew+netdev, davem, edumazet,
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 Wed, Sep 10, 2025 at 10:21:58AM +0200, Jörg Sommer wrote:
> Yibo Dong schrieb am Mi 10. Sep, 14:08 (+0800):
> > On Tue, Sep 09, 2025 at 01:58:22PM -0700, Jakub Kicinski wrote:
> > > On Tue, 9 Sep 2025 19:59:11 +0530 Anwar, Md Danish wrote:
> > > > > +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;
> > > > > +}
> > > >
> > > > There's a logical issue in the code. The loop structure attempts to
> > > > retry on ETIMEDOUT errors, but the unconditional break statement after
> > > > the if-check will always exit the loop after the first attempt,
> > > > regardless of the error. The do-while loop will never actually retry
> > > > because the break statement is placed outside of the if condition that
> > > > checks for timeout errors.
> > >
> >
> > What is expected is 'retry on ETIMEDOUT' and 'no retry others'.
> > https://lore.kernel.org/netdev/a066746c-2f12-4e70-b63a-7996392a9132@lunn.ch/
> >
> > > The other way around. continue; in a do {} while () look does *not*
> > > evaluate the condition. So this can loop forever.
> > >
> >
> > Maybe I can update like this ?
> >
> > 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)
> > break;
> > /* only retry with ETIMEDOUT, others just return */
> > } while (try_cnt--);
> >
> > return err;
> > }
>
> How about something like this?
>
> int mucse_mbx_sync_fw(struct mucse_hw *hw)
> {
> for (int try = 3; try; --try) {
> int err = mucse_mbx_get_info(hw);
> if (err != -ETIMEDOUT)
> return err;
> }
>
> return ETIMEDOUT;
> }
>
I think Jakub Kicinski's suggestion is clearer, right?
do {
err = mucse_mbx_get_info(hw);
} while (err == -ETIMEDOUT && try_cnt--);
>
> My 2cent.
>
> Regards Jörg
>
> --
> „Es wurden und werden zu viele sprachlose Bücher gedruckt, nach deren
> schon flüchtiger Lektüre man all die Bäume um Vergebung bitten möchte,
> die für den Schund ihr Leben lassen mussten.“ (Michael Jürgs,
> Seichtgebiete – Warum wir hemmungslos verblöden)
Thanks for your feedback.
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2025-09-11 1:46 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 12:09 [PATCH net-next v11 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-09-09 12:09 ` [PATCH net-next v11 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-09-09 12:37 ` Vadim Fedorenko
2025-09-09 12:09 ` [PATCH net-next v11 2/5] net: rnpgbe: Add n500/n210 chip support with BAR2 mapping Dong Yibo
2025-09-09 12:41 ` Vadim Fedorenko
2025-09-09 12:09 ` [PATCH net-next v11 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-09-09 14:22 ` Anwar, Md Danish
2025-09-09 20:55 ` Jakub Kicinski
2025-09-10 5:56 ` Yibo Dong
2025-09-11 1:02 ` Jakub Kicinski
2025-09-11 1:38 ` Yibo Dong
2025-09-10 5:52 ` Yibo Dong
2025-09-09 12:09 ` [PATCH net-next v11 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-09-09 14:29 ` Anwar, Md Danish
2025-09-09 20:58 ` Jakub Kicinski
2025-09-10 6:08 ` Yibo Dong
2025-09-10 8:21 ` Jörg Sommer
2025-09-11 1:46 ` Yibo Dong
2025-09-11 1:03 ` Jakub Kicinski
2025-09-11 1:41 ` Yibo Dong
2025-09-09 12:09 ` [PATCH net-next v11 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-09-09 14:31 ` Anwar, Md Danish
2025-09-10 6:10 ` Yibo Dong
2025-09-09 14:37 ` Vadim Fedorenko
2025-09-10 6:22 ` Yibo Dong
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).