linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Mailhol <vincent.mailhol@gmail.com>
To: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Cc: linux-kernel@vger.kernel.org,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Amarula patchwork <linux-amarula@amarulasolutions.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	michael@amarulasolutions.com, Dario Binacchi <dariobin@libero.it>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Wolfgang Grandegger <wg@grandegger.com>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [RFC PATCH v2 4/4] can: bxcan: add support for ST bxCAN controller
Date: Sat, 27 Aug 2022 06:56:42 +0900	[thread overview]
Message-ID: <CAMZ6RqKQJZBVOSU7oA3AGSRG11vxdysAyRotHavUzsVRuM28Kw@mail.gmail.com> (raw)
In-Reply-To: <20220820082936.686924-5-dario.binacchi@amarulasolutions.com>

On Sat. 20 Aug. 2022 à 17:32, Dario Binacchi
<dario.binacchi@amarulasolutions.com> a écrit :
> Add support for the basic extended CAN controller (bxCAN) found in many
> low- to middle-end STM32 SoCs. It supports the Basic Extended CAN
> protocol versions 2.0A and B with a maximum bit rate of 1 Mbit/s.
>
> The controller supports two channels (CAN1 as master and CAN2 as slave)
> and the driver can enable either or both of the channels. They share
> some of the required logic (e. g. clocks and filters), and that means
> you cannot use the slave CAN without enabling some hardware resources
> managed by the master CAN.
>
> Each channel has 3 transmit mailboxes, 2 receive FIFOs with 3 stages and
> 28 scalable filter banks.
> It also manages 4 dedicated interrupt vectors:
> - transmit interrupt
> - FIFO 0 receive interrupt
> - FIFO 1 receive interrupt
> - status change error interrupt
>
> Driver uses all 3 available mailboxes for transmission and FIFO 0 for
> reception. Rx filter rules are configured to the minimum. They accept
> all messages and assign filter 0 to CAN1 and filter 14 to CAN2 in
> identifier mask mode with 32 bits width. It enables and uses transmit,
> receive buffers for FIFO 0 and error and status change interrupts.
>
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
>
> ---

(...)

> +static void bxcan_handle_state_change(struct net_device *ndev, u32 esr)
> +{
> +       struct bxcan_priv *priv = netdev_priv(ndev);
> +       struct net_device_stats *stats = &ndev->stats;
> +       enum can_state new_state = priv->can.state;
> +       struct can_berr_counter bec;
> +       enum can_state rx_state, tx_state;
> +       struct sk_buff *skb;
> +       struct can_frame *cf;
> +
> +       /* Early exit if no error flag is set */
> +       if (!(esr & (BXCAN_ESR_EWGF | BXCAN_ESR_EPVF | BXCAN_ESR_BOFF)))
> +               return;
> +
> +       bec.txerr = BXCAN_TEC(esr);
> +       bec.rxerr = BXCAN_REC(esr);
> +
> +       if (esr & BXCAN_ESR_BOFF)
> +               new_state = CAN_STATE_BUS_OFF;
> +       else if (esr & BXCAN_ESR_EPVF)
> +               new_state = CAN_STATE_ERROR_PASSIVE;
> +       else if (esr & BXCAN_ESR_EWGF)
> +               new_state = CAN_STATE_ERROR_WARNING;
> +
> +       /* state hasn't changed */
> +       if (unlikely(new_state == priv->can.state))
> +               return;
> +
> +       skb = alloc_can_err_skb(ndev, &cf);
> +       if (unlikely(!skb))
> +               return;
> +
> +       tx_state = bec.txerr >= bec.rxerr ? new_state : 0;
> +       rx_state = bec.txerr <= bec.rxerr ? new_state : 0;
> +       can_change_state(ndev, cf, tx_state, rx_state);
> +
> +       if (new_state == CAN_STATE_BUS_OFF)
> +               can_bus_off(ndev);
> +
> +       stats->rx_bytes += cf->len;

Please do not increment the stats if the frame is remote (c.f. CAN_RTR_FLAG).

> +       stats->rx_packets++;
> +       netif_rx(skb);
> +}


Yours sincerely,
Vincent Mailhol

      reply	other threads:[~2022-08-26 21:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20  8:29 [RFC PATCH v2 0/4] can: bxcan: add support for ST bxCAN controller Dario Binacchi
2022-08-20  8:29 ` [RFC PATCH v2 1/4] dt-bindings: net: can: add STM32 bxcan DT bindings Dario Binacchi
2022-08-23 13:41   ` Krzysztof Kozlowski
2022-08-26  7:12     ` Dario Binacchi
2022-08-25 21:12   ` Rob Herring
2022-08-26  7:27     ` Dario Binacchi
2022-08-31 22:05       ` Rob Herring
2022-08-20  8:29 ` [RFC PATCH v2 2/4] ARM: dts: stm32: add CAN support on stm32f429 Dario Binacchi
2022-08-20  8:29 ` [RFC PATCH v2 3/4] ARM: dts: stm32: add pin map for CAN controller on stm32f4 Dario Binacchi
2022-08-23 13:43   ` Krzysztof Kozlowski
2022-08-26  6:32     ` Dario Binacchi
2022-08-20  8:29 ` [RFC PATCH v2 4/4] can: bxcan: add support for ST bxCAN controller Dario Binacchi
2022-08-26 21:56   ` Vincent Mailhol [this message]

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=CAMZ6RqKQJZBVOSU7oA3AGSRG11vxdysAyRotHavUzsVRuM28Kw@mail.gmail.com \
    --to=vincent.mailhol@gmail.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=dariobin@libero.it \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@amarulasolutions.com \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --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).