nuttx/driver/rpmsg: new folder, extract common rpmsg api in rptun.c to rpmsg.c.
rpmsg provide rpmsg_ops to each backend for specific implementation.
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
In `drivers/rptun/rptun.c`, we have a `rptun_is_recursive` function,
which lets rptun thread run recursively. Then the `usrsock_rpmsg_ept_cb`
may be called inside `usrsock_rpmsg_ept_cb`, which can cause some
unexpected behavior, so we add a queue to keep the order of incoming
messages to reduce the complexity.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
There is a risk that interfaces such as psock_ioctl/psock_setsockopt
will cause paramete to be not four-byte aligned after calculating the
offset, so align the length of the structure with parameters by four
bytes.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
A dead lock may happen before this patch:
rptun thread (usrsock_rpmsg_recvfrom_handler):
Gets all tx payload but waiting net_lock in psock_recvfrom
net driver thread (higher priority):
Receives a packet, holding net_lock, calling usrsock_rpmsg_send_event
But no tx buffer left, so rpmsg_send blocks, and won't release net_lock
In short:
Rptun: Hold all `tx_payload_buffer` -> want `net_lock`
Driver: Hold `net_lock` -> want `tx_payload_buffer`
This patch use net_lock to combine get_tx_payload and recvfrom together,
then:
- If it's waiting net_lock, tx payload will not be held, other threads
may get tx buffer and do their work.
- If net_lock is got, it won't be disturbed before finish receiving,
then tx payload won't have chance to be blocked before releasing.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Note:
tcp_poll_eventhandler have logic after poll_notify, if we teardown poll
inside poll callback without clearing revents, use-after-free will
happen.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
req->usockid maybe < 0 or > CONFIG_NET_USRSOCK_RPMSG_SERVER_NSOCKS,
if so , priv->pfds[req->usockid] will access invalid memory.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)
------------------
How to test
From within nuttx/. Configure:
cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja
(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja
This uses ninja generator (install with sudo apt install ninja-build). To build:
$ cmake --build build
menuconfig:
$ cmake --build build -t menuconfig
--------------------------
2. cmake/build: reformat the cmake style by cmake-format
https://github.com/cheshirekow/cmake_format
$ pip install cmakelang
$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done
Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
if number of bytes available for reading more than zero,set USRSOCK_EVENT_RECVFROM_AVAIL flag into the event
Signed-off-by: wangchen <wangchen41@xiaomi.com>
the previous patch can not handle the revent is POLLHUP or POLLERR,
poll_setup needs to be executed only when the POLLIN or POLLOUT event
changes.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
If the current poll setup only has POLLIN, adding POLLOUT does not cause the
protocol stack to refocus on flags such as TCP_ACK or UDP_POLL, the user is
not notified when flags for POLLOUT relationships appear and vice versa,
so we have to call poll_setup again.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
It's better to raise error before client sends its (NIOVEC+1)th buffer
(and release buffers held by server), otherwise the client may stuck at
getting (NIOVEC+1)th tx buffer if NIOVEC is equal to rpmsg buffer num.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Found a problem:
When sendto handler gets an error, it will release all its rx buffer,
then iov_base becomes NULL. But it cannot let client stop its request,
then the next data from client cannot be handled by usrsock server
correctly.
It's better to note down the remaining bytes, then we can stop at
correct time.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
since mmap may exist in block_operations, but truncate may not,
moving mmap beforee truncate could make three struct more compatible
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
- Add mmap into file_operations and remove it from ioctl definitions.
- Add mm_map structure definitions to support future unmapping
- Modify all drivers to initialize the operations struct accordingly
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
- Add truncate into file_operations
- Move truncate to be common for mountpt_operations and file_operations
- Modify all drivers to initialize the operations struct accordingly
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
move usrsock rpmsg driver from userspace to kernel to reduce extra
context switch for usrsock operations
Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>