smc_core.h 20 KB

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