smc_core.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  3. *
  4. * Definitions for SMC Connections, Link Groups and Links
  5. *
  6. * Copyright IBM Corp. 2016
  7. *
  8. * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
  9. */
  10. #ifndef _SMC_CORE_H
  11. #define _SMC_CORE_H
  12. #include <linux/atomic.h>
  13. #include <rdma/ib_verbs.h>
  14. #include "smc.h"
  15. #include "smc_ib.h"
  16. #define SMC_RMBS_PER_LGR_MAX 255 /* max. # of RMBs per link group */
  17. struct smc_lgr_list { /* list of link group definition */
  18. struct list_head list;
  19. spinlock_t lock; /* protects list of link groups */
  20. };
  21. extern struct smc_lgr_list smc_lgr_list; /* list of link groups */
  22. enum smc_lgr_role { /* possible roles of a link group */
  23. SMC_CLNT, /* client */
  24. SMC_SERV /* server */
  25. };
  26. #define SMC_WR_BUF_SIZE 48 /* size of work request buffer */
  27. struct smc_wr_buf {
  28. u8 raw[SMC_WR_BUF_SIZE];
  29. };
  30. struct smc_link {
  31. struct smc_ib_device *smcibdev; /* ib-device */
  32. u8 ibport; /* port - values 1 | 2 */
  33. struct ib_pd *roce_pd; /* IB protection domain,
  34. * unique for every RoCE QP
  35. */
  36. struct ib_qp *roce_qp; /* IB queue pair */
  37. struct ib_qp_attr qp_attr; /* IB queue pair attributes */
  38. struct smc_wr_buf *wr_tx_bufs; /* WR send payload buffers */
  39. struct ib_send_wr *wr_tx_ibs; /* WR send meta data */
  40. struct ib_sge *wr_tx_sges; /* WR send gather meta data */
  41. struct smc_wr_tx_pend *wr_tx_pends; /* WR send waiting for CQE */
  42. /* above four vectors have wr_tx_cnt elements and use the same index */
  43. dma_addr_t wr_tx_dma_addr; /* DMA address of wr_tx_bufs */
  44. atomic_long_t wr_tx_id; /* seq # of last sent WR */
  45. unsigned long *wr_tx_mask; /* bit mask of used indexes */
  46. u32 wr_tx_cnt; /* number of WR send buffers */
  47. wait_queue_head_t wr_tx_wait; /* wait for free WR send buf */
  48. struct smc_wr_buf *wr_rx_bufs; /* WR recv payload buffers */
  49. struct ib_recv_wr *wr_rx_ibs; /* WR recv meta data */
  50. struct ib_sge *wr_rx_sges; /* WR recv scatter meta data */
  51. /* above three vectors have wr_rx_cnt elements and use the same index */
  52. dma_addr_t wr_rx_dma_addr; /* DMA address of wr_rx_bufs */
  53. u64 wr_rx_id; /* seq # of last recv WR */
  54. u32 wr_rx_cnt; /* number of WR recv buffers */
  55. union ib_gid gid; /* gid matching used vlan id */
  56. u32 peer_qpn; /* QP number of peer */
  57. enum ib_mtu path_mtu; /* used mtu */
  58. enum ib_mtu peer_mtu; /* mtu size of peer */
  59. u32 psn_initial; /* QP tx initial packet seqno */
  60. u32 peer_psn; /* QP rx initial packet seqno */
  61. u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
  62. u8 peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
  63. u8 link_id; /* unique # within link group */
  64. struct completion llc_confirm; /* wait for rx of conf link */
  65. struct completion llc_confirm_resp; /* wait 4 rx of cnf lnk rsp */
  66. };
  67. /* For now we just allow one parallel link per link group. The SMC protocol
  68. * allows more (up to 8).
  69. */
  70. #define SMC_LINKS_PER_LGR_MAX 1
  71. #define SMC_SINGLE_LINK 0
  72. #define SMC_FIRST_CONTACT 1 /* first contact to a peer */
  73. #define SMC_REUSE_CONTACT 0 /* follow-on contact to a peer*/
  74. /* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
  75. struct smc_buf_desc {
  76. struct list_head list;
  77. u64 dma_addr[SMC_LINKS_PER_LGR_MAX];
  78. /* mapped address of buffer */
  79. void *cpu_addr; /* virtual address of buffer */
  80. struct ib_mr *mr_rx[SMC_LINKS_PER_LGR_MAX];
  81. /* for rmb only:
  82. * rkey provided to peer
  83. */
  84. u32 used; /* currently used / unused */
  85. };
  86. struct smc_rtoken { /* address/key of remote RMB */
  87. u64 dma_addr;
  88. u32 rkey;
  89. };
  90. #define SMC_LGR_ID_SIZE 4
  91. struct smc_link_group {
  92. struct list_head list;
  93. enum smc_lgr_role role; /* client or server */
  94. __be32 daddr; /* destination ip address */
  95. struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
  96. char peer_systemid[SMC_SYSTEMID_LEN];
  97. /* unique system_id of peer */
  98. struct rb_root conns_all; /* connection tree */
  99. rwlock_t conns_lock; /* protects conns_all */
  100. unsigned int conns_num; /* current # of connections */
  101. unsigned short vlan_id; /* vlan id of link group */
  102. struct list_head sndbufs[SMC_RMBE_SIZES];/* tx buffers */
  103. rwlock_t sndbufs_lock; /* protects tx buffers */
  104. struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */
  105. rwlock_t rmbs_lock; /* protects rx buffers */
  106. struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX]
  107. [SMC_LINKS_PER_LGR_MAX];
  108. /* remote addr/key pairs */
  109. unsigned long rtokens_used_mask[BITS_TO_LONGS(
  110. SMC_RMBS_PER_LGR_MAX)];
  111. /* used rtoken elements */
  112. u8 id[SMC_LGR_ID_SIZE]; /* unique lgr id */
  113. struct delayed_work free_work; /* delayed freeing of an lgr */
  114. bool sync_err; /* lgr no longer fits to peer */
  115. };
  116. /* Find the connection associated with the given alert token in the link group.
  117. * To use rbtrees we have to implement our own search core.
  118. * Requires @conns_lock
  119. * @token alert token to search for
  120. * @lgr link group to search in
  121. * Returns connection associated with token if found, NULL otherwise.
  122. */
  123. static inline struct smc_connection *smc_lgr_find_conn(
  124. u32 token, struct smc_link_group *lgr)
  125. {
  126. struct smc_connection *res = NULL;
  127. struct rb_node *node;
  128. node = lgr->conns_all.rb_node;
  129. while (node) {
  130. struct smc_connection *cur = rb_entry(node,
  131. struct smc_connection, alert_node);
  132. if (cur->alert_token_local > token) {
  133. node = node->rb_left;
  134. } else {
  135. if (cur->alert_token_local < token) {
  136. node = node->rb_right;
  137. } else {
  138. res = cur;
  139. break;
  140. }
  141. }
  142. }
  143. return res;
  144. }
  145. struct smc_sock;
  146. struct smc_clc_msg_accept_confirm;
  147. void smc_lgr_free(struct smc_link_group *lgr);
  148. void smc_lgr_terminate(struct smc_link_group *lgr);
  149. int smc_sndbuf_create(struct smc_sock *smc);
  150. int smc_rmb_create(struct smc_sock *smc);
  151. int smc_rmb_rtoken_handling(struct smc_connection *conn,
  152. struct smc_clc_msg_accept_confirm *clc);
  153. #endif