From: Andrew Lunn <andrew@lunn.ch>
To: Hal Feng <hal.feng@starfivetech.com>
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Emil Renner Berthing <emil.renner.berthing@canonical.com>,
William Qiu <william.qiu@starfivetech.com>,
devicetree@vger.kernel.org, linux-can@vger.kernel.org,
netdev@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/4] can: Add driver for CAST CAN Bus Controller
Date: Sun, 22 Sep 2024 18:33:57 +0200 [thread overview]
Message-ID: <cf17f15b-cbd7-4692-b3b2-065e549cb21e@lunn.ch> (raw)
In-Reply-To: <20240922145151.130999-4-hal.feng@starfivetech.com>
> +static inline u32 ccan_read_reg(const struct ccan_priv *priv, u8 reg)
> +{
> + return ioread32(priv->reg_base + reg);
> +}
> +
> +static inline void ccan_write_reg(const struct ccan_priv *priv, u8 reg, u32 value)
> +{
> + iowrite32(value, priv->reg_base + reg);
> +}
No inline functions in .c files please. Let the compiler decide.
> +static inline u8 ccan_read_reg_8bit(const struct ccan_priv *priv,
> + enum ccan_reg reg)
> +{
> + u8 reg_down;
> + union val {
> + u8 val_8[4];
> + u32 val_32;
> + } val;
> +
> + reg_down = ALIGN_DOWN(reg, 4);
> + val.val_32 = ccan_read_reg(priv, reg_down);
> + return val.val_8[reg - reg_down];
There is an ioread8(). Is it invalid to do a byte read for this
hardware? If so, it is probably worth a comment.
> +static int ccan_bittime_configuration(struct net_device *ndev)
> +{
> + struct ccan_priv *priv = netdev_priv(ndev);
> + struct can_bittiming *bt = &priv->can.bittiming;
> + struct can_bittiming *dbt = &priv->can.data_bittiming;
> + u32 bittiming, data_bittiming;
> + u8 reset_test;
> +
> + reset_test = ccan_read_reg_8bit(priv, CCAN_CFG_STAT);
> +
> + if (!(reset_test & CCAN_RST_MASK)) {
> + netdev_alert(ndev, "Not in reset mode, cannot set bit timing\n");
> + return -EPERM;
> + }
You don't see nedev_alert() used very often. If this is fatal then
netdev_err().
Also, EPERM? man 3 errno say:
EPERM Operation not permitted (POSIX.1-2001).
Why is this a permission issue?
> +static void ccan_tx_interrupt(struct net_device *ndev, u8 isr)
> +{
> + struct ccan_priv *priv = netdev_priv(ndev);
> +
> + /* wait till transmission of the PTB or STB finished */
> + while (isr & (CCAN_TPIF_MASK | CCAN_TSIF_MASK)) {
> + if (isr & CCAN_TPIF_MASK)
> + ccan_reg_set_bits(priv, CCAN_RTIF, CCAN_TPIF_MASK);
> +
> + if (isr & CCAN_TSIF_MASK)
> + ccan_reg_set_bits(priv, CCAN_RTIF, CCAN_TSIF_MASK);
> +
> + isr = ccan_read_reg_8bit(priv, CCAN_RTIF);
> + }
Potentially endless loops like this are a bad idea. If the firmware
crashes, you are never getting out of here. Please use one of the
macros from iopoll.h
> +static irqreturn_t ccan_interrupt(int irq, void *dev_id)
> +{
> + struct net_device *ndev = (struct net_device *)dev_id;
dev_id is a void *, so you don't need the cast.
Andrew
next prev parent reply other threads:[~2024-09-22 16:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-22 14:51 [PATCH v2 0/4] CAST Controller Area Network driver support Hal Feng
2024-09-22 14:51 ` [PATCH v2 1/4] dt-bindings: vendor-prefixes: Add cast vendor prefix Hal Feng
2024-09-22 14:51 ` [PATCH v2 2/4] dt-bindings: can: Add CAST CAN Bus Controller Hal Feng
2024-09-24 18:01 ` Rob Herring (Arm)
2024-09-24 20:03 ` Rob Herring
2024-09-22 14:51 ` [PATCH v2 3/4] can: Add driver for " Hal Feng
2024-09-22 16:33 ` Andrew Lunn [this message]
2024-09-23 7:53 ` Hal Feng
2024-09-23 12:12 ` Andrew Lunn
2024-10-28 14:18 ` Marc Kleine-Budde
2024-09-22 21:13 ` Marc Kleine-Budde
2024-10-25 1:45 ` Hal Feng
2024-10-28 15:28 ` Marc Kleine-Budde
2024-09-23 3:41 ` Vincent MAILHOL
2024-10-15 9:30 ` Hal Feng
2024-10-16 5:05 ` Vincent MAILHOL
2024-10-16 14:16 ` Vincent MAILHOL
2024-09-22 14:51 ` [PATCH v2 4/4] riscv: dts: starfive: jh7110: Add CAN nodes Hal Feng
-- strict thread matches above, loose matches on Subject: below --
2024-10-25 2:11 [PATCH v2 3/4] can: Add driver for CAST CAN Bus Controller Hal Feng
2024-10-25 2:49 Hal Feng
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=cf17f15b-cbd7-4692-b3b2-065e549cb21e@lunn.ch \
--to=andrew@lunn.ch \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=emil.renner.berthing@canonical.com \
--cc=hal.feng@starfivetech.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=william.qiu@starfivetech.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).