Signed-off-by: Dmitry Fleytman <dmi...@daynix.com> Signed-off-by: Yan Vugenfirer <y...@daynix.com> --- hw/vmxnet_pkt.c | 1243 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/vmxnet_pkt.h | 479 +++++++++++++++++++++ 2 files changed, 1722 insertions(+), 0 deletions(-) create mode 100644 hw/vmxnet_pkt.c create mode 100644 hw/vmxnet_pkt.h
diff --git a/hw/vmxnet_pkt.c b/hw/vmxnet_pkt.c new file mode 100644 index 0000000..5fe2672 --- /dev/null +++ b/hw/vmxnet_pkt.c @@ -0,0 +1,1243 @@ +/* + * QEMU VMWARE VMXNET* paravirtual NICs - packets abstractions + * + * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com) + * + * Developed by Daynix Computing LTD (http://www.daynix.com) + * + * Authors: + * Dmitry Fleytman <dmi...@daynix.com> + * Tamir Shomer <tam...@daynix.com> + * Yan Vugenfirer <y...@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. + * + */ + +#include "vmxnet_pkt.h" +#include "vmxnet_utils.h" +#include "iov.h" + +#include "net/checksum.h" + +/*============================================================================= + *============================================================================= + * + * TX CODE + * + *============================================================================= + *===========================================================================*/ + +enum { + VMXNET_TX_PKT_VHDR_FRAG = 0, + VMXNET_TX_PKT_L2HDR_FRAG, + VMXNET_TX_PKT_L3HDR_FRAG, + VMXNET_TX_PKT_PL_START_FRAG +}; + +/* TX packet private context */ +typedef struct _Vmxnet_TxPkt { + struct virtio_net_hdr virt_hdr; + bool has_virt_hdr; + + struct iovec *vec; + + uint8_t l2_hdr[ETH_MAX_L2_HDR_LEN]; + uint8_t l3_hdr[ETH_MAX_L3_HDR_LEN]; + + uint32_t payload_len; + + uint32_t payload_frags; + uint32_t max_payload_frags; + + uint16_t hdr_len; + eth_pkt_types_e packet_type; + uint16_t l3_proto; +} Vmxnet_TxPkt; + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_init + * + * Desc: Init function for tx packet functionality. + * + * Params: (OUT) pkt - private handle. + * (IN) max_frags - max tx ip fragments. + * (IN) has_virt_hdr - device uses virtio header. + * + * Return: 0 on success, -1 on error + * + * Scope: Global + * + *****************************************************************************/ +int vmxnet_tx_pkt_init(Vmxnet_TxPkt_h *pkt, uint32_t max_frags, + bool has_virt_hdr) +{ + int rc = 0; + + Vmxnet_TxPkt *p = g_malloc(sizeof *p); + if (!p) { + rc = -1; + goto Exit; + } + + memset(p, 0, sizeof *p); + + p->vec = g_malloc((sizeof *p->vec) * + (max_frags + VMXNET_TX_PKT_PL_START_FRAG)); + if (!p->vec) { + rc = -1; + goto Exit; + } + + p->max_payload_frags = max_frags; + p->has_virt_hdr = has_virt_hdr; + p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_base = &p->virt_hdr; + p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_len = + p->has_virt_hdr ? sizeof p->virt_hdr : 0; + p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base = &p->l2_hdr; + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base = &p->l3_hdr; + + *pkt = p; + +Exit: + if (rc) { + vmxnet_tx_pkt_uninit(p); + } + return rc; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_uninit + * + * Desc: Clean all tx packet resources. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_uninit(Vmxnet_TxPkt_h pkt) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + + if (p) { + if (p->vec) { + g_free(p->vec); + } + + g_free(p); + } +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_update_ip_checksums + * + * Desc: fix ip header fields and calculate checksums needed. + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_update_ip_checksums(Vmxnet_TxPkt_h pkt) +{ + uint16_t csum; + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + uint8_t gso_type = p->virt_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN; + struct ip_header *ip_hdr; + target_phys_addr_t payload = (target_phys_addr_t) + (uint64_t) p->vec[VMXNET_TX_PKT_PL_START_FRAG].iov_base; + + if (VIRTIO_NET_HDR_GSO_TCPV4 != gso_type && + VIRTIO_NET_HDR_GSO_UDP != gso_type) { + return; + } + + ip_hdr = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + + if (p->payload_len + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len > + ETH_MAX_IP_DGRAM_LEN) { + return; + } + + ip_hdr->ip_len = cpu_to_be16(p->payload_len + + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len); + + /* Calculate IP header checksum */ + ip_hdr->ip_sum = 0; + csum = net_raw_checksum((uint8_t *)ip_hdr, + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len); + ip_hdr->ip_sum = cpu_to_be16(csum); + + /* Calculate IP pseudo header checksum */ + csum = cpu_to_be16(eth_calc_pseudo_hdr_csum(ip_hdr, p->payload_len)); + cpu_physical_memory_write(payload + p->virt_hdr.csum_offset, + &csum, sizeof(csum)); +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_l4_proto + * + * Desc: get l4 protocol. + * + * Params: (IN) p - module context + * + * Return: l4 protocol + * + * Scope: Local + * + *****************************************************************************/ +static uint8_t vmxnet_tx_pkt_get_l4_proto(Vmxnet_TxPkt *p) +{ + struct ip_header *ip_hdr; + struct ip6_header *ip6_hdr; + + if (!p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len) { + return 0; + } + + if (ETH_P_IP == p->l3_proto) { + ip_hdr = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + return ip_hdr->ip_p; + } else if (p->l3_proto == ETH_P_IPV6) { + ip6_hdr = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + return ip6_hdr->ip6_nxt; + } + + return 0; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_calculate_hdr_len + * + * Desc: store l2 and l3 headers length. + * + * Params: (IN) p - module context + * + * Return: nothing + * + * Scope: Local + * + *****************************************************************************/ +static void vmxnet_tx_pkt_calculate_hdr_len(Vmxnet_TxPkt *p) +{ + p->hdr_len = p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len + + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_prepare + * + * Desc: populates headers and parses them to gether some metadata for later + * use. + * + * Params: (IN) pkt - private handle. + * (IN) pa - physical address of tx data + * (IN) len - length of data + * + * Return: number of bytes populated by the function. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_prepare(Vmxnet_TxPkt_h pkt, target_phys_addr_t pa, + size_t len) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + /* some pointers that my lines stay nice and short. */ + void *l2_iov_base = NULL, *l3_iov_base = NULL; + size_t *l2_iov_len = NULL, *l3_iov_len = NULL; + assert(p); + + l2_iov_base = p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base; + l2_iov_len = &p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len; + l3_iov_base = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + l3_iov_len = &p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len; + + cpu_physical_memory_read(pa, l2_iov_base, ETH_MAX_L2_HDR_LEN); + + *l2_iov_len = eth_get_l2_hdr_length(l2_iov_base); + + p->l3_proto = eth_get_l3_proto(l2_iov_base, *l2_iov_len); + + switch (p->l3_proto) { + case ETH_P_IP: + assert(len >= *l2_iov_len + sizeof(struct ip_header)); + + cpu_physical_memory_read(pa + *l2_iov_len, l3_iov_base, + sizeof(struct ip_header)); + *l3_iov_len = IP_HDR_GET_LEN(l3_iov_base); + + /* handle optional header data */ + if (*l3_iov_len > sizeof(struct ip_header)) { + cpu_physical_memory_read( + pa + *l2_iov_len + sizeof(struct ip_header), + l3_iov_base + sizeof(struct ip_header), + *l3_iov_len - sizeof(struct ip_header)); + } + break; + + case ETH_P_IPV6: + *l3_iov_len = sizeof(struct ip6_header); + if (len < *l2_iov_len + *l3_iov_len) { + /* + * no ipv6 header in this buffer. can happen in vmxnet, + * when zero copy is enabled + */ + *l3_iov_len = 0; + break; + } + cpu_physical_memory_read(pa + *l2_iov_len, l3_iov_base, *l3_iov_len); + break; + + default: + *l3_iov_len = 0; + break; + } + + vmxnet_tx_pkt_calculate_hdr_len(p); + p->packet_type = get_eth_packet_type(l2_iov_base); + + /* Return amount of data populated into vec */ + return *l2_iov_len + *l3_iov_len; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_vhdr + * + * Desc: get virtio header. + * + * Params: (IN) pkt - private handle. + * + * Return: virtio header + * + * Scope: Global + * + *****************************************************************************/ +struct virtio_net_hdr *vmxnet_tx_pkt_get_vhdr(Vmxnet_TxPkt_h pkt) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + return &p->virt_hdr; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_gso_type + * + * Desc: calculate gso type. + * + * Params: (IN) pkt - private handle. + * (IN) tso_enable + * + * Return: gso type. + * + * Scope: Local + * + *****************************************************************************/ +static uint8_t vmxnet_tx_pkt_get_gso_type(Vmxnet_TxPkt *p, bool tso_enable) +{ + uint8_t rc = VIRTIO_NET_HDR_GSO_NONE; + uint16_t l3_proto; + + l3_proto = eth_get_l3_proto(p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base, + p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len); + + if (!tso_enable) { + goto Exit; + } + + rc = eth_get_gso_type(l3_proto, p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base); + +Exit: + return rc; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_build_vheader + * + * Desc: build virtio header. (will be stored in module context) + * + * Params: (IN) pkt - private handle. + * (IN) tso_enable + * (IN) csum_enable (has to be enabled if tso_enable is true) + * (IN) gso_size - (relevent only if tso enabled) + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_build_vheader(Vmxnet_TxPkt_h pkt, bool tso_enable, + bool csum_enable, uint32_t gso_size) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + struct tcp_hdr l4hdr; + target_phys_addr_t l4hdr_pa; + assert(p); + + /* csum has to be enabled if tso is. */ + assert(csum_enable || !tso_enable); + + p->virt_hdr.gso_type = vmxnet_tx_pkt_get_gso_type(p, tso_enable); + + switch (p->virt_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { + case VIRTIO_NET_HDR_GSO_NONE: + p->virt_hdr.hdr_len = 0; + p->virt_hdr.gso_size = 0; + break; + + case VIRTIO_NET_HDR_GSO_UDP: + p->virt_hdr.gso_size = IP_FRAG_ALIGN_SIZE(gso_size); + p->virt_hdr.hdr_len = p->hdr_len + sizeof(struct udp_header); + break; + + case VIRTIO_NET_HDR_GSO_TCPV4: + case VIRTIO_NET_HDR_GSO_TCPV6: + l4hdr_pa = (target_phys_addr_t) + (uint64_t) p->vec[VMXNET_TX_PKT_PL_START_FRAG].iov_base; + cpu_physical_memory_read(l4hdr_pa, &l4hdr, sizeof(l4hdr)); + p->virt_hdr.hdr_len = p->hdr_len + l4hdr.th_off * sizeof(uint32_t); + p->virt_hdr.gso_size = IP_FRAG_ALIGN_SIZE(gso_size); + break; + + default: + assert(false); + } + + if (csum_enable) { + p->virt_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; + + p->virt_hdr.csum_start = p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len + + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len; + switch (vmxnet_tx_pkt_get_l4_proto(p)) { + case IP_PROTO_TCP: + p->virt_hdr.csum_offset = offsetof(struct tcp_hdr, th_sum); + break; + case IP_PROTO_UDP: + p->virt_hdr.csum_offset = offsetof(struct udp_hdr, uh_sum); + break; + default: + assert(false); + break; + } + } +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_setup_vlan_header + * + * Desc: updates vlan tag, and adds vlan header in case it is missing. + * + * Params: (IN) pkt - private handle. + * (IN) vlan + * + * Return: Nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_setup_vlan_header(Vmxnet_TxPkt_h pkt, uint16_t vlan) +{ + bool is_new; + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + + eth_setup_vlan_headers(p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base, + vlan, &is_new); + + /* update l2hdrlen */ + if (is_new) { + p->hdr_len += sizeof(struct vlan_header); + p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len += sizeof(struct vlan_header); + } +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_add_fragment + * + * Desc: populate fragment into pkt context. + * + * Params: (IN) pkt - private handle. + * (IN) pa - physical address of fragment + * (IN) len - length of fragment + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_add_fragment(Vmxnet_TxPkt_h pkt, target_phys_addr_t pa, + size_t len) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + int abs_frag_num = p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG; + assert(p); + + if (!len) { + return; + } + + assert(p->max_payload_frags > p->payload_frags); + + p->vec[abs_frag_num].iov_base = (void *) (uint64_t) pa; + p->vec[abs_frag_num].iov_len = len; + p->payload_frags++; + p->payload_len += len; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_packet_type + * + * Desc: returns packet type + * + * Params: (IN) pkt - private handle. + * + * Return: packet type. + * + * Scope: Global + * + *****************************************************************************/ +eth_pkt_types_e vmxnet_tx_pkt_get_packet_type(Vmxnet_TxPkt_h pkt) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + + return p->packet_type; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_total_len + * + * Desc: Returns the length of all populated data. + * + * Params: (IN) pkt - private handle. + * + * Return: length of populated data. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_get_total_len(Vmxnet_TxPkt_h pkt) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + + return p->hdr_len + p->payload_len; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_unmap + * + * Desc: unmap all populated headers and fragments from iovec. + * + * Params: (IN) p - private context. + * + * Return: Nothing. + * + * Scope: Local + * + *****************************************************************************/ +static void vmxnet_tx_pkt_unmap(Vmxnet_TxPkt *p) +{ + int i; + + for (i = VMXNET_TX_PKT_PL_START_FRAG; + i < p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG; i++) { + cpu_physical_memory_unmap(p->vec[i].iov_base, p->vec[i].iov_len, + false, p->vec[i].iov_len); + } +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_map + * + * Desc: map all populated headers and fragments into iovec. + * + * Params: (IN) p - private context. + * (OUT) mapped_fragments - length of iovec. + * + * Return: iovec head. NULL on error. + * + * Scope: local + * + *****************************************************************************/ +static void *vmxnet_tx_pkt_map(Vmxnet_TxPkt *p, uint32_t *mapped_fragments) +{ + int i; + + for (i = VMXNET_TX_PKT_PL_START_FRAG; + i < p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG; i++) { + target_phys_addr_t mapped_len = p->vec[i].iov_len; + size_t orig_len = p->vec[i].iov_len; + p->vec[i].iov_base = + cpu_physical_memory_map((target_phys_addr_t) (uint64_t) + p->vec[i].iov_base, &mapped_len, false); + p->vec[i].iov_len = mapped_len; + + if ((NULL == p->vec[i].iov_base) || (orig_len != mapped_len)) { + p->payload_frags = i + !!p->vec[i].iov_base; + vmxnet_tx_pkt_unmap(p); + return NULL; + } + } + + *mapped_fragments = p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG; + return p->vec; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_dump + * + * Desc: Prints packet data if debug is enabled + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_dump(Vmxnet_TxPkt_h pkt) +{ +#ifdef VMXNET_TX_PKT_DEBUG + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + + printf("TX PKT: hdr_len: %d, pkt_type: 0x%X, l2hdr_len: %lu, " + "l3hdr_len: %lu, payload_len: %u\n", p->hdr_len, p->packet_type, + p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len, + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len, p->payload_len); +#endif +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_reset + * + * Desc: reset tx packet private context. (needed to be called between packets) + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_reset(Vmxnet_TxPkt_h pkt) +{ + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + int i; + + /* no assert, as reset can be called before tx_pkt_init */ + if (!p) { + return; + } + + memset(&p->virt_hdr, 0, sizeof(p->virt_hdr)); + + assert(p->vec); + for (i = VMXNET_TX_PKT_L2HDR_FRAG; i < p->max_payload_frags; i++) { + p->vec[i].iov_len = 0; + } + + p->payload_len = 0; + p->payload_frags = 0; + p->hdr_len = 0; + p->packet_type = 0; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_do_sw_csum + * + * Desc: Calculate l4 csum and put it in hdr. + * + * Params: (IN) p - private handle. + * + * Return: nothing. + * + * Scope: Local + * + *****************************************************************************/ +static void vmxnet_tx_pkt_do_sw_csum(Vmxnet_TxPkt *p) +{ + struct iovec *iov = &p->vec[VMXNET_TX_PKT_L2HDR_FRAG]; + uint32_t csum_cntr; + uint16_t csum = 0; + /* num of iovec without vhdr */ + uint32_t iov_len = p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG - 1; + uint16_t csl; + struct ip_header *iphdr; + size_t csum_offset = p->virt_hdr.csum_start + p->virt_hdr.csum_offset; + + /* Put zero to checksum field */ + iov_from_buf(iov, iov_len, &csum, csum_offset, sizeof csum); + + /* Calculate L4 TCP/UDP checksum */ + csl = p->payload_len; + + /* data checksum */ + csum_cntr = iov_net_csum_add(iov, iov_len, p->virt_hdr.csum_start, csl); + /* add pseudo header to csum */ + iphdr = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + csum_cntr += eth_calc_pseudo_hdr_csum(iphdr, csl); + + /* Put the checksum obtained into the packet */ + csum = cpu_to_be16(net_checksum_finish(csum_cntr)); + iov_from_buf(iov, iov_len, &csum, csum_offset, sizeof csum); +} + +enum { + VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS = 0, + VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS, + VMXNET_TX_PKT_FRAGMENT_HEADER_NUM +}; + +#define VMXNET_MAX_FRAG_SG_LIST (64) + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_fetch_fragment + * + * Desc: Copy data from packet to fragment iov. + * + * Params: (IN) p - private context. + * (IN/OUT) src_idx - current index in packet iov + * (IN/OUT) src_offset - current offset in iov member + * (OUT) dst - fragment iov + * (OUT) dst_idx - the used length of the fragment iov + * (+1 as this is an index) + * + * Return: number of bytes sent. + * + * Scope: Local + * + *****************************************************************************/ +static size_t vmxnet_tx_pkt_fetch_fragment(Vmxnet_TxPkt *p, int *src_idx, + size_t *src_offset, struct iovec *dst, int *dst_idx) +{ + size_t fetched = 0; + struct iovec *src = p->vec; + + *dst_idx = VMXNET_TX_PKT_FRAGMENT_HEADER_NUM; + + while (fetched < p->virt_hdr.gso_size) { + + /* no more place in fragment iov */ + if (*dst_idx == VMXNET_MAX_FRAG_SG_LIST) { + break; + } + + /* no more data in iovec */ + if (*src_idx == (p->payload_frags + VMXNET_TX_PKT_PL_START_FRAG)) { + break; + } + + + dst[*dst_idx].iov_base = src[*src_idx].iov_base + *src_offset; + dst[*dst_idx].iov_len = MIN(src[*src_idx].iov_len - *src_offset, + p->virt_hdr.gso_size - fetched); + + *src_offset += dst[*dst_idx].iov_len; + fetched += dst[*dst_idx].iov_len; + + if (*src_offset == src[*src_idx].iov_len) { + *src_offset = 0; + (*src_idx)++; + } + + (*dst_idx)++; + } + + return fetched; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_do_sw_fragmentation + * + * Desc: Preformes softwere fragmentation of the packet and sends in to qemu + * + * Params: (IN) p - private context. + * (IN) vc - VLANClientState. + * + * Return: number of bytes sent. + * + * Scope: Local + * + *****************************************************************************/ +static size_t vmxnet_tx_pkt_do_sw_fragmentation(Vmxnet_TxPkt *p, + VLANClientState *vc) +{ + struct iovec fragment[VMXNET_MAX_FRAG_SG_LIST]; + size_t fragment_len = 0; + bool more_frags = false; + /* some poiners for shorter code */ + void *l2_iov_base, *l3_iov_base; + size_t l2_iov_len, l3_iov_len; + int src_idx = VMXNET_TX_PKT_PL_START_FRAG, dst_idx; + size_t src_offset = 0; + size_t bytes_sent = 0; + size_t fragment_offset = 0; + + l2_iov_base = p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base; + l2_iov_len = p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len; + l3_iov_base = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base; + l3_iov_len = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len; + + /* Copy headers */ + fragment[VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS].iov_base = l2_iov_base; + fragment[VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS].iov_len = l2_iov_len; + fragment[VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS].iov_base = l3_iov_base; + fragment[VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS].iov_len = l3_iov_len; + + + /* Put as much data as possible and send */ + do { + fragment_len = vmxnet_tx_pkt_fetch_fragment(p, &src_idx, &src_offset, + fragment, &dst_idx); + + more_frags = (fragment_offset + fragment_len < p->payload_len); + + eth_setup_ip4_fragmentation(l2_iov_base, l2_iov_len, l3_iov_base, + l3_iov_len, fragment_len, fragment_offset, more_frags); + + eth_fix_ip4_checksum(l3_iov_base, l3_iov_len); + + bytes_sent += qemu_sendv_packet(vc, fragment, dst_idx); + + fragment_offset += fragment_len; + + } while (more_frags); + + return bytes_sent; +} + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_send + * + * Desc: Send packet to qemu. handles sw offloads if vhdr is not supported. + * + * Params: (IN) pkt - private handle. + * (IN) vc - VLANClientState. + * + * Return: number of bytes sent. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_send(Vmxnet_TxPkt_h pkt, VLANClientState *vc) +{ + void *iovec = NULL; + uint32_t iovec_size; + size_t bytes_sent = 0; + Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt; + assert(p); + + iovec = vmxnet_tx_pkt_map(p, &iovec_size); + if (!iovec) { + goto Exit; + } + + if (!p->has_virt_hdr && p->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { + vmxnet_tx_pkt_do_sw_csum(p); + } + + if (p->has_virt_hdr || VIRTIO_NET_HDR_GSO_NONE == p->virt_hdr.gso_type) { + bytes_sent = qemu_sendv_packet(vc, iovec, iovec_size); + goto Exit; + } + + bytes_sent = vmxnet_tx_pkt_do_sw_fragmentation(p, vc); + +Exit: + vmxnet_tx_pkt_unmap(p); + return bytes_sent; +} + +/*============================================================================= + *============================================================================= + * + * RX CODE + * + *============================================================================= + *===========================================================================*/ + +/* + * RX packet may contain up to 2 fragments - rebuilt eth header + * in case of VLAN tag stripping + * and payload received from QEMU - in any case + */ +#define VMXNET_MAX_RX_PACKET_FRAGMENTS (2) + +typedef struct Vmxnet_RxPkt { + struct virtio_net_hdr virt_hdr; + struct eth_header eth_hdr; + struct iovec vec[VMXNET_MAX_RX_PACKET_FRAGMENTS]; + uint16 vec_len; + uint32_t tot_len; + uint16_t vlan_tag; + bool vlan_stripped; + bool has_virt_hdr; + eth_pkt_types_e packet_type; +} Vmxnet_RxPkt; + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_init + * + * Desc: Init function for rx packet functionality. + * + * Params: (OUT) pkt - private handle. + * (IN) has_virt_hdr - device uses virtio header. + * + * Return: 0 on success, -1 on error + * + * Scope: Global + * + *****************************************************************************/ +int vmxnet_rx_pkt_init(Vmxnet_RxPkt_h *pkt, bool has_virt_hdr) +{ + int rc = 0; + + Vmxnet_RxPkt *p = g_malloc(sizeof *p); + if (!p) { + rc = -1; + goto Exit; + } + + memset(p, 0, sizeof *p); + p->has_virt_hdr = has_virt_hdr; + + *pkt = p; + +Exit: + if (rc) { + vmxnet_rx_pkt_uninit(p); + } + return rc; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_uninit + * + * Desc: Clean all rx packet resources. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_uninit(Vmxnet_RxPkt_h pkt) +{ + if (pkt) { + g_free(pkt); + } +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_vhdr + * + * Desc: returns virtio header stored in rx context. + * + * Params: (IN) pkt - private handle. + * + * Return: virtio header + * + * Scope: Global + * + *****************************************************************************/ +struct virtio_net_hdr *vmxnet_rx_pkt_get_vhdr(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + return &p->virt_hdr; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_attach_data + * + * Desc: Attach data to rx packet. + * + * Params: (IN) pkt - private handle. + * (IN) data + * (IN) len + * (IN) strip_vlan - should the module strip vlan from data. + * + * Return: nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_attach_data(Vmxnet_RxPkt_h pkt, const void *data, size_t len, + bool strip_vlan) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + uint16_t vtag = 0; + uint16_t ploff; + assert(p); + p->vlan_stripped = false; + + if (strip_vlan) { + p->vlan_stripped = eth_strip_vlan(&data, &p->eth_hdr, &ploff, &vtag); + } + + if (p->vlan_stripped) { + p->vec[0].iov_base = &p->eth_hdr; + p->vec[0].iov_len = sizeof p->eth_hdr; + p->vec[1].iov_base = (uint8_t *) data + ploff; + p->vec[1].iov_len = len - ploff; + p->vec_len = 2; + p->tot_len = len - ploff + sizeof(struct eth_header); + } else { + p->vec[0].iov_base = (void *)data; + p->vec[0].iov_len = len; + p->vec_len = 1; + p->tot_len = len; + } + + p->vlan_tag = vtag; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_dump + * + * Desc: prints rx packet data if debug is enabled. + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_dump(Vmxnet_RxPkt_h pkt) +{ +#ifdef VMXNET_RX_PKT_DEBUG + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + printf("RX PKT: tot_len: %d, vlan_stripped: %d, vlan_tag: %d\n", + p->tot_len, p->vlan_stripped, p->vlan_tag); +#endif +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_set_packet_type + * + * Desc: save packet type in packet context + * + * Params: (IN) pkt - private handle. + * (IN) packet_type. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_set_packet_type(Vmxnet_RxPkt_h pkt, + eth_pkt_types_e packet_type) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + p->packet_type = packet_type; + +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_packet_type + * + * Desc: returns packet type. + * + * Params: (IN) pkt - private handle. + * + * Return: packet type. + * + * Scope: Global + * + *****************************************************************************/ +eth_pkt_types_e vmxnet_rx_pkt_get_packet_type(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->packet_type; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_total_len + * + * Desc: returns total length of data attached to rx context. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_rx_pkt_get_total_len(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->tot_len; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_iovec + * + * Desc: returns io vector that holds the attached data. + * + * Params: (IN) pkt - private handle. + * + * Return: iovector. + * + * Scope: Global + * + *****************************************************************************/ +struct iovec *vmxnet_rx_pkt_get_iovec(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->vec; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_set_vhdr + * + * Desc: copy passed phdr data to packet context. + * + * Params: (IN) pkt - private handle. + * (IN) vhdr - new vhdr data. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_set_vhdr(Vmxnet_RxPkt_h pkt, struct virtio_net_hdr *vhdr) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + memcpy(&p->virt_hdr, vhdr, sizeof p->virt_hdr); +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_is_vlan_stripped + * + * Desc: notifies caller if a vlan was stripped from the packet. + * + * Params: (IN) pkt - private handle. + * + * Return: true if vlan vas stripped form the packet, false otherwize. + * + * Scope: Global + * + *****************************************************************************/ +bool vmxnet_rx_pkt_is_vlan_stripped(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->vlan_stripped; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_has_virt_hdr + * + * Desc: notifies caller if the packet has virtio header + * + * Params: (IN) pkt - private handle. + * + * Return: true if packet has virtio header, false otherwize. + * + * Scope: Global + * + *****************************************************************************/ +bool vmxnet_rx_pkt_has_virt_hdr(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->has_virt_hdr; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_num_frags + * + * Desc: returns number of frags attached to the packet. + * + * Params: (IN) pkt - private handle. + * + * Return: number of frags. + * + * Scope: Global + * + *****************************************************************************/ +uint16_t vmxnet_rx_pkt_get_num_frags(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->vec_len; +} + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_vlan_tag + * + * Desc: returns vlan tag. + * + * Params: (IN) pkt - private handle. + * + * Return: vlan tag. + * + * Scope: Global + * + *****************************************************************************/ +uint16_t vmxnet_rx_pkt_get_vlan_tag(Vmxnet_RxPkt_h pkt) +{ + Vmxnet_RxPkt *p = (Vmxnet_RxPkt *)pkt; + assert(p); + + return p->vlan_tag; +} diff --git a/hw/vmxnet_pkt.h b/hw/vmxnet_pkt.h new file mode 100644 index 0000000..099bf1a --- /dev/null +++ b/hw/vmxnet_pkt.h @@ -0,0 +1,479 @@ +/* + * QEMU VMWARE VMXNET* paravirtual NICs - packets abstractions + * + * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com) + * + * Developed by Daynix Computing LTD (http://www.daynix.com) + * + * Authors: + * Dmitry Fleytman <dmi...@daynix.com> + * Tamir Shomer <tam...@daynix.com> + * Yan Vugenfirer <y...@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. + * + */ + +#ifndef VMXNET_PKT_H +#define VMXNET_PKT_H + +#include "stdint.h" +#include "stdbool.h" +#include "vmxnet_utils.h" + +/* defines to enable packet dump functions */ +/*#define VMXNET_TX_PKT_DEBUG*/ +/*#define VMXNET_RX_PKT_DEBUG*/ + +/*============================================================================= + *============================================================================= + * + * TX INTERFACE + * + *============================================================================= + *===========================================================================*/ + +/* tx module context handle */ +typedef void *Vmxnet_TxPkt_h; + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_init + * + * Desc: Init function for tx packet functionality. + * + * Params: (OUT) pkt - private handle. + * (IN) max_frags - max tx ip fragments. + * (IN) has_virt_hdr - device uses virtio header. + * + * Return: 0 on success, -1 on error + * + * Scope: Global + * + *****************************************************************************/ +int vmxnet_tx_pkt_init(Vmxnet_TxPkt_h *pkt, uint32_t max_frags, + bool has_virt_hdr); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_uninit + * + * Desc: Clean all tx packet resources. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_uninit(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_vhdr + * + * Desc: get virtio header. + * + * Params: (IN) pkt - private handle. + * + * Return: virtio header + * + * Scope: Global + * + *****************************************************************************/ +struct virtio_net_hdr *vmxnet_tx_pkt_get_vhdr(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_build_vheader + * + * Desc: build virtio header. (will be stored in module context) + * + * Params: (IN) pkt - private handle. + * (IN) tso_enable + * (IN) csum_enable (has to be enabled if tso_enable is true) + * (IN) gso_size - (relevent only if tso enabled) + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_build_vheader(Vmxnet_TxPkt_h pkt, bool tso_enable, + bool csum_enable, uint32_t gso_size); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_prepare + * + * Desc: populates headers and parses them to gether some metadata for later + * use. + * + * Params: (IN) pkt - private handle. + * (IN) pa - physical address of tx data + * (IN) len - length of data + * + * Return: number of bytes populated by the function. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_prepare(Vmxnet_TxPkt_h pkt, target_phys_addr_t pa, + size_t len); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_setup_vlan_header + * + * Desc: updates vlan tag, and adds vlan header in case it is missing. + * + * Params: (IN) pkt - private handle. + * (IN) vlan + * + * Return: Nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_setup_vlan_header(Vmxnet_TxPkt_h pkt, uint16_t vlan); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_add_fragment + * + * Desc: populate fragment into pkt context. + * + * Params: (IN) pkt - private handle. + * (IN) pa - physical addred of fragment + * (IN) len - length of fragment + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_add_fragment(Vmxnet_TxPkt_h pkt, target_phys_addr_t pa, + size_t len); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_update_ip_checksums + * + * Desc: fix ip header fields and calculate checksums needed. + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_update_ip_checksums(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_total_len + * + * Desc: Returns the length of all populated data. + * + * Params: (IN) pkt - private handle. + * + * Return: length of populated data. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_get_total_len(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_get_packet_type + * + * Desc: returns packet type + * + * Params: (IN) pkt - private handle. + * + * Return: packet type. + * + * Scope: Global + * + *****************************************************************************/ +eth_pkt_types_e vmxnet_tx_pkt_get_packet_type(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_dump + * + * Desc: Prints packet data if debug is enabled + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_dump(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_reset + * + * Desc: reset tx packet private context. (needed to be called between packets) + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_tx_pkt_reset(Vmxnet_TxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_tx_pkt_send + * + * Desc: Send packet to qemu. handles sw offloads if vhdr is not supported. + * + * Params: (IN) pkt - private handle. + * (IN) vc - VLANClientState. + * + * Return: number of bytes sent. + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_tx_pkt_send(Vmxnet_TxPkt_h pkt, VLANClientState *vc); + +/*============================================================================= + *============================================================================= + * + * RX INTERFACE + * + *============================================================================= + *===========================================================================*/ + +/* rx module context handle */ +typedef void *Vmxnet_RxPkt_h; + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_uninit + * + * Desc: Clean all rx packet resources. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_uninit(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_init + * + * Desc: Init function for rx packet functionality. + * + * Params: (OUT) pkt - private handle. + * (IN) has_virt_hdr - device uses virtio header. + * + * Return: 0 on success, -1 on error + * + * Scope: Global + * + *****************************************************************************/ +int vmxnet_rx_pkt_init(Vmxnet_RxPkt_h *pkt, bool has_virt_hdr); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_total_len + * + * Desc: returns total length of data attached to rx context. + * + * Params: (IN) pkt - private handle. + * + * Return: nothing + * + * Scope: Global + * + *****************************************************************************/ +size_t vmxnet_rx_pkt_get_total_len(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_vhdr + * + * Desc: returns virtio header stored in rx context. + * + * Params: (IN) pkt - private handle. + * + * Return: virtio header + * + * Scope: Global + * + *****************************************************************************/ +struct virtio_net_hdr *vmxnet_rx_pkt_get_vhdr(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_packet_type + * + * Desc: returns packet type. + * + * Params: (IN) pkt - private handle. + * + * Return: packet type. + * + * Scope: Global + * + *****************************************************************************/ +eth_pkt_types_e vmxnet_rx_pkt_get_packet_type(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_vlan_tag + * + * Desc: returns vlan tag. + * + * Params: (IN) pkt - private handle. + * + * Return: vlan tag. + * + * Scope: Global + * + *****************************************************************************/ +uint16_t vmxnet_rx_pkt_get_vlan_tag(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_is_vlan_stripped + * + * Desc: notifies caller if a vlan was stripped from the packet. + * + * Params: (IN) pkt - private handle. + * + * Return: true if vlan vas stripped form the packet, false otherwize. + * + * Scope: Global + * + *****************************************************************************/ +bool vmxnet_rx_pkt_is_vlan_stripped(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_has_virt_hdr + * + * Desc: notifies caller if the packet has virtio header + * + * Params: (IN) pkt - private handle. + * + * Return: true if packet has virtio header, false otherwize. + * + * Scope: Global + * + *****************************************************************************/ +bool vmxnet_rx_pkt_has_virt_hdr(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_num_frags + * + * Desc: returns number of frags attached to the packet. + * + * Params: (IN) pkt - private handle. + * + * Return: number of frags. + * + * Scope: Global + * + *****************************************************************************/ +uint16_t vmxnet_rx_pkt_get_num_frags(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_attach_data + * + * Desc: Attach data to rx packet. + * + * Params: (IN) pkt - private handle. + * (IN) data + * (IN) len + * (IN) strip_vlan - should the module strip vlan from data. + * + * Return: nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_attach_data(Vmxnet_RxPkt_h pkt, const void *data, + size_t len, bool strip_vlan); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_get_iovec + * + * Desc: returns io vector that holds the attached data. + * + * Params: (IN) pkt - private handle. + * + * Return: iovector. + * + * Scope: Global + * + *****************************************************************************/ +struct iovec *vmxnet_rx_pkt_get_iovec(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_dump + * + * Desc: prints rx packet data if debug is enabled. + * + * Params: (IN) pkt - private handle. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_dump(Vmxnet_RxPkt_h pkt); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_set_vhdr + * + * Desc: copy passed phdr data to packet context. + * + * Params: (IN) pkt - private handle. + * (IN) vhdr - new vhdr data. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_set_vhdr(Vmxnet_RxPkt_h pkt, struct virtio_net_hdr *vhdr); + +/****************************************************************************** + * + * Function: vmxnet_rx_pkt_set_packet_type + * + * Desc: save packet type in packet context + * + * Params: (IN) pkt - private handle. + * (IN) packet_type. + * + * Return: Nothing. + * + * Scope: Global + * + *****************************************************************************/ +void vmxnet_rx_pkt_set_packet_type(Vmxnet_RxPkt_h pkt, + eth_pkt_types_e packet_type); + +#endif + -- 1.7.7.6