Skip to content

Commit c86c120

Browse files
fengidrikuba-moo
authored andcommitted
virtio_net: separate receive_buf
This commit separates the function receive_buf(), then we wrap the logic of handling the skb to an independent function virtnet_receive_done(). The subsequent commit will reuse it. Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 391aa2a commit c86c120

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

drivers/net/virtio_net.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,14 +1968,47 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash,
19681968
skb_set_hash(skb, __le32_to_cpu(hdr_hash->hash_value), rss_hash_type);
19691969
}
19701970

1971+
static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq,
1972+
struct sk_buff *skb, u8 flags)
1973+
{
1974+
struct virtio_net_common_hdr *hdr;
1975+
struct net_device *dev = vi->dev;
1976+
1977+
hdr = skb_vnet_common_hdr(skb);
1978+
if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report)
1979+
virtio_skb_set_hash(&hdr->hash_v1_hdr, skb);
1980+
1981+
if (flags & VIRTIO_NET_HDR_F_DATA_VALID)
1982+
skb->ip_summed = CHECKSUM_UNNECESSARY;
1983+
1984+
if (virtio_net_hdr_to_skb(skb, &hdr->hdr,
1985+
virtio_is_little_endian(vi->vdev))) {
1986+
net_warn_ratelimited("%s: bad gso: type: %u, size: %u\n",
1987+
dev->name, hdr->hdr.gso_type,
1988+
hdr->hdr.gso_size);
1989+
goto frame_err;
1990+
}
1991+
1992+
skb_record_rx_queue(skb, vq2rxq(rq->vq));
1993+
skb->protocol = eth_type_trans(skb, dev);
1994+
pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
1995+
ntohs(skb->protocol), skb->len, skb->pkt_type);
1996+
1997+
napi_gro_receive(&rq->napi, skb);
1998+
return;
1999+
2000+
frame_err:
2001+
DEV_STATS_INC(dev, rx_frame_errors);
2002+
dev_kfree_skb(skb);
2003+
}
2004+
19712005
static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
19722006
void *buf, unsigned int len, void **ctx,
19732007
unsigned int *xdp_xmit,
19742008
struct virtnet_rq_stats *stats)
19752009
{
19762010
struct net_device *dev = vi->dev;
19772011
struct sk_buff *skb;
1978-
struct virtio_net_common_hdr *hdr;
19792012
u8 flags;
19802013

19812014
if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
@@ -2005,32 +2038,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
20052038
if (unlikely(!skb))
20062039
return;
20072040

2008-
hdr = skb_vnet_common_hdr(skb);
2009-
if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report)
2010-
virtio_skb_set_hash(&hdr->hash_v1_hdr, skb);
2011-
2012-
if (flags & VIRTIO_NET_HDR_F_DATA_VALID)
2013-
skb->ip_summed = CHECKSUM_UNNECESSARY;
2014-
2015-
if (virtio_net_hdr_to_skb(skb, &hdr->hdr,
2016-
virtio_is_little_endian(vi->vdev))) {
2017-
net_warn_ratelimited("%s: bad gso: type: %u, size: %u\n",
2018-
dev->name, hdr->hdr.gso_type,
2019-
hdr->hdr.gso_size);
2020-
goto frame_err;
2021-
}
2022-
2023-
skb_record_rx_queue(skb, vq2rxq(rq->vq));
2024-
skb->protocol = eth_type_trans(skb, dev);
2025-
pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
2026-
ntohs(skb->protocol), skb->len, skb->pkt_type);
2027-
2028-
napi_gro_receive(&rq->napi, skb);
2029-
return;
2030-
2031-
frame_err:
2032-
DEV_STATS_INC(dev, rx_frame_errors);
2033-
dev_kfree_skb(skb);
2041+
virtnet_receive_done(vi, rq, skb, flags);
20342042
}
20352043

20362044
/* Unlike mergeable buffers, all buffers are allocated to the

0 commit comments

Comments
 (0)