LCOV - code coverage report
Current view: top level - net/core - tso.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 0 52 0.0 %
Date: 2021-04-22 12:43:58 Functions: 0 4 0.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : #include <linux/export.h>
       3             : #include <linux/if_vlan.h>
       4             : #include <net/ip.h>
       5             : #include <net/tso.h>
       6             : #include <asm/unaligned.h>
       7             : 
       8             : /* Calculate expected number of TX descriptors */
       9           0 : int tso_count_descs(const struct sk_buff *skb)
      10             : {
      11             :         /* The Marvell Way */
      12           0 :         return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
      13             : }
      14             : EXPORT_SYMBOL(tso_count_descs);
      15             : 
      16           0 : void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
      17             :                    int size, bool is_last)
      18             : {
      19           0 :         int hdr_len = skb_transport_offset(skb) + tso->tlen;
      20           0 :         int mac_hdr_len = skb_network_offset(skb);
      21             : 
      22           0 :         memcpy(hdr, skb->data, hdr_len);
      23           0 :         if (!tso->ipv6) {
      24           0 :                 struct iphdr *iph = (void *)(hdr + mac_hdr_len);
      25             : 
      26           0 :                 iph->id = htons(tso->ip_id);
      27           0 :                 iph->tot_len = htons(size + hdr_len - mac_hdr_len);
      28           0 :                 tso->ip_id++;
      29             :         } else {
      30           0 :                 struct ipv6hdr *iph = (void *)(hdr + mac_hdr_len);
      31             : 
      32           0 :                 iph->payload_len = htons(size + tso->tlen);
      33             :         }
      34           0 :         hdr += skb_transport_offset(skb);
      35           0 :         if (tso->tlen != sizeof(struct udphdr)) {
      36           0 :                 struct tcphdr *tcph = (struct tcphdr *)hdr;
      37             : 
      38           0 :                 put_unaligned_be32(tso->tcp_seq, &tcph->seq);
      39             : 
      40           0 :                 if (!is_last) {
      41             :                         /* Clear all special flags for not last packet */
      42           0 :                         tcph->psh = 0;
      43           0 :                         tcph->fin = 0;
      44           0 :                         tcph->rst = 0;
      45             :                 }
      46             :         } else {
      47           0 :                 struct udphdr *uh = (struct udphdr *)hdr;
      48             : 
      49           0 :                 uh->len = htons(sizeof(*uh) + size);
      50             :         }
      51           0 : }
      52             : EXPORT_SYMBOL(tso_build_hdr);
      53             : 
      54           0 : void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size)
      55             : {
      56           0 :         tso->tcp_seq += size; /* not worth avoiding this operation for UDP */
      57           0 :         tso->size -= size;
      58           0 :         tso->data += size;
      59             : 
      60           0 :         if ((tso->size == 0) &&
      61           0 :             (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
      62           0 :                 skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
      63             : 
      64             :                 /* Move to next segment */
      65           0 :                 tso->size = skb_frag_size(frag);
      66           0 :                 tso->data = skb_frag_address(frag);
      67           0 :                 tso->next_frag_idx++;
      68             :         }
      69           0 : }
      70             : EXPORT_SYMBOL(tso_build_data);
      71             : 
      72           0 : int tso_start(struct sk_buff *skb, struct tso_t *tso)
      73             : {
      74           0 :         int tlen = skb_is_gso_tcp(skb) ? tcp_hdrlen(skb) : sizeof(struct udphdr);
      75           0 :         int hdr_len = skb_transport_offset(skb) + tlen;
      76             : 
      77           0 :         tso->tlen = tlen;
      78           0 :         tso->ip_id = ntohs(ip_hdr(skb)->id);
      79           0 :         tso->tcp_seq = (tlen != sizeof(struct udphdr)) ? ntohl(tcp_hdr(skb)->seq) : 0;
      80           0 :         tso->next_frag_idx = 0;
      81           0 :         tso->ipv6 = vlan_get_protocol(skb) == htons(ETH_P_IPV6);
      82             : 
      83             :         /* Build first data */
      84           0 :         tso->size = skb_headlen(skb) - hdr_len;
      85           0 :         tso->data = skb->data + hdr_len;
      86           0 :         if ((tso->size == 0) &&
      87           0 :             (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
      88           0 :                 skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
      89             : 
      90             :                 /* Move to next segment */
      91           0 :                 tso->size = skb_frag_size(frag);
      92           0 :                 tso->data = skb_frag_address(frag);
      93           0 :                 tso->next_frag_idx++;
      94             :         }
      95           0 :         return hdr_len;
      96             : }
      97             : EXPORT_SYMBOL(tso_start);

Generated by: LCOV version 1.14