1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
3 * Copyright(c) 2020 Intel Corporation.
8 * This file contains HFI1 support for IPOIB functionality
14 #include <linux/types.h>
15 #include <linux/stddef.h>
16 #include <linux/atomic.h>
17 #include <linux/netdevice.h>
18 #include <linux/slab.h>
19 #include <linux/skbuff.h>
20 #include <linux/list.h>
21 #include <linux/if_infiniband.h>
27 #include <rdma/ib_verbs.h>
29 #define HFI1_IPOIB_ENTROPY_SHIFT 24
31 #define HFI1_IPOIB_TXREQ_NAME_LEN 32
33 #define HFI1_IPOIB_PSEUDO_LEN 20
34 #define HFI1_IPOIB_ENCAP_LEN 4
36 struct hfi1_ipoib_dev_priv;
38 union hfi1_ipoib_flow {
43 } __attribute__((__packed__));
47 * struct hfi1_ipoib_circ_buf - List of items to be processed
48 * @items: ring of items
51 * @max_items: max items + 1 that the ring can contain
52 * @producer_lock: producer sync lock
53 * @consumer_lock: consumer sync lock
56 struct hfi1_ipoib_circ_buf {
57 struct ipoib_txreq **items;
60 unsigned long max_items;
61 spinlock_t producer_lock; /* head sync lock */
62 spinlock_t consumer_lock; /* tail sync lock */
66 * struct hfi1_ipoib_txq - IPOIB per Tx queue information
67 * @priv: private pointer
69 * @tx_list: tx request list
70 * @sent_txreqs: count of txreqs posted to sdma
71 * @stops: count of stops of queue
72 * @ring_full: ring has been filled
73 * @no_desc: descriptor shortage seen
74 * @flow: tracks when list needs to be flushed for a flow change
75 * @q_idx: ipoib Tx queue index
76 * @pkts_sent: indicator packets have been sent from this queue
77 * @wait: iowait structure
78 * @complete_txreqs: count of txreqs completed by sdma
79 * @napi: pointer to tx napi interface
80 * @tx_ring: ring of ipoib txreqs to be reaped by napi callback
82 struct hfi1_ipoib_txq {
83 struct hfi1_ipoib_dev_priv *priv;
84 struct sdma_engine *sde;
85 struct list_head tx_list;
90 union hfi1_ipoib_flow flow;
95 atomic64_t ____cacheline_aligned_in_smp complete_txreqs;
96 struct napi_struct *napi;
97 struct hfi1_ipoib_circ_buf tx_ring;
100 struct hfi1_ipoib_dev_priv {
101 struct hfi1_devdata *dd;
102 struct net_device *netdev;
103 struct ib_device *device;
104 struct hfi1_ipoib_txq *txqs;
105 struct kmem_cache *txreq_cache;
106 struct napi_struct *tx_napis;
112 const struct net_device_ops *netdev_ops;
114 struct pcpu_sw_netstats __percpu *netstats;
117 /* hfi1 ipoib rdma netdev's private data structure */
118 struct hfi1_ipoib_rdma_netdev {
119 struct rdma_netdev rn; /* keep this first */
120 /* followed by device private data */
121 struct hfi1_ipoib_dev_priv dev_priv;
124 static inline struct hfi1_ipoib_dev_priv *
125 hfi1_ipoib_priv(const struct net_device *dev)
127 return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv;
131 hfi1_ipoib_update_rx_netstats(struct hfi1_ipoib_dev_priv *priv,
135 struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
137 u64_stats_update_begin(&netstats->syncp);
138 netstats->rx_packets += packets;
139 netstats->rx_bytes += bytes;
140 u64_stats_update_end(&netstats->syncp);
144 hfi1_ipoib_update_tx_netstats(struct hfi1_ipoib_dev_priv *priv,
148 struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
150 u64_stats_update_begin(&netstats->syncp);
151 netstats->tx_packets += packets;
152 netstats->tx_bytes += bytes;
153 u64_stats_update_end(&netstats->syncp);
156 int hfi1_ipoib_send_dma(struct net_device *dev,
158 struct ib_ah *address,
161 int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
162 void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
164 int hfi1_ipoib_rxq_init(struct net_device *dev);
165 void hfi1_ipoib_rxq_deinit(struct net_device *dev);
167 void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
168 void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
170 struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
171 int size, void *data);
173 int hfi1_ipoib_rn_get_params(struct ib_device *device,
175 enum rdma_netdev_t type,
176 struct rdma_netdev_alloc_params *params);
178 #endif /* _IPOIB_H */