linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: David Jander <david@protonic.nl>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	linux-can@vger.kernel.org,
	Alexander Stein <alexander.stein@systec-electronic.com>
Subject: Re: [PATCH 13/15] can: rx-fifo: Add support for simple irq offloading
Date: Mon, 03 Nov 2014 12:59:32 +0100	[thread overview]
Message-ID: <54576E24.5000307@pengutronix.de> (raw)
In-Reply-To: <1412956020-21489-14-git-send-email-david@protonic.nl>

[-- Attachment #1: Type: text/plain, Size: 5197 bytes --]

On 10/10/2014 05:46 PM, David Jander wrote:
> Some CAN controllers have a usable FIFO already but can still benefit from
> off-loading the CAN controller FIFO in the interrupt into an extra ring-
> buffer. Add support for these simpler cases also.
> 
> Signed-off-by: David Jander <david@protonic.nl>
> ---
>  drivers/net/can/dev.c   | 76 ++++++++++++++++++++++++++++++++++++++++---------
>  include/linux/can/dev.h |  2 ++
>  2 files changed, 65 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index dac7579..278aea3 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -384,10 +384,32 @@ restart_poll:
>  	return work_done;
>  }
>  
> +static int can_rx_fifo_init_ring(struct net_device *dev,
> +		struct can_rx_fifo *fifo, unsigned int weight)
> +{
> +	fifo->dev = dev;
> +
> +	/* Make ring-buffer a sensible size that is a power of 2 */
> +	fifo->ring_size = (2 << fls(weight));
> +	fifo->ring = kzalloc(sizeof(struct can_frame) * fifo->ring_size,
> +			     GFP_KERNEL);
> +	if (!fifo->ring)
> +		return -ENOMEM;
> +
> +	fifo->ring_head = fifo->ring_tail = 0;
> +
> +	/* Take care of NAPI handling */
> +	netif_napi_add(dev, &fifo->napi, can_rx_fifo_napi_poll, weight);
> +
> +	fifo->poll_errors = false;
> +
> +	return 0;
> +}
> +
>  int can_rx_fifo_add(struct net_device *dev, struct can_rx_fifo *fifo)
>  {
>  	unsigned int weight;
> -	fifo->dev = dev;
> +	int ret;
>  
>  	if ((fifo->low_first < fifo->high_first) &&
>  	    (fifo->high_first < fifo->high_last)) {
> @@ -405,23 +427,14 @@ int can_rx_fifo_add(struct net_device *dev, struct can_rx_fifo *fifo)
>  	    !fifo->poll_can_state)
>  		return -EINVAL;
>  
> -	/* Make ring-buffer a sensible size that is a power of 2 */
> -	fifo->ring_size = (2 << fls(weight));
> -	fifo->ring = kzalloc(sizeof(struct can_frame) * fifo->ring_size,
> -			     GFP_KERNEL);
> -	if (!fifo->ring)
> -		return -ENOMEM;
> -
> -	fifo->ring_head = fifo->ring_tail = 0;
> -
> -	/* Take care of NAPI handling */
> -	netif_napi_add(dev, &fifo->napi, can_rx_fifo_napi_poll, weight);
> +	ret = can_rx_fifo_init_ring(dev, fifo, weight);
> +	if (ret)
> +		return ret;
>  
>  	/* init variables */
>  	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);
>  
> @@ -434,6 +447,26 @@ int can_rx_fifo_add(struct net_device *dev, struct can_rx_fifo *fifo)
>  }
>  EXPORT_SYMBOL_GPL(can_rx_fifo_add);
>  
> +int can_rx_fifo_add_simple(struct net_device *dev, struct can_rx_fifo *fifo)
> +{
> +	int ret;
> +
> +	if (!fifo->mailbox_move_to_buffer || !fifo->poll_bus_error ||
> +	    !fifo->poll_can_state)
> +		return -EINVAL;
> +
> +	ret = can_rx_fifo_init_ring(dev, fifo, 64);
> +	if (ret)
> +		return ret;
> +
> +	/* init variables */
> +	fifo->mask_low = 0;
> +	fifo->mask_high = 0;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(can_rx_fifo_add_simple);

I'd rather see, that we use the same rx_fifo_add() function to create
all rx-fifo available. Can we add a flag to struct can_rx_fifo?

> +
>  static unsigned int can_rx_fifo_offload_if_full(struct can_rx_fifo *fifo, unsigned int n)
>  {
>  	unsigned int head = fifo->ring_head;
> @@ -513,6 +546,23 @@ int can_rx_fifo_irq_offload(struct can_rx_fifo *fifo)
>  }
>  EXPORT_SYMBOL_GPL(can_rx_fifo_irq_offload);
>  
> +int can_rx_fifo_irq_offload_simple(struct can_rx_fifo *fifo)
> +{
> +	unsigned int received = 0;
> +	unsigned int ret;
> +
> +	do {
> +		ret = can_rx_fifo_offload_if_full(fifo, 0);
> +		received += ret;
> +	} while (ret);
> +
> +	if (received)
> +		can_rx_fifo_napi_schedule(fifo);
> +
> +	return received;
> +}
> +EXPORT_SYMBOL_GPL(can_rx_fifo_irq_offload_simple);

I think it's better to have only one offload function, that should do
the right thing depending on the struct can_rx_fifo.

> +
>  void can_rx_fifo_irq_error(struct can_rx_fifo *fifo)
>  {
>  	fifo->poll_errors = true;
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index e1ed6d4..18feef3 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -142,7 +142,9 @@ u8 can_dlc2len(u8 can_dlc);
>  u8 can_len2dlc(u8 len);
>  
>  int can_rx_fifo_add(struct net_device *dev, struct can_rx_fifo *fifo);
> +int can_rx_fifo_add_simple(struct net_device *dev, struct can_rx_fifo *fifo);
>  int can_rx_fifo_irq_offload(struct can_rx_fifo *fifo);
> +int can_rx_fifo_irq_offload_simple(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);
> 

Marc

-- 
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   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2014-11-03 11:59 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
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 [this message]
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=54576E24.5000307@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=alexander.stein@systec-electronic.com \
    --cc=david@protonic.nl \
    --cc=linux-can@vger.kernel.org \
    --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).