pm_smbus: rename variable to avoid shadowing
[qemu/kevin.git] / hw / net / net_rx_pkt.h
blob55ec67a1a7ba885eb43febb80a4f041ffe82ebb5
1 /*
2 * QEMU RX 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_RX_PKT_H
19 #define NET_RX_PKT_H
21 #include "net/eth.h"
23 /* defines to enable packet dump functions */
24 /*#define NET_RX_PKT_DEBUG*/
26 struct NetRxPkt;
28 /**
29 * Clean all rx packet resources
31 * @pkt: packet
34 void net_rx_pkt_uninit(struct NetRxPkt *pkt);
36 /**
37 * Init function for rx packet functionality
39 * @pkt: packet pointer
42 void net_rx_pkt_init(struct NetRxPkt **pkt);
44 /**
45 * returns total length of data attached to rx context
47 * @pkt: packet
49 * Return: nothing
52 size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt);
54 /**
55 * parse and set packet analysis results
57 * @pkt: packet
58 * @iov: received data scatter-gather list
59 * @iovcnt: number of elements in iov
60 * @iovoff: data start offset in the iov
63 void net_rx_pkt_set_protocols(struct NetRxPkt *pkt,
64 const struct iovec *iov, size_t iovcnt,
65 size_t iovoff);
67 /**
68 * fetches packet analysis results
70 * @pkt: packet
71 * @hasip4: whether the packet has an IPv4 header
72 * @hasip6: whether the packet has an IPv6 header
73 * @l4hdr_proto: protocol of L4 header
76 void net_rx_pkt_get_protocols(struct NetRxPkt *pkt,
77 bool *hasip4, bool *hasip6,
78 EthL4HdrProto *l4hdr_proto);
80 /**
81 * fetches L3 header offset
83 * @pkt: packet
86 size_t net_rx_pkt_get_l3_hdr_offset(struct NetRxPkt *pkt);
88 /**
89 * fetches L4 header offset
91 * @pkt: packet
94 size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt *pkt);
96 /**
97 * fetches L5 header offset
99 * @pkt: packet
102 size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt *pkt);
105 * fetches IP6 header analysis results
107 * Return: pointer to analysis results structure which is stored in internal
108 * packet area.
111 eth_ip6_hdr_info *net_rx_pkt_get_ip6_info(struct NetRxPkt *pkt);
114 * fetches IP4 header analysis results
116 * Return: pointer to analysis results structure which is stored in internal
117 * packet area.
120 eth_ip4_hdr_info *net_rx_pkt_get_ip4_info(struct NetRxPkt *pkt);
122 typedef enum {
123 NetPktRssIpV4,
124 NetPktRssIpV4Tcp,
125 NetPktRssIpV6Tcp,
126 NetPktRssIpV6,
127 NetPktRssIpV6Ex,
128 NetPktRssIpV6TcpEx,
129 NetPktRssIpV4Udp,
130 NetPktRssIpV6Udp,
131 NetPktRssIpV6UdpEx,
132 } NetRxPktRssType;
135 * calculates RSS hash for packet
137 * @pkt: packet
138 * @type: RSS hash type
140 * Return: Toeplitz RSS hash.
143 uint32_t
144 net_rx_pkt_calc_rss_hash(struct NetRxPkt *pkt,
145 NetRxPktRssType type,
146 uint8_t *key);
149 * fetches IP identification for the packet
151 * @pkt: packet
154 uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt *pkt);
157 * check if given packet is a TCP ACK packet
159 * @pkt: packet
162 bool net_rx_pkt_is_tcp_ack(struct NetRxPkt *pkt);
165 * check if given packet contains TCP data
167 * @pkt: packet
170 bool net_rx_pkt_has_tcp_data(struct NetRxPkt *pkt);
173 * returns virtio header stored in rx context
175 * @pkt: packet
176 * @ret: virtio header
179 struct virtio_net_hdr *net_rx_pkt_get_vhdr(struct NetRxPkt *pkt);
182 * returns packet type
184 * @pkt: packet
185 * @ret: packet type
188 eth_pkt_types_e net_rx_pkt_get_packet_type(struct NetRxPkt *pkt);
191 * returns vlan tag
193 * @pkt: packet
194 * @ret: VLAN tag
197 uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt *pkt);
200 * tells whether vlan was stripped from the packet
202 * @pkt: packet
203 * @ret: VLAN stripped sign
206 bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt);
209 * attach scatter-gather data to rx packet
211 * @pkt: packet
212 * @iov: received data scatter-gather list
213 * @iovcnt number of elements in iov
214 * @iovoff data start offset in the iov
215 * @strip_vlan: should the module strip vlan from data
218 void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt,
219 const struct iovec *iov,
220 int iovcnt, size_t iovoff,
221 bool strip_vlan);
224 * attach scatter-gather data to rx packet
226 * @pkt: packet
227 * @iov: received data scatter-gather list
228 * @iovcnt: number of elements in iov
229 * @iovoff: data start offset in the iov
230 * @strip_vlan_index: index of Q tag if it is to be stripped. negative otherwise.
231 * @vet: VLAN tag Ethernet type
232 * @vet_ext: outer VLAN tag Ethernet type
235 void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt,
236 const struct iovec *iov, int iovcnt,
237 size_t iovoff, int strip_vlan_index,
238 uint16_t vet, uint16_t vet_ext);
241 * attach data to rx packet
243 * @pkt: packet
244 * @data: pointer to the data buffer
245 * @len: data length
246 * @strip_vlan: should the module strip vlan from data
249 static inline void
250 net_rx_pkt_attach_data(struct NetRxPkt *pkt, const void *data,
251 size_t len, bool strip_vlan)
253 const struct iovec iov = {
254 .iov_base = (void *) data,
255 .iov_len = len
258 net_rx_pkt_attach_iovec(pkt, &iov, 1, 0, strip_vlan);
262 * returns io vector that holds the attached data
264 * @pkt: packet
265 * @ret: pointer to IOVec
268 struct iovec *net_rx_pkt_get_iovec(struct NetRxPkt *pkt);
271 * returns io vector length that holds the attached data
273 * @pkt: packet
274 * @ret: IOVec length
277 uint16_t net_rx_pkt_get_iovec_len(struct NetRxPkt *pkt);
280 * prints rx packet data if debug is enabled
282 * @pkt: packet
285 void net_rx_pkt_dump(struct NetRxPkt *pkt);
288 * copy passed vhdr data to packet context
290 * @pkt: packet
291 * @vhdr: VHDR buffer
294 void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt,
295 struct virtio_net_hdr *vhdr);
298 * copy passed vhdr data to packet context
300 * @pkt: packet
301 * @iov: VHDR iov
302 * @iovcnt: VHDR iov array size
305 void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt *pkt,
306 const struct iovec *iov, int iovcnt);
309 * unset vhdr data from packet context
311 * @pkt: packet
314 void net_rx_pkt_unset_vhdr(struct NetRxPkt *pkt);
317 * save packet type in packet context
319 * @pkt: packet
320 * @packet_type: the packet type
323 void net_rx_pkt_set_packet_type(struct NetRxPkt *pkt,
324 eth_pkt_types_e packet_type);
327 * validate TCP/UDP checksum of the packet
329 * @pkt: packet
330 * @csum_valid: checksum validation result
331 * @ret: true if validation was performed, false in case packet is
332 * not TCP/UDP or checksum validation is not possible
335 bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid);
338 * validate IPv4 checksum of the packet
340 * @pkt: packet
341 * @csum_valid: checksum validation result
342 * @ret: true if validation was performed, false in case packet is
343 * not TCP/UDP or checksum validation is not possible
346 bool net_rx_pkt_validate_l3_csum(struct NetRxPkt *pkt, bool *csum_valid);
349 * fix IPv4 checksum of the packet
351 * @pkt: packet
352 * @ret: true if checksum was fixed, false in case packet is
353 * not TCP/UDP or checksum correction is not possible
356 bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt);
358 #endif