qemu/hw/net/vmxnet_tx_pkt.c
<<
>>
Prefs
   1/*
   2 * QEMU VMWARE VMXNET* paravirtual NICs - TX packets abstractions
   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 <dmitry@daynix.com>
  10 * Tamir Shomer <tamirs@daynix.com>
  11 * Yan Vugenfirer <yan@daynix.com>
  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
  18#include "qemu/osdep.h"
  19#include "hw/hw.h"
  20#include "vmxnet_tx_pkt.h"
  21#include "net/eth.h"
  22#include "qemu-common.h"
  23#include "qemu/iov.h"
  24#include "net/checksum.h"
  25#include "net/tap.h"
  26#include "net/net.h"
  27
  28enum {
  29    VMXNET_TX_PKT_VHDR_FRAG = 0,
  30    VMXNET_TX_PKT_L2HDR_FRAG,
  31    VMXNET_TX_PKT_L3HDR_FRAG,
  32    VMXNET_TX_PKT_PL_START_FRAG
  33};
  34
  35/* TX packet private context */
  36struct VmxnetTxPkt {
  37    struct virtio_net_hdr virt_hdr;
  38    bool has_virt_hdr;
  39
  40    struct iovec *raw;
  41    uint32_t raw_frags;
  42    uint32_t max_raw_frags;
  43
  44    struct iovec *vec;
  45
  46    uint8_t l2_hdr[ETH_MAX_L2_HDR_LEN];
  47
  48    uint32_t payload_len;
  49
  50    uint32_t payload_frags;
  51    uint32_t max_payload_frags;
  52
  53    uint16_t hdr_len;
  54    eth_pkt_types_e packet_type;
  55    uint8_t l4proto;
  56};
  57
  58void vmxnet_tx_pkt_init(struct VmxnetTxPkt **pkt, uint32_t max_frags,
  59    bool has_virt_hdr)
  60{
  61    struct VmxnetTxPkt *p = g_malloc0(sizeof *p);
  62
  63    p->vec = g_new(struct iovec, max_frags + VMXNET_TX_PKT_PL_START_FRAG);
  64
  65    p->raw = g_new(struct iovec, max_frags);
  66
  67    p->max_payload_frags = max_frags;
  68    p->max_raw_frags = max_frags;
  69    p->has_virt_hdr = has_virt_hdr;
  70    p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_base = &p->virt_hdr;
  71    p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_len =
  72        p->has_virt_hdr ? sizeof p->virt_hdr : 0;
  73    p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base = &p->l2_hdr;
  74    p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base = NULL;
  75    p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len = 0;
  76
  77    *pkt = p;
  78}
  79
  80void vmxnet_tx_pkt_uninit(struct VmxnetTxPkt *pkt)
  81{
  82    if (pkt) {
  83        g_free(pkt->vec);
  84        g_free(pkt->raw);
  85        g_free(pkt);
  86    }
  87}
  88
  89void vmxnet_tx_pkt_update_ip_checksums(struct VmxnetTxPkt *pkt)
  90{
  91    uint16_t csum;
  92    uint32_t ph_raw_csum;
  93    assert(pkt);
  94    uint8_t gso_type = pkt->virt_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN;
  95    struct ip_header *ip_hdr;
  96
  97    if (VIRTIO_NET_HDR_GSO_TCPV4 != gso_type &&
  98        VIRTIO_NET_HDR_GSO_UDP != gso_type) {
  99        return;
 100    }
 101
 102    ip_hdr = pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base;
 103
 104    if (pkt->payload_len + pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len >
 105        ETH_MAX_IP_DGRAM_LEN) {
 106        return;
 107    }
 108
 109    ip_hdr->ip_len = cpu_to_be16(pkt->payload_len +
 110        pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len);
 111
 112    /* Calculate IP header checksum                    */
 113    ip_hdr->ip_sum = 0;
 114    csum = net_raw_checksum((uint8_t *)ip_hdr,
 115        pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len);
 116    ip_hdr->ip_sum = cpu_to_be16(csum);
 117
 118    /* Calculate IP pseudo header checksum             */
 119    ph_raw_csum = eth_calc_pseudo_hdr_csum(ip_hdr, pkt->payload_len);
 120    csum = cpu_to_be16(~net_checksum_finish(ph_raw_csum));
 121    iov_from_buf(&pkt->vec[VMXNET_TX_PKT_PL_START_FRAG], pkt->payload_frags,
 122                 pkt->virt_hdr.csum_offset, &csum, sizeof(csum));
 123}
 124
 125static void vmxnet_tx_pkt_calculate_hdr_len(struct VmxnetTxPkt *pkt)
 126{
 127    pkt->hdr_len = pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len +
 128        pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len;
 129}
 130
 131static bool vmxnet_tx_pkt_parse_headers(struct VmxnetTxPkt *pkt)
 132{
 133    struct iovec *l2_hdr, *l3_hdr;
 134    size_t bytes_read;
 135    size_t full_ip6hdr_len;
 136    uint16_t l3_proto;
 137
 138    assert(pkt);
 139
 140    l2_hdr = &pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG];
 141    l3_hdr = &pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG];
 142
 143    bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, 0, l2_hdr->iov_base,
 144                            ETH_MAX_L2_HDR_LEN);
 145    if (bytes_read < sizeof(struct eth_header)) {
 146        l2_hdr->iov_len = 0;
 147        return false;
 148    }
 149
 150    l2_hdr->iov_len = sizeof(struct eth_header);
 151    switch (be16_to_cpu(PKT_GET_ETH_HDR(l2_hdr->iov_base)->h_proto)) {
 152    case ETH_P_VLAN:
 153        l2_hdr->iov_len += sizeof(struct vlan_header);
 154        break;
 155    case ETH_P_DVLAN:
 156        l2_hdr->iov_len += 2 * sizeof(struct vlan_header);
 157        break;
 158    }
 159
 160    if (bytes_read < l2_hdr->iov_len) {
 161        l2_hdr->iov_len = 0;
 162        return false;
 163    }
 164
 165    l3_proto = eth_get_l3_proto(l2_hdr->iov_base, l2_hdr->iov_len);
 166
 167    switch (l3_proto) {
 168    case ETH_P_IP:
 169        l3_hdr->iov_base = g_malloc(ETH_MAX_IP4_HDR_LEN);
 170
 171        bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, l2_hdr->iov_len,
 172                                l3_hdr->iov_base, sizeof(struct ip_header));
 173
 174        if (bytes_read < sizeof(struct ip_header)) {
 175            l3_hdr->iov_len = 0;
 176            return false;
 177        }
 178
 179        l3_hdr->iov_len = IP_HDR_GET_LEN(l3_hdr->iov_base);
 180        if(l3_hdr->iov_len < sizeof(struct ip_header))
 181        {
 182            l3_hdr->iov_len = 0;
 183            return false;
 184        }
 185        pkt->l4proto = ((struct ip_header *) l3_hdr->iov_base)->ip_p;
 186
 187        /* copy optional IPv4 header data */
 188        bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags,
 189                                l2_hdr->iov_len + sizeof(struct ip_header),
 190                                l3_hdr->iov_base + sizeof(struct ip_header),
 191                                l3_hdr->iov_len - sizeof(struct ip_header));
 192        if (bytes_read < l3_hdr->iov_len - sizeof(struct ip_header)) {
 193            l3_hdr->iov_len = 0;
 194            return false;
 195        }
 196        break;
 197
 198    case ETH_P_IPV6:
 199        if (!eth_parse_ipv6_hdr(pkt->raw, pkt->raw_frags, l2_hdr->iov_len,
 200                               &pkt->l4proto, &full_ip6hdr_len)) {
 201            l3_hdr->iov_len = 0;
 202            return false;
 203        }
 204
 205        l3_hdr->iov_base = g_malloc(full_ip6hdr_len);
 206
 207        bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, l2_hdr->iov_len,
 208                                l3_hdr->iov_base, full_ip6hdr_len);
 209
 210        if (bytes_read < full_ip6hdr_len) {
 211            l3_hdr->iov_len = 0;
 212            return false;
 213        } else {
 214            l3_hdr->iov_len = full_ip6hdr_len;
 215        }
 216        break;
 217
 218    default:
 219        l3_hdr->iov_len = 0;
 220        break;
 221    }
 222
 223    vmxnet_tx_pkt_calculate_hdr_len(pkt);
 224    pkt->packet_type = get_eth_packet_type(l2_hdr->iov_base);
 225    return true;
 226}
 227
 228static bool vmxnet_tx_pkt_rebuild_payload(struct VmxnetTxPkt *pkt)
 229{
 230    size_t payload_len = iov_size(pkt->raw, pkt->raw_frags) - pkt->hdr_len;
 231
 232    pkt->payload_frags = iov_copy(&pkt->vec[VMXNET_TX_PKT_PL_START_FRAG],
 233                                pkt->max_payload_frags,
 234                                pkt->raw, pkt->raw_frags,
 235                                pkt->hdr_len, payload_len);
 236
 237    if (pkt->payload_frags != (uint32_t) -1) {
 238        pkt->payload_len = payload_len;
 239        return true;
 240    } else {
 241        return false;
 242    }
 243}
 244
 245bool vmxnet_tx_pkt_parse(struct VmxnetTxPkt *pkt)
 246{
 247    return vmxnet_tx_pkt_parse_headers(pkt) &&
 248           vmxnet_tx_pkt_rebuild_payload(pkt);
 249}
 250
 251struct virtio_net_hdr *vmxnet_tx_pkt_get_vhdr(struct VmxnetTxPkt *pkt)
 252{
 253    assert(pkt);
 254    return &pkt->virt_hdr;
 255}
 256
 257static uint8_t vmxnet_tx_pkt_get_gso_type(struct VmxnetTxPkt *pkt,
 258                                          bool tso_enable)
 259{
 260    uint8_t rc = VIRTIO_NET_HDR_GSO_NONE;
 261    uint16_t l3_proto;
 262
 263    l3_proto = eth_get_l3_proto(pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base,
 264        pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len);
 265
 266    if (!tso_enable) {
 267        goto func_exit;
 268    }
 269
 270    rc = eth_get_gso_type(l3_proto, pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base,
 271                          pkt->l4proto);
 272
 273func_exit:
 274    return rc;
 275}
 276
 277void vmxnet_tx_pkt_build_vheader(struct VmxnetTxPkt *pkt, bool tso_enable,
 278    bool csum_enable, uint32_t gso_size)
 279{
 280    struct tcp_hdr l4hdr;
 281    assert(pkt);
 282
 283    /* csum has to be enabled if tso is. */
 284    assert(csum_enable || !tso_enable);
 285
 286    pkt->virt_hdr.gso_type = vmxnet_tx_pkt_get_gso_type(pkt, tso_enable);
 287
 288    switch (pkt->virt_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
 289    case VIRTIO_NET_HDR_GSO_NONE:
 290        pkt->virt_hdr.hdr_len = 0;
 291        pkt->virt_hdr.gso_size = 0;
 292        break;
 293
 294    case VIRTIO_NET_HDR_GSO_UDP:
 295        pkt->virt_hdr.gso_size = IP_FRAG_ALIGN_SIZE(gso_size);
 296        pkt->virt_hdr.hdr_len = pkt->hdr_len + sizeof(struct udp_header);
 297        break;
 298
 299    case VIRTIO_NET_HDR_GSO_TCPV4:
 300    case VIRTIO_NET_HDR_GSO_TCPV6:
 301        iov_to_buf(&pkt->vec[VMXNET_TX_PKT_PL_START_FRAG], pkt->payload_frags,
 302                   0, &l4hdr, sizeof(l4hdr));
 303        pkt->virt_hdr.hdr_len = pkt->hdr_len + l4hdr.th_off * sizeof(uint32_t);
 304        pkt->virt_hdr.gso_size = IP_FRAG_ALIGN_SIZE(gso_size);
 305        break;
 306
 307    default:
 308        g_assert_not_reached();
 309    }
 310
 311    if (csum_enable) {
 312        switch (pkt->l4proto) {
 313        case IP_PROTO_TCP:
 314            pkt->virt_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
 315            pkt->virt_hdr.csum_start = pkt->hdr_len;
 316            pkt->virt_hdr.csum_offset = offsetof(struct tcp_hdr, th_sum);
 317            break;
 318        case IP_PROTO_UDP:
 319            pkt->virt_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
 320            pkt->virt_hdr.csum_start = pkt->hdr_len;
 321            pkt->virt_hdr.csum_offset = offsetof(struct udp_hdr, uh_sum);
 322            break;
 323        default:
 324            break;
 325        }
 326    }
 327}
 328
 329void vmxnet_tx_pkt_setup_vlan_header(struct VmxnetTxPkt *pkt, uint16_t vlan)
 330{
 331    bool is_new;
 332    assert(pkt);
 333
 334    eth_setup_vlan_headers(pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base,
 335        vlan, &is_new);
 336
 337    /* update l2hdrlen */
 338    if (is_new) {
 339        pkt->hdr_len += sizeof(struct vlan_header);
 340        pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len +=
 341            sizeof(struct vlan_header);
 342    }
 343}
 344
 345bool vmxnet_tx_pkt_add_raw_fragment(struct VmxnetTxPkt *pkt, hwaddr pa,
 346    size_t len)
 347{
 348    hwaddr mapped_len = 0;
 349    struct iovec *ventry;
 350    assert(pkt);
 351    assert(pkt->max_raw_frags > pkt->raw_frags);
 352
 353    if (!len) {
 354        return true;
 355     }
 356
 357    ventry = &pkt->raw[pkt->raw_frags];
 358    mapped_len = len;
 359
 360    ventry->iov_base = cpu_physical_memory_map(pa, &mapped_len, false);
 361    ventry->iov_len = mapped_len;
 362    pkt->raw_frags += !!ventry->iov_base;
 363
 364    if ((ventry->iov_base == NULL) || (len != mapped_len)) {
 365        return false;
 366    }
 367
 368    return true;
 369}
 370
 371eth_pkt_types_e vmxnet_tx_pkt_get_packet_type(struct VmxnetTxPkt *pkt)
 372{
 373    assert(pkt);
 374
 375    return pkt->packet_type;
 376}
 377
 378size_t vmxnet_tx_pkt_get_total_len(struct VmxnetTxPkt *pkt)
 379{
 380    assert(pkt);
 381
 382    return pkt->hdr_len + pkt->payload_len;
 383}
 384
 385void vmxnet_tx_pkt_dump(struct VmxnetTxPkt *pkt)
 386{
 387#ifdef VMXNET_TX_PKT_DEBUG
 388    assert(pkt);
 389
 390    printf("TX PKT: hdr_len: %d, pkt_type: 0x%X, l2hdr_len: %lu, "
 391        "l3hdr_len: %lu, payload_len: %u\n", pkt->hdr_len, pkt->packet_type,
 392        pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len,
 393        pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len, pkt->payload_len);
 394#endif
 395}
 396
 397void vmxnet_tx_pkt_reset(struct VmxnetTxPkt *pkt)
 398{
 399    int i;
 400
 401    /* no assert, as reset can be called before tx_pkt_init */
 402    if (!pkt) {
 403        return;
 404    }
 405
 406    memset(&pkt->virt_hdr, 0, sizeof(pkt->virt_hdr));
 407
 408    g_free(pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base);
 409    pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base = NULL;
 410
 411    assert(pkt->vec);
 412    for (i = VMXNET_TX_PKT_L2HDR_FRAG;
 413         i < pkt->payload_frags + VMXNET_TX_PKT_PL_START_FRAG; i++) {
 414        pkt->vec[i].iov_len = 0;
 415    }
 416    pkt->payload_len = 0;
 417    pkt->payload_frags = 0;
 418
 419    assert(pkt->raw);
 420    for (i = 0; i < pkt->raw_frags; i++) {
 421        assert(pkt->raw[i].iov_base);
 422        cpu_physical_memory_unmap(pkt->raw[i].iov_base, pkt->raw[i].iov_len,
 423                                  false, pkt->raw[i].iov_len);
 424        pkt->raw[i].iov_len = 0;
 425    }
 426    pkt->raw_frags = 0;
 427
 428    pkt->hdr_len = 0;
 429    pkt->packet_type = 0;
 430    pkt->l4proto = 0;
 431}
 432
 433static void vmxnet_tx_pkt_do_sw_csum(struct VmxnetTxPkt *pkt)
 434{
 435    struct iovec *iov = &pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG];
 436    uint32_t csum_cntr;
 437    uint16_t csum = 0;
 438    /* num of iovec without vhdr */
 439    uint32_t iov_len = pkt->payload_frags + VMXNET_TX_PKT_PL_START_FRAG - 1;
 440    uint16_t csl;
 441    struct ip_header *iphdr;
 442    size_t csum_offset = pkt->virt_hdr.csum_start + pkt->virt_hdr.csum_offset;
 443
 444    /* Put zero to checksum field */
 445    iov_from_buf(iov, iov_len, csum_offset, &csum, sizeof csum);
 446
 447    /* Calculate L4 TCP/UDP checksum */
 448    csl = pkt->payload_len;
 449
 450    /* data checksum */
 451    csum_cntr =
 452        net_checksum_add_iov(iov, iov_len, pkt->virt_hdr.csum_start, csl);
 453    /* add pseudo header to csum */
 454    iphdr = pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base;
 455    csum_cntr += eth_calc_pseudo_hdr_csum(iphdr, csl);
 456
 457    /* Put the checksum obtained into the packet */
 458    csum = cpu_to_be16(net_checksum_finish(csum_cntr));
 459    iov_from_buf(iov, iov_len, csum_offset, &csum, sizeof csum);
 460}
 461
 462enum {
 463    VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS = 0,
 464    VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS,
 465    VMXNET_TX_PKT_FRAGMENT_HEADER_NUM
 466};
 467
 468#define VMXNET_MAX_FRAG_SG_LIST (64)
 469
 470static size_t vmxnet_tx_pkt_fetch_fragment(struct VmxnetTxPkt *pkt,
 471    int *src_idx, size_t *src_offset, struct iovec *dst, int *dst_idx)
 472{
 473    size_t fetched = 0;
 474    struct iovec *src = pkt->vec;
 475
 476    *dst_idx = VMXNET_TX_PKT_FRAGMENT_HEADER_NUM;
 477
 478    while (fetched < pkt->virt_hdr.gso_size) {
 479
 480        /* no more place in fragment iov */
 481        if (*dst_idx == VMXNET_MAX_FRAG_SG_LIST) {
 482            break;
 483        }
 484
 485        /* no more data in iovec */
 486        if (*src_idx == (pkt->payload_frags + VMXNET_TX_PKT_PL_START_FRAG)) {
 487            break;
 488        }
 489
 490
 491        dst[*dst_idx].iov_base = src[*src_idx].iov_base + *src_offset;
 492        dst[*dst_idx].iov_len = MIN(src[*src_idx].iov_len - *src_offset,
 493            pkt->virt_hdr.gso_size - fetched);
 494
 495        *src_offset += dst[*dst_idx].iov_len;
 496        fetched += dst[*dst_idx].iov_len;
 497
 498        if (*src_offset == src[*src_idx].iov_len) {
 499            *src_offset = 0;
 500            (*src_idx)++;
 501        }
 502
 503        (*dst_idx)++;
 504    }
 505
 506    return fetched;
 507}
 508
 509static bool vmxnet_tx_pkt_do_sw_fragmentation(struct VmxnetTxPkt *pkt,
 510    NetClientState *nc)
 511{
 512    struct iovec fragment[VMXNET_MAX_FRAG_SG_LIST];
 513    size_t fragment_len = 0;
 514    bool more_frags = false;
 515
 516    /* some pointers for shorter code */
 517    void *l2_iov_base, *l3_iov_base;
 518    size_t l2_iov_len, l3_iov_len;
 519    int src_idx =  VMXNET_TX_PKT_PL_START_FRAG, dst_idx;
 520    size_t src_offset = 0;
 521    size_t fragment_offset = 0;
 522
 523    l2_iov_base = pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base;
 524    l2_iov_len = pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_len;
 525    l3_iov_base = pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base;
 526    l3_iov_len = pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len;
 527
 528    /* Copy headers */
 529    fragment[VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS].iov_base = l2_iov_base;
 530    fragment[VMXNET_TX_PKT_FRAGMENT_L2_HDR_POS].iov_len = l2_iov_len;
 531    fragment[VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS].iov_base = l3_iov_base;
 532    fragment[VMXNET_TX_PKT_FRAGMENT_L3_HDR_POS].iov_len = l3_iov_len;
 533
 534
 535    /* Put as much data as possible and send */
 536    do {
 537        fragment_len = vmxnet_tx_pkt_fetch_fragment(pkt, &src_idx, &src_offset,
 538            fragment, &dst_idx);
 539
 540        more_frags = (fragment_offset + fragment_len < pkt->payload_len);
 541
 542        eth_setup_ip4_fragmentation(l2_iov_base, l2_iov_len, l3_iov_base,
 543            l3_iov_len, fragment_len, fragment_offset, more_frags);
 544
 545        eth_fix_ip4_checksum(l3_iov_base, l3_iov_len);
 546
 547        qemu_sendv_packet(nc, fragment, dst_idx);
 548
 549        fragment_offset += fragment_len;
 550
 551    } while (fragment_len && more_frags);
 552
 553    return true;
 554}
 555
 556bool vmxnet_tx_pkt_send(struct VmxnetTxPkt *pkt, NetClientState *nc)
 557{
 558    assert(pkt);
 559
 560    if (!pkt->has_virt_hdr &&
 561        pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
 562        vmxnet_tx_pkt_do_sw_csum(pkt);
 563    }
 564
 565    /*
 566     * Since underlying infrastructure does not support IP datagrams longer
 567     * than 64K we should drop such packets and don't even try to send
 568     */
 569    if (VIRTIO_NET_HDR_GSO_NONE != pkt->virt_hdr.gso_type) {
 570        if (pkt->payload_len >
 571            ETH_MAX_IP_DGRAM_LEN -
 572            pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len) {
 573            return false;
 574        }
 575    }
 576
 577    if (pkt->has_virt_hdr ||
 578        pkt->virt_hdr.gso_type == VIRTIO_NET_HDR_GSO_NONE) {
 579        qemu_sendv_packet(nc, pkt->vec,
 580            pkt->payload_frags + VMXNET_TX_PKT_PL_START_FRAG);
 581        return true;
 582    }
 583
 584    return vmxnet_tx_pkt_do_sw_fragmentation(pkt, nc);
 585}
 586