1
2
3
4
5
6
7
8
9
10
11
12#ifndef _SMC_CORE_H
13#define _SMC_CORE_H
14
15#include <linux/atomic.h>
16#include <rdma/ib_verbs.h>
17
18#include "smc.h"
19#include "smc_ib.h"
20
21#define SMC_RMBS_PER_LGR_MAX 255
22
23struct smc_lgr_list {
24 struct list_head list;
25 spinlock_t lock;
26 u32 num;
27};
28
29enum smc_lgr_role {
30 SMC_CLNT,
31 SMC_SERV
32};
33
34enum smc_link_state {
35 SMC_LNK_INACTIVE,
36 SMC_LNK_ACTIVATING,
37 SMC_LNK_ACTIVE,
38 SMC_LNK_DELETING,
39};
40
41#define SMC_WR_BUF_SIZE 48
42
43struct smc_wr_buf {
44 u8 raw[SMC_WR_BUF_SIZE];
45};
46
47#define SMC_WR_REG_MR_WAIT_TIME (5 * HZ)
48
49enum smc_wr_reg_state {
50 POSTED,
51 CONFIRMED,
52 FAILED
53};
54
55struct smc_link {
56 struct smc_ib_device *smcibdev;
57 u8 ibport;
58 struct ib_pd *roce_pd;
59
60
61 struct ib_qp *roce_qp;
62 struct ib_qp_attr qp_attr;
63
64 struct smc_wr_buf *wr_tx_bufs;
65 struct ib_send_wr *wr_tx_ibs;
66 struct ib_sge *wr_tx_sges;
67 struct smc_wr_tx_pend *wr_tx_pends;
68
69 dma_addr_t wr_tx_dma_addr;
70 atomic_long_t wr_tx_id;
71 unsigned long *wr_tx_mask;
72 u32 wr_tx_cnt;
73 wait_queue_head_t wr_tx_wait;
74
75 struct smc_wr_buf *wr_rx_bufs;
76 struct ib_recv_wr *wr_rx_ibs;
77 struct ib_sge *wr_rx_sges;
78
79 dma_addr_t wr_rx_dma_addr;
80 u64 wr_rx_id;
81 u32 wr_rx_cnt;
82 unsigned long wr_rx_tstamp;
83
84 struct ib_reg_wr wr_reg;
85 wait_queue_head_t wr_reg_wait;
86 enum smc_wr_reg_state wr_reg_state;
87
88 u8 gid[SMC_GID_SIZE];
89 u8 sgid_index;
90 u32 peer_qpn;
91 enum ib_mtu path_mtu;
92 enum ib_mtu peer_mtu;
93 u32 psn_initial;
94 u32 peer_psn;
95 u8 peer_mac[ETH_ALEN];
96 u8 peer_gid[SMC_GID_SIZE];
97 u8 link_id;
98
99 enum smc_link_state state;
100 struct workqueue_struct *llc_wq;
101 struct completion llc_confirm;
102 struct completion llc_confirm_resp;
103 int llc_confirm_rc;
104 int llc_confirm_resp_rc;
105 struct completion llc_add;
106 struct completion llc_add_resp;
107 struct delayed_work llc_testlink_wrk;
108 struct completion llc_testlink_resp;
109 int llc_testlink_time;
110 struct completion llc_confirm_rkey;
111 int llc_confirm_rkey_rc;
112};
113
114
115
116
117#define SMC_LINKS_PER_LGR_MAX 1
118#define SMC_SINGLE_LINK 0
119
120#define SMC_FIRST_CONTACT 1
121#define SMC_REUSE_CONTACT 0
122
123
124struct smc_buf_desc {
125 struct list_head list;
126 void *cpu_addr;
127 struct page *pages;
128 int len;
129 u32 used;
130 u8 reused : 1;
131 u8 regerr : 1;
132 union {
133 struct {
134 struct sg_table sgt[SMC_LINKS_PER_LGR_MAX];
135
136 struct ib_mr *mr_rx[SMC_LINKS_PER_LGR_MAX];
137
138
139
140 u32 order;
141 };
142 struct {
143 unsigned short sba_idx;
144
145 u64 token;
146
147 dma_addr_t dma_addr;
148
149 };
150 };
151};
152
153struct smc_rtoken {
154 u64 dma_addr;
155 u32 rkey;
156};
157
158#define SMC_LGR_ID_SIZE 4
159#define SMC_BUF_MIN_SIZE 16384
160#define SMC_RMBE_SIZES 16
161
162
163
164
165
166struct smcd_dev;
167
168struct smc_link_group {
169 struct list_head list;
170 struct rb_root conns_all;
171 rwlock_t conns_lock;
172 unsigned int conns_num;
173 unsigned short vlan_id;
174
175 struct list_head sndbufs[SMC_RMBE_SIZES];
176 rwlock_t sndbufs_lock;
177 struct list_head rmbs[SMC_RMBE_SIZES];
178 rwlock_t rmbs_lock;
179
180 u8 id[SMC_LGR_ID_SIZE];
181 struct delayed_work free_work;
182 u8 sync_err : 1;
183 u8 terminating : 1;
184
185 bool is_smcd;
186 union {
187 struct {
188 enum smc_lgr_role role;
189
190 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX];
191
192 char peer_systemid[SMC_SYSTEMID_LEN];
193
194 struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX]
195 [SMC_LINKS_PER_LGR_MAX];
196
197 DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
198
199 };
200 struct {
201 u64 peer_gid;
202
203 struct smcd_dev *smcd;
204
205 };
206 };
207};
208
209
210
211
212
213
214
215
216static inline struct smc_connection *smc_lgr_find_conn(
217 u32 token, struct smc_link_group *lgr)
218{
219 struct smc_connection *res = NULL;
220 struct rb_node *node;
221
222 node = lgr->conns_all.rb_node;
223 while (node) {
224 struct smc_connection *cur = rb_entry(node,
225 struct smc_connection, alert_node);
226
227 if (cur->alert_token_local > token) {
228 node = node->rb_left;
229 } else {
230 if (cur->alert_token_local < token) {
231 node = node->rb_right;
232 } else {
233 res = cur;
234 break;
235 }
236 }
237 }
238
239 return res;
240}
241
242struct smc_sock;
243struct smc_clc_msg_accept_confirm;
244struct smc_clc_msg_local;
245
246void smc_lgr_free(struct smc_link_group *lgr);
247void smc_lgr_forget(struct smc_link_group *lgr);
248void smc_lgr_terminate(struct smc_link_group *lgr);
249void smc_port_terminate(struct smc_ib_device *smcibdev, u8 ibport);
250void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid);
251int smc_buf_create(struct smc_sock *smc, bool is_smcd);
252int smc_uncompress_bufsize(u8 compressed);
253int smc_rmb_rtoken_handling(struct smc_connection *conn,
254 struct smc_clc_msg_accept_confirm *clc);
255int smc_rtoken_add(struct smc_link_group *lgr, __be64 nw_vaddr, __be32 nw_rkey);
256int smc_rtoken_delete(struct smc_link_group *lgr, __be32 nw_rkey);
257void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn);
258void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn);
259void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn);
260void smc_rmb_sync_sg_for_device(struct smc_connection *conn);
261int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id);
262
263void smc_conn_free(struct smc_connection *conn);
264int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
265 struct smc_ib_device *smcibdev, u8 ibport,
266 struct smc_clc_msg_local *lcl, struct smcd_dev *smcd,
267 u64 peer_gid);
268void smcd_conn_free(struct smc_connection *conn);
269void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr);
270void smc_core_exit(void);
271
272static inline struct smc_link_group *smc_get_lgr(struct smc_link *link)
273{
274 return container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
275}
276#endif
277