blob: b013cb43a327ea81cd8bc9e4a5ffff733f87f6a7 [file] [log] [blame]
Ursula Braun0cfdd8f2017-01-09 16:55:17 +01001/*
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
11#ifndef _SMC_CORE_H
12#define _SMC_CORE_H
13
Ursula Braunf38ba1792017-01-09 16:55:19 +010014#include <linux/atomic.h>
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010015#include <rdma/ib_verbs.h>
16
17#include "smc.h"
18#include "smc_ib.h"
19
Ursula Brauncd6851f2017-01-09 16:55:18 +010020#define SMC_RMBS_PER_LGR_MAX 255 /* max. # of RMBs per link group */
21
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010022struct smc_lgr_list { /* list of link group definition */
23 struct list_head list;
24 spinlock_t lock; /* protects list of link groups */
25};
26
27extern struct smc_lgr_list smc_lgr_list; /* list of link groups */
28
29enum smc_lgr_role { /* possible roles of a link group */
30 SMC_CLNT, /* client */
31 SMC_SERV /* server */
32};
33
Ursula Braunf38ba1792017-01-09 16:55:19 +010034#define SMC_WR_BUF_SIZE 48 /* size of work request buffer */
35
36struct smc_wr_buf {
37 u8 raw[SMC_WR_BUF_SIZE];
38};
39
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010040struct smc_link {
41 struct smc_ib_device *smcibdev; /* ib-device */
42 u8 ibport; /* port - values 1 | 2 */
Ursula Braunf38ba1792017-01-09 16:55:19 +010043 struct ib_pd *roce_pd; /* IB protection domain,
44 * unique for every RoCE QP
45 */
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010046 struct ib_qp *roce_qp; /* IB queue pair */
47 struct ib_qp_attr qp_attr; /* IB queue pair attributes */
Ursula Braunf38ba1792017-01-09 16:55:19 +010048
49 struct smc_wr_buf *wr_tx_bufs; /* WR send payload buffers */
50 struct ib_send_wr *wr_tx_ibs; /* WR send meta data */
51 struct ib_sge *wr_tx_sges; /* WR send gather meta data */
52 struct smc_wr_tx_pend *wr_tx_pends; /* WR send waiting for CQE */
53 /* above four vectors have wr_tx_cnt elements and use the same index */
54 dma_addr_t wr_tx_dma_addr; /* DMA address of wr_tx_bufs */
55 atomic_long_t wr_tx_id; /* seq # of last sent WR */
56 unsigned long *wr_tx_mask; /* bit mask of used indexes */
57 u32 wr_tx_cnt; /* number of WR send buffers */
58 wait_queue_head_t wr_tx_wait; /* wait for free WR send buf */
59
60 struct smc_wr_buf *wr_rx_bufs; /* WR recv payload buffers */
61 struct ib_recv_wr *wr_rx_ibs; /* WR recv meta data */
62 struct ib_sge *wr_rx_sges; /* WR recv scatter meta data */
63 /* above three vectors have wr_rx_cnt elements and use the same index */
64 dma_addr_t wr_rx_dma_addr; /* DMA address of wr_rx_bufs */
65 u64 wr_rx_id; /* seq # of last recv WR */
66 u32 wr_rx_cnt; /* number of WR recv buffers */
67
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010068 union ib_gid gid; /* gid matching used vlan id */
69 u32 peer_qpn; /* QP number of peer */
70 enum ib_mtu path_mtu; /* used mtu */
71 enum ib_mtu peer_mtu; /* mtu size of peer */
72 u32 psn_initial; /* QP tx initial packet seqno */
73 u32 peer_psn; /* QP rx initial packet seqno */
74 u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
75 u8 peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
Ursula Braun9bf9abe2017-01-09 16:55:21 +010076 u8 link_id; /* unique # within link group */
77 struct completion llc_confirm; /* wait for rx of conf link */
78 struct completion llc_confirm_resp; /* wait 4 rx of cnf lnk rsp */
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010079};
80
81/* For now we just allow one parallel link per link group. The SMC protocol
82 * allows more (up to 8).
83 */
84#define SMC_LINKS_PER_LGR_MAX 1
85#define SMC_SINGLE_LINK 0
86
87#define SMC_FIRST_CONTACT 1 /* first contact to a peer */
88#define SMC_REUSE_CONTACT 0 /* follow-on contact to a peer*/
89
Ursula Brauncd6851f2017-01-09 16:55:18 +010090/* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
91struct smc_buf_desc {
92 struct list_head list;
93 u64 dma_addr[SMC_LINKS_PER_LGR_MAX];
94 /* mapped address of buffer */
95 void *cpu_addr; /* virtual address of buffer */
Ursula Braun263eec92017-05-15 17:33:37 +020096 u32 rkey[SMC_LINKS_PER_LGR_MAX];
Ursula Braunbd4ad572017-01-09 16:55:20 +010097 /* for rmb only:
98 * rkey provided to peer
99 */
Ursula Brauncd6851f2017-01-09 16:55:18 +0100100 u32 used; /* currently used / unused */
101};
102
Ursula Braunbd4ad572017-01-09 16:55:20 +0100103struct smc_rtoken { /* address/key of remote RMB */
104 u64 dma_addr;
105 u32 rkey;
106};
107
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100108#define SMC_LGR_ID_SIZE 4
109
Ursula Braun0cfdd8f2017-01-09 16:55:17 +0100110struct smc_link_group {
111 struct list_head list;
112 enum smc_lgr_role role; /* client or server */
113 __be32 daddr; /* destination ip address */
114 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
115 char peer_systemid[SMC_SYSTEMID_LEN];
116 /* unique system_id of peer */
117 struct rb_root conns_all; /* connection tree */
118 rwlock_t conns_lock; /* protects conns_all */
119 unsigned int conns_num; /* current # of connections */
120 unsigned short vlan_id; /* vlan id of link group */
Ursula Brauncd6851f2017-01-09 16:55:18 +0100121
122 struct list_head sndbufs[SMC_RMBE_SIZES];/* tx buffers */
123 rwlock_t sndbufs_lock; /* protects tx buffers */
124 struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */
125 rwlock_t rmbs_lock; /* protects rx buffers */
Ursula Braunbd4ad572017-01-09 16:55:20 +0100126 struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX]
127 [SMC_LINKS_PER_LGR_MAX];
128 /* remote addr/key pairs */
129 unsigned long rtokens_used_mask[BITS_TO_LONGS(
130 SMC_RMBS_PER_LGR_MAX)];
131 /* used rtoken elements */
132
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100133 u8 id[SMC_LGR_ID_SIZE]; /* unique lgr id */
Ursula Braun0cfdd8f2017-01-09 16:55:17 +0100134 struct delayed_work free_work; /* delayed freeing of an lgr */
135 bool sync_err; /* lgr no longer fits to peer */
136};
137
138/* Find the connection associated with the given alert token in the link group.
139 * To use rbtrees we have to implement our own search core.
140 * Requires @conns_lock
141 * @token alert token to search for
142 * @lgr link group to search in
143 * Returns connection associated with token if found, NULL otherwise.
144 */
145static inline struct smc_connection *smc_lgr_find_conn(
146 u32 token, struct smc_link_group *lgr)
147{
148 struct smc_connection *res = NULL;
149 struct rb_node *node;
150
151 node = lgr->conns_all.rb_node;
152 while (node) {
153 struct smc_connection *cur = rb_entry(node,
154 struct smc_connection, alert_node);
155
156 if (cur->alert_token_local > token) {
157 node = node->rb_left;
158 } else {
159 if (cur->alert_token_local < token) {
160 node = node->rb_right;
161 } else {
162 res = cur;
163 break;
164 }
165 }
166 }
167
168 return res;
169}
170
Ursula Brauncd6851f2017-01-09 16:55:18 +0100171struct smc_sock;
172struct smc_clc_msg_accept_confirm;
173
Ursula Braun0cfdd8f2017-01-09 16:55:17 +0100174void smc_lgr_free(struct smc_link_group *lgr);
175void smc_lgr_terminate(struct smc_link_group *lgr);
Ursula Brauncd6851f2017-01-09 16:55:18 +0100176int smc_sndbuf_create(struct smc_sock *smc);
177int smc_rmb_create(struct smc_sock *smc);
Ursula Braunbd4ad572017-01-09 16:55:20 +0100178int smc_rmb_rtoken_handling(struct smc_connection *conn,
179 struct smc_clc_msg_accept_confirm *clc);
Ursula Braun0cfdd8f2017-01-09 16:55:17 +0100180
181#endif