| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  |  * QEMU TX packets abstraction | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Developed by Daynix Computing LTD (http://www.daynix.com)
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: | 
					
						
							|  |  |  |  * Dmitry Fleytman <dmitry@daynix.com> | 
					
						
							|  |  |  |  * Tamir Shomer <tamirs@daynix.com> | 
					
						
							|  |  |  |  * Yan Vugenfirer <yan@daynix.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is licensed under the terms of the GNU GPL, version 2 or later. | 
					
						
							|  |  |  |  * See the COPYING file in the top-level directory. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | #ifndef NET_TX_PKT_H
 | 
					
						
							|  |  |  | #define NET_TX_PKT_H
 | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "net/eth.h"
 | 
					
						
							|  |  |  | #include "exec/hwaddr.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* define to enable packet dump functions */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | /*#define NET_TX_PKT_DEBUG*/ | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | struct NetTxPkt; | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Init function for tx packet functionality | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet pointer | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:42 +03:00
										 |  |  |  * @pci_dev:        PCI device processing this packet | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  |  * @max_frags:      max tx ip fragments | 
					
						
							|  |  |  |  * @has_virt_hdr:   device uses virtio header. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:42 +03:00
										 |  |  | void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev, | 
					
						
							|  |  |  |     uint32_t max_frags, bool has_virt_hdr); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Clean all tx packet resources. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | void net_tx_pkt_uninit(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * get virtio header | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @ret:            virtio header | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * build virtio header (will be stored in module context) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @tso_enable:     TSO enabled | 
					
						
							|  |  |  |  * @csum_enable:    CSO enabled | 
					
						
							|  |  |  |  * @gso_size:       MSS size for TSO | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable, | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  |     bool csum_enable, uint32_t gso_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:41 +03:00
										 |  |  | * updates vlan tag, and adds vlan header with custom ethernet type | 
					
						
							|  |  |  | * in case it is missing. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @pkt:            packet | 
					
						
							|  |  |  | * @vlan:           VLAN tag | 
					
						
							|  |  |  | * @vlan_ethtype:   VLAN header Ethernet type | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt, | 
					
						
							|  |  |  |     uint16_t vlan, uint16_t vlan_ethtype); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | * updates vlan tag, and adds vlan header in case it is missing | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @pkt:            packet | 
					
						
							|  |  |  | * @vlan:           VLAN tag | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static inline void | 
					
						
							|  |  |  | net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * populate data fragment into pkt context. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @pa:             physical address of fragment | 
					
						
							|  |  |  |  * @len:            length of fragment | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  |     size_t len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:41 +03:00
										 |  |  |  * Fix ip header fields and calculate IP header and pseudo header checksums. | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:41 +03:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Calculate the IP header checksum. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * get length of all populated data. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @ret:            total data length | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * get packet type | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @ret:            packet type | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * prints packet data if debug is enabled | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | void net_tx_pkt_dump(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * reset tx packet private context (needed to be called between packets) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | void net_tx_pkt_reset(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Send packet to qemu. handles sw offloads if vhdr is not supported. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * @nc:             NetClientState | 
					
						
							|  |  |  |  * @ret:            operation result | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:41 +03:00
										 |  |  | /**
 | 
					
						
							|  |  |  | * Redirect packet directly to receive path (emulate loopback phy). | 
					
						
							|  |  |  | * Handles sw offloads if vhdr is not supported. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @pkt:            packet | 
					
						
							|  |  |  | * @nc:             NetClientState | 
					
						
							|  |  |  | * @ret:            operation result | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * parse raw packet data and analyze offload requirements. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt:            packet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:39 +03:00
										 |  |  | bool net_tx_pkt_parse(struct NetTxPkt *pkt); | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:41 +03:00
										 |  |  | /**
 | 
					
						
							|  |  |  | * indicates if there are data fragments held by this packet object. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @pkt:            packet | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-16 06:53:24 +03:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Fix IPv6 'plen' field. | 
					
						
							|  |  |  |  * If ipv6 payload length field is 0 - then there should be Hop-by-Hop | 
					
						
							|  |  |  |  * option for packets greater than 65,535. | 
					
						
							|  |  |  |  * For packets with a payload less than 65,535: fix 'plen' field. | 
					
						
							|  |  |  |  * For backends with vheader, we need just one packet with proper | 
					
						
							|  |  |  |  * payload size. For now, qemu drops every packet with size greater 64K | 
					
						
							|  |  |  |  * (see net_tx_pkt_send()) so, there is no reason to add jumbo option to ip6 | 
					
						
							|  |  |  |  * hop-by-hop extension if it's missed | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @pkt            packet | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void net_tx_pkt_fix_ip6_payload_len(struct NetTxPkt *pkt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-09 11:21:05 +02:00
										 |  |  | #endif
 |