nuttx/include
chao an 34d2cde8a8 net/l2/l3/l4: add support of iob offload
1. Add new config CONFIG_NET_LL_GUARDSIZE to isolation of l2 stack,
   which will benefit l3(IP) layer for multi-MAC(l2) implementation,
   especially in some NICs such as celluler net driver.

new configuration options: CONFIG_NET_LL_GUARDSIZE

CONFIG_NET_LL_GUARDSIZE will reserved l2 buffer header size of
network buffer to isolate the L2/L3 (MAC/IP) data on network layer,
which will be beneficial to L3 network layer protocol transparent
transmission and forwarding

------------------------------------------------------------
Layout of frist iob entry:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                  io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
      iob   |            Reserved            |    io_len    |
            -------------------------------------------------

-------------------------------------------------------------
Layout of different NICs implementation:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                 io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
 Ethernet   |       Reserved    | ETH_HDRLEN |    io_len    |
            ---------------------------------|---------------
 8021Q      |   Reserved  | ETH_8021Q_HDRLEN |    io_len    |
            ---------------------------------|---------------
 ipforward  |            Reserved            |    io_len    |
            -------------------------------------------------

--------------------------------------------------------------------

2. Support iob offload to l2 driver to avoid unnecessary memory copy

Support send/receive iob vectors directly between the NICs and l3/l4
stack to avoid unnecessary memory copies, especially on hardware that
supports Scatter/gather, which can greatly improve performance.

new interface to support iob offload:

  ------------------------------------------
  |    IOB version     |     original      |
  |----------------------------------------|
  |  devif_iob_poll()  |   devif_poll()    |
  |       ...          |       ...         |
  ------------------------------------------

--------------------------------------------------------------------

1> NIC hardware support Scatter/gather transfer

TX:

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                            dev->d_iob:           |
                                                ---------------         ---------------
                             io_data       iob1 |  |          |    iob3 |  |          |
                                    \           ---------------         ---------------
                                  ---------------  |       --------------- |
                             iob0 |  |          |  |  iob2 |  |          | |
                                  ---------------  |       --------------- |
                                     \             |          /           /
                                        \          |       /           /
                                   ----------------------------------------------
                    NICs io vector |    |    |    |    |    |    |    |    |    |
                                   ----------------------------------------------

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to each iobs)

--------------------------------------------------------------------

2> CONFIG_IOB_BUFSIZE is greater than MTU:

TX:

"(CONFIG_IOB_BUFSIZE) > (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE + CONFIG_NET_LL_GUARDSIZE)"

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                                             "NIC"_send()
                          (dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE - NET_LL_HDRLEN(dev)])

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to io_data)

--------------------------------------------------------------------

3> Compatible with all old flat buffer NICs

TX:
                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll(devif_poll_callback())  devif_poll_callback() /* new interface, gather iobs to flat buffer */
       /                                           \
      /                                             \
 devif_poll("NIC"_txpoll)                     "NIC"_send()(dev->d_buf)

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
               netdev_input()  /* new interface, Scatter/gather flat/iob buffer */
                    |
                    |
          pkt/ipv[4|6]_input()/...
                    |
                    |
    NICs io vector receive(Orignal flat buffer)

3. Iperf passthrough on NuttX simulator:

  -------------------------------------------------
  |  Protocol      | Server | Client |            |
  |-----------------------------------------------|
  |  TCP           |  813   |   834  |  Mbits/sec |
  |  TCP(Offload)  | 1720   |  1100  |  Mbits/sec |
  |  UDP           |   22   |   757  |  Mbits/sec |
  |  UDP(Offload)  |   25   |  1250  |  Mbits/sec |
  -------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-03 11:47:04 +08:00
..
arpa Net thread-safe ntoa functions 2022-08-02 21:04:19 +08:00
cxx libc/wchar: remove unnecessary config 2022-07-27 00:36:49 +08:00
net net: add basic NAT workflow 2022-11-11 14:36:55 +08:00
netinet net: Add IN6_IS_ADDR_LINKLOCAL macro 2022-09-21 18:28:40 +08:00
netpacket
nuttx net/l2/l3/l4: add support of iob offload 2022-12-03 11:47:04 +08:00
ssp
sys drivers/video: enhance v4l2 compatibility 2022-12-03 02:48:01 +08:00
.gitignore Add Embedded Template Library (ETL) support 2022-08-05 09:38:48 +08:00
aio.h
alloca.h
assert.h
byteswap.h
ctype.h
debug.h virtio: Add virtio drivers 2022-11-29 13:16:44 +08:00
dirent.h Implement fdopendir 2022-10-19 21:20:35 +08:00
dlfcn.h
dsp.h
dspb16.h
elf32.h
elf64.h
elf.h
endian.h include/endian:add openbsd style macro 2022-11-05 20:37:39 +08:00
err.h libc/err: Add _func suffix to avoid the the penitential symbol collision 2022-08-08 07:39:59 -04:00
errno.h Update errno to match asm-generic 2022-10-28 02:19:26 +08:00
execinfo.h
fcntl.h libc: Implement memfd on top of tmpfs 2022-08-09 22:13:09 +03:00
fixedmath.h
fnmatch.h
ftw.h
getopt.h
glob.h
grp.h
hex2bin.h
ifaddrs.h
inttypes.h
iso646.h
langinfo.h
libgen.h
libintl.h
limits.h libc/wchar: support wchar 2022-07-27 00:36:49 +08:00
locale.h
lzf.h
malloc.h mm/mm_heap: change CONFIG_MM_BACKTRACE to int type 2022-07-26 23:45:31 +08:00
mqueue.h
netdb.h
nl_types.h
nxflat.h
obstack.h libs/libc: add obstack 2022-10-26 09:11:52 +08:00
poll.h
pthread.h phtread: Change stacksize type from long to size_t 2022-11-22 08:23:37 +09:00
pty.h
pwd.h
resolv.h
sched.h sched/spawn: Support task_spawnattr_[set|get]stackaddr 2022-10-31 12:46:58 +09:00
semaphore.h sched/mutex: NXMUTEX_INITIALIZER should enable priority inheritance 2022-10-29 21:37:06 +02:00
signal.h
spawn.h sched/spawn: Rename task_spawnattr_[get|set]stack[size|addr] to posix_spawnattr_[get|set]stack[size|addr] 2022-11-01 09:51:18 +09:00
stdbool.h
stddef.h
stdint.h include/stdint.h: add sig_atomic_t limits 2022-10-02 22:30:54 +08:00
stdio.h libc/stdio: Add stdio file locking functions 2022-10-22 23:34:45 +08:00
stdlib.h random_pool:add a new api arc4random 2022-11-09 06:41:19 +01:00
stdnoreturn.h
string.h libc:add timingsafe_bcmp to libc 2022-09-05 22:27:05 +08:00
strings.h
syscall.h
syslog.h
termios.h
threads.h sched/task/task_getpid: getpid should return process id not thread id 2022-11-17 17:58:08 +08:00
time.h time: Typedef time_t to int64_t if CONFIG_SYSTEM_TIME64 is defined 2022-10-20 22:17:52 +02:00
unistd.h fs: Remove the unused nx_pipe to prefer file_pipe for kernel 2022-10-27 23:14:25 +02:00
utime.h
uuid.h
wchar.h
wctype.h libc: Remove the unnecessary include from wchar and wctype 2022-07-27 10:55:37 +03:00