From: "Ahmed S. Darwish" <darwish.07@gmail.com>
To: "Thomas Körper" <thomas.koerper@esd.eu>
Cc: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
Andri Yngvason <andri.yngvason@marel.com>
Subject: Re: [PATCH V6 1/1] can: Add support for esd CAN PCIe/402 card
Date: Tue, 17 Mar 2015 09:33:09 -0400 [thread overview]
Message-ID: <20150317133309.GA30168@linux> (raw)
In-Reply-To: <1426592308-23817-1-git-send-email-thomas.koerper@esd.eu>
Hi,
[ Adding Marc to the CC list. Kindly add him in future submissions.. ]
On Tue, Mar 17, 2015 at 12:38:28PM +0100, Thomas Körper wrote:
...
> +netdev_tx_t acc_start_xmit(struct sk_buff *skb, struct net_device *netdev)
> +{
> + struct acc_net_priv *priv = netdev_priv(netdev);
> + struct acc_core *core = priv->core;
> + struct can_frame *cf = (struct can_frame *)skb->data;
> + u8 new_fifo_head = (core->tx_fifo_head + 1) % core->tx_fifo_size;
> + u32 esd_id;
> + u8 esd_len;
> +
> + if ((new_fifo_head == core->tx_fifo_tail) || !acc_txq_isready(core)) {
> + netif_stop_queue(netdev);
> + return NETDEV_TX_BUSY;
> + }
> +
In that case, an error or warning message is in order. Quoting from
Documentation/networking/{driver.txt,netdevices.txt}:
When this happens, it usually means start/stop flow control
is broken in the driver. This is a hard error that should be logged:
netdev_err("BUG: Tx ring full when queue awake!\n");
[ Actually it would be nice to print such message and _heavily_ test
the driver tx/rx pathes afterwards, making sure no practical race
conditions exist regarding the netif tx queue .. ]
On another topic, I've searched the code for the part where it stops
the queue because "we've taken the last slot in the ring, and we will
not be able to handle further transmissions" but couldn't find it at
all. AFAIK, that part calls netif_stop_queue(), but _always_ return
with NETDEV_TX_OK. Am I missing something obvious?
[...]
> +static void
> +handle_core_msg_errstatechange(struct acc_core *core,
> + const struct acc_bmmsg_errstatechange *msg)
> +{
> + struct acc_net_priv *priv = netdev_priv(core->net_dev);
> + struct net_device_stats *stats = &core->net_dev->stats;
> + struct can_frame *cf;
> + struct sk_buff *skb;
> +
> + skb = alloc_can_err_skb(core->net_dev, &cf);
> + if (skb) {
> + enum can_state new_state;
> + u8 txerr;
> + u8 rxerr;
> +
> + txerr = (u8)(msg->reg_status >> 8);
> + rxerr = (u8)msg->reg_status;
> +
> + cf->data[6] = txerr;
> + cf->data[7] = rxerr;
> +
> + if (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_BS)
> + new_state = CAN_STATE_BUS_OFF;
> + else if (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_EP)
> + new_state = CAN_STATE_ERROR_PASSIVE;
> + else if (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_ES)
> + new_state = CAN_STATE_ERROR_WARNING;
> + else
> + new_state = CAN_STATE_ERROR_ACTIVE;
> +
> + if (new_state != priv->can.state) {
> + enum can_state tx_state, rx_state;
> +
> + tx_state = (txerr >= rxerr) ? new_state : 0;
> + rx_state = (rxerr >= txerr) ? new_state : 0;
> +
> + can_change_state(core->net_dev, cf, tx_state, rx_state);
> + }
> +
@Marc: can we set a standard for new drivers to update the CAN state
before trying an skb allocation than can fail with -ENOMEM? That way,
in the future, we will have the incentive to break can_change_state()
responsibility between 1) updating the CAN interface's state & counters,
and 2) setting up of CAN error frame ID and data to userspace.
@Thomas: Kindly check kvaser_usb.c::kvaser_usb_rx_err() for context.
Of course Marc will have the final word for this :-)
> + netif_rx(skb);
> + stats->rx_packets++;
> + stats->rx_bytes += cf->can_dlc;
> + } else {
> + stats->rx_dropped++;
> + }
> +
> + if (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_BS) {
> + acc_write32(core, ACC_CORE_OF_TX_ABORT_MASK, 0xffff);
> + can_bus_off(core->net_dev);
> + }
> +}
Thanks,
Darwish
next prev parent reply other threads:[~2015-03-17 13:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 11:38 [PATCH V6 1/1] can: Add support for esd CAN PCIe/402 card Thomas Körper
2015-03-17 13:33 ` Ahmed S. Darwish [this message]
2015-03-17 14:51 ` Ahmed S. Darwish
2015-03-17 21:55 ` Ahmed S. Darwish
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=20150317133309.GA30168@linux \
--to=darwish.07@gmail.com \
--cc=andri.yngvason@marel.com \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=thomas.koerper@esd.eu \
/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).