From: Andri Yngvason <andri.yngvason@marel.com>
To: linux-can@vger.kernel.org
Cc: "Thomas Körper" <thomas.koerper@esd.eu>
Subject: Re: [PATCH V5 1/1] can: Add support for esd CAN PCIe/402 card
Date: Mon, 16 Mar 2015 12:46:21 +0000 [thread overview]
Message-ID: <20150316124621.14895.31220@shannon> (raw)
In-Reply-To: <1426508113-14904-1-git-send-email-thomas.koerper@esd.eu>
Quoting Thomas Körper (2015-03-16 12:15:13)
[...]
> +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;
> + int is_busoff;
> + int is_passive;
> + int is_warning;
> + u8 txerr;
> + u8 rxerr;
> +
> + txerr = (u8)(msg->reg_status >> 8);
> + rxerr = (u8)msg->reg_status;
> + is_warning = (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_ES) != 0;
> + is_passive = (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_EP) != 0;
> + is_busoff = (msg->reg_status & ACC_REG_STATUS_MASK_STATUS_BS) != 0;
> +
> + skb = alloc_can_err_skb(core->net_dev, &cf);
> + if (skb) {
> + if (is_busoff) {
> + priv->can.state = CAN_STATE_BUS_OFF;
> + /* bus-offs counted by can_bus_off() */
> + cf->can_id |= CAN_ERR_BUSOFF;
> + } else if (is_passive) {
> + priv->can.state = CAN_STATE_ERROR_PASSIVE;
> + priv->can.can_stats.error_passive++;
> + cf->data[1] = (txerr > rxerr) ?
> + CAN_ERR_CRTL_TX_PASSIVE :
> + CAN_ERR_CRTL_RX_PASSIVE;
> + cf->can_id |= CAN_ERR_CRTL;
> + cf->data[6] = txerr;
> + cf->data[7] = rxerr;
> + } else if (is_warning) {
> + priv->can.state = CAN_STATE_ERROR_WARNING;
> + priv->can.can_stats.error_warning++;
> + cf->data[1] = (txerr > rxerr) ?
> + CAN_ERR_CRTL_TX_WARNING :
> + CAN_ERR_CRTL_RX_WARNING;
> + cf->can_id |= CAN_ERR_CRTL;
> + cf->data[6] = txerr;
> + cf->data[7] = rxerr;
> + } else {
> + priv->can.state = CAN_STATE_ERROR_ACTIVE;
> + /* restarts counted in dev.c */
>
There is now a back-to-error-active message available for use, so you can do
cf->can_id = CAN_ERR_CRTL;
cf->data[1] = CAN_ERROR_CRTL_ACTIVE.
However, you could shave off a few lines in this code by using
can_change_state().
>
> + }
> +
> + netif_rx(skb);
> + stats->rx_packets++;
> + stats->rx_bytes += cf->can_dlc;
> + }
> +
> + if (is_busoff) {
> + acc_write32(core, ACC_CORE_OF_TX_ABORT_MASK, 0xffff);
> + can_bus_off(core->net_dev);
> + }
> +}
> +
[...]
can_change_state() is now used in mscan, flexcan, sja1000, kvaser and peak.
Those drivers should provide sufficent examples for you to learn how to use the
function.
Best regards,
Andri Yngvason
next prev parent reply other threads:[~2015-03-16 13:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-16 12:15 [PATCH V5 1/1] can: Add support for esd CAN PCIe/402 card Thomas Körper
2015-03-16 12:46 ` Andri Yngvason [this message]
2015-03-16 13:35 ` Marc Kleine-Budde
2015-03-17 6:30 ` AW: " Thomas Körper
2015-03-17 7:26 ` Ahmed S. Darwish
2015-03-17 10:10 ` Andri Yngvason
2015-03-17 10:33 ` AW: " Andri Yngvason
2015-03-17 21:27 ` Marc Kleine-Budde
2015-03-18 5:08 ` Thomas Körper
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=20150316124621.14895.31220@shannon \
--to=andri.yngvason@marel.com \
--cc=linux-can@vger.kernel.org \
--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