48 Commits

Author SHA1 Message Date
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
zhanghongyu b0ab56aca2 netdev_upperhalf: add direct rx mode
avoid packet processing delays caused by task switching,
to support those applications that are extremely time-sensitive.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 14:29:24 +08:00
zhanghongyu 3e18d72661 netdev_upperhalf.c: add vlan lock in rxpoll flow
Protect the RX process of the VLAN network card.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu eb60667561 net/utils/net_lock.c: add api to lock conn and netdev
add new api to protect access and operation to conn and dev

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu 6144b51848 netdev_upperhalf.c: support alloc iob from CAN buffer pool
when the network card type is NET_LL_CAN, packets are defaultly
allocated from the can buffer.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:56:12 -03:00
zhanghongyu 2ebb08e78f netdev_upperhalf: avoid recursion during transmission
to avoid uncontrollable stack overhead, we actively
avoid scenarios where recursion occurs.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-20 10:58:16 +08:00
zhanghongyu 16947ddacd netdev_upperhalf: modify txavail to be sent directly in the current thread
avoid packet processing delays caused by task switching,
to support those applications that are extremely time-sensitive.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-20 10:58:16 +08:00
zhanghongyu aa8ffea3cf netdev_upperhalf: convert Kconfig to variable
Build Documentation / build-html (push) Has been cancelled
Upperhalf supports multiple working modes at the same time,
which is specified by NIC when register

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-14 10:01:22 +08:00
zhangkai25 ad422684d4 drivers/net: Ethernet protocol stack key abnormal point pile for DFX
add log output for error flow

Signed-off-by: zhangkai25 <zhangkai25@xiaomi.com>
2025-12-09 07:56:20 -03:00
zhanghongyu 4f7e03db2e netdev_upperhalf.c: add net_lock when vlan_foreach
avoid illegal address access caused by removing vlan
network cards during the traversal of vlan network cards

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-09 07:56:20 -03:00
gaohedong 00dfb5d1f3 ethernet: Release iob when dropping ethernet packets
Release iob when dropping ethernet packets

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng 8d7799d6c1 net/vlan: Allow setting default priority (PCP)
1. We add default PCP because some of our apps may not want to set PCP
   manually (e.g. Our user may just ping with pre-set PCP)
2. The `vlan_qos` is used as PCP when setting Linux's priority mapping:
   https://github.com/torvalds/linux/blob/v6.12/net/8021q/vlan.c#L590
   Although `vlan_qos` is not used when creating VLAN on Linux, we can
   use it as PCP on creating VLAN (without changing its meaning), and
   keep compatible with Linux's creating (Exactly the same when
   `vlan_qos` is 0).

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng 2b34bcfcb1 netdev/ioctl: Add support for simple VLAN ioctl
Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN
Ref: https://github.com/torvalds/linux/blob/v6.12/net/8021q/vlan.c#L621

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng 242c253178 net: Add VLAN device support
Inspired by Linux's way, we also create VLAN devices for managing VLAN,
which will become interfaces like `eth0.58`.

QinQ is also supported, we can create VLAN devices above another VLAN
devices, like `eth0.100.101` (or even `eth0.1.2.3.4`, also supported on
Linux).

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng 750fae4cca netdev/lower: Support share quota between devices
To prepare for VLAN device support, a VLAN device will share quota with
its real device.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
daichuan afc210667d netdev_upperhalf.c: modify for maybe use after free with upper pointer
avoid continuing to access the released memory after the netdev_register
error occurs.

Signed-off-by: daichuan <daichuan@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng b2db3a6430 net/netdev: Add netdev_iob_replace_l2 for netdev to avoid misuse
And fix wrong `d_len` for IOBs from `upper->txq` in TX.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Zhe Weng 286de7df01 netdev/upper: Fix wrong CPU when RSS is disabled
When `CONFIG_NETDEV_RSS` is disabled, `NETDEV_THREAD_COUNT` will be 1,
and we should not access `upper->sem[cpu]` with `cpu > 0`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-25 15:58:42 +08:00
zhangyuan29 060fda032b drivers/net: change netdev_lower_quota_load to macro.
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-05 13:26:22 +08:00
zhangyuan29 dcea1b90e7 arch_atomic: only support atomic_xx and atomic64_xx function
Modify the kernel to use only atomic_xx and atomic64_xx interfaces,
avoiding the use of sizeof or typeof to determine the type of
atomic operations, thereby simplifying the kernel's atomic
interface operations.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-04 14:03:14 +01: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
meijian a7224cf35a net/netstatistics: add tx/rx bytes statistics for dev
We can see them in ifconfig:

ap> ifconfig
wlan0   Link encap:Ethernet HWaddr 42:64:7f:b3:12:03 at UP mtu 1500
        inet addr:10.0.1.2 DRaddr:10.0.1.1 Mask:255.255.255.0
        inet6 DRaddr: ::

        RX: Received Fragment Errors   Bytes
            00000b9b 00000000 00000000 21daf5
            IPv4     IPv6     ARP      Dropped
            00000a33 00000137 00000031 00000000
        TX: Queued   Sent     Errors   Timeouts Bytes
            00000ac4 00000ac4 00000000 00000000 1a2103
        Total Errors: 00000000

Signed-off-by: meijian <meijian@xiaomi.com>
2024-09-10 11:36:03 +08:00
fangxinyong 7b05a550dc sched: replace up_cpu_index with this_cpu
Make this_cpu is arch independent and up_cpu_index do that.
In AMP mode, up_cpu_index() may return the index of the physical core.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-09-05 12:09:24 +08:00
guoshichao cd52edd6d7 greenhills: fix enumerated type mixed with another type warning
"net/netdev_upperhalf.c", line 133: warning #188-D: enumerated type mixed with
          another type
        total += netdev_lower_quota_load(lower, type);

CC:  dirent/lib_alphasort.c "spi/spi_transfer.c", line 83: warning #188-D: enumerated type mixed with
          another type
    SPI_SETMODE(spi, seq->mode);
    ^

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-24 20:43:53 +08:00
daichuan a9e2942d8f support mutil thread with netdev upperhalf
Signed-off-by: daichuan <daichuan@xiaomi.com>
2024-08-24 20:41:40 +08:00
chenrun1 cfcf347515 nuttx/atomic.h:replace ALL stdatomic.h with nuttx/stdatomic.h in nuttx/
Summary:
 1. use nuttx/atomic.h instead of stdatomic
 2. remove CONFIG_HAVE_ATOMIC,because we now support atomic on all platforms

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:44:29 +08:00
zhanghongyu ccf60a7bab netdev_upperhalf: add polling mode support for tx/rx
support more work modes to support more scenarios

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-08-21 02:31:53 +08:00
zhanghongyu d740a8e73c netdev_lowerhalf: add reclaim callback in netdev_ops_s
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-08-21 01:39:34 +08:00
Zhe Weng 4b5585a316 netdev/upper: Delay replied packets to prevent TX quota become negated
When our netstack is replying packets when processing RX, the replied
packets will be sent without considering of TX quota because we don't
want to drop them. Now we may delay them by pushing them to a queue and
send them later, which can always keep quota working.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-08-20 06:37:46 +08:00
Zhe Weng c234fac910 net/netdev: Check quota when registering lower-half devices
Some drivers may set too big quota by accident and consume all of our
buffers, so we add a check when registering devices.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-05-14 17:43:26 -03:00
zhanghongyu 92cd1c3742 netdev_upperhalf: add L3 packet handle
To provide support for the received L3 network packets

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-22 23:44:37 +08:00
liqinhui 98e3615b60 net/netdev: Modify the logic for setting the IFF_RUNNING status of interfaces.
Refer to the logic of the `netif_carrier_on` on linux.
https://github.com/torvalds/linux/blob/master/net/sched/sch_generic.c#L575

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-15 18:24:23 -08:00
Zhe Weng 22b6076f26 net/udp: Add check when sending too big packet without IP frag
Commit 8a63d29c removed `devif_iob_send` from `udp_sendto_buffered`
workflow, `devif_iob_send` drops too big packet. Now we still need a
place to check the packet length, otherwise a packet larger than MTU
may be sent to the net driver.

In case of similar problem happens somewhere else, this commit also
adds a check in `netdev_upperhalf`, and count these cases into
`NETDEV_TXERRORS`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-12 06:42:33 -08:00
Zhe Weng 318d136320 netdev/upper: Add netpkt_to_iov() interface
Some driver like virtio-net can offload fragmented IOBs, so an interface
to support this feature is needed.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-22 16:34:21 +09:00
Zhe Weng d44e19d115 mm/iob: Add support for increasing length in iob_update_pktlen
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-22 16:34:21 +09:00
xucheng5 872913e67b netdev_upperhalf: reply logic only for ipv4/ipv6/arp input
VELAPLATFO-12228

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-07-28 06:56:35 -07:00
xucheng5 04c4207dee driver/net : net_upperhalf support NET_LL_CAN
VELAPLATFO-9099

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-07-28 06:56:35 -07:00
chao an 0b69731a97 netdev/upperhalf: fix visual studio Compiler Error C2059
D:\archer\code\nuttx\drivers\net\netdev_upperhalf.c(557,5): error C2059: syntax error : '{'

Compiler error C2059:
The token caused a syntax error.

Reference:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2059?view=msvc-170
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-14 07:52:34 +02:00
Zhe Weng c253bb91a2 drivers/net: Add wireless ops in upper-half driver
Take the idea from Linux's iw_handler array and esp32c3_wlan's wlan_ops_s, and make it a common logic of upper-half driver.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-12 03:32:02 +08:00
Xiang Xiao 015e30a866 drivers/net: Remove HAVE_ATOMICS and use CONFIG_HAVE_ATOMICS directly
since OpenAMP never support to compile in c89 only mode

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-05 13:43:17 +03:00
Petro Karashchenko 46facd44b3 drivers/net/netdev: improve granularity of 'quota' locking
There is no need to use global spinlock to protect netdev
specific data counters. Allocate per-netdev specific spinlock
to get better locking granularity.

Move C/C++ atomic support checking to compiler.h

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-01 15:27:09 -03:00
Zhe Weng f80539b6a8 netdev/upper: Use atomic when we have atomic support from compiler
Ref: How to test atomic support https://beej.us/guide/bgc/html/split/chapter-atomics.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-06-15 19:31:59 -03:00
Zhe Weng 483eb10f37 netdev/upper: Make quota_load public
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-06-15 19:31:59 -03:00
Zhe Weng eb47312518 netdev_upper: Protect quota by spin lock to allow netpkt_xxx be called in interrupt context
Before atomic is ready on every platform, we need a way to protect
quota, previously it's protected by net_lock, but this makes netpkt_xxx
interfaces unable to be called under interrupt context, so changed to
spin lock. Also, we can easily change them into atomic under this
implementation.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-16 21:39:05 +08:00
Zhe Weng 60e66d5e29 net/netdev: Support dedicated thread in upper half driver
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 01:41:01 +08:00
Zhe Weng f21742899f net/netdev: Use upper half of netdev to simplify sim driver
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 01:41:01 +08:00
Zhe Weng 72b77d36e2 net/netdev: Add upper half of netdev to simplify driver logic
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 01:41:01 +08:00