[SLOF] [PATCH v1 24/27] virtio-net: make net_hdr_size a variable
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Wed Jan 13 22:17:11 AEDT 2016
Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
lib/libvirtio/virtio-net.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c
index 18ad2f7..9c51a39 100644
--- a/lib/libvirtio/virtio-net.c
+++ b/lib/libvirtio/virtio-net.c
@@ -53,6 +53,8 @@ struct virtio_net_hdr {
// uint16_t num_buffers; /* Only if VIRTIO_NET_F_MRG_RXBUF */
};
+static unsigned int net_hdr_size;
+
static uint16_t last_rx_idx; /* Last index in RX "used" ring */
/**
@@ -128,8 +130,9 @@ static int virtionet_init(net_driver_t *driver)
/* Device specific setup - we do not support special features right now */
virtio_set_guest_features(&virtiodev, 0);
+ net_hdr_size = sizeof(struct virtio_net_hdr);
/* Allocate memory for one transmit an multiple receive buffers */
- vq_rx.buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+sizeof(struct virtio_net_hdr))
+ vq_rx.buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size)
* RX_QUEUE_SIZE);
if (!vq_rx.buf_mem) {
printf("virtionet: Failed to allocate buffers!\n");
@@ -140,14 +143,14 @@ static int virtionet_init(net_driver_t *driver)
/* Prepare receive buffer queue */
for (i = 0; i < RX_QUEUE_SIZE; i++) {
uint64_t addr = (uint64_t)vq_rx.buf_mem
- + i * (BUFFER_ENTRY_SIZE+sizeof(struct virtio_net_hdr));
+ + i * (BUFFER_ENTRY_SIZE+net_hdr_size);
uint32_t id = i*2;
/* Descriptor for net_hdr: */
- fill_desc(&vq_rx.desc[id], 0, addr, sizeof(struct virtio_net_hdr),
+ fill_desc(&vq_rx.desc[id], 0, addr, net_hdr_size,
VRING_DESC_F_NEXT | VRING_DESC_F_WRITE, id + 1);
/* Descriptor for data: */
- fill_desc(&vq_rx.desc[id+1], 0, addr + sizeof(struct virtio_net_hdr),
+ fill_desc(&vq_rx.desc[id+1], 0, addr + net_hdr_size,
BUFFER_ENTRY_SIZE, VRING_DESC_F_WRITE, 0);
vq_rx.avail->ring[i] = id;
@@ -221,7 +224,7 @@ static int virtionet_xmit(char *buf, int len)
/* Set up virtqueue descriptor for header */
fill_desc(&vq_tx.desc[id], 0, (uint64_t)&nethdr,
- sizeof(struct virtio_net_hdr), VRING_DESC_F_NEXT, id + 1);
+ net_hdr_size, VRING_DESC_F_NEXT, id + 1);
/* Set up virtqueue descriptor for data */
fill_desc(&vq_tx.desc[id+1], 0, (uint64_t)buf, len, 0, 0);
@@ -254,7 +257,7 @@ static int virtionet_receive(char *buf, int maxlen)
id = (vq_rx.used->ring[last_rx_idx % vq_rx.size].id + 1)
% vq_rx.size;
len = vq_rx.used->ring[last_rx_idx % vq_rx.size].len
- - sizeof(struct virtio_net_hdr);
+ - net_hdr_size;
dprintf("virtionet_receive() last_rx_idx=%i, vq_rx.used->idx=%i,"
" id=%i len=%i\n", last_rx_idx, vq_rx.used->idx, id, len);
--
2.5.0
More information about the SLOF
mailing list