netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* can: c_can: TX handling
@ 2011-03-22 15:59 Jan Altenberg
  2011-03-23  8:51 ` can: c_can: TX echo Kurt Van Dijck
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Jan Altenberg @ 2011-03-22 15:59 UTC (permalink / raw)
  To: bhupesh.sharma; +Cc: wg, kurt.van.dijck, b.spranger, netdev

Hi all,

I did some more testing on the SocketCAN driver for the Bosch c_can
controller and I observed some strange behaviour for the TX handling.
First of all the TX bytes are not accounted correctly. The reason for that
seems to be quite obvious if we look into c_can_do_tx():

[...]

c_can_inval_msg_object(dev, 0, msg_obj_no);
val = c_can_read_reg32(priv, &priv->regs->txrqst1);
if (!(val & (1 << msg_obj_no))) {
        can_get_echo_skb(dev,
                        msg_obj_no - C_CAN_MSG_OBJ_TX_FIRST);
        stats->tx_bytes += priv->read_reg(priv,
                        &priv->regs->ifregs[0].msg_cntrl)
                        & IF_MCONT_DLC_MASK;

So, we first invalidate the message object and afterwards we read the DLC
value from the msg_cntrl (which is 0 after invalidating the
message object) to account the TX bytes. So tx_bytes will always be 0. The
fix should be easy, I think, we can just move
c_can_inval_msg_object to the end of that loop.

The second problem is related to tx_next, which should hold the number of
the oldest CAN frame, which was not on the line:

for (/* nix */; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) {
        msg_obj_no = get_tx_echo_msg_obj(priv);
        c_can_inval_msg_object(dev, 0, msg_obj_no);
        val = c_can_read_reg32(priv, &priv->regs->txrqst1);
        if (!(val & (1 << msg_obj_no))) {
                can_get_echo_skb(dev,
                                msg_obj_no - C_CAN_MSG_OBJ_TX_FIRST);
                stats->tx_bytes += priv->read_reg(priv,
                                &priv->regs->ifregs[0].msg_cntrl)
                                & IF_MCONT_DLC_MASK;
                stats->tx_packets++;
        }
}

But tx_echo is incremented unconditionally and we don't actually track the
number of the oldest unsent frame.
Let's assume the following scenario: We bring up can0 and send 3
frames: TX object: 0, 1, 2; 1 and 2 make it on the line, but 0 is
still pending. If we go through the above loop in that situation, we will
skip message object 0, because the txrqst bit is still set.  We will
account message object 1 and 2. That's correct, but afterwards tx_echo is
set to 2, BUT the oldest message which is pending is 0. Am I right or did
I get something wrong?
The operation of c_can_do_tx() is described as follows: "We iterate from
priv->tx_echo to priv->tx_next and check if the packet has been
transmitted, echo it back to the CAN framework. If we discover a not yet
transmitted package, stop looking for more." The actual
implementation doesn't seem to stop if we discover a not yet
transmitted package. But I'm not sure if just stopping might be a
good idea, because in that case, the echo skb for already transmitted
messages might be delayed by not yet transmitted messages.

Cheers,
        Jan





^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2011-03-28  1:24 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-22 15:59 can: c_can: TX handling Jan Altenberg
2011-03-23  8:51 ` can: c_can: TX echo Kurt Van Dijck
2011-03-23 13:54   ` Jan Altenberg
2011-03-23 14:25     ` Wolfgang Grandegger
2011-03-23 14:52       ` Jan Altenberg
2011-03-23  8:53 ` can: c_can: TX delivery Kurt Van Dijck
2011-03-23 15:32   ` Jan Altenberg
2011-03-23 15:49     ` Kurt Van Dijck
2011-03-24 10:02     ` Marc Kleine-Budde
2011-03-24  4:18 ` c_can: TX handling Bhupesh SHARMA
2011-03-24 10:56   ` Jan Altenberg
2011-03-24  5:43 ` Bhupesh SHARMA
2011-03-24 10:38   ` [PATCH] can: c_can: Fix tx_bytes accounting Jan Altenberg
2011-03-24 10:00     ` Wolfgang Grandegger
2011-03-24 11:26       ` [PATCH resend] " Jan Altenberg
2011-03-24 10:49         ` Kurt Van Dijck
     [not found]           ` <20110324104925.GB339-MxZ6Iy/zr/UdbCeoMzGj59i2O/JbrIOy@public.gmane.org>
2011-03-24 11:49             ` Wolfgang Grandegger
     [not found]               ` <4D8B2FAF.5040000-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2011-03-28  1:24                 ` David Miller

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