From: Vincent Mailhol <mailhol@kernel.org>
To: Binbin Zhou <zhoubb.aaron@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
Huacai Chen <chenhuacai@loongson.cn>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Bingxiong Li <libingxiong@loongson.cn>,
Huacai Chen <chenhuacai@kernel.org>,
Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, linux-can@vger.kernel.org,
jeffbai@aosc.io
Subject: Re: [PATCH v2 1/2] can: Add Loongson CAN-FD controller driver
Date: Fri, 19 Jun 2026 18:24:36 +0200 [thread overview]
Message-ID: <38387630-513e-470c-9c19-b5f7391f1fc3@kernel.org> (raw)
In-Reply-To: <CAMpQs4J5vq8U-_1BanyFcn6PYhnws=vuE3Yq1hvSBbLZJC8aEQ@mail.gmail.com>
On 18/06/2026 at 11:49, Binbin Zhou wrote:
> Hi Vincent:
>
> Thanks for your detailed review and sorry for the late reply.
>
> On Tue, Jun 9, 2026 at 1:43 AM Vincent Mailhol <mailhol@kernel.org> wrote:
>>
>> On 08/06/2026 at 10:49, Binbin Zhou wrote:
(...)
>>> +static void loongson_canfd_set_mode(struct loongson_canfd_priv *priv,
>>> + const struct can_ctrlmode *ctrlmode)
>>
>> Rename this to loongson_canfd_set_ctrlmode(). Otherwhise there is a
>> risk of confusion with loongson_canfd_do_set_mode()
>
> Actually, this function sets the `LOONGSON_CANFD_MODE` and
> `LOONGSON_CANFD_CONF` registers based on `priv->can.ctrlmode`.
>
> How about rewriting it as follows:
>
> static void loongson_canfd_set_confmode(struct loongson_canfd_priv *priv)
> {
> u32 ctrlmode = priv->can.ctrlmode;
> .....
> }
That also works. My point was to avoid the confusion with
loongson_canfd_do_set_mode(). As long as there is enough disambiguation,
it is OK for me.
(...)
>>> + /* Write Data payload */
>>> + if (!(cf->can_id & CAN_RTR_FLAG)) {
>>> + for (unsigned int i = 0; i < cf->len; i += LOONGSON_CANFD_DW_BYTE) {
>>> + regmap_write(priv->regmap,
>>> + LOONGSON_CANFD_TX_DATA_1 + LOONGSON_CANFD_FRAME_DB_1 + i,
>>> + le32_to_cpu(*(__le32 *)(cf->data + i)));
>> ^^^^^^^^^^
>> This cast is just wrong. What if the code is run on a big endian
>> machine?
>>
>> To begin with, here, you are writing to your registers. So it should
>> be the other way around: cpu_to_le32(). And to add to it, if you need
>> endian conversion, populate regmap_config.val_format_endian.
>>
>> Also, why do you need some endian conversion only here and not on the
>> other registers?
>
> Sorry, this is the old test code—I forgot to update it. Just use `u32`:
>
> for (i = 0; i < len; i += LOONGSON_CANFD_DW_BYTE)
> regmap_read(priv->regmap, LOONGSON_CANFD_RX_DATA, (u32
> *)(cf->data + i));
OK. Note that I don't mind if you want to keep the declaration of i in
the for loop:
for (unsigned int i = 0; i < len; i += LOONGSON_CANFD_DW_BYTE)
/* ... */
>>> + }
>>> + }
>>> +
>>> + return true;
>>> +}
(...)
>>> +static irqreturn_t loongson_canfd_interrupt(int irq, void *dev_id)
>>> +{
>>> + struct net_device *ndev = (struct net_device *)dev_id;
>>> + struct loongson_canfd_priv *priv = netdev_priv(ndev);
>>> + u32 isr, imask;
>>> +
>>> + for (unsigned int irq_loops = 0; irq_loops < 10000; irq_loops++) {
>>> + /* Get the interrupt status */
>>> + regmap_read(priv->regmap, LOONGSON_CANFD_INT_STAT, &isr);
>>> + if (!isr)
>>> + return irq_loops ? IRQ_HANDLED : IRQ_NONE;
>>
>> if (irq_loops)
>> return IRQ_HANDLED;
>> else
>> return IRQ_NONE;
>>
> Emm...
> Is the ternary operator here more concise than `if-else`?
>
> if (!isr) {
> if (irq_loops)
> return IRQ_HANDLED;
> else
> return IRQ_NONE;
> }
Unless you are getting an actual checkpatch.pl warning here, if I record
correctly, the curly brackets can be ommitted here:
if (!isr)
if (irq_loops)
return IRQ_HANDLED;
else
return IRQ_NONE;
> vs
>
> if (!isr)
> return irq_loops ? IRQ_HANDLED : IRQ_NONE;
Yes, it is more consise, but is it more readable?
Actually, you might say that which one is the most readable is a
subjective topic and you would be right.
But it is the prefered style here. The indentation of the if/else makes
it more visual. And when you review thousands of line of code, it starts
to make a difference.
And I this is not my personnal opinion. For example, see this message
from Greg:
https://lore.kernel.org/all/20250311150130.7a875e63@bahia/
So, even if this is an arguable case, let this be an if/else.
(...)
>>> +static const struct net_device_ops loongson_canfd_netdev_ops = {
>>> + .ndo_open = loongson_canfd_open,
>>> + .ndo_stop = loongson_canfd_close,
>>> + .ndo_start_xmit = loongson_canfd_start_xmit,
>>> +};
>>
>> Also add a struct ethtool_ops and populate
>> ethtool_ops.get_ts_info. Something like:
>>
>> static const struct ethtool_ops es58x_ethtool_ops = {
>> .get_ts_info = can_ethtool_op_get_ts_info_hwts,
>> };
>>
>> Refer to what the other CAN drivers with hardware timestamps are
>> doing.
>
> Regarding the hardware timestamp, could this be submitted as a
> separate feature patch? I need some time to resolve the related
> issues.
> Could we proceed as follows for now:
>
> static const struct ethtool_ops loongson_canfd_ethtool_ops = {
> .get_ts_info = ethtool_op_get_ts_info,
> };
OK, but make sure to remove all your local hacks. We will not accept the
use of the reserved fields in sturct canfd_frame for that.
Note that once you undertsand the timestamp framework, I would expect
the patch to be rather tiny.
Yours sincerely,
Vincent Mailhol
next prev parent reply other threads:[~2026-06-19 16:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 8:49 [PATCH v2 0/2] Add Loongson CAN-FD controller driver Binbin Zhou
2026-06-08 8:49 ` [PATCH v2 1/2] can: " Binbin Zhou
2026-06-08 17:43 ` Vincent Mailhol
2026-06-18 9:49 ` Binbin Zhou
2026-06-19 16:24 ` Vincent Mailhol [this message]
2026-06-09 18:49 ` sashiko-bot
2026-06-08 8:49 ` [PATCH v2 2/2] can: loongson_canfd: Add RXDMA support Binbin Zhou
2026-06-08 12:13 ` Vincent Mailhol
2026-06-15 1:35 ` Binbin Zhou
2026-06-15 8:35 ` Vincent Mailhol
2026-06-09 18:59 ` sashiko-bot
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=38387630-513e-470c-9c19-b5f7391f1fc3@kernel.org \
--to=mailhol@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=jeffbai@aosc.io \
--cc=kernel@xen0n.name \
--cc=libingxiong@loongson.cn \
--cc=linux-can@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mkl@pengutronix.de \
--cc=zhoubb.aaron@gmail.com \
--cc=zhoubinbin@loongson.cn \
/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