Commit 6139d8f2 authored by Josua Mayer's avatar Josua Mayer

linux: add support for link-status LEDs to dpmac objects

To allow reliable link-status indication when exporting native
interfaces to dpdk, add support for controlling an LED to dpmac driver
link up- and down- functions.

Note that this is a hack and not a proper solution - with its own
particular shortcomings. Most notable is the lack of status indication
while Linux is controlling the interface through the dpaa2 ethernet
driver!
Signed-off-by: default avatarJosua Mayer <josua@solid-run.com>
parent bd2d3fd7
From cd9771eaa89a4d46fc2c94655890f39d39984aae Mon Sep 17 00:00:00 2001
From: Josua Mayer <josua@solid-run.com>
Date: Mon, 26 Sep 2022 13:13:06 +0300
Subject: [PATCH 24/25] dpaa2-mac: support assigning status LEDs to dpmac
instances
This is an alternative hack sidestepping the led trigger framework.
It updates link status on the LEDs from the viewpoint of the MAC - which
is the only Linux object still alive e.g. when binding ports to dpdk, or
a virtual machine.
Signed-off-by: Josua Mayer <josua@solid-run.com>
---
.../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 51 +++++++++++++++++++
.../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 2 +
2 files changed, 53 insertions(+)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index c46d29e28582..2ec4c940dc99 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -6,6 +6,7 @@
#include <linux/acpi.h>
#include <linux/phy/phy.h>
#include <linux/property.h>
+#include <linux/leds.h>
#include "dpaa2-eth.h"
#include "dpaa2-mac.h"
@@ -239,6 +240,9 @@ static void dpaa2_mac_link_up(struct phylink_config *config,
if (err)
netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n",
__func__, err);
+
+ if (mac->link_status_led)
+ led_set_brightness(mac->link_status_led, mac->link_status_led->max_brightness);
}
static void dpaa2_mac_link_down(struct phylink_config *config,
@@ -254,6 +258,9 @@ static void dpaa2_mac_link_down(struct phylink_config *config,
mac->mc_dev->mc_handle, dpmac_state);
if (err)
netdev_err(mac->net_dev, "dpmac_set_link_state() = %d\n", err);
+
+ if (mac->link_status_led)
+ led_set_brightness(mac->link_status_led, LED_OFF);
}
static int dpaa2_mac_prepare(struct phylink_config *config, unsigned int mode,
@@ -894,6 +901,28 @@ static int dpaa2_mac_probe(struct fsl_mc_device *mc_dev)
if (err)
goto free_portal;
+ if (is_of_node(priv->fw_node)) {
+ struct device_node *np;
+
+ np = of_parse_phandle(to_of_node(priv->fw_node), "link-status-led", 0);
+ priv->link_status_led = of_led_get_hack(np);
+ of_node_put(np);
+
+ if (IS_ERR(priv->link_status_led)) {
+ err = PTR_ERR(priv->link_status_led);
+ switch (err) {
+ case -ENODEV:
+ priv->link_status_led = NULL;
+ break;
+ default:
+ dev_err(dev, "failed to get link-status led from 'link-status-led' property: %pe\n", priv->link_status_led);
+ fallthrough;
+ case -EPROBE_DEFER:
+ goto free_portal;
+ };
+ }
+ }
+
if (dpaa2_mac_is_type_phy(priv)) {
err = dpaa2_mac_connect(priv);
if (err) {
@@ -902,6 +931,21 @@ static int dpaa2_mac_probe(struct fsl_mc_device *mc_dev)
}
}
+ if (priv->link_status_led) {
+ mutex_lock(&priv->link_status_led->led_access);
+
+ /* remove from sysfs to avoid userspce control */
+ led_sysfs_disable(priv->link_status_led);
+
+ /* remove triggers, if any */
+ led_trigger_remove(priv->link_status_led);
+
+ mutex_unlock(&priv->link_status_led->led_access);
+
+ /* turn off initially */
+ led_set_brightness(priv->link_status_led, LED_OFF);
+ }
+
return 0;
free_portal:
fsl_mc_portal_free(mc_dev->mc_io);
@@ -921,6 +965,13 @@ static int dpaa2_mac_remove(struct fsl_mc_device *mc_dev)
struct net_device *net_dev = dev_get_drvdata(dev);
struct dpaa2_mac *priv = netdev_priv(net_dev);
+ if (priv->link_status_led) {
+ /* re-enable sysfs interface */
+ mutex_lock(&priv->link_status_led->led_access);
+ led_sysfs_enable(priv->link_status_led);
+ mutex_unlock(&priv->link_status_led->led_access);
+ }
+
dpaa2_mac_teardown_irqs(mc_dev);
if (dpaa2_mac_is_type_phy(priv)) {
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
index 5f1a500b503a..60086fc9c985 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
@@ -29,6 +29,8 @@ struct dpaa2_mac {
struct phy *serdes_phy;
void __iomem *if_mode_reg;
+
+ struct led_classdev *link_status_led;
};
bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev,
--
2.37.3
From 2ea0cb8ad697cb9954cf1e221b78f6a2d319ca7b Mon Sep 17 00:00:00 2001
From: Josua Mayer <josua@solid-run.com>
Date: Mon, 26 Sep 2022 13:05:17 +0300
Subject: [PATCH 25/25] arm64: dts: lx2160a-half-twins: link sfp cage leds to
dpmac nodes
Signed-off-by: Josua Mayer <josua@solid-run.com>
---
.../dts/freescale/fsl-lx2160a-half-twins.dts | 32 +++++++++----------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a-half-twins.dts b/arch/arm64/boot/dts/freescale/fsl-lx2160a-half-twins.dts
index 7907507b3ea5..5c3905f28b46 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a-half-twins.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a-half-twins.dts
@@ -160,112 +160,96 @@ c1_at_sfp: c1-at-sfp {
i2c-bus = <&twins_sfp_c1_at_i2c>;
mod-def0-gpio = <&expander0 1 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c1_at>;
};
c1_ab_sfp: c1-ab-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c1_ab_i2c>;
mod-def0-gpio = <&expander0 2 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c1_ab>;
};
c1_bt_sfp: c1-bt-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c1_bt_i2c>;
mod-def0-gpio = <&expander0 3 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c1_bt>;
};
c1_bb_sfp: c1-bb-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c1_bb_i2c>;
mod-def0-gpio = <&expander0 4 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c1_bb>;
};
c2_at_sfp: c2-at-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c2_at_i2c>;
mod-def0-gpio = <&expander0 5 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c2_at>;
};
c2_ab_sfp: c2-ab-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c2_ab_i2c>;
mod-def0-gpio = <&expander0 6 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c2_ab>;
};
c2_bt_sfp: c2-bt-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c2_bt_i2c>;
mod-def0-gpio = <&expander0 9 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c2_bt>;
};
c2_bb_sfp: c2-bb-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c2_bb_i2c>;
mod-def0-gpio = <&expander0 10 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c2_bb>;
};
c3_at_sfp: c3-at-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c3_at_i2c>;
mod-def0-gpio = <&expander0 11 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c3_at>;
};
c3_ab_sfp: c3-ab-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c3_ab_i2c>;
mod-def0-gpio = <&expander0 12 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c3_ab>;
};
c3_bt_sfp: c3-bt-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c3_bt_i2c>;
mod-def0-gpio = <&expander0 13 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c3_bt>;
};
c3_bb_sfp: c3-bb-sfp {
compatible = "sff,sfp";
i2c-bus = <&twins_sfp_c3_bb_i2c>;
mod-def0-gpio = <&expander0 14 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_c3_bb>;
};
ht_c3_at_sfp: ht-c3-at-sfp {
compatible = "sff,sfp";
i2c-bus = <&htwins_sfp_c3_at_i2c>;
mod-def0-gpio = <&expander2 11 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_ht_c3_at>;
};
ht_c3_ab_sfp: ht-c3-ab-sfp {
compatible = "sff,sfp";
i2c-bus = <&htwins_sfp_c3_ab_i2c>;
mod-def0-gpio = <&expander2 12 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_ht_c3_ab>;
};
ht_c3_bt_sfp: ht-c3-bt-sfp {
compatible = "sff,sfp";
i2c-bus = <&htwins_sfp_c3_bt_i2c>;
mod-def0-gpio = <&expander2 13 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_ht_c3_bt>;
};
ht_c3_bb_sfp: ht-c3-bb-sfp {
compatible = "sff,sfp";
i2c-bus = <&htwins_sfp_c3_bb_i2c>;
mod-def0-gpio = <&expander2 14 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <2000>;
- link-status-led = <&led_ht_c3_bb>;
};
leds {
compatible = "gpio-leds";
@@ -341,75 +325,89 @@ &dpmac3 {
sfp = <&c1_at_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_h>;
+ link-status-led = <&led_c1_at>;
};
&dpmac4 {
sfp = <&c1_bt_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_g>;
+ link-status-led = <&led_c1_bt>;
};
&dpmac5 {
sfp = <&ht_c3_bt_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_f>;
+ link-status-led = <&led_ht_c3_bt>;
};
&dpmac6 {
sfp = <&ht_c3_at_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_e>;
+ link-status-led = <&led_ht_c3_at>;
};
&dpmac7 {
sfp = <&c2_at_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_d>;
+ link-status-led = <&led_c2_at>;
};
&dpmac8 {
sfp = <&c2_bt_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_c>;
+ link-status-led = <&led_c2_bt>;
};
&dpmac9 {
sfp = <&c3_at_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_b>;
+ link-status-led = <&led_c3_at>;
};
&dpmac10 {
sfp = <&c3_bt_sfp>;
managed = "in-band-status";
phys = <&serdes1_lane_a>;
+ link-status-led = <&led_c3_bt>;
};
/* SD2 lanes #0.. #7 */
&dpmac11 {
sfp = <&ht_c3_ab_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_a>;
+ link-status-led = <&led_ht_c3_ab>;
};
&dpmac12 {
sfp = <&c1_ab_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_b>;
+ link-status-led = <&led_c1_ab>;
};
&dpmac13 { // ok
sfp = <&c3_ab_sfp>;
managed = "in-band-status";
phy-mode = "sgmii";
phys = <&serdes2_lane_g>;
+ link-status-led = <&led_c3_ab>;
};
&dpmac14 { // ok
sfp = <&c3_bb_sfp>;
managed = "in-band-status";
phy-mode = "sgmii";
phys = <&serdes2_lane_h>;
+ link-status-led = <&led_c3_bb>;
};
&dpmac15 {
sfp = <&ht_c3_bb_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_e>;
+ link-status-led = <&led_ht_c3_bb>;
};
&dpmac16 {
sfp = <&c2_bb_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_f>;
+ link-status-led = <&led_c2_bb>;
};
&dpmac17 {
/delete-property/ phy-handle;
@@ -417,11 +415,13 @@ &dpmac17 {
sfp = <&c1_bb_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_c>;
+ link-status-led = <&led_c1_bb>;
};
&dpmac18 {
sfp = <&c2_ab_sfp>;
managed = "in-band-status";
phys = <&serdes2_lane_d>;
+ link-status-led = <&led_c2_ab>;
};
&emdio1 {
--
2.37.3
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment