184659b24SMichael Zeller /*- 2*32640292SAndy Fiddaman * SPDX-License-Identifier: BSD-2-Clause 384659b24SMichael Zeller * 484659b24SMichael Zeller * Copyright (c) 2019 Vincenzo Maffione <vmaffione@FreeBSD.org> 584659b24SMichael Zeller * 684659b24SMichael Zeller * Redistribution and use in source and binary forms, with or without 784659b24SMichael Zeller * modification, are permitted provided that the following conditions 884659b24SMichael Zeller * are met: 984659b24SMichael Zeller * 1. Redistributions of source code must retain the above copyright 1084659b24SMichael Zeller * notice, this list of conditions and the following disclaimer. 1184659b24SMichael Zeller * 2. Redistributions in binary form must reproduce the above copyright 1284659b24SMichael Zeller * notice, this list of conditions and the following disclaimer in the 1384659b24SMichael Zeller * documentation and/or other materials provided with the distribution. 1484659b24SMichael Zeller * 1584659b24SMichael Zeller * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND 1684659b24SMichael Zeller * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1784659b24SMichael Zeller * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1884659b24SMichael Zeller * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 1984659b24SMichael Zeller * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 2084659b24SMichael Zeller * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 2184659b24SMichael Zeller * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2284659b24SMichael Zeller * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2384659b24SMichael Zeller * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 2484659b24SMichael Zeller * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 2584659b24SMichael Zeller * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2684659b24SMichael Zeller */ 2784659b24SMichael Zeller 2884659b24SMichael Zeller #ifndef __NET_BACKENDS_H__ 2984659b24SMichael Zeller #define __NET_BACKENDS_H__ 3084659b24SMichael Zeller 3184659b24SMichael Zeller #include <stdint.h> 3284659b24SMichael Zeller 3384659b24SMichael Zeller /* Opaque type representing a network backend. */ 3484659b24SMichael Zeller typedef struct net_backend net_backend_t; 3584659b24SMichael Zeller 3684659b24SMichael Zeller /* Interface between network frontends and the network backends. */ 3784659b24SMichael Zeller typedef void (*net_be_rxeof_t)(int, enum ev_type, void *param); 382b948146SAndy Fiddaman int netbe_init(net_backend_t **be, nvlist_t *nvl, net_be_rxeof_t cb, 3984659b24SMichael Zeller void *param); 402b948146SAndy Fiddaman int netbe_legacy_config(nvlist_t *nvl, const char *opts); 4184659b24SMichael Zeller void netbe_cleanup(net_backend_t *be); 4284659b24SMichael Zeller uint64_t netbe_get_cap(net_backend_t *be); 4384659b24SMichael Zeller int netbe_set_cap(net_backend_t *be, uint64_t cap, 4484659b24SMichael Zeller unsigned vnet_hdr_len); 45154972afSPatrick Mooney size_t netbe_get_vnet_hdr_len(net_backend_t *be); 46154972afSPatrick Mooney ssize_t netbe_send(net_backend_t *be, const struct iovec *iov, int iovcnt); 47154972afSPatrick Mooney ssize_t netbe_peek_recvlen(net_backend_t *be); 48154972afSPatrick Mooney ssize_t netbe_recv(net_backend_t *be, const struct iovec *iov, int iovcnt); 4984659b24SMichael Zeller ssize_t netbe_rx_discard(net_backend_t *be); 50154972afSPatrick Mooney void netbe_rx_disable(net_backend_t *be); 51154972afSPatrick Mooney void netbe_rx_enable(net_backend_t *be); 52069b2ef0SAndy Fiddaman #ifndef __FreeBSD__ 53069b2ef0SAndy Fiddaman int netbe_get_mac(net_backend_t *, void *, size_t *); 54069b2ef0SAndy Fiddaman #endif 5584659b24SMichael Zeller 5684659b24SMichael Zeller /* 5784659b24SMichael Zeller * Network device capabilities taken from the VirtIO standard. 58*32640292SAndy Fiddaman * Despite the name, these capabilities can be used by different frontends 5984659b24SMichael Zeller * (virtio-net, ptnet) and supported by different backends (netmap, tap, ...). 6084659b24SMichael Zeller */ 6184659b24SMichael Zeller #define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */ 6284659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */ 63154972afSPatrick Mooney #define VIRTIO_NET_F_MTU (1 << 3) /* initial MTU advice */ 6484659b24SMichael Zeller #define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */ 6584659b24SMichael Zeller #define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */ 6684659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */ 6784659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_TSO6 (1 << 8) /* guest can rcv TSOv6 */ 6884659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_ECN (1 << 9) /* guest can rcv TSO with ECN */ 6984659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_UFO (1 << 10) /* guest can rcv UFO */ 7084659b24SMichael Zeller #define VIRTIO_NET_F_HOST_TSO4 (1 << 11) /* host can rcv TSOv4 */ 7184659b24SMichael Zeller #define VIRTIO_NET_F_HOST_TSO6 (1 << 12) /* host can rcv TSOv6 */ 7284659b24SMichael Zeller #define VIRTIO_NET_F_HOST_ECN (1 << 13) /* host can rcv TSO with ECN */ 7384659b24SMichael Zeller #define VIRTIO_NET_F_HOST_UFO (1 << 14) /* host can rcv UFO */ 7484659b24SMichael Zeller #define VIRTIO_NET_F_MRG_RXBUF (1 << 15) /* host can merge RX buffers */ 7584659b24SMichael Zeller #define VIRTIO_NET_F_STATUS (1 << 16) /* config status field available */ 7684659b24SMichael Zeller #define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* control channel available */ 7784659b24SMichael Zeller #define VIRTIO_NET_F_CTRL_RX (1 << 18) /* control channel RX mode support */ 7884659b24SMichael Zeller #define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */ 7984659b24SMichael Zeller #define VIRTIO_NET_F_GUEST_ANNOUNCE \ 8084659b24SMichael Zeller (1 << 21) /* guest can send gratuitous pkts */ 81154972afSPatrick Mooney #define VIRTIO_NET_F_MQ (1 << 22) /* host supports multiple VQ pairs */ 8284659b24SMichael Zeller 8384659b24SMichael Zeller /* 8484659b24SMichael Zeller * Fixed network header size 8584659b24SMichael Zeller */ 8684659b24SMichael Zeller struct virtio_net_rxhdr { 8784659b24SMichael Zeller uint8_t vrh_flags; 8884659b24SMichael Zeller uint8_t vrh_gso_type; 8984659b24SMichael Zeller uint16_t vrh_hdr_len; 9084659b24SMichael Zeller uint16_t vrh_gso_size; 9184659b24SMichael Zeller uint16_t vrh_csum_start; 9284659b24SMichael Zeller uint16_t vrh_csum_offset; 9384659b24SMichael Zeller uint16_t vrh_bufs; 9484659b24SMichael Zeller } __packed; 9584659b24SMichael Zeller 9684659b24SMichael Zeller #endif /* __NET_BACKENDS_H__ */ 97