xref: /openbmc/linux/drivers/infiniband/hw/hfi1/ipoib.h (revision 82df5b73)
1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /*
3  * Copyright(c) 2020 Intel Corporation.
4  *
5  */
6 
7 /*
8  * This file contains HFI1 support for IPOIB functionality
9  */
10 
11 #ifndef HFI1_IPOIB_H
12 #define HFI1_IPOIB_H
13 
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>
22 
23 #include "hfi.h"
24 #include "iowait.h"
25 #include "netdev.h"
26 
27 #include <rdma/ib_verbs.h>
28 
29 #define HFI1_IPOIB_ENTROPY_SHIFT   24
30 
31 #define HFI1_IPOIB_TXREQ_NAME_LEN   32
32 
33 #define HFI1_IPOIB_PSEUDO_LEN 20
34 #define HFI1_IPOIB_ENCAP_LEN 4
35 
36 struct hfi1_ipoib_dev_priv;
37 
38 union hfi1_ipoib_flow {
39 	u16 as_int;
40 	struct {
41 		u8 tx_queue;
42 		u8 sc5;
43 	} __attribute__((__packed__));
44 };
45 
46 /**
47  * struct hfi1_ipoib_circ_buf - List of items to be processed
48  * @items: ring of items
49  * @head: ring head
50  * @tail: ring tail
51  * @max_items: max items + 1 that the ring can contain
52  * @producer_lock: producer sync lock
53  * @consumer_lock: consumer sync lock
54  */
55 struct hfi1_ipoib_circ_buf {
56 	void **items;
57 	unsigned long head;
58 	unsigned long tail;
59 	unsigned long max_items;
60 	spinlock_t producer_lock; /* head sync lock */
61 	spinlock_t consumer_lock; /* tail sync lock */
62 };
63 
64 /**
65  * struct hfi1_ipoib_txq - IPOIB per Tx queue information
66  * @priv: private pointer
67  * @sde: sdma engine
68  * @tx_list: tx request list
69  * @sent_txreqs: count of txreqs posted to sdma
70  * @flow: tracks when list needs to be flushed for a flow change
71  * @q_idx: ipoib Tx queue index
72  * @pkts_sent: indicator packets have been sent from this queue
73  * @wait: iowait structure
74  * @complete_txreqs: count of txreqs completed by sdma
75  * @napi: pointer to tx napi interface
76  * @tx_ring: ring of ipoib txreqs to be reaped by napi callback
77  */
78 struct hfi1_ipoib_txq {
79 	struct hfi1_ipoib_dev_priv *priv;
80 	struct sdma_engine *sde;
81 	struct list_head tx_list;
82 	u64 sent_txreqs;
83 	union hfi1_ipoib_flow flow;
84 	u8 q_idx;
85 	bool pkts_sent;
86 	struct iowait wait;
87 
88 	atomic64_t ____cacheline_aligned_in_smp complete_txreqs;
89 	struct napi_struct *napi;
90 	struct hfi1_ipoib_circ_buf tx_ring;
91 };
92 
93 struct hfi1_ipoib_dev_priv {
94 	struct hfi1_devdata *dd;
95 	struct net_device   *netdev;
96 	struct ib_device    *device;
97 	struct hfi1_ipoib_txq *txqs;
98 	struct kmem_cache *txreq_cache;
99 	struct napi_struct *tx_napis;
100 	u16 pkey;
101 	u16 pkey_index;
102 	u32 qkey;
103 	u8 port_num;
104 
105 	const struct net_device_ops *netdev_ops;
106 	struct rvt_qp *qp;
107 	struct pcpu_sw_netstats __percpu *netstats;
108 };
109 
110 /* hfi1 ipoib rdma netdev's private data structure */
111 struct hfi1_ipoib_rdma_netdev {
112 	struct rdma_netdev rn;  /* keep this first */
113 	/* followed by device private data */
114 	struct hfi1_ipoib_dev_priv dev_priv;
115 };
116 
117 static inline struct hfi1_ipoib_dev_priv *
118 hfi1_ipoib_priv(const struct net_device *dev)
119 {
120 	return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv;
121 }
122 
123 static inline void
124 hfi1_ipoib_update_rx_netstats(struct hfi1_ipoib_dev_priv *priv,
125 			      u64 packets,
126 			      u64 bytes)
127 {
128 	struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
129 
130 	u64_stats_update_begin(&netstats->syncp);
131 	netstats->rx_packets += packets;
132 	netstats->rx_bytes += bytes;
133 	u64_stats_update_end(&netstats->syncp);
134 }
135 
136 static inline void
137 hfi1_ipoib_update_tx_netstats(struct hfi1_ipoib_dev_priv *priv,
138 			      u64 packets,
139 			      u64 bytes)
140 {
141 	struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
142 
143 	u64_stats_update_begin(&netstats->syncp);
144 	netstats->tx_packets += packets;
145 	netstats->tx_bytes += bytes;
146 	u64_stats_update_end(&netstats->syncp);
147 }
148 
149 int hfi1_ipoib_send_dma(struct net_device *dev,
150 			struct sk_buff *skb,
151 			struct ib_ah *address,
152 			u32 dqpn);
153 
154 int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
155 void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
156 
157 int hfi1_ipoib_rxq_init(struct net_device *dev);
158 void hfi1_ipoib_rxq_deinit(struct net_device *dev);
159 
160 void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
161 void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
162 
163 struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
164 				       int size, void *data);
165 
166 int hfi1_ipoib_rn_get_params(struct ib_device *device,
167 			     u8 port_num,
168 			     enum rdma_netdev_t type,
169 			     struct rdma_netdev_alloc_params *params);
170 
171 #endif /* _IPOIB_H */
172