[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [qemu-xen-traditional master] rtl8139: drop tautologous if (ip) {...} statement



commit ed8122ba5d27663fb40de7d9e0482fcd6f12b363
Author:     Stefan Hajnoczi <stefanha@xxxxxxxxxx>
AuthorDate: Wed Jul 15 18:16:59 2015 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Tue May 10 19:11:39 2016 +0100

    rtl8139: drop tautologous if (ip) {...} statement
    
    The previous patch stopped using the ip pointer as an indicator that the
    IP header is present.  When we reach the if (ip) {...} statement we know
    ip is always non-NULL.
    
    Remove the if statement to reduce nesting.
    
    Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxx>
    [Backport to qemu-xen-tradition]
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 hw/rtl8139.c | 255 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 126 insertions(+), 129 deletions(-)

diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 44c221c..8b17bd9 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -2137,185 +2137,182 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
             ip_protocol = ip->ip_p;
             ip_data_len = be16_to_cpu(ip->ip_len) - hlen;
 
-            if (ip)
+            if (txdw0 & CP_TX_IPCS)
             {
-                if (txdw0 & CP_TX_IPCS)
-                {
-                    DEBUG_PRINT(("RTL8139: +++ C+ mode need IP checksum\n"));
+                DEBUG_PRINT(("RTL8139: +++ C+ mode need IP checksum\n"));
 
-                    if (hlen<sizeof(ip_header) || hlen>eth_payload_len) {/* 
min header length */
-                        /* bad packet header len */
-                        /* or packet too short */
-                    }
-                    else
-                    {
-                        ip->ip_sum = 0;
-                        ip->ip_sum = ip_checksum(ip, hlen);
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode IP header len=%d 
checksum=%04x\n", hlen, ip->ip_sum));
-                    }
+                if (hlen<sizeof(ip_header) || hlen>eth_payload_len) {/* min 
header length */
+                    /* bad packet header len */
+                    /* or packet too short */
                 }
-
-                if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP)
+                else
                 {
+                    ip->ip_sum = 0;
+                    ip->ip_sum = ip_checksum(ip, hlen);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode IP header len=%d 
checksum=%04x\n", hlen, ip->ip_sum));
+                }
+            }
+
+            if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP)
+            {
 #if defined (DEBUG_RTL8139)
-                    int large_send_mss = (txdw0 >> 16) & CP_TC_LGSEN_MSS_MASK;
+                int large_send_mss = (txdw0 >> 16) & CP_TC_LGSEN_MSS_MASK;
 #endif
-                    DEBUG_PRINT(("RTL8139: +++ C+ mode offloaded task TSO 
MTU=%d IP data %d frame data %d specified MSS=%d\n",
-                                 ETH_MTU, ip_data_len, saved_size - ETH_HLEN, 
large_send_mss));
-
-                    int tcp_send_offset = 0;
-                    int send_count = 0;
+                DEBUG_PRINT(("RTL8139: +++ C+ mode offloaded task TSO MTU=%d 
IP data %d frame data %d specified MSS=%d\n",
+                             ETH_MTU, ip_data_len, saved_size - ETH_HLEN, 
large_send_mss));
 
-                    /* maximum IP header length is 60 bytes */
-                    uint8_t saved_ip_header[60];
+                int tcp_send_offset = 0;
+                int send_count = 0;
 
-                    /* save IP header template; data area is used in tcp 
checksum calculation */
-                    memcpy(saved_ip_header, eth_payload_data, hlen);
+                /* maximum IP header length is 60 bytes */
+                uint8_t saved_ip_header[60];
 
-                    /* a placeholder for checksum calculation routine in tcp 
case */
-                    uint8_t *data_to_checksum     = eth_payload_data + hlen - 
12;
-                    //                    size_t   data_to_checksum_len = 
eth_payload_len  - hlen + 12;
+                /* save IP header template; data area is used in tcp checksum 
calculation */
+                memcpy(saved_ip_header, eth_payload_data, hlen);
 
-                    /* pointer to TCP header */
-                    tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + 
hlen);
+                /* a placeholder for checksum calculation routine in tcp case 
*/
+                uint8_t *data_to_checksum     = eth_payload_data + hlen - 12;
+                //                    size_t   data_to_checksum_len = 
eth_payload_len  - hlen + 12;
 
-                    int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);
+                /* pointer to TCP header */
+                tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + hlen);
 
-                    /* ETH_MTU = ip header len + tcp header len + payload */
-                    int tcp_data_len = ip_data_len - tcp_hlen;
-                    int tcp_chunk_size = ETH_MTU - hlen - tcp_hlen;
+                int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);
 
-                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP data len %d TCP 
hlen %d TCP data len %d TCP chunk size %d\n",
-                                 ip_data_len, tcp_hlen, tcp_data_len, 
tcp_chunk_size));
+                /* ETH_MTU = ip header len + tcp header len + payload */
+                int tcp_data_len = ip_data_len - tcp_hlen;
+                int tcp_chunk_size = ETH_MTU - hlen - tcp_hlen;
 
-                    /* note the cycle below overwrites IP header data,
-                       but restores it from saved_ip_header before sending 
packet */
+                DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP data len %d TCP hlen 
%d TCP data len %d TCP chunk size %d\n",
+                             ip_data_len, tcp_hlen, tcp_data_len, 
tcp_chunk_size));
 
-                    int is_last_frame = 0;
+                /* note the cycle below overwrites IP header data,
+                   but restores it from saved_ip_header before sending packet 
*/
 
-                    for (tcp_send_offset = 0; tcp_send_offset < tcp_data_len; 
tcp_send_offset += tcp_chunk_size)
-                    {
-                        uint16_t chunk_size = tcp_chunk_size;
+                int is_last_frame = 0;
 
-                        /* check if this is the last frame */
-                        if (tcp_send_offset + tcp_chunk_size >= tcp_data_len)
-                        {
-                            is_last_frame = 1;
-                            chunk_size = tcp_data_len - tcp_send_offset;
-                        }
+                for (tcp_send_offset = 0; tcp_send_offset < tcp_data_len; 
tcp_send_offset += tcp_chunk_size)
+                {
+                    uint16_t chunk_size = tcp_chunk_size;
 
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP seqno 
%08x\n", be32_to_cpu(p_tcp_hdr->th_seq)));
+                    /* check if this is the last frame */
+                    if (tcp_send_offset + tcp_chunk_size >= tcp_data_len)
+                    {
+                        is_last_frame = 1;
+                        chunk_size = tcp_data_len - tcp_send_offset;
+                    }
 
-                        /* add 4 TCP pseudoheader fields */
-                        /* copy IP source and destination fields */
-                        memcpy(data_to_checksum, saved_ip_header + 12, 8);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP seqno %08x\n", 
be32_to_cpu(p_tcp_hdr->th_seq)));
 
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TSO calculating TCP 
checksum for packet with %d bytes data\n", tcp_hlen + chunk_size));
+                    /* add 4 TCP pseudoheader fields */
+                    /* copy IP source and destination fields */
+                    memcpy(data_to_checksum, saved_ip_header + 12, 8);
 
-                        if (tcp_send_offset)
-                        {
-                            memcpy((uint8_t*)p_tcp_hdr + tcp_hlen, 
(uint8_t*)p_tcp_hdr + tcp_hlen + tcp_send_offset, chunk_size);
-                        }
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO calculating TCP 
checksum for packet with %d bytes data\n", tcp_hlen + chunk_size));
 
-                        /* keep PUSH and FIN flags only for the last frame */
-                        if (!is_last_frame)
-                        {
-                            TCP_HEADER_CLEAR_FLAGS(p_tcp_hdr, 
TCP_FLAG_PUSH|TCP_FLAG_FIN);
-                        }
+                    if (tcp_send_offset)
+                    {
+                        memcpy((uint8_t*)p_tcp_hdr + tcp_hlen, 
(uint8_t*)p_tcp_hdr + tcp_hlen + tcp_send_offset, chunk_size);
+                    }
 
-                        /* recalculate TCP checksum */
-                        ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
-                        p_tcpip_hdr->zeros      = 0;
-                        p_tcpip_hdr->ip_proto   = IP_PROTO_TCP;
-                        p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + 
chunk_size);
+                    /* keep PUSH and FIN flags only for the last frame */
+                    if (!is_last_frame)
+                    {
+                        TCP_HEADER_CLEAR_FLAGS(p_tcp_hdr, 
TCP_FLAG_PUSH|TCP_FLAG_FIN);
+                    }
 
-                        p_tcp_hdr->th_sum = 0;
+                    /* recalculate TCP checksum */
+                    ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
+                    p_tcpip_hdr->zeros      = 0;
+                    p_tcpip_hdr->ip_proto   = IP_PROTO_TCP;
+                    p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + 
chunk_size);
 
-                        int tcp_checksum = ip_checksum(data_to_checksum, 
tcp_hlen + chunk_size + 12);
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP checksum 
%04x\n", tcp_checksum));
+                    p_tcp_hdr->th_sum = 0;
 
-                        p_tcp_hdr->th_sum = tcp_checksum;
+                    int tcp_checksum = ip_checksum(data_to_checksum, tcp_hlen 
+ chunk_size + 12);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP checksum 
%04x\n", tcp_checksum));
 
-                        /* restore IP header */
-                        memcpy(eth_payload_data, saved_ip_header, hlen);
+                    p_tcp_hdr->th_sum = tcp_checksum;
 
-                        /* set IP data length and recalculate IP checksum */
-                        ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size);
+                    /* restore IP header */
+                    memcpy(eth_payload_data, saved_ip_header, hlen);
 
-                        /* increment IP id for subsequent frames */
-                        ip->ip_id = cpu_to_be16(tcp_send_offset/tcp_chunk_size 
+ be16_to_cpu(ip->ip_id));
+                    /* set IP data length and recalculate IP checksum */
+                    ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size);
 
-                        ip->ip_sum = 0;
-                        ip->ip_sum = ip_checksum(eth_payload_data, hlen);
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP header 
len=%d checksum=%04x\n", hlen, ip->ip_sum));
+                    /* increment IP id for subsequent frames */
+                    ip->ip_id = cpu_to_be16(tcp_send_offset/tcp_chunk_size + 
be16_to_cpu(ip->ip_id));
 
-                        int tso_send_size = ETH_HLEN + hlen + tcp_hlen + 
chunk_size;
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TSO transferring 
packet size %d\n", tso_send_size));
-                        rtl8139_transfer_frame(s, saved_buffer, tso_send_size, 
0);
+                    ip->ip_sum = 0;
+                    ip->ip_sum = ip_checksum(eth_payload_data, hlen);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP header len=%d 
checksum=%04x\n", hlen, ip->ip_sum));
 
-                        /* add transferred count to TCP sequence number */
-                        p_tcp_hdr->th_seq = cpu_to_be32(chunk_size + 
be32_to_cpu(p_tcp_hdr->th_seq));
-                        ++send_count;
-                    }
+                    int tso_send_size = ETH_HLEN + hlen + tcp_hlen + 
chunk_size;
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TSO transferring packet 
size %d\n", tso_send_size));
+                    rtl8139_transfer_frame(s, saved_buffer, tso_send_size, 0);
 
-                    /* Stop sending this frame */
-                    saved_size = 0;
+                    /* add transferred count to TCP sequence number */
+                    p_tcp_hdr->th_seq = cpu_to_be32(chunk_size + 
be32_to_cpu(p_tcp_hdr->th_seq));
+                    ++send_count;
                 }
-                else if (txdw0 & (CP_TX_TCPCS|CP_TX_UDPCS))
-                {
-                    DEBUG_PRINT(("RTL8139: +++ C+ mode need TCP or UDP 
checksum\n"));
 
-                    /* maximum IP header length is 60 bytes */
-                    uint8_t saved_ip_header[60];
-                    memcpy(saved_ip_header, eth_payload_data, hlen);
+                /* Stop sending this frame */
+                saved_size = 0;
+            }
+            else if (txdw0 & (CP_TX_TCPCS|CP_TX_UDPCS))
+            {
+                DEBUG_PRINT(("RTL8139: +++ C+ mode need TCP or UDP 
checksum\n"));
 
-                    uint8_t *data_to_checksum     = eth_payload_data + hlen - 
12;
-                    //                    size_t   data_to_checksum_len = 
eth_payload_len  - hlen + 12;
+                /* maximum IP header length is 60 bytes */
+                uint8_t saved_ip_header[60];
+                memcpy(saved_ip_header, eth_payload_data, hlen);
 
-                    /* add 4 TCP pseudoheader fields */
-                    /* copy IP source and destination fields */
-                    memcpy(data_to_checksum, saved_ip_header + 12, 8);
+                uint8_t *data_to_checksum     = eth_payload_data + hlen - 12;
+                //                    size_t   data_to_checksum_len = 
eth_payload_len  - hlen + 12;
 
-                    if ((txdw0 & CP_TX_TCPCS) && ip_protocol == IP_PROTO_TCP)
-                    {
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode calculating TCP 
checksum for packet with %d bytes data\n", ip_data_len));
+                /* add 4 TCP pseudoheader fields */
+                /* copy IP source and destination fields */
+                memcpy(data_to_checksum, saved_ip_header + 12, 8);
 
-                        ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
-                        p_tcpip_hdr->zeros      = 0;
-                        p_tcpip_hdr->ip_proto   = IP_PROTO_TCP;
-                        p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
+                if ((txdw0 & CP_TX_TCPCS) && ip_protocol == IP_PROTO_TCP)
+                {
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode calculating TCP 
checksum for packet with %d bytes data\n", ip_data_len));
 
-                        tcp_header* p_tcp_hdr = (tcp_header *) 
(data_to_checksum+12);
+                    ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
+                    p_tcpip_hdr->zeros      = 0;
+                    p_tcpip_hdr->ip_proto   = IP_PROTO_TCP;
+                    p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
 
-                        p_tcp_hdr->th_sum = 0;
+                    tcp_header* p_tcp_hdr = (tcp_header *) 
(data_to_checksum+12);
 
-                        int tcp_checksum = ip_checksum(data_to_checksum, 
ip_data_len + 12);
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode TCP checksum 
%04x\n", tcp_checksum));
+                    p_tcp_hdr->th_sum = 0;
 
-                        p_tcp_hdr->th_sum = tcp_checksum;
-                    }
-                    else if ((txdw0 & CP_TX_UDPCS) && ip_protocol == 
IP_PROTO_UDP)
-                    {
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode calculating UDP 
checksum for packet with %d bytes data\n", ip_data_len));
+                    int tcp_checksum = ip_checksum(data_to_checksum, 
ip_data_len + 12);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode TCP checksum %04x\n", 
tcp_checksum));
 
-                        ip_pseudo_header *p_udpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
-                        p_udpip_hdr->zeros      = 0;
-                        p_udpip_hdr->ip_proto   = IP_PROTO_UDP;
-                        p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
+                    p_tcp_hdr->th_sum = tcp_checksum;
+                }
+                else if ((txdw0 & CP_TX_UDPCS) && ip_protocol == IP_PROTO_UDP)
+                {
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode calculating UDP 
checksum for packet with %d bytes data\n", ip_data_len));
 
-                        udp_header *p_udp_hdr = (udp_header *) 
(data_to_checksum+12);
+                    ip_pseudo_header *p_udpip_hdr = (ip_pseudo_header 
*)data_to_checksum;
+                    p_udpip_hdr->zeros      = 0;
+                    p_udpip_hdr->ip_proto   = IP_PROTO_UDP;
+                    p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len);
 
-                        p_udp_hdr->uh_sum = 0;
+                    udp_header *p_udp_hdr = (udp_header *) 
(data_to_checksum+12);
 
-                        int udp_checksum = ip_checksum(data_to_checksum, 
ip_data_len + 12);
-                        DEBUG_PRINT(("RTL8139: +++ C+ mode UDP checksum 
%04x\n", udp_checksum));
+                    p_udp_hdr->uh_sum = 0;
 
-                        p_udp_hdr->uh_sum = udp_checksum;
-                    }
+                    int udp_checksum = ip_checksum(data_to_checksum, 
ip_data_len + 12);
+                    DEBUG_PRINT(("RTL8139: +++ C+ mode UDP checksum %04x\n", 
udp_checksum));
 
-                    /* restore IP header */
-                    memcpy(eth_payload_data, saved_ip_header, hlen);
+                    p_udp_hdr->uh_sum = udp_checksum;
                 }
+
+                /* restore IP header */
+                memcpy(eth_payload_data, saved_ip_header, hlen);
             }
         }
 
--
generated by git-patchbot for /home/xen/git/qemu-xen-traditional.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.