fw_cfg: follow CODING_STYLE
[qemu/ar7.git] / hw / net / net_tx_pkt.h
blob07b9a2098bfc72fd91e7a19cd90f3acf1402538d
1 /*
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)
8 * Authors:
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.
18 #ifndef NET_TX_PKT_H
19 #define NET_TX_PKT_H
21 #include "qemu/osdep.h"
22 #include "net/eth.h"
23 #include "exec/hwaddr.h"
25 /* define to enable packet dump functions */
26 /*#define NET_TX_PKT_DEBUG*/
28 struct NetTxPkt;
30 /**
31 * Init function for tx packet functionality
33 * @pkt: packet pointer
34 * @pci_dev: PCI device processing this packet
35 * @max_frags: max tx ip fragments
36 * @has_virt_hdr: device uses virtio header.
38 void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
39 uint32_t max_frags, bool has_virt_hdr);
41 /**
42 * Clean all tx packet resources.
44 * @pkt: packet.
46 void net_tx_pkt_uninit(struct NetTxPkt *pkt);
48 /**
49 * get virtio header
51 * @pkt: packet
52 * @ret: virtio header
54 struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt);
56 /**
57 * build virtio header (will be stored in module context)
59 * @pkt: packet
60 * @tso_enable: TSO enabled
61 * @csum_enable: CSO enabled
62 * @gso_size: MSS size for TSO
65 void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
66 bool csum_enable, uint32_t gso_size);
68 /**
69 * updates vlan tag, and adds vlan header with custom ethernet type
70 * in case it is missing.
72 * @pkt: packet
73 * @vlan: VLAN tag
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);
80 /**
81 * updates vlan tag, and adds vlan header in case it is missing
83 * @pkt: packet
84 * @vlan: VLAN tag
87 static inline void
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);
93 /**
94 * populate data fragment into pkt context.
96 * @pkt: packet
97 * @pa: physical address of fragment
98 * @len: length of fragment
101 bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
102 size_t len);
105 * Fix ip header fields and calculate IP header and pseudo header checksums.
107 * @pkt: packet
110 void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt);
113 * Calculate the IP header checksum.
115 * @pkt: packet
118 void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt);
121 * get length of all populated data.
123 * @pkt: packet
124 * @ret: total data length
127 size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt);
130 * get packet type
132 * @pkt: packet
133 * @ret: packet type
136 eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt);
139 * prints packet data if debug is enabled
141 * @pkt: packet
144 void net_tx_pkt_dump(struct NetTxPkt *pkt);
147 * reset tx packet private context (needed to be called between packets)
149 * @pkt: packet
152 void net_tx_pkt_reset(struct NetTxPkt *pkt);
155 * Send packet to qemu. handles sw offloads if vhdr is not supported.
157 * @pkt: packet
158 * @nc: NetClientState
159 * @ret: operation result
162 bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc);
165 * Redirect packet directly to receive path (emulate loopback phy).
166 * Handles sw offloads if vhdr is not supported.
168 * @pkt: packet
169 * @nc: NetClientState
170 * @ret: operation result
173 bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);
176 * parse raw packet data and analyze offload requirements.
178 * @pkt: packet
181 bool net_tx_pkt_parse(struct NetTxPkt *pkt);
184 * indicates if there are data fragments held by this packet object.
186 * @pkt: packet
189 bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt);
191 #endif