From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Ming Yu <a0282524688@gmail.com>
Cc: tmyu0@nuvoton.com, lee@kernel.org, linus.walleij@linaro.org,
brgl@bgdev.pl, andi.shyti@kernel.org,
mailhol.vincent@wanadoo.fr, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, wim@linux-watchdog.org, linux@roeck-us.net,
jdelvare@suse.com, jic23@kernel.org, lars@metafoo.de,
ukleinek@kernel.org, alexandre.belloni@bootlin.com,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-can@vger.kernel.org,
netdev@vger.kernel.org, linux-watchdog@vger.kernel.org,
linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-rtc@vger.kernel.org
Subject: Re: [PATCH v1 1/9] mfd: Add core driver for Nuvoton NCT6694
Date: Mon, 28 Oct 2024 08:52:31 +0100 [thread overview]
Message-ID: <20241028-uptight-modest-puffin-0556e7-mkl@pengutronix.de> (raw)
In-Reply-To: <CAOoeyxW5QwPMGAYCWhQDtZwJJLG5xj9HXpL3-cduRSgF+4VHhg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 6817 bytes --]
On 28.10.2024 15:33:08, Ming Yu wrote:
> Dear Marc,
>
> Thank you for your comments,
>
> Marc Kleine-Budde <mkl@pengutronix.de> 於 2024年10月25日 週五 下午8:24寫道:
> >
> > On 25.10.2024 19:03:55, Ming Yu wrote:
> > > Oh! I'm sorry about that I confused the packet size.
> > > The NCT6694 bulk maximum packet size is 256 bytes,
> > > and USB High speed bulk maximum packet size is 512 bytes.
> > >
> > > Marc Kleine-Budde <mkl@pengutronix.de> 於 2024年10月25日 週五 下午6:08寫道:
> > > >
> > > > On 25.10.2024 16:08:10, Ming Yu wrote:
> > > > > > > +int nct6694_read_msg(struct nct6694 *nct6694, u8 mod, u16 offset, u16 length,
> > > > > > > + u8 rd_idx, u8 rd_len, unsigned char *buf)
> > > > > >
> > > > > > why not make buf a void *?
> > > > >
> > > > > [Ming] I'll change the type in the next patch.
> > > > >
> > > > > >
> > > > > > > +{
> > > > > > > + struct usb_device *udev = nct6694->udev;
> > > > > > > + unsigned char err_status;
> > > > > > > + int len, packet_len, tx_len, rx_len;
> > > > > > > + int i, ret;
> > > > > > > +
> > > > > > > + mutex_lock(&nct6694->access_lock);
> > > > > > > +
> > > > > > > + /* Send command packet to USB device */
> > > > > > > + nct6694->cmd_buffer[REQUEST_MOD_IDX] = mod;
> > > > > > > + nct6694->cmd_buffer[REQUEST_CMD_IDX] = offset & 0xFF;
> > > > > > > + nct6694->cmd_buffer[REQUEST_SEL_IDX] = (offset >> 8) & 0xFF;
> > > > > > > + nct6694->cmd_buffer[REQUEST_HCTRL_IDX] = HCTRL_GET;
> > > > > > > + nct6694->cmd_buffer[REQUEST_LEN_L_IDX] = length & 0xFF;
> > > > > > > + nct6694->cmd_buffer[REQUEST_LEN_H_IDX] = (length >> 8) & 0xFF;
> > > > > > > +
> > > > > > > + ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, BULK_OUT_ENDPOINT),
> > > > > > > + nct6694->cmd_buffer, CMD_PACKET_SZ, &tx_len,
> > > > > > > + nct6694->timeout);
> > > > > > > + if (ret)
> > > > > > > + goto err;
> > > > > > > +
> > > > > > > + /* Receive response packet from USB device */
> > > > > > > + ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, BULK_IN_ENDPOINT),
> > > > > > > + nct6694->rx_buffer, CMD_PACKET_SZ, &rx_len,
> > > > > > > + nct6694->timeout);
> > > > > > > + if (ret)
> > > > > > > + goto err;
> > > > > > > +
> > > > > > > + err_status = nct6694->rx_buffer[RESPONSE_STS_IDX];
> > > > > > > +
> > > > > > > + /*
> > > > > > > + * Segmented reception of messages that exceed the size of USB bulk
> > > > > > > + * pipe packets.
> > > > > > > + */
> > > > > >
> > > > > > The Linux USB stack can receive bulk messages longer than the max packet size.
> > > > >
> > > > > [Ming] Since NCT6694's bulk pipe endpoint size is 128 bytes for this MFD device.
> > > > > The core will divide packet 256 bytes for high speed USB device, but
> > > > > it is exceeds
> > > > > the hardware limitation, so I am dividing it manually.
> > > >
> > > > You say the endpoint descriptor is correctly reporting it's max packet
> > > > size of 128, but the Linux USB will send packets of 256 bytes?
> > >
> > > [Ming] The endpoint descriptor is correctly reporting it's max packet
> > > size of 256, but the Linux USB may send more than 256 (max is 512)
> > > https://elixir.bootlin.com/linux/v6.11.5/source/drivers/usb/host/xhci-mem.c#L1446
> >
> > AFAIK according to the USB-2.0 spec the maximum packet size for
> > high-speed bulk transfers is fixed set to 512 bytes. Does this mean that
> > your device is a non-compliant USB device?
>
> We will reduce the endpoint size of other interfaces to ensure that MFD device
> meets the USB2.0 spec. In other words, I will remove the code for manual
> unpacking in the next patch.
I was not talking about the driver, but your USB device. According to
the USB2.0 spec, the packet size is fixed to 512 for high-speed bulk
transfers. So your device must be able to handle 512 byte transfers or
it's a non-compliant USB device.
> > > > > > > + for (i = 0, len = length; len > 0; i++, len -= packet_len) {
> > > > > > > + if (len > nct6694->maxp)
> > > > > > > + packet_len = nct6694->maxp;
> > > > > > > + else
> > > > > > > + packet_len = len;
> > > > > > > +
> > > > > > > + ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, BULK_IN_ENDPOINT),
> > > > > > > + nct6694->rx_buffer + nct6694->maxp * i,
> > > > > > > + packet_len, &rx_len, nct6694->timeout);
> > > > > > > + if (ret)
> > > > > > > + goto err;
> > > > > > > + }
> > > > > > > +
> > > > > > > + for (i = 0; i < rd_len; i++)
> > > > > > > + buf[i] = nct6694->rx_buffer[i + rd_idx];
> > > > > >
> > > > > > memcpy()?
> > > > > >
> > > > > > Or why don't you directly receive data into the provided buffer? Copying
> > > > > > of the data doesn't make it faster.
> > > > > >
> > > > > > On the other hand, receiving directly into the target buffer means the
> > > > > > target buffer must not live on the stack.
> > > > >
> > > > > [Ming] Okay! I'll change it to memcpy().
> > > >
> > > > fine!
> > > >
> > > > > This is my perspective: the data is uniformly received by the rx_bffer held
> > > > > by the MFD device. does it need to be changed?
> > > >
> > > > My question is: Why do you first receive into the nct6694->rx_buffer and
> > > > then memcpy() to the buffer provided by the caller, why don't you
> > > > directly receive into the memory provided by the caller?
> > >
> > > [Ming] Due to the bulk pipe maximum packet size limitation, I think consistently
> > > using the MFD'd dynamically allocated buffer to submit URBs will better
> > > manage USB-related operations
> >
> > The non-compliant max packet size limitation is unrelated to the
> > question which RX or TX buffer to use.
>
> I think these two USB functions can be easily called using the buffer
> dynamically
> allocated by the MFD. However, if they transfer data directly to the
> target buffer,
> they must ensure that it is not located on the stack.
You have a high coupling between the MFD driver and the individual
drivers anyways, so why not directly use the dynamically allocated
buffer provided by the caller and get rid of the memcpy()?
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2024-10-28 7:53 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 8:59 [PATCH v1 0/9] Add Nuvoton NCT6694 MFD devices Ming Yu
2024-10-24 8:59 ` [PATCH v1 1/9] mfd: Add core driver for Nuvoton NCT6694 Ming Yu
2024-10-24 9:03 ` Marc Kleine-Budde
2024-10-25 8:00 ` Ming Yu
2024-10-24 9:57 ` Marc Kleine-Budde
2024-10-25 8:02 ` Ming Yu
2024-10-24 15:20 ` Marc Kleine-Budde
2024-10-24 15:34 ` Marc Kleine-Budde
2024-10-25 8:14 ` Ming Yu
2024-10-25 8:35 ` Marc Kleine-Budde
2024-10-25 9:02 ` Marc Kleine-Budde
2024-10-25 10:22 ` Ming Yu
2024-10-25 8:08 ` Ming Yu
2024-10-25 10:08 ` Marc Kleine-Budde
2024-10-25 11:03 ` Ming Yu
2024-10-25 12:23 ` Marc Kleine-Budde
2024-10-28 7:33 ` Ming Yu
2024-10-28 7:52 ` Marc Kleine-Budde [this message]
2024-10-28 8:31 ` Ming Yu
2024-10-28 14:06 ` Marc Kleine-Budde
2024-10-29 3:45 ` Ming Yu
2024-10-29 8:14 ` Marc Kleine-Budde
2024-11-01 5:35 ` Ming Yu
2024-10-26 14:58 ` Christophe JAILLET
2024-10-28 7:37 ` Ming Yu
2024-10-24 8:59 ` [PATCH v1 2/9] gpio: Add Nuvoton NCT6694 GPIO support Ming Yu
2024-10-24 9:47 ` Bartosz Golaszewski
[not found] ` <CAOoeyxUUOCSaDLK8=ox3hwDVu=Ej-ds4=FsS8F+9GfiE-8HYvg@mail.gmail.com>
2024-10-25 7:12 ` Bartosz Golaszewski
2024-10-25 7:38 ` 游子民
2024-10-25 7:46 ` Bartosz Golaszewski
2024-10-28 8:56 ` Ming Yu
2024-10-30 19:32 ` Bartosz Golaszewski
2024-11-01 6:15 ` Ming Yu
2024-10-24 8:59 ` [PATCH v1 3/9] i2c: Add Nuvoton NCT6694 I2C support Ming Yu
2024-10-24 10:41 ` Andi Shyti
2024-10-25 7:47 ` 游子民
2024-10-24 8:59 ` [PATCH v1 4/9] can: Add Nuvoton NCT6694 CAN support Ming Yu
2024-10-24 10:03 ` Marc Kleine-Budde
2024-10-24 10:05 ` Marc Kleine-Budde
2024-11-01 1:27 ` Ming Yu
2024-10-24 12:12 ` Marc Kleine-Budde
2024-10-24 15:28 ` Marc Kleine-Budde
2024-11-01 5:32 ` Ming Yu
2024-10-24 14:17 ` Marc Kleine-Budde
2024-10-24 14:20 ` Marc Kleine-Budde
2024-11-01 1:44 ` Ming Yu
2024-11-01 1:37 ` Ming Yu
2024-10-25 11:18 ` kernel test robot
2024-10-25 23:31 ` kernel test robot
2024-10-24 8:59 ` [PATCH v1 5/9] watchdog: Add Nuvoton NCT6694 WDT support Ming Yu
2024-10-24 15:32 ` Guenter Roeck
2024-10-28 9:49 ` Ming Yu
2024-10-24 16:06 ` Guenter Roeck
2024-10-26 9:19 ` kernel test robot
2024-10-24 8:59 ` [PATCH v1 6/9] hwmon: Add Nuvoton NCT6694 HWMON support Ming Yu
2024-10-24 9:20 ` Kalesh Anakkur Purayil
2024-10-24 14:53 ` Guenter Roeck
2024-10-25 15:22 ` Ming Yu
2024-10-25 15:44 ` Guenter Roeck
2024-10-26 14:50 ` Guenter Roeck
2024-10-28 7:58 ` Ming Yu
2024-10-28 18:54 ` Jonathan Cameron
2024-10-30 3:29 ` Ming Yu
2024-10-30 4:26 ` Guenter Roeck
2024-11-01 6:11 ` Ming Yu
2024-10-28 7:42 ` Ming Yu
2024-10-25 15:10 ` Ming Yu
2024-10-24 15:03 ` Guenter Roeck
2024-10-25 15:33 ` Ming Yu
2024-10-24 8:59 ` [PATCH v1 7/9] iio: adc: Add Nuvoton NCT6694 IIO support Ming Yu
2024-10-26 14:41 ` Jonathan Cameron
2024-11-05 6:21 ` Ming Yu
2024-10-24 8:59 ` [PATCH v1 8/9] pwm: Add Nuvoton NCT6694 PWM support Ming Yu
2024-11-22 18:05 ` Uwe Kleine-König
2024-10-24 8:59 ` [PATCH v1 9/9] rtc: Add Nuvoton NCT6694 RTC support Ming Yu
2024-10-25 23:34 ` Nobuhiro Iwamatsu
2024-10-28 8:42 ` Ming Yu
2024-10-24 11:57 ` [PATCH v1 0/9] Add Nuvoton NCT6694 MFD devices Marc Kleine-Budde
2024-10-25 8:22 ` Ming Yu
2024-10-25 8:33 ` Marc Kleine-Budde
2024-10-30 8:30 ` Ming Yu
2024-10-30 10:12 ` Marc Kleine-Budde
2024-10-30 14:21 ` Ming Yu
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=20241028-uptight-modest-puffin-0556e7-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=a0282524688@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andi.shyti@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=brgl@bgdev.pl \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jdelvare@suse.com \
--cc=jic23@kernel.org \
--cc=kuba@kernel.org \
--cc=lars@metafoo.de \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mailhol.vincent@wanadoo.fr \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tmyu0@nuvoton.com \
--cc=ukleinek@kernel.org \
--cc=wim@linux-watchdog.org \
/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