Skip to contentSkip to conversation

Add Mellanox BlueField Gigabit Ethernet driver

PATCH Superseded David Thompson 3 participants 4 messages Nov 17, 2020 – Nov 18, 2020

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Add Mellanox BlueField Gigabit Ethernet driver

This patch adds build and driver logic for the "mlxbf_gige" Ethernet driver from Mellanox Technologies. The second generation BlueField SoC from Mellanox supports an out-of-band GigaBit Ethernet management port to the Arm subsystem. This driver supports TCP/IP network connectivity for that port, and provides back-end routines to handle basic ethtool requests.

The logic in "mlxbf_gige_main.c" is the driver performing packet processing and handling ethtool management requests. The driver interfaces to the Gigabit Ethernet block of BlueField SoC via MMIO accesses to registers, which contain control information or pointers describing transmit and receive resources. There is a single transmit queue, and the port supports transmit ring sizes of 4 to 256 entries. There is a single receive queue, and the port supports receive ring sizes of 32 to 32K entries. The transmit and receive rings are allocated from DMA coherent memory. There is a 16-bit producer and consumer index per ring to denote software ownership and hardware ownership, respectively. The main driver supports the handling of some basic ethtool
requests: get driver info, get/set ring parameters, get registers, and get statistics.

The logic in "mlxbf_gige_mdio.c" is the driver controlling the Mellanox BlueField hardware that interacts with a PHY device via MDIO/MDC pins. This driver does the following:
- At driver probe time, it configures several BlueField MDIO parameters such as sample rate, full drive, voltage and MDC
- It defines functions to read and write MDIO registers and registers the MDIO bus.
- It defines the phy interrupt handler reporting a link up/down status change
- This driver's probe is invoked from the main driver logic while the phy interrupt handler is registered in ndo_open.

Driver limitations
- Only supports 1Gbps speed
- Only supports GMII protocol
- Supports maximum packet size of 2KB
- Does not support scatter-gather buffering

Testing
- Successful build of kernel for ARM64, ARM32, X86_64
- Tested ARM64 build on FastModels & Palladium
- Tested ARM64 build on several Mellanox boards that are built with the BlueField-2 SoC. The testing includes coverage in the areas of networking (e.g. ping, iperf, ifconfig, route), file transfers (e.g. SCP), and various ethtool options relevant to this driver.

v2 -> v3
Added logic to handle PHY link up/down interrupts
Use streaming DMA mapping for packet buffers
Changed logic to use standard iopoll methods
Changed PHY logic to not allow C45 transactions
Enhanced the error handling in open() method
Enhanced start_xmit() method to use xmit_more mechanism Added support for ndo_get_stats64
Removed standard stats from "ethtool -S" output
v1 -> v2:
Fixed all warnings raised by "make C=1" and "make W=1"
a) Changed logic in mlxbf_gige_rx_deinit() and mlxbf_gige_tx_deinit() to initialize relevant pointers as NULL, not 0
b) Change mlxbf_gige_get_mac_rx_filter() to return void, as this function's return status is not used by caller
c) Fixed type definition of "buff" in mlxbf_gige_get_regs()

---
 drivers/net/ethernet/mellanox/Kconfig              |    1 +
 drivers/net/ethernet/mellanox/Makefile             |    1 +
 drivers/net/ethernet/mellanox/mlxbf_gige/Kconfig   |   13 +
 drivers/net/ethernet/mellanox/mlxbf_gige/Makefile  |    5 +
 .../net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h  |  159 +++
 .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c | 1292 ++++++++++++++++++++
 .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c |  286 +++++
 .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_regs.h |   78 ++
 8 files changed, 1835 insertions(+)
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/Kconfig
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/Makefile
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c
 create mode 100644 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_regs.h
drivers/net/ethernet/mellanox/Kconfig +1 -0
index ff6613a..b4f66eb 100644
@@ -22,5 +22,6 @@ source "drivers/net/ethernet/mellanox/mlx4/Kconfig"
 source "drivers/net/ethernet/mellanox/mlx5/core/Kconfig"
 source "drivers/net/ethernet/mellanox/mlxsw/Kconfig"
 source "drivers/net/ethernet/mellanox/mlxfw/Kconfig"
+source "drivers/net/ethernet/mellanox/mlxbf_gige/Kconfig"
 
 endif # NET_VENDOR_MELLANOX
drivers/net/ethernet/mellanox/Makefile +1 -0
index 79773ac..d4b5f54 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_MLX4_CORE) += mlx4/
 obj-$(CONFIG_MLX5_CORE) += mlx5/core/
 obj-$(CONFIG_MLXSW_CORE) += mlxsw/
 obj-$(CONFIG_MLXFW) += mlxfw/
+obj-$(CONFIG_MLXBF_GIGE) += mlxbf_gige/
drivers/net/ethernet/mellanox/mlxbf_gige/Kconfig new file +13 -0
new file mode 100644
index 0000000..08a4487
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
+#
+# Mellanox GigE driver configuration
+#
+
+config MLXBF_GIGE
+	tristate "Mellanox Technologies BlueField Gigabit Ethernet support"
+	depends on (ARM64 || COMPILE_TEST) && ACPI
+	select PHYLIB
+	help
+	  The second generation BlueField SoC from Mellanox Technologies
+	  supports an out-of-band Gigabit Ethernet management port to the
+	  Arm subsystem.
drivers/net/ethernet/mellanox/mlxbf_gige/Makefile new file +5 -0
new file mode 100644
index 0000000..e99fc19
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
+
+obj-$(CONFIG_MLXBF_GIGE) += mlxbf_gige.o
+
+mlxbf_gige-y := mlxbf_gige_main.o mlxbf_gige_mdio.o
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h new file +159 -0

159 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +1292 -0

1,293 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c new file +286 -0

286 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_regs.h new file +78 -0

78 lines not on this page · raw message

Signature · 1 line
2.1.2
#1 lore raw

Hi David

Quoted 21 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +21 -0
+static int mlxbf_gige_phy_enable_interrupt(struct phy_device *phydev)
+{
+	int err = 0;
+
+	if (phydev->drv->ack_interrupt)
+		err = phydev->drv->ack_interrupt(phydev);
+	if (err < 0)
+		return err;
+
+	phydev->interrupts = PHY_INTERRUPT_ENABLED;
+	if (phydev->drv->config_intr)
+		err = phydev->drv->config_intr(phydev);
+
+	return err;
+}
+
+static int mlxbf_gige_phy_disable_interrupt(struct phy_device *phydev)
+{
+	int err = 0;
+
+	if (phydev->drv->ack_interrupt)

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c line 856

Quoted 10 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +10 -0
+		err = phydev->drv->ack_interrupt(phydev);
+	if (err < 0)
+		return err;
+
+	phydev->interrupts = PHY_INTERRUPT_DISABLED;
+	if (phydev->drv->config_intr)
+		err = phydev->drv->config_intr(phydev);
+
+	return err;
+}

This is, erm, interesting.

Quoted 25 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c new file +25 -0
+irqreturn_t mlxbf_gige_mdio_handle_phy_interrupt(int irq, void *dev_id)
+{
+	struct phy_device *phydev;
+	struct mlxbf_gige *priv;
+	u32 val;
+
+	priv = dev_id;
+	phydev = priv->netdev->phydev;
+
+	/* Check if this interrupt is from PHY device.
+	 * Return if it is not.
+	 */
+	val = readl(priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CAUSE_EVTEN0);
+	if (!(val & MLXBF_GIGE_CAUSE_OR_CAUSE_EVTEN0_MASK))
+		return IRQ_NONE;
+
+	phy_mac_interrupt(phydev);
+
+	/* Clear interrupt when done, otherwise, no further interrupt
+	 * will be triggered.
+	 */
+	val = readl(priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CLRCAUSE);
+	val |= MLXBF_GIGE_CAUSE_OR_CLRCAUSE_MASK;

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c line 228

Quoted 10 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c new file +10 -0
+	writel(val, priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CLRCAUSE);
+
+	/* Make sure to clear the PHY device interrupt */
+	if (phydev->drv->ack_interrupt)
+		phydev->drv->ack_interrupt(phydev);
+
+	phydev->interrupts = PHY_INTERRUPT_ENABLED;
+	if (phydev->drv->config_intr)
+		phydev->drv->config_intr(phydev);

And more interesting code.

We have to find a better way to do this, you should not by copying core PHY code into a MAC driver.

So it seems to me, the PHY interrupt you request is not actually a PHY interrupt. It looks more like an interrupt controller. The EVTEN0 suggests that there could be multiple interrupts here, of which one if the PHY? This is more a generic GPIO block which can do interrupts when the pins are configured as inputs? Or is it an interrupt controller with multiple interrupts?

Once you model this correctly in Linux, you can probably remove all the interesting code.

Andrew

#2 lore raw

Hi Andrew,

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +7 -0
+static int mlxbf_gige_phy_enable_interrupt(struct phy_device *phydev)
+{
+	int err = 0;
+
+	if (phydev->drv->ack_interrupt)
+		err = phydev->drv->ack_interrupt(phydev);
+	if (err < 0)
Quoted 8 lines

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c line 840

Quoted 8 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +8 -0
+		return err;
+
+	phydev->interrupts = PHY_INTERRUPT_ENABLED;
+	if (phydev->drv->config_intr)
+		err = phydev->drv->config_intr(phydev);
+
+	return err;
+}

We actually just need to make sure here, the PHY INT register is still configured properly. mlxbf_gige_phy_enable_interrupt is called right after phy_start because the PHY INT controller/status register gets cleared out after phy_start due to the call to __phy_resume. Because it gets cleared, the PHY no longer reports any interrupts.

Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +8 -0
+
+static int mlxbf_gige_phy_disable_interrupt(struct phy_device
+*phydev) {
+	int err = 0;
+
+	if (phydev->drv->ack_interrupt)
+		err = phydev->drv->ack_interrupt(phydev);
+	if (err < 0)
Quoted 9 lines

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c line 856

Quoted 8 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c new file +8 -0
+		return err;
+
+	phydev->interrupts = PHY_INTERRUPT_DISABLED;
+	if (phydev->drv->config_intr)
+		err = phydev->drv->config_intr(phydev);
+
+	return err;
+}

We need to call mlxbf_gige_phy_disable_interrupt from the stop routine because if we leave it enabled, and decide to call the ndo_open routine after, the interrupt coming from the PHY will be discarded until the PHY state machine is setup properly (via phy_start).

Quoted 29 lines

This is, erm, interesting.

Quoted 27 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c new file +27 -0
+irqreturn_t mlxbf_gige_mdio_handle_phy_interrupt(int irq, void
+*dev_id) {
+	struct phy_device *phydev;
+	struct mlxbf_gige *priv;
+	u32 val;
+
+	priv = dev_id;
+	phydev = priv->netdev->phydev;
+
+	/* Check if this interrupt is from PHY device.
+	 * Return if it is not.
+	 */
+	val = readl(priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CAUSE_EVTEN0);
+	if (!(val & MLXBF_GIGE_CAUSE_OR_CAUSE_EVTEN0_MASK))
+		return IRQ_NONE;
+
+	phy_mac_interrupt(phydev);
+
+	/* Clear interrupt when done, otherwise, no further interrupt
+	 * will be triggered.
+	 */
+	val = readl(priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CLRCAUSE);
+	val |= MLXBF_GIGE_CAUSE_OR_CLRCAUSE_MASK;
+	writel(val, priv->gpio_io +
+			MLXBF_GIGE_GPIO_CAUSE_OR_CLRCAUSE);
Quoted 9 lines

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c line 228

Quoted 8 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_mdio.c new file +8 -0
+
+	/* Make sure to clear the PHY device interrupt */
+	if (phydev->drv->ack_interrupt)
+		phydev->drv->ack_interrupt(phydev);
+
+	phydev->interrupts = PHY_INTERRUPT_ENABLED;
+	if (phydev->drv->config_intr)
+		phydev->drv->config_intr(phydev);

Yes mlxbf_gige_mdio_handle_phy_interrupt is used to check whether the interrupt is coming from GPIO12 (which is set in HW as the PHY INT_N pin). There is one HW interrupt line (here defined as MLXBF_GIGE_PHY_INT_N) shared among all the GPIOs and other components (like I2C). Now you mentioned that we should not be copying core PHY code. Ack_interrupt needs to be called here to make sure we clear the interrupt after clearing the Mellanox HW interrupt MLXBF_GIGE_PHY_INT_N. and config_intr needs to be called because phy_mac_interrupt causes the PHY device to clear the PHY INT enable bits.

Quoted 15 lines

And more interesting code.

We have to find a better way to do this, you should not by copying core PHY code into a MAC driver.

So it seems to me, the PHY interrupt you request is not actually a PHY interrupt. It looks more like an interrupt controller. The EVTEN0 suggests that there could be multiple interrupts here, of which one if the PHY? This is more a generic GPIO block which can do interrupts when the pins are configured as inputs? Or is it an interrupt controller with multiple interrupts?

Once you model this correctly in Linux, you can probably remove all the interesting code.

Andrew

#3 lore raw
Quoted 5 lines

Yes mlxbf_gige_mdio_handle_phy_interrupt is used to check whether the interrupt is coming from GPIO12 (which is set in HW as the PHY INT_N pin). There is one HW interrupt line (here defined as MLXBF_GIGE_PHY_INT_N) shared among all the GPIOs and other components (like I2C).

So this is the key thing here. You have an interrupt controller, where as the PHY subsystem wants a plain interrupt. Give the PHY subsystem a plain interrupt, and it will do all the calls to configure the PHY, enable interrupts in the PHY etc.

There is nothing stopping you have an interrupt controller inside an Ethernet driver, or any other sort of driver. Take for example:

https://elixir.bootlin.com/linux/v5.10-rc4/source/drivers/net/dsa/mv88e6xxx/chip.c#L127

The Marvell Ethernet switches also have an interrupt controller. Actually they have two nested controllers. This code registers an irq domain with the linux core, so that the individual interrupt sources can be used as just plain old Linux interrupts. The irqdomain is responsible to masking and unmasking interrupts, in the interrupt controller.

The end user of these interrupts, then just request them in the usual way:

https://elixir.bootlin.com/linux/v5.10-rc4/source/drivers/net/dsa/mv88e6xxx/global1_atu.c#L419

So in your case, map the PHY interrupt in this domain, and pass it to the PHY subsystem.

Andrew