xref: /dpdk/drivers/net/virtio/virtqueue.c (revision 6c3169a3dc041cbdbef506f19e3779940caa4b29)
1*6c3169a3SBruce Richardson /*-
2*6c3169a3SBruce Richardson  *   BSD LICENSE
3*6c3169a3SBruce Richardson  *
4*6c3169a3SBruce Richardson  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5*6c3169a3SBruce Richardson  *   All rights reserved.
6*6c3169a3SBruce Richardson  *
7*6c3169a3SBruce Richardson  *   Redistribution and use in source and binary forms, with or without
8*6c3169a3SBruce Richardson  *   modification, are permitted provided that the following conditions
9*6c3169a3SBruce Richardson  *   are met:
10*6c3169a3SBruce Richardson  *
11*6c3169a3SBruce Richardson  *     * Redistributions of source code must retain the above copyright
12*6c3169a3SBruce Richardson  *       notice, this list of conditions and the following disclaimer.
13*6c3169a3SBruce Richardson  *     * Redistributions in binary form must reproduce the above copyright
14*6c3169a3SBruce Richardson  *       notice, this list of conditions and the following disclaimer in
15*6c3169a3SBruce Richardson  *       the documentation and/or other materials provided with the
16*6c3169a3SBruce Richardson  *       distribution.
17*6c3169a3SBruce Richardson  *     * Neither the name of Intel Corporation nor the names of its
18*6c3169a3SBruce Richardson  *       contributors may be used to endorse or promote products derived
19*6c3169a3SBruce Richardson  *       from this software without specific prior written permission.
20*6c3169a3SBruce Richardson  *
21*6c3169a3SBruce Richardson  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*6c3169a3SBruce Richardson  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*6c3169a3SBruce Richardson  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24*6c3169a3SBruce Richardson  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25*6c3169a3SBruce Richardson  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26*6c3169a3SBruce Richardson  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27*6c3169a3SBruce Richardson  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*6c3169a3SBruce Richardson  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*6c3169a3SBruce Richardson  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*6c3169a3SBruce Richardson  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*6c3169a3SBruce Richardson  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*6c3169a3SBruce Richardson  */
33*6c3169a3SBruce Richardson #include <stdint.h>
34*6c3169a3SBruce Richardson 
35*6c3169a3SBruce Richardson #include <rte_mbuf.h>
36*6c3169a3SBruce Richardson 
37*6c3169a3SBruce Richardson #include "virtqueue.h"
38*6c3169a3SBruce Richardson #include "virtio_logs.h"
39*6c3169a3SBruce Richardson #include "virtio_pci.h"
40*6c3169a3SBruce Richardson 
41*6c3169a3SBruce Richardson void
42*6c3169a3SBruce Richardson virtqueue_disable_intr(struct virtqueue *vq)
43*6c3169a3SBruce Richardson {
44*6c3169a3SBruce Richardson 	/*
45*6c3169a3SBruce Richardson 	 * Set VRING_AVAIL_F_NO_INTERRUPT to hint host
46*6c3169a3SBruce Richardson 	 * not to interrupt when it consumes packets
47*6c3169a3SBruce Richardson 	 * Note: this is only considered a hint to the host
48*6c3169a3SBruce Richardson 	 */
49*6c3169a3SBruce Richardson 	vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
50*6c3169a3SBruce Richardson }
51*6c3169a3SBruce Richardson 
52*6c3169a3SBruce Richardson /*
53*6c3169a3SBruce Richardson  * Two types of mbuf to be cleaned:
54*6c3169a3SBruce Richardson  * 1) mbuf that has been consumed by backend but not used by virtio.
55*6c3169a3SBruce Richardson  * 2) mbuf that hasn't been consued by backend.
56*6c3169a3SBruce Richardson  */
57*6c3169a3SBruce Richardson struct rte_mbuf *
58*6c3169a3SBruce Richardson virtqueue_detatch_unused(struct virtqueue *vq)
59*6c3169a3SBruce Richardson {
60*6c3169a3SBruce Richardson 	struct rte_mbuf *cookie;
61*6c3169a3SBruce Richardson 	int idx;
62*6c3169a3SBruce Richardson 
63*6c3169a3SBruce Richardson 	for (idx = 0; idx < vq->vq_nentries; idx++) {
64*6c3169a3SBruce Richardson 		if ((cookie = vq->vq_descx[idx].cookie) != NULL) {
65*6c3169a3SBruce Richardson 			vq->vq_descx[idx].cookie = NULL;
66*6c3169a3SBruce Richardson 			return cookie;
67*6c3169a3SBruce Richardson 		}
68*6c3169a3SBruce Richardson 	}
69*6c3169a3SBruce Richardson 	return NULL;
70*6c3169a3SBruce Richardson }
71