All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Markus Pargmann <mpa@pengutronix.de>,
	Benedikt Spranger <b.spranger@linutronix.de>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org
Subject: [patch 11/12] can: c_can: Simplify TX interrupt cleanup
Date: Tue, 18 Mar 2014 17:19:14 -0000	[thread overview]
Message-ID: <20140318171127.802717594@linutronix.de> (raw)
In-Reply-To: 20140318171007.528610837@linutronix.de

[-- Attachment #1: can-c_can-simplify-xmit.patch --]
[-- Type: text/plain, Size: 2925 bytes --]

The function loads the message object from the hardware to get the
payload length. The previous patch stores that information in an
array, so we can avoid the hardware access.

Remove the hardware access and move the led toggle outside of the
spinlocked region. Toggle the led only once when at least one packet
has been received.

Binary size shrinks along with the code

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/net/can/c_can/c_can.c |   37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

Index: linux/drivers/net/can/c_can/c_can.c
===================================================================
--- linux.orig/drivers/net/can/c_can/c_can.c
+++ linux/drivers/net/can/c_can/c_can.c
@@ -232,10 +232,9 @@ static inline int get_tx_next_msg_obj(co
 			C_CAN_MSG_OBJ_TX_FIRST;
 }
 
-static inline int get_tx_echo_msg_obj(const struct c_can_priv *priv)
+static inline int get_tx_echo_msg_obj(int txecho)
 {
-	return (priv->tx_echo & C_CAN_NEXT_MSG_OBJ_MASK) +
-			C_CAN_MSG_OBJ_TX_FIRST;
+	return (txecho & C_CAN_NEXT_MSG_OBJ_MASK) + C_CAN_MSG_OBJ_TX_FIRST;
 }
 
 static u32 c_can_read_reg32(struct c_can_priv *priv, enum reg index)
@@ -720,8 +719,6 @@ static int c_can_get_berr_counter(const
 }
 
 /*
- * theory of operation:
- *
  * priv->tx_echo holds the number of the oldest can_frame put for
  * transmission into the hardware, but not yet ACKed by the CAN tx
  * complete IRQ.
@@ -732,29 +729,23 @@ static int c_can_get_berr_counter(const
  */
 static void c_can_do_tx(struct net_device *dev)
 {
-	u32 val;
-	u32 msg_obj_no;
 	struct c_can_priv *priv = netdev_priv(dev);
 	struct net_device_stats *stats = &dev->stats;
+	u32 val, obj, pkts = 0, bytes = 0;
 
 	spin_lock_bh(&priv->xmit_lock);
 
 	for (; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) {
-		msg_obj_no = get_tx_echo_msg_obj(priv);
+		obj = get_tx_echo_msg_obj(priv->tx_echo);
 		val = c_can_read_reg32(priv, C_CAN_TXRQST1_REG);
-		if (!(val & (1 << (msg_obj_no - 1)))) {
-			can_get_echo_skb(dev,
-					msg_obj_no - C_CAN_MSG_OBJ_TX_FIRST);
-			c_can_object_get(dev, IF_TX, msg_obj_no, IF_COMM_ALL);
-			stats->tx_bytes += priv->read_reg(priv,
-					C_CAN_IFACE(MSGCTRL_REG, IF_TX))
-					& IF_MCONT_DLC_MASK;
-			stats->tx_packets++;
-			can_led_event(dev, CAN_LED_EVENT_TX);
-			c_can_inval_msg_object(dev, IF_TX, msg_obj_no);
-		} else {
+
+		if (val & (1 << (obj - 1)))
 			break;
-		}
+
+		can_get_echo_skb(dev, obj - C_CAN_MSG_OBJ_TX_FIRST);
+		bytes += priv->dlc[obj - C_CAN_MSG_OBJ_TX_FIRST];
+		pkts++;
+		c_can_inval_msg_object(dev, IF_TX, obj);
 	}
 
 	/* restart queue if wrap-up or if queue stalled on last pkt */
@@ -763,6 +754,12 @@ static void c_can_do_tx(struct net_devic
 		netif_wake_queue(dev);
 
 	spin_unlock_bh(&priv->xmit_lock);
+
+	if (pkts) {
+		stats->tx_bytes += bytes;
+		stats->tx_packets += pkts;
+		can_led_event(dev, CAN_LED_EVENT_TX);
+	}
 }
 
 /*

  parent reply	other threads:[~2014-03-18 17:19 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18 17:19 [patch 00/12] can: c_can: Fix a series of serious bugs and improve the performance Thomas Gleixner
2014-03-18 17:19 ` [patch 02/12] can: c_can: Fix hardware raminit function Thomas Gleixner
2014-03-18 18:38   ` Marc Kleine-Budde
2014-03-18 22:15     ` Thomas Gleixner
2014-03-19  6:37       ` Oliver Hartkopp
2014-03-19  9:22         ` Thomas Gleixner
2014-03-18 17:19 ` [patch 01/12] can: c_can: Wait for CONTROL_INIT to be cleared Thomas Gleixner
2014-03-18 18:11   ` Marc Kleine-Budde
2014-03-18 18:19     ` Thomas Gleixner
2014-03-18 17:19 ` [patch 03/12] can: c_can: Make it SMP safe Thomas Gleixner
2014-03-18 18:46   ` Marc Kleine-Budde
2014-03-18 19:40     ` Thomas Gleixner
2014-03-18 17:19 ` [patch 04/12] can: c_can: Fix buffer ordering for real Thomas Gleixner
2014-03-18 17:19 ` [patch 05/12] can: c_can: Fix the lost message handling Thomas Gleixner
2014-03-18 17:19 ` [patch 06/12] can: c_can: Remove braindamaged EOB exit Thomas Gleixner
2014-03-18 17:19 ` [patch 07/12] can: c_can: Provide protection in the xmit path Thomas Gleixner
2014-03-18 17:19 ` [patch 08/12] can: c_can: Makethe code readable Thomas Gleixner
2014-03-18 17:37   ` Joe Perches
2014-03-18 18:23     ` Thomas Gleixner
2014-03-18 18:27     ` [patch 08/12 V2] " Thomas Gleixner
2014-03-18 19:20       ` Joe Perches
2014-03-18 17:19 ` [patch 09/12] can: c_can: Reduce register access for real Thomas Gleixner
2014-03-18 17:19 ` Thomas Gleixner [this message]
2014-03-18 17:19 ` [patch 10/12] can: c_can: Store dlc private Thomas Gleixner
2014-03-18 17:19 ` [patch 12/12] can: c_can: Avoid led toggling for every packet Thomas Gleixner
2014-03-18 20:18   ` can: c_can: Reduce interrupt load by 50% Thomas Gleixner
2014-03-18 20:35     ` Joe Perches
2014-03-18 20:43       ` Thomas Gleixner
2014-03-18 21:27         ` Joe Perches
2014-03-31 22:35 ` [patch 00/12] can: c_can: Fix a series of serious bugs and improve the performance Thomas Gleixner
2014-04-01  8:09   ` Marc Kleine-Budde
2014-04-01  9:07     ` Thomas Gleixner
2014-04-01  9:09       ` Marc Kleine-Budde
2014-04-01 21:29     ` 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=20140318171127.802717594@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=b.spranger@linutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=mpa@pengutronix.de \
    --cc=netdev@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 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.