Commit Graph

556 Commits

Author SHA1 Message Date
zhanghongyu e404fe4b8d rndis.c: move ifup in setconfig to the work queue
Move network interface up operation (ifup) to work queue in RNDIS USB
device driver to avoid calling netdev_carrier_on API in interrupt context.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-02-27 15:39:38 +08:00
Ari Kimari 1c36ba764f drivers/usbdev: Fix usbmsc_unbind() function for composite device
1. Move DEBUGASSERT to correct place
2. Leave it out if composite device
3. Move working thread stop to separate function
4. Call it from unbind function for composite device

Signed-off-by: Ari Kimari <ari.kimari@tii.ae>
2026-02-12 10:29:15 -03:00
zhanghongyu a7567677a8 netdev_driver: add carrier_on to xxx_ifup where carrier_on is absent
since the judgment for network card selection was changed from IS_UP to
IS_RUNNING, drivers that lack carrier_on need to add the carrier_on
operation; otherwise, network access issues will occur.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-02-02 13:23:05 +08:00
masc 09f09daeab Author: shichunma <masc2008@gmail.com> Date: Thu Jan 15 07:24:08 2026 +0800
drivers/usbdev/rndis: after client send notication, host can't read msg timely

rndis use intr ep to notify host to read RNDIS message from client, it should
read all the messages cached. Need notify host to read again if there is msg left.

Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
2026-01-25 23:59:49 +08:00
zhanghongyu fa6c8579dd driver/net: replace net_lock with netdev_lock
modify the code of the adapted protocol stack to avoid deadlocks and the
logic that cannot be protected by locks after modification.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-06 16:08:30 +08:00
zhanghongyu 097dd84bba drivers/usbdev/cdcecm.c: fix cdcecm netdev can not enter running state
When the setinterface interface is called, it indicates that the underlying
USB link has been successfully established. At this point, the status of the
network card needs to be updated to RUNNING by calling the netdev_carrier_on
interface. It is similar to the logic after a Wi-Fi network card is
connected to a hotspot. Otherwise, an incorrect network card status may
cause packets to fail to be successfully sent.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-15 11:14:20 -03:00
yangsong8 69cac3bd3a driver/usbdev: Fix usbtrace lock unpaired issue
Fix usbtrace lock unpaired issue

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-13 16:45:06 +08:00
yangsong8 444293e3b5 drivers/usbdev: Use small lock to protect usbdev trace
Use spin lock to replace enter_critical_section

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-13 16:45:06 +08:00
yangsong8 35a89be950 drivers/usbdev: Use small lock to protect usbdev msc
Use spin lock to replace enter_critical_section

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-13 16:45:06 +08:00
yangsong8 4d319c6816 driver/usbdev: Use small lock to protect usbdev fs
Use spin lock to replace enter_critical_section

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-13 16:45:06 +08:00
yangsong8 a1f5c269d7 driver/usbdev: Use small lock to protect composite device
Use spin lock to replace enter_critical_section

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-13 16:45:06 +08:00
yangsong8 ae39301416 drivers/usbdev: not use wd timer when zero copy in cdcacm
When using the serial framework buffer, if the buffer is full, excess
data is cached in the usb req buffer. The CDCACM driver doesn't know
when the upper layer will read data from the serial buffer, so it
needs to periodically check if the cached data can be put into the
serial buffer. However, when using zero-copy, each usb req buffer
needs to be completely read before actively switching to the next
req buffer, so the timer is not needed to assist to query.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 04fbce9d40 driver/usbdev: fix cdcacm wr container missing issue
in cdcacm_sndpacket, If `if (priv->wrcontainer)` is true, then
`priv->wrcontainer` is set to NULL. If an interrupt occurs before
`priv->wrcontainer` is reassigned after being NULL,
`priv->wrcontainer` will be reassigned once during the interrupt,
and `nwrq--` will be called, but no data will be sent at this time.
Only when data is sent by calling `txint` will `priv->wrcontainer`
be reassigned and `nwrq--` called again. This causes the issue.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 10180ab4eb drivers/usb: use lock to protect reqbuf when cdcacm unbind
When CONFIG_CDCACM_DISABLE_TXBUF is enabled, if the USB is
unplugged during serial data transmission, it is possible
that cdcacm will enter the unbind process, and reqbuf will
be released, causing a crash during serial write.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 a53223741e drivers/usbdev: fix usb cdcacm build warning
usbdev/cdcacm.c:371:11: warning: implicit declaration of function 'spin_lock_irqsave' [-Wimplicit-function-declaration]
  371 |   flags = spin_lock_irqsave(&priv->lock);
      |           ^~~~~~~~~~~~~~~~~
usbdev/cdcacm.c:375:3: warning: implicit declaration of function 'spin_unlock_irqrestore' [-Wimplicit-function-declaration]
  375 |   spin_unlock_irqrestore(&priv->lock, flags);
      |   ^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 d2daf66d38 drivers/usbdev/cdcacm: Fix the issue of missing release one req buf
When unbinding, if a req buf is held by priv->container, it also
needs to be released.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 cc067ab199 drivers/usbdev/cdcacm.c: Use small lock to protect cdcacm
Use spin lock to replace enter_critical_section

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 fe293ec9b5 drivers/usbdev/cdcacm.c: fix check priv->nwrq issue
When enable CONFIG_CDCACM_DISABLE_TXBUF, dev->xmit.buffer always
take one req, so just compare CONFIG_CDCACM_NWRREQS - 1.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 e78e152cc7 drivers/usbdev/cdcacm.c: fix runtime error memcpy para is null
usbdev/cdcacm.c:2974:3: runtime error: null pointer passed as argument 2, which is declared to never be null
    #0 0x44716307 in cdcuart_dmasend usbdev/cdcacm.c:2974

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
yangsong8 dd5a2662ac cdcacm: check present bit
When close the serial tool in PC, only the persent bit is cleared
on Windows but all bits are cleared on linux.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-12 09:34:47 +08:00
chao an 87f134cfaa sched/sleep: replace all Signal-based sleep implement to Scheduled sleep
Nuttx currently has 2 types of sleep interfaces:

1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
Weaknesses:
a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.

2. Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
a. Does not actively trigger scheduling, occupy the CPU loading.

3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
Strengths:
a. Does not depend on the signal framework.
b. Tick-based, without additional computational overhead.

Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.

(This PR also aims to make signals optional, further reducing the code size of Nuttx.)

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-17 14:05:02 +08:00
Jukka Laitinen 1210dc4919 drivers/usbdev/cdcacm: Add a mutex around driver initialize / uninitialize
This protects the driver in case multiple threads are trying to initialize
or uninitialize the cdcacm concurrently.

Note that this only protects the case when the private pointer is not managed
outside the kernel. If someone has acquired the pointer to the driver and uses
that, it also needs to manage the protection itself if needed.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-10-11 00:47:02 +08:00
Jukka Laitinen 2435caa925 drivers/usbdev: Unregister CDCACM by instance number
Add a function to search the cdcacm instance by the devnode
minor number to unregister it

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-10-11 00:47:02 +08:00
simbit18 ff1dc87ccf drivers/usbdev: Aligned Cmake with Make
Add:
- media transfer protocol (MTP) #10620

Signed-off-by: simbit18 <simbit18@gmail.com>
2025-10-09 20:01:30 +08:00
Tim Hardisty a28367f507 drivers/usbdev/cdcncm.c: Fix issue with unplug/replug of USB causing link not to re-establish
Signed-off-by: Tim Hardisty <timh@jti.uk.com>
2025-05-24 12:29:07 +08:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Michal Lenc c0a6afff11 drivers/usbdev/Kconfig: fix COMPOSITE_VENDORSTR description
Option COMPOSITE_VENDORSTR should be described as composite vendor
string, not vendor id. This is consistent with other USB devices.

Also fixes a typo in USBDEV_EPBUFFER_ALIGNMENT.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-05-13 09:57:30 +08:00
yangsong8 e8f9570ffd driver/serial/cdcacm: config to enable or disable txbuf
To be compatible with the previous method, add a buf between cdcacm
and serial. Because when using usbreqbuf directly as the buf of serial,
the amount of data sent may be insufficient due to the limit of the
number of reqs. For example, when the number of reqs is 4, the number
of data send through cdcacm is 5, and each data is a separate USB
packet, if the host does not read in time, resulting in blocking send.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-03-28 08:52:42 +08:00
yangsong8 f0b52a8b2d driver/serial/cdcacm: config to enable or disable rxbuf
To be compatible with the previous method, add a buf between cdcacm
and serial. Because when using usbreqbuf directly as the buf of serial,
the amount of data received may be insufficient due to the limit of the
number of reqs. For example, when the number of reqs is 4, the number
of data received through cdcacm is 5, and each data is a separate USB
packet, which should require 5 reqs, resulting in the last number not
being received. If the application always waits for 5 numbers before
performing an operation, this will cause problems.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-03-28 08:52:42 +08:00
yangsong8 a0a61ff345 driver/serial/cdcacm: Get the status of rx or tx buf by ioctl
Build Documentation / build-html (push) Has been cancelled
In cdcacm, USB req buf is directly used as serial buf, so the getting
buf status operation in ioctl is different from the original serial.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-03-22 08:41:33 +08:00
yangsong8 9c55a19238 driver/syslog: add cdcacm channel
Use the CDCACM as a SYSLOG output device, send message to remote proc.
If there are more than one CDCACM devices, then a device minor number
may also need to be provided. Default: 0

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-03-10 13:43:54 +08:00
yangsong8 c497c5feb0 drivers/serial/cdcacm: Reduce one copy of data between serial and cdcacm framework
Data form serial framework will be written to usb reqbuf directly,
and data form cdcacm will be read form reqbuf directly.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-03-05 12:52:00 -03:00
Jukka Laitinen 575c608be8 drivers/usbdev/cdcacm.c: Fix a crash in cdcacm if usbdev gets unregistered while client calls close for the tty
Make sure that the cdcacm is disconnected before the usbdev gets unregistered.

Also, check if the device is connected or not in cdcuart_txempty (uart_txempty). Otherwise there may be a crash during uart_tcdrain, called in tty close path, if the usbdev unregistration happens during the loop.

This issue can be triggered by monitoring the cable connection status in one thread, sending BOARDIOC_USBDEV_DISCONNECT if the usb cable is detached. In another thread close the ttyACM.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2025-01-10 21:14:55 +08:00
Alin Jerpelea 286d37026c drivers: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-11-06 18:02:25 +08:00
ouyangxiangzhen 17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
Tim Hardisty bc0f90659f Fix cdcncm printf formatter compiler warning 2024-10-25 00:52:29 +08:00
yangsong8 0beceeb745 usb: Fix issue with the calculation descriptor length error
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-10-15 21:00:29 +08:00
yangsong8 954e84c82a usb: If usb3.0, set the ep0 sssize to cfgdescsize
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-10-09 14:19:16 +08:00
Jouni Ukkonen b4de080b1f usbdev/cdcacm: Fix read queue counter in shutdown
nrdq is already set 0 in resetconfig.

Signed-off-by: Jouni Ukkonen <jouni.ukkonen@unikie.com>
2024-10-08 22:28:51 +08:00
Jukka Laitinen a88693f519 drivers/usbdev/cdcacm.c: Fix compilation issues
Add #ifdef CONFIG_SERIAL_TXDMA/RXDMA in g_uartops init

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-03 08:55:13 +08:00
Jukka Laitinen 5d4d2cbbc8 drivers/usbdev/pl2303.c: Don't let maximum number of bytes in request exceed CONFIG_PL2303_BULKIN_REQLEN
The request length may not exceed CONFIG_PL2303_BULKIN_REQLEN, otherwise buffer overflow will occur

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-03 08:55:13 +08:00
Jukka Laitinen 18526d78eb drivers/usbdev/cdcacm.c: Set reqlen properly according to ep->maxpacket and CONFIG_CDCACM_BULKIN/OUT_REQLEN
The request length may not exceed CONFIG_CDCACM_BULKIN_ lenghts, otherwise buffer overflow will occur

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-03 08:55:13 +08:00
yangsong8 09030b5d67 cdcacm: config to enable or disable interrupt endpoint
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-09-30 20:32:47 +08:00
yangsong8 6290e70212 cdcacm: remove the duplicate code with serial
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-09-30 16:27:21 +08:00
yangsong8 6c71276359 cdcacm: support polling mode in order to work normally in interrupt
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-09-30 16:27:21 +08:00
yangsong8 6161b1ea84 cdcacm: use DMA to rx and tx
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-09-30 16:27:21 +08:00
yangsong8 e3fcabaec2 cdcacm: use serial public APIs
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-09-30 16:27:21 +08:00
dongjiuzhu1 aa03182bab drivers/usbdev/: don't send setconfig response for xxxx_setup with composite
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-30 14:06:35 +08:00
dongjiuzhu1 a9bc198bc3 composite.c warning
usbdev/composite.c:649:36: warning: implicit declaration of function 'board_usbdev_pid' [-Wimplicit-function-declaration]
649 | uint16_t pid = board_usbdev_pid(); usbdev/composite.c:650:36: warning: implicit declaration of function 'board_usbdev_vid'
[-Wimplicit-function-declaration] 650 | uint16_t vid = board_usbdev_vid();

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-16 10:33:01 +08:00
dongjiuzhu1 e0d82fdf3a drivers/usedev: remove unnecessary mdelay because remain req info had beed push to serial buffer
this mdelay causes cpu busy wait, affects other process running.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-16 10:33:01 +08:00