Commit Graph

67 Commits

Author SHA1 Message Date
chao an 2eb9abc3d8 net/can: fix can mssage corruption if enable NET_TIMESTAMP
Timestamp location in can message has changed,
In the original logic timestamp is saved at the end of the data segment:

io_data
   -------------------------------------------------
   |         CAN message            |  Time Stamp  |
   -------------------------------------------------
   |<---------------     io_len   ---------------->|

In the new structure timestamps will reuse NET_LL_GUARDSIZE to isolate CAN messages:
io_data       io_offset
   -------------------------------------------------
   |  Time Stamp  |         CAN message            |
   -------------------------------------------------
                  |<--------    io_len   --------->|

This PR will:
1. Increase NET_LL_GUARDSIZE to 16 (sizeof(struct timeval)) if NET_CAN && NET_TIMESTAMP are enabled
2. Apply timestamp to adapt to the new structure

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-27 00:30:58 +08:00
Xiang Xiao c39be172da net: Make si_accept callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 5dd037c599 net: Make si_connect callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao a97e2523a4 net: Make si_listen callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 2553b7701c net: Remove the empty si_getpeername implementation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 9b3715050b net: Make si_getsockname callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Fotis Panagiotopoulos 5e625b9cdb Performance optimizations in connection allocations. 2023-02-28 14:23:16 +01:00
Xiang Xiao 2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00
Fotis Panagiotopoulos b5b7d24ba1 Improvements in CAN connections allocation. 2023-02-20 09:06:46 +08:00
SPRESENSE 277e0b941a include/sys/socket.h: Add SOCK_CTRL to socket type
SOCK_CTRL is added to provide special control over network drivers
and daemons. Currently, SOCK_DGRAM and SOCK_STREAM perform this control,
but these use socket resources. In the case of usersocket in particular,
this is a waste of the device's limited socket resources.
2023-02-16 12:13:01 +09:00
Xiang Xiao 0ef073573a net: Remove protocol argument from si_setup callback
since the implementor could get the same value from socket::s_proto

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-13 22:41:19 +08:00
Masayuki Ishikawa 3f3e090716 Revert "include/sys/socket.h: Add SOCK_CTRL to socket type"
This reverts commit abba05a934.
2023-02-09 09:13:14 +01:00
SPRESENSE abba05a934 include/sys/socket.h: Add SOCK_CTRL to socket type
SOCK_CTRL is added to provide special control over network drivers
and daemons. Currently, SOCK_DGRAM and SOCK_STREAM perform this control,
but these use socket resources. In the case of usersocket in particular,
this is a waste of the device's limited socket resources.
2023-02-08 20:43:33 +08:00
Zhe Weng 8819eeaf15 net: Implement shutdown() interface and tcp shutdown
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
David 22feaeeebb Bugfixed the SocketCAN send via setting the dev->d_len to dev->d_sndlen. The dev->d_len wouldn't be assigned otherwise. 2023-01-27 23:08:05 +08:00
Zhe Weng 1cf3147626 net/netdev: Avoid hardcoded guardsize when using d_iob
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-18 14:41:07 +08:00
Xiang Xiao a851ad84c3 net: consistent the net sem wait naming conversion
to prepare the new mutex wait function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-15 12:31:30 -03:00
chao an 8a63d29c6e net/devif_poll: optimize device buffer alloc in txpoll
Allocate the device buffer only if the protocol really need to send data.
not all protocols require the driver to prepare additional iob before
sending, especially UDP, each iob reserves l2/l3 header in advance
after prepare write buffer, net device could reuse this entry to send directly

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-13 16:41:10 +08:00
chao an 0cbbbb9215 net/devif: reuse devif_send() for can/pkt/icmp stack
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-13 16:41:10 +08:00
chao an 11de08de27 net/devif_send: replace all block send to nonblock mode
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 09:53:15 +01:00
chao an 6950b67b46 net/can: device buffer must be clear after enqueue to readahead
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
chao an fc1b71b9a6 net/can: add support of iob input
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
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
chao an 3caa551ff4 net: remove psock reference from connect
Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-24 22:57:42 +08:00
dongjiuzhu1 e6f8ccda4a net/get/setsockopt: add si_get/setsockopt interface to simply get/setsockopt
move private option to protocol sockif

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-11-23 15:01:54 +08:00
chao an a8d3286258 net: move device buffer define to common header
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-28 00:32:16 -04:00
anjiahao 5724c6b2e4 sem:remove sem default protocl
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
raiden00pl 2b0ce033d7 net/can/can_xxxsockopt.c: correct the code alignment 2022-10-21 16:24:13 -03:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
raiden00pl d8e329231f let NET_CAN_RAW_FILTER_MAX depends on NET_CANPROTO_OPTIONS to prevent compiler errors 2022-10-05 07:56:54 +08:00
Xiang Xiao 40ef5bc6db libc: Move queue.h from include to include/nuttx
to avoid the conflict with libuv's queue.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-26 08:04:58 +02:00
wangbowen6 344c8be049 poll: add poll_notify() api and call it in all drivers
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-09-26 12:06:32 +08:00
chao.an 162fcd10ca net: cleanup pvconn reference to avoid confuse
More reference:
https://github.com/apache/incubator-nuttx/pull/5252
https://github.com/apache/incubator-nuttx/pull/5434

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 20:58:11 +08:00
Xiang Xiao ba9486de4a iob: Remove iob_user_e enum and related code
since it is impossible to track producer and consumer
correctly if TCP/IP stack pass IOB directly to netdev

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-15 08:41:20 +03:00
Peter van der Perk b3590f00b3 NXStyle and preprocessor fixes
Co-authored-by: Jari van Ewijk <jari.vanewijk@nxp.com>
2022-07-25 23:47:05 +08:00
Jari van Ewijk 51a845ce54 SocketCAN: add non-blocking write
Co-authored-by: Peter van der Perk <peter.vanderperk@nxp.com>
2022-07-25 23:47:05 +08:00
JacobCrabill 3ddc019f8e net: Fix typos, update comments in Kconfigs 2022-05-06 08:54:58 +02:00
JacobCrabill 0a6181f4d7 net/can: Fix CONFIG errors in can_recvmsg 2022-05-06 08:54:58 +02:00
JacobCrabill 4610aee973 net/netdev: Add CONFIG_NETDEV_CAN_FILTER_IOCTL 2022-05-06 08:54:58 +02:00
Xiang Xiao 7598070508 net: Remove the unnecessary initialization code
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 19:24:17 +02:00
raiden00pl cbbe1c661e net/can/can_recvmsg.c: fix unused variable 'conn' error 2022-02-14 10:42:01 +08:00
raiden00pl 5b678ab12e net/can/can_setsockopt.c: fix assertion, value can be NULL 2022-02-13 23:16:00 +08:00
chao.an 98833affd0 net/can: remove psock reference from can connect
remove the psock back reference since timestamp
has been migrated to can_conn_s

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-11 21:22:55 +08:00
chao.an 0d19a3a248 net/inet: move socket timestamp into socket_conn_s
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-10 15:04:33 -03:00
chao.an 99cde13a11 net/inet: move socket flags into socket_conn_s
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-10 15:04:33 -03:00
chao.an 43ca28da36 net/can: replace the common connect prologue
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-10 15:04:33 -03:00
raiden00pl bc178344a9 net/can: add an option to control CAN EXTID support 2022-02-06 17:09:11 +08:00
raiden00pl a8ca1ec026 SocketCAN: add CAN error definitions 2022-01-05 18:32:46 +08:00
chao.an 504f1d1b5f net/misc: add support for CONFIG_NET_ALLOC_CONNS
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-01-04 14:36:07 +08:00
raiden00pl 649619b8f8 net/can/can_recvmsg.c: fix warning 2022-01-03 08:52:49 -03:00