blob: 5dbeced6cea5b68ef79040db3e01a0c1b3ac85f2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Ursula Braun9bf9abe2017-01-09 16:55:21 +01002/*
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
4 *
5 * Link Layer Control (LLC)
6 *
Ursula Braun9bf9abe2017-01-09 16:55:21 +01007 * Copyright IBM Corp. 2016
8 *
9 * Author(s): Klaus Wacker <Klaus.Wacker@de.ibm.com>
10 * Ursula Braun <ubraun@linux.vnet.ibm.com>
11 */
12
13#include <net/tcp.h>
14#include <rdma/ib_verbs.h>
15
16#include "smc.h"
17#include "smc_core.h"
18#include "smc_clc.h"
19#include "smc_llc.h"
20
Stefan Raspl0f627122018-03-01 13:51:26 +010021#define SMC_LLC_DATA_LEN 40
22
23struct smc_llc_hdr {
24 struct smc_wr_rx_hdr common;
25 u8 length; /* 44 */
Karsten Graul52bedf32018-03-01 13:51:32 +010026#if defined(__BIG_ENDIAN_BITFIELD)
27 u8 reserved:4,
28 add_link_rej_rsn:4;
29#elif defined(__LITTLE_ENDIAN_BITFIELD)
30 u8 add_link_rej_rsn:4,
31 reserved:4;
32#endif
Stefan Raspl0f627122018-03-01 13:51:26 +010033 u8 flags;
34};
35
Karsten Graul75d320d2018-03-01 13:51:31 +010036#define SMC_LLC_FLAG_NO_RMBE_EYEC 0x03
37
Stefan Raspl0f627122018-03-01 13:51:26 +010038struct smc_llc_msg_confirm_link { /* type 0x01 */
39 struct smc_llc_hdr hd;
40 u8 sender_mac[ETH_ALEN];
41 u8 sender_gid[SMC_GID_SIZE];
42 u8 sender_qp_num[3];
43 u8 link_num;
44 u8 link_uid[SMC_LGR_ID_SIZE];
45 u8 max_links;
46 u8 reserved[9];
47};
48
Karsten Graul52bedf32018-03-01 13:51:32 +010049#define SMC_LLC_FLAG_ADD_LNK_REJ 0x40
50#define SMC_LLC_REJ_RSN_NO_ALT_PATH 1
51
52#define SMC_LLC_ADD_LNK_MAX_LINKS 2
53
54struct smc_llc_msg_add_link { /* type 0x02 */
55 struct smc_llc_hdr hd;
56 u8 sender_mac[ETH_ALEN];
57 u8 reserved2[2];
58 u8 sender_gid[SMC_GID_SIZE];
59 u8 sender_qp_num[3];
60 u8 link_num;
61 u8 flags2; /* QP mtu */
62 u8 initial_psn[3];
63 u8 reserved[8];
64};
65
66#define SMC_LLC_FLAG_DEL_LINK_ALL 0x40
67#define SMC_LLC_FLAG_DEL_LINK_ORDERLY 0x20
68
69struct smc_llc_msg_del_link { /* type 0x04 */
70 struct smc_llc_hdr hd;
71 u8 link_num;
72 __be32 reason;
73 u8 reserved[35];
74} __packed; /* format defined in RFC7609 */
75
Karsten Graul313164d2018-03-01 13:51:29 +010076struct smc_llc_msg_test_link { /* type 0x07 */
77 struct smc_llc_hdr hd;
78 u8 user_data[16];
79 u8 reserved[24];
80};
81
Karsten Graul4ed75de2018-03-01 13:51:30 +010082struct smc_rmb_rtoken {
83 union {
84 u8 num_rkeys; /* first rtoken byte of CONFIRM LINK msg */
85 /* is actually the num of rtokens, first */
86 /* rtoken is always for the current link */
87 u8 link_id; /* link id of the rtoken */
88 };
89 __be32 rmb_key;
90 __be64 rmb_vaddr;
91} __packed; /* format defined in RFC7609 */
92
93#define SMC_LLC_RKEYS_PER_MSG 3
94
95struct smc_llc_msg_confirm_rkey { /* type 0x06 */
96 struct smc_llc_hdr hd;
97 struct smc_rmb_rtoken rtoken[SMC_LLC_RKEYS_PER_MSG];
98 u8 reserved;
99};
100
101struct smc_llc_msg_confirm_rkey_cont { /* type 0x08 */
102 struct smc_llc_hdr hd;
103 u8 num_rkeys;
104 struct smc_rmb_rtoken rtoken[SMC_LLC_RKEYS_PER_MSG];
105};
106
107#define SMC_LLC_DEL_RKEY_MAX 8
108#define SMC_LLC_FLAG_RKEY_NEG 0x20
109
110struct smc_llc_msg_delete_rkey { /* type 0x09 */
111 struct smc_llc_hdr hd;
112 u8 num_rkeys;
113 u8 err_mask;
114 u8 reserved[2];
115 __be32 rkey[8];
116 u8 reserved2[4];
117};
118
Stefan Raspl0f627122018-03-01 13:51:26 +0100119union smc_llc_msg {
120 struct smc_llc_msg_confirm_link confirm_link;
Karsten Graul52bedf32018-03-01 13:51:32 +0100121 struct smc_llc_msg_add_link add_link;
122 struct smc_llc_msg_del_link delete_link;
Karsten Graul4ed75de2018-03-01 13:51:30 +0100123
124 struct smc_llc_msg_confirm_rkey confirm_rkey;
125 struct smc_llc_msg_confirm_rkey_cont confirm_rkey_cont;
126 struct smc_llc_msg_delete_rkey delete_rkey;
127
Karsten Graul313164d2018-03-01 13:51:29 +0100128 struct smc_llc_msg_test_link test_link;
Stefan Raspl0f627122018-03-01 13:51:26 +0100129 struct {
130 struct smc_llc_hdr hdr;
131 u8 data[SMC_LLC_DATA_LEN];
132 } raw;
133};
134
135#define SMC_LLC_FLAG_RESP 0x80
136
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100137/********************************** send *************************************/
138
139struct smc_llc_tx_pend {
140};
141
142/* handler for send/transmission completion of an LLC msg */
143static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend,
144 struct smc_link *link,
145 enum ib_wc_status wc_status)
146{
147 /* future work: handle wc_status error for recovery and failover */
148}
149
150/**
151 * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits
152 * @link: Pointer to SMC link used for sending LLC control message.
153 * @wr_buf: Out variable returning pointer to work request payload buffer.
154 * @pend: Out variable returning pointer to private pending WR tracking.
155 * It's the context the transmit complete handler will get.
156 *
157 * Reserves and pre-fills an entry for a pending work request send/tx.
158 * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx.
159 * Can sleep due to smc_get_ctrl_buf (if not in softirq context).
160 *
161 * Return: 0 on success, otherwise an error value.
162 */
163static int smc_llc_add_pending_send(struct smc_link *link,
164 struct smc_wr_buf **wr_buf,
165 struct smc_wr_tx_pend_priv **pend)
166{
167 int rc;
168
169 rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, pend);
170 if (rc < 0)
171 return rc;
172 BUILD_BUG_ON_MSG(
173 sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE,
174 "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)");
175 BUILD_BUG_ON_MSG(
176 sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE,
177 "must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()");
178 BUILD_BUG_ON_MSG(
179 sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
180 "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)");
181 return 0;
182}
183
184/* high-level API to send LLC confirm link */
185int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
186 union ib_gid *gid,
187 enum smc_llc_reqresp reqresp)
188{
189 struct smc_link_group *lgr = container_of(link, struct smc_link_group,
190 lnk[SMC_SINGLE_LINK]);
191 struct smc_llc_msg_confirm_link *confllc;
192 struct smc_wr_tx_pend_priv *pend;
193 struct smc_wr_buf *wr_buf;
194 int rc;
195
196 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
197 if (rc)
198 return rc;
199 confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
200 memset(confllc, 0, sizeof(*confllc));
201 confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
202 confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link);
Karsten Graul75d320d2018-03-01 13:51:31 +0100203 confllc->hd.flags |= SMC_LLC_FLAG_NO_RMBE_EYEC;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100204 if (reqresp == SMC_LLC_RESP)
205 confllc->hd.flags |= SMC_LLC_FLAG_RESP;
206 memcpy(confllc->sender_mac, mac, ETH_ALEN);
207 memcpy(confllc->sender_gid, gid, SMC_GID_SIZE);
208 hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
Karsten Graul2be922f2018-02-28 12:44:08 +0100209 confllc->link_num = link->link_id;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100210 memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE);
Karsten Graul52bedf32018-03-01 13:51:32 +0100211 confllc->max_links = SMC_LLC_ADD_LNK_MAX_LINKS; /* enforce peer resp. */
212 /* send llc message */
213 rc = smc_wr_tx_send(link, pend);
214 return rc;
215}
216
Karsten Graul44aa81c2018-05-15 17:04:55 +0200217/* send LLC confirm rkey request */
218static int smc_llc_send_confirm_rkey(struct smc_link *link,
219 struct smc_buf_desc *rmb_desc)
220{
221 struct smc_llc_msg_confirm_rkey *rkeyllc;
222 struct smc_wr_tx_pend_priv *pend;
223 struct smc_wr_buf *wr_buf;
224 int rc;
225
226 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
227 if (rc)
228 return rc;
229 rkeyllc = (struct smc_llc_msg_confirm_rkey *)wr_buf;
230 memset(rkeyllc, 0, sizeof(*rkeyllc));
231 rkeyllc->hd.common.type = SMC_LLC_CONFIRM_RKEY;
232 rkeyllc->hd.length = sizeof(struct smc_llc_msg_confirm_rkey);
233 rkeyllc->rtoken[0].rmb_key =
234 htonl(rmb_desc->mr_rx[SMC_SINGLE_LINK]->rkey);
235 rkeyllc->rtoken[0].rmb_vaddr = cpu_to_be64(
236 (u64)sg_dma_address(rmb_desc->sgt[SMC_SINGLE_LINK].sgl));
237 /* send llc message */
238 rc = smc_wr_tx_send(link, pend);
239 return rc;
240}
241
Karsten Graul52bedf32018-03-01 13:51:32 +0100242/* send ADD LINK request or response */
243int smc_llc_send_add_link(struct smc_link *link, u8 mac[],
244 union ib_gid *gid,
245 enum smc_llc_reqresp reqresp)
246{
247 struct smc_llc_msg_add_link *addllc;
248 struct smc_wr_tx_pend_priv *pend;
249 struct smc_wr_buf *wr_buf;
250 int rc;
251
252 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
253 if (rc)
254 return rc;
255 addllc = (struct smc_llc_msg_add_link *)wr_buf;
256 memset(addllc, 0, sizeof(*addllc));
257 addllc->hd.common.type = SMC_LLC_ADD_LINK;
258 addllc->hd.length = sizeof(struct smc_llc_msg_add_link);
259 if (reqresp == SMC_LLC_RESP) {
260 addllc->hd.flags |= SMC_LLC_FLAG_RESP;
261 /* always reject more links for now */
262 addllc->hd.flags |= SMC_LLC_FLAG_ADD_LNK_REJ;
263 addllc->hd.add_link_rej_rsn = SMC_LLC_REJ_RSN_NO_ALT_PATH;
264 }
265 memcpy(addllc->sender_mac, mac, ETH_ALEN);
266 memcpy(addllc->sender_gid, gid, SMC_GID_SIZE);
267 /* send llc message */
268 rc = smc_wr_tx_send(link, pend);
269 return rc;
270}
271
272/* send DELETE LINK request or response */
273int smc_llc_send_delete_link(struct smc_link *link,
274 enum smc_llc_reqresp reqresp)
275{
276 struct smc_llc_msg_del_link *delllc;
277 struct smc_wr_tx_pend_priv *pend;
278 struct smc_wr_buf *wr_buf;
279 int rc;
280
281 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
282 if (rc)
283 return rc;
284 delllc = (struct smc_llc_msg_del_link *)wr_buf;
285 memset(delllc, 0, sizeof(*delllc));
286 delllc->hd.common.type = SMC_LLC_DELETE_LINK;
287 delllc->hd.length = sizeof(struct smc_llc_msg_add_link);
288 if (reqresp == SMC_LLC_RESP)
289 delllc->hd.flags |= SMC_LLC_FLAG_RESP;
290 /* DEL_LINK_ALL because only 1 link supported */
291 delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL;
292 delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY;
293 delllc->link_num = link->link_id;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100294 /* send llc message */
295 rc = smc_wr_tx_send(link, pend);
296 return rc;
297}
298
Karsten Grauld97935f2018-05-15 17:04:57 +0200299/* send LLC test link request */
300static int smc_llc_send_test_link(struct smc_link *link, u8 user_data[16])
Karsten Graul313164d2018-03-01 13:51:29 +0100301{
302 struct smc_llc_msg_test_link *testllc;
303 struct smc_wr_tx_pend_priv *pend;
304 struct smc_wr_buf *wr_buf;
305 int rc;
306
307 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
308 if (rc)
309 return rc;
310 testllc = (struct smc_llc_msg_test_link *)wr_buf;
311 memset(testllc, 0, sizeof(*testllc));
312 testllc->hd.common.type = SMC_LLC_TEST_LINK;
313 testllc->hd.length = sizeof(struct smc_llc_msg_test_link);
Karsten Graul313164d2018-03-01 13:51:29 +0100314 memcpy(testllc->user_data, user_data, sizeof(testllc->user_data));
315 /* send llc message */
316 rc = smc_wr_tx_send(link, pend);
317 return rc;
318}
319
Karsten Graul4ed75de2018-03-01 13:51:30 +0100320/* send a prepared message */
321static int smc_llc_send_message(struct smc_link *link, void *llcbuf, int llclen)
322{
323 struct smc_wr_tx_pend_priv *pend;
324 struct smc_wr_buf *wr_buf;
325 int rc;
326
327 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
328 if (rc)
329 return rc;
330 memcpy(wr_buf, llcbuf, llclen);
331 /* send llc message */
332 rc = smc_wr_tx_send(link, pend);
333 return rc;
334}
335
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100336/********************************* receive ***********************************/
337
338static void smc_llc_rx_confirm_link(struct smc_link *link,
339 struct smc_llc_msg_confirm_link *llc)
340{
341 struct smc_link_group *lgr;
Karsten Graul75d320d2018-03-01 13:51:31 +0100342 int conf_rc;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100343
344 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
Karsten Graul75d320d2018-03-01 13:51:31 +0100345
346 /* RMBE eyecatchers are not supported */
347 if (llc->hd.flags & SMC_LLC_FLAG_NO_RMBE_EYEC)
348 conf_rc = 0;
349 else
350 conf_rc = ENOTSUPP;
351
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100352 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
Karsten Graul52bedf32018-03-01 13:51:32 +0100353 if (lgr->role == SMC_SERV &&
354 link->state == SMC_LNK_ACTIVATING) {
Karsten Graul75d320d2018-03-01 13:51:31 +0100355 link->llc_confirm_resp_rc = conf_rc;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100356 complete(&link->llc_confirm_resp);
Karsten Graul75d320d2018-03-01 13:51:31 +0100357 }
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100358 } else {
Karsten Graul52bedf32018-03-01 13:51:32 +0100359 if (lgr->role == SMC_CLNT &&
360 link->state == SMC_LNK_ACTIVATING) {
Karsten Graul75d320d2018-03-01 13:51:31 +0100361 link->llc_confirm_rc = conf_rc;
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100362 link->link_id = llc->link_num;
363 complete(&link->llc_confirm);
364 }
365 }
366}
367
Karsten Graul52bedf32018-03-01 13:51:32 +0100368static void smc_llc_rx_add_link(struct smc_link *link,
369 struct smc_llc_msg_add_link *llc)
370{
371 struct smc_link_group *lgr = container_of(link, struct smc_link_group,
372 lnk[SMC_SINGLE_LINK]);
373
374 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
375 if (link->state == SMC_LNK_ACTIVATING)
376 complete(&link->llc_add_resp);
377 } else {
378 if (link->state == SMC_LNK_ACTIVATING) {
379 complete(&link->llc_add);
380 return;
381 }
382
383 if (lgr->role == SMC_SERV) {
384 smc_llc_send_add_link(link,
385 link->smcibdev->mac[link->ibport - 1],
386 &link->smcibdev->gid[link->ibport - 1],
387 SMC_LLC_REQ);
388
389 } else {
390 smc_llc_send_add_link(link,
391 link->smcibdev->mac[link->ibport - 1],
392 &link->smcibdev->gid[link->ibport - 1],
393 SMC_LLC_RESP);
394 }
395 }
396}
397
398static void smc_llc_rx_delete_link(struct smc_link *link,
399 struct smc_llc_msg_del_link *llc)
400{
401 struct smc_link_group *lgr = container_of(link, struct smc_link_group,
402 lnk[SMC_SINGLE_LINK]);
403
404 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
405 if (lgr->role == SMC_SERV)
406 smc_lgr_terminate(lgr);
407 } else {
408 if (lgr->role == SMC_SERV) {
Karsten Graul9651b932018-03-01 13:51:33 +0100409 smc_lgr_forget(lgr);
Karsten Graul52bedf32018-03-01 13:51:32 +0100410 smc_llc_send_delete_link(link, SMC_LLC_REQ);
411 } else {
412 smc_llc_send_delete_link(link, SMC_LLC_RESP);
413 smc_lgr_terminate(lgr);
414 }
415 }
416}
417
Karsten Graul313164d2018-03-01 13:51:29 +0100418static void smc_llc_rx_test_link(struct smc_link *link,
419 struct smc_llc_msg_test_link *llc)
420{
421 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
Karsten Graul877ae5b2018-05-02 16:56:44 +0200422 if (link->state == SMC_LNK_ACTIVE)
423 complete(&link->llc_testlink_resp);
Karsten Graul313164d2018-03-01 13:51:29 +0100424 } else {
Karsten Grauld97935f2018-05-15 17:04:57 +0200425 llc->hd.flags |= SMC_LLC_FLAG_RESP;
426 smc_llc_send_message(link, llc, sizeof(*llc));
Karsten Graul313164d2018-03-01 13:51:29 +0100427 }
428}
429
Karsten Graul4ed75de2018-03-01 13:51:30 +0100430static void smc_llc_rx_confirm_rkey(struct smc_link *link,
431 struct smc_llc_msg_confirm_rkey *llc)
432{
433 struct smc_link_group *lgr;
434 int rc;
435
436 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
437
438 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
Karsten Graul44aa81c2018-05-15 17:04:55 +0200439 link->llc_confirm_rkey_rc = llc->hd.flags &
440 SMC_LLC_FLAG_RKEY_NEG;
441 complete(&link->llc_confirm_rkey);
Karsten Graul4ed75de2018-03-01 13:51:30 +0100442 } else {
443 rc = smc_rtoken_add(lgr,
444 llc->rtoken[0].rmb_vaddr,
445 llc->rtoken[0].rmb_key);
446
447 /* ignore rtokens for other links, we have only one link */
448
449 llc->hd.flags |= SMC_LLC_FLAG_RESP;
450 if (rc < 0)
451 llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG;
Karsten Graul9fcdf8e2018-05-15 17:04:56 +0200452 smc_llc_send_message(link, llc, sizeof(*llc));
Karsten Graul4ed75de2018-03-01 13:51:30 +0100453 }
454}
455
456static void smc_llc_rx_confirm_rkey_cont(struct smc_link *link,
457 struct smc_llc_msg_confirm_rkey_cont *llc)
458{
459 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
460 /* unused as long as we don't send this type of msg */
461 } else {
462 /* ignore rtokens for other links, we have only one link */
463 llc->hd.flags |= SMC_LLC_FLAG_RESP;
Karsten Graul9fcdf8e2018-05-15 17:04:56 +0200464 smc_llc_send_message(link, llc, sizeof(*llc));
Karsten Graul4ed75de2018-03-01 13:51:30 +0100465 }
466}
467
468static void smc_llc_rx_delete_rkey(struct smc_link *link,
469 struct smc_llc_msg_delete_rkey *llc)
470{
471 struct smc_link_group *lgr;
472 u8 err_mask = 0;
473 int i, max;
474
475 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
476
477 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
478 /* unused as long as we don't send this type of msg */
479 } else {
480 max = min_t(u8, llc->num_rkeys, SMC_LLC_DEL_RKEY_MAX);
481 for (i = 0; i < max; i++) {
482 if (smc_rtoken_delete(lgr, llc->rkey[i]))
483 err_mask |= 1 << (SMC_LLC_DEL_RKEY_MAX - 1 - i);
484 }
485
486 if (err_mask) {
487 llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG;
488 llc->err_mask = err_mask;
489 }
490
491 llc->hd.flags |= SMC_LLC_FLAG_RESP;
Karsten Graul9fcdf8e2018-05-15 17:04:56 +0200492 smc_llc_send_message(link, llc, sizeof(*llc));
Karsten Graul4ed75de2018-03-01 13:51:30 +0100493 }
494}
495
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100496static void smc_llc_rx_handler(struct ib_wc *wc, void *buf)
497{
498 struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
499 union smc_llc_msg *llc = buf;
500
501 if (wc->byte_len < sizeof(*llc))
502 return; /* short message */
503 if (llc->raw.hdr.length != sizeof(*llc))
504 return; /* invalid message */
Karsten Graul313164d2018-03-01 13:51:29 +0100505
506 switch (llc->raw.hdr.common.type) {
507 case SMC_LLC_TEST_LINK:
508 smc_llc_rx_test_link(link, &llc->test_link);
509 break;
510 case SMC_LLC_CONFIRM_LINK:
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100511 smc_llc_rx_confirm_link(link, &llc->confirm_link);
Karsten Graul313164d2018-03-01 13:51:29 +0100512 break;
Karsten Graul52bedf32018-03-01 13:51:32 +0100513 case SMC_LLC_ADD_LINK:
514 smc_llc_rx_add_link(link, &llc->add_link);
515 break;
516 case SMC_LLC_DELETE_LINK:
517 smc_llc_rx_delete_link(link, &llc->delete_link);
518 break;
Karsten Graul4ed75de2018-03-01 13:51:30 +0100519 case SMC_LLC_CONFIRM_RKEY:
520 smc_llc_rx_confirm_rkey(link, &llc->confirm_rkey);
521 break;
522 case SMC_LLC_CONFIRM_RKEY_CONT:
523 smc_llc_rx_confirm_rkey_cont(link, &llc->confirm_rkey_cont);
524 break;
525 case SMC_LLC_DELETE_RKEY:
526 smc_llc_rx_delete_rkey(link, &llc->delete_rkey);
527 break;
Karsten Graul313164d2018-03-01 13:51:29 +0100528 }
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100529}
530
Karsten Graul44aa81c2018-05-15 17:04:55 +0200531/***************************** worker, utils *********************************/
Karsten Graul877ae5b2018-05-02 16:56:44 +0200532
533static void smc_llc_testlink_work(struct work_struct *work)
534{
535 struct smc_link *link = container_of(to_delayed_work(work),
536 struct smc_link, llc_testlink_wrk);
537 unsigned long next_interval;
538 struct smc_link_group *lgr;
539 unsigned long expire_time;
540 u8 user_data[16] = { 0 };
541 int rc;
542
543 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
544 if (link->state != SMC_LNK_ACTIVE)
545 return; /* don't reschedule worker */
546 expire_time = link->wr_rx_tstamp + link->llc_testlink_time;
547 if (time_is_after_jiffies(expire_time)) {
548 next_interval = expire_time - jiffies;
549 goto out;
550 }
551 reinit_completion(&link->llc_testlink_resp);
Karsten Grauld97935f2018-05-15 17:04:57 +0200552 smc_llc_send_test_link(link, user_data);
Karsten Graul877ae5b2018-05-02 16:56:44 +0200553 /* receive TEST LINK response over RoCE fabric */
554 rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp,
555 SMC_LLC_WAIT_TIME);
556 if (rc <= 0) {
557 smc_lgr_terminate(lgr);
558 return;
559 }
560 next_interval = link->llc_testlink_time;
561out:
562 schedule_delayed_work(&link->llc_testlink_wrk, next_interval);
563}
564
Karsten Graulb32cf4a2018-05-15 17:04:58 +0200565void smc_llc_link_init(struct smc_link *link)
Karsten Graul877ae5b2018-05-02 16:56:44 +0200566{
Karsten Graulb32cf4a2018-05-15 17:04:58 +0200567 init_completion(&link->llc_confirm);
568 init_completion(&link->llc_confirm_resp);
569 init_completion(&link->llc_add);
570 init_completion(&link->llc_add_resp);
571 init_completion(&link->llc_confirm_rkey);
Karsten Graul877ae5b2018-05-02 16:56:44 +0200572 init_completion(&link->llc_testlink_resp);
573 INIT_DELAYED_WORK(&link->llc_testlink_wrk, smc_llc_testlink_work);
Karsten Graulb32cf4a2018-05-15 17:04:58 +0200574}
575
576void smc_llc_link_active(struct smc_link *link, int testlink_time)
577{
Karsten Graul877ae5b2018-05-02 16:56:44 +0200578 link->state = SMC_LNK_ACTIVE;
579 if (testlink_time) {
580 link->llc_testlink_time = testlink_time * HZ;
581 schedule_delayed_work(&link->llc_testlink_wrk,
582 link->llc_testlink_time);
583 }
584}
585
586/* called in tasklet context */
587void smc_llc_link_inactive(struct smc_link *link)
588{
589 link->state = SMC_LNK_INACTIVE;
590 cancel_delayed_work(&link->llc_testlink_wrk);
591}
592
593/* called in worker context */
594void smc_llc_link_flush(struct smc_link *link)
595{
596 cancel_delayed_work_sync(&link->llc_testlink_wrk);
597}
598
Karsten Graul44aa81c2018-05-15 17:04:55 +0200599/* register a new rtoken at the remote peer */
600int smc_llc_do_confirm_rkey(struct smc_link *link,
601 struct smc_buf_desc *rmb_desc)
602{
603 int rc;
604
605 reinit_completion(&link->llc_confirm_rkey);
606 smc_llc_send_confirm_rkey(link, rmb_desc);
607 /* receive CONFIRM RKEY response from server over RoCE fabric */
608 rc = wait_for_completion_interruptible_timeout(&link->llc_confirm_rkey,
609 SMC_LLC_WAIT_TIME);
610 if (rc <= 0 || link->llc_confirm_rkey_rc)
611 return -EFAULT;
612 return 0;
613}
614
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100615/***************************** init, exit, misc ******************************/
616
617static struct smc_wr_rx_handler smc_llc_rx_handlers[] = {
618 {
619 .handler = smc_llc_rx_handler,
620 .type = SMC_LLC_CONFIRM_LINK
621 },
622 {
Karsten Graul313164d2018-03-01 13:51:29 +0100623 .handler = smc_llc_rx_handler,
624 .type = SMC_LLC_TEST_LINK
625 },
626 {
Karsten Graul4ed75de2018-03-01 13:51:30 +0100627 .handler = smc_llc_rx_handler,
Karsten Graul52bedf32018-03-01 13:51:32 +0100628 .type = SMC_LLC_ADD_LINK
629 },
630 {
631 .handler = smc_llc_rx_handler,
632 .type = SMC_LLC_DELETE_LINK
633 },
634 {
635 .handler = smc_llc_rx_handler,
Karsten Graul4ed75de2018-03-01 13:51:30 +0100636 .type = SMC_LLC_CONFIRM_RKEY
637 },
638 {
639 .handler = smc_llc_rx_handler,
640 .type = SMC_LLC_CONFIRM_RKEY_CONT
641 },
642 {
643 .handler = smc_llc_rx_handler,
644 .type = SMC_LLC_DELETE_RKEY
645 },
646 {
Ursula Braun9bf9abe2017-01-09 16:55:21 +0100647 .handler = NULL,
648 }
649};
650
651int __init smc_llc_init(void)
652{
653 struct smc_wr_rx_handler *handler;
654 int rc = 0;
655
656 for (handler = smc_llc_rx_handlers; handler->handler; handler++) {
657 INIT_HLIST_NODE(&handler->list);
658 rc = smc_wr_rx_register_handler(handler);
659 if (rc)
660 break;
661 }
662 return rc;
663}