]>
Commit | Line | Data |
---|---|---|
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 <[email protected]> | |
10 | * Tamir Shomer <[email protected]> | |
11 | * Yan Vugenfirer <[email protected]> | |
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 | 27 | struct NetTxPkt; |
e263cd49 DF |
28 | |
29 | /** | |
30 | * Init function for tx packet functionality | |
31 | * | |
32 | * @pkt: packet pointer | |
11171010 | 33 | * @pci_dev: PCI device processing this packet |
e263cd49 DF |
34 | * @max_frags: max tx ip fragments |
35 | * @has_virt_hdr: device uses virtio header. | |
36 | */ | |
11171010 DF |
37 | void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev, |
38 | uint32_t max_frags, bool has_virt_hdr); | |
e263cd49 DF |
39 | |
40 | /** | |
41 | * Clean all tx packet resources. | |
42 | * | |
43 | * @pkt: packet. | |
44 | */ | |
605d52e6 | 45 | void 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 | 53 | struct 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 | |
62 | * | |
63 | */ | |
605d52e6 | 64 | void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable, |
e263cd49 DF |
65 | bool csum_enable, uint32_t gso_size); |
66 | ||
67 | /** | |
eb700029 DF |
68 | * updates vlan tag, and adds vlan header with custom ethernet type |
69 | * in case it is missing. | |
70 | * | |
71 | * @pkt: packet | |
72 | * @vlan: VLAN tag | |
73 | * @vlan_ethtype: VLAN header Ethernet type | |
74 | * | |
75 | */ | |
76 | void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt, | |
77 | uint16_t vlan, uint16_t vlan_ethtype); | |
78 | ||
79 | /** | |
80 | * updates vlan tag, and adds vlan header in case it is missing | |
81 | * | |
82 | * @pkt: packet | |
83 | * @vlan: VLAN tag | |
84 | * | |
85 | */ | |
86 | static inline void | |
87 | net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan) | |
88 | { | |
89 | net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN); | |
90 | } | |
e263cd49 DF |
91 | |
92 | /** | |
93 | * populate data fragment into pkt context. | |
94 | * | |
95 | * @pkt: packet | |
96 | * @pa: physical address of fragment | |
97 | * @len: length of fragment | |
98 | * | |
99 | */ | |
605d52e6 | 100 | bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, |
e263cd49 DF |
101 | size_t len); |
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 | 109 | void 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 | */ | |
117 | void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt); | |
118 | ||
e263cd49 DF |
119 | /** |
120 | * get length of all populated data. | |
121 | * | |
122 | * @pkt: packet | |
123 | * @ret: total data length | |
124 | * | |
125 | */ | |
605d52e6 | 126 | size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt); |
e263cd49 DF |
127 | |
128 | /** | |
129 | * get packet type | |
130 | * | |
131 | * @pkt: packet | |
132 | * @ret: packet type | |
133 | * | |
134 | */ | |
605d52e6 | 135 | eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt); |
e263cd49 DF |
136 | |
137 | /** | |
138 | * prints packet data if debug is enabled | |
139 | * | |
140 | * @pkt: packet | |
141 | * | |
142 | */ | |
605d52e6 | 143 | void net_tx_pkt_dump(struct NetTxPkt *pkt); |
e263cd49 DF |
144 | |
145 | /** | |
146 | * reset tx packet private context (needed to be called between packets) | |
147 | * | |
148 | * @pkt: packet | |
149 | * | |
150 | */ | |
605d52e6 | 151 | void net_tx_pkt_reset(struct NetTxPkt *pkt); |
e263cd49 DF |
152 | |
153 | /** | |
154 | * Send packet to qemu. handles sw offloads if vhdr is not supported. | |
155 | * | |
156 | * @pkt: packet | |
157 | * @nc: NetClientState | |
158 | * @ret: operation result | |
159 | * | |
160 | */ | |
605d52e6 | 161 | bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc); |
e263cd49 | 162 | |
eb700029 DF |
163 | /** |
164 | * Redirect packet directly to receive path (emulate loopback phy). | |
165 | * Handles sw offloads if vhdr is not supported. | |
166 | * | |
167 | * @pkt: packet | |
168 | * @nc: NetClientState | |
169 | * @ret: operation result | |
170 | * | |
171 | */ | |
172 | bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc); | |
173 | ||
e263cd49 DF |
174 | /** |
175 | * parse raw packet data and analyze offload requirements. | |
176 | * | |
177 | * @pkt: packet | |
178 | * | |
179 | */ | |
605d52e6 | 180 | bool net_tx_pkt_parse(struct NetTxPkt *pkt); |
e263cd49 | 181 | |
eb700029 DF |
182 | /** |
183 | * indicates if there are data fragments held by this packet object. | |
184 | * | |
185 | * @pkt: packet | |
186 | * | |
187 | */ | |
188 | bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt); | |
189 | ||
e263cd49 | 190 | #endif |