linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Jander <david@protonic.nl>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	linux-can@vger.kernel.org,
	Alexander Stein <alexander.stein@systec-electronic.com>
Subject: Re: [PATCH 11/15] can: rx-fifo: Add support for can state tracking and error polling
Date: Mon, 3 Nov 2014 13:51:35 +0100	[thread overview]
Message-ID: <20141103135135.10fd4c6f@archvile> (raw)
In-Reply-To: <545765D8.7090906@pengutronix.de>

On Mon, 03 Nov 2014 12:24:08 +0100
Marc Kleine-Budde <mkl@pengutronix.de> wrote:

> On 10/10/2014 05:46 PM, David Jander wrote:
> > The interrupt handler should store the error flags if needed and call
> > can_rx_fifo_irq_error() if there was an error flag set. This will trigger
> > a napi-poll that will call poll_can_state() and poll_bus_error()
> > callbacks. Those should handle can state machine and send error frames
> > as needed.
> > 
> > Signed-off-by: David Jander <david@protonic.nl>
> > ---
> >  drivers/net/can/dev.c   | 23 ++++++++++++++++++++---
> >  include/linux/can/dev.h |  9 +++++++++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> > index fc35d28..dac7579 100644
> > --- a/drivers/net/can/dev.c
> > +++ b/drivers/net/can/dev.c
> > @@ -352,6 +352,9 @@ static int can_rx_fifo_napi_poll(struct napi_struct
> > *napi, int quota) unsigned int tail;
> >  
> >  restart_poll:
> > +	if (work_done < quota)
> > +		work_done += fifo->poll_can_state(fifo);
> > +
> 
> Do we need two callbacks in the poll-loop? I think one should be enough.
> The driver can call as many non-rx related functions as needed then.
> E.g. state change, bus error handling, tx-completion handling, etc...

Ok. I split it into two handlers, because I saw most drivers doing first
state-handling then message reception and last error handling... in this
particular order. If that order is not important, we can use one poll()
function for both state- and error-handling.
In that case... should the poll() handler be called _before_ or _after_
handling the mailboxes?

> What about adding a guard:
> 
> 	if (fifo->poll && work_done < quota)
> 		work_done += fifo->poll(fifo);
> 
> ...so that the poll callback can be NULL.

Ok, good idea.

> >  	/* handle mailboxes */
> >  	head = smp_load_acquire(&fifo->ring_head);
> >  	tail = fifo->ring_tail;
> > @@ -363,14 +366,19 @@ restart_poll:
> >  		smp_store_release(&fifo->ring_tail, tail);
> >  	}
> >  
> > +	if (work_done < quota)
> > +		work_done += fifo->poll_bus_error(fifo);
> > +
> >  	if (work_done < quota) {
> >  		napi_complete(napi);
> >  
> >  		/* Check if there was another interrupt */
> >  		head = smp_load_acquire(&fifo->ring_head);
> > -		if ((CIRC_CNT(head, tail, fifo->ring_size) >= 1) &&
> > -		    napi_reschedule(&fifo->napi))
> > +		if (((CIRC_CNT(head, tail, fifo->ring_size) >= 1) ||
> > +		    fifo->poll_errors) && napi_reschedule(&fifo->napi)) {
> > +			fifo->poll_errors = false;
> >  			goto restart_poll;
> > +		}
> >  	}
> >  
> >  	return work_done;
> > @@ -393,7 +401,8 @@ int can_rx_fifo_add(struct net_device *dev, struct
> > can_rx_fifo *fifo) return -EINVAL;
> >  
> >  	if (!fifo->mailbox_enable_mask || !fifo->mailbox_move_to_buffer ||
> > -	    !fifo->mailbox_enable)
> > +	    !fifo->mailbox_enable || !fifo->poll_bus_error ||
> > +	    !fifo->poll_can_state)
> >  		return -EINVAL;
> >  
> >  	/* Make ring-buffer a sensible size that is a power of 2 */
> > @@ -412,6 +421,7 @@ int can_rx_fifo_add(struct net_device *dev, struct
> > can_rx_fifo *fifo) fifo->mask_low = can_rx_fifo_mask_low(fifo);
> >  	fifo->mask_high = can_rx_fifo_mask_high(fifo);
> >  	fifo->second_first = false;
> > +	fifo->poll_errors = false;
> >  	fifo->active = fifo->mask_low | fifo->mask_high;
> >  	fifo->mailbox_enable_mask(fifo, fifo->active);
> >  
> > @@ -503,6 +513,13 @@ int can_rx_fifo_irq_offload(struct can_rx_fifo *fifo)
> >  }
> >  EXPORT_SYMBOL_GPL(can_rx_fifo_irq_offload);
> >  
> > +void can_rx_fifo_irq_error(struct can_rx_fifo *fifo)
> > +{
> > +	fifo->poll_errors = true;
> > +	can_rx_fifo_napi_schedule(fifo);
> > +}
> > +EXPORT_SYMBOL_GPL(can_rx_fifo_irq_error);
> > +
> >  void can_rx_fifo_napi_enable(struct can_rx_fifo *fifo)
> >  {
> >  	napi_enable(&fifo->napi);
> > diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> > index c49c37b..e1ed6d4 100644
> > --- a/include/linux/can/dev.h
> > +++ b/include/linux/can/dev.h
> > @@ -75,12 +75,15 @@ struct can_rx_fifo {
> >  	void (*mailbox_enable)(struct can_rx_fifo *rx_fifo, unsigned int
> > mb); unsigned int (*mailbox_move_to_buffer)(struct can_rx_fifo *rx_fifo,
> >  		struct can_frame *frame, unsigned int mb);
> > +	unsigned int (*poll_can_state)(struct can_rx_fifo *rx_fifo);
> > +	unsigned int (*poll_bus_error)(struct can_rx_fifo *rx_fifo);
> >  
> >  	u64 mask_low;
> >  	u64 mask_high;
> >  	u64 active;
> >  
> >  	unsigned int second_first;
> > +	bool poll_errors;
> >  
> >  	bool inc;
> >  
> > @@ -92,6 +95,11 @@ struct can_rx_fifo {
> >  	struct napi_struct napi;
> >  };
> >  
> > +static inline void can_rx_fifo_napi_schedule(struct can_rx_fifo *fifo)
> > +{
> > +	napi_schedule(&fifo->napi);
> > +}
> > +
> >  /*
> >   * get_can_dlc(value) - helper macro to cast a given data length code
> > (dlc)
> >   * to __u8 and ensure the dlc value to be max. 8 bytes.
> > @@ -135,6 +143,7 @@ u8 can_len2dlc(u8 len);
> >  
> >  int can_rx_fifo_add(struct net_device *dev, struct can_rx_fifo *fifo);
> >  int can_rx_fifo_irq_offload(struct can_rx_fifo *fifo);
> > +void can_rx_fifo_irq_error(struct can_rx_fifo *fifo);
> >  void can_rx_fifo_napi_enable(struct can_rx_fifo *fifo);
> >  void can_rx_fifo_napi_disable(struct can_rx_fifo *fifo);
> >  void can_rx_fifo_reset(struct can_rx_fifo *fifo);
> > 
> 
> Marc
> 

Best regards,

-- 
David Jander
Protonic Holland.

  reply	other threads:[~2014-11-03 12:51 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 15:46 [RFC PATCH V3 00/15] CAN: Add rx-fifo support and port flexcan to it David Jander
2014-10-10 15:46 ` [PATCH 01/15] can: flexcan: add documentation about mailbox organizaiton David Jander
2014-10-10 15:46 ` [PATCH 02/15] can: flexcan: rename crl2 -> ctrl2 David Jander
2014-10-10 15:46 ` [PATCH 03/15] can: flexcan: replace open coded mailbox code by proper defines David Jander
2014-10-10 15:46 ` [PATCH 04/15] can: flexcan: Re-write receive path to use MB queue instead of FIFO David Jander
2014-10-10 15:46 ` [PATCH 05/15] can: dev: add preliminary rx-fifo David Jander
2014-10-10 15:46 ` [PATCH 06/15] can: rx-fifo: Increase MB size limit from 32 to 64 David Jander
2014-10-19 21:25   ` Marc Kleine-Budde
2014-10-20  6:14     ` David Jander
2014-10-10 15:46 ` [PATCH 07/15] can: rx-fifo: Change to do controller off-load in interrupt and NAPI poll David Jander
2014-10-19 22:09   ` Marc Kleine-Budde
2014-10-20  7:06     ` David Jander
2014-11-03 11:10       ` Marc Kleine-Budde
2014-11-03 12:44         ` David Jander
2014-10-10 15:46 ` [PATCH 08/15] can: rx-fifo: fix long lines David Jander
2014-10-19 21:18   ` Marc Kleine-Budde
2014-10-20  7:09     ` David Jander
2014-10-10 15:46 ` [PATCH 09/15] can: rx-fifo: Add can_rx_fifo_reset() function David Jander
2014-11-03 11:16   ` Marc Kleine-Budde
2014-11-03 12:46     ` David Jander
2014-11-03 12:51       ` Marc Kleine-Budde
2014-10-10 15:46 ` [PATCH 10/15] can: rx-fifo: remove obsolete comment David Jander
2014-10-10 15:46 ` [PATCH 11/15] can: rx-fifo: Add support for can state tracking and error polling David Jander
2014-11-03 11:24   ` Marc Kleine-Budde
2014-11-03 12:51     ` David Jander [this message]
2014-11-03 12:58       ` Marc Kleine-Budde
2014-11-03 13:09         ` David Jander
2014-11-03 13:24           ` Marc Kleine-Budde
2014-11-05 17:16             ` David Jander
2014-11-06 10:20               ` Marc Kleine-Budde
2014-11-06 11:07                 ` David Jander
2014-10-10 15:46 ` [PATCH 12/15] can: flexcan: Add support for RX-FIFO David Jander
2014-11-03 11:26   ` Marc Kleine-Budde
2014-11-03 12:55     ` David Jander
2014-11-03 13:34       ` Marc Kleine-Budde
2014-10-10 15:46 ` [PATCH 13/15] can: rx-fifo: Add support for simple irq offloading David Jander
2014-11-03 11:59   ` Marc Kleine-Budde
2014-10-10 15:46 ` [PATCH 14/15] can: flexcan: Add MB/Fifo specific column to comment table of IP versions David Jander
2014-10-10 15:47 ` [PATCH 15/15] can: flexcan: Re-enable RTR reception support for older flexcan IPs David Jander
2014-11-03 12:02   ` Marc Kleine-Budde

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=20141103135135.10fd4c6f@archvile \
    --to=david@protonic.nl \
    --cc=alexander.stein@systec-electronic.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=wg@grandegger.com \
    /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 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).