Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / infiniband / hw / hfi1 / ipoib_rx.c
blob629691a572efe47c7c1eaa7e52c9effcf85ef0db
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 /*
3 * Copyright(c) 2020 Intel Corporation.
5 */
7 #include "netdev.h"
8 #include "ipoib.h"
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)
24 struct sk_buff *skb;
25 int skb_size = SKB_DATA_ALIGN(size + HFI1_IPOIB_SKB_PAD);
26 void *frag;
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);
32 if (unlikely(!frag))
33 return napi_alloc_skb(napi, size);
35 skb = build_skb(frag, skb_size);
37 if (unlikely(!skb)) {
38 skb_free_frag(frag);
39 return NULL;
42 skb_reserve(skb, HFI1_IPOIB_SKB_PAD);
43 return skb;
46 struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
47 int size, void *data)
49 struct napi_struct *napi = &rxq->napi;
50 int skb_size = size + HFI1_IPOIB_ENCAP_LEN;
51 struct sk_buff *skb;
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);
59 else
60 skb = prepare_frag_skb(napi, skb_size);
62 if (unlikely(!skb))
63 return NULL;
65 copy_ipoib_buf(skb, data, size);
67 return skb;
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;
74 int ret;
76 ret = hfi1_netdev_rx_init(dd);
77 if (ret)
78 return ret;
80 hfi1_init_aip_rsm(dd);
82 return ret;
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);