NetHubVirtualChannel:修订间差异

来自Bouffalo Lab Docs
跳转到导航 跳转到搜索
张良留言 | 贡献
Sync NetHub docs from local Markdown
张良留言 | 贡献
Sync NetHub docs from local Markdown (2026-04-24)
第1行: 第1行:
= NetHub USER Virtual Channel =
= NetHub USER Virtual Channel =


This document describes how to use the NetHub <code>USER virtual channel</code>.
This document describes the current NetHub USER virtual-channel support.


== 1. Concept ==
== 1. Concept ==


<code>USER virtual channel</code> is a logical message channel carried on the current host link.
USER virtual channel is a logical message channel carried on the active host link.


It is not a separate physical interface. It reuses the current <code>SDIO / USB / SPI</code> transport and multiplexes different payload types into separate logical channels.
It is not a separate physical interface. The public API is designed to be transport-neutral, while the current in-tree implementation is still centered on the SDIO reference path.


Commonly used types:
Common logical types are:


* <code>USER</code>
***** <code>USER</code>
** private customer or application data
****** private customer or application data
* <code>AT</code>
***** <code>AT</code>
** host control-plane data
****** control payloads
* <code>SYSTEM</code>
***** <code>SYSTEM</code>
** internal system coordination messages
****** internal coordination messages


For most customer integrations, only the <code>USER</code> type matters.
== 2. Current Support Status ==


== 2. Bring-Up Prerequisites ==
{| class="wikitable"
|-
! Area !! Current status
|-
| Device API surface || transport-neutral by design
|-
| Device in-tree implementation || currently in <code>backend/host/sdio/virtualchan.c</code>
|-
| Host userspace library || currently aligned with <code>mr_sdio.ko + netlink</code>
|-
| End-to-end USER vchan reference path || <code>SDIO</code>
|-
| USB || device-side ACM transport exists, but in-tree host <code>nethub_vchan</code> alignment is not finished
|-
| SPI || not supported
|}


Before using it, confirm:
== 3. Prerequisites ==


* device side is built with <code>CONFIG_NETHUB=y</code>
Before using the current in-tree USER virtual-channel path, confirm:
* device side is built with <code>CONFIG_MR_VIRTUALCHAN=y</code>
* host side has already loaded <code>mr_sdio.ko</code>
* the underlying host-device link is already working


Additional notes:
***** device side is built with <code>CONFIG_NETHUB=y</code>
***** device side enables <code>CONFIG_MR_VIRTUALCHAN=y</code>
***** the selected bring-up path is the current SDIO reference flow
***** host side has loaded <code>mr_sdio.ko</code>
***** the host-device link is already working


* The <code>USER</code> channel and the control channel are parallel channels
Notes:
* If the host control plane itself uses <code>vchan</code>, it uses the <code>AT</code> type
* Customer private messages should stay on the <code>USER</code> type


== 3. device-side Interfaces ==
***** USER and AT are parallel logical channels
***** customer private data should stay on the <code>USER</code> type
***** documentation should not claim that USB and SPI already share the same finished end-to-end virtual-channel stack
 
== 4. Device-Side API ==


Header:
Header:


* <code>components/net/nethub/include/nethub_vchan.h</code>
***** <code>components/net/nethub/include/nethub_vchan.h</code>


Common APIs:
Common APIs:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
int nethub_vchan_user_send(const void *data, uint16_t len);
        int nethub_vchan_user_send(const void *data, uint16_t len);
int nethub_vchan_user_recv_register(nethub_vchan_recv_cb_t recv_cb, void *cb_arg);
        int nethub_vchan_user_recv_register(nethub_vchan_recv_cb_t recv_cb, void *cb_arg);
</syntaxhighlight>
</syntaxhighlight>


== 4. host-side Interfaces ==
== 5. Host-Side API ==


Header:
Header:


* <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>
***** <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>


=== 4.1 Initialization and Cleanup ===
Initialization and cleanup:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
int nethub_vchan_init(void);
        int nethub_vchan_init(void);
int nethub_vchan_deinit(void);
        int nethub_vchan_deinit(void);
</syntaxhighlight>
</syntaxhighlight>


=== 4.2 USER Channel ===
USER channel:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
typedef void (*nethub_vchan_recv_callback_t)(const void *data, size_t len);
        typedef void (*nethub_vchan_recv_callback_t)(const void *data, size_t len);


int nethub_vchan_user_send(const void *data, size_t len);
        int nethub_vchan_user_send(const void *data, size_t len);
int nethub_vchan_user_register_callback(nethub_vchan_recv_callback_t callback);
        int nethub_vchan_user_register_callback(nethub_vchan_recv_callback_t callback);
</syntaxhighlight>
</syntaxhighlight>


=== 4.3 Optional State Query ===
Optional state query:
 
If you need to know whether the virtual channel is ready, you can optionally use:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
typedef struct {
        typedef struct {
    nethub_vchan_link_state_t link_state;
            nethub_vchan_link_state_t link_state;
    nethub_vchan_host_state_t host_state;
            nethub_vchan_host_state_t host_state;
} nethub_vchan_state_snapshot_t;
        } nethub_vchan_state_snapshot_t;


int nethub_vchan_get_state_snapshot(nethub_vchan_state_snapshot_t *snapshot);
        int nethub_vchan_get_state_snapshot(nethub_vchan_state_snapshot_t *snapshot);
</syntaxhighlight>
</syntaxhighlight>


Typical checks:
Optional link event callback:
 
* <code>link_state == NETHUB_VCHAN_LINK_UP</code>
** the link is ready for TX/RX
* <code>host_state == NETHUB_VCHAN_HOST_STATE_DEVICE_RUN</code>
** the host has completed the handshake with the device
 
=== 4.4 Optional Link Event Callback ===
 
If the application wants passive notification when the link goes up or down, it can optionally register:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
int nethub_vchan_register_link_event_callback(
        int nethub_vchan_register_link_event_callback(
    nethub_vchan_link_event_callback_t callback,
            nethub_vchan_link_event_callback_t callback,
    void *user_data);
            void *user_data);
</syntaxhighlight>
</syntaxhighlight>


== 5. Typical Usage Order ==
== 6. Typical Usage Order ==


# <code>nethub_vchan_init()</code>
##### <code>nethub_vchan_init()</code>
# <code>nethub_vchan_user_register_callback()</code>
##### <code>nethub_vchan_user_register_callback()</code>
# <code>nethub_vchan_user_send()</code>
##### <code>nethub_vchan_user_send()</code>
# Call <code>nethub_vchan_deinit()</code> when finished
##### <code>nethub_vchan_deinit()</code> when finished


Example:
Example:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
#include <stdio.h>
        #include <stdio.h>
#include <string.h>
        #include <string.h>


#include "nethub_vchan.h"
        #include "nethub_vchan.h"


static void user_rx_cb(const void *data, size_t len)
        static void user_rx_cb(const void *data, size_t len)
{
        {
    printf("recv USER data: %.*s\n", (int)len, (const char *)data);
            printf("recv USER data: %.*s
}
", (int)len, (const char *)data);
        }


int main(void)
        int main(void)
{
        {
    const char *msg = "hello from host";
            const char *msg = "hello from host";


    if (nethub_vchan_init() != 0) {
            if (nethub_vchan_init() != 0) {
        return -1;
                return -1;
    }
            }


    nethub_vchan_user_register_callback(user_rx_cb);
            nethub_vchan_user_register_callback(user_rx_cb);
    nethub_vchan_user_send(msg, strlen(msg));
            nethub_vchan_user_send(msg, strlen(msg));


    nethub_vchan_deinit();
            nethub_vchan_deinit();
    return 0;
            return 0;
}
        }
</syntaxhighlight>
</syntaxhighlight>


== 6. Limits and Notes ==
== 7. Limits and Notes ==


* Maximum payload length per message is <code>1500</code> bytes
***** maximum payload length per message is <code>1500</code> bytes
* The <code>USER</code> channel is packet-oriented, not a byte stream
***** USER virtual channel is packet-oriented, not a byte stream
* The kernel module must be loaded before use
***** the current in-tree end-to-end path is SDIO-based
* If the device side does not enable <code>CONFIG_MR_VIRTUALCHAN</code>, the host-side <code>USER</code> channel will not work
***** if the device side does not enable <code>CONFIG_MR_VIRTUALCHAN</code>, the current in-tree USER virtual-channel path will not work
* If host control-plane traffic and <code>USER</code> traffic coexist, do not reuse the <code>AT</code> type for customer private data
***** if control traffic and USER traffic coexist, keep private application traffic on <code>USER</code> and do not reuse the <code>AT</code> type


== 7. Related Pages ==
== 8. Related Pages ==


* [[NetHubQuickBringup|NetHubQuickBringup.md]]
***** [[NetHub|NetHub.md]]
* [[NetHubArchitecture|NetHubArchitecture.md]]
***** [[NetHubQuickBringup|NetHubQuickBringup.md]]
* [[NetHub|NetHub.md]]
***** [[NetHubArchitecture|NetHubArchitecture.md]]

2026年4月24日 (五) 13:48的版本

NetHub USER Virtual Channel

This document describes the current NetHub USER virtual-channel support.

1. Concept

USER virtual channel is a logical message channel carried on the active host link.

It is not a separate physical interface. The public API is designed to be transport-neutral, while the current in-tree implementation is still centered on the SDIO reference path.

Common logical types are:

          • USER
            • private customer or application data
          • AT
            • control payloads
          • SYSTEM
            • internal coordination messages

2. Current Support Status

Area Current status
Device API surface transport-neutral by design
Device in-tree implementation currently in backend/host/sdio/virtualchan.c
Host userspace library currently aligned with mr_sdio.ko + netlink
End-to-end USER vchan reference path SDIO
USB device-side ACM transport exists, but in-tree host nethub_vchan alignment is not finished
SPI not supported

3. Prerequisites

Before using the current in-tree USER virtual-channel path, confirm:

          • device side is built with CONFIG_NETHUB=y
          • device side enables CONFIG_MR_VIRTUALCHAN=y
          • the selected bring-up path is the current SDIO reference flow
          • host side has loaded mr_sdio.ko
          • the host-device link is already working

Notes:

          • USER and AT are parallel logical channels
          • customer private data should stay on the USER type
          • documentation should not claim that USB and SPI already share the same finished end-to-end virtual-channel stack

4. Device-Side API

Header:

          • components/net/nethub/include/nethub_vchan.h

Common APIs:

        int nethub_vchan_user_send(const void *data, uint16_t len);
        int nethub_vchan_user_recv_register(nethub_vchan_recv_cb_t recv_cb, void *cb_arg);

5. Host-Side API

Header:

          • bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h

Initialization and cleanup:

        int nethub_vchan_init(void);
        int nethub_vchan_deinit(void);

USER channel:

        typedef void (*nethub_vchan_recv_callback_t)(const void *data, size_t len);

        int nethub_vchan_user_send(const void *data, size_t len);
        int nethub_vchan_user_register_callback(nethub_vchan_recv_callback_t callback);

Optional state query:

        typedef struct {
            nethub_vchan_link_state_t link_state;
            nethub_vchan_host_state_t host_state;
        } nethub_vchan_state_snapshot_t;

        int nethub_vchan_get_state_snapshot(nethub_vchan_state_snapshot_t *snapshot);

Optional link event callback:

        int nethub_vchan_register_link_event_callback(
            nethub_vchan_link_event_callback_t callback,
            void *user_data);

6. Typical Usage Order

          1. nethub_vchan_init()
          2. nethub_vchan_user_register_callback()
          3. nethub_vchan_user_send()
          4. nethub_vchan_deinit() when finished

Example:

        #include <stdio.h>
        #include <string.h>

        #include "nethub_vchan.h"

        static void user_rx_cb(const void *data, size_t len)
        {
            printf("recv USER data: %.*s
", (int)len, (const char *)data);
        }

        int main(void)
        {
            const char *msg = "hello from host";

            if (nethub_vchan_init() != 0) {
                return -1;
            }

            nethub_vchan_user_register_callback(user_rx_cb);
            nethub_vchan_user_send(msg, strlen(msg));

            nethub_vchan_deinit();
            return 0;
        }

7. Limits and Notes

          • maximum payload length per message is 1500 bytes
          • USER virtual channel is packet-oriented, not a byte stream
          • the current in-tree end-to-end path is SDIO-based
          • if the device side does not enable CONFIG_MR_VIRTUALCHAN, the current in-tree USER virtual-channel path will not work
          • if control traffic and USER traffic coexist, keep private application traffic on USER and do not reuse the AT type

8. Related Pages