This is an automated email from the ASF dual-hosted git repository. masayuki pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 318d136320a5b297404380c1b393f4b69342b86d Author: Zhe Weng <[email protected]> AuthorDate: Wed May 17 17:30:40 2023 +0800 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 <[email protected]> --- drivers/net/netdev_upperhalf.c | 39 ++++++++++++++++++++++++++++++++++++ include/nuttx/net/netdev_lowerhalf.h | 35 +++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index e2cede4d47..8c1c3244d2 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -1359,3 +1359,42 @@ bool netpkt_is_fragmented(FAR netpkt_t *pkt) { return pkt->io_flink != NULL; } + +/**************************************************************************** + * Name: netpkt_to_iov + * + * Description: + * Write each piece of data/len into iov array. + * + * Input Parameters: + * dev - The lower half device driver structure + * pkt - The net packet + * iov - The iov array to write + * iovcnt - The number of elements in the iov array + * + * Returned Value: + * The actual written count of iov entries. + * + ****************************************************************************/ + +int netpkt_to_iov(FAR struct netdev_lowerhalf_s *dev, FAR netpkt_t *pkt, + FAR struct iovec *iov, int iovcnt) +{ + int i; + + for (i = 0; pkt != NULL && i < iovcnt; pkt = pkt->io_flink, i++) + { + if (i == 0) + { + iov[i].iov_base = IOB_DATA(pkt) - NET_LL_HDRLEN(&dev->netdev); + iov[i].iov_len = pkt->io_len + NET_LL_HDRLEN(&dev->netdev); + } + else + { + iov[i].iov_base = IOB_DATA(pkt); + iov[i].iov_len = pkt->io_len; + } + } + + return i; +} diff --git a/include/nuttx/net/netdev_lowerhalf.h b/include/nuttx/net/netdev_lowerhalf.h index d47f324739..f29f9b4337 100644 --- a/include/nuttx/net/netdev_lowerhalf.h +++ b/include/nuttx/net/netdev_lowerhalf.h @@ -47,7 +47,9 @@ * Pre-processor Definitions ****************************************************************************/ -/* | <-------------- NETPKT_BUFLEN ---------------> | +/* Layout for net packet: + * + * | <-------------- NETPKT_BUFLEN ---------------> | * +---------------------+-------------------+------+ +-------------+ * | reserved for driver | data | free | ---> | next netpkt | * +---------------------+-------------------+------+ +-------------+ @@ -55,6 +57,17 @@ * ^base ^data */ +/* Layout for linked net packet, you can get list of (data, len) by + * netpkt_to_iov() interface: + * + * | <----------- datalen = sum(len) ------------> | + * +----------+-----------+ +-----------+ +-----------+------+ + * | reserved | data | --> | data | --> | data | free | + * +----------+-----------+ +-----------+ +-----------+------+ + * | | <- len -> | | <- len -> | | <- len -> | + * ^base ^data ^data ^data + */ + #define NETPKT_BUFLEN CONFIG_IOB_BUFSIZE /**************************************************************************** @@ -478,4 +491,24 @@ void netpkt_reset_reserved(FAR struct netdev_lowerhalf_s *dev, bool netpkt_is_fragmented(FAR netpkt_t *pkt); +/**************************************************************************** + * Name: netpkt_to_iov + * + * Description: + * Write each piece of data/len into iov array. + * + * Input Parameters: + * dev - The lower half device driver structure + * pkt - The net packet + * iov - The iov array to write + * iovcnt - The number of elements in the iov array + * + * Returned Value: + * The actual written count of iov entries. + * + ****************************************************************************/ + +int netpkt_to_iov(FAR struct netdev_lowerhalf_s *dev, FAR netpkt_t *pkt, + FAR struct iovec *iov, int iovcnt); + #endif /* __INCLUDE_NUTTX_NET_NETDEV_LOWERHALF_H */
