16c3169a3SBruce Richardson /*- 26c3169a3SBruce Richardson * BSD LICENSE 36c3169a3SBruce Richardson * 45382b188SBernard Iremonger * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. 56c3169a3SBruce Richardson * All rights reserved. 66c3169a3SBruce Richardson * 76c3169a3SBruce Richardson * Redistribution and use in source and binary forms, with or without 86c3169a3SBruce Richardson * modification, are permitted provided that the following conditions 96c3169a3SBruce Richardson * are met: 106c3169a3SBruce Richardson * 116c3169a3SBruce Richardson * * Redistributions of source code must retain the above copyright 126c3169a3SBruce Richardson * notice, this list of conditions and the following disclaimer. 136c3169a3SBruce Richardson * * Redistributions in binary form must reproduce the above copyright 146c3169a3SBruce Richardson * notice, this list of conditions and the following disclaimer in 156c3169a3SBruce Richardson * the documentation and/or other materials provided with the 166c3169a3SBruce Richardson * distribution. 176c3169a3SBruce Richardson * * Neither the name of Intel Corporation nor the names of its 186c3169a3SBruce Richardson * contributors may be used to endorse or promote products derived 196c3169a3SBruce Richardson * from this software without specific prior written permission. 206c3169a3SBruce Richardson * 216c3169a3SBruce Richardson * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 226c3169a3SBruce Richardson * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 236c3169a3SBruce Richardson * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 246c3169a3SBruce Richardson * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 256c3169a3SBruce Richardson * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 266c3169a3SBruce Richardson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 276c3169a3SBruce Richardson * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 286c3169a3SBruce Richardson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 296c3169a3SBruce Richardson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 306c3169a3SBruce Richardson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 316c3169a3SBruce Richardson * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 326c3169a3SBruce Richardson */ 336c3169a3SBruce Richardson 346c3169a3SBruce Richardson #ifndef _VIRTIO_ETHDEV_H_ 356c3169a3SBruce Richardson #define _VIRTIO_ETHDEV_H_ 366c3169a3SBruce Richardson 376c3169a3SBruce Richardson #include <stdint.h> 386c3169a3SBruce Richardson 396c3169a3SBruce Richardson #include "virtio_pci.h" 406c3169a3SBruce Richardson 416c3169a3SBruce Richardson #define SPEED_10 10 426c3169a3SBruce Richardson #define SPEED_100 100 436c3169a3SBruce Richardson #define SPEED_1000 1000 446c3169a3SBruce Richardson #define SPEED_10G 10000 456c3169a3SBruce Richardson 466c3169a3SBruce Richardson #ifndef PAGE_SIZE 476c3169a3SBruce Richardson #define PAGE_SIZE 4096 486c3169a3SBruce Richardson #endif 496c3169a3SBruce Richardson 5045e4acd4SOlivier Matz #define VIRTIO_MAX_RX_QUEUES 128U 5145e4acd4SOlivier Matz #define VIRTIO_MAX_TX_QUEUES 128U 526c3169a3SBruce Richardson #define VIRTIO_MAX_MAC_ADDRS 64 536c3169a3SBruce Richardson #define VIRTIO_MIN_RX_BUFSIZE 64 546c3169a3SBruce Richardson #define VIRTIO_MAX_RX_PKTLEN 9728 556c3169a3SBruce Richardson 566c3169a3SBruce Richardson /* Features desired/implemented by this driver. */ 57*96cb6711SOlivier Matz #define VIRTIO_PMD_DEFAULT_GUEST_FEATURES \ 584a92b671SStephen Hemminger (1u << VIRTIO_NET_F_MAC | \ 594a92b671SStephen Hemminger 1u << VIRTIO_NET_F_STATUS | \ 604a92b671SStephen Hemminger 1u << VIRTIO_NET_F_MQ | \ 614a92b671SStephen Hemminger 1u << VIRTIO_NET_F_CTRL_MAC_ADDR | \ 624a92b671SStephen Hemminger 1u << VIRTIO_NET_F_CTRL_VQ | \ 634a92b671SStephen Hemminger 1u << VIRTIO_NET_F_CTRL_RX | \ 644a92b671SStephen Hemminger 1u << VIRTIO_NET_F_CTRL_VLAN | \ 656ba1f63bSYuanhan Liu 1u << VIRTIO_NET_F_MRG_RXBUF | \ 66eb9dce6cSPierre Pfister 1u << VIRTIO_RING_F_INDIRECT_DESC | \ 677a75276eSJason Wang 1ULL << VIRTIO_F_VERSION_1 | \ 687a75276eSJason Wang 1ULL << VIRTIO_F_IOMMU_PLATFORM) 696c3169a3SBruce Richardson 706c3169a3SBruce Richardson /* 716c3169a3SBruce Richardson * CQ function prototype 726c3169a3SBruce Richardson */ 736c3169a3SBruce Richardson void virtio_dev_cq_start(struct rte_eth_dev *dev); 746c3169a3SBruce Richardson 756c3169a3SBruce Richardson /* 766c3169a3SBruce Richardson * RX/TX function prototypes 776c3169a3SBruce Richardson */ 786c3169a3SBruce Richardson void virtio_dev_rxtx_start(struct rte_eth_dev *dev); 796c3169a3SBruce Richardson 806c3169a3SBruce Richardson int virtio_dev_queue_setup(struct rte_eth_dev *dev, 816c3169a3SBruce Richardson int queue_type, 826c3169a3SBruce Richardson uint16_t queue_idx, 836c3169a3SBruce Richardson uint16_t vtpci_queue_idx, 846c3169a3SBruce Richardson uint16_t nb_desc, 856c3169a3SBruce Richardson unsigned int socket_id, 8601ad44fdSHuawei Xie void **pvq); 876c3169a3SBruce Richardson 885382b188SBernard Iremonger void virtio_dev_queue_release(struct virtqueue *vq); 895382b188SBernard Iremonger 906c3169a3SBruce Richardson int virtio_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, 916c3169a3SBruce Richardson uint16_t nb_rx_desc, unsigned int socket_id, 926c3169a3SBruce Richardson const struct rte_eth_rxconf *rx_conf, 936c3169a3SBruce Richardson struct rte_mempool *mb_pool); 946c3169a3SBruce Richardson 955382b188SBernard Iremonger void virtio_dev_rx_queue_release(void *rxq); 965382b188SBernard Iremonger 976c3169a3SBruce Richardson int virtio_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, 986c3169a3SBruce Richardson uint16_t nb_tx_desc, unsigned int socket_id, 996c3169a3SBruce Richardson const struct rte_eth_txconf *tx_conf); 1006c3169a3SBruce Richardson 1015382b188SBernard Iremonger void virtio_dev_tx_queue_release(void *txq); 1025382b188SBernard Iremonger 1036c3169a3SBruce Richardson uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, 1046c3169a3SBruce Richardson uint16_t nb_pkts); 1056c3169a3SBruce Richardson 1066c3169a3SBruce Richardson uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, 1076c3169a3SBruce Richardson uint16_t nb_pkts); 1086c3169a3SBruce Richardson 1096c3169a3SBruce Richardson uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, 1106c3169a3SBruce Richardson uint16_t nb_pkts); 1116c3169a3SBruce Richardson 112fc3d6621SHuawei Xie uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, 113fc3d6621SHuawei Xie uint16_t nb_pkts); 1146c3169a3SBruce Richardson 115c121c8d6SHuawei Xie uint16_t virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, 116c121c8d6SHuawei Xie uint16_t nb_pkts); 117c121c8d6SHuawei Xie 118ce2eabddSJianfeng Tan int eth_virtio_dev_init(struct rte_eth_dev *eth_dev); 119ce2eabddSJianfeng Tan 1206c3169a3SBruce Richardson /* 1216c3169a3SBruce Richardson * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us 1226c3169a3SBruce Richardson * frames larger than 1514 bytes. We do not yet support software LRO 1236c3169a3SBruce Richardson * via tcp_lro_rx(). 1246c3169a3SBruce Richardson */ 1256c3169a3SBruce Richardson #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \ 1266c3169a3SBruce Richardson VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN) 1276c3169a3SBruce Richardson 1286c3169a3SBruce Richardson 1296c3169a3SBruce Richardson #endif /* _VIRTIO_ETHDEV_H_ */ 130