xref: /dpdk/drivers/net/virtio/virtio_ethdev.h (revision 3666feb30b42fbf143126344994c48810098feb7)
15566a3e3SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
25566a3e3SBruce Richardson  * Copyright(c) 2010-2015 Intel Corporation
36c3169a3SBruce Richardson  */
46c3169a3SBruce Richardson 
56c3169a3SBruce Richardson #ifndef _VIRTIO_ETHDEV_H_
66c3169a3SBruce Richardson #define _VIRTIO_ETHDEV_H_
76c3169a3SBruce Richardson 
86c3169a3SBruce Richardson #include <stdint.h>
96c3169a3SBruce Richardson 
107990d039SMaxime Coquelin #include <ethdev_driver.h>
117990d039SMaxime Coquelin 
127990d039SMaxime Coquelin #include "virtio.h"
136c3169a3SBruce Richardson 
1445e4acd4SOlivier Matz #define VIRTIO_MAX_RX_QUEUES 128U
1545e4acd4SOlivier Matz #define VIRTIO_MAX_TX_QUEUES 128U
166c3169a3SBruce Richardson #define VIRTIO_MAX_MAC_ADDRS 64
176c3169a3SBruce Richardson #define VIRTIO_MIN_RX_BUFSIZE 64
1849d26d9eSMaxime Coquelin #define VIRTIO_MAX_RX_PKTLEN  9728U
196c3169a3SBruce Richardson 
206c3169a3SBruce Richardson /* Features desired/implemented by this driver. */
2196cb6711SOlivier Matz #define VIRTIO_PMD_DEFAULT_GUEST_FEATURES	\
224a92b671SStephen Hemminger 	(1u << VIRTIO_NET_F_MAC		  |	\
234a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_STATUS	  |	\
244a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_MQ		  |	\
254a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_CTRL_MAC_ADDR |	\
264a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_CTRL_VQ	  |	\
274a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_CTRL_RX	  |	\
284a92b671SStephen Hemminger 	 1u << VIRTIO_NET_F_CTRL_VLAN	  |	\
296ba1f63bSYuanhan Liu 	 1u << VIRTIO_NET_F_MRG_RXBUF	  |	\
3049d26d9eSMaxime Coquelin 	 1u << VIRTIO_NET_F_MTU	| \
317365504fSXiao Wang 	 1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE |	\
32eb9dce6cSPierre Pfister 	 1u << VIRTIO_RING_F_INDIRECT_DESC |    \
337a75276eSJason Wang 	 1ULL << VIRTIO_F_VERSION_1       |	\
3441e45c90SMarvin Liu 	 1ULL << VIRTIO_F_IN_ORDER        |	\
35aea29aa5SJens Freimann 	 1ULL << VIRTIO_F_RING_PACKED	  |	\
369230ab8dSIlya Maximets 	 1ULL << VIRTIO_F_IOMMU_PLATFORM  |	\
377e72f3ecSCheng Jiang 	 1ULL << VIRTIO_F_ORDER_PLATFORM  |	\
381357b4b3SIvan Dyukov 	 1ULL << VIRTIO_F_NOTIFICATION_DATA | \
391357b4b3SIvan Dyukov 	 1ULL << VIRTIO_NET_F_SPEED_DUPLEX)
406c3169a3SBruce Richardson 
41142678d4SJianfeng Tan #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES	\
42142678d4SJianfeng Tan 	(VIRTIO_PMD_DEFAULT_GUEST_FEATURES |	\
43142678d4SJianfeng Tan 	 1u << VIRTIO_NET_F_GUEST_CSUM	   |	\
44142678d4SJianfeng Tan 	 1u << VIRTIO_NET_F_GUEST_TSO4     |	\
4566908effSTiwei Bie 	 1u << VIRTIO_NET_F_GUEST_TSO6     |	\
4666908effSTiwei Bie 	 1u << VIRTIO_NET_F_CSUM           |	\
4766908effSTiwei Bie 	 1u << VIRTIO_NET_F_HOST_TSO4      |	\
48*0c9d6620SMaxime Coquelin 	 1u << VIRTIO_NET_F_HOST_TSO6      |	\
49*0c9d6620SMaxime Coquelin 	 1ULL << VIRTIO_NET_F_RSS)
509c7ce8bdSTiwei Bie 
511c8489daSTiwei Bie extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops;
521c8489daSTiwei Bie 
536c3169a3SBruce Richardson /*
546c3169a3SBruce Richardson  * CQ function prototype
556c3169a3SBruce Richardson  */
566c3169a3SBruce Richardson void virtio_dev_cq_start(struct rte_eth_dev *dev);
576c3169a3SBruce Richardson 
586c3169a3SBruce Richardson /*
596c3169a3SBruce Richardson  * RX/TX function prototypes
606c3169a3SBruce Richardson  */
61b0caba1aSJianfeng Tan 
626c3169a3SBruce Richardson int  virtio_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
636c3169a3SBruce Richardson 		uint16_t nb_rx_desc, unsigned int socket_id,
646c3169a3SBruce Richardson 		const struct rte_eth_rxconf *rx_conf,
656c3169a3SBruce Richardson 		struct rte_mempool *mb_pool);
666c3169a3SBruce Richardson 
67efc83a1eSOlivier Matz int virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev,
68efc83a1eSOlivier Matz 				uint16_t rx_queue_id);
69efc83a1eSOlivier Matz 
706c3169a3SBruce Richardson int  virtio_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
716c3169a3SBruce Richardson 		uint16_t nb_tx_desc, unsigned int socket_id,
726c3169a3SBruce Richardson 		const struct rte_eth_txconf *tx_conf);
736c3169a3SBruce Richardson 
74efc83a1eSOlivier Matz int virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
75efc83a1eSOlivier Matz 				uint16_t tx_queue_id);
76efc83a1eSOlivier Matz 
776c3169a3SBruce Richardson uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
786c3169a3SBruce Richardson 		uint16_t nb_pkts);
79a76290c8SJens Freimann uint16_t virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts,
80a76290c8SJens Freimann 		uint16_t nb_pkts);
816c3169a3SBruce Richardson 
826c3169a3SBruce Richardson uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
836c3169a3SBruce Richardson 		uint16_t nb_pkts);
846c3169a3SBruce Richardson 
85a76290c8SJens Freimann uint16_t virtio_recv_mergeable_pkts_packed(void *rx_queue,
86a76290c8SJens Freimann 		struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
87a76290c8SJens Freimann 
88efcda136SMaxime Coquelin uint16_t virtio_recv_pkts_inorder(void *rx_queue,
89e5f456a9SMarvin Liu 		struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
90e5f456a9SMarvin Liu 
9100a5ea02SDilshod Urazov uint16_t virtio_xmit_pkts_prepare(void *tx_queue, struct rte_mbuf **tx_pkts,
9200a5ea02SDilshod Urazov 		uint16_t nb_pkts);
9300a5ea02SDilshod Urazov 
946c3169a3SBruce Richardson uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
956c3169a3SBruce Richardson 		uint16_t nb_pkts);
96892dc798SJens Freimann uint16_t virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
97892dc798SJens Freimann 		uint16_t nb_pkts);
986c3169a3SBruce Richardson 
99e5f456a9SMarvin Liu uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,
100e5f456a9SMarvin Liu 		uint16_t nb_pkts);
101e5f456a9SMarvin Liu 
102fc3d6621SHuawei Xie uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
103fc3d6621SHuawei Xie 		uint16_t nb_pkts);
1046c3169a3SBruce Richardson 
10577d66da8SMarvin Liu uint16_t virtio_recv_pkts_packed_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
10677d66da8SMarvin Liu 		uint16_t nb_pkts);
10777d66da8SMarvin Liu 
1086494b9a9SMarvin Liu uint16_t virtio_xmit_pkts_packed_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
1096494b9a9SMarvin Liu 		uint16_t nb_pkts);
1106494b9a9SMarvin Liu 
111ce2eabddSJianfeng Tan int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
112ce2eabddSJianfeng Tan 
113c23a1a30SQi Zhang void virtio_interrupt_handler(void *param);
114ef53b603SJianfeng Tan 
11536a7a2e7SMaxime Coquelin int virtio_dev_stop(struct rte_eth_dev *dev);
11636a7a2e7SMaxime Coquelin int virtio_dev_close(struct rte_eth_dev *dev);
1171978a9dcSXiao Wang 
1184e8169ebSIvan Ilchenko bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
1194e8169ebSIvan Ilchenko 			bool rx_scatter_enabled, const char **error);
1204e8169ebSIvan Ilchenko 
1214e8169ebSIvan Ilchenko uint16_t virtio_rx_mem_pool_buf_size(struct rte_mempool *mp);
1224e8169ebSIvan Ilchenko 
1236c3169a3SBruce Richardson #endif /* _VIRTIO_ETHDEV_H_ */
124