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" |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 20 | #include "smc_pnet.h" |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 21 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 22 | #define SMC_LLC_DATA_LEN 40 |
| 23 | |
| 24 | struct smc_llc_hdr { |
| 25 | struct smc_wr_rx_hdr common; |
| 26 | u8 length; /* 44 */ |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 27 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 28 | u8 reserved:4, |
| 29 | add_link_rej_rsn:4; |
| 30 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 31 | u8 add_link_rej_rsn:4, |
| 32 | reserved:4; |
| 33 | #endif |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 34 | u8 flags; |
| 35 | }; |
| 36 | |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 37 | #define SMC_LLC_FLAG_NO_RMBE_EYEC 0x03 |
| 38 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 39 | struct smc_llc_msg_confirm_link { /* type 0x01 */ |
| 40 | struct smc_llc_hdr hd; |
| 41 | u8 sender_mac[ETH_ALEN]; |
| 42 | u8 sender_gid[SMC_GID_SIZE]; |
| 43 | u8 sender_qp_num[3]; |
| 44 | u8 link_num; |
| 45 | u8 link_uid[SMC_LGR_ID_SIZE]; |
| 46 | u8 max_links; |
| 47 | u8 reserved[9]; |
| 48 | }; |
| 49 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 50 | #define SMC_LLC_FLAG_ADD_LNK_REJ 0x40 |
| 51 | #define SMC_LLC_REJ_RSN_NO_ALT_PATH 1 |
| 52 | |
| 53 | #define SMC_LLC_ADD_LNK_MAX_LINKS 2 |
| 54 | |
| 55 | struct smc_llc_msg_add_link { /* type 0x02 */ |
| 56 | struct smc_llc_hdr hd; |
| 57 | u8 sender_mac[ETH_ALEN]; |
| 58 | u8 reserved2[2]; |
| 59 | u8 sender_gid[SMC_GID_SIZE]; |
| 60 | u8 sender_qp_num[3]; |
| 61 | u8 link_num; |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 62 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 63 | u8 reserved3 : 4, |
| 64 | qp_mtu : 4; |
| 65 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 66 | u8 qp_mtu : 4, |
| 67 | reserved3 : 4; |
| 68 | #endif |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 69 | u8 initial_psn[3]; |
| 70 | u8 reserved[8]; |
| 71 | }; |
| 72 | |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 73 | struct smc_llc_msg_add_link_cont_rt { |
| 74 | __be32 rmb_key; |
| 75 | __be32 rmb_key_new; |
| 76 | __be64 rmb_vaddr_new; |
| 77 | }; |
| 78 | |
| 79 | #define SMC_LLC_RKEYS_PER_CONT_MSG 2 |
| 80 | |
| 81 | struct smc_llc_msg_add_link_cont { /* type 0x03 */ |
| 82 | struct smc_llc_hdr hd; |
| 83 | u8 link_num; |
| 84 | u8 num_rkeys; |
| 85 | u8 reserved2[2]; |
| 86 | struct smc_llc_msg_add_link_cont_rt rt[SMC_LLC_RKEYS_PER_CONT_MSG]; |
| 87 | u8 reserved[4]; |
| 88 | } __packed; /* format defined in RFC7609 */ |
| 89 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 90 | #define SMC_LLC_FLAG_DEL_LINK_ALL 0x40 |
| 91 | #define SMC_LLC_FLAG_DEL_LINK_ORDERLY 0x20 |
| 92 | |
| 93 | struct smc_llc_msg_del_link { /* type 0x04 */ |
| 94 | struct smc_llc_hdr hd; |
| 95 | u8 link_num; |
| 96 | __be32 reason; |
| 97 | u8 reserved[35]; |
| 98 | } __packed; /* format defined in RFC7609 */ |
| 99 | |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 100 | struct smc_llc_msg_test_link { /* type 0x07 */ |
| 101 | struct smc_llc_hdr hd; |
| 102 | u8 user_data[16]; |
| 103 | u8 reserved[24]; |
| 104 | }; |
| 105 | |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 106 | struct smc_rmb_rtoken { |
| 107 | union { |
| 108 | u8 num_rkeys; /* first rtoken byte of CONFIRM LINK msg */ |
| 109 | /* is actually the num of rtokens, first */ |
| 110 | /* rtoken is always for the current link */ |
| 111 | u8 link_id; /* link id of the rtoken */ |
| 112 | }; |
| 113 | __be32 rmb_key; |
| 114 | __be64 rmb_vaddr; |
| 115 | } __packed; /* format defined in RFC7609 */ |
| 116 | |
| 117 | #define SMC_LLC_RKEYS_PER_MSG 3 |
| 118 | |
| 119 | struct smc_llc_msg_confirm_rkey { /* type 0x06 */ |
| 120 | struct smc_llc_hdr hd; |
| 121 | struct smc_rmb_rtoken rtoken[SMC_LLC_RKEYS_PER_MSG]; |
| 122 | u8 reserved; |
| 123 | }; |
| 124 | |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 125 | #define SMC_LLC_DEL_RKEY_MAX 8 |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 126 | #define SMC_LLC_FLAG_RKEY_RETRY 0x10 |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 127 | #define SMC_LLC_FLAG_RKEY_NEG 0x20 |
| 128 | |
| 129 | struct smc_llc_msg_delete_rkey { /* type 0x09 */ |
| 130 | struct smc_llc_hdr hd; |
| 131 | u8 num_rkeys; |
| 132 | u8 err_mask; |
| 133 | u8 reserved[2]; |
| 134 | __be32 rkey[8]; |
| 135 | u8 reserved2[4]; |
| 136 | }; |
| 137 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 138 | union smc_llc_msg { |
| 139 | struct smc_llc_msg_confirm_link confirm_link; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 140 | struct smc_llc_msg_add_link add_link; |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 141 | struct smc_llc_msg_add_link_cont add_link_cont; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 142 | struct smc_llc_msg_del_link delete_link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 143 | |
| 144 | struct smc_llc_msg_confirm_rkey confirm_rkey; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 145 | struct smc_llc_msg_delete_rkey delete_rkey; |
| 146 | |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 147 | struct smc_llc_msg_test_link test_link; |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 148 | struct { |
| 149 | struct smc_llc_hdr hdr; |
| 150 | u8 data[SMC_LLC_DATA_LEN]; |
| 151 | } raw; |
| 152 | }; |
| 153 | |
| 154 | #define SMC_LLC_FLAG_RESP 0x80 |
| 155 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 156 | struct smc_llc_qentry { |
| 157 | struct list_head list; |
| 158 | struct smc_link *link; |
| 159 | union smc_llc_msg msg; |
| 160 | }; |
| 161 | |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 162 | struct smc_llc_qentry *smc_llc_flow_qentry_clr(struct smc_llc_flow *flow) |
| 163 | { |
| 164 | struct smc_llc_qentry *qentry = flow->qentry; |
| 165 | |
| 166 | flow->qentry = NULL; |
| 167 | return qentry; |
| 168 | } |
| 169 | |
| 170 | void smc_llc_flow_qentry_del(struct smc_llc_flow *flow) |
| 171 | { |
| 172 | struct smc_llc_qentry *qentry; |
| 173 | |
| 174 | if (flow->qentry) { |
| 175 | qentry = flow->qentry; |
| 176 | flow->qentry = NULL; |
| 177 | kfree(qentry); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | static inline void smc_llc_flow_qentry_set(struct smc_llc_flow *flow, |
| 182 | struct smc_llc_qentry *qentry) |
| 183 | { |
| 184 | flow->qentry = qentry; |
| 185 | } |
| 186 | |
| 187 | /* try to start a new llc flow, initiated by an incoming llc msg */ |
| 188 | static bool smc_llc_flow_start(struct smc_llc_flow *flow, |
| 189 | struct smc_llc_qentry *qentry) |
| 190 | { |
| 191 | struct smc_link_group *lgr = qentry->link->lgr; |
| 192 | |
| 193 | spin_lock_bh(&lgr->llc_flow_lock); |
| 194 | if (flow->type) { |
| 195 | /* a flow is already active */ |
| 196 | if ((qentry->msg.raw.hdr.common.type == SMC_LLC_ADD_LINK || |
| 197 | qentry->msg.raw.hdr.common.type == SMC_LLC_DELETE_LINK) && |
| 198 | !lgr->delayed_event) { |
| 199 | lgr->delayed_event = qentry; |
| 200 | } else { |
| 201 | /* forget this llc request */ |
| 202 | kfree(qentry); |
| 203 | } |
| 204 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 205 | return false; |
| 206 | } |
| 207 | switch (qentry->msg.raw.hdr.common.type) { |
| 208 | case SMC_LLC_ADD_LINK: |
| 209 | flow->type = SMC_LLC_FLOW_ADD_LINK; |
| 210 | break; |
| 211 | case SMC_LLC_DELETE_LINK: |
| 212 | flow->type = SMC_LLC_FLOW_DEL_LINK; |
| 213 | break; |
| 214 | case SMC_LLC_CONFIRM_RKEY: |
| 215 | case SMC_LLC_DELETE_RKEY: |
| 216 | flow->type = SMC_LLC_FLOW_RKEY; |
| 217 | break; |
| 218 | default: |
| 219 | flow->type = SMC_LLC_FLOW_NONE; |
| 220 | } |
| 221 | if (qentry == lgr->delayed_event) |
| 222 | lgr->delayed_event = NULL; |
| 223 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 224 | smc_llc_flow_qentry_set(flow, qentry); |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | /* start a new local llc flow, wait till current flow finished */ |
| 229 | int smc_llc_flow_initiate(struct smc_link_group *lgr, |
| 230 | enum smc_llc_flowtype type) |
| 231 | { |
| 232 | enum smc_llc_flowtype allowed_remote = SMC_LLC_FLOW_NONE; |
| 233 | int rc; |
| 234 | |
| 235 | /* all flows except confirm_rkey and delete_rkey are exclusive, |
| 236 | * confirm/delete rkey flows can run concurrently (local and remote) |
| 237 | */ |
| 238 | if (type == SMC_LLC_FLOW_RKEY) |
| 239 | allowed_remote = SMC_LLC_FLOW_RKEY; |
| 240 | again: |
| 241 | if (list_empty(&lgr->list)) |
| 242 | return -ENODEV; |
| 243 | spin_lock_bh(&lgr->llc_flow_lock); |
| 244 | if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE && |
| 245 | (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE || |
| 246 | lgr->llc_flow_rmt.type == allowed_remote)) { |
| 247 | lgr->llc_flow_lcl.type = type; |
| 248 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 249 | return 0; |
| 250 | } |
| 251 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 252 | rc = wait_event_interruptible_timeout(lgr->llc_waiter, |
| 253 | (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE && |
| 254 | (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE || |
| 255 | lgr->llc_flow_rmt.type == allowed_remote)), |
| 256 | SMC_LLC_WAIT_TIME); |
| 257 | if (!rc) |
| 258 | return -ETIMEDOUT; |
| 259 | goto again; |
| 260 | } |
| 261 | |
| 262 | /* finish the current llc flow */ |
| 263 | void smc_llc_flow_stop(struct smc_link_group *lgr, struct smc_llc_flow *flow) |
| 264 | { |
| 265 | spin_lock_bh(&lgr->llc_flow_lock); |
| 266 | memset(flow, 0, sizeof(*flow)); |
| 267 | flow->type = SMC_LLC_FLOW_NONE; |
| 268 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 269 | if (!list_empty(&lgr->list) && lgr->delayed_event && |
| 270 | flow == &lgr->llc_flow_lcl) |
| 271 | schedule_work(&lgr->llc_event_work); |
| 272 | else |
| 273 | wake_up_interruptible(&lgr->llc_waiter); |
| 274 | } |
| 275 | |
| 276 | /* lnk is optional and used for early wakeup when link goes down, useful in |
| 277 | * cases where we wait for a response on the link after we sent a request |
| 278 | */ |
| 279 | struct smc_llc_qentry *smc_llc_wait(struct smc_link_group *lgr, |
| 280 | struct smc_link *lnk, |
| 281 | int time_out, u8 exp_msg) |
| 282 | { |
| 283 | struct smc_llc_flow *flow = &lgr->llc_flow_lcl; |
| 284 | |
| 285 | wait_event_interruptible_timeout(lgr->llc_waiter, |
| 286 | (flow->qentry || |
| 287 | (lnk && !smc_link_usable(lnk)) || |
| 288 | list_empty(&lgr->list)), |
| 289 | time_out); |
| 290 | if (!flow->qentry || |
| 291 | (lnk && !smc_link_usable(lnk)) || list_empty(&lgr->list)) { |
| 292 | smc_llc_flow_qentry_del(flow); |
| 293 | goto out; |
| 294 | } |
| 295 | if (exp_msg && flow->qentry->msg.raw.hdr.common.type != exp_msg) { |
| 296 | if (exp_msg == SMC_LLC_ADD_LINK && |
| 297 | flow->qentry->msg.raw.hdr.common.type == |
| 298 | SMC_LLC_DELETE_LINK) { |
| 299 | /* flow_start will delay the unexpected msg */ |
| 300 | smc_llc_flow_start(&lgr->llc_flow_lcl, |
| 301 | smc_llc_flow_qentry_clr(flow)); |
| 302 | return NULL; |
| 303 | } |
| 304 | smc_llc_flow_qentry_del(flow); |
| 305 | } |
| 306 | out: |
| 307 | return flow->qentry; |
| 308 | } |
| 309 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 310 | /********************************** send *************************************/ |
| 311 | |
| 312 | struct smc_llc_tx_pend { |
| 313 | }; |
| 314 | |
| 315 | /* handler for send/transmission completion of an LLC msg */ |
| 316 | static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend, |
| 317 | struct smc_link *link, |
| 318 | enum ib_wc_status wc_status) |
| 319 | { |
| 320 | /* future work: handle wc_status error for recovery and failover */ |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits |
| 325 | * @link: Pointer to SMC link used for sending LLC control message. |
| 326 | * @wr_buf: Out variable returning pointer to work request payload buffer. |
| 327 | * @pend: Out variable returning pointer to private pending WR tracking. |
| 328 | * It's the context the transmit complete handler will get. |
| 329 | * |
| 330 | * Reserves and pre-fills an entry for a pending work request send/tx. |
| 331 | * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx. |
| 332 | * Can sleep due to smc_get_ctrl_buf (if not in softirq context). |
| 333 | * |
| 334 | * Return: 0 on success, otherwise an error value. |
| 335 | */ |
| 336 | static int smc_llc_add_pending_send(struct smc_link *link, |
| 337 | struct smc_wr_buf **wr_buf, |
| 338 | struct smc_wr_tx_pend_priv **pend) |
| 339 | { |
| 340 | int rc; |
| 341 | |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 342 | rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, NULL, |
| 343 | pend); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 344 | if (rc < 0) |
| 345 | return rc; |
| 346 | BUILD_BUG_ON_MSG( |
| 347 | sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE, |
| 348 | "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)"); |
| 349 | BUILD_BUG_ON_MSG( |
| 350 | sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE, |
| 351 | "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()"); |
| 352 | BUILD_BUG_ON_MSG( |
| 353 | sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE, |
| 354 | "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)"); |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | /* high-level API to send LLC confirm link */ |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 359 | int smc_llc_send_confirm_link(struct smc_link *link, |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 360 | enum smc_llc_reqresp reqresp) |
| 361 | { |
Stefan Raspl | 00e5fb2 | 2018-07-23 13:53:10 +0200 | [diff] [blame] | 362 | struct smc_link_group *lgr = smc_get_lgr(link); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 363 | struct smc_llc_msg_confirm_link *confllc; |
| 364 | struct smc_wr_tx_pend_priv *pend; |
| 365 | struct smc_wr_buf *wr_buf; |
| 366 | int rc; |
| 367 | |
| 368 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 369 | if (rc) |
| 370 | return rc; |
| 371 | confllc = (struct smc_llc_msg_confirm_link *)wr_buf; |
| 372 | memset(confllc, 0, sizeof(*confllc)); |
| 373 | confllc->hd.common.type = SMC_LLC_CONFIRM_LINK; |
| 374 | confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 375 | confllc->hd.flags |= SMC_LLC_FLAG_NO_RMBE_EYEC; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 376 | if (reqresp == SMC_LLC_RESP) |
| 377 | confllc->hd.flags |= SMC_LLC_FLAG_RESP; |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 378 | memcpy(confllc->sender_mac, link->smcibdev->mac[link->ibport - 1], |
| 379 | ETH_ALEN); |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 380 | memcpy(confllc->sender_gid, link->gid, SMC_GID_SIZE); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 381 | hton24(confllc->sender_qp_num, link->roce_qp->qp_num); |
Karsten Graul | 2be922f | 2018-02-28 12:44:08 +0100 | [diff] [blame] | 382 | confllc->link_num = link->link_id; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 383 | memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 384 | confllc->max_links = SMC_LLC_ADD_LNK_MAX_LINKS; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 385 | /* send llc message */ |
| 386 | rc = smc_wr_tx_send(link, pend); |
| 387 | return rc; |
| 388 | } |
| 389 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 390 | /* send LLC confirm rkey request */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 391 | static int smc_llc_send_confirm_rkey(struct smc_link *send_link, |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 392 | struct smc_buf_desc *rmb_desc) |
| 393 | { |
| 394 | struct smc_llc_msg_confirm_rkey *rkeyllc; |
| 395 | struct smc_wr_tx_pend_priv *pend; |
| 396 | struct smc_wr_buf *wr_buf; |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 397 | struct smc_link *link; |
| 398 | int i, rc, rtok_ix; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 399 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 400 | rc = smc_llc_add_pending_send(send_link, &wr_buf, &pend); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 401 | if (rc) |
| 402 | return rc; |
| 403 | rkeyllc = (struct smc_llc_msg_confirm_rkey *)wr_buf; |
| 404 | memset(rkeyllc, 0, sizeof(*rkeyllc)); |
| 405 | rkeyllc->hd.common.type = SMC_LLC_CONFIRM_RKEY; |
| 406 | rkeyllc->hd.length = sizeof(struct smc_llc_msg_confirm_rkey); |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 407 | |
| 408 | rtok_ix = 1; |
| 409 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 410 | link = &send_link->lgr->lnk[i]; |
| 411 | if (link->state == SMC_LNK_ACTIVE && link != send_link) { |
| 412 | rkeyllc->rtoken[rtok_ix].link_id = link->link_id; |
| 413 | rkeyllc->rtoken[rtok_ix].rmb_key = |
| 414 | htonl(rmb_desc->mr_rx[link->link_idx]->rkey); |
| 415 | rkeyllc->rtoken[rtok_ix].rmb_vaddr = cpu_to_be64( |
| 416 | (u64)sg_dma_address( |
| 417 | rmb_desc->sgt[link->link_idx].sgl)); |
| 418 | rtok_ix++; |
| 419 | } |
| 420 | } |
| 421 | /* rkey of send_link is in rtoken[0] */ |
| 422 | rkeyllc->rtoken[0].num_rkeys = rtok_ix - 1; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 423 | rkeyllc->rtoken[0].rmb_key = |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 424 | htonl(rmb_desc->mr_rx[send_link->link_idx]->rkey); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 425 | rkeyllc->rtoken[0].rmb_vaddr = cpu_to_be64( |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 426 | (u64)sg_dma_address(rmb_desc->sgt[send_link->link_idx].sgl)); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 427 | /* send llc message */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 428 | rc = smc_wr_tx_send(send_link, pend); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 429 | return rc; |
| 430 | } |
| 431 | |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 432 | /* send LLC delete rkey request */ |
| 433 | static int smc_llc_send_delete_rkey(struct smc_link *link, |
| 434 | struct smc_buf_desc *rmb_desc) |
| 435 | { |
| 436 | struct smc_llc_msg_delete_rkey *rkeyllc; |
| 437 | struct smc_wr_tx_pend_priv *pend; |
| 438 | struct smc_wr_buf *wr_buf; |
| 439 | int rc; |
| 440 | |
| 441 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 442 | if (rc) |
| 443 | return rc; |
| 444 | rkeyllc = (struct smc_llc_msg_delete_rkey *)wr_buf; |
| 445 | memset(rkeyllc, 0, sizeof(*rkeyllc)); |
| 446 | rkeyllc->hd.common.type = SMC_LLC_DELETE_RKEY; |
| 447 | rkeyllc->hd.length = sizeof(struct smc_llc_msg_delete_rkey); |
| 448 | rkeyllc->num_rkeys = 1; |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 449 | rkeyllc->rkey[0] = htonl(rmb_desc->mr_rx[link->link_idx]->rkey); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 450 | /* send llc message */ |
| 451 | rc = smc_wr_tx_send(link, pend); |
| 452 | return rc; |
| 453 | } |
| 454 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 455 | /* send ADD LINK request or response */ |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 456 | int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[], |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 457 | struct smc_link *link_new, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 458 | enum smc_llc_reqresp reqresp) |
| 459 | { |
| 460 | struct smc_llc_msg_add_link *addllc; |
| 461 | struct smc_wr_tx_pend_priv *pend; |
| 462 | struct smc_wr_buf *wr_buf; |
| 463 | int rc; |
| 464 | |
| 465 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 466 | if (rc) |
| 467 | return rc; |
| 468 | addllc = (struct smc_llc_msg_add_link *)wr_buf; |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 469 | |
| 470 | memset(addllc, 0, sizeof(*addllc)); |
| 471 | addllc->hd.common.type = SMC_LLC_ADD_LINK; |
| 472 | addllc->hd.length = sizeof(struct smc_llc_msg_add_link); |
| 473 | if (reqresp == SMC_LLC_RESP) |
| 474 | addllc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 475 | memcpy(addllc->sender_mac, mac, ETH_ALEN); |
| 476 | memcpy(addllc->sender_gid, gid, SMC_GID_SIZE); |
| 477 | if (link_new) { |
| 478 | addllc->link_num = link_new->link_id; |
| 479 | hton24(addllc->sender_qp_num, link_new->roce_qp->qp_num); |
| 480 | hton24(addllc->initial_psn, link_new->psn_initial); |
| 481 | if (reqresp == SMC_LLC_REQ) |
| 482 | addllc->qp_mtu = link_new->path_mtu; |
| 483 | else |
| 484 | addllc->qp_mtu = min(link_new->path_mtu, |
| 485 | link_new->peer_mtu); |
| 486 | } |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 487 | /* send llc message */ |
| 488 | rc = smc_wr_tx_send(link, pend); |
| 489 | return rc; |
| 490 | } |
| 491 | |
| 492 | /* send DELETE LINK request or response */ |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 493 | int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id, |
| 494 | enum smc_llc_reqresp reqresp, bool orderly, |
| 495 | u32 reason) |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 496 | { |
| 497 | struct smc_llc_msg_del_link *delllc; |
| 498 | struct smc_wr_tx_pend_priv *pend; |
| 499 | struct smc_wr_buf *wr_buf; |
| 500 | int rc; |
| 501 | |
| 502 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 503 | if (rc) |
| 504 | return rc; |
| 505 | delllc = (struct smc_llc_msg_del_link *)wr_buf; |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 506 | |
| 507 | memset(delllc, 0, sizeof(*delllc)); |
| 508 | delllc->hd.common.type = SMC_LLC_DELETE_LINK; |
| 509 | delllc->hd.length = sizeof(struct smc_llc_msg_del_link); |
| 510 | if (reqresp == SMC_LLC_RESP) |
| 511 | delllc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 512 | if (orderly) |
| 513 | delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY; |
| 514 | if (link_del_id) |
| 515 | delllc->link_num = link_del_id; |
| 516 | else |
| 517 | delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL; |
| 518 | delllc->reason = htonl(reason); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 519 | /* send llc message */ |
| 520 | rc = smc_wr_tx_send(link, pend); |
| 521 | return rc; |
| 522 | } |
| 523 | |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 524 | /* send LLC test link request */ |
| 525 | 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] | 526 | { |
| 527 | struct smc_llc_msg_test_link *testllc; |
| 528 | struct smc_wr_tx_pend_priv *pend; |
| 529 | struct smc_wr_buf *wr_buf; |
| 530 | int rc; |
| 531 | |
| 532 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 533 | if (rc) |
| 534 | return rc; |
| 535 | testllc = (struct smc_llc_msg_test_link *)wr_buf; |
| 536 | memset(testllc, 0, sizeof(*testllc)); |
| 537 | testllc->hd.common.type = SMC_LLC_TEST_LINK; |
| 538 | testllc->hd.length = sizeof(struct smc_llc_msg_test_link); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 539 | memcpy(testllc->user_data, user_data, sizeof(testllc->user_data)); |
| 540 | /* send llc message */ |
| 541 | rc = smc_wr_tx_send(link, pend); |
| 542 | return rc; |
| 543 | } |
| 544 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 545 | /* schedule an llc send on link, may wait for buffers */ |
| 546 | static int smc_llc_send_message(struct smc_link *link, void *llcbuf) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 547 | { |
| 548 | struct smc_wr_tx_pend_priv *pend; |
| 549 | struct smc_wr_buf *wr_buf; |
| 550 | int rc; |
| 551 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 552 | if (!smc_link_usable(link)) |
| 553 | return -ENOLINK; |
| 554 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 555 | if (rc) |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 556 | return rc; |
| 557 | memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg)); |
| 558 | return smc_wr_tx_send(link, pend); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 561 | /********************************* receive ***********************************/ |
| 562 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 563 | static int smc_llc_alloc_alt_link(struct smc_link_group *lgr, |
| 564 | enum smc_lgr_type lgr_new_t) |
| 565 | { |
| 566 | int i; |
| 567 | |
| 568 | if (lgr->type == SMC_LGR_SYMMETRIC || |
| 569 | (lgr->type != SMC_LGR_SINGLE && |
| 570 | (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 571 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER))) |
| 572 | return -EMLINK; |
| 573 | |
| 574 | if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 575 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER) { |
| 576 | for (i = SMC_LINKS_PER_LGR_MAX - 1; i >= 0; i--) |
| 577 | if (lgr->lnk[i].state == SMC_LNK_UNUSED) |
| 578 | return i; |
| 579 | } else { |
| 580 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) |
| 581 | if (lgr->lnk[i].state == SMC_LNK_UNUSED) |
| 582 | return i; |
| 583 | } |
| 584 | return -EMLINK; |
| 585 | } |
| 586 | |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 587 | /* return first buffer from any of the next buf lists */ |
| 588 | static struct smc_buf_desc *_smc_llc_get_next_rmb(struct smc_link_group *lgr, |
| 589 | int *buf_lst) |
| 590 | { |
| 591 | struct smc_buf_desc *buf_pos; |
| 592 | |
| 593 | while (*buf_lst < SMC_RMBE_SIZES) { |
| 594 | buf_pos = list_first_entry_or_null(&lgr->rmbs[*buf_lst], |
| 595 | struct smc_buf_desc, list); |
| 596 | if (buf_pos) |
| 597 | return buf_pos; |
| 598 | (*buf_lst)++; |
| 599 | } |
| 600 | return NULL; |
| 601 | } |
| 602 | |
| 603 | /* return next rmb from buffer lists */ |
| 604 | static struct smc_buf_desc *smc_llc_get_next_rmb(struct smc_link_group *lgr, |
| 605 | int *buf_lst, |
| 606 | struct smc_buf_desc *buf_pos) |
| 607 | { |
| 608 | struct smc_buf_desc *buf_next; |
| 609 | |
| 610 | if (!buf_pos || list_is_last(&buf_pos->list, &lgr->rmbs[*buf_lst])) { |
| 611 | (*buf_lst)++; |
| 612 | return _smc_llc_get_next_rmb(lgr, buf_lst); |
| 613 | } |
| 614 | buf_next = list_next_entry(buf_pos, list); |
| 615 | return buf_next; |
| 616 | } |
| 617 | |
| 618 | static struct smc_buf_desc *smc_llc_get_first_rmb(struct smc_link_group *lgr, |
| 619 | int *buf_lst) |
| 620 | { |
| 621 | *buf_lst = 0; |
| 622 | return smc_llc_get_next_rmb(lgr, buf_lst, NULL); |
| 623 | } |
| 624 | |
| 625 | /* send one add_link_continue msg */ |
| 626 | static int smc_llc_add_link_cont(struct smc_link *link, |
| 627 | struct smc_link *link_new, u8 *num_rkeys_todo, |
| 628 | int *buf_lst, struct smc_buf_desc **buf_pos) |
| 629 | { |
| 630 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 631 | struct smc_link_group *lgr = link->lgr; |
| 632 | int prim_lnk_idx, lnk_idx, i, rc; |
| 633 | struct smc_wr_tx_pend_priv *pend; |
| 634 | struct smc_wr_buf *wr_buf; |
| 635 | struct smc_buf_desc *rmb; |
| 636 | u8 n; |
| 637 | |
| 638 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 639 | if (rc) |
| 640 | return rc; |
| 641 | addc_llc = (struct smc_llc_msg_add_link_cont *)wr_buf; |
| 642 | memset(addc_llc, 0, sizeof(*addc_llc)); |
| 643 | |
| 644 | prim_lnk_idx = link->link_idx; |
| 645 | lnk_idx = link_new->link_idx; |
| 646 | addc_llc->link_num = link_new->link_id; |
| 647 | addc_llc->num_rkeys = *num_rkeys_todo; |
| 648 | n = *num_rkeys_todo; |
| 649 | for (i = 0; i < min_t(u8, n, SMC_LLC_RKEYS_PER_CONT_MSG); i++) { |
| 650 | if (!*buf_pos) { |
| 651 | addc_llc->num_rkeys = addc_llc->num_rkeys - |
| 652 | *num_rkeys_todo; |
| 653 | *num_rkeys_todo = 0; |
| 654 | break; |
| 655 | } |
| 656 | rmb = *buf_pos; |
| 657 | |
| 658 | addc_llc->rt[i].rmb_key = htonl(rmb->mr_rx[prim_lnk_idx]->rkey); |
| 659 | addc_llc->rt[i].rmb_key_new = htonl(rmb->mr_rx[lnk_idx]->rkey); |
| 660 | addc_llc->rt[i].rmb_vaddr_new = |
| 661 | cpu_to_be64((u64)sg_dma_address(rmb->sgt[lnk_idx].sgl)); |
| 662 | |
| 663 | (*num_rkeys_todo)--; |
| 664 | *buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos); |
| 665 | while (*buf_pos && !(*buf_pos)->used) |
| 666 | *buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos); |
| 667 | } |
| 668 | addc_llc->hd.common.type = SMC_LLC_ADD_LINK_CONT; |
| 669 | addc_llc->hd.length = sizeof(struct smc_llc_msg_add_link_cont); |
| 670 | if (lgr->role == SMC_CLNT) |
| 671 | addc_llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 672 | return smc_wr_tx_send(link, pend); |
| 673 | } |
| 674 | |
| 675 | static int smc_llc_cli_rkey_exchange(struct smc_link *link, |
| 676 | struct smc_link *link_new) |
| 677 | { |
| 678 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 679 | struct smc_link_group *lgr = link->lgr; |
| 680 | u8 max, num_rkeys_send, num_rkeys_recv; |
| 681 | struct smc_llc_qentry *qentry; |
| 682 | struct smc_buf_desc *buf_pos; |
| 683 | int buf_lst; |
| 684 | int rc = 0; |
| 685 | int i; |
| 686 | |
| 687 | mutex_lock(&lgr->rmbs_lock); |
| 688 | num_rkeys_send = lgr->conns_num; |
| 689 | buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); |
| 690 | do { |
| 691 | qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_TIME, |
| 692 | SMC_LLC_ADD_LINK_CONT); |
| 693 | if (!qentry) { |
| 694 | rc = -ETIMEDOUT; |
| 695 | break; |
| 696 | } |
| 697 | addc_llc = &qentry->msg.add_link_cont; |
| 698 | num_rkeys_recv = addc_llc->num_rkeys; |
| 699 | max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG); |
| 700 | for (i = 0; i < max; i++) { |
| 701 | smc_rtoken_set(lgr, link->link_idx, link_new->link_idx, |
| 702 | addc_llc->rt[i].rmb_key, |
| 703 | addc_llc->rt[i].rmb_vaddr_new, |
| 704 | addc_llc->rt[i].rmb_key_new); |
| 705 | num_rkeys_recv--; |
| 706 | } |
| 707 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 708 | rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send, |
| 709 | &buf_lst, &buf_pos); |
| 710 | if (rc) |
| 711 | break; |
| 712 | } while (num_rkeys_send || num_rkeys_recv); |
| 713 | |
| 714 | mutex_unlock(&lgr->rmbs_lock); |
| 715 | return rc; |
| 716 | } |
| 717 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 718 | /* prepare and send an add link reject response */ |
| 719 | static int smc_llc_cli_add_link_reject(struct smc_llc_qentry *qentry) |
| 720 | { |
| 721 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP; |
| 722 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_ADD_LNK_REJ; |
| 723 | qentry->msg.raw.hdr.add_link_rej_rsn = SMC_LLC_REJ_RSN_NO_ALT_PATH; |
| 724 | return smc_llc_send_message(qentry->link, &qentry->msg); |
| 725 | } |
| 726 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 727 | static int smc_llc_cli_conf_link(struct smc_link *link, |
| 728 | struct smc_init_info *ini, |
| 729 | struct smc_link *link_new, |
| 730 | enum smc_lgr_type lgr_new_t) |
| 731 | { |
| 732 | struct smc_link_group *lgr = link->lgr; |
| 733 | struct smc_llc_msg_del_link *del_llc; |
| 734 | struct smc_llc_qentry *qentry = NULL; |
| 735 | int rc = 0; |
| 736 | |
| 737 | /* receive CONFIRM LINK request over RoCE fabric */ |
| 738 | qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_FIRST_TIME, 0); |
| 739 | if (!qentry) { |
| 740 | rc = smc_llc_send_delete_link(link, link_new->link_id, |
| 741 | SMC_LLC_REQ, false, |
| 742 | SMC_LLC_DEL_LOST_PATH); |
| 743 | return -ENOLINK; |
| 744 | } |
| 745 | if (qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) { |
| 746 | /* received DELETE_LINK instead */ |
| 747 | del_llc = &qentry->msg.delete_link; |
| 748 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP; |
| 749 | smc_llc_send_message(link, &qentry->msg); |
| 750 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 751 | return -ENOLINK; |
| 752 | } |
| 753 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 754 | |
| 755 | rc = smc_ib_modify_qp_rts(link_new); |
| 756 | if (rc) { |
| 757 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 758 | false, SMC_LLC_DEL_LOST_PATH); |
| 759 | return -ENOLINK; |
| 760 | } |
| 761 | smc_wr_remember_qp_attr(link_new); |
| 762 | |
| 763 | rc = smcr_buf_reg_lgr(link_new); |
| 764 | if (rc) { |
| 765 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 766 | false, SMC_LLC_DEL_LOST_PATH); |
| 767 | return -ENOLINK; |
| 768 | } |
| 769 | |
| 770 | /* send CONFIRM LINK response over RoCE fabric */ |
| 771 | rc = smc_llc_send_confirm_link(link_new, SMC_LLC_RESP); |
| 772 | if (rc) { |
| 773 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 774 | false, SMC_LLC_DEL_LOST_PATH); |
| 775 | return -ENOLINK; |
| 776 | } |
| 777 | smc_llc_link_active(link_new); |
| 778 | lgr->type = lgr_new_t; |
| 779 | return 0; |
| 780 | } |
| 781 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 782 | static void smc_llc_save_add_link_info(struct smc_link *link, |
| 783 | struct smc_llc_msg_add_link *add_llc) |
| 784 | { |
| 785 | link->peer_qpn = ntoh24(add_llc->sender_qp_num); |
| 786 | memcpy(link->peer_gid, add_llc->sender_gid, SMC_GID_SIZE); |
| 787 | memcpy(link->peer_mac, add_llc->sender_mac, ETH_ALEN); |
| 788 | link->peer_psn = ntoh24(add_llc->initial_psn); |
| 789 | link->peer_mtu = add_llc->qp_mtu; |
| 790 | } |
| 791 | |
| 792 | /* as an SMC client, process an add link request */ |
| 793 | int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry) |
| 794 | { |
| 795 | struct smc_llc_msg_add_link *llc = &qentry->msg.add_link; |
| 796 | enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC; |
| 797 | struct smc_link_group *lgr = smc_get_lgr(link); |
| 798 | struct smc_link *lnk_new = NULL; |
| 799 | struct smc_init_info ini; |
| 800 | int lnk_idx, rc = 0; |
| 801 | |
| 802 | ini.vlan_id = lgr->vlan_id; |
| 803 | smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev); |
| 804 | if (!memcmp(llc->sender_gid, link->peer_gid, SMC_GID_SIZE) && |
| 805 | !memcmp(llc->sender_mac, link->peer_mac, ETH_ALEN)) { |
| 806 | if (!ini.ib_dev) |
| 807 | goto out_reject; |
| 808 | lgr_new_t = SMC_LGR_ASYMMETRIC_PEER; |
| 809 | } |
| 810 | if (!ini.ib_dev) { |
| 811 | lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL; |
| 812 | ini.ib_dev = link->smcibdev; |
| 813 | ini.ib_port = link->ibport; |
| 814 | } |
| 815 | lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t); |
| 816 | if (lnk_idx < 0) |
| 817 | goto out_reject; |
| 818 | lnk_new = &lgr->lnk[lnk_idx]; |
| 819 | rc = smcr_link_init(lgr, lnk_new, lnk_idx, &ini); |
| 820 | if (rc) |
| 821 | goto out_reject; |
| 822 | smc_llc_save_add_link_info(lnk_new, llc); |
| 823 | lnk_new->link_id = llc->link_num; |
| 824 | |
| 825 | rc = smc_ib_ready_link(lnk_new); |
| 826 | if (rc) |
| 827 | goto out_clear_lnk; |
| 828 | |
| 829 | rc = smcr_buf_map_lgr(lnk_new); |
| 830 | if (rc) |
| 831 | goto out_clear_lnk; |
| 832 | |
| 833 | rc = smc_llc_send_add_link(link, |
| 834 | lnk_new->smcibdev->mac[ini.ib_port - 1], |
| 835 | lnk_new->gid, lnk_new, SMC_LLC_RESP); |
| 836 | if (rc) |
| 837 | goto out_clear_lnk; |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 838 | rc = smc_llc_cli_rkey_exchange(link, lnk_new); |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 839 | if (rc) { |
| 840 | rc = 0; |
| 841 | goto out_clear_lnk; |
| 842 | } |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 843 | rc = smc_llc_cli_conf_link(link, &ini, lnk_new, lgr_new_t); |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 844 | if (!rc) |
| 845 | goto out; |
| 846 | out_clear_lnk: |
| 847 | smcr_link_clear(lnk_new); |
| 848 | out_reject: |
| 849 | smc_llc_cli_add_link_reject(qentry); |
| 850 | out: |
| 851 | kfree(qentry); |
| 852 | return rc; |
| 853 | } |
| 854 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 855 | static void smc_llc_process_cli_add_link(struct smc_link_group *lgr) |
| 856 | { |
| 857 | struct smc_llc_qentry *qentry; |
| 858 | |
| 859 | qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl); |
| 860 | |
| 861 | mutex_lock(&lgr->llc_conf_mutex); |
| 862 | smc_llc_cli_add_link(qentry->link, qentry); |
| 863 | mutex_unlock(&lgr->llc_conf_mutex); |
| 864 | } |
| 865 | |
Karsten Graul | 57b4992 | 2020-05-03 14:38:44 +0200 | [diff] [blame^] | 866 | static int smc_llc_srv_rkey_exchange(struct smc_link *link, |
| 867 | struct smc_link *link_new) |
| 868 | { |
| 869 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 870 | struct smc_link_group *lgr = link->lgr; |
| 871 | u8 max, num_rkeys_send, num_rkeys_recv; |
| 872 | struct smc_llc_qentry *qentry = NULL; |
| 873 | struct smc_buf_desc *buf_pos; |
| 874 | int buf_lst; |
| 875 | int rc = 0; |
| 876 | int i; |
| 877 | |
| 878 | mutex_lock(&lgr->rmbs_lock); |
| 879 | num_rkeys_send = lgr->conns_num; |
| 880 | buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); |
| 881 | do { |
| 882 | smc_llc_add_link_cont(link, link_new, &num_rkeys_send, |
| 883 | &buf_lst, &buf_pos); |
| 884 | qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, |
| 885 | SMC_LLC_ADD_LINK_CONT); |
| 886 | if (!qentry) { |
| 887 | rc = -ETIMEDOUT; |
| 888 | goto out; |
| 889 | } |
| 890 | addc_llc = &qentry->msg.add_link_cont; |
| 891 | num_rkeys_recv = addc_llc->num_rkeys; |
| 892 | max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG); |
| 893 | for (i = 0; i < max; i++) { |
| 894 | smc_rtoken_set(lgr, link->link_idx, link_new->link_idx, |
| 895 | addc_llc->rt[i].rmb_key, |
| 896 | addc_llc->rt[i].rmb_vaddr_new, |
| 897 | addc_llc->rt[i].rmb_key_new); |
| 898 | num_rkeys_recv--; |
| 899 | } |
| 900 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 901 | } while (num_rkeys_send || num_rkeys_recv); |
| 902 | out: |
| 903 | mutex_unlock(&lgr->rmbs_lock); |
| 904 | return rc; |
| 905 | } |
| 906 | |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 907 | int smc_llc_srv_add_link(struct smc_link *link) |
| 908 | { |
| 909 | enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC; |
| 910 | struct smc_link_group *lgr = link->lgr; |
| 911 | struct smc_llc_msg_add_link *add_llc; |
| 912 | struct smc_llc_qentry *qentry = NULL; |
| 913 | struct smc_link *link_new; |
| 914 | struct smc_init_info ini; |
| 915 | int lnk_idx, rc = 0; |
| 916 | |
| 917 | /* ignore client add link recommendation, start new flow */ |
| 918 | ini.vlan_id = lgr->vlan_id; |
| 919 | smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev); |
| 920 | if (!ini.ib_dev) { |
| 921 | lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL; |
| 922 | ini.ib_dev = link->smcibdev; |
| 923 | ini.ib_port = link->ibport; |
| 924 | } |
| 925 | lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t); |
| 926 | if (lnk_idx < 0) |
| 927 | return 0; |
| 928 | |
| 929 | rc = smcr_link_init(lgr, &lgr->lnk[lnk_idx], lnk_idx, &ini); |
| 930 | if (rc) |
| 931 | return rc; |
| 932 | link_new = &lgr->lnk[lnk_idx]; |
| 933 | rc = smc_llc_send_add_link(link, |
| 934 | link_new->smcibdev->mac[ini.ib_port - 1], |
| 935 | link_new->gid, link_new, SMC_LLC_REQ); |
| 936 | if (rc) |
| 937 | goto out_err; |
| 938 | /* receive ADD LINK response over the RoCE fabric */ |
| 939 | qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, SMC_LLC_ADD_LINK); |
| 940 | if (!qentry) { |
| 941 | rc = -ETIMEDOUT; |
| 942 | goto out_err; |
| 943 | } |
| 944 | add_llc = &qentry->msg.add_link; |
| 945 | if (add_llc->hd.flags & SMC_LLC_FLAG_ADD_LNK_REJ) { |
| 946 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 947 | rc = -ENOLINK; |
| 948 | goto out_err; |
| 949 | } |
| 950 | if (lgr->type == SMC_LGR_SINGLE && |
| 951 | (!memcmp(add_llc->sender_gid, link->peer_gid, SMC_GID_SIZE) && |
| 952 | !memcmp(add_llc->sender_mac, link->peer_mac, ETH_ALEN))) { |
| 953 | lgr_new_t = SMC_LGR_ASYMMETRIC_PEER; |
| 954 | } |
| 955 | smc_llc_save_add_link_info(link_new, add_llc); |
| 956 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 957 | |
| 958 | rc = smc_ib_ready_link(link_new); |
| 959 | if (rc) |
| 960 | goto out_err; |
| 961 | rc = smcr_buf_map_lgr(link_new); |
| 962 | if (rc) |
| 963 | goto out_err; |
| 964 | rc = smcr_buf_reg_lgr(link_new); |
| 965 | if (rc) |
| 966 | goto out_err; |
Karsten Graul | 57b4992 | 2020-05-03 14:38:44 +0200 | [diff] [blame^] | 967 | rc = smc_llc_srv_rkey_exchange(link, link_new); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 968 | if (rc) |
| 969 | goto out_err; |
| 970 | /* tbd: rc = smc_llc_srv_conf_link(link, link_new, lgr_new_t); */ |
| 971 | if (rc) |
| 972 | goto out_err; |
| 973 | return 0; |
| 974 | out_err: |
| 975 | smcr_link_clear(link_new); |
| 976 | return rc; |
| 977 | } |
| 978 | |
| 979 | static void smc_llc_process_srv_add_link(struct smc_link_group *lgr) |
| 980 | { |
| 981 | struct smc_link *link = lgr->llc_flow_lcl.qentry->link; |
| 982 | int rc; |
| 983 | |
| 984 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 985 | |
| 986 | mutex_lock(&lgr->llc_conf_mutex); |
| 987 | rc = smc_llc_srv_add_link(link); |
| 988 | if (!rc && lgr->type == SMC_LGR_SYMMETRIC) { |
| 989 | /* delete any asymmetric link */ |
| 990 | /* tbd: smc_llc_delete_asym_link(lgr); */ |
| 991 | } |
| 992 | mutex_unlock(&lgr->llc_conf_mutex); |
| 993 | } |
| 994 | |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 995 | /* worker to process an add link message */ |
| 996 | static void smc_llc_add_link_work(struct work_struct *work) |
| 997 | { |
| 998 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, |
| 999 | llc_add_link_work); |
| 1000 | |
| 1001 | if (list_empty(&lgr->list)) { |
| 1002 | /* link group is terminating */ |
| 1003 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1004 | goto out; |
| 1005 | } |
| 1006 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 1007 | if (lgr->role == SMC_CLNT) |
| 1008 | smc_llc_process_cli_add_link(lgr); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1009 | else |
| 1010 | smc_llc_process_srv_add_link(lgr); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1011 | out: |
| 1012 | smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl); |
| 1013 | } |
| 1014 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1015 | static void smc_llc_rx_delete_link(struct smc_link *link, |
| 1016 | struct smc_llc_msg_del_link *llc) |
| 1017 | { |
Stefan Raspl | 00e5fb2 | 2018-07-23 13:53:10 +0200 | [diff] [blame] | 1018 | struct smc_link_group *lgr = smc_get_lgr(link); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1019 | |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1020 | smc_lgr_forget(lgr); |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1021 | if (lgr->role == SMC_SERV) { |
| 1022 | /* client asks to delete this link, send request */ |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 1023 | smc_llc_send_delete_link(link, 0, SMC_LLC_REQ, true, |
| 1024 | SMC_LLC_DEL_PROG_INIT_TERM); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1025 | } else { |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1026 | /* server requests to delete this link, send response */ |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 1027 | smc_llc_send_delete_link(link, 0, SMC_LLC_RESP, true, |
| 1028 | SMC_LLC_DEL_PROG_INIT_TERM); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1029 | } |
Karsten Graul | 8752393 | 2020-05-01 12:48:09 +0200 | [diff] [blame] | 1030 | smcr_link_down_cond(link); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1033 | /* process a confirm_rkey request from peer, remote flow */ |
| 1034 | static void smc_llc_rmt_conf_rkey(struct smc_link_group *lgr) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1035 | { |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1036 | struct smc_llc_msg_confirm_rkey *llc; |
| 1037 | struct smc_llc_qentry *qentry; |
| 1038 | struct smc_link *link; |
| 1039 | int num_entries; |
| 1040 | int rk_idx; |
| 1041 | int i; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1042 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1043 | qentry = lgr->llc_flow_rmt.qentry; |
| 1044 | llc = &qentry->msg.confirm_rkey; |
| 1045 | link = qentry->link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1046 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1047 | num_entries = llc->rtoken[0].num_rkeys; |
| 1048 | /* first rkey entry is for receiving link */ |
| 1049 | rk_idx = smc_rtoken_add(link, |
| 1050 | llc->rtoken[0].rmb_vaddr, |
| 1051 | llc->rtoken[0].rmb_key); |
| 1052 | if (rk_idx < 0) |
| 1053 | goto out_err; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1054 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1055 | for (i = 1; i <= min_t(u8, num_entries, SMC_LLC_RKEYS_PER_MSG - 1); i++) |
| 1056 | smc_rtoken_set2(lgr, rk_idx, llc->rtoken[i].link_id, |
| 1057 | llc->rtoken[i].rmb_vaddr, |
| 1058 | llc->rtoken[i].rmb_key); |
| 1059 | /* max links is 3 so there is no need to support conf_rkey_cont msgs */ |
| 1060 | goto out; |
| 1061 | out_err: |
| 1062 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG; |
| 1063 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_RETRY; |
| 1064 | out: |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1065 | llc->hd.flags |= SMC_LLC_FLAG_RESP; |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1066 | smc_llc_send_message(link, &qentry->msg); |
| 1067 | smc_llc_flow_qentry_del(&lgr->llc_flow_rmt); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1070 | /* process a delete_rkey request from peer, remote flow */ |
| 1071 | static void smc_llc_rmt_delete_rkey(struct smc_link_group *lgr) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1072 | { |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1073 | struct smc_llc_msg_delete_rkey *llc; |
| 1074 | struct smc_llc_qentry *qentry; |
| 1075 | struct smc_link *link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1076 | u8 err_mask = 0; |
| 1077 | int i, max; |
| 1078 | |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1079 | qentry = lgr->llc_flow_rmt.qentry; |
| 1080 | llc = &qentry->msg.delete_rkey; |
| 1081 | link = qentry->link; |
| 1082 | |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1083 | max = min_t(u8, llc->num_rkeys, SMC_LLC_DEL_RKEY_MAX); |
| 1084 | for (i = 0; i < max; i++) { |
| 1085 | if (smc_rtoken_delete(link, llc->rkey[i])) |
| 1086 | err_mask |= 1 << (SMC_LLC_DEL_RKEY_MAX - 1 - i); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1087 | } |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1088 | if (err_mask) { |
| 1089 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG; |
| 1090 | llc->err_mask = err_mask; |
| 1091 | } |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1092 | llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 1093 | smc_llc_send_message(link, &qentry->msg); |
| 1094 | smc_llc_flow_qentry_del(&lgr->llc_flow_rmt); |
| 1095 | } |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1096 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1097 | /* flush the llc event queue */ |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1098 | static void smc_llc_event_flush(struct smc_link_group *lgr) |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1099 | { |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1100 | struct smc_llc_qentry *qentry, *q; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1101 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1102 | spin_lock_bh(&lgr->llc_event_q_lock); |
| 1103 | list_for_each_entry_safe(qentry, q, &lgr->llc_event_q, list) { |
| 1104 | list_del_init(&qentry->list); |
| 1105 | kfree(qentry); |
| 1106 | } |
| 1107 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1108 | } |
| 1109 | |
| 1110 | static void smc_llc_event_handler(struct smc_llc_qentry *qentry) |
| 1111 | { |
| 1112 | union smc_llc_msg *llc = &qentry->msg; |
| 1113 | struct smc_link *link = qentry->link; |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1114 | struct smc_link_group *lgr = link->lgr; |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1115 | |
Karsten Graul | d854fcb | 2020-04-29 17:10:43 +0200 | [diff] [blame] | 1116 | if (!smc_link_usable(link)) |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1117 | goto out; |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1118 | |
| 1119 | switch (llc->raw.hdr.common.type) { |
| 1120 | case SMC_LLC_TEST_LINK: |
Karsten Graul | 56e8091 | 2020-04-30 15:55:46 +0200 | [diff] [blame] | 1121 | llc->test_link.hd.flags |= SMC_LLC_FLAG_RESP; |
| 1122 | smc_llc_send_message(link, llc); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1123 | break; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1124 | case SMC_LLC_ADD_LINK: |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1125 | if (list_empty(&lgr->list)) |
| 1126 | goto out; /* lgr is terminating */ |
| 1127 | if (lgr->role == SMC_CLNT) { |
| 1128 | if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK) { |
| 1129 | /* a flow is waiting for this message */ |
| 1130 | smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, |
| 1131 | qentry); |
| 1132 | wake_up_interruptible(&lgr->llc_waiter); |
| 1133 | } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, |
| 1134 | qentry)) { |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1135 | schedule_work(&lgr->llc_add_link_work); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1136 | } |
| 1137 | } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) { |
| 1138 | /* as smc server, handle client suggestion */ |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1139 | schedule_work(&lgr->llc_add_link_work); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1140 | } |
| 1141 | return; |
| 1142 | case SMC_LLC_CONFIRM_LINK: |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1143 | case SMC_LLC_ADD_LINK_CONT: |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1144 | if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) { |
| 1145 | /* a flow is waiting for this message */ |
| 1146 | smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry); |
| 1147 | wake_up_interruptible(&lgr->llc_waiter); |
| 1148 | return; |
| 1149 | } |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1150 | break; |
| 1151 | case SMC_LLC_DELETE_LINK: |
| 1152 | smc_llc_rx_delete_link(link, &llc->delete_link); |
| 1153 | break; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1154 | case SMC_LLC_CONFIRM_RKEY: |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1155 | /* new request from remote, assign to remote flow */ |
| 1156 | if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) { |
| 1157 | /* process here, does not wait for more llc msgs */ |
| 1158 | smc_llc_rmt_conf_rkey(lgr); |
| 1159 | smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt); |
| 1160 | } |
| 1161 | return; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1162 | case SMC_LLC_CONFIRM_RKEY_CONT: |
Karsten Graul | 42d18ac | 2020-04-30 15:55:50 +0200 | [diff] [blame] | 1163 | /* not used because max links is 3, and 3 rkeys fit into |
| 1164 | * one CONFIRM_RKEY message |
| 1165 | */ |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1166 | break; |
| 1167 | case SMC_LLC_DELETE_RKEY: |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1168 | /* new request from remote, assign to remote flow */ |
| 1169 | if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) { |
| 1170 | /* process here, does not wait for more llc msgs */ |
| 1171 | smc_llc_rmt_delete_rkey(lgr); |
| 1172 | smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt); |
| 1173 | } |
| 1174 | return; |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1175 | } |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1176 | out: |
| 1177 | kfree(qentry); |
| 1178 | } |
| 1179 | |
| 1180 | /* worker to process llc messages on the event queue */ |
| 1181 | static void smc_llc_event_work(struct work_struct *work) |
| 1182 | { |
| 1183 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, |
| 1184 | llc_event_work); |
| 1185 | struct smc_llc_qentry *qentry; |
| 1186 | |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1187 | if (!lgr->llc_flow_lcl.type && lgr->delayed_event) { |
| 1188 | if (smc_link_usable(lgr->delayed_event->link)) { |
| 1189 | smc_llc_event_handler(lgr->delayed_event); |
| 1190 | } else { |
| 1191 | qentry = lgr->delayed_event; |
| 1192 | lgr->delayed_event = NULL; |
| 1193 | kfree(qentry); |
| 1194 | } |
| 1195 | } |
| 1196 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1197 | again: |
| 1198 | spin_lock_bh(&lgr->llc_event_q_lock); |
| 1199 | if (!list_empty(&lgr->llc_event_q)) { |
| 1200 | qentry = list_first_entry(&lgr->llc_event_q, |
| 1201 | struct smc_llc_qentry, list); |
| 1202 | list_del_init(&qentry->list); |
| 1203 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1204 | smc_llc_event_handler(qentry); |
| 1205 | goto again; |
| 1206 | } |
| 1207 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1208 | } |
| 1209 | |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1210 | /* process llc responses in tasklet context */ |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1211 | static void smc_llc_rx_response(struct smc_link *link, |
| 1212 | struct smc_llc_qentry *qentry) |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1213 | { |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1214 | u8 llc_type = qentry->msg.raw.hdr.common.type; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1215 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1216 | switch (llc_type) { |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1217 | case SMC_LLC_TEST_LINK: |
| 1218 | if (link->state == SMC_LNK_ACTIVE) |
| 1219 | complete(&link->llc_testlink_resp); |
| 1220 | break; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1221 | case SMC_LLC_ADD_LINK: |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1222 | case SMC_LLC_CONFIRM_LINK: |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1223 | case SMC_LLC_ADD_LINK_CONT: |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1224 | case SMC_LLC_CONFIRM_RKEY: |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1225 | case SMC_LLC_DELETE_RKEY: |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1226 | /* assign responses to the local flow, we requested them */ |
| 1227 | smc_llc_flow_qentry_set(&link->lgr->llc_flow_lcl, qentry); |
| 1228 | wake_up_interruptible(&link->lgr->llc_waiter); |
| 1229 | return; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1230 | case SMC_LLC_DELETE_LINK: |
| 1231 | if (link->lgr->role == SMC_SERV) |
| 1232 | smc_lgr_schedule_free_work_fast(link->lgr); |
| 1233 | break; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1234 | case SMC_LLC_CONFIRM_RKEY_CONT: |
Karsten Graul | 42d18ac | 2020-04-30 15:55:50 +0200 | [diff] [blame] | 1235 | /* not used because max links is 3 */ |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1236 | break; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1237 | } |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1238 | kfree(qentry); |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1241 | static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc) |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1242 | { |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1243 | struct smc_link_group *lgr = link->lgr; |
| 1244 | struct smc_llc_qentry *qentry; |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1245 | unsigned long flags; |
| 1246 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1247 | qentry = kmalloc(sizeof(*qentry), GFP_ATOMIC); |
| 1248 | if (!qentry) |
| 1249 | return; |
| 1250 | qentry->link = link; |
| 1251 | INIT_LIST_HEAD(&qentry->list); |
| 1252 | memcpy(&qentry->msg, llc, sizeof(union smc_llc_msg)); |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1253 | |
| 1254 | /* process responses immediately */ |
| 1255 | if (llc->raw.hdr.flags & SMC_LLC_FLAG_RESP) { |
| 1256 | smc_llc_rx_response(link, qentry); |
| 1257 | return; |
| 1258 | } |
| 1259 | |
| 1260 | /* add requests to event queue */ |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1261 | spin_lock_irqsave(&lgr->llc_event_q_lock, flags); |
| 1262 | list_add_tail(&qentry->list, &lgr->llc_event_q); |
| 1263 | spin_unlock_irqrestore(&lgr->llc_event_q_lock, flags); |
| 1264 | schedule_work(&link->lgr->llc_event_work); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1267 | /* copy received msg and add it to the event queue */ |
| 1268 | static void smc_llc_rx_handler(struct ib_wc *wc, void *buf) |
| 1269 | { |
| 1270 | struct smc_link *link = (struct smc_link *)wc->qp->qp_context; |
| 1271 | union smc_llc_msg *llc = buf; |
| 1272 | |
| 1273 | if (wc->byte_len < sizeof(*llc)) |
| 1274 | return; /* short message */ |
| 1275 | if (llc->raw.hdr.length != sizeof(*llc)) |
| 1276 | return; /* invalid message */ |
| 1277 | |
| 1278 | smc_llc_enqueue(link, llc); |
| 1279 | } |
| 1280 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1281 | /***************************** worker, utils *********************************/ |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1282 | |
| 1283 | static void smc_llc_testlink_work(struct work_struct *work) |
| 1284 | { |
| 1285 | struct smc_link *link = container_of(to_delayed_work(work), |
| 1286 | struct smc_link, llc_testlink_wrk); |
| 1287 | unsigned long next_interval; |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1288 | unsigned long expire_time; |
| 1289 | u8 user_data[16] = { 0 }; |
| 1290 | int rc; |
| 1291 | |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1292 | if (link->state != SMC_LNK_ACTIVE) |
| 1293 | return; /* don't reschedule worker */ |
| 1294 | expire_time = link->wr_rx_tstamp + link->llc_testlink_time; |
| 1295 | if (time_is_after_jiffies(expire_time)) { |
| 1296 | next_interval = expire_time - jiffies; |
| 1297 | goto out; |
| 1298 | } |
| 1299 | reinit_completion(&link->llc_testlink_resp); |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 1300 | smc_llc_send_test_link(link, user_data); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1301 | /* receive TEST LINK response over RoCE fabric */ |
| 1302 | rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp, |
| 1303 | SMC_LLC_WAIT_TIME); |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1304 | if (link->state != SMC_LNK_ACTIVE) |
| 1305 | return; /* link state changed */ |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1306 | if (rc <= 0) { |
Karsten Graul | 8752393 | 2020-05-01 12:48:09 +0200 | [diff] [blame] | 1307 | smcr_link_down_cond_sched(link); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1308 | return; |
| 1309 | } |
| 1310 | next_interval = link->llc_testlink_time; |
| 1311 | out: |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1312 | schedule_delayed_work(&link->llc_testlink_wrk, next_interval); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1315 | void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc) |
| 1316 | { |
| 1317 | struct net *net = sock_net(smc->clcsock->sk); |
| 1318 | |
| 1319 | INIT_WORK(&lgr->llc_event_work, smc_llc_event_work); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1320 | INIT_WORK(&lgr->llc_add_link_work, smc_llc_add_link_work); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1321 | INIT_LIST_HEAD(&lgr->llc_event_q); |
| 1322 | spin_lock_init(&lgr->llc_event_q_lock); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1323 | spin_lock_init(&lgr->llc_flow_lock); |
| 1324 | init_waitqueue_head(&lgr->llc_waiter); |
Karsten Graul | d550066 | 2020-05-01 12:48:05 +0200 | [diff] [blame] | 1325 | mutex_init(&lgr->llc_conf_mutex); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1326 | lgr->llc_testlink_time = net->ipv4.sysctl_tcp_keepalive_time; |
| 1327 | } |
| 1328 | |
| 1329 | /* called after lgr was removed from lgr_list */ |
| 1330 | void smc_llc_lgr_clear(struct smc_link_group *lgr) |
| 1331 | { |
| 1332 | smc_llc_event_flush(lgr); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1333 | wake_up_interruptible_all(&lgr->llc_waiter); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1334 | cancel_work_sync(&lgr->llc_event_work); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1335 | cancel_work_sync(&lgr->llc_add_link_work); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1336 | if (lgr->delayed_event) { |
| 1337 | kfree(lgr->delayed_event); |
| 1338 | lgr->delayed_event = NULL; |
| 1339 | } |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 1342 | int smc_llc_link_init(struct smc_link *link) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1343 | { |
| 1344 | init_completion(&link->llc_testlink_resp); |
| 1345 | INIT_DELAYED_WORK(&link->llc_testlink_wrk, smc_llc_testlink_work); |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 1346 | return 0; |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1349 | void smc_llc_link_active(struct smc_link *link) |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame] | 1350 | { |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1351 | link->state = SMC_LNK_ACTIVE; |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1352 | if (link->lgr->llc_testlink_time) { |
| 1353 | link->llc_testlink_time = link->lgr->llc_testlink_time * HZ; |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1354 | schedule_delayed_work(&link->llc_testlink_wrk, |
| 1355 | link->llc_testlink_time); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1359 | /* called in worker context */ |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 1360 | void smc_llc_link_clear(struct smc_link *link) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1361 | { |
Karsten Graul | 2140ac2 | 2020-04-29 17:10:45 +0200 | [diff] [blame] | 1362 | complete(&link->llc_testlink_resp); |
| 1363 | cancel_delayed_work_sync(&link->llc_testlink_wrk); |
| 1364 | smc_wr_wakeup_reg_wait(link); |
| 1365 | smc_wr_wakeup_tx_wait(link); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1368 | /* register a new rtoken at the remote peer (for all links) */ |
| 1369 | int smc_llc_do_confirm_rkey(struct smc_link *send_link, |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1370 | struct smc_buf_desc *rmb_desc) |
| 1371 | { |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1372 | struct smc_link_group *lgr = send_link->lgr; |
| 1373 | struct smc_llc_qentry *qentry = NULL; |
| 1374 | int rc = 0; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1375 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1376 | rc = smc_llc_send_confirm_rkey(send_link, rmb_desc); |
| 1377 | if (rc) |
| 1378 | goto out; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1379 | /* receive CONFIRM RKEY response from server over RoCE fabric */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1380 | qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME, |
| 1381 | SMC_LLC_CONFIRM_RKEY); |
| 1382 | if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG)) |
| 1383 | rc = -EFAULT; |
| 1384 | out: |
| 1385 | if (qentry) |
| 1386 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1387 | return rc; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1390 | /* unregister an rtoken at the remote peer */ |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1391 | int smc_llc_do_delete_rkey(struct smc_link_group *lgr, |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1392 | struct smc_buf_desc *rmb_desc) |
| 1393 | { |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1394 | struct smc_llc_qentry *qentry = NULL; |
| 1395 | struct smc_link *send_link; |
Ursula Braun | 0b29ec6 | 2019-11-14 13:02:47 +0100 | [diff] [blame] | 1396 | int rc = 0; |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1397 | |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1398 | send_link = smc_llc_usable_link(lgr); |
| 1399 | if (!send_link) |
| 1400 | return -ENOLINK; |
| 1401 | |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1402 | /* protected by llc_flow control */ |
| 1403 | rc = smc_llc_send_delete_rkey(send_link, rmb_desc); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1404 | if (rc) |
| 1405 | goto out; |
| 1406 | /* receive DELETE RKEY response from server over RoCE fabric */ |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1407 | qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME, |
| 1408 | SMC_LLC_DELETE_RKEY); |
| 1409 | if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG)) |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1410 | rc = -EFAULT; |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1411 | out: |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1412 | if (qentry) |
| 1413 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1414 | return rc; |
| 1415 | } |
| 1416 | |
Karsten Graul | 92334cf | 2020-04-30 15:55:41 +0200 | [diff] [blame] | 1417 | /* evaluate confirm link request or response */ |
| 1418 | int smc_llc_eval_conf_link(struct smc_llc_qentry *qentry, |
| 1419 | enum smc_llc_reqresp type) |
| 1420 | { |
| 1421 | if (type == SMC_LLC_REQ) /* SMC server assigns link_id */ |
| 1422 | qentry->link->link_id = qentry->msg.confirm_link.link_num; |
| 1423 | if (!(qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_NO_RMBE_EYEC)) |
| 1424 | return -ENOTSUPP; |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1428 | /***************************** init, exit, misc ******************************/ |
| 1429 | |
| 1430 | static struct smc_wr_rx_handler smc_llc_rx_handlers[] = { |
| 1431 | { |
| 1432 | .handler = smc_llc_rx_handler, |
| 1433 | .type = SMC_LLC_CONFIRM_LINK |
| 1434 | }, |
| 1435 | { |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1436 | .handler = smc_llc_rx_handler, |
| 1437 | .type = SMC_LLC_TEST_LINK |
| 1438 | }, |
| 1439 | { |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1440 | .handler = smc_llc_rx_handler, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1441 | .type = SMC_LLC_ADD_LINK |
| 1442 | }, |
| 1443 | { |
| 1444 | .handler = smc_llc_rx_handler, |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1445 | .type = SMC_LLC_ADD_LINK_CONT |
| 1446 | }, |
| 1447 | { |
| 1448 | .handler = smc_llc_rx_handler, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1449 | .type = SMC_LLC_DELETE_LINK |
| 1450 | }, |
| 1451 | { |
| 1452 | .handler = smc_llc_rx_handler, |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1453 | .type = SMC_LLC_CONFIRM_RKEY |
| 1454 | }, |
| 1455 | { |
| 1456 | .handler = smc_llc_rx_handler, |
| 1457 | .type = SMC_LLC_CONFIRM_RKEY_CONT |
| 1458 | }, |
| 1459 | { |
| 1460 | .handler = smc_llc_rx_handler, |
| 1461 | .type = SMC_LLC_DELETE_RKEY |
| 1462 | }, |
| 1463 | { |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1464 | .handler = NULL, |
| 1465 | } |
| 1466 | }; |
| 1467 | |
| 1468 | int __init smc_llc_init(void) |
| 1469 | { |
| 1470 | struct smc_wr_rx_handler *handler; |
| 1471 | int rc = 0; |
| 1472 | |
| 1473 | for (handler = smc_llc_rx_handlers; handler->handler; handler++) { |
| 1474 | INIT_HLIST_NODE(&handler->list); |
| 1475 | rc = smc_wr_rx_register_handler(handler); |
| 1476 | if (rc) |
| 1477 | break; |
| 1478 | } |
| 1479 | return rc; |
| 1480 | } |