2 * QEMU TX packets abstraction
4 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
6 * Developed by Daynix Computing LTD (http://www.daynix.com)
9 * Dmitry Fleytman <dmitry@daynix.com>
10 * Tamir Shomer <tamirs@daynix.com>
11 * Yan Vugenfirer <yan@daynix.com>
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.
22 #include "exec/hwaddr.h"
24 /* define to enable packet dump functions */
25 /*#define NET_TX_PKT_DEBUG*/
29 typedef void (*NetTxPktFreeFrag
)(void *, void *, size_t);
30 typedef void (*NetTxPktSend
)(void *, const struct iovec
*, int, const struct iovec
*, int);
33 * Init function for tx packet functionality
35 * @pkt: packet pointer
36 * @max_frags: max tx ip fragments
38 void net_tx_pkt_init(struct NetTxPkt
**pkt
, uint32_t max_frags
);
41 * Clean all tx packet resources.
45 void net_tx_pkt_uninit(struct NetTxPkt
*pkt
);
53 struct virtio_net_hdr
*net_tx_pkt_get_vhdr(struct NetTxPkt
*pkt
);
56 * build virtio header (will be stored in module context)
59 * @tso_enable: TSO enabled
60 * @csum_enable: CSO enabled
61 * @gso_size: MSS size for TSO
62 * @ret: operation result
65 bool net_tx_pkt_build_vheader(struct NetTxPkt
*pkt
, bool tso_enable
,
66 bool csum_enable
, uint32_t gso_size
);
69 * updates vlan tag, and adds vlan header with custom ethernet type
70 * in case it is missing.
74 * @vlan_ethtype: VLAN header Ethernet type
77 void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt
*pkt
,
78 uint16_t vlan
, uint16_t vlan_ethtype
);
81 * updates vlan tag, and adds vlan header in case it is missing
88 net_tx_pkt_setup_vlan_header(struct NetTxPkt
*pkt
, uint16_t vlan
)
90 net_tx_pkt_setup_vlan_header_ex(pkt
, vlan
, ETH_P_VLAN
);
94 * populate data fragment into pkt context.
97 * @base: pointer to fragment
98 * @len: length of fragment
101 bool net_tx_pkt_add_raw_fragment(struct NetTxPkt
*pkt
, void *base
, size_t len
);
104 * Fix ip header fields and calculate IP header and pseudo header checksums.
109 void net_tx_pkt_update_ip_checksums(struct NetTxPkt
*pkt
);
112 * Calculate the IP header checksum.
117 void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt
*pkt
);
120 * get length of all populated data.
123 * @ret: total data length
126 size_t net_tx_pkt_get_total_len(struct NetTxPkt
*pkt
);
135 eth_pkt_types_e
net_tx_pkt_get_packet_type(struct NetTxPkt
*pkt
);
138 * prints packet data if debug is enabled
143 void net_tx_pkt_dump(struct NetTxPkt
*pkt
);
146 * reset tx packet private context (needed to be called between packets)
149 * @callback: function to free the fragments
150 * @context: pointer to be passed to the callback
152 void net_tx_pkt_reset(struct NetTxPkt
*pkt
,
153 NetTxPktFreeFrag callback
, void *context
);
156 * Unmap a fragment mapped from a PCI device.
158 * @context: PCI device owning fragment
159 * @base: pointer to fragment
160 * @len: length of fragment
162 void net_tx_pkt_unmap_frag_pci(void *context
, void *base
, size_t len
);
165 * map data fragment from PCI device and populate it into pkt context.
167 * @pci_dev: PCI device owning fragment
168 * @pa: physical address of fragment
169 * @len: length of fragment
171 bool net_tx_pkt_add_raw_fragment_pci(struct NetTxPkt
*pkt
, PCIDevice
*pci_dev
,
172 dma_addr_t pa
, size_t len
);
175 * Send packet to qemu. handles sw offloads if vhdr is not supported.
178 * @nc: NetClientState
179 * @ret: operation result
182 bool net_tx_pkt_send(struct NetTxPkt
*pkt
, NetClientState
*nc
);
185 * Send packet with a custom function.
188 * @offload: whether the callback implements offloading
189 * @callback: a function to be called back for each transformed packet
190 * @context: a pointer to be passed to the callback.
191 * @ret: operation result
193 bool net_tx_pkt_send_custom(struct NetTxPkt
*pkt
, bool offload
,
194 NetTxPktSend callback
, void *context
);
197 * parse raw packet data and analyze offload requirements.
202 bool net_tx_pkt_parse(struct NetTxPkt
*pkt
);
205 * indicates if there are data fragments held by this packet object.
210 bool net_tx_pkt_has_fragments(struct NetTxPkt
*pkt
);
213 * Fix IPv6 'plen' field.
214 * If ipv6 payload length field is 0 - then there should be Hop-by-Hop
215 * option for packets greater than 65,535.
216 * For packets with a payload less than 65,535: fix 'plen' field.
217 * For backends with vheader, we need just one packet with proper
218 * payload size. For now, qemu drops every packet with size greater 64K
219 * (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6
220 * hop-by-hop extension if it's missed
224 void net_tx_pkt_fix_ip6_payload_len(struct NetTxPkt
*pkt
);