[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOoeyxXRMhkRhi20tctcs3Htg4wug4wPd+n_f_NZcVBtV-GuXA@mail.gmail.com>
Date: Fri, 1 Nov 2024 13:32:07 +0800
From: Ming Yu <a0282524688@...il.com>
To: Marc Kleine-Budde <mkl@...gutronix.de>
Cc: tmyu0@...oton.com, lee@...nel.org, linus.walleij@...aro.org, brgl@...ev.pl,
andi.shyti@...nel.org, mailhol.vincent@...adoo.fr, andrew+netdev@...n.ch,
davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
wim@...ux-watchdog.org, linux@...ck-us.net, jdelvare@...e.com,
jic23@...nel.org, lars@...afoo.de, ukleinek@...nel.org,
alexandre.belloni@...tlin.com, linux-kernel@...r.kernel.org,
linux-gpio@...r.kernel.org, linux-i2c@...r.kernel.org,
linux-can@...r.kernel.org, netdev@...r.kernel.org,
linux-watchdog@...r.kernel.org, linux-hwmon@...r.kernel.org,
linux-iio@...r.kernel.org, linux-pwm@...r.kernel.org,
linux-rtc@...r.kernel.org
Subject: Re: [PATCH v1 4/9] can: Add Nuvoton NCT6694 CAN support
> > > +static netdev_tx_t nct6694_canfd_start_xmit(struct sk_buff *skb,
> > > + struct net_device *ndev)
> > > +{
> > > + struct nct6694_canfd_priv *priv = netdev_priv(ndev);
> > > + struct nct6694 *nct6694 = priv->nct6694;
> > > + struct canfd_frame *cf = (struct canfd_frame *)skb->data;
> > > + struct net_device_stats *stats = &ndev->stats;
> > > + int can_idx = priv->can_idx;
> > > + u32 txid = 0;
> > > + int i;
> > > + unsigned int echo_byte;
> > > + u8 data_buf[REQUEST_CAN_CMD10_LEN] = {0};
> > > +
> > > + if (can_dropped_invalid_skb(ndev, skb))
> > > + return NETDEV_TX_OK;
> > > +
> > > + /*
> > > + * No check for NCT66794 because the TX bit is read-clear
> > > + * and may be read-cleared by other function
> > > + * Just check the result of tx command.
> > > + */
> >
> > Where do you check the result of the TX command?
> >
> > > + /* Check if the TX buffer is full */
> >
> > Where's the check if the TX buffer is full?
> >
Sorry for the missing code. It will be checked in tx_work().
If nct6694_write_msg() for CMD10 returns an error related to CAN_Deliver,
I will add error handling in the next patch.
> > > + netif_stop_queue(ndev);
> > > +
> > > + if (can_idx == 0)
> > > + data_buf[CAN_TAG_IDX] = CAN_TAG_CAN0;
> > > + else
> > > + data_buf[CAN_TAG_IDX] = CAN_TAG_CAN1;
> > > +
> > > + if (cf->can_id & CAN_EFF_FLAG) {
> > > + txid = cf->can_id & CAN_EFF_MASK;
> > > + /*
> > > + * In case the Extended ID frame is transmitted, the
> > > + * standard and extended part of the ID are swapped
> > > + * in the register, so swap them back to send the
> > > + * correct ID.
> > > + */
> > > + data_buf[CAN_FLAG_IDX] |= CAN_FLAG_EFF;
> > > + } else {
> > > + txid = cf->can_id & CAN_SFF_MASK;
> > > + }
> > > +
> > > + set_buf32(&data_buf[CAN_ID_IDX], txid);
> > > +
> > > + data_buf[CAN_DLC_IDX] = cf->len;
> > > +
> > > + if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) {
> > > + data_buf[CAN_FLAG_IDX] |= CAN_FLAG_FD;
> > > + if (cf->flags & CANFD_BRS)
> > > + data_buf[CAN_FLAG_IDX] |= CAN_FLAG_BRS;
> > > + }
> > > +
> > > + if (cf->can_id & CAN_RTR_FLAG)
> > > + data_buf[CAN_FLAG_IDX] |= CAN_FLAG_RTR;
> > > +
> > > + /* set data to buf */
> > > + for (i = 0; i < cf->len; i++)
> > > + data_buf[CAN_DATA_IDX + i] = *(u8 *)(cf->data + i);
> > > +
> > > + can_put_echo_skb(skb, ndev, 0, 0);
> > > +
> > > + memcpy(priv->data_buf, data_buf, REQUEST_CAN_CMD10_LEN);
> > > + queue_work(nct6694->async_workqueue, &priv->tx_work);
> > > +
> > > + stats->tx_bytes += cf->len;
> > > + stats->tx_packets++;
> > > + echo_byte = can_get_echo_skb(ndev, 0, NULL);
> > > +
> > > + netif_wake_queue(ndev);
> >
> > How do you make sure that the tx_work has finished?
> > Once you wake the queue, the xmit function can be called again. If your
> > tx_work has not finished, you'll overwrite the priv->data_buf.
>
> Do you get a CAN TX complete message/IRQ from your device?
>
I will move the code that needs to confirm the completion of TX transmission
to tx_work().
In tx_work(), CMD2 CAN_Event's TX_EVT will first confirm TX_FIFO_EMPTY,
ensuring transmission is complete.
Best regards,
Ming
Powered by blists - more mailing lists