All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Grandegger <wg@grandegger.com>
To: Fabio Baltieri <fabio.baltieri@gmail.com>
Cc: linux-can@vger.kernel.org
Subject: Re: [RFC PATCH] can: add tx/rx led trigger support
Date: Wed, 11 Apr 2012 16:45:59 +0200	[thread overview]
Message-ID: <4F859927.1040404@grandegger.com> (raw)
In-Reply-To: <1334093965-2692-1-git-send-email-fabio.baltieri@gmail.com>

Hi Fabio,

On 04/10/2012 11:39 PM, Fabio Baltieri wrote:
> This patch adds two led triggers, named <ifname>-tx and <ifname>-rx to
> each registered canbus interface.
> 
> Triggers are called from can_send() and can_rcv() functions in af_can.h,
> and can be disabled with a Kconfig option.
> 
> The implementation lights up the LED when a packet is transmitted or
> received and turn it off after a configurable time using a timer.
> 
> This only supports can-dev based drivers, as it uses some support field
> in the can_priv structure.
> 
> Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
> ---
> Hi all,
> 
> this is a try to add generic tx/rx LED triggers for canbus interfaces, somthing
> I think is very useful in embedded systems where canbus devices often have
> status leds associated with them, maybe on the bus connector itself, like

Please define "often"? So far only a few CAN devices need LED control by
software. Actually, I only remember the PEAK PCMCIA card.

> ethernet interfaces. I saw a couple of hardware implementation to drive status
> leds from tx/rx lines but these were not as effective as software ones.

Why? LEDs are ususally controlled by software only if the hardware does
not do it (properly?). But your LED support cannot be compared with the
LEDs on the CAN devices itself. It will allow to trigger user-defined
LEDs by RX or TX activity, right? ... which might be useful especially
for debugging, I assume.

> The implementation is similar to the MAC80211_LEDS one, and takes quite a lot
> of inspiration and some code from it.
> 
> In this case, however, tx and rx events are trapped from the af_can source file
> as there are no generic tx/rx functions in can/dev.c. This also required an
> additional counter to discard rx events for looped frames.

Well, controlling the LEDs from the protocol level seems wrong to me. If
at all, it should be handled by the CAN device interface.

> Also, as all the support data are in the can_priv structure, this only supports
> can-dev based drivers. All the others are ignored by checking the
> netdev->rtnl_link_ops->kind string. This actually excludes only vcan and slcan
> drivers.
> 
> The implementation should be quite unintrusive on existing code and can be disabled
> altogether with a config option.

I find it rather intrusive, especially when #ifdef's should be avoided.
Furthermore it introduces overhead in the RX and TX path and uses a lot
of space in the "struct can_priv".

> This has been tested tested on x86 and a powerpc with a custom USB-CAN
> interface (which I hope to publish as open-hardware soon BTW) and i2c-based
> leds.
> 
> Any thoughts? Do you think this can be merged?

LED interface might be useful, especially for debugging. Why not
enabling it just if "CONFIG_CAN_DEBUG_DEVICES=y". Also LEDs for error
states would make sense.

Some more comments inline...

>  include/linux/can/dev.h |    9 +++
>  net/can/Kconfig         |   10 +++
>  net/can/Makefile        |    2 +
>  net/can/af_can.c        |   14 ++++-
>  net/can/led.c           |  154 +++++++++++++++++++++++++++++++++++++++++++++++
>  net/can/led.h           |   29 +++++++++
>  6 files changed, 217 insertions(+), 1 deletions(-)
>  create mode 100644 net/can/led.c
>  create mode 100644 net/can/led.h
> 
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 5d2efe7..76eb70c 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -16,6 +16,8 @@
>  #include <linux/can.h>
>  #include <linux/can/netlink.h>
>  #include <linux/can/error.h>
> +#include <linux/timer.h>
> +#include <linux/leds.h>
>  
>  /*
>   * CAN mode
> @@ -52,6 +54,13 @@ struct can_priv {
>  
>  	unsigned int echo_skb_max;
>  	struct sk_buff **echo_skb;
> +
> +#ifdef CONFIG_CAN_LEDS
> +	struct timer_list tx_off_timer, rx_off_timer;
> +	struct led_trigger *tx_led, *rx_led;
> +	char tx_led_name[32], rx_led_name[32];
> +	atomic_t led_discard_count;
> +#endif

This requires a lot of space. Please add just *one* pointer here and
allocate the required space when needed.

>  };
>  
>  /*
> diff --git a/net/can/Kconfig b/net/can/Kconfig
> index 0320069..55894b7 100644
> --- a/net/can/Kconfig
> +++ b/net/can/Kconfig
> @@ -52,4 +52,14 @@ config CAN_GW
>  	  They can be modified with AND/OR/XOR/SET operations as configured
>  	  by the netlink configuration interface known e.g. from iptables.
>  
> +config CAN_LEDS
> +	bool "Enable LED triggers for Netlink based drivers"
> +	depends on CAN
> +	depends on CAN_DEV
> +	depends on LEDS_CLASS
> +	select LEDS_TRIGGERS
> +	---help---
> +	  This option enables two LED triggers for packet receive and transmit
> +	  events on each CAN device based on the can-dev framework.
> +
>  source "drivers/net/can/Kconfig"
> diff --git a/net/can/Makefile b/net/can/Makefile
> index cef49eb..fc6b286 100644
> --- a/net/can/Makefile
> +++ b/net/can/Makefile
> @@ -5,6 +5,8 @@
>  obj-$(CONFIG_CAN)	+= can.o
>  can-y			:= af_can.o proc.o
>  
> +can-$(CONFIG_CAN_LEDS)	+= led.o
> +
>  obj-$(CONFIG_CAN_RAW)	+= can-raw.o
>  can-raw-y		:= raw.o

In this file you only find things for CAN protocol support. LEDs should
be handled by drivers/net/can/dev.c.

Wolfgang.

  parent reply	other threads:[~2012-04-11 14:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10 21:39 [RFC PATCH] can: add tx/rx led trigger support Fabio Baltieri
2012-04-11  6:14 ` Oliver Hartkopp
2012-04-11 17:58   ` Fabio Baltieri
2012-04-11 18:29     ` Oliver Hartkopp
2012-04-11 18:58       ` Wolfgang Grandegger
2012-04-12  6:16         ` Oliver Hartkopp
2012-04-11 19:02     ` Oliver Hartkopp
2012-04-11 19:36       ` Fabio Baltieri
2012-04-12  6:05         ` Oliver Hartkopp
2012-04-12  6:32         ` Alexander Stein
2012-04-12 15:52           ` Oliver Hartkopp
2012-04-12 18:30             ` Fabio Baltieri
2012-04-13 19:00               ` Oliver Hartkopp
2012-04-12  7:37         ` Wolfgang Grandegger
2012-04-12 11:07           ` Martin Gysel
2012-04-12 16:02             ` Oliver Hartkopp
2012-04-12 16:13               ` Wolfgang Grandegger
2012-04-12 17:28                 ` Fabio Baltieri
2012-04-12 18:47                   ` Wolfgang Grandegger
2012-04-12 17:46           ` Fabio Baltieri
2012-04-12 18:53             ` Wolfgang Grandegger
2012-04-11  6:29 ` Alexander Stein
2012-04-11 18:03   ` Fabio Baltieri
2012-04-11 14:45 ` Wolfgang Grandegger [this message]
2012-04-11 16:24   ` Oliver Hartkopp
2012-04-11 19:11   ` Fabio Baltieri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F859927.1040404@grandegger.com \
    --to=wg@grandegger.com \
    --cc=fabio.baltieri@gmail.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.