xref: /linux/net/smc/smc_core.h (revision c31f4aa8fed048fa70e742c4bb49bb48dc489ab3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Shared Memory Communications over RDMA (SMC-R) and RoCE
4  *
5  *  Definitions for SMC Connections, Link Groups and Links
6  *
7  *  Copyright IBM Corp. 2016
8  *
9  *  Author(s):  Ursula Braun <ubraun@linux.vnet.ibm.com>
10  */
11 
12 #ifndef _SMC_CORE_H
13 #define _SMC_CORE_H
14 
15 #include <linux/atomic.h>
16 #include <linux/types.h>
17 #include <linux/smc.h>
18 #include <linux/pci.h>
19 #include <rdma/ib_verbs.h>
20 #include <net/genetlink.h>
21 #include <net/smc.h>
22 
23 #include "smc.h"
24 #include "smc_ib.h"
25 #include "smc_clc.h"
26 
27 #define SMC_RMBS_PER_LGR_MAX	255	/* max. # of RMBs per link group */
28 #define SMC_CONN_PER_LGR_MIN	16	/* min. # of connections per link group */
29 #define SMC_CONN_PER_LGR_MAX	255	/* max. # of connections per link group,
30 					 * also is the default value for SMC-R v1 and v2.0
31 					 */
32 #define SMC_CONN_PER_LGR_PREFER	255	/* Preferred connections per link group used for
33 					 * SMC-R v2.1 and later negotiation, vendors or
34 					 * distributions may modify it to a value between
35 					 * 16-255 as needed.
36 					 */
37 #define SMCR_MAX_SEND_WR_DEF	16	/* Default number of work requests per send queue */
38 #define SMCR_MAX_RECV_WR_DEF	48	/* Default number of work requests per recv queue */
39 
40 struct smc_lgr_list {			/* list of link group definition */
41 	struct list_head	list;
42 	spinlock_t		lock;	/* protects list of link groups */
43 	u32			num;	/* unique link group number */
44 };
45 
46 enum smc_lgr_role {		/* possible roles of a link group */
47 	SMC_CLNT,	/* client */
48 	SMC_SERV	/* server */
49 };
50 
51 enum smc_link_state {			/* possible states of a link */
52 	SMC_LNK_UNUSED,		/* link is unused */
53 	SMC_LNK_INACTIVE,	/* link is inactive */
54 	SMC_LNK_ACTIVATING,	/* link is being activated */
55 	SMC_LNK_ACTIVE,		/* link is active */
56 };
57 
58 #define SMC_WR_BUF_SIZE		48	/* size of work request buffer */
59 #define SMC_WR_BUF_V2_SIZE	8192	/* size of v2 work request buffer */
60 
61 struct smc_wr_buf {
62 	u8	raw[SMC_WR_BUF_SIZE];
63 };
64 
65 struct smc_wr_v2_buf {
66 	u8	raw[SMC_WR_BUF_V2_SIZE];
67 };
68 
69 #define SMC_WR_REG_MR_WAIT_TIME	(5 * HZ)/* wait time for ib_wr_reg_mr result */
70 
71 enum smc_wr_reg_state {
72 	POSTED,		/* ib_wr_reg_mr request posted */
73 	CONFIRMED,	/* ib_wr_reg_mr response: successful */
74 	FAILED		/* ib_wr_reg_mr response: failure */
75 };
76 
77 struct smc_rdma_sge {				/* sges for RDMA writes */
78 	struct ib_sge		wr_tx_rdma_sge[SMC_IB_MAX_SEND_SGE];
79 };
80 
81 #define SMC_MAX_RDMA_WRITES	2		/* max. # of RDMA writes per
82 						 * message send
83 						 */
84 
85 struct smc_rdma_sges {				/* sges per message send */
86 	struct smc_rdma_sge	tx_rdma_sge[SMC_MAX_RDMA_WRITES];
87 };
88 
89 struct smc_rdma_wr {				/* work requests per message
90 						 * send
91 						 */
92 	struct ib_rdma_wr	wr_tx_rdma[SMC_MAX_RDMA_WRITES];
93 };
94 
95 #define SMC_LGR_ID_SIZE		4
96 
97 struct smc_link {
98 	struct smc_ib_device	*smcibdev;	/* ib-device */
99 	u8			ibport;		/* port - values 1 | 2 */
100 	struct ib_pd		*roce_pd;	/* IB protection domain,
101 						 * unique for every RoCE QP
102 						 */
103 	struct ib_qp		*roce_qp;	/* IB queue pair */
104 	struct ib_qp_attr	qp_attr;	/* IB queue pair attributes */
105 
106 	struct smc_wr_buf	*wr_tx_bufs;	/* WR send payload buffers */
107 	struct ib_send_wr	*wr_tx_ibs;	/* WR send meta data */
108 	struct ib_sge		*wr_tx_sges;	/* WR send gather meta data */
109 	struct smc_rdma_sges	*wr_tx_rdma_sges;/*RDMA WRITE gather meta data*/
110 	struct smc_rdma_wr	*wr_tx_rdmas;	/* WR RDMA WRITE */
111 	struct smc_wr_tx_pend	*wr_tx_pends;	/* WR send waiting for CQE */
112 	struct completion	*wr_tx_compl;	/* WR send CQE completion */
113 	/* above four vectors have wr_tx_cnt elements and use the same index */
114 	struct ib_send_wr	*wr_tx_v2_ib;	/* WR send v2 meta data */
115 	struct ib_sge		*wr_tx_v2_sge;	/* WR send v2 gather meta data*/
116 	struct smc_wr_tx_pend	*wr_tx_v2_pend;	/* WR send v2 waiting for CQE */
117 	dma_addr_t		wr_tx_dma_addr;	/* DMA address of wr_tx_bufs */
118 	dma_addr_t		wr_tx_v2_dma_addr; /* DMA address of v2 tx buf*/
119 	atomic_long_t		wr_tx_id;	/* seq # of last sent WR */
120 	unsigned long		*wr_tx_mask;	/* bit mask of used indexes */
121 	u32			wr_tx_cnt;	/* number of WR send buffers */
122 	wait_queue_head_t	wr_tx_wait;	/* wait for free WR send buf */
123 	struct {
124 		struct percpu_ref	wr_tx_refs;
125 	} ____cacheline_aligned_in_smp;
126 	struct completion	tx_ref_comp;
127 
128 	u8			*wr_rx_bufs;	/* WR recv payload buffers */
129 	struct ib_recv_wr	*wr_rx_ibs;	/* WR recv meta data */
130 	struct ib_sge		*wr_rx_sges;	/* WR recv scatter meta data */
131 	/* above three vectors have wr_rx_cnt elements and use the same index */
132 	int			wr_rx_sge_cnt; /* rx sge, V1 is 1, V2 is either 2 or 1 */
133 	int			wr_rx_buflen;	/* buffer len for the first sge, len for the
134 						 * second sge is lgr shared if rx sge is 2.
135 						 */
136 	dma_addr_t		wr_rx_dma_addr;	/* DMA address of wr_rx_bufs */
137 	dma_addr_t		wr_rx_v2_dma_addr; /* DMA address of v2 rx buf*/
138 	u64			wr_rx_id;	/* seq # of last recv WR */
139 	u64			wr_rx_id_compl; /* seq # of last completed WR */
140 	u32			wr_rx_cnt;	/* number of WR recv buffers */
141 	unsigned long		wr_rx_tstamp;	/* jiffies when last buf rx */
142 	wait_queue_head_t       wr_rx_empty_wait; /* wait for RQ empty */
143 
144 	struct ib_reg_wr	wr_reg;		/* WR register memory region */
145 	wait_queue_head_t	wr_reg_wait;	/* wait for wr_reg result */
146 	struct {
147 		struct percpu_ref	wr_reg_refs;
148 	} ____cacheline_aligned_in_smp;
149 	struct completion	reg_ref_comp;
150 	enum smc_wr_reg_state	wr_reg_state;	/* state of wr_reg request */
151 
152 	u8			gid[SMC_GID_SIZE];/* gid matching used vlan id*/
153 	u8			sgid_index;	/* gid index for vlan id      */
154 	u32			peer_qpn;	/* QP number of peer */
155 	enum ib_mtu		path_mtu;	/* used mtu */
156 	enum ib_mtu		peer_mtu;	/* mtu size of peer */
157 	u32			psn_initial;	/* QP tx initial packet seqno */
158 	u32			peer_psn;	/* QP rx initial packet seqno */
159 	u8			peer_mac[ETH_ALEN];	/* = gid[8:10||13:15] */
160 	u8			peer_gid[SMC_GID_SIZE];	/* gid of peer*/
161 	u8			link_id;	/* unique # within link group */
162 	u8			link_uid[SMC_LGR_ID_SIZE]; /* unique lnk id */
163 	u8			peer_link_uid[SMC_LGR_ID_SIZE]; /* peer uid */
164 	u8			link_idx;	/* index in lgr link array */
165 	u8			link_is_asym;	/* is link asymmetric? */
166 	u8			clearing : 1;	/* link is being cleared */
167 	refcount_t		refcnt;		/* link reference count */
168 	struct smc_link_group	*lgr;		/* parent link group */
169 	struct work_struct	link_down_wrk;	/* wrk to bring link down */
170 	char			ibname[IB_DEVICE_NAME_MAX]; /* ib device name */
171 	int			ndev_ifidx; /* network device ifindex */
172 
173 	enum smc_link_state	state;		/* state of link */
174 	struct delayed_work	llc_testlink_wrk; /* testlink worker */
175 	struct completion	llc_testlink_resp; /* wait for rx of testlink */
176 	int			llc_testlink_time; /* testlink interval */
177 	atomic_t		conn_cnt; /* connections on this link */
178 	u16			max_send_wr;
179 	u16			max_recv_wr;
180 };
181 
182 /* For now we just allow one parallel link per link group. The SMC protocol
183  * allows more (up to 8).
184  */
185 #define SMC_LINKS_PER_LGR_MAX	3
186 #define SMC_SINGLE_LINK		0
187 #define SMC_LINKS_ADD_LNK_MIN	1	/* min. # of links per link group */
188 #define SMC_LINKS_ADD_LNK_MAX	2	/* max. # of links per link group, also is the
189 					 * default value for smc-r v1.0 and v2.0
190 					 */
191 #define SMC_LINKS_PER_LGR_MAX_PREFER	2	/* Preferred max links per link group used for
192 						 * SMC-R v2.1 and later negotiation, vendors or
193 						 * distributions may modify it to a value between
194 						 * 1-2 as needed.
195 						 */
196 
197 /* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
198 struct smc_buf_desc {
199 	struct list_head	list;
200 	void			*cpu_addr;	/* virtual address of buffer */
201 	struct page		*pages;
202 	int			len;		/* length of buffer */
203 	u32			used;		/* currently used / unused */
204 	union {
205 		struct { /* SMC-R */
206 			struct sg_table	sgt[SMC_LINKS_PER_LGR_MAX];
207 					/* virtual buffer */
208 			struct ib_mr	*mr[SMC_LINKS_PER_LGR_MAX];
209 					/* memory region: for rmb and
210 					 * vzalloced sndbuf
211 					 * incl. rkey provided to peer
212 					 * and lkey provided to local
213 					 */
214 			u32		order;	/* allocation order */
215 
216 			u8		is_conf_rkey;
217 					/* confirm_rkey done */
218 			u8		is_reg_mr[SMC_LINKS_PER_LGR_MAX];
219 					/* mem region registered */
220 			u8		is_map_ib[SMC_LINKS_PER_LGR_MAX];
221 					/* mem region mapped to lnk */
222 			u8		is_dma_need_sync;
223 			u8		is_reg_err;
224 					/* buffer registration err */
225 			u8		is_vm;
226 					/* virtually contiguous */
227 		};
228 		struct { /* SMC-D */
229 			/* SMC-D tx buffer */
230 			bool		is_attached;
231 					/* no need for explicit writes */
232 			 /* SMC-D rx buffer: */
233 			unsigned short	sba_idx;
234 					/* SBA index number */
235 			u64		token;
236 					/* DMB token number */
237 			dma_addr_t	dma_addr;
238 					/* DMA address */
239 		};
240 	};
241 };
242 
243 struct smc_rtoken {				/* address/key of remote RMB */
244 	u64			dma_addr;
245 	u32			rkey;
246 };
247 
248 #define SMC_BUF_MIN_SIZE	16384	/* minimum size of an RMB */
249 #define SMC_RMBE_SIZES		16	/* number of distinct RMBE sizes */
250 /* theoretically, the RFC states that largest size would be 512K,
251  * i.e. compressed 5 and thus 6 sizes (0..5), despite
252  * struct smc_clc_msg_accept_confirm.rmbe_size being a 4 bit value (0..15)
253  */
254 
255 struct smcd_dev;
256 
257 enum smc_lgr_type {				/* redundancy state of lgr */
258 	SMC_LGR_NONE,			/* no active links, lgr to be deleted */
259 	SMC_LGR_SINGLE,			/* 1 active RNIC on each peer */
260 	SMC_LGR_SYMMETRIC,		/* 2 active RNICs on each peer */
261 	SMC_LGR_ASYMMETRIC_PEER,	/* local has 2, peer 1 active RNICs */
262 	SMC_LGR_ASYMMETRIC_LOCAL,	/* local has 1, peer 2 active RNICs */
263 };
264 
265 enum smcr_buf_type {		/* types of SMC-R sndbufs and RMBs */
266 	SMCR_PHYS_CONT_BUFS	= 0,
267 	SMCR_VIRT_CONT_BUFS	= 1,
268 	SMCR_MIXED_BUFS		= 2,
269 };
270 
271 enum smc_llc_flowtype {
272 	SMC_LLC_FLOW_NONE	= 0,
273 	SMC_LLC_FLOW_ADD_LINK	= 2,
274 	SMC_LLC_FLOW_DEL_LINK	= 4,
275 	SMC_LLC_FLOW_REQ_ADD_LINK = 5,
276 	SMC_LLC_FLOW_RKEY	= 6,
277 };
278 
279 struct smc_llc_qentry;
280 
281 struct smc_llc_flow {
282 	enum smc_llc_flowtype type;
283 	struct smc_llc_qentry *qentry;
284 };
285 
286 struct smc_link_group {
287 	struct list_head	list;
288 	struct rb_root		conns_all;	/* connection tree */
289 	rwlock_t		conns_lock;	/* protects conns_all */
290 	unsigned int		conns_num;	/* current # of connections */
291 	unsigned short		vlan_id;	/* vlan id of link group */
292 
293 	struct list_head	sndbufs[SMC_RMBE_SIZES];/* tx buffers */
294 	struct rw_semaphore	sndbufs_lock;	/* protects tx buffers */
295 	struct list_head	rmbs[SMC_RMBE_SIZES];	/* rx buffers */
296 	struct rw_semaphore	rmbs_lock;	/* protects rx buffers */
297 	u64			alloc_sndbufs;	/* stats of tx buffers */
298 	u64			alloc_rmbs;	/* stats of rx buffers */
299 
300 	u8			id[SMC_LGR_ID_SIZE];	/* unique lgr id */
301 	struct delayed_work	free_work;	/* delayed freeing of an lgr */
302 	struct work_struct	terminate_work;	/* abnormal lgr termination */
303 	struct workqueue_struct	*tx_wq;		/* wq for conn. tx workers */
304 	u8			sync_err : 1;	/* lgr no longer fits to peer */
305 	u8			terminating : 1;/* lgr is terminating */
306 	u8			freeing : 1;	/* lgr is being freed */
307 
308 	refcount_t		refcnt;		/* lgr reference count */
309 	bool			is_smcd;	/* SMC-R or SMC-D */
310 	u8			smc_version;
311 	u8			negotiated_eid[SMC_MAX_EID_LEN];
312 	u8			peer_os;	/* peer operating system */
313 	u8			peer_smc_release;
314 	u8			peer_hostname[SMC_MAX_HOSTNAME_LEN];
315 	union {
316 		struct { /* SMC-R */
317 			enum smc_lgr_role	role;
318 						/* client or server */
319 			struct smc_link		lnk[SMC_LINKS_PER_LGR_MAX];
320 						/* smc link */
321 			struct smc_wr_v2_buf	*wr_rx_buf_v2;
322 						/* WR v2 recv payload buffer */
323 			struct smc_wr_v2_buf	*wr_tx_buf_v2;
324 						/* WR v2 send payload buffer */
325 			char			peer_systemid[SMC_SYSTEMID_LEN];
326 						/* unique system_id of peer */
327 			struct smc_rtoken	rtokens[SMC_RMBS_PER_LGR_MAX]
328 						[SMC_LINKS_PER_LGR_MAX];
329 						/* remote addr/key pairs */
330 			DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
331 						/* used rtoken elements */
332 			u8			next_link_id;
333 			enum smc_lgr_type	type;
334 			enum smcr_buf_type	buf_type;
335 						/* redundancy state */
336 			u8			pnet_id[SMC_MAX_PNETID_LEN + 1];
337 						/* pnet id of this lgr */
338 			struct list_head	llc_event_q;
339 						/* queue for llc events */
340 			spinlock_t		llc_event_q_lock;
341 						/* protects llc_event_q */
342 			struct rw_semaphore	llc_conf_mutex;
343 						/* protects lgr reconfig. */
344 			struct work_struct	llc_add_link_work;
345 			struct work_struct	llc_del_link_work;
346 			struct work_struct	llc_event_work;
347 						/* llc event worker */
348 			wait_queue_head_t	llc_flow_waiter;
349 						/* w4 next llc event */
350 			wait_queue_head_t	llc_msg_waiter;
351 						/* w4 next llc msg */
352 			struct smc_llc_flow	llc_flow_lcl;
353 						/* llc local control field */
354 			struct smc_llc_flow	llc_flow_rmt;
355 						/* llc remote control field */
356 			struct smc_llc_qentry	*delayed_event;
357 						/* arrived when flow active */
358 			spinlock_t		llc_flow_lock;
359 						/* protects llc flow */
360 			int			llc_testlink_time;
361 						/* link keep alive time */
362 			u32			llc_termination_rsn;
363 						/* rsn code for termination */
364 			u8			nexthop_mac[ETH_ALEN];
365 			u8			uses_gateway;
366 			__be32			saddr;
367 						/* net namespace */
368 			struct net		*net;
369 			u8			max_conns;
370 						/* max conn can be assigned to lgr */
371 			u8			max_links;
372 						/* max links can be added in lgr */
373 			u16			max_send_wr;
374 						/* number of WR buffers on send */
375 			u16			max_recv_wr;
376 						/* number of WR buffers on recv */
377 		};
378 		struct { /* SMC-D */
379 			struct smcd_gid		peer_gid;
380 						/* Peer GID (remote) */
381 			struct smcd_dev		*smcd;
382 						/* ISM device for VLAN reg. */
383 			u8			peer_shutdown : 1;
384 						/* peer triggered shutdownn */
385 		};
386 	};
387 };
388 
389 struct smc_clc_msg_local;
390 
391 #define GID_LIST_SIZE	2
392 
393 struct smc_gidlist {
394 	u8			len;
395 	u8			list[GID_LIST_SIZE][SMC_GID_SIZE];
396 };
397 
398 struct smc_init_info_smcrv2 {
399 	/* Input fields */
400 	__be32			saddr;
401 	struct sock		*clc_sk;
402 	__be32			daddr;
403 
404 	/* Output fields when saddr is set */
405 	struct smc_ib_device	*ib_dev_v2;
406 	u8			ib_port_v2;
407 	u8			ib_gid_v2[SMC_GID_SIZE];
408 
409 	/* Additional output fields when clc_sk and daddr is set as well */
410 	u8			uses_gateway;
411 	u8			nexthop_mac[ETH_ALEN];
412 
413 	struct smc_gidlist	gidlist;
414 };
415 
416 #define SMC_MAX_V2_ISM_DEVS	SMCD_CLC_MAX_V2_GID_ENTRIES
417 				/* max # of proposed non-native ISM devices,
418 				 * which can't exceed the max # of CHID-GID
419 				 * entries in CLC proposal SMC-Dv2 extension.
420 				 */
421 struct smc_init_info {
422 	u8			is_smcd;
423 	u8			smc_type_v1;
424 	u8			smc_type_v2;
425 	u8			release_nr;
426 	u8			max_conns;
427 	u8			max_links;
428 	u8			first_contact_peer;
429 	u8			first_contact_local;
430 	u16			feature_mask;
431 	unsigned short		vlan_id;
432 	u32			rc;
433 	u8			negotiated_eid[SMC_MAX_EID_LEN];
434 	/* SMC-R */
435 	u8			smcr_version;
436 	u8			check_smcrv2;
437 	u8			peer_gid[SMC_GID_SIZE];
438 	u8			peer_mac[ETH_ALEN];
439 	u8			peer_systemid[SMC_SYSTEMID_LEN];
440 	struct smc_ib_device	*ib_dev;
441 	u8			ib_gid[SMC_GID_SIZE];
442 	u8			ib_port;
443 	u32			ib_clcqpn;
444 	struct smc_init_info_smcrv2 smcrv2;
445 	/* SMC-D */
446 	struct smcd_gid		ism_peer_gid[SMC_MAX_V2_ISM_DEVS + 1];
447 	struct smcd_dev		*ism_dev[SMC_MAX_V2_ISM_DEVS + 1];
448 	u16			ism_chid[SMC_MAX_V2_ISM_DEVS + 1];
449 	u8			ism_offered_cnt; /* # of ISM devices offered */
450 	u8			ism_selected;    /* index of selected ISM dev*/
451 	u8			smcd_version;
452 };
453 
454 /* Find the connection associated with the given alert token in the link group.
455  * To use rbtrees we have to implement our own search core.
456  * Requires @conns_lock
457  * @token	alert token to search for
458  * @lgr		 link group to search in
459  * Returns connection associated with token if found, NULL otherwise.
460  */
461 static inline struct smc_connection *smc_lgr_find_conn(
462 	u32 token, struct smc_link_group *lgr)
463 {
464 	struct smc_connection *res = NULL;
465 	struct rb_node *node;
466 
467 	node = lgr->conns_all.rb_node;
468 	while (node) {
469 		struct smc_connection *cur = rb_entry(node,
470 					struct smc_connection, alert_node);
471 
472 		if (cur->alert_token_local > token) {
473 			node = node->rb_left;
474 		} else {
475 			if (cur->alert_token_local < token) {
476 				node = node->rb_right;
477 			} else {
478 				res = cur;
479 				break;
480 			}
481 		}
482 	}
483 
484 	return res;
485 }
486 
487 static inline bool smc_conn_lgr_valid(struct smc_connection *conn)
488 {
489 	return conn->lgr && conn->alert_token_local;
490 }
491 
492 /*
493  * Returns true if the specified link is usable.
494  *
495  * usable means the link is ready to receive RDMA messages, map memory
496  * on the link, etc. This doesn't ensure we are able to send RDMA messages
497  * on this link, if sending RDMA messages is needed, use smc_link_sendable()
498  */
499 static inline bool smc_link_usable(struct smc_link *lnk)
500 {
501 	if (lnk->state == SMC_LNK_UNUSED || lnk->state == SMC_LNK_INACTIVE)
502 		return false;
503 	return true;
504 }
505 
506 /*
507  * Returns true if the specified link is ready to receive AND send RDMA
508  * messages.
509  *
510  * For the client side in first contact, the underlying QP may still in
511  * RESET or RTR when the link state is ACTIVATING, checks in smc_link_usable()
512  * is not strong enough. For those places that need to send any CDC or LLC
513  * messages, use smc_link_sendable(), otherwise, use smc_link_usable() instead
514  */
515 static inline bool smc_link_sendable(struct smc_link *lnk)
516 {
517 	return smc_link_usable(lnk) &&
518 		lnk->qp_attr.cur_qp_state == IB_QPS_RTS;
519 }
520 
521 static inline bool smc_link_active(struct smc_link *lnk)
522 {
523 	return lnk->state == SMC_LNK_ACTIVE;
524 }
525 
526 static inline bool smc_link_shared_v2_rxbuf(struct smc_link *lnk)
527 {
528 	return lnk->wr_rx_sge_cnt > 1;
529 }
530 
531 static inline void smc_gid_be16_convert(__u8 *buf, u8 *gid_raw)
532 {
533 	sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
534 		be16_to_cpu(((__be16 *)gid_raw)[0]),
535 		be16_to_cpu(((__be16 *)gid_raw)[1]),
536 		be16_to_cpu(((__be16 *)gid_raw)[2]),
537 		be16_to_cpu(((__be16 *)gid_raw)[3]),
538 		be16_to_cpu(((__be16 *)gid_raw)[4]),
539 		be16_to_cpu(((__be16 *)gid_raw)[5]),
540 		be16_to_cpu(((__be16 *)gid_raw)[6]),
541 		be16_to_cpu(((__be16 *)gid_raw)[7]));
542 }
543 
544 struct smc_pci_dev {
545 	__u32		pci_fid;
546 	__u16		pci_pchid;
547 	__u16		pci_vendor;
548 	__u16		pci_device;
549 	__u8		pci_id[SMC_PCI_ID_STR_LEN];
550 };
551 
552 static inline void smc_set_pci_values(struct pci_dev *pci_dev,
553 				      struct smc_pci_dev *smc_dev)
554 {
555 	smc_dev->pci_vendor = pci_dev->vendor;
556 	smc_dev->pci_device = pci_dev->device;
557 	snprintf(smc_dev->pci_id, sizeof(smc_dev->pci_id), "%s",
558 		 pci_name(pci_dev));
559 #if IS_ENABLED(CONFIG_S390)
560 	{ /* Set s390 specific PCI information */
561 	struct zpci_dev *zdev;
562 
563 	zdev = to_zpci(pci_dev);
564 	smc_dev->pci_fid = zdev->fid;
565 	smc_dev->pci_pchid = zdev->pchid;
566 	}
567 #endif
568 }
569 
570 struct smc_sock;
571 struct smc_clc_msg_accept_confirm;
572 
573 void smc_lgr_cleanup_early(struct smc_link_group *lgr);
574 void smc_lgr_terminate_sched(struct smc_link_group *lgr);
575 void smc_lgr_hold(struct smc_link_group *lgr);
576 void smc_lgr_put(struct smc_link_group *lgr);
577 void smcr_port_add(struct smc_ib_device *smcibdev, u8 ibport);
578 void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport);
579 void smc_smcd_terminate(struct smcd_dev *dev, struct smcd_gid *peer_gid,
580 			unsigned short vlan);
581 void smc_smcd_terminate_all(struct smcd_dev *dev);
582 void smc_smcr_terminate_all(struct smc_ib_device *smcibdev);
583 int smc_buf_create(struct smc_sock *smc, bool is_smcd);
584 int smcd_buf_attach(struct smc_sock *smc);
585 int smc_uncompress_bufsize(u8 compressed);
586 int smc_rmb_rtoken_handling(struct smc_connection *conn, struct smc_link *link,
587 			    struct smc_clc_msg_accept_confirm *clc);
588 int smc_rtoken_add(struct smc_link *lnk, __be64 nw_vaddr, __be32 nw_rkey);
589 int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey);
590 void smc_rtoken_set(struct smc_link_group *lgr, int link_idx, int link_idx_new,
591 		    __be32 nw_rkey_known, __be64 nw_vaddr, __be32 nw_rkey);
592 void smc_rtoken_set2(struct smc_link_group *lgr, int rtok_idx, int link_id,
593 		     __be64 nw_vaddr, __be32 nw_rkey);
594 void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn);
595 void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn);
596 int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
597 
598 void smc_conn_free(struct smc_connection *conn);
599 int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
600 int smc_core_init(void);
601 void smc_core_exit(void);
602 
603 int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
604 		   u8 link_idx, struct smc_init_info *ini);
605 void smcr_link_clear(struct smc_link *lnk, bool log);
606 void smcr_link_hold(struct smc_link *lnk);
607 void smcr_link_put(struct smc_link *lnk);
608 void smc_switch_link_and_count(struct smc_connection *conn,
609 			       struct smc_link *to_lnk);
610 int smcr_buf_map_lgr(struct smc_link *lnk);
611 int smcr_buf_reg_lgr(struct smc_link *lnk);
612 void smcr_lgr_set_type(struct smc_link_group *lgr, enum smc_lgr_type new_type);
613 void smcr_lgr_set_type_asym(struct smc_link_group *lgr,
614 			    enum smc_lgr_type new_type, int asym_lnk_idx);
615 int smcr_link_reg_buf(struct smc_link *link, struct smc_buf_desc *rmb_desc);
616 struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
617 				  struct smc_link *from_lnk, bool is_dev_err);
618 void smcr_link_down_cond(struct smc_link *lnk);
619 void smcr_link_down_cond_sched(struct smc_link *lnk);
620 int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb);
621 int smcr_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb);
622 int smcr_nl_get_link(struct sk_buff *skb, struct netlink_callback *cb);
623 int smcd_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb);
624 
625 static inline struct smc_link_group *smc_get_lgr(struct smc_link *link)
626 {
627 	return link->lgr;
628 }
629 #endif
630