1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * Copyright(c) 2020 Intel Corporation.
10 #define HFI1_IPOIB_SKB_PAD ((NET_SKB_PAD) + (NET_IP_ALIGN))
12 static void copy_ipoib_buf(struct sk_buff
*skb
, void *data
, int size
)
14 skb_checksum_none_assert(skb
);
15 skb
->protocol
= *((__be16
*)data
);
17 skb_put_data(skb
, data
, size
);
18 skb
->mac_header
= HFI1_IPOIB_PSEUDO_LEN
;
19 skb_pull(skb
, HFI1_IPOIB_ENCAP_LEN
);
22 static struct sk_buff
*prepare_frag_skb(struct napi_struct
*napi
, int size
)
25 int skb_size
= SKB_DATA_ALIGN(size
+ HFI1_IPOIB_SKB_PAD
);
28 skb_size
+= SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
29 skb_size
= SKB_DATA_ALIGN(skb_size
);
30 frag
= napi_alloc_frag(skb_size
);
33 return napi_alloc_skb(napi
, size
);
35 skb
= build_skb(frag
, skb_size
);
42 skb_reserve(skb
, HFI1_IPOIB_SKB_PAD
);
46 struct sk_buff
*hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq
*rxq
,
49 struct napi_struct
*napi
= &rxq
->napi
;
50 int skb_size
= size
+ HFI1_IPOIB_ENCAP_LEN
;
54 * For smaller(4k + skb overhead) allocations we will go using
55 * napi cache. Otherwise we will try to use napi frag cache.
57 if (size
<= SKB_WITH_OVERHEAD(PAGE_SIZE
))
58 skb
= napi_alloc_skb(napi
, skb_size
);
60 skb
= prepare_frag_skb(napi
, skb_size
);
65 copy_ipoib_buf(skb
, data
, size
);
70 int hfi1_ipoib_rxq_init(struct net_device
*netdev
)
72 struct hfi1_ipoib_dev_priv
*ipoib_priv
= hfi1_ipoib_priv(netdev
);
73 struct hfi1_devdata
*dd
= ipoib_priv
->dd
;
76 ret
= hfi1_netdev_rx_init(dd
);
80 hfi1_init_aip_rsm(dd
);
85 void hfi1_ipoib_rxq_deinit(struct net_device
*netdev
)
87 struct hfi1_ipoib_dev_priv
*ipoib_priv
= hfi1_ipoib_priv(netdev
);
88 struct hfi1_devdata
*dd
= ipoib_priv
->dd
;
90 hfi1_deinit_aip_rsm(dd
);
91 hfi1_netdev_rx_destroy(dd
);