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*/
30 * Init function for tx packet functionality
32 * @pkt: packet pointer
33 * @pci_dev: PCI device processing this packet
34 * @max_frags: max tx ip fragments
35 * @has_virt_hdr: device uses virtio header.
37 void net_tx_pkt_init(struct NetTxPkt
**pkt
, PCIDevice
*pci_dev
,
38 uint32_t max_frags
, bool has_virt_hdr
);
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
64 void net_tx_pkt_build_vheader(struct NetTxPkt
*pkt
, bool tso_enable
,
65 bool csum_enable
, uint32_t gso_size
);
68 * updates vlan tag, and adds vlan header with custom ethernet type
69 * in case it is missing.
73 * @vlan_ethtype: VLAN header Ethernet type
76 void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt
*pkt
,
77 uint16_t vlan
, uint16_t vlan_ethtype
);
80 * updates vlan tag, and adds vlan header in case it is missing
87 net_tx_pkt_setup_vlan_header(struct NetTxPkt
*pkt
, uint16_t vlan
)
89 net_tx_pkt_setup_vlan_header_ex(pkt
, vlan
, ETH_P_VLAN
);
93 * populate data fragment into pkt context.
96 * @pa: physical address of fragment
97 * @len: length of fragment
100 bool net_tx_pkt_add_raw_fragment(struct NetTxPkt
*pkt
, hwaddr pa
,
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)
151 void net_tx_pkt_reset(struct NetTxPkt
*pkt
);
154 * Send packet to qemu. handles sw offloads if vhdr is not supported.
157 * @nc: NetClientState
158 * @ret: operation result
161 bool net_tx_pkt_send(struct NetTxPkt
*pkt
, NetClientState
*nc
);
164 * Redirect packet directly to receive path (emulate loopback phy).
165 * Handles sw offloads if vhdr is not supported.
168 * @nc: NetClientState
169 * @ret: operation result
172 bool net_tx_pkt_send_loopback(struct NetTxPkt
*pkt
, NetClientState
*nc
);
175 * parse raw packet data and analyze offload requirements.
180 bool net_tx_pkt_parse(struct NetTxPkt
*pkt
);
183 * indicates if there are data fragments held by this packet object.
188 bool net_tx_pkt_has_fragments(struct NetTxPkt
*pkt
);