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 <wengzhe@xiaomi.com>
This commit is contained in:
parent
d44e19d115
commit
318d136320
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user