Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * Link Layer Control (LLC) |
| 6 | * |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 7 | * 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 Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 21 | #define SMC_LLC_DATA_LEN 40 |
| 22 | |
| 23 | struct smc_llc_hdr { |
| 24 | struct smc_wr_rx_hdr common; |
| 25 | u8 length; /* 44 */ |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 26 | #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 Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 33 | u8 flags; |
| 34 | }; |
| 35 | |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 36 | #define SMC_LLC_FLAG_NO_RMBE_EYEC 0x03 |
| 37 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 38 | struct 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 Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 49 | #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 | |
| 54 | struct 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 | |
| 69 | struct 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 76 | struct 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 Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 82 | struct 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 | |
| 95 | struct 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 | |
| 101 | struct 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 | |
| 110 | struct 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 Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 119 | union smc_llc_msg { |
| 120 | struct smc_llc_msg_confirm_link confirm_link; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 121 | struct smc_llc_msg_add_link add_link; |
| 122 | struct smc_llc_msg_del_link delete_link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 123 | |
| 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 128 | struct smc_llc_msg_test_link test_link; |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 129 | 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 137 | /********************************** send *************************************/ |
| 138 | |
| 139 | struct smc_llc_tx_pend { |
| 140 | }; |
| 141 | |
| 142 | /* handler for send/transmission completion of an LLC msg */ |
| 143 | static 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 | */ |
| 163 | static 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 */ |
| 185 | int 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 Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 203 | confllc->hd.flags |= SMC_LLC_FLAG_NO_RMBE_EYEC; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 204 | 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 Graul | 2be922f | 2018-02-28 12:44:08 +0100 | [diff] [blame] | 209 | confllc->link_num = link->link_id; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 210 | memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 211 | 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 Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 217 | /* send LLC confirm rkey request */ |
| 218 | static 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 Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 242 | /* send ADD LINK request or response */ |
| 243 | int 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 */ |
| 273 | int 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 294 | /* send llc message */ |
| 295 | rc = smc_wr_tx_send(link, pend); |
| 296 | return rc; |
| 297 | } |
| 298 | |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 299 | /* send LLC test link request */ |
| 300 | static int smc_llc_send_test_link(struct smc_link *link, u8 user_data[16]) |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 301 | { |
| 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 314 | 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 Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 320 | /* send a prepared message */ |
| 321 | static 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 336 | /********************************* receive ***********************************/ |
| 337 | |
| 338 | static 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 Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 342 | int conf_rc; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 343 | |
| 344 | lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 345 | |
| 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 352 | if (llc->hd.flags & SMC_LLC_FLAG_RESP) { |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 353 | if (lgr->role == SMC_SERV && |
| 354 | link->state == SMC_LNK_ACTIVATING) { |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 355 | link->llc_confirm_resp_rc = conf_rc; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 356 | complete(&link->llc_confirm_resp); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 357 | } |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 358 | } else { |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 359 | if (lgr->role == SMC_CLNT && |
| 360 | link->state == SMC_LNK_ACTIVATING) { |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 361 | link->llc_confirm_rc = conf_rc; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 362 | link->link_id = llc->link_num; |
| 363 | complete(&link->llc_confirm); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 368 | static 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 | |
| 398 | static 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 Graul | 9651b93 | 2018-03-01 13:51:33 +0100 | [diff] [blame] | 409 | smc_lgr_forget(lgr); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 410 | 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 418 | static 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 Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 422 | if (link->state == SMC_LNK_ACTIVE) |
| 423 | complete(&link->llc_testlink_resp); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 424 | } else { |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 425 | llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 426 | smc_llc_send_message(link, llc, sizeof(*llc)); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 430 | static 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 Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 439 | link->llc_confirm_rkey_rc = llc->hd.flags & |
| 440 | SMC_LLC_FLAG_RKEY_NEG; |
| 441 | complete(&link->llc_confirm_rkey); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 442 | } 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 Graul | 9fcdf8e | 2018-05-15 17:04:56 +0200 | [diff] [blame] | 452 | smc_llc_send_message(link, llc, sizeof(*llc)); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | static 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 Graul | 9fcdf8e | 2018-05-15 17:04:56 +0200 | [diff] [blame] | 464 | smc_llc_send_message(link, llc, sizeof(*llc)); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
| 468 | static 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 Graul | 9fcdf8e | 2018-05-15 17:04:56 +0200 | [diff] [blame] | 492 | smc_llc_send_message(link, llc, sizeof(*llc)); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 496 | static 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 505 | |
| 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 511 | smc_llc_rx_confirm_link(link, &llc->confirm_link); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 512 | break; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 513 | 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 Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 519 | 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 528 | } |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 531 | /***************************** worker, utils *********************************/ |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 532 | |
| 533 | static 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 Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 552 | smc_llc_send_test_link(link, user_data); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 553 | /* 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; |
| 561 | out: |
| 562 | schedule_delayed_work(&link->llc_testlink_wrk, next_interval); |
| 563 | } |
| 564 | |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame^] | 565 | void smc_llc_link_init(struct smc_link *link) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 566 | { |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame^] | 567 | 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 Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 572 | init_completion(&link->llc_testlink_resp); |
| 573 | INIT_DELAYED_WORK(&link->llc_testlink_wrk, smc_llc_testlink_work); |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame^] | 574 | } |
| 575 | |
| 576 | void smc_llc_link_active(struct smc_link *link, int testlink_time) |
| 577 | { |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 578 | 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 */ |
| 587 | void 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 */ |
| 594 | void smc_llc_link_flush(struct smc_link *link) |
| 595 | { |
| 596 | cancel_delayed_work_sync(&link->llc_testlink_wrk); |
| 597 | } |
| 598 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 599 | /* register a new rtoken at the remote peer */ |
| 600 | int 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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 615 | /***************************** init, exit, misc ******************************/ |
| 616 | |
| 617 | static 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 Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 623 | .handler = smc_llc_rx_handler, |
| 624 | .type = SMC_LLC_TEST_LINK |
| 625 | }, |
| 626 | { |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 627 | .handler = smc_llc_rx_handler, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 628 | .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 Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 636 | .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 Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 647 | .handler = NULL, |
| 648 | } |
| 649 | }; |
| 650 | |
| 651 | int __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 | } |