net_backends.h (84659b24) net_backends.h (154972af)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2019 Vincenzo Maffione <vmaffione@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 23 unchanged lines hidden (view full) ---

32
33#include <stdint.h>
34
35/* Opaque type representing a network backend. */
36typedef struct net_backend net_backend_t;
37
38/* Interface between network frontends and the network backends. */
39typedef void (*net_be_rxeof_t)(int, enum ev_type, void *param);
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2019 Vincenzo Maffione <vmaffione@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 23 unchanged lines hidden (view full) ---

32
33#include <stdint.h>
34
35/* Opaque type representing a network backend. */
36typedef struct net_backend net_backend_t;
37
38/* Interface between network frontends and the network backends. */
39typedef void (*net_be_rxeof_t)(int, enum ev_type, void *param);
40int netbe_init(net_backend_t **be, const char *devname, net_be_rxeof_t cb,
40int netbe_init(net_backend_t **be, const char *opts, net_be_rxeof_t cb,
41 void *param);
42void netbe_cleanup(net_backend_t *be);
43uint64_t netbe_get_cap(net_backend_t *be);
44int netbe_set_cap(net_backend_t *be, uint64_t cap,
45 unsigned vnet_hdr_len);
41 void *param);
42void netbe_cleanup(net_backend_t *be);
43uint64_t netbe_get_cap(net_backend_t *be);
44int netbe_set_cap(net_backend_t *be, uint64_t cap,
45 unsigned vnet_hdr_len);
46ssize_t netbe_send(net_backend_t *be, struct iovec *iov, int iovcnt);
47ssize_t netbe_recv(net_backend_t *be, struct iovec *iov, int iovcnt);
46size_t netbe_get_vnet_hdr_len(net_backend_t *be);
47ssize_t netbe_send(net_backend_t *be, const struct iovec *iov, int iovcnt);
48ssize_t netbe_peek_recvlen(net_backend_t *be);
49ssize_t netbe_recv(net_backend_t *be, const struct iovec *iov, int iovcnt);
48ssize_t netbe_rx_discard(net_backend_t *be);
50ssize_t netbe_rx_discard(net_backend_t *be);
51void netbe_rx_disable(net_backend_t *be);
52void netbe_rx_enable(net_backend_t *be);
49
50
51/*
52 * Network device capabilities taken from the VirtIO standard.
53 * Despite the name, these capabilities can be used by different frontents
54 * (virtio-net, ptnet) and supported by different backends (netmap, tap, ...).
55 */
56#define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */
57#define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */
53
54
55/*
56 * Network device capabilities taken from the VirtIO standard.
57 * Despite the name, these capabilities can be used by different frontents
58 * (virtio-net, ptnet) and supported by different backends (netmap, tap, ...).
59 */
60#define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */
61#define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */
62#define VIRTIO_NET_F_MTU (1 << 3) /* initial MTU advice */
58#define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */
59#define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */
60#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */
61#define VIRTIO_NET_F_GUEST_TSO6 (1 << 8) /* guest can rcv TSOv6 */
62#define VIRTIO_NET_F_GUEST_ECN (1 << 9) /* guest can rcv TSO with ECN */
63#define VIRTIO_NET_F_GUEST_UFO (1 << 10) /* guest can rcv UFO */
64#define VIRTIO_NET_F_HOST_TSO4 (1 << 11) /* host can rcv TSOv4 */
65#define VIRTIO_NET_F_HOST_TSO6 (1 << 12) /* host can rcv TSOv6 */
66#define VIRTIO_NET_F_HOST_ECN (1 << 13) /* host can rcv TSO with ECN */
67#define VIRTIO_NET_F_HOST_UFO (1 << 14) /* host can rcv UFO */
68#define VIRTIO_NET_F_MRG_RXBUF (1 << 15) /* host can merge RX buffers */
69#define VIRTIO_NET_F_STATUS (1 << 16) /* config status field available */
70#define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* control channel available */
71#define VIRTIO_NET_F_CTRL_RX (1 << 18) /* control channel RX mode support */
72#define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */
73#define VIRTIO_NET_F_GUEST_ANNOUNCE \
74 (1 << 21) /* guest can send gratuitous pkts */
63#define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */
64#define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */
65#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */
66#define VIRTIO_NET_F_GUEST_TSO6 (1 << 8) /* guest can rcv TSOv6 */
67#define VIRTIO_NET_F_GUEST_ECN (1 << 9) /* guest can rcv TSO with ECN */
68#define VIRTIO_NET_F_GUEST_UFO (1 << 10) /* guest can rcv UFO */
69#define VIRTIO_NET_F_HOST_TSO4 (1 << 11) /* host can rcv TSOv4 */
70#define VIRTIO_NET_F_HOST_TSO6 (1 << 12) /* host can rcv TSOv6 */
71#define VIRTIO_NET_F_HOST_ECN (1 << 13) /* host can rcv TSO with ECN */
72#define VIRTIO_NET_F_HOST_UFO (1 << 14) /* host can rcv UFO */
73#define VIRTIO_NET_F_MRG_RXBUF (1 << 15) /* host can merge RX buffers */
74#define VIRTIO_NET_F_STATUS (1 << 16) /* config status field available */
75#define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* control channel available */
76#define VIRTIO_NET_F_CTRL_RX (1 << 18) /* control channel RX mode support */
77#define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */
78#define VIRTIO_NET_F_GUEST_ANNOUNCE \
79 (1 << 21) /* guest can send gratuitous pkts */
80#define VIRTIO_NET_F_MQ (1 << 22) /* host supports multiple VQ pairs */
75
76/*
77 * Fixed network header size
78 */
79struct virtio_net_rxhdr {
80 uint8_t vrh_flags;
81 uint8_t vrh_gso_type;
82 uint16_t vrh_hdr_len;
83 uint16_t vrh_gso_size;
84 uint16_t vrh_csum_start;
85 uint16_t vrh_csum_offset;
86 uint16_t vrh_bufs;
87} __packed;
88
89#endif /* __NET_BACKENDS_H__ */
81
82/*
83 * Fixed network header size
84 */
85struct virtio_net_rxhdr {
86 uint8_t vrh_flags;
87 uint8_t vrh_gso_type;
88 uint16_t vrh_hdr_len;
89 uint16_t vrh_gso_size;
90 uint16_t vrh_csum_start;
91 uint16_t vrh_csum_offset;
92 uint16_t vrh_bufs;
93} __packed;
94
95#endif /* __NET_BACKENDS_H__ */