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