]> git.proxmox.com Git - mirror_qemu.git/blame - hw/net/net_tx_pkt.h
hw/timer/hpet: Convert DPRINTF to trace events
[mirror_qemu.git] / hw / net / net_tx_pkt.h
CommitLineData
e263cd49 1/*
605d52e6 2 * QEMU TX packets abstraction
e263cd49
DF
3 *
4 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
5 *
6 * Developed by Daynix Computing LTD (http://www.daynix.com)
7 *
8 * Authors:
9 * Dmitry Fleytman <dmitry@daynix.com>
10 * Tamir Shomer <tamirs@daynix.com>
11 * Yan Vugenfirer <yan@daynix.com>
12 *
13 * This work is licensed under the terms of the GNU GPL, version 2 or later.
14 * See the COPYING file in the top-level directory.
15 *
16 */
17
605d52e6
DF
18#ifndef NET_TX_PKT_H
19#define NET_TX_PKT_H
e263cd49 20
e263cd49
DF
21#include "net/eth.h"
22#include "exec/hwaddr.h"
23
24/* define to enable packet dump functions */
605d52e6 25/*#define NET_TX_PKT_DEBUG*/
e263cd49 26
605d52e6 27struct NetTxPkt;
e263cd49 28
a51db580
AO
29typedef void (*NetTxPktFreeFrag)(void *, void *, size_t);
30typedef void (*NetTxPktSend)(void *, const struct iovec *, int, const struct iovec *, int);
ffbd2dbd 31
e263cd49
DF
32/**
33 * Init function for tx packet functionality
34 *
35 * @pkt: packet pointer
36 * @max_frags: max tx ip fragments
e263cd49 37 */
a51db580 38void net_tx_pkt_init(struct NetTxPkt **pkt, uint32_t max_frags);
e263cd49
DF
39
40/**
41 * Clean all tx packet resources.
42 *
43 * @pkt: packet.
44 */
605d52e6 45void net_tx_pkt_uninit(struct NetTxPkt *pkt);
e263cd49
DF
46
47/**
48 * get virtio header
49 *
50 * @pkt: packet
51 * @ret: virtio header
52 */
605d52e6 53struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt);
e263cd49
DF
54
55/**
56 * build virtio header (will be stored in module context)
57 *
58 * @pkt: packet
59 * @tso_enable: TSO enabled
60 * @csum_enable: CSO enabled
61 * @gso_size: MSS size for TSO
f9a9eb16 62 * @ret: operation result
e263cd49
DF
63 *
64 */
f9a9eb16 65bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
e263cd49
DF
66 bool csum_enable, uint32_t gso_size);
67
68/**
eb700029
DF
69* updates vlan tag, and adds vlan header with custom ethernet type
70* in case it is missing.
71*
72* @pkt: packet
73* @vlan: VLAN tag
74* @vlan_ethtype: VLAN header Ethernet type
75*
76*/
77void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
78 uint16_t vlan, uint16_t vlan_ethtype);
79
80/**
81* updates vlan tag, and adds vlan header in case it is missing
82*
83* @pkt: packet
84* @vlan: VLAN tag
85*
86*/
87static inline void
88net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan)
89{
90 net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN);
91}
e263cd49
DF
92
93/**
94 * populate data fragment into pkt context.
95 *
96 * @pkt: packet
a51db580 97 * @base: pointer to fragment
e263cd49
DF
98 * @len: length of fragment
99 *
100 */
a51db580 101bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, void *base, size_t len);
e263cd49
DF
102
103/**
eb700029 104 * Fix ip header fields and calculate IP header and pseudo header checksums.
e263cd49
DF
105 *
106 * @pkt: packet
107 *
108 */
605d52e6 109void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt);
e263cd49 110
eb700029
DF
111/**
112 * Calculate the IP header checksum.
113 *
114 * @pkt: packet
115 *
116 */
117void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt);
118
f199b13b
AO
119/**
120 * Calculate the SCTP checksum.
121 *
122 * @pkt: packet
123 *
124 */
125bool net_tx_pkt_update_sctp_checksum(struct NetTxPkt *pkt);
126
e263cd49
DF
127/**
128 * get length of all populated data.
129 *
130 * @pkt: packet
131 * @ret: total data length
132 *
133 */
605d52e6 134size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt);
e263cd49
DF
135
136/**
137 * get packet type
138 *
139 * @pkt: packet
140 * @ret: packet type
141 *
142 */
605d52e6 143eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt);
e263cd49
DF
144
145/**
146 * prints packet data if debug is enabled
147 *
148 * @pkt: packet
149 *
150 */
605d52e6 151void net_tx_pkt_dump(struct NetTxPkt *pkt);
e263cd49
DF
152
153/**
154 * reset tx packet private context (needed to be called between packets)
155 *
156 * @pkt: packet
a51db580
AO
157 * @callback: function to free the fragments
158 * @context: pointer to be passed to the callback
e263cd49 159 */
a51db580
AO
160void net_tx_pkt_reset(struct NetTxPkt *pkt,
161 NetTxPktFreeFrag callback, void *context);
e263cd49 162
163246e1
AO
163/**
164 * Unmap a fragment mapped from a PCI device.
165 *
166 * @context: PCI device owning fragment
167 * @base: pointer to fragment
168 * @len: length of fragment
169 */
170void net_tx_pkt_unmap_frag_pci(void *context, void *base, size_t len);
171
a51db580
AO
172/**
173 * map data fragment from PCI device and populate it into pkt context.
174 *
175 * @pci_dev: PCI device owning fragment
176 * @pa: physical address of fragment
177 * @len: length of fragment
178 */
179bool net_tx_pkt_add_raw_fragment_pci(struct NetTxPkt *pkt, PCIDevice *pci_dev,
180 dma_addr_t pa, size_t len);
181
e263cd49
DF
182/**
183 * Send packet to qemu. handles sw offloads if vhdr is not supported.
184 *
185 * @pkt: packet
186 * @nc: NetClientState
187 * @ret: operation result
188 *
189 */
605d52e6 190bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc);
e263cd49 191
eb700029 192/**
ffbd2dbd
AO
193 * Send packet with a custom function.
194 *
195 * @pkt: packet
196 * @offload: whether the callback implements offloading
197 * @callback: a function to be called back for each transformed packet
198 * @context: a pointer to be passed to the callback.
199 * @ret: operation result
200 */
201bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
a51db580 202 NetTxPktSend callback, void *context);
eb700029 203
e263cd49
DF
204/**
205 * parse raw packet data and analyze offload requirements.
206 *
207 * @pkt: packet
208 *
209 */
605d52e6 210bool net_tx_pkt_parse(struct NetTxPkt *pkt);
e263cd49 211
eb700029
DF
212/**
213* indicates if there are data fragments held by this packet object.
214*
215* @pkt: packet
216*
217*/
218bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt);
219
e219d309
A
220/**
221 * Fix IPv6 'plen' field.
222 * If ipv6 payload length field is 0 - then there should be Hop-by-Hop
223 * option for packets greater than 65,535.
224 * For packets with a payload less than 65,535: fix 'plen' field.
225 * For backends with vheader, we need just one packet with proper
226 * payload size. For now, qemu drops every packet with size greater 64K
227 * (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6
228 * hop-by-hop extension if it's missed
229 *
230 * @pkt packet
231 */
232void net_tx_pkt_fix_ip6_payload_len(struct NetTxPkt *pkt);
233
e263cd49 234#endif