Skip to contentSkip to conversation

tx/rx LED trigger support

PATCH Superseded Fabio Baltieri 4 participants 19 messages Dec 16, 2012 – Dec 18, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#8 lore raw

PATCH 2/9 can: flexcan: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on flexcan devices by calling appropriate can_led_* functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Oliver Hartkopp <[email protected]>
Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/flexcan.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/can/flexcan.c +11 -0
index 0289a6d..769d29e 100644
@@ -23,6 +23,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
@@ -564,6 +565,8 @@ static int flexcan_read_frame(struct net_device *dev)
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
 
+	can_led_event(dev, CAN_LED_EVENT_RX);
+
 	return 1;
 }
 
@@ -652,6 +655,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	if (reg_iflag1 & (1 << FLEXCAN_TX_BUF_ID)) {
 		stats->tx_bytes += can_get_echo_skb(dev, 0);
 		stats->tx_packets++;
+		can_led_event(dev, CAN_LED_EVENT_TX);
 		flexcan_write((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1);
 		netif_wake_queue(dev);
 	}
@@ -865,6 +869,9 @@ static int flexcan_open(struct net_device *dev)
 	err = flexcan_chip_start(dev);
 	if (err)
 		goto out_close;
+
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	napi_enable(&priv->napi);
 	netif_start_queue(dev);
 
@@ -893,6 +900,8 @@ static int flexcan_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1092,6 +1101,8 @@ static int flexcan_probe(struct platform_device *pdev)
 		goto failed_register;
 	}
 
+	devm_can_led_init(dev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->base, dev->irq);
 
Signature · 1 line
1.7.12.1
#10 lore raw

PATCH 4/9 can: ti_hecc: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on ti_hecc devices by calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Anant Gole <[email protected]>
Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/ti_hecc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/can/ti_hecc.c +10 -0
index f898c63..f52a975 100644
@@ -50,6 +50,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/ti_hecc.h>
 
 #define DRV_NAME "ti_hecc"
@@ -593,6 +594,7 @@ static int ti_hecc_rx_pkt(struct ti_hecc_priv *priv, int mbxno)
 	spin_unlock_irqrestore(&priv->mbx_lock, flags);
 
 	stats->rx_bytes += cf->can_dlc;
+	can_led_event(priv->ndev, CAN_LED_EVENT_RX);
 	netif_receive_skb(skb);
 	stats->rx_packets++;
 
@@ -796,6 +798,7 @@ static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)
 			stats->tx_bytes += hecc_read_mbx(priv, mbxno,
 						HECC_CANMCF) & 0xF;
 			stats->tx_packets++;
+			can_led_event(ndev, CAN_LED_EVENT_TX);
 			can_get_echo_skb(ndev, mbxno);
 			--priv->tx_tail;
 		}
@@ -851,6 +854,8 @@ static int ti_hecc_open(struct net_device *ndev)
 		return err;
 	}
 
+	can_led_event(ndev, CAN_LED_EVENT_OPEN);
+
 	ti_hecc_start(ndev);
 	napi_enable(&priv->napi);
 	netif_start_queue(ndev);
@@ -869,6 +874,8 @@ static int ti_hecc_close(struct net_device *ndev)
 	close_candev(ndev);
 	ti_hecc_transceiver_switch(priv, 0);
 
+	can_led_event(ndev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -961,6 +968,9 @@ static int ti_hecc_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "register_candev() failed\n");
 		goto probe_exit_clk;
 	}
+
+	devm_can_led_init(ndev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%u)\n",
 		priv->base, (u32) ndev->irq);
 
Signature · 1 line
1.7.12.1
#12 lore raw

PATCH 6/9 can: mcp251x: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on mcp251x devices by calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Christian Pellegrin <[email protected]>
Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/mcp251x.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/net/can/mcp251x.c +19 -4
index 5eaf47b..f32b9fc 100644
@@ -60,6 +60,7 @@
 
 #include <linux/can/core.h>
 #include <linux/can/dev.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/mcp251x.h>
 #include <linux/completion.h>
 #include <linux/delay.h>
@@ -494,6 +495,9 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx)
 
 	priv->net->stats.rx_packets++;
 	priv->net->stats.rx_bytes += frame->can_dlc;
+
+	can_led_event(priv->net, CAN_LED_EVENT_RX);
+
 	netif_rx_ni(skb);
 }
 
@@ -707,6 +711,8 @@ static int mcp251x_stop(struct net_device *net)
 
 	mutex_unlock(&priv->mcp_lock);
 
+	can_led_event(net, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -905,6 +911,7 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
 		if (intf & CANINTF_TX) {
 			net->stats.tx_packets++;
 			net->stats.tx_bytes += priv->tx_len - 1;
+			can_led_event(net, CAN_LED_EVENT_TX);
 			if (priv->tx_len) {
 				can_get_echo_skb(net, 0);
 				priv->tx_len = 0;
@@ -968,6 +975,9 @@ static int mcp251x_open(struct net_device *net)
 		mcp251x_open_clean(net);
 		goto open_unlock;
 	}
+
+	can_led_event(net, CAN_LED_EVENT_OPEN);
+
 	netif_wake_queue(net);
 
 open_unlock:
@@ -1077,10 +1087,15 @@ static int mcp251x_can_probe(struct spi_device *spi)
 		pdata->transceiver_enable(0);
 
 	ret = register_candev(net);
-	if (!ret) {
-		dev_info(&spi->dev, "probed\n");
-		return ret;
-	}
+	if (ret)
+		goto error_probe;
+
+	devm_can_led_init(net);
+
+	dev_info(&spi->dev, "probed\n");
+
+	return ret;
+
 error_probe:
 	if (!mcp251x_enable_dma)
 		kfree(priv->spi_rx_buf);
Signature · 1 line
1.7.12.1
#13 lore raw

PATCH 7/9 can: sja1000: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on sja1000 devices by calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Oliver Hartkopp <[email protected]>
Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/sja1000/sja1000.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/net/can/sja1000/sja1000.c +16 -1
index 83ee11e..daf4013 100644
@@ -60,6 +60,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #include "sja1000.h"
 
@@ -368,6 +369,8 @@ static void sja1000_rx(struct net_device *dev)
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
+
+	can_led_event(dev, CAN_LED_EVENT_RX);
 }
 
 static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
@@ -521,6 +524,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
 				can_get_echo_skb(dev, 0);
 			}
 			netif_wake_queue(dev);
+			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
 		if (isrc & IRQ_RI) {
 			/* receive interrupt */
@@ -575,6 +579,8 @@ static int sja1000_open(struct net_device *dev)
 	/* init and start chi */
 	sja1000_start(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	netif_start_queue(dev);
 
 	return 0;
@@ -592,6 +598,8 @@ static int sja1000_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -639,6 +647,8 @@ static const struct net_device_ops sja1000_netdev_ops = {
 
 int register_sja1000dev(struct net_device *dev)
 {
+	int ret;
+
 	if (!sja1000_probe_chip(dev))
 		return -ENODEV;
 
@@ -648,7 +658,12 @@ int register_sja1000dev(struct net_device *dev)
 	set_reset_mode(dev);
 	chipset_init(dev);
 
-	return register_candev(dev);
+	ret =  register_candev(dev);
+
+	if (!ret)
+		devm_can_led_init(dev);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(register_sja1000dev);
 
Signature · 1 line
1.7.12.1
#14 lore raw

PATCH 8/9 can: export a safe netdev_priv wrapper for candev

In reply to Fabio Baltieri

From: Kurt Van Dijck <[email protected]>

In net_device notifier calls, it was impossible to determine if a CAN device is based on candev in a safe way. This patch adds such test in order to access candev storage from within those notifiers.

---
 drivers/net/can/dev.c   | 13 +++++++++++++
 include/linux/can/dev.h |  3 +++
 2 files changed, 16 insertions(+)
drivers/net/can/dev.c +13 -0
index 8233e5e..13e7380 100644
@@ -794,6 +794,19 @@ void unregister_candev(struct net_device *dev)
 }
 EXPORT_SYMBOL_GPL(unregister_candev);
 
+/*
+ * Test if a network device is a candev based device
+ * and return the can_priv* if so.
+ */
+struct can_priv *safe_candev_priv(struct net_device *dev)
+{
+	if ((dev->type != ARPHRD_CAN) || (dev->rtnl_link_ops != &can_link_ops))
+		return NULL;
+
+	return netdev_priv(dev);
+}
+EXPORT_SYMBOL_GPL(safe_candev_priv);
+
 static __init int can_dev_init(void)
 {
 	int err;
include/linux/can/dev.h +3 -0
index 7747d9b..fb0ab65 100644
@@ -106,6 +106,9 @@ u8 can_len2dlc(u8 len);
 struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
 void free_candev(struct net_device *dev);
 
+/* a candev safe wrapper around netdev_priv */
+struct can_priv *safe_candev_priv(struct net_device *dev);
+
 int open_candev(struct net_device *dev);
 void close_candev(struct net_device *dev);
 
Signature · 1 line
1.7.12.1
#0 lore raw

cover tx/rx LED trigger support

Hi all,

this is a resend of the patch series on tx/rx LEDs trigger. The patch set was put on hold after the latest discussions on Kurt's rename patch due to a missing feature in the LED subsystem, which has been just merged in:

a8df7b1 leds: add led_trigger_rename function

So, as months passed since the latest developments, I'm reposting the whole set, rebased on current mainline. The first patches are the same that were merged in can-next/led-trigger, but there was some (trivial) conflict in the rebase.

As for the test, I've tried the patch on the current mainline kernel with my custom usb-can interface. For the drivers, I don't have any SoC-enabled board anymore, so they have only been compile tested.

Cheers,
Fabio

Fabio Baltieri (7):
can: add tx/rx LED trigger support
can: flexcan: add LED trigger support
can: at91_can: add LED trigger support
can: ti_hecc: add LED trigger support
can: c_can: add LED trigger support
can: mcp251x: add LED trigger support
can: sja1000: add LED trigger support

Kurt Van Dijck (2):
can: export a safe netdev_priv wrapper for candev
can: rename LED trigger name on netdev renames

 drivers/net/can/Kconfig           |  12 ++++
 drivers/net/can/Makefile          |   2 +
 drivers/net/can/at91_can.c        |  10 +++
 drivers/net/can/c_can/c_can.c     |  10 +++
 drivers/net/can/dev.c             |  18 ++++++
 drivers/net/can/flexcan.c         |  11 ++++
 drivers/net/can/led.c             | 129 ++++++++++++++++++++++++++++++++++++++
 drivers/net/can/mcp251x.c         |  23 +++++--
 drivers/net/can/sja1000/sja1000.c |  17 ++++-
 drivers/net/can/ti_hecc.c         |  10 +++
 include/linux/can/dev.h           |  11 ++++
 include/linux/can/led.h           |  51 +++++++++++++++
 12 files changed, 299 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/can/led.c
 create mode 100644 include/linux/can/led.h
Signature · 1 line
1.7.12.1
#1 lore raw

PATCH 1/9 can: add tx/rx LED trigger support

This patch implements the functions to add two LED triggers, named <ifname>-tx and <ifname>-rx, to a canbus device driver.

Triggers are called from specific handlers by each CAN device driver and can be disabled altogether with a Kconfig option.

The implementation keeps the LED on when the interface is UP and blinks the LED on network activity at a configurable rate.

This only supports can-dev based drivers, as it uses some support field in the can_priv structure.

Supported drivers should call devm_can_led_init() and can_led_event() as needed.

Cleanup is handled automatically by devres, so no *_exit function is needed.

Supported events are:
- CAN_LED_EVENT_OPEN: turn on tx/rx LEDs
- CAN_LED_EVENT_STOP: turn off tx/rx LEDs
- CAN_LED_EVENT_TX: trigger tx LED blink
- CAN_LED_EVENT_RX: trigger tx LED blink

---
 drivers/net/can/Kconfig  | 12 +++++++
 drivers/net/can/Makefile |  2 ++
 drivers/net/can/led.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/can/dev.h  |  8 +++++
 include/linux/can/led.h  | 42 +++++++++++++++++++++++
 5 files changed, 153 insertions(+)
 create mode 100644 drivers/net/can/led.c
 create mode 100644 include/linux/can/led.h
drivers/net/can/Kconfig +12 -0
index b56bd9e..8e59120 100644
@@ -54,6 +54,18 @@ config CAN_CALC_BITTIMING
 	  arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw".
 	  If unsure, say Y.
 
+config CAN_LEDS
+	bool "Enable LED triggers for Netlink based drivers"
+	depends on CAN_DEV
+	depends on LEDS_CLASS
+	select LEDS_TRIGGERS
+	---help---
+	  This option adds two LED triggers for packet receive and transmit
+	  events on each supported CAN device.
+
+	  Say Y here if you are working on a system with led-class supported
+	  LEDs and you want to use them as canbus activity indicators.
+
 config CAN_AT91
 	tristate "Atmel AT91 onchip CAN controller"
 	depends on CAN_DEV && (ARCH_AT91SAM9263 || ARCH_AT91SAM9X5)
drivers/net/can/Makefile +2 -0
index 7de5986..c744039 100644
@@ -8,6 +8,8 @@ obj-$(CONFIG_CAN_SLCAN)		+= slcan.o
 obj-$(CONFIG_CAN_DEV)		+= can-dev.o
 can-dev-y			:= dev.o
 
+can-dev-$(CONFIG_CAN_LEDS)	+= led.o
+
 obj-y				+= usb/
 obj-y				+= softing/
 
drivers/net/can/led.c new file +89 -0

89 lines not on this page · raw message

include/linux/can/dev.h +8 -0
index 2b2fc34..7747d9b 100644
@@ -16,6 +16,7 @@
 #include <linux/can.h>
 #include <linux/can/netlink.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 /*
  * CAN mode
@@ -52,6 +53,13 @@ struct can_priv {
 
 	unsigned int echo_skb_max;
 	struct sk_buff **echo_skb;
+
+#ifdef CONFIG_CAN_LEDS
+	struct led_trigger *tx_led_trig;
+	char tx_led_trig_name[CAN_LED_NAME_SZ];
+	struct led_trigger *rx_led_trig;
+	char rx_led_trig_name[CAN_LED_NAME_SZ];
+#endif
 };
 
 /*
include/linux/can/led.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.7.12.1
#9 lore raw

PATCH 3/9 can: at91_can: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on at91_can devices by calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/at91_can.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/can/at91_can.c +10 -0
index 81baefd..44f3637 100644
@@ -37,6 +37,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #define AT91_MB_MASK(i)		((1 << (i)) - 1)
 
@@ -641,6 +642,8 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb)
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
+
+	can_led_event(dev, CAN_LED_EVENT_RX);
 }
 
 /**
@@ -875,6 +878,7 @@ static void at91_irq_tx(struct net_device *dev, u32 reg_sr)
 			/* _NOTE_: subtract AT91_MB_TX_FIRST offset from mb! */
 			can_get_echo_skb(dev, mb - get_mb_tx_first(priv));
 			dev->stats.tx_packets++;
+			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
 	}
 
@@ -1128,6 +1132,8 @@ static int at91_open(struct net_device *dev)
 		goto out_close;
 	}
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	/* start chip and queuing */
 	at91_chip_start(dev);
 	napi_enable(&priv->napi);
@@ -1159,6 +1165,8 @@ static int at91_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1321,6 +1329,8 @@ static int at91_can_probe(struct platform_device *pdev)
 		goto exit_free;
 	}
 
+	devm_can_led_init(dev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->reg_base, dev->irq);
 
Signature · 1 line
1.7.12.1
#11 lore raw

PATCH 5/9 can: c_can: add LED trigger support

In reply to Fabio Baltieri

Add support for canbus activity led indicators on c_can devices by calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op otherwise.

Cc Bhupesh Sharma <[email protected]>
Cc AnilKumar Ch <[email protected]>
Cc Wolfgang Grandegger <[email protected]>
Cc Marc Kleine-Budde <[email protected]>
---
 drivers/net/can/c_can/c_can.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/can/c_can/c_can.c +10 -0
index 5233b8f..57eb1e7 100644
@@ -39,6 +39,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #include "c_can.h"
 
@@ -477,6 +478,8 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, int ctrl)
 	stats->rx_packets++;
 	stats->rx_bytes += frame->can_dlc;
 
+	can_led_event(dev, CAN_LED_EVENT_RX);
+
 	return 0;
 }
 
@@ -751,6 +754,7 @@ static void c_can_do_tx(struct net_device *dev)
 					C_CAN_IFACE(MSGCTRL_REG, 0))
 					& IF_MCONT_DLC_MASK;
 			stats->tx_packets++;
+			can_led_event(dev, CAN_LED_EVENT_TX);
 			c_can_inval_msg_object(dev, 0, msg_obj_no);
 		} else {
 			break;
@@ -1115,6 +1119,8 @@ static int c_can_open(struct net_device *dev)
 
 	napi_enable(&priv->napi);
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	/* start the c_can controller */
 	c_can_start(dev);
 
@@ -1143,6 +1149,8 @@ static int c_can_close(struct net_device *dev)
 	c_can_reset_ram(priv, false);
 	c_can_pm_runtime_put_sync(priv);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1268,6 +1276,8 @@ int register_c_can_dev(struct net_device *dev)
 	err = register_candev(dev);
 	if (err)
 		c_can_pm_runtime_disable(priv);
+	else
+		devm_can_led_init(dev);
 
 	return err;
 }
Signature · 1 line
1.7.12.1
#15 lore raw

PATCH 9/9 can: rename LED trigger name on netdev renames

In reply to Fabio Baltieri

From: Kurt Van Dijck <[email protected]>

The LED trigger name for CAN devices is based on the initial CAN device name, but does never change. The LED trigger name is not guaranteed to be unique in case of hotplugging CAN devices.

This patch tries to address this problem by modifying the LED trigger name according to the CAN device name when the latter changes.

v1 - Kurt Van Dijck
v2 - Fabio Baltieri
- remove rename blocking if trigger is bound
- use led-subsystem function for the actual rename (still WiP)
- call init/exit functions from dev.c
v3 - Kurt Van Dijck
- safe operation for non-candev based devices (vcan, slcan) based on earlier patch
v4 - Kurt Van Dijck
- trivial patch mistakes fixed

---
 drivers/net/can/dev.c   |  5 +++++
 drivers/net/can/led.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/can/led.h |  9 +++++++++
 3 files changed, 54 insertions(+)
drivers/net/can/dev.c +5 -0
index 13e7380..6abc6e5 100644
@@ -25,6 +25,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/netlink.h>
+#include <linux/can/led.h>
 #include <net/rtnetlink.h>
 
 #define MOD_DESC "CAN device driver interface"
@@ -811,6 +812,8 @@ static __init int can_dev_init(void)
 {
 	int err;
 
+	can_led_notifier_init();
+
 	err = rtnl_link_register(&can_link_ops);
 	if (!err)
 		printk(KERN_INFO MOD_DESC "\n");
@@ -822,6 +825,8 @@ module_init(can_dev_init);
 static __exit void can_dev_exit(void)
 {
 	rtnl_link_unregister(&can_link_ops);
+
+	can_led_notifier_exit();
 }
 module_exit(can_dev_exit);
 
drivers/net/can/led.c +40 -0
index eaa14ac..227d359 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright 2012, Fabio Baltieri <[email protected]>
+ * Copyright 2012, Kurt Van Dijck <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -87,3 +88,42 @@ void devm_can_led_init(struct net_device *netdev)
 	devres_add(&netdev->dev, res);
 }
 EXPORT_SYMBOL_GPL(devm_can_led_init);
+
+/*
+ * NETDEV rename notifier to rename the associated led triggers too
+ */
+static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
+			void *data)
+{
+	struct net_device *netdev = data;
+	struct can_priv *priv = safe_candev_priv(netdev);
+	char name[CAN_LED_NAME_SZ];
+
+	if (!priv)
+		return NOTIFY_DONE;
+
+	if (msg == NETDEV_CHANGENAME) {
+		snprintf(name, sizeof(name), "%s-tx", netdev->name);
+		led_trigger_rename_static(name, priv->tx_led_trig);
+
+		snprintf(name, sizeof(name), "%s-rx", netdev->name);
+		led_trigger_rename_static(name, priv->rx_led_trig);
+	}
+
+	return NOTIFY_DONE;
+}
+
+/* notifier block for netdevice event */
+static struct notifier_block can_netdev_notifier __read_mostly = {
+	.notifier_call = can_led_notifier,
+};
+
+int __init can_led_notifier_init(void)
+{
+	return register_netdevice_notifier(&can_netdev_notifier);
+}
+
+void __exit can_led_notifier_exit(void)
+{
+	unregister_netdevice_notifier(&can_netdev_notifier);
+}
include/linux/can/led.h +9 -0
index 12d5549..9c1167b 100644
@@ -26,6 +26,8 @@ enum can_led_event {
 
 void can_led_event(struct net_device *netdev, enum can_led_event event);
 void devm_can_led_init(struct net_device *netdev);
+int __init can_led_notifier_init(void);
+void __exit can_led_notifier_exit(void);
 
 #else
 
@@ -36,6 +38,13 @@ static inline void can_led_event(struct net_device *netdev,
 static inline void devm_can_led_init(struct net_device *netdev)
 {
 }
+static inline int can_led_notifier_init(void)
+{
+	return 0;
+}
+static inline void can_led_notifier_exit(void)
+{
+}
 
 #endif
 
Signature · 1 line
1.7.12.1
#16 lore raw
In reply to Fabio Baltieri
Quoted 9 lines · Fabio Baltieri

Hi all,

this is a resend of the patch series on tx/rx LEDs trigger. The patch set was put on hold after the latest discussions on Kurt's rename patch due to a missing feature in the LED subsystem, which has been just merged in:

a8df7b1 leds: add led_trigger_rename function

Quoted 8 lines

So, as months passed since the latest developments, I'm reposting the whole set, rebased on current mainline. The first patches are the same that were merged in can-next/led-trigger, but there was some (trivial) conflict in the rebase.

As for the test, I've tried the patch on the current mainline kernel with my custom usb-can interface. For the drivers, I don't have any SoC-enabled board anymore, so they have only been compile tested.

Thanks for your work. Can you move patches 8+9 to the beginning, before touching the device drivers. I'll apply on the Thursday, as I don't have proper internet now.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#17 lore raw

Hello Marc,

Quoted 3 lines · Marc Kleine-Budde

Thanks for your work. Can you move patches 8+9 to the beginning, before touching the device drivers. I'll apply on the Thursday, as I don't have proper internet now.

Ok, it makes sense. In that case I'll wait a couple of days before re-sending the reordered series, just in case someone else wants to comment.

Thanks!
Fabio

Signature · 1 line
Fabio Baltieri
#2 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

In reply to Fabio Baltieri

Hello Fabio!

Am 2012-12-16 12:08, schrieb Fabio Baltieri:

Quoted 15 lines

This patch implements the functions to add two LED triggers, named <ifname>-tx and <ifname>-rx, to a canbus device driver.

Triggers are called from specific handlers by each CAN device driver and can be disabled altogether with a Kconfig option.

The implementation keeps the LED on when the interface is UP and blinks the LED on network activity at a configurable rate.

This only supports can-dev based drivers, as it uses some support field in the can_priv structure.

Supported drivers should call devm_can_led_init() and can_led_event() as needed.

Quoted 8 lines

Cleanup is handled automatically by devres, so no *_exit function is needed.

Supported events are:
- CAN_LED_EVENT_OPEN: turn on tx/rx LEDs
- CAN_LED_EVENT_STOP: turn off tx/rx LEDs
- CAN_LED_EVENT_TX: trigger tx LED blink
- CAN_LED_EVENT_RX: trigger tx LED blink

Why there is no patch for any usb can device?

Can this be done in a more general way, except patching every driver?

regards,
Bernd

#3 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

Quoted 27 lines · Bernd Krumboeck

Hello Fabio!

Am 2012-12-16 12:08, schrieb Fabio Baltieri:

Quoted 15 lines

This patch implements the functions to add two LED triggers, named <ifname>-tx and <ifname>-rx, to a canbus device driver.

Triggers are called from specific handlers by each CAN device driver and can be disabled altogether with a Kconfig option.

The implementation keeps the LED on when the interface is UP and blinks the LED on network activity at a configurable rate.

This only supports can-dev based drivers, as it uses some support field in the can_priv structure.

Supported drivers should call devm_can_led_init() and can_led_event() as needed.

Quoted 8 lines

Cleanup is handled automatically by devres, so no *_exit function is needed.

Supported events are:
- CAN_LED_EVENT_OPEN: turn on tx/rx LEDs
- CAN_LED_EVENT_STOP: turn off tx/rx LEDs
- CAN_LED_EVENT_TX: trigger tx LED blink
- CAN_LED_EVENT_RX: trigger tx LED blink

Quoted 3 lines

Why there is no patch for any usb can device?

Can this be done in a more general way, except patching every driver?

There must be a way.
Up to this series, there were a few minor problems:
* determine if a CAN device is can_dev based
* led trigger calls.

After this series, I think it's possible to make this functionality generic. But up to then, this per-driver code is a working model.

Kind regards,
Kurt

#18 lore raw
In reply to Fabio Baltieri

Fabio,

Nice work to repackage this :-) !

Kurt

Quoted 54 lines · Fabio Baltieri

Hi all,

this is a resend of the patch series on tx/rx LEDs trigger. The patch set was put on hold after the latest discussions on Kurt's rename patch due to a missing feature in the LED subsystem, which has been just merged in:

a8df7b1 leds: add led_trigger_rename function

So, as months passed since the latest developments, I'm reposting the whole set, rebased on current mainline. The first patches are the same that were merged in can-next/led-trigger, but there was some (trivial) conflict in the rebase.

As for the test, I've tried the patch on the current mainline kernel with my custom usb-can interface. For the drivers, I don't have any SoC-enabled board anymore, so they have only been compile tested.

Cheers,
Fabio

Fabio Baltieri (7):
can: add tx/rx LED trigger support
can: flexcan: add LED trigger support
can: at91_can: add LED trigger support
can: ti_hecc: add LED trigger support
can: c_can: add LED trigger support
can: mcp251x: add LED trigger support
can: sja1000: add LED trigger support

Kurt Van Dijck (2):
can: export a safe netdev_priv wrapper for candev
can: rename LED trigger name on netdev renames

 drivers/net/can/Kconfig           |  12 ++++
 drivers/net/can/Makefile          |   2 +
 drivers/net/can/at91_can.c        |  10 +++
 drivers/net/can/c_can/c_can.c     |  10 +++
 drivers/net/can/dev.c             |  18 ++++++
 drivers/net/can/flexcan.c         |  11 ++++
 drivers/net/can/led.c             | 129 ++++++++++++++++++++++++++++++++++++++
 drivers/net/can/mcp251x.c         |  23 +++++--
 drivers/net/can/sja1000/sja1000.c |  17 ++++-
 drivers/net/can/ti_hecc.c         |  10 +++
 include/linux/can/dev.h           |  11 ++++
 include/linux/can/led.h           |  51 +++++++++++++++
 12 files changed, 299 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/can/led.c
 create mode 100644 include/linux/can/led.h
Signature · 1 line
1.7.12.1
#4 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

In reply to Bernd Krumboeck

Hi Bernd,

Quoted 1 line · Bernd Krumboeck

Why there is no patch for any usb can device?

Because USB canbus interfaces usually already has some dedicated activity LED on the device itself, while this patch is meant to give an equivalent functionality for Embedded SoC with GPIO based LEDs, so I just started by modifying some Embedded CAN drivers.

If you think it's useful for USB controller, just tell me or modify the driver by yourself! As you see the patch is really easy.

Quoted 1 line

Can this be done in a more general way, except patching every driver?

Actually this started as a generic patch bolted to the CAN stack, but the implementation was too invasive and a bit too hacky. A generic implementation at can-dev level is hard to obtain because the can-dev layer is not used in all the device operation, as the most of the driver calls generick network API directly.

Fabio

Signature · 1 line
Fabio Baltieri
#5 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

Quoted 5 lines

Hi Bernd,

Quoted 1 line · Bernd Krumboeck

Why there is no patch for any usb can device?

Quoted 7 lines

Because USB canbus interfaces usually already has some dedicated activity LED on the device itself, while this patch is meant to give an equivalent functionality for Embedded SoC with GPIO based LEDs, so I just started by modifying some Embedded CAN drivers.

If you think it's useful for USB controller, just tell me or modify the driver by yourself! As you see the patch is really easy.

At least it is useful for the usb_8dev driver. I'll write a patch.

Photo of the device:
http://www.8devices.com/product/2/usb2can

Quoted 8 lines
Quoted 1 line

Can this be done in a more general way, except patching every driver?

Actually this started as a generic patch bolted to the CAN stack, but the implementation was too invasive and a bit too hacky. A generic implementation at can-dev level is hard to obtain because the can-dev layer is not used in all the device operation, as the most of the driver calls generick network API directly.

Thanks!

regards,
Bernd

#6 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

Quoted 7 lines · Bernd Krumböck
Quoted 2 lines

If you think it's useful for USB controller, just tell me or modify the driver by yourself! As you see the patch is really easy.

At least it is useful for the usb_8dev driver. I'll write a patch.

Photo of the device:
http://www.8devices.com/product/2/usb2can

Sure that it's needed? That status LED is probably controlled directly by the firmware itself. Anyway I think it makes sense to support all the mainline drivers and I'm really happy if you test the patch on your hardware!

My only suggestion is to keep the LED support on a separate patch from the "add driver" one.

Cheers,
Fabio

Signature · 1 line
Fabio Baltieri
#7 lore raw

Re: [PATCH 1/9] can: add tx/rx LED trigger support

Hi Fabio!

Quoted 7 lines · Bernd Krumböck
Quoted 6 lines
Quoted 1 line

If you think it's useful for USB controller, just tell me or modify

the

Quoted 1 line

driver by yourself! As you see the patch is really easy.

At least it is useful for the usb_8dev driver. I'll write a patch.

Quoted 7 lines
Quoted 2 lines

Photo of the device:
http://www.8devices.com/product/2/usb2can

Sure that it's needed? That status LED is probably controlled directly by the firmware itself. Anyway I think it makes sense to support all the mainline drivers and I'm really happy if you test the patch on your hardware!

Yes, it is controlled by the firmware, but it does not show rx/tx. Whereas my OpenWRT hardware has enough leds. ;-)

regards,
Bernd