compat: Fix autoconf probe for pcie_mpss
[~emulex/for-vlad/old/compat.git] / compat / compat-3.3.c
1 /*
2  * Copyright 2012  Luis R. Rodriguez <mcgrof@frijolero.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Compatibility file for Linux wireless for kernels 3.3.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/version.h>
13 #include <linux/skbuff.h>
14 #include <linux/module.h>
15 #include <net/dst.h>
16 #include <net/xfrm.h>
17
18 static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
19 {
20         new->tstamp             = old->tstamp;
21         new->dev                = old->dev;
22         new->transport_header   = old->transport_header;
23         new->network_header     = old->network_header;
24         new->mac_header         = old->mac_header;
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
26         skb_dst_copy(new, old);
27         new->rxhash             = old->rxhash;
28 #else
29         skb_dst_set(new, dst_clone(skb_dst(old)));
30 #endif
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0))
32         new->ooo_okay           = old->ooo_okay;
33 #endif
34 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
35         new->l4_rxhash          = old->l4_rxhash;
36 #endif
37 #ifdef CONFIG_XFRM
38         new->sp                 = secpath_get(old->sp);
39 #endif
40         memcpy(new->cb, old->cb, sizeof(old->cb));
41         new->csum               = old->csum;
42         new->local_df           = old->local_df;
43         new->pkt_type           = old->pkt_type;
44         new->ip_summed          = old->ip_summed;
45         skb_copy_queue_mapping(new, old);
46         new->priority           = old->priority;
47 #if IS_ENABLED(CONFIG_IP_VS)
48         new->ipvs_property      = old->ipvs_property;
49 #endif
50         new->protocol           = old->protocol;
51         new->mark               = old->mark;
52 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
53         new->skb_iif            = old->skb_iif;
54 #endif
55         __nf_copy(new, old);
56 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
57         new->nf_trace           = old->nf_trace;
58 #endif
59 #ifdef CONFIG_NET_SCHED
60         new->tc_index           = old->tc_index;
61 #ifdef CONFIG_NET_CLS_ACT
62         new->tc_verd            = old->tc_verd;
63 #endif
64 #endif
65 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
66         new->vlan_tci           = old->vlan_tci;
67 #endif
68
69         skb_copy_secmark(new, old);
70 }
71
72 static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
73 {
74 #ifndef NET_SKBUFF_DATA_USES_OFFSET
75         /*
76          *      Shift between the two data areas in bytes
77          */
78         unsigned long offset = new->data - old->data;
79 #endif
80
81         __copy_skb_header(new, old);
82
83 #ifndef NET_SKBUFF_DATA_USES_OFFSET
84         /* {transport,network,mac}_header are relative to skb->head */
85         new->transport_header += offset;
86         new->network_header   += offset;
87         if (skb_mac_header_was_set(new))
88                 new->mac_header       += offset;
89 #endif
90         skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
91         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
92         skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
93 }
94
95 static void skb_clone_fraglist(struct sk_buff *skb)
96 {
97         struct sk_buff *list;
98
99         skb_walk_frags(skb, list)
100                 skb_get(list);
101 }
102
103
104 /**
105  *      __pskb_copy     -       create copy of an sk_buff with private head.
106  *      @skb: buffer to copy
107  *      @headroom: headroom of new skb
108  *      @gfp_mask: allocation priority
109  *
110  *      Make a copy of both an &sk_buff and part of its data, located
111  *      in header. Fragmented data remain shared. This is used when
112  *      the caller wishes to modify only header of &sk_buff and needs
113  *      private copy of the header to alter. Returns %NULL on failure
114  *      or the pointer to the buffer on success.
115  *      The returned buffer has a reference count of 1.
116  */
117
118 struct sk_buff *__pskb_copy(struct sk_buff *skb, int headroom, gfp_t gfp_mask)
119 {
120         unsigned int size = skb_headlen(skb) + headroom;
121         struct sk_buff *n = alloc_skb(size, gfp_mask);
122
123         if (!n)
124                 goto out;
125
126         /* Set the data pointer */
127         skb_reserve(n, headroom);
128         /* Set the tail pointer and length */
129         skb_put(n, skb_headlen(skb));
130         /* Copy the bytes */
131         skb_copy_from_linear_data(skb, n->data, n->len);
132
133         n->truesize += skb->data_len;
134         n->data_len  = skb->data_len;
135         n->len       = skb->len;
136
137         if (skb_shinfo(skb)->nr_frags) {
138                 int i;
139
140 /*
141  * SKBTX_DEV_ZEROCOPY was added on 3.1 as well but requires ubuf
142  * stuff added to the skb which we do not have
143  */
144 #if 0
145                 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
146                         if (skb_copy_ubufs(skb, gfp_mask)) {
147                                 kfree_skb(n);
148                                 n = NULL;
149                                 goto out;
150                         }
151                 }
152 #endif
153                 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
154                         skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i];
155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
156                         skb_frag_ref(skb, i);
157 #else
158                         get_page(skb_shinfo(skb)->frags[i].page);
159 #endif
160                 }
161                 skb_shinfo(n)->nr_frags = i;
162         }
163
164         if (skb_has_frag_list(skb)) {
165                 skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
166                 skb_clone_fraglist(n);
167         }
168
169         copy_skb_header(n, skb);
170 out:
171         return n;
172 }
173 EXPORT_SYMBOL_GPL(__pskb_copy);