/*-
* BSD LICENSE
- *
+ *
* Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
PMD_INIT_FUNC_TRACE();
/*
- * Reinitialise since virtio port might have been stopped and restarted
- */
+ * Reinitialise since virtio port might have been stopped and restarted
+ */
memset(vq->vq_ring_virt_mem, 0, vq->vq_ring_size);
vring_init(vr, size, ring_mem, vq->vq_alignment);
vq->vq_used_cons_idx = 0;
vq->vq_desc_head_idx = 0;
vq->vq_avail_idx = 0;
- vq->vq_desc_tail_idx = vq->vq_nentries - 1;
+ vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
vq->vq_free_cnt = vq->vq_nentries;
memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
/* Only rx virtqueue needs mbufs to be allocated at initialization */
if (queue_type == VTNET_RQ) {
if (vq->mpool == NULL)
- rte_exit(EXIT_FAILURE, "Cannot allocate initial mbufs for rx virtqueue\n");
- /* Allocate blank mbufs for the each rx descriptor */
+ rte_exit(EXIT_FAILURE,
+ "Cannot allocate initial mbufs for rx virtqueue\n");
+
+ /* Allocate blank mbufs for the each rx descriptor */
nbufs = 0;
error = ENOSPC;
while (!virtqueue_full(vq)) {
m = rte_rxmbuf_alloc(vq->mpool);
if (m == NULL)
break;
+
/******************************************
* Enqueue allocated buffers *
*******************************************/
error = virtqueue_enqueue_recv_refill(vq, m);
+
if (error) {
- rte_pktmbuf_free_seg(m);
+ rte_pktmbuf_free_seg(m);
break;
}
nbufs++;
}
+
vq_update_avail_idx(vq);
+
PMD_INIT_LOG(DEBUG, "Allocated %d bufs\n", nbufs);
- VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL, VTNET_SQ_RQ_QUEUE_IDX);
+
+ VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL,
+ vq->vq_queue_index);
+ VIRTIO_WRITE_REG_4(vq->hw, VIRTIO_PCI_QUEUE_PFN,
+ vq->mz->phys_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
+ } else if (queue_type == VTNET_TQ) {
+ VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL,
+ vq->vq_queue_index);
VIRTIO_WRITE_REG_4(vq->hw, VIRTIO_PCI_QUEUE_PFN,
vq->mz->phys_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
} else {
- VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL, VTNET_SQ_TQ_QUEUE_IDX);
+ VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL,
+ vq->vq_queue_index);
VIRTIO_WRITE_REG_4(vq->hw, VIRTIO_PCI_QUEUE_PFN,
vq->mz->phys_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
}
}
+void
+virtio_dev_cq_start(struct rte_eth_dev *dev)
+{
+ struct virtio_hw *hw
+ = VIRTIO_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+ virtio_dev_vring_start(dev, hw->cvq, VTNET_CQ);
+ VIRTQUEUE_DUMP((struct virtqueue *)hw->cvq);
+}
+
void
virtio_dev_rxtx_start(struct rte_eth_dev *dev)
{
* - Allocate blank mbufs for the each rx descriptor
*
*/
+ int i;
PMD_INIT_FUNC_TRACE();
- /* Start rx vring: by default we have 1 rx virtqueue. */
- virtio_dev_vring_start(dev, dev->data->rx_queues[0], VTNET_RQ);
- VIRTQUEUE_DUMP((struct virtqueue *)dev->data->rx_queues[0]);
+ /* Start rx vring. */
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ virtio_dev_vring_start(dev, dev->data->rx_queues[i], VTNET_RQ);
+ VIRTQUEUE_DUMP((struct virtqueue *)dev->data->rx_queues[i]);
+ }
- /* Start tx vring: by default we have 1 tx virtqueue. */
- virtio_dev_vring_start(dev, dev->data->tx_queues[0], VTNET_TQ);
- VIRTQUEUE_DUMP((struct virtqueue *)dev->data->tx_queues[0]);
+ /* Start tx vring. */
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ virtio_dev_vring_start(dev, dev->data->tx_queues[i], VTNET_TQ);
+ VIRTQUEUE_DUMP((struct virtqueue *)dev->data->tx_queues[i]);
+ }
}
int
__rte_unused const struct rte_eth_rxconf *rx_conf,
struct rte_mempool *mp)
{
- uint8_t vtpci_queue_idx = VTNET_SQ_RQ_QUEUE_IDX;
+ uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
struct virtqueue *vq;
int ret;
PMD_INIT_LOG(ERR, "tvq initialization failed\n");
return ret;
}
+
/* Create mempool for rx mbuf allocation */
vq->mpool = mp;
unsigned int socket_id,
__rte_unused const struct rte_eth_txconf *tx_conf)
{
- uint8_t vtpci_queue_idx = VTNET_SQ_TQ_QUEUE_IDX;
+ uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
struct virtqueue *vq;
int ret;
error = virtqueue_enqueue_recv_refill(vq, m);
if (unlikely(error)) {
RTE_LOG(ERR, PMD, "cannot requeue discarded mbuf");
- rte_pktmbuf_free_seg(m);
+ rte_pktmbuf_free_seg(m);
}
}
num = (uint16_t)(likely(num <= VIRTIO_MBUF_BURST_SZ) ? num : VIRTIO_MBUF_BURST_SZ);
if (likely(num > DESC_PER_CACHELINE))
num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
+
if(num == 0) return 0;
+
num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
PMD_RX_LOG(DEBUG, "used:%d dequeue:%d\n", nb_used, num);
for (i = 0; i < num ; i ++) {
rxm = rcv_pkts[i];
+
PMD_RX_LOG(DEBUG, "packet len:%d\n", len[i]);
- if (unlikely(len[i] < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
+
+ if (unlikely(len[i]
+ < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
PMD_RX_LOG(ERR, "Packet drop\n");
nb_enqueued++;
virtio_discard_rxbuf(rxvq, rxm);
hw->eth_stats.ierrors++;
continue;
}
+
rxm->pkt.in_port = rxvq->port_id;
rxm->pkt.data = (char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM;
rxm->pkt.nb_segs = 1;
rxm->pkt.next = NULL;
- rxm->pkt.pkt_len = (uint32_t)(len[i] - sizeof(struct virtio_net_hdr));
- rxm->pkt.data_len = (uint16_t)(len[i] - sizeof(struct virtio_net_hdr));
+ rxm->pkt.pkt_len = (uint32_t)(len[i]
+ - sizeof(struct virtio_net_hdr));
+ rxm->pkt.data_len = (uint16_t)(len[i]
+ - sizeof(struct virtio_net_hdr));
+
VIRTIO_DUMP_PACKET(rxm, rxm->pkt.data_len);
+
rx_pkts[nb_rx++] = rxm;
hw->eth_stats.ibytes += len[i] - sizeof(struct virtio_net_hdr);
+ hw->eth_stats.q_ibytes[rxvq->queue_id] += len[i]
+ - sizeof(struct virtio_net_hdr);
}
+
hw->eth_stats.ipackets += nb_rx;
+ hw->eth_stats.q_ipackets[rxvq->queue_id] += nb_rx;
/* Allocate new mbuf for the used descriptor */
error = ENOSPC;
}
error = virtqueue_enqueue_recv_refill(rxvq, new_mbuf);
if (unlikely(error)) {
- rte_pktmbuf_free_seg(new_mbuf);
+ rte_pktmbuf_free_seg(new_mbuf);
break;
}
nb_enqueued ++;
}
- if(likely(nb_enqueued)) {
- if(unlikely(virtqueue_kick_prepare(rxvq))) {
- virtqueue_notify(rxvq);
+ if (likely(nb_enqueued)) {
+ if (unlikely(virtqueue_kick_prepare(rxvq))) {
+ virtqueue_notify(rxvq);
PMD_RX_LOG(DEBUG, "Notified\n");
}
}
+
vq_update_avail_idx(rxvq);
-
+
return (nb_rx);
}
virtqueue_dequeue_pkt_tx(txvq);
num--;
}
+
if(!virtqueue_full(txvq)) {
txm = tx_pkts[nb_tx];
/* Enqueue Packet buffers */
PMD_TX_LOG(ERR, "virtqueue_enqueue error: %d\n", error);
break;
}
- nb_tx++;
+ nb_tx++;
hw->eth_stats.obytes += txm->pkt.data_len;
+ hw->eth_stats.q_obytes[txvq->queue_id]
+ += txm->pkt.data_len;
} else {
PMD_TX_LOG(ERR, "No free tx descriptors to transmit\n");
break;
vq_update_avail_idx(txvq);
hw->eth_stats.opackets += nb_tx;
+ hw->eth_stats.q_opackets[txvq->queue_id] += nb_tx;
if(unlikely(virtqueue_kick_prepare(txvq))) {
- virtqueue_notify(txvq);
+ virtqueue_notify(txvq);
PMD_TX_LOG(DEBUG, "Notified backend after xmit\n");
}
+
return (nb_tx);
}