xmit_seg(E1000State *s)

{

    uint16_t len, *sp;

    unsigned int frames = s->tx.tso_frames, css, sofar, n;

    struct e1000_tx *tp = &s->tx;



    if (tp->tse && tp->cptse) {

        css = tp->ipcss;

        DBGOUT(TXSUM, "frames %d size %d ipcss %d\n",

               frames, tp->size, css);

        if (tp->ip) {		// IPv4

            cpu_to_be16wu((uint16_t *)(tp->data+css+2),

                          tp->size - css);

            cpu_to_be16wu((uint16_t *)(tp->data+css+4),

                          be16_to_cpup((uint16_t *)(tp->data+css+4))+frames);

        } else			// IPv6

            cpu_to_be16wu((uint16_t *)(tp->data+css+4),

                          tp->size - css);

        css = tp->tucss;

        len = tp->size - css;

        DBGOUT(TXSUM, "tcp %d tucss %d len %d\n", tp->tcp, css, len);

        if (tp->tcp) {

            sofar = frames * tp->mss;

            cpu_to_be32wu((uint32_t *)(tp->data+css+4),	// seq

                be32_to_cpupu((uint32_t *)(tp->data+css+4))+sofar);

            if (tp->paylen - sofar > tp->mss)

                tp->data[css + 13] &= ~9;		// PSH, FIN

        } else	// UDP

            cpu_to_be16wu((uint16_t *)(tp->data+css+4), len);

        if (tp->sum_needed & E1000_TXD_POPTS_TXSM) {

            // add pseudo-header length before checksum calculation

            sp = (uint16_t *)(tp->data + tp->tucso);

            cpu_to_be16wu(sp, be16_to_cpup(sp) + len);

        }

        tp->tso_frames++;

    }



    if (tp->sum_needed & E1000_TXD_POPTS_TXSM)

        putsum(tp->data, tp->size, tp->tucso, tp->tucss, tp->tucse);

    if (tp->sum_needed & E1000_TXD_POPTS_IXSM)

        putsum(tp->data, tp->size, tp->ipcso, tp->ipcss, tp->ipcse);

    if (tp->vlan_needed) {

        memmove(tp->vlan, tp->data, 4);

        memmove(tp->data, tp->data + 4, 8);

        memcpy(tp->data + 8, tp->vlan_header, 4);

        qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4);

    } else

        qemu_send_packet(&s->nic->nc, tp->data, tp->size);

    s->mac_reg[TPT]++;

    s->mac_reg[GPTC]++;

    n = s->mac_reg[TOTL];

    if ((s->mac_reg[TOTL] += s->tx.size) < n)

        s->mac_reg[TOTH]++;

}

xmit_seg(E1000State *s)

{

    uint16_t len, *sp;

    unsigned int frames = s->tx.tso_frames, css, sofar, n;

    struct e1000_tx *tp = &s->tx;



    if (tp->tse && tp->cptse) {

        css = tp->ipcss;

        DBGOUT(TXSUM, "frames %d size %d ipcss %d\n",

               frames, tp->size, css);

        if (tp->ip) {		

            cpu_to_be16wu((uint16_t *)(tp->data+css+2),

                          tp->size - css);

            cpu_to_be16wu((uint16_t *)(tp->data+css+4),

                          be16_to_cpup((uint16_t *)(tp->data+css+4))+frames);

        } else			

            cpu_to_be16wu((uint16_t *)(tp->data+css+4),

                          tp->size - css);

        css = tp->tucss;

        len = tp->size - css;

        DBGOUT(TXSUM, "tcp %d tucss %d len %d\n", tp->tcp, css, len);

        if (tp->tcp) {

            sofar = frames * tp->mss;

            cpu_to_be32wu((uint32_t *)(tp->data+css+4),	

                be32_to_cpupu((uint32_t *)(tp->data+css+4))+sofar);

            if (tp->paylen - sofar > tp->mss)

                tp->data[css + 13] &= ~9;		

        } else	

            cpu_to_be16wu((uint16_t *)(tp->data+css+4), len);

        if (tp->sum_needed & E1000_TXD_POPTS_TXSM) {

            

            sp = (uint16_t *)(tp->data + tp->tucso);

            cpu_to_be16wu(sp, be16_to_cpup(sp) + len);

        }

        tp->tso_frames++;

    }



    if (tp->sum_needed & E1000_TXD_POPTS_TXSM)

        putsum(tp->data, tp->size, tp->tucso, tp->tucss, tp->tucse);

    if (tp->sum_needed & E1000_TXD_POPTS_IXSM)

        putsum(tp->data, tp->size, tp->ipcso, tp->ipcss, tp->ipcse);

    if (tp->vlan_needed) {

        memmove(tp->vlan, tp->data, 4);

        memmove(tp->data, tp->data + 4, 8);

        memcpy(tp->data + 8, tp->vlan_header, 4);

        qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4);

    } else

        qemu_send_packet(&s->nic->nc, tp->data, tp->size);

    s->mac_reg[TPT]++;

    s->mac_reg[GPTC]++;

    n = s->mac_reg[TOTL];

    if ((s->mac_reg[TOTL] += s->tx.size) < n)

        s->mac_reg[TOTH]++;

}

            cpu_to_be16wu(sp, be16_to_cpup(sp) + len);
FUNC_0(E1000State *VAR_0)

{

    uint16_t len, *sp;

    unsigned int VAR_1 = VAR_0->tx.tso_frames, VAR_2, VAR_3, VAR_4;

    struct e1000_tx *VAR_5 = &VAR_0->tx;



    if (VAR_5->tse && VAR_5->cptse) {

        VAR_2 = VAR_5->ipcss;

        DBGOUT(TXSUM, "VAR_1 %d size %d ipcss %d\VAR_4",

               VAR_1, VAR_5->size, VAR_2);

        if (VAR_5->ip) {		

            cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+2),

                          VAR_5->size - VAR_2);

            cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4),

                          be16_to_cpup((uint16_t *)(VAR_5->data+VAR_2+4))+VAR_1);

        } else			

            cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4),

                          VAR_5->size - VAR_2);

        VAR_2 = VAR_5->tucss;

        len = VAR_5->size - VAR_2;

        DBGOUT(TXSUM, "tcp %d tucss %d len %d\VAR_4", VAR_5->tcp, VAR_2, len);

        if (VAR_5->tcp) {

            VAR_3 = VAR_1 * VAR_5->mss;

            cpu_to_be32wu((uint32_t *)(VAR_5->data+VAR_2+4),	

                be32_to_cpupu((uint32_t *)(VAR_5->data+VAR_2+4))+VAR_3);

            if (VAR_5->paylen - VAR_3 > VAR_5->mss)

                VAR_5->data[VAR_2 + 13] &= ~9;		

        } else	

            cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4), len);

        if (VAR_5->sum_needed & E1000_TXD_POPTS_TXSM) {

            

            sp = (uint16_t *)(VAR_5->data + VAR_5->tucso);

            cpu_to_be16wu(sp, be16_to_cpup(sp) + len);

        }

        VAR_5->tso_frames++;

    }



    if (VAR_5->sum_needed & E1000_TXD_POPTS_TXSM)

        putsum(VAR_5->data, VAR_5->size, VAR_5->tucso, VAR_5->tucss, VAR_5->tucse);

    if (VAR_5->sum_needed & E1000_TXD_POPTS_IXSM)

        putsum(VAR_5->data, VAR_5->size, VAR_5->ipcso, VAR_5->ipcss, VAR_5->ipcse);

    if (VAR_5->vlan_needed) {

        memmove(VAR_5->vlan, VAR_5->data, 4);

        memmove(VAR_5->data, VAR_5->data + 4, 8);

        memcpy(VAR_5->data + 8, VAR_5->vlan_header, 4);

        qemu_send_packet(&VAR_0->nic->nc, VAR_5->vlan, VAR_5->size + 4);

    } else

        qemu_send_packet(&VAR_0->nic->nc, VAR_5->data, VAR_5->size);

    VAR_0->mac_reg[TPT]++;

    VAR_0->mac_reg[GPTC]++;

    VAR_4 = VAR_0->mac_reg[TOTL];

    if ((VAR_0->mac_reg[TOTL] += VAR_0->tx.size) < VAR_4)

        VAR_0->mac_reg[TOTH]++;

}

FUNC_0(E1000State *VAR_0)
{ uint16_t len, *sp; unsigned int VAR_1 = VAR_0->tx.tso_frames, VAR_2, VAR_3, VAR_4; struct e1000_tx *VAR_5 = &VAR_0->tx; if (VAR_5->tse && VAR_5->cptse) { VAR_2 = VAR_5->ipcss; DBGOUT(TXSUM, "VAR_1 %d size %d ipcss %d\VAR_4",
VAR_1, VAR_5->size, VAR_2); if (VAR_5->ip) { cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+2),
VAR_5->size - VAR_2); cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4),
be16_to_cpup((uint16_t *)(VAR_5->data+VAR_2+4))+VAR_1); } else cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4),
VAR_5->size - VAR_2); VAR_2 = VAR_5->tucss; len = VAR_5->size - VAR_2; DBGOUT(TXSUM, "tcp %d tucss %d len %d\VAR_4", VAR_5->tcp, VAR_2, len); if (VAR_5->tcp) { VAR_3 = VAR_1 * VAR_5->mss; cpu_to_be32wu((uint32_t *)(VAR_5->data+VAR_2+4),
be32_to_cpupu((uint32_t *)(VAR_5->data+VAR_2+4))+VAR_3); if (VAR_5->paylen - VAR_3 > VAR_5->mss)
VAR_5->data[VAR_2 + 13] &= ~9; } else cpu_to_be16wu((uint16_t *)(VAR_5->data+VAR_2+4), len); if (VAR_5->sum_needed & E1000_TXD_POPTS_TXSM) { sp = (uint16_t *)(VAR_5->data + VAR_5->tucso); cpu_to_be16wu(sp, be16_to_cpup(sp) + len); } VAR_5->tso_frames++; } if (VAR_5->sum_needed & E1000_TXD_POPTS_TXSM)
putsum(VAR_5->data, VAR_5->size, VAR_5->tucso, VAR_5->tucss, VAR_5->tucse); if (VAR_5->sum_needed & E1000_TXD_POPTS_IXSM)
putsum(VAR_5->data, VAR_5->size, VAR_5->ipcso, VAR_5->ipcss, VAR_5->ipcse); if (VAR_5->vlan_needed) { memmove(VAR_5->vlan, VAR_5->data, 4); memmove(VAR_5->data, VAR_5->data + 4, 8); memcpy(VAR_5->data + 8, VAR_5->vlan_header, 4); qemu_send_packet(&VAR_0->nic->nc, VAR_5->vlan, VAR_5->size + 4); } else qemu_send_packet(&VAR_0->nic->nc, VAR_5->data, VAR_5->size); VAR_0->mac_reg[TPT]++; VAR_0->mac_reg[GPTC]++; VAR_4 = VAR_0->mac_reg[TOTL]; if ((VAR_0->mac_reg[TOTL] += VAR_0->tx.size) < VAR_4)
VAR_0->mac_reg[TOTH]++; }